Skip to content

Commit 46c1465

Browse files
committed
Added syntax tag option 'showCount'. If set, the number of occurrences of a word will be shown. Closes #30.
1 parent 5b856e3 commit 46c1465

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

syntax.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
require_once(DOKU_PLUGIN.'syntax.php');
1616

1717
class syntax_plugin_cloud extends DokuWiki_Syntax_Plugin {
18+
protected $knownFlags = array('showCount');
1819

1920
function getType() { return 'substition'; }
2021
function getPType() { return 'block'; }
@@ -37,19 +38,31 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
3738

3839
list($num, $ns) = explode('>', $match, 2);
3940
list($junk, $num) = explode(':', $num, 2);
41+
$flags = null;
42+
if (preg_match ('/\[.*\]/', $junk, $flags) === 1) {
43+
$flags = trim ($flags [0], '[]');
44+
$found = explode(',', $flags);
45+
$flags = array();
46+
foreach ($found as $flag) {
47+
if (in_array($flag, $this->knownFlags)) {
48+
// Actually we just set flags as present
49+
// Later we might add values to flags like key=value pairs
50+
$flags [$flag] = true;
51+
}
52+
}
53+
}
4054

4155
if (!is_numeric($num)) $num = 50;
4256
if(!is_null($ns)) $namespaces = explode('|', $ns);
4357
else $namespaces = null;
4458

45-
return array($type, $num, $namespaces);
59+
return array($type, $num, $namespaces, $flags);
4660
}
4761

4862
function render($mode, Doku_Renderer $renderer, $data) {
4963
global $conf;
5064

51-
list($type, $num, $namespaces) = $data;
52-
65+
list($type, $num, $namespaces, $flags) = $data;
5366
if ($mode == 'xhtml') {
5467

5568
if ($type == 'tag') { // we need the tag helper plugin
@@ -122,6 +135,9 @@ function render($mode, Doku_Renderer $renderer, $data) {
122135
}
123136
}
124137

138+
if ($flags ['showCount'] === true) {
139+
$name .= '('.$size.')';
140+
}
125141
$renderer->doc .= DOKU_TAB . '<a href="' . $link . '" class="' . $class .'"'
126142
.' title="' . $title . '">' . hsc($name) . '</a>' . DOKU_LF;
127143
}

0 commit comments

Comments
 (0)