Summary: Talk page for AttachListSort.
Users: +1 (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.


A change in v1.5, I think - or maybe it's a PHP version mismatch? I get:

Array and string offset access syntax with curly braces is no longer supported in /var/www/html/pmwiki/cookbook/AttachListSort.php on line 57

and the site falls over...

Editing line 57 from if ($file{0} == '.') continue; to if ($file[0] == '.') continue; does the trick, though....

There appears to be a typo in version 1.4. On line 27, >attachlist should be changed to <attachlist so that the markup rule takes effect before the normal attachlist rule, not after (see Functions#Markup). Without this change, the script never takes effect. sroracle? July 14, 2017, at 06:19 PM

Also, line 162 should also be using $TimeFmt instead of $t. sroracle? July 14, 2017, at 10:43 PM

  • Does this work? I installed as stated above and get "Argument #2 is expected to be an array or a sort flag in c:\program files\apache group\Apache\htdocs\PMwiki\cookbook\AttachListSort.php on line 170
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.
Change line 102 in "AttachListSort.php" from "$D = SORT_DEC;" to "$D = SORT_DESC;" and it works.
– Subhash Nov. 30, 2006
Fantastic catch there subhash! It is fixed in the newest version

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...

Using "$filelist = $namelist;" has always worked for me. I originally programmed it in PHP version 5 which makes array assignments by reference. We moved to a new server and now I use PHP version 4.39 and it still works great with "$filelist = $namelist;". Can you please tell me what version of PHP you are using?

Please correct the code as indicated above because it did not work at all with PHP 5.2.0 (3 may 2007).

I also have PHP 5.2.0+ and had to go into AttachListSort.php and change that line to '$filelist = $sortlist[$sortkey[0]]' to get it to work. I've uploaded my changed version to be the current one so others don't have to go to the same confusion & trouble. That said, GNUZoo, this is some great code, and thanks for it. --ez
OK, so it is something with the newer version 5 of php and had stopped working for me since I upgraded. It is fixed in the newest version.

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)

Please do make these recipes for everyone using PMWiki to use!!!

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.
--errorsys, 2007-10-24

I do not understand what CP1250 is, but it seems to me that it is a european thing. Is there some more generic way to get the current input charset and not just designate everything as CP1250 in my code? I live in Dallas Texas in the USA.

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 :

if (count($namelist) == 0) { return ""; }

I'm not a PHP guru so feel free to correct me if I'm wrong :).
--jce, 2008-05-27

Great idea. It is fixed in the newest version.

How is it possible to use this recipe in combination with AttachDelete?

--cg, 2010-01-24

Talk page for the AttachListSort recipe (users).