Session
- attempted to fixed crashes with the custom session handler. External SMTP library - added functionality to have Drupal not use the default PHP mail() function. For more info see: http://www.drupal.org/node.php?id=44 Note: for this to work all modules that send mails should use the Drupal function to send mail: user_mail($mail, $subject, $message, $header); Calendar - added an archive page which users can use to find archives instead of the good old block. Miscellaneous - fixed a "random" offset bug on module.inc that occurred on Windows. All of this needs more testing, and further suggestions are welcome.4.0.x
parent
c71e133958
commit
3b5c380611
|
@ -1,98 +1,98 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
// initialize modules:
|
// initialize modules:
|
||||||
function module_init() {
|
function module_init() {
|
||||||
module_list();
|
module_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply function $function to every known module:
|
// apply function $function to every known module:
|
||||||
function module_iterate($function, $argument = "") {
|
function module_iterate($function, $argument = "") {
|
||||||
foreach (module_list() as $name) $function($name, $argument);
|
foreach (module_list() as $name) $function($name, $argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke hook $hook of module $name with optional arguments:
|
// invoke hook $hook of module $name with optional arguments:
|
||||||
function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
||||||
$function = $name ."_". $hook;
|
$function = $name ."_". $hook;
|
||||||
if (function_exists($function)) {
|
if (function_exists($function)) {
|
||||||
return $function($a1, $a2, $a3, $a4);
|
return $function($a1, $a2, $a3, $a4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return array of module names (includes lazy module loading):
|
// return array of module names (includes lazy module loading):
|
||||||
function module_list() {
|
function module_list() {
|
||||||
static $list;
|
static $list;
|
||||||
|
|
||||||
if (!$list) {
|
if (!$list) {
|
||||||
if ($handle = @opendir("modules")) {
|
if ($handle = @opendir("modules")) {
|
||||||
$list = array();
|
$list = array();
|
||||||
while ($file = readdir($handle)) {
|
while ($file = readdir($handle)) {
|
||||||
if (".module" == substr($file, -7)) {
|
if (".module" == substr($file, -7)) {
|
||||||
$filename = substr($file, 0, -7);
|
$filename = substr($file, 0, -7);
|
||||||
include "modules/$filename.module";
|
$list[$filename] = $filename;
|
||||||
$list[$filename] = $filename;
|
include "modules/$filename.module";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
asort($list);
|
asort($list);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$list = array();
|
$list = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 1 if module $name exists, 0 otherwise:
|
// return 1 if module $name exists, 0 otherwise:
|
||||||
function module_exist($name) {
|
function module_exist($name) {
|
||||||
$list = module_list();
|
$list = module_list();
|
||||||
return ($list[$name]) ? 1 : 0;
|
return ($list[$name]) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 1 if module $name implements hook $hook, 0 otherwise:
|
// return 1 if module $name implements hook $hook, 0 otherwise:
|
||||||
function module_hook($name, $hook) {
|
function module_hook($name, $hook) {
|
||||||
return function_exists($name ."_". $hook);
|
return function_exists($name ."_". $hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rehash module-exported blocks:
|
// rehash module-exported blocks:
|
||||||
function module_rehash_blocks($name) {
|
function module_rehash_blocks($name) {
|
||||||
db_query("UPDATE blocks SET remove = '1' WHERE module = '$name'");
|
db_query("UPDATE blocks SET remove = '1' WHERE module = '$name'");
|
||||||
|
|
||||||
if ($blocks = module_invoke($name, "block")) {
|
if ($blocks = module_invoke($name, "block")) {
|
||||||
foreach ($blocks as $delta => $block) {
|
foreach ($blocks as $delta => $block) {
|
||||||
foreach ($block as $item => $data) {
|
foreach ($block as $item => $data) {
|
||||||
$block[$item] = addslashes($data);
|
$block[$item] = addslashes($data);
|
||||||
}
|
}
|
||||||
if (!db_fetch_object(db_query("SELECT * FROM blocks WHERE module = '$name' AND name = '$block[info]'"))) {
|
if (!db_fetch_object(db_query("SELECT * FROM blocks WHERE module = '$name' AND name = '$block[info]'"))) {
|
||||||
db_query("INSERT INTO blocks (name, module, delta) VALUES ('$block[info]', '$name', '$delta')");
|
db_query("INSERT INTO blocks (name, module, delta) VALUES ('$block[info]', '$name', '$delta')");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
db_query("UPDATE blocks SET delta = '$delta', remove = '0' WHERE module = '$name' AND name = '$block[info]'");
|
db_query("UPDATE blocks SET delta = '$delta', remove = '0' WHERE module = '$name' AND name = '$block[info]'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db_query("DELETE FROM blocks WHERE module = '$name' AND remove = '1'");
|
db_query("DELETE FROM blocks WHERE module = '$name' AND remove = '1'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// rehash a module:
|
// rehash a module:
|
||||||
function module_rehash($name) {
|
function module_rehash($name) {
|
||||||
if (module_exist($name)) {
|
if (module_exist($name)) {
|
||||||
$result = db_query("SELECT * FROM modules WHERE name = '$name'");
|
$result = db_query("SELECT * FROM modules WHERE name = '$name'");
|
||||||
|
|
||||||
if (!$object = db_fetch_object($result)) {
|
if (!$object = db_fetch_object($result)) {
|
||||||
db_query("INSERT INTO modules (name) VALUES ('$name')");
|
db_query("INSERT INTO modules (name) VALUES ('$name')");
|
||||||
}
|
}
|
||||||
|
|
||||||
// rehash module-exported blocks (if necessary):
|
// rehash module-exported blocks (if necessary):
|
||||||
module_rehash_blocks($name);
|
module_rehash_blocks($name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// remove all reference to module:
|
// remove all reference to module:
|
||||||
db_query("DELETE FROM modules WHERE name = '$name'");
|
db_query("DELETE FROM modules WHERE name = '$name'");
|
||||||
db_query("DELETE FROM blocks WHERE module = '$name'");
|
db_query("DELETE FROM blocks WHERE module = '$name'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,104 +1,165 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
class Calendar {
|
class Calendar {
|
||||||
var $date;
|
var $date;
|
||||||
|
|
||||||
function calendar($date = 0) {
|
function calendar($date = 0) {
|
||||||
// Prevent future dates
|
// Prevent future dates
|
||||||
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
|
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
|
||||||
$this->date = (($date && $date <= $today) ? $date : $today);
|
$this->date = (($date && $date <= $today) ? $date : $today);
|
||||||
}
|
}
|
||||||
|
|
||||||
function display() {
|
function display() {
|
||||||
// Extract information from the given date:
|
// Extract information from the given date:
|
||||||
$month = date("n", $this->date);
|
$month = date("n", $this->date);
|
||||||
$year = date("Y", $this->date);
|
$year = date("Y", $this->date);
|
||||||
$day = date("d", $this->date);
|
$day = date("d", $this->date);
|
||||||
|
|
||||||
// Extract today's date:
|
// Extract today's date:
|
||||||
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
|
$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:
|
// 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()));
|
$thislast = mktime(23, 59, 59, date("n", time()), date("t", time()), date("Y", time()));
|
||||||
|
|
||||||
// Extract first day of the month:
|
// Extract first day of the month:
|
||||||
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
|
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
|
||||||
|
|
||||||
// Extract last day of the month:
|
// Extract last day of the month:
|
||||||
$last = date("t", mktime(0, 0, 0, $month, 1, $year));
|
$last = date("t", mktime(0, 0, 0, $month, 1, $year));
|
||||||
|
|
||||||
// Calculate previous and next months dates and check for shorter months (28/30 days)
|
// Calculate previous and next months dates and check for shorter months (28/30 days)
|
||||||
$prevmonth = mktime(23, 59, 59, $month - 1, 1, $year);
|
$prevmonth = mktime(23, 59, 59, $month - 1, 1, $year);
|
||||||
$prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year);
|
$prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year);
|
||||||
$nextmonth = mktime(23, 59, 59, $month + 1, 1, $year);
|
$nextmonth = mktime(23, 59, 59, $month + 1, 1, $year);
|
||||||
$next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year);
|
$next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year);
|
||||||
|
|
||||||
// Generate calendar header:
|
// Generate calendar header:
|
||||||
$output .= "\n<!-- calendar -->\n";
|
$output .= "\n<!-- calendar -->\n";
|
||||||
$output .= "<TABLE WIDTH=\"100%\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
|
$output .= "<TABLE WIDTH=\"100%\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
|
||||||
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"7\"><SMALL><A HREF=\"index.php?date=$prev\"><</A> ". date("F Y", $this->date) ." " . ($next <= $thislast ? "<A HREF=\"index.php?date=$next\">></A>" : ">") . "</SMALL></TD></TR>\n";
|
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"7\"><SMALL><A HREF=\"index.php?date=$prev\"><</A> ". date("F Y", $this->date) ." " . ($next <= $thislast ? "<A HREF=\"index.php?date=$next\">></A>" : ">") . "</SMALL></TD></TR>\n";
|
||||||
|
|
||||||
// Generate the days of the week:
|
// Generate the days of the week:
|
||||||
$output .= " <TR>";
|
$output .= " <TR>";
|
||||||
$somesunday = mktime(0, 0, 0, 3, 20, 1994);
|
$somesunday = mktime(0, 0, 0, 3, 20, 1994);
|
||||||
for ($i = 0; $i < 7; $i++) {
|
for ($i = 0; $i < 7; $i++) {
|
||||||
$output .= "<TD ALIGN=\"center\"><SMALL>" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "</SMALL></TD>";
|
$output .= "<TD ALIGN=\"center\"><SMALL>" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "</SMALL></TD>";
|
||||||
}
|
}
|
||||||
$output .= "</TR>\n";
|
$output .= "</TR>\n";
|
||||||
|
|
||||||
// Initialize temporary variables:
|
// Initialize temporary variables:
|
||||||
$nday = 1;
|
$nday = 1;
|
||||||
$sday = $first;
|
$sday = $first;
|
||||||
|
|
||||||
// Loop through all the days of the month:
|
// Loop through all the days of the month:
|
||||||
while ($nday <= $last) {
|
while ($nday <= $last) {
|
||||||
// Set up blank days for first week of the month:
|
// Set up blank days for first week of the month:
|
||||||
if ($first) {
|
if ($first) {
|
||||||
$output .= " <TR><TD COLSPAN=\"$first\"> </TD>\n";
|
$output .= " <TR><TD COLSPAN=\"$first\"> </TD>\n";
|
||||||
$first = 0;
|
$first = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start every week on a new line:
|
// Start every week on a new line:
|
||||||
if ($sday == 0) $output .= " <TR>\n";
|
if ($sday == 0) $output .= " <TR>\n";
|
||||||
|
|
||||||
// Print one cell:
|
// Print one cell:
|
||||||
$date = mktime(23, 59, 59, $month, $nday, $year);
|
$date = mktime(23, 59, 59, $month, $nday, $year);
|
||||||
if ($date == $this->date) $output .= " <TD ALIGN=\"center\"><SMALL><B>$nday</B></SMALL></TD>\n";
|
if ($date == $this->date) $output .= " <TD ALIGN=\"center\"><SMALL><B>$nday</B></SMALL></TD>\n";
|
||||||
else if ($date > $today) $output .= " <TD ALIGN=\"center\"><SMALL>$nday</SMALL></TD>\n";
|
else if ($date > $today) $output .= " <TD ALIGN=\"center\"><SMALL>$nday</SMALL></TD>\n";
|
||||||
else $output .= " <TD ALIGN=\"center\"><SMALL><A HREF=\"index.php?date=$date\" STYLE=\"text-decoration: none;\">$nday</A></SMALL></TD>\n";
|
else $output .= " <TD ALIGN=\"center\"><SMALL><A HREF=\"index.php?date=$date\" STYLE=\"text-decoration: none;\">$nday</A></SMALL></TD>\n";
|
||||||
|
|
||||||
// Start every week on a new line:
|
// Start every week on a new line:
|
||||||
if ($sday == 6) $output .= " </TR>\n";
|
if ($sday == 6) $output .= " </TR>\n";
|
||||||
|
|
||||||
// Update temporary variables:
|
// Update temporary variables:
|
||||||
$sday++;
|
$sday++;
|
||||||
$sday = $sday % 7;
|
$sday = $sday % 7;
|
||||||
$nday++;
|
$nday++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete the calendar:
|
// Complete the calendar:
|
||||||
if ($sday) {
|
if ($sday) {
|
||||||
$end = 7 - $sday;
|
$end = 7 - $sday;
|
||||||
$output .= " <TD COLSPAN=\"$end\"> </TD>\n </TR>\n";
|
$output .= " <TD COLSPAN=\"$end\"> </TD>\n </TR>\n";
|
||||||
}
|
}
|
||||||
$output .= "</TABLE>\n\n";
|
$output .= "</TABLE>\n\n";
|
||||||
|
|
||||||
// Return calendar:
|
// Return calendar:
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calendar_block() {
|
function calendar_block() {
|
||||||
global $date;
|
global $date;
|
||||||
|
|
||||||
$calendar = new Calendar($date);
|
$calendar = new Calendar($date);
|
||||||
|
|
||||||
$block[0]["subject"] = "Browse archives";
|
$block[0]["subject"] = "Browse archives";
|
||||||
$block[0]["content"] = $calendar->display();
|
$block[0]["content"] = $calendar->display();
|
||||||
$block[0]["info"] = "Calendar to browse archives";
|
$block[0]["info"] = "Calendar to browse archives";
|
||||||
|
|
||||||
return $block;
|
return $block;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
function calendar_link($type) {
|
||||||
|
if ($type == "page" && user_access("access content")) {
|
||||||
|
$links[] = "<a href=\"module.php?mod=calendar\">archives</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
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("<b>:</b><br />", " ", 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("<p>", "", $start);
|
||||||
|
$start = str_replace("</p>\n", " ", $start);
|
||||||
|
$start = str_replace("<option value=\"0\">-</option>", "", $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();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
2812
modules/user.module
2812
modules/user.module
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue