|
Cookbook /
AttachListSortSummary: Sort an attachlist
Version: 1.1
Prerequisites: none
Status: Working
Maintainer: JB
Categories: Uploads
Downloads: AttachListSort.phpΔ
Questions answered by this recipe
DescriptionThis recipe allows you to sort the attachlist via name and/or date/time and/or size and/or file type. Syntax is easy: (:attachlist sort=name:) (:attachlist sort=type:) (:attachlist sort=date:) (:attachlist sort=size:) (:attachlist sort=time:) - sorting by time same as sorting by date (:attachlist sort=ext:) - same as "type" (:attachlist sort=ascendingname:) - ascending is default direction (:attachlist sort=ascendingtype:) (:attachlist sort=ascendingdate:) (:attachlist sort=ascendingsize:) (:attachlist sort=ascendingtime:) (:attachlist sort=ascendingext:) (:attachlist sort=descendingname:) (:attachlist sort=descendingtype:) (:attachlist sort=descendingdate:) (:attachlist sort=descendingsize:) (:attachlist sort=descendingtime:) (:attachlist sort=descendingext:) (:attachlist sort=date ext=jpg:) sort just the jpg files Multi-SortThe left most parameter value has precedence when using sort. (:attachlist sort="date size":) - Sort list by dates which are sorted by size (:attachlist sort="type,size":) - Sort list by types which are sorted by size (:attachlist sort="name type date size":) - default sort Case-insensitive name-sortingBy default, the sort method by name IS SENSITIVE to case. That means all filenames where the first letter is capitalized will come before all filenames with a lowercase first letter. To have the files be sorted alphabetically irrelevant of case, go into the given AttachListSort.php and replace all instances of $namelist with array_map('strtolower', $namelist) . The filename's capitalization will still be shown in the attachment list - it just won't be used for sorting purposes if you make this change. InstallingCopy AttachListSort.phpΔ to your cookbook directory In your config.php enter: include_once("cookbook/AttachListSort.php");
or in your farmconfig.php enter: include_once(" $FarmD/cookbook/AttachListSort.php");
NotesRelease NotesThis program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation http://www.fsf.org either version 2 of the License, or (at your option) any later version. Copyright 2007 by GNUZoo (guru@gnuzoo.org) Please donate to the author at url: http://gnuzoo.org/GNUZooPayPal
Comments
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\apache group\Apache\htdocs\PMwiki\cookbook\AttachListSort.php:170) in c:\program files\apache group\Apache\htdocs\PMwiki\pmwiki.php on line 884" error message.
There seems to be another problem there. No matter what parameters I give to "sort" I always get sort by name. I think that the problem is that the sorting result is not used at all. When using the array_multisort:
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 = $namelist;
As you can see the result can not be in $namelist, since it is not sent to array_multisort. So the script just does nothing, you will always get sort by name (since $sortlist['name']=$namelist ), unless you send to $filelist some part of $sortlist... I am not a PHP expert (I am not sure I can even be considered as a beginner...) so I might be wrong. but whet I try the following change I get the right result $filelist = $sortlist[$sortkey[0]]; please check...
Please correct the code as indicated above because it did not work at all with PHP 5.2.0 (3 may 2007).
BTW I wonder no one has ever thought of that. This cookbook can be easily tweaked to produce a table of attachments, which can be easily sorted on-the-fly using sorttable.js which can be embedded in pmwiki.(or the great firefox extention TableTools which can be used to sort/filter on HTML tables) And another idea - this could be combined with - adding an icon to attachments based on file types, as was written recently in the "AttachIcon" idea in the mailing list. I have tried it on my private pmwiki installation. took 5 minutes to update attachlistsort for both... - Avi Dec. 05, 2006 (add some more on 19-Dec-2006)
When I listed files with non-ASCII characters in their names I had strange effects. To get proper encoding I've made some changes to your recipe as follows: 1. add $Charset to globals in attachlistsort function, 2. change $namelist[$file] = $file; to $namelist[$file] = iconv('CP1250', $Charset, $file); I'm not a PHP guru so feel free to correct me if I'm wrong. I'm using version 1.1 ; when I use AttachListSort on an empty list of attachment, I get an error (implode function illegal argument). I simply suggest to return an empty string when the file list is empty, e.g. by adding the following after line 101 :
I'm not a PHP guru so feel free to correct me if I'm wrong :). See AlsoContributors |