From 1514b0f4e5c053df60b8873b5411c70be727d227 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 21 Mar 2018 21:19:18 -0700 Subject: initial support for alternative sort orders on the cloud pages. Can be triggered manually but further development is required. --- Zotlabs/Module/Cloud.php | 6 ++++++ Zotlabs/Storage/Directory.php | 18 +++++++++++++++++- include/zid.php | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index 8b5476efc..34397d275 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -60,6 +60,12 @@ class Cloud extends \Zotlabs\Web\Controller { // if we arrived at this path with any query parameters in the url, build a clean url without // them and redirect. + if(! array_key_exists('cloud_sort',$_SESSION)) { + $_SESSION['cloud_sort'] = 'name'; + } + + $_SESSION['cloud_sort'] = (($_REQUEST['sort']) ? trim(notags($_REQUEST['sort'])) : $_SESSION['cloud_sort']); + $x = clean_query_string(); if($x !== \App::$query_string) goaway(z_root() . '/' . $x); diff --git a/Zotlabs/Storage/Directory.php b/Zotlabs/Storage/Directory.php index a2dd1e9b8..a2ae0fee8 100644 --- a/Zotlabs/Storage/Directory.php +++ b/Zotlabs/Storage/Directory.php @@ -691,7 +691,23 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo } $prefix = ''; - $suffix = ' order by is_dir desc, filename asc '; + + if(! array_key_exists('cloud_sort',$_SESSION)) + $_SESSION['cloud_sort'] = 'name'; + + switch($_SESSION['cloud_sort']) { + case 'size': + $suffix = ' order by is_dir desc, filesize asc '; + break; + // The following provides inconsistent results for directories because we re-calculate the date for directories based on the most recent change + case 'date': + $suffix = ' order by is_dir desc, edited asc '; + break; + case 'name': + default: + $suffix = ' order by is_dir desc, filename asc '; + break; + } $r = q("select $prefix id, uid, hash, filename, filetype, filesize, revision, folder, flags, is_dir, created, edited from attach where folder = '%s' and uid = %d $perms $suffix", dbesc($folder), diff --git a/include/zid.php b/include/zid.php index 5b5601191..5275c6d5a 100644 --- a/include/zid.php +++ b/include/zid.php @@ -109,6 +109,7 @@ function clean_query_string($s = '') { $x = strip_zids(($s) ? $s : \App::$query_string); $x = strip_owt($x); $x = strip_zats($x); + $x = strip_query_param($x,'sort'); return strip_query_param($x,'f'); } -- cgit v1.2.3