www-apps/pmwiki - cookbook - FileList - init
[anomen-overlay.git] / www-apps / pmwiki / cookbook / FileList / filelist.php
blobafc2d4f13c08dc9befe123a914d4bb162ed6cc00
1 <?php if (!defined('PmWiki')) exit();
2 /*
3 filelist.php
4 Copyright 2007 Hans Bracker
5 Copyright 2004-2007 Patrick Michaud
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
8 by the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Script to create alternative filelists with markup (:filelist:)
13 $RecipeInfo['FileList']['Version'] = '2007-09-01a';
15 SDV($FileListTimeFmt, '%d %b %Y');
16 #alternatively use pmwiki's time format:
17 #$FileListTimeFmt = $TimeFmt;
19 # load uploads.php now so alt filelist will work
20 include_once("$FarmD/scripts/upload.php");
22 # add (:filelist:) as another kind of attachlist
23 Markup('filelist', '<block',
24 '/\\(:filelist\\s*(.*?):\\)/ei',
25 "Keep('<table class=\"filelist\">'.FmtUploadList2('$pagename',PSS('$1')).'</table>')");
27 # file list generation & formatting
28 function FmtUploadList2($pagename, $args) {
29 global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite,
30 $FileListTimeFmt, $EnableDirectDownload, $HTMLStylesFmt, $FarmPubDirUrl;
32 $HTMLStylesFmt['filelist'] = "
33 table.filelist { padding:0; margin:0; border-spacing:0; }
34 table.filelist td { padding:3px 0 0 0; margin:0; }
35 .filelist a { text-decoration:underline; }
36 .dotted { background:url($FarmPubDirUrl/images/dot3.png) repeat-x bottom; }
37 .nodots { background:#feffff; }
40 $opt = ParseArgs($args);
41 if (@$opt[''][0]) $pagename = MakePageName($pagename, $opt[''][0]);
42 if (@$opt['ext'])
43 $matchext = '/\\.('
44 . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY))
45 . ')$/i';
47 $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename);
48 $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1)
49 ? "$UploadUrlFmt$UploadPrefixFmt/"
50 : "\$PageUrl?action=download&amp;upname=",
51 $pagename);
53 $dirp = @opendir($uploaddir);
54 if (!$dirp) return '';
55 $filelist = array();
56 while (($file=readdir($dirp)) !== false) {
57 if ($file{0} == '.') continue;
58 if (@$matchext && !preg_match(@$matchext, $file)) continue;
59 $filelist[$file] = $file;
61 closedir($dirp);
62 $out = array();
63 #asort($filelist);
64 $overwrite = '';
65 foreach($filelist as $file=>$x) {
66 $name = PUE("$uploadurl$file");
67 $stat = stat("$uploaddir/$file");
69 if ($EnableUploadOverwrite)
70 $overwrite = FmtPageName("<a class='createlink'
71 href='\$PageUrl?action=upload&amp;upname=$file'>&nbsp;&Delta;</a>",
72 $pagename);
74 $out[] = "<tr><td class='dotted'> <a href='$name'>$file</a>$overwrite &nbsp;&nbsp;</td>"
75 ."<td class='dotted' align=right><span class='nodots'>".number_format($stat['size']/1024). "Kb</span></td>"
76 ."<td>&nbsp;&nbsp;&nbsp;".strftime($FileListTimeFmt, $stat['mtime'])."</td>"
77 ."<tr>";
80 return implode("\n",$out);