b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_coll_tag_cloud.widget.php - 266 lines - 6775 bytes - Summary - Text - Print

Description: This file implements the xyz Widget class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the xyz Widget class.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * @package evocore
  20   *
  21   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  22   * @author fplanque: Francois PLANQUE.
  23   *
  24   * @version $Id: _coll_tag_cloud.widget.php 6136 2014-03-08 07:59:48Z manuel $
  25   */
  26  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  27  
  28  load_class( 'widgets/model/_widget.class.php', 'ComponentWidget' );
  29  
  30  /**
  31   * ComponentWidget Class
  32   *
  33   * A ComponentWidget is a displayable entity that can be placed into a Container on a web page.
  34   *
  35   * @package evocore
  36   */
  37  class coll_tag_cloud_Widget extends ComponentWidget
  38  {
  39      /**
  40       * Constructor
  41       */
  42  	function coll_tag_cloud_Widget( $db_row = NULL )
  43      {
  44          // Call parent constructor:
  45          parent::ComponentWidget( $db_row, 'core', 'coll_tag_cloud' );
  46      }
  47  
  48  
  49      /**
  50       * Load params
  51       */
  52  	function load_from_Request()
  53      {
  54          parent::load_from_Request();
  55  
  56          // SPECIAL treatments:
  57          if( empty($this->param_array['tag_separator']) )
  58          {    // Default name, don't store:
  59              $this->set( 'tag_separator', ' ' );
  60          }
  61      }
  62  
  63  
  64      /**
  65       * Get name of widget
  66       */
  67  	function get_name()
  68      {
  69          return T_('Tag cloud');
  70      }
  71  
  72  
  73      /**
  74       * Get a very short desc. Used in the widget list.
  75       */
  76  	function get_short_desc()
  77      {
  78          return format_to_output($this->disp_params['title']);
  79      }
  80  
  81  
  82      /**
  83       * Get short description
  84       */
  85  	function get_desc()
  86      {
  87          return T_('Cloud of all tags; click filters blog on selected tag.');
  88      }
  89  
  90  
  91      /**
  92       * Get definitions for editable params
  93       *
  94       * @see Plugin::GetDefaultSettings()
  95       * @param local params like 'for_editing' => true
  96       */
  97  	function get_param_definitions( $params )
  98      {
  99          $r = array_merge( array(
 100              'title' => array(
 101                      'type' => 'text',
 102                      'label' => T_('Block title'),
 103                      'defaultvalue' => T_('Tag cloud'),
 104                      'maxlength' => 100,
 105                  ),
 106              'blog_ids' => array(
 107                      'type' => 'text',
 108                      'label' => T_('Include blogs'),
 109                      'note' => T_('A comma-separated list of Blog IDs.'),
 110                  ),
 111              'max_tags' => array(
 112                      'type' => 'integer',
 113                      'label' => T_('Max # of tags'),
 114                      'size' => 4,
 115                      'defaultvalue' => 50,
 116                  ),
 117              'tag_separator' => array(
 118                      'type' => 'text',
 119                      'label' => T_('Tag separator'),
 120                      'defaultvalue' => ' ',
 121                      'maxlength' => 100,
 122                  ),
 123              'tag_min_size' => array(
 124                      'type' => 'integer',
 125                      'label' => T_('Min size'),
 126                      'size' => 3,
 127                      'defaultvalue' => 8,
 128                  ),
 129              'tag_max_size' => array(
 130                      'type' => 'integer',
 131                      'label' => T_('Max size'),
 132                      'size' => 3,
 133                      'defaultvalue' => 22,
 134                  ),
 135              'tag_ordering' => array(
 136                      'type' => 'select',
 137                      'label' => T_('Ordering'),
 138                      'options' => array( 'ASC'  => T_('Ascending'), 'RAND' => T_('Random') ),
 139                      'defaultvalue' => 'ASC',
 140                      'note' => T_('How to sort the tag cloud.'),
 141                  ),
 142              'filter_list' => array(
 143                      'type' => 'textarea',
 144                      'label' => T_('Filter tags'),
 145                      'note' => T_('This is a comma separated list of tags to ignore.'),
 146                      'size' => 40,
 147                      'rows' => 2,
 148                  ),
 149              ), parent::get_param_definitions( $params )    );
 150  
 151          // add limit default 100
 152  
 153          return $r;
 154      }
 155  
 156  
 157      /**
 158       * Display the widget!
 159       *
 160       * @param array MUST contain at least the basic display params
 161       */
 162  	function display( $params )
 163      {
 164          $this->init_display( $params );
 165  
 166          global $blog;
 167  
 168          // Get a list of quoted blog IDs
 169          $blog_ids = sanitize_id_list($this->disp_params['blog_ids'], true);
 170  
 171          if( empty($blog) && empty($blog_ids) )
 172          {    // Nothing to display
 173              return;
 174          }
 175          elseif( empty($blog_ids) )
 176          {    // Use current Blog
 177              $blog_ids = $blog;
 178          }
 179  
 180          $results = get_tags( $blog_ids, $this->disp_params['max_tags'], $this->disp_params['filter_list'], true );
 181  
 182          if( empty($results) )
 183          {    // No tags!
 184              return;
 185          }
 186  
 187          $BlogCache = & get_BlogCache();
 188  
 189          $max_count = $results[0]->tag_count;
 190          $min_count = $results[count($results)-1]->tag_count;
 191          $count_span = max( 1, $max_count - $min_count );
 192          $max_size = $this->disp_params['tag_max_size'];
 193          $min_size = $this->disp_params['tag_min_size'];
 194          $size_span = $max_size - $min_size;
 195  
 196          if ($this->disp_params['tag_ordering'] == 'ASC')
 197          {
 198              usort($results, array($this, 'tag_cloud_cmp'));
 199          }
 200          else if ($this->disp_params['tag_ordering'] == 'RAND')
 201          {
 202              shuffle( $results );
 203          }
 204  
 205          echo $this->disp_params['block_start'];
 206  
 207          $this->disp_title();
 208  
 209          echo $this->disp_params['tag_cloud_start'];
 210          $count = 0;
 211          foreach( $results as $row )
 212          {
 213              if( $count > 0 )
 214              {
 215                  echo $this->disp_params['tag_separator'];
 216              }
 217              // If there's a space in the tag name, quote it:
 218              $tag_name_disp = strpos($row->tag_name, ' ')
 219                  ? '&laquo;'.format_to_output($row->tag_name, 'htmlbody').'&raquo;'
 220                  : format_to_output($row->tag_name, 'htmlbody');
 221              $size = floor( $row->tag_count * $size_span / $count_span + $min_size );
 222  
 223              $l_Blog = $BlogCache->get_by_id( $row->cat_blog_ID );
 224              echo $l_Blog->get_tag_link( $row->tag_name, $tag_name_disp, array(
 225                  'style' => 'font-size:'.$size.'pt;',
 226                  'title' => sprintf( T_('Display posts tagged with &laquo;%s&raquo;'), $row->tag_name ) ) );
 227              $count++;
 228          }
 229          echo $this->disp_params['tag_cloud_end'];
 230  
 231          echo $this->disp_params['block_end'];
 232  
 233          return true;
 234      }
 235  
 236  
 237  	function tag_cloud_cmp($a, $b)
 238      {
 239          return strcasecmp($a->tag_name, $b->tag_name);
 240      }
 241  
 242  
 243      /**
 244       * May be overriden by some widgets, depending on what THEY depend on..
 245       *
 246       * @todo dh> this needs a custom implementation I believe.
 247       *           It could depend on tag_ID_any (once tags have an ID)
 248       *           or just the list of blogs (cont_coll_ID_*)?
 249       * fp> I don't understand what you mean.
 250       * dh> That the widget should get cached, and needs a custom implementation
 251       *     of this method (get_cache_keys).
 252       *     Cache contents should get invalidated when any tags get changed.
 253       *
 254       * @return array of keys this widget depends on
 255       *
 256      function get_cache_keys()
 257      {
 258          return array(
 259                  'wi_ID'   => $this->ID,                    // Have the widget settings changed ?
 260                  'item_ID' => 'any',                            // doc???
 261              );
 262      }
 263      */
 264  }
 265  
 266  ?>

title

Description

title

Description

title

Description

title

title

Body