diff --git a/CHANGELOG b/CHANGELOG
index 3ce548602048c075f1ee93b9b22c0d75612c3797..bebdf1a17e2b0dcea45608cf4bc321f4a5df242d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,7 @@ Drupal x.x.x, xxxx-xx-xx
* made it possible to disable the "comment viewing controls".
- performance:
* improved module loading when serving cached pages.
+ * made it possible to automatically disable blocks when under heavy load.
- theme system:
* made all theme functions start with 'theme_'.
* made all theme functions return their output.
diff --git a/database/database.mssql b/database/database.mssql
index f1f5552a465dfc7ea4f54aeacc6c2717a8e3d768..396f1b8577012aa7b15bbb0dc012ddac0b56fc7c 100644
--- a/database/database.mssql
+++ b/database/database.mssql
@@ -34,7 +34,8 @@ CREATE TABLE [dbo].[blocks] (
[weight] [smallint] NOT NULL ,
[region] [smallint] NOT NULL ,
[path] [varchar] (255) NOT NULL ,
- [custom] [smallint] NOT NULL
+ [custom] [smallint] NOT NULL,
+ [throttle] [smallint] NOT NULL
) ON [PRIMARY]
GO
diff --git a/database/database.mysql b/database/database.mysql
index 8ba395e81b364ec2da46440d6e57ff16f24e49c1..3c36c03eeca7e72021bc2f1bba9a2551ff0d80f2 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -53,7 +53,8 @@ CREATE TABLE blocks (
weight tinyint(1) DEFAULT '0' NOT NULL,
region tinyint(1) DEFAULT '0' NOT NULL,
path varchar(255) DEFAULT '' NOT NULL,
- custom tinyint(2) DEFAULT '0' NOT NULL
+ custom tinyint(2) DEFAULT '0' NOT NULL,
+ throttle tinyint(1) DEFAULT '0' NOT NULL
) TYPE=MyISAM;
--
diff --git a/database/database.pgsql b/database/database.pgsql
index cd77a2fa4bd9dd6dad726430aff70590184d0a56..b6a22be9dda04efd8777c41f0f1606ab10546656 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -51,7 +51,8 @@ CREATE TABLE blocks (
weight smallint NOT NULL default '0',
region smallint NOT NULL default '0',
path varchar(255) NOT NULL default '',
- custom smallint NOT NULL default '0'
+ custom smallint NOT NULL default '0',
+ throttle smallint NOT NULL default '0'
);
--
diff --git a/includes/xmlrpcs.inc b/includes/xmlrpcs.inc
index a3dce43d19c4991b2b8fd6ec6de1e0e9ea220e11..01d81822ee3ae348df55353bc6ab743fafccf669 100644
--- a/includes/xmlrpcs.inc
+++ b/includes/xmlrpcs.inc
@@ -173,7 +173,7 @@ function service() {
$payload="\n" .
$this->serializeDebug() .
$r->serialize();
- Header("Content-type: text/xml\r\nContent-Length: " .
+ Header("Content-Type: text/xml\r\nContent-Length: " .
strlen($payload));
print $payload;
}
diff --git a/modules/block.module b/modules/block.module
index a6ba601450a01b2ef194cbc4d3a3e7c6d3754291..57e4e843e4aa68a7337c4cd00d1280ff24a55c00 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -40,7 +40,7 @@ function block_help($section = "admin/help#block") {
$output = t("Controls the boxes that are displayed around the main content.");
break;
case 'admin/system/block':
- $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by active Drupal modules. In order to view a block it must be enabled. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. The custom checkbox lets your users hide the block using their account setting. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the %createblock link in the menu to the left. Edit and delete links will become active below for these customized blocks.", array("%createblock" => l(t("new block"), "admin/system/block/add")));
+ $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by active Drupal modules. In order to view a block it must be enabled. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. The custom checkbox lets your users hide the block using their account setting. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the %createblock link in the menu to the left. Edit and delete links will become active below for these customized blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking auto-throttle. The auto-throttle functionality must be enabled on the %throttle.", array("%createblock" => l(t("new block"), "admin/system/block/add"), "%throttle" => l(t("throttle configuration page"), "admin/system/modules/throttle")));
break;
case 'admin/system/block/add':
$output = t("Here you can create a custom content block. Once you have created this block you must make it active, and give it a place on the page using %overview. The title is used when displaying the block. The description is used in the \"block\" column on the %overview page. If you are going to place PHP code in the block, and you have create php content permission (see the %permission page) you must change the type to PHP to make your code active.", array("%overview" => l(t("blocks"), "admin/system/block"), "%permission" => l(t("permissions"), "admin/user/permission")));
@@ -90,8 +90,8 @@ function block_block($op = "list", $delta = 0) {
function block_admin_save($edit) {
foreach ($edit as $module => $blocks) {
foreach ($blocks as $delta => $block) {
- db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'",
- $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
+ db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'",
+ $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $block["throttle"], $module, $delta);
}
}
@@ -125,6 +125,7 @@ function _block_rehash($order_by = array("weight")) {
$block["region"] = $old_blocks[$module][$delta]->region;
$block["path"] = $old_blocks[$module][$delta]->path;
$block["custom"] = $old_blocks[$module][$delta]->custom;
+ $block["throttle"] = $old_blocks[$module][$delta]->throttle;
}
else {
$block["status"] = $block["weight"] = $block["region"] = $block["custom"] = 0;
@@ -132,8 +133,8 @@ function _block_rehash($order_by = array("weight")) {
}
// reinsert blocks into table
- db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)",
- $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]);
+ db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, '%s', %d, %d)",
+ $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"], $block["throttle"]);
$blocks[] = $block;
@@ -153,7 +154,7 @@ function block_admin_display() {
$blocks = _block_rehash();
- $header = array(t("block"), t("enabled"), t("custom"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
+ $header = array(t("block"), t("enabled"), t("custom"), t("throttle"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
foreach ($blocks as $block) {
if ($block["module"] == "block") {
@@ -165,7 +166,10 @@ function block_admin_display() {
$delete = "";
}
- $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][custom", 1, $block["custom"]), "align" => "center"), form_weight(NULL, $block["module"]."][".$block["delta"]."][weight", $block["weight"]), form_radios(NULL, $block["module"]."][".$block["delta"]."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"]."][".$block["delta"]."][path", $block["path"], 10, 255), $edit, $delete);
+ $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][custom", 1, $block["custom"]), "align" => "center"),
+ array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][throttle", 1, $block["throttle"], NULL, variable_get("statistics_enable_auto_throttle", 0) ? NULL : array("disabled" => "disabled")), "align" => "center"),
+ form_weight(NULL, $block["module"]."][".$block["delta"]."][weight", $block["weight"]), form_radios(NULL, $block["module"]."][".$block["delta"]."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"]."][".$block["delta"]."][path", $block["path"], 10, 255),
+ $edit, $delete);
}
$output = theme("table", $header, $rows);
@@ -373,7 +377,17 @@ function block_list($region) {
while ($result && ($block = db_fetch_array($result))) {
if ((($block['status'] && (!$user->uid || !$block['custom'])) || ($block['custom'] && $user->block[$block['module']][$block['delta']])) && (!$block['path'] || preg_match($block['path'], str_replace("?q=", "", request_uri())))) {
- $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
+
+ /*
+ ** If congestion control is enabled, check current throttle status
+ ** and see if block should be displayed based on server load.
+ */
+ if ((module_invoke("throttle", "status") < 5) && $block['throttle'] && variable_get("statistics_enable_auto_throttle", 0)) {
+ $block['content'] = t('This block has been temporarily disabled as we are currently experiencing excessive load on our webserver. The block will be automatically reenabled when the webserver is less busy.');
+ }
+ else {
+ $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
+ }
if ($block['content']) {
$blocks[$region]["$block[module]_$block[delta]"] = (object) $block;
}
diff --git a/modules/block/block.module b/modules/block/block.module
index a6ba601450a01b2ef194cbc4d3a3e7c6d3754291..57e4e843e4aa68a7337c4cd00d1280ff24a55c00 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -40,7 +40,7 @@ function block_help($section = "admin/help#block") {
$output = t("Controls the boxes that are displayed around the main content.");
break;
case 'admin/system/block':
- $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by active Drupal modules. In order to view a block it must be enabled. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. The custom checkbox lets your users hide the block using their account setting. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the %createblock link in the menu to the left. Edit and delete links will become active below for these customized blocks.", array("%createblock" => l(t("new block"), "admin/system/block/add")));
+ $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by active Drupal modules. In order to view a block it must be enabled. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. The custom checkbox lets your users hide the block using their account setting. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the %createblock link in the menu to the left. Edit and delete links will become active below for these customized blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking auto-throttle. The auto-throttle functionality must be enabled on the %throttle.", array("%createblock" => l(t("new block"), "admin/system/block/add"), "%throttle" => l(t("throttle configuration page"), "admin/system/modules/throttle")));
break;
case 'admin/system/block/add':
$output = t("Here you can create a custom content block. Once you have created this block you must make it active, and give it a place on the page using %overview. The title is used when displaying the block. The description is used in the \"block\" column on the %overview page. If you are going to place PHP code in the block, and you have create php content permission (see the %permission page) you must change the type to PHP to make your code active.", array("%overview" => l(t("blocks"), "admin/system/block"), "%permission" => l(t("permissions"), "admin/user/permission")));
@@ -90,8 +90,8 @@ function block_block($op = "list", $delta = 0) {
function block_admin_save($edit) {
foreach ($edit as $module => $blocks) {
foreach ($blocks as $delta => $block) {
- db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'",
- $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
+ db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'",
+ $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $block["throttle"], $module, $delta);
}
}
@@ -125,6 +125,7 @@ function _block_rehash($order_by = array("weight")) {
$block["region"] = $old_blocks[$module][$delta]->region;
$block["path"] = $old_blocks[$module][$delta]->path;
$block["custom"] = $old_blocks[$module][$delta]->custom;
+ $block["throttle"] = $old_blocks[$module][$delta]->throttle;
}
else {
$block["status"] = $block["weight"] = $block["region"] = $block["custom"] = 0;
@@ -132,8 +133,8 @@ function _block_rehash($order_by = array("weight")) {
}
// reinsert blocks into table
- db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)",
- $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]);
+ db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, '%s', %d, %d)",
+ $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"], $block["throttle"]);
$blocks[] = $block;
@@ -153,7 +154,7 @@ function block_admin_display() {
$blocks = _block_rehash();
- $header = array(t("block"), t("enabled"), t("custom"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
+ $header = array(t("block"), t("enabled"), t("custom"), t("throttle"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
foreach ($blocks as $block) {
if ($block["module"] == "block") {
@@ -165,7 +166,10 @@ function block_admin_display() {
$delete = "";
}
- $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][custom", 1, $block["custom"]), "align" => "center"), form_weight(NULL, $block["module"]."][".$block["delta"]."][weight", $block["weight"]), form_radios(NULL, $block["module"]."][".$block["delta"]."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"]."][".$block["delta"]."][path", $block["path"], 10, 255), $edit, $delete);
+ $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][custom", 1, $block["custom"]), "align" => "center"),
+ array("data" => form_checkbox(NULL, $block["module"]."][".$block["delta"]."][throttle", 1, $block["throttle"], NULL, variable_get("statistics_enable_auto_throttle", 0) ? NULL : array("disabled" => "disabled")), "align" => "center"),
+ form_weight(NULL, $block["module"]."][".$block["delta"]."][weight", $block["weight"]), form_radios(NULL, $block["module"]."][".$block["delta"]."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"]."][".$block["delta"]."][path", $block["path"], 10, 255),
+ $edit, $delete);
}
$output = theme("table", $header, $rows);
@@ -373,7 +377,17 @@ function block_list($region) {
while ($result && ($block = db_fetch_array($result))) {
if ((($block['status'] && (!$user->uid || !$block['custom'])) || ($block['custom'] && $user->block[$block['module']][$block['delta']])) && (!$block['path'] || preg_match($block['path'], str_replace("?q=", "", request_uri())))) {
- $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
+
+ /*
+ ** If congestion control is enabled, check current throttle status
+ ** and see if block should be displayed based on server load.
+ */
+ if ((module_invoke("throttle", "status") < 5) && $block['throttle'] && variable_get("statistics_enable_auto_throttle", 0)) {
+ $block['content'] = t('This block has been temporarily disabled as we are currently experiencing excessive load on our webserver. The block will be automatically reenabled when the webserver is less busy.');
+ }
+ else {
+ $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
+ }
if ($block['content']) {
$blocks[$region]["$block[module]_$block[delta]"] = (object) $block;
}
diff --git a/modules/forum.module b/modules/forum.module
index 9b1b08c350e56eb9334aa006816af9c29dbf8915..eaedf11e26f0ab9be90f8339122da79163fc1714 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -33,7 +33,7 @@ function forum_settings() {
$group = form_select(t("Forum vocabulary"), "forum_nav_vocabulary", variable_get("forum_nav_vocabulary", ""), $vocs, t("The taxonomy vocabulary that will be used as the navigation tree. The vacabulary's terms define the forums."));
$group .= _taxonomy_term_select(t("Containers"), "forum_containers", variable_get("forum_containers", array()), variable_get("forum_nav_vocabulary", ""), t("You can choose forums which will not have topics, but will be just containers for other forums. This lets you both group and nest forums."), 1, t(""));
- $output = form_group(t("Forum structure"), $group);
+ $output = form_group(t('Forum structure settings'), $group);
$group = form_textarea(t("Explanation or submission guidelines"), "forum_help", variable_get("forum_help", ""), 70, 5, t("This text will be displayed at the top of the forum submission form. Useful for helping or instructing your users."));
$group .= form_textfield(t("Forum icon path"), "forum_icon_path", variable_get("forum_icon_path", ""), 30, 255, t("The path to the forum icons. Leave blank to disable icons. Don't add a trailing slash. Default icons are available in the 'misc' directory."));
@@ -43,10 +43,10 @@ function forum_settings() {
$group .= form_select(t("Topics per page"), "forum_per_page", variable_get("forum_per_page", 25), $number, t("The default number of topics displayed per page; links to browse older messages are automatically being displayed."));
$forder = array(1 => t("Date - newest first"), 2 => t("Date - oldest first"), 3 => t("Posts - most active first"), 4=> t("Posts - least active first"));
$group .= form_radios(t("Default order"), "forum_order", variable_get("forum_order", "1"), $forder, t("The default display order for topics."));
- $output .= form_group(t("Forum viewing options"), $group);
+ $output .= form_group(t('Forum viewing options'), $group);
$group = form_textfield(t("Number of topics in block"), "forum_block_num", variable_get("forum_block_num", "5"), 5, 5, t("The number of topics to show in the \"Forum topics\" block. To enable the block, click ". l("here", "admin/system/block") ."."));
- $output .= form_group(t('"Forum topic" block'), $group);
+ $output .= form_group(t('"Forum topic" block settings'), $group);
}
}
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 9b1b08c350e56eb9334aa006816af9c29dbf8915..eaedf11e26f0ab9be90f8339122da79163fc1714 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -33,7 +33,7 @@ function forum_settings() {
$group = form_select(t("Forum vocabulary"), "forum_nav_vocabulary", variable_get("forum_nav_vocabulary", ""), $vocs, t("The taxonomy vocabulary that will be used as the navigation tree. The vacabulary's terms define the forums."));
$group .= _taxonomy_term_select(t("Containers"), "forum_containers", variable_get("forum_containers", array()), variable_get("forum_nav_vocabulary", ""), t("You can choose forums which will not have topics, but will be just containers for other forums. This lets you both group and nest forums."), 1, t(""));
- $output = form_group(t("Forum structure"), $group);
+ $output = form_group(t('Forum structure settings'), $group);
$group = form_textarea(t("Explanation or submission guidelines"), "forum_help", variable_get("forum_help", ""), 70, 5, t("This text will be displayed at the top of the forum submission form. Useful for helping or instructing your users."));
$group .= form_textfield(t("Forum icon path"), "forum_icon_path", variable_get("forum_icon_path", ""), 30, 255, t("The path to the forum icons. Leave blank to disable icons. Don't add a trailing slash. Default icons are available in the 'misc' directory."));
@@ -43,10 +43,10 @@ function forum_settings() {
$group .= form_select(t("Topics per page"), "forum_per_page", variable_get("forum_per_page", 25), $number, t("The default number of topics displayed per page; links to browse older messages are automatically being displayed."));
$forder = array(1 => t("Date - newest first"), 2 => t("Date - oldest first"), 3 => t("Posts - most active first"), 4=> t("Posts - least active first"));
$group .= form_radios(t("Default order"), "forum_order", variable_get("forum_order", "1"), $forder, t("The default display order for topics."));
- $output .= form_group(t("Forum viewing options"), $group);
+ $output .= form_group(t('Forum viewing options'), $group);
$group = form_textfield(t("Number of topics in block"), "forum_block_num", variable_get("forum_block_num", "5"), 5, 5, t("The number of topics to show in the \"Forum topics\" block. To enable the block, click ". l("here", "admin/system/block") ."."));
- $output .= form_group(t('"Forum topic" block'), $group);
+ $output .= form_group(t('"Forum topic" block settings'), $group);
}
}
diff --git a/modules/user.module b/modules/user.module
index 3ef65910431c0de751eccb8b6f8cffdb9bd41aae..2c40b86321a6cdc41a921fca640f76236c51bfa8 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -383,52 +383,39 @@ function user_block($op = "list", $delta = 0) {
}
case 3:
if (user_access("access content")) {
- /* utilize auto-throttle to disable when this site is too busy */
- if (function_exists("throttle_status"))
- $throttle = throttle_status();
- else
- $throttle = 0;
-
- /* be sure the site isn't too busy prior to performing db queries */
- if ($throttle < 5) {
- /* count users with activity in the past defined period */
- $time_period = variable_get("user_block_seconds_online", 2700);
-
- /* perform database queries to gather online user lists */
- $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period));
- $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period );
- $total_users = db_affected_rows();
-
- /* format the output with proper grammar */
- if ($total_users == 1 && $guests->count == 1) {
- $output = t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
- }
- else {
- $output = t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
- }
+ /* count users with activity in the past defined period */
+ $time_period = variable_get("user_block_seconds_online", 2700);
- if (user_access("access user list") && $total_users) {
- /* Display a list of currently online users */
- $max_users = variable_get("user_block_max_list_count", 10);
- $items = array();
- while ($uid = db_fetch_object($users)) {
- $items[] = format_name(user_load(array("uid" => $uid->uid)));
- }
-
- if ($items) {
- $output .= "
";
- $output .= theme("item_list", $items, t("Online users:"));
- }
- }
+ /* perform database queries to gather online user lists */
+ $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period));
+ $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period );
+ $total_users = db_affected_rows();
+
+ /* format the output with proper grammar */
+ if ($total_users == 1 && $guests->count == 1) {
+ $output = t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
}
else {
- /* the site is too busy -- display a simple "too busy" message */
- $output = t("This site is currently sustaining more than %total page views a minute.", array("%total" => ($throttle * variable_get("statistics_throttle_multiplier", 60))));
+ $output = t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
+ }
+
+ if (user_access("access user list") && $total_users) {
+ /* Display a list of currently online users */
+ $max_users = variable_get("user_block_max_list_count", 10);
+ $items = array();
+ while ($uid = db_fetch_object($users)) {
+ $items[] = format_name(user_load(array("uid" => $uid->uid)));
+ }
+
+ if ($items) {
+ $output .= "
";
+ $output .= theme("item_list", $items, t("Online users:"));
+ }
}
- $block["subject"] = t("Who's online");
- $block["content"] = $output;
- return $block;
}
+ $block["subject"] = t("Who's online");
+ $block["content"] = $output;
+ return $block;
}
}
}
diff --git a/modules/user/user.module b/modules/user/user.module
index 3ef65910431c0de751eccb8b6f8cffdb9bd41aae..2c40b86321a6cdc41a921fca640f76236c51bfa8 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -383,52 +383,39 @@ function user_block($op = "list", $delta = 0) {
}
case 3:
if (user_access("access content")) {
- /* utilize auto-throttle to disable when this site is too busy */
- if (function_exists("throttle_status"))
- $throttle = throttle_status();
- else
- $throttle = 0;
-
- /* be sure the site isn't too busy prior to performing db queries */
- if ($throttle < 5) {
- /* count users with activity in the past defined period */
- $time_period = variable_get("user_block_seconds_online", 2700);
-
- /* perform database queries to gather online user lists */
- $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period));
- $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period );
- $total_users = db_affected_rows();
-
- /* format the output with proper grammar */
- if ($total_users == 1 && $guests->count == 1) {
- $output = t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
- }
- else {
- $output = t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
- }
+ /* count users with activity in the past defined period */
+ $time_period = variable_get("user_block_seconds_online", 2700);
- if (user_access("access user list") && $total_users) {
- /* Display a list of currently online users */
- $max_users = variable_get("user_block_max_list_count", 10);
- $items = array();
- while ($uid = db_fetch_object($users)) {
- $items[] = format_name(user_load(array("uid" => $uid->uid)));
- }
-
- if ($items) {
- $output .= "
";
- $output .= theme("item_list", $items, t("Online users:"));
- }
- }
+ /* perform database queries to gather online user lists */
+ $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period));
+ $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period );
+ $total_users = db_affected_rows();
+
+ /* format the output with proper grammar */
+ if ($total_users == 1 && $guests->count == 1) {
+ $output = t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
}
else {
- /* the site is too busy -- display a simple "too busy" message */
- $output = t("This site is currently sustaining more than %total page views a minute.", array("%total" => ($throttle * variable_get("statistics_throttle_multiplier", 60))));
+ $output = t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
+ }
+
+ if (user_access("access user list") && $total_users) {
+ /* Display a list of currently online users */
+ $max_users = variable_get("user_block_max_list_count", 10);
+ $items = array();
+ while ($uid = db_fetch_object($users)) {
+ $items[] = format_name(user_load(array("uid" => $uid->uid)));
+ }
+
+ if ($items) {
+ $output .= "
";
+ $output .= theme("item_list", $items, t("Online users:"));
+ }
}
- $block["subject"] = t("Who's online");
- $block["content"] = $output;
- return $block;
}
+ $block["subject"] = t("Who's online");
+ $block["content"] = $output;
+ return $block;
}
}
}
diff --git a/update.php b/update.php
index acedf0054246412bae0d2fc7f840a528866f3651..6b28a512c2becb786bea225fb6bed47586eba138 100644
--- a/update.php
+++ b/update.php
@@ -60,7 +60,8 @@
"2003-10-20" => "update_68",
"2003-10-22" => "update_69",
"2003-10-27" => "update_70",
- "2003-11-17" => "update_71"
+ "2003-11-17" => "update_71",
+ "2003-11-27" => "update_72"
);
function update_32() {
@@ -552,6 +553,10 @@ function update_71() {
update_sql("ALTER TABLE {system} ADD bootstrap int(2)");
}
+function update_72() {
+ update_sql("ALTER TABLE {blocks} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
+}
+
/*
** System functions
*/