~quam-plures-core/quam-plures/fix-auto_p_plugin

« back to all changes in this revision

Viewing changes to qp_inc/items/model/_itemlistlight.class.php

  • Committer: EdB
  • Date: 2013-03-18 19:30:14 UTC
  • mfrom: (7602.1.58 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20130318193014-qogr0c0lwd5ix8lj
quam-plures/qp5_colls-blogs_chaps-cats

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
 * This file implements the ItemListLight class.
4
 
 *
5
 
 * This object handles item/post/article lists WITHOUT FULL FUNCTIONNALITY
6
 
 * but with a LOWER MEMORY FOOTPRINT.
7
 
 *
8
 
 * This file is part of Quam Plures - {@link http://quamplures.net/}
9
 
 * See also {@link https://launchpad.net/quam-plures}.
10
 
 *
11
 
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
12
 
 * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
13
 
 *
14
 
 * {@internal License choice
15
 
 * - If you have received this file as part of a package, please find the license.txt file in
16
 
 *   the same folder or the closest folder above for complete license terms.
17
 
 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
18
 
 *   then you must choose one of the following licenses before using the file:
19
 
 *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
20
 
 *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
21
 
 * }}
22
 
 *
23
 
 * {@internal Open Source relicensing agreement:
24
 
 * }}
25
 
 *
26
 
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
27
 
 * @author fplanque: Francois PLANQUE.
28
 
 *
 
3
 * This file implements the ItemListLight class
 
4
 *
 
5
 * This object handles item/post/article lists without full functionality but
 
6
 * with a lower memory footprint. Contrary to ItemList2, we only do 1 query
 
7
 * here and we extract only a few selected params. Basically all we want is
 
8
 * being able to generate permalinks.
 
9
 *
 
10
 * @todo (1111) vars type 'foo' need useful/valid descriptions
 
11
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
12
 * @author {@link http://fplanque.net/ Francois PLANQUE}
 
13
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
14
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
29
15
 * @package items
30
16
 */
31
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
17
if(!defined('QP_MAIN_INIT')) die('fail');
32
18
 
33
 
load_class('_core/model/dataobjects/_dataobjectcache.class.php');
34
 
load_class('_core/model/dataobjects/_dataobjectlist2.class.php');
35
 
load_class('items/model/_item.class.php');
36
 
load_funcs('items/model/_item.funcs.php');
 
19
load_funcs( 'items/model/_item.funcs.php' );
37
20
 
38
21
/**
39
 
 * Item List Class LIGHT
40
 
 *
41
 
 * Contrary to ItemList2, we only do 1 query here and we extract only a few selected params.
42
 
 * Basically all we want is being able to generate permalinks.
 
22
 * ItemListLight class
43
23
 *
44
24
 * @package items
45
25
 */
47
27
{
48
28
        /**
49
29
         * SQL object for the Query
 
30
         * @var foo
50
31
         */
51
32
        var $ItemQuery;
52
 
 
53
33
        /**
54
34
         * Blog object this ItemList refers to
 
35
         * @var foo
55
36
         */
56
37
        var $Blog;
57
 
 
58
38
        /**
59
39
         * list unit: 'posts' or 'days'
 
40
         * @var foo
60
41
         */
61
42
        var $unit;
62
 
 
63
43
        /**
64
44
         * Did we request a single post?
 
45
         * @var foo
65
46
         */
66
 
        var $single_post = false;
67
 
 
 
47
        var $single_post = false;
68
48
        /**
69
49
         * Last date that has been output by date_if_changed()
 
50
         * @var foo
70
51
         */
71
52
        var $last_displayed_date = '';
72
 
 
73
53
        /**
74
54
         * Lazy filled
75
 
         * @access private
 
55
         * @var foo
76
56
         */
77
57
        var $advertised_start_date;
 
58
        /**
 
59
         * FIX THIS
 
60
         * @var foo
 
61
         */
78
62
        var $advertised_stop_date;
79
63
        /**
80
64
         * Anti infinite loops:
 
65
         * @var foo
81
66
         */
82
67
        var $getting_adv_start_date = false;
 
68
        /**
 
69
         * FIX THIS
 
70
         * @var foo
 
71
         */
83
72
        var $getting_adv_stop_date = false;
84
 
 
 
73
        /**
 
74
         * FIX THIS
 
75
         * @var foo
 
76
         */
85
77
        var $group_by_cat = 0;
86
78
 
87
 
 
88
79
        /**
89
80
         * Constructor
90
81
         *
91
 
         * @todo  add param for saved session filter set
92
 
         *
 
82
         * @todo add param for saved session filter set
93
83
         * @param Blog
94
84
         * @param mixed Default filter set: Do not show posts before this timestamp, can be 'now'
95
85
         * @param mixed Default filter set: Do not show posts after this timestamp, can be 'now'
100
90
         */
101
91
        function ItemListLight(
102
92
                        & $Blog,
103
 
                        $timestamp_min = NULL,       // Do not show posts before this timestamp
104
 
                        $timestamp_max = NULL,                   // Do not show posts after this timestamp
 
93
                        $timestamp_min = NULL, // Do not show posts before this timestamp
 
94
                        $timestamp_max = NULL, // Do not show posts after this timestamp
105
95
                        $limit = 20,
106
 
                        $cache_name = 'ItemCacheLight',  // name of cache to be used (for table prefix info)
 
96
                        $cache_name = 'ItemCacheLight', // name of cache to be used (for table prefix info)
107
97
                        $param_prefix = '',
108
 
                        $filterset_name = ''                            // Name to be used when saving the filterset (leave empty to use default for collection)
 
98
                        $filterset_name = '' // Name to be used when saving the filterset (leave empty to use default for collection)
109
99
                )
110
100
        {
111
101
                global $Settings;
112
102
 
113
 
                // Call parent constructor:
114
 
                parent::DataObjectList2( get_Cache($cache_name), $limit, $param_prefix, NULL );
 
103
                // Call parent constructor
 
104
                parent::DataObjectList2( get_Cache( $cache_name ), $limit, $param_prefix, NULL );
115
105
 
116
 
                // The SQL Query object:
 
106
                // The SQL Query object
117
107
                $this->ItemQuery = new ItemQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname );
118
108
 
119
109
                $this->Blog = & $Blog;
120
110
 
121
 
                if( !empty( $filterset_name ) )
122
 
                {       // Set the filterset_name with the filterset_name param
 
111
                if( ! empty( $filterset_name ) )
 
112
                {
 
113
                        // Set the filterset_name with the filterset_name param
123
114
                        $this->filterset_name = 'ItemList_filters_'.$filterset_name;
124
115
                }
125
116
                else
126
 
                {       // Set a generic filterset_name
 
117
                {
 
118
                        // Set a generic filterset_name
127
119
                        $this->filterset_name = 'ItemList_filters_coll'.$this->Blog->ID;
128
120
                }
129
121
 
130
122
                $this->page_param = $param_prefix.'paged';
131
123
 
132
 
                // Initialize the default filter set:
 
124
                // Initialize the default filter set
133
125
                $this->set_default_filters( array(
134
 
                                'filter_preset' => NULL,
135
 
                                'ts_min' => $timestamp_min,
136
 
                                'ts_max' => $timestamp_max,
137
 
                                'ts_created_max' => NULL,
138
 
                                'cat_array' => array(),
139
 
                                'cat_modifier' => NULL,
140
 
                                'cat_focus' => 'wide',                                  // Search in extra categories, not just main cat
141
 
                                'tags' => NULL,
142
 
                                'authors' => NULL,
143
 
                                'assignees' => NULL,
144
 
                                'author_assignee' => NULL,
145
 
                                'lc' => 'all',                                                                  // Filter on requested locale
146
 
                                'keywords' => NULL,
147
 
                                'phrase' => 'AND',
148
 
                                'exact' => 0,
149
 
                                'post_ID' => NULL,
150
 
                                'post_ID_list' => NULL,
151
 
                                'post_title' => NULL,
152
 
                                'ymdhms' => NULL,
153
 
                                'week' => NULL,
154
 
                                'ymdhms_min' => NULL,
155
 
                                'ymdhms_max' => NULL,
156
 
                                'statuses' => NULL,
157
 
                                'types' => '-1000,1500,1520,1530,1570,1600,3000', // All types except pages, intros and sidebar links
158
 
                                'visibility_array' => array( 'published', 'protected', 'private' ),
159
 
                                'orderby' => $this->Blog->get_setting('orderby'),
160
 
                                'order' => $this->Blog->get_setting('orderdir'),
161
 
                                'unit' => $this->Blog->get_setting('what_to_show'),
162
 
                                'posts' => $this->limit,
163
 
                                'page' => 1,
164
 
                                'featured' => NULL,
165
 
                        ) );
 
126
                        'filter_preset' => NULL,
 
127
                        'ts_min' => $timestamp_min,
 
128
                        'ts_max' => $timestamp_max,
 
129
                        'ts_created_max' => NULL,
 
130
                        'cat_array' => array(),
 
131
                        'cat_modifier' => NULL,
 
132
                        'cat_focus' => 'wide', // Search in extra categories, not just main cat
 
133
                        'tags' => NULL,
 
134
                        'authors' => NULL,
 
135
                        'assignees' => NULL,
 
136
                        'author_assignee' => NULL,
 
137
                        'lc' => 'all', // Filter on requested locale
 
138
                        'keywords' => NULL,
 
139
                        'phrase' => 'AND',
 
140
                        'exact' => 0,
 
141
                        'post_ID' => NULL,
 
142
                        'post_ID_list' => NULL,
 
143
                        'post_title' => NULL,
 
144
                        'ymdhms' => NULL,
 
145
                        'week' => NULL,
 
146
                        'ymdhms_min' => NULL,
 
147
                        'ymdhms_max' => NULL,
 
148
                        'statuses' => NULL,
 
149
                        'types' => '-1000,1500,1520,1530,1570,2000', // All types except pages, intros and sidebar links
 
150
                        'visibility_array' => array( 'published', 'protected', 'private' ),
 
151
                        'orderby' => $this->Blog->get_setting( 'orderby' ),
 
152
                        'order' => $this->Blog->get_setting( 'orderdir' ),
 
153
                        'unit' => $this->Blog->get_setting( 'what_to_show' ),
 
154
                        'posts' => $this->limit,
 
155
                        'page' => 1,
 
156
                        'featured' => NULL,
 
157
                ) );
166
158
        }
167
159
 
168
160
 
173
165
         */
174
166
        function reset()
175
167
        {
176
 
                // The SQL Query object:
 
168
                // The SQL Query object
177
169
                $this->ItemQuery = new ItemQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname );
178
170
 
179
171
                parent::reset();
181
173
 
182
174
 
183
175
        /**
184
 
         * Set default filter values we always want to use if not individually specified otherwise:
 
176
         * Set default filter values we always want to use if not individually specified otherwise
185
177
         *
186
178
         * @param array default filters to be merged with the class defaults
187
179
         * @param array default filters for each preset, to be merged with general default filters if the preset is used
203
195
         */
204
196
        function set_filters( $filters, $memorize = true )
205
197
        {
206
 
                if( !empty( $filters ) )
207
 
                { // Activate the filterset (fallback to default filter when a value is not set):
 
198
                if( ! empty( $filters ) )
 
199
                {
 
200
                        // Activate the filterset (fallback to default filter when a value is not set)
208
201
                        $this->filters = array_merge( $this->default_filters, $filters );
209
202
                }
210
203
 
211
 
                // Activate preset filters if necessary:
 
204
                // Activate preset filters if necessary
212
205
                $this->activate_preset_filters();
213
206
 
214
 
                // Funky oldstyle params:
 
207
                // Funky oldstyle params
215
208
                $this->limit = $this->filters['posts']; // for compatibility with parent class
216
209
                $this->page = $this->filters['page'];
217
210
 
218
 
 
219
211
                if( $memorize )
220
 
                {       // set back the GLOBALS !!! needed for regenerate_url() :
 
212
                {
 
213
                        // set back the GLOBALS !!! needed for regenerate_url() :
221
214
 
222
 
                        /*
223
 
                         * Selected filter preset:
224
 
                         */
 
215
                        // Selected filter preset
225
216
                        memorize_param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], $this->filters['filter_preset'] );  // List of authors to restrict to
226
217
 
 
218
                        // Blog & categories restrictions
227
219
 
228
 
                        /*
229
 
                         * Blog & Chapters/categories restrictions:
230
 
                         */
231
 
                        // Get chapters/categories (and compile those values right away)
 
220
                        // Get categories (and compile those values right away)
232
221
                        memorize_param( 'cat', '/^[*\-]?([0-9]+(,[0-9]+)*)?$/', $this->default_filters['cat_modifier'], $this->filters['cat_modifier'] );  // List of authors to restrict to
233
222
                        memorize_param( 'catsel', 'array', $this->default_filters['cat_array'], $this->filters['cat_array'] );
234
223
                        memorize_param( $this->param_prefix.'cat_focus', 'string', $this->default_filters['cat_focus'], $this->filters['cat_focus'] );  // Categories to search on
235
 
                        // TEMP until we get this straight:
236
 
                        // fp> this would only be used for the categories widget and setting it here overwtrites the interesting values when a post list widget is tirggered
 
224
                        // TEMP until we get this straight
 
225
                        // fp> this would only be used for the categories widget and setting it here
 
226
                        // overwtrites the interesting values when a post list widget is triggered
237
227
                        // fp> if we need it here we want to use a $set_globals params to this function
238
 
                        // global $cat_array, $cat_modifier;
 
228
                        // global $cat_array;
 
229
                        // global $cat_modifier;
239
230
                        // $cat_array = $this->default_filters['cat_array'];
240
231
                        // $cat_modifier = $this->default_filters['cat_modifier'];
241
232
 
242
 
 
243
 
                        /*
244
 
                         * Restrict to selected tags:
245
 
                         */
 
233
                        // Restrict to selected tags
246
234
                        memorize_param( $this->param_prefix.'tags', 'string', $this->default_filters['tags'], $this->filters['tags'] );
247
235
 
248
 
 
249
 
                        /*
250
 
                         * Restrict to selected authors:
251
 
                         */
252
 
                        memorize_param( $this->param_prefix.'author', 'string', $this->default_filters['authors'], $this->filters['authors'] );  // List of authors to restrict to
253
 
 
254
 
                        /*
255
 
                         * Restrict to selected assignees:
256
 
                         */
257
 
                        memorize_param( $this->param_prefix.'assgn', 'string', $this->default_filters['assignees'], $this->filters['assignees'] );  // List of assignees to restrict to
258
 
 
259
 
                        /*
260
 
                         * Restrict to selected author OR assignee:
261
 
                         */
 
236
                        // Restrict to selected authors
 
237
                        memorize_param( $this->param_prefix.'author', 'string', $this->default_filters['authors'], $this->filters['authors'] ); // List of authors to restrict to
 
238
 
 
239
                        // Restrict to selected assignees
 
240
                        memorize_param( $this->param_prefix.'assgn', 'string', $this->default_filters['assignees'], $this->filters['assignees'] ); // List of assignees to restrict to
 
241
 
 
242
                        // Restrict to selected author OR assignee
262
243
                        memorize_param( $this->param_prefix.'author_assignee', 'string', $this->default_filters['author_assignee'], $this->filters['author_assignee'] );
263
244
 
264
 
                        /*
265
 
                         * Restrict to selected locale:
266
 
                         */
267
 
                        memorize_param( $this->param_prefix.'lc', 'string', $this->default_filters['lc'], $this->filters['lc'] );  // Locale to restrict to
268
 
 
269
 
                        /*
270
 
                         * Restrict to selected statuses:
271
 
                         */
272
 
                        memorize_param( $this->param_prefix.'status', 'string', $this->default_filters['statuses'], $this->filters['statuses'] );  // List of statuses to restrict to
273
 
 
274
 
                        /*
275
 
                         * Restrict to selected item type:
276
 
                         */
277
 
                        memorize_param( $this->param_prefix.'types', 'integer', $this->default_filters['types'], $this->filters['types'] );  // List of item types to restrict to
278
 
 
279
 
                        /*
280
 
                         * Restrict by keywords
281
 
                         */
282
 
                        memorize_param( $this->param_prefix.'s', 'string', $this->default_filters['keywords'], $this->filters['keywords'] );                     // Search string
 
245
                        // Restrict to selected locale
 
246
                        memorize_param( $this->param_prefix.'lc', 'string', $this->default_filters['lc'], $this->filters['lc'] ); // Locale to restrict to
 
247
 
 
248
                        // Restrict to selected statuses
 
249
                        memorize_param( $this->param_prefix.'status', 'string', $this->default_filters['statuses'], $this->filters['statuses'] ); // List of statuses to restrict to
 
250
 
 
251
                        // Restrict to selected item type
 
252
                        memorize_param( $this->param_prefix.'types', 'integer', $this->default_filters['types'], $this->filters['types'] ); // List of item types to restrict to
 
253
 
 
254
                        // Restrict by keywords
 
255
                        memorize_param( $this->param_prefix.'s', 'string', $this->default_filters['keywords'], $this->filters['keywords'] ); // Search string
283
256
                        memorize_param( $this->param_prefix.'sentence', 'string', $this->default_filters['phrase'], $this->filters['phrase'] ); // Search for sentence or for words
284
 
                        memorize_param( $this->param_prefix.'exact', 'integer', $this->default_filters['exact'], $this->filters['exact'] );     // Require exact match of title or contents
 
257
                        memorize_param( $this->param_prefix.'exact', 'integer', $this->default_filters['exact'], $this->filters['exact'] ); // Require exact match of title or contents
285
258
 
286
 
                        /*
287
 
                         * Specific Item selection?
288
 
                         */
289
 
                        memorize_param( $this->param_prefix.'m', '/^\d{4}(0[1-9]|1[0-2])?(?(1)(0[1-9]|[12][0-9]|3[01])?)(?(2)([01][0-9]|2[0-3])?)(?(3)([0-5][0-9]){0,2})$/', $this->default_filters['ymdhms'], $this->filters['ymdhms'] );          // YearMonth(Day) to display
290
 
                        memorize_param( $this->param_prefix.'w', '/^(0?[0-9]|[1-4][0-9]|5[0-3])$/', $this->default_filters['week'], $this->filters['week'] );            // Week number
 
259
                        // Specific Item selection?
 
260
                        memorize_param( $this->param_prefix.'m', '/^\d{4}(0[1-9]|1[0-2])?(?(1)(0[1-9]|[12][0-9]|3[01])?)(?(2)([01][0-9]|2[0-3])?)(?(3)([0-5][0-9]){0,2})$/', $this->default_filters['ymdhms'], $this->filters['ymdhms'] ); // YearMonth(Day) to display
 
261
                        memorize_param( $this->param_prefix.'w', '/^(0?[0-9]|[1-4][0-9]|5[0-3])$/', $this->default_filters['week'], $this->filters['week'] ); // Week number
291
262
                        memorize_param( $this->param_prefix.'dstart', 'integer', $this->default_filters['ymdhms_min'], $this->filters['ymdhms_min'] ); // YearMonth(Day) to start at
292
263
                        memorize_param( $this->param_prefix.'dstop', 'integer', $this->default_filters['ymdhms_max'], $this->filters['ymdhms_max'] ); // YearMonth(Day) to start at
293
264
 
294
 
                        // TODO: show_past/future should probably be wired on dstart/dstop instead on timestamps -> get timestamps out of filter perimeter
295
 
                        if( is_null($this->default_filters['ts_min'])
296
 
                                && is_null($this->default_filters['ts_max'] ) )
297
 
                        {       // We have not set a strict default -> we allow overridding:
298
 
                                memorize_param( $this->param_prefix.'show_past', 'integer', 0, ($this->filters['ts_min'] == 'now') ? 0 : 1 );
299
 
                                memorize_param( $this->param_prefix.'show_future', 'integer', 0, ($this->filters['ts_max'] == 'now') ? 0 : 1 );
 
265
                        // @todo (0000) show_past/future should probably be wired on dstart/dstop
 
266
                        // instead on timestamps -> get timestamps out of filter perimeter
 
267
                        if( is_null( $this->default_filters['ts_min'] ) && is_null( $this->default_filters['ts_max'] ) )
 
268
                        {
 
269
                                // We have not set a strict default -> we allow overridding
 
270
                                memorize_param( $this->param_prefix.'show_past', 'integer', 0, ( $this->filters['ts_min'] == 'now' ) ? 0 : 1 );
 
271
                                memorize_param( $this->param_prefix.'show_future', 'integer', 0, ( $this->filters['ts_max'] == 'now' ) ? 0 : 1 );
300
272
                        }
301
273
 
302
 
                        /*
303
 
                         * Restrict to the statuses we want to show:
304
 
                         */
305
 
                        // Note: oftentimes, $show_statuses will have been preset to a more restrictive set of values
306
 
                        memorize_param( $this->param_prefix.'show_statuses', 'array', $this->default_filters['visibility_array'], $this->filters['visibility_array'] ); // Array of sharings to restrict to
307
 
 
308
 
                        /*
309
 
                         * OLD STYLE orders:
310
 
                         */
311
 
                        memorize_param( $this->param_prefix.'order', 'string', $this->default_filters['order'], $this->filters['order'] );              // ASC or DESC
312
 
                        memorize_param( $this->param_prefix.'orderby', 'string', $this->default_filters['orderby'], $this->filters['orderby'] );  // list of fields to order by (TODO: change that crap)
313
 
 
314
 
                        /*
315
 
                         * Paging limits:
316
 
                         */
317
 
                        memorize_param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], $this->filters['unit'] );                 // list unit: 'posts' or 'days'
318
 
 
319
 
                        memorize_param( $this->param_prefix.'posts', 'integer', $this->default_filters['posts'], $this->filters['posts'] );                     // # of units to display on the page
 
274
                        // Restrict to the statuses we want to show. Note: oftentimes,
 
275
                        // $show_statuses will have been preset to a more restrictive set of values
 
276
                        memorize_param( $this->param_prefix.'show_statuses', 'array', $this->default_filters['visibility_array'], $this->filters['visibility_array'] ); // Array of sharings to restrict to
 
277
 
 
278
                        // OLD STYLE orders
 
279
                        memorize_param( $this->param_prefix.'order', 'string', $this->default_filters['order'], $this->filters['order'] ); // ASC or DESC
 
280
                        memorize_param( $this->param_prefix.'orderby', 'string', $this->default_filters['orderby'], $this->filters['orderby'] ); // list of fields to order by (TODO: change that crap)
 
281
 
 
282
                        // Paging limits
 
283
                        memorize_param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], $this->filters['unit'] ); // list unit: 'posts' or 'days'
 
284
 
 
285
                        memorize_param( $this->param_prefix.'posts', 'integer', $this->default_filters['posts'], $this->filters['posts'] ); // # of units to display on the page
320
286
 
321
287
                        // 'paged'
322
 
                        memorize_param( $this->page_param, 'integer', 1, $this->filters['page'] );      // List page number in paged display
 
288
                        memorize_param( $this->page_param, 'integer', 1, $this->filters['page'] ); // List page number in paged display
323
289
                }
324
290
        }
325
291
 
344
310
                        switch( $filter_action )
345
311
                        {
346
312
                                case 'restore':
347
 
                                        return $this->restore_filterset();
348
 
                                        /* BREAK */
 
313
                                return $this->restore_filterset();
 
314
                                /* BREAK */
349
315
 
350
316
                                case 'reset':
351
 
                                        // We want to reset the memorized filterset:
352
 
                                        global $Session;
353
 
                                        $Session->delete( $this->filterset_name );
354
 
 
355
 
                                        // Memorize global variables:
356
 
                                        $this->set_filters( array(), true );
357
 
 
358
 
                                        // We have applied no filterset:
359
 
                                        return false;
360
 
                                        /* BREAK */
 
317
                                global $Session;
 
318
 
 
319
                                // We want to reset the memorized filterset
 
320
                                $Session->delete( $this->filterset_name );
 
321
 
 
322
                                // Memorize global variables
 
323
                                $this->set_filters( array(), true );
 
324
 
 
325
                                // We have applied no filterset
 
326
                                return false;
 
327
                                /* BREAK */
361
328
                        }
362
329
 
363
 
                        /**
364
 
                         * Filter preset
365
 
                         */
 
330
                        // Filter preset
366
331
                        $this->filters['filter_preset'] = param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], true );
367
332
 
368
 
                        // Activate preset default filters if necessary:
 
333
                        // Activate preset default filters if necessary
369
334
                        $this->activate_preset_filters();
370
335
                }
371
336
 
372
 
 
373
 
                // fp> TODO: param( 'loc', 'string', '', true );                                                        // Locale of the posts (all by default)
374
 
 
375
 
 
376
 
                /*
377
 
                 * Blog & Chapters/categories restrictions:
378
 
                 */
379
 
                // Get chapters/categories (and compile those values right away)
380
 
                param_compile_cat_array( /* TODO: check $this->Blog->ID == 1 ? 0 :*/ $this->Blog->ID,
381
 
                                                                $this->default_filters['cat_modifier'], $this->default_filters['cat_array'] );
 
337
                // fp> TODO: param( 'loc', 'string', '', true ); // Locale of the posts (all by default)
 
338
 
 
339
                // Blog & categories restrictions
 
340
                // Get categories (and compile those values right away)
 
341
                param_compile_cat_array( /* @todo (0000) check $this->Blog->ID == 1 ? 0 :*/ $this->Blog->ID,
 
342
                        $this->default_filters['cat_modifier'], $this->default_filters['cat_array'] );
382
343
 
383
344
                $this->filters['cat_array'] = get_param( 'cat_array' );
384
345
                $this->filters['cat_modifier'] = get_param( 'cat_modifier' );
385
346
 
386
347
                $this->filters['cat_focus'] = param( $this->param_prefix.'cat_focus', 'string', $this->default_filters['cat_focus'], true );
387
348
 
388
 
 
389
 
                /*
390
 
                 * Restrict to selected tags:
391
 
                 */
 
349
                // Restrict to selected tags
392
350
                $this->filters['tags'] = param( $this->param_prefix.'tag', 'string', $this->default_filters['tags'], true );
393
351
 
394
 
 
395
 
                /*
396
 
                 * Restrict to selected authors:
397
 
                 */
 
352
                // Restrict to selected authors
398
353
                $this->filters['authors'] = param( $this->param_prefix.'author', '/^-?[0-9]+(,[0-9]+)*$/', $this->default_filters['authors'], true );      // List of authors to restrict to
399
354
 
400
 
 
401
 
                /*
402
 
                 * Restrict to selected assignees:
403
 
                 */
 
355
                // Restrict to selected assignees
404
356
                $this->filters['assignees'] = param( $this->param_prefix.'assgn', '/^(-|-[0-9]+|[0-9]+)(,[0-9]+)*$/', $this->default_filters['assignees'], true );      // List of assignees to restrict to
405
357
 
406
 
 
407
 
                /*
408
 
                 * Restrict to selected author or assignee:
409
 
                 */
 
358
                // Restrict to selected author or assignee
410
359
                $this->filters['author_assignee'] = param( $this->param_prefix.'author_assignee', '/^[0-9]+$/', $this->default_filters['author_assignee'], true );
411
360
 
412
 
 
413
 
                /*
414
 
                 * Restrict to selected locale:
415
 
                 */
 
361
                // Restrict to selected locale
416
362
                $this->filters['lc'] = param( $this->param_prefix.'lc', 'string', $this->default_filters['lc'], true );
417
363
 
418
 
 
419
 
                /*
420
 
                 * Restrict to selected statuses:
421
 
                 */
 
364
                // Restrict to selected statuses
422
365
                $this->filters['statuses'] = param( $this->param_prefix.'status', '/^(-|-[0-9]+|[0-9]+)(,[0-9]+)*$/', $this->default_filters['statuses'], true );      // List of statuses to restrict to
423
366
 
424
 
                /*
425
 
                 * Restrict to selected types:
426
 
                 */
 
367
                // Restrict to selected types
427
368
                $this->filters['types'] = param( $this->param_prefix.'types', '/^(-|-[0-9]+|[0-9]+)(,[0-9]+)*$/', $this->default_filters['types'], true );      // List of types to restrict to
428
369
 
429
 
 
430
 
                /*
431
 
                 * Restrict by keywords
432
 
                 */
433
 
                $this->filters['keywords'] = param( $this->param_prefix.'s', 'string', $this->default_filters['keywords'], true );         // Search string
434
 
                $this->filters['phrase'] = param( $this->param_prefix.'sentence', 'string', $this->default_filters['phrase'], true );           // Search for sentence or for words
435
 
                $this->filters['exact'] = param( $this->param_prefix.'exact', 'integer', $this->default_filters['exact'], true );        // Require exact match of title or contents
436
 
 
437
 
 
438
 
                /*
439
 
                 * Specific Item selection?
440
 
                 */
441
 
                $this->filters['post_ID'] = param( $this->param_prefix.'p', 'integer', $this->default_filters['post_ID'] );          // Specific post number to display
442
 
                $this->filters['post_title'] = param( $this->param_prefix.'title', 'string', $this->default_filters['post_title'] );      // urtitle of post to display
443
 
 
444
 
 
445
 
                /*
446
 
                 * multiple Item selection ?
447
 
                 */
448
 
                $this->filters['post_ID_list'] = param( $this->param_prefix.'pl', 'string', $this->default_filters['post_ID_list'] );  // Specific list of post numbers to display
449
 
 
450
 
 
451
 
                $this->single_post = !empty($this->filters['post_ID']) || !empty($this->filters['post_title']);
452
 
 
453
 
 
454
 
                /*
455
 
                 * If a timeframe is specified in the querystring, restrict to that timeframe:
456
 
                 */
 
370
                // Restrict by keywords
 
371
                $this->filters['keywords'] = param( $this->param_prefix.'s', 'string', $this->default_filters['keywords'], true ); // Search string
 
372
                $this->filters['phrase'] = param( $this->param_prefix.'sentence', 'string', $this->default_filters['phrase'], true ); // Search for sentence or for words
 
373
                $this->filters['exact'] = param( $this->param_prefix.'exact', 'integer', $this->default_filters['exact'], true ); // Require exact match of title or contents
 
374
 
 
375
                // Specific Item selection?
 
376
                $this->filters['post_ID'] = param( $this->param_prefix.'p', 'integer', $this->default_filters['post_ID'] ); // Specific post number to display
 
377
                $this->filters['post_title'] = param( $this->param_prefix.'title', 'string', $this->default_filters['post_title'] ); // urtitle of post to display
 
378
 
 
379
                // multiple Item selection?
 
380
                $this->filters['post_ID_list'] = param( $this->param_prefix.'pl', 'string', $this->default_filters['post_ID_list'] ); // Specific list of post numbers to display
 
381
 
 
382
                $this->single_post = ! empty( $this->filters['post_ID'] ) || ! empty( $this->filters['post_title'] );
 
383
 
 
384
                // If a timeframe is specified in the querystring, restrict to that timeframe
457
385
                $this->filters['ymdhms'] = param( $this->param_prefix.'m', '/^\d{4}(0[1-9]|1[0-2])?(?(1)(0[1-9]|[12][0-9]|3[01])?)(?(2)([01][0-9]|2[0-3])?)(?(3)([0-5][0-9]){0,2})$/', $this->default_filters['ymdhms'], true ); // YearMonth(Day) to display
458
386
                $this->filters['week'] = param( $this->param_prefix.'w', '/^(0?[0-9]|[1-4][0-9]|5[0-3])$/', $this->default_filters['week'], true ); // Week number (0?0-53)
459
387
 
460
388
                $this->filters['ymdhms_min'] = param_compact_date( $this->param_prefix.'dstart', $this->default_filters['ymdhms_min'], true, T_( 'Invalid date' ) ); // YearMonth(Day) to start at
461
389
                $this->filters['ymdhms_max'] = param_compact_date( $this->param_prefix.'dstop', $this->default_filters['ymdhms_max'], true, T_( 'Invalid date' ) ); // YearMonth(Day) to stop at
462
390
 
463
 
 
464
 
                // TODO: show_past/future should probably be wired on dstart/dstop instead on timestamps -> get timestamps out of filter perimeter
465
 
                // So far, these act as SILENT filters. They will not advertise their filtering in titles etc.
 
391
                // @todo (0000) show_past/future should probably be wired on dstart/dstop instead
 
392
                // on timestamps -> get timestamps out of filter perimeter So far, these act as
 
393
                // SILENT filters. They will not advertise their filtering in titles etc.
466
394
                $this->filters['ts_min'] = $this->default_filters['ts_min'];
467
395
                $this->filters['ts_max'] = $this->default_filters['ts_max'];
468
 
                if( is_null($this->default_filters['ts_min'])
469
 
                        && is_null($this->default_filters['ts_max'] ) )
470
 
                {       // We have not set a strict default -> we allow overridding:
 
396
                if( is_null( $this->default_filters['ts_min'] ) && is_null( $this->default_filters['ts_max'] ) )
 
397
                {
 
398
                        // We have not set a strict default -> we allow overridding
471
399
                        $show_past = param( $this->param_prefix.'show_past', 'integer', 0, true );
472
400
                        $show_future = param( $this->param_prefix.'show_future', 'integer', 0, true );
473
401
                        if( $show_past != $show_future )
474
 
                        {       // There is a point in overridding:
 
402
                        {
 
403
                                // There is a point in overridding
475
404
                                $this->filters['ts_min'] = ( $show_past == 0 ) ? 'now' : '';
476
405
                                $this->filters['ts_max'] = ( $show_future == 0 ) ? 'now' : '';
477
406
                        }
478
407
                }
479
408
 
480
 
                /*
481
 
                 * Restrict to the statuses we want to show:
482
 
                 */
483
 
                // Note: oftentimes, $show_statuses will have been preset to a more restrictive set of values
 
409
                // Restrict to the statuses we want to show. Note: oftentimes,
 
410
                // $show_statuses will have been preset to a more restrictive set of values
484
411
                $this->filters['visibility_array'] = param( $this->param_prefix.'show_statuses', 'array', $this->default_filters['visibility_array']
485
 
                                                , true, false, true, false );   // Array of sharings to restrict to
 
412
                                                , true, false, true, false ); // Array of sharings to restrict to
486
413
 
487
 
                /*
488
 
                 * Ordering:
489
 
                 */
 
414
                // Ordering
490
415
                $this->filters['order'] = param( $this->param_prefix.'order', '/^(ASC|asc|DESC|desc)$/', $this->default_filters['order'], true );               // ASC or DESC
491
416
                $this->filters['orderby'] = param( $this->param_prefix.'orderby', '/^([A-Za-z0-9_]+([ ,][A-Za-z0-9_]+)*)?$/', $this->default_filters['orderby'], true );   // list of fields to order by (TODO: change that crap)
492
417
 
493
 
                /*
494
 
                 * Paging limits:
495
 
                 */
496
 
                $this->filters['unit'] = param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], true );                   // list unit: 'posts' or 'days'
 
418
                // Paging limits
 
419
                $this->filters['unit'] = param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], true ); // list unit: 'posts' or 'days'
497
420
 
498
 
                $this->filters['posts'] = param( $this->param_prefix.'posts', 'integer', $this->default_filters['posts'], true );                       // # of units to display on the page
 
421
                $this->filters['posts'] = param( $this->param_prefix.'posts', 'integer', $this->default_filters['posts'], true ); // # of units to display on the page
499
422
                $this->limit = $this->filters['posts']; // for compatibility with parent class
500
423
 
501
424
                // 'paged'
502
 
                $this->filters['page'] = param( $this->page_param, 'integer', 1, true );      // List page number in paged display
 
425
                $this->filters['page'] = param( $this->page_param, 'integer', 1, true ); // List page number in paged display
503
426
                $this->page = $this->filters['page'];
504
427
 
505
428
                if( param_errors_detected() )
508
431
                }
509
432
 
510
433
                if( $this->single_post )
511
 
                {       // We have requested a specific post
512
 
                        // Do not attempt to save or load any filterset:
 
434
                {
 
435
                        // We have requested a specific post
 
436
                        // Do not attempt to save or load any filterset
513
437
                        return true;
514
438
                }
515
439
 
524
448
 
525
449
        /**
526
450
         * Activate preset default filters if necessary
527
 
         *
528
451
         */
529
452
        function activate_preset_filters()
530
453
        {
531
454
                $filter_preset = $this->filters['filter_preset'];
532
455
 
533
456
                if( empty( $filter_preset ) )
534
 
                { // No filter preset, there are no additional defaults to use:
 
457
                {
 
458
                        // No filter preset, there are no additional defaults to use
535
459
                        return;
536
460
                }
537
461
 
538
 
                // Override general defaults with the specific defaults for the preset:
 
462
                // Override general defaults with the specific defaults for the preset
539
463
                $this->default_filters = array_merge( $this->default_filters, $this->preset_filters[$filter_preset] );
540
464
 
541
 
                // Save the name of the preset in order for is_filtered() to work properly:
 
465
                // Save the name of the preset in order for is_filtered() to work properly
542
466
                $this->default_filters['filter_preset'] = $this->filters['filter_preset'];
543
467
        }
544
468
 
545
469
 
546
470
        /**
547
 
         * Save current filterset to session.
 
471
         * Save current filterset to session
548
472
         */
549
473
        function save_filterset()
550
474
        {
551
 
                /**
552
 
                 * @var Session
553
 
                 */
554
 
                global $Session, $Debuglog;
555
 
 
556
 
                $Debuglog->add( 'Saving filterset <strong>'.$this->filterset_name.'</strong>', 'filters' );
 
475
                global $Session;
557
476
 
558
477
                $Session->set( $this->filterset_name, $this->filters );
559
478
        }
560
479
 
561
480
 
562
481
        /**
563
 
         * Load previously saved filterset from session.
564
 
         *
 
482
         * Load previously saved filterset from session
565
483
         * @return boolean true if we could restore something
566
484
         */
567
485
        function restore_filterset()
568
486
        {
569
 
          /**
570
 
           * @var Session
571
 
           */
572
487
                global $Session;
573
 
          /**
574
 
           * @var Request
575
 
           */
576
 
 
577
 
                global $Debuglog;
578
488
 
579
489
                $filters = $Session->get( $this->filterset_name );
580
490
 
581
491
                /*
582
492
                fp> 2007-09-26> even if there are no filters, we need to "set" them in order to set global variables like $show_statuses
583
 
                if( empty($filters) )
584
 
                { // We have no saved filters:
 
493
                if( empty( $filters ) )
 
494
                {
 
495
                        // We have no saved filters
585
496
                        return false;
586
497
                }
587
498
                */
588
499
 
589
 
                if( empty($filters) )
590
 
                { // set_filters() expects array
 
500
                if( empty( $filters ) )
 
501
                {
 
502
                        // set_filters() expects array
591
503
                        $filters = array();
592
504
                }
593
505
 
594
 
                $Debuglog->add( 'Restoring filterset <strong>'.$this->filterset_name.'</strong>', 'filters' );
595
 
 
596
 
                // Restore filters:
 
506
                // Restore filters
597
507
                $this->set_filters( $filters );
598
508
 
599
509
                return true;
601
511
 
602
512
 
603
513
        /**
604
 
         *
 
514
         * Query Init
605
515
         *
606
516
         * @todo count?
607
517
         */
610
520
                global $current_User;
611
521
 
612
522
                if( empty( $this->filters ) )
613
 
                {       // Filters have not been set before, we'll use the default filterset:
614
 
                        // If there is a preset filter, we need to activate its specific defaults:
 
523
                {
 
524
                        // Filters have not been set before, we'll use the default filterset
 
525
                        // If there is a preset filter, we need to activate its specific defaults
615
526
                        $this->filters['filter_preset'] = param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], true );
616
527
                        $this->activate_preset_filters();
617
528
 
618
 
                        // Use the default filters:
 
529
                        // Use the default filters
619
530
                        $this->set_filters( $this->default_filters );
620
531
                }
621
532
 
622
 
                // GENERATE THE QUERY:
623
 
 
624
 
                /*
625
 
                 * filtering stuff:
626
 
                 */
627
 
                $this->ItemQuery->where_chapter2( $this->Blog, $this->filters['cat_array'], $this->filters['cat_modifier'],
628
 
                                                                                                                                                        $this->filters['cat_focus'] );
 
533
                // GENERATE THE QUERY
 
534
                // filtering stuff
 
535
                $this->ItemQuery->where_category2( $this->Blog, $this->filters['cat_array'], $this->filters['cat_modifier'], $this->filters['cat_focus'] );
629
536
                $this->ItemQuery->where_tags( $this->filters['tags'] );
630
537
                $this->ItemQuery->where_author( $this->filters['authors'] );
631
538
                $this->ItemQuery->where_assignees( $this->filters['assignees'] );
637
544
                $this->ItemQuery->where_ID( $this->filters['post_ID'], $this->filters['post_title'] );
638
545
                $this->ItemQuery->where_ID_list( $this->filters['post_ID_list'] );
639
546
                $this->ItemQuery->where_datestart( $this->filters['ymdhms'], $this->filters['week'],
640
 
                                                   $this->filters['ymdhms_min'], $this->filters['ymdhms_max'],
641
 
                                                   $this->filters['ts_min'], $this->filters['ts_max'] );
 
547
                        $this->filters['ymdhms_min'], $this->filters['ymdhms_max'],
 
548
                        $this->filters['ts_min'], $this->filters['ts_max'] );
642
549
                $this->ItemQuery->where_datecreated( $this->filters['ts_created_max'] );
643
550
                $this->ItemQuery->where_visibility( $this->filters['visibility_array'] );
644
551
                $this->ItemQuery->where_featured( $this->filters['featured'] );
645
552
 
646
 
 
647
 
                /*
648
 
                 * ORDER BY stuff:
649
 
                 */
 
553
                // ORDER BY stuff
650
554
                $order_by = gen_order_clause( $this->filters['orderby'], $this->filters['order'], $this->Cache->dbprefix, $this->Cache->dbIDname );
651
555
 
652
556
                $this->ItemQuery->order_by( $order_by );
653
557
 
654
 
 
655
 
 
656
 
                /*
657
 
                 * GET TOTAL ROW COUNT:
658
 
                 */
659
 
                if( $this->single_post )   // p or title
660
 
                { // Single post: no paging required!
 
558
                // GET TOTAL ROW COUNT
 
559
                if( $this->single_post ) // p or title
 
560
                {
 
561
                        // Single post: no paging required!
661
562
                        $this->total_rows = 1;
662
563
                        $this->total_pages = 1;
663
564
                        $this->page = 1;
664
565
                }
665
566
                /*
666
 
                elseif( !empty($this->filters['ymdhms']) // no restriction if we request a month... some permalinks may point to the archive!
 
567
                elseif( ! empty( $this->filters['ymdhms'] ) // no restriction if we request a month... some permalinks may point to the archive!
667
568
                */
668
 
                elseif( $this->filters['unit'] == 'days'    // We are going to limit to x days: no limit
669
 
                                 || $this->filters['unit'] == 'all' )    // We want ALL results!
 
569
                elseif( $this->filters['unit'] == 'days' // We are going to limit to x days: no limit
 
570
                        || $this->filters['unit'] == 'all' ) // We want ALL results!
670
571
                {
671
572
                        $this->total_rows = NULL; // unknown!
672
573
                        $this->total_pages = 1;
674
575
                }
675
576
                elseif( $this->filters['unit'] == 'posts' )
676
577
                {
677
 
                        /*
678
 
                         * TODO: The result is incorrect when using AND on categories
679
 
                         * We would need to use a HAVING close and thyen COUNT, which would be a subquery
680
 
                         * This is nto compatible with mysql 3.23
681
 
                         * We need fallback code.
682
 
                         */
 
578
                        // @todo (0000) The result is incorrect when using AND on categories. We
 
579
                        // would need to use a HAVING close and thyen COUNT, which would be a
 
580
                        // subquery. This is not compatible with mysql 3.23. We need fallback code.
683
581
                        $sql_count = '
684
582
                                SELECT COUNT( DISTINCT '.$this->Cache->dbIDname.') '
685
 
                                        .$this->ItemQuery->get_from()
686
 
                                        .$this->ItemQuery->get_where();
 
583
                                .$this->ItemQuery->get_from()
 
584
                                .$this->ItemQuery->get_where();
687
585
 
688
586
                        parent::count_total_rows( $sql_count );
689
587
                }
693
591
                }
694
592
 
695
593
 
696
 
                /*
697
 
                 * Paging LIMITs:
698
 
                 */
699
 
                if( $this->single_post )   // p or title
700
 
                { // Single post: no paging required!
 
594
                // Paging LIMITs
 
595
                if( $this->single_post ) // p or title
 
596
                {
 
597
                        // Single post: no paging required!
701
598
                }
702
599
                /*
703
600
                        fp> 2007-11-25 : a very high post count can now be configured in the admin for this. Default is 100.
704
 
                        elseif( !empty($this->filters['ymdhms']) )
705
 
                        { // no restriction if we request a month... some permalinks may point to the archive!
 
601
                        elseif( ! empty( $this->filters['ymdhms'] ) )
 
602
                        {
 
603
                                // no restriction if we request a month... some permalinks may point to the archive!
706
604
                        }
707
605
                */
708
606
                elseif( $this->filters['unit'] == 'all' )
709
 
                {       // We want ALL results!
 
607
                {
 
608
                        // We want ALL results!
710
609
                }
711
610
                elseif( $this->filters['unit'] == 'posts' )
712
611
                {
713
 
                        // TODO: dh> check if $limit is NULL!? - though it should not arrive at $page>1 then..
714
612
                        $pgstrt = '';
715
613
                        if( $this->page > 1 )
716
 
                        { // We have requested a specific page number
717
 
                                $pgstrt = (intval($this->page) -1) * $this->limit. ', ';
 
614
                        {
 
615
                                // We have requested a specific page number
 
616
                                $pgstrt = ( intval( $this->page ) - 1 ) * $this->limit. ', ';
718
617
                        }
719
618
                        $this->ItemQuery->LIMIT( $pgstrt.$this->limit );
720
619
                }
721
620
                elseif( $this->filters['unit'] == 'days' )
722
 
                { // We are going to limit to x days:
 
621
                {
 
622
                        // We are going to limit to x days
723
623
                        if( empty( $this->filters['ymdhms_min'] ) )
724
 
                        { // We have no start date, we'll display the last x days:
725
 
                                if( !empty($this->filters['keywords'])
726
 
                                        || !empty($this->filters['cat_array'])
727
 
                                        || !empty($this->filters['authors']) )
728
 
                                { // We are in DAYS mode but we can't restrict on these! (TODO: ?)
 
624
                        {
 
625
                                // We have no start date, we'll display the last x days
 
626
                                if( ! empty( $this->filters['keywords'] )
 
627
                                        || ! empty( $this->filters['cat_array'] )
 
628
                                        || ! empty( $this->filters['authors'] ) )
 
629
                                {
 
630
                                        // We are in DAYS mode but we can't restrict on these! (TODO: ?)
729
631
                                        $limits = '';
730
632
                                }
731
633
                                else
732
 
                                { // We are going to limit to LAST x days:
 
634
                                {
 
635
                                        // We are going to limit to LAST x days
733
636
                                        $lastpostdate = $this->get_lastpostdate();
734
 
                                        $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
735
 
                                        $lastpostdate = mysql2date('U',$lastpostdate);
 
637
                                        $lastpostdate = mysql2date( 'Y-m-d 00:00:00', $lastpostdate );
 
638
                                        $lastpostdate = mysql2date( 'U', $lastpostdate );
736
639
                                        // go back x days
737
 
                                        $otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($this->limit-1) * 86400)));
 
640
                                        $otherdate = date( 'Y-m-d H:i:s', ( $lastpostdate - ( ( $this->limit-1 ) * 86400 ) ) );
738
641
                                        $this->ItemQuery->WHERE_and( $this->Cache->dbprefix.'datestart > \''. $otherdate.'\'' );
739
642
                                }
740
643
                        }
741
644
                        else
742
 
                        { // We have a start date, we'll display x days starting from that point:
 
645
                        {
 
646
                                // We have a start date, we'll display x days starting from that point
743
647
                                // $dstart_mysql has been calculated earlier
744
648
 
745
 
                                // TODO: this is redundant with previous dstart processing:
746
649
                                // Add trailing 0s: YYYYMMDDHHMMSS
747
650
                                $dstart0 = $this->filters['ymdhms_min'].'00000000000000';
748
651
 
749
 
                                $dstart_mysql = substr($dstart0,0,4).'-'.substr($dstart0,4,2).'-'.substr($dstart0,6,2).' '
750
 
                                                                                                .substr($dstart0,8,2).':'.substr($dstart0,10,2).':'.substr($dstart0,12,2);
 
652
                                $dstart_mysql = substr( $dstart0, 0, 4 ).'-'.substr( $dstart0, 4, 2 ).'-'.substr( $dstart0, 6, 2 ).' '
 
653
                                        .substr( $dstart0, 8, 2 ).':'.substr( $dstart0, 10, 2 ).':'.substr( $dstart0, 12, 2 );
751
654
                                $dstart_ts = mysql2timestamp( $dstart_mysql );
752
655
                                // go forward x days
753
 
                                $enddate_ts = date('Y-m-d H:i:s', ($dstart_ts + ($this->limit * 86400)));
 
656
                                $enddate_ts = date( 'Y-m-d H:i:s', ( $dstart_ts + ( $this->limit * 86400 ) ) );
754
657
                                $this->ItemQuery->WHERE_and( $this->Cache->dbprefix.'datestart < \''. $enddate_ts.'\'' );
755
658
                        }
756
659
                }
759
662
        }
760
663
 
761
664
 
762
 
  /**
 
665
        /**
763
666
         * Run Query: GET DATA ROWS *** LIGHT ***
764
667
         *
765
 
         * Contrary to ItemList2, we only do 1 query here and we extract only a few selected params.
766
 
         * Basically all we want is being able to generate permalinks.
 
668
         * Contrary to ItemList2, we only do 1 query here and we extract only a few
 
669
         * selected params. Basically all we want is being able to generate permalinks.
767
670
         */
768
671
        function query()
769
672
        {
770
673
                global $DB;
771
674
 
772
675
                if( !is_null( $this->rows ) )
773
 
                { // Query has already executed:
 
676
                {
 
677
                        // Query has already executed
774
678
                        return;
775
679
                }
776
680
 
777
 
                // INNIT THE QUERY:
 
681
                // INNIT THE QUERY
778
682
                $this->query_init();
779
683
 
780
 
                // QUERY:
781
 
                $this->sql = 'SELECT DISTINCT '.$this->Cache->dbIDname.', post_datestart, post_datemodified, post_title, post_url,
782
 
                                                                        post_excerpt, post_urltitle, post_main_cat_ID, post_ptyp_ID '
783
 
                                                                        .$this->ItemQuery->get_from()
784
 
                                                                        .$this->ItemQuery->get_where()
785
 
                                                                        .$this->ItemQuery->get_group_by()
786
 
                                                                        .$this->ItemQuery->get_order_by()
787
 
                                                                        .$this->ItemQuery->get_limit();
 
684
                // QUERY
 
685
                $this->sql = 'SELECT DISTINCT '.$this->Cache->dbIDname.', post_datestart, post_datemodified,
 
686
                        post_title, post_url, post_excerpt, post_urltitle, post_main_cat_ID, post_ptyp_ID '
 
687
                        .$this->ItemQuery->get_from()
 
688
                        .$this->ItemQuery->get_where()
 
689
                        .$this->ItemQuery->get_group_by()
 
690
                        .$this->ItemQuery->get_order_by()
 
691
                        .$this->ItemQuery->get_limit();
788
692
 
789
693
                parent::query( false, false, false, 'ItemListLight::query()' );
790
694
        }
794
698
 
795
699
        /**
796
700
         * Get datetime of the last post/item
797
 
         * @todo dh> Optimize this, if this can be said after having done {@link query()} already.
798
 
         * @todo dh> Cache result
799
 
         * @todo dh> Add $dateformat param
 
701
         *
800
702
         * @return string 'Y-m-d H:i:s' formatted; If there are no items this will be {@link $localtimenow}.
801
703
         */
802
704
        function get_lastpostdate()
803
705
        {
804
 
                global $localtimenow, $DB;
 
706
                global $DB;
 
707
                global $localtimenow;
805
708
 
806
709
                if( empty( $this->filters ) )
807
 
                {       // Filters have no been set before, we'll use the default filterset:
 
710
                {
 
711
                        // Filters have no been set before, we'll use the default filterset
808
712
                        $this->set_filters( $this->default_filters );
809
713
                }
810
714
 
811
 
                // GENERATE THE QUERY:
812
 
 
813
 
                // The SQL Query object:
 
715
                // GENERATE THE QUERY
 
716
                // The SQL Query object
814
717
                $lastpost_ItemQuery = new ItemQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname );
815
718
 
816
 
                /*
817
 
                 * filtering stuff:
818
 
                 */
819
 
                $lastpost_ItemQuery->where_chapter2( $this->Blog, $this->filters['cat_array'], $this->filters['cat_modifier'],
820
 
                                                                                                                                                                 $this->filters['cat_focus']  );
 
719
                // filtering stuff
 
720
                $lastpost_ItemQuery->where_category2( $this->Blog, $this->filters['cat_array'], $this->filters['cat_modifier'], $this->filters['cat_focus']  );
821
721
                $lastpost_ItemQuery->where_author( $this->filters['authors'] );
822
722
                $lastpost_ItemQuery->where_assignees( $this->filters['assignees'] );
823
723
                $lastpost_ItemQuery->where_locale( $this->filters['lc'] );
825
725
                $lastpost_ItemQuery->where_types( $this->filters['types'] );
826
726
                $lastpost_ItemQuery->where_keywords( $this->filters['keywords'], $this->filters['phrase'], $this->filters['exact'] );
827
727
                $lastpost_ItemQuery->where_ID( $this->filters['post_ID'], $this->filters['post_title'] );
828
 
                $lastpost_ItemQuery->where_datestart( $this->filters['ymdhms'], $this->filters['week'],
829
 
                                                   $this->filters['ymdhms_min'], $this->filters['ymdhms_max'],
830
 
                                                   $this->filters['ts_min'], $this->filters['ts_max'] );
 
728
                $lastpost_ItemQuery->where_datestart( $this->filters['ymdhms'], $this->filters['week'], $this->filters['ymdhms_min'], $this->filters['ymdhms_max'], $this->filters['ts_min'], $this->filters['ts_max'] );
831
729
                $lastpost_ItemQuery->where_visibility( $this->filters['visibility_array'] );
832
730
 
833
 
                /*
834
 
                 * order by stuff:
835
 
                 * LAST POST FIRST!!! (That's the whole point!)
836
 
                 */
 
731
                // order by stuff
 
732
                // LAST POST FIRST!!! (That's the whole point!)
837
733
                $lastpost_ItemQuery->order_by( $this->Cache->dbprefix.'datestart DESC' );
838
734
 
839
 
                /*
840
 
                 * Paging limits:
841
 
                 * ONLY THE LAST POST!!!
842
 
                 */
 
735
                // Paging limits
 
736
                // ONLY THE LAST POST!!!
843
737
                $lastpost_ItemQuery->LIMIT( '1' );
844
738
 
845
 
                // Select the datestart:
 
739
                // Select the datestart
846
740
                $lastpost_ItemQuery->select( $this->Cache->dbprefix.'datestart' );
847
741
 
848
742
                $lastpostdate = $DB->get_var( $lastpost_ItemQuery->get(), 0, 0, 'Get last post date' );
849
743
 
850
744
                if( empty( $lastpostdate ) )
851
745
                {
852
 
                        $lastpostdate = date('Y-m-d H:i:s', $localtimenow);
 
746
                        $lastpostdate = date( 'Y-m-d H:i:s', $localtimenow );
853
747
                }
854
748
 
855
749
                return $lastpostdate;
861
755
         *
862
756
         * @todo cleanup some displays
863
757
         * @todo implement HMS part of YMDHMS
864
 
         *
865
758
         * @return array
866
759
         */
867
760
        function get_filter_titles( $ignore = array(), $params = array() )
868
761
        {
869
 
                global $month, $post_statuses;
 
762
                global $month;
 
763
                global $post_statuses;
870
764
 
871
765
                $params = array_merge( array(
872
766
                                'category_text' => T_('Category').': ',
876
770
                        ), $params );
877
771
 
878
772
                if( empty( $this->filters ) )
879
 
                {       // Filters have no been set before, we'll use the default filterset:
 
773
                {
 
774
                        // Filters have no been set before, we'll use the default filterset
880
775
                        $this->set_filters( $this->default_filters );
881
776
                }
882
777
 
883
778
                $title_array = array();
884
779
 
885
780
                if( $this->single_post )
886
 
                {       // We have requested a specific post:
887
 
                        // Should be in first position
 
781
                {
 
782
                        // We have requested a specific post, should be in first position
888
783
                        $Item = & $this->get_by_idx( 0 );
889
784
 
890
 
                        if( is_null($Item) )
 
785
                        if( is_null( $Item ) )
891
786
                        {
892
787
                                $title_array[] = T_('Invalid request');
893
788
                        }
898
793
                        return $title_array;
899
794
                }
900
795
 
901
 
 
902
 
                // CATEGORIES:
903
 
                if( !empty($this->filters['cat_array']) )
904
 
                { // We have requested specific categories...
 
796
                // CATEGORIES
 
797
                if( ! empty( $this->filters['cat_array'] ) )
 
798
                {
 
799
                        // We have requested specific categories...
905
800
                        $cat_names = array();
906
 
                        $ChapterCache = & get_Cache('ChapterCache');
 
801
                        $CategoryCache = & get_Cache('CategoryCache');
907
802
                        foreach( $this->filters['cat_array'] as $cat_ID )
908
803
                        {
909
 
                                if( ($my_Chapter = & $ChapterCache->get_by_ID($cat_ID, false) ) !== false )
910
 
                                { // It is almost never meaningful to die over an invalid cat when generating title
 
804
                                if( ( $my_Chapter = & $CategoryCache->get_by_ID( $cat_ID, false ) ) !== false )
 
805
                                {
 
806
                                        // It is almost never meaningful to die over an invalid cat when generating title
911
807
                                        $cat_names[] = $my_Chapter->name;
912
808
                                }
913
809
                        }
919
815
                        {
920
816
                                $cat_names_string = implode( ', ', $cat_names );
921
817
                        }
922
 
                        if( !empty( $cat_names_string ) )
 
818
                        if( ! empty( $cat_names_string ) )
923
819
                        {
924
820
                                if( $this->filters['cat_modifier'] == '-' )
925
821
                                {
928
824
                                }
929
825
                                else
930
826
                                {
931
 
                                        if( count($this->filters['cat_array']) > 1 )
 
827
                                        if( count( $this->filters['cat_array'] ) > 1 )
932
828
                                                $title_array['cats'] = $params['categories_text'].$cat_names_string;
933
829
                                        else
934
830
                                                $title_array['cats'] = $params['category_text'].$cat_names_string;
936
832
                        }
937
833
                }
938
834
 
939
 
 
940
 
                // ARCHIVE TIMESLOT:
941
 
                if( !empty($this->filters['ymdhms']) )
942
 
                {       // We have asked for a specific timeframe:
943
 
 
944
 
                        $my_year = substr($this->filters['ymdhms'],0,4);
945
 
 
946
 
                        if( strlen($this->filters['ymdhms']) > 4 )
947
 
                        { // We have requested a month too:
948
 
                                $my_month = T_($month[substr($this->filters['ymdhms'],4,2)]);
 
835
                // ARCHIVE TIMESLOT
 
836
                if( ! empty( $this->filters['ymdhms'] ) )
 
837
                {
 
838
                        // We have asked for a specific timeframe
 
839
 
 
840
                        $my_year = substr( $this->filters['ymdhms'], 0, 4 );
 
841
 
 
842
                        if( strlen( $this->filters['ymdhms'] ) > 4 )
 
843
                        {
 
844
                                // We have requested a month too:
 
845
                                $my_month = T_( $month[substr( $this->filters['ymdhms'], 4, 2 )] );
949
846
                        }
950
847
                        else
951
848
                        {
953
850
                        }
954
851
 
955
852
                        // Requested a day?
956
 
                        $my_day = substr($this->filters['ymdhms'],6,2);
 
853
                        $my_day = substr( $this->filters['ymdhms'], 6, 2 );
957
854
 
958
855
                        $arch = T_('Archives for').': '.$my_month.' '.$my_year;
959
856
 
960
 
                        if( !empty( $my_day ) )
961
 
                        {       // We also want to display a day
 
857
                        if( ! empty( $my_day ) )
 
858
                        {
 
859
                                // We also want to display a day
962
860
                                $arch .= ', '.$my_day;
963
861
                        }
964
862
 
965
 
                        if( !empty($this->filters['week']) || ($this->filters['week'] === 0) ) // Note: week # can be 0
966
 
                        {       // We also want to display a week number
 
863
                        if( ! empty( $this->filters['week'] ) || ( $this->filters['week'] === 0 ) ) // Note: week # can be 0
 
864
                        {
 
865
                                // We also want to display a week number
967
866
                                $arch .= ', '.T_('week').' '.$this->filters['week'];
968
867
                        }
969
868
 
970
869
                        $title_array['ymdhms'] = $arch;
971
870
                }
972
871
 
973
 
 
974
 
                // KEYWORDS:
975
 
                if( !empty($this->filters['keywords']) )
 
872
                // KEYWORDS
 
873
                if( ! empty( $this->filters['keywords'] ) )
976
874
                {
977
875
                        $title_array['keywords'] = T_('Keyword(s)').': '.$this->filters['keywords'];
978
876
                }
979
877
 
980
 
 
981
 
                // TAGS:
982
 
                if( !empty($this->filters['tags']) )
 
878
                // TAGS
 
879
                if( ! empty( $this->filters['tags'] ) )
983
880
                {
984
881
                        $title_array[] = $params['tags_text'].$this->filters['tags'];
985
882
                }
986
883
 
987
 
 
988
 
                // AUTHORS:
989
 
                if( !empty($this->filters['authors']) )
 
884
                // AUTHORS
 
885
                if( ! empty( $this->filters['authors'] ) )
990
886
                {
991
887
                        $title_array[] = T_('Author(s)').': '.$this->filters['authors'];
992
888
                }
993
889
 
994
 
 
995
 
                // ASSIGNEES:
996
 
                if( !empty($this->filters['assignees']) )
 
890
                // ASSIGNEES
 
891
                if( ! empty( $this->filters['assignees'] ) )
997
892
                {
998
893
                        if( $this->filters['assignees'] == '-' )
999
894
                        {
1005
900
                        }
1006
901
                }
1007
902
 
1008
 
 
1009
 
                // LOCALE:
 
903
                // LOCALE
1010
904
                if( $this->filters['lc'] != 'all' )
1011
905
                {
1012
906
                        $title_array[] = T_('Locale').': '.$this->filters['lc'];
1013
907
                }
1014
908
 
1015
 
 
1016
 
                // EXTRA STATUSES:
1017
 
                if( !empty($this->filters['statuses']) )
 
909
                // EXTRA STATUSES
 
910
                if( ! empty( $this->filters['statuses'] ) )
1018
911
                {
1019
912
                        if( $this->filters['statuses'] == '-' )
1020
913
                        {
1026
919
                        }
1027
920
                }
1028
921
 
1029
 
 
1030
922
                // SHOW STATUSES
1031
923
                if( count( $this->filters['visibility_array'] ) < 5
1032
924
                        && !in_array( 'visibility', $ignore ) )
1039
931
                        $title_array[] = T_('Visibility').': '.implode( ', ', $status_titles );
1040
932
                }
1041
933
 
1042
 
 
1043
934
                // START AT
1044
 
                if( !empty($this->filters['ymdhms_min'] ) )
 
935
                if( ! empty( $this->filters['ymdhms_min'] ) )
1045
936
                {
1046
937
                        $title_array['ymdhms_min'] = T_('Start at').': '.$this->filters['ymdhms_min'] ;
1047
938
                }
1048
 
                if( !empty($this->filters['ts_min'] ) )
 
939
                if( ! empty( $this->filters['ts_min'] ) )
1049
940
                {
1050
941
                        if( $this->filters['ts_min'] == 'now' )
1051
942
                        {
1057
948
                        }
1058
949
                }
1059
950
 
1060
 
 
1061
951
                // STOP AT
1062
 
                if( !empty($this->filters['ymdhms_max'] ) )
 
952
                if( ! empty( $this->filters['ymdhms_max'] ) )
1063
953
                {
1064
954
                        $title_array['ymdhms_max'] = T_('Stop at').': '.$this->filters['ymdhms_max'];
1065
955
                }
1066
 
                if( !empty($this->filters['ts_max'] ) )
 
956
                if( ! empty( $this->filters['ts_max'] ) )
1067
957
                {
1068
958
                        if( $this->filters['ts_max'] == 'now' )
1069
959
                        {
1078
968
                        }
1079
969
                }
1080
970
 
1081
 
 
1082
971
                // LIMIT TO
1083
 
                if( $this->single_post )   // p or title
1084
 
                { // Single post: no paging required!
 
972
                if( $this->single_post ) // p or title
 
973
                {
 
974
                        // Single post: no paging required!
1085
975
                }
1086
 
                elseif( !empty($this->filters['ymdhms']) )
1087
 
                { // no restriction if we request a month... some permalinks may point to the archive!
 
976
                elseif( ! empty( $this->filters['ymdhms'] ) )
 
977
                {
 
978
                        // no restriction if we request a month... some permalinks may point to the archive!
1088
979
                }
1089
980
                elseif( $this->filters['unit'] == 'posts' || $this->filters['unit'] == 'all' )
1090
 
                { // We're going to page, so there's no real limit here...
 
981
                {
 
982
                        // We're going to page, so there's no real limit here...
1091
983
                }
1092
984
                elseif( $this->filters['unit'] == 'days' )
1093
 
                { // We are going to limit to x days:
 
985
                {
 
986
                        // We are going to limit to x days:
1094
987
                        if( empty( $this->filters['ymdhms_min'] ) )
1095
 
                        { // We have no start date, we'll display the last x days:
1096
 
                                if( !empty($this->filters['keywords'])
1097
 
                                        || !empty($this->filters['cat_array'])
1098
 
                                        || !empty($this->filters['authors']) )
1099
 
                                { // We are in DAYS mode but we can't restrict on these! (TODO: ?)
 
988
                        {
 
989
                                // We have no start date, we'll display the last x days:
 
990
                                if( ! empty( $this->filters['keywords'] )
 
991
                                        || ! empty( $this->filters['cat_array'] )
 
992
                                        || ! empty( $this->filters['authors'] ) )
 
993
                                {
 
994
                                        // We are in DAYS mode but we can't restrict on these! (TODO: ?)
1100
995
                                }
1101
996
                                else
1102
 
                                { // We are going to limit to LAST x days:
1103
 
                                        // TODO: rename 'posts' to 'limit'
 
997
                                {
 
998
                                        // We are going to limit to LAST x days:
1104
999
                                        $title_array['posts'] = sprintf( T_('Limited to %d last days'), $this->limit );
1105
1000
                                }
1106
1001
                        }
1107
1002
                        else
1108
 
                        { // We have a start date, we'll display x days starting from that point:
 
1003
                        {
 
1004
                                // We have a start date, we'll display x days starting from that point:
1109
1005
                                $title_array['posts'] = sprintf( T_('Limited to %d days'), $this->limit );
1110
1006
                        }
1111
1007
                }
1128
1024
                global $row;
1129
1025
 
1130
1026
                if( empty( $this->current_Obj ) )
1131
 
                {       // Very first call
 
1027
                {
 
1028
                        // Very first call
1132
1029
                        // Do a normal get_next()
1133
1030
                        parent::get_next();
1134
1031
                }
1135
1032
 
1136
1033
                if( empty( $this->current_Obj ) )
1137
 
                {       // We have reached the end of the list
 
1034
                {
 
1035
                        // We have reached the end of the list
1138
1036
                        return $this->current_Obj;
1139
1037
                }
1140
1038
 
1149
1047
 
1150
1048
        /**
1151
1049
         * If the list is sorted by category...
1152
 
         *
1153
 
         * This is basically just a stub for backward compatibility
 
1050
         *
 
1051
         * This is basically just a stub for backward compatibility
1154
1052
         */
1155
1053
        function & get_item()
1156
1054
        {
1157
1055
                if( $this->group_by_cat == 1 )
1158
 
                {       // This is the first call to get_item() after get_category_group()
 
1056
                {
 
1057
                        // This is the first call to get_item() after get_category_group()
1159
1058
                        $this->group_by_cat = 2;
1160
1059
                        // Return the object we already got in get_category_group():
1161
1060
                        return $this->current_Obj;
1163
1062
 
1164
1063
                $Item = & $this->get_next();
1165
1064
 
1166
 
                if( !empty($Item) && $this->group_by_cat == 2 && $Item->main_cat_ID != $this->main_cat_ID )
1167
 
                {       // We have just hit a new category!
 
1065
                if( ! empty( $Item ) && $this->group_by_cat == 2 && $Item->main_cat_ID != $this->main_cat_ID )
 
1066
                {
 
1067
                        // We have just hit a new category!
1168
1068
                        $this->group_by_cat == 0; // For info only.
1169
1069
                        $r = false;
1170
1070
                        return $r;
1182
1082
         *  -week + m
1183
1083
         *  -m
1184
1084
         *  -dstop - x days
 
1085
         *
1185
1086
         * @see ItemQuery::where_datestart()
1186
1087
         */
1187
1088
        function get_advertised_start_date()
1188
1089
        {
1189
1090
                if( $this->getting_adv_start_date )
1190
 
                {       // We would be entering an infinite loop, stop now:
1191
 
                        // We cannot determine a start date, save an empty string (to differentiate from NULL)
 
1091
                {
 
1092
                        // We would be entering an infinite loop, stop now. We cannot determine
 
1093
                        // a start date, save an empty string (to differentiate from NULL)
1192
1094
                        $this->advertised_start_date = '';
1193
1095
 
1194
 
                        // Reset anti infinite loop:
 
1096
                        // Reset anti infinite loop
1195
1097
                        $this->getting_adv_start_date = false;
1196
1098
 
1197
1099
                        return $this->advertised_start_date;
1198
1100
                }
1199
1101
 
1200
 
                // Anti infinite loop:
 
1102
                // Anti infinite loop
1201
1103
                $this->getting_adv_start_date = true;
1202
1104
 
1203
1105
 
1204
1106
                if( is_null( $this->advertised_start_date ) )
1205
 
                {       // We haven't determined the start date yet:
 
1107
                {
 
1108
                        // We haven't determined the start date yet
1206
1109
 
1207
 
                        if( !empty( $this->filters['ymdhms_min'] ) )
1208
 
                        {       // We have requested start date (8 digits)
 
1110
                        if( ! empty( $this->filters['ymdhms_min'] ) )
 
1111
                        {
 
1112
                                // We have requested start date (8 digits)
1209
1113
                                $m = $this->filters['ymdhms_min'];
1210
 
                                $this->advertised_start_date = mktime( 0, 0, 0, substr($m,4,2), substr($m,6,2), substr($m,0,4) );
 
1114
                                $this->advertised_start_date = mktime( 0, 0, 0, substr( $m, 4, 2 ), substr( $m, 6, 2 ), substr( $m, 0, 4 ) );
1211
1115
                        }
1212
 
                        elseif( !is_null($this->filters['week'])                // note: 0 is a valid week number
1213
 
                                                && !empty( $this->filters['ymdhms'] ) )
1214
 
                        {       // we want to restrict on a specific week
1215
 
                                $this->advertised_start_date = get_start_date_for_week( substr($this->filters['ymdhms'],0,4), $this->filters['week'], locale_startofweek() );
 
1116
                        elseif( ! is_null( $this->filters['week'] ) // note: 0 is a valid week number
 
1117
                                                && ! empty( $this->filters['ymdhms'] ) )
 
1118
                        {
 
1119
                                // we want to restrict on a specific week
 
1120
                                $this->advertised_start_date = get_start_date_for_week( substr( $this->filters['ymdhms'],0, 4 ), $this->filters['week'], locale_startofweek() );
1216
1121
                        }
1217
1122
                        elseif( strlen( $this->filters['ymdhms'] ) >= 4 )
1218
 
                        {       // We have requested an interval
 
1123
                        {
 
1124
                                // We have requested an interval
1219
1125
                                $m = $this->filters['ymdhms'].'0101';
1220
 
                                $this->advertised_start_date = mktime( 0, 0, 0, substr($m,4,2), substr($m,6,2), substr($m,0,4) );
 
1126
                                $this->advertised_start_date = mktime( 0, 0, 0, substr( $m, 4, 2 ), substr( $m, 6, 2 ), substr( $m, 0, 4 ) );
1221
1127
                        }
1222
1128
                        elseif( $this->filters['unit'] == 'days'
1223
 
                                                && ($stop_date = $this->get_advertised_stop_date()) != '' )
1224
 
                        {       // We want to restrict on a specific number of days after the start date:
1225
 
                                $this->advertised_start_date = $stop_date - ($this->limit-1) * 86400;
 
1129
                                                && ( $stop_date = $this->get_advertised_stop_date() ) != '' )
 
1130
                        {
 
1131
                                // We want to restrict on a specific number of days after the start date
 
1132
                                $this->advertised_start_date = $stop_date - ( $this->limit-1 ) * 86400;
1226
1133
                        }
1227
1134
                        else
1228
 
                        {       // We cannot determine a start date, save an empty string (to differentiate from NULL)
 
1135
                        {
 
1136
                                // We cannot determine a start date, save an empty string (to differentiate from NULL)
1229
1137
                                $this->advertised_start_date = '';
1230
1138
                        }
1231
1139
 
1232
1140
                }
1233
1141
 
1234
 
                // Reset anti infinite loop:
 
1142
                // Reset anti infinite loop
1235
1143
                $this->getting_adv_start_date = false;
1236
1144
 
1237
1145
                return $this->advertised_start_date;
1250
1158
        function get_advertised_stop_date()
1251
1159
        {
1252
1160
                if( $this->getting_adv_stop_date )
1253
 
                {       // We would be entering an infinite loop, stop now:
1254
 
                        // We cannot determine a stop date, save an empty string (to differentiate from NULL)
 
1161
                {
 
1162
                        // We would be entering an infinite loop, stop now. We cannot determine
 
1163
                        // a stop date, save an empty string (to differentiate from NULL)
1255
1164
                        $this->advertised_stop_date = '';
1256
1165
 
1257
 
                        // Reset anti infinite loop:
 
1166
                        // Reset anti infinite loop
1258
1167
                        $this->getting_adv_stop_date = false;
1259
1168
 
1260
1169
                        return $this->advertised_stop_date;
1261
1170
                }
1262
1171
 
1263
 
                // Anti infinite loop:
 
1172
                // Anti infinite loop
1264
1173
                $this->getting_adv_stop_date = true;
1265
1174
 
1266
1175
 
1267
1176
                if( is_null( $this->advertised_stop_date ) )
1268
 
                {       // We haven't determined the stop date yet:
 
1177
                {
 
1178
                        // We haven't determined the stop date yet
1269
1179
 
1270
 
                        if( !empty( $this->filters['ymdhms_max'] ) )
1271
 
                        {       // We have requested an end date (8 digits)
 
1180
                        if( ! empty( $this->filters['ymdhms_max'] ) )
 
1181
                        {
 
1182
                                // We have requested an end date (8 digits)
1272
1183
                                $m = $this->filters['ymdhms_max'];
1273
 
                                $this->advertised_stop_date = mktime( 0, 0, 0, substr($m,4,2), substr($m,6,2), substr($m,0,4) );
 
1184
                                $this->advertised_stop_date = mktime( 0, 0, 0, substr( $m, 4, 2 ), substr( $m, 6, 2 ), substr( $m, 0, 4 ) );
1274
1185
                        }
1275
 
                        elseif( !is_null($this->filters['week'])                // note: 0 is a valid week number
1276
 
                                                && !empty( $this->filters['ymdhms'] ) )
1277
 
                        {       // we want to restrict on a specific week
1278
 
                                $this->advertised_stop_date = get_start_date_for_week( substr($this->filters['ymdhms'],0,4), $this->filters['week'], locale_startofweek() );
 
1186
                        elseif( !is_null( $this->filters['week'] ) // note: 0 is a valid week number
 
1187
                                                && ! empty( $this->filters['ymdhms'] ) )
 
1188
                        {
 
1189
                                // we want to restrict on a specific week
 
1190
                                $this->advertised_stop_date = get_start_date_for_week( substr( $this->filters['ymdhms'],0,4 ), $this->filters['week'], locale_startofweek() );
1279
1191
                                $this->advertised_stop_date += 518400; // + 6 days
1280
1192
                        }
1281
 
                        elseif( !empty( $this->filters['ymdhms'] ) )
1282
 
                        {       // We want to restrict on an interval:
 
1193
                        elseif( ! empty( $this->filters['ymdhms'] ) )
 
1194
                        {
 
1195
                                // We want to restrict on an interval
1283
1196
                                if( strlen( $this->filters['ymdhms'] ) >= 8 )
1284
 
                                {       // We have requested a day interval
 
1197
                                {
 
1198
                                        // We have requested a day interval
1285
1199
                                        $m = $this->filters['ymdhms'];
1286
 
                                        $this->advertised_stop_date = mktime( 0, 0, 0, substr($m,4,2), substr($m,6,2), substr($m,0,4) );
 
1200
                                        $this->advertised_stop_date = mktime( 0, 0, 0, substr( $m, 4, 2 ), substr( $m, 6, 2 ), substr( $m, 0, 4 ) );
1287
1201
                                }
1288
1202
                                elseif( strlen( $this->filters['ymdhms'] ) == 6 )
1289
 
                                { // We want to go to the end of the month:
 
1203
                                {
 
1204
                                        // We want to go to the end of the month
1290
1205
                                        $m = $this->filters['ymdhms'];
1291
 
                                        $this->advertised_stop_date = mktime( 0, 0, 0, substr($m,4,2)+1, 0, substr($m,0,4) ); // 0th day of next mont = last day of month
 
1206
                                        $this->advertised_stop_date = mktime( 0, 0, 0, substr( $m, 4, 2 )+1, 0, substr( $m, 0, 4 ) ); // 0th day of next mont = last day of month
1292
1207
                                }
1293
1208
                                elseif( strlen( $this->filters['ymdhms'] ) == 4 )
1294
 
                                { // We want to go to the end of the year:
 
1209
                                {
 
1210
                                        // We want to go to the end of the year
1295
1211
                                        $m = $this->filters['ymdhms'];
1296
 
                                        $this->advertised_stop_date = mktime( 0, 0, 0, 12, 31, substr($m,0,4) );
 
1212
                                        $this->advertised_stop_date = mktime( 0, 0, 0, 12, 31, substr( $m, 0, 4 ) );
1297
1213
                                }
1298
1214
                        }
1299
1215
                        elseif( $this->filters['unit'] == 'days'
1300
 
                                                && ($start_date = $this->get_advertised_start_date()) != '' )
1301
 
                        {       // We want to restrict on a specific number of days after the start date:
1302
 
                                $this->advertised_stop_date = $start_date + ($this->limit-1) * 86400;
 
1216
                                                && ( $start_date = $this->get_advertised_start_date() ) != '' )
 
1217
                        {
 
1218
                                // We want to restrict on a specific number of days after the start date
 
1219
                                $this->advertised_stop_date = $start_date + ( $this->limit-1 ) * 86400;
1303
1220
                        }
1304
1221
                        else
1305
 
                        {       // We cannot determine a stop date, save an empty string (to differentiate from NULL)
 
1222
                        {
 
1223
                                // We cannot determine a stop date, save an empty string (to differentiate from NULL)
1306
1224
                                $this->advertised_stop_date = '';
1307
1225
                        }
1308
1226
 
1309
1227
                }
1310
1228
 
1311
 
                // Reset anti infinite loop:
 
1229
                // Reset anti infinite loop
1312
1230
                $this->getting_adv_stop_date = false;
1313
1231
 
1314
1232
                return $this->advertised_stop_date;
1316
1234
 
1317
1235
 
1318
1236
        /**
1319
 
         * Make sure date displaying starts at the beginning of the current filter interval
 
1237
         * set start date
1320
1238
         *
 
1239
         * Make sure date displaying starts at the beginning of the current filter interval.
1321
1240
         * Note: we're talking about strict dates (no times involved)
1322
1241
         */
1323
1242
        function set_start_date( )
1324
1243
        {
1325
1244
                $start_date = $this->get_advertised_start_date();
1326
1245
 
1327
 
                if( !empty( $start_date ) )
1328
 
                {       // Memorize the last displayed as the day BEFORE the one we're going to display
 
1246
                if( ! empty( $start_date ) )
 
1247
                {
 
1248
                        // Memorize the last displayed as the day BEFORE the one we're going to display
1329
1249
                        $this->last_displayed_date = $start_date - 86400;
1330
1250
                }
1331
1251
        }
1332
1252
 
1333
1253
 
1334
1254
        /**
1335
 
         * Template function: display potentially remaining empty days until the end of the filter interval
 
1255
         * Template function: dates to end
 
1256
         *
 
1257
         * display potentially remaining empty days until the end of the filter interval
1336
1258
         *
1337
1259
         * @param string string to display before the date (if changed)
1338
1260
         * @param string string to display after the date (if changed)
1343
1265
                $stop_date = $this->get_advertised_stop_date();
1344
1266
 
1345
1267
                if( !is_null( $stop_date ) )
1346
 
                {       // There is a stop date, we want to display days:
 
1268
                {
 
1269
                        // There is a stop date, we want to display days
1347
1270
                        while( $this->last_displayed_date < $stop_date )
1348
1271
                        {
1349
 
                                $this->last_displayed_date += 86400;    // Add one day's worth of seconds
 
1272
                                $this->last_displayed_date += 86400; // Add one day's worth of seconds
1350
1273
                                echo date_sprintf( $before_empty_day, $this->last_displayed_date )
1351
 
                                                .date_i18n( $format, $this->last_displayed_date )
1352
 
                                                .date_sprintf( $after_empty_day, $this->last_displayed_date );
 
1274
                                        .date_i18n( $format, $this->last_displayed_date )
 
1275
                                        .date_sprintf( $after_empty_day, $this->last_displayed_date );
1353
1276
                        }
1354
1277
                }
1355
1278
        }
1362
1285
         *
1363
1286
         * <code>
1364
1287
         * $default_params = array(
1365
 
         *      'before'            => '<h2>',
1366
 
         *      'after'             => '</h2>',
1367
 
         *      'empty_day_display' => false,
1368
 
         *      'empty_day_before'  => '<h2>',
1369
 
         *      'empty_day_after'   => '</h2>',
1370
 
         *      'date_format'       => '#', // '#' = locale_datefmt()
 
1288
         *   'before' => '<h2>',
 
1289
         *   'after' => '</h2>',
 
1290
         *   'empty_day_display' => false,
 
1291
         *   'empty_day_before' => '<h2>',
 
1292
         *   'empty_day_after' => '</h2>',
 
1293
         *   'date_format' => '#', // '#' = locale_datefmt()
1371
1294
         * ), $params );
1372
1295
         * </code>
 
1296
         *
 
1297
         * @param array Associative array of parameters
1373
1298
         */
1374
1299
        function date_if_changed( $params = array() )
1375
1300
        {
1376
1301
                if( $this->current_Obj->ptyp_ID == 1000 )
1377
 
                {       // This is not applicable to pages
 
1302
                {
 
1303
                        // This is not applicable to pages
1378
1304
                        return;
1379
1305
                }
1380
1306
 
1381
 
                // Make sure we are not missing any param:
 
1307
                // Make sure we are not missing any param
1382
1308
                $params = array_merge( array(
1383
 
                                'before'            => '<h2>',
1384
 
                                'after'             => '</h2>',
1385
 
                                'empty_day_display' => false,
1386
 
                                'empty_day_before'  => '<h2>',
1387
 
                                'empty_day_after'   => '</h2>',
1388
 
                                'date_format'       => '#',
1389
 
                        ), $params );
 
1309
                        'before' => '<h2>',
 
1310
                        'after' => '</h2>',
 
1311
                        'empty_day_display' => false,
 
1312
                        'empty_day_before' => '<h2>',
 
1313
                        'empty_day_after' => '</h2>',
 
1314
                        'date_format' => '#',
 
1315
                ), $params );
1390
1316
 
1391
 
                // Get a timestamp for the date WITHOUT the time:
 
1317
                // Get a timestamp for the date WITHOUT the time
1392
1318
                $current_item_date = mysql2datestamp( $this->current_Obj->issue_date );
1393
1319
 
1394
1320
                if( $current_item_date != $this->last_displayed_date )
1395
 
                {       // Date has changed...
1396
 
 
1397
 
 
 
1321
                {
 
1322
                        // Date has changed...
1398
1323
                        if( $params['date_format'] == '#' )
1399
 
                        {       // No format specified, use default locale format:
 
1324
                        {
 
1325
                                // No format specified, use default locale format
1400
1326
                                $params['date_format'] = locale_datefmt();
1401
1327
                        }
1402
1328
 
1403
 
                        if( $params['empty_day_display'] && !empty($this->last_displayed_date) )
1404
 
                        {       // We want to display ALL dates from the previous to the current:
 
1329
                        if( $params['empty_day_display'] && ! empty( $this->last_displayed_date ) )
 
1330
                        {
 
1331
                                // We want to display ALL dates from the previous to the current
1405
1332
                                while( $this->last_displayed_date < $current_item_date-86400 )
1406
1333
                                {
1407
 
                                        $this->last_displayed_date += 86400;    // Add one day's worth of seconds
 
1334
                                        $this->last_displayed_date += 86400; // Add one day's worth of seconds
1408
1335
                                        echo date_sprintf( $params['empty_day_before'], $this->last_displayed_date )
1409
 
                                                        .date_i18n( $params['date_format'], $this->last_displayed_date )
1410
 
                                                        .date_sprintf( $params['empty_day_after'], $this->last_displayed_date );
 
1336
                                                .date_i18n( $params['date_format'], $this->last_displayed_date )
 
1337
                                                .date_sprintf( $params['empty_day_after'], $this->last_displayed_date );
1411
1338
                                }
1412
1339
                        }
1413
1340
 
1414
 
                        // Display the new current date:
 
1341
                        // Display the new current date
1415
1342
                        echo date_sprintf( $params['before'], $this->last_displayed_date )
1416
 
                                        .date_i18n( $params['date_format'], $current_item_date )
1417
 
                                        .date_sprintf( $params['after'], $this->last_displayed_date );
 
1343
                                .date_i18n( $params['date_format'], $current_item_date )
 
1344
                                .date_sprintf( $params['after'], $this->last_displayed_date );
1418
1345
 
1419
1346
                        $this->last_displayed_date = $current_item_date;
1420
1347
                }
1441
1368
         *   'scroll_list_range' => 5,
1442
1369
         * );
1443
1370
         * </code>
 
1371
         *
 
1372
         * @param array Associative array of parameters
1444
1373
         */
1445
1374
        function page_links( $params = array() )
1446
1375
        {
1447
1376
 
1448
 
                // Make sure we are not missing any param:
 
1377
                // Make sure we are not missing any param
1449
1378
                $default_params = array(
1450
 
                                'block_start'       => '<p class="center">',
1451
 
                                'block_end'         => '</p>',
1452
 
                                'block_single'      => '',
1453
 
                                'links_format'      => '$prev$ $first$ $list_prev$ $list$ $list_next$ $last$ $next$',
1454
 
                                'page_url'          => '',
1455
 
                                'prev_text'         => '&lt;&lt;',
1456
 
                                'next_text'         => '&gt;&gt;',
1457
 
                                'no_prev_text'      => '',
1458
 
                                'no_next_text'      => '',
1459
 
                                'list_prev_text'    => '...',
1460
 
                                'list_next_text'    => '...',
1461
 
                                'list_span'         => 11,
1462
 
                                'scroll_list_range' => 5,
1463
 
                        );
 
1379
                        'block_start' => '<p class="center">',
 
1380
                        'block_end' => '</p>',
 
1381
                        'block_single' => '',
 
1382
                        'links_format' => '$prev$ $first$ $list_prev$ $list$ $list_next$ $last$ $next$',
 
1383
                        'page_url' => '',
 
1384
                        'prev_text' => '&lt;&lt;',
 
1385
                        'next_text' => '&gt;&gt;',
 
1386
                        'no_prev_text' => '',
 
1387
                        'no_next_text' => '',
 
1388
                        'list_prev_text' => '...',
 
1389
                        'list_next_text' => '...',
 
1390
                        'list_span' => 11,
 
1391
                        'scroll_list_range' => 5,
 
1392
                );
1464
1393
 
1465
 
                // Use defaults + overrides:
 
1394
                // Use defaults + overrides
1466
1395
                $params = array_merge( $default_params, $params );
1467
1396
 
1468
1397
                if( $this->total_pages <= 1 )
1469
 
                {       // Single page:
 
1398
                {
 
1399
                        // Single page
1470
1400
                        echo $params['block_single'];
1471
1401
                        return;
1472
1402
                }
1473
1403
 
1474
 
                if( $this->Blog->get_setting( 'paged_nofollowto' ) )
1475
 
                {       // We prefer robots not to follow to pages:
1476
 
                        $this-> nofollow_pagenav = true;
 
1404
                if( $this->Blog->get_setting( 'paged_nofollowto' ) )
 
1405
                {
 
1406
                        // We prefer robots not to follow to pages
 
1407
                        $this->nofollow_pagenav = true;
1477
1408
                }
1478
1409
 
1479
1410
                echo $params['block_start'];