Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27865
Modified Files:
Tag: branch-smarty
serendipity_config.inc.php serendipity_functions.inc.php
serendipity_sidebar_items.php
Log Message:
- Convert the calendar into a Smarty tempate, and move it out of _functions.inc.php
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.93.2.9
retrieving revision 1.93.2.10
diff -u -d -r1.93.2.9 -r1.93.2.10
--- serendipity_config.inc.php 21 Sep 2004 20:43:15 -0000 1.93.2.9
+++ serendipity_config.inc.php 25 Sep 2004 23:29:19 -0000 1.93.2.10
@@ -246,6 +246,7 @@
$serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime');
$serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar');
$serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin');
+$serendipity['smarty']->register_function('serendipity_getFile', 'serendipity_smarty_getFile');
/* vim: set sts=4 ts=4 expandtab : */
?>
Index: serendipity_sidebar_items.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_sidebar_items.php,v
retrieving revision 1.84.2.1
retrieving revision 1.84.2.2
diff -u -d -r1.84.2.1 -r1.84.2.2
--- serendipity_sidebar_items.php 15 Sep 2004 15:17:09 -0000 1.84.2.1
+++ serendipity_sidebar_items.php 25 Sep 2004 23:29:20 -0000 1.84.2.2
@@ -36,6 +36,7 @@
$title = CALENDAR;
+ /* TODO: Patch this out */
if (!isset($serendipity['GET']['calendarZoom'])) {
if (!isset($serendipity['GET']['range'])) {
$calendarZoom = date('Y') . date('m');
@@ -46,22 +47,170 @@
$calendarZoom = $serendipity['GET']['calendarZoom'];
}
- serendipity_drawCalendar(
- substr(
- $calendarZoom,
- 4,
- 2
- ),
- substr(
- $calendarZoom,
- 0,
- 4
- ),
- $this->get_config('beginningOfWeek')
- );
- }
-}
+ /* TODO: must change */
+ $year = substr($calendarZoom, 0, 4);
+ $month = substr($calendarZoom, 4, 2);
+
+ $bow = (int)$this->get_config('beginningOfWeek', 1);
+ // Check for faulty input, is so - run the default
+ if ($bow>6) {
+ $bow = 1;
+ }
+
+ // Catch faulty month
+ $month = (int)$month;
+ if ($month<1) {
+ $month = 1;
+ }
+
+ // How many days does the month have?
+ $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01');
+ $nrOfDays = date('t', $ts);
+ $firstDayWeekDay = date('w', $ts);
+
+ // Calculate the first day of the week, based on the beginning of the week ($bow)
+ if ( $bow > $firstDayWeekDay ) {
+ $firstDayWeekDay = $firstDayWeekDay+7-$bow;
+ } elseif ( $bow < $firstDayWeekDay ) {
+ $firstDayWeekDay = $firstDayWeekDay-$bow;
+ } else {
+ $firstDayWeekDay = 0;
+ }
+
+ // Calculate the number of next/previous month
+ if ($month > 1) {
+ $previousMonth = $month-1;
+ $previousYear = $year;
+ } else {
+ $previousMonth = 12;
+ $previousYear = $year-1;
+ }
+
+ if ($month <12) {
+ $nextMonth = $month+1;
+ $nextYear = $year;
+ } else {
+ $nextMonth = 1;
+ $nextYear = $year+1;
+ }
+
+ $endts = mktime(0, 0, 0, $month + 1, 1, $year);
+
+ // Get first and last entry
+ $minmax = serendipity_db_query("SELECT MAX(timestamp) AS max, MIN(timestamp) AS min FROM {$serendipity['dbPrefix']}entries");
+ if (!is_array($minmax) || !is_array($minmax[0]) || $minmax[0]['min'] < 1 || $minmax[0]['max'] < 1) {
+ // If no entry is available yet, allow scrolling a year back and forth
+ $minmax = array(
+ '0' => array(
+ 'min' => mktime(0, 0, 0, 1, 1, date('Y')-1),
+ 'max' => mktime(0, 0, 0, 1, 1, date('Y')+1)
+ )
+ );
+ }
+
+ // Find out about diary entries
+ $add_query = '';
+ $base_query = '';
+ if (isset($serendipity['GET']['category'])) {
+ $categoryid = serendipity_db_escape_string($serendipity['GET']['category']);
+
+ if (is_numeric($categoryid)) {
+ $base_query = 'serendipity[category]=' . $categoryid;
+ $add_query = '&' . $base_query;
+ $querystring = "SELECT timestamp
+ FROM {$serendipity['dbPrefix']}entries e,
+ {$serendipity['dbPrefix']}category c,
+ {$serendipity['dbPrefix']}entrycat ec
+ WHERE e.timestamp >= $ts
+ AND e.timestamp <= $endts
+ AND e.isdraft = 'false'
+ AND e.id = ec.entryid
+ AND c.categoryid = ec.categoryid
+ AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
+ }
+ }
+
+ if (!isset($querystring)) {
+ $querystring = "SELECT timestamp
+ FROM {$serendipity['dbPrefix']}entries e
+ WHERE e.timestamp >= $ts and e.timestamp <= $endts AND e.isdraft = 'false'";
+ }
+
+ $rows = serendipity_db_query($querystring);
+ $activeDays = array();
+ if (is_array($rows)) {
+ foreach ($rows as $row) {
+ $activeDays[date('j', $row['timestamp'])] = $row['timestamp'];
+ }
+ }
+
+ // Print the calendar
+ $currDay = 1;
+ $nrOfRows = ceil(($nrOfDays+$firstDayWeekDay)/7);
+ $today_day = date('j');
+ $today_month = date('m');
+ $today_year = date('Y');
+ for ($x = 0; $x < 6; $x++) {
+ // Break out if we are out of days
+ if ($currDay > $nrOfDays) {
+ break;
+ }
+ // Prepare row
+ for ($y = 0; $y < 7; $y++) {
+ $cellProps = array();
+ $printDay = '';
+ $link = '';
+
+ if ($x == 0) {
+ $cellProps['FirstRow'] = 1;
+ }
+ if ($y == 0) {
+ $cellProps['FirstInRow'] = 1;
+ }
+ if ($y == 6) {
+ $cellProps['LastInRow'] = 1;
+ }
+ if ($x == $nrOfRows-1) {
+ $cellProps['LastRow'] = 1;
+ }
+
+ // If it's not a blank day, we print the day
+ if (($x > 0 || $y >= $firstDayWeekDay) && $currDay <= $nrOfDays) {
+ $printDay = $currDay;
+ if ($today_year == $year && $today_month == $month && $today_day == $currDay) {
+ $cellProps['Today'] = 1;
+ }
+ if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) {
+ $cellProps['Active'] = 1;
+ $cellProps['Link'] = serendipity_archiveDateUrl(sprintf('%4d%02d%02d', $year, $month, $currDay)) . $base_query;
+ }
+ $currDay++;
+ }
+ $smartyRows[$x]['days'][] = array('name' => $printDay,
+ 'properties' => $cellProps,
+ 'classes' => implode(' ', array_keys($cellProps)));
+ } // end for
+ } // end for
+ $serendipity['smarty']->assign('plugin_calendar_weeks', $smartyRows);
+
+
+ $dow = array();
+ for ($i = 1; $i <= 7; $i++) {
+ $dow[] = array('date' => mktime(0,0,0,3,$bow+$i-1,2004));
+ }
+ $serendipity['smarty']->assign('plugin_calendar_dow', $dow);
+
+
+ $serendipity['smarty']->assign('plugin_calendar_head', array('month_date' => $ts,
+ 'uri_previous' => $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] .'?serendipity[calendarZoom]='. $previousYear . sprintf('%02d',$previousMonth) . $add_query,
+ 'uri_month' => serendipity_archiveDateUrl($year . sprintf('%02d', $month)) . $base_query,
+ 'uri_next' => $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] .'?serendipity[calendarZoom]='. $previousYear . sprintf('%02d',$nextMonth) . $add_query,
+ 'minScroll' => $minmax[0]['min'],
+ 'maxScroll' => $minmax[0]['max']));
+ echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl');
+ } // end function
+} // end class
class serendipity_quicksearch_plugin extends serendipity_plugin {
function introspect(&$propbag)
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.419.2.31
retrieving revision 1.419.2.32
diff -u -d -r1.419.2.31 -r1.419.2.32
--- serendipity_functions.inc.php 24 Sep 2004 18:13:12 -0000 1.419.2.31
+++ serendipity_functions.inc.php 25 Sep 2004 23:29:19 -0000 1.419.2.32
@@ -285,217 +285,6 @@
}
}
-// Draws a little calendar in HTML
-function serendipity_drawCalendar($month, $year, $bow=1) {
- global $serendipity;
-
- // Check for faulty input, is so - run the default
- if (!is_numeric($bow) || (int)$bow>6) {
- $bow = 1;
- }
-
- $bow = (int)$bow;
-
- // Catch faulty month
- if ($month<1) {
- $month = 1;
- }
- $month = sprintf('%d', $month);
-
- // How many days does the month have?
- $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01');
- $nrOfDays = date('t', $ts);
- $firstDayWeekDay = date('w', $ts);
-
- // Calculate the first day of the week, based on the beginning of the week ($bow)
- if ( $bow > $firstDayWeekDay ) {
- $firstDayWeekDay = $firstDayWeekDay+7-$bow;
- } elseif ( $bow < $firstDayWeekDay ) {
- $firstDayWeekDay = $firstDayWeekDay-$bow;
- } else {
- $firstDayWeekDay = 0;
- }
-
- // Calculate the number of next/previous month
- if ($month > 1) {
- $previousMonth = $month-1;
- $previousYear = $year;
- } else {
- $previousMonth = 12;
- $previousYear = $year-1;
- }
-
- if ($month <12) {
- $nextMonth = $month+1;
- $nextYear = $year;
- } else {
- $nextMonth = 1;
- $nextYear = $year+1;
- }
-
- $endts = mktime(0, 0, 0, $month + 1, 1, $year);
-
- // Get first and last entry
- $minmax = serendipity_db_query("SELECT MAX(timestamp) AS max, MIN(timestamp) AS min FROM {$serendipity['dbPrefix']}entries");
- if (!is_array($minmax) || !is_array($minmax[0]) || $minmax[0]['min'] < 1 || $minmax[0]['max'] < 1) {
- // If no entry is available yet, allow scrolling a year back and forth
- $minmax = array(
- '0' => array(
- 'min' => mktime(0, 0, 0, 1, 1, date('Y')-1),
- 'max' => mktime(0, 0, 0, 1, 1, date('Y')+1)
- )
- );
- }
-
- // Find out about diary entries
- $add_query = '';
- $base_query = '';
- if (isset($serendipity['GET']['category'])) {
- $categoryid = serendipity_db_escape_string($serendipity['GET']['category']);
-
- if (is_numeric($categoryid)) {
- $base_query = 'serendipity[category]=' . $categoryid;
- $add_query = '&' . $base_query;
- $querystring = "SELECT timestamp
- FROM {$serendipity['dbPrefix']}entries e,
- {$serendipity['dbPrefix']}category c,
- {$serendipity['dbPrefix']}entrycat ec
- WHERE e.timestamp >= $ts
- AND e.timestamp <= $endts
- AND e.isdraft = 'false'
- AND e.id = ec.entryid
- AND c.categoryid = ec.categoryid
- AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
- }
- }
-
- if (!isset($querystring)) {
- $querystring = "SELECT timestamp
- FROM {$serendipity['dbPrefix']}entries e
- WHERE e.timestamp >= $ts and e.timestamp <= $endts AND e.isdraft = 'false'";
- }
-
- $rows = serendipity_db_query($querystring);
- $activeDays = array();
- if (is_array($rows)) {
- foreach ($rows as $row) {
- $activeDays[date('j', $row['timestamp'])] = $row['timestamp'];
- }
- }
-
- // Prepare the table
- $link = serendipity_archiveDateUrl($year . sprintf('%02d', $month)) . $base_query;
-?>
-<table width="100%" class="serendipity_calendar" cellspacing="0" cellpadding="0">
- <tr>
- <td align="left" class="serendipity_calendarHeader">
-<?php
- // Only allow to scroll to the previous month if the first entry is from the month before
- if ($ts > ($minmax[0]['min'] - 2678400)) {
-?>
- <a title="<?php echo BACK; ?>" href="<?php echo $serendipity['serendipityHTTPPath'] . $serendipity['indexFile']; ?>?serendipity[calendarZoom]=<?php echo $previousYear . sprintf('%02d',$previousMonth) . $add_query; ?>"><img alt="<?php echo BACK; ?>" src="<?php echo serendipity_getTemplateFile('img/back.png'); ?>" <?php echo ($serendipity['XHTML11'] ? 'style="border: 0px"' : 'border="0"'); ?> /></a>
-<?php
- }
-?>
- </td>
-
- <td colspan="5" align="center" valign="bottom" class="serendipity_calendarHeader">
- <b><?php echo ($serendipity['XHTML11'] ? '<span style="white-space: nowrap">' : '<nobr>'); ?><a href="<?php echo $link; ?>"><?php echo serendipity_formatTime("%B '%y", mktime(0,0,0,$month, 1, $year)) ?></a><?php echo ($serendipity['XHTML11'] ? '</span>' : '</nobr>'); ?></b>
- </td>
-
- <td align="right" class="serendipity_calendarHeader">
-<?php
- // Only allow to scroll to the next month if the last entry is from the month before
- if ($endts < ($minmax[0]['max'] + 2678400)) {
-?>
- <a title="<?php echo FORWARD; ?>" href="<?php echo $serendipity['serendipityHTTPPath'] . $serendipity['indexFile']; ?>?serendipity[calendarZoom]=<?php echo $nextYear . sprintf('%02d', $nextMonth) . $add_query; ?>"><img alt="<?php echo FORWARD; ?>" src="<?php echo serendipity_getTemplateFile('img/forward.png'); ?>" <?php echo ($serendipity['XHTML11'] ? 'style="border: 0px"' : 'border="0"'); ?> /></a>
-<?php
- }
-?>
- </td>
- </tr>
-
- <tr>
-<?php
- for ($i = 1; $i <= 7; $i++) {
- $date = mktime(0,0,0,3,$bow+$i-1,2004);
-?>
- <td scope="col" abbr="<?php echo serendipity_formatTime("%A", $date) ?>" title="<?php echo serendipity_formatTime("%A", $date) ?>" class="serendipity_weekDayName" align="center"><?php echo substr(serendipity_formatTime("%a", $date),0,2); ?></td>
-<?php
- }
-?>
- </tr>
-
-<?php
- // Print the calendar
- $currDay = 1;
- $nrOfRows = ceil(($nrOfDays+$firstDayWeekDay)/7);
- $today_day = date('j');
- $today_month = date('m');
- $today_year = date('Y');
- for ($x = 0; $x < 6; $x++) {
- // Break out if we are out of days
- if ($currDay > $nrOfDays) {
- break;
- }
-?>
- <tr class="serendipity_calendar">
-<?php
- // Prepare row
- for ($y = 0; $y < 7; $y++) {
- $cellProps = array();
- $link = '';
-
- if ($x == 0) {
- $cellProps[] = 'FirstRow';
- }
- if ($y == 0) {
- $cellProps[] = 'FirstInRow';
- }
- if ($y == 6) {
- $cellProps[] = 'LastInRow';
- }
- if ($x == $nrOfRows-1) {
- $cellProps[] = 'LastRow';
- }
-
- // If it's not a blank day, we print the day
- if (($x > 0 || $y >= $firstDayWeekDay) && $currDay <= $nrOfDays) {
-
- $printDay = $currDay;
-
- if ($today_year == $year && $today_month == $month && $today_day == $currDay) {
- $cellProps[] = 'Today';
- }
-
- if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) {
- $cellProps[] = 'Active';
- }
-
- if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) {
- $printDay = '<a href="' . serendipity_archiveDateUrl(sprintf('%4d%02d%02d', $year, $month, $currDay)) . $base_query . '">'. $printDay .'</a>';
- }
-
- $currDay++;
-?>
- <td class="serendipity_calendarDay <?php echo implode(' ', $cellProps); ?>"><?php echo $printDay ?></td>
-<?php
- // If it's a blank day (a day outside the month)
- } else {
-?>
- <td class="serendipity_calendarDay BlankDay <?php echo implode(' ', $cellProps); ?>"> </td>
-<?php
- } // end if (print day)
- } // end for-loop (inner: days)
-?>
- </tr>
-<?php
- } // end for-loop (outer: weeks)
-?>
-</table>
-<?php
-} // end function: serendipity_drawCalendar
-
function serendipity_fetchCategoryRange($categoryid) {
global $serendipity;
@@ -3544,6 +3333,15 @@
return serendipity_plugin_api::generate_plugins($params['side']);
}
+function serendipity_smarty_getFile($params, &$smarty) {
+ if ( !isset($params['file']) ) {
+ $smarty->trigger_error(__FUNCTION__ .": missing 'file' parameter");
+ return;
+ }
+ return serendipity_getTemplateFile($params['file']);
+}
+
+
function serendipity_smarty_formatTime($timestamp, $format) {
if (defined($format)) {
return serendipity_formatTime(constant($format), $timestamp);
|