summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-01-30 09:53:19 +0000
committerDries Buytaert <dries@buytaert.net>2005-01-30 09:53:19 +0000
commit59c2208ea68c4695fe0fa2122b786ac5eb748383 (patch)
tree6a1c3e3d1f1af6565ec7adde526f33e69727d61d
parent9f77077584b592de68ca3e59f92204b715e03006 (diff)
downloadbrdo-59c2208ea68c4695fe0fa2122b786ac5eb748383.tar.gz
brdo-59c2208ea68c4695fe0fa2122b786ac5eb748383.tar.bz2
- Patch #16253 by Goba: incremental improvements to the new content markers.
Goba: it would be nice if one of the core themes would showcase this functionality. ;-)
-rw-r--r--includes/theme.inc29
-rw-r--r--misc/drupal.css2
-rw-r--r--modules/comment.module9
-rw-r--r--modules/comment/comment.module9
-rw-r--r--modules/node.module28
-rw-r--r--modules/node/node.module28
-rw-r--r--modules/tracker.module2
-rw-r--r--modules/tracker/tracker.module2
8 files changed, 66 insertions, 43 deletions
diff --git a/includes/theme.inc b/includes/theme.inc
index e8539f3ca..c2698aef4 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -12,6 +12,19 @@
* @see themeable
*/
+ /**
+ * @name Content markers
+ * @{
+ * Markers used by theme_mark() and node_mark() to designate content.
+ * @see theme_mark(), node_mark()
+ */
+define('MARK_READ', 0);
+define('MARK_NEW', 1);
+define('MARK_UPDATED', 2);
+/**
+ * @} End of "Content markers".
+ */
+
/**
* Hook Help - returns theme specific help and information.
*
@@ -522,7 +535,7 @@ function theme_node($node, $teaser = FALSE, $page = FALSE) {
function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
$output = "<div class=\"form-item\">\n";
- $required = $required ? theme('mark', 'required') : '';
+ $required = $required ? '<span class="form-required">*</span>' : '';
if ($title) {
if ($id) {
@@ -695,16 +708,20 @@ function theme_block($block) {
}
/**
- * Return a themed marker, useful for marking new comments or required form
- * elements.
+ * Return a themed marker, useful for marking new or updated
+ * content.
*
* @param $type
- * Type of marker to return: 'new' or 'required'
+ * Number representing the marker type to display
+ * @see MARK_NEW, MARK_UPDATED, MARK_READ
* @return
* A string containing the marker.
*/
-function theme_mark($type = 'new') {
- return '<span class="marker">*</span>';
+function theme_mark($type = MARK_NEW) {
+ global $user;
+ if ($user->uid && $type != MARK_READ) {
+ return '<span class="marker">*</span>';
+ }
}
/**
diff --git a/misc/drupal.css b/misc/drupal.css
index 27978f48f..531a9c1b1 100644
--- a/misc/drupal.css
+++ b/misc/drupal.css
@@ -154,7 +154,7 @@ tr.light .form-item, tr.dark .form-item {
.form-submit {
margin: 0.5em 0;
}
-.marker {
+.marker, .form-required {
color: #f00;
}
.more-link {
diff --git a/modules/comment.module b/modules/comment.module
index 18c46f354..22c51bd15 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -1017,7 +1017,7 @@ function comment_admin_overview($type = 'new') {
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$rows[] = array(
- l($comment->subject, "node/$comment->nid", array('title' => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme('mark', 'new') : ''),
+ l($comment->subject, "node/$comment->nid", array('title' => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". theme('mark', node_mark($comment->nid, $comment->timestamp)),
format_name($comment),
($comment->status == 0 ? t('Published') : t('Not published')),
format_date($comment->timestamp, 'small'),
@@ -1428,8 +1428,7 @@ function theme_comment_view($comment, $links = '', $visible = 1) {
// Emit selectors:
$output = '';
- if (node_is_new($comment->nid, $comment->timestamp)) {
- $comment->new = 1;
+ if (($comment->new = node_mark($comment->nid, $comment->timestamp)) != MARK_READ) {
$output .= "<a id=\"new\"></a>\n";
}
@@ -1549,7 +1548,7 @@ function theme_comment_moderation_form($comment) {
function theme_comment($comment, $links = 0) {
$output = "<div class=\"comment\">\n";
- $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ($comment->new ? ' '. theme('mark', 'new') : '') ."</div>\n";
+ $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
$output .= '<div class="moderation">'. $comment->moderation ."</div>\n";
$output .= '<div class="credit">'. t('by %a on %b', array('%a' => format_name($comment), '%b' => format_date($comment->timestamp))) ."</div>\n";
$output .= "<div class=\"body\">$comment->comment</div>\n";
@@ -1560,7 +1559,7 @@ function theme_comment($comment, $links = 0) {
function theme_comment_folded($comment) {
$output = "<div class=\"comment-folded\">\n";
- $output .= ' <span class="subject">'. l($comment->subject, comment_node_url() .'/'. $comment->cid, NULL, NULL, "comment-$comment->cid") . ($comment->new ? ' '. theme('mark', 'new') : '') .'</span> ';
+ $output .= ' <span class="subject">'. l($comment->subject, comment_node_url() .'/'. $comment->cid, NULL, NULL, "comment-$comment->cid") . ' '. theme('mark', $comment->new) .'</span> ';
$output .= '<span class="credit">'. t('by') .' '. format_name($comment) ."</span>\n";
$output .= "</div>\n";
return $output;
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 18c46f354..22c51bd15 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -1017,7 +1017,7 @@ function comment_admin_overview($type = 'new') {
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$rows[] = array(
- l($comment->subject, "node/$comment->nid", array('title' => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme('mark', 'new') : ''),
+ l($comment->subject, "node/$comment->nid", array('title' => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". theme('mark', node_mark($comment->nid, $comment->timestamp)),
format_name($comment),
($comment->status == 0 ? t('Published') : t('Not published')),
format_date($comment->timestamp, 'small'),
@@ -1428,8 +1428,7 @@ function theme_comment_view($comment, $links = '', $visible = 1) {
// Emit selectors:
$output = '';
- if (node_is_new($comment->nid, $comment->timestamp)) {
- $comment->new = 1;
+ if (($comment->new = node_mark($comment->nid, $comment->timestamp)) != MARK_READ) {
$output .= "<a id=\"new\"></a>\n";
}
@@ -1549,7 +1548,7 @@ function theme_comment_moderation_form($comment) {
function theme_comment($comment, $links = 0) {
$output = "<div class=\"comment\">\n";
- $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ($comment->new ? ' '. theme('mark', 'new') : '') ."</div>\n";
+ $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
$output .= '<div class="moderation">'. $comment->moderation ."</div>\n";
$output .= '<div class="credit">'. t('by %a on %b', array('%a' => format_name($comment), '%b' => format_date($comment->timestamp))) ."</div>\n";
$output .= "<div class=\"body\">$comment->comment</div>\n";
@@ -1560,7 +1559,7 @@ function theme_comment($comment, $links = 0) {
function theme_comment_folded($comment) {
$output = "<div class=\"comment-folded\">\n";
- $output .= ' <span class="subject">'. l($comment->subject, comment_node_url() .'/'. $comment->cid, NULL, NULL, "comment-$comment->cid") . ($comment->new ? ' '. theme('mark', 'new') : '') .'</span> ';
+ $output .= ' <span class="subject">'. l($comment->subject, comment_node_url() .'/'. $comment->cid, NULL, NULL, "comment-$comment->cid") . ' '. theme('mark', $comment->new) .'</span> ';
$output .= '<span class="credit">'. t('by') .' '. format_name($comment) ."</span>\n";
$output .= "</div>\n";
return $output;
diff --git a/modules/node.module b/modules/node.module
index b21c4ea5e..63bc7b1df 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -125,28 +125,32 @@ function node_last_viewed($nid) {
}
/**
- * Determine whether the supplied timestamp is newer than the user's last view
- * of a given node.
+ * Decide on the type of marker to be displayed for a given node.
*
* @param $nid
* Node ID whose history supplies the "last viewed" timestamp.
* @param $timestamp
* Time which is compared against node's "last viewed" timestamp.
+ * @return
+ * One of the MARK constants.
*/
-function node_is_new($nid, $timestamp) {
+function node_mark($nid, $timestamp) {
global $user;
static $cache;
+ if (!$user->uid) {
+ return MARK_READ;
+ }
if (!isset($cache[$nid])) {
- if ($user->uid) {
- $cache[$nid] = node_last_viewed($nid);
- }
- else {
- $cache[$nid] = time();
- }
+ $cache[$nid] = node_last_viewed($nid);
}
-
- return ($timestamp > $cache[$nid] && $timestamp > NODE_NEW_LIMIT);
+ if ($cache[$nid] == 0 && $timestamp > NODE_NEW_LIMIT) {
+ return MARK_NEW;
+ }
+ elseif ($timestamp > $cache[$nid] && $timestamp > NODE_NEW_LIMIT) {
+ return MARK_UPDATED;
+ }
+ return MARK_READ;
}
/**
@@ -807,7 +811,7 @@ function node_admin_nodes() {
$header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), array('data' => t('Operations'), 'colspan' => '2'));
while ($node = db_fetch_object($result)) {
- $rows[] = array(form_checkbox(NULL, 'status]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. (node_is_new($node->nid, $node->changed) ? theme_mark() : ''), node_invoke($node, 'node_name'), format_name($node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit'), l(t('delete'), 'admin/node/delete/'. $node->nid));
+ $rows[] = array(form_checkbox(NULL, 'status]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), node_invoke($node, 'node_name'), format_name($node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit'), l(t('delete'), 'admin/node/delete/'. $node->nid));
}
if ($pager = theme('pager', NULL, 50, 0)) {
diff --git a/modules/node/node.module b/modules/node/node.module
index b21c4ea5e..63bc7b1df 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -125,28 +125,32 @@ function node_last_viewed($nid) {
}
/**
- * Determine whether the supplied timestamp is newer than the user's last view
- * of a given node.
+ * Decide on the type of marker to be displayed for a given node.
*
* @param $nid
* Node ID whose history supplies the "last viewed" timestamp.
* @param $timestamp
* Time which is compared against node's "last viewed" timestamp.
+ * @return
+ * One of the MARK constants.
*/
-function node_is_new($nid, $timestamp) {
+function node_mark($nid, $timestamp) {
global $user;
static $cache;
+ if (!$user->uid) {
+ return MARK_READ;
+ }
if (!isset($cache[$nid])) {
- if ($user->uid) {
- $cache[$nid] = node_last_viewed($nid);
- }
- else {
- $cache[$nid] = time();
- }
+ $cache[$nid] = node_last_viewed($nid);
}
-
- return ($timestamp > $cache[$nid] && $timestamp > NODE_NEW_LIMIT);
+ if ($cache[$nid] == 0 && $timestamp > NODE_NEW_LIMIT) {
+ return MARK_NEW;
+ }
+ elseif ($timestamp > $cache[$nid] && $timestamp > NODE_NEW_LIMIT) {
+ return MARK_UPDATED;
+ }
+ return MARK_READ;
}
/**
@@ -807,7 +811,7 @@ function node_admin_nodes() {
$header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), array('data' => t('Operations'), 'colspan' => '2'));
while ($node = db_fetch_object($result)) {
- $rows[] = array(form_checkbox(NULL, 'status]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. (node_is_new($node->nid, $node->changed) ? theme_mark() : ''), node_invoke($node, 'node_name'), format_name($node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit'), l(t('delete'), 'admin/node/delete/'. $node->nid));
+ $rows[] = array(form_checkbox(NULL, 'status]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), node_invoke($node, 'node_name'), format_name($node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit'), l(t('delete'), 'admin/node/delete/'. $node->nid));
}
if ($pager = theme('pager', NULL, 50, 0)) {
diff --git a/modules/tracker.module b/modules/tracker.module
index 8f377f07d..d4fb00e15 100644
--- a/modules/tracker.module
+++ b/modules/tracker.module
@@ -101,7 +101,7 @@ function tracker_page($uid = 0) {
$rows[] = array(
node_invoke($node->type, 'node_name'),
- l($node->title, "node/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme('mark', 'new') : ''),
+ l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
format_name($node),
array('class' => 'replies', 'data' => $comments),
t('%time ago', array('%time' => format_interval(time() - $node->last_post)))
diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module
index 8f377f07d..d4fb00e15 100644
--- a/modules/tracker/tracker.module
+++ b/modules/tracker/tracker.module
@@ -101,7 +101,7 @@ function tracker_page($uid = 0) {
$rows[] = array(
node_invoke($node->type, 'node_name'),
- l($node->title, "node/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme('mark', 'new') : ''),
+ l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
format_name($node),
array('class' => 'replies', 'data' => $comments),
t('%time ago', array('%time' => format_interval(time() - $node->last_post)))