You are here

function theme_comment_post_forbidden in Drupal 7

Same name and namespace in other branches
  1. 4 modules/comment.module \theme_comment_post_forbidden()
  2. 5 modules/comment/comment.module \theme_comment_post_forbidden()
  3. 6 modules/comment/comment.module \theme_comment_post_forbidden()

Returns HTML for a "you can't post comments" notice.

Parameters

$variables: An associative array containing:

  • node: The comment node.

Related topics

2 theme calls to theme_comment_post_forbidden()
comment_links in modules/comment/comment.module
Helper function, build links for an individual comment.
comment_node_view in modules/comment/comment.module
Implements hook_node_view().

File

modules/comment/comment.module, line 2364
Enables users to comment on published content.

Code

function theme_comment_post_forbidden($variables) {
  $node = $variables['node'];
  global $user;

  // Since this is expensive to compute, we cache it so that a page with many
  // comments only has to query the database once for all the links.
  $authenticated_post_comments =& drupal_static(__FUNCTION__, NULL);
  if (!$user->uid) {
    if (!isset($authenticated_post_comments)) {

      // We only output a link if we are certain that users will get permission
      // to post comments by logging in.
      $comment_roles = user_roles(TRUE, 'post comments');
      $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
    }
    if ($authenticated_post_comments) {

      // We cannot use drupal_get_destination() because these links
      // sometimes appear on /node and taxonomy listing pages.
      if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
        $destination = array(
          'destination' => "comment/reply/{$node->nid}#comment-form",
        );
      }
      else {
        $destination = array(
          'destination' => "node/{$node->nid}#comment-form",
        );
      }
      if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {

        // Users can register themselves.
        return t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array(
          '@login' => url('user/login', array(
            'query' => $destination,
          )),
          '@register' => url('user/register', array(
            'query' => $destination,
          )),
        ));
      }
      else {

        // Only admins can add new users, no public registration.
        return t('<a href="@login">Log in</a> to post comments', array(
          '@login' => url('user/login', array(
            'query' => $destination,
          )),
        ));
      }
    }
  }
}