refactored var naming to better reflect "resource" instead of "file" where appropriate

This commit is contained in:
mohrt
2003-06-20 20:01:10 +00:00
parent ae41b61e7e
commit a889155fdc
12 changed files with 104 additions and 106 deletions

View File

@@ -1073,9 +1073,9 @@ reques * @var string
*/
function template_exists($tpl_file)
{
$_params = array('file_path' => $tpl_file);
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
return smarty_core_fetch_file_info($_params, $this);
$_params = array('resource_name' => $tpl_file);
require_once(SMARTY_DIR . 'core/core.fetch_resource_info.php');
return smarty_core_fetch_resource_info($_params, $this);
}
/**
@@ -1126,24 +1126,24 @@ reques * @var string
/**
* executes & displays the template results
*
* @param string $tpl_file
* @param string $resource_name
* @param string $cache_id
* @param string $compile_id
*/
function display($tpl_file, $cache_id = null, $compile_id = null)
function display($resource_name, $cache_id = null, $compile_id = null)
{
$this->fetch($tpl_file, $cache_id, $compile_id, true);
$this->fetch($resource_name, $cache_id, $compile_id, true);
}
/**
* executes & returns or displays the template results
*
* @param string $file_path
* @param string $resource_name
* @param string $cache_id
* @param string $compile_id
* @param boolean $display
*/
function fetch($file_path, $cache_id = null, $compile_id = null, $display = false)
function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
{
static $_cache_info = array();
@@ -1166,7 +1166,7 @@ reques * @var string
require_once(SMARTY_DIR . 'core/core.get_microtime.php');
$_debug_start_time = smarty_core_get_microtime($_params, $this);
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $file_path,
'filename' => $resource_name,
'depth' => 0);
$_included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
@@ -1183,7 +1183,7 @@ reques * @var string
array_push($_cache_info, $this->_cache_info);
$this->_cache_info = array();
$_params = array(
'tpl_file' => $file_path,
'tpl_file' => $resource_name,
'cache_id' => $cache_id,
'compile_id' => $compile_id,
'results' => null
@@ -1241,7 +1241,7 @@ reques * @var string
return $_smarty_results;
}
} else {
$this->_cache_info['template'][$file_path] = true;
$this->_cache_info['template'][$resource_name] = true;
if ($this->cache_modified_check) {
header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT');
}
@@ -1257,20 +1257,20 @@ reques * @var string
}
}
$_smarty_compile_path = $this->_get_compile_path($file_path);
$_smarty_compile_path = $this->_get_compile_path($resource_name);
// if we just need to display the results, don't perform output
// buffering - for speed
if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
if ($this->_is_compiled($file_path, $_smarty_compile_path)
|| $this->_compile_file($file_path, $_smarty_compile_path))
if ($this->_is_compiled($resource_name, $_smarty_compile_path)
|| $this->_compile_resource($resource_name, $_smarty_compile_path))
{
include($_smarty_compile_path);
}
} else {
ob_start();
if ($this->_is_compiled($file_path, $_smarty_compile_path)
|| $this->_compile_file($file_path, $_smarty_compile_path))
if ($this->_is_compiled($resource_name, $_smarty_compile_path)
|| $this->_compile_resource($resource_name, $_smarty_compile_path))
{
include($_smarty_compile_path);
}
@@ -1283,7 +1283,7 @@ reques * @var string
}
if ($this->caching) {
$_params = array('tpl_file' => $file_path,
$_params = array('tpl_file' => $resource_name,
'cache_id' => $cache_id,
'compile_id' => $compile_id,
'results' => $_smarty_results);
@@ -1422,13 +1422,13 @@ reques * @var string
}
/**
* test if source file needs compiling
* test if resource needs compiling
*
* @param string $tpl_file
* @param string $resource_name
* @param string $compile_path
* @return boolean
*/
function _is_compiled($file_path, $compile_path)
function _is_compiled($resource_name, $compile_path)
{
if (!$this->force_compile && file_exists($compile_path)) {
if (!$this->compile_check) {
@@ -1436,14 +1436,12 @@ reques * @var string
return true;
} else {
// get file source and timestamp
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
$_params = array('file_path' => $file_path);
if (!smarty_core_fetch_file_info($_params, $this)) {
require_once(SMARTY_DIR . 'core/core.fetch_resource_info.php');
$_params = array('resource_name' => $resource_name);
if (!smarty_core_fetch_resource_info($_params, $this)) {
return false;
}
$_file_source = $_params['file_source'];
$_file_timestamp = $_params['file_timestamp'];
if ($_file_timestamp <= filemtime($compile_path)) {
if ($_params['resource_timestamp'] <= filemtime($compile_path)) {
// template not expired, no recompile
return true;
} else {
@@ -1460,31 +1458,31 @@ reques * @var string
/**
* compile the template
*
* @param string $file_path
* @param string $resource_name
* @param string $compile_path
* @return boolean
*/
function _compile_file($file_path, $compile_path)
function _compile_resource($resource_name, $compile_path)
{
$_params = array('file_path' => $file_path);
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
if (!smarty_core_fetch_file_info($_params, $this)) {
$_params = array('resource_name' => $resource_name);
require_once(SMARTY_DIR . 'core/core.fetch_resource_info.php');
if (!smarty_core_fetch_resource_info($_params, $this)) {
return false;
}
$_file_source = $_params['file_source'];
$_file_timestamp = $_params['file_timestamp'];
$_source_content = $_params['source_content'];
$_resource_timestamp = $_params['resource_timestamp'];
if ($this->_compile_source($file_path, $_file_source, $_file_compiled)) {
$_params = array('compile_path' => $compile_path, 'file_compiled' => $_file_compiled, 'file_timestamp' => $_file_timestamp);
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
smarty_core_write_compiled_template($_params, $this);
if ($this->_compile_source($resource_name, $_source_content, $_compiled_content)) {
$_params = array('compile_path' => $compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);
require_once(SMARTY_DIR . 'core/core.write_compiled_resource.php');
smarty_core_write_compiled_resource($_params, $this);
// if a _cache_serial was set, we also have to write an include-file:
if ($this->_cache_serial = $smarty_compiler->_cache_serial) {
$_params['plugins_code'] = $smarty_compiler->_plugins_code;
$_params['include_file_path'] = $smarty_compiler->_cache_include;
$_params['include_file_path'] = $smarty_compiler->_cache_include;
require_once(SMARTY_DIR . 'core/core.write_compiled_include.php');
smarty_core_write_compiled_include($_params, $this);
}
@@ -1499,12 +1497,12 @@ reques * @var string
/**
* compile the given source
*
* @param string $file_path
* @param string $file_source
* @param string $file_compiled
* @param string $resource_name
* @param string $source_content
* @param string $compiled_content
* @return boolean
*/
function _compile_source($file_path, &$file_source, &$file_compiled)
function _compile_source($resource_name, &$source_content, &$compiled_content)
{
if (file_exists(SMARTY_DIR . $this->compiler_file)) {
require_once(SMARTY_DIR . $this->compiler_file);
@@ -1541,7 +1539,7 @@ reques * @var string
$smarty_compiler->_cache_serial = null;
$smarty_compiler->_cache_include = substr($compile_path, 0, -4).'.inc';
return $smarty_compiler->_compile_file($file_path, $file_source, $file_compiled);
return $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);
}

View File

@@ -37,7 +37,7 @@ function smarty_core_display_debug_console($params, &$this)
$this->_compile_id = null;
$_compile_path = $this->_get_compile_path($this->debug_tpl);
if ($this->_compile_file($this->debug_tpl, $_compile_path))
if ($this->_compile_resource($this->debug_tpl, $_compile_path))
{
ob_start();
include($_compile_path);

View File

@@ -9,34 +9,34 @@
* fetch the template info. Gets timestamp, and source
* if get_source is true
*
* sets $file_source to the source of the template, and
* $file_timestamp to its time stamp
* @param string $file_path
* @param string $file_source
* @param integer $file_timestamp
* sets $source_content to the source of the template, and
* $resource_timestamp to its time stamp
* @param string $resource_name
* @param string $source_content
* @param integer $resource_timestamp
* @param boolean $get_source
* @param boolean $quiet
* @return boolean
*/
function smarty_core_fetch_file_info(&$params, &$this)
function smarty_core_fetch_resource_info(&$params, &$this)
{
if(!isset($params['get_source'])) { $params['get_source'] = true; }
if(!isset($params['quiet'])) { $params['quiet'] = false; }
$_return = false;
$_params = array('file_path' => $params['file_path']) ;
require_once(SMARTY_DIR . 'core/core.parse_file_path.php');
if (smarty_core_parse_file_path($_params, $this)) {
$_params = array('resource_name' => $params['resource_name']) ;
require_once(SMARTY_DIR . 'core/core.parse_resource_name.php');
if (smarty_core_parse_resource_name($_params, $this)) {
$_resource_type = $_params['resource_type'];
$_resource_name = $_params['resource_name'];
switch ($_resource_type) {
case 'file':
if ($params['get_source']) {
$params['file_source'] = $this->_read_file($_resource_name);
$params['source_content'] = $this->_read_file($_resource_name);
}
$params['file_timestamp'] = filemtime($_resource_name);
$params['resource_timestamp'] = filemtime($_resource_name);
$_return = true;
break;
@@ -45,14 +45,14 @@ function smarty_core_fetch_file_info(&$params, &$this)
if ($params['get_source']) {
$_source_return = isset($this->_plugins['resource'][$_resource_type]) &&
call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],
array($_resource_name, &$params['file_source'], &$this));
array($_resource_name, &$params['source_content'], &$this));
} else {
$_source_return = true;
}
$_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&
call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],
array($_resource_name, &$params['file_timestamp'], &$this));
array($_resource_name, &$params['resource_timestamp'], &$this));
$_return = $_source_return && $_timestamp_return;
break;
@@ -67,7 +67,7 @@ function smarty_core_fetch_file_info(&$params, &$this)
} else {
$_return = call_user_func_array(
$this->default_template_handler_func,
array($_resource_type, $_resource_name, &$params['file_source'], &$params['file_timestamp'], &$this));
array($_resource_type, $_resource_name, &$params['source_content'], &$params['resource_timestamp'], &$this));
}
}
}
@@ -75,13 +75,13 @@ function smarty_core_fetch_file_info(&$params, &$this)
require_once(SMARTY_DIR . 'core/core.is_secure.php');
if (!$_return) {
if (!$params['quiet']) {
$this->trigger_error('unable to read file resource: "' . $params['file_path'] . '"');
$this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');
}
} else if ($_return && $this->security && !smarty_core_is_secure($_params, $this)) {
if (!$params['quiet'])
$this->trigger_error('(secure mode) accessing "' . $params['file_path'] . '" is not allowed');
$params['file_source'] = null;
$params['file_timestamp'] = null;
$this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
$params['source_content'] = null;
$params['resource_timestamp'] = null;
return false;
}
return $_return;

View File

@@ -18,9 +18,9 @@
function smarty_core_get_php_resource(&$params, &$this)
{
$params['file_base_path'] = $this->trusted_dir;
require_once(SMARTY_DIR . 'core/core.parse_file_path.php');
smarty_core_parse_file_path($params, $this);
$params['resource_base_path'] = $this->trusted_dir;
require_once(SMARTY_DIR . 'core/core.parse_resource_name.php');
smarty_core_parse_resource_name($params, $this);
/*
* Find out if the resource exists.

View File

@@ -6,55 +6,55 @@
*/
/**
* parse out the type and name from the template resource
* parse out the type and name from the resource
*
* @param string $file_base_path
* @param string $file_path
* @param string $resource_base_path
* @param string $resource_name
* @param string $resource_type
* @param string $resource_name
* @return boolean
*/
// $file_base_path, $file_path, &$resource_type, &$resource_name
// $resource_base_path, $resource_name, &$resource_type, &$resource_name
function smarty_core_parse_file_path(&$params, &$this)
function smarty_core_parse_resource_name(&$params, &$this)
{
// split tpl_path by the first colon
$_file_path_parts = explode(':', $params['file_path'], 2);
$_resource_name_parts = explode(':', $params['resource_name'], 2);
if (count($_file_path_parts) == 1) {
if (count($_resource_name_parts) == 1) {
// no resource type given
$params['resource_type'] = $this->default_resource_type;
$params['resource_name'] = $_file_path_parts[0];
$params['resource_name'] = $_resource_name_parts[0];
} else {
if(strlen($_file_path_parts[0]) == 1) {
if(strlen($_resource_name_parts[0]) == 1) {
// 1 char is not resource type, but part of filepath
$params['resource_type'] = $this->default_resource_type;
$params['resource_name'] = $params['file_path'];
$params['resource_name'] = $params['resource_name'];
} else {
$params['resource_type'] = $_file_path_parts[0];
$params['resource_name'] = $_file_path_parts[1];
$params['resource_type'] = $_resource_name_parts[0];
$params['resource_name'] = $_resource_name_parts[1];
}
}
if ($params['resource_type'] == 'file') {
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) {
// relative pathname to $params['file_base_path']
// relative pathname to $params['resource_base_path']
// use the first directory where the file is found
$_file_base_path = isset($params['file_base_path']) ? $params['file_base_path'] : array($this->template_dir, '.');
settype($_file_base_path, 'array');
foreach ($_file_base_path as $_curr_path) {
$_resource_base_path = isset($params['resource_base_path']) ? $params['resource_base_path'] : array($this->template_dir, '.');
settype($_resource_base_path, 'array');
foreach ($_resource_base_path as $_curr_path) {
$_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];
if (file_exists($_fullpath) && is_file($_fullpath)) {
$params['resource_name'] = $_fullpath;
return true;
}
// didn't find the file, try include_path
$_params = array('file_path' => $_fullpath);
$_params = array('resource_name' => $_fullpath);
require_once(SMARTY_DIR . 'core/core.get_include_path.php');
if(smarty_core_get_include_path($_params, $this)) {
$params['resource_name'] = $_params['new_file_path'];
$params['resource_name'] = $_params['new_resource_name'];
return true;
}
}

View File

@@ -28,7 +28,7 @@ function smarty_core_process_cached_inserts($params, &$this)
$name = $args['name'];
if (isset($args['script'])) {
$_params = array('file_path' => $this->_dequote($args['script']));
$_params = array('resource_name' => $this->_dequote($args['script']));
require_once(SMARTY_DIR . 'core/core.get_php_resource.php');
if(!smarty_core_get_php_resource($_params, $this)) {
return false;

View File

@@ -68,22 +68,22 @@ function smarty_core_read_cache_file(&$params, &$this)
}
if ($this->compile_check) {
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
require_once(SMARTY_DIR . 'core/core.fetch_resource_info.php');
foreach (array_keys($this->_cache_info['template']) as $_template_dep) {
$_params = array('file_path' => $_template_dep);
smarty_core_fetch_file_info($_params, $this);
if ($this->_cache_info['timestamp'] < $_params['file_timestamp']) {
$_params = array('resource_name' => $_template_dep);
smarty_core_fetch_resource_info($_params, $this);
if ($this->_cache_info['timestamp'] < $_params['resource_timestamp']) {
// template file has changed, regenerate cache
return false;
}
}
if (isset($this->_cache_info['config'])) {
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
require_once(SMARTY_DIR . 'core/core.fetch_resource_info.php');
foreach (array_keys($this->_cache_info['config']) as $_config_dep) {
$_params = array('file_path' => $_config_dep);
smarty_core_fetch_file_info($_params, $this);
if ($this->_cache_info['timestamp'] < $_params['file_timestamp']) {
$_params = array('resource_name' => $_config_dep);
smarty_core_fetch_resource_info($_params, $this);
if ($this->_cache_info['timestamp'] < $_params['resource_timestamp']) {
// config file has changed, regenerate cache
return false;
}

View File

@@ -33,7 +33,7 @@ function smarty_core_run_insert_handler($params, &$this)
return $this->_smarty_md5."{insert_cache $_arg_string}".$this->_smarty_md5;
} else {
if (isset($params['args']['script'])) {
$_params = array('file_path' => $this->_dequote($params['args']['script']));
$_params = array('resource_name' => $this->_dequote($params['args']['script']));
require_once(SMARTY_DIR . 'core/core.get_php_resource.php');
if(!smarty_core_get_php_resource($_params, $this)) {
return false;

View File

@@ -36,7 +36,7 @@ function smarty_core_smarty_include($params, &$this)
if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
|| $this->_compile_file($params['smarty_include_tpl_file'], $_smarty_compile_path))
|| $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
{
include($_smarty_compile_path);
}

View File

@@ -20,7 +20,7 @@
function smarty_core_smarty_include_php($params, &$this)
{
$_params = array('file_path' => $params['smarty_file']);
$_params = array('resource_name' => $params['smarty_file']);
require_once(SMARTY_DIR . 'core/core.get_php_resource.php');
smarty_core_get_php_resource($_params, $this);
$_smarty_resource_type = $_params['resource_type'];

View File

@@ -6,14 +6,14 @@
*/
/**
* write the compiled template
* write the compiled resource
*
* @param string $compile_path
* @param string $file_compiled
* @param integer $file_timestamp
* @param string $compiled_content
* @param integer $resource_timestamp
* @return true
*/
function smarty_core_write_compiled_template($params, &$this)
function smarty_core_write_compiled_resource($params, &$this)
{
if(!@is_writable($this->compile_dir)) {
// compile_dir not writable, see if it exists
@@ -23,12 +23,12 @@ function smarty_core_write_compiled_template($params, &$this)
}
$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);
return false;
}
$_params = array('filename' => $params['compile_path'], 'contents' => $params['file_compiled'], 'create_dirs' => true);
}
$_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true);
require_once(SMARTY_DIR . 'core/core.write_file.php');
smarty_core_write_file($_params, $this);
touch($params['compile_path'], $params['file_timestamp']);
touch($params['compile_path'], $params['resource_timestamp']);
return true;
}

View File

@@ -87,9 +87,9 @@ function smarty_function_config_load($params, &$smarty)
} else {
$_output = '<?php $_config_vars = unserialize(' . serialize($_config_vars) . '); ?>';
}
$_params = (array('compile_path' => $_compile_file, 'file_compiled' => $_output, 'file_timestamp' => filemtime($_file_path)));
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
smarty_core_write_compiled_template($_params, $smarty);
$_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => filemtime($_file_path)));
require_once(SMARTY_DIR . 'core/core.write_compiled_resource.php');
smarty_core_write_compiled_resource($_params, $smarty);
} else {
include_once($_compile_file);
}