Project

General

Profile

Paste
Download (2.1 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / ctools / plugins / access / php.inc @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide access control based on evaluated PHP.
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' => t("PHP Code"),
14
  'description' => t('Control access through arbitrary PHP code.'),
15
  'callback' => 'ctools_php_ctools_access_check',
16
  'default' => array('description' => '', 'php' => ''),
17
  'settings form' => 'ctools_php_ctools_access_settings',
18
  'summary' => 'ctools_php_ctools_access_summary',
19
  'all contexts' => TRUE,
20
);
21

    
22
/**
23
 * Settings form for the 'by perm' access plugin.
24
 *
25
 * @todo Need a way to provide a list of all available contexts to be used by
26
 *       the eval-ed PHP.
27
 */
28
function ctools_php_ctools_access_settings($form, &$form_state, $conf) {
29
  $perms = array();
30

    
31
  $form['settings']['description'] = array(
32
    '#type' => 'textfield',
33
    '#title' => t('Administrative desc'),
34
    '#default_value' => $conf['description'],
35
    '#description' => t('A description for this test for administrative purposes.'),
36
  );
37
  $form['settings']['php'] = array(
38
    '#type' => 'textarea',
39
    '#title' => t('PHP Code'),
40
    '#default_value' => $conf['php'],
41
    '#description' => t('Access will be granted if the following PHP code returns <code>TRUE</code>. Do not include &lt;?php ?&gt;. Note that executing incorrect PHP-code can break your Drupal site. All contexts will be available in the <em>$contexts</em> variable.'),
42
  );
43
  if (!user_access('use PHP for settings')) {
44
    $form['settings']['php']['#disabled'] = TRUE;
45
    $form['settings']['php']['#value'] = $conf['php'];
46
    $form['settings']['php']['#description'] .= ' ' . t('You do not have sufficient permissions to edit PHP code.');
47
  }
48
  return $form;
49
}
50

    
51
/**
52
 * Check for access.
53
 */
54
function ctools_php_ctools_access_check($__conf, $contexts) {
55
  $access = eval($__conf['php']);
56
  return $access;
57
}
58

    
59
/**
60
 * Provide a summary description based upon the checked roles.
61
 */
62
function ctools_php_ctools_access_summary($conf, $contexts) {
63
  return !empty($conf['description']) ? check_plain($conf['description']) : t('No description');
64
}