Overview

Packages

  • Auth
  • Core
  • Horde
    • Imsp
  • None
  • Notification

Classes

  • Horde
  • Horde_Config
  • Horde_Config_Form
  • Horde_Core_ActiveSync_Connector
  • Horde_Core_ActiveSync_Driver
  • Horde_Core_Ajax_Application
  • Horde_Core_Ajax_Imple
  • Horde_Core_Ajax_Imple_AutoCompleter
  • Horde_Core_Ajax_Imple_Geocoder_Geonames
  • Horde_Core_Ajax_Imple_SpellChecker
  • Horde_Core_Alarm_Handler_Notify
  • Horde_Core_Auth_Application
  • Horde_Core_Auth_Composite
  • Horde_Core_Auth_Ldap
  • Horde_Core_Auth_Msad
  • Horde_Core_Auth_Shibboleth
  • Horde_Core_Auth_Signup_Base
  • Horde_Core_Auth_Signup_Form
  • Horde_Core_Auth_Signup_Null
  • Horde_Core_Auth_Signup_Sql
  • Horde_Core_Auth_Signup_SqlObject
  • Horde_Core_Autoloader_Callback_Mime
  • Horde_Core_Autoloader_Callback_Nls
  • Horde_Core_Block
  • Horde_Core_Block_Collection
  • Horde_Core_Block_Layout
  • Horde_Core_Block_Layout_Manager
  • Horde_Core_Block_Layout_View
  • Horde_Core_Block_Upgrade
  • Horde_Core_Browser
  • Horde_Core_Bundle
  • Horde_Core_Cli
  • Horde_Core_Controller_NotFound
  • Horde_Core_Controller_RequestConfiguration
  • Horde_Core_Controller_RequestMapper
  • Horde_Core_Controller_SettingsFinder
  • Horde_Core_Db_Migration
  • Horde_Core_Factory_ActiveSyncBackend
  • Horde_Core_Factory_ActiveSyncServer
  • Horde_Core_Factory_ActiveSyncState
  • Horde_Core_Factory_Ajax
  • Horde_Core_Factory_Alarm
  • Horde_Core_Factory_Auth
  • Horde_Core_Factory_AuthSignup
  • Horde_Core_Factory_Base
  • Horde_Core_Factory_BlockCollection
  • Horde_Core_Factory_Browser
  • Horde_Core_Factory_Cache
  • Horde_Core_Factory_Crypt
  • Horde_Core_Factory_Data
  • Horde_Core_Factory_Db
  • Horde_Core_Factory_DbBase
  • Horde_Core_Factory_DbPear
  • Horde_Core_Factory_Dns
  • Horde_Core_Factory_Editor
  • Horde_Core_Factory_Facebook
  • Horde_Core_Factory_Group
  • Horde_Core_Factory_History
  • Horde_Core_Factory_HttpClient
  • Horde_Core_Factory_Identity
  • Horde_Core_Factory_Image
  • Horde_Core_Factory_Imple
  • Horde_Core_Factory_Imsp
  • Horde_Core_Factory_ImspAuth
  • Horde_Core_Factory_Injector
  • Horde_Core_Factory_KolabServer
  • Horde_Core_Factory_KolabSession
  • Horde_Core_Factory_KolabStorage
  • Horde_Core_Factory_Ldap
  • Horde_Core_Factory_Lock
  • Horde_Core_Factory_Logger
  • Horde_Core_Factory_LoginTasks
  • Horde_Core_Factory_Mail
  • Horde_Core_Factory_Mapper
  • Horde_Core_Factory_Matcher
  • Horde_Core_Factory_Memcache
  • Horde_Core_Factory_MimeViewer
  • Horde_Core_Factory_Notification
  • Horde_Core_Factory_Perms
  • Horde_Core_Factory_PermsCore
  • Horde_Core_Factory_Prefs
  • Horde_Core_Factory_Request
  • Horde_Core_Factory_Secret
  • Horde_Core_Factory_SessionHandler
  • Horde_Core_Factory_Share
  • Horde_Core_Factory_ShareBase
  • Horde_Core_Factory_Template
  • Horde_Core_Factory_TextFilter
  • Horde_Core_Factory_ThemesCache
  • Horde_Core_Factory_Token
  • Horde_Core_Factory_Tree
  • Horde_Core_Factory_Twitter
  • Horde_Core_Factory_UrlShortener
  • Horde_Core_Factory_Vfs
  • Horde_Core_Factory_View
  • Horde_Core_Factory_Weather
  • Horde_Core_Group_Ldap
  • Horde_Core_Log_Logger
  • Horde_Core_LoginTasks
  • Horde_Core_LoginTasks_Backend_Horde
  • Horde_Core_LoginTasks_SystemTask_Upgrade
  • Horde_Core_Mime_Viewer_Syntaxhighlighter
  • Horde_Core_Mime_Viewer_Vcard
  • Horde_Core_Notification_Event_Status
  • Horde_Core_Notification_Handler_Decorator_Hordelog
  • Horde_Core_Notification_Storage_Session
  • Horde_Core_Perms
  • Horde_Core_Perms_Ui
  • Horde_Core_Prefs_Cache_Session
  • Horde_Core_Prefs_Identity
  • Horde_Core_Prefs_Storage_Configuration
  • Horde_Core_Prefs_Storage_Hooks
  • Horde_Core_Prefs_Storage_Upgrade
  • Horde_Core_Prefs_Ui
  • Horde_Core_Prefs_Ui_Widgets
  • Horde_Core_Share_Driver
  • Horde_Core_Share_FactoryCallback
  • Horde_Core_Sidebar
  • Horde_Core_Text_Filter_Bbcode
  • Horde_Core_Text_Filter_Emails
  • Horde_Core_Text_Filter_Emoticons
  • Horde_Core_Text_Filter_Highlightquotes
  • Horde_Core_Translation
  • Horde_Core_Tree_Html
  • Horde_Core_Tree_Javascript
  • Horde_Core_Tree_Simplehtml
  • Horde_Core_Ui_FlagImage
  • Horde_Core_Ui_JsCalendar
  • Horde_Core_Ui_Language
  • Horde_Core_Ui_Layout
  • Horde_Core_Ui_ModalFormRenderer
  • Horde_Core_Ui_Pager
  • Horde_Core_Ui_Tabs
  • Horde_Core_Ui_TagCloud
  • Horde_Core_Ui_VarRenderer
  • Horde_Core_Ui_VarRenderer_Html
  • Horde_Core_Ui_VarRenderer_TablesetHtml
  • Horde_Core_Ui_Widget
  • Horde_ErrorHandler
  • Horde_Help
  • Horde_Menu
  • Horde_Registry
  • Horde_Registry_Api
  • Horde_Registry_Application
  • Horde_Registry_Caller
  • Horde_Registry_Nlsconfig
  • Horde_Script_Files
  • Horde_Session
  • Horde_Session_Null
  • Horde_Themes
  • Horde_Themes_Cache
  • Horde_Themes_Css
  • Horde_Themes_Element
  • Horde_Themes_Image
  • Horde_Themes_Sound

Exceptions

  • Horde_Exception_HookNotSet
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Horde_Core_Ui_TagCloud:: for creating and displaying tag clouds.
  4:  *
  5:  * Based on a striped down version of Pear's HTML_TagCloud
  6:  *
  7:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  8:  *
  9:  * See the enclosed file COPYING for license information (LGPL). If you
 10:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 11:  *
 12:  * @category Horde
 13:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 14:  * @package  Core
 15:  */
 16: class Horde_Core_Ui_TagCloud
 17: {
 18:     /**
 19:      * @var integer
 20:      */
 21:     public $basefontsize = 24;
 22: 
 23:     /**
 24:      * @var integer
 25:      */
 26:     public $fontsizerange = 12;
 27: 
 28:     /**
 29:      * @var string
 30:      */
 31:     public $css_class = 'tagcloud';
 32: 
 33:     /**
 34:      * @var    string
 35:      * mm,cm,in,pt,pc,px,em
 36:      */
 37:     public $size_suffix = 'px';
 38: 
 39:     /**
 40:      * @var integer
 41:      */
 42:     public $factor;
 43: 
 44:     /**
 45:      * @var array
 46:      */
 47:     public $epoc_level = array(
 48:         'earliest',
 49:         'earlier',
 50:         'later',
 51:         'latest'
 52:     );
 53: 
 54:     /**
 55:      * @var array
 56:      */
 57:     protected $_elements = array();
 58: 
 59:     /**
 60:      * @var integer
 61:      */
 62:     protected $_max = 0;
 63: 
 64:     /**
 65:      * @var integer
 66:      */
 67:     protected $_min = 0;
 68: 
 69:     /**
 70:      * @var integer
 71:      */
 72:     protected $_max_epoc;
 73: 
 74:     /**
 75:      * @var integer
 76:      */
 77:     protected $_min_epoc;
 78: 
 79:     /**
 80:      * @var array
 81:      */
 82:     protected $_map = array();
 83: 
 84:     /**
 85:      * Constructor
 86:      *
 87:      * @param integer $basefontsize   Base font size of output tag (option).
 88:      * @param integer $fontsizerange  Font size range.
 89:      */
 90:     public function __construct($basefontsize = 24, $fontsizerange = 12)
 91:     {
 92:         $this->basefontsize = $basefontsize;
 93:         $this->minfontsize = max($this->basefontsize - $this->fontsizerange, 0);
 94:         $this->maxfontsize = $this->basefontsize + $this->fontsizerange;
 95:     }
 96: 
 97:     /**
 98:      * Add a Tag Element to build Tag Cloud.
 99:      *
100:      * @param string $tag         TODO
101:      * @param string $url         TODO
102:      * @param integer $count      TODO
103:      * @param integer $timestamp  UNIX timestamp.
104:      * @param string $onclick     Javascript onclick event handler.
105:      */
106:     public function addElement($name, $url ='', $count = 0, $timestamp = null,
107:                                $onclick = null)
108:     {
109: 
110:         if (isset($this->_map[$name])) {
111:             $i = $this->_map[$name];
112:             // Increase the count
113:             $this->_elements[$i]['count'] += $count;
114: 
115:             // Keep the latest timestamp
116:             if (!empty($timestamp) &&
117:                 $timestamp > $this->_elements[$i]['timestamp']) {
118:                 $this->_elements[$i]['timestamp'] = $timestamp;
119:             }
120:             // For onclick and url we will simply overwrite the existing values
121:             // instead of checking if they are empty, then overwriting.
122:             $this->_elements[$i]['onclick'] = $onclick;
123:             $this->elements[$i]['url'] = $url;
124:         } else {
125:             $i = count($this->_elements);
126:             $this->_elements[$i]['name'] = $name;
127:             $this->_elements[$i]['url'] = $url;
128:             $this->_elements[$i]['count'] = $count;
129:             $this->_elements[$i]['timestamp'] = $timestamp == null ? time() : $timestamp;
130:             $this->_elements[$i]['onclick'] = $onclick;
131:             $this->_map[$name] = $i;
132:         }
133:     }
134: 
135:     /**
136:      * Add a Tag Element to build Tag Cloud.
137:      *
138:      * @param array $tags  Associative array to $this->_elements.
139:      */
140:     public function addElements($tags)
141:     {
142:         $this->_elements = array_merge($this->_elements, $tags);
143:     }
144: 
145:     /**
146:      * Clear Tag Elements.
147:      */
148:     public function clearElements()
149:     {
150:         $this->_elements = array();
151:     }
152: 
153:     /**
154:      * Build HTML part.
155:      *
156:      * @param array $param  'limit' => int limit of generation tag num.
157:      *
158:      * @return string   HTML
159:      */
160:     public function buildHTML($param = array())
161:     {
162:         return $this->_wrapDiv($this->_buidHTMLTags($param));
163:     }
164: 
165:     /**
166:      * Calc Tag level and create whole HTML of each Tags.
167:      *
168:      * @param array $param  Limit of Tag Number.
169:      *
170:      * @return string  HTML
171:      */
172:     protected function _buidHTMLTags($param)
173:     {
174:         $this->total = count($this->_elements);
175:         // no tags elements
176:         if ($this->total == 0) {
177:             return '';
178:         } elseif ($this->total == 1) {
179:             $tag = $this->_elements[0];
180:             return $this->_createHTMLTag($tag, 'latest', $this->basefontsize);
181:         }
182: 
183:         $limit = array_key_exists('limit', $param) ? $param['limit'] : 0;
184:         $this->_sortTags($limit);
185:         $this->_calcMumCount();
186:         $this->_calcMumEpoc();
187: 
188:         $range = $this->maxfontsize - $this->minfontsize;
189:         $this->factor = ($this->_max == $this->_min)
190:             ? 1
191:             : $range / (sqrt($this->_max) - sqrt($this->_min));
192:         $this->epoc_factor = ($this->_max_epoc == $this->_min_epoc)
193:             ? 1
194:             : count($this->epoc_level) / (sqrt($this->_max_epoc) - sqrt($this->_min_epoc));
195:         $rtn = array();
196:         foreach ($this->_elements as $tag){
197:             $count_lv = $this->_getCountLevel($tag['count']);
198:             if (!isset($tag['timestamp']) || empty($tag['timestamp'])) {
199:                 $epoc_lv = count($this->epoc_level) - 1;
200:             } else {
201:                 $epoc_lv = $this->_getEpocLevel($tag['timestamp']);
202:             }
203:             $color_type = $this->epoc_level[$epoc_lv];
204:             $font_size  = $this->minfontsize + $count_lv;
205:             $rtn[] = $this->_createHTMLTag($tag, $color_type, $font_size);
206:         }
207:         return implode('', $rtn);
208:     }
209: 
210:     /**
211:      * Create a Element of HTML part.
212:      *
213:      * @param array $tag         TODO
214:      * @param string $type       CSS class of time line param.
215:      * @param integer $fontsize  TODO
216:      *
217:      * @return  string a Element of Tag HTML
218:      */
219:     protected function _createHTMLTag($tag, $type, $fontsize)
220:     {
221:         return sprintf('<a style="font-size:%d%s" class="%s" href="%s"%s>%s</a>' . "\n",
222:                        $fontsize,
223:                        $this->size_suffix,
224:                        $type,
225:                        $tag['url'],
226:                        (empty($tag['onclick']) ? '' : ' onclick="' . $tag['onclick'] . '"'),
227:                        htmlspecialchars($tag['name']));
228:     }
229: 
230:     /**
231:      * Sort tags by name.
232:      *
233:      * @param integer $limit  Limit element number of create TagCloud.
234:      */
235:     protected function _sortTags($limit = 0)
236:     {
237:         usort($this->_elements, array($this, 'cmpElementsName'));
238:         if ($limit != 0){
239:             $this->_elements = array_splice($this->_elements, 0, $limit);
240:         }
241:     }
242: 
243:     /**
244:      * Using for usort().
245:      *
246:      * @return integer  TODO
247:      */
248:     public function cmpElementsName($a, $b)
249:     {
250:         return ($a['name'] == $b['name'])
251:             ? 0
252:             : (($a['name'] < $b['name']) ? -1 : 1);
253:     }
254: 
255:     /**
256:      * Calc max and min tag count of use.
257:      */
258:     protected function _calcMumCount()
259:     {
260:         foreach($this->_elements as $item){
261:             $array[] = $item['count'];
262:         }
263:         $this->_min = min($array);
264:         $this->_max = max($array);
265:     }
266: 
267:     /**
268:      * Calc max and min timestamp.
269:      */
270:     protected function _calcMumEpoc()
271:     {
272:         foreach($this->_elements as $item){
273:             $array[] = $item['timestamp'];
274:         }
275:         $this->_min_epoc = min($array);
276:         $this->_max_epoc = max($array);
277:     }
278: 
279:     /**
280:      * Calc Tag Level of size.
281:      *
282:      * @param integer $count  TODO
283:      *
284:      * @return integer  Level.
285:      */
286:     protected function _getCountLevel($count = 0)
287:     {
288:         return (int)((sqrt($count) - sqrt($this->_min)) * $this->factor);
289:     }
290: 
291:     /**
292:      * Calc timeline level of Tag.
293:      *
294:      * @param integer $timestamp  TODO
295:      *
296:      * @return integer  Level of timeline.
297:      */
298:     protected function _getEpocLevel($timestamp = 0)
299:     {
300:         return (int)((sqrt($timestamp) - sqrt($this->_min_epoc)) * $this->epoc_factor);
301:     }
302: 
303:     /**
304:      * Wrap div tag.
305:      *
306:      * @param string $html  TODO
307:      *
308:      * @return string  TODO
309:      */
310:     protected function _wrapDiv($html)
311:     {
312:         return ($html == '')
313:             ? ''
314:             : sprintf("<div class=\"%s\">\n%s</div>\n", $this->css_class, $html);
315:     }
316: 
317: }
318: 
API documentation generated by ApiGen