'.attachlistsort('$pagename',PSS('$1')).'')"); #DIFFERENT from filelist.php This function call and the below function declaration were both copied from attachlistsort.php function attachlistsort($pagename, $args) { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $TimeFmt, $EnableDirectDownload; $sortby = array(); $opt = ParseArgs($args); @$sortby = preg_split('/\\W+/', $opt['sort'], -1, PREG_SPLIT_NO_EMPTY); if (@$opt[''][0]) $pagename = MakePageName($pagename, $opt[''][0]); if (@$opt['ext']) $matchext = '/\\.(' . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) . ')$/i'; $filelist = array(); $typelist = array(); $namelist = array(); $sizelist = array(); $datelist = array(); $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "$UploadUrlFmt$UploadPrefixFmt/" : "\$PageUrl?action=download&upname=", $pagename); $dirp = @opendir($uploaddir); if (!$dirp) return ''; while (($file=readdir($dirp)) !== false) { if ($file{0} == '.') continue; if (@$matchext && !preg_match(@$matchext, $file)) continue; $stat = stat("$uploaddir/$file"); $namelist[$file] = $file; preg_match('/[^.]+$/', $file, $matches); $typelist[$file] = $matches[0]; $sizelist[$file] = $stat['size']; $datelist[$file] = $stat['mtime']; } closedir($dirp); $A = SORT_ASC; $D = SORT_DESC; foreach ($sortby as $key => $s) { switch ($s) { case "descendingtime": case "descendingdate": $sortkey [] = 'date'; $sortlist['date'] = $datelist; $sorthow ['date'] = $D; break; case "ascendingtime": case "ascendingdate": case "time": case "date": $sortkey [] = 'date'; $sortlist['date'] = $datelist; $sorthow ['date'] = $A; break; case "descendingsize": $sortkey [] = 'size'; $sortlist['size'] = $sizelist; $sorthow ['size'] = $D; break; case "ascendingsize": case "size": $sortkey [] = 'size'; $sortlist['size'] = $sizelist; $sorthow ['size'] = $A; break; case "descendingtype": case "descendingext": $sortkey [] = 'type'; $sortlist['type'] = $typelist; $sorthow ['type'] = $D; break; case "ascendingtype": case "type": case "ascendingext": case "ext": $sortkey [] = 'type'; $sortlist['type'] = $typelist; $sorthow ['type'] = $A; break; case "descendingname": $sortkey [] = 'name'; $sortlist['name'] = array_map('strtolower', $namelist); $sorthow ['name'] = $D; break; case "ascendingname": case "name": default: $sortkey [] = 'name'; $sortlist['name'] = array_map('strtolower', $namelist); $sorthow ['name'] = $A; break; } } if (!isset($sortlist['name'])) { $sortkey[] = 'name'; $sortlist['name'] = array_map('strtolower', $namelist); $sorthow['name'] = $A; } if (!isset($sortlist['type'])) { $sortkey[] = 'type'; $sortlist['type'] = $typelist; $sorthow['type'] = $A; } if (!isset($sortlist['size'])) { $sortkey[] = 'size'; $sortlist['size'] = $sizelist; $sorthow['size'] = $A; } if (!isset($sortlist['date'])) { $sortkey[] = 'date'; $sortlist['date'] = $datelist; $sorthow['date'] = $A; } #echo "Sorted by:"; foreach ($sortkey as $key => $v ) { echo " $key='$v'"; }# echo " TimeFormat='$TimeFmt'"; array_multisort($sortlist[$sortkey[0]], $sorthow[$sortkey[0]], $sortlist[$sortkey[1]], $sorthow[$sortkey[1]], $sortlist[$sortkey[2]], $sorthow[$sortkey[2]], $sortlist[$sortkey[3]], $sorthow[$sortkey[3]]); $filelist = $sortlist[$sortkey[0]]; $overwrite = ''; /* foreach ($filelist as $key => $s) { #DIFFERENT from AttachListSort.php. This presentational section is normally NOT commented out. $file = $namelist[$key]; $name = PUE("$uploadurl$file"); if ($EnableUploadOverwrite) $overwrite = FmtPageName(" Δ", $pagename); $t = '%B %d, %Y, at %I:%M:%S %p'; $out[] = "
  • $file$overwrite ... ". number_format($sizelist[$key]) . " bytes ... " . strftime($t, $datelist[$key]) . "
  • "; #strftime($TimeFmt, $datelist[$key]) . ""; } */ return $filelist; #DIFFERENT from AttachListSort.php Normally, a version of $out is returned, not the pure, sorted $filelist array. } # add (:filelist:) as another kind of attachlist Markup('filelist', ''.FmtUploadList2('$pagename',PSS('$1')).'')"); # file list generation & formatting function FmtUploadList2($pagename, $args) { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $EnableUploadOverwrite, $FileListTimeFmt, $EnableDirectDownload, $HTMLStylesFmt, $FarmPubDirUrl; $HTMLStylesFmt['filelist'] = " table.filelist { padding:0; margin:0; border-spacing:0; } table.filelist td { padding:3px 0 0 0; margin:0; } .filelist a { text-decoration:underline; } .dotted { background:url($FarmPubDirUrl/images/dot3.png) repeat-x bottom; } .nodots { background:#feffff; } "; #$opt = ParseArgs($args); #DIFFERENT from filelist.php all these lines are normally used, and not commented out. But here the sorting function does this work for us, so we don't need them. #if (@$opt[''][0]) $pagename = MakePageName($pagename, $opt[''][0]); #if (@$opt['ext']) # $matchext = '/\\.(' # . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) # . ')$/i'; $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "$UploadUrlFmt$UploadPrefixFmt/" : "\$PageUrl?action=download&upname=", $pagename); #$dirp = @opendir($uploaddir); #DIFFERENT from filelist.php all these lines are normally used, and not commented out. But here the sorting function does this work for us, so we don't need them. #if (!$dirp) return ''; #$filelist = array(); #while (($file=readdir($dirp)) !== false) { # if ($file{0} == '.') continue; # if (@$matchext && !preg_match(@$matchext, $file)) continue; # $filelist[$file] = $file; #} #closedir($dirp); $out = array(); #asort($filelist); $overwrite = ''; $filelist = attachlistsort($pagename, $args); # DIFFERENT from filelist.php this function call is special to filelist_sortable.php foreach($filelist as $file=>$x) { $name = PUE("$uploadurl$file"); $stat = stat("$uploaddir/$file"); if ($EnableUploadOverwrite) $overwrite = FmtPageName(" Δ", $pagename); $out[] = " $file$overwrite   " ."".number_format($stat['size']/1024). "Kb" ."   ".strftime($FileListTimeFmt, $stat['mtime'])."" .""; } return implode("\n",$out); }