function comment_link in Drupal 4
Same name and namespace in other branches
- 5 modules/comment/comment.module \comment_link()
- 6 modules/comment/comment.module \comment_link()
Implementation of hook_link().
File
- modules/
comment.module, line 184 - Enables users to comment on published content.
Code
function comment_link($type, $node = 0, $main = 0) {
$links = array();
if ($type == 'node' && $node->comment) {
if ($main) {
// 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[] = l(format_plural($all, '1 comment', '%count comments'), "node/{$node->nid}", array(
'title' => t('Jump to the first comment of this posting.'),
), NULL, 'comment');
$new = comment_num_new($node->nid);
if ($new) {
$links[] = l(format_plural($new, '1 new comment', '%count new comments'), "node/{$node->nid}", array(
'title' => t('Jump to the first new comment of this posting.'),
), NULL, 'new');
}
}
else {
if ($node->comment == COMMENT_NODE_READ_WRITE) {
if (user_access('post comments')) {
$links[] = l(t('add new comment'), "comment/reply/{$node->nid}", array(
'title' => t('Add a new comment to this page.'),
), NULL, 'comment_form');
}
else {
$links[] = theme('comment_post_forbidden', $node->nid);
}
}
}
}
}
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', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
$links[] = l(t('add new comment'), "comment/reply/{$node->nid}", array(
'title' => t('Share your thoughts and opinions related to this posting.'),
), NULL, 'comment_form');
}
}
else {
$links[] = theme('comment_post_forbidden', $node->nid);
}
}
}
}
if ($type == 'comment') {
$links = comment_links($node, $main);
}
return $links;
}