Skip to content

Commit

Permalink
Discard space after &-symbol / Output error message when the result i…
Browse files Browse the repository at this point in the history
…s empty
  • Loading branch information
lupo49 committed Aug 19, 2011
1 parent 5148541 commit 2adff97
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
7 changes: 4 additions & 3 deletions helper.php
Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions lang/de/lang.php
Expand Up @@ -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.';

Expand Down
1 change: 1 addition & 0 deletions lang/en/lang.php
Expand Up @@ -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.';

Expand Down
24 changes: 20 additions & 4 deletions syntax/count.php
Expand Up @@ -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;
Expand Down Expand Up @@ -105,12 +110,23 @@ function render($mode, &$renderer, $data) {
$renderer->doc .= '<th class="'.$col.'">#</th>';
$renderer->doc .= DOKU_LF.DOKU_TAB.'</tr>'.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.'<tr>'.DOKU_LF.DOKU_TAB.DOKU_TAB;
$renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'">'.$tl[$key].'</td>'.DOKU_LF;
$renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'">'.$tag.'</td>'.DOKU_LF;
$renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'" colspan="2">'.$this->getLang('empty_output').'</td>'.DOKU_LF;
$renderer->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
} else {
foreach($data as $key => $tag) {
if($tag <= 0) continue; // don't display tags with zero occurences
$renderer->doc .= DOKU_TAB.'<tr>'.DOKU_LF.DOKU_TAB.DOKU_TAB;
$renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'">'.$tl[$key].'</td>'.DOKU_LF;
$renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'">'.$tag.'</td>'.DOKU_LF;
$renderer->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
}
}
$renderer->doc .= '</table>'.DOKU_LF;
}
Expand Down

0 comments on commit 2adff97

Please sign in to comment.