From 4028362fda6f9423d95e53267fbd7ba99e96c106 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 26 Jan 2003 13:22:02 +0000 Subject: - Applied Moshe's _exit patch (slightly modified). - Fixed bug in system.module. --- includes/common.inc | 47 +++++-------------------- modules/development.module | 22 ++++++++++++ modules/statistics.module | 59 +++++++++++++++++--------------- modules/statistics/statistics.module | 59 +++++++++++++++++--------------- modules/system.module | 66 +++++++++++++++++++----------------- modules/system/system.module | 66 +++++++++++++++++++----------------- 6 files changed, 162 insertions(+), 157 deletions(-) create mode 100644 modules/development.module diff --git a/includes/common.inc b/includes/common.inc index afc64fae3..65f994db2 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -462,13 +462,7 @@ function check_input($text) { } function filter($text) { - foreach (module_list() as $name) { - if (module_hook($name, "filter")) { - $text = module_invoke($name, "filter", $text); - } - } - - return $text; + return module_invoke_all("filter", $text);; } function rewrite_old_urls($text) { @@ -808,28 +802,14 @@ function link_page() { return $custom_links; } else { - $links[] = "". t("home") .""; - - foreach (module_list() as $name) { - if (module_hook($name, "link")) { - $links = array_merge($links, module_invoke($name, "link", "page")); - } - } - + $links = module_invoke_all("link", "page"); + array_unshift($links, "". t("home") .""); return $links; } } function link_node($node, $main = 0) { - $links = array(); - - foreach (module_list() as $name) { - if (module_hook($name, "link")) { - $links = array_merge($links, module_invoke($name, "link", "node", $node, $main)); - } - } - - return $links; + return module_invoke_all("link", "node", $node, $main); } function timer_start() { @@ -838,14 +818,6 @@ function timer_start() { $timer = (float)$usec + (float)$sec; } -function timer_print() { - global $timer; - list($usec, $sec) = explode(" ", microtime()); - $stop = (float)$usec + (float)$sec; - $diff = $stop - $timer; - print "
execution time: $diff sec
"; -} - function query_print() { global $queries; print "
";
@@ -877,17 +849,14 @@ function page_header() {
 }
 
 function page_footer() {
-  if (variable_get("dev_timer", 0)) {
-    timer_print();
-  }
-
-  if (variable_get("dev_query", 0)) {
-    query_print();
-  }
 
   if (variable_get("cache", 0)) {
     page_set_cache();
   }
+
+  // a hook for modules where modules may take action at the end of a request
+  // good uses include setting a cache, page logging, etc.
+  module_invoke_all("exit");
 }
 
 unset($conf);
diff --git a/modules/development.module b/modules/development.module
new file mode 100644
index 000000000..c93b9e9ce
--- /dev/null
+++ b/modules/development.module
@@ -0,0 +1,22 @@
+
diff --git a/modules/statistics.module b/modules/statistics.module
index 3121a7dbf..4fd0c6267 100644
--- a/modules/statistics.module
+++ b/modules/statistics.module
@@ -1,35 +1,8 @@
 uid, time());
-    }
-    else {
-      db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s')", $referrer, $hostname, $user->uid, time());
-    }
-  }
+  global $recent_activity;
 
   /*
   ** The following logic determines what the current throttle level should
@@ -61,6 +34,36 @@ function statistics_init() {
   }
 }
 
+// Footer hook, runs at the end of every page request
+function statistics_exit() {
+  global $user;
+
+  if (variable_get("statistics_enable_node_counter", 0)) {
+    // node view counters are enabled
+    if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
+      // a node has been viewed, so updated the node's counters
+      db_query("UPDATE statistics SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = '%s' WHERE nid = '%s'", time(), arg(2));
+      // if we affected 0 rows, this is the first time viewing the node
+      if (!db_affected_rows()) {
+        // must create a new row to store counter's for new node
+        db_query("INSERT INTO statistics (nid, daycount, totalcount) VALUES('%s', daycount + 1, totalcount + 1)", arg(2));
+      }
+    }
+  }
+
+  if ((variable_get("statistics_enable_access_log", 0)) && (throttle_status() < 5)) {
+    // statistical logs are enabled
+    $referrer = getenv("HTTP_REFERER");
+    $hostname = getenv("REMOTE_ADDR");
+    // log this page access
+    if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
+      db_query("INSERT INTO accesslog (nid, url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s', '%s')", arg(2), $referrer, $hostname, $user->uid, time());
+    }
+    else {
+      db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s')", $referrer, $hostname, $user->uid, time());
+    }
+  }
+}
 
 /* System hook, sets description of module in admin page */
 function statistics_system($field) {
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index 3121a7dbf..4fd0c6267 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -1,35 +1,8 @@
 uid, time());
-    }
-    else {
-      db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s')", $referrer, $hostname, $user->uid, time());
-    }
-  }
+  global $recent_activity;
 
   /*
   ** The following logic determines what the current throttle level should
@@ -61,6 +34,36 @@ function statistics_init() {
   }
 }
 
+// Footer hook, runs at the end of every page request
+function statistics_exit() {
+  global $user;
+
+  if (variable_get("statistics_enable_node_counter", 0)) {
+    // node view counters are enabled
+    if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
+      // a node has been viewed, so updated the node's counters
+      db_query("UPDATE statistics SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = '%s' WHERE nid = '%s'", time(), arg(2));
+      // if we affected 0 rows, this is the first time viewing the node
+      if (!db_affected_rows()) {
+        // must create a new row to store counter's for new node
+        db_query("INSERT INTO statistics (nid, daycount, totalcount) VALUES('%s', daycount + 1, totalcount + 1)", arg(2));
+      }
+    }
+  }
+
+  if ((variable_get("statistics_enable_access_log", 0)) && (throttle_status() < 5)) {
+    // statistical logs are enabled
+    $referrer = getenv("HTTP_REFERER");
+    $hostname = getenv("REMOTE_ADDR");
+    // log this page access
+    if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
+      db_query("INSERT INTO accesslog (nid, url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s', '%s')", arg(2), $referrer, $hostname, $user->uid, time());
+    }
+    else {
+      db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s')", $referrer, $hostname, $user->uid, time());
+    }
+  }
+}
 
 /* System hook, sets description of module in admin page */
 function statistics_system($field) {
diff --git a/modules/system.module b/modules/system.module
index 9f59c00ed..480d5ac95 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -84,13 +84,6 @@ function system_view_modules() {
   $output .= form_item(t("Default theme"), "", t("The default theme as seen by visitors or anonymous users."));
   $output .= "
\n"; - // development settings: - $output .= "

" . t("Development settings") . "

\n"; - $output .= form_select(t("Display timer information"), "dev_timer", variable_get("dev_timer", 0), array(t("Disabled"), t("Enabled")), t("Display the time it took to generate a page. For Drupal development only.")); - $output .= form_select(t("Display query log"), "dev_query", variable_get("dev_query", 0), array(t("Disabled"), t("Enabled")), t("Display a log of the database queries needed to generate the current page.")); - - $output .= "
\n"; - foreach (module_list() as $name) { if (module_hook($name, "conf_options")) { $output .= "

". ucfirst(t("$name")) ." " . t("settings") . "

". module_invoke($name, "conf_options") ."
\n"; @@ -119,19 +112,34 @@ function system_view_filters() { return $output; } -function system_save($edit = array()) { +function system_save_settings($edit = array()) { foreach ($edit as $name => $value) { variable_set($name, $value); } + cache_clear_all(); + + return t("the configuration options have been saved."); +} + +function system_save_selector($type, $edit = array()) { + db_query("UPDATE system SET status = '0' WHERE type = '%s'", $type); + foreach ($edit["status"] as $filename => $status) { + db_query("UPDATE system SET status = '%d' WHERE filename = '$filename'", $status); + } + + cache_clear_all(); + return t("the configuration options have been saved."); } -function system_default($edit = array()) { +function system_reset_default($edit = array()) { foreach ($edit as $name => $value) { variable_del($name); } + cache_clear_all(); + return t("the configuration options have been reset to their default values."); } @@ -182,21 +190,9 @@ function system_dirscan($dir, $mask, $nomask = array(".", "..", "CVS")) { } function system_listing($type, $directory, $required = array()) { - $op = arg(2); - // Make sure we set $type correctly $type = $type != 'theme' ? "module" : "theme"; - if ($op == t("Save $type settings")) { - db_query("UPDATE system SET status = '0' WHERE type = '%d'", $type); - foreach ($edit["status"] as $filename => $status) { - db_query("UPDATE system SET status = '%d' WHERE filename = '$filename'", $status); - } - cache_clear_all(); - - $message = t("the configuration options have been saved."); - } - // Find files in the directory. $files = system_dirscan($directory, "\.$type$"); @@ -250,6 +246,10 @@ function system_admin() { global $op, $edit; if (user_access("administer site configuration")) { + + // NOTE: changing this also requires changing module_init() @ "includes/module.inc". + $required = array("modules/admin.module", "modules/user.module", "modules/system.module", "modules/watchdog.module"); + if (empty($op)) { $op = arg(2); } @@ -260,31 +260,35 @@ function system_admin() { break; case "modules": if (arg(3) == "settings") { - print status(system_view("modules")); + print system_view("modules"); } else { - // NOTE: changing this also requires changing module_init() @ "includes/module.inc". - $required = array("modules/admin.module", "modules/user.module", "modules/system.module", "modules/watchdog.module"); - print status(system_listing("module", "modules", $required)); + print system_listing("module", "modules", $required); } break; case "themes": if (arg(3) == "settings") { - print status(system_view("themes")); + print system_view("themes"); } else { - print status(system_listing("theme", "themes")); + print system_listing("theme", "themes"); } break; + case t("Save module settings"): + print status(system_save_selector("module", $edit)); + print system_listing("module", "modules", $required); + break; + case t("Save theme settings"): + print status(system_save_selector("theme", $edit)); + print system_listing("theme", "themes"); + break; case t("Reset to defaults"): - print status(system_default($edit)); + print status(system_reset_default($edit)); print system_view(arg(2)); - cache_clear_all(); break; case t("Save configuration"): - print status(system_save($edit)); + print status(system_save_settings($edit)); print system_view(arg(2)); - cache_clear_all(); break; default: print system_view(arg(2)); diff --git a/modules/system/system.module b/modules/system/system.module index 9f59c00ed..480d5ac95 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -84,13 +84,6 @@ function system_view_modules() { $output .= form_item(t("Default theme"), "", t("The default theme as seen by visitors or anonymous users.")); $output .= "
\n"; - // development settings: - $output .= "

" . t("Development settings") . "

\n"; - $output .= form_select(t("Display timer information"), "dev_timer", variable_get("dev_timer", 0), array(t("Disabled"), t("Enabled")), t("Display the time it took to generate a page. For Drupal development only.")); - $output .= form_select(t("Display query log"), "dev_query", variable_get("dev_query", 0), array(t("Disabled"), t("Enabled")), t("Display a log of the database queries needed to generate the current page.")); - - $output .= "
\n"; - foreach (module_list() as $name) { if (module_hook($name, "conf_options")) { $output .= "

". ucfirst(t("$name")) ." " . t("settings") . "

". module_invoke($name, "conf_options") ."
\n"; @@ -119,19 +112,34 @@ function system_view_filters() { return $output; } -function system_save($edit = array()) { +function system_save_settings($edit = array()) { foreach ($edit as $name => $value) { variable_set($name, $value); } + cache_clear_all(); + + return t("the configuration options have been saved."); +} + +function system_save_selector($type, $edit = array()) { + db_query("UPDATE system SET status = '0' WHERE type = '%s'", $type); + foreach ($edit["status"] as $filename => $status) { + db_query("UPDATE system SET status = '%d' WHERE filename = '$filename'", $status); + } + + cache_clear_all(); + return t("the configuration options have been saved."); } -function system_default($edit = array()) { +function system_reset_default($edit = array()) { foreach ($edit as $name => $value) { variable_del($name); } + cache_clear_all(); + return t("the configuration options have been reset to their default values."); } @@ -182,21 +190,9 @@ function system_dirscan($dir, $mask, $nomask = array(".", "..", "CVS")) { } function system_listing($type, $directory, $required = array()) { - $op = arg(2); - // Make sure we set $type correctly $type = $type != 'theme' ? "module" : "theme"; - if ($op == t("Save $type settings")) { - db_query("UPDATE system SET status = '0' WHERE type = '%d'", $type); - foreach ($edit["status"] as $filename => $status) { - db_query("UPDATE system SET status = '%d' WHERE filename = '$filename'", $status); - } - cache_clear_all(); - - $message = t("the configuration options have been saved."); - } - // Find files in the directory. $files = system_dirscan($directory, "\.$type$"); @@ -250,6 +246,10 @@ function system_admin() { global $op, $edit; if (user_access("administer site configuration")) { + + // NOTE: changing this also requires changing module_init() @ "includes/module.inc". + $required = array("modules/admin.module", "modules/user.module", "modules/system.module", "modules/watchdog.module"); + if (empty($op)) { $op = arg(2); } @@ -260,31 +260,35 @@ function system_admin() { break; case "modules": if (arg(3) == "settings") { - print status(system_view("modules")); + print system_view("modules"); } else { - // NOTE: changing this also requires changing module_init() @ "includes/module.inc". - $required = array("modules/admin.module", "modules/user.module", "modules/system.module", "modules/watchdog.module"); - print status(system_listing("module", "modules", $required)); + print system_listing("module", "modules", $required); } break; case "themes": if (arg(3) == "settings") { - print status(system_view("themes")); + print system_view("themes"); } else { - print status(system_listing("theme", "themes")); + print system_listing("theme", "themes"); } break; + case t("Save module settings"): + print status(system_save_selector("module", $edit)); + print system_listing("module", "modules", $required); + break; + case t("Save theme settings"): + print status(system_save_selector("theme", $edit)); + print system_listing("theme", "themes"); + break; case t("Reset to defaults"): - print status(system_default($edit)); + print status(system_reset_default($edit)); print system_view(arg(2)); - cache_clear_all(); break; case t("Save configuration"): - print status(system_save($edit)); + print status(system_save_settings($edit)); print system_view(arg(2)); - cache_clear_all(); break; default: print system_view(arg(2)); -- cgit v1.2.3