Projet

Général

Profil

Paste
Télécharger (1,99 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_argument_validate_php.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_argument_validate_php.
6
 */
7

    
8
/**
9
 * Provide PHP code to validate whether or not an argument is ok.
10
 *
11
 * @ingroup views_argument_validate_plugins
12
 */
13
class views_plugin_argument_validate_php extends views_plugin_argument_validate {
14

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function option_definition() {
19
    $options = parent::option_definition();
20
    $options['code'] = array('default' => '');
21

    
22
    return $options;
23
  }
24

    
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function options_form(&$form, &$form_state) {
29
    parent::options_form($form, $form_state);
30
    $form['code'] = array(
31
      '#type' => 'textarea',
32
      '#title' => t('PHP validate code'),
33
      '#default_value' => $this->options['code'],
34
      '#description' => t('Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use &lt;?php ?&gt;. The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument". You may change the title used for substitutions for this argument by setting "$handler->validated_title".'),
35
    );
36

    
37
    $this->check_access($form, 'code');
38
  }
39

    
40
  /**
41
   * Only let users with PHP block visibility permissions set/modify this
42
   * validate plugin.
43
   */
44
  public function access() {
45
    return user_access('use PHP for settings');
46
  }
47

    
48
  /**
49
   * {@inheritdoc}
50
   */
51
  public function convert_options(&$options) {
52
    if (!isset($options['code']) && isset($this->argument->options['validate_argument_php'])) {
53
      $options['code'] = $this->argument->options['validate_argument_php'];
54
    }
55
  }
56

    
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public function validate_argument($argument) {
61
    // set up variables to make it easier to reference during the argument.
62
    $view = &$this->view;
63
    $handler = &$this->argument;
64

    
65
    ob_start();
66
    $result = eval($this->options['code']);
67
    ob_end_clean();
68
    return $result;
69
  }
70

    
71
}