commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / views / plugins / views_plugin_argument_validate_php.inc
1 <?php
2
3 /**
4 * @file
5 * Contains the php code argument validator plugin.
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 function option_definition() {
15 $options = parent::option_definition();
16 $options['code'] = array('default' => '');
17
18 return $options;
19 }
20
21 function options_form(&$form, &$form_state) {
22 parent::options_form($form, $form_state);
23 $form['code'] = array(
24 '#type' => 'textarea',
25 '#title' => t('PHP validate code'),
26 '#default_value' => $this->options['code'],
27 '#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".'),
28 );
29
30 $this->check_access($form, 'code');
31 }
32
33 /**
34 * Only let users with PHP block visibility permissions set/modify this
35 * validate plugin.
36 */
37 function access() {
38 return user_access('use PHP for settings');
39 }
40
41 function convert_options(&$options) {
42 if (!isset($options['code']) && isset($this->argument->options['validate_argument_php'])) {
43 $options['code'] = $this->argument->options['validate_argument_php'];
44 }
45 }
46
47 function validate_argument($argument) {
48 // set up variables to make it easier to reference during the argument.
49 $view = &$this->view;
50 $handler = &$this->argument;
51
52 ob_start();
53 $result = eval($this->options['code']);
54 ob_end_clean();
55 return $result;
56 }
57 }