You are here

function comment_og_access in Comment OG 7

Same name and namespace in other branches
  1. 6 comment_og.module \comment_og_access()

Determines whether the current user has access to a particular comment.

Authenticated users can edit their comments as long they have not been replied to. This prevents people from changing or revising their statements based on the replies to their posts.

Parameters

string $op: The operation that is to be performed on the comment. Only 'edit' is recognized now.

object $comment: The comment object. A CID is also allowed.

int $gid: A group ID, loaded from og_context() which cannot be called natively within this function because it causes a white screen (WSOD).

Return value

bool TRUE if the current user has acces to the comment, FALSE otherwise.

1 call to comment_og_access()
comment_og_comment_view_alter in ./comment_og.module
Implements hook_comment_view_alter().
1 string reference to 'comment_og_access'
comment_og_menu_alter in ./comment_og.module
Implements hook_menu_alter().

File

./comment_og.module, line 203
Provides comment integration for Organic Groups.

Code

function comment_og_access($op, $comment, $gid = FALSE) {
  global $user;

  // Load comment object if not passed in.
  if (is_numeric($comment)) {
    $comment = comment_load($comment);
  }

  // Group context logic.
  if ($comment && $gid) {
    switch ($op) {
      case 'approve':
        return og_user_access($gid, 'approve ' . $comment->node_type) || user_access('administer comments');
      case 'delete':
        return og_user_access($gid, 'delete ' . $comment->node_type) || user_access('administer comments');
      case 'edit':
        $own = $user->uid && $user->uid == $comment->uid ? 'own ' : '';
        return og_user_access($gid, 'edit ' . $own . $comment->node_type) || user_access('administer comments');
      case 'post':
        return og_user_access($gid, 'post ' . $comment->node_type);
    }
  }
  else {
    switch ($op) {
      case 'approve':
      case 'delete':
        return user_access('administer comments');
      case 'edit':
        return $user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments') || user_access('administer comments');
      case 'post':
        return user_access('post comments');
    }
  }
}