* Improved calendar.class.php speed-wise: did some inline caching to make

rendering a calendar less expensive.
* Added a function displayCalendar($theme, $active_date) to functions.inc.
* Adjusted index.php so it would support URIs formated like
  "?date=$unix_timestamp".
* Integrated the calendar in my personal theme: themes/Dries/theme.class.
  If you want to include the calendar in your theme, check the code in my
  $theme->footer(): global $date and call displayCalendar($theme, $date).

Check the main page at http://beta.drop.org/ with theme 'Dries' to see it
yourself!
3-00
Dries Buytaert 2000-06-03 11:39:07 +00:00
parent b260b2bce7
commit 07118dbd48
3 changed files with 38 additions and 47 deletions

View File

@ -13,6 +13,7 @@ class calendar {
### Extract information from the given date:
$month = date("n", $this->date);
$year = date("Y", $this->date);
$day = date("d", $this->date);
### Extract first day of the month:
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
@ -21,70 +22,54 @@ class calendar {
$last = date("t", mktime(0, 0, 0, $month, 1, $year));
### Calculate previous and next months dates:
$prev = mktime(0, 0, 0, $month - 1, 1, $year);
$next = mktime(0, 0, 0, $month + 1, 1, $year);
$prev = mktime(0, 0, 0, $month - 1, $day, $year);
$next = mktime(0, 0, 0, $month + 1, $day, $year);
### Generate calendar header:
print "<TABLE WIDTH=\"150\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\">";
print " <TR><TH COLSPAN=\"7\"><A HREF=\"$PHP_SELF?date=$prev\">&lt;&lt;</A> &nbsp; ". date("F Y", $this->date) ." &nbsp; <A HREF=\"$PHP_SELF?date=$next\">&gt;&gt;</A></TH></TR>";
print " <TR><TH>S</TH><TH>M</TH><TH>T</TH><TH>W</TH><TH>T</TH><TH>F</TH><TH>S</TH></TR>\n";
$output .= "<TABLE WIDTH=\"150\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\">";
$output .= " <TR><TH COLSPAN=\"7\"><A HREF=\"$PHP_SELF?date=$prev\">&lt;&lt;</A> &nbsp; ". date("F Y", $this->date) ." &nbsp; <A HREF=\"$PHP_SELF?date=$next\">&gt;&gt;</A></TH></TR>";
$output .= " <TR><TH>S</TH><TH>M</TH><TH>T</TH><TH>W</TH><TH>T</TH><TH>F</TH><TH>S</TH></TR>\n";
### Initialize temporary variables:
$day = 1;
$weekday = $first;
$nday = 1;
$sday = $first;
### Loop through all the days of the month:
while ($day <= $last) {
while ($nday <= $last) {
### Set up blank days for first week of the month:
if ($first) {
print "<TR><TD COLSPAN=\"$first\">&nbsp</TD>";
$output .= "<TR><TD COLSPAN=\"$first\">&nbsp</TD>";
$first = 0;
}
### Start every week on a new line:
if ($weekday == 0) print "<TR>";
if ($sday == 0) $output .= "<TR>";
### Print one cell:
$date = mktime(0, 0, 0, $month, $day, $year);
if ($day == date("d", $this->date)) {
print "<TD ALIGN=\"center\"><B>$day</B></TD>";
}
else {
print "<TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?date=$date\">$day</A></TD>";
}
$date = mktime(0, 0, 0, $month, $nday, $year);
if ($nday > $day) $output .= "<TD ALIGN=\"center\">$nday</TD>";
else if ($nday == $day) $output .= "<TD ALIGN=\"center\"><B>$nday</B></TD>";
else $output .= "<TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?date=$date\">$nday</A></TD>";
### Start every week on a new line:
if ($weekday == 6) print "</TR>";
if ($sday == 6) $output .= "</TR>";
### Update temporary variables:
$weekday++;
$weekday = $weekday % 7;
$day++;
$sday++;
$sday = $sday % 7;
$nday++;
}
### End the calendar:
if ($weekday != 0) {
$end = 7 - $weekday;
print "<TD COLSPAN=\"$end\">&nbsp;</TD></TR>";
if ($sday != 0) {
$end = 7 - $sday;
$output .= "<TD COLSPAN=\"$end\">&nbsp;</TD></TR>";
}
print "</TABLE>";
$output .= "</TABLE>";
### Return calendar:
return $output;
}
}
// -----------------------------------------------------------------------
// ---------- TEMPORARY CODE - should be removed after testing -----------
// -----------------------------------------------------------------------
print "<H1>CALENDAR TEST</H1>";
// Code to initialize and display a calendar:
if (!$date) $date = time();
$calendar = new calendar($date);
$calendar->display();
// Debug output:
print "<P><B>Selected date:</B><BR>". date("l, F d, Y", $date) ."</P>";
?>

View File

@ -169,6 +169,11 @@ function displayAccount($theme) {
}
}
function displayCalendar($theme, $date) {
include "calendar.class.php";
$calendar = new calendar($date);
$theme->box("Browse archives", $calendar->display());
}
function displayAccountSettings($theme) {
global $user;

View File

@ -7,18 +7,20 @@ if (($url) && (strstr(getenv("HTTP_REFERER"), $url))) {
addRefer($url);
}
include "theme.inc";
$theme->header();
dbconnect();
if (isset($user->storynum)) $number = $user->storynum; else $number = 10;
### Initialize variables:
$number = ($user->storynum) ? $user->storynum : 10;
$date = ($date) ? $date : time();
$result = mysql_query("SELECT * FROM stories ORDER BY sid DESC LIMIT $number");
### Perform query:
$result = mysql_query("SELECT * FROM stories WHERE time <= $date ORDER BY sid DESC LIMIT $number");
### Display stories:
while ($story = mysql_fetch_object($result)) {
### Compose more-link:
$morelink = "[ ";
if ($story->article) {
@ -28,16 +30,15 @@ while ($story = mysql_fetch_object($result)) {
$bytes = strlen($story->article);
$morelink .= "\"><FONT COLOR=\"$theme->hlcolor2\"><B>read more</B></FONT></A> | $bytes bytes in body | ";
}
$query = mysql_query("SELECT sid FROM comments WHERE sid = $story->sid");
if (!$query) { $count = 0; } else { $count = mysql_num_rows($query); }
$morelink .= "<A HREF=\"article.php?sid=$story->sid";
if (isset($user->umode)) { $morelink .= "&mode=$user->umode"; } else { $morelink .= "&mode=threaded"; }
if (isset($user->uorder)) { $morelink .= "&order=$user->uorder"; } else { $morelink .= "&order=0"; }
if (isset($user->thold)) { $morelink .= "&thold=$user->thold"; } else { $morelink .= "&thold=0"; }
$morelink .= "\"><FONT COLOR=\"$theme->hlcolor2\">$count comments</FONT></A> ]";
### Display story:
$theme->abstract($story->aid, $story->informant, $story->time, stripslashes($story->subject), stripslashes($story->abstract), stripslashes($story->comments), $story->category, $story->department, $morelink);
}