Removed parse_expression() & added error logging to eval_expression().

pull/67/head^2
Andy Wermke 12 years ago
parent fe245e5f5d
commit 58e3a504b9

@ -759,14 +759,11 @@ class rcmail_output_html extends rcmail_output
/** /**
* Parses expression and replaces variables * Parse & evaluate a given expression and return its result.
*
* @param string Expression statement * @param string Expression statement
* @return string Expression value
*/ */
protected function parse_expression($expression) protected function eval_expression ($expression) {
{ $expression = preg_replace(
return preg_replace(
array( array(
'/session:([a-z0-9_]+)/i', '/session:([a-z0-9_]+)/i',
'/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i', '/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
@ -785,16 +782,19 @@ class rcmail_output_html extends rcmail_output
"\$browser->{'\\1'}", "\$browser->{'\\1'}",
$this->template_name, $this->template_name,
), ),
$expression); $expression
} );
/**
* Evaluate a given expression and return its result.
* @param string Expression statement
*/
protected function eval_expression ($expression) {
$expression = $this->parse_expression($expression);
$fn = create_function('$app,$browser,$env', "return ($expression);"); $fn = create_function('$app,$browser,$env', "return ($expression);");
if(!$fn) {
rcube::raise_error(array(
'code' => 505,
'type' => 'php',
'file' => __FILE__,
'line' => __LINE__,
'message' => "Expression parse error on: ($expression)"), true, false);
}
return $fn($this->app, $this->browser, $this->env); return $fn($this->app, $this->browser, $this->env);
} }

Loading…
Cancel
Save