From d790f915f49bd40615e364b5fb4cbcd7d2bf38eb Mon Sep 17 00:00:00 2001 From: mohrt Date: Fri, 14 Jun 2002 20:58:20 +0000 Subject: [PATCH] change directory delimiter to "^" for cache and compile files --- Smarty.class.php | 22 ++++++-------- docs/programmers.sgml | 43 +++++++++++++++++++++------- libs/Smarty.class.php | 22 ++++++-------- libs/plugins/function.popup_init.php | 13 +++------ plugins/function.popup_init.php | 13 +++------ 5 files changed, 59 insertions(+), 54 deletions(-) diff --git a/Smarty.class.php b/Smarty.class.php index 05b85cc6..bea203fb 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -175,7 +175,6 @@ class Smarty var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode var $_smarty_debug_info = array(); // debugging information for debug console var $_cache_info = array(); // info that makes up a cache file - var $_auto_id_delim = '|'; // delimiter for auto_id groups var $_plugins = array( // table keeping track of plugins 'modifier' => array(), 'function' => array(), @@ -457,7 +456,7 @@ class Smarty $compile_id = $this->compile_id; if (isset($compile_id) || isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . $this->_auto_id_delim . $cache_id : $cache_id; + $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_id : $cache_id; else $auto_id = null; @@ -1403,18 +1402,15 @@ function _run_insert_handler($args) \*======================================================================*/ function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) { - static $_auto_id_delim_hex = null; static $_dir_sep = null; - - if(!isset($_auto_id_delim_hex)) { - $_auto_id_delim_hex = strtoupper(bin2hex($this->_auto_id_delim)); - } + static $_dir_sep_enc = null; if(!isset($_dir_sep)) { + $_dir_sep_enc = urlencode(DIR_SEP); if($this->use_sub_dirs) { $_dir_sep = DIR_SEP; } else { - $_dir_sep = '%2F'; + $_dir_sep = '^'; } } @@ -1422,15 +1418,15 @@ function _run_insert_handler($args) if(isset($auto_id)) { // make auto_id safe for directory names - $auto_id = str_replace('%'.$_auto_id_delim_hex,$this->_auto_id_delim,(urlencode($auto_id))); + $auto_id = str_replace('%7C','|',(urlencode($auto_id))); // split into separate directories - $auto_id = str_replace($this->_auto_id_delim, $_dir_sep, $auto_id); + $auto_id = str_replace('|', $_dir_sep, $auto_id); $res .= $auto_id . $_dir_sep; } if(isset($auto_source)) { // make source name safe for filename - $auto_source = urlencode($auto_source); + $auto_source = str_replace($_dir_sep_enc,'^',urlencode($auto_source)); $res .= $auto_source . '.php'; } @@ -1551,7 +1547,7 @@ function _run_insert_handler($args) } else { // use local cache file if (isset($compile_id) || isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . $this->_auto_id_delim . $cache_id : $cache_id; + $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_id : $cache_id; else $auto_id = null; @@ -1587,7 +1583,7 @@ function _run_insert_handler($args) } else { // use local file cache if (isset($compile_id) || isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . $this->_auto_id_delim . $cache_id : $cache_id; + $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_id : $cache_id; else $auto_id = null; diff --git a/docs/programmers.sgml b/docs/programmers.sgml index 910d6f86..57c4e0db 100644 --- a/docs/programmers.sgml +++ b/docs/programmers.sgml @@ -402,9 +402,17 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'), $compile_id - Persistant compile identifier. As an alternative to passing the - same compile_id to each and every function call, you can set this - compile_id and it will be used implicitly thereafter. + Persistant compile identifier. As an alternative to passing the same + compile_id to each and every function call, you can set this compile_id + and it will be used implicitly thereafter. + + + + $use_sub_dirs + + Set this to false if your PHP environment does not allow the creation of + sub directories by Smarty. Sub directories are more efficient, so use them + if you can. @@ -536,14 +544,17 @@ $smarty->clear_assign(array("Name","Address","Zip")); void clear_cache string template string cache id + string compile id - This clears the cache for the specified template. If you have - multiple caches for this template, you can clear a specific - cache by supplying the cache id as the second parameter. See the - caching section for more - information. This was added to Smarty 1.3.0. + This clears the cache for a specific template. If you have + multiple caches for this template, you can clear a specific + cache by supplying the cache id as the second parameter. You + can also pass a compile id as a third paramter. You can "group" + templates together so they can be removed as a group. See the + caching section for + more information. clear_cache @@ -599,7 +610,13 @@ $smarty->clear_compiled_tpl(); As an optional third parameter, you can pass a compile id. This is in the event that you want to compile different versions of the same template, such as having separate templates compiled - for different languages. This was added to Smarty 1.4.5. + for different languages. Another use for compile_id is when you + use more than one $template_dir but only one $compile_dir. Set + a separate compile_id for each $template_dir, otherwise + templates of the same name will overwrite each other. You can + also set the $compile_id variable once + instead of passing this to each call to display(). display @@ -673,7 +690,13 @@ $smarty->display("db:header.tpl"); As an optional third parameter, you can pass a compile id. This is in the event that you want to compile different versions of the same template, such as having separate templates compiled - for different languages. This was added to Smarty 1.4.5. + for different languages. Another use for compile_id is when you + use more than one $template_dir but only one $compile_dir. Set + a separate compile_id for each $template_dir, otherwise + templates of the same name will overwrite each other. You can + also set the $compile_id variable once + instead of passing this to each call to fetch(). fetch diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 05b85cc6..bea203fb 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -175,7 +175,6 @@ class Smarty var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode var $_smarty_debug_info = array(); // debugging information for debug console var $_cache_info = array(); // info that makes up a cache file - var $_auto_id_delim = '|'; // delimiter for auto_id groups var $_plugins = array( // table keeping track of plugins 'modifier' => array(), 'function' => array(), @@ -457,7 +456,7 @@ class Smarty $compile_id = $this->compile_id; if (isset($compile_id) || isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . $this->_auto_id_delim . $cache_id : $cache_id; + $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_id : $cache_id; else $auto_id = null; @@ -1403,18 +1402,15 @@ function _run_insert_handler($args) \*======================================================================*/ function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) { - static $_auto_id_delim_hex = null; static $_dir_sep = null; - - if(!isset($_auto_id_delim_hex)) { - $_auto_id_delim_hex = strtoupper(bin2hex($this->_auto_id_delim)); - } + static $_dir_sep_enc = null; if(!isset($_dir_sep)) { + $_dir_sep_enc = urlencode(DIR_SEP); if($this->use_sub_dirs) { $_dir_sep = DIR_SEP; } else { - $_dir_sep = '%2F'; + $_dir_sep = '^'; } } @@ -1422,15 +1418,15 @@ function _run_insert_handler($args) if(isset($auto_id)) { // make auto_id safe for directory names - $auto_id = str_replace('%'.$_auto_id_delim_hex,$this->_auto_id_delim,(urlencode($auto_id))); + $auto_id = str_replace('%7C','|',(urlencode($auto_id))); // split into separate directories - $auto_id = str_replace($this->_auto_id_delim, $_dir_sep, $auto_id); + $auto_id = str_replace('|', $_dir_sep, $auto_id); $res .= $auto_id . $_dir_sep; } if(isset($auto_source)) { // make source name safe for filename - $auto_source = urlencode($auto_source); + $auto_source = str_replace($_dir_sep_enc,'^',urlencode($auto_source)); $res .= $auto_source . '.php'; } @@ -1551,7 +1547,7 @@ function _run_insert_handler($args) } else { // use local cache file if (isset($compile_id) || isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . $this->_auto_id_delim . $cache_id : $cache_id; + $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_id : $cache_id; else $auto_id = null; @@ -1587,7 +1583,7 @@ function _run_insert_handler($args) } else { // use local file cache if (isset($compile_id) || isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . $this->_auto_id_delim . $cache_id : $cache_id; + $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_id : $cache_id; else $auto_id = null; diff --git a/libs/plugins/function.popup_init.php b/libs/plugins/function.popup_init.php index f3ab84d8..c5d3cd44 100644 --- a/libs/plugins/function.popup_init.php +++ b/libs/plugins/function.popup_init.php @@ -10,16 +10,11 @@ */ function smarty_function_popup_init($params, &$smarty) { - // be sure to place overlib.js where Smarty can locate it. - // overlib.js came with the distribution of Smarty. - extract($params); - echo ''."\n"; - if (empty($src)) { - echo ''."\n"; + if (!empty($params['src'])) { + echo ''."\n"; + echo ''."\n"; } else { - echo ''."\n"; + $smarty->trigger_error("popup_init: missing src parameter"); } } diff --git a/plugins/function.popup_init.php b/plugins/function.popup_init.php index f3ab84d8..c5d3cd44 100644 --- a/plugins/function.popup_init.php +++ b/plugins/function.popup_init.php @@ -10,16 +10,11 @@ */ function smarty_function_popup_init($params, &$smarty) { - // be sure to place overlib.js where Smarty can locate it. - // overlib.js came with the distribution of Smarty. - extract($params); - echo ''."\n"; - if (empty($src)) { - echo ''."\n"; + if (!empty($params['src'])) { + echo ''."\n"; + echo ''."\n"; } else { - echo ''."\n"; + $smarty->trigger_error("popup_init: missing src parameter"); } }