List_Dir - script of (von) Ash Young

Gast

QuoteMuss das im lister () gemacht werden?

konnte ich dir ohne diese Funktion nicht sagen. Komm aber erst morgen dazu, mir das anzuschauen, war den ganzen Tag unterwegs heute und bin platt

maweb

Deutsch            <-- Sags doch gleich 8-)
Möchte jetzt nicht das ganze Modul ändern, da ich mehrere Droplets dieser Art verwende. Möchte nur in diesem bestimmten Verzeichnis nach Namen sortieren, in den anderen Verzeichnissen ist die Sortierung nach Datumsänderung gut (Wahrscheinlich nachfolgendes ändern: $_GET['sort'] ="date <---name";[/b]).
Kann ich es im 1. Code-Droplet (s. erster Beitrag)oder 2. Code in Website nicht einfach angeben? Muss das im lister () gemacht werden?

Nachfolgend Lister -> include.php
Quote<?
if (!function_exists("lister")) {
function lister( $path, $thumb_width=200) {
   global $wb;
   $temp = explode(",",$wb->page['page_trail']);
   for($i=0, $path_add=""; $i < count($temp); $i++, $path_add .= "../");

   ##$path = MEDIA_DIRECTORY."/".$path; ##WB_PATH.MEDIA_DIRECTORY."/".$path;
   
   $icon_url = WB_URL."/modules/lister/icons/";

/* Kommentar: zeigt die Eintr�ge beim Start so an, dass das neuste zuerst steht */

if (!isset($_GET['sort'])) {
   $_GET['sort'] ="date";
   $_GET['order']="desc";
}
/* Kommentar Ende */
   
/*
Directory Listing Script - Version 2
====================================
Script Author: Ash Young <ash@evoluted.net>. www.evoluted.net
Layout: Manny <manny@tenka.co.uk>. www.tenka.co.uk (im Original - hier nicht mehr!)

REQUIREMENTS
============
This script requires PHP and GD2 if you wish to use the
thumbnail functionality.

CONFIGURATION
=============
Edit the variables in this section to make the script work as
you require.

Start Directory - To list the files contained within the current
directory enter '.', otherwise enter the path to the directory
you wish to list. The path must be relative to the current
directory.
*/
$startdir = substr($path_add, 0, -1).MEDIA_DIRECTORY."/".$path;

/*
Show Thumbnails? - Set to true if you wish to use the
scripts auto-thumbnail generation capabilities.
This requires that GD2 is installed.
*/
$showthumbnails = true;

/*
Show Directories - Do you want to make subdirectories available?
If not set this to false
*/
$showdirs = true;

/*
Force downloads - Do you want to force people to download the files
rather than viewing them in their browser?
*/
$forcedownloads = false;

/*
Hide Files - If you wish to hide certain files or directories
then enter their details here. The values entered are matched
against the file/directory names. If any part of the name
matches what is entered below then it is now shown.
*/
$hide = array(
            'dlf',
            'Thumbs',
            '.htaccess',
            '.php',
            '.htpasswd',
            '.verstecken',
            '.js',
            '.DS_Store'
         );
         
/*
Show index files - if an index file is found in a directory
to you want to display that rather than the listing output
from this script?
*/         
$displayindex = false;

/*
Allow uploads? - If enabled users will be able to upload
files to any viewable directory. You should really only enable
this if the area this script is in is already password protected.
*/
$allowuploads = false;

/*
Overwrite files - If a user uploads a file with the same
name as an existing file do you want the existing file
to be overwritten?
*/
$overwrite = false;

/*
Index files - The follow array contains all the index files
that will be used if $displayindex (above) is set to true.
Feel free to add, delete or alter these
*/

$indexfiles = array (
            'index.html',
            'index.htm',
            'default.htm',
            'default.html'
         );
         
/*
File Icons - If you want to add your own special file icons use
this section below. Each entry relates to the extension of the
given file, in the form <extension> => <filename>.
These files must be located within the dlf directory.
*/
$filetypes = array (
            'png' => 'jpg.gif',
            'jpeg' => 'jpg.gif',
            'bmp' => 'jpg.gif',
            'jpg' => 'jpg.gif',
            'gif' => 'gif.gif',
            'zip' => 'archive.png',
            'rar' => 'archive.png',
            'exe' => 'exe.gif',
            'setup' => 'setup.gif',
            'txt' => 'text.png',
            'htm' => 'html.gif',
            'html' => 'html.gif',
            'url' => 'html.gif',
            'fla' => 'fla.gif',
            'swf' => 'swf.gif',
            'xls' => 'xls.gif',
            'doc' => 'doc.gif',
            'sig' => 'sig.gif',
            'fh10' => 'fh10.gif',
            'pdf' => 'pdf.gif',
            'psd' => 'psd.gif',
            'rm' => 'real.gif',
            'mpg' => 'video.gif',
            'mpeg' => 'video.gif',
            'mov' => 'video2.gif',
            'avi' => 'video.gif',
            'eps' => 'eps.gif',
            'gz' => 'archive.png',
            'asc' => 'sig.gif',
         );

/*
That's it! You are now ready to upload this script to the server.

Only edit what is below this line if you are sure that you know what you
are doing!
*/
error_reporting(0);
if(!function_exists('imagecreatetruecolor')) $showthumbnails = false;
$leadon = $startdir;
if($leadon=='.') $leadon = '';
if((substr($leadon, -1, 1)!='/') && $leadon!='') $leadon = $leadon . '/';
$startdir = $leadon;

if($_GET['dir']) {
   //check this is okay.
   
   if(substr($_GET['dir'], -1, 1)!='/') {
      $_GET['dir'] = $_GET['dir'] . '/';
   }
   
   $dirok = true;
   $dirnames = explode('/', $_GET['dir']);
   for($di=0; $di<count($dirnames); $di++) {
      
      if($di<(sizeof($dirnames)-2)) {
         $dotdotdir = $dotdotdir . $dirnames[$di] . '/';
      }
      
      if($dirnames[$di] == '..') {
         $dirok = false;
      }
   }
   
   if(substr($_GET['dir'], 0, 1)=='/') {
      $dirok = false;
   }
   
   if($dirok) {
       $leadon = $leadon . $_GET['dir'];
   }
}

if($_GET['download'] && $forcedownloads) {
   $file = str_replace('/', '', $_GET['download']);
   $file = str_replace('..', '', $file);

   if(file_exists($leadon . $file)) {
      header("Content-type: application/x-download");
      header("Content-Length: ".filesize($leadon . $file));
      header('Content-Disposition: attachment; filename="'.$file.'"');
      readfile($leadon . $file);
      die();
   }
}

if($allowuploads && $_FILES['file']) {
   $upload = true;
   if(!$overwrite) {
      if(file_exists($leadon.$_FILES['file']['name'])) {
         $upload = false;
      }
   }
   
   if($upload) {
      move_uploaded_file($_FILES['file']['tmp_name'], $leadon . $_FILES['file']['name']);
   }
}

$opendir = $leadon;
if(!$leadon) $opendir = '.';
if(!file_exists($opendir)) {
   $opendir = '.';
   $leadon = $startdir;
}

clearstatcache();
if ($handle = opendir($opendir)) {
   while (false !== ($file = readdir($handle))) {
      //first see if this file is required in the listing
      if ($file == "." || $file == "..")  continue;
      $discard = false;
      for($hi=0;$hi<sizeof($hide);$hi++) {
         if(strpos($file, $hide[$hi])!==false) {
            $discard = true;
         }
      }
      
      if($discard) continue;
      if (@filetype($leadon.$file) == "dir") {
         if(!$showdirs) continue;
      
         $n++;
         if($_GET['sort']=="date") {
            $key = @filemtime($leadon.$file) . ".$n";
         }
         else {
            $key = $n;
         }
         $dirs[$key] = $file . "/";
      }
      else {
         $n++;
         if($_GET['sort']=="date") {
            $key = @filemtime($leadon.$file) . ".$n";
         }
         elseif($_GET['sort']=="size") {
            $key = @filesize($leadon.$file) . ".$n";
         }
         else {
            $key = $n;
         }
         $files[$key] = $file;
         
         if($displayindex) {
            if(in_array(strtolower($file), $indexfiles)) {
               header("Location: $file");
               die();
            }
         }
      }
   }
   closedir($handle);
}

//sort our files
if($_GET['sort']=="date") {
   @ksort($dirs, SORT_NUMERIC);
   @ksort($files, SORT_NUMERIC);
}
elseif($_GET['sort']=="size") {
   @natcasesort($dirs);
   @ksort($files, SORT_NUMERIC);
}
else {
   @natcasesort($dirs);
   @natcasesort($files);
}

//order correctly
if($_GET['order']=="desc" && $_GET['sort']!="size") {$dirs = @array_reverse($dirs);}
if($_GET['order']=="desc") {$files = @array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);


?>

<script type="text/javascript" src="<?php echo WB_URL."/modules/lister/"; ?>js/overlib.js" ></script>
<table border="0" width="98%" style="font-family:Verdana; font-size:8pt;" cellspacing="3" cellpadding="0" align="center">
    <tr>
        <td style="border-width:1px; border-color:rgb(204,204,204); border-bottom-style:none;" colspan="3">
  <a href="<?php echo $_SERVER['PHP_SELF'];?>">home</a>
  <?
    $breadcrumbs = explode('/', str_replace($startdir, "", $leadon) );
     if(($bsize = sizeof($breadcrumbs))>0) {
        $sofar = '';
        for($bi=0;$bi<($bsize-1);$bi++) {
         $sofar = $sofar . $breadcrumbs[$bi] . '/';
         echo ' &gt; <a href="'.$_SERVER['PHP_SELF'].'?dir='.($sofar).'">'.$breadcrumbs[$bi].'</a>';
      }
     }
 
   $baseurl = $_SERVER['PHP_SELF'] . '?dir='.$_GET['dir'] . '&amp;';
   $fileurl = 'sort=name&amp;order=asc';
   $sizeurl = 'sort=size&amp;order=asc';
   $dateurl = 'sort=date&amp;order=asc';
   
   switch ($_GET['sort']) {
      case 'name':
         if($_GET['order']=='asc') $fileurl = 'sort=name&amp;order=desc';
         break;
      case 'size':
         if($_GET['order']=='asc') $sizeurl = 'sort=size&amp;order=desc';
         break;
         
      case 'date':
         if($_GET['order']=='asc') $dateurl = 'sort=date&amp;order=desc';
         break; 
      default:
         $fileurl = 'sort=name&amp;order=desc';
         break;
   }
  ?>
  <br />
  <br /><i><font color="#990000">Sortieren nach </font><a href="<?php echo $baseurl . $fileurl; ?>"><font color="#990000">Dateiname</font></a><font color="#990000">/</font><a href="<?php echo $baseurl . $sizeurl; ?>"><font color="#990000">Dateigröße</font></a><font color="#990000">/</font><a href="<?php echo $baseurl . $dateurl; ?>"><font color="#990000">Änderungsdatum</font></a><font color="#990000"> (aufsteigend/absteigend entsprechend oft klicken)<span style="font-size:4pt;"><br>&nbsp;</span></font></i></td>
    </tr>
    <tr class="iframe_tabellenkopf">
        <td height="22" bgcolor="whitesmoke"><p align="left"><a href="<?php echo $baseurl.$fileurl; ?>"><font color="black">Dateiname</font></a><font color="black">
            </font><a href="<?php echo $baseurl.$fileurl; ?>"><font color="black"><img src='<?php echo $icon_url."ARROWS.gif"; ?>' absbottom" width="16" height="11" border="0" align="absbottom"></font></a></td>
        <td width="120" height="22" bgcolor="whitesmoke"><p align="right"><a href="<?php echo $baseurl.$sizeurl; ?>"><font color="black">Dateigröße </font></a><font color="black">&nbsp;
            </font><a href="<?php echo $baseurl.$sizeurl; ?>"><font color="black"><img src='<?php echo $icon_url."ARROWS.gif"; ?>' absbottom" width="16" height="11" border="0" align="absbottom"></font></a></p></td>
        <td width="220" height="22" bgcolor="whitesmoke"><p align="right"><a href="<?php echo $baseurl.$dateurl; ?>"><font color="black">Änderungsdatum </font></a><font color="black">&nbsp;</font><a href="<?php echo $baseurl.$dateurl; ?>"><font color="black"><img src='<?php echo $icon_url."ARROWS.gif"; ?>' absbottom" width="16" height="11" border="0" align="absbottom"></font></a></p></td>
    </tr>
    <tr>
        <td colspan="3">
            <p align="left"><?
   $class = 'b';
   if($dirok) {
   ?><a href="<?=$_SERVER['PHP_SELF'].'?dir='.($dotdotdir);?>" class="<?=$class;?>"><img src="<?php echo $icon_url; ?>dirup.png" border="0" alt="Ordner" /><strong> ..</strong></a><br>
   <?
      if($class=='b') $class='w';
      else $class = 'b';
   }
   $arsize = sizeof($dirs);
   for($i=0;$i<$arsize;$i++) {
   ?>
<br />
<img src="<?php echo $icon_url."folder.png"; ?>" alt='' /> <a href="<? echo $_SERVER['PHP_SELF'].'?dir='.str_replace($startdir, "", $leadon.$dirs[$i]); ?>" class="<?=$class;?>"><strong><?=$dirs[$i];?></strong></a>
   <?php
      $class = ($class=='b') ? 'w' : 'b';
   }
   
   $arsize = sizeof($files);
   for($i=0;$i<$arsize;$i++) {
      $icon = 'unknown.png';
      $ext = strtolower(substr($files[$i], strrpos($files[$i], '.')+1));
      $supportedimages = array('gif', 'png', 'jpeg', 'jpg', 'bmp');
      
      if($filetypes[$ext]) {
         $icon = $filetypes[$ext];
      }
      
      $filename = $files[$i];
      if(strlen($filename)>43) {
         $filename = substr($files[$i], 0, 40) . '...';
      }
      
      $fileurl = $leadon . $files[$i];
      if($forcedownloads) {
         $fileurl = $_SESSION['PHP_SELF'] . '?dir=' . ($leadon) . '&download=' . ($files[$i]);
      }
      if (in_array($ext, $supportedimages) ) {
         $overlib_code = "onmouseover=\"overlib('<img src=\'".($leadon.$files[$i])."\' width=\'".$thumb_width."px\' >',VAUTO, WIDTH)\" onmouseout='nd();'";
      } else {
         $overlib_code = "";
      }
   ?>
        </td>
    </tr>
    <tr>
        <td bgcolor="whitesmoke">
            <p align="left"><img src="<?php echo $icon_url.$icon;?>" > <a href="<?=$fileurl;?>" class="<?=$class;?>" target="_blank" title="<?=$files[$i]?>" <?php echo $overlib_code; ?>><?php echo $filename;?></a></td>
        <td bgcolor="whitesmoke">
         <p align="right"><?=round(filesize($leadon.$files[$i])/1024);?> KB</td>
        <td bgcolor="whitesmoke">
         <p align="right"><?=date ("M d Y h:i:s A", filemtime($leadon.$files[$i]));?></td>
    </tr>
    <?php } ?>
    <tr>
        <td colspan="3">
        <p align="right"><br /><font color="#E8E8E8"><i>Directory Listing Script ©2005 Ash Young</i></font></td>
    </tr>
</table>
<?php
}
}
?>

Danke für Deine/Eure Hilfe :wink:

Gast

QuoteMein Englisch ist etwas eingerostet hoffe es kam verständlich herüber.

dann sprech doch deutsch   :wink: :-)

wir müßten mal schauen, wie die Dateien da eingelesen werden, d.h. bräuchten diese Funktion lister()

maweb

@hillschmidt: Ich habe den Code 2.) in der Webseite wie nachfolgend abgeändert
Quote
[[telefon_dir?dir=webseiten/telefonverzeichnis1/&width=100&sort=name&order=asc]]
Hat leider nicht funktioniert! :|

@jacobi22: The Code goes to a Directory in the Media of a websitebakerpage. In the Directory are mostly *.pdf-files.
On the Website Outputs the pdf files but always on the last date and not sorted by Name.
On the Website it gives Buttons which i can sort by Name but i will here the Setting chance to get first the sort by name.
Mein Englisch ist etwas eingerostet hoffe es kam verständlich herüber.
1.Code = yes think (lister).

Have you/anywho a idea?

Gast

where do you have the datas for this output - in database or in a extern file like a txt-file?

if Database, its the best method, if you use different MySQL-Order's for a sortable output

$query = 'SELECT * FROM `'.TABLE_PREFIX.'deine_tabelle` '
            .'ORDER BY `'.$orderby.'` '.$ordering.' '
            .' ';


$orderby is the name of the field
$ordering is the order-direction (ASC or DESC)

if you dont need a free sortable list (means: only a sorted list for one output), its enough, to use the field name and direction as hardcoded text like
$query = 'SELECT * FROM `'.TABLE_PREFIX.'deine_tabelle` '
            .'ORDER BY `name` ASC '
            .' ';


if you read a text-file, you need other methods like sort, asort, natsort etc

if you need more help, we need the code to read the data's (i think, the function "lister"). your posted code in the top is only the output

hillschmidt

Hast Du mal mit &sort=name&order=asc probiert?

maweb

I need help with the sorting function (Kann ich die Sortierfunktion ändern, und wenn ja wie?).
The Droplet "List_Dir" is installed and works.
My Question is, can i change the sorting?
I have 3 column (1. name | 2. size | 3. date change). It first always to point 3.date change.
Can i change the sorting first to the column 1. name?  :?

Following the code (Anbei der Code mit der Einbindung):

1. Code-Droplet:
Quoteif (!isset($dir)) $dir="";
if (!isset($width)) $width=200;
if (function_exists("lister")) {
   ob_start();
   lister($dir, $width);
   $c = ob_get_contents();
   ob_end_clean();
   return $c;
} else {
   return "not installed ye";
}


2. Code in Website:
Quote[[telefon_dir?dir=webseiten/telefonverzeichnis1/&width=100&sort=asc]]