Definition

comment_links($comment, $return = 1)
drupal/modules/comment/comment.module, line 907

Description

Build command links for a comment (e.g.\ edit, reply, delete) with respect to the current user's access permissions.

Parameters

$comment The comment to which the links will be related.

$return Not used.

Return value

An associative array containing the links.

Code

function comment_links($comment, $return = 1) {
  global $user;
  $links = array();

  // If viewing just this comment, link back to the node.
  if ($return) {
    $links['comment_parent'] = array(
      'title' => t('parent'),
      'href' => comment_node_url(),
      'fragment' => "comment-$comment->cid"
    );
  }

  $node = node_load($comment->nid);
  if ($node->comment == COMMENT_NODE_READ_WRITE) {
    if (user_access('administer comments') && user_access('post comments')) {
      $links['comment_delete'] = array(
        'title' => t('delete'),
        'href' => "comment/delete/$comment->cid"
      );
      $links['comment_edit'] = array(
        'title' => t('edit'),
        'href' => "comment/edit/$comment->cid"
      );
      $links['comment_reply'] = array(
        'title' => t('reply'),
        'href' => "comment/reply/$comment->nid/$comment->cid"
      );
      if ($comment->status == COMMENT_NOT_PUBLISHED) {
        $links['comment_approve'] = array(
          'title' => t('approve'),
          'href' => "comment/approve/$comment->cid"
        );
      }
    }
    elseif (user_access('post comments')) {
      if (comment_access('edit', $comment)) {
        $links['comment_edit'] = array(
          'title' => t('edit'),
          'href' => "comment/edit/$comment->cid"
        );
      }
      $links['comment_reply'] = array(
        'title' => t('reply'),
        'href' => "comment/reply/$comment->nid/$comment->cid"
      );
    }
    else {
      $node = node_load($comment->nid);
      $links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node);
    }
  }

  return $links;
}