You are here

flag_abuse.module in Flag Abuse 6.2

Same filename and directory in other branches
  1. 6 flag_abuse.module
  2. 7.2 flag_abuse.module

File

flag_abuse.module
View source
<?php

/**
 * Implementation of hook_flag_default_flags().
 */
function flag_abuse_flag_default_flags() {
  $flags = array();
  module_load_include('inc', 'flag_abuse', 'includes/flag_abuse.flag_default');
  _flag_abuse_abuse_node_flags($flags);
  _flag_abuse_abuse_comment_flags($flags);
  _flag_abuse_abuse_user_flags($flags);

  // @todo: module implements?
  return $flags;
}

/**
 * Implementation of hook_views_api().
 */
function flag_abuse_views_api() {
  return array(
    'api' => 2.0,
    'path' => drupal_get_path('module', 'flag_abuse') . '/includes',
  );
}

/**
 * Implementation of hook_perm().
 */
function flag_abuse_perm() {
  return array(
    'reset abuse flags',
  );
}

/**
 * Implementation of hook_preprocess_flag().
 *
 * Here we change our flag event/action to 'reset'.
 */
function flag_abuse_preprocess_flag(&$vars) {
  global $user;

  // permmission check instead of a role
  if (user_access('reset abuse flags', $user)) {

    // is this one of our abuse flags
    // @todo: should be dynamic
    if (in_array($vars['flag']->name, array(
      'abuse_node',
      'abuse_comment',
      'abuse_user',
    ))) {
      $vars['action'] = 'reset';
      $vars['link_text'] = t('Reset flags');
      $vars['link_title'] = t('Remove all flags on this content');
    }
  }
}

/**
 * Implementation of hook_flag().
 *
 * If a user with appropriate permission/role flags this content from our view
 * we want to remove all flags. http://drupal.org/node/327901#comment-1085685
 *
 * @todo: When $flag->access() goes in, use this to limit access to a flag that
 * an administrator has already acted upon. http://drupal.org/node/322034
 */
function flag_abuse_flag($event, $flag, $content_id, $account) {

  // permmission check instead of a role
  if (user_access('reset abuse flags', $account)) {

    // is this one of our abuse flags
    // @todo: should be dynamic
    if (in_array($flag->name, array(
      'abuse_node',
      'abuse_comment',
      'abuse_user',
    ))) {

      // remove all flags on this content
      $rows = flag_reset_flag($flag, $content_id);
      if ($rows) {

        // This user actually flags the content as well, so it may confuse the
        // user if they reset what they thought was one flag and we report two.
        $rows--;
        drupal_set_message(t('Reset !rows flags.', array(
          '!rows' => $rows,
        )));
        variable_set($flag->name . '-' . $content_id, TRUE);
      }
    }
  }
}

/**
 * Implementation of hook_flag_access().
 */
function flag_abuse_flag_access($flag, $content_id, $action, $account) {
  if (in_array($flag->name, array(
    'abuse_node',
    'abuse_comment',
    'abuse_user',
  ))) {

    // Check to see if this flag has already been reset.
    if (variable_get($flag->name . '-' . $content_id, FALSE)) {
      return FALSE;
    }
  }
}

/**
 * Implementation of hook_form_FORM_ID_alter().
 */
function flag_abuse_form_flag_confirm_alter(&$form, &$form_state) {
  global $user;

  // Permmission check instead of a role.
  if (user_access('reset abuse flags', $account)) {
    $flag_name = $form['flag_name']['#value'];

    // Is this one of our abuse flags?
    if (in_array($flag_name, array(
      'abuse_node',
      'abuse_comment',
      'abuse_user',
    ))) {
      drupal_set_title(t('Flag reset'));
      $form['description']['#value'] = t('Are you sure you want to reset all offensive flag on this content? Once doing so, users will not be able to flag this content again.');
      $form['actions']['submit']['#value'] = t('Reset flags');
    }
  }
}

Functions

Namesort descending Description
flag_abuse_flag Implementation of hook_flag().
flag_abuse_flag_access Implementation of hook_flag_access().
flag_abuse_flag_default_flags Implementation of hook_flag_default_flags().
flag_abuse_form_flag_confirm_alter Implementation of hook_form_FORM_ID_alter().
flag_abuse_perm Implementation of hook_perm().
flag_abuse_preprocess_flag Implementation of hook_preprocess_flag().
flag_abuse_views_api Implementation of hook_views_api().