You are here

function ad_permission in Advertisement 6.3

Same name and namespace in other branches
  1. 5.2 ad.module \ad_permission()
  2. 6.2 ad.module \ad_permission()
  3. 7 ad.module \ad_permission()
  4. 7.2 ad.module \ad_permission()

Determine whether the user has a given privilege.

Parameters

$aid: ID of advertisement.

$permission: Permission string which should be checked (such as 'access click history')

$account: User object, which are accessing the ad or current user by default.

10 calls to ad_permission()
ad_activity_details in ./ad.pages.inc
ad_form in ./ad.module
Implementation of hook_form().
ad_html_node_form in html/ad_html.module
Adapi helper function for displaying a node form.
ad_image_adapi in image/ad_image.module
Implementation of hook_adapi().
ad_owners_access in owners/ad_owners.module
Menu item access callback.

... See full list

2 string references to 'ad_permission'
ad_menu in ./ad.module
Implementation of hook_menu().
ad_owners_menu in owners/ad_owners.module
Implementation of hook_menu().

File

./ad.module, line 1167

Code

function ad_permission($aid, $string, $account = NULL) {
  global $user;
  $access = FALSE;

  // See bug http://drupal.org/node/664956
  // Using substr() as AdBard has a custom ad_adbard type.
  if (is_object($aid) && substr($aid->type, 0, 2) != 'ad') {
    return FALSE;
  }

  // by default, check permission for current user
  if (!isset($account)) {
    $account = $user;
  }

  // user #1 has all privileges
  if ($account->uid == 1) {
    return TRUE;
  }

  // if you have administer permissions, you have all permissions
  if (user_access('administer advertisements', $account)) {
    return TRUE;
  }

  // when used in the Drupal menu, $aid may be the full ad object.
  if (is_object($aid) && isset($aid->aid)) {
    $aid = $aid->aid;
  }
  else {
    if (is_object($aid) && isset($aid->nid)) {
      $aid = $aid->nid;
    }
    else {
      if (is_object($aid)) {
        watchdog('ad', 'Invalid aid object passed into ad_permission, no aid->aid set.');
        $aid = 0;
      }
    }
  }

  // invoke ad_owners module to determine user's access
  if (module_exists('ad_owners') && function_exists('ad_owners_permission')) {
    $access = ad_owners_permission($aid, $string, $account);
  }
  else {
    if (in_array($string, array(
      'access statistics',
      'access click history',
    ))) {
      $access = TRUE;
    }
  }

  // with no ad_owners module, all other permissions are denied unless user
  // has 'administer advertisements' permission
  return $access;
}