~quam-plures-core/quam-plures/qp5_colls-blogs_chaps-cats

« back to all changes in this revision

Viewing changes to qp_plugins/archives_plugin/_archives.plugin.php

  • Committer: EdB
  • Date: 2013-03-12 06:26:03 UTC
  • Revision ID: 1912webworks@gmail.com-20130312062603-tnlb5zco5mglydqj
lots of changes in this branch. tested and functional, but not going into merge just yet ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
 * This file implements the Archives plugin.
4
 
 *
5
 
 * Displays a list of post archives.
6
 
 *
7
 
 * This file is part of the Quam Plures project - {@link http://quamplures.net/}
8
 
 *
9
 
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
10
 
 * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
11
 
 * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
12
 
 *
13
 
 * {@internal License choice
14
 
 * - If you have received this file as part of a package, please find the license.txt file in
15
 
 *   the same folder or the closest folder above for complete license terms.
16
 
 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
17
 
 *   then you must choose one of the following licenses before using the file:
18
 
 *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
19
 
 *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
20
 
 * }}
21
 
 *
22
 
 * {@internal Open Source relicensing agreement:
23
 
 * Daniel HAHLER grants Francois PLANQUE the right to license
24
 
 * Daniel HAHLER's contributions to this file and the b2evolution project
25
 
 * under any OSI approved OSS license (http://www.opensource.org/licenses/).
26
 
 * }}
27
 
 *
28
 
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
29
 
 * @author blueyed: Daniel HAHLER.
30
 
 * @author fplanque: Francois PLANQUE - {@link http://fplanque.net/}
 
3
 * This file implements the Archives plugin
 
4
 *
 
5
 * @todo (2033) EdB> why does this have 2 title fields? one setting, one default setting...
 
6
 *
 
7
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
8
 * @author {@link http://daniel.hahler.de/ Daniel HAHLER}
 
9
 * @author {@link http://fplanque.net/ Francois PLANQUE}
31
10
 * @author cafelog (group)
32
 
 *
 
11
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
12
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
33
13
 * @package plugins
34
14
 * @subpackage Archives
35
15
 */
36
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
37
 
 
38
 
load_class('_core/ui/results/_results.class.php');
39
 
 
 
16
if(!defined('QP_MAIN_INIT')) die('fail');
40
17
 
41
18
/**
42
19
 * @package plugins
48
25
        var $group = 'widgets';
49
26
        var $number_of_installs = 1;
50
27
        var $priority = 50;
51
 
        var $version = '0.1';
52
 
 
 
28
        var $version = '1.0';
53
29
 
54
30
        /**
55
31
         * @see Plugin::PluginInit()
56
32
         */
57
33
        function PluginInit( & $params )
58
34
        {
59
 
                $this->name = $this->T_('Archives Widget');
 
35
                $this->name = $this->T_('Archives');
60
36
                $this->short_desc = $this->T_('This template tag displays a list of post archives.');
61
 
                $this->long_desc = $this->T_('Archives can be grouped monthly, daily, weekly or post by post.');
 
37
                $this->long_desc = $this->T_('Creates a widget that displays your post archives; grouped monthly, daily, weekly or post by post.');
62
38
 
63
39
                $this->dbtable = 'T_items__item';
64
40
                $this->dbprefix = 'post_';
67
43
 
68
44
 
69
45
        /**
 
46
         * @see Plugin::GetDefaultWidgetSettings()
 
47
         */
 
48
        function GetDefaultWidgetSettings( $params )
 
49
        {
 
50
                $default_widget_settings = array(
 
51
                        'title' => array(
 
52
                                'label' => $this->T_('Block title'),
 
53
                                'defaultvalue' => $this->T_('Archives'),
 
54
                                'size' => 60,
 
55
                                'note' => $this->T_('Title to display in your template.'),
 
56
                        ),
 
57
                        'limit' => array(
 
58
                                'label' => $this->T_('Max items'),
 
59
                                'defaultvalue' => 12,
 
60
                                'size' => 4,
 
61
                                'note' => $this->T_('Maximum number of items to display.'),
 
62
                        ),
 
63
                );
 
64
                return $default_widget_settings;
 
65
        }
 
66
 
 
67
 
 
68
        /**
70
69
         * Event handler: TemplateTag
71
70
         *
72
71
         * @param array Associative array of parameters. Valid keys are:
89
88
         */
90
89
        function TemplateTag( $params )
91
90
        {
92
 
                global $month;
93
 
 
94
 
                /**
95
 
                 * @todo get rid of this global:
96
 
                 */
 
91
                global $Blog;
97
92
                global $m;
98
 
 
99
 
                /**
100
 
                 * @var Blog
101
 
                 */
102
 
                global $Blog;
103
 
 
104
 
                if( empty($Blog) )
 
93
                global $month;
 
94
 
 
95
                if( empty( $Blog ) )
105
96
                {
106
97
                        return false;
107
98
                }
108
99
 
109
 
                /**
110
 
                 * Default params:
111
 
                 */
 
100
                // Default params
112
101
                $params = array_merge( array(
113
 
                                // This is what will enclose the block in the template:
114
 
                                'block_start' => '<div class="bSideItem">',
115
 
                                'block_end' => "</div>\n",
116
 
                                // Title:
117
 
                                'block_title_start' => '<h3>',
118
 
                                'block_title_end' => '</h3>',
119
 
                                // Archive mode:
120
 
                                'mode' => $Blog->get_setting('archive_mode'),
121
 
                                // Link type:
122
 
                                'link_type' => 'canonic',
123
 
                                'context_isolation' => 'm,w,p,title,unit,dstart',
124
 
                                // Add form fields?:
125
 
                                'form' => false,
126
 
                                // Number of archive entries to display:
127
 
                                'limit' => 12,
128
 
                                // More link text:
129
 
                                'more_link' => $this->T_('More...'),
130
 
                                // This is what will enclose the list:
131
 
                                'list_start' => '<ul>',
132
 
                                'list_end' => "</ul>\n",
133
 
                                // This is what will separate the archive links:
134
 
                                'line_start' => '<li>',
135
 
                                'line_end' => "</li>\n",
136
 
                                'sort_order' => 'date',
137
 
                                // Daily archive date format?
138
 
                                'day_date_format' => locale_datefmt(),
139
 
                        ), $params );
 
102
                        'block_start' => '<div class="bSideItem">',
 
103
                        'block_end' => "</div>\n",
 
104
                        'block_title_start' => '<h3>',
 
105
                        'block_title_end' => '</h3>',
 
106
                        'mode' => $Blog->get_setting( 'archive_mode' ),
 
107
                        'link_type' => 'canonic',
 
108
                        'context_isolation' => 'm,w,p,title,unit,dstart',
 
109
                        'form' => false,
 
110
                        'limit' => 12,
 
111
                        'more_link' => $this->T_('More...'),
 
112
                        'list_start' => '<ul>',
 
113
                        'list_end' => "</ul>\n",
 
114
                        'line_start' => '<li>',
 
115
                        'line_end' => "</li>\n",
 
116
                        'sort_order' => 'date',
 
117
                        'day_date_format' => locale_datefmt(),
 
118
                ), $params );
140
119
 
141
 
                //Sort order (used only in postbypost mode):
142
 
                if($params['mode'] !='postbypost' || $params['sort_order'] == ''){
 
120
                // Sort order (used only in postbypost mode)
 
121
                if( $params['mode'] !='postbypost' || $params['sort_order'] == '' )
 
122
                {
143
123
                        $params['sort_order'] = 'date';
144
124
                }
145
125
 
149
129
                        $params['day_date_format'] = locale_datefmt();
150
130
                }
151
131
 
152
 
                $ArchiveList = new ArchiveList( $params['mode'], $params['limit'], $params['sort_order'], ($params['link_type'] == 'context'),
153
 
                                                                                                                                                        $this->dbtable, $this->dbprefix, $this->dbIDname );
 
132
                $ArchiveList = new ArchiveList(
 
133
                        $params['mode'], $params['limit'], $params['sort_order'],
 
134
                        ( $params['link_type'] == 'context' ),
 
135
                        $this->dbtable, $this->dbprefix, $this->dbIDname );
154
136
 
155
137
                echo $params['block_start'];
156
138
 
157
 
                if( !empty($params['title']) )
158
 
                {       // We want to display a title for the widget block:
 
139
                if( ! empty( $params['title'] ) )
 
140
                {
 
141
                        // We want to display a title for the widget block
159
142
                        echo $params['block_title_start'];
160
143
                        echo $params['title'];
161
144
                        echo $params['block_title_end'];
162
145
                }
163
146
 
164
147
                echo $params['list_start'];
165
 
                while( $ArchiveList->get_item( $arc_year, $arc_month, $arc_dayofmonth, $arc_w, $arc_count, $post_ID, $post_title) )
 
148
                while( $ArchiveList->get_item( $arc_year, $arc_month, $arc_dayofmonth, $arc_w, $arc_count, $post_ID, $post_title ) )
166
149
                {
167
150
                        echo $params['line_start'];
168
151
                        switch( $params['mode'] )
169
152
                        {
170
153
                                case 'monthly':
171
 
                                        // --------------------------------- MONTHLY ARCHIVES -------------------------------------
172
 
                                        $arc_m = $arc_year.zeroise($arc_month,2);
173
 
 
174
 
                                        if( $params['form'] )
175
 
                                        { // We want a radio button:
176
 
                                                echo '<input type="radio" name="m" value="'.$arc_m.'" class="checkbox"';
177
 
                                                if( $m == $arc_m ) echo ' checked="checked"' ;
178
 
                                                echo ' /> ';
179
 
                                        }
180
 
 
181
 
                                        $text = $this->T_($month[zeroise($arc_month,2)]).' '.$arc_year;
182
 
 
183
 
                                        if( $params['link_type'] == 'context' )
184
 
                                        {       // We want to preserve current browsing context:
185
 
                                                echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'm='.$arc_m ).'">'.$text.'</a>';
186
 
                                        }
187
 
                                        else
188
 
                                        {       // We want to link to the absolute canonical URL for this archive:
189
 
                                                echo $Blog->gen_archive_link( $text, $this->T_('View monthly archive'), $arc_year, $arc_month );
190
 
                                        }
191
 
 
192
 
                                        echo ' <span class="dimmed">('.$arc_count.')</span>';
193
 
                                        break;
 
154
                                $arc_m = $arc_year.zeroise( $arc_month, 2 );
 
155
                                if( $params['form'] )
 
156
                                {
 
157
                                        // We want a radio button
 
158
                                        echo '<input type="radio" name="m" value="'.$arc_m.'" class="checkbox"';
 
159
                                        if( $m == $arc_m ) echo ' checked="checked"' ;
 
160
                                        echo ' /> ';
 
161
                                }
 
162
                                $text = $this->T_( $month[zeroise( $arc_month,2 )] ).' '.$arc_year;
 
163
                                if( $params['link_type'] == 'context' )
 
164
                                {
 
165
                                        // We want to preserve current browsing context
 
166
                                        echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'm='.$arc_m ).'">'.$text.'</a>';
 
167
                                }
 
168
                                else
 
169
                                {
 
170
                                        // We want to link to the absolute canonical URL for this archive
 
171
                                        echo $Blog->gen_archive_link( $text, $this->T_('View monthly archive'), $arc_year, $arc_month );
 
172
                                }
 
173
                                echo ' <span class="dimmed">('.$arc_count.')</span>';
 
174
                                break;
194
175
 
195
176
                                case 'daily':
196
 
                                        // --------------------------------- DAILY ARCHIVES ---------------------------------------
197
 
                                        $arc_m = $arc_year.zeroise($arc_month,2).zeroise($arc_dayofmonth,2);
198
 
 
199
 
                                        if( $params['form'] )
200
 
                                        { // We want a radio button:
201
 
                                                echo '<input type="radio" name="m" value="'. $arc_m. '" class="checkbox"';
202
 
                                                if( $m == $arc_m ) echo ' checked="checked"' ;
203
 
                                                echo ' /> ';
204
 
                                        }
205
 
 
206
 
                                        $text = mysql2date($params['day_date_format'], $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00');
207
 
 
208
 
                                        if( $params['link_type'] == 'context' )
209
 
                                        {       // We want to preserve current browsing context:
210
 
                                                echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'm='.$arc_m ).'">'.$text.'</a>';
211
 
                                        }
212
 
                                        else
213
 
                                        {       // We want to link to the absolute canonical URL for this archive:
214
 
                                                echo $Blog->gen_archive_link( $text, $this->T_('View daily archive'), $arc_year, $arc_month, $arc_dayofmonth );
215
 
                                        }
216
 
 
217
 
                                        echo ' <span class="dimmed">('.$arc_count.')</span>';
218
 
                                        break;
 
177
                                $arc_m = $arc_year.zeroise( $arc_month, 2 ).zeroise( $arc_dayofmonth, 2 );
 
178
                                if( $params['form'] )
 
179
                                {
 
180
                                        // We want a radio button
 
181
                                        echo '<input type="radio" name="m" value="'. $arc_m. '" class="checkbox"';
 
182
                                        if( $m == $arc_m ) echo ' checked="checked"' ;
 
183
                                        echo ' /> ';
 
184
                                }
 
185
                                $text = mysql2date( $params['day_date_format'], $arc_year.'-'.zeroise( $arc_month, 2 ).'-'.zeroise( $arc_dayofmonth, 2 ).' 00:00:00');
 
186
                                if( $params['link_type'] == 'context' )
 
187
                                { // We want to preserve current browsing context
 
188
                                        echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'm='.$arc_m ).'">'.$text.'</a>';
 
189
                                }
 
190
                                else
 
191
                                {
 
192
                                        // We want to link to the absolute canonical URL for this archive
 
193
                                        echo $Blog->gen_archive_link( $text, $this->T_('View daily archive'), $arc_year, $arc_month, $arc_dayofmonth );
 
194
                                }
 
195
                                echo ' <span class="dimmed">('.$arc_count.')</span>';
 
196
                                break;
219
197
 
220
198
                                case 'weekly':
221
 
                                        // --------------------------------- WEEKLY ARCHIVES --------------------------------------
222
 
 
223
 
                                        $text = $arc_year.', '.$this->T_('week').' '.$arc_w;
224
 
 
225
 
                                        if( $params['link_type'] == 'context' )
226
 
                                        {       // We want to preserve current browsing context:
227
 
                                                echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'm='.$arc_year.'&amp;w='.$arc_w ).'">'.$text.'</a>';
228
 
                                        }
229
 
                                        else
230
 
                                        {       // We want to link to the absolute canonical URL for this archive:
231
 
                                                echo $Blog->gen_archive_link( $text, $this->T_('View weekly archive'), $arc_year, NULL, NULL, $arc_w );
232
 
                                        }
233
 
                                        echo ' <span class="dimmed">('.$arc_count.')</span>';
234
 
                                        break;
 
199
                                $text = $arc_year.', '.$this->T_('week').' '.$arc_w;
 
200
                                if( $params['link_type'] == 'context' )
 
201
                                {
 
202
                                        // We want to preserve current browsing context
 
203
                                        echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'm='.$arc_year.'&amp;w='.$arc_w ).'">'.$text.'</a>';
 
204
                                }
 
205
                                else
 
206
                                {
 
207
                                        // We want to link to the absolute canonical URL for this archive
 
208
                                        echo $Blog->gen_archive_link( $text, $this->T_('View weekly archive'), $arc_year, NULL, NULL, $arc_w );
 
209
                                }
 
210
                                echo ' <span class="dimmed">('.$arc_count.')</span>';
 
211
                                break;
235
212
 
236
213
                                case 'postbypost':
237
214
                                default:
238
 
                                        // -------------------------------- POST BY POST ARCHIVES ---------------------------------
239
 
 
240
 
                                        if( $post_title)
241
 
                                        {
242
 
                                                $text = strip_tags($post_title);
243
 
                                        }
244
 
                                        else
245
 
                                        {
246
 
                                                $text = $post_ID;
247
 
                                        }
248
 
 
249
 
                                        if( $params['link_type'] == 'context' )
250
 
                                        {       // We want to preserve current browsing context:
251
 
                                                echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'p='.$post_ID ).'">'.$text.'</a>';
252
 
                                        }
253
 
                                        else
254
 
                                        {       // We want to link to the absolute (canonical) URL for this archive:
255
 
                                                // fp> TODO: This is NOT canonical. To go to the canonical, we'd need a 'light' itemlist (which does not load too much data)
256
 
                                                // fp> Note: there may be a "redirect to canonical" anyway. Not optimal, but at least this is less broken than it was before.
257
 
                                                // fp> THIS IS ALL OBSOLETE. There is a better way to have a post list with a specific widget.
258
 
                                                // TO BE DELETED (waiting for photoblog cleanup)
259
 
                                                echo '<a href="'.url_add_param( $Blog->get('url'), 'p='.$post_ID.'&amp;more=1&amp;c=1&amp;tb=1' ).'">'.$text.'</a>';
260
 
                                        }
 
215
                                if( $post_title )
 
216
                                {
 
217
                                        $text = strip_tags( $post_title );
 
218
                                }
 
219
                                else
 
220
                                {
 
221
                                        $text = $post_ID;
 
222
                                }
 
223
 
 
224
                                if( $params['link_type'] == 'context' )
 
225
                                {
 
226
                                        // We want to preserve current browsing context
 
227
                                        echo '<a rel="nofollow" href="'.regenerate_url( $params['context_isolation'], 'p='.$post_ID ).'">'.$text.'</a>';
 
228
                                }
 
229
                                else
 
230
                                {
 
231
                                        // We want to link to the absolute (canonical) URL for this archive:
 
232
                                        // @todo (0000) fp> This is NOT canonical. To go to the canonical, we'd
 
233
                                        // need a 'light' itemlist (which does not load too much data)
 
234
                                        // fp> Note: there may be a "redirect to canonical" anyway. Not optimal,
 
235
                                        // but at least this is less broken than it was before.
 
236
                                        // fp> THIS IS ALL OBSOLETE. There is a better way to have a post list
 
237
                                        // with a specific widget. TO BE DELETED (waiting for photoblog cleanup)
 
238
                                        echo '<a href="'.url_add_param( $Blog->get( 'url' ), 'p='.$post_ID.'&amp;more=1&amp;c=1&amp;tb=1' ).'">'.$text.'</a>';
 
239
                                }
261
240
                        }
262
241
 
263
242
                        echo $params['line_end'];
264
243
                }
265
244
 
266
 
                // Display more link:
267
 
                if( !empty($params['more_link']) )
 
245
                // Display more link
 
246
                if( ! empty( $params['more_link'] ) )
268
247
                {
269
248
                        echo $params['line_start'];
270
249
                        echo '<a href="';
271
250
                        $Blog->disp( 'arcdirurl', 'raw' );
272
 
                        echo '">'.format_to_output($params['more_link']).'</a>';
 
251
                        echo '">'.format_to_output( $params['more_link'] ).'</a>';
273
252
                        echo $params['line_end'];
274
253
                }
275
254
 
276
255
                echo $params['list_end'];
277
 
 
278
256
                echo $params['block_end'];
279
257
 
280
258
                return true;
281
259
        }
282
260
 
283
 
 
284
 
  /**
285
 
         * @see Plugin::GetDefaultWidgetSettings()
286
 
         */
287
 
        function GetDefaultWidgetSettings( $params )
288
 
        {
289
 
                $r = array(
290
 
                        'title' => array(
291
 
                                        'label' => $this->T_('Block title'),
292
 
                                        'note' => $this->T_('Title to display in your template.'),
293
 
                                        'size' => 60,
294
 
                                        'defaultvalue' => $this->T_('Archives'),
295
 
                        ),
296
 
                        'limit' => array(
297
 
                                'label' => $this->T_('Max items'),
298
 
                                'note' => $this->T_('Maximum number of items to display.'),
299
 
                                'size' => 4,
300
 
                                'defaultvalue' => 12,
301
 
                        ),
302
 
                );
303
 
                return $r;
304
 
        }
305
 
 
306
261
}
307
262
 
308
 
 
309
263
/**
310
 
 * Archive List Class
 
264
 * ArchiveList class
311
265
 *
312
266
 * @package plugins
 
267
 * @subpackage Archives
313
268
 */
314
269
class ArchiveList extends Results
315
270
{
320
275
         * Constructor
321
276
         *
322
277
         * Note: Weekly archives use MySQL's week numbering and MySQL default if applicable.
323
 
         * In MySQL < 4.0.14, WEEK() always uses mode 0: Week starts on Sunday;
324
 
         * Value range is 0 to 53; week 1 is the first week that starts in this year.
 
278
         * In MySQL < 4.0.14, WEEK() always uses mode 0: Week starts on Sunday; Value range
 
279
         * is 0 to 53; week 1 is the first week that starts in this year.
325
280
         *
 
281
         * @todo (0000) categories combined with 'ALL' are not supported (will output
 
282
         * too many archives, some of which will resolve to no results). We need
 
283
         * subqueries to support this efficiently.
326
284
         * @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
327
 
         *
328
 
         * @todo categories combined with 'ALL' are not supported (will output too many archives,
329
 
         * some of which will resolve to no results). We need subqueries to support this efficiently.
330
 
         *
331
285
         * @param string
332
286
         * @param integer
333
287
         * @param boolean
341
295
                $dbprefix = 'post_',
342
296
                $dbIDname = 'ID' )
343
297
        {
 
298
                global $assgn;
 
299
                global $author;
 
300
                global $blog;
 
301
                global $cat;
 
302
                global $catsel;
344
303
                global $DB;
345
 
                global $blog, $cat, $catsel;
 
304
                global $exact;
 
305
                global $s;
 
306
                global $sentence;
346
307
                global $show_statuses;
347
 
                global $author, $assgn, $status, $types;
348
 
                global $timestamp_min, $timestamp_max;
349
 
                global $s, $sentence, $exact;
 
308
                global $status;
 
309
                global $types;
 
310
                global $timestamp_min;
 
311
                global $timestamp_max;
350
312
 
351
313
                $this->dbtable = $dbtable;
352
314
                $this->dbprefix = $dbprefix;
353
315
                $this->dbIDname = $dbIDname;
354
316
                $this->archive_mode = $archive_mode;
355
317
 
356
 
 
357
 
                /*
358
 
                 * WE ARE GOING TO CONSTRUCT THE WHERE CLOSE...
359
 
                 */
 
318
                // WE ARE GOING TO CONSTRUCT THE WHERE CLOSE...
360
319
                $this->ItemQuery = new ItemQuery( $this->dbtable, $this->dbprefix, $this->dbIDname ); // TEMPORARY OBJ
361
320
 
362
 
                // - - Select a specific Item:
 
321
                // - - Select a specific Item
363
322
                // $this->ItemQuery->where_ID( $p, $title );
364
323
 
365
324
                if( $preserve_context )
366
 
                {       // We want to preserve the current context:
367
 
                        // * - - Restrict to selected blog/categories:
368
 
                        $this->ItemQuery->where_chapter( $blog, $cat, $catsel );
369
 
 
370
 
                        // * Restrict to the statuses we want to show:
 
325
                {
 
326
                        // We want to preserve the current context
 
327
                        // * - - Restrict to selected blog/categories
 
328
                        $this->ItemQuery->where_category( $blog, $cat, $catsel );
 
329
                        // * Restrict to the statuses we want to show
371
330
                        $this->ItemQuery->where_visibility( $show_statuses );
372
 
 
373
 
                        // Restrict to selected authors:
 
331
                        // Restrict to selected authors
374
332
                        $this->ItemQuery->where_author( $author );
375
 
 
376
 
                        // Restrict to selected assignees:
 
333
                        // Restrict to selected assignees
377
334
                        $this->ItemQuery->where_assignees( $assgn );
378
 
 
379
 
                        // Restrict to selected satuses:
 
335
                        // Restrict to selected satuses
380
336
                        $this->ItemQuery->where_statuses( $status );
381
 
 
382
 
                        // - - - + * * timestamp restrictions:
 
337
                        // - - - + * * timestamp restrictions
383
338
                        $this->ItemQuery->where_datestart( '', '', '', '', $timestamp_min, $timestamp_max );
384
 
 
385
 
                        // Keyword search stuff:
 
339
                        // Keyword search stuff
386
340
                        $this->ItemQuery->where_keywords( $s, $sentence, $exact );
387
 
 
388
341
                        $this->ItemQuery->where_types( $types );
389
342
                }
390
343
                else
391
 
                {       // We want to preserve only the minimal context:
392
 
                        // * - - Restrict to selected blog/categories:
393
 
                        $this->ItemQuery->where_chapter( $blog, '', array() );
394
 
 
395
 
                        // * Restrict to the statuses we want to show:
 
344
                {
 
345
                        // We want to preserve only the minimal context
 
346
                        // * - - Restrict to selected blog/categories
 
347
                        $this->ItemQuery->where_category( $blog, '', array() );
 
348
                        // * Restrict to the statuses we want to show
396
349
                        $this->ItemQuery->where_visibility( $show_statuses );
397
 
 
398
 
                        // - - - + * * timestamp restrictions:
 
350
                        // - - - + * * timestamp restrictions
399
351
                        $this->ItemQuery->where_datestart( '', '', '', '', $timestamp_min, $timestamp_max );
400
 
 
401
 
                        // Include all types except pages, intros and sidebar links:
402
 
                        $this->ItemQuery->where_types( '-1000,1500,1520,1530,1570,1600,3000' );
 
352
                        // Include all types except pages, intros and sidebar links
 
353
                        $this->ItemQuery->where_types( '-1000,1500,1520,1530,1570,2000' );
403
354
                }
404
355
 
405
 
 
406
356
                $this->from = $this->ItemQuery->get_from();
407
357
                $this->where = $this->ItemQuery->get_where();
408
358
                $this->group_by = $this->ItemQuery->get_group_by();
410
360
                switch( $this->archive_mode )
411
361
                {
412
362
                        case 'monthly':
413
 
                                // ------------------------------ MONTHLY ARCHIVES ------------------------------------
414
 
                                $sql = 'SELECT EXTRACT(YEAR FROM '.$this->dbprefix.'datestart) AS year, EXTRACT(MONTH FROM '.$this->dbprefix.'datestart) AS month,
415
 
                                                                                                                                        COUNT(DISTINCT postcat_post_ID) AS count '
416
 
                                                                                                        .$this->from
417
 
                                                                                                        .$this->where.'
418
 
                                                                                                        GROUP BY year, month
419
 
                                                                                                        ORDER BY year DESC, month DESC';
420
 
                                break;
 
363
                        $sql = 'SELECT EXTRACT(YEAR FROM '
 
364
                                .$this->dbprefix.'datestart) AS year, EXTRACT(MONTH FROM '.$this->dbprefix.'datestart) AS month,
 
365
                                COUNT(DISTINCT postcat_post_ID) AS count '
 
366
                                .$this->from
 
367
                                .$this->where.'
 
368
                                GROUP BY year, month
 
369
                                ORDER BY year DESC, month DESC';
 
370
                        break;
421
371
 
422
372
                        case 'daily':
423
 
                                // ------------------------------- DAILY ARCHIVES -------------------------------------
424
 
                                $sql = 'SELECT EXTRACT(YEAR FROM '.$this->dbprefix.'datestart) AS year, MONTH('.$this->dbprefix.'datestart) AS month,
425
 
                                                                                                                                        DAYOFMONTH('.$this->dbprefix.'datestart) AS day,
426
 
                                                                                                                                        COUNT(DISTINCT postcat_post_ID) AS count '
427
 
                                                                                                        .$this->from
428
 
                                                                                                        .$this->where.'
429
 
                                                                                                        GROUP BY year, month, day
430
 
                                                                                                        ORDER BY year DESC, month DESC, day DESC';
431
 
                                break;
 
373
                        $sql = 'SELECT EXTRACT(YEAR FROM '
 
374
                                .$this->dbprefix.'datestart) AS year, MONTH('.$this->dbprefix.'datestart) AS month,
 
375
                                DAYOFMONTH('.$this->dbprefix.'datestart) AS day,
 
376
                                COUNT(DISTINCT postcat_post_ID) AS count '
 
377
                                .$this->from
 
378
                                .$this->where.'
 
379
                                GROUP BY year, month, day
 
380
                                ORDER BY year DESC, month DESC, day DESC';
 
381
                        break;
432
382
 
433
383
                        case 'weekly':
434
 
                                // ------------------------------- WEEKLY ARCHIVES -------------------------------------
435
 
                                $sql = 'SELECT EXTRACT(YEAR FROM '.$this->dbprefix.'datestart) AS year, '.
436
 
                                                                                                                        $DB->week( $this->dbprefix.'datestart', locale_startofweek() ).' AS week,
437
 
                                                                                                                        COUNT(DISTINCT postcat_post_ID) AS count '
438
 
                                                                                                        .$this->from
439
 
                                                                                                        .$this->where.'
440
 
                                                                                                        GROUP BY year, week
441
 
                                                                                                        ORDER BY year DESC, week DESC';
442
 
                                break;
 
384
                        $sql = 'SELECT EXTRACT(YEAR FROM '
 
385
                                .$this->dbprefix.'datestart) AS year, '.
 
386
                                $DB->week( $this->dbprefix.'datestart', locale_startofweek() ).' AS week,
 
387
                                COUNT(DISTINCT postcat_post_ID) AS count '
 
388
                                .$this->from
 
389
                                .$this->where.'
 
390
                                GROUP BY year, week
 
391
                                ORDER BY year DESC, week DESC';
 
392
                        break;
443
393
 
444
394
                        case 'postbypost':
445
395
                        default:
446
 
                                // ----------------------------- POSY BY POST ARCHIVES --------------------------------
447
 
                                $sql = 'SELECT DISTINCT '.$this->dbIDname.', '.$this->dbprefix.'datestart, '.$this->dbprefix.'title '
448
 
                                                                                                        .$this->from
449
 
                                                                                                        .$this->where
450
 
                                                                                                        .$this->group_by.'
451
 
                                                                                                        ORDER BY ';
452
 
                                if($sort_order == 'title'){
453
 
                                        $sql .= $this->dbprefix.'title ASC';
454
 
                                }
455
 
                                else if($sort_order == 'date'){
456
 
                                        $sql .= $this->dbprefix.'datestart DESC';
457
 
                                }
 
396
                        $sql = 'SELECT DISTINCT '.
 
397
                                $this->dbIDname.', '.$this->dbprefix.'datestart, '.$this->dbprefix.'title '
 
398
                                .$this->from
 
399
                                .$this->where
 
400
                                .$this->group_by.'
 
401
                                ORDER BY ';
 
402
                        if( $sort_order == 'title' )
 
403
                        {
 
404
                                $sql .= $this->dbprefix.'title ASC';
 
405
                        }
 
406
                        elseif( $sort_order == 'date' )
 
407
                        {
 
408
                                $sql .= $this->dbprefix.'datestart DESC';
 
409
                        }
 
410
                        break;
458
411
                }
459
412
 
460
 
 
461
413
                // dh> Temp fix for MySQL bug - apparently in/around 4.1.21/5.0.24.
462
 
                // See http://forums.b2evolution.net/viewtopic.php?p=42529#42529
463
 
                if( in_array($this->archive_mode, array('monthly', 'daily', 'weekly')) )
 
414
                if( in_array( $this->archive_mode, array( 'monthly', 'daily', 'weekly' ) ) )
464
415
                {
465
416
                        $sql_version = $DB->get_var('SELECT VERSION()'); // fp> TODO: $DB->get_mysql_version()
466
 
                        if( version_compare($sql_version, '4', '>') )
 
417
                        if( version_compare( $sql_version, '4', '>' ) )
467
418
                        {
468
419
                                $sql = 'SELECT SQL_CALC_FOUND_ROWS '.substr( $sql, 7 ); // "SQL_CALC_FOUND_ROWS" available since MySQL 4
469
420
                        }
470
421
                }
471
422
 
472
 
 
473
423
                parent::Results( $sql, 'archivelist_', '', $limit );
474
424
 
475
425
                $this->restart();
479
429
        /**
480
430
         * Count the number of rows of the SQL result
481
431
         *
482
 
         * These queries are complex enough for us not to have to rewrite them:
483
 
         * dh> ???
 
432
         * These queries are complex enough for us not to have to rewrite them. dh> ???
484
433
         */
485
434
        function count_total_rows()
486
435
        {
489
438
                switch( $this->archive_mode )
490
439
                {
491
440
                        case 'monthly':
492
 
                                // ------------------------------ MONTHLY ARCHIVES ------------------------------------
493
 
                                $sql_count = 'SELECT COUNT( DISTINCT EXTRACT(YEAR FROM '.$this->dbprefix.'datestart), EXTRACT(MONTH FROM '.$this->dbprefix.'datestart) ) '
494
 
                                                                                                        .$this->from
495
 
                                                                                                        .$this->where;
496
 
                                break;
 
441
                        $sql_count = 'SELECT COUNT(DISTINCT EXTRACT(YEAR FROM '
 
442
                                .$this->dbprefix.'datestart), EXTRACT(MONTH FROM '.$this->dbprefix.'datestart) ) '
 
443
                                .$this->from
 
444
                                .$this->where;
 
445
                        break;
497
446
 
498
447
                        case 'daily':
499
 
                                // ------------------------------- DAILY ARCHIVES -------------------------------------
500
 
                                $sql_count = 'SELECT COUNT( DISTINCT EXTRACT(YEAR FROM '.$this->dbprefix.'datestart), EXTRACT(MONTH FROM '.$this->dbprefix.'datestart),
501
 
                                                                                                                                        EXTRACT(DAY FROM '.$this->dbprefix.'datestart) ) '
502
 
                                                                                                        .$this->from
503
 
                                                                                                        .$this->where;
504
 
                                break;
 
448
                        $sql_count = 'SELECT COUNT(DISTINCT EXTRACT(YEAR FROM '
 
449
                                .$this->dbprefix.'datestart), EXTRACT(MONTH FROM '.$this->dbprefix.'datestart),
 
450
                                EXTRACT(DAY FROM '.$this->dbprefix.'datestart) ) '
 
451
                                .$this->from
 
452
                                .$this->where;
 
453
                        break;
505
454
 
506
455
                        case 'weekly':
507
 
                                // ------------------------------- WEEKLY ARCHIVES -------------------------------------
508
 
                                $sql_count = 'SELECT COUNT( DISTINCT EXTRACT(YEAR FROM '.$this->dbprefix.'datestart), '
509
 
                                                                                                        .$DB->week( $this->dbprefix.'datestart', locale_startofweek() ).' ) '
510
 
                                                                                                        .$this->from
511
 
                                                                                                        .$this->where;
512
 
                                break;
 
456
                        $sql_count = 'SELECT COUNT(DISTINCT EXTRACT(YEAR FROM '
 
457
                                .$this->dbprefix.'datestart), '
 
458
                                .$DB->week( $this->dbprefix.'datestart', locale_startofweek() ).' ) '
 
459
                                .$this->from
 
460
                                .$this->where;
 
461
                        break;
513
462
 
514
463
                        case 'postbypost':
515
464
                        default:
516
 
                                // ----------------------------- POSY BY POST ARCHIVES --------------------------------
517
 
                                $sql_count = 'SELECT COUNT( DISTINCT '.$this->dbIDname.' ) '
518
 
                                                                                                        .$this->from
519
 
                                                                                                        .$this->where
520
 
                                                                                                        .$this->group_by;
 
465
                        $sql_count = 'SELECT COUNT( DISTINCT '
 
466
                                .$this->dbIDname.' ) '
 
467
                                .$this->from
 
468
                                .$this->where
 
469
                                .$this->group_by;
 
470
                        break;
521
471
                }
522
472
 
523
473
                $this->total_rows = $DB->get_var( $sql_count ); //count total rows
530
480
         */
531
481
        function restart()
532
482
        {
533
 
                // Make sure query has executed at least once:
 
483
                // Make sure query has executed at least once
534
484
                $this->query();
535
485
 
536
486
                $this->current_idx = 0;
545
495
        function get_item( & $arc_year, & $arc_month, & $arc_dayofmonth, & $arc_w, & $arc_count, & $post_ID, & $post_title )
546
496
        {
547
497
                if( $this->current_idx >= $this->result_num_rows )
548
 
                {       // No more entry
 
498
                {
 
499
                        // No more entry
549
500
                        return false;
550
501
                }
551
502
 
552
 
                $arc_row = $this->rows[ $this->current_idx++ ];
 
503
                $arc_row = $this->rows[$this->current_idx++];
553
504
 
554
505
                switch( $this->archive_mode )
555
506
                {
556
507
                        case 'monthly':
557
 
                                $arc_year  = $arc_row->year;
558
 
                                $arc_month = $arc_row->month;
559
 
                                $arc_count = $arc_row->count;
560
 
                                return true;
 
508
                        $arc_year  = $arc_row->year;
 
509
                        $arc_month = $arc_row->month;
 
510
                        $arc_count = $arc_row->count;
 
511
                        return true;
561
512
 
562
513
                        case 'daily':
563
 
                                $arc_year  = $arc_row->year;
564
 
                                $arc_month = $arc_row->month;
565
 
                                $arc_dayofmonth = $arc_row->day;
566
 
                                $arc_count = $arc_row->count;
567
 
                                return true;
 
514
                        $arc_year  = $arc_row->year;
 
515
                        $arc_month = $arc_row->month;
 
516
                        $arc_dayofmonth = $arc_row->day;
 
517
                        $arc_count = $arc_row->count;
 
518
                        return true;
568
519
 
569
520
                        case 'weekly':
570
 
                                $arc_year  = $arc_row->year;
571
 
                                $arc_w = $arc_row->week;
572
 
                                $arc_count = $arc_row->count;
573
 
                                return true;
 
521
                        $arc_year  = $arc_row->year;
 
522
                        $arc_w = $arc_row->week;
 
523
                        $arc_count = $arc_row->count;
 
524
                        return true;
574
525
 
575
526
                        case 'postbypost':
576
527
                        default:
577
 
                                $post_ID = $arc_row->post_ID;
578
 
                                $post_title = $arc_row->{$this->dbprefix.'title'};
579
 
                                return true;
 
528
                        $post_ID = $arc_row->post_ID;
 
529
                        $post_title = $arc_row->{$this->dbprefix.'title'};
 
530
                        return true;
580
531
                }
581
532
        }
 
533
 
582
534
}
 
535
 
583
536
?>