HTML_TagCloud
[ class tree: HTML_TagCloud ] [ index: HTML_TagCloud ] [ all elements ]

Source for file TagCloud_example3.php

Documentation is available at TagCloud_example3.php

  1. <?php
  2. /**
  3.  * TagCloud_example3.php
  4.  *
  5.  * Generate a customized Tag Cloud by extending the class.
  6.  * In this example we visualize only the timeline information, not the number of
  7.  * occurrences. Because of this every item of the tag cloud will have the same
  8.  * font size, but different colors. The newer the tag is, the deeper its color
  9.  * will be; older tags will have a lighter color.
  10.  *
  11.  * PHP version 5
  12.  *
  13.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  14.  * that is available through the world-wide-web at the following URI:
  15.  * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
  16.  * the PHP License and are unable to obtain it through the web, please
  17.  * send a note to license@php.net so we can mail you a copy immediately.
  18.  *
  19.  * @category  HTML
  20.  * @package   HTML_TagCloud
  21.  * @author    Bastian Onken <bastianonken@php.net>
  22.  * @copyright 2010 Bastian Onken
  23.  * @license   http://www.php.net/license/3_01.txt  PHP License 3.01
  24.  * @version   SVN: $Id: TagCloud_example3.php 295251 2010-02-19 11:32:43Z bastianonken $
  25.  * @link      http://pear.php.net/package/HTML_TagCloud
  26.  * @since     File available since Release 0.1.0
  27.  */
  28.  
  29. require_once 'HTML/TagCloud.php';
  30.  
  31. // To get the date function working properly we have to set the time zone
  32.  
  33. // {{{ class MyTags extends HTML_TagCloud{
  34.  
  35. /**
  36.  * MyTags extends HTML_TagCloud
  37.  *
  38.  * Showing how to override the protected class vars
  39.  *
  40.  * @category  HTML
  41.  * @package   HTML_TagCloud
  42.  * @author    Shoma Suzuki <shoma@catbot.net>
  43.  * @author    Bastian Onken <bastianonken@php.net>
  44.  * @copyright 2010 Bastian Onken
  45.  * @license   http://www.php.net/license/3_01.txt  PHP License 3.01
  46.  * @version   Release: 1.0.0
  47.  * @link      http://pear.php.net/package/HTML_TagCloud
  48.  * @since     Class available since Release 0.1.0
  49.  */
  50. class MyTags extends HTML_TagCloud
  51. {
  52.     /**
  53.      * Defines colors of the different levels that tags will be assigned to
  54.      * (based on tag's age)
  55.      *
  56.      * @var    array 
  57.      * @access protected
  58.      */
  59.     protected $epocLevel = array(
  60.         array(
  61.             'earliest' => array(
  62.                 'link'    => 'ffdfdf',
  63.                 'visited' => 'ffdfdf',
  64.                 'hover'   => 'ffdfdf',
  65.                 'active'  => 'ffdfdf',
  66.             ),
  67.         ),
  68.         array(
  69.             'earlier' => array(
  70.                 'link'    => 'ff7f7f',
  71.                 'visited' => 'ff7f7f',
  72.                 'hover'   => 'ff7f7f',
  73.                 'active'  => 'ff7f7f',
  74.             ),
  75.         ),
  76.         array(
  77.             'previous' => array(
  78.                 'link'    => 'ff7f7f',
  79.                 'visited' => 'ff7f7f',
  80.                 'hover'   => 'ff7f7f',
  81.                 'active'  => 'ff7f7f',
  82.             ),
  83.         ),
  84.         array(
  85.             'recent' => array(
  86.                 'link'    => 'ff4f4f',
  87.                 'visited' => 'ff4f4f',
  88.                 'hover'   => 'ff4f4f',
  89.                 'active'  => 'ff4f4f',
  90.             ),
  91.         ),
  92.         array(
  93.             'later' => array(
  94.                 'link'    => 'ff1f1f',
  95.                 'visited' => 'ff1f1f',
  96.                 'hover'   => 'ff1f1f',
  97.                 'active'  => 'ff1f1f',
  98.             ),
  99.         ),
  100.         array(
  101.             'latest' => array(
  102.                 'link'    => 'ff0000',
  103.                 'visited' => 'ff0000',
  104.                 'hover'   => 'ff0000',
  105.                 'active'  => 'ff0000',
  106.             ),
  107.         ),
  108.     );
  109.  
  110.     /**
  111.      * Stores the font-size unit, potentional values are: mm,cm,in,pt,pc,px,em
  112.      *
  113.      * @var    string 
  114.      * @access protected
  115.      */
  116.     protected $sizeSuffix = 'pt';
  117.  
  118.     /**
  119.      * Limits the range of generated font-sizes
  120.      *
  121.      * @var    int 
  122.      * @access protected
  123.      */
  124.     protected $fontSizeRange = 0;
  125.  
  126.     /**
  127.      * Defines the base font size
  128.      *
  129.      * @var    int 
  130.      * @access protected
  131.      */
  132.     protected $baseFontSize = 12;
  133. }
  134.  
  135. // }}}
  136.  
  137. // Create an instance of our extended HTML_TagCloud we prepared above
  138. $tags = new MyTags();
  139.  
  140. // Add Elements (same as TagCloud_example1.php)
  141. $tags->addElement('PHP''http://www.php.net'39strtotime('-1 day'));
  142. $tags->addElement('XML''http://www.xml.org'21strtotime('-2 week'));
  143. $tags->addElement('Perl''http://www.perl.org'15strtotime('-1 month'));
  144. $tags->addElement('PEAR''http://pear.php.net'32time());
  145. $tags->addElement('MySQL''http://www.mysql.com'10strtotime('-2 day'));
  146. $tags->addElement('PostgreSQL''http://pgsql.com'6strtotime('-3 week'));
  147.  
  148. // Print out HTML and CSS
  149. print $tags->buildALL();
  150.  
  151. // Show source, you don't need this line in your code, it's just for showing off
  152. ?>
  153. <br/>
  154. Take a look at the source:<br/>
  155. <?php
  156.  
  157. show_source(__FILE__);

Documentation generated on Wed, 02 Mar 2011 14:00:03 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.