diff options
author | Dries Buytaert <dries@buytaert.net> | 2003-03-14 20:41:27 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2003-03-14 20:41:27 +0000 |
commit | dc19b22fb8397dcd7697db09fbb808d91d9fc0c8 (patch) | |
tree | 628f268e91ba39a834251f865ba8543eaa408b02 /modules/node/node.module | |
parent | 1f2d2b73dd577bb915ffcf7316f388dbe9c22e01 (diff) | |
download | brdo-dc19b22fb8397dcd7697db09fbb808d91d9fc0c8.tar.gz brdo-dc19b22fb8397dcd7697db09fbb808d91d9fc0c8.tar.bz2 |
- Modified patch of Moshe. Enhances the tracker module so it displayes recent
*nodes* in addition to comments. This will be helpful for tracking down new
book nodes, blog posts, news items, and other stuff which isn't interesting
enough to be promoted to the home page.
Diffstat (limited to 'modules/node/node.module')
-rw-r--r-- | modules/node/node.module | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/modules/node/node.module b/modules/node/node.module index cbb475500..04611cdd9 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -37,6 +37,62 @@ function node_title_list($result, $title = NULL) { return theme("theme_item_list", $items, $title); } +// Update the 'last viewed' timestamp of the specified node for current user. +function node_tag_new($nid) { + global $user; + + if ($user->uid) { + $nid = check_query($nid); + + $result = db_query("SELECT timestamp FROM history WHERE uid = '%d' AND nid = '%d'", $user->uid, $nid); + if (db_fetch_object($result)) { + db_query("UPDATE history SET timestamp = '%d' WHERE uid = '%d' AND nid = '%d'", time(), $user->uid, $nid); + } + else { + db_query("INSERT INTO history (uid, nid, timestamp) VALUES ('%d', '%d', '%d')", $user->uid, $nid, time()); + } + } +} + +/* +** Retrieves the timestamp at which the current user last viewed the +** specified node. +*/ +function node_last_viewed($nid) { + global $user; + + $history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '$user->uid' AND nid = '%d'", $nid)); + return ($history->timestamp ? $history->timestamp : 0); +} + +/** + * Determines whether the supplied timestamp is newer than the user's last view of a given node + * + * @param $nid node-id twhose history supplies the 'last viewed' timestamp + * @param $timestamp time which is compared against node's 'last veiwed' timestamp +*/ +function node_is_new($nid, $timestamp) { + global $user; + static $cache; + + if (!$cache[$nid]) { + if ($user->uid) { + $history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '%d' AND nid = '%d'", $user->uid, $nid)); + $cache[$nid] = $history->timestamp ? $history->timestamp : 0; + } + else { + $cache[$nid] = time(); + } + } + + if ($timestamp > $cache[$nid]) { + return 1; + } + else { + return 0; + } +} + function node_teaser($body) { $size = variable_get("teaser_length", 600); @@ -299,6 +355,7 @@ function node_view($node, $main = 0) { } } + function node_show($nid, $cid) { global $revision; @@ -314,6 +371,12 @@ function node_show($nid, $cid) { if (function_exists("comment_render") && $node->comment) { comment_render($node, $cid); } + + /* + ** Update the history table, stating that this user viewed this node. + */ + + node_tag_new($node->nid); } } @@ -512,7 +575,7 @@ function node_admin_nodes() { $header = array(t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); while ($node = db_fetch_object($result)) { - $rows[] = array(l($node->title, "node/view/$node->nid"), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); + $rows[] = array(l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); } if ($pager = pager_display(NULL, 50, 0, "admin")) { |