[pLog-svn] r2983 - plog/branches/lifetype-1.0.4/class/data
pwestbro at devel.lifetype.net
pwestbro at devel.lifetype.net
Fri Feb 24 05:56:48 GMT 2006
Author: pwestbro
Date: 2006-02-24 05:56:47 +0000 (Fri, 24 Feb 2006)
New Revision: 2983
Modified:
plog/branches/lifetype-1.0.4/class/data/htmlcalendar.class.php
plog/branches/lifetype-1.0.4/class/data/plogcalendar.class.php
Log:
Fixed bug http://bugs.lifetype.net/view.php?id=804. Now the HTML calendar correctly takes into account he time offset when rendering
Modified: plog/branches/lifetype-1.0.4/class/data/htmlcalendar.class.php
===================================================================
--- plog/branches/lifetype-1.0.4/class/data/htmlcalendar.class.php 2006-02-23 18:57:38 UTC (rev 2982)
+++ plog/branches/lifetype-1.0.4/class/data/htmlcalendar.class.php 2006-02-24 05:56:47 UTC (rev 2983)
@@ -1,17 +1,14 @@
<?php
include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
-
-/**
- * \ingroup Data
- *
- * Generates an html calendar
- *
+/**
+ * \ingroup Data
+ *
+ * Generates an html calendar *
* PHP Calendar Class Version 1.4 (5th March 2001)
*
* Copyright David Wilkinson 2000 - 2001. All Rights reserved.
- *
- * This software may be used, modified and distributed freely
+ * * This software may be used, modified and distributed freely
* providing this copyright notice remains intact at the head
* of the file.
*
@@ -23,14 +20,12 @@
* it meets your requirements.
*
* URL: http://www.cascade.org.uk/software/php/calendar/
- * Email: davidw at cascade.org.uk
- *
+ * Email: davidw at cascade.org.uk *
* Modified by fuze (http://www.fuze.org) on 2004/07/11
*
* Just changed the html table output for better (CSS) accessibility
* and variable names.
*/
-
class Calendar extends Object
{
/*
@@ -38,7 +33,7 @@
*/
function Calendar()
{
- $this->Object();
+ $this->Object();
}
@@ -234,7 +229,7 @@
/**
* Generate the HTML for a given month
*/
- function getMonthHTML($m, $y, $showYear = 1)
+ function getMonthHTML($m, $y, $showYear = 1, $highlightTimeStamp = 0 )
{
$s = "";
@@ -242,89 +237,97 @@
$month = $a[0];
$year = $a[1];
- $daysInMonth = $this->getDaysInMonth($month, $year);
- $date = getdate(mktime(12, 0, 0, $month, 1, $year));
+ $daysInMonth = $this->getDaysInMonth($month, $year);
+ $date = getdate(mktime(12, 0, 0, $month, 1, $year));
- $first = $date["wday"];
- $monthName = $this->monthNames[$month - 1];
-
- $prev = $this->adjustDate($month - 1, $year);
- $next = $this->adjustDate($month + 1, $year);
+ $first = $date["wday"];
+ $monthName = $this->monthNames[$month - 1];
+
+ $prev = $this->adjustDate($month - 1, $year);
+ $next = $this->adjustDate($month + 1, $year);
- if ($showYear == 1)
- {
- $prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
- $nextMonth = $this->getCalendarLink($next[0], $next[1]);
- $nextMonthName = $this->monthNames[ $next[0] - 1 ].(($showYear > 0) ? " " . $next[1] : "");
- $prevMonthName = $this->monthNames[ $prev[0] - 1 ].(($showYear > 0) ? " " . $prev[1] : "");
- }
- else
- {
- $prevMonth = "";
- $nextMonth = "";
- }
+ if ($showYear == 1)
+ {
+ $prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
+ $nextMonth = $this->getCalendarLink($next[0], $next[1]);
+ $nextMonthName = $this->monthNames[ $next[0] - 1 ].(($showYear > 0) ? " " . $next[1] : "");
+ $prevMonthName = $this->monthNames[ $prev[0] - 1 ].(($showYear > 0) ? " " . $prev[1] : "");
+ }
+ else
+ {
+ $prevMonth = "";
+ $nextMonth = "";
+ }
- $header = $monthName . (($showYear > 0) ? " " . $year : "");
+ $header = $monthName . (($showYear > 0) ? " " . $year : "");
//$s .= '<h2>'.$header.'</h2>'; // remove this line #1
- $s .= "<table class=\"calMonth\">\n";
+ $s .= "<table class=\"calMonth\">\n";
///* // remove this line #2
- $s .= "<thead>\n";
+ $s .= "<thead>\n";
$s .= "<tr class=\"calMonthNav\">\n";
- $s .= "\t<th class=\"calMonthBackward\">" . (($prevMonth == "") ? " " : "<a href=\"$prevMonth\" title=\"$prevMonthName\">«</a>") . "</th>\n";
- $s .= "\t<th class=\"calMonthCurrent\" colspan=\"5\">$header</th>\n";
- $s .= "\t<th class=\"calMonthForward\">" . (($nextMonth == "") ? " " : "<a href=\"$nextMonth\" title=\"$nextMonthName\">»</a>") . "</th>\n";
- $s .= "</tr>\n";
+ $s .= "\t<th class=\"calMonthBackward\">" . (($prevMonth == "") ? " " : "<a href=\"$prevMonth\" title=\"$prevMonthName\">«</a>") . "</th>\n";
+ $s .= "\t<th class=\"calMonthCurrent\" colspan=\"5\">$header</th>\n";
+ $s .= "\t<th class=\"calMonthForward\">" . (($nextMonth == "") ? " " : "<a href=\"$nextMonth\" title=\"$nextMonthName\">»</a>") . "</th>\n";
+ $s .= "</tr>\n";
// */ // remove this line #3 to go to t
- $s .= "<tr class=\"calMonthHeader\">\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay)%7] . "\">" . $this->dayNamesShort[($this->startDay)%7] . "</th>\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+1)%7] . "\">" . $this->dayNamesShort[($this->startDay+1)%7] . "</th>\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+2)%7] . "\">" . $this->dayNamesShort[($this->startDay+2)%7] . "</th>\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+3)%7] . "\">" . $this->dayNamesShort[($this->startDay+3)%7] . "</th>\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+4)%7] . "\">" . $this->dayNamesShort[($this->startDay+4)%7] . "</th>\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+5)%7] . "\">" . $this->dayNamesShort[($this->startDay+5)%7] . "</th>\n";
- $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+6)%7] . "\">" . $this->dayNamesShort[($this->startDay+6)%7] . "</th>\n";
- $s .= "</tr>\n";
- $s .= "</thead>\n";
- $s .= "<tbody>\n";
+ $s .= "<tr class=\"calMonthHeader\">\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay)%7] . "\">" . $this->dayNamesShort[($this->startDay)%7] . "</th>\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+1)%7] . "\">" . $this->dayNamesShort[($this->startDay+1)%7] . "</th>\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+2)%7] . "\">" . $this->dayNamesShort[($this->startDay+2)%7] . "</th>\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+3)%7] . "\">" . $this->dayNamesShort[($this->startDay+3)%7] . "</th>\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+4)%7] . "\">" . $this->dayNamesShort[($this->startDay+4)%7] . "</th>\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+5)%7] . "\">" . $this->dayNamesShort[($this->startDay+5)%7] . "</th>\n";
+ $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+6)%7] . "\">" . $this->dayNamesShort[($this->startDay+6)%7] . "</th>\n";
+ $s .= "</tr>\n";
+ $s .= "</thead>\n";
+ $s .= "<tbody>\n";
- // We need to work out what date to start at so that the first appears in the correct column
- $d = $this->startDay + 1 - $first;
- while ($d > 1)
- {
- $d -= 7;
- }
+ // We need to work out what date to start at so that the first appears in the correct column
+ $d = $this->startDay + 1 - $first;
+ while ($d > 1)
+ {
+ $d -= 7;
+ }
// Make sure we know when today is, so that we can use a different CSS style
- $today = getdate(time());
+ if ( $highlightTimeStamp == 0 )
+ {
+ $today = getdate(time());
+ }
+ else
+ {
+ $today = getdate( $highlightTimeStamp );
+ }
+
- while ($d <= $daysInMonth)
- {
- $s .= "<tr>\n";
+ while ($d <= $daysInMonth)
+ {
+ $s .= "<tr>\n";
- for ($i = 0; $i < 7; $i++)
- {
- $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? " class=\"calMonthToday\"" : " class=\"calMonthDay\"";
- $s .= "\t<td$class>";
- if ($d > 0 && $d <= $daysInMonth)
- {
- $link = $this->getDateLink($d, $month, $year);
- $s .= (($link == "") ? $d : "<a href=\"$link\">$d</a>");
- }
- else
- {
- $s .= " ";
- }
- $s .= "</td>\n";
- $d++;
- }
- $s .= "</tr>\n";
- }
- $s .= "</tbody>\n";
- $s .= "</table>\n";
+ for ($i = 0; $i < 7; $i++)
+ {
+ $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? " class=\"calMonthToday\"" : " class=\"calMonthDay\"";
+ $s .= "\t<td$class>";
+ if ($d > 0 && $d <= $daysInMonth)
+ {
+ $link = $this->getDateLink($d, $month, $year);
+ $s .= (($link == "") ? $d : "<a href=\"$link\">$d</a>");
+ }
+ else
+ {
+ $s .= " ";
+ }
+ $s .= "</td>\n";
+ $d++;
+ }
+ $s .= "</tr>\n";
+ }
+ $s .= "</tbody>\n";
+ $s .= "</table>\n";
- return $s;
+ return $s;
}
@@ -334,18 +337,18 @@
function getYearHTML($year)
{
$s = "";
- $prev = $this->getCalendarLink(0, $year - 1);
- $next = $this->getCalendarLink(0, $year + 1);
+ $prev = $this->getCalendarLink(0, $year - 1);
+ $next = $this->getCalendarLink(0, $year + 1);
$s .= "<table class=\"calYear\">\n";
- $s .= "<thead>\n";
+ $s .= "<thead>\n";
$s .= "<tr>";
- $s .= "\t<th class=\"calYearBackward\">" . (($prev == "") ? " " : "<a href=\"$prev\">«</a>") . "</th>\n";
+ $s .= "\t<th class=\"calYearBackward\">" . (($prev == "") ? " " : "<a href=\"$prev\">«</a>") . "</th>\n";
$s .= "\t<th class=\"calYearCurrent\">" . (($this->startMonth > 1) ? $year . " - " . ($year + 1) : $year) ."</th>\n";
- $s .= "\t<th class=\"calYearForward\">" . (($next == "") ? " " : "<a href=\"$next\">»</a>") . "</th>\n";
+ $s .= "\t<th class=\"calYearForward\">" . (($next == "") ? " " : "<a href=\"$next\">»</a>") . "</th>\n";
$s .= "</tr>\n";
- $s .= "</thead>\n";
- $s .= "<tbody>\n";
+ $s .= "</thead>\n";
+ $s .= "<tbody>\n";
$s .= "<tr>";
$s .= "\t<td>" . $this->getMonthHTML(0 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "\t<td>" . $this->getMonthHTML(1 + $this->startMonth, $year, 0) ."</td>\n";
@@ -366,7 +369,7 @@
$s .= "\t<td>" . $this->getMonthHTML(10 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "\t<td>" . $this->getMonthHTML(11 + $this->startMonth, $year, 0) ."</td>\n";
$s .= "</tr>\n";
- $s .= "</tbody>\n";
+ $s .= "</tbody>\n";
$s .= "</table>\n";
return $s;
Modified: plog/branches/lifetype-1.0.4/class/data/plogcalendar.class.php
===================================================================
--- plog/branches/lifetype-1.0.4/class/data/plogcalendar.class.php 2006-02-23 18:57:38 UTC (rev 2982)
+++ plog/branches/lifetype-1.0.4/class/data/plogcalendar.class.php 2006-02-24 05:56:47 UTC (rev 2983)
@@ -1,30 +1,29 @@
<?php
-
- include_once( PLOG_CLASS_PATH."class/data/htmlcalendar.class.php" );
- include_once( PLOG_CLASS_PATH."class/locale/locale.class.php" );
include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
- include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/htmlcalendar.class.php" );
+ include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+ include_once( PLOG_CLASS_PATH."class/locale/locale.class.php" );
include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
- /**
- * \ingroup Data
+ /**
+ * \ingroup Data
*
- * A derived class is required to reimplement some methods from the parent
- * Calendar class to add things like links to the days and so on.
+ * A derived class is required to reimplement some methods from the parent
+ * Calendar class to add things like links to the days and so on.
* This one also converts the original HtmlCalendar into Locale aware, respecting
- * things like the first day of the week and the abbreviations of the days of the week.
- *
+ * things like the first day of the week and the abbreviations of the days of the week.
+ *
* User classes will rarely need to use this class.
- */
- class PlogCalendar extends Calendar
- {
+ */
+ class PlogCalendar extends Calendar {
- var $_dayPosts;
- var $_blogInfo;
- var $rg;
+ var $_dayPosts;
+ var $_blogInfo; var $rg;
- /**
+ /**
* Constructor.
*
* @param dayPosts An array indexed from 1 to as many days as the month where
@@ -32,43 +31,43 @@
* @param localeCode A code specifying the locale we want to use. If empty, the default
* one specified in the configuration file will be used.
*/
- function PlogCalendar( $dayPosts = null, $blogInfo = null, $localeCode = null )
- {
- $this->Calendar();
+ function PlogCalendar( $dayPosts = null, $blogInfo = null, $localeCode = null )
+ {
+ $this->Calendar();
- if( $localeCode == null ) {
- $config = Config::getConfig();
- //$locale = new Locale( $config->getValue( "default_locale" ));
- $locale = Locales::getLocale( $config->getValue( "default_locale" ));
- }
- else {
- //$locale = new Locale( $localeCode );
- $locale = Locales::getLocale( $localeCode );
- }
+ if( $localeCode == null ) {
+ $config = Config::getConfig();
+ //$locale = new Locale( $config->getValue( "default_locale" ));
+ $locale = Locales::getLocale( $config->getValue( "default_locale" ));
+ }
+ else {
+ //$locale = new Locale( $localeCode );
+ $locale = Locales::getLocale( $localeCode );
+ }
$this->_dayPosts = $dayPosts;
$this->_blogInfo = $blogInfo;
- // set the first day of the week according to our locale
- $this->startDay = $locale->firstDayOfWeek();
- //array_push( $this->monthsNames, $locale->tr("January"));
- $this->monthNames = $locale->getMonthNames();
- // abbreviations of the days of the week
- $this->dayNamesShort = $locale->getDayNamesShort();
- // full names of the days of the week
- $this->dayNames = $locale->getDayNames();
+ // set the first day of the week according to our locale
+ $this->startDay = $locale->firstDayOfWeek();
+ //array_push( $this->monthsNames, $locale->tr("January"));
+ $this->monthNames = $locale->getMonthNames();
+ // abbreviations of the days of the week
+ $this->dayNamesShort = $locale->getDayNamesShort();
+ // full names of the days of the week
+ $this->dayNames = $locale->getDayNames();
- $this->rg = RequestGenerator::getRequestGenerator( $blogInfo );
- }
+ $this->rg = RequestGenerator::getRequestGenerator( $blogInfo );
+ }
/**
* Function overwritten from the base one, so that we can display links for the
- * next month and the previous month
- *
+ * next month and the previous month
+ *
* @see Calendar::getCalendarLink()
*/
- function getCalendarLink( $month, $year )
- {
+ function getCalendarLink( $month, $year )
+ {
if( $month < 10 ) $month = "0".$month;
$date = "$year$month";
@@ -76,29 +75,55 @@
return( $calendarLink );
- }
+ }
/**
* Function overwritten from the base one, so that we can display a link for the days
- * that have posts
- *
+ * that have posts
+ *
* @see Calendar::getDateLink()
*/
- function getDateLink( $day, $month, $year )
- {
- if( $this->_dayPosts == null )
- return "";
+ function getDateLink( $day, $month, $year )
+ {
+ if( $this->_dayPosts == null )
+ return "";
if( array_key_exists( $day, $this->_dayPosts) && $this->_dayPosts[$day] > 0 ) {
- if( $day < 10 ) $day = "0".$day;
+ if( $day < 10 ) $day = "0".$day;
$date = "$year$month$day";
$dateLink = $this->rg->getArchiveLink( $date );
- return( $dateLink );
+ return( $dateLink );
}
return "";
- }
- }
+ }
+
+ /**
+ * Return the HTML for a specified month
+ *
+ * @see Calendar::getMonthView()
+ */
+ function getMonthView($month, $year)
+ {
+
+ $t = Timestamp::getBlogDate( $this->_blogInfo );
+
+ // getBlogDate sometimes returns the time without the time zone applied. If it wasn't
+ // We need to make sure that it is applied now
+ $config =& Config::getConfig();
+ if( $config->getValue( "time_difference_calculation" ) == TIME_DIFFERENCE_CALCULATION_DYNAMIC ) {
+ $blogSettings = $this->_blogInfo->getSettings();
+ $timeDifference = $blogSettings->getValue( "time_offset" );
+ $t->setDate( Timestamp::getDateWithOffset( $t->getDate(), $timeDifference ), DATE_FORMAT_TIMESTAMP );
+ }
+
+ return $this->getMonthHTML($month, $year, 1/*showYear*/,
+ $t->getTimestamp(DATE_FORMAT_UNIXTIME) );
+ }
+
+
+
+ }
?>
More information about the pLog-svn
mailing list