AttachListSort

Summary: Sort an attachlist
Version: 1.5
Prerequisites: none
Status: Working
Maintainer:
Users: +1 (View / Edit)
Categories: Uploads PHP72

Questions answered by this recipe

  • Is there a way to sort the attachlist?

Description

This 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-Sort

The 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-sorting

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

Installing

Copy 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");

Notes

Release Notes

  • Version 1.5 - Use $TimeFmt, fix rule ordering (see talk page), drop use of /e modifier -sroracle? January 04, 2019, at 03:03 AM
  • Version 1.4
  • Version: 1.3 - Fix bug where there are no files in the attachlist directory, make adjustment for php version 5.
  • Version: 1.1 - Add recipeinfo
  • Version: 10 20 2006 2:57 AM CST - fix "$D = SORT_DESC;" bug & fix tabs in code
  • Version: 10 10 2006 2:34 AM CST - Add Multi-Sort, Include seconds in file information
  • Version: 10 09 2006 4:53 PM CST - Add ability to sort based on file type
  • Version: 10 07 2006 7:00 AM CST - fix bugs, improve sort, add ascending & descending
  • Version: 10 06 2006 7:02 PM CST - Initial release

See Also

Contributors

Comments

See discussion at AttachListSort-Talk

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.