make cache_path per resource, fix a couple directory path issues

This commit is contained in:
mohrt
2003-06-23 21:31:32 +00:00
parent 650cbd9bbe
commit 5980723e09
3 changed files with 23 additions and 34 deletions

View File

@@ -92,7 +92,7 @@ class Smarty
/** /**
* The directory where config files are located. * The directory where config files are located.
* *
reques * @var string * @var string
*/ */
var $config_dir = 'configs'; var $config_dir = 'configs';
@@ -585,13 +585,6 @@ reques * @var string
*/ */
var $_cache_paths_file = null; var $_cache_paths_file = null;
/**
* cached file paths
*
* @var array
*/
var $_cache_paths_max = array('auto_file' => 500);
/**#@-*/ /**#@-*/
/** /**
* The class constructor. * The class constructor.
@@ -601,7 +594,6 @@ reques * @var string
*/ */
function Smarty() function Smarty()
{ {
$this->_cache_paths_file = $this->compile_dir . '/_smarty_cached_paths.php';
foreach ($this->global_assign as $key => $var_name) { foreach ($this->global_assign as $key => $var_name) {
if (is_array($var_name)) { if (is_array($var_name)) {
foreach ($var_name as $var) { foreach ($var_name as $var) {
@@ -1173,6 +1165,13 @@ reques * @var string
{ {
static $_cache_info = array(); static $_cache_info = array();
$this->_cache_paths_file = $this->compile_dir
. DIRECTORY_SEPARATOR
. '_smarty_cached_paths'
. DIRECTORY_SEPARATOR
. urlencode($resource_name)
. '.php';
$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE); $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
if($this->security && !in_array($this->template_dir, $this->secure_dir)) { if($this->security && !in_array($this->template_dir, $this->secure_dir)) {
@@ -1413,14 +1412,14 @@ reques * @var string
function _get_plugin_filepath($type, $name) function _get_plugin_filepath($type, $name)
{ {
$_cache_paths_key = $type . '/' . $name; $_cache_paths_key = $type . '/' . $name;
if (isset($this->_cache_paths['plugins'][$_cache_paths_key])) {
return $this->_cache_paths['plugins'][$_cache_paths_key];
}
if (!$this->force_compile if (!$this->force_compile
&& !isset($this->_cache_paths) && !isset($this->_cache_paths)
&& file_exists($this->_cache_paths_file)) { && file_exists($this->_cache_paths_file)) {
include_once($this->_cache_paths_file); include_once($this->_cache_paths_file);
} }
if (isset($this->_cache_paths['plugins'][$_cache_paths_key])) {
return $this->_cache_paths['plugins'][$_cache_paths_key];
}
$_params = array('type' => $type, 'name' => $name); $_params = array('type' => $type, 'name' => $name);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_plugin_filepath.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_plugin_filepath.php');
@@ -1683,14 +1682,14 @@ reques * @var string
function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
{ {
$_cache_paths_key = $auto_base . '/' . $auto_source . '/' . $auto_id; $_cache_paths_key = $auto_base . '/' . $auto_source . '/' . $auto_id;
if (isset($this->_cache_paths['auto_file'][$_cache_paths_key])) {
return $this->_cache_paths['auto_file'][$_cache_paths_key];
}
if(!$this->force_compile if(!$this->force_compile
&& !isset($this->_cache_paths) && !isset($this->_cache_paths)
&& file_exists($this->_cache_paths_file)) { && file_exists($this->_cache_paths_file)) {
include_once($this->_cache_paths_file); include_once($this->_cache_paths_file);
} }
if (isset($this->_cache_paths['auto_file'][$_cache_paths_key])) {
return $this->_cache_paths['auto_file'][$_cache_paths_key];
}
$_params = array('auto_base' => $auto_base, 'auto_source' => $auto_source, 'auto_id' => $auto_id); $_params = array('auto_base' => $auto_base, 'auto_source' => $auto_source, 'auto_id' => $auto_id);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_auto_filename.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_auto_filename.php');

View File

@@ -369,14 +369,14 @@ class Smarty_Compiler extends Smarty {
} }
} }
$_plugins_params .= '))'; $_plugins_params .= '))';
$plugins_code = "<?php require_once(SMARTY_DIR . 'core/core.load_plugins.php');\nsmarty_core_load_plugins($_plugins_params, \$this); ?>\n"; $plugins_code = "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');\nsmarty_core_load_plugins($_plugins_params, \$this); ?>\n";
$template_header .= $plugins_code; $template_header .= $plugins_code;
$this->_plugin_info = array(); $this->_plugin_info = array();
$this->_plugins_code = $plugins_code; $this->_plugins_code = $plugins_code;
} }
if ($this->_init_smarty_vars) { if ($this->_init_smarty_vars) {
$template_header .= "<?php require_once(SMARTY_DIR . 'core/core.assign_smarty_interface.php');\nsmarty_core_assign_smarty_interface(null, \$this); ?>\n"; $template_header .= "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assign_smarty_interface.php');\nsmarty_core_assign_smarty_interface(null, \$this); ?>\n";
$this->_init_smarty_vars = false; $this->_init_smarty_vars = false;
} }
@@ -837,7 +837,7 @@ class Smarty_Compiler extends Smarty {
$_params = "array('args' => array(".implode(', ', (array)$arg_list)."))"; $_params = "array('args' => array(".implode(', ', (array)$arg_list)."))";
return "<?php require_once(SMARTY_DIR . 'core/core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>\n"; return "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>\n";
} }
/** /**
@@ -880,7 +880,7 @@ class Smarty_Compiler extends Smarty {
$_params = "array('smarty_include_tpl_file' => " . $include_file . ", 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))"; $_params = "array('smarty_include_tpl_file' => " . $include_file . ", 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))";
$output .= "require_once(SMARTY_DIR . 'core/core.smarty_include.php');\nsmarty_core_smarty_include($_params, \$this);\n" . $output .= "require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.smarty_include.php');\nsmarty_core_smarty_include($_params, \$this);\n" .
"\$this->_tpl_vars = \$_smarty_tpl_vars;\n" . "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
"unset(\$_smarty_tpl_vars);\n"; "unset(\$_smarty_tpl_vars);\n";
@@ -921,7 +921,7 @@ class Smarty_Compiler extends Smarty {
$_params = "array('smarty_file' => " . $attrs['file'] . ", 'smarty_assign' => '$assign_var', 'smarty_once' => $once_var, 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))"; $_params = "array('smarty_file' => " . $attrs['file'] . ", 'smarty_assign' => '$assign_var', 'smarty_once' => $once_var, 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))";
return "<?php require_once(SMARTY_DIR . 'core/core.smarty_include_php.php');\nsmarty_core_smarty_include_php($_params, \$this); ?>\n"; return "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.smarty_include_php.php');\nsmarty_core_smarty_include_php($_params, \$this); ?>\n";
} }
@@ -1953,7 +1953,7 @@ class Smarty_Compiler extends Smarty {
if ($prefilter === false) { if ($prefilter === false) {
unset($this->_plugins['prefilter'][$filter_name]); unset($this->_plugins['prefilter'][$filter_name]);
$_params = array('plugins' => array(array('prefilter', $filter_name, null, null, false))); $_params = array('plugins' => array(array('prefilter', $filter_name, null, null, false)));
require_once(SMARTY_DIR . 'core/core.load_plugins.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');
smarty_core_load_plugins($_params, $this); smarty_core_load_plugins($_params, $this);
} }
} }
@@ -1963,7 +1963,7 @@ class Smarty_Compiler extends Smarty {
if ($postfilter === false) { if ($postfilter === false) {
unset($this->_plugins['postfilter'][$filter_name]); unset($this->_plugins['postfilter'][$filter_name]);
$_params = array('plugins' => array(array('postfilter', $filter_name, null, null, false))); $_params = array('plugins' => array(array('postfilter', $filter_name, null, null, false)));
require_once(SMARTY_DIR . 'core/core.load_plugins.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');
smarty_core_load_plugins($_params, $this); smarty_core_load_plugins($_params, $this);
} }
} }

View File

@@ -14,21 +14,11 @@
function smarty_core_write_cache_paths_file($params, &$smarty) function smarty_core_write_cache_paths_file($params, &$smarty)
{ {
// see if there is an pruning to do
foreach($smarty->_cache_paths_max as $_max_key => $_max_val) {
if(isset($smarty->_cache_paths[$_max_key])
&& count($smarty->_cache_paths[$_max_key]) > $_max_val) {
// remove the oldest (first) value
array_unshift($smarty->_cache_paths[$_max_key]);
}
}
$_compiled_content = function_exists('var_export') ? var_export($smarty->_cache_paths, true) : "unserialize('" . serialize($smarty->_cache_paths) . "')"; $_compiled_content = function_exists('var_export') ? var_export($smarty->_cache_paths, true) : "unserialize('" . serialize($smarty->_cache_paths) . "')";
$_compiled_content = '<?php $smarty->_cache_paths = ' . $_compiled_content . '; ?>'; $_compiled_content = '<?php $smarty->_cache_paths = ' . $_compiled_content . '; ?>';
$_params = array('compile_path' => $smarty->_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');
return smarty_core_write_compiled_resource($_params, $smarty); return smarty_core_write_compiled_resource($_params, $smarty);
return $_return;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */