You are here

flag_abuse.module in Flag Abuse 7.2

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

File

flag_abuse.module
View source
<?php

/**
 * Implements hook_menu().
 */
function flag_abuse_menu() {
  $items = array();
  $items[FLAG_ADMIN_PATH . '/abuse'] = array(
    'title' => 'Abuse Flags',
    'description' => 'Configure Flag Abuse',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'flag_abuse_settings_form',
    ),
    'access arguments' => array(
      'administer flags',
    ),
    'file' => 'includes/flag_abuse.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  return $items;
}

/**
 * Implements 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);
  return $flags;
}

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

/**
 * Implements hook_features_pipe_flag_alter().
 */
function flag_abuse_features_pipe_flag_alter(&$pipe, $data, $export) {
  foreach ($data as $flag_name) {
    if (flag_abuse_is_abuse_flag($flag_name)) {
      $pipe['dependencies'][] = 'flag_abuse';
      break;
    }
  }
}

/**
 * Determine if a flag is an abuse flag.
 *
 * @param string $flag_name
 *   The machine name of the flag.
 * @return bool
 *   Whether the flag is an abuse flag or not.
 */
function flag_abuse_is_abuse_flag($flag_name) {

  // Use in_array() in strict mode, so that array keys aren't detected.
  return in_array($flag_name, flag_abuse_get_abuse_flags(), TRUE);
}

/**
 * Get the machine names of abuse flags.
 *
 * @return array
 *   The machine names of abuse flags.
 */
function flag_abuse_get_abuse_flags() {
  return variable_get('flag_abuse_flags', array(
    'abuse_node',
    'abuse_comment',
    'abuse_user',
  ));
}

/**
 * Make sure we're using the correct api.
 * @return string
 *   Either content_type or entity_type depending on flag api
 */
function flag_abuse_get_api_type() {
  if (FLAG_API_VERSION == 2) {
    $type = 'content_type';
  }
  elseif (FLAG_API_VERSION == 3) {
    $type = 'entity_type';
  }
  return $type;
}
function flag_abuse_flag_access($flag, $entity_id, $action, $account) {
  $type = flag_abuse_get_api_type();
  $content_flags = flag_get_counts($flag->{$type}, $entity_id);
  if (flag_abuse_is_abuse_flag($flag->name)) {

    // Check to see if there is a whitelist flag
    if (isset($content_flags['abuse_whitelist_' . $flag->{$type}]) && $content_flags['abuse_whitelist_' . $flag->{$type}] == 1) {
      flag_reset_flag($flag, $entity_id);
      return FALSE;
    }
  }
}

Functions

Namesort descending Description
flag_abuse_features_pipe_flag_alter Implements hook_features_pipe_flag_alter().
flag_abuse_flag_access
flag_abuse_flag_default_flags Implements hook_flag_default_flags().
flag_abuse_get_abuse_flags Get the machine names of abuse flags.
flag_abuse_get_api_type Make sure we're using the correct api.
flag_abuse_is_abuse_flag Determine if a flag is an abuse flag.
flag_abuse_menu Implements hook_menu().
flag_abuse_views_api Implements hook_views_api().