~quam-plures-core/quam-plures/multiple_user_adsense

« back to all changes in this revision

Viewing changes to qp_plugins/category_list_widget/_category_list.widget.php

  • Committer: EdB
  • Date: 2013-02-25 05:03:58 UTC
  • mfrom: (7618.1.37 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20130225050358-v7ogz34ydcvohkq6
updating to current core

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * This file implements the Category list Widget class.
 
4
 *
 
5
 * This file is part of Quam Plures - {@link http://quamplures.net/}
 
6
 * See also {@link https://launchpad.net/quam-plures}.
 
7
 *
 
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/}.
 
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://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
 
19
 * }}
 
20
 *
 
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.
 
24
 *
 
25
 * @package widgets
 
26
 */
 
27
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
28
 
 
29
load_class( 'widgets/model/_widget.class.php' );
 
30
 
 
31
 
 
32
/**
 
33
 * @package widgets
 
34
 */
 
35
class category_list_Widget extends ComponentWidget
 
36
{
 
37
        /**
 
38
         * Constructor
 
39
         */
 
40
        function category_list_Widget( $db_row = NULL )
 
41
        {
 
42
                // Call parent constructor:
 
43
                parent::ComponentWidget( $db_row, 'widget', 'category_list' );
 
44
 
 
45
                $this->widget_name = $this->T_('Category list');
 
46
                $this->widget_title = $this->T_('Categories');
 
47
        }
 
48
 
 
49
 
 
50
 
 
51
        /**
 
52
         * Get a very short desc. Used in the widget list.
 
53
         */
 
54
        function get_short_desc()
 
55
        {
 
56
                return format_to_output($this->disp_params['widget_title']);
 
57
        }
 
58
 
 
59
 
 
60
        /**
 
61
         * Get short description
 
62
         */
 
63
        function get_desc()
 
64
        {
 
65
                return $this->T_('List of all categories; click filters blog on selected category.');
 
66
        }
 
67
 
 
68
 
 
69
        /**
 
70
         * Get definitions for editable params
 
71
         *
 
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)
 
79
         */
 
80
        function get_param_definitions( $params )
 
81
        {
 
82
                $r = array_merge( array(
 
83
                        'option_all' => array(
 
84
                                        'type' => 'text',
 
85
                                        'label' => $this->T_('Option "All"'),
 
86
                                        'defaultvalue' => $this->T_('All'),
 
87
                                        'maxlength' => 100,
 
88
                                        'note' => $this->T_('The "All categories" link allows to reset the filter. Leave blank if you want no such option.'),
 
89
                                ),
 
90
                        'use_form' => array(
 
91
                                        'type' => 'checkbox',
 
92
                                        'label' => $this->T_('Use form'),
 
93
                                        'defaultvalue' => 0,
 
94
                                        'note' => $this->T_('Add checkboxes to allow selection of multiple categories.'),
 
95
                                ),
 
96
                        'disp_names_for_coll_list' => array(
 
97
                                        'type' => 'checkbox',
 
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.'),
 
101
                                ),
 
102
 
 
103
                        // Hidden, used by the item list sidebar in the backoffice.
 
104
                        'display_checkboxes' => array(
 
105
                                        'label' => 'Internal: Display checkboxes', // This key is required
 
106
                                        'defaultvalue' => 0,
 
107
                                        'no_edit' => true,
 
108
                                ),
 
109
                        ), parent::get_param_definitions( $params ) );
 
110
 
 
111
                return $r;
 
112
        }
 
113
 
 
114
 
 
115
        /**
 
116
         * Display the widget!
 
117
         *
 
118
         * @param array MUST contain at least the basic display params
 
119
         */
 
120
        function display( $params )
 
121
        {
 
122
                global $cat_modifier;
 
123
                global $Blog;
 
124
 
 
125
                $this->init_display( $params );
 
126
 
 
127
                /**
 
128
                 * @var ChapterCache
 
129
                 */
 
130
                $ChapterCache = & get_Cache( 'ChapterCache' );
 
131
 
 
132
                $callbacks = array(
 
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' )
 
137
                );
 
138
 
 
139
                // START DISPLAY:
 
140
                echo $this->disp_params['block_start'];
 
141
 
 
142
                // Display title if requested
 
143
                $this->disp_title();
 
144
 
 
145
                if ( $this->disp_params['use_form'] )
 
146
                {       // We want a complete form:
 
147
                        echo '<form method="get" action="'.$Blog->gen_blogurl().'">';
 
148
                }
 
149
 
 
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 ____________________
 
153
                        $tmp_disp = '';
 
154
 
 
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' );
 
161
                                }
 
162
                                else
 
163
                                {
 
164
                                        $tmp_disp .= $Blog->gen_blogurl();
 
165
                                }
 
166
                                $tmp_disp .= '">'.$this->disp_params['option_all'].'</a>';
 
167
                                $tmp_disp .= $this->disp_params['item_end'];
 
168
                        }
 
169
 
 
170
                        $r = $tmp_disp . $ChapterCache->recurse( $callbacks, $Blog->ID );
 
171
 
 
172
                        if( ! empty($r) )
 
173
                        {
 
174
                                echo $this->disp_params['list_start'];
 
175
                                echo $r;
 
176
                                echo $this->disp_params['list_end'];
 
177
                        }
 
178
                }
 
179
                else
 
180
                { // ____________________ We want to display cats for SEVERAL blogs ____________________
 
181
 
 
182
                        $BlogCache = & get_Cache( 'BlogCache' );
 
183
 
 
184
                        // Make sure everything is loaded at once (vs multiple queries)
 
185
                        // fp> TODO: scaling
 
186
                        $ChapterCache->load_all();
 
187
 
 
188
                        echo $this->disp_params['collist_start'];
 
189
 
 
190
                        if( $aggregate_coll_IDs == '*' )
 
191
                        {
 
192
                                $BlogCache->load_all();
 
193
                                $coll_ID_array = $BlogCache->get_ID_array();
 
194
                        }
 
195
                        else
 
196
                        {
 
197
                                $coll_ID_array = explode( ',', $aggregate_coll_IDs );
 
198
                        }
 
199
                        foreach( $coll_ID_array as $curr_blog_ID )
 
200
                        {
 
201
                                // Get blog:
 
202
                                $loop_Blog = & $BlogCache->get_by_ID( $curr_blog_ID, false );
 
203
                                if( empty($loop_Blog) )
 
204
                                {       // That one doesn't exist (any more?)
 
205
                                        continue;
 
206
                                }
 
207
 
 
208
                                // Display blog title, if requested:
 
209
                                if( $this->disp_params['disp_names_for_coll_list'] )
 
210
                                {
 
211
                                        echo $this->disp_params['coll_start'];
 
212
                                        echo '<a href="';
 
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 );
 
216
                                        }
 
217
                                        else
 
218
                                        {
 
219
                                                $loop_Blog->disp('url','raw');
 
220
                                        }
 
221
                                        echo '">';
 
222
                                        $loop_Blog->disp('name');
 
223
                                        echo '</a>';
 
224
                                        echo $this->disp_params['coll_end'];
 
225
                                }
 
226
 
 
227
                                $r = $ChapterCache->recurse( $callbacks, $curr_blog_ID );
 
228
 
 
229
                                if( ! empty($r) )
 
230
                                {
 
231
                                        echo $this->disp_params['list_start'];
 
232
                                        echo $r;
 
233
                                        echo $this->disp_params['list_end'];
 
234
                                }
 
235
                        }
 
236
                }
 
237
 
 
238
 
 
239
                if( $this->disp_params['use_form'] || $this->disp_params['display_checkboxes'] )
 
240
                {       // We want to add form fields:
 
241
                ?>
 
242
                        <div class="tile">
 
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>
 
245
                        </div>
 
246
                        <div class="tile">
 
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>
 
249
                        </div>
 
250
                        <div class="tile">
 
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>
 
253
                        </div>
 
254
                <?php
 
255
                        if( $this->disp_params['use_form'] )
 
256
                        {       // We want a complete form:
 
257
                        ?>
 
258
                                <div class="tile">
 
259
                                        <input type="submit" value="<?php echo $this->T_('Filter categories'); ?>" />
 
260
                                </div>
 
261
                                </form>
 
262
                        <?php
 
263
                        }
 
264
                }
 
265
 
 
266
                echo $this->disp_params['block_end'];
 
267
 
 
268
                return true;
 
269
        }
 
270
 
 
271
 
 
272
        /**
 
273
         * Callback: Generate category line when it has children
 
274
         *
 
275
         * @param Chapter generic category we want to display
 
276
         * @param int level of the category in the recursive tree
 
277
         * @return string HTML
 
278
         */
 
279
        function cat_line( $Chapter, $level )
 
280
        {
 
281
                global $cat_array;
 
282
 
 
283
                if( !isset($cat_array) )
 
284
                {
 
285
                        $cat_array = array();
 
286
                }
 
287
 
 
288
                if( in_array( $Chapter->ID, $cat_array ) )
 
289
                { // This category is in the current selection
 
290
                        $r = $this->disp_params['item_selected_start'];
 
291
                }
 
292
                else
 
293
                {
 
294
                        $r = $this->disp_params['item_start'];
 
295
                }
 
296
 
 
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"';
 
303
                        }
 
304
                        $r .= ' /> ';
 
305
                }
 
306
 
 
307
                $r .= '<a href="';
 
308
 
 
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 );
 
312
                }
 
313
                else
 
314
                {
 
315
                        $r .= $Chapter->get_permanent_url();
 
316
                }
 
317
 
 
318
                $r .= '">'.$Chapter->dget('name').'</a>';
 
319
 
 
320
                if( $this->disp_params['use_form'] || $this->disp_params['display_checkboxes'] )
 
321
                {       // We want to add form fields:
 
322
                        $r .= '</label>';
 
323
                }
 
324
 
 
325
                // Do not end line here because we need to include children first!
 
326
                // $r .= $this->disp_params['item_end'];
 
327
 
 
328
                return $r;
 
329
        }
 
330
 
 
331
 
 
332
        /**
 
333
         * Callback: Generate category line when it has no children
 
334
         *
 
335
         * @param Chapter generic category we want to display
 
336
         * @param int level of the category in the recursive tree
 
337
         * @return string HTML
 
338
         */
 
339
        function cat_no_children( $Chapter, $level )
 
340
        {
 
341
                // End current line:
 
342
                return $this->disp_params['item_end'];
 
343
        }
 
344
 
 
345
 
 
346
        /**
 
347
         * Callback: Generate code when entering a new level
 
348
         *
 
349
         * @param int level of the category in the recursive tree
 
350
         * @return string HTML
 
351
         */
 
352
        function cat_before_level( $level )
 
353
        {
 
354
                $r = '';
 
355
                if( $level > 0 )
 
356
                {       // If this is not the root:
 
357
                        $r .= $this->disp_params['group_start'];
 
358
                }
 
359
                return $r;
 
360
        }
 
361
 
 
362
 
 
363
        /**
 
364
         * Callback: Generate code when exiting from a level
 
365
         *
 
366
         * @param int level of the category in the recursive tree
 
367
         * @return string HTML
 
368
         */
 
369
        function cat_after_level( $level )
 
370
        {
 
371
                $r = '';
 
372
                if( $level > 0 )
 
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'];
 
377
                }
 
378
                return $r;
 
379
        }
 
380
}
 
381
 
 
382
 
 
383
?>