b2evolution

Multilingual multiuser multiblog engine

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

Source for file _coll_category_list.widget.php

Documentation is available at _coll_category_list.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.  *  Parts of this file are copyright (c)2008 by Daniel HAHLER - {@link http://daniel.hahler.de/}.
  10.  *
  11.  *  {@internal License choice
  12.  *  - If you have received this file as part of a package, please find the license.txt file in
  13.  *    the same folder or the closest folder above for complete license terms.
  14.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15.  *    then you must choose one of the following licenses before using the file:
  16.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18.  *  }}}
  19.  *
  20.  * @package evocore
  21.  *
  22.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  23.  * @author blueyed: Daniel HAHLER
  24.  * @author fplanque: Francois PLANQUE.
  25.  *
  26.  * @version $Id: _coll_category_list.widget.php,v 1.26 2010/02/26 02:05:09 sam2kb Exp $
  27.  */
  28. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  29.  
  30. load_class'widgets/model/_widget.class.php''ComponentWidget' );
  31.  
  32. /**
  33.  * ComponentWidget Class
  34.  *
  35.  * A ComponentWidget is a displayable entity that can be placed into a Container on a web page.
  36.  *
  37.  * @package evocore
  38.  */
  39. {
  40.     /**
  41.      * Constructor
  42.      */
  43.     function coll_category_list_Widget$db_row NULL )
  44.     {
  45.         // Call parent constructor:
  46.         parent::ComponentWidget$db_row'core''coll_category_list' );
  47.     }
  48.  
  49.  
  50.     /**
  51.      * Get name of widget
  52.      */
  53.     function get_name()
  54.     {
  55.         return T_('Category list');
  56.     }
  57.  
  58.  
  59.     /**
  60.      * Get a very short desc. Used in the widget list.
  61.      */
  62.     function get_short_desc()
  63.     {
  64.         return format_to_output($this->disp_params['title']);
  65.     }
  66.  
  67.  
  68.     /**
  69.      * Get short description
  70.      */
  71.     function get_desc()
  72.     {
  73.         return T_('List of all categories; click filters blog on selected category.');
  74.     }
  75.  
  76.  
  77.     /**
  78.      * Get definitions for editable params
  79.      *
  80.      * @see Plugin::GetDefaultSettings()
  81.      * @param array local params
  82.      *   - 'title': block title (string, default "Categories")
  83.      *   - 'option_all': "All categories" link title, empty to disable (string, default "All")
  84.      *   - 'use_form': Add a form with checkboxes to allow selection of multiple categories (boolean)
  85.      *   - 'disp_names_for_coll_list': Display blog names, if this is an aggregated blog? (boolean)
  86.      *   - 'display_checkboxes': Add checkboxes (but not a complete form) to allow selection of multiple categories (boolean)
  87.      */
  88.     function get_param_definitions$params )
  89.     {
  90.         $r array_mergearray(
  91.             'title' => array(
  92.                     'type' => 'text',
  93.                     'label' => T_('Block title'),
  94.                     'defaultvalue' => T_('Categories'),
  95.                     'maxlength' => 100,
  96.                 ),
  97.             'option_all' => array(
  98.                     'type' => 'text',
  99.                     'label' => T_('Option "All"'),
  100.                     'defaultvalue' => T_('All'),
  101.                     'maxlength' => 100,
  102.                     'note' => T_('The "All categories" link allows to reset the filter. Leave blank if you want no such option.'),
  103.                 ),
  104.             'use_form' => array(
  105.                     'type' => 'checkbox',
  106.                     'label' => T_('Use form'),
  107.                     'defaultvalue' => 0,
  108.                     'note' => T_('Add checkboxes to allow selection of multiple categories.'),
  109.                 ),
  110.             'disp_names_for_coll_list' => array(
  111.                     'type' => 'checkbox',
  112.                     'label' => T_('Display blog names'),
  113.                     'defaultvalue' => 1/* previous behaviour */
  114.                     'note' => T_('Display blog names, if this is an aggregated blog.'),
  115.                 ),
  116.  
  117.             // Hidden, used by the item list sidebar in the backoffice.
  118.             'display_checkboxes' => array(
  119.                     'label' => 'Internal: Display checkboxes'// This key is required
  120.                     'defaultvalue' => 0,
  121.                     'no_edit' => true,
  122.                 ),
  123.             )parent::get_param_definitions$params ) );
  124.  
  125.         return $r;
  126.     }
  127.  
  128.  
  129.     /**
  130.      * Display the widget!
  131.      *
  132.      * @param array MUST contain at least the basic display params
  133.      */
  134.     function display$params )
  135.     {
  136.         global $cat_modifier;
  137.         global $Blog;
  138.  
  139.         $this->init_display$params );
  140.  
  141.         /**
  142.          * @var ChapterCache
  143.          */
  144.         $ChapterCache get_ChapterCache();
  145.  
  146.         $callbacks array(
  147.             'line'         => array$this'cat_line' ),
  148.             'no_children'  => array$this'cat_no_children' ),
  149.             'before_level' => array$this'cat_before_level' ),
  150.             'after_level'  => array$this'cat_after_level' )
  151.         );
  152.  
  153.         // START DISPLAY:
  154.         echo $this->disp_params['block_start'];
  155.  
  156.         // Display title if requested
  157.         $this->disp_title();
  158.  
  159.         if $this->disp_params['use_form')
  160.         {    // We want a complete form:
  161.             echo '<form method="get" action="'.$Blog->gen_blogurl().'">';
  162.         }
  163.  
  164.         $aggregate_coll_IDs $Blog->get_setting('aggregate_coll_IDs');
  165.         ifempty($aggregate_coll_IDs) )
  166.         // ____________________ We want to display cats for ONE blog ____________________
  167.             $tmp_disp '';
  168.  
  169.             if$this->disp_params['option_all')
  170.             {    // We want to display a link to all cats:
  171.                 $tmp_disp .= $this->disp_params['item_start'].'<a href="';
  172.                 if$this->disp_params['link_type'== 'context' )
  173.                 {    // We want to preserve current browsing context:
  174.                     $tmp_disp .= regenerate_url'cats,catsel' );
  175.                 }
  176.                 else
  177.                 {
  178.                     $tmp_disp .= $Blog->gen_blogurl();
  179.                 }
  180.                 $tmp_disp .= '">'.$this->disp_params['option_all'].'</a>';
  181.                 $tmp_disp .= $this->disp_params['item_end'];
  182.             }
  183.  
  184.             $r $tmp_disp $ChapterCache->recurse$callbacks$Blog->ID );
  185.  
  186.             ifempty($r) )
  187.             {
  188.                 echo $this->disp_params['list_start'];
  189.                 echo $r;
  190.                 echo $this->disp_params['list_end'];
  191.             }
  192.         }
  193.         else
  194.         // ____________________ We want to display cats for SEVERAL blogs ____________________
  195.  
  196.             $BlogCache get_BlogCache();
  197.  
  198.             // Make sure everything is loaded at once (vs multiple queries)
  199.             // fp> TODO: scaling
  200.             $ChapterCache->load_all();
  201.  
  202.             echo $this->disp_params['collist_start'];
  203.  
  204.             if$aggregate_coll_IDs == '*' )
  205.             {
  206.                 $BlogCache->load_all();
  207.                 $coll_ID_array $BlogCache->get_ID_array();
  208.             }
  209.             else
  210.             {
  211.                 $coll_ID_array array_filterarray_map'trim'explode','$aggregate_coll_IDs ) ) );
  212.             }
  213.             foreach$coll_ID_array as $curr_blog_ID )
  214.             {
  215.                 // Get blog:
  216.                 $loop_Blog $BlogCache->get_by_ID$curr_blog_IDfalse );
  217.                 ifempty($loop_Blog) )
  218.                 {    // That one doesn't exist (any more?)
  219.                     continue;
  220.                 }
  221.  
  222.                 // Display blog title, if requested:
  223.                 if$this->disp_params['disp_names_for_coll_list')
  224.                 {
  225.                     echo $this->disp_params['coll_start'];
  226.                     echo '<a href="';
  227.                     if$this->disp_params['link_type'== 'context' )
  228.                     {    // We want to preserve current browsing context:
  229.                         echo regenerate_url'blog,cats,catsel''blog='.$curr_blog_ID );
  230.                     }
  231.                     else
  232.                     {
  233.                         $loop_Blog->disp('url','raw');
  234.                     }
  235.                     echo '">';
  236.                     $loop_Blog->disp('name');
  237.                     echo '</a>';
  238.                     echo $this->disp_params['coll_end'];
  239.                 }
  240.  
  241.                 $r $ChapterCache->recurse$callbacks$curr_blog_ID );
  242.  
  243.                 ifempty($r) )
  244.                 {
  245.                     echo $this->disp_params['list_start'];
  246.                     echo $r;
  247.                     echo $this->disp_params['list_end'];
  248.                 }
  249.             }
  250.         }
  251.  
  252.  
  253.         if$this->disp_params['use_form'|| $this->disp_params['display_checkboxes')
  254.         {    // We want to add form fields:
  255.         ?>
  256.             <div class="tile">
  257.                 <input type="radio" name="cat" value="" id="catANY" class="radio" <?php if$cat_modifier != '-' && $cat_modifier != '*' echo 'checked="checked" '?> />
  258.                 <label for="catANY"><?php echo T_('ANY'?></label>
  259.             </div>
  260.             <div class="tile">
  261.                 <input type="radio" name="cat" value="-" id="catANYBUT" class="radio" <?php if$cat_modifier == '-' echo 'checked="checked" '?> />
  262.                 <label for="catANYBUT"><?php echo T_('ANY BUT'?></label>
  263.             </div>
  264.             <div class="tile">
  265.                 <input type="radio" name="cat" value="*" id="catALL" class="radio" <?php if$cat_modifier == '*' echo 'checked="checked" '?> />
  266.                 <label for="catALL"><?php echo T_('ALL'?></label>
  267.             </div>
  268.         <?php
  269.             if$this->disp_params['use_form')
  270.             {    // We want a complete form:
  271.             ?>
  272.                 <div class="tile">
  273.                     <input type="submit" value="<?php echo T_'Filter categories' )?>" />
  274.                 </div>
  275.                 </form>
  276.             <?php
  277.             }
  278.         }
  279.  
  280.         echo $this->disp_params['block_end'];
  281.  
  282.         return true;
  283.     }
  284.  
  285.  
  286.     /**
  287.      * Callback: Generate category line when it has children
  288.      *
  289.      * @param Chapter generic category we want to display
  290.      * @param int level of the category in the recursive tree
  291.      * @return string HTML
  292.      */
  293.     function cat_line$Chapter$level )
  294.     {
  295.         global $cat_array;
  296.  
  297.         if!isset($cat_array) )
  298.         {
  299.             $cat_array array();
  300.         }
  301.  
  302.         ifin_array$Chapter->ID$cat_array ) )
  303.         // This category is in the current selection
  304.             $r $this->disp_params['item_selected_start'];
  305.         }
  306.         else
  307.         {
  308.             $r $this->disp_params['item_start'];
  309.         }
  310.  
  311.         if$this->disp_params['use_form'|| $this->disp_params['display_checkboxes')
  312.         {    // We want to add form fields:
  313.             $r .= '<label><input type="checkbox" name="catsel[]" value="'.$Chapter->ID.'" class="checkbox"';
  314.             ifin_array$Chapter->ID$cat_array ) )
  315.             // This category is in the current selection
  316.                 $r .= ' checked="checked"';
  317.             }
  318.             $r .= ' /> ';
  319.         }
  320.  
  321.         $r .= '<a href="';
  322.  
  323.         if$this->disp_params['link_type'== 'context' )
  324.         {    // We want to preserve current browsing context:
  325.             $r .= regenerate_url'cats,catsel''cat='.$Chapter->ID );
  326.         }
  327.         else
  328.         {
  329.             $r .= $Chapter->get_permanent_url();
  330.         }
  331.  
  332.         $r .= '">'.$Chapter->dget('name').'</a>';
  333.  
  334.         if$this->disp_params['use_form'|| $this->disp_params['display_checkboxes')
  335.         {    // We want to add form fields:
  336.             $r .= '</label>';
  337.         }
  338.  
  339.         // Do not end line here because we need to include children first!
  340.         // $r .= $this->disp_params['item_end'];
  341.  
  342.         return $r;
  343.     }
  344.  
  345.  
  346.     /**
  347.      * Callback: Generate category line when it has no children
  348.      *
  349.      * @param Chapter generic category we want to display
  350.      * @param int level of the category in the recursive tree
  351.      * @return string HTML
  352.      */
  353.     function cat_no_children$Chapter$level )
  354.     {
  355.         // End current line:
  356.         return $this->disp_params['item_end'];
  357.     }
  358.  
  359.  
  360.     /**
  361.      * Callback: Generate code when entering a new level
  362.      *
  363.      * @param int level of the category in the recursive tree
  364.      * @return string HTML
  365.      */
  366.     function cat_before_level$level )
  367.     {
  368.         $r '';
  369.         if$level )
  370.         {    // If this is not the root:
  371.             $r .= $this->disp_params['group_start'];
  372.         }
  373.         return $r;
  374.     }
  375.  
  376.  
  377.     /**
  378.      * Callback: Generate code when exiting from a level
  379.      *
  380.      * @param int level of the category in the recursive tree
  381.      * @return string HTML
  382.      */
  383.     function cat_after_level$level )
  384.     {
  385.         $r '';
  386.         if$level )
  387.         {    // If this is not the root:
  388.             $r .= $this->disp_params['group_end'];
  389.             // End current (parent) line:
  390.             $r .= $this->disp_params['item_end'];
  391.         }
  392.         return $r;
  393.     }
  394. }
  395.  
  396.  
  397. /*
  398.  * $Log: _coll_category_list.widget.php,v $
  399.  * Revision 1.26  2010/02/26 02:05:09  sam2kb
  400.  * Sanitize aggregate_coll_IDs array
  401.  *
  402.  * Revision 1.25  2010/02/08 17:54:47  efy-yury
  403.  * copyright 2009 -> 2010
  404.  *
  405.  * Revision 1.24  2009/09/26 12:00:44  tblue246
  406.  * Minor/coding style
  407.  *
  408.  * Revision 1.23  2009/09/25 07:33:31  efy-cantor
  409.  * replace get_cache to get_*cache
  410.  *
  411.  * Revision 1.22  2009/09/14 13:54:13  efy-arrin
  412.  * Included the ClassName in load_class() call with proper UpperCase
  413.  *
  414.  * Revision 1.21  2009/09/12 11:03:12  efy-arrin
  415.  * Included the ClassName in the loadclass() with proper UpperCase
  416.  *
  417.  * Revision 1.20  2009/03/13 02:32:07  fplanque
  418.  * Cleaned up widgets.
  419.  * Removed stupid widget_name param.
  420.  *
  421.  * Revision 1.19  2009/03/10 13:53:04  tblue246
  422.  * Fixing the "Category list" widget again, now hopefully without making the backoffice sidebar look ugly...
  423.  *
  424.  * Revision 1.18  2009/03/08 23:57:46  fplanque
  425.  * 2009
  426.  *
  427.  * Revision 1.17  2009/03/08 23:08:35  fplanque
  428.  * rollback: NOT A BUG (this "fix" ads an unwanted button to admin)
  429.  * There should probably be no public setting for the form mode.
  430.  * (Or there should be an option for "standalone form".)
  431.  *
  432.  * Revision 1.16  2009/03/07 23:14:34  tblue246
  433.  * Bugfix for bugfix
  434.  *
  435.  * Revision 1.15  2009/03/07 22:41:13  tblue246
  436.  * Display submit button on category widget when requested (fixes https://bugs.launchpad.net/b2evolution/+bug/194849 ).
  437.  *
  438.  * Revision 1.14  2009/01/23 00:06:25  blueyed
  439.  * Support '*' for aggregate_coll_IDs in coll_category_list.widget, too.
  440.  *
  441.  * Revision 1.13  2008/05/30 19:57:37  blueyed
  442.  * really fix indent
  443.  *
  444.  * Revision 1.12  2008/05/30 16:39:06  blueyed
  445.  * Indent, doc
  446.  *
  447.  * Revision 1.11  2008/05/06 23:35:47  fplanque
  448.  * 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.
  449.  *
  450.  * Revision 1.9  2008/01/21 09:35:37  fplanque
  451.  * (c) 2008
  452.  *
  453.  * Revision 1.8  2008/01/06 17:52:50  fplanque
  454.  * minor/doc
  455.  *
  456.  * Revision 1.7  2008/01/06 15:35:34  blueyed
  457.  * - added "disp_names_for_coll_list" param
  458.  * -doc
  459.  *
  460.  * Revision 1.6  2007/12/23 16:16:18  fplanque
  461.  * Wording improvements
  462.  *
  463.  * Revision 1.5  2007/12/23 14:14:25  fplanque
  464.  * Enhanced widget name display
  465.  *
  466.  * Revision 1.4  2007/12/22 19:54:59  yabs
  467.  * cleanup from adding core params
  468.  *
  469.  * Revision 1.3  2007/11/27 10:01:05  yabs
  470.  * validation
  471.  *
  472.  * Revision 1.2  2007/07/01 15:12:28  fplanque
  473.  * simplified 'use_form'
  474.  *
  475.  * Revision 1.1  2007/07/01 03:55:04  fplanque
  476.  * category plugin replaced by widget
  477.  *
  478.  */
  479. ?>

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