From e09b98b308e4b499d131a4c9c77b9cda27e23b38 Mon Sep 17 00:00:00 2001 From: Julien Mathis <jmathis@merethis.com> Date: Wed, 6 Apr 2011 09:33:22 +0000 Subject: [PATCH] fix syntax problem with preg_split git-svn-id: http://svn.centreon.com/trunk/centreon@12037 6bcd3966-0018-0410-8128-fd23d134de7e --- GPL_LIB/Smarty/libs/Smarty_Compiler.class.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/GPL_LIB/Smarty/libs/Smarty_Compiler.class.php b/GPL_LIB/Smarty/libs/Smarty_Compiler.class.php index 3201195c8c..09b149b792 100644 --- a/GPL_LIB/Smarty/libs/Smarty_Compiler.class.php +++ b/GPL_LIB/Smarty/libs/Smarty_Compiler.class.php @@ -162,7 +162,7 @@ class Smarty_Compiler extends Smarty { . '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)'; $this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)'; $this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)'; - + // matches valid modifier syntax: // |foo // |@foo @@ -304,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++) { @@ -333,7 +333,7 @@ class Smarty_Compiler extends Smarty { for ($j = $i + 1; $j < $for_max; $j++) { /* remove leading and trailing whitespaces of each line */ $text_blocks[$j] = preg_replace('![\t ]*[\r\n]+[\t ]*!', '', $text_blocks[$j]); - if ($compiled_tags[$j] == '{/strip}') { + if ($compiled_tags[$j] == '{/strip}') { /* remove trailing whitespaces from the last text_block */ $text_blocks[$j] = rtrim($text_blocks[$j]); } @@ -349,9 +349,9 @@ 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] == '') { @@ -361,7 +361,7 @@ class Smarty_Compiler extends Smarty { // replace legit PHP tags with placeholder $text_blocks[$i] = str_replace('<?', $tag_guard, $text_blocks[$i]); $compiled_tags[$i] = str_replace('<?', $tag_guard, $compiled_tags[$i]); - + $compiled_content .= $text_blocks[$i] . $compiled_tags[$i]; } $compiled_content .= str_replace('<?', $tag_guard, $text_blocks[$i]); @@ -371,8 +371,8 @@ class Smarty_Compiler extends Smarty { $compiled_content = preg_replace("~(?<!')language\s*=\s*[\"\']?\s*php\s*[\"\']?~", "<?php echo 'language=php' ?>\n", $compiled_content); // recover legit tags - $compiled_content = str_replace($tag_guard, '<?', $compiled_content); - + $compiled_content = str_replace($tag_guard, '<?', $compiled_content); + // remove \n from the end of the file, if any if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) { $compiled_content = substr($compiled_content, 0, -1); @@ -437,7 +437,7 @@ class Smarty_Compiler extends Smarty { /* Matched comment. */ if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*') return ''; - + /* preg_split tag into two three parts: command, command modifiers and the arguments. */ if(! preg_match('~^(?:(' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\/?' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*)) @@ -445,7 +445,7 @@ class Smarty_Compiler extends Smarty { ~xs', $template_tag, $match)) { $this->_syntax_error("unrecognized tag: $template_tag", E_USER_ERROR, __FILE__, __LINE__); } - + $tag_command = $match[1]; $tag_modifier = isset($match[2]) ? $match[2] : null; $tag_args = isset($match[3]) ? $match[3] : null; @@ -585,7 +585,7 @@ class Smarty_Compiler extends Smarty { } 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)) { - return $output; + return $output; } else { $this->_syntax_error("unrecognized tag '$tag_command'", E_USER_ERROR, __FILE__, __LINE__); } @@ -936,7 +936,7 @@ class Smarty_Compiler extends Smarty { if (empty($name)) { 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__); } @@ -1268,11 +1268,11 @@ class Smarty_Compiler extends Smarty { if(empty($tokens)) { $_error_msg = $elseif ? "'elseif'" : "'if'"; - $_error_msg .= ' statement requires arguments'; + $_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[')']) { @@ -1397,7 +1397,7 @@ class Smarty_Compiler extends Smarty { } } 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__); + $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)) { // object or variable $token = $this->_parse_var_props($token); @@ -1706,7 +1706,7 @@ class Smarty_Compiler extends Smarty { function _parse_var($var_expr) { $_has_math = false; - $_math_vars = preg_split('~('.$this->_dvar_math_regexp.'|'.$this->_qstr_regexp.')~', $var_expr, -1, preg_split_DELIM_CAPTURE); + $_math_vars = preg_split('~('.$this->_dvar_math_regexp.'|'.$this->_qstr_regexp.')~', $var_expr, -1, PREG_SPLIT_DELIM_CAPTURE); if(count($_math_vars) > 1) { $_first_var = ""; @@ -1750,12 +1750,12 @@ class Smarty_Compiler extends Smarty { $_var_ref = $var_expr; else $_var_ref = substr($var_expr, 1); - + if(!$_has_math) { - + // get [foo] and .foo and ->foo and (...) pieces preg_match_all('~(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\$?\w+|\.\$?\w+|\S+~', $_var_ref, $match); - + $_indexes = $match[0]; $_var_name = array_shift($_indexes); @@ -2015,7 +2015,7 @@ class Smarty_Compiler extends Smarty { array_shift($indexes); $compiled_ref = "(\$this->_foreach[$_var]['iteration']-1)"; break; - + case 'first': array_shift($indexes); $compiled_ref = "(\$this->_foreach[$_var]['iteration'] <= 1)"; @@ -2025,12 +2025,12 @@ class Smarty_Compiler extends Smarty { array_shift($indexes); $compiled_ref = "(\$this->_foreach[$_var]['iteration'] == \$this->_foreach[$_var]['total'])"; break; - + case 'show': array_shift($indexes); $compiled_ref = "(\$this->_foreach[$_var]['total'] > 0)"; break; - + default: unset($_max_index); $compiled_ref = "\$this->_foreach[$_var]"; @@ -2121,7 +2121,7 @@ class Smarty_Compiler extends Smarty { case 'rdelim': $compiled_ref = "'$this->right_delimiter'"; break; - + default: $this->_syntax_error('$smarty.' . $_ref . ' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__); break; -- GitLab