t('Comment\'s parent ID (just for parent being another comment, otherwise zero)'), 'comment-parent-title' => t('Paren\'s title (the parent might be the node or a another comment)'), 'comment-parent-title-raw' => t('Paren\'s title. WARNING - raw user input'), 'comment-auto-numbering' => t('Auto-numbering with respect to node\'s comments count.'), 'comment-parent-auto-numbering' => t('Parent\'s auto-numbering with respect to node\'s comments count.'), ); return $tokens; } } /** * Implementation of hook_token_list(). */ function comment_subject_token_values($type, $object = NULL) { if ($type == 'comment') { $comment = (object)$object; // support uninitialized pid (comment_form will have it uninitialized for new comment) if (!isset($comment->pid)) $comment->pid = 0; // [comment-parent-title-raw] if ($comment->pid) { $parent = _comment_load($comment->pid); $parent_title = $parent->subject; } else { $parent = node_load($comment->nid); $parent_title = $parent->title; } // [comment-parent-auto-numbering] $parent_numbering = _comment_subject_get_parent_numbering($comment); // [comment-auto-numbering] $comment_numbering = _comment_subject_get_numbering($comment->nid, $comment->cid); $tokens['comment-pid'] = $comment->pid; $tokens['comment-parent-title'] = check_plain($parent_title); $tokens['comment-parent-title-raw'] = $parent_title; $tokens['comment-auto-numbering'] = $comment_numbering; $tokens['comment-parent-auto-numbering'] = $parent_numbering; return $tokens; } } // this function receives $nid to avoid loading the parent comment // when it has the same nid as the replying comment: _comment_subject_get_parent_numbering function _comment_subject_get_numbering($nid, $cid) { static $comments_count_cache = array(); if (!isset($comments_count_cache[$cid])) { $query = 'SELECT COUNT(cid) FROM {comments} WHERE nid = %d AND cid < %d GROUP BY nid'; $comments_count_cache[$cid] = db_result(db_query($query, $nid, $cid)); } $comment_count = $comments_count_cache[$cid]; return ($comment_count + 1); } function _comment_subject_get_parent_numbering($comment) { // support uninitialized pid (comment_form will have it uninitialized for new comment) return (empty($comment->pid) ? 0 : _comment_subject_get_numbering($comment->nid, $comment->pid)); }