Permalink
Browse files

Merge branch 'master' into CorePack

  • Loading branch information...
nao-pon committed Nov 3, 2017
2 parents f1d8742 + 7556e90 commit 35b0c36c68d7c2379c4ef2e4aea220dca91499ee
@@ -27,7 +27,7 @@
* @author Monte Ohrt <monte at ohrt dot com>
* @author Andrei Zmievski <andrei@php.net>
* @package Smarty
* @version 2.6.30
* @version 2.6.31-dev
*/
/* $Id$ */
@@ -63,10 +63,6 @@
*/
class Smarty
{
/**#@+
* Smarty Configuration Section
*/
/**
* For backward compatibility of XOOPS Cube
*/
@@ -75,6 +71,10 @@ public function Smarty()
self::__construct();
}
/**#@+
* Smarty Configuration Section
*/
/**
* The name of the directory where templates are located.
*
@@ -473,7 +473,7 @@ public function Smarty()
*
* @var string
*/
var $_version = '2.6.30';
var $_version = '2.6.31';
/**
* current template inclusion depth
@@ -33,7 +33,6 @@
* @package Smarty
*/
class Smarty_Compiler extends Smarty {
/**
* For backward compatibility of XOOPS Cube
*/
@@ -267,14 +266,9 @@ function _compile_file($resource_name, $source_content, &$compiled_content)
preg_match_all($search, $source_content, $match, PREG_SET_ORDER);
$this->_folded_blocks = $match;
reset($this->_folded_blocks);
/* replace special blocks by "{php}" */
$source_content = preg_replace_callback($search, create_function ('$matches', "return '"
. $this->_quote_replace($this->left_delimiter) . 'php'
. "' . str_repeat(\"\n\", substr_count('\$matches[1]', \"\n\")) .'"
. $this->_quote_replace($this->right_delimiter)
. "';")
$source_content = preg_replace_callback($search, array($this,'_preg_callback')
, $source_content);
/* Gather all template tags. */
@@ -564,7 +558,7 @@ function _compile_tag($template_tag)
case 'php':
/* handle folded tags replaced by {php} */
list(, $block) = each($this->_folded_blocks);
$block = array_shift($this->_folded_blocks);
$this->_current_line_no += substr_count($block[0], "\n");
/* the number of matched elements in the regexp in _compile_file()
determins the type of folded tag that was found */
@@ -762,7 +756,12 @@ function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output)
return true;
}
function _preg_callback ($matches) {
return $this->_quote_replace($this->left_delimiter)
. 'php'
. str_repeat("\n", substr_count($matches[1], "\n"))
. $this->_quote_replace($this->right_delimiter);
}
/**
* compile custom function tag
*
@@ -18,11 +18,11 @@
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Smarty
*
* @return string|null
*/
function smarty_function_math($params, $template)
function smarty_function_math($params, &$smarty)
{
static $_allowed_funcs =
array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
@@ -58,30 +58,35 @@ function smarty_function_math($params, $template)
return;
}
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val) == 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
return;
}
}
}
// match all vars in equation, make sure all are passed
preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
foreach ($match[ 1 ] as $curr_var) {
if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
trigger_error("math: function call $curr_var not allowed", E_USER_WARNING);
trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING);
return;
}
}
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val) == 0) {
trigger_error("math: parameter $key is empty", E_USER_WARNING);
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter $key: is not numeric", E_USER_WARNING);
return;
}
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
}
}
@@ -92,13 +97,13 @@ function smarty_function_math($params, $template)
if (empty($params[ 'assign' ])) {
return $smarty_math_result;
} else {
$template->assign($params[ 'assign' ], $smarty_math_result);
$smarty->assign($params[ 'assign' ], $smarty_math_result);
}
} else {
if (empty($params[ 'assign' ])) {
printf($params[ 'format' ], $smarty_math_result);
} else {
$template->assign($params[ 'assign' ], sprintf($params[ 'format' ], $smarty_math_result));
$smarty->assign($params[ 'assign' ], sprintf($params[ 'format' ], $smarty_math_result));
}
}
}

0 comments on commit 35b0c36

Please sign in to comment.