'Page name(s) for cosmos display. Separate multiple names with spaces. If blank, the cosmos will appear in all active contexts.', 'scale_max' => 'Maximum value for count scaling (set to zero for no scaling)', 'scale_min' => 'Minimum value for count scaling (ignored if max is zero)', 'count_min' => 'Minimum count required for a tag to included in the results', 'display_max' => 'Maximum number of tags to display', 'sort_order' => 'Results sort order: must be one of alpha, natural, countup, countdown', ); var $_frontend; // options var $page_name = 'tags'; var $scale_max = 0; var $scale_min = 1; var $count_min = 1; var $display_max = 30; var $sort_order = 'natural'; function TagCloud(&$frontend, $args, $dummy_run=false) { $this->LightPressPlugin($frontend, $args, $dummy_run); // pre-processing (if not changing settings) if (!$dummy_run) { if (isset($GLOBALS['feed_type'])) { $this->active = false; return; } // check if this is a cosmos request if ($this->page_name != '') { $pages = explode(' ', $this->page_name); $c =& $frontend->context; $found = false; foreach($pages as $p) { if ($c['filter'] == $p) { $found = true; break; } } if (!$found) $this->active = false; } } } function run($hook, &$post) { if (!$this->active) return ($this->hide()); $tpl =& $this->_frontend->tpl; $tpl->setFile('plugin_tagcloud', 'plugins/tag_cloud.xml'); $tpl->setBlock('plugin_tagcloud', 'plugin_tagcloud_tag', 'BLOCK_TAGCLOUD'); $alltags =& $this->_frontend->getTags(); // limit results $limit = (int) $this->display_max; if (($limit > 0) && (count($alltags) > $limit)) { //uasort($alltags, array($this, 'sortCountDesc'); // should already be descending $alltags = array_slice($alltags, 0, $limit); } // sort results switch(strtolower($this->sort_order)) { case 'alpha': ksort($alltags); break; case 'countup': $alltags = array_reverse($alltags, true); // reverse array order to be ascending break; case 'countdown': // already in descending order break; case 'random': // TODO - random sort would be fun // but for now we'll fall through default: // case for 'natural' uksort($alltags, 'strnatcasecmp'); break; } // scaling $mincount =& $this->count_min; $do_scale = ($this->scale_max != 0); if ($do_scale) { $minval = $maxval = $alltags[ key($alltags) ]['numposts']; foreach($alltags as $tag) { $minval = min($tag['numposts'], $minval); $maxval = max($tag['numposts'], $maxval, $mincount); } $minval = max($minval, $mincount); $minout = max($this->scale_min, 0); $maxout = max($this->scale_max, $minout); $scale = ($maxval > $minval) ? (($maxout - $minout) / ($maxval - $minval)) : 0; } // loop through tags $appendblock = false; foreach($alltags as $tag) { if ($tag['numposts'] >= $mincount) { $tpl->setVar(array( 'plugin_tagcloud_tag_name' => $tag['name'], 'plugin_tagcloud_tag_encoded' => $tag['encoded'], 'plugin_tagcloud_tag_count' => $tag['numposts'], 'plugin_tagcloud_tag_scaled' => ( ($do_scale) ? (int) (($tag['numposts'] - $minval) * $scale + $minout) : $tag['numposts'] ) )); $tpl->parse('BLOCK_TAGCLOUD', 'plugin_tagcloud_tag', $appendblock); $appendblock = true; } } if ($appendblock) $tpl->parse('PLUGIN_TAGCLOUD', 'plugin_tagcloud'); else $tpl->setVar('PLUGIN_TAGCLOUD', ''); } function hide() { $this->_frontend->tpl->setVar('PLUGIN_TAGCLOUD', ''); } } ?>