diff U3 syntax.bak.php syntax.php --- syntax.bak.php Wed Jul 16 09:20:49 2008 +++ syntax.php Wed Jul 16 14:08:52 2008 @@ -32,24 +32,37 @@ function getSort() { return 98; } function connectTo($mode) { - $this->Lexer->addSpecialPattern('~~\w*?CLOUD.*?~~', $mode, 'plugin_cloud'); + $this->Lexer->addSpecialPattern('{{\w*?cloud>.*?}}', $mode, 'plugin_cloud'); } function handle($match, $state, $pos, &$handler) { + global $ID; + $match = substr($match, 2, -2); // strip markup - if (substr($match, 0, 3) == 'TAG') $type = 'tag'; - else $type = 'word'; + if (substr($match, 0, 3) == 'tag') { + $match = substr($match, 9); + $type = 'tag'; + } + else { + $match = substr($match, 6); + $type = 'word'; + } + + list($ns, $num) = explode('#', $match, 2); - list($junk, $num) = explode(':', $match, 2); - if (!is_numeric($num)) $num = 50; + if (($ns == '*') || ($ns == ':')) $ns = ''; + elseif ($ns == '.') $ns = getNS($ID); + else $ns = cleanID($ns); - return array($type, $num); + if (!is_numeric($num)) $num = 20; + + return array($type, $ns, $num); } function render($mode, &$renderer, $data) { global $conf; - list($type, $num) = $data; + list($type, $ns, $num) = $data; if ($mode == 'xhtml') { @@ -58,9 +71,9 @@ msg('The Tag Plugin must be installed to display tag clouds.', -1); return false; } - $cloud = $this->_getTagCloud($num, $min, $max, $tag); + $cloud = $this->_getTagCloud($ns, $num, $min, $max, $tag); } else { - $cloud = $this->_getWordCloud($num, $min, $max); + $cloud = $this->_getWordCloud($ns, $num, $min, $max); } if (!is_array($cloud) || empty($cloud)) return false; $delta = ($max-$min)/16; @@ -89,10 +102,16 @@ $class .= ($exists ? '_tag1' : '_tag2'); } else { if($conf['userewrite'] == 2) { - $link = wl($word, array('do'=>'search', 'id'=>$word)); + if ($ns == '') + $link = wl($word, array('do'=>'search', 'id'=>$word)); + else + $link = wl($word, array('do'=>'search', 'id'=>"$word@$ns")); $title = $size; } else { - $link = wl($word, 'do=search'); + if ($ns == '') + $link = wl($word, 'do=search'); + else + $link = wl("$word@$ns", 'do=search'); $title = $size; } } @@ -108,7 +127,7 @@ /** * Returns the sorted word cloud array */ - function _getWordCloud($num, &$min, &$max) { + function _getWordCloud($ns, $num, &$min, &$max){ global $conf; // load stopwords @@ -124,6 +143,7 @@ if (@file_exists($conf['indexdir'].'/page.idx')) { // new word-lenght based index require_once(DOKU_INC.'inc/indexer.php'); + $page_idx = idx_getIndex('page',''); $n = 2; // minimum word length $lengths = idx_indexLengths($n); @@ -131,23 +151,19 @@ $idx = idx_getIndex('i', $len); $word_idx = idx_getIndex('w', $len); - $this->_addWordsToCloud($cloud, $idx, $word_idx, $stopwords); + $this->_addWordsToCloud($cloud, $ns, $idx, $word_idx, $page_idx, $stopwords); } - } else { // old index - $idx = file($conf['cachedir'].'/index.idx'); - $word_idx = file($conf['cachedir'].'/word.idx'); - - $this->_addWordsToCloud($cloud, $idx, $word_idx, $stopwords); } - return $this->_sortCloud($cloud, $num, $min, $max); + if (empty($cloud)) return $cloud; + return $this->_sortCloud($cloud, $num, $min, $max); } /** * Adds all words in given index as $word => $freq to $cloud array */ - function _addWordsToCloud(&$cloud, $idx, $word_idx, &$stopwords) { + function _addWordsToCloud(&$cloud, $ns, $idx, $word_idx, $page_idx, &$stopwords){ $wcount = count($word_idx); // collect the frequency of the words @@ -156,22 +172,41 @@ if (!is_int(array_search("$key\n", $stopwords))) { $value = explode(':', $idx[$i]); if (!trim($value[0])) continue; + if ($ns == '') $cloud[$key] = count($value); - } + else + { + foreach ($value as $v) + { + list($p,$c) = explode('*', $v); + if (substr($page_idx[$p], 0, strlen($ns)) == $ns) + $cloud[$key]++; + } + } + } } } /** * Returns the sorted tag cloud array */ - function _getTagCloud($num, &$min, &$max, &$tag) { + function _getTagCloud($ns, $num, &$min, &$max, &$tag){ $cloud = array(); foreach ($tag->topic_idx as $key => $value) { if (!is_array($value) || empty($value) || (!trim($value[0]))) continue; + if ($ns == '') $cloud[$key] = count($value); - } + else + { + foreach ($value as $idx){ + if (substr($idx, 0, strlen($ns)) == $ns) + $cloud[$key]++; + } + } + } - return $this->_sortCloud($cloud, $num, $min, $max); + if (empty($cloud)) return $cloud; + return $this->_sortCloud($cloud, $num, $min, $max); } /**