1 | <?php |
---|
2 | /** |
---|
3 | * @file |
---|
4 | * Contains the php code argument default plugin. |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * Default argument plugin to provide a PHP code block. |
---|
9 | */ |
---|
10 | class views_plugin_argument_default_php extends views_plugin_argument_default { |
---|
11 | function option_definition() { |
---|
12 | $options = parent::option_definition(); |
---|
13 | $options['code'] = array('default' => ''); |
---|
14 | |
---|
15 | return $options; |
---|
16 | } |
---|
17 | |
---|
18 | function options_form(&$form, &$form_state) { |
---|
19 | $form['code'] = array( |
---|
20 | '#type' => 'textarea', |
---|
21 | '#title' => t('PHP argument code'), |
---|
22 | '#default_value' => $this->options['code'], |
---|
23 | '#process' => array('views_process_dependency'), |
---|
24 | '#description' => t('Enter PHP code that returns a value to use for this argument. Do not use <?php ?>. You must return only a single value for just this argument. Some variables are available: the view object will be "$view". The argument handler will be "$argument", for example you may change the title used for substitutions for this argument by setting "argument->validated_title"".'), |
---|
25 | ); |
---|
26 | |
---|
27 | // Only do this if using one simple standard form gadget |
---|
28 | $this->check_access($form, 'code'); |
---|
29 | } |
---|
30 | |
---|
31 | function convert_options(&$options) { |
---|
32 | if (!isset($options['code']) && isset($this->argument->options['default_argument_php'])) { |
---|
33 | $options['code'] = $this->argument->options['default_argument_php']; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Only let users with PHP block visibility permissions set/modify this |
---|
39 | * default plugin. |
---|
40 | */ |
---|
41 | function access() { |
---|
42 | return user_access('use PHP for block visibility'); |
---|
43 | } |
---|
44 | |
---|
45 | function get_argument() { |
---|
46 | // set up variables to make it easier to reference during the argument. |
---|
47 | $view = &$this->view; |
---|
48 | $argument = &$this->argument; |
---|
49 | ob_start(); |
---|
50 | $result = eval($this->options['code']); |
---|
51 | ob_end_clean(); |
---|
52 | return $result; |
---|
53 | } |
---|
54 | } |
---|