Projet

Général

Profil

Paste
Télécharger (3,29 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / ctools_access_ruleset / plugins / access / ruleset.inc @ 7e72b748

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide access control based on user rulesetission strings.
6
 */
7

    
8
/**
9
 * Plugins are described by creating a $plugin array which will be used
10
 * by the system that includes this file.
11
 */
12
$plugin = array(
13
  'title' => '',
14
  'description' => '',
15
  'callback' => 'ctools_ruleset_ctools_access_check',
16
  'settings form' => 'ctools_ruleset_ctools_access_settings',
17
  'summary' => 'ctools_ruleset_ctools_access_summary',
18

    
19
  // This access plugin actually just contains child plugins that are
20
  // exportable, UI configured rulesets.
21
  'get child' => 'ctools_ruleset_ctools_access_get_child',
22
  'get children' => 'ctools_ruleset_ctools_access_get_children',
23
);
24

    
25
/**
26
 * Merge the main access plugin with a loaded ruleset to form a child plugin.
27
 */
28
function ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item) {
29
  $plugin['name'] = $parent . ':' . $item->name;
30
  $plugin['title'] = check_plain($item->admin_title);
31
  $plugin['description'] = check_plain($item->admin_description);
32

    
33
  // TODO: Generalize this in CTools.
34
  if (!empty($item->requiredcontexts)) {
35
    $plugin['required context'] = array();
36
    foreach ($item->requiredcontexts as $context) {
37
      $info = ctools_get_context($context['name']);
38
      // TODO: allow an optional setting.
39
      $plugin['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
40
    }
41
  }
42

    
43
  // Store the loaded ruleset in the plugin.
44
  $plugin['ruleset'] = $item;
45
  return $plugin;
46
}
47

    
48
/**
49
 * Get a single child access plugin.
50
 */
51
function ctools_ruleset_ctools_access_get_child($plugin, $parent, $child) {
52
  ctools_include('export');
53
  $item = ctools_export_crud_load('ctools_access_ruleset', $child);
54
  if ($item) {
55
    return ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item);
56
  }
57
}
58

    
59
/**
60
 * Get all child access plugins.
61
 */
62
function ctools_ruleset_ctools_access_get_children($plugin, $parent) {
63
  $plugins = array();
64
  ctools_include('export');
65
  $items = ctools_export_crud_load_all('ctools_access_ruleset');
66
  foreach ($items as $name => $item) {
67
    $child = ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item);
68
    $plugins[$child['name']] = $child;
69
  }
70

    
71
  return $plugins;
72
}
73

    
74
/**
75
 * Settings form for the 'by ruleset' access plugin.
76
 */
77
function ctools_ruleset_ctools_access_settings(&$form, &$form_state, $conf) {
78
  if (!empty($form_state['plugin']['ruleset']->admin_description)) {
79
    $form['markup'] = array(
80
      '#markup' => '<div class="description">' . check_plain($form_state['plugin']['ruleset']->admin_description) . '</div>',
81
    );
82
  }
83

    
84
  return $form;
85
}
86

    
87
/**
88
 * Check for access.
89
 */
90
function ctools_ruleset_ctools_access_check($conf, $context, $plugin) {
91
  // Load up any contexts we might be using.
92
  $contexts = ctools_context_match_required_contexts($plugin['ruleset']->requiredcontexts, $context);
93
  $contexts = ctools_context_load_contexts($plugin['ruleset'], FALSE, $contexts);
94

    
95
  return ctools_access($plugin['ruleset']->access, $contexts);
96
}
97

    
98
/**
99
 * Provide a summary description based upon the checked roles.
100
 */
101
function ctools_ruleset_ctools_access_summary($conf, $context, $plugin) {
102
  if (!empty($plugin['ruleset']->admin_description)) {
103
    return check_plain($plugin['ruleset']->admin_description);
104
  }
105
  else {
106
    return check_plain($plugin['ruleset']->admin_title);
107
  }
108
}