removed auto-filenames from path-cache. merged assemble_auto_filename

back into Smarty::_get_auto_filename()
This commit is contained in:
messju
2003-09-14 13:37:15 +00:00
parent cb2961afd6
commit a566b01a12
2 changed files with 29 additions and 72 deletions

View File

@@ -1856,25 +1856,38 @@ class Smarty
*/
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];
$_compile_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
if(@is_dir($auto_base)) {
$_return = $auto_base . DIRECTORY_SEPARATOR;
} else {
// auto_base not found, try include_path
$_params = array('file_path' => $auto_base);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
smarty_core_get_include_path($_params, $smarty);
$_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null;
}
$_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');
$_return = smarty_core_assemble_auto_filename($_params, $this);
if(isset($auto_id)) {
// make auto_id safe for directory names
$auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));
// split into separate directories
$_return .= $auto_id . $_compile_dir_sep;
}
if(isset($auto_source)) {
// make source name safe for filename
$_filename = urlencode(basename($auto_source));
$_crc32 = crc32($auto_source) . $_compile_dir_sep;
// prepend %% to avoid name conflicts with
// with $params['auto_id'] names
$_crc32 = '%%' . substr($_crc32,0,3) . $_compile_dir_sep . '%%' . $_crc32;
$_return .= $_crc32 . $_filename;
}
if($_return !== false) {
$this->_cache_paths['auto_file'][$_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);
return $_return;
}
return false;
}
/**
* unlink a file, possibly using expiration time
*

View File

@@ -1,56 +0,0 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* get a concrete filename for automagically created content
*
* @param string $auto_base
* @param string $auto_source
* @param string $auto_id
* @return string
* @staticvar string|null
* @staticvar string|null
*/
function smarty_core_assemble_auto_filename($params, &$smarty)
{
$_compile_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
if(@is_dir($params['auto_base'])) {
$_return = $params['auto_base'] . DIRECTORY_SEPARATOR;
} else {
// auto_base not found, try include_path
$_params = array('file_path' => $params['auto_base']);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
smarty_core_get_include_path($_params, $smarty);
$_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null;
}
if(isset($params['auto_id'])) {
// make auto_id safe for directory names
$params['auto_id'] = str_replace('%7C','|',(urlencode($params['auto_id'])));
// split into separate directories
$params['auto_id'] = str_replace('|', $_compile_dir_sep, $params['auto_id']);
$_return .= $params['auto_id'] . $_compile_dir_sep;
}
if(isset($params['auto_source'])) {
// make source name safe for filename
$_filename = urlencode(basename($params['auto_source']));
$_crc32 = crc32($params['auto_source']) . $_compile_dir_sep;
// prepend %% to avoid name conflicts with
// with $params['auto_id'] names
$_crc32 = '%%' . substr($_crc32,0,3) . $_compile_dir_sep . '%%' . $_crc32;
$_return .= $_crc32 . $_filename;
}
return $_return;
}
/* vim: set expandtab: */
?>