comment_node_view($node, $view_mode)Implements hook_node_view().
modules/comment/comment.module, line 577
<?php
function comment_node_view($node, $view_mode) {
$links = array();
if ($node->comment) {
if ($view_mode == 'rss') {
if ($node->comment != COMMENT_NODE_HIDDEN) {
// Add a comments RSS element which is a URL to the comments of this node.
$node->rss_elements[] = array(
'key' => 'comments',
'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))
);
}
}
elseif ($view_mode == 'teaser') {
// Teaser view: display the number of comments that have been posted,
// or a link to add new comments if the user has permission, the node
// is open to new comments, and there currently are none.
if (user_access('access comments')) {
if (!empty($node->comment_count)) {
$links['comment_comments'] = array(
'title' => format_plural($node->comment_count, '1 comment', '@count comments'),
'href' => "node/$node->nid",
'attributes' => array('title' => t('Jump to the first comment of this posting.')),
'fragment' => 'comments',
'html' => TRUE,
);
$new = comment_num_new($node->nid);
if ($new) {
$links['comment_new_comments'] = array(
'title' => format_plural($new, '1 new comment', '@count new comments'),
'href' => "node/$node->nid",
'query' => comment_new_page_count($node->comment_count, $new, $node),
'attributes' => array('title' => t('Jump to the first new comment of this posting.')),
'fragment' => 'new',
'html' => TRUE,
);
}
}
else {
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('post comments')) {
$links['comment_add'] = array(
'title' => t('Add new comment'),
'href' => "comment/reply/$node->nid",
'attributes' => array('title' => t('Add a new comment to this page.')),
'fragment' => 'comment-form',
'html' => TRUE,
);
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', array('node' => $node));
}
}
}
}
}
elseif ($view_mode != 'search_index') {
// Node in other view modes: add a "post comment" link if the user is
// allowed to post comments and if this node is allowing new comments.
// But we don't want this link if we're building the node for search
// indexing.
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('post comments')) {
$links['comment_add'] = array(
'title' => t('Add new comment'),
'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),
'fragment' => 'comment-form',
'html' => TRUE,
);
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
$links['comment_add']['href'] = "comment/reply/$node->nid";
}
else {
$links['comment_add']['href'] = "node/$node->nid";
}
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', array('node' => $node));
}
}
}
if (isset($links['comment_forbidden'])) {
$links['comment_forbidden']['html'] = TRUE;
}
$node->content['links']['comment'] = array(
'#theme' => 'links__comment_node',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
// Only append comments when we are building a node on its own node detail
// page. We compare $node and $page_node to ensure that comments are not
// appended to other nodes shown on the page, for example a node_reference
// displayed in 'full' view mode within another node.
if ($node->comment && node_is_page($node) && empty($node->in_preview) && user_access('access comments')) {
$node->content['comments'] = comment_node_page_additions($node);
}
}
}
?>