comment_node_view
- Versions
- 7
comment_node_view($node, $build_mode)
Implement hook_node_view().
Code
modules/comment/comment.module, line 470
<?php
function comment_node_view($node, $build_mode) {
$links = array();
if ($node->comment) {
if ($build_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 ($build_mode == 'teaser') {
// Main page: display the number of comments that have been posted.
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));
}
}
}
}
}
else {
// Node page: add a "post comment" link if the user is allowed to post
// comments and if this node is not read-only.
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',
'#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' build mode within another node.
$page_node = menu_get_object();
if ($node->comment && isset($page_node->nid) && $page_node->nid == $node->nid && empty($node->in_preview) && user_access('access comments')) {
$node->content['comments'] = comment_node_page_additions($node);
}
}
}
?>Login or register to post comments 