cvs: pear /HTML_TagCloud TagCloud.php generatePackage.xml.php package.xml /HTML_TagCloud/docs/examples TagCloud_example1.php TagCloud_example2.php
TagCloud_example3.php
| From: | Shoma Suzuki | Date: | Sun, 01 Oct 2006 05:14:14 +0000 |
| Subject: | cvs: pear /HTML_TagCloud TagCloud.php generatePackage.xml.php package.xml /HTML_TagCloud/docs/examples TagCloud_example1.php TagCloud_example2.php TagCloud_example3.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42332@lists.php.net to get a copy of this message | ||
shomas Sun Oct 1 05:14:14 2006 UTC
Added files:
/pear/HTML_TagCloud TagCloud.php generatePackage.xml.php
package.xml
/pear/HTML_TagCloud/docs/examples TagCloud_example1.php
TagCloud_example2.php
TagCloud_example3.php
Log:
Initial release
http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/TagCloud.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/TagCloud.php +++ pear/HTML_TagCloud/TagCloud.php <?php /** * HTML Tag Cloud * * HTML_TagCloud enables you to generate a "tag cloud" in HTML. * * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category HTML * @package HTML_TagCloud * @author Shoma Suzuki <shoma@catbot.net> * @copyright 2006 Shoma Suzuki * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: TagCloud.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ * @see http://search.cpan.org/~lyokato/HTML-TagCloud-Extended-0.10/lib/HTML/TagCloud/Extended.pm * */ // {{{ class HTML_TagCloud class HTML_TagCloud { // {{{ class vars /** * @var int * @access protected */ protected $baseFontSize = 24; /** * @var int * @access protected */ protected $fontSizeRange = 12; /** * @var string * @access protected */ protected $cssClass = 'tagcloud'; /** * @var string * @access protected * mm,cm,in,pt,pc,px,em */ protected $sizeSuffix = 'px'; /** * @var array * @access protected */ protected $epocLevel = array( array( 'earliest' => array( 'link' => 'cccccc', 'visited' => 'cccccc', 'hover' => 'cccccc', 'active' => 'cccccc', ), ), array( 'earlier' => array( 'link' => '9999cc', 'visited' => '9999cc', 'hover' => '9999cc', 'active' => '9999cc', ), ), array( 'later' => array( 'link' => '9999ff', 'visited' => '9999ff', 'hover' => '9999ff', 'active' => '9999ff', ), ), array( 'latest' => array( 'link' => '0000ff', 'visited' => '0000ff', 'hover' => '0000ff', 'active' => '0000ff', ), ), ); /** * @var array * @access private */ private $_elements = array(); /** * @var int * @access private */ private $_max = 0; /** * @var int * @access private */ private $_min = 0; /** * @var int * @access private */ private $_maxEpoc; /** * @var int * @access private */ private $_minEpoc; /** * @var float * @access private */ private $_factor = 1; /** * @var float * @access private */ private $_epocFactor = 1; // }}} // {{{ public function __construct($baseFontSize = 24, $fontSizeRange = 12) /** * * Class constructor * * @param int $baseFontSize base font size of output tag (option) * @param int $fontSizeRange font size range * @access public */ public function __construct($baseFontSize = 24, $fontSizeRange = 12) { $this->baseFontSize = $baseFontSize; $this->fontSizeRange = $fontSizeRange; if ($this->baseFontSize - $this->fontSizeRange > 0){ $this->minFontSize = $this->baseFontSize - $this->fontSizeRange; } else { $this->minFontSize = 0; } $this->maxFontSize = $this->baseFontSize + $this->fontSizeRange; } // }}} // {{{ public function addElement($name = '', $url ='', $count = 0, $timestamp = null) /** * * add a Tag Element to build Tag Cloud * * @return void * @param string $tag * @param string $url * @param int $count * @param int $timestamp unixtimestamp * @access public */ public function addElement($name = '', $url ='', $count = 0, $timestamp = null) { $i = count($this->_elements); $this->_elements[$i]['name'] = $name; $this->_elements[$i]['url'] = $url; $this->_elements[$i]['count'] = $count; $this->_elements[$i]['timestamp'] = $timestamp == null ? time() : $timestamp; } // }}} // {{{ public function addElements($tags) /** * * add a Tag Element to build Tag Cloud * * @return void * @param array $tags Associative array to $this->_elements * @access public */ public function addElements($tags) { $this->_elements = array_merge($this->_elements, $tags); } // }}} // {{{ public function clearElements() /** * * clear Tag Elements * * @access public */ public function clearElements() { $this->_elements = array(); } // }}} // {{{ public function buildAll($param = array()) /** * * build HTML and CSS at once. * * @return string HTML and CSS * @param array $param * @see _buidHTMLTags * @access public */ public function buildAll($param = array()) { $html = '<style type="text/css">'."\n"; $html .= $this->buildCSS()."</style>\n"; $html .= $this->buildHTML($param); return $html; } // }}} // {{{ public function html_and_css($param = array()) /** * * Alias to buildAll. Compatibilities for Perl Module. * * @return string HTML and CSS * @param array $param 'limit' => int limit of generation tag num. * @access public */ public function html_and_css($param = array()) { return $this->buildAll($param); } // }}} // {{{ public function buildHTML($param = array()) /** * * build HTML part * * @return string HTML * @param array $param 'limit' => int limit of generation tag num. * @access public */ public function buildHTML($param = array()) { $htmltags = $this->_buidHTMLTags($param); return $this->_wrapDiv($htmltags); } // }}} // {{{ public function buildCSS() /** * * build CSS part * * @return string base CSS * @access public */ public function buildCSS() { $css = ''; foreach ($this->epocLevel as $item) { foreach ($item as $epocName => $colors) { foreach ($colors as $attr => $color) { $css .= "a.{$epocName}:{$attr} {text-decoration: none; color: #{$color};}\n"; } } } return $css; } // }}} // {{{ private function _buidHTMLTags($param) /** * * calc Tag level and create whole HTML of each Tags * * @return string HTML * @param array $param limit of Tag Number * @access private */ private function _buidHTMLTags($param) { $this->total = count($this->_elements); // no tags elements if ($this->total == 0) { return array(); } elseif ($this->total == 1) { $tag = $this->_elements[0]; return $this->_createHTMLTag($tag, 'latest', $this->baseFontSize); } $limit = array_key_exists('limit', $param) ? $param['limit'] : 0; $this->_sortTags($limit); $this->_calcMumCount(); $this->_calcMumEpoc(); $range = $this->maxFontSize - $this->minFontSize; if ($this->_max != $this->_min) { $this->_factor = $range / (sqrt($this->_max) - sqrt($this->_min)); } else { $this->_factor = 1; } if ($this->_maxEpoc != $this->_minEpoc) { $this->_epocFactor = count($this->epocLevel) / (sqrt($this->_maxEpoc) - sqrt($this->_minEpoc)); } else { $this->_epocFactor = 1; } $rtn = array(); foreach ($this->_elements as $tag) { $countLv = $this->_getCountLevel($tag['count']); if (! isset($tag['timestamp']) || empty($tag['timestamp'])) { $epocLv = count($this->epocLevel) - 1; } else { $epocLv = $this->_getEpocLevel($tag['timestamp']); } $colorType = $this->epocLevel[$epocLv]; $fontSize = $this->minFontSize + $countLv; $rtn[] = $this->_createHTMLTag($tag, key($colorType), $fontSize); } return implode("", $rtn); } // }}} // {{{ protected function _createHTMLTag($tag, $type, $fontSize) /** * * create a Element of HTML part * * @return string a Element of Tag HTML * @param array $tag * @param string $type css class of time line param * @param float $fontSize * @access protected */ protected function _createHTMLTag($tag, $type, $fontSize) { return '<a href="'. $tag['url'] . '" style="font-size: '. $fontSize . $this->sizeSuffix . ';" class="'. $type .'">' . htmlspecialchars($tag['name']) . '</a> '. "\n"; } // }}} // {{{ private function _sortTags($limit = 0) /** * * sort tags by name * * @return array * @param int $limit limit element number of create TagCloud * @access private */ private function _sortTags($limit = 0) { usort($this->_elements, array($this, "_cmpElementsName")); if ($limit != 0) { $this->_elements = array_splice($this->_elements, 0, $limit); } } // }}} // {{{ private function _cmpElementsName($a, $b) /** * * using for usort() * * @return int (bool) * @access public */ private function _cmpElementsName($a, $b) { if ($a['name'] == $b['name']) { return 0; } return ($a['name'] < $b['name']) ? -1 : 1; } // }}} // {{{ private function _calcMumCount() /** * * calc max and min tag count of use * * @access private */ private function _calcMumCount() { foreach ($this->_elements as $item) { $array[] = $item['count']; } $this->_min = min($array); $this->_max = max($array); } // }}} // {{{ private function _calcMumEpoc() /** * * calc max and min timestamp * * @access private */ private function _calcMumEpoc() { foreach ($this->_elements as $item) { $array[] = $item['timestamp']; } $this->_minEpoc = min($array); $this->_maxEpoc = max($array); } // }}} // {{{ private function _getCountLevel($count = 0) /** * * calc Tag Level of size * * @return int level * @param int $count * @access private */ private function _getCountLevel($count = 0) { return (int)(sqrt($count) - sqrt($this->_min) ) * $this->_factor; } // }}} // {{{ private function _getEpocLevel($timestamp = 0) /** * * calc timeline level of Tag * * @return int level of timeline * @param int $timestamp * @access private */ private function _getEpocLevel($timestamp = 0) { return (int) (sqrt($timestamp) - sqrt($this->_minEpoc)) * $this->_epocFactor; } // }}} // {{{ private function _wrapDiv($html) /** * * wrap div tag * * @return string * @param string $html * @access private */ private function _wrapDiv($html) { return $html == '' ? '' : '<div class="'.$this->cssClass .'">'.$html.'</div>'."\n"; } // }}} } // }}} /* * vim: set expandtab tabstop=4 shiftwidth=4 * vim600: foldmethod=marker * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */ ?> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/generatePackage.xml.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/generatePackage.xml.php +++ pear/HTML_TagCloud/generatePackage.xml.php <?php /* * A simple example * * @category PEAR * @package PEAR_PackageFileManager * @author Greg Beaver <cellog@php.net> * @copyright 2003-2006 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: generatePackage.xml.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ * @link http://pear.php.net/package/PEAR_PackageFileManager * @since File available since Release 0.1 * @ignore */ require_once 'PEAR/PackageFileManager.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); $test = new PEAR_PackageFileManager(); $test->setOptions(array( 'package' => 'HTML_TagCloud', 'summary' => 'generate a "tag cloud" in HTML', 'description' => 'HTML_TagCloud enables you to generate a "tag cloud" in HTML', 'baseinstalldir' => 'HTML', 'version' => '0.1.0', 'packagedirectory' => '/home/shouma/dev/php/pear/HTML_TagCloud-0.1.0', 'state' => 'beta', 'filelistgenerator' => 'file', 'notes' => 'First Release as PEAR Package', 'ignore' => array('package.xml', 'generatePackage.xml.php') )); $test->addDependency('PEAR', '1.1'); $test->addDependency('php', '5.0.0', 'ge', 'php'); $test->addMaintainer('shomas', 'lead', 'Shoma Suzuki', 'shoma@catbot.net'); $test->writePackageFile(); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/package.xml?view=markup&rev=1.1 Index: pear/HTML_TagCloud/package.xml +++ pear/HTML_TagCloud/package.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0" packagerversion="1.4.6"> <name>HTML_TagCloud</name> <summary>generate a "tag cloud" in HTML</summary> <description>HTML_TagCloud enables you to generate a "tag cloud" in HTML </description> <maintainers> <maintainer> <user>shomas</user> <name>Shoma Suzuki</name> <email>shoma@catbot.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1.0</version> <date>2006-08-02</date> <license>PHP License</license> <state>beta</state> <notes>First Release as PEAR Package </notes> <deps> <dep type="pkg" rel="ge" version="1.1" optional="no">PEAR</dep> <dep type="php" rel="ge" version="5.0.0" optional="no"/> </deps> <provides type="class" name="HTML_TagCloud" /> <provides type="function" name="HTML_TagCloud::addElement" /> <provides type="function" name="HTML_TagCloud::addElements" /> <provides type="function" name="HTML_TagCloud::clearElements" /> <provides type="function" name="HTML_TagCloud::buildAll" /> <provides type="function" name="HTML_TagCloud::html_and_css" /> <provides type="function" name="HTML_TagCloud::buildHTML" /> <provides type="function" name="HTML_TagCloud::buildCSS" /> <filelist> <file role="doc" baseinstalldir="HTML" name="docs/examples/TagCloud_example1.php"/> <file role="doc" baseinstalldir="HTML" name="docs/examples/TagCloud_example2.php"/> <file role="doc" baseinstalldir="HTML" name="docs/examples/TagCloud_example3.php"/> <file role="php" baseinstalldir="HTML" name="TagCloud.php"/> </filelist> </release> <changelog> <release> <version>0.1.0</version> <date>2006-08-02</date> <license>PHP License</license> <state>beta</state> <notes>First Release as PEAR Package </notes> </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/docs/examples/TagCloud_example1.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/docs/examples/TagCloud_example1.php +++ pear/HTML_TagCloud/docs/examples/TagCloud_example1.php <?php // $Id: TagCloud_example1.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ require_once 'HTML/TagCloud.php'; date_default_timezone_set('Asia/Tokyo'); $tags = new HTML_TagCloud(); // add Element $tags->addElement('PHP','http://www.php.net', 39, strtotime('-1 day')); $tags->addElement('XML','http://www.xml.org', 21, strtotime('-2 week')); $tags->addElement('Perl','http://www.xml.org', 15, strtotime('-1 month')); $tags->addElement('PEAR','http://pear.php.net', 32, time()); $tags->addElement('MySQL','http://www.mysql.com', 10, strtotime('-2 day')); $tags->addElement('PostgreSQL','http://pgsql.com', 6, strtotime('-3 week')); // output HTML and CSS print $tags->buildALL(); show_source(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/docs/examples/TagCloud_example2.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/docs/examples/TagCloud_example2.php +++ pear/HTML_TagCloud/docs/examples/TagCloud_example2.php <?php // $Id: TagCloud_example2.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ require_once 'HTML/TagCloud.php'; $basefontsize = 36; $fontsizerange = 24; // Tag size range in ($basefontsize - $fontsizerange) to ($basefontsize + $fontsizerange). $tags = new HTML_TagCloud($basefontsize, $fontsizerange); $name = 'a'; // set a item without timestamp foreach(range(0,15) as $i){ $arr[$i]['name'] = $name; $arr[$i]['url'] = '#'; $arr[$i]['count'] = $i; $name++; } // set many item at once by array $tags->addElements($arr); $tags->addElement('H', '#', 16); $tags->addElement('P', '#', 18); // CSS part only $css = $tags->buildCSS(); // html part only $taghtml = $tags->buildHTML(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title></title> <style type="text/css"> <?php print $css; ?> </style> </head> <body> <?php print $taghtml; ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/docs/examples/TagCloud_example3.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/docs/examples/TagCloud_example3.php +++ pear/HTML_TagCloud/docs/examples/TagCloud_example3.php <?php // $Id: TagCloud_example3.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ require_once 'HTML/TagCloud.php'; // {{{ class MyTags extends HTML_TagCloud{ /** * * OverRide protected class vars * * @author Shoma Suzuki <shoma@catbot.net> * @version $Id: TagCloud_example3.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ */ class MyTags extends HTML_TagCloud{ protected $epoc_level = array( array( 'earliest' => array( 'link' => 'ffdfdf', 'visited' => 'ffdfdf', 'hover' => 'ffdfdf', 'active' => 'ffdfdf', ), ), array( 'earlier' => array( 'link' => 'ff7f7f', 'visited' => 'ff7f7f', 'hover' => 'ff7f7f', 'active' => 'ff7f7f', ), ), array( 'previous' => array( 'link' => 'ff7f7f', 'visited' => 'ff7f7f', 'hover' => 'ff7f7f', 'active' => 'ff7f7f', ), ), array( 'recent' => array( 'link' => 'ff4f4f', 'visited' => 'ff4f4f', 'hover' => 'ff4f4f', 'active' => 'ff4f4f', ), ), array( 'later' => array( 'link' => 'ff1f1f', 'visited' => 'ff1f1f', 'hover' => 'ff1f1f', 'active' => 'ff1f1f', ), ), array( 'latest' => array( 'link' => 'ff0000', 'visited' => 'ff0000', 'hover' => 'ff0000', 'active' => 'ff0000', ), ), ); protected $size_suffix = 'pt'; protected $fontsizerange = 0; protected $basefontsize = 12; } // }}} date_default_timezone_set('Asia/Tokyo'); $tags = new MyTags(); // below same as example2 // add Element $tags->addElement('PHP','http://www.php.net', 39, strtotime('-1 day')); $tags->addElement('XML','http://www.xml.org', 21, strtotime('-2 week')); $tags->addElement('Perl','http://www.xml.org', 15, strtotime('-1 month')); $tags->addElement('PEAR','http://pear.php.net', 32, time()); $tags->addElement('MySQL','http://www.mysql.com', 10, strtotime('-2 day')); $tags->addElement('PostgreSQL','http://pgsql.com', 6, strtotime('-3 week')); // output HTML and CSS print $tags->buildALL(); show_source(__FILE__); ?>
http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/TagCloud.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/TagCloud.php +++ pear/HTML_TagCloud/TagCloud.php <?php /** * HTML Tag Cloud * * HTML_TagCloud enables you to generate a "tag cloud" in HTML. * * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category HTML * @package HTML_TagCloud * @author Shoma Suzuki <shoma@catbot.net> * @copyright 2006 Shoma Suzuki * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: TagCloud.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ * @see http://search.cpan.org/~lyokato/HTML-TagCloud-Extended-0.10/lib/HTML/TagCloud/Extended.pm * */ // {{{ class HTML_TagCloud class HTML_TagCloud { // {{{ class vars /** * @var int * @access protected */ protected $baseFontSize = 24; /** * @var int * @access protected */ protected $fontSizeRange = 12; /** * @var string * @access protected */ protected $cssClass = 'tagcloud'; /** * @var string * @access protected * mm,cm,in,pt,pc,px,em */ protected $sizeSuffix = 'px'; /** * @var array * @access protected */ protected $epocLevel = array( array( 'earliest' => array( 'link' => 'cccccc', 'visited' => 'cccccc', 'hover' => 'cccccc', 'active' => 'cccccc', ), ), array( 'earlier' => array( 'link' => '9999cc', 'visited' => '9999cc', 'hover' => '9999cc', 'active' => '9999cc', ), ), array( 'later' => array( 'link' => '9999ff', 'visited' => '9999ff', 'hover' => '9999ff', 'active' => '9999ff', ), ), array( 'latest' => array( 'link' => '0000ff', 'visited' => '0000ff', 'hover' => '0000ff', 'active' => '0000ff', ), ), ); /** * @var array * @access private */ private $_elements = array(); /** * @var int * @access private */ private $_max = 0; /** * @var int * @access private */ private $_min = 0; /** * @var int * @access private */ private $_maxEpoc; /** * @var int * @access private */ private $_minEpoc; /** * @var float * @access private */ private $_factor = 1; /** * @var float * @access private */ private $_epocFactor = 1; // }}} // {{{ public function __construct($baseFontSize = 24, $fontSizeRange = 12) /** * * Class constructor * * @param int $baseFontSize base font size of output tag (option) * @param int $fontSizeRange font size range * @access public */ public function __construct($baseFontSize = 24, $fontSizeRange = 12) { $this->baseFontSize = $baseFontSize; $this->fontSizeRange = $fontSizeRange; if ($this->baseFontSize - $this->fontSizeRange > 0){ $this->minFontSize = $this->baseFontSize - $this->fontSizeRange; } else { $this->minFontSize = 0; } $this->maxFontSize = $this->baseFontSize + $this->fontSizeRange; } // }}} // {{{ public function addElement($name = '', $url ='', $count = 0, $timestamp = null) /** * * add a Tag Element to build Tag Cloud * * @return void * @param string $tag * @param string $url * @param int $count * @param int $timestamp unixtimestamp * @access public */ public function addElement($name = '', $url ='', $count = 0, $timestamp = null) { $i = count($this->_elements); $this->_elements[$i]['name'] = $name; $this->_elements[$i]['url'] = $url; $this->_elements[$i]['count'] = $count; $this->_elements[$i]['timestamp'] = $timestamp == null ? time() : $timestamp; } // }}} // {{{ public function addElements($tags) /** * * add a Tag Element to build Tag Cloud * * @return void * @param array $tags Associative array to $this->_elements * @access public */ public function addElements($tags) { $this->_elements = array_merge($this->_elements, $tags); } // }}} // {{{ public function clearElements() /** * * clear Tag Elements * * @access public */ public function clearElements() { $this->_elements = array(); } // }}} // {{{ public function buildAll($param = array()) /** * * build HTML and CSS at once. * * @return string HTML and CSS * @param array $param * @see _buidHTMLTags * @access public */ public function buildAll($param = array()) { $html = '<style type="text/css">'."\n"; $html .= $this->buildCSS()."</style>\n"; $html .= $this->buildHTML($param); return $html; } // }}} // {{{ public function html_and_css($param = array()) /** * * Alias to buildAll. Compatibilities for Perl Module. * * @return string HTML and CSS * @param array $param 'limit' => int limit of generation tag num. * @access public */ public function html_and_css($param = array()) { return $this->buildAll($param); } // }}} // {{{ public function buildHTML($param = array()) /** * * build HTML part * * @return string HTML * @param array $param 'limit' => int limit of generation tag num. * @access public */ public function buildHTML($param = array()) { $htmltags = $this->_buidHTMLTags($param); return $this->_wrapDiv($htmltags); } // }}} // {{{ public function buildCSS() /** * * build CSS part * * @return string base CSS * @access public */ public function buildCSS() { $css = ''; foreach ($this->epocLevel as $item) { foreach ($item as $epocName => $colors) { foreach ($colors as $attr => $color) { $css .= "a.{$epocName}:{$attr} {text-decoration: none; color: #{$color};}\n"; } } } return $css; } // }}} // {{{ private function _buidHTMLTags($param) /** * * calc Tag level and create whole HTML of each Tags * * @return string HTML * @param array $param limit of Tag Number * @access private */ private function _buidHTMLTags($param) { $this->total = count($this->_elements); // no tags elements if ($this->total == 0) { return array(); } elseif ($this->total == 1) { $tag = $this->_elements[0]; return $this->_createHTMLTag($tag, 'latest', $this->baseFontSize); } $limit = array_key_exists('limit', $param) ? $param['limit'] : 0; $this->_sortTags($limit); $this->_calcMumCount(); $this->_calcMumEpoc(); $range = $this->maxFontSize - $this->minFontSize; if ($this->_max != $this->_min) { $this->_factor = $range / (sqrt($this->_max) - sqrt($this->_min)); } else { $this->_factor = 1; } if ($this->_maxEpoc != $this->_minEpoc) { $this->_epocFactor = count($this->epocLevel) / (sqrt($this->_maxEpoc) - sqrt($this->_minEpoc)); } else { $this->_epocFactor = 1; } $rtn = array(); foreach ($this->_elements as $tag) { $countLv = $this->_getCountLevel($tag['count']); if (! isset($tag['timestamp']) || empty($tag['timestamp'])) { $epocLv = count($this->epocLevel) - 1; } else { $epocLv = $this->_getEpocLevel($tag['timestamp']); } $colorType = $this->epocLevel[$epocLv]; $fontSize = $this->minFontSize + $countLv; $rtn[] = $this->_createHTMLTag($tag, key($colorType), $fontSize); } return implode("", $rtn); } // }}} // {{{ protected function _createHTMLTag($tag, $type, $fontSize) /** * * create a Element of HTML part * * @return string a Element of Tag HTML * @param array $tag * @param string $type css class of time line param * @param float $fontSize * @access protected */ protected function _createHTMLTag($tag, $type, $fontSize) { return '<a href="'. $tag['url'] . '" style="font-size: '. $fontSize . $this->sizeSuffix . ';" class="'. $type .'">' . htmlspecialchars($tag['name']) . '</a> '. "\n"; } // }}} // {{{ private function _sortTags($limit = 0) /** * * sort tags by name * * @return array * @param int $limit limit element number of create TagCloud * @access private */ private function _sortTags($limit = 0) { usort($this->_elements, array($this, "_cmpElementsName")); if ($limit != 0) { $this->_elements = array_splice($this->_elements, 0, $limit); } } // }}} // {{{ private function _cmpElementsName($a, $b) /** * * using for usort() * * @return int (bool) * @access public */ private function _cmpElementsName($a, $b) { if ($a['name'] == $b['name']) { return 0; } return ($a['name'] < $b['name']) ? -1 : 1; } // }}} // {{{ private function _calcMumCount() /** * * calc max and min tag count of use * * @access private */ private function _calcMumCount() { foreach ($this->_elements as $item) { $array[] = $item['count']; } $this->_min = min($array); $this->_max = max($array); } // }}} // {{{ private function _calcMumEpoc() /** * * calc max and min timestamp * * @access private */ private function _calcMumEpoc() { foreach ($this->_elements as $item) { $array[] = $item['timestamp']; } $this->_minEpoc = min($array); $this->_maxEpoc = max($array); } // }}} // {{{ private function _getCountLevel($count = 0) /** * * calc Tag Level of size * * @return int level * @param int $count * @access private */ private function _getCountLevel($count = 0) { return (int)(sqrt($count) - sqrt($this->_min) ) * $this->_factor; } // }}} // {{{ private function _getEpocLevel($timestamp = 0) /** * * calc timeline level of Tag * * @return int level of timeline * @param int $timestamp * @access private */ private function _getEpocLevel($timestamp = 0) { return (int) (sqrt($timestamp) - sqrt($this->_minEpoc)) * $this->_epocFactor; } // }}} // {{{ private function _wrapDiv($html) /** * * wrap div tag * * @return string * @param string $html * @access private */ private function _wrapDiv($html) { return $html == '' ? '' : '<div class="'.$this->cssClass .'">'.$html.'</div>'."\n"; } // }}} } // }}} /* * vim: set expandtab tabstop=4 shiftwidth=4 * vim600: foldmethod=marker * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */ ?> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/generatePackage.xml.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/generatePackage.xml.php +++ pear/HTML_TagCloud/generatePackage.xml.php <?php /* * A simple example * * @category PEAR * @package PEAR_PackageFileManager * @author Greg Beaver <cellog@php.net> * @copyright 2003-2006 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: generatePackage.xml.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ * @link http://pear.php.net/package/PEAR_PackageFileManager * @since File available since Release 0.1 * @ignore */ require_once 'PEAR/PackageFileManager.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); $test = new PEAR_PackageFileManager(); $test->setOptions(array( 'package' => 'HTML_TagCloud', 'summary' => 'generate a "tag cloud" in HTML', 'description' => 'HTML_TagCloud enables you to generate a "tag cloud" in HTML', 'baseinstalldir' => 'HTML', 'version' => '0.1.0', 'packagedirectory' => '/home/shouma/dev/php/pear/HTML_TagCloud-0.1.0', 'state' => 'beta', 'filelistgenerator' => 'file', 'notes' => 'First Release as PEAR Package', 'ignore' => array('package.xml', 'generatePackage.xml.php') )); $test->addDependency('PEAR', '1.1'); $test->addDependency('php', '5.0.0', 'ge', 'php'); $test->addMaintainer('shomas', 'lead', 'Shoma Suzuki', 'shoma@catbot.net'); $test->writePackageFile(); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/package.xml?view=markup&rev=1.1 Index: pear/HTML_TagCloud/package.xml +++ pear/HTML_TagCloud/package.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0" packagerversion="1.4.6"> <name>HTML_TagCloud</name> <summary>generate a "tag cloud" in HTML</summary> <description>HTML_TagCloud enables you to generate a "tag cloud" in HTML </description> <maintainers> <maintainer> <user>shomas</user> <name>Shoma Suzuki</name> <email>shoma@catbot.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1.0</version> <date>2006-08-02</date> <license>PHP License</license> <state>beta</state> <notes>First Release as PEAR Package </notes> <deps> <dep type="pkg" rel="ge" version="1.1" optional="no">PEAR</dep> <dep type="php" rel="ge" version="5.0.0" optional="no"/> </deps> <provides type="class" name="HTML_TagCloud" /> <provides type="function" name="HTML_TagCloud::addElement" /> <provides type="function" name="HTML_TagCloud::addElements" /> <provides type="function" name="HTML_TagCloud::clearElements" /> <provides type="function" name="HTML_TagCloud::buildAll" /> <provides type="function" name="HTML_TagCloud::html_and_css" /> <provides type="function" name="HTML_TagCloud::buildHTML" /> <provides type="function" name="HTML_TagCloud::buildCSS" /> <filelist> <file role="doc" baseinstalldir="HTML" name="docs/examples/TagCloud_example1.php"/> <file role="doc" baseinstalldir="HTML" name="docs/examples/TagCloud_example2.php"/> <file role="doc" baseinstalldir="HTML" name="docs/examples/TagCloud_example3.php"/> <file role="php" baseinstalldir="HTML" name="TagCloud.php"/> </filelist> </release> <changelog> <release> <version>0.1.0</version> <date>2006-08-02</date> <license>PHP License</license> <state>beta</state> <notes>First Release as PEAR Package </notes> </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/docs/examples/TagCloud_example1.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/docs/examples/TagCloud_example1.php +++ pear/HTML_TagCloud/docs/examples/TagCloud_example1.php <?php // $Id: TagCloud_example1.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ require_once 'HTML/TagCloud.php'; date_default_timezone_set('Asia/Tokyo'); $tags = new HTML_TagCloud(); // add Element $tags->addElement('PHP','http://www.php.net', 39, strtotime('-1 day')); $tags->addElement('XML','http://www.xml.org', 21, strtotime('-2 week')); $tags->addElement('Perl','http://www.xml.org', 15, strtotime('-1 month')); $tags->addElement('PEAR','http://pear.php.net', 32, time()); $tags->addElement('MySQL','http://www.mysql.com', 10, strtotime('-2 day')); $tags->addElement('PostgreSQL','http://pgsql.com', 6, strtotime('-3 week')); // output HTML and CSS print $tags->buildALL(); show_source(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/docs/examples/TagCloud_example2.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/docs/examples/TagCloud_example2.php +++ pear/HTML_TagCloud/docs/examples/TagCloud_example2.php <?php // $Id: TagCloud_example2.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ require_once 'HTML/TagCloud.php'; $basefontsize = 36; $fontsizerange = 24; // Tag size range in ($basefontsize - $fontsizerange) to ($basefontsize + $fontsizerange). $tags = new HTML_TagCloud($basefontsize, $fontsizerange); $name = 'a'; // set a item without timestamp foreach(range(0,15) as $i){ $arr[$i]['name'] = $name; $arr[$i]['url'] = '#'; $arr[$i]['count'] = $i; $name++; } // set many item at once by array $tags->addElements($arr); $tags->addElement('H', '#', 16); $tags->addElement('P', '#', 18); // CSS part only $css = $tags->buildCSS(); // html part only $taghtml = $tags->buildHTML(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title></title> <style type="text/css"> <?php print $css; ?> </style> </head> <body> <?php print $taghtml; ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_TagCloud/docs/examples/TagCloud_example3.php?view=markup&rev=1.1 Index: pear/HTML_TagCloud/docs/examples/TagCloud_example3.php +++ pear/HTML_TagCloud/docs/examples/TagCloud_example3.php <?php // $Id: TagCloud_example3.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ require_once 'HTML/TagCloud.php'; // {{{ class MyTags extends HTML_TagCloud{ /** * * OverRide protected class vars * * @author Shoma Suzuki <shoma@catbot.net> * @version $Id: TagCloud_example3.php,v 1.1 2006/10/01 05:14:14 shomas Exp $ */ class MyTags extends HTML_TagCloud{ protected $epoc_level = array( array( 'earliest' => array( 'link' => 'ffdfdf', 'visited' => 'ffdfdf', 'hover' => 'ffdfdf', 'active' => 'ffdfdf', ), ), array( 'earlier' => array( 'link' => 'ff7f7f', 'visited' => 'ff7f7f', 'hover' => 'ff7f7f', 'active' => 'ff7f7f', ), ), array( 'previous' => array( 'link' => 'ff7f7f', 'visited' => 'ff7f7f', 'hover' => 'ff7f7f', 'active' => 'ff7f7f', ), ), array( 'recent' => array( 'link' => 'ff4f4f', 'visited' => 'ff4f4f', 'hover' => 'ff4f4f', 'active' => 'ff4f4f', ), ), array( 'later' => array( 'link' => 'ff1f1f', 'visited' => 'ff1f1f', 'hover' => 'ff1f1f', 'active' => 'ff1f1f', ), ), array( 'latest' => array( 'link' => 'ff0000', 'visited' => 'ff0000', 'hover' => 'ff0000', 'active' => 'ff0000', ), ), ); protected $size_suffix = 'pt'; protected $fontsizerange = 0; protected $basefontsize = 12; } // }}} date_default_timezone_set('Asia/Tokyo'); $tags = new MyTags(); // below same as example2 // add Element $tags->addElement('PHP','http://www.php.net', 39, strtotime('-1 day')); $tags->addElement('XML','http://www.xml.org', 21, strtotime('-2 week')); $tags->addElement('Perl','http://www.xml.org', 15, strtotime('-1 month')); $tags->addElement('PEAR','http://pear.php.net', 32, time()); $tags->addElement('MySQL','http://www.mysql.com', 10, strtotime('-2 day')); $tags->addElement('PostgreSQL','http://pgsql.com', 6, strtotime('-3 week')); // output HTML and CSS print $tags->buildALL(); show_source(__FILE__); ?>