X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fsmarty%2FSmarty_Compiler.class.php;h=cbcbddb1bd65701972b563de0241ff9d820cb3fa;hb=ac1973d8ab3daa49a77a60980e5a2ee1160d37dc;hp=b444b72454528ae06bd9e4809c748373191f406c;hpb=ce84536664bde5801ec480eeff050df2ba90a045;p=gosa.git diff --git a/include/smarty/Smarty_Compiler.class.php b/include/smarty/Smarty_Compiler.class.php index b444b7245..cbcbddb1b 100644 --- a/include/smarty/Smarty_Compiler.class.php +++ b/include/smarty/Smarty_Compiler.class.php @@ -21,12 +21,12 @@ * @link http://smarty.php.net/ * @author Monte Ohrt * @author Andrei Zmievski - * @version 2.6.9 + * @version 2.6.14 * @copyright 2001-2005 New Digital Group, Inc. * @package Smarty */ -/* $Id: Smarty_Compiler.class.php,v 1.367 2005/03/30 16:48:41 mohrt Exp $ */ +/* $Id: Smarty_Compiler.class.php,v 1.381 2006/05/25 14:46:18 boots Exp $ */ /** * Template compiling class @@ -240,6 +240,9 @@ 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) { @@ -361,7 +364,7 @@ class Smarty_Compiler extends Smarty { $compiled_content .= $text_blocks[$i]; // remove \n from the end of the file, if any - if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) { + if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) { $compiled_content = substr($compiled_content, 0, -1); } @@ -425,7 +428,7 @@ class Smarty_Compiler extends Smarty { function _compile_tag($template_tag) { /* Matched comment. */ - if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') + if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*') return ''; /* Split tag into two three parts: command, command modifiers and the arguments. */ @@ -529,7 +532,7 @@ class Smarty_Compiler extends Smarty { case 'strip': case '/strip': - if ($tag_command{0}=='/') { + if (substr($tag_command, 0, 1)=='/') { $this->_pop_tag('strip'); if (--$this->_strip_depth==0) { /* outermost closing {/strip} */ $this->_additional_newline = "\n"; @@ -572,9 +575,9 @@ class Smarty_Compiler extends Smarty { default: if ($this->_compile_compiler_tag($tag_command, $tag_args, $output)) { return $output; - } else if (@$this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) { + } else if ($this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) { return $output; - } else if (@$this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output)) { + } else if ($this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output)) { return $output; } else { $this->_syntax_error("unrecognized tag '$tag_command'", E_USER_ERROR, __FILE__, __LINE__); @@ -664,7 +667,7 @@ class Smarty_Compiler extends Smarty { */ function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) { - if ($tag_command{0} == '/') { + if (substr($tag_command, 0, 1) == '/') { $start_tag = false; $tag_command = substr($tag_command, 1); } else @@ -726,17 +729,18 @@ class Smarty_Compiler extends Smarty { if ($start_tag) { $output = '_push_cacheable_state('block', $tag_command); $attrs = $this->_parse_attrs($tag_args); - $arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs=''); + $_cache_attrs=''; + $arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs); $output .= "$_cache_attrs\$this->_tag_stack[] = array('$tag_command', array(".implode(',', $arg_list).')); '; - $output .= $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat=true);'; + $output .= '$_block_repeat=true;' . $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat);'; $output .= 'while ($_block_repeat) { ob_start(); ?>'; } else { $output = '_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], $_block_content, $this, $_block_repeat=false)'; + $_out_tag_text = $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], $_block_content, $this, $_block_repeat)'; if ($tag_modifier != '') { $this->_parse_modifiers($_out_tag_text, $tag_modifier); } - $output .= 'echo '.$_out_tag_text.'; } '; + $output .= '$_block_repeat=false;echo ' . $_out_tag_text . '; } '; $output .= " array_pop(\$this->_tag_stack); " . $this->_pop_cacheable_state('block', $tag_command) . '?>'; } @@ -801,7 +805,8 @@ class Smarty_Compiler extends Smarty { $_cacheable_state = $this->_push_cacheable_state('function', $tag_command); $attrs = $this->_parse_attrs($tag_args); - $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs=''); + $_cache_attrs = ''; + $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs); $output = $this->_compile_plugin_call('function', $tag_command).'(array('.implode(',', $arg_list)."), \$this)"; if($tag_modifier != '') { @@ -826,7 +831,7 @@ class Smarty_Compiler extends Smarty { */ function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) { - if ($tag_command{0} == '/') { + if (substr($tag_command, 0, 1) == '/') { $start_tag = false; $tag_command = substr($tag_command, 1); } else { @@ -874,13 +879,13 @@ class Smarty_Compiler extends Smarty { // block method if ($start_tag) { $prefix = "\$this->_tag_stack[] = array('$obj_comp', $args); "; - $prefix .= "\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], null, \$this, \$_block_repeat=true); "; + $prefix .= "\$_block_repeat=true; \$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], null, \$this, \$_block_repeat); "; $prefix .= "while (\$_block_repeat) { ob_start();"; $return = null; $postfix = ''; - } else { - $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); "; - $return = "\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat=false)"; + } else { + $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;"; + $return = "\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat)"; $postfix = "} array_pop(\$this->_tag_stack);"; } } else { @@ -1250,6 +1255,13 @@ class Smarty_Compiler extends Smarty { $tokens = $match[0]; + if(empty($tokens)) { + $_error_msg = $elseif ? "'elseif'" : "'if'"; + $_error_msg .= ' statement requires arguments'; + $this->_syntax_error($_error_msg, E_USER_ERROR, __FILE__, __LINE__); + } + + // make sure we have balanced parenthesis $token_count = array_count_values($tokens); if(isset($token_count['(']) && $token_count['('] != $token_count[')']) { @@ -1372,7 +1384,7 @@ class Smarty_Compiler extends Smarty { !in_array($token, $this->security_settings['IF_FUNCS'])) { $this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__); } - } elseif(preg_match('~^' . $this->_var_regexp . '$~', $token) && isset($tokens[$i+1]) && $tokens[$i+1] == '(') { + } elseif(preg_match('~^' . $this->_var_regexp . '$~', $token) && (strpos('+-*/^%&|', substr($token, -1)) === false) && isset($tokens[$i+1]) && $tokens[$i+1] == '(') { // variable function call $this->_syntax_error("variable function call '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__); } elseif(preg_match('~^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$~', $token)) { @@ -1643,7 +1655,7 @@ class Smarty_Compiler extends Smarty { } elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) { // literal string - return $this->_expand_quoted_text('"' . $val .'"'); + return $this->_expand_quoted_text('"' . strtr($val, array('\\' => '\\\\', '"' => '\\"')) .'"'); } return $val; } @@ -1723,7 +1735,7 @@ class Smarty_Compiler extends Smarty { } // prevent cutting of first digit in the number (we _definitly_ got a number if the first char is a digit) - if(is_numeric($var_expr{0})) + if(is_numeric(substr($var_expr, 0, 1))) $_var_ref = $var_expr; else $_var_ref = substr($var_expr, 1); @@ -1749,7 +1761,7 @@ class Smarty_Compiler extends Smarty { $_var_name = substr(array_shift($_indexes), 1); $_output = "\$this->_smarty_vars['$_var_name']"; } - } elseif(is_numeric($_var_name) && is_numeric($var_expr{0})) { + } elseif(is_numeric($_var_name) && is_numeric(substr($var_expr, 0, 1))) { // because . is the operator for accessing arrays thru inidizes we need to put it together again for floating point numbers if(count($_indexes) > 0) { @@ -1762,11 +1774,11 @@ class Smarty_Compiler extends Smarty { } foreach ($_indexes as $_index) { - if ($_index{0} == '[') { + if (substr($_index, 0, 1) == '[') { $_index = substr($_index, 1, -1); if (is_numeric($_index)) { $_output .= "[$_index]"; - } elseif ($_index{0} == '$') { + } elseif (substr($_index, 0, 1) == '$') { if (strpos($_index, '.') !== false) { $_output .= '[' . $this->_parse_var($_index) . ']'; } else { @@ -1778,8 +1790,8 @@ class Smarty_Compiler extends Smarty { $_var_section_prop = isset($_var_parts[1]) ? $_var_parts[1] : 'index'; $_output .= "[\$this->_sections['$_var_section']['$_var_section_prop']]"; } - } else if ($_index{0} == '.') { - if ($_index{1} == '$') + } else if (substr($_index, 0, 1) == '.') { + if (substr($_index, 1, 1) == '$') $_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]"; else $_output .= "['" . substr($_index, 1) . "']"; @@ -1788,7 +1800,7 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__); } elseif($this->security && substr($_index, 2, 1) == '_') { $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); - } elseif ($_index{2} == '$') { + } elseif (substr($_index, 2, 1) == '$') { if ($this->security) { $this->_syntax_error('(secure) call to dynamic object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); } else { @@ -1797,7 +1809,7 @@ class Smarty_Compiler extends Smarty { } else { $_output .= $_index; } - } elseif ($_index{0} == '(') { + } elseif (substr($_index, 0, 1) == '(') { $_index = $this->_parse_parenth_args($_index); $_output .= $_index; } else { @@ -1894,7 +1906,7 @@ class Smarty_Compiler extends Smarty { preg_match_all('~:(' . $this->_qstr_regexp . '|[^:]+)~', $modifier_arg_strings[$_i], $_match); $_modifier_args = $_match[1]; - if ($_modifier_name{0} == '@') { + if (substr($_modifier_name, 0, 1) == '@') { $_map_array = false; $_modifier_name = substr($_modifier_name, 1); } else { @@ -1916,10 +1928,10 @@ class Smarty_Compiler extends Smarty { if($_modifier_name == 'default') { // supress notifications of default modifier vars and args - if($output{0} == '$') { + if(substr($output, 0, 1) == '$') { $output = '@' . $output; } - if(isset($_modifier_args[0]) && $_modifier_args[0]{0} == '$') { + if(isset($_modifier_args[0]) && substr($_modifier_args[0], 0, 1) == '$') { $_modifier_args[0] = '@' . $_modifier_args[0]; } } @@ -1971,7 +1983,7 @@ class Smarty_Compiler extends Smarty { /* Extract the reference name. */ $_ref = substr($indexes[0], 1); foreach($indexes as $_index_no=>$_index) { - if ($_index{0} != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) { + if (substr($_index, 0, 1) != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) { $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); } } @@ -2209,7 +2221,7 @@ class Smarty_Compiler extends Smarty { if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty')); $_ret = 'if ($this->caching && !$this->_cache_including) { echo \'{nocache:' . $this->_cache_serial . '#' . $this->_nocache_count - . '}\';}'; + . '}\'; };'; return $_ret; } @@ -2226,7 +2238,7 @@ class Smarty_Compiler extends Smarty { || --$this->_cacheable_state>0) return ''; return 'if ($this->caching && !$this->_cache_including) { echo \'{/nocache:' . $this->_cache_serial . '#' . ($this->_nocache_count++) - . '}\';}'; + . '}\'; };'; }