|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/**
|
|
Chris PeBenito |
696b41 |
* Smarty plugin
|
|
Chris PeBenito |
696b41 |
* @package Smarty
|
|
Chris PeBenito |
696b41 |
* @subpackage plugins
|
|
Chris PeBenito |
696b41 |
*/
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/**
|
|
Chris PeBenito |
696b41 |
* Retrieves PHP script resource
|
|
Chris PeBenito |
696b41 |
*
|
|
Chris PeBenito |
696b41 |
* sets $php_resource to the returned resource
|
|
Chris PeBenito |
696b41 |
* @param string $resource
|
|
Chris PeBenito |
696b41 |
* @param string $resource_type
|
|
Chris PeBenito |
696b41 |
* @param $php_resource
|
|
Chris PeBenito |
696b41 |
* @return boolean
|
|
Chris PeBenito |
696b41 |
*/
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
function smarty_core_get_php_resource(&$params, &$smarty)
|
|
Chris PeBenito |
696b41 |
{
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
$params['resource_base_path'] = $smarty->trusted_dir;
|
|
Chris PeBenito |
696b41 |
$smarty->_parse_resource_name($params, $smarty);
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/*
|
|
Chris PeBenito |
696b41 |
* Find out if the resource exists.
|
|
Chris PeBenito |
696b41 |
*/
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
if ($params['resource_type'] == 'file') {
|
|
Chris PeBenito |
696b41 |
$_readable = false;
|
|
Chris PeBenito |
696b41 |
if(file_exists($params['resource_name']) && is_readable($params['resource_name'])) {
|
|
Chris PeBenito |
696b41 |
$_readable = true;
|
|
Chris PeBenito |
696b41 |
} else {
|
|
Chris PeBenito |
696b41 |
// test for file in include_path
|
|
Chris PeBenito |
696b41 |
$_params = array('file_path' => $params['resource_name']);
|
|
Chris PeBenito |
696b41 |
require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
|
|
Chris PeBenito |
696b41 |
if(smarty_core_get_include_path($_params, $smarty)) {
|
|
Chris PeBenito |
696b41 |
$_include_path = $_params['new_file_path'];
|
|
Chris PeBenito |
696b41 |
$_readable = true;
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
} else if ($params['resource_type'] != 'file') {
|
|
Chris PeBenito |
696b41 |
$_template_source = null;
|
|
Chris PeBenito |
696b41 |
$_readable = is_callable($smarty->_plugins['resource'][$params['resource_type']][0][0])
|
|
Chris PeBenito |
696b41 |
&& call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0],
|
|
Chris PeBenito |
696b41 |
array($params['resource_name'], &$_template_source, &$smarty));
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/*
|
|
Chris PeBenito |
696b41 |
* Set the error function, depending on which class calls us.
|
|
Chris PeBenito |
696b41 |
*/
|
|
Chris PeBenito |
696b41 |
if (method_exists($smarty, '_syntax_error')) {
|
|
Chris PeBenito |
696b41 |
$_error_funcc = '_syntax_error';
|
|
Chris PeBenito |
696b41 |
} else {
|
|
Chris PeBenito |
696b41 |
$_error_funcc = 'trigger_error';
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
if ($_readable) {
|
|
Chris PeBenito |
696b41 |
if ($smarty->security) {
|
|
Chris PeBenito |
696b41 |
require_once(SMARTY_CORE_DIR . 'core.is_trusted.php');
|
|
Chris PeBenito |
696b41 |
if (!smarty_core_is_trusted($params, $smarty)) {
|
|
Chris PeBenito |
696b41 |
$smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted');
|
|
Chris PeBenito |
696b41 |
return false;
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
} else {
|
|
Chris PeBenito |
696b41 |
$smarty->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable');
|
|
Chris PeBenito |
696b41 |
return false;
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
if ($params['resource_type'] == 'file') {
|
|
Chris PeBenito |
696b41 |
$params['php_resource'] = $params['resource_name'];
|
|
Chris PeBenito |
696b41 |
} else {
|
|
Chris PeBenito |
696b41 |
$params['php_resource'] = $_template_source;
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
return true;
|
|
Chris PeBenito |
696b41 |
}
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
/* vim: set expandtab: */
|
|
Chris PeBenito |
696b41 |
|
|
Chris PeBenito |
696b41 |
?>
|