From c3036c228740b8983c945a78e67341d33bc86fcf Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 12 Jan 2001 16:05:26 +0000 Subject: [PATCH] Fix template traversal. --- Smarty.class.php | 37 +++++++++++++------------------------ libs/Smarty.class.php | 37 +++++++++++++------------------------ 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/Smarty.class.php b/Smarty.class.php index 655e369d..8eb30b39 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -45,7 +45,7 @@ class Smarty 'html_select_date' => 'smarty_func_html_select_date' ); - var $custom_mods = array( 'lower' => 'strtolower', + var $custom_mods = array( 'lower' => 'strtolower', 'upper' => 'strtoupper', 'capitalize' => 'ucwords', 'escape' => 'smarty_mod_escape', @@ -158,16 +158,13 @@ class Smarty function display($tpl_file) { - if(preg_match("/^(.+)\/([^\/]+)$/",$tpl_file,$match)) - { - // compile files - $this->_compile($match[1]); - //assemble compile directory path to file - $_compile_file = preg_replace("/([\.\/]*[^\/]+)(.*)/","\\1".preg_quote($this->compile_dir_ext,"/")."\\2",$tpl_file); - - extract($this->_tpl_vars); - include($_compile_file); - } + // compile files + $this->_compile($this->template_dir); + //assemble compile directory path to file + $_compile_file = preg_replace("/([\.\/]*[^\/]+)(.*)/","\\1".preg_quote($this->compile_dir_ext,"/")."\\2",$tpl_file); + + extract($this->_tpl_vars); + include($_compile_file); } /*======================================================================*\ @@ -218,30 +215,22 @@ class Smarty if(is_dir($tpl_dir)) { if($tpl_dir) + $dir_handle = opendir($tpl_dir); - $dir_handle = opendir($tpl_dir); while($curr_file = readdir($dir_handle)) { - if(!preg_match("/".preg_quote($this->tpl_file_ext,"/")."$/",$curr_file)) - { - //echo "skipping $curr_file
\n"; + if ($curr_file == '.' || $curr_file == '..') continue; - } - + $filepath = $tpl_dir."/".$curr_file; - //echo "filepath is $filepath
\n"; if(is_readable($filepath)) { - if(is_file($filepath)) - { - //echo "is file.
\n"; - //echo $filepath, $depth
\n"; + if(is_file($filepath) && preg_match("/".preg_quote($this->tpl_file_ext,"/")."$/",$curr_file)) { if(!$this->_process_file($filepath)) - return false; + return false; } elseif(is_dir($filepath)) { - //echo "is directory.
\n"; if(!$this->_traverse_files($filepath,$depth+1)) return false; } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 655e369d..8eb30b39 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -45,7 +45,7 @@ class Smarty 'html_select_date' => 'smarty_func_html_select_date' ); - var $custom_mods = array( 'lower' => 'strtolower', + var $custom_mods = array( 'lower' => 'strtolower', 'upper' => 'strtoupper', 'capitalize' => 'ucwords', 'escape' => 'smarty_mod_escape', @@ -158,16 +158,13 @@ class Smarty function display($tpl_file) { - if(preg_match("/^(.+)\/([^\/]+)$/",$tpl_file,$match)) - { - // compile files - $this->_compile($match[1]); - //assemble compile directory path to file - $_compile_file = preg_replace("/([\.\/]*[^\/]+)(.*)/","\\1".preg_quote($this->compile_dir_ext,"/")."\\2",$tpl_file); - - extract($this->_tpl_vars); - include($_compile_file); - } + // compile files + $this->_compile($this->template_dir); + //assemble compile directory path to file + $_compile_file = preg_replace("/([\.\/]*[^\/]+)(.*)/","\\1".preg_quote($this->compile_dir_ext,"/")."\\2",$tpl_file); + + extract($this->_tpl_vars); + include($_compile_file); } /*======================================================================*\ @@ -218,30 +215,22 @@ class Smarty if(is_dir($tpl_dir)) { if($tpl_dir) + $dir_handle = opendir($tpl_dir); - $dir_handle = opendir($tpl_dir); while($curr_file = readdir($dir_handle)) { - if(!preg_match("/".preg_quote($this->tpl_file_ext,"/")."$/",$curr_file)) - { - //echo "skipping $curr_file
\n"; + if ($curr_file == '.' || $curr_file == '..') continue; - } - + $filepath = $tpl_dir."/".$curr_file; - //echo "filepath is $filepath
\n"; if(is_readable($filepath)) { - if(is_file($filepath)) - { - //echo "is file.
\n"; - //echo $filepath, $depth
\n"; + if(is_file($filepath) && preg_match("/".preg_quote($this->tpl_file_ext,"/")."$/",$curr_file)) { if(!$this->_process_file($filepath)) - return false; + return false; } elseif(is_dir($filepath)) { - //echo "is directory.
\n"; if(!$this->_traverse_files($filepath,$depth+1)) return false; }