Commit 562df8fe authored by Dries's avatar Dries

* 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.
parent 29adfb40
......@@ -782,6 +782,7 @@ function page_footer() {
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());
......
<?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;
}
?>
......@@ -49,7 +49,7 @@ function node($node, $main) {
$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.
......
......@@ -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;
......
......@@ -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;
......
......@@ -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>";
......
......@@ -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>";
......
......@@ -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
?>
......@@ -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
?>
......@@ -192,14 +192,14 @@ function statistics_help() {
<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>