Alpha Framework alpha--view--widgets
[ class tree: alpha--view--widgets ] [ index: alpha--view--widgets ] [ all elements ]

Source for file TagCloud.inc

Documentation is available at TagCloud.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/AlphaErrorHandlers.inc';
  4. require_once $config->get('sysRoot').'alpha/util/Logger.inc';
  5. require_once $config->get('sysRoot').'alpha/model/TagObject.inc';
  6.  
  7. /**
  8.  * A widget for rendering a tag cloud, based off the TagObject instances in the
  9.  * database.
  10.  * 
  11.  * @package alpha::view::widgets
  12.  * @author John Collins <dev@alphaframework.org>
  13.  * @copyright 2010 John Collins
  14.  * @version $Id: TagCloud.inc 1315 2011-03-09 18:09:22Z johnc $
  15.  * 
  16.  */
  17. class TagCloud {
  18.     
  19.     /**
  20.      * Trace logger
  21.      * 
  22.      * @var Logger 
  23.      */
  24.     private static $logger null;
  25.     
  26.     /**
  27.      * A hash array of popular tags
  28.      * 
  29.      * @var array 
  30.      */
  31.     private $popTags array();
  32.     
  33.     /**
  34.      * Constructor
  35.      */
  36.     public function __construct($limit{
  37.         $this->popTags TagObject::getPopularTagsArray($limit);
  38.     }
  39.     
  40.     /**
  41.      * Render the tag cloud and return all of the HTML links in a single paragraph.
  42.      * 
  43.      * @param $minLinkSize The minimum font size for any tag link, in points.
  44.      * @param $maxLinkSize The maximum font size for any tag link, in points.
  45.      * @param $target The target attribute for the links
  46.      * @return string 
  47.      */
  48.     public function render($minLinkSize=8$maxLinkSize=20$target=''{
  49.         global $config;
  50.         
  51.         $html '<p>';
  52.         
  53.         foreach (array_keys($this->popTagsas $key{
  54.             $linkSize $this->popTags[$key];
  55.             if ($linkSize $minLinkSize)
  56.                 $linkSize $minLinkSize;
  57.             if ($linkSize $maxLinkSize)
  58.                 $linkSize $maxLinkSize;
  59.             $html .= '<a href="'.$config->get('sysURL').'search/q/'.$key.'" style="font-size:'.$linkSize.'pt;"'.(empty($target'' ' target="'.$target.'"').' rel="tag">'.$key.'</a> ';
  60.         }
  61.         
  62.         return $html.'</p>';
  63.     }
  64. }
  65.  
  66. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:54 +0000 by phpDocumentor 1.4.3