private function tagToName($t) { $exists = false; $id = $t; resolve_pageID($this->tagplugin->namespace, $id, $exists); $name = p_get_first_heading($id, false); if (empty($name)) { $name = $t; } else { $name = $name; } return $name; }
function render($mode, &$renderer, $data) { global $conf; list($type, $num, $namespaces) = $data; if ($mode == 'xhtml') { if ($type == 'tag') { // we need the tag helper plugin if (plugin_isdisabled('tag') || !($tag = plugin_load('helper', 'tag'))) { msg('The Tag Plugin must be installed to display tag clouds.', -1); return false; } $cloud = $this->_getTagCloud($num, $min, $max, $namespaces, $tag); } elseif ($type == 'search') { $helper = plugin_load('helper', 'searchstats'); if ($helper) { $cloud = $helper->getSearchWordArray($num); // calculate min/max values $min = PHP_INT_MAX; $max = 0; foreach ($cloud as $size) { $min = min($size, $min); $max = max($size, $max); } } else { msg('You have to install the searchstats plugin to use this feature.', -1); return false; } } else { $cloud = $this->_getWordCloud($num, $min, $max); } if (!is_array($cloud) || empty($cloud)) { return false; } $delta = ($max - $min) / 16; // prevent caching to ensure the included pages are always fresh $renderer->info['cache'] = false; // and render the cloud $renderer->doc .= '<div class="cloud">' . DOKU_LF; foreach ($cloud as $word => $size) { if ($size < $min + round($delta)) { $class = 'cloud1'; } elseif ($size < $min + round(2 * $delta)) { $class = 'cloud2'; } elseif ($size < $min + round(4 * $delta)) { $class = 'cloud3'; } elseif ($size < $min + round(8 * $delta)) { $class = 'cloud4'; } else { $class = 'cloud5'; } $name = $word; if ($type == 'tag') { $id = $word; $exists = false; resolve_pageID($tag->namespace, $id, $exists); if ($exists) { $link = wl($id); if ($conf['useheading']) { $name = p_get_first_heading($id, false); } else { $name = $word; } } else { $link = wl($id, array('do' => 'showtag', 'tag' => $word)); } $title = $word; $class .= $exists ? '_tag1' : '_tag2'; } else { if ($conf['userewrite'] == 2) { $link = wl($word, array('do' => 'search', 'id' => $word)); $title = $size; } else { $link = wl($word, 'do=search'); $title = $size; } } $renderer->doc .= DOKU_TAB . '<a href="' . $link . '" class="' . $class . '"' . ' title="' . $title . '">' . hsc($name) . '</a>' . DOKU_LF; } $renderer->doc .= '</div>' . DOKU_LF; return true; } return false; }
/** * Returns <a></a> links with font style attribut representing number of ocurrences * (inspired by DokuWiki Cloud plugin by Gina Häußge, Michael Klier, Esther Brunner) */ function _getTagXml($options) { global $conf; if ($options['show'] == 'tags') { // we need the tag helper plugin if (plugin_isdisabled('tag') || !($tag = plugin_load('helper', 'tag'))) { msg('The Tag Plugin must be installed to display tag clouds.', -1); return ''; } $cloud = $this->_getTagCloud($options['max'], $min, $max, $tag); } elseif ($options['show'] == 'namespaces') { $cloud = $this->_getNamespaceCloud($options['max'], $min, $max); } else { $cloud = $this->_getWordCloud($options['max'], $min, $max); } if (!is_array($cloud) || empty($cloud)) { return ''; } $delta = ($max - $min) / 16; if ($delta == 0) { $delta = 1; } foreach ($cloud as $word => $size) { if ($size < $min + round($delta)) { $class = 'cloud1'; } elseif ($size < $min + round(2 * $delta)) { $class = 'cloud2'; } elseif ($size < $min + round(4 * $delta)) { $class = 'cloud3'; } elseif ($size < $min + round(8 * $delta)) { $class = 'cloud4'; } else { $class = 'cloud5'; } $name = $word; if ($options['show'] == 'tags') { $id = $word; resolve_pageID($tag->namespace, $id, $exists); if ($exists) { $link = wl($id, '', true); if ($conf['useheading']) { $name = p_get_first_heading($id, false); } } else { $link = wl($id, array('do' => 'showtag', 'tag' => noNS($id)), true); } $title = $id; $class .= $exists ? '_tag1' : '_tag2'; } elseif ($options['show'] == 'namespaces') { $id = ''; resolve_pageID($word, $id, $exists); $link = wl($id, '', true); $title = $id; $size = 108; $class = 'cloud5'; } else { if ($conf['userewrite'] == 2) { $link = wl($word, array('do' => 'search', 'id' => $word), true); $title = $size; } else { $link = wl($word, 'do=search', true); $title = $size; } } $fsize = 8 + round(($size - $min) / $delta); $xmlCloude .= '<a href="' . $link . '" class="' . $class . '"' . ' title="' . $title . '" style="font-size: ' . $fsize . 'pt;">' . hsc($name) . '</a>' . DOKU_LF; } return $xmlCloude; }