function comment_prepare_thread in Drupal 7
Loop over comment thread, noting indentation level.
Parameters
array $comments: An array of comment objects, keyed by cid.
Return value
The $comments argument is altered by reference with indentation information.
2 calls to comment_prepare_thread()
- comment_node_page_additions in modules/
comment/ comment.module - Build the comment-related elements for node detail pages.
- comment_node_update_index in modules/
comment/ comment.module - Implements hook_node_update_index().
File
- modules/
comment/ comment.module, line 869 - Enables users to comment on published content.
Code
function comment_prepare_thread(&$comments) {
// A flag stating if we are still searching for first new comment on the thread.
$first_new = TRUE;
// A counter that helps track how indented we are.
$divs = 0;
foreach ($comments as $key => $comment) {
if ($first_new && $comment->new != MARK_READ) {
// Assign the anchor only for the first new comment. This avoids duplicate
// id attributes on a page.
$first_new = FALSE;
$comment->first_new = TRUE;
}
// The $divs element instructs #prefix whether to add an indent div or
// close existing divs (a negative value).
$comment->depth = count(explode('.', $comment->thread)) - 1;
if ($comment->depth > $divs) {
$comment->divs = 1;
$divs++;
}
else {
$comment->divs = $comment->depth - $divs;
while ($comment->depth < $divs) {
$divs--;
}
}
$comments[$key] = $comment;
}
// The final comment must close up some hanging divs
$comments[$key]->divs_final = $divs;
}