[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: ruleset.inc,v 1.1.2.1 2010/07/26 22:09:19 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide access control based on user rulesetission 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' => '',
  15    'description' => '',
  16    'callback' => 'ctools_ruleset_ctools_access_check',
  17    'settings form' => 'ctools_ruleset_ctools_access_settings',
  18    'summary' => 'ctools_ruleset_ctools_access_summary',
  19  
  20    // This access plugin actually just contains child plugins that are
  21    // exportable, UI configured rulesets.
  22    'get child' => 'ctools_ruleset_ctools_access_get_child',
  23    'get children' => 'ctools_ruleset_ctools_access_get_children',
  24  );
  25  
  26  /**
  27   * Merge the main access plugin with a loaded ruleset to form a child plugin.
  28   */
  29  function ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item) {
  30    $plugin['name'] = $parent . ':' . $item->name;
  31    $plugin['title'] = check_plain($item->admin_title);
  32    $plugin['description'] = check_plain($item->admin_description);
  33  
  34    // TODO: Generalize this in CTools.
  35    if (!empty($item->requiredcontexts)) {
  36      $plugin['required context'] = array();
  37      foreach ($item->requiredcontexts as $context) {
  38        $info = ctools_get_context($context['name']);
  39        // TODO: allow an optional setting
  40        $plugin['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
  41      }
  42    }
  43  
  44    // Store the loaded ruleset in the plugin.
  45    $plugin['ruleset'] = $item;
  46    return $plugin;
  47  }
  48  
  49  /**
  50   * Get a single child access plugin.
  51   */
  52  function ctools_ruleset_ctools_access_get_child($plugin, $parent, $child) {
  53    ctools_include('export');
  54    $item = ctools_export_crud_load('ctools_access_ruleset', $child);
  55    if ($item) {
  56      return ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item);
  57    }
  58  }
  59  
  60  /**
  61   * Get all child access plugins.
  62   */
  63  function ctools_ruleset_ctools_access_get_children($plugin, $parent) {
  64    $plugins = array();
  65    ctools_include('export');
  66    $items = ctools_export_crud_load_all('ctools_access_ruleset');
  67    foreach ($items as $name => $item) {
  68      $child = ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item);
  69      $plugins[$child['name']] = $child;
  70    }
  71  
  72    return $plugins;
  73  }
  74  
  75  /**
  76   * Settings form for the 'by ruleset' access plugin
  77   */
  78  function ctools_ruleset_ctools_access_settings(&$form, &$form_state, $conf) {
  79    $form['markup'] = array(
  80      '#value' => '<div class="description">' . check_plain($form_state['plugin']['ruleset']->admin_description) . '</div>',
  81    );
  82  }
  83  
  84  /**
  85   * Check for access.
  86   */
  87  function ctools_ruleset_ctools_access_check($conf, $context, $plugin) {
  88    // Load up any contexts we might be using.
  89    $contexts = ctools_context_match_required_contexts($plugin['ruleset']->requiredcontexts, $context);
  90    $contexts = ctools_context_load_contexts($plugin['ruleset'], FALSE, $contexts);
  91  
  92    return ctools_access($plugin['ruleset']->access, $contexts);
  93  }
  94  
  95  /**
  96   * Provide a summary description based upon the checked roles.
  97   */
  98  function ctools_ruleset_ctools_access_summary($conf, $context, $plugin) {
  99    return check_plain($plugin['ruleset']->admin_description);
 100  }
 101  


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