Version 1.14a

This commit is contained in:
nemunaire 2020-11-15 16:12:32 +01:00
commit dc48225dc9
1094 changed files with 189052 additions and 13889 deletions

View file

@ -2,7 +2,7 @@
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
* @subpackage PluginsFunction
*/
@ -15,24 +15,22 @@
* @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
* @param Smarty
* @param array $params parameters
* @param object $smarty Smarty object
* @param object $template template object
* @return string|null if the assign parameter is passed, Smarty assigns the
* result to a template variable
*/
function smarty_function_fetch($params, &$smarty)
function smarty_function_fetch($params, $smarty, $template)
{
if (empty($params['file'])) {
$smarty->_trigger_fatal_error("[plugin] parameter 'file' cannot be empty");
throw new Exception ("[plugin] fetch parameter 'file' cannot be empty");
return;
}
$content = '';
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');
if ($template->security && !preg_match('!^(http|ftp)://!i', $params['file'])) {
if(!$smarty->security_handler->isTrustedResourceDir($params['file'])) {
return;
}
@ -43,7 +41,7 @@ function smarty_function_fetch($params, &$smarty)
}
fclose($fp);
} else {
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
throw new Exception ('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
return;
}
} else {
@ -96,7 +94,7 @@ function smarty_function_fetch($params, &$smarty)
case "header":
if(!empty($param_value)) {
if(!preg_match('![\w\d-]+: .+!',$param_value)) {
$smarty->_trigger_fatal_error("[plugin] invalid header format '".$param_value."'");
throw new Exception ("[plugin] invalid header format '".$param_value."'");
return;
} else {
$extra_headers[] = $param_value;
@ -112,7 +110,7 @@ function smarty_function_fetch($params, &$smarty)
if(!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
} else {
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
throw new Exception ("[plugin] invalid value for attribute '".$param_key."'");
return;
}
break;
@ -130,12 +128,12 @@ function smarty_function_fetch($params, &$smarty)
if(!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
throw new Exception ("[plugin] invalid value for attribute '".$param_key."'");
return;
}
break;
default:
$smarty->_trigger_fatal_error("[plugin] unrecognized attribute '".$param_key."'");
throw new Exception ("[plugin] unrecognized attribute '".$param_key."'");
return;
}
}
@ -147,7 +145,7 @@ function smarty_function_fetch($params, &$smarty)
}
if(!$fp) {
$smarty->_trigger_fatal_error("[plugin] unable to fetch: $errstr ($errno)");
throw new Exception ("[plugin] unable to fetch: $errstr ($errno)");
return;
} else {
if($_is_proxy) {
@ -181,16 +179,16 @@ function smarty_function_fetch($params, &$smarty)
$content .= fgets($fp,4096);
}
fclose($fp);
$csplit = split("\r\n\r\n",$content,2);
$csplit = preg_split("!\r\n\r\n!",$content,2);
$content = $csplit[1];
if(!empty($params['assign_headers'])) {
$smarty->assign($params['assign_headers'],split("\r\n",$csplit[0]));
$template->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0]));
}
}
} else {
$smarty->_trigger_fatal_error("[plugin] unable to parse URL, check syntax");
throw new Exception ("[plugin] unable to parse URL, check syntax");
return;
}
} else {
@ -201,7 +199,7 @@ function smarty_function_fetch($params, &$smarty)
}
fclose($fp);
} else {
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'');
throw new Exception ('[plugin] fetch cannot read file \'' . $params['file'] .'\'');
return;
}
}
@ -210,12 +208,10 @@ function smarty_function_fetch($params, &$smarty)
if (!empty($params['assign'])) {
$smarty->assign($params['assign'],$content);
$template->assign($params['assign'],$content);
} else {
return $content;
}
}
/* vim: set expandtab: */
?>