You are here

function comment_perm_comment in Comment Permissions 6

Same name and namespace in other branches
  1. 5 comment_perm.module \comment_perm_comment()
  2. 7 comment_perm.module \comment_perm_comment()

Implementation of hook_comment().

File

./comment_perm.module, line 50
Module to control commenting permissions by role and by node type.

Code

function comment_perm_comment(&$comment, $op) {
  switch ($op) {
    case 'validate':
      $nid = $comment['nid'];
      if (!comment_perm_access($nid)) {
        form_set_error('', _comment_perm_access_denied_message());
      }
      break;
    case 'insert':
      $current_status = $comment['status'];
      $desired_status = comment_perm_post_without_permission_access($comment['nid']) ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED;
      if ($current_status != $desired_status) {
        db_query("UPDATE {comments} SET status=%d WHERE cid=%d", $desired_status, $comment['cid']);
        $comment['status'] = $desired_status;
      }
      break;
  }
}