Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21059 Upgrade Smarty to 2.6.30 #195

Merged
merged 3 commits into from Oct 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Smarty/Config_File.class.php
Expand Up @@ -19,7 +19,7 @@
*
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @version 2.6.25-dev
Expand All @@ -29,7 +29,7 @@
* @package Smarty
*/

/* $Id: Config_File.class.php 3149 2009-05-23 20:59:25Z monte.ohrt $ */
/* $Id$ */

/**
* Config file reading class
Expand Down Expand Up @@ -73,7 +73,7 @@ class Config_File {
*
* @param string $config_path (optional) path to the config files
*/
function Config_File($config_path = NULL)
public function __construct($config_path = NULL)
{
if (isset($config_path))
$this->set_path($config_path);
Expand Down Expand Up @@ -301,7 +301,7 @@ function parse_contents($contents)
$vars = array();
continue;
}
} else {
} else {
$section_name = $match[1];
}
if (!isset($config_data['sections'][$section_name]))
Expand Down
24 changes: 14 additions & 10 deletions Smarty/Smarty.class.php
Expand Up @@ -27,10 +27,10 @@
* @author Monte Ohrt <monte at ohrt dot com>
* @author Andrei Zmievski <andrei@php.net>
* @package Smarty
* @version 2.6.27
* @version 2.6.30
*/

/* $Id: Smarty.class.php 4660 2012-09-24 20:05:15Z uwe.tews@googlemail.com $ */
/* $Id$ */

/**
* DIR_SEP isn't used anymore, but third party apps might
Expand Down Expand Up @@ -465,7 +465,7 @@ class Smarty
*
* @var string
*/
var $_version = '2.6.27';
var $_version = '2.6.30';

/**
* current template inclusion depth
Expand Down Expand Up @@ -562,11 +562,17 @@ class Smarty
*/
var $_cache_including = false;

/**
* plugin filepath cache
*
* @var array
*/
var $_filepaths_cache = array();
/**#@-*/
/**
* The class constructor.
*/
function Smarty()
public function __construct()
{
$this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
: @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
Expand Down Expand Up @@ -1511,10 +1517,8 @@ function _compile_source($resource_name, &$source_content, &$compiled_content, $
*/
function _get_compile_path($resource_name)
{
$compilePath = $this->_get_auto_filename( $this->compile_dir,
$resource_name,
$this->_compile_id );
$compilePath .= '.php';
$compilePath = $this->_get_auto_filename($this->compile_dir, $resource_name,
$this->_compile_id) . '.php';

//for 'string:' resource smarty might going to fail to create
//compile file, so make sure we should have valid path, CRM-5890
Expand Down Expand Up @@ -1542,9 +1546,9 @@ function validateCompilePath( $compilePath ) {
smarty_core_create_dir_structure( array('dir' => $dirname ), $this );
}

$isValid = false;
$isValid = FALSE;
if ( $fd = @fopen( $compilePath, 'wb') ) {
$isValid = true;
$isValid = TRUE;
@fclose( $fd );
@unlink($compilePath);
}
Expand Down
4 changes: 2 additions & 2 deletions Smarty/Smarty_Compiler.class.php
Expand Up @@ -26,7 +26,7 @@
* @package Smarty
*/

/* $Id: Smarty_Compiler.class.php 3163 2009-06-17 14:39:24Z monte.ohrt $ */
/* $Id$ */

/**
* Template compiling class
Expand Down Expand Up @@ -78,7 +78,7 @@ class Smarty_Compiler extends Smarty {
/**
* The class constructor.
*/
function Smarty_Compiler()
public function __construct()
{
// matches double quoted strings:
// "foobar"
Expand Down
8 changes: 3 additions & 5 deletions Smarty/internals/core.assemble_plugin_filepath.php
Expand Up @@ -14,11 +14,9 @@
*/
function smarty_core_assemble_plugin_filepath($params, &$smarty)
{
static $_filepaths_cache = array();

$_plugin_filename = $params['type'] . '.' . $params['name'] . '.php';
if (isset($_filepaths_cache[$_plugin_filename])) {
return $_filepaths_cache[$_plugin_filename];
if (isset($smarty->_filepaths_cache[$_plugin_filename])) {
return $smarty->_filepaths_cache[$_plugin_filename];
}
$_return = false;

Expand Down Expand Up @@ -58,7 +56,7 @@ function smarty_core_assemble_plugin_filepath($params, &$smarty)
}
}
}
$_filepaths_cache[$_plugin_filename] = $_return;
$smarty->_filepaths_cache[$_plugin_filename] = $_return;
return $_return;
}

Expand Down
98 changes: 60 additions & 38 deletions Smarty/plugins/function.math.php
@@ -1,85 +1,107 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
* This plugin is only for Smarty2 BC
*
* @package Smarty
* @subpackage PluginsFunction
*/


/**
* Smarty {math} function plugin
*
* Type: function<br>
* Name: math<br>
* Purpose: handle math computations in template<br>
* @link http://smarty.php.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* Purpose: handle math computations in template
*
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
*
* @param array $params parameters
* @param Smarty
* @return string
*
* @return string|null
*/
function smarty_function_math($params, &$smarty)
{
static $_allowed_funcs = array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true,
'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true);
// be sure equation parameter is present
if (empty($params['equation'])) {
$smarty->trigger_error("math: missing equation parameter");
trigger_error("math: missing equation parameter", E_USER_WARNING);

return;
}

// strip out backticks, not necessary for math
$equation = str_replace('`','',$params['equation']);
$equation = $params['equation'];

// make sure parenthesis are balanced
if (substr_count($equation,"(") != substr_count($equation,")")) {
$smarty->trigger_error("math: unbalanced parenthesis");
if (substr_count($equation, "(") != substr_count($equation, ")")) {
trigger_error("math: unbalanced parenthesis", 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][a-zA-Z0-9_]*)!",$equation, $match);
$allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');

foreach($match[1] as $curr_var) {
if ($curr_var && !in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
$smarty->trigger_error("math: function call $curr_var not allowed");
return;
}
// disallow backticks
if (strpos($equation, '`') !== FALSE) {
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);

return;
}

// also disallow dollar signs
if (strpos($equation, '$') !== FALSE) {
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);

return;
}

foreach($params as $key => $val) {
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val)==0) {
$smarty->trigger_error("math: parameter $key is empty");
if (strlen($val) == 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);

return;
}
if (!is_numeric($val)) {
$smarty->trigger_error("math: parameter $key: is not numeric");
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);

return;
}
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
}
}
// 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, or missing parameter '{$curr_var}'", E_USER_WARNING);

return;
}
}

eval("\$smarty_math_result = ".$equation.";");
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
}
}
$smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";");

if (empty($params['format'])) {
if (empty($params['assign'])) {
return $smarty_math_result;
} else {
$smarty->assign($params['assign'],$smarty_math_result);
$smarty->assign($params['assign'], $smarty_math_result);
}
} else {
if (empty($params['assign'])){
printf($params['format'],$smarty_math_result);
if (empty($params['assign'])) {
printf($params['format'], $smarty_math_result);
} else {
$smarty->assign($params['assign'],sprintf($params['format'],$smarty_math_result));
$smarty->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
}
}
}

/* vim: set expandtab: */

?>