You are here

comment_og.module in Comment OG 5

Same filename and directory in other branches
  1. 6 comment_og.module
  2. 7 comment_og.module

File

comment_og.module
View source
<?php

/**
 * Implementation of hook_link_alter().
 * Removes comment link for non-members
 */
function comment_og_link_alter(&$links, $node) {
  if ($node->comment) {
    if (isset($node->og_groups)) {
      if (!og_is_group_member(og_get_group_context())) {
        unset($links['comment_add']);
      }
    }
  }
}

/*
 * Modifies the comment links via a preprocess funtion as described here:
 * http://drupal.org/node/352020
 */
function comment_og_preprocess_comment(&$variables) {
  $comment = $variables['comment'];

  //load links for current comment
  $links = comment_links($comment, FALSE);
  $group = og_get_group_context();

  // if group context
  if ($group) {

    // remove the reply link for non-group members
    if (!og_is_group_member($group)) {
      unset($links['comment_reply']);
    }

    // we add the Group ID to the URL to determin group admin status later
    if (og_is_group_admin($group)) {
      $links['comment_delete'] = array(
        'title' => t('delete'),
        'href' => "comment/delete/{$comment->cid}/{$group->nid}",
      );
    }
  }

  //reset the links HTML
  $variables['links'] = theme('links', $links);
}

/**
 * Implementation of hook_form_alter().
 */
function comment_og_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'comment_form' && isset($form['nid'])) {

    // if this is group context and you're not a member of this group, disable the comment form
    if (!og_is_group_member(og_get_group_context())) {
      $form['comment_filter']['comment'] = array(
        '#type' => 'textarea',
        '#title' => t('Comment'),
        '#rows' => 5,
        '#disabled' => TRUE,
        '#description' => t('You must be a member of this group in order to post a comment.'),
      );
      if (isset($form['subject'])) {
        unset($form['subject']);
      }
      if (isset($form['comment_filter']['format'])) {
        unset($form['comment_filter']['format']);
      }
      if (isset($form['submit'])) {
        unset($form['submit']);
      }
      if (isset($form['preview'])) {
        unset($form['preview']);
      }
      if (isset($form['author'])) {
        unset($form['author']);
      }
      if (isset($form['_author'])) {
        unset($form['_author']);
      }
    }
  }
}

/**
 * Implementation of hook_menu_alter().
 */
function comment_og_menu_alter(&$items) {

  // allows group admins to delete comments
  $items['comment/delete'] = array(
    'title' => 'Delete comment',
    'page callback' => 'comment_delete',
    'access callback' => 'comment_og_comment_delete',
    'access arguments' => array(
      3,
    ),
    'type' => MENU_CALLBACK,
    'file' => 'comment.admin.inc',
    'file path' => drupal_get_path('module', 'comment'),
  );
}

/**
 * Returns true if the acting user is a group admin
 */
function comment_og_comment_delete($gid = NULL) {
  if ($gid) {
    $group = node_load($gid);
    og_load_group($group);
    return og_is_group_admin($group);
  }
  else {
    return user_access('administer comments') && user_access('post comments');
  }
}

Functions

Namesort descending Description
comment_og_comment_delete Returns true if the acting user is a group admin
comment_og_form_alter Implementation of hook_form_alter().
comment_og_link_alter Implementation of hook_link_alter(). Removes comment link for non-members
comment_og_menu_alter Implementation of hook_menu_alter().
comment_og_preprocess_comment