Révision 950416da
Ajouté par Assos Assos il y a plus de 5 ans
drupal7/sites/all/modules/rules/modules/php.eval.inc | ||
---|---|---|
5 | 5 |
* Contains rules integration for the php module needed during evaluation. |
6 | 6 |
* |
7 | 7 |
* @addtogroup rules |
8 |
* |
|
8 | 9 |
* @{ |
9 | 10 |
*/ |
10 | 11 |
|
... | ... | |
13 | 14 |
*/ |
14 | 15 |
class RulesPHPEvaluator extends RulesDataInputEvaluator { |
15 | 16 |
|
16 |
public static function access() { |
|
17 |
return user_access('use PHP for settings'); |
|
17 |
/** |
|
18 |
* Overrides RulesDataProcessor::editAccess(). |
|
19 |
*/ |
|
20 |
public function editAccess() { |
|
21 |
return parent::editAccess() && (user_access('use PHP for settings') || drupal_is_cli()); |
|
18 | 22 |
} |
19 | 23 |
|
24 |
/** |
|
25 |
* Helper function to find variables in PHP code. |
|
26 |
* |
|
27 |
* @param string $text |
|
28 |
* The PHP code. |
|
29 |
* @param array $var_info |
|
30 |
* Array with variable names as keys. |
|
31 |
*/ |
|
20 | 32 |
public static function getUsedVars($text, $var_info) { |
21 | 33 |
if (strpos($text, '<?') !== FALSE) { |
22 | 34 |
$used_vars = array(); |
... | ... | |
29 | 41 |
} |
30 | 42 |
} |
31 | 43 |
|
44 |
/** |
|
45 |
* Overrides RulesDataInputEvaluator::prepare(). |
|
46 |
*/ |
|
32 | 47 |
public function prepare($text, $var_info) { |
33 | 48 |
// A returned NULL skips the evaluator. |
34 | 49 |
$this->setting = self::getUsedVars($text, $var_info); |
35 | 50 |
} |
36 | 51 |
|
37 | 52 |
/** |
38 |
* Evaluates PHP code contained in $text. This doesn't apply $options, thus |
|
39 |
* the PHP code is responsible for behaving appropriately. |
|
53 |
* Evaluates PHP code contained in $text. |
|
54 |
* |
|
55 |
* This method doesn't apply $options, thus the PHP code is responsible for |
|
56 |
* behaving appropriately. |
|
40 | 57 |
*/ |
41 | 58 |
public function evaluate($text, $options, RulesState $state) { |
42 | 59 |
$vars['eval_options'] = $options; |
... | ... | |
46 | 63 |
return rules_php_eval($text, rules_unwrap_data($vars)); |
47 | 64 |
} |
48 | 65 |
|
66 |
/** |
|
67 |
* Overrides RulesDataInputEvaluator::help(). |
|
68 |
*/ |
|
49 | 69 |
public static function help($var_info) { |
50 | 70 |
module_load_include('inc', 'rules', 'rules/modules/php.rules'); |
51 | 71 |
|
... | ... | |
58 | 78 |
|
59 | 79 |
return $render; |
60 | 80 |
} |
81 |
|
|
61 | 82 |
} |
62 | 83 |
|
63 | 84 |
/** |
... | ... | |
65 | 86 |
*/ |
66 | 87 |
class RulesPHPDataProcessor extends RulesDataProcessor { |
67 | 88 |
|
89 |
/** |
|
90 |
* Overrides RulesDataProcessor::form(). |
|
91 |
*/ |
|
68 | 92 |
protected static function form($settings, $var_info) { |
69 | 93 |
$settings += array('code' => ''); |
70 | 94 |
$form = array( |
... | ... | |
84 | 108 |
return $form; |
85 | 109 |
} |
86 | 110 |
|
87 |
public static function access() { |
|
88 |
return user_access('use PHP for settings'); |
|
111 |
/** |
|
112 |
* Overrides RulesDataProcessor::editAccess(). |
|
113 |
*/ |
|
114 |
public function editAccess() { |
|
115 |
return parent::editAccess() && (user_access('use PHP for settings') || drupal_is_cli()); |
|
89 | 116 |
} |
90 | 117 |
|
118 |
/** |
|
119 |
* Overrides RulesDataProcessor::process(). |
|
120 |
*/ |
|
91 | 121 |
public function process($value, $info, RulesState $state, RulesPlugin $element) { |
92 | 122 |
$value = isset($this->processor) ? $this->processor->process($value, $info, $state, $element) : $value; |
93 | 123 |
return rules_php_eval_return($this->setting['code'], array('value' => $value)); |
94 | 124 |
} |
125 |
|
|
95 | 126 |
} |
96 | 127 |
|
97 | 128 |
/** |
... | ... | |
108 | 139 |
} |
109 | 140 |
|
110 | 141 |
/** |
111 |
* Evalutes the given PHP code, with the given variables defined. |
|
142 |
* Evaluates the given PHP code, with the given variables defined.
|
|
112 | 143 |
* |
113 |
* @param $code |
|
114 |
* The PHP code to run, with <?php ?>
|
|
115 |
* @param $arguments |
|
144 |
* @param string $code
|
|
145 |
* The PHP code to run, including <?php and ?>
|
|
146 |
* @param array $arguments
|
|
116 | 147 |
* Array containing variables to be extracted to the code. |
117 | 148 |
* |
118 | 149 |
* @return |
... | ... | |
122 | 153 |
extract($arguments); |
123 | 154 |
|
124 | 155 |
ob_start(); |
125 |
print eval('?>'. $code); |
|
156 |
print eval('?>' . $code);
|
|
126 | 157 |
$output = ob_get_contents(); |
127 | 158 |
ob_end_clean(); |
128 | 159 |
|
... | ... | |
130 | 161 |
} |
131 | 162 |
|
132 | 163 |
/** |
133 |
* Evalutes the given PHP code, with the given variables defined. This is like |
|
134 |
* rules_php_eval() but does return the returned data from the PHP code. |
|
164 |
* Evaluates the given PHP code, with the given variables defined. |
|
135 | 165 |
* |
136 |
* @param $code |
|
137 |
* The PHP code to run, without <?php ?> |
|
138 |
* @param $arguments |
|
139 |
* Array containing variables to be extracted to the code. |
|
166 |
* This is like rules_php_eval(), but does return the returned data from |
|
167 |
* the PHP code. |
|
168 |
* |
|
169 |
* @param string $code |
|
170 |
* The PHP code to run, without <?php or ?> |
|
171 |
* @param array $arguments |
|
172 |
* Array containing variables to be extracted to the code. |
|
140 | 173 |
* |
141 | 174 |
* @return |
142 | 175 |
* The return value of the evaled code. |
Formats disponibles : Unified diff
Weekly update of contrib modules