/** * Parsing the joint text of templates and entry text. */ function parse_step4($text) { global $parse_recursion; // We keep a counter to prevent infinite loops. The maximum amount of // recursion is 4.. We also set $Paths['log_url'] the first time. if (isset($parse_recursion)) { $parse_recursion++; } else { $parse_recursion = 1; set_paths_log_url(); } if ($parse_recursion > 4) { return $text; } preg_match_all("|\\[\\[(.*)\\]\\]|U", $text, $match, PREG_PATTERN_ORDER); foreach ($match[1] as $snippet_code) { $snippet_replace = snippet_parse($snippet_code); $text = str_replace("[[" . $snippet_code . "]]", $snippet_replace, $text); } $parse_recursion = 0; return $text; }
/** * Compile a template tag * * @param string $template_tag * @return string */ function _compile_tag($template_tag) { /* Matched comment. */ if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*') { return ''; } /* 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 . '*)) (?:\\s+(.*))?$ ~xs', $template_tag, $match)) { /** * Modified for PivotX: Instead of outputting the error, we attempt to parse the * unrecognised [[ tag ]] as a Pivot 1.x tag. * */ return snippet_parse($template_tag); // $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; if (preg_match('~^' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '$~', $tag_command)) { /* tag name is a variable or object */ $_return = $this->_parse_var_props($tag_command . $tag_modifier); return "<?php echo {$_return}; ?>" . $this->_additional_newline; } /* If the tag name is a registered object, we process it. */ if (preg_match('~^\\/?' . $this->_reg_obj_regexp . '$~', $tag_command)) { return $this->_compile_registered_object_tag($tag_command, $this->_parse_attrs($tag_args), $tag_modifier); } switch ($tag_command) { case 'include': return $this->_compile_include_tag($tag_args); case 'include_php': return $this->_compile_include_php_tag($tag_args); case 'if': $this->_push_tag('if'); return $this->_compile_if_tag($tag_args); case 'else': list($_open_tag) = end($this->_tag_stack); if ($_open_tag != 'if' && $_open_tag != 'elseif') { $this->_syntax_error('unexpected {else}', E_USER_ERROR, __FILE__, __LINE__); } else { $this->_push_tag('else'); } return '<?php else: ?>'; case 'elseif': list($_open_tag) = end($this->_tag_stack); if ($_open_tag != 'if' && $_open_tag != 'elseif') { $this->_syntax_error('unexpected {elseif}', E_USER_ERROR, __FILE__, __LINE__); } if ($_open_tag == 'if') { $this->_push_tag('elseif'); } return $this->_compile_if_tag($tag_args, true); case '/if': $this->_pop_tag('if'); return '<?php endif; ?>'; case 'capture': return $this->_compile_capture_tag(true, $tag_args); case '/capture': return $this->_compile_capture_tag(false); case 'ldelim': return $this->left_delimiter; case 'rdelim': return $this->right_delimiter; case 'section': $this->_push_tag('section'); return $this->_compile_section_start($tag_args); case 'sectionelse': $this->_push_tag('sectionelse'); return "<?php endfor; else: ?>"; break; case '/section': $_open_tag = $this->_pop_tag('section'); if ($_open_tag == 'sectionelse') { return "<?php endif; ?>"; } else { return "<?php endfor; endif; ?>"; } case 'foreach': $this->_push_tag('foreach'); return $this->_compile_foreach_start($tag_args); break; case 'foreachelse': $this->_push_tag('foreachelse'); return "<?php endforeach; else: ?>"; case '/foreach': $_open_tag = $this->_pop_tag('foreach'); if ($_open_tag == 'foreachelse') { return "<?php endif; unset(\$_from); ?>"; } else { return "<?php endforeach; endif; unset(\$_from); ?>"; } break; case 'strip': case '/strip': if (substr($tag_command, 0, 1) == '/') { $this->_pop_tag('strip'); if (--$this->_strip_depth == 0) { /* outermost closing {/strip} */ $this->_additional_newline = "\n"; return '{' . $tag_command . '}'; } } else { $this->_push_tag('strip'); if ($this->_strip_depth++ == 0) { /* outermost opening {strip} */ $this->_additional_newline = ""; return '{' . $tag_command . '}'; } } return ''; case 'php': /* handle folded tags replaced by {php} */ list(, $block) = each($this->_folded_blocks); $this->_current_line_no += substr_count($block[0], "\n"); /* the number of matched elements in the regexp in _compile_file() determins the type of folded tag that was found */ switch (count($block)) { case 2: /* comment */ return ''; case 3: /* literal */ return "<?php echo '" . strtr($block[2], array("'" => "\\'", "\\" => "\\\\")) . "'; ?>" . $this->_additional_newline; case 4: /* php */ if ($this->security && !$this->security_settings['PHP_TAGS']) { $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__); return; } return '<?php ' . $block[3] . ' ?>'; } break; case 'insert': return $this->_compile_insert_tag($tag_args); 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)) { return $output; } else { if ($this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output)) { return $output; } else { /** * Modified for PivotX: Instead of outputting the error, we attempt to parse the * unrecognised [[ tag ]] as a Pivot 1.x tag. * */ return snippet_parse($tag_command); // $this->_syntax_error("unrecognized tag '$tag_command'", E_USER_ERROR, __FILE__, __LINE__); } } } } }