b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _coll_tag_cloud.widget.php

Documentation is available at _coll_tag_cloud.widget.php

  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-2010 by Francois PLANQUE - {@link http://fplanque.net/}
  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,v 1.29 2010/02/08 17:54:48 efy-yury Exp $
  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. {
  38.     /**
  39.      * Constructor
  40.      */
  41.     function coll_tag_cloud_Widget$db_row NULL )
  42.     {
  43.         // Call parent constructor:
  44.         parent::ComponentWidget$db_row'core''coll_tag_cloud' );
  45.     }
  46.  
  47.  
  48.     /**
  49.      * Load params
  50.      */
  51.     function load_from_Request()
  52.     {
  53.         parent::load_from_Request();
  54.  
  55.         // SPECIAL treatments:
  56.         ifempty($this->param_array['tag_separator']) )
  57.         {    // Default name, don't store:
  58.             $this->set'tag_separator'' ' );
  59.         }
  60.     }
  61.  
  62.  
  63.     /**
  64.      * Get name of widget
  65.      */
  66.     function get_name()
  67.     {
  68.         return T_('Tag cloud');
  69.     }
  70.  
  71.  
  72.     /**
  73.      * Get a very short desc. Used in the widget list.
  74.      */
  75.     function get_short_desc()
  76.     {
  77.         return format_to_output($this->disp_params['title']);
  78.     }
  79.  
  80.  
  81.     /**
  82.      * Get short description
  83.      */
  84.     function get_desc()
  85.     {
  86.         return T_('Cloud of all tags; click filters blog on selected tag.');
  87.     }
  88.  
  89.  
  90.     /**
  91.      * Get definitions for editable params
  92.      *
  93.      * @see Plugin::GetDefaultSettings()
  94.      * @param local params like 'for_editing' => true
  95.      */
  96.     function get_param_definitions$params )
  97.     {
  98.         $r array_mergearray(
  99.             'title' => array(
  100.                     'type' => 'text',
  101.                     'label' => T_('Block title'),
  102.                     'defaultvalue' => T_('Tag cloud'),
  103.                     'maxlength' => 100,
  104.                 ),
  105.             'max_tags' => array(
  106.                     'type' => 'integer',
  107.                     'label' => T_('Max # of tags'),
  108.                     'size' => 4,
  109.                     'defaultvalue' => 50,
  110.                 ),
  111.             'tag_separator' => array(
  112.                     'type' => 'text',
  113.                     'label' => T_('Tag separator'),
  114.                     'defaultvalue' => ' ',
  115.                     'maxlength' => 100,
  116.                 ),
  117.             'tag_min_size' => array(
  118.                     'type' => 'integer',
  119.                     'label' => T_('Min size'),
  120.                     'size' => 3,
  121.                     'defaultvalue' => 8,
  122.                 ),
  123.             'tag_max_size' => array(
  124.                     'type' => 'integer',
  125.                     'label' => T_('Max size'),
  126.                     'size' => 3,
  127.                     'defaultvalue' => 22,
  128.                 ),
  129.             'tag_ordering' => array(
  130.                     'type' => 'select',
  131.                     'label' => T_('Ordering'),
  132.                     'options' => array'ASC'  => T_('Ascending')'RAND' => T_('Random') ),
  133.                     'defaultvalue' => 'ASC',
  134.                     'note' => T_'How to sort the tag cloud.' ),
  135.                 ),
  136.             'filter_list' => array(
  137.                     'type' => 'textarea',
  138.                     'label' => T_('Filter tags'),
  139.                     'note' => T_('This is a comma separated list of tags to ignore.'),
  140.                     'size' => 40,
  141.                     'rows' => 2,
  142.                 ),
  143.             )parent::get_param_definitions$params )    );
  144.  
  145.         // add limit default 100
  146.  
  147.         return $r;
  148.     }
  149.  
  150.  
  151.     /**
  152.      * Display the widget!
  153.      *
  154.      * @param array MUST contain at least the basic display params
  155.      */
  156.     function display$params )
  157.     {
  158.         $this->init_display$params );
  159.  
  160.         global $Blog;
  161.  
  162.         ifempty($Blog) )
  163.         {    // Nothing to display
  164.             return;
  165.         }
  166.  
  167.         global $DB$localtimenow;
  168.  
  169. // fp> verrry dirty and params; TODO: clean up
  170. // dh> oddly, this appears to not get cached by the query cache. Have experimented a bit, but not found the reason.
  171. //     It worked locally somehow, but not live.
  172. //     This takes up to ~50% (but more likely 15%) off the total SQL time. With the query being cached, it would be far better.
  173.         // get list of relevant blogs
  174.         $where_cats trim($Blog->get_sql_where_aggregate_coll_IDs('cat_blog_ID'));
  175.  
  176.         // build query, only joining categories, if not using all.
  177.         $sql "SELECT LOWER(tag_name) AS tag_name, post_datestart, COUNT(DISTINCT itag_itm_ID) AS tag_count
  178.               FROM T_items__tag INNER JOIN T_items__itemtag ON itag_tag_ID = tag_ID";
  179.         if$where_cats != '1' )
  180.         // we have to join the cats
  181.             $sql .= "
  182.              INNER JOIN T_postcats ON itag_itm_ID = postcat_post_ID
  183.              INNER JOIN T_categories ON postcat_cat_ID = cat_ID";
  184.         }
  185.         $sql .= "
  186.              INNER JOIN T_items__item ON itag_itm_ID = post_ID
  187.              WHERE $where_cats
  188.                AND post_status = 'published' AND post_datestart < '".remove_seconds($localtimenow)."'";
  189.         
  190.         if$this->disp_params['filter_list')
  191.         {    // Filter tags
  192.             $filter_list explode','$this->disp_params['filter_list';
  193.             
  194.             $filter_tags array();
  195.             foreach$filter_list as $l_tag )
  196.             {
  197.                 $filter_tags['"'.$DB->escape(trim($l_tag)).'"';
  198.             }
  199.             
  200.             $sql .= ' AND tag_name NOT IN ('.implode(', '$filter_tags).')';
  201.         }
  202.         
  203.         $sql .= "
  204.              GROUP BY tag_name
  205.              ORDER BY tag_count DESC
  206.              LIMIT ".$this->disp_params['max_tags'];
  207.  
  208.         $results $DB->get_results$sqlOBJECT'Get tags' );
  209.  
  210.         ifempty($results) )
  211.         {    // No tags!
  212.             return;
  213.         }
  214.  
  215.         $max_count $results[0]->tag_count;
  216.         $min_count $results[count($results)-1]->tag_count;
  217.         $count_span max1$max_count $min_count );
  218.         $max_size $this->disp_params['tag_max_size'];
  219.         $min_size $this->disp_params['tag_min_size'];
  220.         $size_span $max_size $min_size;
  221.  
  222.         if ($this->disp_params['tag_ordering'== 'ASC')
  223.         {
  224.             usort($resultsarray($this'tag_cloud_cmp'));
  225.         }
  226.         else if ($this->disp_params['tag_ordering'== 'RAND')
  227.         {
  228.             shuffle$results );
  229.         }
  230.  
  231.         echo $this->disp_params['block_start'];
  232.  
  233.         $this->disp_title();
  234.  
  235.         echo $this->disp_params['tag_cloud_start'];
  236.         $count 0;
  237.         foreach$results as $row )
  238.         {
  239.             if$count )
  240.             {
  241.                 echo $this->disp_params['tag_separator'];
  242.             }
  243.             // If there's a space in the tag name, quote it:
  244.             $tag_name_disp strpos($row->tag_name' ')
  245.                 ? '&laquo;'.format_to_output($row->tag_name'htmlbody').'&raquo;'
  246.                 : format_to_output($row->tag_name'htmlbody');
  247.             $size floor$row->tag_count $size_span $count_span $min_size );
  248.  
  249.             echo $Blog->get_tag_link$row->tag_name$tag_name_disparray(
  250.                 'style' => 'font-size: '.$size.'pt;',
  251.                 'title' => sprintfT_('%d posts')$row->tag_count ) ) );
  252.             $count++;
  253.         }
  254.         echo $this->disp_params['tag_cloud_end'];
  255.  
  256.         echo $this->disp_params['block_end'];
  257.  
  258.         return true;
  259.     }
  260.  
  261.  
  262.     function tag_cloud_cmp($a$b)
  263.     {
  264.         return strcasecmp($a->tag_name$b->tag_name);
  265.     }
  266.  
  267.  
  268.     /**
  269.      * May be overriden by some widgets, depending on what THEY depend on..
  270.      *
  271.      * @todo dh> this needs a custom implementation I believe.
  272.      *            It could depend on tag_ID_any (once tags have an ID)
  273.      *            or just the list of blogs (cont_coll_ID_*)?
  274.      *  fp> I don't understand what you mean.
  275.      *
  276.      * @return array of keys this widget depends on
  277.      *
  278.     function get_cache_keys()
  279.     {
  280.         return array(
  281.                 'wi_ID'   => $this->ID,                    // Have the widget settings changed ?
  282.                 'item_ID' => 'any',                            // doc???
  283.             );
  284.     }
  285.     */
  286. }
  287.  
  288.  
  289. /*
  290.  * $Log: _coll_tag_cloud.widget.php,v $
  291.  * Revision 1.29  2010/02/08 17:54:48  efy-yury
  292.  * copyright 2009 -> 2010
  293.  *
  294.  * Revision 1.28  2010/01/08 22:24:18  blueyed
  295.  * tagcloud widget: Trans fix.
  296.  *
  297.  * Revision 1.27  2010/01/08 20:21:17  sam2kb
  298.  * Filter unwanted tags
  299.  *
  300.  * Revision 1.26  2009/12/22 08:02:12  fplanque
  301.  * doc
  302.  *
  303.  * Revision 1.25  2009/12/22 03:31:37  blueyed
  304.  * todo about tag widget block cache keys
  305.  *
  306.  * Revision 1.24  2009/10/28 13:39:07  waltercruz
  307.  * Random order to tag cloud widget
  308.  *
  309.  * Revision 1.23  2009/09/14 13:54:13  efy-arrin
  310.  * Included the ClassName in load_class() call with proper UpperCase
  311.  *
  312.  * Revision 1.22  2009/09/13 21:33:44  blueyed
  313.  * coll_tag_cloud_Widget: optimizing tag query a bit. doc.
  314.  *
  315.  * Revision 1.21  2009/09/13 21:29:22  blueyed
  316.  * MySQL query cache optimization: remove information about seconds from post_datestart and item_issue_date.
  317.  *
  318.  * Revision 1.20  2009/09/12 11:03:13  efy-arrin
  319.  * Included the ClassName in the loadclass() with proper UpperCase
  320.  *
  321.  * Revision 1.19  2009/04/23 19:51:40  blueyed
  322.  * Add Blog::get_tag_link, use it where appropriate.
  323.  *
  324.  * Revision 1.18  2009/03/13 02:32:07  fplanque
  325.  * Cleaned up widgets.
  326.  * Removed stupid widget_name param.
  327.  *
  328.  * Revision 1.17  2009/03/08 23:57:46  fplanque
  329.  * 2009
  330.  *
  331.  * Revision 1.16  2009/01/23 00:10:45  blueyed
  332.  * coll_tag_cloud.widget: quote tags with spaces in them
  333.  *
  334.  * Revision 1.15  2009/01/23 00:09:41  blueyed
  335.  * coll_tag_cloud_Widget:
  336.  *  - fix E_FATAL, when included twice (tag_cloud_cmp function would get
  337.  *    defined twice)
  338.  *  - Simplify tag_cloud_cmp by using strcasecmp
  339.  *
  340.  * Revision 1.14  2009/01/23 00:05:25  blueyed
  341.  * Add Blog::get_sql_where_aggregate_coll_IDs, which adds support for '*' in list of aggregated blogs.
  342.  *
  343.  * Revision 1.13  2009/01/13 22:51:29  fplanque
  344.  * rollback / normalized / MFB
  345.  *
  346.  * Revision 1.12  2008/09/09 06:03:31  fplanque
  347.  * More tag URL options
  348.  * Enhanced URL resolution for categories and tags
  349.  *
  350.  * Revision 1.11  2008/07/17 02:03:23  afwas
  351.  * Bug fix in DB query. Won't show tags from not published posts and future posts. Also will no longer show tags twice.
  352.  *
  353.  * Revision 1.10  2008/05/06 23:35:47  fplanque
  354.  * The correct way to add linebreaks to widgets is to add them to $disp_params when the container is called, right after the array_merge with defaults.
  355.  *
  356.  * Revision 1.8  2008/01/21 09:35:37  fplanque
  357.  * (c) 2008
  358.  *
  359.  * Revision 1.7  2007/12/23 17:47:59  fplanque
  360.  * fixes
  361.  *
  362.  * Revision 1.6  2007/12/23 16:16:18  fplanque
  363.  * Wording improvements
  364.  *
  365.  * Revision 1.5  2007/12/23 14:14:25  fplanque
  366.  * Enhanced widget name display
  367.  *
  368.  * Revision 1.4  2007/12/22 19:55:00  yabs
  369.  * cleanup from adding core params
  370.  *
  371.  * Revision 1.3  2007/12/22 17:19:35  fplanque
  372.  * bugfix
  373.  *
  374.  * Revision 1.2  2007/12/21 21:50:28  fplanque
  375.  * tag cloud sizing
  376.  *
  377.  * Revision 1.1  2007/12/20 22:59:34  fplanque
  378.  * TagCloud widget prototype
  379.  *
  380.  * Revision 1.1  2007/06/25 11:02:18  fplanque
  381.  * MODULES (refactored MVC)
  382.  *
  383.  * Revision 1.2  2007/06/20 21:42:13  fplanque
  384.  * implemented working widget/plugin params
  385.  *
  386.  * Revision 1.1  2007/06/18 21:25:47  fplanque
  387.  * one class per core widget
  388.  *
  389.  */
  390. ?>

Documentation generated on Sat, 06 Mar 2010 04:05:54 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).