3
* This file implements the Category list Widget class.
5
* This file is part of Quam Plures - {@link http://quamplures.net/}
6
* See also {@link https://launchpad.net/quam-plures}.
8
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
9
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
10
* Parts of this file are copyright (c)2008 by Daniel HAHLER - {@link http://daniel.hahler.de/}.
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://evocms.cvs.sourceforge.net/)
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
21
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
22
* @author blueyed: Daniel HAHLER
23
* @author fplanque: Francois PLANQUE.
27
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
29
load_class( 'widgets/model/_widget.class.php' );
35
class category_list_Widget extends ComponentWidget
40
function category_list_Widget( $db_row = NULL )
42
// Call parent constructor:
43
parent::ComponentWidget( $db_row, 'widget', 'category_list' );
45
$this->widget_name = $this->T_('Category list');
46
$this->widget_title = $this->T_('Categories');
52
* Get a very short desc. Used in the widget list.
54
function get_short_desc()
56
return format_to_output($this->disp_params['widget_title']);
61
* Get short description
65
return $this->T_('List of all categories; click filters blog on selected category.');
70
* Get definitions for editable params
72
* @see Plugin::GetDefaultSettings()
73
* @param array local params
74
* - 'title': block title (string, default "Categories")
75
* - 'option_all': "All categories" link title, empty to disable (string, default "All")
76
* - 'use_form': Add a form with checkboxes to allow selection of multiple categories (boolean)
77
* - 'disp_names_for_coll_list': Display blog names, if this is an aggregated blog? (boolean)
78
* - 'display_checkboxes': Add checkboxes (but not a complete form) to allow selection of multiple categories (boolean)
80
function get_param_definitions( $params )
82
$r = array_merge( array(
83
'option_all' => array(
85
'label' => $this->T_('Option "All"'),
86
'defaultvalue' => $this->T_('All'),
88
'note' => $this->T_('The "All categories" link allows to reset the filter. Leave blank if you want no such option.'),
92
'label' => $this->T_('Use form'),
94
'note' => $this->T_('Add checkboxes to allow selection of multiple categories.'),
96
'disp_names_for_coll_list' => array(
98
'label' => $this->T_('Display blog names'),
99
'defaultvalue' => 1, /* previous behaviour */
100
'note' => $this->T_('Display blog names, if this is an aggregated blog.'),
103
// Hidden, used by the item list sidebar in the backoffice.
104
'display_checkboxes' => array(
105
'label' => 'Internal: Display checkboxes', // This key is required
109
), parent::get_param_definitions( $params ) );
116
* Display the widget!
118
* @param array MUST contain at least the basic display params
120
function display( $params )
122
global $cat_modifier;
125
$this->init_display( $params );
130
$ChapterCache = & get_Cache( 'ChapterCache' );
133
'line' => array( $this, 'cat_line' ),
134
'no_children' => array( $this, 'cat_no_children' ),
135
'before_level' => array( $this, 'cat_before_level' ),
136
'after_level' => array( $this, 'cat_after_level' )
140
echo $this->disp_params['block_start'];
142
// Display title if requested
145
if ( $this->disp_params['use_form'] )
146
{ // We want a complete form:
147
echo '<form method="get" action="'.$Blog->gen_blogurl().'">';
150
$aggregate_coll_IDs = $Blog->get_setting('aggregate_coll_IDs');
151
if( empty($aggregate_coll_IDs) )
152
{ // ____________________ We want to display cats for ONE blog ____________________
155
if( $this->disp_params['option_all'] )
156
{ // We want to display a link to all cats:
157
$tmp_disp .= $this->disp_params['item_start'].'<a href="';
158
if( $this->disp_params['link_type'] == 'context' )
159
{ // We want to preserve current browsing context:
160
$tmp_disp .= regenerate_url( 'cats,catsel' );
164
$tmp_disp .= $Blog->gen_blogurl();
166
$tmp_disp .= '">'.$this->disp_params['option_all'].'</a>';
167
$tmp_disp .= $this->disp_params['item_end'];
170
$r = $tmp_disp . $ChapterCache->recurse( $callbacks, $Blog->ID );
174
echo $this->disp_params['list_start'];
176
echo $this->disp_params['list_end'];
180
{ // ____________________ We want to display cats for SEVERAL blogs ____________________
182
$BlogCache = & get_Cache( 'BlogCache' );
184
// Make sure everything is loaded at once (vs multiple queries)
186
$ChapterCache->load_all();
188
echo $this->disp_params['collist_start'];
190
if( $aggregate_coll_IDs == '*' )
192
$BlogCache->load_all();
193
$coll_ID_array = $BlogCache->get_ID_array();
197
$coll_ID_array = explode( ',', $aggregate_coll_IDs );
199
foreach( $coll_ID_array as $curr_blog_ID )
202
$loop_Blog = & $BlogCache->get_by_ID( $curr_blog_ID, false );
203
if( empty($loop_Blog) )
204
{ // That one doesn't exist (any more?)
208
// Display blog title, if requested:
209
if( $this->disp_params['disp_names_for_coll_list'] )
211
echo $this->disp_params['coll_start'];
213
if( $this->disp_params['link_type'] == 'context' )
214
{ // We want to preserve current browsing context:
215
echo regenerate_url( 'blog,cats,catsel', 'blog='.$curr_blog_ID );
219
$loop_Blog->disp('url','raw');
222
$loop_Blog->disp('name');
224
echo $this->disp_params['coll_end'];
227
$r = $ChapterCache->recurse( $callbacks, $curr_blog_ID );
231
echo $this->disp_params['list_start'];
233
echo $this->disp_params['list_end'];
239
if( $this->disp_params['use_form'] || $this->disp_params['display_checkboxes'] )
240
{ // We want to add form fields:
243
<input type="radio" name="cat" value="" id="catANY" class="radio" <?php if( $cat_modifier != '-' && $cat_modifier != '*' ) echo 'checked="checked" '?> />
244
<label for="catANY"><?php echo $this->T_('ANY') ?></label>
247
<input type="radio" name="cat" value="-" id="catANYBUT" class="radio" <?php if( $cat_modifier == '-' ) echo 'checked="checked" '?> />
248
<label for="catANYBUT"><?php echo $this->T_('ANY BUT') ?></label>
251
<input type="radio" name="cat" value="*" id="catALL" class="radio" <?php if( $cat_modifier == '*' ) echo 'checked="checked" '?> />
252
<label for="catALL"><?php echo $this->T_('ALL') ?></label>
255
if( $this->disp_params['use_form'] )
256
{ // We want a complete form:
259
<input type="submit" value="<?php echo $this->T_('Filter categories'); ?>" />
266
echo $this->disp_params['block_end'];
273
* Callback: Generate category line when it has children
275
* @param Chapter generic category we want to display
276
* @param int level of the category in the recursive tree
277
* @return string HTML
279
function cat_line( $Chapter, $level )
283
if( !isset($cat_array) )
285
$cat_array = array();
288
if( in_array( $Chapter->ID, $cat_array ) )
289
{ // This category is in the current selection
290
$r = $this->disp_params['item_selected_start'];
294
$r = $this->disp_params['item_start'];
297
if( $this->disp_params['use_form'] || $this->disp_params['display_checkboxes'] )
298
{ // We want to add form fields:
299
$r .= '<label><input type="checkbox" name="catsel[]" value="'.$Chapter->ID.'" class="checkbox"';
300
if( in_array( $Chapter->ID, $cat_array ) )
301
{ // This category is in the current selection
302
$r .= ' checked="checked"';
309
if( $this->disp_params['link_type'] == 'context' )
310
{ // We want to preserve current browsing context:
311
$r .= regenerate_url( 'cats,catsel', 'cat='.$Chapter->ID );
315
$r .= $Chapter->get_permanent_url();
318
$r .= '">'.$Chapter->dget('name').'</a>';
320
if( $this->disp_params['use_form'] || $this->disp_params['display_checkboxes'] )
321
{ // We want to add form fields:
325
// Do not end line here because we need to include children first!
326
// $r .= $this->disp_params['item_end'];
333
* Callback: Generate category line when it has no children
335
* @param Chapter generic category we want to display
336
* @param int level of the category in the recursive tree
337
* @return string HTML
339
function cat_no_children( $Chapter, $level )
342
return $this->disp_params['item_end'];
347
* Callback: Generate code when entering a new level
349
* @param int level of the category in the recursive tree
350
* @return string HTML
352
function cat_before_level( $level )
356
{ // If this is not the root:
357
$r .= $this->disp_params['group_start'];
364
* Callback: Generate code when exiting from a level
366
* @param int level of the category in the recursive tree
367
* @return string HTML
369
function cat_after_level( $level )
373
{ // If this is not the root:
374
$r .= $this->disp_params['group_end'];
375
// End current (parent) line:
376
$r .= $this->disp_params['item_end'];