FileList.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2005 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     /* get modification date / time */
00052     $modified = date ("d M Y H:m:s", filemtime($file));
00053   
00054     /* get file icon */
00055     $icon = $globals->icons->get_mime_icon($file);
00056     
00057     /* calculate file size */
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     /* figure out description */
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 = "&nbsp;";
00084     
00085     /* display the link */
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     // process arguments
00101     $params = array();
00102     foreach($this->params as $key => $val) {
00103       $params[$key] = isset($args[$key]) ? $args[$key] : $this->params[$key];
00104     }
00105     
00106    //print_r($params);
00107     if (empty($params['dirbase'])) {
00108       $params['dirbase'] = $bbarel->spool->spoolPath($page->curpage->props['PID']);
00109     }
00110 
00111     // process parameters 
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       /* get the matching files */
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       /* order and display */
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 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1