Source for file _calendar.plugin.php
Documentation is available at _calendar.plugin.php
* This file implements the Calendar plugin.
* 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://evocms.cvs.sourceforge.net/)
* 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 hansreinders: Hans REINDERS
* @version $Id: _calendar.plugin.php,v 1.26.2.7 2007/03/29 10:34:48 fplanque Exp $
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
* Variables below MUST be overriden by plugin implementations,
* either in the subclass declaration or in the subclass constructor.
var $name =
'Calendar Skin Tag';
$this->short_desc =
T_('This skin tag displays a navigable calendar.');
$this->long_desc =
T_('Days containing posts are highlighted.');
$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_('Calendar').'</h3>')
* - 'linkposttodaycellstart'
* - 'navigation' : Where do we want to have the navigation arrows? (Default: 'tfoot')
* - 'browseyears' : boolean Do we want arrows to move one year at a time?
* - 'min_timestamp' : Minimum unix timestamp the user can browse too or 'query' (Default: 2000-01-01)
* - 'max_timestamp' : Maximum unix timestamp the user can browse too or 'query' (Default: now + 1 year )
* - 'postcount_month_cell'
* - 'postcount_month_cell_one'
* - 'postcount_month_atitle'
* - 'postcount_month_atitle_one'
* - 'postcount_year_cell'
* - 'postcount_year_cell_one'
* - 'postcount_year_atitle'
* - 'postcount_year_atitle_one'
* - 'link_type' : 'canonic'|'context' (default: canonic)
* @return boolean did we display?
global $Settings, $month;
global $blog, $cat, $catsel;
global $author, $assgn, $status;
global $m, $w, $dstart, $timestamp_min, $timestamp_max;
global $s, $sentence, $exact;
// 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_('Calendar').
'</h3>';
$Calendar =
& new Calendar( $m, $params );
// TODO: automate with a table inside of Calendatr object. Table should also contain descriptions and default values to display in help screen.
// Note: minbrowse and maxbrowe already work this way.
if( isset
($params['displaycaption']) ) $Calendar->set( 'displaycaption', $params['displaycaption'] );
if( isset
($params['monthformat']) ) $Calendar->set( 'monthformat', $params['monthformat'] );
if( isset
($params['linktomontharchive']) ) $Calendar->set( 'linktomontharchive', $params['linktomontharchive'] );
if( isset
($params['tablestart']) ) $Calendar->set( 'tablestart', $params['tablestart'] );
if( isset
($params['tableend']) ) $Calendar->set( 'tableend', $params['tableend'] );
if( isset
($params['monthstart']) ) $Calendar->set( 'monthstart', $params['monthstart'] );
if( isset
($params['monthend']) ) $Calendar->set( 'monthend', $params['monthend'] );
if( isset
($params['rowstart']) ) $Calendar->set( 'rowstart', $params['rowstart'] );
if( isset
($params['rowend']) ) $Calendar->set( 'rowend', $params['rowend'] );
if( isset
($params['headerdisplay']) ) $Calendar->set( 'headerdisplay', $params['headerdisplay'] );
if( isset
($params['headerrowstart']) ) $Calendar->set( 'headerrowstart', $params['headerrowstart'] );
if( isset
($params['headerrowend']) ) $Calendar->set( 'headerrowend', $params['headerrowend'] );
if( isset
($params['headercellstart']) ) $Calendar->set( 'headercellstart', $params['headercellstart'] );
if( isset
($params['headercellend']) ) $Calendar->set( 'headercellend', $params['headercellend'] );
if( isset
($params['cellstart']) ) $Calendar->set( 'cellstart', $params['cellstart'] );
if( isset
($params['cellend']) ) $Calendar->set( 'cellend', $params['cellend'] );
if( isset
($params['emptycellstart']) ) $Calendar->set( 'emptycellstart', $params['emptycellstart'] );
if( isset
($params['emptycellend']) ) $Calendar->set( 'emptycellend', $params['emptycellend'] );
if( isset
($params['emptycellcontent']) ) $Calendar->set( 'emptycellcontent', $params['emptycellcontent'] );
if( isset
($params['linkpostcellstart']) ) $Calendar->set( 'linkpostcellstart', $params['linkpostcellstart'] );
if( isset
($params['linkposttodaycellstart']) ) $Calendar->set( 'linkposttodaycellstart', $params['linkposttodaycellstart'] );
if( isset
($params['todaycellstart']) ) $Calendar->set( 'todaycellstart', $params['todaycellstart'] );
if( isset
($params['todaycellstartpost']) ) $Calendar->set( 'todaycellstartpost', $params['todaycellstartpost'] );
if( isset
($params['navigation']) ) $Calendar->set( 'navigation', $params['navigation'] );
if( isset
($params['browseyears']) ) $Calendar->set( 'browseyears', $params['browseyears'] );
if( isset
($params['postcount_month_cell']) ) $Calendar->set( 'postcount_month_cell', $params['postcount_month_cell'] );
if( isset
($params['postcount_month_cell_one']) ) $Calendar->set( 'postcount_month_cell_one', $params['postcount_month_cell_one'] );
if( isset
($params['postcount_month_atitle']) ) $Calendar->set( 'postcount_month_atitle', $params['postcount_month_atitle'] );
if( isset
($params['postcount_month_atitle_one']) ) $Calendar->set( 'postcount_month_atitle_one', $params['postcount_month_atitle_one'] );
if( isset
($params['postcount_year_cell']) ) $Calendar->set( 'postcount_year_cell', $params['postcount_year_cell'] );
if( isset
($params['postcount_year_cell_one']) ) $Calendar->set( 'postcount_year_cell_one', $params['postcount_year_cell_one'] );
if( isset
($params['postcount_year_atitle']) ) $Calendar->set( 'postcount_year_atitle', $params['postcount_year_atitle'] );
if( isset
($params['postcount_year_atitle_one']) ) $Calendar->set( 'postcount_year_atitle_one', $params['postcount_year_atitle_one'] );
if( isset
($params['link_type']) ) $Calendar->set( 'link_type', $params['link_type'] );
if( isset
($params['context_isolation']) ) $Calendar->set( 'context_isolation', $params['context_isolation'] );
echo
$params['block_start'];
// CONSTRUCT THE WHERE CLAUSE:
// - - Select a specific Item:
// $this->ItemQuery->where_ID( $p, $title );
if( $Calendar->link_type ==
'context' )
{ // We want to preserve the current context:
// * - - Restrict to selected blog/categories:
$Calendar->ItemQuery->where_chapter( $blog, $cat, $catsel );
// * Restrict to the statuses we want to show:
$Calendar->ItemQuery->where_visibility( $show_statuses );
// Restrict to selected authors:
$Calendar->ItemQuery->where_author( $author );
// Restrict to selected assignees:
$Calendar->ItemQuery->where_assignees( $assgn );
// Restrict to selected satuses:
$Calendar->ItemQuery->where_statuses( $status );
// - - - + * * if a month is specified in the querystring, load that month:
$Calendar->ItemQuery->where_datestart( /* NO m */'', /* NO w */'', $dstart, '', $timestamp_min, $timestamp_max );
$Calendar->ItemQuery->where_keywords( $s, $sentence, $exact );
{ // We want to preserve only the minimal context:
// * - - Restrict to selected blog/categories:
$Calendar->ItemQuery->where_chapter( $blog, '', array() );
// * Restrict to the statuses we want to show:
$Calendar->ItemQuery->where_visibility( $show_statuses );
// - - - + * * if a month is specified in the querystring, load that month:
$Calendar->ItemQuery->where_datestart( /* NO m */'', /* NO w */'', '', '', $timestamp_min, $timestamp_max );
echo
$params['block_end'];
* The month to display or empty in mode 'year' with no selected month.
* Number of rows in result set
* Where to do the navigation
* Do we want to browse years in the caption? True by default for mode == year,
* false for mode == month (gets set in constructor).
* Is today in the displayed frame?
* @param string Month ('YYYYMM'), year ('YYYY'), current ('')
* @param array Associative array of parameters. Valid keys are:
* - 'min_timestamp' : Minimum unix timestamp the user can browse too or 'query' (Default: 2000-01-01)
* - 'max_timestamp' : Maximum unix timestamp the user can browse too or 'query' (Default: now + 1 year )
function Calendar( $m =
'', $params =
array() )
global $Settings, $localtimenow;
$this->dbtable =
'T_posts';
$this->dbprefix =
'post_';
$this->dbIDname =
'post_ID';
// OBJECT THAT WILL BE USED TO CONSTRUCT THE WHERE CLAUSE:
$this->ItemQuery =
new ItemQuery( $this->dbtable, $this->dbprefix, $this->dbIDname ); // COPY!!
$localyearnow =
date( 'Y', $localtimenow );
$localmonthnow =
date( 'm', $localtimenow );
// Find out which month to display:
{ // Current month (monthly)
$this->year =
$localyearnow;
$this->month =
$localmonthnow;
{ // We have requested a specific date
if( $this->year ==
$localyearnow )
{ // we display current year, month gets current
$this->month =
$localmonthnow;
{ // highlight no month, when not current year
&&
( empty($this->month) ||
$this->month ==
$localmonthnow ) );
$this->displaycaption =
1; // set this to 0 if you don't want to display the month name
$this->tablestart =
'<table class="bCalendarTable" cellspacing="0" summary="Monthly calendar with links to each day\'s posts">'.
"\n";
$this->monthstart =
'<caption class="bCalendarCaption">';
$this->rowstart =
'<tr class="bCalendarRow">' .
"\n";
$this->headerdisplay =
'D'; // D => 'Fri'; e => 'F', l (lowercase l) => 'Friday'
// These codes are twisted because they're the same as for date formats.
// set this to 0 or '' if you don't want to display the "Mon Tue Wed..." header
$this->headercellstart =
'<th class="bCalendarHeaderCell" abbr="[abbr]" scope="col" title="[abbr]">'; // please leave [abbr] there !
$this->cellstart =
'<td class="bCalendarCell">';
$this->linkpostcellstart =
'<td class="bCalendarLinkPost">';
$this->linkposttodaycellstart =
'<td class="bCalendarLinkPostToday">';
$this->todaycellstart =
'<td id="bCalendarToday">';
$this->todaycellstartpost =
'<td id="bCalendarToday" class="bCalendarLinkPost">';
// Where do we want to have the navigation arrows?
// Do we want to check if there are posts behind the navigation arrows?
// WARNING: this will slow things down...
// TODO: $this->check_navigation = false;
// Do we want arrows to move one year at a time?
* Display number of posts with days/months
* - set to '' (empty) to disable
* - %d gets replaced with the number of posts on that day/month
$this->postcount_month_cell =
''; // in table cell (behind day)
$this->postcount_month_cell_one =
''; // -- " -- [for single post]
$this->postcount_month_atitle =
T_('%d posts'); // in archive links title tag
$this->postcount_month_atitle_one =
T_('1 post'); // -- " -- [for single post]
$this->postcount_year_cell =
'';
$this->postcount_year_cell_one =
'';
$this->postcount_year_atitle =
T_('%d posts'); // in archive links title tag
$this->postcount_year_atitle_one =
T_('1 post'); // in archive links title tag
if( empty( $this->params['min_timestamp'] ) )
$this->params['min_timestamp'] =
mktime( 0, 0, 0, 1, 1, 2000 );
if( empty( $this->params['max_timestamp'] ) )
$this->params['max_timestamp'] =
mktime( 23, 59, 59, date( 'm', $localtimenow ), date( 'd', $localtimenow ), date( 'Y', $localtimenow )+
1 );
function set( $var, $value )
* @todo If a specific day (mode == month) or month (mode == year) is selected, apply another class (default to some border)
global $weekday, $weekday_abbrev, $weekday_letter, $month, $month_abbrev;
if( $this->mode ==
'month' )
// fplanque>> note: I am removing the searchframe thing because 1) I don't think it's of any use
// and 2) it's brutally inefficient! If someone needs this it should be implemented with A SINGLE
// QUERY which gets the last available post (BTW, I think there is already a function for that somwhere)
$arc_sql =
'SELECT COUNT(DISTINCT '.
$this->dbIDname.
') AS item_count,
YEAR('.
$this->dbprefix.
'datestart), MONTH('.
$this->dbprefix.
'datestart),
DAYOFMONTH('.
$this->dbprefix.
'datestart) AS myday
FROM ('.
$this->dbtable.
' INNER JOIN T_postcats ON '.
$this->dbIDname.
' = postcat_post_ID)
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
WHERE YEAR('.
$this->dbprefix.
'datestart) = "'.
$this->year.
'"
AND MONTH('.
$this->dbprefix.
'datestart) = "'.
$this->month.
'"
'.
$this->ItemQuery->get_where( ' AND ' ).
'
GROUP BY myday '.
$this->ItemQuery->get_group_by( ', ' ).
'
ORDER BY '.
$this->dbprefix.
'datestart DESC';
// echo $this->ItemQuery->where;
$arc_result =
$DB->get_results( $arc_sql, ARRAY_A );
foreach( $arc_result as $arc_row )
if( !isset
( $daysinmonthwithposts[ $arc_row['myday'] ] ) )
$daysinmonthwithposts[ $arc_row['myday'] ] =
0;
// The '+' situation actually only happens when we have a complex GROUP BY above
// (multiple categories wcombined with "ALL")
$daysinmonthwithposts[ $arc_row['myday'] ] +=
$arc_row['item_count'];
// echo 'days in month=', $daysinmonth;
// caution: offset bug inside (??)
// echo date( locale_datefmt(), $datestartofmonth );
$calendarfirst =
$calendarblah['start'];
$dateendofmonth =
mktime(0, 0, 0, $this->month, $daysinmonth, $this->year);
// echo date( locale_datefmt(), $dateendofmonth );
$calendarlast =
$calendarblah['end'];
// here the offset bug is corrected
#pre_dump( 'with offset bug', date('Y-m-d', $calendarfirst) );
$calendarfirst =
$calendarfirst -
604800 /* 1 week */;
#pre_dump( 'without offset bug', date('Y-m-d', $calendarfirst) );
// Find months with posts
$arc_sql =
'SELECT COUNT(DISTINCT '.
$this->dbIDname.
') AS item_count, MONTH('.
$this->dbprefix.
'datestart) AS mymonth
FROM ('.
$this->dbtable.
' INNER JOIN T_postcats ON '.
$this->dbIDname.
' = postcat_post_ID)
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
WHERE YEAR('.
$this->dbprefix.
'datestart) = "'.
$this->year.
'" '
.
$this->ItemQuery->get_where( ' AND ' ).
'
GROUP BY mymonth '.
$this->ItemQuery->get_group_by( ', ' );
$arc_result =
$DB->get_results( $arc_sql, ARRAY_A );
{ // OK we have a month with posts!
foreach( $arc_result as $arc_row )
$monthswithposts[ $arc_row['mymonth'] ] =
$arc_row['item_count'];
// ** display everything **
if( $this->mode ==
'month' )
{ // chosen month with link to archives
echo
'<a href="'.
$this->archive_link( $this->year, $this->month, '', '' ).
'" title="'.
T_('go to month\'s archive').
'">';
{ // close link to month archive
echo
T_($weekday_letter[($i %
7)]);
// l (lowercase l) => 'Friday'
echo
T_($weekday[($i %
7)]);
default:
// Backward compatibility: any non emty value will display this
echo
T_($weekday_abbrev[($i %
7)]);
{ // We want to display navigation in the table footer:
echo
'<td colspan="'.
( ( $this->mode ==
'month' ?
2 :
1 ) + (int)
$this->today_is_visible ).
'" id="prev">';
if( $this->mode ==
'month' )
echo
'<td class="pad"> </td>'.
"\n";
echo
'<td colspan="'.
( $this->mode ==
'month' ?
'3' :
'2' ).
'" class="center"><a href="'
echo
'<td colspan="'.
( ( $this->mode ==
'month' ?
2 :
1 ) + (int)
$this->today_is_visible ).
'" id="next">';
if( $this->mode ==
'year' )
for ($i =
1; $i <
13; $i =
$i +
1)
if( isset
($monthswithposts[ $i ]) )
echo
$this->todaycellstartpost;
echo
$this->linkpostcellstart;
if( $monthswithposts[ $i ] >
1 &&
!empty($this->postcount_year_atitle) )
echo
' title="'.
sprintf($this->postcount_year_atitle, $monthswithposts[ $i ]).
'"';
elseif( !empty($this->postcount_year_atitle_one) )
{ // display postcount for one post
echo
' title="'.
sprintf($this->postcount_year_atitle_one, 1).
'"';
elseif( $this->month ==
$i )
echo
$this->todaycellstart;
if( isset
($monthswithposts[ $i ]) )
{ // close anchor and show how many posts we have for this month
if( $monthswithposts[ $i ] >
1 &&
!empty($this->postcount_year_cell) )
printf($this->postcount_year_cell, $monthswithposts[ $i ]);
elseif( !empty($this->postcount_year_cell_one) )
{ // display postcount for one post
printf($this->postcount_year_cell_one, 1);
{ // Display current month:
$dom_displayed =
0; // days of month displayed
for( $i =
$calendarfirst; $i <=
$calendarlast; $i =
$i +
86400 )
{ // loop day by day (86400 seconds = 24 hours; but not on days where daylight saving changes!)
{ // We need to start a new row:
if( $dom_displayed >=
$daysinmonth )
{ // Last day already displayed!
// correct daylight saving ("last day"+86400 would lead to "last day at 23:00")
// fp> TODO: use mkdate()
while( date('j', $i) ==
$last_day )
$last_day =
date('j', $i);
{ // This day is in this month
$calendartoday =
(date('Ymd',$i) ==
date('Ymd', (time() +
$Settings->get('time_difference'))));
if( isset
($daysinmonthwithposts[ date('j', $i) ]) )
echo
$this->todaycellstartpost;
echo
$this->linkpostcellstart;
if( $daysinmonthwithposts[ date('j', $i) ] >
1 &&
!empty($this->postcount_month_atitle) )
echo
' title="'.
sprintf($this->postcount_month_atitle, $daysinmonthwithposts[ date('j', $i) ]).
'"';
elseif( !empty($this->postcount_month_atitle_one) )
{ // display postcount for one post
echo
' title="'.
sprintf($this->postcount_month_atitle_one, 1).
'"';
echo
$this->todaycellstart;
if( isset
($daysinmonthwithposts[ date('j', $i) ]) )
if( $daysinmonthwithposts[ date('j', $i) ] >
1 &&
!empty($this->postcount_month_cell) )
printf($this->postcount_month_cell, $daysinmonthwithposts[ date('j', $i) ]);
elseif( !empty($this->postcount_month_cell_one) )
{ // display postcount for one post
printf($this->postcount_month_cell_one, 1);
* Create a link to archive, using either URL params or extra path info.
* Can make contextual links.
function archive_link( $year, $month, $day =
'', $week =
'' )
{ // We want to preserve context:
$url_params =
'm='.
$year;
elseif( $week !==
'' ) // Note: week # can be 0 !
$url_params .=
'&w='.
$week;
{ // We want a canonic link:
* Get links to navigate between month / year.
* Unless min/max_timestamp='query' has been specified, this will not do any (time consuming!) queries to check where the posts are.
* @param string 'prev' / 'next'
global $DB, $localtimenow;
//pre_dump( 'get_nav_links', $direction );
// WE NEED SPECIAL QUERY PARAMS WHEN MOVING THOUGH MONTHS ( NO dstart especially! )
$nav_ItemQuery =
& new ItemQuery( $this->dbtable, $this->dbprefix, $this->dbIDname ); // TEMP object
// Restrict to selected blog/categories:
$nav_ItemQuery->where_chapter( $this->ItemQuery->blog, $this->ItemQuery->cat, $this->ItemQuery->catsel );
// Restrict to the statuses we want to show:
$nav_ItemQuery->where_visibility( $this->ItemQuery->show_statuses );
// Restrict to selected authors:
$nav_ItemQuery->where_author( $this->ItemQuery->author );
// if a month is specified in the querystring, load that month:
$nav_ItemQuery->where_datestart( /* NO m */'', /* NO w */'', /* NO dstart */'', '', $this->ItemQuery->timestamp_min, $this->ItemQuery->timestamp_max );
$nav_ItemQuery->where_keywords( $this->ItemQuery->keywords, $this->ItemQuery->phrase, $this->ItemQuery->exact );
//pre_dump( $this->params['min_timestamp'] );
if( empty($this->month) )
{ // if $this->month is empty, we're in mode "year" with no selected month
$use_range_month =
$this->month;
$use_range_day =
1; // Note: cannot use current day since all months do not have same number of days
{ // We want arrows to move one year at a time
if( $this->params['min_timestamp'] ==
'query' )
{ // Let's query to find the correct year:
'SELECT YEAR('.
$this->dbprefix.
'datestart) AS year,
MONTH('.
$this->dbprefix.
'datestart) AS month
FROM ('.
$this->dbtable.
' INNER JOIN T_postcats ON '.
$this->dbIDname.
' = postcat_post_ID)
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
WHERE YEAR('.
$this->dbprefix.
'datestart) < '.
$this->year.
'
'.
$nav_ItemQuery->get_where( ' AND ' )
.
$nav_ItemQuery->get_group_by( ' GROUP BY ' ).
'
ORDER BY YEAR('.
$this->dbprefix.
'datestart) DESC, ABS( '.
$use_range_month.
' - MONTH('.
$this->dbprefix.
'datestart) ) ASC
LIMIT 1', OBJECT, 0, 'Calendar: find prev year with posts' )
$prev_year_year =
$row->year;
$prev_year_month =
$row->month;
{ // Let's see if the previous year is in the desired navigation range:
$prev_year_ts =
mktime( 0, 0, 0, $use_range_month, $use_range_day, $this->year-
1 );
if( $prev_year_ts >=
$this->params['min_timestamp'] )
$prev_year_year =
date( 'Y', $prev_year_ts );
$prev_year_month =
date( 'm', $prev_year_ts );
if( !empty($prev_year_year) )
{ // We have a link to display:
$r[] =
'<a href="'.
$this->archive_link( $prev_year_year, ($this->mode ==
'month') ?
$prev_year_month :
'', '', '' )
?
/* Calendar link title to a month in a previous year */ T_('Previous year (%04d-%02d)')
:
/* Calendar link title to a previous year */ T_('Previous year (%04d)') ),
$prev_year_year, $prev_year_month )
if( $this->mode ==
'month' )
{ // We are browsing months, we'll display arrows to move one month at a time:
if( $this->params['min_timestamp'] ==
'query' )
{ // Let's query to find the correct month:
'SELECT MONTH('.
$this->dbprefix.
'datestart) AS month,
YEAR('.
$this->dbprefix.
'datestart) AS year
FROM ('.
$this->dbtable.
' INNER JOIN T_postcats ON '.
$this->dbIDname.
' = postcat_post_ID)
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
YEAR('.
$this->dbprefix.
'datestart) < '.
($this->year).
'
OR ( YEAR('.
$this->dbprefix.
'datestart) = '.
($this->year).
'
AND MONTH('.
$this->dbprefix.
'datestart) < '.
($this->month).
'
'.
$nav_ItemQuery->get_where( ' AND ' )
.
$nav_ItemQuery->get_group_by( ' GROUP BY ' ).
'
ORDER BY YEAR('.
$this->dbprefix.
'datestart) DESC, MONTH('.
$this->dbprefix.
'datestart) DESC
'Calendar: Find prev month with posts' )
$prev_month_year =
$row->year;
$prev_month_month =
$row->month;
{ // Let's see if the previous month is in the desired navigation range:
$prev_month_ts =
mktime( 0, 0, 0, $this->month-
1, 1, $this->year ); // Note: cannot use current day since all months do not have same number of days
if( $prev_month_ts >=
$this->params['min_timestamp'] )
$prev_month_year =
date( 'Y', $prev_month_ts );
$prev_month_month =
date( 'm', $prev_month_ts );
if( !empty($prev_month_year) )
{ // We have a link to display:
.
$this->archive_link( $prev_month_year, $prev_month_month, '', '' )
.
'" title="'.
sprintf( T_('Previous month (%04d-%02d)'), $prev_month_year, $prev_month_month ).
'"><</a>';
//pre_dump( $this->params['max_timestamp'] );
if( $this->mode ==
'month' )
{ // We are browsing months, we'll display arrows to move one month at a time:
if( $this->params['max_timestamp'] ==
'query' )
{ // Let's query to find the correct month:
'SELECT MONTH('.
$this->dbprefix.
'datestart) AS month,
YEAR('.
$this->dbprefix.
'datestart) AS year
FROM ('.
$this->dbtable.
' INNER JOIN T_postcats ON '.
$this->dbIDname.
' = postcat_post_ID)
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
YEAR('.
$this->dbprefix.
'datestart) > '.
($this->year).
'
OR ( YEAR('.
$this->dbprefix.
'datestart) = '.
($this->year).
'
AND MONTH('.
$this->dbprefix.
'datestart) > '.
($this->month).
'
'.
$nav_ItemQuery->get_where( ' AND ' )
.
$nav_ItemQuery->get_group_by( ' GROUP BY ' ).
'
ORDER BY YEAR('.
$this->dbprefix.
'datestart), MONTH('.
$this->dbprefix.
'datestart) ASC
'Calendar: Find next month with posts' )
$next_month_year =
$row->year;
$next_month_month =
$row->month;
{ // Let's see if the next month is in the desired navigation range:
$next_month_ts =
mktime( 0, 0, 0, $this->month+
1, 1, $this->year ); // Note: cannot use current day since all months do not have same number of days
if( $next_month_ts <=
$this->params['max_timestamp'] )
$next_month_year =
date( 'Y', $next_month_ts );
$next_month_month =
date( 'm', $next_month_ts );
if( !empty($next_month_year) )
{ // We have a link to display:
.
$this->archive_link( $next_month_year, $next_month_month, '', '' )
.
'" title="'.
sprintf( T_('Next month (%04d-%02d)'), $next_month_year, $next_month_month ).
'">></a>';
if( empty($this->month) )
{ // if $this->month is empty, we're in mode "year" with no selected month
$use_range_month =
$this->month;
$use_range_day =
1; // Note: cannot use current day since all months do not have same number of days
{ // We want arrows to move one year at a time
if( $this->params['max_timestamp'] ==
'query' )
{ // Let's query to find the correct year:
'SELECT YEAR('.
$this->dbprefix.
'datestart) AS year,
MONTH('.
$this->dbprefix.
'datestart) AS month
FROM ('.
$this->dbtable.
' INNER JOIN T_postcats ON '.
$this->dbIDname.
' = postcat_post_ID)
INNER JOIN T_categories ON postcat_cat_ID = cat_ID
WHERE YEAR('.
$this->dbprefix.
'datestart) > '.
$this->year.
'
'.
$nav_ItemQuery->get_where( ' AND ' )
.
$nav_ItemQuery->get_group_by( ' GROUP BY ' ).
'
ORDER BY YEAR('.
$this->dbprefix.
'datestart) ASC, ABS( '.
$use_range_month.
' - MONTH('.
$this->dbprefix.
'datestart) ) ASC
LIMIT 1', OBJECT, 0, 'Calendar: find next year with posts' )
$next_year_year =
$row->year;
$next_year_month =
$row->month;
{ // Let's see if the next year is in the desired navigation range:
$next_year_ts =
mktime( 0, 0, 0, $use_range_month, $use_range_day, $this->year+
1 );
if( $next_year_ts <=
$this->params['max_timestamp'] )
$next_year_year =
date( 'Y', $next_year_ts );
$next_year_month =
date( 'm', $next_year_ts );
if( !empty($next_year_year) )
{ // We have a link to display:
$r[] =
'<a href="'.
$this->archive_link( $next_year_year, ($this->mode ==
'month') ?
$next_year_month :
'', '', '' )
?
/* Calendar link title to a month in a following year */ T_('Next year (%04d-%02d)')
:
/* Calendar link title to a following year */ T_('Next year (%04d)') ),
$next_year_year, $next_year_month )
* $Log: _calendar.plugin.php,v $
* Revision 1.26.2.7 2007/03/29 10:34:48 fplanque
* Revision 1.26.2.6 2006/12/26 03:18:50 fplanque
* assigned a few significant plugin groups
* Revision 1.26.2.5 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.26 2006/07/28 15:27:47 blueyed
* Revision 1.25 2006/07/22 18:21:19 blueyed
* Fixed doc (min_timestamp/max_timestamp)
* Revision 1.24 2006/07/12 22:09:49 blueyed
* Fixed "Notice: A non well formed numeric value encountered" notices + whitespace
* Revision 1.23 2006/07/12 15:40:50 fplanque
* save 4 expensive queries
* Revision 1.22 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.21 2006/07/07 21:26:49 blueyed
* Revision 1.20 2006/07/02 21:53:31 blueyed
* time difference as seconds instead of hours; validate user#1 on upgrade; bumped new_db_version to 9300.
* Revision 1.19 2006/06/16 21:30:57 fplanque
* Started clean numbering of plugin versions (feel free do add dots...)
* Revision 1.18 2006/05/30 20:25:35 blueyed
* Revision 1.17 2006/05/30 19:39:55 fplanque
* Revision 1.16 2006/04/19 20:14:03 fplanque
* do not restrict to :// (does not catch subdomains, not even www.)
* Revision 1.15 2006/03/17 18:08:37 blueyed
* Revision 1.13 2006/03/12 23:09:27 fplanque
* Revision 1.12 2006/02/03 21:58:05 fplanque
* Too many merges, too little time. I can hardly keep up. I'll try to check/debug/fine tune next week...
* Revision 1.11 2006/01/04 20:34:51 fplanque
* allow filtering on extra statuses
* Revision 1.10 2005/12/12 19:22:04 fplanque
* big merge; lots of small mods; hope I didn't make to many mistakes :]
* Revision 1.9 2005/10/03 18:10:08 fplanque
* Revision 1.8 2005/09/06 19:38:29 fplanque
* Revision 1.7 2005/09/06 17:14:12 fplanque
* stop processing early if referer spam has been detected
* Revision 1.6 2005/09/01 17:11:46 fplanque
* Merged in _calendar.class.php; history below:
* Revision 1.18 2005/08/31 19:08:51 fplanque
* Factorized Item query WHERE clause.
* Fixed calendar contextual accuracy.
* Revision 1.17 2005/08/26 18:41:31 fplanque
* Revision 1.16 2005/08/26 17:52:02 fplanque
* Revision 1.15 2005/08/26 16:15:08 fplanque
* made the whole calendar contextual (wow am I happy about this functionality! :)
* Revision 1.14 2005/08/25 11:02:11 fplanque
* moved calendar to a skintag plugin
* Revision 1.13 2005/05/09 19:07:03 fplanque
* bugfixes + global access permission
* Revision 1.12 2005/04/27 19:05:46 fplanque
* normalizing, cleanup, documentaion
* Revision 1.10 2005/03/18 01:40:50 blueyed
* link to prev month fixed
* Revision 1.9 2005/03/18 00:29:32 blueyed
* navigation: only link to month/year with posts
* Revision 1.8 2005/03/07 17:08:20 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/02/23 19:31:58 blueyed
* get_weekstartend() fixed
* Revision 1.5 2005/02/23 04:26:18 blueyed
* moved global $start_of_week into $locales properties
* Revision 1.4 2005/02/12 03:58:44 blueyed
* default to $navigation = 'tfoot', fixed queries that find posts in month or on day, refactored navigation link generation
* Revision 1.3 2004/12/13 21:29:58 fplanque
* Revision 1.2 2004/10/14 18:31:24 blueyed
* Revision 1.1 2004/10/13 22:46:32 fplanque
* Revision 1.34 2004/10/11 19:02:04 fplanque
* Edited code documentation.
* Revision 1.6 2004/1/15 20:49:14 hansreinders
* Add more flexibility to calendar