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/Skel/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_Skel_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.";
44 $this->declareParam('dirbase', '');
45 $this->declareParam('urlbase', '');
46 $this->declareParam('match', '');
50 /** Prepare the output for a single file of the list.
56 function list_file($file,$title,$url="") {
57 if (empty($url)) $url = $file;
60 /* get modification date / time */
61 $modified = date ("d M Y H:m:s", filemtime($file));
64 $icon = $globals->icons
->get_mime_icon($file);
66 /* calculate file size */
67 $size = filesize($file);
70 elseif ($size < 1000000)
71 $size = floor($size/1000)." kB";
73 $size = floor($size/1000000)." MB";
75 /* figure out description */
77 if (preg_match("/(i386\.changes|\.dsc)$/",$file))
79 elseif (preg_match("/\.tar\.gz$/",$file))
80 $desc = "source tarball";
81 elseif (preg_match("/_(all|i386)\.deb$/",$file,$matches))
84 $desc = "Debian package";
86 $desc .= " [platform independant]";
88 $desc .= " [$type specific]";
90 elseif (preg_match("/\.diff\.gz$/",$file))
91 $desc = "Debian diff";
92 else $desc = " ";
94 /* display the link */
96 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";
100 /** Show an instance of the FileList plugin.
107 $bbarel = $page->barrel
;
110 $instance_vals = array();
111 foreach($this->getParamNames() as $key) {
112 $instance_vals[$key] = isset($args[$key]) ?
$args[key
] : $this->getParamValue($key);
115 //print_r($instance_vals);
116 if (empty($instance_vals['dirbase'])) {
117 $instance_vals['dirbase'] = $bbarel->spool
->spoolPath($page->curpage
->props
['PID']);
120 // process parameters
122 $dir = $instance_vals['dirbase'];
123 if (is_dir($dir) && ($dh = opendir($dir))) {
125 '<table class="light">
127 <th>'.__("file").'</th>
128 <th>'.__("date").'</th>
129 <th>'.__("size").'</th>
130 <th>'.__("description").'</th>
133 /* get the matching files */
134 while (($fname = readdir($dh)) !== false
) {
135 if ( is_file("$dir/$fname")
136 && preg_match('/^'.$instance_vals['match'].'/',$fname) )
137 $filelist[] = $fname;
141 /* order and display */
142 if (is_array($filelist)) {
144 while(list ($key,$val) = each($filelist)) {
145 $output .= $this->list_file("$dir/$val",$val,$instance_vals['urlbase'].$val);
148 $output .= '<tr><td colspan="4"><i>'.__("no files").'</i></td></tr>';
150 $output .= '</table>';