diff options
author | Dries Buytaert <dries@buytaert.net> | 2002-11-09 13:59:36 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2002-11-09 13:59:36 +0000 |
commit | 562df8fe43f8794317c974dae463f5470cfdc497 (patch) | |
tree | 73d897d51f8b1873eff41193733d309495d01aea /modules | |
parent | 29adfb4086c8ef6102d9f22f5351382485444be5 (diff) | |
download | brdo-562df8fe43f8794317c974dae463f5470cfdc497.tar.gz brdo-562df8fe43f8794317c974dae463f5470cfdc497.tar.bz2 |
* Added Jeremy's pager:
"This is a simple, generic pager for Drupal-CVS. It is designed to be
easily themeable and expandable. The code is highly-commented to
enhance readability."
"Pagers are constructed by combining the provided pieces (all of which
can be easily modified to display the text or image you prefer) into
your custom pager."
* Statistics module fixes by Jeremy:
- removed superfluous check for existence of watchdog()
- saving changes in admin page displays status and returns same page
- no longer return 1971/01/01 in "view statistics" table
- switched from "!=" to "<>" in SQL queries for ANSI-SQL compliance
- switched from "MAX(timestamp) as timestamp" to "MAX(timestamp) as
max_timestamp" moving towards ANSI-SQL compliance.
* Added a "theme_item_list" function to format itemized lists. Also
changed a couple of modules to take advantage of it. Makes for a
more consistent UI.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/blog.module | 6 | ||||
-rw-r--r-- | modules/blog/blog.module | 6 | ||||
-rw-r--r-- | modules/forum.module | 13 | ||||
-rw-r--r-- | modules/forum/forum.module | 13 | ||||
-rw-r--r-- | modules/node.module | 15 | ||||
-rw-r--r-- | modules/node/node.module | 15 | ||||
-rw-r--r-- | modules/statistics.module | 120 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 120 | ||||
-rw-r--r-- | modules/user.module | 47 | ||||
-rw-r--r-- | modules/user/user.module | 47 |
10 files changed, 188 insertions, 214 deletions
diff --git a/modules/blog.module b/modules/blog.module index ef75b500d..b603884fc 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -343,10 +343,10 @@ function blog_block($op = "list", $delta = 0) { if (user_access("access content")) { $result = db_query("SELECT u.uid, u.name, n.created, n.title, n.nid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10"); while ($node = db_fetch_object($result)) { - $output .= l(check_output($node->title), array("id" => $node->nid)) ."<br />\n"; + $items[] = l(check_output($node->title), array("id" => $node->nid)); } - $output .= "<br /><div align=\"right\">". lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>"; - $block["content"] = $output; + + $block["content"] = theme_invoke("theme_item_list", $items) ."<br /><div align=\"right\">". lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>"; $block["subject"] = t("User blogs"); } return $block; diff --git a/modules/blog/blog.module b/modules/blog/blog.module index ef75b500d..b603884fc 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -343,10 +343,10 @@ function blog_block($op = "list", $delta = 0) { if (user_access("access content")) { $result = db_query("SELECT u.uid, u.name, n.created, n.title, n.nid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10"); while ($node = db_fetch_object($result)) { - $output .= l(check_output($node->title), array("id" => $node->nid)) ."<br />\n"; + $items[] = l(check_output($node->title), array("id" => $node->nid)); } - $output .= "<br /><div align=\"right\">". lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>"; - $block["content"] = $output; + + $block["content"] = theme_invoke("theme_item_list", $items) ."<br /><div align=\"right\">". lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>"; $block["subject"] = t("User blogs"); } return $block; diff --git a/modules/forum.module b/modules/forum.module index f7a78c7d2..81308d5dd 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -96,18 +96,21 @@ function forum_block($op = "list", $delta = 0) { } if (!$content) { - $content = "<b>". t("Active forum topics:") ."</b><br />"; + unset($items); $result = db_query("SELECT n.nid, n.title, n.body, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM node n, forum f LEFT JOIN comments c ON c.nid = n.nid WHERE n.type = 'forum' AND n.nid = f.nid AND f.shadow = 0 AND n.status = 1 GROUP BY n.nid ORDER BY sort DESC LIMIT ". variable_get("forum_block_num", "5")); while ($node = db_fetch_object($result)) { - $content .= "- ". l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")) ."<br />"; + $items[] = l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")); } + $content .= theme_invoke("theme_item_list", $items, t("Active forum topics:")); $content .= "<br />"; - $content .= "<b>". t("New forum topics:") ."</b><br />"; + + unset ($items); $result = db_query("SELECT n.nid, n.title, n.body FROM node n LEFT JOIN forum f ON n.nid = f.nid WHERE n.type = 'forum' ORDER BY n.nid DESC LIMIT ". variable_get("forum_block_num", "5")); while ($node = db_fetch_object($result)) { - $content .= "- ". l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")) ."<br />"; + $items[] = l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")); } + $content .= theme_invoke("theme_item_list", $items, t("New forum topics:")); if ($content) { $content .= "<div align=\"right\">". lm(t("more"), array("mod" => "forum")) ."</div>"; @@ -182,7 +185,7 @@ function forum_view($node, $main = 0) { $voc = taxonomy_get_vocabulary($term_data->vid); /* TODO: find out what this code was ment to do and either use it or not. - + $output .= "<p>"._forum_get_icon($node)." ".lm(check_output($voc->name), array("mod" => "forum"))." : ".lm(check_output($term_data->name), array("mod" => "forum", "tid" => $term_data->tid)); $output .= " / <b>". check_output($node->title) ."</b><br>".t("%a by %b", array("%a" => format_date($node->created), "%b" => format_name($node)))."</p><p>". check_output($node->body, 1) ."</p>"; diff --git a/modules/forum/forum.module b/modules/forum/forum.module index f7a78c7d2..81308d5dd 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -96,18 +96,21 @@ function forum_block($op = "list", $delta = 0) { } if (!$content) { - $content = "<b>". t("Active forum topics:") ."</b><br />"; + unset($items); $result = db_query("SELECT n.nid, n.title, n.body, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM node n, forum f LEFT JOIN comments c ON c.nid = n.nid WHERE n.type = 'forum' AND n.nid = f.nid AND f.shadow = 0 AND n.status = 1 GROUP BY n.nid ORDER BY sort DESC LIMIT ". variable_get("forum_block_num", "5")); while ($node = db_fetch_object($result)) { - $content .= "- ". l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")) ."<br />"; + $items[] = l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")); } + $content .= theme_invoke("theme_item_list", $items, t("Active forum topics:")); $content .= "<br />"; - $content .= "<b>". t("New forum topics:") ."</b><br />"; + + unset ($items); $result = db_query("SELECT n.nid, n.title, n.body FROM node n LEFT JOIN forum f ON n.nid = f.nid WHERE n.type = 'forum' ORDER BY n.nid DESC LIMIT ". variable_get("forum_block_num", "5")); while ($node = db_fetch_object($result)) { - $content .= "- ". l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")) ."<br />"; + $items[] = l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => substr(strip_tags($node->body), 0, 100)."...")); } + $content .= theme_invoke("theme_item_list", $items, t("New forum topics:")); if ($content) { $content .= "<div align=\"right\">". lm(t("more"), array("mod" => "forum")) ."</div>"; @@ -182,7 +185,7 @@ function forum_view($node, $main = 0) { $voc = taxonomy_get_vocabulary($term_data->vid); /* TODO: find out what this code was ment to do and either use it or not. - + $output .= "<p>"._forum_get_icon($node)." ".lm(check_output($voc->name), array("mod" => "forum"))." : ".lm(check_output($term_data->name), array("mod" => "forum", "tid" => $term_data->tid)); $output .= " / <b>". check_output($node->title) ."</b><br>".t("%a by %b", array("%a" => format_date($node->created), "%b" => format_name($node)))."</p><p>". check_output($node->body, 1) ."</p>"; diff --git a/modules/node.module b/modules/node.module index a9c4863f9..38718cb52 100644 --- a/modules/node.module +++ b/modules/node.module @@ -491,7 +491,7 @@ function node_admin_nodes() { $queries = array(array("ORDER BY n.created DESC", "new nodes"), array("ORDER BY n.changed DESC", "updated nodes"), array("WHERE n.status = 1 AND n.moderate = 0 ORDER BY n.nid DESC", "published nodes"), array("WHERE n.status = 0 AND n.moderate = 0 ORDER BY n.nid DESC", "non-published nodes"), array("WHERE n.status = 1 AND n.moderate = 1 ORDER BY n.nid DESC", "pending nodes"), array("WHERE n.status = 1 AND n.promote = 1 ORDER BY n.nid DESC", "promoted nodes")); - $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0] ." LIMIT 50"); + $result = db_query_pager("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0], 50); foreach ($queries as $key => $value) { $links[] = la($value[1], array("mod" => "node", "op" => "nodes", "query" => $key)); @@ -504,7 +504,8 @@ function node_admin_nodes() { while ($node = db_fetch_object($result)) { $output .= "<tr><td>". l(check_output($node->title), array("id" => $node->nid)) ."</td><td>". module_invoke($node->type, "node", "name") ."</td><td nowrap=\"nowrap\">". format_name($node) ."</td><td>". ($node->status ? t("published") : t("not published")) ."</td><td nowrap=\"nowrap\">". la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)) ."</td><td nowrap=\"nowrap\">". la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid)) ."</td></tr>"; } - $output .= "</table>"; + $output .= "<tr><td colspan=\"6\">". pager_display(NULL, 50, 0, "admin") ."</td></tr></table>"; + return $output; } @@ -1296,19 +1297,21 @@ function node_page() { if ($or) { // this is an OR of terms - $result = db_query("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + $result = db_query_pager("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); } else if ($and) { // this is an AND - $result = db_query("SELECT n.nid, type, count(*) AS c FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid HAVING c = ".count($terms)." ORDER BY static DESC, created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + $result = db_query_pager("SELECT n.nid, type, count(*) AS c FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid HAVING c = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); } else { - $result = db_query("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + $result = db_query_pager("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + } while ($node = db_fetch_object($result)) { node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); } + print pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); } } @@ -1334,4 +1337,4 @@ function node_update_index() { "select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM node n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")"); } -?>
\ No newline at end of file +?> diff --git a/modules/node/node.module b/modules/node/node.module index a9c4863f9..38718cb52 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -491,7 +491,7 @@ function node_admin_nodes() { $queries = array(array("ORDER BY n.created DESC", "new nodes"), array("ORDER BY n.changed DESC", "updated nodes"), array("WHERE n.status = 1 AND n.moderate = 0 ORDER BY n.nid DESC", "published nodes"), array("WHERE n.status = 0 AND n.moderate = 0 ORDER BY n.nid DESC", "non-published nodes"), array("WHERE n.status = 1 AND n.moderate = 1 ORDER BY n.nid DESC", "pending nodes"), array("WHERE n.status = 1 AND n.promote = 1 ORDER BY n.nid DESC", "promoted nodes")); - $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0] ." LIMIT 50"); + $result = db_query_pager("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0], 50); foreach ($queries as $key => $value) { $links[] = la($value[1], array("mod" => "node", "op" => "nodes", "query" => $key)); @@ -504,7 +504,8 @@ function node_admin_nodes() { while ($node = db_fetch_object($result)) { $output .= "<tr><td>". l(check_output($node->title), array("id" => $node->nid)) ."</td><td>". module_invoke($node->type, "node", "name") ."</td><td nowrap=\"nowrap\">". format_name($node) ."</td><td>". ($node->status ? t("published") : t("not published")) ."</td><td nowrap=\"nowrap\">". la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)) ."</td><td nowrap=\"nowrap\">". la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid)) ."</td></tr>"; } - $output .= "</table>"; + $output .= "<tr><td colspan=\"6\">". pager_display(NULL, 50, 0, "admin") ."</td></tr></table>"; + return $output; } @@ -1296,19 +1297,21 @@ function node_page() { if ($or) { // this is an OR of terms - $result = db_query("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + $result = db_query_pager("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); } else if ($and) { // this is an AND - $result = db_query("SELECT n.nid, type, count(*) AS c FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid HAVING c = ".count($terms)." ORDER BY static DESC, created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + $result = db_query_pager("SELECT n.nid, type, count(*) AS c FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid HAVING c = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); } else { - $result = db_query("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + $result = db_query_pager("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); + } while ($node = db_fetch_object($result)) { node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); } + print pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); } } @@ -1334,4 +1337,4 @@ function node_update_index() { "select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM node n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")"); } -?>
\ No newline at end of file +?> diff --git a/modules/statistics.module b/modules/statistics.module index 890c43c3c..58fd7140b 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -192,14 +192,14 @@ If '<i>administer statistics</i>' and '<i>access statistics</i>' are both enable <p>The module automatically adds '# reads' to each node's link section (if enabled).</p> <h3>Top stories</h3> -<p>The statistics.module provides a function '<i>statistics_display_linked_title($type)</i>' to return a linked title of any of the following: the top viewed node of all time, the top viewed node of today, the last viewed node. You can pass in: +<p>The statistics.module provides a function '<i>statistics_title_list($type)</i>' to return an array of links to any of the following: the top viewed nodes of all time, the top viewed nodes of today, the last viewed nodes. You can pass in: <ul> - <li><i>totalcount</i> - This will return a link to the top viewed node of all time.<br /> - Example: <code>statistics_display_linked_title("totalcount");</code><br /><br /></li> - <li><i>daycount</i> - This will return a link to the top viewed node for today.<br /> - Example: <code>statistics_display_linked_title("daycount");</code><br /><br /></li> - <li><i>timestamp</i> - This will return a link to the last viewed node.<br /> - Example: <code>statistics_display_linked_title("timestamp");</code></li> + <li><i>totalcount</i> - This will return an array with links to the top viewed nodes of all time.<br /> + Example: <code>statistics_title_list("totalcount");</code><br /><br /></li> + <li><i>daycount</i> - This will return an array with links to the top viewed nodes for today.<br /> + Example: <code>statistics_title_list("daycount");</code><br /><br /></li> + <li><i>timestamp</i> - This will return a array with links to the last viewed node.<br /> + Example: <code>statistics_title_list("timestamp");</code></li> </ul> <h3>Throttle</h3> @@ -260,17 +260,10 @@ function statistics_admin() { /* configuration admin pages */ if (user_access("administer statistics module")) { - $op = stripslashes($op); - switch ($op) { + switch (stripslashes($op)) { case "Submit \"top nodes\" block changes": - print status(statistics_save_topnodes_block($edit)); - break; - case "Submit \"who's online\" block changes": - print status(statistics_save_online_block($edit)); - break; - case "Submit \"top nodes\" page changes": - print status(statistics_save_userconfig($edit)); - break; + statistics_save_topnodes_block($edit); + print status(t("Saved top nodes block changes")); case "top nodes block": print statistics_config_topnodes_block(array( "statistics_block_top_title" => variable_get("statistics_block_top_title", "Top nodes"), @@ -282,6 +275,9 @@ function statistics_admin() { "statistics_block_top_last_num" => variable_get("statistics_block_top_last_num", 0) )); break; + case "Submit \"who's online\" block changes": + statistics_save_online_block($edit); + print status(t("Saved who's online block changes")); case "whos online block": print statistics_config_online_block(array( "statistics_block_online_title" => variable_get("statistics_block_online_title", "Whos online"), @@ -291,6 +287,9 @@ function statistics_admin() { "statistics_block_online_max_cnt" => variable_get("statistics_block_online_max_cnt", 10) )); break; + case "Submit \"top nodes\" page changes": + statistics_save_userconfig($edit); + print status(t("Saved top nodes page changes")); case "top nodes page": print statistics_admin_userpage_config(array( "statistics_userpage_link" => variable_get("statistics_userpage_link", ""), @@ -302,14 +301,6 @@ function statistics_admin() { "statistics_userpage_last_cnt" => variable_get("statistics_userpage_last_cnt", 0) )); break; - case "submit statistics config": - print status(statistics_save_statistics($edit)); - break; - break; - case "reset day counter": - db_query("UPDATE statistics SET daycount='0'"); - variable_set("statistics_day_timestamp", time()); - break; default: print statistics_admin_displaycounts(); break; @@ -321,7 +312,7 @@ function statistics_admin() { /* Displays the various admin tables */ function statistics_admin_count_table($dbfield, $dbrows) { - $result = db_query("SELECT statistics.nid, statistics.daycount, statistics.totalcount, statistics.timestamp, node.title FROM statistics LEFT JOIN node USING (nid) ORDER BY statistics.%s DESC LIMIT %s", $dbfield, $dbrows); + $result = db_query("SELECT statistics.nid, statistics.daycount, statistics.totalcount, statistics.timestamp, node.title FROM statistics LEFT JOIN node USING (nid) WHERE statistics.%s <> '0' ORDER BY statistics.%s DESC LIMIT %s", $dbfield, $dbfield, $dbrows); $output = "<table border=\"1\" cellpadding=\"3\" cellspacing =\"0\"><tr><th>title</th><th>today</th><th>all time</th><th>last hit</th><th>referrers</th></tr>\n"; @@ -350,7 +341,7 @@ function statistics_admin_accesslog_table($type, $id) { } else { /* retrieve recent access logs for all users */ - $result = db_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM accesslog WHERE uid != '0' GROUP BY uid ORDER BY timestamp DESC LIMIT %s", $limit1); + $result = db_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS max_timestamp FROM accesslog WHERE uid <> '0' GROUP BY uid ORDER BY max_timestamp DESC LIMIT %s", $limit1); } } else if ($type == 2) { @@ -404,7 +395,7 @@ function statistics_recent_refer($nid = 0) { if ($nid > 0) { if ($view == "all") { - $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url <> '' ORDER BY timestamp DESC LIMIT 15"; } elseif ($view == "internal") { $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url LIKE '%". check_input($HTTP_HOST) ."%' ORDER BY timestamp DESC LIMIT 15"; @@ -412,7 +403,7 @@ function statistics_recent_refer($nid = 0) { } else { /* default to external referrers */ - $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' ORDER BY timestamp DESC LIMIT 15"; $describe = "external "; } @@ -421,14 +412,14 @@ function statistics_recent_refer($nid = 0) { } else { if ($view == "all") { - $query = "SELECT url,timestamp FROM accesslog WHERE url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE url <> '' ORDER BY timestamp DESC LIMIT 15"; } elseif ($view == "internal") { $query = "SELECT url,timestamp FROM accesslog WHERE url LIKE '%". check_input($HTTP_HOST) ."%' ORDER BY timestamp DESC LIMIT 15"; $describe = "internal "; } else { - $query = "SELECT url,timestamp FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' ORDER BY timestamp DESC LIMIT 15"; $describe = "external "; } @@ -455,7 +446,7 @@ function statistics_top_refer($nid = 0) { if ($nid > 0) { if ($view == "all") { - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url <> '' GROUP BY url ORDER BY count DESC"; } elseif ($view == "internal") { $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url LIKE '%". check_input($HTTP_HOST) ."%' GROUP BY url ORDER BY count DESC"; @@ -463,7 +454,7 @@ function statistics_top_refer($nid = 0) { } else { /* default to external */ - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; $describe = "external "; } @@ -471,7 +462,7 @@ function statistics_top_refer($nid = 0) { } else { if ($view == "all") { - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url <> '' GROUP BY url ORDER BY count DESC"; } elseif ($view == "internal") { $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url LIKE '%". check_input($HTTP_HOST) ."%' GROUP BY url ORDER BY count DESC"; @@ -479,7 +470,7 @@ function statistics_top_refer($nid = 0) { } else { /* default to external */ - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; $describe = "external "; } @@ -694,42 +685,31 @@ function statistics_cron() { /* If throttle is on, back off one notch to test server load */ variable_set("statistics_throttle_level", $throttle - 1); variable_set("statistics_throttle_cron_timestamp", time()); - if (function_exists("watchdog")) { - watchdog("warning", "cron: decreasing throttle to level '". ($throttle - 1) ."' to test server load."); - } + watchdog("warning", "cron: decreasing throttle to level '". ($throttle - 1) ."' to test server load."); } } /* Displays the "Top nodes" block */ function statistics_display_topnodes_block() { - global $id; - $output = ""; $daytop = variable_get("statistics_block_top_day_num", ""); if ($daytop) { - $dayheading = variable_get("statistics_block_top_day_head", ""); - if ($dayheading) { - $output .= $dayheading ."<br />"; - } - $output .= statistics_display_linked_title("daycount", $daytop) ."<br />"; + $content[] = theme_invoke("theme_item_list", statistics_title_list("daycount", $daytop), variable_get("statistics_block_top_day_head", "")); } + $alltimetop = variable_get("statistics_block_top_all_num", ""); if ($alltimetop) { - $alltimeheading = variable_get("statistics_block_top_all_head", ""); - if ($alltimeheading) { - $output .= $alltimeheading ."<br />"; - } - $output .= statistics_display_linked_title("totalcount", $alltimetop) ."<br />"; + $content[] = theme_invoke("theme_item_list", statistics_title_list("totalcount", $alltimetop), variable_get("statistics_block_top_all_head", "")); } + $lasttop = variable_get("statistics_block_top_last_num", ""); if ($lasttop) { - $lastheading = variable_get("statistics_block_top_last_head", ""); - if ($lastheading) { - $output .= $lastheading ."<br />"; - } - $output .= statistics_display_linked_title("timestamp", $lasttop); + $content[] = theme_invoke("theme_item_list", statistics_title_list("timestamp", $lasttop), variable_get("statistics_block_top_last_head", "")); } + + $output = implode($content, "<br />"); + return $output; } @@ -750,7 +730,7 @@ function statistics_display_online_block() { ** This call gathers all the info we need on users/guests in a single ** database call, thus is quite efficient. */ - $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) as timestamp FROM accesslog WHERE timestamp >= '%s' GROUP BY uid ORDER BY timestamp DESC", (time() - $time_period)); + $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM accesslog WHERE timestamp >= '%s' GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period)); $users = $guests = 0; /* Count number of users & guests currently online based on db query */ @@ -769,6 +749,7 @@ function statistics_display_online_block() { $guests = $users_online["count"]; } } + /* format the output with proper grammar */ if ($users == 1) { $output = "There is currently "; @@ -785,12 +766,11 @@ function statistics_display_online_block() { /* Display a list of currently online users */ $max_users = variable_get("statistics_block_online_max_cnt", 10); $max_name_len = variable_get("statistics_block_online_max_len", 15); - $output .= "<br /><br />\n<b>". variable_get("statistics_block_online_subtitle", "Online users:") ."</b><br />\n"; $uid = reset($user_list); while (($uid) && ($max_users)) { $user = user_load(array("uid" => $uid)); /* When displaying name, be sure it's not more than defined max length */ - $output .= " - ". lm((strlen($user->name) > $max_name_len ? substr($user->name, 0, $max_name_len) . '...' : $user->name), array("mod" => "user", "op" => "view", "id" => $user->uid)) ."<br />"; + $items[] = lm((strlen($user->name) > $max_name_len ? substr($user->name, 0, $max_name_len) . '...' : $user->name), array("mod" => "user", "op" => "view", "id" => $user->uid)); $uid = next($user_list); /* ** When $max_users reaches zero, we break out even if there are @@ -798,6 +778,9 @@ function statistics_display_online_block() { */ $max_users--; } + + $output .= "<br /><br />"; + $output .= theme_invoke("theme_item_list", $items, variable_get("statistics_block_online_subtitle", "Online users:")); } } else { @@ -809,16 +792,15 @@ function statistics_display_online_block() { /* Display linked title based on field name */ -function statistics_display_linked_title($dbfield, $dbrows) { +function statistics_title_list($dbfield, $dbrows) { /* valid dbfields: totalcount, daycount, timestamp */ - $output = ""; - $result = db_query("SELECT statistics.nid, node.title FROM statistics LEFT JOIN node ON statistics.nid = node.nid ORDER BY %s DESC LIMIT %s", $dbfield, $dbrows); + $result = db_query("SELECT statistics.nid, node.title FROM statistics LEFT JOIN node ON statistics.nid = node.nid WHERE %s <> '0' ORDER BY %s DESC LIMIT %s", $dbfield, $dbfield, $dbrows); while ($nid = db_fetch_array($result)) { - $output .= " - ". l($nid["title"], array("id" => $nid["nid"]), "node", "", array("title" => t("View this posting."))) ."<br />"; + $items[] = l($nid["title"], array("id" => $nid["nid"]), "node", "", array("title" => t("View this posting."))); } - return $output; + return $items; } @@ -956,13 +938,11 @@ function throttle_update($recent_activity) { */ variable_set("statistics_throttle_cron_timestamp", time()); /* log the change */ - if (function_exists(watchdog)) { - if ($throttle_new < $throttle) { - watchdog("message", "message: '". $recent_activity ."' hits in past minute; throttle decreased to level ". $throttle_new); - } - else { - watchdog("warning", "warning: '". $recent_activity ."' hits in past minute; throttle increased to level ". $throttle_new); - } + if ($throttle_new < $throttle) { + watchdog("message", "message: '". $recent_activity ."' hits in past minute; throttle decreased to level ". $throttle_new); + } + else { + watchdog("warning", "warning: '". $recent_activity ."' hits in past minute; throttle increased to level ". $throttle_new); } } } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 890c43c3c..58fd7140b 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -192,14 +192,14 @@ If '<i>administer statistics</i>' and '<i>access statistics</i>' are both enable <p>The module automatically adds '# reads' to each node's link section (if enabled).</p> <h3>Top stories</h3> -<p>The statistics.module provides a function '<i>statistics_display_linked_title($type)</i>' to return a linked title of any of the following: the top viewed node of all time, the top viewed node of today, the last viewed node. You can pass in: +<p>The statistics.module provides a function '<i>statistics_title_list($type)</i>' to return an array of links to any of the following: the top viewed nodes of all time, the top viewed nodes of today, the last viewed nodes. You can pass in: <ul> - <li><i>totalcount</i> - This will return a link to the top viewed node of all time.<br /> - Example: <code>statistics_display_linked_title("totalcount");</code><br /><br /></li> - <li><i>daycount</i> - This will return a link to the top viewed node for today.<br /> - Example: <code>statistics_display_linked_title("daycount");</code><br /><br /></li> - <li><i>timestamp</i> - This will return a link to the last viewed node.<br /> - Example: <code>statistics_display_linked_title("timestamp");</code></li> + <li><i>totalcount</i> - This will return an array with links to the top viewed nodes of all time.<br /> + Example: <code>statistics_title_list("totalcount");</code><br /><br /></li> + <li><i>daycount</i> - This will return an array with links to the top viewed nodes for today.<br /> + Example: <code>statistics_title_list("daycount");</code><br /><br /></li> + <li><i>timestamp</i> - This will return a array with links to the last viewed node.<br /> + Example: <code>statistics_title_list("timestamp");</code></li> </ul> <h3>Throttle</h3> @@ -260,17 +260,10 @@ function statistics_admin() { /* configuration admin pages */ if (user_access("administer statistics module")) { - $op = stripslashes($op); - switch ($op) { + switch (stripslashes($op)) { case "Submit \"top nodes\" block changes": - print status(statistics_save_topnodes_block($edit)); - break; - case "Submit \"who's online\" block changes": - print status(statistics_save_online_block($edit)); - break; - case "Submit \"top nodes\" page changes": - print status(statistics_save_userconfig($edit)); - break; + statistics_save_topnodes_block($edit); + print status(t("Saved top nodes block changes")); case "top nodes block": print statistics_config_topnodes_block(array( "statistics_block_top_title" => variable_get("statistics_block_top_title", "Top nodes"), @@ -282,6 +275,9 @@ function statistics_admin() { "statistics_block_top_last_num" => variable_get("statistics_block_top_last_num", 0) )); break; + case "Submit \"who's online\" block changes": + statistics_save_online_block($edit); + print status(t("Saved who's online block changes")); case "whos online block": print statistics_config_online_block(array( "statistics_block_online_title" => variable_get("statistics_block_online_title", "Whos online"), @@ -291,6 +287,9 @@ function statistics_admin() { "statistics_block_online_max_cnt" => variable_get("statistics_block_online_max_cnt", 10) )); break; + case "Submit \"top nodes\" page changes": + statistics_save_userconfig($edit); + print status(t("Saved top nodes page changes")); case "top nodes page": print statistics_admin_userpage_config(array( "statistics_userpage_link" => variable_get("statistics_userpage_link", ""), @@ -302,14 +301,6 @@ function statistics_admin() { "statistics_userpage_last_cnt" => variable_get("statistics_userpage_last_cnt", 0) )); break; - case "submit statistics config": - print status(statistics_save_statistics($edit)); - break; - break; - case "reset day counter": - db_query("UPDATE statistics SET daycount='0'"); - variable_set("statistics_day_timestamp", time()); - break; default: print statistics_admin_displaycounts(); break; @@ -321,7 +312,7 @@ function statistics_admin() { /* Displays the various admin tables */ function statistics_admin_count_table($dbfield, $dbrows) { - $result = db_query("SELECT statistics.nid, statistics.daycount, statistics.totalcount, statistics.timestamp, node.title FROM statistics LEFT JOIN node USING (nid) ORDER BY statistics.%s DESC LIMIT %s", $dbfield, $dbrows); + $result = db_query("SELECT statistics.nid, statistics.daycount, statistics.totalcount, statistics.timestamp, node.title FROM statistics LEFT JOIN node USING (nid) WHERE statistics.%s <> '0' ORDER BY statistics.%s DESC LIMIT %s", $dbfield, $dbfield, $dbrows); $output = "<table border=\"1\" cellpadding=\"3\" cellspacing =\"0\"><tr><th>title</th><th>today</th><th>all time</th><th>last hit</th><th>referrers</th></tr>\n"; @@ -350,7 +341,7 @@ function statistics_admin_accesslog_table($type, $id) { } else { /* retrieve recent access logs for all users */ - $result = db_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM accesslog WHERE uid != '0' GROUP BY uid ORDER BY timestamp DESC LIMIT %s", $limit1); + $result = db_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS max_timestamp FROM accesslog WHERE uid <> '0' GROUP BY uid ORDER BY max_timestamp DESC LIMIT %s", $limit1); } } else if ($type == 2) { @@ -404,7 +395,7 @@ function statistics_recent_refer($nid = 0) { if ($nid > 0) { if ($view == "all") { - $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url <> '' ORDER BY timestamp DESC LIMIT 15"; } elseif ($view == "internal") { $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url LIKE '%". check_input($HTTP_HOST) ."%' ORDER BY timestamp DESC LIMIT 15"; @@ -412,7 +403,7 @@ function statistics_recent_refer($nid = 0) { } else { /* default to external referrers */ - $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE nid='$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' ORDER BY timestamp DESC LIMIT 15"; $describe = "external "; } @@ -421,14 +412,14 @@ function statistics_recent_refer($nid = 0) { } else { if ($view == "all") { - $query = "SELECT url,timestamp FROM accesslog WHERE url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE url <> '' ORDER BY timestamp DESC LIMIT 15"; } elseif ($view == "internal") { $query = "SELECT url,timestamp FROM accesslog WHERE url LIKE '%". check_input($HTTP_HOST) ."%' ORDER BY timestamp DESC LIMIT 15"; $describe = "internal "; } else { - $query = "SELECT url,timestamp FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' ORDER BY timestamp DESC LIMIT 15"; + $query = "SELECT url,timestamp FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' ORDER BY timestamp DESC LIMIT 15"; $describe = "external "; } @@ -455,7 +446,7 @@ function statistics_top_refer($nid = 0) { if ($nid > 0) { if ($view == "all") { - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url <> '' GROUP BY url ORDER BY count DESC"; } elseif ($view == "internal") { $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url LIKE '%". check_input($HTTP_HOST) ."%' GROUP BY url ORDER BY count DESC"; @@ -463,7 +454,7 @@ function statistics_top_refer($nid = 0) { } else { /* default to external */ - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE nid = '$nid' AND url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; $describe = "external "; } @@ -471,7 +462,7 @@ function statistics_top_refer($nid = 0) { } else { if ($view == "all") { - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url <> '' GROUP BY url ORDER BY count DESC"; } elseif ($view == "internal") { $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url LIKE '%". check_input($HTTP_HOST) ."%' GROUP BY url ORDER BY count DESC"; @@ -479,7 +470,7 @@ function statistics_top_refer($nid = 0) { } else { /* default to external */ - $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url != '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url NOT LIKE '%". check_input($HTTP_HOST) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; $describe = "external "; } @@ -694,42 +685,31 @@ function statistics_cron() { /* If throttle is on, back off one notch to test server load */ variable_set("statistics_throttle_level", $throttle - 1); variable_set("statistics_throttle_cron_timestamp", time()); - if (function_exists("watchdog")) { - watchdog("warning", "cron: decreasing throttle to level '". ($throttle - 1) ."' to test server load."); - } + watchdog("warning", "cron: decreasing throttle to level '". ($throttle - 1) ."' to test server load."); } } /* Displays the "Top nodes" block */ function statistics_display_topnodes_block() { - global $id; - $output = ""; $daytop = variable_get("statistics_block_top_day_num", ""); if ($daytop) { - $dayheading = variable_get("statistics_block_top_day_head", ""); - if ($dayheading) { - $output .= $dayheading ."<br />"; - } - $output .= statistics_display_linked_title("daycount", $daytop) ."<br />"; + $content[] = theme_invoke("theme_item_list", statistics_title_list("daycount", $daytop), variable_get("statistics_block_top_day_head", "")); } + $alltimetop = variable_get("statistics_block_top_all_num", ""); if ($alltimetop) { - $alltimeheading = variable_get("statistics_block_top_all_head", ""); - if ($alltimeheading) { - $output .= $alltimeheading ."<br />"; - } - $output .= statistics_display_linked_title("totalcount", $alltimetop) ."<br />"; + $content[] = theme_invoke("theme_item_list", statistics_title_list("totalcount", $alltimetop), variable_get("statistics_block_top_all_head", "")); } + $lasttop = variable_get("statistics_block_top_last_num", ""); if ($lasttop) { - $lastheading = variable_get("statistics_block_top_last_head", ""); - if ($lastheading) { - $output .= $lastheading ."<br />"; - } - $output .= statistics_display_linked_title("timestamp", $lasttop); + $content[] = theme_invoke("theme_item_list", statistics_title_list("timestamp", $lasttop), variable_get("statistics_block_top_last_head", "")); } + + $output = implode($content, "<br />"); + return $output; } @@ -750,7 +730,7 @@ function statistics_display_online_block() { ** This call gathers all the info we need on users/guests in a single ** database call, thus is quite efficient. */ - $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) as timestamp FROM accesslog WHERE timestamp >= '%s' GROUP BY uid ORDER BY timestamp DESC", (time() - $time_period)); + $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM accesslog WHERE timestamp >= '%s' GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period)); $users = $guests = 0; /* Count number of users & guests currently online based on db query */ @@ -769,6 +749,7 @@ function statistics_display_online_block() { $guests = $users_online["count"]; } } + /* format the output with proper grammar */ if ($users == 1) { $output = "There is currently "; @@ -785,12 +766,11 @@ function statistics_display_online_block() { /* Display a list of currently online users */ $max_users = variable_get("statistics_block_online_max_cnt", 10); $max_name_len = variable_get("statistics_block_online_max_len", 15); - $output .= "<br /><br />\n<b>". variable_get("statistics_block_online_subtitle", "Online users:") ."</b><br />\n"; $uid = reset($user_list); while (($uid) && ($max_users)) { $user = user_load(array("uid" => $uid)); /* When displaying name, be sure it's not more than defined max length */ - $output .= " - ". lm((strlen($user->name) > $max_name_len ? substr($user->name, 0, $max_name_len) . '...' : $user->name), array("mod" => "user", "op" => "view", "id" => $user->uid)) ."<br />"; + $items[] = lm((strlen($user->name) > $max_name_len ? substr($user->name, 0, $max_name_len) . '...' : $user->name), array("mod" => "user", "op" => "view", "id" => $user->uid)); $uid = next($user_list); /* ** When $max_users reaches zero, we break out even if there are @@ -798,6 +778,9 @@ function statistics_display_online_block() { */ $max_users--; } + + $output .= "<br /><br />"; + $output .= theme_invoke("theme_item_list", $items, variable_get("statistics_block_online_subtitle", "Online users:")); } } else { @@ -809,16 +792,15 @@ function statistics_display_online_block() { /* Display linked title based on field name */ -function statistics_display_linked_title($dbfield, $dbrows) { +function statistics_title_list($dbfield, $dbrows) { /* valid dbfields: totalcount, daycount, timestamp */ - $output = ""; - $result = db_query("SELECT statistics.nid, node.title FROM statistics LEFT JOIN node ON statistics.nid = node.nid ORDER BY %s DESC LIMIT %s", $dbfield, $dbrows); + $result = db_query("SELECT statistics.nid, node.title FROM statistics LEFT JOIN node ON statistics.nid = node.nid WHERE %s <> '0' ORDER BY %s DESC LIMIT %s", $dbfield, $dbfield, $dbrows); while ($nid = db_fetch_array($result)) { - $output .= " - ". l($nid["title"], array("id" => $nid["nid"]), "node", "", array("title" => t("View this posting."))) ."<br />"; + $items[] = l($nid["title"], array("id" => $nid["nid"]), "node", "", array("title" => t("View this posting."))); } - return $output; + return $items; } @@ -956,13 +938,11 @@ function throttle_update($recent_activity) { */ variable_set("statistics_throttle_cron_timestamp", time()); /* log the change */ - if (function_exists(watchdog)) { - if ($throttle_new < $throttle) { - watchdog("message", "message: '". $recent_activity ."' hits in past minute; throttle decreased to level ". $throttle_new); - } - else { - watchdog("warning", "warning: '". $recent_activity ."' hits in past minute; throttle increased to level ". $throttle_new); - } + if ($throttle_new < $throttle) { + watchdog("message", "message: '". $recent_activity ."' hits in past minute; throttle decreased to level ". $throttle_new); + } + else { + watchdog("warning", "warning: '". $recent_activity ."' hits in past minute; throttle increased to level ". $throttle_new); } } } diff --git a/modules/user.module b/modules/user.module index 23fc80a4a..d51974d34 100644 --- a/modules/user.module +++ b/modules/user.module @@ -314,8 +314,6 @@ function user_block($op = "list", $delta = 0) { switch ($delta) { case 0: if (!$user->uid) { - $block["subject"] = t("Log in"); - $output = "<div align=\"center\">\n"; $output .= "<form action=\"". drupal_url(array("mod" => "user", "op" => "login"), "module") ."\" method=\"post\">\n"; // Save the referer. We record where the user came from such that we @@ -334,46 +332,49 @@ function user_block($op = "list", $delta = 0) { $output .= "<br />\n<input name=\"edit[op]\" type=\"submit\" value=\"". t("Log in") ."\" /><br />\n"; $output .= "</form></div>\n"; + if (variable_get("user_register", 1)) { - $output .= "» ". lm(t("Register"), array("mod" => "user", "op" => "register"), "", array("title" => t("Create a new user account."))) ."<br />\n"; + $items[] = lm(t("Create new account"), array("mod" => "user", "op" => "register"), "", array("title" => t("Create a new user account."))); } - $output .= "» ". lm(t("New password"), array("mod" => "user", "op" => "password"), "", array("title" => t("Request new password via e-mail."))); + $items[] = lm(t("Request new password"), array("mod" => "user", "op" => "password"), "", array("title" => t("Request new password via e-mail."))); - $block["content"] = $output; + $output .= theme_invoke("theme_item_list", $items); + + $block["subject"] = t("Log in"); + $block["content"] = "<div style=\"{ width: 155; }\">$output</div>"; return $block; } break; case 1: if ($user->uid) { - // Display account settings: - $block["subject"] = $user->name; - - $output = "<div style=\"{ width: 155; }\">\n"; + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.create")); + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.view")); + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.settings")); + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.misc")); - $links = array_merge(module_invoke_all("link", "menu.create"), array(""), module_invoke_all("link", "menu.view"), array(""), module_invoke_all("link", "menu.settings"), array(""), module_invoke_all("link", "menu.misc")); - $output .= @implode("<br />\n", $links); + $output = implode($content, "<br />"); - $output .= "</div>"; - $block["content"] = $output; + $block["subject"] = $user->name; + $block["content"] = "<div style=\"{ width: 155; }\">$output</div>"; return $block; } break; case 2: + + $result = db_query("SELECT uid, name FROM users WHERE status != '0' ORDER BY uid DESC LIMIT 5"); + while ($account = db_fetch_object($result)) { + $items[] = lm((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), array("mod" =>user, "op" => "view", "id" => $account->uid)); + } + + $output = theme_invoke("theme_item_list", $items); + $block["subject"] = t("Who's new"); - $block["content"] = user_new_users(); + $block["content"] = $output; 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."))); @@ -619,7 +620,7 @@ function user_login($edit = array(), $msg = "") { $output .= form_password(t("Password"), "pass", $pass, 20, 64, t("Enter the password that accompanies your username.")); $output .= form_checkbox(t("Remember me"), "remember_me", 1, 0, 0); $output .= form_submit(t("Log in")); - $output .= "<p>» ". lm(t("E-mail new password"), array("mod" => "user", "op" => "password")). "<br />"; + $output .= "<p>» ". lm(t("Request new password"), array("mod" => "user", "op" => "password")). "<br />"; if (variable_get("user_register", 1)) { $output .= "» ". lm(t("Create new account"), array("mod" => "user", "op" => "register")); } diff --git a/modules/user/user.module b/modules/user/user.module index 23fc80a4a..d51974d34 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -314,8 +314,6 @@ function user_block($op = "list", $delta = 0) { switch ($delta) { case 0: if (!$user->uid) { - $block["subject"] = t("Log in"); - $output = "<div align=\"center\">\n"; $output .= "<form action=\"". drupal_url(array("mod" => "user", "op" => "login"), "module") ."\" method=\"post\">\n"; // Save the referer. We record where the user came from such that we @@ -334,46 +332,49 @@ function user_block($op = "list", $delta = 0) { $output .= "<br />\n<input name=\"edit[op]\" type=\"submit\" value=\"". t("Log in") ."\" /><br />\n"; $output .= "</form></div>\n"; + if (variable_get("user_register", 1)) { - $output .= "» ". lm(t("Register"), array("mod" => "user", "op" => "register"), "", array("title" => t("Create a new user account."))) ."<br />\n"; + $items[] = lm(t("Create new account"), array("mod" => "user", "op" => "register"), "", array("title" => t("Create a new user account."))); } - $output .= "» ". lm(t("New password"), array("mod" => "user", "op" => "password"), "", array("title" => t("Request new password via e-mail."))); + $items[] = lm(t("Request new password"), array("mod" => "user", "op" => "password"), "", array("title" => t("Request new password via e-mail."))); - $block["content"] = $output; + $output .= theme_invoke("theme_item_list", $items); + + $block["subject"] = t("Log in"); + $block["content"] = "<div style=\"{ width: 155; }\">$output</div>"; return $block; } break; case 1: if ($user->uid) { - // Display account settings: - $block["subject"] = $user->name; - - $output = "<div style=\"{ width: 155; }\">\n"; + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.create")); + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.view")); + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.settings")); + $content[] = theme_invoke("theme_item_list", module_invoke_all("link", "menu.misc")); - $links = array_merge(module_invoke_all("link", "menu.create"), array(""), module_invoke_all("link", "menu.view"), array(""), module_invoke_all("link", "menu.settings"), array(""), module_invoke_all("link", "menu.misc")); - $output .= @implode("<br />\n", $links); + $output = implode($content, "<br />"); - $output .= "</div>"; - $block["content"] = $output; + $block["subject"] = $user->name; + $block["content"] = "<div style=\"{ width: 155; }\">$output</div>"; return $block; } break; case 2: + + $result = db_query("SELECT uid, name FROM users WHERE status != '0' ORDER BY uid DESC LIMIT 5"); + while ($account = db_fetch_object($result)) { + $items[] = lm((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), array("mod" =>user, "op" => "view", "id" => $account->uid)); + } + + $output = theme_invoke("theme_item_list", $items); + $block["subject"] = t("Who's new"); - $block["content"] = user_new_users(); + $block["content"] = $output; 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."))); @@ -619,7 +620,7 @@ function user_login($edit = array(), $msg = "") { $output .= form_password(t("Password"), "pass", $pass, 20, 64, t("Enter the password that accompanies your username.")); $output .= form_checkbox(t("Remember me"), "remember_me", 1, 0, 0); $output .= form_submit(t("Log in")); - $output .= "<p>» ". lm(t("E-mail new password"), array("mod" => "user", "op" => "password")). "<br />"; + $output .= "<p>» ". lm(t("Request new password"), array("mod" => "user", "op" => "password")). "<br />"; if (variable_get("user_register", 1)) { $output .= "» ". lm(t("Create new account"), array("mod" => "user", "op" => "register")); } |