/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if ($tag == 'breadcrumb') { throw $compiler->getNewCompilerException(new XenForo_Phrase('breadcrumb_tag_must_be_within_navigation_tag')); } if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'navigation'))); } $rawStatement = $compiler->getNewRawStatement(); $rawStatement->addStatement("\$__extraData['navigation'] = array();\n"); foreach ($children as $child) { if ($compiler->isSegmentNamedTag($child, 'breadcrumb')) { if (isset($child['attributes']['source'])) { $sourceVar = $compiler->compileVarRef($child['attributes']['source'], $options); $rawStatement->addStatement('$__extraData[\'navigation\'] = XenForo_Template_Helper_Core::appendBreadCrumbs($__extraData[\'navigation\'], ' . $sourceVar . ");\n"); } else { $parts = array(); foreach ($child['attributes'] as $name => $value) { $parts[] = "'" . $compiler->escapeSingleQuotedString($name) . "' => " . $compiler->compileAndCombineSegments($value, $options); } $parts[] = "'value' => " . $compiler->compileAndCombineSegments($child['children'], $options); $rawStatement->addStatement('$__extraData[\'navigation\'][] = array(' . implode(', ', $parts) . ");\n"); } } else { if (is_string($child) && trim($child) === '') { // whitespace -- ignore it } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_data_found_in_navigation_tag'), $child); } } } return $rawStatement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'set'))); } if (empty($attributes['var'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'var', 'tag' => 'set'))); } $var = $compiler->compileVarRef($attributes['var'], array_merge($options, array('disableVarMap' => true))); $var = substr($var, 1); // need to take off leading $ if (empty($children)) { $children = null; } if (!empty($attributes['value'])) { if ($children) { throw $compiler->getNewCompilerException(new XenForo_Phrase('tag_contained_children_and_value_attribute')); } $value = $compiler->compileAndCombineSegments($attributes['value'], array_merge($options, array('varEscape' => false))); $childOutput = '$' . $var . ' = ' . $value . ";\n"; } else { $childOutput = $compiler->compileIntoVariable($children, $var, $options, false); } $statement = $compiler->getNewRawStatement(); $statement->addStatement($childOutput); return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'callback'))); } if (empty($attributes['class'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'class', 'tag' => 'callback'))); } if (empty($attributes['method'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'method', 'tag' => 'callback'))); } $noEscapeOptions = array_merge($options, array('varEscape' => false)); $class = $compiler->compileAndCombineSegments($attributes['class'], $noEscapeOptions); $method = $compiler->compileAndCombineSegments($attributes['method'], $noEscapeOptions); $compiled = $compiler->compileIntoVariable($children, $var, $options); if (!empty($attributes['params'])) { $params = $compiler->compileAndCombineSegments($attributes['params'], $noEscapeOptions); } else { $params = 'array()'; } $statement = $compiler->getNewRawStatement(); $statement->addStatement($compiled); $statement->addStatement('$' . $compiler->getOutputVar() . ' .= $this->callTemplateCallback(' . $class . ', ' . $method . ', $' . $var . ', ' . $params . ");\n" . 'unset($' . $var . ");\n"); return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'require'))); } $requirements = $compiler->getNamedAttributes($attributes, array('css', 'js')); if (!$requirements) { throw $compiler->getNewCompilerException(new XenForo_Phrase('require_tag_does_not_specify_any_known_types_css_or_js')); } if (isset($requirements['css'])) { $css = $requirements['css']; if (empty($css) || count($css) != 1 || !is_string($css[0])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('only_literal_css_templates_may_be_included_by_require_tag')); } if (substr($css[0], -4) != '.css') { throw $compiler->getNewCompilerException(new XenForo_Phrase('all_required_css_templates_must_end_in_')); } $requirements['css'][0] = substr($css[0], 0, -4); } $statement = $compiler->getNewRawStatement(); foreach ($requirements as $attribute => $value) { $statement->addStatement('$this->addRequiredExternal(\'' . $compiler->escapeSingleQuotedString($attribute) . '\', ' . $compiler->compileAndCombineSegments($value) . ");\n"); } return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { // number (integer) if (!empty($attributes['number'])) { $number = $compiler->compileVarRef($attributes['number'], $options); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'number', 'tag' => 'likes'))); } if (!empty($attributes['url'])) { $url = $compiler->compileVarRef($attributes['url'], $options); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'url', 'tag' => 'likes'))); } return 'XenForo_Template_Helper_Core::callHelper(\'likeshtml\', array(' . $number . ',' . $url . ',' . $compiler->compileVarRef($attributes['liked'], $options) . ',' . $compiler->compileVarRef($attributes['users'], $options) . '))'; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'container'))); } if (empty($attributes['var'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_container_tag_var_attribute')); } $var = $compiler->compileVarRef($attributes['var'], array_merge($options, array('disableVarMap' => true))); $var = preg_replace('/^\\$([^[\']*)/', '__extraData[\'$1\']', $var); $childOutput = $compiler->compileIntoVariable($children, $var, $options, false); $statement = $compiler->getNewRawStatement(); $statement->addStatement($childOutput); return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($attributes['template'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'template', 'tag' => 'edithint'))); } return ''; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($attributes['url'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'url', 'tag' => 'formaction'))); } return 'XenForo_Template_Helper_Core::getHiddenInputsFromUrl(' . $compiler->compileAndCombineSegments($attributes['url'], $options) . ')'; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'set'))); } if (empty($attributes['var'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'var', 'tag' => 'set'))); } $var = $compiler->compileVarRef($attributes['var'], array_merge($options, array('disableVarMap' => true))); $var = substr($var, 1); // need to take off leading $ $childOutput = $compiler->compileIntoVariable($children, $var, $options, false); $statement = $compiler->getNewRawStatement(); $statement->addStatement($childOutput); return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (!empty($attributes['user'])) { $user = $compiler->compileVarRef($attributes['user'], $options); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'user', 'tag' => 'follow'))); } return 'XenForo_Template_Helper_Core::followHtml(' . $user . ',' . $compiler->getNamedParamsAsPhpCode($attributes, $options, array('code')) . ')'; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'title'))); } $var = '__extraData[\'title\']'; $childOutput = $compiler->compileIntoVariable($children, $var, $options, false); return $compiler->getNewRawStatement($childOutput); }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'description'))); } $rawStatement = $compiler->getNewRawStatement(); $rawStatement->addStatement("\$__extraData['pageDescription'] = " . $compiler->getNamedParamsAsPhpCode($attributes, $options, array('skipmeta')) . ";\n"); $var = '__extraData[\'pageDescription\'][\'content\']'; $rawStatement->addStatement($compiler->compileIntoVariable($children, $var, $options, false)); return $rawStatement; }
/** * Helper to allow foreach tags to be compiled in multiple places with easier validation. * * @param string $inner Compiled inner code * @param XenForo_Template_Compiler $compiler * @param array $attributes * @param array $options * * @return XenForo_Compiler_Statement_Raw */ public static function compileForeach($inner, XenForo_Template_Compiler $compiler, array $attributes, array $options) { if (empty($attributes['loop'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'loop', 'tag' => 'foreach'))); } if (empty($attributes['value'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'value', 'tag' => 'foreach'))); } $noMapOptions = array_merge($options, array('disableVarMap' => true)); $loop = $compiler->compileVarRef($attributes['loop'], $options); $value = $compiler->compileVarRef($attributes['value'], $noMapOptions); if (isset($attributes['key'])) { $key = $compiler->compileVarRef($attributes['key'], $noMapOptions); $keyCode = $key . ' => '; } else { $keyCode = ''; } if (isset($attributes['i'])) { $i = $compiler->compileVarRef($attributes['i'], $noMapOptions); } else { $i = ''; } if (isset($attributes['count'])) { $count = $compiler->compileVarRef($attributes['count'], $noMapOptions); } else { $count = ''; } $statement = $compiler->getNewRawStatement(); if ($i) { $statement->addStatement($i . " = 0;\n"); } if ($count) { $statement->addStatement($count . ' = count(' . $loop . ");\n"); } $statement->addStatement('foreach (' . $loop . ' AS ' . $keyCode . $value . ")\n{\n"); if ($i) { $statement->addStatement($i . "++;\n"); } $statement->addStatement($inner)->addStatement("}\n"); return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (!isset($attributes['action'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('form_tags_must_specify_an_action')); } $rowOptions = $compiler->getNamedParamsAsPhpCode($attributes, $options, array('upload')); $childOutput = $compiler->compileIntoVariable($children, $formVar, $options); $statement = $compiler->getNewRawStatement(); $statement->addStatement($childOutput); $statement->addStatement('$' . $compiler->getOutputVar() . ' .= XenForo_Template_Helper_Admin::form($' . $formVar . ', ' . $rowOptions . ");\n" . 'unset($' . $formVar . ");\n"); return $statement; }
/** * Compile the content in the first argument and escape it for JS based on the second. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the function called * @param array Arguments to the function (should have at least 1) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $function, array $arguments, array $options) { $argc = count($arguments); if ($argc != 1 && $argc != 2) { throw $compiler->getNewCompilerArgumentException(); } if (empty($arguments[1])) { $arguments[1] = 'double'; } if (!is_string($arguments[1])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('argument_must_be_string')); } switch ($arguments[1]) { case 'double': case 'single': break; default: throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_argument')); } return 'XenForo_Template_Helper_Core::jsEscape(' . $compiler->compileAndCombineSegments($arguments[0], $options) . ', \'' . $arguments[1] . '\')'; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (!empty($attributes['time'])) { $time = $compiler->compileVarRef($attributes['time'], $options); } else { if (!empty($children)) { $time = $compiler->compileAndCombineSegments($children, $options); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'time', 'tag' => 'datetime'))); } } return 'XenForo_Template_Helper_Core::callHelper(\'datetimehtml\', array(' . $time . ',' . $compiler->getNamedParamsAsPhpCode($attributes, $options, array('code')) . '))'; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($attributes['perpage'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'perpage', 'tag' => 'pagenav'))); } if (empty($attributes['total'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'total', 'tag' => 'pagenav'))); } if (empty($attributes['page'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'page', 'tag' => 'pagenav'))); } if (empty($attributes['link'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'link', 'tag' => 'pagenav'))); } if (!empty($attributes['linkdata'])) { $linkData = $compiler->compileAndCombineSegments($attributes['linkdata'], array_merge($options, array('varEscape' => false))); } else { $linkData = 'false'; } if (!empty($attributes['unreadlink'])) { $unreadLink = $compiler->compileAndCombineSegments($attributes['unreadlink'], $options); } else { $unreadLink = 'false'; } if (!empty($attributes['linkparams'])) { $linkParams = $compiler->compileAndCombineSegments($attributes['linkparams'], array_merge($options, array('varEscape' => false))); } else { $linkParams = 'array()'; } if (!empty($attributes['options'])) { $tagOptions = $compiler->compileAndCombineSegments($attributes['options'], array_merge($options, array('varEscape' => false))); } else { $tagOptions = 'array()'; } $type = $tag == 'adminpagenav' ? 'admin' : 'public'; return 'XenForo_Template_Helper_Core::callHelper(\'pagenavhtml\', array(' . '\'' . $type . '\', ' . $compiler->compileAndCombineSegments($attributes['perpage'], $options) . ', ' . $compiler->compileAndCombineSegments($attributes['total'], $options) . ', ' . $compiler->compileAndCombineSegments($attributes['page'], $options) . ', ' . $compiler->compileAndCombineSegments($attributes['link'], $options) . ', ' . $linkData . ', ' . $linkParams . ', ' . $unreadLink . ', ' . $tagOptions . '))'; }
/** * Helper to compile a popup statically. Used to allow list rows to modify * the compilation behavior. * * @param XenForo_Template_Compiler $compiler * @param array $attributes * @param array $children Child tags * @param array $options Compiler option * @param string $wrapTag The HTML tag to wrap with (probably div or li) * @param string $extraMenuClass An extra menu class (or multiple to add) * * @return XenForo_Compiler_Statement_Raw */ public static function compilePopup(XenForo_Template_Compiler $compiler, array $attributes, array $children, array $options, $wrapTag, $extraMenuClass = '') { if (!isset($attributes['title'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('popups_must_specify_title')); } $choiceOutputVar = $compiler->getUniqueVar(); $choicesCode = self::compilePopupChildren($choiceOutputVar, $children, $compiler, $options); $controlData = $compiler->getNamedParamsAsPhpCode($attributes, $options); $statement = $compiler->getNewRawStatement(); $statement->addStatement('$' . $choiceOutputVar . " = array();\n"); $statement->addStatement($choicesCode); $statement->addStatement('$' . $compiler->getOutputVar() . ' .= XenForo_Template_Helper_Admin::popup(' . $controlData . ', $' . $choiceOutputVar . ', \'' . $compiler->escapeSingleQuotedString($wrapTag) . '\', \'' . $compiler->escapeSingleQuotedString($extraMenuClass) . "');\n"); $statement->addStatement('unset($' . $choiceOutputVar . ");\n"); return $statement; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { // user array if (!empty($attributes['user'])) { $user = $compiler->compileVarRef($attributes['user'], $options); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_attribute_x_for_tag_y', array('attribute' => 'user', 'tag' => 'avatar'))); } // avatar image mode (span or img) if (isset($attributes['img'])) { $img = $compiler->parseConditionExpression($attributes['img'], $options); } else { $img = 'false'; } return 'XenForo_Template_Helper_Core::callHelper(\'avatarhtml\', array(' . $user . ',' . $img . ',' . $compiler->getNamedParamsAsPhpCode($attributes, $options, array('code')) . ',' . $compiler->compileAndCombineSegments($children, $options) . '))'; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { // user array if (!empty($attributes['user'])) { $user = $compiler->compileVarRef($attributes['user'], $options); unset($attributes['user']); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_x_attribute_for_y_tag', array('attribute' => 'user', 'tag' => 'username'))); } if (!empty($attributes['rich'])) { $rich = $compiler->parseConditionExpression($attributes['rich'], $options); } else { $rich = 'false'; } unset($attributes['rich']); return 'XenForo_Template_Helper_Core::userNameHtml(' . $user . ',' . $compiler->compileAndCombineSegments($children, $options) . ',' . $rich . ',' . $compiler->getNamedParamsAsPhpCode($attributes, $options, array('code')) . ')'; }
/** * Compiles the phrase call. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the function called * @param array Arguments to the function (should have at least 1) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $function, array $arguments, array $options) { $argc = count($arguments); if ($argc < 1) { throw $compiler->getNewCompilerArgumentException(); } $phraseName = $compiler->getArgumentLiteralValue(array_shift($arguments)); if ($phraseName === false) { throw $compiler->getNewCompilerException(new XenForo_Phrase('phrase_name_must_be_literal')); } $phraseValue = $compiler->getPhraseValue($phraseName); if ($phraseValue === false) { return "'" . $compiler->escapeSingleQuotedString($phraseName) . "'"; } $this->_params = $compiler->compileNamedParams($compiler->parseNamedArguments($arguments), $options); $phraseValueEscaped = $compiler->escapeSingleQuotedString($phraseValue); $phraseValueEscaped = preg_replace_callback('/\\{([a-z0-9_-]+)\\}/i', array($this, '_replaceParam'), $phraseValueEscaped); if ($phraseValueEscaped === '') { return ''; } $this->_params = array(); return "'" . $phraseValueEscaped . "'"; }
/** * Compile the function and return PHP handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the function called * @param array Arguments to the function (should have at least 1) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $function, array $arguments, array $options) { if (count($arguments) != 1) { throw $compiler->getNewCompilerArgumentException(); } $placeholders = array(); if (is_string($arguments[0])) { $expression = $arguments[0]; } else { $expression = ''; foreach ($compiler->prepareSegmentsForIteration($arguments[0]) as $segment) { if (is_string($segment)) { if (strpos($segment, '?') !== false) { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_math_expression')); } $expression .= $segment; } else { $expression .= '?'; $placeholders[] = $compiler->compileSegment($segment, array_merge($options, array('varEscape' => false))); } } } return $this->_parseMathExpression($compiler, $expression, $placeholders); }
/** * Gets all data-* attributes and returns them as an array without the * data prefix. * * @param array $attributes * * @return array Key-value data pairs, without the "data-" prefix */ protected function _getDataAttributes(XenForo_Template_Compiler $compiler, array $attributes) { $data = array(); foreach ($attributes as $key => $value) { if (strtolower(substr($key, 0, 5)) == 'data-') { $dataKey = substr($key, 5); if (is_string($dataKey) && strlen($dataKey) >= 1) { if (strval(intval($dataKey)) === $dataKey) { throw $compiler->getNewCompilerException(new XenForo_Phrase('data_attributes_names_may_not_look_like_integers')); } $data[$dataKey] = $value; } } } return $data; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if ($tag == 'contentcheck') { throw $compiler->getNewCompilerException(new XenForo_Phrase('contentcheck_tag_found_that_was_not_direct_child_of_an_if_tag_with')); } else { if ($tag != 'if') { throw $compiler->getNewCompilerException(new XenForo_Phrase('else_or_else_if_tag_not_found_that_was_not_direct_child_of_an_if_tag')); } } if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'if'))); } $parts = array(0 => array('is' => isset($attributes['is']) ? $attributes['is'] : '', 'hascontent' => isset($attributes['hascontent']) ? $attributes['hascontent'] : '', 'segments' => array(), 'line' => $compiler->getLineNumber())); $partKey = 0; $haveElse = false; foreach ($children as $child) { if ($compiler->isSegmentNamedTag($child, 'elseif')) { if ($haveElse) { throw $compiler->getNewCompilerException(new XenForo_Phrase('else_if_tag_found_after_else_tag'), $child); } if (!empty($child['children'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('else_if_tags_may_not_have_children'), $child); } $partKey++; $parts[$partKey] = array('is' => isset($child['attributes']['is']) ? $child['attributes']['is'] : '', 'hascontent' => isset($child['attributes']['hascontent']) ? $child['attributes']['hascontent'] : '', 'segments' => array(), 'line' => $child['line']); } else { if ($compiler->isSegmentNamedTag($child, 'else')) { if (!empty($child['children'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('else_tags_may_not_have_children'), $child); } if ($haveElse) { throw $compiler->getNewCompilerException(new XenForo_Phrase('only_one_else_tag_allowed_per_if_tag'), $child); } $haveElse = true; $partKey++; $parts[$partKey] = array('else' => true, 'segments' => array(), 'line' => $child['line']); } else { $parts[$partKey]['segments'][] = $child; } } } $ifStatement = $compiler->getNewRawStatement(); $prependCheckStatements = $compiler->getNewRawStatement(); $allCheckVars = array(); foreach ($parts as $partKey => $part) { $conditionType = $partKey == 0 ? 'if' : 'else if'; if (!empty($part['is'])) { $condition = $compiler->parseConditionExpression($part['is'], $options); $ifStatement->addStatement($conditionType . ' ' . $condition . "\n{\n")->addStatement($compiler->compileSegments($part['segments'], $options))->addStatement("}\n"); } else { if (!empty($part['hascontent'])) { $childStatement = $compiler->getNewStatementCollection(); $checkVars = array(); foreach ($part['segments'] as $segment) { if ($compiler->isSegmentNamedTag($segment, 'contentcheck')) { $prependCheckStatements->addStatement($compiler->compileIntoVariable($segment['children'], $checkVar, $options)); $childStatement->addStatement('$' . $checkVar); $checkVars[] = $checkVar; $allCheckVars[] = '$' . $checkVar; } else { $childStatement->addStatement($compiler->compileSegment($segment, $options)); } } if (!$checkVars) { throw $compiler->getNewCompilerException(new XenForo_Phrase('cannot_have_content_checking_if_tag_without_contentcheck_part'), $part['line']); } $conditionParts = array(); foreach ($checkVars as $checkCondition) { $conditionParts[] = 'trim($' . $checkCondition . ") !== ''"; } $checkCond = implode(' || ', $conditionParts); $ifStatement->addStatement("{$conditionType} ({$checkCond})\n{\n")->addStatement($childStatement)->addStatement("}\n"); } else { if (!empty($part['else'])) { $ifStatement->addStatement("else\n{\n")->addStatement($compiler->compileSegments($part['segments'], $options))->addStatement("}\n"); } else { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_if_or_else_if_tag_missing_is_or_hascontent'), $part['line']); } } } } $prependCheckStatements->addStatement($ifStatement); if ($allCheckVars) { $prependCheckStatements->addStatement("unset(" . implode(', ', $allCheckVars) . ");\n"); } return $prependCheckStatements; }
/** * Compile the specified tag and return PHP code to handle it. * * @param XenForo_Template_Compiler The invoking compiler * @param string Name of the tag called * @param array Attributes for the tag (may be empty) * @param array Nodes (tags/curlies/text) within this tag (may be empty) * @param array Compilation options * * @return string */ public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options) { if (empty($options['allowRawStatements'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'include'))); } if (empty($attributes['template']) || count($attributes['template']) != 1 || !is_string($attributes['template'][0])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_specified')); } $include = $attributes['template'][0]; $template = $compiler->includeParsedTemplate($include); $statement = $compiler->getNewRawStatement(); $tempVars = array(); $mapVars = array(); foreach ($children as $child) { if ($compiler->isSegmentNamedTag($child, 'map')) { $childAttr = $child['attributes']; if (empty($childAttr['from']) || empty($childAttr['to'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('included_template_variable_mappings_must_include_from_and_to_attributes')); } $from = $compiler->compileVarRef($childAttr['from'], $options); if (count($childAttr['to']) != 1 || !is_string($childAttr['to'][0])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_mapping_specified')); } if (!preg_match('#^\\$([a-zA-Z_][a-zA-Z0-9_]*)$#', $childAttr['to'][0])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_mapping_specified')); } // "from $outer" and "to $inner"; when processed (within inner template), need to map the other direction. $mapVars[substr($childAttr['to'][0], 1)] = substr($from, 1); } else { if ($compiler->isSegmentNamedTag($child, 'set')) { // take var as "to" and compile into a temporary variable $childAttr = $child['attributes']; if (empty($childAttr['var'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('included_template_variable_assignments_must_include_var_attribute')); } if (count($childAttr['var']) != 1 || !is_string($childAttr['var'][0])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_assignment_specified')); } $mapRegex = '#^\\$([a-zA-Z_][a-zA-Z0-9_]*)$#'; if (!preg_match($mapRegex, $childAttr['var'][0])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_assignment_specified')); } if (!empty($childAttr['value'])) { if ($child['children']) { throw $compiler->getNewCompilerException(new XenForo_Phrase('tag_contained_children_and_value_attribute')); } $value = $compiler->compileAndCombineSegments($childAttr['value'], array_merge($options, array('varEscape' => false))); $setVar = $compiler->getUniqueVar(); $childOutput = '$' . $setVar . ' = ' . $value . ";\n"; } else { $childOutput = $compiler->compileIntoVariable($child['children'], $setVar, $options); } $statement->addStatement($childOutput); $mapVars[substr($childAttr['var'][0], 1)] = $setVar; $tempVars[] = $setVar; } } } if ($template) { $oldMap = $compiler->getVariableMap(); $compiler->setVariableMap($mapVars, true); $compiled = $compiler->compileIntoVariable($template, $var, $options); $tempVars[] = $var; $compiler->setVariableMap($oldMap); $statement->addStatement($compiled); $statement->addStatement('$' . $compiler->getOutputVar() . ' .= $' . $var . ";\n" . 'unset($' . implode(', $', $tempVars) . ");\n"); return $statement; } else { return ''; } }