function comment_link in Drupal 6
Same name and namespace in other branches
- 4 modules/comment.module \comment_link()
- 5 modules/comment/comment.module \comment_link()
Implementation of hook_link().
File
- modules/
comment/ comment.module, line 405 - Enables users to comment on published content.
Code
function comment_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && $node->comment) {
if ($teaser) {
// Main page: display the number of comments that have been posted.
if (user_access('access comments')) {
$all = comment_num_all($node->nid);
if ($all) {
$links['comment_comments'] = array(
'title' => format_plural($all, '1 comment', '@count comments'),
'href' => "node/{$node->nid}",
'attributes' => array(
'title' => t('Jump to the first comment of this posting.'),
),
'fragment' => 'comments',
);
$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($all, $new, $node),
'attributes' => array(
'title' => t('Jump to the first new comment of this posting.'),
),
'fragment' => 'new',
);
}
}
else {
if ($node->comment == COMMENT_NODE_READ_WRITE) {
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',
);
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node);
}
}
}
}
}
else {
// Node page: add a "post comment" link if the user is allowed to
// post comments, if this node is not read-only, and if the comment form isn't already shown
if ($node->comment == COMMENT_NODE_READ_WRITE) {
if (user_access('post comments')) {
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
$links['comment_add'] = array(
'title' => t('Add new comment'),
'href' => "comment/reply/{$node->nid}",
'attributes' => array(
'title' => t('Share your thoughts and opinions related to this posting.'),
),
'fragment' => 'comment-form',
);
}
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node);
}
}
}
}
if ($type == 'comment') {
$links = comment_links($node, $teaser);
}
if (isset($links['comment_forbidden'])) {
$links['comment_forbidden']['html'] = TRUE;
}
return $links;
}