Commit 4028362f authored by Dries's avatar Dries

- Applied Moshe's _exit patch (slightly modified).

- Fixed bug in system.module.
parent ad9b0303
......@@ -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[] = "<a href=\"index.php\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>";
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, "<a href=\"index.php\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>");
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 "<pre>execution time: $diff sec</pre>";
}
function query_print() {
global $queries;
print "<pre>";
......@@ -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);
......
<?php
// This module is holds functions useful for Drupal development.
// Please contribute!
function development_exit() {
if (variable_get("dev_query", 0)) {
query_print();
}
}
function development_system($field) {
$system["description"] = t("Enables features and functions to help Drupal development.");
return $system[$field];
}
function development_conf_options() {
$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, and the execution time for each."));
return $output;
}
?>
<?php
// $Id$
// Initialization hook, runs each time statistic module is loaded
function statistics_init() {
global $user, $recent_activity;
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());
}
}
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) {
......
<?php
// $Id$
// Initialization hook, runs each time statistic module is loaded
function statistics_init() {
global $user, $recent_activity;
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());
}
}
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) {
......
......@@ -84,13 +84,6 @@ function system_view_modules() {
$output .= form_item(t("Default theme"), "<select name=\"edit[theme_default]\">$options</select>", t("The default theme as seen by visitors or anonymous users."));
$output .= "<hr />\n";
// development settings:
$output .= "<h3>" . t("Development settings") . "</h3>\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 .= "<hr />\n";
foreach (module_list() as $name) {
if (module_hook($name, "conf_options")) {
$output .= "<h3><a name=\"$name\">". ucfirst(t("$name")) ." " . t("settings") . "</a></h3>". module_invoke($name, "conf_options") ."<hr />\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));
......
......@@ -84,13 +84,6 @@ function system_view_modules() {
$output .= form_item(t("Default theme"), "<select name=\"edit[theme_default]\">$options</select>", t("The default theme as seen by visitors or anonymous users."));
$output .= "<hr />\n";
// development settings:
$output .= "<h3>" . t("Development settings") . "</h3>\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 .= "<hr />\n";
foreach (module_list() as $name) {
if (module_hook($name, "conf_options")) {
$output .= "<h3><a name=\"$name\">". ucfirst(t("$name")) ." " . t("settings") . "</a></h3>". module_invoke($name, "conf_options") ."<hr />\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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment