diff options
-rw-r--r-- | modules/statistics.module | 78 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 78 |
2 files changed, 68 insertions, 88 deletions
diff --git a/modules/statistics.module b/modules/statistics.module index 282f00016..b46bc84c8 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -1,42 +1,9 @@ <?php // $Id$ -function statistics_init() { - global $recent_activity; - - /* - ** The following logic determines what the current throttle level should - ** be, and can be disabled by the admin. If enabled, the rand() function - ** returns a number between 0 and N, N being specified by the admin. If - ** 0 is returned, the throttle logic is run, adding on additional database - ** query. Otherwise, the following logic is skipped. This mechanism is - ** referred to in the admin page as the 'probability limiter', roughly - ** limiting throttle related database calls to 1 in N. - */ - if ((variable_get("statistics_enable_auto_throttle", 0)) && (!rand(0, variable_get("statistics_probability_limiter", 9)))) { - /* - ** Note: The rand() function is supported by PHP 3+. However, prior to - ** PHP 4.2.0 it needs to be seeded with a call to srand(). It is important - ** that this only happens once, so this should be managed by the Drupal - ** engine, not this module. The Drupal engine should use phpversion() to - ** detect and automatically seed pre-4.2.0 systems. - */ - - $throttle = throttle_status(); - // if we're at throttle level 5, we don't do anything - if ($throttle < 5) { - $multiplier = variable_get("statistics_throttle_multiplier", 60); - // count all hits in past sixty seconds - $result = db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60)); - $recent_activity = db_fetch_array($result); - throttle_update($recent_activity["hits"]); - } - } -} - // Exit hook, runs at the end of every page request function statistics_exit() { - global $user; + global $user, $recent_activity; if (variable_get("statistics_count_content_views", 0)) { // we are counting content views @@ -63,6 +30,35 @@ function statistics_exit() { db_query("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time()); } } + + /* + ** The following logic determines what the current throttle level should + ** be, and can be disabled by the admin. If enabled, the rand() function + ** returns a number between 0 and N, N being specified by the admin. If + ** 0 is returned, the throttle logic is run, adding on additional database + ** query. Otherwise, the following logic is skipped. This mechanism is + ** referred to in the admin page as the 'probability limiter', roughly + ** limiting throttle related database calls to 1 in N. + */ + if ((variable_get("statistics_enable_auto_throttle", 0)) && (!rand(0, variable_get("statistics_probability_limiter", 9)))) { + /* + ** Note: The rand() function is supported by PHP 3+. However, prior to + ** PHP 4.2.0 it needs to be seeded with a call to srand(). It is important + ** that this only happens once, so this should be managed by the Drupal + ** engine, not this module. The Drupal engine should use phpversion() to + ** detect and automatically seed pre-4.2.0 systems. + */ + + $throttle = throttle_status(); + // if we're at throttle level 5, we don't do anything + if ($throttle < 5) { + $multiplier = variable_get("statistics_throttle_multiplier", 60); + // count all hits in past sixty seconds + $result = db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60)); + $recent_activity = db_fetch_array($result); + _throttle_update($recent_activity["hits"]); + } + } } /* Permissions hook, defines module's permissions */ @@ -449,7 +445,6 @@ function statistics_settings() { $group .= form_select(t("Number of day's top views to display"), "statistics_userpage_day_cnt", variable_get("statistics_userpage_day_cnt", 0), array("0" => t("Disabled"), "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "15" => "15", "20" => "20", "25" => "25"), t("How many content items to display in the \"day\" list. Requires enabled content viewing counters.")); $group .= form_select(t("Number of all time top views to display"), "statistics_userpage_all_cnt", variable_get("statistics_userpage_all_cnt", 0), array("0" => t("Disabled"), "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "15" => "15", "20" => "20", "25" => "25"), t("How many content items to display in the \"all time\" list. Requires enabled content viewing counters.")); $group .= form_select(t("Number of most recent views to display"), "statistics_userpage_last_cnt", variable_get("statistics_userpage_last_cnt", 0), array("0" => t("Disabled"), "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "15" => "15", "20" => "20", "25" => "25"), t("How many posts to display in the \"recently viewed\" list. Requires enabled content viewing counters.")); - $output .= form_group(t("\"Popular content\" page settings"), $group); return $output; @@ -486,8 +481,6 @@ function statistics_cron() { } - - /* Display linked title based on field name */ function statistics_title_list($dbfield, $dbrows) { /* valid dbfields: totalcount, daycount, timestamp */ @@ -504,7 +497,6 @@ function statistics_get($nid) { } return $statistics; - } @@ -523,17 +515,17 @@ function statistics_block($op = "list", $delta = 0) { $daytop = variable_get("statistics_block_top_day_num", ""); if ($daytop) { - $content[] = node_title_list(statistics_title_list("daycount", $daytop), variable_get("statistics_block_top_day_head", "")); + $content[] = node_title_list(statistics_title_list("daycount", $daytop), t("Today's:")); } $alltimetop = variable_get("statistics_block_top_all_num", ""); if ($alltimetop) { - $content[] = node_title_list(statistics_title_list("totalcount", $alltimetop), variable_get("statistics_block_top_all_head", "")); + $content[] = node_title_list(statistics_title_list("totalcount", $alltimetop), t("All time:")); } $lasttop = variable_get("statistics_block_top_last_num", ""); if ($lasttop) { - $content[] = node_title_list(statistics_title_list("timestamp", $lasttop), variable_get("statistics_block_top_last_head", "")); + $content[] = node_title_list(statistics_title_list("timestamp", $lasttop), t("Last viewed:")); } $output = implode($content, "<br />"); @@ -548,8 +540,6 @@ function statistics_block($op = "list", $delta = 0) { function statistics_page() { - - if (user_access("access content")) { $output = ""; @@ -615,7 +605,7 @@ function statistics_nodeapi(&$node, $op, $arg = 0) { } /* internal throttle function - do not call from other modules */ -function throttle_update($recent_activity) { +function _throttle_update($recent_activity) { $throttle = throttle_status(); $multiplier = variable_get("statistics_throttle_multiplier", 60); diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 282f00016..b46bc84c8 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -1,42 +1,9 @@ <?php // $Id$ -function statistics_init() { - global $recent_activity; - - /* - ** The following logic determines what the current throttle level should - ** be, and can be disabled by the admin. If enabled, the rand() function - ** returns a number between 0 and N, N being specified by the admin. If - ** 0 is returned, the throttle logic is run, adding on additional database - ** query. Otherwise, the following logic is skipped. This mechanism is - ** referred to in the admin page as the 'probability limiter', roughly - ** limiting throttle related database calls to 1 in N. - */ - if ((variable_get("statistics_enable_auto_throttle", 0)) && (!rand(0, variable_get("statistics_probability_limiter", 9)))) { - /* - ** Note: The rand() function is supported by PHP 3+. However, prior to - ** PHP 4.2.0 it needs to be seeded with a call to srand(). It is important - ** that this only happens once, so this should be managed by the Drupal - ** engine, not this module. The Drupal engine should use phpversion() to - ** detect and automatically seed pre-4.2.0 systems. - */ - - $throttle = throttle_status(); - // if we're at throttle level 5, we don't do anything - if ($throttle < 5) { - $multiplier = variable_get("statistics_throttle_multiplier", 60); - // count all hits in past sixty seconds - $result = db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60)); - $recent_activity = db_fetch_array($result); - throttle_update($recent_activity["hits"]); - } - } -} - // Exit hook, runs at the end of every page request function statistics_exit() { - global $user; + global $user, $recent_activity; if (variable_get("statistics_count_content_views", 0)) { // we are counting content views @@ -63,6 +30,35 @@ function statistics_exit() { db_query("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time()); } } + + /* + ** The following logic determines what the current throttle level should + ** be, and can be disabled by the admin. If enabled, the rand() function + ** returns a number between 0 and N, N being specified by the admin. If + ** 0 is returned, the throttle logic is run, adding on additional database + ** query. Otherwise, the following logic is skipped. This mechanism is + ** referred to in the admin page as the 'probability limiter', roughly + ** limiting throttle related database calls to 1 in N. + */ + if ((variable_get("statistics_enable_auto_throttle", 0)) && (!rand(0, variable_get("statistics_probability_limiter", 9)))) { + /* + ** Note: The rand() function is supported by PHP 3+. However, prior to + ** PHP 4.2.0 it needs to be seeded with a call to srand(). It is important + ** that this only happens once, so this should be managed by the Drupal + ** engine, not this module. The Drupal engine should use phpversion() to + ** detect and automatically seed pre-4.2.0 systems. + */ + + $throttle = throttle_status(); + // if we're at throttle level 5, we don't do anything + if ($throttle < 5) { + $multiplier = variable_get("statistics_throttle_multiplier", 60); + // count all hits in past sixty seconds + $result = db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60)); + $recent_activity = db_fetch_array($result); + _throttle_update($recent_activity["hits"]); + } + } } /* Permissions hook, defines module's permissions */ @@ -449,7 +445,6 @@ function statistics_settings() { $group .= form_select(t("Number of day's top views to display"), "statistics_userpage_day_cnt", variable_get("statistics_userpage_day_cnt", 0), array("0" => t("Disabled"), "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "15" => "15", "20" => "20", "25" => "25"), t("How many content items to display in the \"day\" list. Requires enabled content viewing counters.")); $group .= form_select(t("Number of all time top views to display"), "statistics_userpage_all_cnt", variable_get("statistics_userpage_all_cnt", 0), array("0" => t("Disabled"), "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "15" => "15", "20" => "20", "25" => "25"), t("How many content items to display in the \"all time\" list. Requires enabled content viewing counters.")); $group .= form_select(t("Number of most recent views to display"), "statistics_userpage_last_cnt", variable_get("statistics_userpage_last_cnt", 0), array("0" => t("Disabled"), "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "15" => "15", "20" => "20", "25" => "25"), t("How many posts to display in the \"recently viewed\" list. Requires enabled content viewing counters.")); - $output .= form_group(t("\"Popular content\" page settings"), $group); return $output; @@ -486,8 +481,6 @@ function statistics_cron() { } - - /* Display linked title based on field name */ function statistics_title_list($dbfield, $dbrows) { /* valid dbfields: totalcount, daycount, timestamp */ @@ -504,7 +497,6 @@ function statistics_get($nid) { } return $statistics; - } @@ -523,17 +515,17 @@ function statistics_block($op = "list", $delta = 0) { $daytop = variable_get("statistics_block_top_day_num", ""); if ($daytop) { - $content[] = node_title_list(statistics_title_list("daycount", $daytop), variable_get("statistics_block_top_day_head", "")); + $content[] = node_title_list(statistics_title_list("daycount", $daytop), t("Today's:")); } $alltimetop = variable_get("statistics_block_top_all_num", ""); if ($alltimetop) { - $content[] = node_title_list(statistics_title_list("totalcount", $alltimetop), variable_get("statistics_block_top_all_head", "")); + $content[] = node_title_list(statistics_title_list("totalcount", $alltimetop), t("All time:")); } $lasttop = variable_get("statistics_block_top_last_num", ""); if ($lasttop) { - $content[] = node_title_list(statistics_title_list("timestamp", $lasttop), variable_get("statistics_block_top_last_head", "")); + $content[] = node_title_list(statistics_title_list("timestamp", $lasttop), t("Last viewed:")); } $output = implode($content, "<br />"); @@ -548,8 +540,6 @@ function statistics_block($op = "list", $delta = 0) { function statistics_page() { - - if (user_access("access content")) { $output = ""; @@ -615,7 +605,7 @@ function statistics_nodeapi(&$node, $op, $arg = 0) { } /* internal throttle function - do not call from other modules */ -function throttle_update($recent_activity) { +function _throttle_update($recent_activity) { $throttle = throttle_status(); $multiplier = variable_get("statistics_throttle_multiplier", 60); |