Commit fcae7030 authored by Dries's avatar Dries

- Committed Jeremy's incarnation of the statistics module.  Last minutes
  changes include:

    * a couple of coding style changes, renamed some "stats" into
      "statistics", etc.

    * removed the "Who's online" block from the user module.

    * added db_affected_rows() to the resp. database abstraction
      layers and made the statistics module use db_affected_rows()
      instead.

    * added update logic to "update.php".
parent 30315c40
......@@ -108,4 +108,8 @@ function db_next_id($name) {
return $id;
}
?>
\ No newline at end of file
function db_affected_rows() {
return mysql_affected_rows();
}
?>
......@@ -106,4 +106,10 @@ function db_next_id($name) {
return $db_handle->nextID($name);
}
function db_affected_rows() {
global $db_handle;
return $db_handle->affectedRows();
}
?>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -89,6 +89,20 @@ function user_load($array = array()) {
}
function user_save($account, $array = array()) {
/*
** Validate input fields to make sure users don't submit
** invalid form data.
*/
if (!user_access("administer users")) {
if (array_intersect(array_keys($array), array("rid", "init", "rating", "session"))) {
watchdog("warning", "detected malicious attempt to alter a protected user field");
}
unset($array["rid"], $array["init"], $array["rating"], $array["session"]);
}
/*
** Dynamically compose a SQL query:
*/
......@@ -344,32 +358,9 @@ function user_block() {
$block[1]["info"] = t("Log in");
$block[1]["link"] = drupal_url(array("mod" => "user"), "module");
$result = db_query("SELECT uid, name FROM users WHERE timestamp > %d - %d ORDER BY timestamp DESC", time(), 30 * 60);
if (db_num_rows($result)) {
$output = "";
while ($account = db_fetch_object($result)) {
$output .= lm((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), array("mod" => "user", "op" => "view", "id" => $account->uid)) ."<br />";
}
$block[2]["content"] = $output;
}
$block[2]["subject"] = t("Who's online");
$block[2]["info"] = t("Who's online");
$block[3]["subject"] = t("Who's new");
$block[3]["info"] = t("Who's new");
$block[3]["content"] = user_new_users();
return $block;
}
function user_new_users() {
$result = db_query("SELECT uid, name FROM users WHERE status != '0' ORDER BY uid DESC LIMIT 5");
while ($account = db_fetch_object($result)) {
$output .= lm((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), array("mod" =>user, "op" => "view", "id" => $account->uid)) ."<br />";
}
return $output;
}
function user_link($type) {
if ($type == "page") {
$links[] = lm(t("user account"), array("mod" => "user"), "", array("title" => t("Create a user account, request a new password or edit your account settings.")));
......@@ -899,21 +890,6 @@ function user_edit($edit = array()) {
}
unset($edit["pass1"], $edit["pass2"]);
/*
** Validate input fields to make sure users don't submit
** invalid form data.
*/
if (!user_access("administer users")) {
if (array_intersect(array_keys($edit), array("rid", "init", "rating", "session"))) {
watchdog("warning", "detected malicious attempt to alter a protected database field");
}
$edit["rid"] = $user->rid;
$edit["init"] = $user->init;
$edit["rating"] = $user->rating;
$edit["session"] = $user->session;
}
if (!$error) {
/*
......
......@@ -89,6 +89,20 @@ function user_load($array = array()) {
}
function user_save($account, $array = array()) {
/*
** Validate input fields to make sure users don't submit
** invalid form data.
*/
if (!user_access("administer users")) {
if (array_intersect(array_keys($array), array("rid", "init", "rating", "session"))) {
watchdog("warning", "detected malicious attempt to alter a protected user field");
}
unset($array["rid"], $array["init"], $array["rating"], $array["session"]);
}
/*
** Dynamically compose a SQL query:
*/
......@@ -344,32 +358,9 @@ function user_block() {
$block[1]["info"] = t("Log in");
$block[1]["link"] = drupal_url(array("mod" => "user"), "module");
$result = db_query("SELECT uid, name FROM users WHERE timestamp > %d - %d ORDER BY timestamp DESC", time(), 30 * 60);
if (db_num_rows($result)) {
$output = "";
while ($account = db_fetch_object($result)) {
$output .= lm((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), array("mod" => "user", "op" => "view", "id" => $account->uid)) ."<br />";
}
$block[2]["content"] = $output;
}
$block[2]["subject"] = t("Who's online");
$block[2]["info"] = t("Who's online");
$block[3]["subject"] = t("Who's new");
$block[3]["info"] = t("Who's new");
$block[3]["content"] = user_new_users();
return $block;
}
function user_new_users() {
$result = db_query("SELECT uid, name FROM users WHERE status != '0' ORDER BY uid DESC LIMIT 5");
while ($account = db_fetch_object($result)) {
$output .= lm((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), array("mod" =>user, "op" => "view", "id" => $account->uid)) ."<br />";
}
return $output;
}
function user_link($type) {
if ($type == "page") {
$links[] = lm(t("user account"), array("mod" => "user"), "", array("title" => t("Create a user account, request a new password or edit your account settings.")));
......@@ -899,21 +890,6 @@ function user_edit($edit = array()) {
}
unset($edit["pass1"], $edit["pass2"]);
/*
** Validate input fields to make sure users don't submit
** invalid form data.
*/
if (!user_access("administer users")) {
if (array_intersect(array_keys($edit), array("rid", "init", "rating", "session"))) {
watchdog("warning", "detected malicious attempt to alter a protected database field");
}
$edit["rid"] = $user->rid;
$edit["init"] = $user->init;
$edit["rating"] = $user->rating;
$edit["session"] = $user->session;
}
if (!$error) {
/*
......
......@@ -52,7 +52,8 @@
"2002-08-19" => "update_37",
"2002-08-26" => "update_38",
"2002-09-15" => "update_39",
"2002-09-17" => "update_40"
"2002-09-17" => "update_40",
"2002-10-13" => "update_41"
);
// Update functions
......@@ -588,6 +589,33 @@ function update_40() {
}
}
function update_41() {
if (db_result(db_query("SELECT COUNT(daycount) FROM statistics;")) > 0) {
// NOTE: "daycount" is a newly introduced field so we use that to determine whether we need to wipe the tables.
update_sql("DROP TABLE IF EXISTS statistics;");
update_sql("CREATE TABLE statistics (
nid int(11) NOT NULL,
totalcount bigint UNSIGNED DEFAULT '0' NOT NULL,
daycount mediumint UNSIGNED DEFAULT '0' NOT NULL,
timestamp int(11) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (nid),
INDEX (totalcount),
INDEX (daycount),
INDEX (timestamp)
);");
update_sql("DROP TABLE IF EXISTS accesslog;");
update_sql("CREATE TABLE accesslog (
nid int(11) UNSIGNED DEFAULT '0',
url varchar(255),
hostname varchar(128),
uid int(10) UNSIGNED DEFAULT '0',
timestamp int(11) UNSIGNED NOT NULL
);");
}
}
function update_upgrade3() {
update_sql("INSERT INTO system VALUES ('archive.module','archive','module','',1);");
update_sql("INSERT INTO system VALUES ('block.module','block','module','',1);");
......
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