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