function advanced_forum_first_new_comment in Advanced Forum 6.2
Same name and namespace in other branches
- 5 advanced_forum.module \advanced_forum_first_new_comment()
- 6 advanced_forum.module \advanced_forum_first_new_comment()
- 7.2 advanced_forum.module \advanced_forum_first_new_comment()
Returns the ID of the first unread comment.
Parameters
$nid: Node ID
$timestamp: Date/time used to override when the user last viewed the node.
Return value
Comment ID
1 call to advanced_forum_first_new_comment()
- advanced_forum_first_new_post_link in ./
advanced_forum.module - Returns a link directly to the first new post in a topic.
File
- ./
advanced_forum.module, line 1030 - Enables the look and feel of other popular forum software.
Code
function advanced_forum_first_new_comment($nid, $timestamp = 0) {
global $user;
if ($user->uid) {
// Retrieve the timestamp at which the current user last viewed the
// specified node.
if (!$timestamp) {
$timestamp = node_last_viewed($nid);
}
// Set the timestamp to the limit if the node was last read past the cutoff
$timestamp = $timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT;
// Use the timestamp to retrieve the oldest new comment.
if (module_exists('nodecomment')) {
$query = "SELECT nc.cid\n FROM {node_comments} nc\n INNER JOIN {node} n ON nc.cid = n.nid\n WHERE nc.nid = %d AND n.changed > %d AND n.status = 1\n ORDER BY nc.cid";
$result = db_result(db_query_range($query, $nid, $timestamp, 0, 1));
}
else {
// If this query is appearing in your slow query log @see: http://drupal.org/node/1728770
$query = "SELECT c.cid\n FROM {comments} c\n WHERE c.nid = %d AND c.timestamp > %d AND c.status = %d\n ORDER BY c.cid";
$result = db_result(db_query_range($query, $nid, $timestamp, COMMENT_PUBLISHED, 0, 1));
}
return $result;
}
else {
return 0;
}
}