[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/ctools/plugins/access/ -> perm.inc (source)

   1  <?php
   2  // $Id: perm.inc,v 1.6.2.3 2010/07/14 01:30:19 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide access control based on user permission strings.
   7   */
   8  
   9  /**
  10   * Plugins are described by creating a $plugin array which will be used
  11   * by the system that includes this file.
  12   */
  13  $plugin = array(
  14    'title' => t("User: permission"),
  15    'description' => t('Control access by permission string.'),
  16    'callback' => 'ctools_perm_ctools_access_check',
  17    'default' => array('perm' => 'access content'),
  18    'settings form' => 'ctools_perm_ctools_access_settings',
  19    'summary' => 'ctools_perm_ctools_access_summary',
  20    'required context' => new ctools_context_required(t('User'), 'user'),
  21  );
  22  
  23  /**
  24   * Settings form for the 'by perm' access plugin
  25   */
  26  function ctools_perm_ctools_access_settings(&$form, &$form_state, $conf) {
  27    $perms = array();
  28    // Get list of permissions
  29    foreach (module_list(FALSE, FALSE, TRUE) as $module) {
  30      // By keeping them keyed by module we can use optgroups with the
  31      // 'select' type.
  32      if ($permissions = module_invoke($module, 'perm')) {
  33        $perms[$module] = drupal_map_assoc($permissions);
  34      }
  35    }
  36  
  37    $form['settings']['perm'] = array(
  38      '#type' => 'select',
  39      '#options' => $perms,
  40      '#title' => t('Permission'),
  41      '#default_value' => $conf['perm'],
  42      '#description' => t('Only users with the selected permission flag will be able to access this.'),
  43    );
  44  }
  45  
  46  /**
  47   * Check for access.
  48   */
  49  function ctools_perm_ctools_access_check($conf, $context) {
  50    // As far as I know there should always be a context at this point, but this
  51    // is safe.
  52    if (empty($context) || empty($context->data)) {
  53      return FALSE;
  54    }
  55  
  56    return user_access($conf['perm'], $context->data);
  57  }
  58  
  59  /**
  60   * Provide a summary description based upon the checked roles.
  61   */
  62  function ctools_perm_ctools_access_summary($conf, $context) {
  63    if (!isset($conf['perm'])) {
  64      return t('Error, unset permission');
  65    }
  66  
  67    return t('@identifier has "@perm"', array('@identifier' => $context->identifier, '@perm' => $conf['perm']));
  68  }
  69  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7