Update Smarty to v2.6.31 (fix compatibility with PHP 7.2)

This commit is contained in:
nemunaire 2020-11-15 17:12:18 +01:00
commit f88f9499d0
400 changed files with 3366 additions and 49622 deletions

View file

@ -2,7 +2,7 @@
/**
* Smarty plugin
* @package Smarty
* @subpackage PluginsFunction
* @subpackage plugins
*/
@ -15,22 +15,24 @@
* @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array $params parameters
* @param object $smarty Smarty object
* @param object $template template object
* @param array
* @param Smarty
* @return string|null if the assign parameter is passed, Smarty assigns the
* result to a template variable
*/
function smarty_function_fetch($params, $smarty, $template)
function smarty_function_fetch($params, &$smarty)
{
if (empty($params['file'])) {
throw new Exception ("[plugin] fetch parameter 'file' cannot be empty");
$smarty->_trigger_fatal_error("[plugin] parameter 'file' cannot be empty");
return;
}
$content = '';
if ($template->security && !preg_match('!^(http|ftp)://!i', $params['file'])) {
if(!$smarty->security_handler->isTrustedResourceDir($params['file'])) {
if ($smarty->security && !preg_match('!^(http|ftp)://!i', $params['file'])) {
$_params = array('resource_type' => 'file', 'resource_name' => $params['file']);
require_once(SMARTY_CORE_DIR . 'core.is_secure.php');
if(!smarty_core_is_secure($_params, $smarty)) {
$smarty->_trigger_fatal_error('[plugin] (secure mode) fetch \'' . $params['file'] . '\' is not allowed');
return;
}
@ -41,7 +43,7 @@ function smarty_function_fetch($params, $smarty, $template)
}
fclose($fp);
} else {
throw new Exception ('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
return;
}
} else {
@ -94,7 +96,7 @@ function smarty_function_fetch($params, $smarty, $template)
case "header":
if(!empty($param_value)) {
if(!preg_match('![\w\d-]+: .+!',$param_value)) {
throw new Exception ("[plugin] invalid header format '".$param_value."'");
$smarty->_trigger_fatal_error("[plugin] invalid header format '".$param_value."'");
return;
} else {
$extra_headers[] = $param_value;
@ -110,7 +112,7 @@ function smarty_function_fetch($params, $smarty, $template)
if(!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
} else {
throw new Exception ("[plugin] invalid value for attribute '".$param_key."'");
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
return;
}
break;
@ -128,12 +130,12 @@ function smarty_function_fetch($params, $smarty, $template)
if(!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
throw new Exception ("[plugin] invalid value for attribute '".$param_key."'");
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
return;
}
break;
default:
throw new Exception ("[plugin] unrecognized attribute '".$param_key."'");
$smarty->_trigger_fatal_error("[plugin] unrecognized attribute '".$param_key."'");
return;
}
}
@ -145,7 +147,7 @@ function smarty_function_fetch($params, $smarty, $template)
}
if(!$fp) {
throw new Exception ("[plugin] unable to fetch: $errstr ($errno)");
$smarty->_trigger_fatal_error("[plugin] unable to fetch: $errstr ($errno)");
return;
} else {
if($_is_proxy) {
@ -184,11 +186,11 @@ function smarty_function_fetch($params, $smarty, $template)
$content = $csplit[1];
if(!empty($params['assign_headers'])) {
$template->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0]));
$smarty->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0]));
}
}
} else {
throw new Exception ("[plugin] unable to parse URL, check syntax");
$smarty->_trigger_fatal_error("[plugin] unable to parse URL, check syntax");
return;
}
} else {
@ -199,7 +201,7 @@ function smarty_function_fetch($params, $smarty, $template)
}
fclose($fp);
} else {
throw new Exception ('[plugin] fetch cannot read file \'' . $params['file'] .'\'');
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'');
return;
}
}
@ -208,10 +210,12 @@ function smarty_function_fetch($params, $smarty, $template)
if (!empty($params['assign'])) {
$template->assign($params['assign'],$content);
$smarty->assign($params['assign'],$content);
} else {
return $content;
}
}
/* vim: set expandtab: */
?>