Source for file _archives.plugin.php
Documentation is available at _archives.plugin.php
* This file implements the Archives plugin.
* Displays a list of post archives.
* This file is part of the b2evolution project - {@link http://b2evolution.net/}
* @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
* {@internal License choice
* - If you have received this file as part of a package, please find the license.txt file in
* the same folder or the closest folder above for complete license terms.
* - If you have received this file individually (e-g: from http://cvs.sourceforge.net/viewcvs.py/evocms/)
* then you must choose one of the following licenses before using the file:
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
* {@internal Open Source relicensing agreement:
* Daniel HAHLER grants Francois PLANQUE the right to license
* Daniel HAHLER's contributions to this file and the b2evolution project
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
* @author blueyed: Daniel HAHLER.
* @author fplanque: Francois PLANQUE - {@link http://fplanque.net/}
* @author cafelog (group)
* @version $Id: _archives.plugin.php,v 1.27.2.5 2006/12/26 03:18:50 fplanque Exp $
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
require_once $GLOBALS['inc_path'].
'_misc/_results.class.php';
* Variables below MUST be overriden by plugin implementations,
* either in the subclass declaration or in the subclass constructor.
var $name =
'Archives Skin Tag';
$this->short_desc =
T_('This skin tag displays a list of post archives.');
$this->long_desc =
T_('Archives can be grouped monthly, daily, weekly or post by post.');
$this->dbtable =
'T_posts';
$this->dbprefix =
'post_';
$this->dbIDname =
'post_ID';
* @param array Associative array of parameters. Valid keys are:
* - 'block_start' : (Default: '<div class="bSideItem">')
* - 'block_end' : (Default: '</div>')
* - 'title' : (Default: '<h3>'.T_('Archives').'</h3>')
* - 'mode' : 'monthly'|'daily'|'weekly'|'postbypost' (Default: conf.)
* - 'link_type' : 'canonic'|'context' (default: canonic)
* - 'context_isolation' : what params need override when changing date/range (Default: 'm,w,p,title,unit,dstart' )
* - 'form' : true|false (default: false)
* - 'limit' : # of archive entries to display or '' (Default: 12)
* - 'more_link' : more link text (Default: 'More...')
* - 'list_start' : (Default '<ul>')
* - 'list_end' : (Default '</ul>')
* - 'line_start' : (Default '<li>')
* - 'line_end' : (Default '</li>')
* - 'day_date_format' : (Default: conf.)
* @return boolean did we display?
global $Settings, $month;
* @todo get rid of these globals:
// This is what will enclose the block in the skin:
if(!isset
($params['block_start'])) $params['block_start'] =
'<div class="bSideItem">';
if(!isset
($params['block_end'])) $params['block_end'] =
"</div>\n";
if(!isset
($params['title']))
$params['title'] =
'<h3>'.
T_('Archives').
'</h3>';
if(!isset
($params['mode']))
$params['mode'] =
$Settings->get('archive_mode');
if(!isset
($params['link_type'])) $params['link_type'] =
'canonic';
if(!isset
($params['context_isolation'])) $params['context_isolation'] =
'm,w,p,title,unit,dstart';
if(!isset
($params['form']))
// Number of archive entries to display:
if(!isset
($params['limit'])) $params['limit'] =
12;
if(!isset
($params['more_link'])) $params['more_link'] =
T_('More...');
// This is what will enclose the list:
if(!isset
($params['list_start'])) $params['list_start'] =
'<ul>';
if(!isset
($params['list_end'])) $params['list_end'] =
"</ul>\n";
// This is what will separate the archive links:
if(!isset
($params['line_start'])) $params['line_start'] =
'<li>';
if(!isset
($params['line_end'])) $params['line_end'] =
"</li>\n";
// Daily archive date format?
if( (!isset
($params['day_date_format'])) ||
($params['day_date_format'] ==
'') )
$params['day_date_format'] =
$dateformat;
$ArchiveList =
& new ArchiveList( $params['mode'], $params['limit'], ($params['link_type'] ==
'context'),
$this->dbtable, $this->dbprefix, $this->dbIDname );
echo
$params['block_start'];
echo
$params['list_start'];
while( $ArchiveList->get_item( $arc_year, $arc_month, $arc_dayofmonth, $arc_w, $arc_count, $post_ID, $post_title) )
echo
$params['line_start'];
switch( $params['mode'] )
// --------------------------------- MONTHLY ARCHIVES -------------------------------------
$arc_m =
$arc_year.
zeroise($arc_month,2);
{ // We want a radio button:
echo
'<input type="radio" name="m" value="'.
$arc_m.
'" class="checkbox"';
if( $m ==
$arc_m ) echo
' checked="checked"' ;
if( $params['link_type'] ==
'context' )
{ // We want to preserve current browsing context:
{ // We want to link to the absolute canonical URL for this archive:
echo
T_($month[zeroise($arc_month,2)]),' ',$arc_year;
echo
'</a> <span class="dimmed">('.
$arc_count.
')</span>';
// --------------------------------- DAILY ARCHIVES ---------------------------------------
{ // We want a radio button:
echo
'<input type="radio" name="m" value="'.
$arc_m.
'" class="checkbox"';
if( $m ==
$arc_m ) echo
' checked="checked"' ;
if( $params['link_type'] ==
'context' )
{ // We want to preserve current browsing context:
{ // We want to link to the absolute canonical URL for this archive:
echo
mysql2date($params['day_date_format'], $arc_year.
'-'.
zeroise($arc_month,2).
'-'.
zeroise($arc_dayofmonth,2).
' 00:00:00');
echo
'</a> <span class="dimmed">('.
$arc_count.
')</span>';
// --------------------------------- WEEKLY ARCHIVES --------------------------------------
if( $params['link_type'] ==
'context' )
{ // We want to preserve current browsing context:
echo
regenerate_url( $params['context_isolation'], 'm='.
$arc_year.
'&w='.
$arc_w );
{ // We want to link to the absolute canonical URL for this archive:
echo
$arc_year.
', '.
T_('week').
' '.
$arc_w;
echo
'</a> <span class="dimmed">('.
$arc_count.
')</span>';
// -------------------------------- POST BY POST ARCHIVES ---------------------------------
if( $params['link_type'] ==
'context' )
{ // We want to preserve current browsing context:
{ // We want to link to the absolute canonical URL for this archive:
echo
$params['line_end'];
if( !empty($params['more_link']) )
echo
$params['line_start'];
$Blog->disp( 'arcdirurl', 'raw' );
echo
$params['line_end'];
echo
$params['list_end'];
echo
$params['block_end'];
* Note: Weekly archives use MySQL's week numbering and MySQL default if applicable.
* In MySQL < 4.0.14, WEEK() always uses mode 0: Week starts on Sunday;
* Value range is 0 to 53; week 1 is the first week that starts in this year.
* @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
* @todo categories combined with 'ALL' are not supported (will output too many archives,
* some of which will resolve to no results). We need subqueries to support this efficiently.
$archive_mode =
'monthly',
$preserve_context =
false,
global $blog, $cat, $catsel;
global $author, $assgn, $status;
global $timestamp_min, $timestamp_max;
global $s, $sentence, $exact;
$this->dbtable =
$dbtable;
$this->dbprefix =
$dbprefix;
$this->dbIDname =
$dbIDname;
* WE ARE GOING TO CONSTRUCT THE WHERE CLOSE...
$this->ItemQuery =
& new ItemQuery( $this->dbtable, $this->dbprefix, $this->dbIDname ); // TEMPORARY OBJ
// - - Select a specific Item:
// $this->ItemQuery->where_ID( $p, $title );
{ // We want to preserve the current context:
// * - - Restrict to selected blog/categories:
$this->ItemQuery->where_chapter( $blog, $cat, $catsel );
// * Restrict to the statuses we want to show:
$this->ItemQuery->where_visibility( $show_statuses );
// Restrict to selected authors:
$this->ItemQuery->where_author( $author );
// Restrict to selected assignees:
$this->ItemQuery->where_assignees( $assgn );
// Restrict to selected satuses:
$this->ItemQuery->where_statuses( $status );
// - - - + * * timestamp restrictions:
$this->ItemQuery->where_datestart( '', '', '', '', $timestamp_min, $timestamp_max );
$this->ItemQuery->where_keywords( $s, $sentence, $exact );
{ // We want to preserve only the minimal context:
// * - - Restrict to selected blog/categories:
$this->ItemQuery->where_chapter( $blog, '', array() );
// * Restrict to the statuses we want to show:
$this->ItemQuery->where_visibility( $show_statuses );
// - - - + * * timestamp restrictions:
$this->ItemQuery->where_datestart( '', '', '', '', $timestamp_min, $timestamp_max );
$this->from =
$this->ItemQuery->get_from();
$this->where =
$this->ItemQuery->get_where();
$this->group_by =
$this->ItemQuery->get_group_by();
// ------------------------------ MONTHLY ARCHIVES ------------------------------------
$sql =
'SELECT YEAR('.
$this->dbprefix.
'datestart) AS year, MONTH('.
$this->dbprefix.
'datestart) AS month,
COUNT(DISTINCT postcat_post_ID) AS count '
ORDER BY year DESC, month DESC';
// ------------------------------- DAILY ARCHIVES -------------------------------------
$sql =
'SELECT YEAR('.
$this->dbprefix.
'datestart) AS year, MONTH('.
$this->dbprefix.
'datestart) AS month,
DAYOFMONTH('.
$this->dbprefix.
'datestart) AS day,
COUNT(DISTINCT postcat_post_ID) AS count '
GROUP BY year, month, day
ORDER BY year DESC, month DESC, day DESC';
// ------------------------------- WEEKLY ARCHIVES -------------------------------------
$sql =
'SELECT YEAR('.
$this->dbprefix.
'datestart) AS year, '.
COUNT(DISTINCT postcat_post_ID) AS count '
ORDER BY year DESC, week DESC';
// ----------------------------- POSY BY POST ARCHIVES --------------------------------
$sql =
'SELECT DISTINCT '.
$this->dbIDname.
', '.
$this->dbprefix.
'datestart, '.
$this->dbprefix.
'title '
ORDER BY '.
$this->dbprefix.
'datestart DESC';
// dh> Temp fix for MySQL bug - apparently in/around 4.1.21/5.0.24.
// See http://forums.b2evolution.net/viewtopic.php?p=42529#42529
$sql_version =
$DB->get_var('SELECT VERSION()');
$sql =
'SELECT SQL_CALC_FOUND_ROWS '.
substr( $sql, 7 ); // "SQL_CALC_FOUND_ROWS" available since MySQL 4
parent::Results( $sql, 'archivelist_', '', $limit );
* Count the number of rows of the SQL result
* These queries are complex enough for us not to have to rewrite them:
// ------------------------------ MONTHLY ARCHIVES ------------------------------------
$sql_count =
'SELECT COUNT( DISTINCT YEAR('.
$this->dbprefix.
'datestart), MONTH('.
$this->dbprefix.
'datestart) ) '
// ------------------------------- DAILY ARCHIVES -------------------------------------
$sql_count =
'SELECT COUNT( DISTINCT YEAR('.
$this->dbprefix.
'datestart), MONTH('.
$this->dbprefix.
'datestart),
DAYOFMONTH('.
$this->dbprefix.
'datestart) ) '
// ------------------------------- WEEKLY ARCHIVES -------------------------------------
$sql_count =
'SELECT COUNT( DISTINCT YEAR('.
$this->dbprefix.
'datestart), '
// ----------------------------- POSY BY POST ARCHIVES --------------------------------
$sql_count =
'SELECT COUNT( DISTINCT '.
$this->dbIDname.
' ) '
$this->total_rows =
$this->DB->get_var( $sql_count ); //count total rows
// echo 'total rows='.$this->total_rows;
// Make sure query has executed at least once:
* Getting next item in archive list
* WARNING: these are *NOT* Item objects!
function get_item( & $arc_year, & $arc_month, & $arc_dayofmonth, & $arc_w, & $arc_count, & $post_ID, & $post_title )
// echo 'getting next item<br />';
if( $this->current_idx >=
$this->result_num_rows )
$arc_row =
$this->rows[ $this->current_idx++
];
$arc_year =
$arc_row->year;
$arc_month =
$arc_row->month;
$arc_count =
$arc_row->count;
$arc_year =
$arc_row->year;
$arc_month =
$arc_row->month;
$arc_dayofmonth =
$arc_row->day;
$arc_count =
$arc_row->count;
$arc_year =
$arc_row->year;
$arc_count =
$arc_row->count;
$post_ID =
$arc_row->post_ID;
$post_title =
$arc_row->{$this->dbprefix.
'title'};
* $Log: _archives.plugin.php,v $
* Revision 1.27.2.5 2006/12/26 03:18:50 fplanque
* assigned a few significant plugin groups
* Revision 1.27.2.4 2006/11/04 19:55:11 fplanque
* Reinjected old Log blocks. Removing them from CVS was a bad idea -- especially since Daniel has decided branch 1.9 was his HEAD...
* Revision 1.27 2006/07/10 20:19:30 blueyed
* Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.
* Revision 1.26 2006/07/08 12:33:50 blueyed
* Fixed regression with Results' class adding an additional ORDER column to ItemList2's query
* Revision 1.25 2006/07/07 21:26:49 blueyed
* Revision 1.24 2006/06/20 00:53:07 blueyed
* require results class (through global)!
* Revision 1.23 2006/06/20 00:38:42 blueyed
* Revision 1.22 2006/06/16 21:30:57 fplanque
* Started clean numbering of plugin versions (feel free do add dots...)
* Revision 1.21 2006/05/30 19:39:55 fplanque
* Revision 1.20 2006/04/19 20:14:03 fplanque
* do not restrict to :// (does not catch subdomains, not even www.)
* Revision 1.19 2006/03/12 23:09:27 fplanque
* Revision 1.18 2006/02/05 19:04:49 blueyed
* Revision 1.17 2006/02/05 14:07:18 blueyed
* Fixed 'postbypost' archive mode.
* Revision 1.16 2006/01/04 20:34:51 fplanque
* allow filtering on extra statuses
* Revision 1.15 2005/12/22 23:13:40 blueyed
* Plugins' API changed and handling optimized
* Revision 1.14 2005/12/12 19:22:04 fplanque
* big merge; lots of small mods; hope I didn't make to many mistakes :]
* Revision 1.13 2005/11/01 17:47:37 yabs
* minor corrections to postbypost
* Revision 1.12 2005/10/03 18:10:08 fplanque
* Revision 1.11 2005/09/14 19:23:45 fplanque
* Revision 1.10 2005/09/06 19:38:29 fplanque
* Revision 1.9 2005/09/06 17:14:12 fplanque
* stop processing early if referer spam has been detected
* Revision 1.8 2005/09/01 17:11:46 fplanque
* Merged in the contents of _archivelist.class.php; history below:
* Revision 1.11 2005/06/10 18:25:43 fplanque
* Revision 1.10 2005/05/24 15:26:52 fplanque
* Revision 1.9 2005/03/08 20:32:07 fplanque
* small fixes; slightly enhanced WEEK() handling
* Revision 1.8 2005/03/07 17:36:10 fplanque
* Revision 1.7 2005/02/28 09:06:32 blueyed
* removed constants for DB config (allows to override it from _config_TEST.php), introduced EVO_CONFIG_LOADED
* Revision 1.6 2005/01/03 15:17:52 fplanque
* Revision 1.5 2004/12/27 18:37:58 fplanque
* changed class inheritence
* Changed parent to Results!!
* Revision 1.4 2004/12/13 21:29:58 fplanque
* Revision 1.3 2004/11/09 00:25:11 blueyed
* minor translation changes (+MySQL spelling :/)
* Revision 1.2 2004/10/14 18:31:24 blueyed
* Revision 1.1 2004/10/13 22:46:32 fplanque
* Revision 1.19 2004/10/11 19:02:04 fplanque
* Edited code documentation.