From 4b46252c387637617bd93283756d1b045668aa87 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 31 Jan 2002 20:28:39 +0000 Subject: - Made the calendar module accept a $date parameter such that you can jump directly to a certain date in the archives. Also made the calendar link to itself such that it is self-contained. - Code beautifications: quoted a lot of arrays, removed dead code and simplified a few things. - Replaced the Calendar class by one function "calendar_display": using a class (or class instance, or object) doesn't make sense in the archives' case. - Renamed "calendar.module" to "archive.module". - Fixed a /problem/ with node settings not always being saved like expected. - Reorganized the user menu: renamed a couple of links for clarity and structure. - Fixed a few typos. --- modules/archive.module | 173 +++++++++++++++++++++++++++++++++++++++++ modules/archive/archive.module | 173 +++++++++++++++++++++++++++++++++++++++++ modules/calendar.module | 165 --------------------------------------- 3 files changed, 346 insertions(+), 165 deletions(-) create mode 100644 modules/archive.module create mode 100644 modules/archive/archive.module delete mode 100644 modules/calendar.module (limited to 'modules') diff --git a/modules/archive.module b/modules/archive.module new file mode 100644 index 000000000..0f5368c2f --- /dev/null +++ b/modules/archive.module @@ -0,0 +1,173 @@ +\n"; + $output .= "\n"; + $output .= " \n"; + + // Generate the days of the week: + $somesunday = mktime(0, 0, 0, 3, 20, 1994); + + $output .= " "; + for ($i = 0; $i < 7; $i++) { + $output .= ""; + } + $output .= "\n"; + + // Initialize temporary variables: + $nday = 1; + $sday = $first; + + // Loop through all the days of the month: + while ($nday <= $last) { + // Set up blank days for first week of the month: + if ($first) { + $output .= " \n"; + $first = 0; + } + + // Start every week on a new line: + if ($sday == 0) { + $output .= " \n"; + } + + // Print one cell: + $date = mktime(0, 0, 0, $month, $nday, $year); + + if ($date == $original) { + $output .= " \n"; + } + else if ($date > $today) { + $output .= " \n"; + } + else { + $output .= " \n"; + } + + // Start every week on a new line: + if ($sday == 6) { + $output .= " \n"; + } + + // Update temporary variables: + $sday++; + $sday = $sday % 7; + $nday++; + } + + // Complete the calendar: + if ($sday) { + $end = 7 - $sday; + $output .= " \n \n"; + } + + $output .= "
<   ". date("F Y", $original) ."   " . ($next <= $thislast ? ">" : ">") . "
" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "
 
$nday$nday$nday
 
\n\n"; + + return $output; +} + +function archive_block() { + global $date; + + $block[0]["subject"] = "Browse archives"; + $block[0]["content"] = archive_display($date); + $block[0]["info"] = "Calendar to browse archives"; + + return $block; +} + +function archive_link($type) { + if ($type == "page" && user_access("access content")) { + $links[] = "archives"; + } + + return $links ? $links : array(); +} + +function archive_page() { + global $date, $edit, $theme, $op, $month, $year, $meta; + + $theme->header(); + + if (user_access("access content")) { + + switch ($op) { + case t("Show"): + $date = mktime(0, 0, 0, $edit["month"], $edit["day"], $edit["year"]); + // Fall though + default: + + /* + ** Prepare the values of the form fields: + */ + + $years = array(2000 => "2000", 2001 => "2001", 2002 => "2002", 2003 => "2003", 2004 => "2004", 2005 => "2005"); + $months = array(1 => t("January"), 2 => t("February"), 3 => t("March"), 4 => t("April"), 5 => t("May"), 6 => t("June"), 7 => t("July"), 8 => t("August"), 9 => t("September"), 10 => t("October"), 11 => t("November"), 12 => t("December")); + for ($i = 1; $i <= 31; $i++) $days[$i] = $i; + + /* + ** If a timestamp is being specified, extract the date: + */ + + if ($date) { + $edit["year"] = date("Y", $date); + $edit["month"] = date("m", $date); + $edit["day"] = date("d", $date); + } + + $start = str_replace(":
", " ", form_select("", "year", ($edit["year"] ? $edit["year"] : date("Y")), $years) . form_select("", "month", ($edit["month"] ? $edit["month"] : date("m")), $months) . form_select("", "day", ($edit["day"] ? $edit["day"] : date("d")), $days) . form_submit(t("Show"))); + $start = str_replace("

", "", $start); + $start = str_replace("

\n", " ", $start); + + $theme->box(t("Archives"), form($start)); + + /* + ** Fetch nodes for the selected date, or current date if none + ** selected. + */ + + $result = db_query("SELECT nid FROM node WHERE status = '1' AND created > ". ($date > 0 ? check_input($date) : time()) ." ORDER BY created LIMIT 20"); + + while ($nid = db_fetch_object($result)) { + node_view(node_load(array("nid" => $nid->nid)), 1); + } + } + } + else { + $theme->box(t("Access denied"), message_access()); + } + + $theme->footer(); +} + +?> diff --git a/modules/archive/archive.module b/modules/archive/archive.module new file mode 100644 index 000000000..0f5368c2f --- /dev/null +++ b/modules/archive/archive.module @@ -0,0 +1,173 @@ +\n"; + $output .= "\n"; + $output .= " \n"; + + // Generate the days of the week: + $somesunday = mktime(0, 0, 0, 3, 20, 1994); + + $output .= " "; + for ($i = 0; $i < 7; $i++) { + $output .= ""; + } + $output .= "\n"; + + // Initialize temporary variables: + $nday = 1; + $sday = $first; + + // Loop through all the days of the month: + while ($nday <= $last) { + // Set up blank days for first week of the month: + if ($first) { + $output .= " \n"; + $first = 0; + } + + // Start every week on a new line: + if ($sday == 0) { + $output .= " \n"; + } + + // Print one cell: + $date = mktime(0, 0, 0, $month, $nday, $year); + + if ($date == $original) { + $output .= " \n"; + } + else if ($date > $today) { + $output .= " \n"; + } + else { + $output .= " \n"; + } + + // Start every week on a new line: + if ($sday == 6) { + $output .= " \n"; + } + + // Update temporary variables: + $sday++; + $sday = $sday % 7; + $nday++; + } + + // Complete the calendar: + if ($sday) { + $end = 7 - $sday; + $output .= " \n \n"; + } + + $output .= "
<   ". date("F Y", $original) ."   " . ($next <= $thislast ? ">" : ">") . "
" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "
 
$nday$nday$nday
 
\n\n"; + + return $output; +} + +function archive_block() { + global $date; + + $block[0]["subject"] = "Browse archives"; + $block[0]["content"] = archive_display($date); + $block[0]["info"] = "Calendar to browse archives"; + + return $block; +} + +function archive_link($type) { + if ($type == "page" && user_access("access content")) { + $links[] = "archives"; + } + + return $links ? $links : array(); +} + +function archive_page() { + global $date, $edit, $theme, $op, $month, $year, $meta; + + $theme->header(); + + if (user_access("access content")) { + + switch ($op) { + case t("Show"): + $date = mktime(0, 0, 0, $edit["month"], $edit["day"], $edit["year"]); + // Fall though + default: + + /* + ** Prepare the values of the form fields: + */ + + $years = array(2000 => "2000", 2001 => "2001", 2002 => "2002", 2003 => "2003", 2004 => "2004", 2005 => "2005"); + $months = array(1 => t("January"), 2 => t("February"), 3 => t("March"), 4 => t("April"), 5 => t("May"), 6 => t("June"), 7 => t("July"), 8 => t("August"), 9 => t("September"), 10 => t("October"), 11 => t("November"), 12 => t("December")); + for ($i = 1; $i <= 31; $i++) $days[$i] = $i; + + /* + ** If a timestamp is being specified, extract the date: + */ + + if ($date) { + $edit["year"] = date("Y", $date); + $edit["month"] = date("m", $date); + $edit["day"] = date("d", $date); + } + + $start = str_replace(":
", " ", form_select("", "year", ($edit["year"] ? $edit["year"] : date("Y")), $years) . form_select("", "month", ($edit["month"] ? $edit["month"] : date("m")), $months) . form_select("", "day", ($edit["day"] ? $edit["day"] : date("d")), $days) . form_submit(t("Show"))); + $start = str_replace("

", "", $start); + $start = str_replace("

\n", " ", $start); + + $theme->box(t("Archives"), form($start)); + + /* + ** Fetch nodes for the selected date, or current date if none + ** selected. + */ + + $result = db_query("SELECT nid FROM node WHERE status = '1' AND created > ". ($date > 0 ? check_input($date) : time()) ." ORDER BY created LIMIT 20"); + + while ($nid = db_fetch_object($result)) { + node_view(node_load(array("nid" => $nid->nid)), 1); + } + } + } + else { + $theme->box(t("Access denied"), message_access()); + } + + $theme->footer(); +} + +?> diff --git a/modules/calendar.module b/modules/calendar.module deleted file mode 100644 index cffacdec9..000000000 --- a/modules/calendar.module +++ /dev/null @@ -1,165 +0,0 @@ -date = (($date && $date <= $today) ? $date : $today); - } - - function display() { - // Extract information from the given date: - $month = date("n", $this->date); - $year = date("Y", $this->date); - $day = date("d", $this->date); - - // Extract today's date: - $today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time())); - - // Extract the timestamp of the last day of today's month: - $thislast = mktime(23, 59, 59, date("n", time()), date("t", time()), date("Y", time())); - - // Extract first day of the month: - $first = date("w", mktime(0, 0, 0, $month, 1, $year)); - - // Extract last day of the month: - $last = date("t", mktime(0, 0, 0, $month, 1, $year)); - - // Calculate previous and next months dates and check for shorter months (28/30 days) - $prevmonth = mktime(23, 59, 59, $month - 1, 1, $year); - $prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year); - $nextmonth = mktime(23, 59, 59, $month + 1, 1, $year); - $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year); - - // Generate calendar header: - $output .= "\n\n"; - $output .= "\n"; - $output .= " \n"; - - // Generate the days of the week: - $output .= " "; - $somesunday = mktime(0, 0, 0, 3, 20, 1994); - for ($i = 0; $i < 7; $i++) { - $output .= ""; - } - $output .= "\n"; - - // Initialize temporary variables: - $nday = 1; - $sday = $first; - - // Loop through all the days of the month: - while ($nday <= $last) { - // Set up blank days for first week of the month: - if ($first) { - $output .= " \n"; - $first = 0; - } - - // Start every week on a new line: - if ($sday == 0) $output .= " \n"; - - // Print one cell: - $date = mktime(23, 59, 59, $month, $nday, $year); - if ($date == $this->date) $output .= " \n"; - else if ($date > $today) $output .= " \n"; - else $output .= " \n"; - - // Start every week on a new line: - if ($sday == 6) $output .= " \n"; - - // Update temporary variables: - $sday++; - $sday = $sday % 7; - $nday++; - } - - // Complete the calendar: - if ($sday) { - $end = 7 - $sday; - $output .= " \n \n"; - } - $output .= "
<   ". date("F Y", $this->date) ."   " . ($next <= $thislast ? ">" : ">") . "
" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "
 
$nday$nday$nday
 
\n\n"; - - // Return calendar: - return $output; - } -} - -function calendar_block() { - global $date; - - $calendar = new Calendar($date); - - $block[0]["subject"] = "Browse archives"; - $block[0]["content"] = $calendar->display(); - $block[0]["info"] = "Calendar to browse archives"; - - return $block; -} - -function calendar_link($type) { - if ($type == "page" && user_access("access content")) { - $links[] = "archives"; - } - - return $links ? $links : array(); -} - -function calendar_page() { - global $date, $theme, $op, $month, $year, $meta; - - $theme->header(); - - switch ($op) { - case t("Show"): - global $edit; - $date = mktime(0, 0, 0, $edit[month], $edit[day], $edit[year]); - // Fall though - default: - global $edit; - $years = array(2001 => 2001, 2002 => 2002, 2003 => 2003, 2004 => 2004, 2005 => 2005); - $months = array("-", t("January"), t("February"), t("March"), t("April"), t("May"), t("June"), t("July"), t("August"), t("September"), t("October"), t("November"), t("December")); - for ($i = 1; $i <= 31; $i++) $days[$i] = $i; - for ($i = 0; $i <= 23; $i++) $hours[$i] = $i < 10 ? "0$i" : $i; - for ($i = 0; $i <= 59; $i++) $minutes[$i] = $i < 10 ? "0$i" : $i; - - if ($edit[start]) { - $edit[year] = date("Y", $edit[start]); - $edit[month] = date("m", $edit[start]); - $edit[day] = date("d", $edit[start]); - }; - - $start = str_replace(":
", " ", form_select("", "year", ($edit[year] ? $edit[year] : date("Y")), $years) . form_select("", "month", ($edit[month] ? $edit[month] : date("m")), $months) . form_select("", "day", ($edit[day] ? $edit[day] : date("d")), $days) . form_submit(t("Show"))); - $start = str_replace("

", "", $start); - $start = str_replace("

\n", " ", $start); - $start = str_replace("", "", $start); - - $form = $start; - - $theme->box(t("Archives"), form($form)); - - if (user_access("access content")) { - // Fetch event nodes for the selected date, or current date if none selected. - $result = db_query("SELECT nid FROM node WHERE status = '1' AND created > ". ($date > 0 ? check_input($date) : time()) ." ORDER BY created LIMIT 30"); - if($result){ - while ($nid = db_fetch_object($result)) { - node_view(node_load(array("nid" => $nid->nid)), 1); - } - } - else { - $output .= t("Your search yielded no result."); - } - } - else { - $theme->box(t("Access denied"), message_access()); - } - } - - $theme->footer(); -} - -?> \ No newline at end of file -- cgit v1.2.3