started moving from $this to $smarty in core.*.php

This commit is contained in:
messju
2003-06-22 03:13:25 +00:00
parent b0562c1dce
commit 81bf74f327
22 changed files with 161 additions and 161 deletions

View File

@@ -15,14 +15,14 @@
* @staticvar string|null * @staticvar string|null
* @staticvar string|null * @staticvar string|null
*/ */
function smarty_core_assemble_auto_filename($params, &$this) function smarty_core_assemble_auto_filename($params, &$smarty)
{ {
static $_dir_sep = null; static $_dir_sep = null;
static $_dir_sep_enc = null; static $_dir_sep_enc = null;
if(!isset($_dir_sep)) { if(!isset($_dir_sep)) {
$_dir_sep_enc = urlencode(DIRECTORY_SEPARATOR); $_dir_sep_enc = urlencode(DIRECTORY_SEPARATOR);
if($this->use_sub_dirs) { if($smarty->use_sub_dirs) {
$_dir_sep = DIRECTORY_SEPARATOR; $_dir_sep = DIRECTORY_SEPARATOR;
} else { } else {
$_dir_sep = '^'; $_dir_sep = '^';
@@ -35,7 +35,7 @@ function smarty_core_assemble_auto_filename($params, &$this)
// auto_base not found, try include_path // auto_base not found, try include_path
$_params = array('file_path' => $params['auto_base']); $_params = array('file_path' => $params['auto_base']);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
smarty_core_get_include_path($_params, $this); smarty_core_get_include_path($_params, $smarty);
$_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null; $_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null;
} }
@@ -49,7 +49,7 @@ function smarty_core_assemble_auto_filename($params, &$this)
if(isset($params['auto_source'])) { if(isset($params['auto_source'])) {
// make source name safe for filename // make source name safe for filename
if($this->use_sub_dirs) { if($smarty->use_sub_dirs) {
$_filename = urlencode(basename($params['auto_source'])); $_filename = urlencode(basename($params['auto_source']));
$_crc32 = crc32($params['auto_source']) . $_dir_sep; $_crc32 = crc32($params['auto_source']) . $_dir_sep;
// prepend %% to avoid name conflicts with // prepend %% to avoid name conflicts with

View File

@@ -12,12 +12,12 @@
* @param string $name * @param string $name
* @return string|false * @return string|false
*/ */
function smarty_core_assemble_plugin_filepath($params, &$this) function smarty_core_assemble_plugin_filepath($params, &$smarty)
{ {
$_plugin_filename = $params['type'] . '.' . $params['name'] . '.php'; $_plugin_filename = $params['type'] . '.' . $params['name'] . '.php';
foreach ((array)$this->plugins_dir as $_plugin_dir) { foreach ((array)$smarty->plugins_dir as $_plugin_dir) {
$_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
@@ -44,7 +44,7 @@ function smarty_core_assemble_plugin_filepath($params, &$this)
$_params = array('file_path' => $_plugin_filepath); $_params = array('file_path' => $_plugin_filepath);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
if(smarty_core_get_include_path($_params, $this)) { if(smarty_core_get_include_path($_params, $smarty)) {
return $_params['new_file_path']; return $_params['new_file_path'];
} }
} }

View File

@@ -14,9 +14,9 @@
* @param array Format: null * @param array Format: null
* @param Smarty * @param Smarty
*/ */
function smarty_core_assign_smarty_interface($params, &$this) function smarty_core_assign_smarty_interface($params, &$smarty)
{ {
if (isset($this->_smarty_vars) && isset($this->_smarty_vars['request'])) { if (isset($smarty->_smarty_vars) && isset($smarty->_smarty_vars['request'])) {
return; return;
} }
@@ -28,14 +28,14 @@ function smarty_core_assign_smarty_interface($params, &$this)
$_smarty_vars_request = array(); $_smarty_vars_request = array();
foreach (preg_split('!!', strtolower($this->request_vars_order)) as $_c) { foreach (preg_split('!!', strtolower($smarty->request_vars_order)) as $_c) {
if (isset($_globals_map[$_c])) { if (isset($_globals_map[$_c])) {
$_smarty_vars_request = array_merge($_smarty_vars_request, $GLOBALS[$_globals_map[$_c]]); $_smarty_vars_request = array_merge($_smarty_vars_request, $GLOBALS[$_globals_map[$_c]]);
} }
} }
$_smarty_vars_request = @array_merge($_smarty_vars_request, $GLOBALS['HTTP_SESSION_VARS']); $_smarty_vars_request = @array_merge($_smarty_vars_request, $GLOBALS['HTTP_SESSION_VARS']);
$this->_smarty_vars['request'] = $_smarty_vars_request; $smarty->_smarty_vars['request'] = $_smarty_vars_request;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@@ -13,7 +13,7 @@
// $dir // $dir
function smarty_core_create_dir_structure($params, &$this) function smarty_core_create_dir_structure($params, &$smarty)
{ {
if (!file_exists($params['dir'])) { if (!file_exists($params['dir'])) {
$_open_basedir_ini = ini_get('open_basedir'); $_open_basedir_ini = ini_get('open_basedir');
@@ -65,8 +65,8 @@ function smarty_core_create_dir_structure($params, &$this)
$_make_new_dir = true; $_make_new_dir = true;
} }
if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir($_new_dir, $this->_dir_perms)) { if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir($_new_dir, $smarty->_dir_perms)) {
$this->trigger_error("problem creating directory '" . $_new_dir . "'"); $smarty->trigger_error("problem creating directory '" . $_new_dir . "'");
return false; return false;
} }
$_new_dir .= '/'; $_new_dir .= '/';

View File

@@ -19,7 +19,7 @@
* @return boolean * @return boolean
*/ */
function smarty_core_fetch_resource_info(&$params, &$this) function smarty_core_fetch_resource_info(&$params, &$smarty)
{ {
if(!isset($params['get_source'])) { $params['get_source'] = true; } if(!isset($params['get_source'])) { $params['get_source'] = true; }
@@ -28,13 +28,13 @@ function smarty_core_fetch_resource_info(&$params, &$this)
$_return = false; $_return = false;
$_params = array('resource_name' => $params['resource_name']) ; $_params = array('resource_name' => $params['resource_name']) ;
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.parse_resource_name.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.parse_resource_name.php');
if (smarty_core_parse_resource_name($_params, $this)) { if (smarty_core_parse_resource_name($_params, $smarty)) {
$_resource_type = $_params['resource_type']; $_resource_type = $_params['resource_type'];
$_resource_name = $_params['resource_name']; $_resource_name = $_params['resource_name'];
switch ($_resource_type) { switch ($_resource_type) {
case 'file': case 'file':
if ($params['get_source']) { if ($params['get_source']) {
$params['source_content'] = $this->_read_file($_resource_name); $params['source_content'] = $smarty->_read_file($_resource_name);
} }
$params['resource_timestamp'] = filemtime($_resource_name); $params['resource_timestamp'] = filemtime($_resource_name);
$_return = true; $_return = true;
@@ -43,16 +43,16 @@ function smarty_core_fetch_resource_info(&$params, &$this)
default: default:
// call resource functions to fetch the template source and timestamp // call resource functions to fetch the template source and timestamp
if ($params['get_source']) { if ($params['get_source']) {
$_source_return = isset($this->_plugins['resource'][$_resource_type]) && $_source_return = isset($smarty->_plugins['resource'][$_resource_type]) &&
call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], call_user_func_array($smarty->_plugins['resource'][$_resource_type][0][0],
array($_resource_name, &$params['source_content'], &$this)); array($_resource_name, &$params['source_content'], &$smarty));
} else { } else {
$_source_return = true; $_source_return = true;
} }
$_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && $_timestamp_return = isset($smarty->_plugins['resource'][$_resource_type]) &&
call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], call_user_func_array($smarty->_plugins['resource'][$_resource_type][0][1],
array($_resource_name, &$params['resource_timestamp'], &$this)); array($_resource_name, &$params['resource_timestamp'], &$smarty));
$_return = $_source_return && $_timestamp_return; $_return = $_source_return && $_timestamp_return;
break; break;
@@ -61,13 +61,13 @@ function smarty_core_fetch_resource_info(&$params, &$this)
if (!$_return) { if (!$_return) {
// see if we can get a template with the default template handler // see if we can get a template with the default template handler
if (!empty($this->default_template_handler_func)) { if (!empty($smarty->default_template_handler_func)) {
if (!$this->_plugin_implementation_exists($this->default_template_handler_func)) { if (!$smarty->_plugin_implementation_exists($smarty->default_template_handler_func)) {
$this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); $smarty->trigger_error("default template handler function \"$smarty->default_template_handler_func\" doesn't exist.");
} else { } else {
$_return = call_user_func_array( $_return = call_user_func_array(
$this->default_template_handler_func, $smarty->default_template_handler_func,
array($_resource_type, $_resource_name, &$params['source_content'], &$params['resource_timestamp'], &$this)); array($_resource_type, $_resource_name, &$params['source_content'], &$params['resource_timestamp'], &$smarty));
} }
} }
} }
@@ -75,11 +75,11 @@ function smarty_core_fetch_resource_info(&$params, &$this)
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');
if (!$_return) { if (!$_return) {
if (!$params['quiet']) { if (!$params['quiet']) {
$this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); $smarty->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');
} }
} else if ($_return && $this->security && !smarty_core_is_secure($_params, $this)) { } else if ($_return && $smarty->security && !smarty_core_is_secure($_params, $smarty)) {
if (!$params['quiet']) if (!$params['quiet'])
$this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); $smarty->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
$params['source_content'] = null; $params['source_content'] = null;
$params['resource_timestamp'] = null; $params['resource_timestamp'] = null;
return false; return false;

View File

@@ -16,7 +16,7 @@
// $file_path, &$new_file_path // $file_path, &$new_file_path
function smarty_core_get_include_path(&$params, &$this) function smarty_core_get_include_path(&$params, &$smarty)
{ {
static $_path_array = null; static $_path_array = null;

View File

@@ -9,7 +9,7 @@
* Get seconds and microseconds * Get seconds and microseconds
* @return double * @return double
*/ */
function smarty_core_get_microtime($params, &$this) function smarty_core_get_microtime($params, &$smarty)
{ {
$mtime = microtime(); $mtime = microtime();
$mtime = explode(" ", $mtime); $mtime = explode(" ", $mtime);

View File

@@ -15,12 +15,12 @@
* @return boolean * @return boolean
*/ */
function smarty_core_get_php_resource(&$params, &$this) function smarty_core_get_php_resource(&$params, &$smarty)
{ {
$params['resource_base_path'] = $this->trusted_dir; $params['resource_base_path'] = $smarty->trusted_dir;
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.parse_resource_name.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.parse_resource_name.php');
smarty_core_parse_resource_name($params, $this); smarty_core_parse_resource_name($params, $smarty);
/* /*
* Find out if the resource exists. * Find out if the resource exists.
@@ -34,37 +34,37 @@ function smarty_core_get_php_resource(&$params, &$this)
// test for file in include_path // test for file in include_path
$_params = array('file_path' => $params['resource_name']); $_params = array('file_path' => $params['resource_name']);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
if(smarty_core_get_include_path($_params, $this)) { if(smarty_core_get_include_path($_params, $smarty)) {
$_include_path = $_params['new_file_path']; $_include_path = $_params['new_file_path'];
$_readable = true; $_readable = true;
} }
} }
} else if ($params['resource_type'] != 'file') { } else if ($params['resource_type'] != 'file') {
$_template_source = null; $_template_source = null;
$_readable = $this->_plugin_implementation_exists($this->_plugins['resource'][$params['resource_type']][0][0]) $_readable = $smarty->_plugin_implementation_exists($smarty->_plugins['resource'][$params['resource_type']][0][0])
&& call_user_func_array($this->_plugins['resource'][$params['resource_type']][0][0], && call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0],
array($params['resource_name'], &$_template_source, &$this)); array($params['resource_name'], &$_template_source, &$smarty));
} }
/* /*
* Set the error function, depending on which class calls us. * Set the error function, depending on which class calls us.
*/ */
if (method_exists($this, '_syntax_error')) { if (method_exists($smarty, '_syntax_error')) {
$_error_funcc = '_syntax_error'; $_error_funcc = '_syntax_error';
} else { } else {
$_error_funcc = 'trigger_error'; $_error_funcc = 'trigger_error';
} }
if ($_readable) { if ($_readable) {
if ($this->security) { if ($smarty->security) {
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_trusted.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_trusted.php');
if (!smarty_core_is_trusted($params, $this)) { if (!smarty_core_is_trusted($params, $smarty)) {
$this->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted'); $smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted');
return false; return false;
} }
} }
} else { } else {
$this->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable'); $smarty->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable');
return false; return false;
} }

View File

@@ -15,16 +15,16 @@
// $resource_type, $resource_name // $resource_type, $resource_name
function smarty_core_is_secure($params, &$this) function smarty_core_is_secure($params, &$smarty)
{ {
if (!$this->security || $this->security_settings['INCLUDE_ANY']) { if (!$smarty->security || $smarty->security_settings['INCLUDE_ANY']) {
return true; return true;
} }
$_smarty_secure = false; $_smarty_secure = false;
if ($params['resource_type'] == 'file') { if ($params['resource_type'] == 'file') {
if (!empty($this->secure_dir)) { if (!empty($smarty->secure_dir)) {
foreach ((array)$this->secure_dir as $curr_dir) { foreach ((array)$smarty->secure_dir as $curr_dir) {
if ( !empty($curr_dir) && is_readable ($curr_dir)) { if ( !empty($curr_dir) && is_readable ($curr_dir)) {
if (substr(realpath($params['resource_name']),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) { if (substr(realpath($params['resource_name']),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) {
$_smarty_secure = true; $_smarty_secure = true;
@@ -36,8 +36,8 @@ function smarty_core_is_secure($params, &$this)
} else { } else {
// resource is not on local file system // resource is not on local file system
$_smarty_secure = call_user_func_array( $_smarty_secure = call_user_func_array(
$this->_plugins['resource'][$params['resource_type']][0][2], $smarty->_plugins['resource'][$params['resource_type']][0][2],
array($params['resource_name'], &$_smarty_secure, &$this)); array($params['resource_name'], &$_smarty_secure, &$smarty));
} }
return $_smarty_secure; return $_smarty_secure;

View File

@@ -18,16 +18,16 @@
// $resource_type, $resource_name // $resource_type, $resource_name
function smarty_core_is_trusted($params, &$this) function smarty_core_is_trusted($params, &$smarty)
{ {
$_smarty_trusted = false; $_smarty_trusted = false;
if ($params['resource_type'] == 'file') { if ($params['resource_type'] == 'file') {
if (!empty($this->trusted_dir)) { if (!empty($smarty->trusted_dir)) {
// see if template file is within a trusted directory. If so, // see if template file is within a trusted directory. If so,
// disable security during the execution of the template. // disable security during the execution of the template.
if (!empty($this->trusted_dir)) { if (!empty($smarty->trusted_dir)) {
foreach ((array)$this->trusted_dir as $curr_dir) { foreach ((array)$smarty->trusted_dir as $curr_dir) {
if (!empty($curr_dir) && is_readable ($curr_dir)) { if (!empty($curr_dir) && is_readable ($curr_dir)) {
if (substr(realpath($params['resource_name']),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) { if (substr(realpath($params['resource_name']),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) {
$_smarty_trusted = true; $_smarty_trusted = true;
@@ -39,8 +39,8 @@ function smarty_core_is_trusted($params, &$this)
} }
} else { } else {
// resource is not on local file system // resource is not on local file system
$_smarty_trusted = call_user_func_array($this->_plugins['resource'][$params['resource_type']][0][3], $_smarty_trusted = call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][3],
array($params['resource_name'], $this)); array($params['resource_name'], $smarty));
} }
return $_smarty_trusted; return $_smarty_trusted;

View File

@@ -13,12 +13,12 @@
// $plugins // $plugins
function smarty_core_load_plugins($params, &$this) function smarty_core_load_plugins($params, &$smarty)
{ {
foreach ($params['plugins'] as $_plugin_info) { foreach ($params['plugins'] as $_plugin_info) {
list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info; list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info;
$_plugin = &$this->_plugins[$_type][$_name]; $_plugin = &$smarty->_plugins[$_type][$_name];
/* /*
* We do not load plugin more than once for each instance of Smarty. * We do not load plugin more than once for each instance of Smarty.
@@ -32,8 +32,8 @@ function smarty_core_load_plugins($params, &$this)
*/ */
if (isset($_plugin)) { if (isset($_plugin)) {
if (empty($_plugin[3])) { if (empty($_plugin[3])) {
if (!$this->_plugin_implementation_exists($_plugin[0])) { if (!$smarty->_plugin_implementation_exists($_plugin[0])) {
$this->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__); $smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
} else { } else {
$_plugin[1] = $_tpl_file; $_plugin[1] = $_tpl_file;
$_plugin[2] = $_tpl_line; $_plugin[2] = $_tpl_line;
@@ -54,7 +54,7 @@ function smarty_core_load_plugins($params, &$this)
} }
} }
$_plugin_file = $this->_get_plugin_filepath($_type, $_name); $_plugin_file = $smarty->_get_plugin_filepath($_type, $_name);
if (! $_found = ($_plugin_file != false)) { if (! $_found = ($_plugin_file != false)) {
$_message = "could not load plugin file '$_type.$_name.php'\n"; $_message = "could not load plugin file '$_type.$_name.php'\n";
@@ -69,8 +69,8 @@ function smarty_core_load_plugins($params, &$this)
include_once $_plugin_file; include_once $_plugin_file;
$_plugin_func = 'smarty_' . $_type . '_' . $_name; $_plugin_func = 'smarty_' . $_type . '_' . $_name;
if (!$this->_plugin_implementation_exists($_plugin_func)) { if (!$smarty->_plugin_implementation_exists($_plugin_func)) {
$this->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__); $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
continue; continue;
} }
} }
@@ -93,7 +93,7 @@ function smarty_core_load_plugins($params, &$this)
* directly, we only allow those specified in the security * directly, we only allow those specified in the security
* context. * context.
*/ */
if ($this->security && !in_array($_name, $this->security_settings['MODIFIER_FUNCS'])) { if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {
$_message = "(secure mode) modifier '$_name' is not allowed"; $_message = "(secure mode) modifier '$_name' is not allowed";
} else { } else {
if (!function_exists($_name)) { if (!function_exists($_name)) {
@@ -112,10 +112,10 @@ function smarty_core_load_plugins($params, &$this)
} }
if ($_found) { if ($_found) {
$this->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true); $smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true);
} else { } else {
// output error // output error
$this->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__); $smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__);
} }
} }
} }

View File

@@ -13,7 +13,7 @@
// $type // $type
function smarty_core_load_resource_plugin($params, &$this) function smarty_core_load_resource_plugin($params, &$smarty)
{ {
/* /*
* Resource plugins are not quite like the other ones, so they are * Resource plugins are not quite like the other ones, so they are
@@ -22,12 +22,12 @@ function smarty_core_load_resource_plugin($params, &$this)
* all of them exist or not. * all of them exist or not.
*/ */
$_plugin = &$this->_plugins['resource'][$params['type']]; $_plugin = &$smarty->_plugins['resource'][$params['type']];
if (isset($_plugin)) { if (isset($_plugin)) {
if (!$_plugin[1] && count($_plugin[0])) { if (!$_plugin[1] && count($_plugin[0])) {
$_plugin[1] = true; $_plugin[1] = true;
foreach ($_plugin[0] as $_plugin_func) { foreach ($_plugin[0] as $_plugin_func) {
if (!$this->_plugin_implementation_exists($_plugin_func)) { if (!$smarty->_plugin_implementation_exists($_plugin_func)) {
$_plugin[1] = false; $_plugin[1] = false;
break; break;
} }
@@ -35,20 +35,20 @@ function smarty_core_load_resource_plugin($params, &$this)
} }
if (!$_plugin[1]) { if (!$_plugin[1]) {
$this->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__); $smarty->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__);
} }
return; return;
} }
$_plugin_file = $this->_get_plugin_filepath('resource', $params['type']); $_plugin_file = $smarty->_get_plugin_filepath('resource', $params['type']);
$_found = ($_plugin_file != false); $_found = ($_plugin_file != false);
if ($_found) { /* if ($_found) { /*
* If the plugin file is found, it -must- provide the properly named * If the plugin file is found, it -must- provide the properly named
* plugin functions. * plugin functions.
*/ */
include_once $_plugin_file; $smarty->smarty_include_once($_plugin_file);
/* /*
* Locate functions that we require the plugin to provide. * Locate functions that we require the plugin to provide.
@@ -58,14 +58,14 @@ function smarty_core_load_resource_plugin($params, &$this)
foreach ($_resource_ops as $_op) { foreach ($_resource_ops as $_op) {
$_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op; $_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op;
if (!function_exists($_plugin_func)) { if (!function_exists($_plugin_func)) {
$this->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__); $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__);
return; return;
} else { } else {
$_resource_funcs[] = $_plugin_func; $_resource_funcs[] = $_plugin_func;
} }
} }
$this->_plugins['resource'][$params['type']] = array($_resource_funcs, true); $smarty->_plugins['resource'][$params['type']] = array($_resource_funcs, true);
} }
} }

View File

@@ -17,7 +17,7 @@
// $resource_base_path, $resource_name, &$resource_type, &$resource_name // $resource_base_path, $resource_name, &$resource_type, &$resource_name
function smarty_core_parse_resource_name(&$params, &$this) function smarty_core_parse_resource_name(&$params, &$smarty)
{ {
// split tpl_path by the first colon // split tpl_path by the first colon
@@ -25,12 +25,12 @@ function smarty_core_parse_resource_name(&$params, &$this)
if (count($_resource_name_parts) == 1) { if (count($_resource_name_parts) == 1) {
// no resource type given // no resource type given
$params['resource_type'] = $this->default_resource_type; $params['resource_type'] = $smarty->default_resource_type;
$params['resource_name'] = $_resource_name_parts[0]; $params['resource_name'] = $_resource_name_parts[0];
} else { } else {
if(strlen($_resource_name_parts[0]) == 1) { if(strlen($_resource_name_parts[0]) == 1) {
// 1 char is not resource type, but part of filepath // 1 char is not resource type, but part of filepath
$params['resource_type'] = $this->default_resource_type; $params['resource_type'] = $smarty->default_resource_type;
$params['resource_name'] = $params['resource_name']; $params['resource_name'] = $params['resource_name'];
} else { } else {
$params['resource_type'] = $_resource_name_parts[0]; $params['resource_type'] = $_resource_name_parts[0];
@@ -42,7 +42,7 @@ function smarty_core_parse_resource_name(&$params, &$this)
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) { if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) {
// relative pathname to $params['resource_base_path'] // relative pathname to $params['resource_base_path']
// use the first directory where the file is found // use the first directory where the file is found
$_resource_base_path = isset($params['resource_base_path']) ? $params['resource_base_path'] : array($this->template_dir, '.'); $_resource_base_path = isset($params['resource_base_path']) ? $params['resource_base_path'] : array($smarty->template_dir, '.');
settype($_resource_base_path, 'array'); settype($_resource_base_path, 'array');
foreach ($_resource_base_path as $_curr_path) { foreach ($_resource_base_path as $_curr_path) {
$_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];
@@ -51,10 +51,10 @@ function smarty_core_parse_resource_name(&$params, &$this)
return true; return true;
} }
// didn't find the file, try include_path // didn't find the file, try include_path
$_params = array('resource_name' => $_fullpath); $_params = array('file_path' => $_fullpath);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
if(smarty_core_get_include_path($_params, $this)) { if(smarty_core_get_include_path($_params, $smarty)) {
$params['resource_name'] = $_params['new_resource_name']; $params['resource_name'] = $_params['new_file_path'];
return true; return true;
} }
} }
@@ -63,7 +63,7 @@ function smarty_core_parse_resource_name(&$params, &$this)
} else { } else {
$_params = array('type' => $params['resource_type']); $_params = array('type' => $params['resource_type']);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_resource_plugin.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_resource_plugin.php');
smarty_core_load_resource_plugin($_params, $this); smarty_core_load_resource_plugin($_params, $smarty);
} }
return true; return true;

View File

@@ -18,29 +18,29 @@
// $tpl_file, $cache_id, $compile_id, &$results // $tpl_file, $cache_id, $compile_id, &$results
function smarty_core_read_cache_file(&$params, &$this) function smarty_core_read_cache_file(&$params, &$smarty)
{ {
static $content_cache = array(); static $content_cache = array();
if ($this->force_compile) { if ($smarty->force_compile) {
// force compile enabled, always regenerate // force compile enabled, always regenerate
return false; return false;
} }
if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) { if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
list($params['results'], $this->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']]; list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
return true; return true;
} }
if (!empty($this->cache_handler_func)) { if (!empty($smarty->cache_handler_func)) {
// use cache_handler function // use cache_handler function
call_user_func_array($this->cache_handler_func, call_user_func_array($smarty->cache_handler_func,
array('read', &$this, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'])); array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id']));
} else { } else {
// use local cache file // use local cache file
$_auto_id = $this->_get_auto_id($params['cache_id'], $params['compile_id']); $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
$_cache_file = $this->_get_auto_filename($this->cache_dir, $params['tpl_file'], $_auto_id); $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
$params['results'] = $this->_read_file($_cache_file); $params['results'] = $smarty->_read_file($_cache_file);
} }
if (empty($params['results'])) { if (empty($params['results'])) {
@@ -51,39 +51,39 @@ function smarty_core_read_cache_file(&$params, &$this)
$cache_split = explode("\n", $params['results'], 2); $cache_split = explode("\n", $params['results'], 2);
$cache_header = $cache_split[0]; $cache_header = $cache_split[0];
$this->_cache_info = unserialize($cache_header); $smarty->_cache_info = unserialize($cache_header);
if ($this->caching == 2 && isset ($this->_cache_info['expires'])){ if ($smarty->caching == 2 && isset ($smarty->_cache_info['expires'])){
// caching by expiration time // caching by expiration time
if ($this->_cache_info['expires'] > -1 && (time() > $this->_cache_info['expires'])) { if ($smarty->_cache_info['expires'] > -1 && (time() > $smarty->_cache_info['expires'])) {
// cache expired, regenerate // cache expired, regenerate
return false; return false;
} }
} else { } else {
// caching by lifetime // caching by lifetime
if ($this->cache_lifetime > -1 && (time() - $this->_cache_info['timestamp'] > $this->cache_lifetime)) { if ($smarty->cache_lifetime > -1 && (time() - $smarty->_cache_info['timestamp'] > $smarty->cache_lifetime)) {
// cache expired, regenerate // cache expired, regenerate
return false; return false;
} }
} }
if ($this->compile_check) { if ($smarty->compile_check) {
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.fetch_resource_info.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.fetch_resource_info.php');
foreach (array_keys($this->_cache_info['template']) as $_template_dep) { foreach (array_keys($smarty->_cache_info['template']) as $_template_dep) {
$_params = array('resource_name' => $_template_dep); $_params = array('resource_name' => $_template_dep);
smarty_core_fetch_resource_info($_params, $this); smarty_core_fetch_resource_info($_params, $smarty);
if ($this->_cache_info['timestamp'] < $_params['resource_timestamp']) { if ($smarty->_cache_info['timestamp'] < $_params['resource_timestamp']) {
// template file has changed, regenerate cache // template file has changed, regenerate cache
return false; return false;
} }
} }
if (isset($this->_cache_info['config'])) { if (isset($smarty->_cache_info['config'])) {
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.fetch_resource_info.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.fetch_resource_info.php');
foreach (array_keys($this->_cache_info['config']) as $_config_dep) { foreach (array_keys($smarty->_cache_info['config']) as $_config_dep) {
$_params = array('resource_name' => $_config_dep); $_params = array('resource_name' => $_config_dep);
smarty_core_fetch_resource_info($_params, $this); smarty_core_fetch_resource_info($_params, $smarty);
if ($this->_cache_info['timestamp'] < $_params['resource_timestamp']) { if ($smarty->_cache_info['timestamp'] < $_params['resource_timestamp']) {
// config file has changed, regenerate cache // config file has changed, regenerate cache
return false; return false;
} }
@@ -91,11 +91,11 @@ function smarty_core_read_cache_file(&$params, &$this)
} }
} }
$this->_cache_serials = array_merge($this->_cache_serials, $smarty->_cache_serials = array_merge($smarty->_cache_serials,
$this->_cache_info['cache_serials']); $smarty->_cache_info['cache_serials']);
$params['results'] = $cache_split[1]; $params['results'] = $cache_split[1];
$content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $this->_cache_info); $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $smarty->_cache_info);
return true; return true;
} }

View File

@@ -17,7 +17,7 @@
// $auto_base, $auto_source = null, $auto_id = null, $exp_time = null // $auto_base, $auto_source = null, $auto_id = null, $exp_time = null
function smarty_core_rm_auto($params, &$this) function smarty_core_rm_auto($params, &$smarty)
{ {
if (!@is_dir($params['auto_base'])) if (!@is_dir($params['auto_base']))
return false; return false;
@@ -29,20 +29,20 @@ function smarty_core_rm_auto($params, &$this)
'exp_time' => $params['exp_time'] 'exp_time' => $params['exp_time']
); );
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php');
$_res = smarty_core_rmdir($_params, $this); $_res = smarty_core_rmdir($_params, $smarty);
} else { } else {
$_tname = $this->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']); $_tname = $smarty->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']);
if(isset($params['auto_source'])) { if(isset($params['auto_source'])) {
$_res = $this->_unlink($_tname); $_res = $smarty->_unlink($_tname);
} elseif ($this->use_sub_dirs) { } elseif ($smarty->use_sub_dirs) {
$_params = array( $_params = array(
'dirname' => $_tname, 'dirname' => $_tname,
'level' => 1, 'level' => 1,
'exp_time' => $params['exp_time'] 'exp_time' => $params['exp_time']
); );
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php');
$_res = smarty_core_rmdir($_params, $this); $_res = smarty_core_rmdir($_params, $smarty);
} else { } else {
// remove matching file names // remove matching file names
$_handle = opendir($params['auto_base']); $_handle = opendir($params['auto_base']);
@@ -51,7 +51,7 @@ function smarty_core_rm_auto($params, &$this)
if($_filename == '.' || $_filename == '..') { if($_filename == '.' || $_filename == '..') {
continue; continue;
} elseif (substr($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, 0, strlen($_tname)) == $_tname) { } elseif (substr($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, 0, strlen($_tname)) == $_tname) {
$_res &= (bool)$this->_unlink($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, $params['exp_time']); $_res &= (bool)$smarty->_unlink($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, $params['exp_time']);
} }
} }
} }

View File

@@ -17,7 +17,7 @@
// $dirname, $level = 1, $exp_time = null // $dirname, $level = 1, $exp_time = null
function smarty_core_rmdir($params, &$this) function smarty_core_rmdir($params, &$smarty)
{ {
if(!isset($params['level'])) { $params['level'] = 1; } if(!isset($params['level'])) { $params['level'] = 1; }
if(!isset($params['exp_time'])) { $params['exp_time'] = null; } if(!isset($params['exp_time'])) { $params['exp_time'] = null; }
@@ -33,10 +33,10 @@ function smarty_core_rmdir($params, &$this)
'exp_time' => $params['exp_time'] 'exp_time' => $params['exp_time']
); );
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php');
smarty_core_rmdir($_params, $this); smarty_core_rmdir($_params, $smarty);
} }
else { else {
$this->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']); $smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']);
} }
} }
} }

View File

@@ -18,17 +18,17 @@
// $tpl_file, $cache_id, $compile_id, $results // $tpl_file, $cache_id, $compile_id, $results
function smarty_core_write_cache_file($params, &$this) function smarty_core_write_cache_file($params, &$smarty)
{ {
// put timestamp in cache header // put timestamp in cache header
$this->_cache_info['timestamp'] = time(); $smarty->_cache_info['timestamp'] = time();
if ($this->cache_lifetime > -1){ if ($smarty->cache_lifetime > -1){
// expiration set // expiration set
$this->_cache_info['expires'] = $this->_cache_info['timestamp'] + $this->cache_lifetime; $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;
} else { } else {
// cache will never expire // cache will never expire
$this->_cache_info['expires'] = -1; $smarty->_cache_info['expires'] = -1;
} }
// collapse {nocache...}-tags // collapse {nocache...}-tags
@@ -37,33 +37,33 @@ function smarty_core_write_cache_file($params, &$this)
.'{/nocache\:\\3#\\4\})!Us' .'{/nocache\:\\3#\\4\})!Us'
,'\\2' ,'\\2'
,$params['results']); ,$params['results']);
$this->_cache_info['cache_serials'] = $this->_cache_serials; $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
// prepend the cache header info into cache file // prepend the cache header info into cache file
$params['results'] = serialize($this->_cache_info)."\n".$params['results']; $params['results'] = serialize($smarty->_cache_info)."\n".$params['results'];
if (!empty($this->cache_handler_func)) { if (!empty($smarty->cache_handler_func)) {
// use cache_handler function // use cache_handler function
call_user_func_array($this->cache_handler_func, call_user_func_array($smarty->cache_handler_func,
array('write', &$this, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'])); array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id']));
} else { } else {
// use local cache file // use local cache file
if(!@is_writable($this->cache_dir)) { if(!@is_writable($smarty->cache_dir)) {
// cache_dir not writable, see if it exists // cache_dir not writable, see if it exists
if(!@is_dir($this->cache_dir)) { if(!@is_dir($smarty->cache_dir)) {
$this->trigger_error('the $cache_dir \'' . $this->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR); $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
return false; return false;
} }
$this->trigger_error('unable to write to $cache_dir \'' . realpath($this->cache_dir) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR); $smarty->trigger_error('unable to write to $cache_dir \'' . realpath($smarty->cache_dir) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR);
return false; return false;
} }
$_auto_id = $this->_get_auto_id($params['cache_id'], $params['compile_id']); $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
$_cache_file = $this->_get_auto_filename($this->cache_dir, $params['tpl_file'], $_auto_id); $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
$_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true); $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php');
smarty_core_write_file($_params, $this); smarty_core_write_file($_params, $smarty);
return true; return true;
} }
} }

View File

@@ -12,22 +12,22 @@
* @return boolean * @return boolean
*/ */
function smarty_core_write_cache_paths_file($params, &$this) function smarty_core_write_cache_paths_file($params, &$smarty)
{ {
// see if there is an pruning to do // see if there is an pruning to do
foreach($this->_cache_paths_max as $_max_key => $_max_val) { foreach($smarty->_cache_paths_max as $_max_key => $_max_val) {
if(isset($this->_cache_paths[$_max_key]) if(isset($smarty->_cache_paths[$_max_key])
&& count($this->_cache_paths[$_max_key]) > $_max_val) { && count($smarty->_cache_paths[$_max_key]) > $_max_val) {
// remove the oldest (first) value // remove the oldest (first) value
array_unshift($this->_cache_paths[$_max_key]); array_unshift($smarty->_cache_paths[$_max_key]);
} }
} }
$_compiled_content = function_exists('var_export') ? var_export($this->_cache_paths, true) : "unserialize('" . serialize($this->_cache_paths) . "')"; $_compiled_content = function_exists('var_export') ? var_export($smarty->_cache_paths, true) : "unserialize('" . serialize($smarty->_cache_paths) . "')";
$_compiled_content = '<?php $this->_cache_paths = ' . $_compiled_content . '; ?>'; $_compiled_content = '<?php $smarty->_cache_paths = ' . $_compiled_content . '; ?>';
$_params = array('compile_path' => $this->_cache_paths_file, 'compiled_content' => $_compiled_content, 'resource_timestamp' => time()); $_params = array('compile_path' => $smarty->_cache_paths_file, 'compiled_content' => $_compiled_content, 'resource_timestamp' => time());
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');
smarty_core_write_compiled_resource($_params, $this); smarty_core_write_compiled_resource($_params, $smarty);
return $_return; return $_return;
} }

View File

@@ -14,10 +14,10 @@
* @return boolean * @return boolean
*/ */
function smarty_core_write_compiled_include($params, &$this) function smarty_core_write_compiled_include($params, &$smarty)
{ {
$_tag_start = 'if \(\$this->caching\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\';\}'; $_tag_start = 'if \(\$smarty->caching\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\';\}';
$_tag_end = 'if \(\$this->caching\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\';\}'; $_tag_end = 'if \(\$smarty->caching\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\';\}';
preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us', preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
$params['compiled_content'], $_match_source, PREG_SET_ORDER); $params['compiled_content'], $_match_source, PREG_SET_ORDER);
@@ -30,15 +30,15 @@ function smarty_core_write_compiled_include($params, &$this)
$_compile_path = $params['include_file_path']; $_compile_path = $params['include_file_path'];
$this->_cache_serials[$_compile_path] = $this->_cache_serial; $smarty->_cache_serials[$_compile_path] = $smarty->_cache_serial;
$_include_compiled .= "\$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."';\n\n?>"; $_include_compiled .= "\$smarty->_cache_serials['".$smarty->_cache_include."'] = '".$smarty->_cache_serial."';\n\n?>";
$_include_compiled .= $params['plugins_code']; $_include_compiled .= $params['plugins_code'];
$_include_compiled .= "<?"; $_include_compiled .= "<?";
for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) { for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
$_match =& $_match_source[$_i]; $_match =& $_match_source[$_i];
$_include_compiled .= " $_include_compiled .= "
function _smarty_tplfunc_$_match[2]_$_match[3](&\$this) function _smarty_tplfunc_$_match[2]_$_match[3](&\$smarty)
{ {
$_match[4] $_match[4]
} }
@@ -51,7 +51,7 @@ $_match[4]
'contents' => $_include_compiled, 'create_dirs' => true); 'contents' => $_include_compiled, 'create_dirs' => true);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php');
smarty_core_write_file($_params, $this); smarty_core_write_file($_params, $smarty);
return true; return true;
} }

View File

@@ -13,21 +13,21 @@
* @param integer $resource_timestamp * @param integer $resource_timestamp
* @return true * @return true
*/ */
function smarty_core_write_compiled_resource($params, &$this) function smarty_core_write_compiled_resource($params, &$smarty)
{ {
if(!@is_writable($this->compile_dir)) { if(!@is_writable($smarty->compile_dir)) {
// compile_dir not writable, see if it exists // compile_dir not writable, see if it exists
if(!@is_dir($this->compile_dir)) { if(!@is_dir($smarty->compile_dir)) {
$this->trigger_error('the $compile_dir \'' . $this->compile_dir . '\' does not exist, or is not a directory.', E_USER_ERROR); $smarty->trigger_error('the $compile_dir \'' . $smarty->compile_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
return false; return false;
} }
$this->trigger_error('unable to write to $compile_dir \'' . realpath($this->compile_dir) . '\'. Be sure $compile_dir is writable by the web server user.', E_USER_ERROR); $smarty->trigger_error('unable to write to $compile_dir \'' . realpath($smarty->compile_dir) . '\'. Be sure $compile_dir is writable by the web server user.', E_USER_ERROR);
return false; return false;
} }
$_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true); $_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php');
smarty_core_write_file($_params, $this); smarty_core_write_file($_params, $smarty);
touch($params['compile_path'], $params['resource_timestamp']); touch($params['compile_path'], $params['resource_timestamp']);
return true; return true;
} }

View File

@@ -13,14 +13,14 @@
* @param boolean $create_dirs * @param boolean $create_dirs
* @return boolean * @return boolean
*/ */
function smarty_core_write_file($params, &$this) function smarty_core_write_file($params, &$smarty)
{ {
$_dirname = dirname($params['filename']); $_dirname = dirname($params['filename']);
if ($params['create_dirs']) { if ($params['create_dirs']) {
$_params = array('dir' => $_dirname); $_params = array('dir' => $_dirname);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.create_dir_structure.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.create_dir_structure.php');
smarty_core_create_dir_structure($_params, $this); smarty_core_create_dir_structure($_params, $smarty);
} }
// write to tmp file, then rename it to avoid // write to tmp file, then rename it to avoid
@@ -28,7 +28,7 @@ function smarty_core_write_file($params, &$this)
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid(''); $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('');
if (!($fd = @fopen($_tmp_file, 'w'))) { if (!($fd = @fopen($_tmp_file, 'w'))) {
$this->trigger_error("problem writing temporary file '$_tmp_file'"); $smarty->trigger_error("problem writing temporary file '$_tmp_file'");
return false; return false;
} }
@@ -38,7 +38,7 @@ function smarty_core_write_file($params, &$this)
@unlink($params['filename']); @unlink($params['filename']);
} }
@rename($_tmp_file, $params['filename']); @rename($_tmp_file, $params['filename']);
chmod($params['filename'], $this->_file_perms); chmod($params['filename'], $smarty->_file_perms);
return true; return true;
} }

View File

@@ -8,7 +8,7 @@
/** /**
* Include the {@link shared.make_timestamp.php} plugin * Include the {@link shared.make_timestamp.php} plugin
*/ */
require_once $this->_get_plugin_filepath('shared','make_timestamp'); require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
/** /**
* Smarty date_format modifier plugin * Smarty date_format modifier plugin
* *