3 * Copyright (C) 2003-2005 Polytechnique.org
4 * http://opensource.polytechnique.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 require_once 'Plugin/Filter.php';
22 require_once 'diogenes.icons.inc.php';
25 /** This plugin allows you to insert a directory listing with icons
26 * and modification date.
28 * To make use of this plugin, insert {FileList} in your page where
29 * the file list should appear.
31 class FileList
extends Diogenes_Plugin_Filter
{
33 var $name = "FileList";
35 /** Plugin description */
36 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.";
38 /** Plugin parameters */
39 var $params = array('dirbase' => "", 'urlbase' => "", 'match' => "");
42 /** Prepare the output for a single file of the list.
48 function list_file($file,$title,$url="") {
49 if (empty($url)) $url = $file;
52 /* get modification date / time */
53 $modified = date ("d M Y H:m:s", filemtime($file));
56 $icon = $globals->icons
->get_mime_icon($file);
58 /* calculate file size */
59 $size = filesize($file);
62 elseif ($size < 1000000)
63 $size = floor($size/1000)." kB";
65 $size = floor($size/1000000)." MB";
67 /* figure out description */
69 if (preg_match("/(i386\.changes|\.dsc)$/",$file))
71 elseif (preg_match("/\.tar\.gz$/",$file))
72 $desc = "source tarball";
73 elseif (preg_match("/_(all|i386)\.deb$/",$file,$matches))
76 $desc = "Debian package";
78 $desc .= " [platform independant]";
80 $desc .= " [$type specific]";
82 elseif (preg_match("/\.diff\.gz$/",$file))
83 $desc = "Debian diff";
84 else $desc = " ";
86 /* display the link */
88 return "<tr><td><img class=\"fileicon\" src=\"$icon\" /><a href=\"$url\">$title</a></td><td><small>$modified</small></td><td>$size</td><td>$desc</td></tr>\n";
92 /** Show an instance of the FileList plugin.
99 $bbarel = $page->barrel
;
103 foreach($this->params
as $key => $val) {
104 $params[$key] = isset($args[$key]) ?
$args[$key] : $this->params
[$key];
108 if (empty($params['dirbase'])) {
109 $params['dirbase'] = $bbarel->spool
->spoolPath($page->curpage
->props
['PID']);
112 // process parameters
114 $dir = $params['dirbase'];
115 if (is_dir($dir) && ($dh = opendir($dir))) {
117 '<table class="light">
119 <th>'.__("file").'</th>
120 <th>'.__("date").'</th>
121 <th>'.__("size").'</th>
122 <th>'.__("description").'</th>
125 /* get the matching files */
126 while (($fname = readdir($dh)) !== false
) {
127 if ( is_file("$dir/$fname")
128 && preg_match('/^'.$params['match'].'/',$fname) )
129 $filelist[] = $fname;
133 /* order and display */
134 if (is_array($filelist)) {
136 while(list ($key,$val) = each($filelist)) {
137 $output .= $this->list_file("$dir/$val",$val,$params['urlbase'].$val);
140 $output .= '<tr><td colspan="4"><i>'.__("no files").'</i></td></tr>';
142 $output .= '</table>';