From 5980723e0924cb81c3413df977fef043fdb50162 Mon Sep 17 00:00:00 2001 From: mohrt Date: Mon, 23 Jun 2003 21:31:32 +0000 Subject: [PATCH] make cache_path per resource, fix a couple directory path issues --- libs/Smarty.class.php | 33 +++++++++++------------ libs/Smarty_Compiler.class.php | 14 +++++----- libs/core/core.write_cache_paths_file.php | 10 ------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 440b1ca5..0a7cef60 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -92,7 +92,7 @@ class Smarty /** * The directory where config files are located. * -reques * @var string + * @var string */ var $config_dir = 'configs'; @@ -584,13 +584,6 @@ reques * @var string * @var array */ var $_cache_paths_file = null; - - /** - * cached file paths - * - * @var array - */ - var $_cache_paths_max = array('auto_file' => 500); /**#@-*/ /** @@ -601,7 +594,6 @@ reques * @var string */ function Smarty() { - $this->_cache_paths_file = $this->compile_dir . '/_smarty_cached_paths.php'; foreach ($this->global_assign as $key => $var_name) { if (is_array($var_name)) { foreach ($var_name as $var) { @@ -1173,6 +1165,13 @@ reques * @var string { 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); if($this->security && !in_array($this->template_dir, $this->secure_dir)) { @@ -1413,20 +1412,20 @@ reques * @var string function _get_plugin_filepath($type, $name) { $_cache_paths_key = $type . '/' . $name; - if(!$this->force_compile + if (isset($this->_cache_paths['plugins'][$_cache_paths_key])) { + return $this->_cache_paths['plugins'][$_cache_paths_key]; + } + if (!$this->force_compile && !isset($this->_cache_paths) && file_exists($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); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_plugin_filepath.php'); $_return = smarty_core_assemble_plugin_filepath($_params, $this); - if($_return !== false) { + if ($_return !== false) { $this->_cache_paths['plugins'][$_cache_paths_key] = $_return; require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_cache_paths_file.php'); smarty_core_write_cache_paths_file(null, $this); @@ -1683,14 +1682,14 @@ reques * @var string function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) { $_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 && !isset($this->_cache_paths) && file_exists($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); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_auto_filename.php'); diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index a679f8cf..c3db884b 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -369,14 +369,14 @@ class Smarty_Compiler extends Smarty { } } $_plugins_params .= '))'; - $plugins_code = "\n"; + $plugins_code = "\n"; $template_header .= $plugins_code; $this->_plugin_info = array(); $this->_plugins_code = $plugins_code; } if ($this->_init_smarty_vars) { - $template_header .= "\n"; + $template_header .= "\n"; $this->_init_smarty_vars = false; } @@ -837,7 +837,7 @@ class Smarty_Compiler extends Smarty { $_params = "array('args' => array(".implode(', ', (array)$arg_list)."))"; - return "\n"; + return "\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)."))"; - $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" . "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)."))"; - return "\n"; + return "\n"; } @@ -1953,7 +1953,7 @@ class Smarty_Compiler extends Smarty { if ($prefilter === false) { unset($this->_plugins['prefilter'][$filter_name]); $_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); } } @@ -1963,7 +1963,7 @@ class Smarty_Compiler extends Smarty { if ($postfilter === false) { unset($this->_plugins['postfilter'][$filter_name]); $_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); } } diff --git a/libs/core/core.write_cache_paths_file.php b/libs/core/core.write_cache_paths_file.php index 8dd5c000..2e60dbfc 100644 --- a/libs/core/core.write_cache_paths_file.php +++ b/libs/core/core.write_cache_paths_file.php @@ -14,21 +14,11 @@ 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 = '_cache_paths = ' . $_compiled_content . '; ?>'; $_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'); return smarty_core_write_compiled_resource($_params, $smarty); - return $_return; } /* vim: set expandtab: */