Source for file _class_calendar.php
Documentation is available at _class_calendar.php
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
var $specific; // WE ASKED FOR A SPECIFIC MONTH
var $mode; // 'month' or 'year'
* Where to do the navigation
$show_statuses =
array(),
$timestamp_min =
'', // Do not show posts before this timestamp
$timestamp_max =
'now' ) // Do not show posts after this timestamp
// Find out which month to display:
{ // we display current year, month gets current
{ // highlight no month, when not current year
// CONSTRUCT THE WHERE CLAUSE:
* ----------------------------------------------------
* Restrict to the statuses we want to show:
* ----------------------------------------------------
// Restrict to timestamp limits:
if( $timestamp_min ==
'now' ) $timestamp_min =
time();
if( !empty($timestamp_min) )
$date_min =
date('Y-m-d H:i:s', $timestamp_min +
($Settings->get('time_difference') *
3600) );
$where .=
$where_link.
' post_issue_date >= \''.
$date_min.
'\'';
if( $timestamp_max ==
'now' ) $timestamp_max =
time();
if( !empty($timestamp_max) )
$date_max =
date('Y-m-d H:i:s', $timestamp_max +
($Settings->get('time_difference') *
3600) );
$where .=
$where_link.
' post_issue_date <= \''.
$date_max.
'\'';
// Do we need to restrict categories:
{ // Blog #1 aggregates all
$where .=
$where_link.
' cat_blog_ID = '.
$blog;
$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">';
$this->searchframe =
12; // How many month will we search back for a post before we give up
$this->browseyears =
($this->mode ==
'year'); // browsing years from Calendar's caption
* 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 = ' (%d)'; // in table cell (behind abbr of month)
$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
function set( $var, $value )
function display( $file =
'', $params =
'' ) // Page to use for links
global $tableposts, $tablepostcats, $tablecategories;
global $weekday, $weekday_abbrev, $weekday_letter, $month, $month_abbrev;
if( $this->mode ==
'month' )
$end_of_week =
(($start_of_week +
7) %
7);
// Find a month with posts
$searchmonth =
$this->month;
$searchyear =
$this->year;
$arc_sql =
"SELECT COUNT(DISTINCT ID), YEAR(post_issue_date), MONTH(post_issue_date), DAYOFMONTH(post_issue_date) AS myday".
" FROM ($tableposts INNER JOIN $tablepostcats ON ID = postcat_post_ID)".
" INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID".
" WHERE MONTH(post_issue_date) = '$searchmonth' AND YEAR(post_issue_date) = '$searchyear' ".
$this->where.
" ORDER BY post_issue_date DESC";
$arc_result =
$DB->get_results( $arc_sql, ARRAY_A );
{ // OK we have a month with posts!
foreach( $arc_result as $arc_row )
$daysinmonthwithposts[ $arc_row['myday'] ] =
$arc_row['COUNT(DISTINCT ID)'];
$this->month =
$searchmonth;
$this->year =
$searchyear;
break; // Don't search any further!
{ // No post, but we asked for a specific month to be displayed
break; // Don't search any further!
{ // No, post, let's search in previous month!
if ($searchmonth ==
'00') {
$searchyear =
''.
(intval($searchyear)-
1);
// echo $this->month,'.',$this->year;
// echo 'days in month=', $daysinmonth;
$datestartofmonth =
$this->year.
'-'.
$this->month.
'-01';
$dateendofmonth =
$this->year.
'-'.
$this->month.
'-'.
$daysinmonth;
// caution: offset bug inside
if (mysql2date('w', $datestartofmonth) ==
$start_of_week) {
$calendarfirst =
$calendarblah['start'] +
1 +
3600; // adjust for daylight savings time
$calendarfirst =
$calendarblah['end'] -
604799 +
3600; // adjust for daylight savings time
//echo 'calendarfirst=', $calendarfirst;
if (mysql2date('w', $dateendofmonth) ==
$end_of_week) {
$calendarlast =
$calendarblah['start'] +
1;
$calendarlast =
$calendarblah['end'] +
10000;
//echo 'calendarlast=', $calendarlast;
// here the offset bug is corrected
$calendarfirst =
$calendarfirst -
604800;
// Create links to previous/next month
$previous_month_link =
'<a href="'.
.
'" title="'.
T_('previous month').
'"><</a>';
$next_month_link =
'<a href="'.
.
'" title="'.
T_('next month').
'">></a>';
// Find months with posts
$arc_sql =
"SELECT COUNT(DISTINCT ID), MONTH(post_issue_date) AS mymonth ".
"FROM ($tableposts INNER JOIN $tablepostcats ON ID = postcat_post_ID) ".
"INNER JOIN $tablecategories ON postcat_cat_ID = cat_ID ".
"WHERE YEAR(post_issue_date) = '$this->year' ".
$this->where.
" ORDER BY post_issue_date DESC";
$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['COUNT(DISTINCT ID)'];
{ // create links to previous/next year
$previous_year_link =
'<a href="'.
.
'" title="'.
T_('previous year').
'"><<</a> ';
$next_year_link =
' <a href="'.
.
'" title="'.
T_('next year').
'">>></a>';
// ** display everything **
{ // Link to previous year:
echo isset
( $previous_year_link ) ?
$previous_year_link :
'';
if( $this->mode ==
'month' )
{ // Link to previous month:
echo
$previous_month_link.
' ';
{ // chosen month with link to archives
echo
'<a href="'.
archive_link( $this->year, $this->month, '', '', false, $file, $params ).
'" title="'.
T_('go to month\'s archive').
'">';
{ // close link to month archive
echo
' '.
$next_month_link;
echo isset
( $next_year_link ) ?
$next_year_link :
'';
for ($i =
$start_of_week; $i <
($start_of_week +
7); $i =
$i +
1)
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:
// TODO: YEAR MODE support
echo
'<td colspan="'.
(($this->mode ==
'month') ?
'3' :
'2' ).
'" id="prev">';
echo isset
( $previous_year_link ) ?
$previous_year_link :
'';
echo isset
( $previous_month_link ) ?
$previous_month_link :
'';
if( $this->mode ==
'month' ) echo
'<td class="pad"> </td>'.
"\n";
echo
'<td colspan="'.
(($this->mode ==
'month') ?
'3' :
'2' ).
'" id="next">';
echo isset
( $next_month_link ) ?
$next_month_link :
'';
echo isset
( $next_year_link ) ?
$next_year_link :
'';
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);
for($i =
$calendarfirst; $i <
($calendarlast +
86400); $i =
$i +
86400)
{ // loop day by day (86400 seconds = 24 hours)
{ // We need to start a new row:
{ // Last day already displayed!
{ // This day is in this month
$calendartoday =
(date('Ymd',$i) ==
date('Ymd', (time() +
($Settings->get('time_difference') *
3600))));
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);
{ // This was the last day of week, we need to start a new row: