Wsparcie » Wtyczki » Szukam wtyczki do "strony" download

  • Rozwiązano Paniki

    (@paniki)


    Witam
    ślęczę już nad tym dość długo, sprawdziłem wszystkie pluginy, tworzące „dział download”, jakie znalazłem. Niestety, jedne były lepsze, drugie gorsze, ale każdy opierał się na dodawaniu pojedynczych plików do wpisów.

    Ja natomiast mam przygotowane pliki na dysku. Wszystko ponazywane i najlepiej by było gdyby je jakoś wrzucić hurtem na serwer i by się samo wszystko zrobiło. Nie potrzeba mi żadnych opisów, screenów itp. Po prostu mam pliki w jakimś folderze i pasowało by z tego robiła się strona z listą plików do pobrania. Miło by było gdyby miało to licznik pobrań itp, co ma każdy plugin. No ale jak wspomniałem, żaden plugin nie robi konkretnego działu tylko pokazuje kod do pliku by wkleić do treści. Nawet automatycznie nazwy pliku nie pobierze, tylko sam przycisk się wkleja.

    Czy ktoś zna coś ciekawego?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Te bezpłatne to raczej nic ciekawego, jak masz coś prostego to lepiej poszukaj kodera co ci to zrobi. Nie zapłacisz więcej niż 100zł za całość.

    Nie zapłacisz więcej niż 100zł za całość.

    A na emeryturze będziesz siedział pod palmą … no błagam, czy przeczytałeś co tam ma być? ze zrozumieniem?

    Proszę bardzo:
    http://wordpress.org/plugins/cip4-folder-download-widget/screenshots/
    1. Instalujesz i włączasz
    2. W ustawieniach wybierasz folder, z którego mają być pobrane pliki
    3. Wklejasz na stronę shortcode

    Thread Starter Paniki

    (@paniki)

    Dziękuję bardzo!

    Musiałem co nieco do tego dojść jak to działa, bo jako takich ustawień nie znalazłem. Natomiast wszystko było w widgetach i tam się pojawiał download. Próbowałem ten kod, wzorując się na screenach, wrzucić do wpisu, ale nie działał.

    Wywaliłem widget i przeczytałem opis wtyczki, tam przytoczony kod działa i wszystko jest ok, no może prawie i wymaga to dostosowania pod siebie 😉

    Poradziłem sobie z usunięciem niepotrzebnych kolumn i zmianą zajmowanej szerokości przez resztę.

    Ale, nie sortuje we wpisie od A-Z tylko jakoś po swojemu 😉

    Plik cip4-folder-download-widget/cip4-download.php:

    <?php
    
    	// get param
    	$target = $_GET['target'];
    	$infoPath = $_GET['info'];
    
    	$rootPath = '../../../';
    
    	$infoPath = $rootPath . $infoPath;
    	$target = $rootPath . $target;
    
    	if(file_exists($infoPath)) {
    
    		$csvInfos = array();
    
    		// read info csv
    		$infoFile = fopen($infoPath,"r");
    		while (($line = fgetcsv($infoFile)) !== FALSE) {#
    			$csvInfos[$line[0]] = $line;
    		}
    		fclose($infoFile);
    
    		// extract filename for target
    		$file = substr( $target, strrpos( $target, '/' ) + 1 );
    
    		// increment downloads value
    		if ($csvInfos[$file] != '') {
    			$downloads = $csvInfos[$file][1];
    			$downloads ++;
    			$csvInfos[$file][1] = $downloads;
    		} 
    
    		// update .cip4-download-info file
    		$fp = fopen($infoPath, 'w');
    
    		foreach ($csvInfos as $row) {
    		    fputcsv($fp, $row);
    		}
    
    		fclose($fp);
    	} 
    
    	// redirect to download
    	header('Content-Description: File Transfer');
        header('Content-Disposition: attachment; filename="' . basename($target) . '"');
    	header('Content-Type: application/octet-stream');
        header('Content-Length: ' . filesize($target));
        readfile($target, true);
    ?>

    Plik cip4-folder-download-widget/cip4-folder-download-widget.php:

    <?php
    /**
     * Plugin Name: CIP4 Folder Download Widget
     * Description: A widget that list all files in a defined folder for download.
     * Version: 1.10
     * Author: CIP4 - Stefan Meissner
     * Author URI: http://community.cip4.org
     */
    
    add_action( 'widgets_init', 'cip4_folder_download_widget');
    add_shortcode( 'cip4download', 'shortcode_call' );
    
    function cip4_folder_download_widget() {
    	register_widget( 'CIP4FolderDownloadWidget' );
    
    	wp_register_style( 'cip4-folder-download-widget-css', plugins_url('cip4-folder-download-widget/cip4-folder-download-widget.css') );
    	wp_enqueue_style('cip4-folder-download-widget-css');
    }
    
    function shortcode_call($atts) {
    
    	extract(shortcode_atts(array(
        	'title' => 'No Title',
        	'folder' => 'wp-content/',
        	'is_desc' => false,
        	'is_tracked' => false,
      	), $atts));  
    
    	// create list
    	$result = createList($title, $folder, $is_desc, $is_tracked);
    
    	// return result
    	return $result;
    }
    
    function createList($title, $folder, $is_desc = false, $is_tracked = false) {
    
    	$result = '';
    
    	// create before widget area
    	$result .= $before_widget;
    
    	if(substr($folder, -1) != '/') {
    		$folder .= '/';
    	}
    
    	// show folder items
    	if( $folder ) {
    
    		$csvInfos = array();
    
    		// read .cip4-download-info file
    		$infoPath = $folder . '.cip4-download-info.csv';
    
    		if(file_exists($infoPath)) {
    			$infoFile = fopen($infoPath,"r");
    			while (($line = fgetcsv($infoFile)) !== FALSE) {
    				$csvInfos[$line[0]] = $line;
    			}
    			fclose($infoFile);
    		}
    
    		// read download folder
    		$items = array();
    
    		if ($handle = opendir($folder)) {
    
    			while (false !== ($file = readdir($handle))) {
    
    				if($file{0} != '.') { // starts NOT with .
    
    					// if necessary, add file
    					if ($csvInfos[$file] == '') {
    
    						// add new info item
    						$csvItem = array($file, 0);
    						$csvInfos[$file] = $csvItem;
    					} 
    
    					// get number downloads
    					$downloads = $csvInfos[$file][1];
    
    					// get file path
    					$filepath = $folder . $file;
    
    					$item = array();
    					$item['filename'] = $file;
    					$item['downloads'] = $downloads;
    					$item['bytes'] = number_format(filesize($filepath) / 1024 / 1024, 1, ".", "") . ' MB';
    					$item['modified'] = filemtime($filepath);
    					$item['link'] = plugins_url() . "/cip4-folder-download-widget/cip4-download.php?target=" . $filepath . "&info=" . $infoPath;
    					$item['extension'] = strtolower(pathinfo($filepath, PATHINFO_EXTENSION));
    					$items[] = $item;
    				}
    			}
    		}
    
    		closedir($handle);
    
    		// update .cip4-download-info file
    		$fp = fopen($infoPath, 'w');
    
    		foreach ($csvInfos as $row) {
    		    fputcsv($fp, $row);
    		}
    
    		fclose($fp);
    
    		// sort items
    		foreach ($items as $key => $row) {
    		    $filename[$key]  = $row['filename'];
    		}
    
    		if($is_desc) {
    			array_multisort($filename, SORT_DESC, $items);
    		} else {
    			array_multisort($filename, SORT_ASC, $items);
    		}
    
    		// output
    		$table = '';
    		$table .= '<table class="cip4-folder-download-widget">';
    
    		foreach($items as $item) {
    
    			// find icon extension
    			$icon = 'other.png';
    			$icons = scandir(dirname(__FILE__) . '/icons/');
    			$key = array_search($item['extension'] . '.png', $icons);
    
    			if($key !== FALSE) {
    				$icon = $icons[$key];
    			}
    
    			// time diff
    			$date_modified    = new  DateTime('@' . $item['modified']);
    			$date_now      = new DateTime();
    			$diff = $date_modified->diff($date_now); 
    
    			$y = $diff->y;
    			$m = $diff->m;
    			$d = $diff->d;
    			$h = $diff->h;
    			$i = $diff->i;
    			$s = $diff->s;
    
    			if($y == 0 && $m == 0 && $d > 0) {
    				$modified = $d . ' days ' . $h . ' hours';
    			} else if ($y == 0 && $m == 0 && $d == 0 && $h > 0) {
    				$modified = $h . ' hours';
    			} else if ($y == 0 && $m == 0 && $d == 0 && $h == 0 && $i > 0) {
    				$modified = $i . ' minutes';
    			} else if ($y == 0 && $m == 0 && $d == 0 && $h == 0 && $i == 0 && $s > 0) {
    				$modified = $s . ' sec.';
    			} else {
    				$modified = date_format($date_modified, 'Y-m-d');
    			}
    
    			// table output
    			$table .= '<tr>';
    
    			if($is_tracked) {
    				$table .= '<td class="cip4-fd-row-filename" style="padding-left: 10px"><a href="' . $item['link'] .'" onClick="_gaq.push([\'_trackEvent\', \'' . $title . '\', \'Download\', \'' . $item['filename'] . '\']);">' . $item['filename'] . '</a></td>';
    			} else {
    				$table .= '<td class="cip4-fd-row-filename" style="padding-left: 10px"><a href="' . $item['link'] .'">'. $item['filename'] . '</a></td>';
    			} 
    
    			$table .= '<td class="cip4-fd-row-downloads">' . $item['downloads'] . '</td>';
    			$table .= '<td class="cip4-fd-row-size">' . $item['bytes'] . '</td>';
    
    			$table .= '</tr>';
    		}
    
    		$table .= '</table>';
    
    		$result .=  $table;
    	}
    
    	// append after widget area
    	$result .=  $after_widget;
    
    	// return result
    	return $result;
    }
    
    class CIP4FolderDownloadWidget extends WP_Widget {
    
    	function CIP4FolderDownloadWidget() {
    		$widget_ops = array( 'classname' => 'example', 'description' => __('A widget that list all files in a defined folder for download. ', 'example') );
    
    		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'cip4-folder-download-widget' );
    
    		$this->WP_Widget( 'cip4-folder-download-widget', __('CIP4 Folder Download', 'example'), $widget_ops, $control_ops );
    	}
    
    	function widget( $args, $instance ) {
    
    		extract( $args );
    
    		//Our variables from the widget settings.
    		$title = apply_filters('widget_title', $instance['title'] );
    		$folder = $instance['folder'];
    		$is_desc = isset( $instance['is_desc'] ) ? $instance['is_desc'] : false; 
    
    		// create list
    		$result = createList($title, $folder, $is_desc);
    
    		// output
    		echo $result;
    	}
    
    	//Update the widget
    	function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    
    		// check for last slash in folder
    		$folder = $new_instance['folder'];
    
    		if(substr($folder, -1) != '/') {
    			$folder .= '/';
    		}
    
    		//Strip tags from title and name to remove HTML
    		$instance['title'] = strip_tags( $new_instance['title'] );
    		$instance['folder'] = strip_tags( $folder );
    		$instance['is_desc'] = $new_instance['is_desc']; 
    
    		return $instance;
    	}
    
    	function form( $instance ) {
    
    		//Set up some default widget settings.
    		$defaults = array( 'title' => __('MyFolder', 'example'), 'folder' => __('wp-content/uploads/', 'example'), 'is_desc' => false );
    		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
    
    		<!-- Show widgte ID -->
    		<p>
    			<label>
    			Widget ID: 
    
    			<?php
    
    			if ($this -> number == '__i__') {
    				echo '<b>[save widget first]</b>';
    			} else {
    				echo '<b>' . $this -> id . '</b>';
    			}
    			?>
    			</label>
    		</p>
    
    		<!-- Widget Title: Text Input. -->
    		<p>
    			<label>
    				Title:
    				<input id="<?php echo $this -> get_field_id('title'); ?>" type="text" name="<?php echo $this -> get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
    			</lable>
    		</p>
    
    		<!-- Folder Input -->
    		<p>
    			<label>
    				Folder:
    				<input id="<?php echo $this -> get_field_id('folder'); ?>" type="text" name="<?php echo $this -> get_field_name('folder'); ?>" value="<?php echo $instance['folder']; ?>" class="widefat" />
    			</label>
    		</p>
    
    		<!-- Sort -->
    		<p>
    			<label>
    				<input class="checkbox" type="checkbox" <?php checked(isset($instance['is_desc']), true); ?> id="<?php echo $this -> get_field_id('is_desc'); ?>" name="<?php echo $this -> get_field_name('is_desc'); ?>" />
        			<label for="<?php echo $this -> get_field_id('is_desc'); ?>"><?php _e('sort descendend', 'example'); ?></label>
    			</label>
    		</p>
    	<?php
    	}
    }
    ?>

    [cip4download title=”MyFolder” folder=”wp-content/uploads/” is_desc=”false”]

    Powinno wystarczyć 😛

    oryginalnie miałeś:

    [cip4download title=”MyFolder” folder=”wp-content/uploads/” is_desc=”true”]

    Czyli sortowanie Z-A. Poczytaj trochę o php i sortowaniu plików lub wyników MySQL 😉

    Thread Starter Paniki

    (@paniki)

    W sumie myślałem, że to to, ale byłem pewien, że nie działa 😉

    Wtyczka fajna, ale zajrzałem do takiej propozycji, którą mi ktoś wcześniej podał, ale nie sprawdziłem, jak ta http://wordpress.org/plugins/wp-filebase/

    Można było podać folder i wtyczka go sobie sama zsynchronizowała, do tego jest dość rozbudowana, więc się przerzuciłem na nią, bo może to być lepsza baza do rozbudowy 😉

    Tak więc dziękuję za pomoc i życzę mniej problemów do rozwiązania w WP dla blogowiczów, jak i więcej dla naprawiaczy 😀
    Temat można zamknąć 😉

    Jeśli Twój problem został rozwiązany, zaznacz kwadracik

    Oznacz ten temat jako rozwiązany

    i kliknij

    Wyślij

    🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Temat ‘Szukam wtyczki do "strony" download’ jest zamknięty na nowe odpowiedzi.