3
* This file implements the ItemListLight class.
5
* This object handles item/post/article lists WITHOUT FULL FUNCTIONNALITY
6
* but with a LOWER MEMORY FOOTPRINT.
8
* This file is part of Quam Plures - {@link http://quamplures.net/}
9
* See also {@link https://launchpad.net/quam-plures}.
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/}
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
23
* {@internal Open Source relicensing agreement:
26
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
27
* @author fplanque: Francois PLANQUE.
3
* This file implements the ItemListLight class
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.
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
31
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
17
if(!defined('QP_MAIN_INIT')) die('fail');
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' );
39
* Item List Class LIGHT
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.
101
91
function ItemListLight(
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
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)
111
101
global $Settings;
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 );
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 );
119
109
$this->Blog = & $Blog;
121
if( !empty( $filterset_name ) )
122
{ // Set the filterset_name with the filterset_name param
111
if( ! empty( $filterset_name ) )
113
// Set the filterset_name with the filterset_name param
123
114
$this->filterset_name = 'ItemList_filters_'.$filterset_name;
126
{ // Set a generic filterset_name
118
// Set a generic filterset_name
127
119
$this->filterset_name = 'ItemList_filters_coll'.$this->Blog->ID;
130
122
$this->page_param = $param_prefix.'paged';
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
144
'author_assignee' => NULL,
145
'lc' => 'all', // Filter on requested locale
150
'post_ID_list' => NULL,
151
'post_title' => NULL,
154
'ymdhms_min' => NULL,
155
'ymdhms_max' => 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,
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
136
'author_assignee' => NULL,
137
'lc' => 'all', // Filter on requested locale
142
'post_ID_list' => NULL,
143
'post_title' => NULL,
146
'ymdhms_min' => NULL,
147
'ymdhms_max' => 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,
204
196
function set_filters( $filters, $memorize = true )
206
if( !empty( $filters ) )
207
{ // Activate the filterset (fallback to default filter when a value is not set):
198
if( ! empty( $filters ) )
200
// Activate the filterset (fallback to default filter when a value is not set)
208
201
$this->filters = array_merge( $this->default_filters, $filters );
211
// Activate preset filters if necessary:
204
// Activate preset filters if necessary
212
205
$this->activate_preset_filters();
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'];
220
{ // set back the GLOBALS !!! needed for regenerate_url() :
213
// set back the GLOBALS !!! needed for regenerate_url() :
223
* Selected filter preset:
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
218
// Blog & categories restrictions
229
* Blog & Chapters/categories restrictions:
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'];
244
* Restrict to selected tags:
233
// Restrict to selected tags
246
234
memorize_param( $this->param_prefix.'tags', 'string', $this->default_filters['tags'], $this->filters['tags'] );
250
* Restrict to selected authors:
252
memorize_param( $this->param_prefix.'author', 'string', $this->default_filters['authors'], $this->filters['authors'] ); // List of authors to restrict to
255
* Restrict to selected assignees:
257
memorize_param( $this->param_prefix.'assgn', 'string', $this->default_filters['assignees'], $this->filters['assignees'] ); // List of assignees to restrict to
260
* Restrict to selected author OR assignee:
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
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
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'] );
265
* Restrict to selected locale:
267
memorize_param( $this->param_prefix.'lc', 'string', $this->default_filters['lc'], $this->filters['lc'] ); // Locale to restrict to
270
* Restrict to selected statuses:
272
memorize_param( $this->param_prefix.'status', 'string', $this->default_filters['statuses'], $this->filters['statuses'] ); // List of statuses to restrict to
275
* Restrict to selected item type:
277
memorize_param( $this->param_prefix.'types', 'integer', $this->default_filters['types'], $this->filters['types'] ); // List of item types to restrict to
280
* Restrict by keywords
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
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
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
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
287
* Specific Item selection?
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
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'] ) )
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 );
303
* Restrict to the statuses we want to show:
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
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)
317
memorize_param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], $this->filters['unit'] ); // list unit: 'posts' or 'days'
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
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)
283
memorize_param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], $this->filters['unit'] ); // list unit: 'posts' or 'days'
285
memorize_param( $this->param_prefix.'posts', 'integer', $this->default_filters['posts'], $this->filters['posts'] ); // # of units to display on the page
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
344
310
switch( $filter_action )
347
return $this->restore_filterset();
313
return $this->restore_filterset();
351
// We want to reset the memorized filterset:
353
$Session->delete( $this->filterset_name );
355
// Memorize global variables:
356
$this->set_filters( array(), true );
358
// We have applied no filterset:
319
// We want to reset the memorized filterset
320
$Session->delete( $this->filterset_name );
322
// Memorize global variables
323
$this->set_filters( array(), true );
325
// We have applied no filterset
366
331
$this->filters['filter_preset'] = param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], true );
368
// Activate preset default filters if necessary:
333
// Activate preset default filters if necessary
369
334
$this->activate_preset_filters();
373
// fp> TODO: param( 'loc', 'string', '', true ); // Locale of the posts (all by default)
377
* Blog & Chapters/categories restrictions:
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)
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'] );
383
344
$this->filters['cat_array'] = get_param( 'cat_array' );
384
345
$this->filters['cat_modifier'] = get_param( 'cat_modifier' );
386
347
$this->filters['cat_focus'] = param( $this->param_prefix.'cat_focus', 'string', $this->default_filters['cat_focus'], true );
390
* Restrict to selected tags:
349
// Restrict to selected tags
392
350
$this->filters['tags'] = param( $this->param_prefix.'tag', 'string', $this->default_filters['tags'], true );
396
* Restrict to selected authors:
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
402
* Restrict to selected assignees:
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
408
* Restrict to selected author or assignee:
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 );
414
* Restrict to selected locale:
361
// Restrict to selected locale
416
362
$this->filters['lc'] = param( $this->param_prefix.'lc', 'string', $this->default_filters['lc'], true );
420
* Restrict to selected statuses:
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
425
* Restrict to selected types:
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
431
* Restrict by keywords
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
439
* Specific Item selection?
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
446
* multiple Item selection ?
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
451
$this->single_post = !empty($this->filters['post_ID']) || !empty($this->filters['post_title']);
455
* If a timeframe is specified in the querystring, restrict to that timeframe:
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
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
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
382
$this->single_post = ! empty( $this->filters['post_ID'] ) || ! empty( $this->filters['post_title'] );
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)
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
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'] ) )
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:
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' : '';
481
* Restrict to the statuses we want to show:
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
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)
496
$this->filters['unit'] = param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], true ); // list unit: 'posts' or 'days'
419
$this->filters['unit'] = param( $this->param_prefix.'unit', 'string', $this->default_filters['unit'], true ); // list unit: 'posts' or 'days'
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
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'];
505
428
if( param_errors_detected() )
526
450
* Activate preset default filters if necessary
529
452
function activate_preset_filters()
531
454
$filter_preset = $this->filters['filter_preset'];
533
456
if( empty( $filter_preset ) )
534
{ // No filter preset, there are no additional defaults to use:
458
// No filter preset, there are no additional defaults to use
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] );
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'];
547
* Save current filterset to session.
471
* Save current filterset to session
549
473
function save_filterset()
554
global $Session, $Debuglog;
556
$Debuglog->add( 'Saving filterset <strong>'.$this->filterset_name.'</strong>', 'filters' );
558
477
$Session->set( $this->filterset_name, $this->filters );
563
* Load previously saved filterset from session.
482
* Load previously saved filterset from session
565
483
* @return boolean true if we could restore something
567
485
function restore_filterset()
579
489
$filters = $Session->get( $this->filterset_name );
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 ) )
495
// We have no saved filters
589
if( empty($filters) )
590
{ // set_filters() expects array
500
if( empty( $filters ) )
502
// set_filters() expects array
591
503
$filters = array();
594
$Debuglog->add( 'Restoring filterset <strong>'.$this->filterset_name.'</strong>', 'filters' );
597
507
$this->set_filters( $filters );
699
if( $this->single_post ) // p or title
700
{ // Single post: no paging required!
595
if( $this->single_post ) // p or title
597
// Single post: no paging required!
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'] ) )
603
// no restriction if we request a month... some permalinks may point to the archive!
708
606
elseif( $this->filters['unit'] == 'all' )
709
{ // We want ALL results!
608
// We want ALL results!
711
610
elseif( $this->filters['unit'] == 'posts' )
713
// TODO: dh> check if $limit is NULL!? - though it should not arrive at $page>1 then..
715
613
if( $this->page > 1 )
716
{ // We have requested a specific page number
717
$pgstrt = (intval($this->page) -1) * $this->limit. ', ';
615
// We have requested a specific page number
616
$pgstrt = ( intval( $this->page ) - 1 ) * $this->limit. ', ';
719
618
$this->ItemQuery->LIMIT( $pgstrt.$this->limit );
721
620
elseif( $this->filters['unit'] == 'days' )
722
{ // We are going to limit to x days:
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: ?)
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'] ) )
630
// We are in DAYS mode but we can't restrict on these! (TODO: ?)
732
{ // We are going to limit to LAST x days:
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.'\'' );
742
{ // We have a start date, we'll display x days starting from that point:
646
// We have a start date, we'll display x days starting from that point
743
647
// $dstart_mysql has been calculated earlier
745
// TODO: this is redundant with previous dstart processing:
746
649
// Add trailing 0s: YYYYMMDDHHMMSS
747
650
$dstart0 = $this->filters['ymdhms_min'].'00000000000000';
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.'\'' );
1083
if( $this->single_post ) // p or title
1084
{ // Single post: no paging required!
972
if( $this->single_post ) // p or title
974
// Single post: no paging required!
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'] ) )
978
// no restriction if we request a month... some permalinks may point to the archive!
1089
980
elseif( $this->filters['unit'] == 'posts' || $this->filters['unit'] == 'all' )
1090
{ // We're going to page, so there's no real limit here...
982
// We're going to page, so there's no real limit here...
1092
984
elseif( $this->filters['unit'] == 'days' )
1093
{ // We are going to limit to x days:
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: ?)
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'] ) )
994
// We are in DAYS mode but we can't restrict on these! (TODO: ?)
1102
{ // We are going to limit to LAST x days:
1103
// TODO: rename 'posts' to 'limit'
998
// We are going to limit to LAST x days:
1104
999
$title_array['posts'] = sprintf( T_('Limited to %d last days'), $this->limit );
1108
{ // We have a start date, we'll display x days starting from that point:
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 );
1184
1084
* -dstop - x days
1185
1086
* @see ItemQuery::where_datestart()
1187
1088
function get_advertised_start_date()
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)
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 = '';
1194
// Reset anti infinite loop:
1096
// Reset anti infinite loop
1195
1097
$this->getting_adv_start_date = false;
1197
1099
return $this->advertised_start_date;
1200
// Anti infinite loop:
1102
// Anti infinite loop
1201
1103
$this->getting_adv_start_date = true;
1204
1106
if( is_null( $this->advertised_start_date ) )
1205
{ // We haven't determined the start date yet:
1108
// We haven't determined the start date yet
1207
if( !empty( $this->filters['ymdhms_min'] ) )
1208
{ // We have requested start date (8 digits)
1110
if( ! empty( $this->filters['ymdhms_min'] ) )
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 ) );
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'] ) )
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() );
1217
1122
elseif( strlen( $this->filters['ymdhms'] ) >= 4 )
1218
{ // We have requested an interval
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 ) );
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() ) != '' )
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;
1228
{ // We cannot determine a start date, save an empty string (to differentiate from NULL)
1136
// We cannot determine a start date, save an empty string (to differentiate from NULL)
1229
1137
$this->advertised_start_date = '';
1234
// Reset anti infinite loop:
1142
// Reset anti infinite loop
1235
1143
$this->getting_adv_start_date = false;
1237
1145
return $this->advertised_start_date;
1250
1158
function get_advertised_stop_date()
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)
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 = '';
1257
// Reset anti infinite loop:
1166
// Reset anti infinite loop
1258
1167
$this->getting_adv_stop_date = false;
1260
1169
return $this->advertised_stop_date;
1263
// Anti infinite loop:
1172
// Anti infinite loop
1264
1173
$this->getting_adv_stop_date = true;
1267
1176
if( is_null( $this->advertised_stop_date ) )
1268
{ // We haven't determined the stop date yet:
1178
// We haven't determined the stop date yet
1270
if( !empty( $this->filters['ymdhms_max'] ) )
1271
{ // We have requested an end date (8 digits)
1180
if( ! empty( $this->filters['ymdhms_max'] ) )
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 ) );
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'] ) )
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
1281
elseif( !empty( $this->filters['ymdhms'] ) )
1282
{ // We want to restrict on an interval:
1193
elseif( ! empty( $this->filters['ymdhms'] ) )
1195
// We want to restrict on an interval
1283
1196
if( strlen( $this->filters['ymdhms'] ) >= 8 )
1284
{ // We have requested a day interval
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 ) );
1288
1202
elseif( strlen( $this->filters['ymdhms'] ) == 6 )
1289
{ // We want to go to the end of the month:
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
1293
1208
elseif( strlen( $this->filters['ymdhms'] ) == 4 )
1294
{ // We want to go to the end of the year:
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 ) );
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() ) != '' )
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;
1305
{ // We cannot determine a stop date, save an empty string (to differentiate from NULL)
1223
// We cannot determine a stop date, save an empty string (to differentiate from NULL)
1306
1224
$this->advertised_stop_date = '';
1311
// Reset anti infinite loop:
1229
// Reset anti infinite loop
1312
1230
$this->getting_adv_stop_date = false;
1314
1232
return $this->advertised_stop_date;
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 );
1297
* @param array Associative array of parameters
1374
1299
function date_if_changed( $params = array() )
1376
1301
if( $this->current_Obj->ptyp_ID == 1000 )
1377
{ // This is not applicable to pages
1303
// This is not applicable to pages
1381
// Make sure we are not missing any param:
1307
// Make sure we are not missing any param
1382
1308
$params = array_merge( array(
1385
'empty_day_display' => false,
1386
'empty_day_before' => '<h2>',
1387
'empty_day_after' => '</h2>',
1388
'date_format' => '#',
1311
'empty_day_display' => false,
1312
'empty_day_before' => '<h2>',
1313
'empty_day_after' => '</h2>',
1314
'date_format' => '#',
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 );
1394
1320
if( $current_item_date != $this->last_displayed_date )
1395
{ // Date has changed...
1322
// Date has changed...
1398
1323
if( $params['date_format'] == '#' )
1399
{ // No format specified, use default locale format:
1325
// No format specified, use default locale format
1400
1326
$params['date_format'] = locale_datefmt();
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 ) )
1331
// We want to display ALL dates from the previous to the current
1405
1332
while( $this->last_displayed_date < $current_item_date-86400 )
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 );
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 );
1419
1346
$this->last_displayed_date = $current_item_date;
1441
1368
* 'scroll_list_range' => 5,
1372
* @param array Associative array of parameters
1445
1374
function page_links( $params = array() )
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$',
1455
'prev_text' => '<<',
1456
'next_text' => '>>',
1457
'no_prev_text' => '',
1458
'no_next_text' => '',
1459
'list_prev_text' => '...',
1460
'list_next_text' => '...',
1462
'scroll_list_range' => 5,
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$',
1384
'prev_text' => '<<',
1385
'next_text' => '>>',
1386
'no_prev_text' => '',
1387
'no_next_text' => '',
1388
'list_prev_text' => '...',
1389
'list_next_text' => '...',
1391
'scroll_list_range' => 5,
1465
// Use defaults + overrides:
1394
// Use defaults + overrides
1466
1395
$params = array_merge( $default_params, $params );
1468
1397
if( $this->total_pages <= 1 )
1470
1400
echo $params['block_single'];
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' ) )
1406
// We prefer robots not to follow to pages
1407
$this->nofollow_pagenav = true;
1479
1410
echo $params['block_start'];