From: garvinhicking Date: Fri, 29 Apr 2005 13:05:53 +0000 (+0000) Subject: allow to sort categories by custom fields X-Git-Tag: 0.9~489 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=90f9e6d60e32199bc7d0fe5caa902211f7db4072;p=s9y.git allow to sort categories by custom fields --- diff --git a/docs/NEWS b/docs/NEWS index 7652edf..02e9b1d 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 0.9 () ------------------------------------------------------------------------ + * Categories plugin now offers to sort by category name, description + or creation date. (garvinhicking) + * Deactivated gzip compression by default, as in certain server setups it creates problem with double-encoding or missing ob_gzhandlers. (garvinhicking) diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 5c9f133..9e75576 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -356,7 +356,7 @@ function serendipity_fetchEntryProperties($id) { /** * Fetches a users categories **/ -function serendipity_fetchCategories($authorid = null, $name = '') { +function serendipity_fetchCategories($authorid = null, $name = '', $order = 'category_name ASC') { global $serendipity; if (!isset($authorid) || $authorid === null) { @@ -389,8 +389,12 @@ function serendipity_fetchCategories($authorid = null, $name = '') { a.realname FROM {$serendipity['dbPrefix']}category AS c LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a - ON c.authorid = a.authorid $where - ORDER BY category_name"; + ON c.authorid = a.authorid $where"; + + if (!empty($order)) { + $querystring .= "\n ORDER BY $order"; + } + return serendipity_db_query($querystring); } diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index 749c16d..738dee3 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -954,7 +954,7 @@ class serendipity_categories_plugin extends serendipity_plugin { $propbag->add('stackable', true); $propbag->add('author', 'Serendipity Team'); $propbag->add('version', '1.0'); - $propbag->add('configuration', array('authorid', 'image')); + $propbag->add('configuration', array('authorid', 'image', 'sort_order', 'sort_method')); } function introspect_config_item($name, &$propbag) @@ -977,6 +977,29 @@ class serendipity_categories_plugin extends serendipity_plugin { $propbag->add('default', 'all'); break; + case 'sort_order': + $select = array(); + $select['category_name'] = CATEGORY; + $select['category_description'] = DESCRIPTION; + $select['none'] = NONE; + $propbag->add('type', 'select'); + $propbag->add('name', SORT_ORDER); + $propbag->add('description', ''); + $propbag->add('select_values', $select); + $propbag->add('default', 'category_name'); + break; + + case 'sort_method': + $select = array(); + $select['ASC'] = SORT_ORDER_ASC; + $select['DESC'] = SORT_ORDER_DESC; + $propbag->add('type', 'select'); + $propbag->add('name', SORT_ORDER); + $propbag->add('description', ''); + $propbag->add('select_values', $select); + $propbag->add('default', 'ASC'); + break; + case 'image': $propbag->add('type', 'string'); $propbag->add('name', XML_IMAGE_TO_DISPLAY); @@ -994,7 +1017,13 @@ class serendipity_categories_plugin extends serendipity_plugin { global $serendipity; $which_category = $this->get_config('authorid'); - $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category); + $sort = $this->get_config('sort_order'); + if ($sort == 'none') { + $sort = ''; + } else { + $sort .= ' ' . $this->get_config('sort_method'); + } + $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort); $title = $this->title; $html = ''; $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));