mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
make cache_path per resource, fix a couple directory path issues
This commit is contained in:
@@ -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';
|
||||||
|
|
||||||
@@ -584,13 +584,6 @@ reques * @var string
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $_cache_paths_file = null;
|
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()
|
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,20 +1412,20 @@ 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(!$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)
|
&& !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');
|
||||||
$_return = smarty_core_assemble_plugin_filepath($_params, $this);
|
$_return = smarty_core_assemble_plugin_filepath($_params, $this);
|
||||||
|
|
||||||
if($_return !== false) {
|
if ($_return !== false) {
|
||||||
$this->_cache_paths['plugins'][$_cache_paths_key] = $_return;
|
$this->_cache_paths['plugins'][$_cache_paths_key] = $_return;
|
||||||
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_cache_paths_file.php');
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_cache_paths_file.php');
|
||||||
smarty_core_write_cache_paths_file(null, $this);
|
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)
|
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');
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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: */
|
||||||
|
Reference in New Issue
Block a user