function subscriptions_comment_page in Subscriptions 5
Return the page a comment is on
1 call to subscriptions_comment_page()
File
- ./
subscriptions.module, line 795
Code
function subscriptions_comment_page($cid, $nid) {
// Recipient of email may have different comment settings than the current user.
// Also recipient may have 'administer comments' permission and see unpublished comments.
// Just use default settings and hope for the best..
//$comments_per_page = _comment_get_display_setting('comments_per_page');
$comments_per_page = variable_get('comment_default_per_page', 50);
$comments_num = comment_num_all($nid) + 1;
// +1 for comment being added now
if ($comments_num <= $comments_per_page) {
// One page of comments only
return 0;
}
$comment = db_fetch_object(db_query('SELECT timestamp, thread FROM {comments} WHERE cid = %d', $cid));
// Build the database query that retrieves the comment's position
// This follows the same scheme as in comment_render().
// See comments there for an explanation.
$query = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d';
$query_args = array(
$nid,
COMMENT_PUBLISHED,
);
$mode = variable_get('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED);
$order = variable_get('comment_default_order', COMMENT_ORDER_NEWEST_FIRST);
if ($order == COMMENT_ORDER_NEWEST_FIRST) {
if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
$query .= ' AND timestamp > %d';
$query_args[] = $comment->timestamp;
}
else {
$query .= " AND thread > '%s'";
$query_args[] = $comment->thread;
}
}
else {
if ($order == COMMENT_ORDER_OLDEST_FIRST) {
if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
$query .= ' AND timestamp < %d';
$query_args[] = $comment->timestamp;
}
else {
$query .= " AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '%s'";
$query_args[] = substr($comment->thread, 0, -1);
}
}
}
$count = db_result(db_query($query, $query_args));
return floor($count / $comments_per_page);
}