X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=smarty%2FSmarty_Compiler.class.php;h=f54cc2112a8ebc8e2bbe9850a4e386962b3f3110;hb=fdc0d8d266386b90091ff6ad423244f746edb424;hp=cbcbddb1bd65701972b563de0241ff9d820cb3fa;hpb=6f3a0c8c1a1e0ded813fc79568ef096312a51267;p=contagged diff --git a/smarty/Smarty_Compiler.class.php b/smarty/Smarty_Compiler.class.php index cbcbddb..f54cc21 100644 --- a/smarty/Smarty_Compiler.class.php +++ b/smarty/Smarty_Compiler.class.php @@ -21,12 +21,12 @@ * @link http://smarty.php.net/ * @author Monte Ohrt * @author Andrei Zmievski - * @version 2.6.14 + * @version 2.6.18 * @copyright 2001-2005 New Digital Group, Inc. * @package Smarty */ -/* $Id: Smarty_Compiler.class.php,v 1.381 2006/05/25 14:46:18 boots Exp $ */ +/* $Id: Smarty_Compiler.class.php,v 1.395 2007/03/06 10:40:06 messju Exp $ */ /** * Template compiling class @@ -240,9 +240,6 @@ class Smarty_Compiler extends Smarty { $ldq = preg_quote($this->left_delimiter, '~'); $rdq = preg_quote($this->right_delimiter, '~'); - /* un-hide hidden xml open tags */ - $source_content = preg_replace("~<({$ldq}(.*?){$rdq})[?]~s", '< \\1', $source_content); - // run template source through prefilter functions if (count($this->_plugins['prefilter']) > 0) { foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { @@ -281,7 +278,7 @@ class Smarty_Compiler extends Smarty { /* loop through text blocks */ for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) { /* match anything resembling php tags */ - if (preg_match_all('~(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)~is', $text_blocks[$curr_tb], $sp_match)) { + if (preg_match_all('~(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?\s*php\s*[\"\']?)~is', $text_blocks[$curr_tb], $sp_match)) { /* replace tags with placeholders to prevent recursive replacements */ $sp_match[1] = array_unique($sp_match[1]); usort($sp_match[1], '_smarty_sort_length'); @@ -307,7 +304,7 @@ class Smarty_Compiler extends Smarty { } } } - + /* Compile the template tags into PHP code. */ $compiled_tags = array(); for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) { @@ -352,17 +349,30 @@ class Smarty_Compiler extends Smarty { } } $compiled_content = ''; - + + $tag_guard = '%%%SMARTYOTG' . md5(uniqid(rand(), true)) . '%%%'; + /* Interleave the compiled contents and text blocks to get the final result. */ for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { if ($compiled_tags[$i] == '') { // tag result empty, remove first newline from following text block $text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]); } - $compiled_content .= $text_blocks[$i].$compiled_tags[$i]; + // replace legit PHP tags with placeholder + $text_blocks[$i] = str_replace('\n", $compiled_content); + $compiled_content = preg_replace("~(?\n", $compiled_content); + // recover legit tags + $compiled_content = str_replace($tag_guard, '_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content; } - // remove unnecessary close/open tags - $compiled_content = preg_replace('~\?>\n?<\?php~', '', $compiled_content); - // run compiled template through postfilter functions if (count($this->_plugins['postfilter']) > 0) { foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { @@ -927,7 +934,11 @@ class Smarty_Compiler extends Smarty { $name = $this->_dequote($attrs['name']); if (empty($name)) { - $this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__); + return $this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__); + } + + if (!preg_match('~^\w+$~', $name)) { + return $this->_syntax_error("'insert: 'name' must be an insert function name", E_USER_ERROR, __FILE__, __LINE__); } if (!empty($attrs['script'])) { @@ -1160,7 +1171,7 @@ class Smarty_Compiler extends Smarty { } $item = $this->_dequote($attrs['item']); if (!preg_match('~^\w+$~', $item)) { - return $this->_syntax_error("'foreach: item' must be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__); + return $this->_syntax_error("'foreach: 'item' must be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__); } if (isset($attrs['key'])) { @@ -1671,11 +1682,11 @@ class Smarty_Compiler extends Smarty { // if contains unescaped $, expand it if(preg_match_all('~(?:\`(?_dvar_guts_regexp . '(?:' . $this->_obj_ext_regexp . ')*\`)|(?:(?_parse_var(str_replace('`','',$_var)) . ')."', $var_expr); + $_replace[$_var] = '".(' . $this->_parse_var(str_replace('`','',$_var)) . ')."'; } + $var_expr = strtr($var_expr, $_replace); $_return = preg_replace('~\.""|(?_cacheable_state++) return ''; if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty')); - $_ret = 'if ($this->caching && !$this->_cache_including) { echo \'{nocache:' + $_ret = 'if ($this->caching && !$this->_cache_including): echo \'{nocache:' . $this->_cache_serial . '#' . $this->_nocache_count - . '}\'; };'; + . '}\'; endif;'; return $_ret; } @@ -2236,9 +2247,9 @@ class Smarty_Compiler extends Smarty { $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4]; if ($_cacheable || --$this->_cacheable_state>0) return ''; - return 'if ($this->caching && !$this->_cache_including) { echo \'{/nocache:' + return 'if ($this->caching && !$this->_cache_including): echo \'{/nocache:' . $this->_cache_serial . '#' . ($this->_nocache_count++) - . '}\'; };'; + . '}\'; endif;'; }