summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc1
-rw-r--r--includes/pager.inc310
-rw-r--r--includes/theme.inc18
-rw-r--r--modules/blog.module6
-rw-r--r--modules/blog/blog.module6
-rw-r--r--modules/forum.module13
-rw-r--r--modules/forum/forum.module13
-rw-r--r--modules/node.module15
-rw-r--r--modules/node/node.module15
-rw-r--r--modules/statistics.module120
-rw-r--r--modules/statistics/statistics.module120
-rw-r--r--modules/user.module47
-rw-r--r--modules/user/user.module47
13 files changed, 516 insertions, 215 deletions
diff --git a/includes/common.inc b/includes/common.inc
index dc1e5027a..b85c0530e 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -782,6 +782,7 @@ include_once "includes/database.inc";
include_once "includes/xmlrpc.inc";
include_once "includes/module.inc";
include_once "includes/theme.inc";
+include_once "includes/pager.inc";
// initialize configuration variables, using values from conf.php if available:
$conf = variable_init(isset($conf) ? $conf : array());
diff --git a/includes/pager.inc b/includes/pager.inc
new file mode 100644
index 000000000..a50937e9d
--- /dev/null
+++ b/includes/pager.inc
@@ -0,0 +1,310 @@
+<?php
+
+/*****************************************************
+ * external functions (API) *
+ *****************************************************/
+
+/*
+** PAGER DISPLAY:
+** Use this function in your module or theme to display a pager.
+** $tags: an array that defines your buttons; text or <img>.
+** $limit: how many nodes are displayed per page
+** $element: support for multiple pagers per page (specify which
+** this is)
+** $type: allows for distinction between pagers on main page and
+** admin page, etc. Supported types are "default", "admin"
+** and "simple".
+*/
+function pager_display($tags = "", $limit = 10, $element = 0, $type = "default") {
+ return theme_invoke("pager_display_". $type, $tags, $limit, $element);
+}
+
+/*
+** DEFAULT PAGER:
+** When writing themes, you can rewrite this pager function in your
+** theme. This is the most common pager type, and thus the main one
+** to re-write in your theme.
+*/
+function pager_display_default($tags = "", $limit = 10, $element = 0) {
+ $output .= "<center><table cellpadding=\"10\"><tbody><tr>";
+ $output .= "<td align=\"center\">". pager_first(($tags[0] ? $tags[0] : t("first page")), $limit, $element) ."</td>";
+ $output .= "<td align=\"center\">". pager_previous(($tags[1] ? $tags[1] : t("previous page")), $limit, $element) ."</td>";
+ $output .= "<td align=\"center\">". pager_list($limit, $element, ($tags[2] ? $tags[2] : 9 )) ."</td>";
+ $output .= "<td align=\"center\">". pager_next(($tags[3] ? $tags[3] : t("next page")), $limit, $element) ."</td>";
+ $output .= "<td align=\"center\">". pager_last(($tags[4] ? $tags[4] : t("last page")), $limit, $element) ."</td>";
+ $output .= "</tr></tbody></table></center>";
+
+ return "$output";
+}
+
+/*
+** SIMPLE PAGER:
+** When writing themes, if you rewrite this pager function in your
+** theme, keep in mind that the pager it defines is intended to have
+** a "simple" look, possibly located in a table or block.
+*/
+function pager_display_simple($tags = "", $limit = 10, $element = 0) {
+ /*
+ ** It's left as an exercise to theme writers to create an alternative
+ ** pager for pager_display_simple(). if your theme does not offer a
+ ** replacement, the theme.inc pager_display_default() is used.
+ */
+ return pager_display_default($tags, $limit, $element);
+}
+
+/*
+** ADMIN PAGER:
+** When writing themes, you can rewrite this pager function in your
+** theme. Most themes will probably NOT re-write this function, as
+** admin pages are not normally themed.
+*/
+function pager_display_admin($tags = "", $limit = 10, $element = 0) {
+ /*
+ ** It's left as an exercise to theme writers to create an alternative
+ ** pager for pager_display_admin(). if your theme does not offer a
+ ** replacement, the pager.inc pager_display_default() is used.
+ */
+ return pager_display_default($tags, $limit, $element);
+}
+
+/*********************************************************************
+* PAGER PIECES:
+* Use these pieces to construct your own custom pagers (i.e. in
+* themes). Note that you should NOT modify this file to customize
+* your pager)
+********************************************************************/
+
+/*
+** pager_first: displays a "first-page" link
+** $text: defines the name (or image) of the link
+** $limit: how many nodes are displayed per page
+** $element: distinguish between multiple pagers on one page
+*/
+function pager_first($text, $limit, $element = 0) {
+ global $from_array;
+
+ if ($from_array[$element]) {
+ return "<a href=\"". pager_link(pager_load_array(0, $element, $from_array)) ."\">$text</a>";
+ }
+ else {
+ // we are already at the first page, return nothing
+ return " ";
+ }
+}
+
+/*
+** pager_previous: displays a "previous-page" link
+** $text: defines the name (or image) of the link
+** $limit: how many nodes are displayed per page
+** $element: distinguish between multiple pagers on one page
+** $n: how many pages we move back (defaults to 1)
+*/
+function pager_previous($text, $limit, $element = 0, $n = 1) {
+ global $from_array;
+ $from_new = pager_load_array(((int)$from_array[$element] - ((int)$limit * (int)$n)), $element, $from_array);
+ if ($from_new[$element] < 1) {
+ return pager_first($text, $limit, $element);
+ }
+ return "<a href=\"". pager_link($from_new) ."\">$text</a>";
+}
+
+/*
+** pager_next: displays a "next-page" link
+** $text: defines the name (or image) of the link
+** $limit: how many nodes are displayed per page
+** $element: distinguish between multiple pagers on one page
+** $n: how many pages we move forward (defaults to 1)
+*/
+function pager_next($text, $limit, $element = 0, $n = 1) {
+ global $from_array, $pager_total;
+ $from_new = pager_load_array(((int)$from_array[$element] + ((int)$limit * (int)$n)), $element, $from_array);
+ if ($from_new[$element] < $pager_total[$element]) {
+ return "<a href=\"". pager_link($from_new) ."\">$text</a>";
+ }
+ return " ";
+}
+
+/*
+** pager_last: displays a "last-page" link
+** $text: defines the name (or image) of the link
+** $limit: how many nodes are displayed per page
+** $element: distinguish between multiple pagers on one page
+*/
+function pager_last($text, $limit, $element = 0) {
+ global $from_array, $pager_total;
+
+ $from_new = pager_load_array(($pager_total[$element] - $limit), $element, $from_array);
+ if ($from_new[$element] < ($from_array[$element] + $limit)) {
+ return pager_next($text, $limit, $element);
+ }
+ if (($from_new[$element] > $from_array[$element]) && ($from_new[$element] > 0) && $from_new[$element] < $pager_total[$element]) {
+ return "<a href=\"". pager_link($from_new) ."\">$text</a>";
+ }
+ return " ";
+}
+
+/*
+** pager_detail: displays "%d through %d of $d" type detail about the cur page
+** $limit: how many nodes are displayed per page
+** $element: distinguish between multiple pagers on one page
+** $format: allows you to reword the format string
+*/
+function pager_detail($limit, $element = 0, $format = "%d through %d of %d.") {
+ global $from_array, $pager_total;
+
+ if ($pager_total[$element] > (int)$from_array[$element] + 1) {
+ $output = sprintf($format, (int)$from_array[$element] + 1, ((int)$from_array[$element] + $limit <= $pager_total[$element] ? (int)$from_array[$element] + $limit : $pager_total[$element]), $pager_total[$element]);
+ }
+
+ return $output;
+}
+
+/*
+** pager_list: displays a list of nearby pages with additional nodes
+** $limit: how many nodes are displayed per page
+** $element: distinguish between multiple pagers on one page
+** $quantity: defines the length of the page list
+** $text: optional text to display before the page list
+*/
+function pager_list($limit, $element = 0, $quantity = 5, $text = "") {
+ global $from_array, $pager_total;
+
+// calculate various markers within this pager piece:
+ // middle used to "center" pages around current page
+ $pager_middle = ceil((int)$quantity / 2);
+ // offset adds "offset" second page
+ $pager_offset = (int)$from_array[$element] % (int)$limit;
+ // current is the page we are currently paged to
+ if (($pager_current = (ceil(($from_array[$element] + 1) / $limit))) < 1) {
+ $pager_current = 1;
+ }
+ // first is the first page listed by this pager piece (re quantity)
+ $pager_first = (int)$pager_current - (int)$pager_middle + 1;
+ // last is the last page listed by this pager piece (re quantity)
+ $pager_last = (int)$pager_current + (int)$quantity - (int)$pager_middle;
+ // max is the maximum number of pages content can is devided into
+ if (!$pager_max = (ceil($pager_total[$element] / $limit))) {
+ $pager_max = 1;
+ }
+ if ((int)$pager_offset) {
+ // adjust for offset second page
+ $pager_max++;
+ $pager_current++;
+ }
+// end of various marker calculations
+
+// prepare for generation loop
+ $i = (int)$pager_first;
+ if ($pager_last > $pager_max) {
+ // adjust "center" if at end of query
+ $i = $i + (int)($pager_max - $pager_last);
+ $pager_last = $pager_max;
+ }
+ if ($i <= 0) {
+ // adjust "center" if at start of query
+ $pager_last = $pager_last + (1 - $i);
+ $i = 1;
+ }
+// end of generation loop preparation
+
+ $output = "$text";
+ if ($i > 1) {
+ $output .= "... ";
+ }
+
+ // finally we're ready to generate the actual pager piece
+ for (; $i <= $pager_last && $i <= $pager_max; $i++) {
+ if ($i < $pager_current) {
+ $output .= pager_previous($i, $limit, $element, ($pager_current - $i)) ." ";
+ }
+ if ($i == $pager_current) {
+ $output .= "<b>$i</b> ";
+ }
+ if ($i > $pager_current) {
+ $output .= pager_next($i, $limit, $element, ($i - $pager_current)) ." ";
+ }
+ }
+
+ if ($i < $pager_max) {
+ $output .= "...";
+ }
+
+ return $output;
+}
+
+
+/*********************************************************************
+ * QUERIES - call this instead of db_query() if you want your query to
+ * support a pager.
+ *********************************************************************/
+
+/*
+** Use this function when doing select queries you wish to be able to page
+** $query, the database query *without* "LIMIT" in it
+** examples : "SELECT * FROM table"
+** : "SELECT field1,field2 FROM table WHERE nid = '1'"
+** $limit, how many rows to return (per page) [OPTIONAL]
+** $element, adds support for multiple paged tables on one page [OPTIONAL]
+*/
+function db_query_pager($query, $limit = 10, $element = 0) {
+ global $from, $from_array, $db_type, $pager_total;
+
+ // count the total number of records in this query:
+ $pager_total[$element] = array_pop(db_fetch_array(db_query(preg_replace("/SELECT.*FROM/i", "SELECT COUNT(*) as count FROM", $query))));
+
+ // convert comma separated $from to an array, used by other functions:
+ $from_array = explode(",", $from);
+
+ if ((int)$from_array[$element]) {
+ if ($db_type == "mysql") {
+ // MySQL formatted limit query with offset:
+ $limit_query = $query . " LIMIT " . (int)$from_array[$element] . ", $limit";
+ }
+ else {
+ // pear formatted limit query with offset:
+ $limit_query = $query . " LIMIT $limit OFFSET " . (int)$from_array[$element];
+ }
+ }
+ else {
+ // standard limit query without offset:
+ $limit_query = $query . " LIMIT $limit";
+ }
+ return db_query($limit_query);
+}
+
+function pager_link($from_new) {
+ $from_list = @implode(",", $from_new);
+ if ("$from_list" == "0") {
+ // single pager at zero, so remove the $from
+ return preg_replace(array("/from=*[^&]*/", "/[&]$/", "/[?]$/"), "", request_uri());
+ }
+ if (preg_match("/from=/", request_uri())) {
+ // replace existing from=
+ return preg_replace("/from=*[^&]*/", "from=$from_list", request_uri());
+ }
+ if (preg_match("/[?]/", request_uri())) {
+ // append &from=
+ $href = request_uri() . "&from=$from_list";
+ }
+ else {
+ // append ?from=
+ $href = request_uri() . "?from=$from_list";
+ }
+ return $href;
+}
+
+function pager_load_array($value, $element, $old_array) {
+ $new_array = $old_array;
+ // look for empty elements
+ for ($i = 0; $i < $element; $i++) {
+ if (!$new_array[$i]) {
+ // load found empty element with 0
+ $new_array[$i] = 0;
+ }
+ }
+ // update the changed element
+ $new_array[$element] = (int)$value;
+ return $new_array;
+}
+
+?>
diff --git a/includes/theme.inc b/includes/theme.inc
index da4d3ca06..e153258af 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -49,7 +49,7 @@ class BaseTheme {
$output .= "<small>(". $this->links($terms) .")</small><br />";
}
if ($main && $node->teaser) {
- $output .= strip_tags(check_output($node->teaser, 1));
+ $output .= check_output($node->teaser, 1);
}
else {
$output .= check_output($node->body, 1);
@@ -83,6 +83,22 @@ function theme_mark() {
return "<span style=\"color: red;\">*</span>";
}
+function theme_item_list($items = array(), $title = 0) {
+ /*
+ ** Return a formatted array of items.
+ */
+
+ if ($title) {
+ $output .= "<b>$title</b><br />";
+ }
+
+ foreach ($items as $item) {
+ $output .= "- $item<br />";
+ }
+
+ return $output;
+}
+
function theme_error($message) {
/*
** Return an error message.
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 .= "&raquo; ". 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 .= "&raquo; ". 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>&raquo; ". lm(t("E-mail new password"), array("mod" => "user", "op" => "password")). "<br />";
+ $output .= "<p>&raquo; ". lm(t("Request new password"), array("mod" => "user", "op" => "password")). "<br />";
if (variable_get("user_register", 1)) {
$output .= "&raquo; ". 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 .= "&raquo; ". 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 .= "&raquo; ". 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>&raquo; ". lm(t("E-mail new password"), array("mod" => "user", "op" => "password")). "<br />";
+ $output .= "<p>&raquo; ". lm(t("Request new password"), array("mod" => "user", "op" => "password")). "<br />";
if (variable_get("user_register", 1)) {
$output .= "&raquo; ". lm(t("Create new account"), array("mod" => "user", "op" => "register"));
}