00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once 'Plugin/Filter.php';
00022
00023
00030 class FileList extends Diogenes_Plugin_Filter {
00032 var $name = "FileList";
00033
00035 var $description = "This plugin allows you to insert a directory listing with icons and modification date. To make use of this plugin, insert <b>{FileList}</b> in your page where the file list should appear.";
00036
00038 var $params = array('dirbase' => "", 'urlbase' => "", 'match' => "");
00039
00040
00047 function list_file($file,$title,$url="") {
00048 if (empty($url)) $url = $file;
00049 global $globals;
00050
00051
00052 $modified = date ("d M Y H:m:s", filemtime($file));
00053
00054
00055 $icon = $globals->icons->get_mime_icon($file);
00056
00057
00058 $size = filesize($file);
00059 if ($size < 1000)
00060 $size = "$size B";
00061 elseif ($size < 1000000)
00062 $size = floor($size/1000)." kB";
00063 else
00064 $size = floor($size/1000000)." MB";
00065
00066
00067 $show = 1;
00068 if (preg_match("/(i386\.changes|\.dsc)$/",$file))
00069 $show = 0;
00070 elseif (preg_match("/\.tar\.gz$/",$file))
00071 $desc = "source tarball";
00072 elseif (preg_match("/_(all|i386)\.deb$/",$file,$matches))
00073 {
00074 $type = $matches[1];
00075 $desc = "Debian package";
00076 if ($type == "all")
00077 $desc .= " [platform independant]";
00078 else
00079 $desc .= " [$type specific]";
00080 }
00081 elseif (preg_match("/\.diff\.gz$/",$file))
00082 $desc = "Debian diff";
00083 else $desc = " ";
00084
00085
00086 if ($show)
00087 return "<tr><td><img alt=\"file\" class=\"fileicon\" src=\"$icon\" /><a href=\"$url\">$title</a></td><td><small>$modified</small></td><td>$size</td><td>$desc</td></tr>\n";
00088 }
00089
00090
00095 function show($args)
00096 {
00097 global $page;
00098 $bbarel = $page->barrel;
00099
00100
00101 $params = array();
00102 foreach($this->params as $key => $val) {
00103 $params[$key] = isset($args[$key]) ? $args[$key] : $this->params[$key];
00104 }
00105
00106
00107 if (empty($params['dirbase'])) {
00108 $params['dirbase'] = $bbarel->spool->spoolPath($page->curpage->props['PID']);
00109 }
00110
00111
00112 $output = '';
00113 $dir = $params['dirbase'];
00114 if (is_dir($dir) && ($dh = opendir($dir))) {
00115 $output .=
00116 '<table class="light">
00117 <tr>
00118 <th>'.__("file").'</th>
00119 <th>'.__("date").'</th>
00120 <th>'.__("size").'</th>
00121 <th>'.__("description").'</th>
00122 </tr>';
00123
00124
00125 while (($fname = readdir($dh)) !== false) {
00126 if ( is_file("$dir/$fname")
00127 && preg_match('/^'.$params['match'].'/',$fname) )
00128 $filelist[] = $fname;
00129 }
00130 closedir($dh);
00131
00132
00133 if (is_array($filelist)) {
00134 rsort($filelist);
00135 while(list ($key,$val) = each($filelist)) {
00136 $output .= $this->list_file("$dir/$val",$val,$params['urlbase'].$val);
00137 }
00138 } else {
00139 $output .= '<tr><td colspan="4"><i>'.__("no files").'</i></td></tr>';
00140 }
00141 $output .= '</table>';
00142 }
00143 return $output;
00144 }
00145 }
00146
00147 ?>