b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.9) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Source for file _categories.plugin.php

Documentation is available at _categories.plugin.php

  1. <?php
  2. /**
  3.  * This file implements the Categories plugin.
  4.  *
  5.  * Displays a list of categories (chapters and subchapters) for the blog.
  6.  *
  7.  * This file is part of the b2evolution project - {@link http://b2evolution.net/}
  8.  *
  9.  * @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *  Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  11.  *
  12.  *  {@internal License choice
  13.  *  - If you have received this file as part of a package, please find the license.txt file in
  14.  *    the same folder or the closest folder above for complete license terms.
  15.  *  - If you have received this file individually (e-g: from http://cvs.sourceforge.net/viewcvs.py/evocms/)
  16.  *    then you must choose one of the following licenses before using the file:
  17.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  18.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  19.  *  }}}
  20.  *
  21.  * @package plugins
  22.  *
  23.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  24.  * @author fplanque: Francois PLANQUE - {@link http://fplanque.net/}
  25.  *
  26.  * @version $Id: _categories.plugin.php,v 1.24.2.4 2006/12/26 03:18:50 fplanque Exp $
  27.  */
  28. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  29.  
  30.  
  31. /**
  32.  * Categories Plugin
  33.  *
  34.  * This plugin displays a list of categories (chapters and subchapters) for the blog.
  35.  */
  36. class categories_plugin extends Plugin
  37. {
  38.     /**
  39.      * Variables below MUST be overriden by plugin implementations,
  40.      * either in the subclass declaration or in the subclass constructor.
  41.      */
  42.  
  43.     var $name = 'Categories Skin Tag';
  44.     var $code = 'evo_Cats';
  45.     var $priority = 60;
  46.     var $version = '1.9-dev';
  47.     var $author = 'The b2evo Group';
  48.     var $group = 'skin-tag';
  49.  
  50.  
  51.     /**
  52.      * Init
  53.      */
  54.     function PluginInit$params )
  55.     {
  56.         $this->short_desc = T_('This skin tag displays the list of available categories for the blog.');
  57.         $this->long_desc = T_('Categories are indeed chapters and sub-chapters in the blog.');
  58.  
  59.         $this->dbtable 'T_posts';
  60.         $this->dbprefix 'post_';
  61.         $this->dbIDname 'post_ID';
  62.     }
  63.  
  64.  
  65.     /**
  66.      * Event handler: SkinTag
  67.      *
  68.      * @param array Associative array of parameters. Valid keys are:
  69.      *                 - 'block_start' : (Default: '<div class="bSideItem">')
  70.      *                 - 'block_end' : (Default: '</div>')
  71.      *                 - 'title' : (Default: '<h3>'.T_('Categories').'</h3>')
  72.      *                 - 'link_type' : 'canonic'|'context' (default: canonic)
  73.      *                 - 'context_isolation' : what params need override when changing date/range (Default: 'm,w,p,title,unit,dstart' )
  74.      *                 - 'form' : true|false (default: false)
  75.      *                 - 'list_start' : (Default '<ul>'), does not get displayed for empty lists
  76.      *                 - 'list_end' : (Default '</ul>'), does not get displayed for empty lists
  77.      *                 - 'line_start' : (Default '<li>')
  78.      *                 - 'line_end' : (Default '</li>')
  79.      *                 - 'group_start' : (Default '<ul>') - (for BLOG 1 Categories)
  80.      *                 - 'group_end' : (Default "</ul>\n") - (for BLOG 1 Categories)
  81.      *                 - 'collist_start' : (Default '') - (for BLOG 1 Categories)
  82.      *                 - 'collist_end' : (Default "\n") - (for BLOG 1 Categories)
  83.      *                 - 'coll_start' : (Default '<h4>') - (for BLOG 1 Categories)
  84.      *                 - 'coll_end' : (Default "</h4>\n") - (for BLOG 1 Categories)
  85.      *                 - 'option_all' : (Default T_('All'))
  86.      * @return boolean did we display?
  87.      */
  88.     function SkinTag$params )
  89.     {
  90.         global $cache_categories;
  91.         /**
  92.          * @todo get rid of these globals:
  93.          */
  94.         global $blog$cat_modifier;
  95.  
  96.         /**
  97.          * Default params:
  98.          */
  99.         // This is what will enclose the block in the skin:
  100.         if(!isset($params['block_start'])) $params['block_start''<div class="bSideItem">';
  101.         if(!isset($params['block_end'])) $params['block_end'"</div>\n";
  102.  
  103.         // Title:
  104.         if(!isset($params['title']))
  105.             $params['title''<h3>'.T_('Categories').'</h3>';
  106.  
  107.         // Link type:
  108.         if(!isset($params['link_type'])) $params['link_type''canonic';
  109.         // if(!isset($params['context_isolation'])) $params['context_isolation'] = 'm,w,p,title,unit,dstart';
  110.  
  111.         // Add form fields?:
  112.         if(!isset($params['form'])) $params['form'false;
  113.  
  114.  
  115.         // This is what will enclose the category list:
  116.         if(!isset($params['list_start'])) $params['list_start''<ul>';
  117.         if(!isset($params['list_end'])) $params['list_end'"</ul>\n";
  118.  
  119.         // This is what will separate the category links:
  120.         if(!isset($params['line_start'])) $params['line_start''<li>';
  121.         if(!isset($params['line_end'])) $params['line_end'"</li>\n";
  122.  
  123.         // This is what will enclose the sub chapter lists:
  124.         if(!isset($params['group_start'])) $params['group_start''<ul>';
  125.         if(!isset($params['group_end'])) $params['group_end'"</ul>\n";
  126.  
  127.         // This is what will enclose the global list if several blogs are listed on the same page:
  128.         if(!isset($params['collist_start'])) $params['collist_start''';
  129.         if(!isset($params['collist_end'])) $params['collist_end'"\n";
  130.  
  131.         // This is what will separate blogs/collections when several of them are listed on the same page:
  132.         if(!isset($params['coll_start'])) $params['coll_start''<h4>';
  133.         if(!isset($params['coll_end'])) $params['coll_end'"</h4>\n";
  134.  
  135.  
  136.         if(!isset($params['option_all'])) $params['option_all'T_('All');
  137.  
  138.  
  139.         // Save params for others functions:
  140.         $this->params $params;
  141.  
  142.  
  143.         // make sure the caches are loaded:
  144.         cat_query$params['link_type']$this->dbtable$this->dbprefix$this->dbIDname );
  145.  
  146.  
  147.         // START DISPLAY:
  148.         echo $params['block_start'];
  149.  
  150.         echo $params['title'];
  151.  
  152.         if$blog )
  153.         // We want to display cats for one blog
  154.             $tmp_disp '';
  155.  
  156.             if$params['option_all')
  157.             {    // We want to display a link to all cats:
  158.                 $tmp_disp .= $this->params['line_start'].'<a href="';
  159.                 if$this->params['link_type'== 'context' )
  160.                 {    // We want to preserve current browsing context:
  161.                     $tmp_disp .= regenerate_url'cats,catsel' );
  162.                 }
  163.                 else
  164.                 {
  165.                     $tmp_disp .= get_bloginfo('blogurl');
  166.                 }
  167.                 $tmp_disp .= '">'.$params['option_all'].'</a>';
  168.                 $tmp_disp .= $this->params['line_end'];
  169.             }
  170.             $tmp_disp .= cat_children$cache_categories$blogNULL,
  171.                                        array$this'callback_before_first' )array$this'callback_before_each' ),
  172.                                        array$this'callback_after_each' )array$this'callback_after_last' ));
  173.             ifempty($tmp_disp) )
  174.             {
  175.                 echo $params['list_start'];
  176.                 echo $tmp_disp;
  177.                 echo $params['list_end'];
  178.             }
  179.         }
  180.         else
  181.         // We want to display cats for all blogs
  182.             echo $params['collist_start'];
  183.  
  184.             for$curr_blog_ID=blog_list_start();
  185.                         $curr_blog_ID!=false;
  186.                          $curr_blog_ID=blog_list_next() )
  187.             {
  188.                 ifblog_list_iteminfo('disp_bloglist'false) )
  189.                 // Skip Blogs that should not get displayed in public blog list
  190.                     continue;
  191.                 }
  192.  
  193.                 // run recursively through the cats
  194.                 $cat_list cat_children$cache_categories$curr_blog_IDNULL,
  195.                             array$this'callback_before_first' )array$this'callback_before_each' ),
  196.                             array$this'callback_after_each' )array$this'callback_after_last' ));
  197.  
  198. /* Make this a param with default to OFF (NO Skip) because even if there are no cats, the blog name is a clickable root category itself
  199.                 if( empty( $cat_list ) )
  200.                 { // Skip Blogs that have no categories!
  201.                     continue;
  202.                 }
  203. */
  204.  
  205.                 echo $params['coll_start'];
  206.                 echo '<a href="';
  207.                 if$this->params['link_type'== 'context' )
  208.                 {    // We want to preserve current browsing context:
  209.                     echo regenerate_url'blog,cats,catsel''blog='.$curr_blog_ID );
  210.                 }
  211.                 else
  212.                 {
  213.                     blog_list_iteminfo('blogurl');
  214.                 }
  215.                 echo '">';
  216.                 blog_list_iteminfo('name');
  217.                 echo '</a>';
  218.                 echo $params['coll_end'];
  219.  
  220.                 ifempty($cat_list) )
  221.                 {
  222.                     echo $params['list_start'];
  223.                     echo $cat_list;
  224.                     echo $params['list_end'];
  225.                 }
  226.             }
  227.  
  228.             echo $params['collist_end'];
  229.         }
  230.  
  231.         if$params['form')
  232.         {    // We want to add form fields:
  233.         ?>
  234.             <span class="line"> <?php /* blueyed>> using div.line here makes them "blocks" in Konqueror/Safari(?) */ ?>
  235.                 <input type="radio" name="cat" value="" id="catANY" class="radio" <?php if$cat_modifier != '-' && $cat_modifier != '*' echo 'checked="checked" '?> />
  236.                 <label for="catANY"><?php echo T_('ANY'?></label>
  237.             </span>
  238.             <span class="line">
  239.                 <input type="radio" name="cat" value="-" id="catANYBUT" class="radio" <?php if$cat_modifier == '-' echo 'checked="checked" '?> />
  240.                 <label for="catANYBUT"><?php echo T_('ANY BUT'?></label>
  241.             </span>
  242.             <span class="line">
  243.                 <input type="radio" name="cat" value="*" id="catALL" class="radio" <?php if$cat_modifier == '*' echo 'checked="checked" '?> />
  244.                 <label for="catALL"><?php echo T_('ALL'?></label>
  245.             </span>
  246.         <?php
  247.         }
  248.  
  249.         echo $params['block_end'];
  250.  
  251.         return true;
  252.     }
  253.  
  254.  
  255.     function callback_before_first$parent_cat_ID$level )
  256.     // callback to start sublist
  257.         $r '';
  258.         if$level $r .= $this->params['group_start'];
  259.         return $r;
  260.     }
  261.  
  262.  
  263.     function callback_before_each$cat_ID$level )
  264.     // callback to display sublist element
  265.         global $tab$blog$cat_array;
  266.         $cat get_the_category_by_ID$cat_ID );
  267.         $r $this->params['line_start'];
  268.  
  269.         if$this->params['form')
  270.         {    // We want to add form fields:
  271.             $r .= '<label><input type="checkbox" name="catsel[]" value="'.$cat_ID.'" class="checkbox"';
  272.             ifin_array$cat_ID$cat_array ) )
  273.             // This category is in the current selection
  274.                 $r .= ' checked="checked"';
  275.             }
  276.             $r .= ' /> ';
  277.         }
  278.  
  279.         $r .= '<a href="';
  280.  
  281.         if$this->params['link_type'== 'context' )
  282.         {    // We want to preserve current browsing context:
  283.             $r .= regenerate_url'cats,catsel''cat='.$cat_ID );
  284.         }
  285.         else
  286.         {
  287.             $r .= url_add_paramblog_list_iteminfo('blogurl'false)'cat='.$cat_ID );
  288.         }
  289.  
  290.         $r .= '">'.format_to_output($cat['cat_name']'htmlbody').'</a> <span class="notes">('.$cat['cat_postcount'].')</span>';
  291.  
  292.         ifin_array$cat_ID$cat_array ) )
  293.         // This category is in the current selection
  294.             $r .= '*';
  295.         }
  296.  
  297.         if$this->params['form')
  298.         {    // We want to add form fields:
  299.             $r .= '</label>';
  300.         }
  301.         return $r;
  302.     }
  303.  
  304.  
  305.     function callback_after_each$cat_ID$level )
  306.     // callback to display sublist element
  307.         return $this->params['line_end'];
  308.     }
  309.  
  310.  
  311.     function callback_after_last$parent_cat_ID$level )
  312.     // callback to end sublist
  313.         $r '';
  314.         if$level $r .= $this->params['group_end'];
  315.         return $r;
  316.     }
  317.  
  318. }
  319.  
  320.  
  321. /*
  322.  * $Log: _categories.plugin.php,v $
  323.  * Revision 1.24.2.4  2006/12/26 03:18:50  fplanque
  324.  * assigned a few significant plugin groups
  325.  *
  326.  * Revision 1.24.2.3  2006/12/05 12:44:43  blueyed
  327.  * Link categories with the corresponding blog URL. Fixes "serious google problem". See http://forums.b2evolution.net//viewtopic.php?p=47815#47815
  328.  *
  329.  * Revision 1.24.2.2  2006/11/04 19:55:11  fplanque
  330.  * Reinjected old Log blocks. Removing them from CVS was a bad idea -- especially since Daniel has decided branch 1.9 was his HEAD...
  331.  *
  332.  * Revision 1.24  2006/07/10 20:19:30  blueyed
  333.  * Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.
  334.  *
  335.  * Revision 1.23  2006/07/07 21:26:49  blueyed
  336.  * Bumped to 1.9-dev
  337.  *
  338.  * Revision 1.22  2006/06/16 21:30:57  fplanque
  339.  * Started clean numbering of plugin versions (feel free do add dots...)
  340.  *
  341.  * Revision 1.21  2006/05/30 19:39:55  fplanque
  342.  * plugin cleanup
  343.  *
  344.  * Revision 1.20  2006/04/19 20:14:03  fplanque
  345.  * do not restrict to :// (does not catch subdomains, not even www.)
  346.  *
  347.  * Revision 1.19  2006/04/11 21:22:26  fplanque
  348.  * partial cleanup
  349.  *
  350.  */
  351. ?>

Documentation generated on Tue, 18 Dec 2007 19:12:44 +0100 by phpDocumentor 1.4.0