From 2adff9720223b19106f20d2e5f09638bfa19e754 Mon Sep 17 00:00:00 2001 From: lupo49 Date: Fri, 19 Aug 2011 20:43:02 +0200 Subject: [PATCH] Discard space after &-symbol / Output error message when the result is empty --- helper.php | 7 ++++--- lang/de/lang.php | 1 + lang/en/lang.php | 1 + syntax/count.php | 24 ++++++++++++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/helper.php b/helper.php index 8dc9afc..22e2d5c 100644 --- a/helper.php +++ b/helper.php @@ -296,16 +296,17 @@ function tagOccurences($tags, $ns = NULL) { foreach($tags as $index => $tagname) { // get pages for $tagname $pages = $this->topic_idx[$tagname]; - $deleteID = false; // $pages is null when non-existing tags are specified if($pages != null) { foreach($pages as $key => $page) { + $deleteID = false; + // check if the namespace of the current page is in a given namespace if(getNS($page) != false && !in_array(getNS($page), $ns)) $deleteID = true; - // condition for root namespace - if(getNS($page) == false && in_array('.', $ns)) $deleteID = false; + // condition for root namespace + if(getNS($page) == false && !in_array('.', $ns)) $deleteID = true; // remove the page in the array if($deleteID) unset($pages[$key]); diff --git a/lang/de/lang.php b/lang/de/lang.php index d0347ac..cdee23b 100644 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -11,6 +11,7 @@ $lang['topic'] = 'Thema'; $lang['rebuildindex'] = 'Tagindex neu aufbauen'; $lang['toolbar_icon'] = 'Tag-Syntax einfügen'; +$lang['empty_output'] = 'Leere Ausgabe'; $lang['missing_pagelistplugin'] = 'Ohne Pagelist Plugin können Themenlisten nicht angezeigt werden.'; diff --git a/lang/en/lang.php b/lang/en/lang.php index 586f1d8..ab8ac0a 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -11,6 +11,7 @@ $lang['topic'] = 'Topic'; $lang['rebuildindex'] = 'Rebuild Tagindex'; $lang['toolbar_icon'] = 'Insert Tag-Syntax'; +$lang['empty_output'] = 'Empty Output'; $lang['missing_pagelistplugin'] = 'The Pagelist Plugin must be installed for topic lists.'; diff --git a/syntax/count.php b/syntax/count.php index 0f42739..db09b44 100644 --- a/syntax/count.php +++ b/syntax/count.php @@ -48,6 +48,11 @@ function handle($match, $state, $pos, &$handler) { $tags = $dump[0]; $allowedNamespaces = explode(' ', $dump[1]); // split given namespaces into an array + if($allowedNamespaces && $allowedNamespaces[0] == '') { + unset($allowedNamespaces[0]); // When exists, remove leading space after the delimiter + $allowedNamespaces = array_values(($allowedNamespaces)); + } + if (!$tags) return false; if(!($my = plugin_load('helper', 'tag'))) return false; @@ -105,12 +110,23 @@ function render($mode, &$renderer, $data) { $renderer->doc .= '#'; $renderer->doc .= DOKU_LF.DOKU_TAB.''.DOKU_LF; - foreach($data as $key => $tag) { - if($tag <= 0) continue; + // skip output, if the individual occurences of the tags is zero + // if the amount of tags with count == 0 is equal to the overall count of tags then skip output + $countTags = array_keys($data, 0); + + if(sizeof($countTags) == sizeof($data)) { + // Skip output $renderer->doc .= DOKU_TAB.''.DOKU_LF.DOKU_TAB.DOKU_TAB; - $renderer->doc .= DOKU_TAB.DOKU_TAB.''.$tl[$key].''.DOKU_LF; - $renderer->doc .= DOKU_TAB.DOKU_TAB.''.$tag.''.DOKU_LF; + $renderer->doc .= DOKU_TAB.DOKU_TAB.''.$this->getLang('empty_output').''.DOKU_LF; $renderer->doc .= DOKU_LF.DOKU_TAB.''.DOKU_LF; + } else { + foreach($data as $key => $tag) { + if($tag <= 0) continue; // don't display tags with zero occurences + $renderer->doc .= DOKU_TAB.''.DOKU_LF.DOKU_TAB.DOKU_TAB; + $renderer->doc .= DOKU_TAB.DOKU_TAB.''.$tl[$key].''.DOKU_LF; + $renderer->doc .= DOKU_TAB.DOKU_TAB.''.$tag.''.DOKU_LF; + $renderer->doc .= DOKU_LF.DOKU_TAB.''.DOKU_LF; + } } $renderer->doc .= ''.DOKU_LF; }