Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * Compile the var named in the first argument and return PHP code to access it raw.
  *
  * @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();
     }
     return $compiler->compileVarRef($arguments[0], $options);
 }
Exemple #3
0
 /**
  * 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 ($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 var named in the first argument and return PHP code to access and urlencode 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();
     }
     return 'urlencode(' . $compiler->compileAndCombineSegments($arguments[0], array_merge($options, array('varEscape' => false))) . ')';
 }
 /**
  * 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();
     }
     return "XenForo_Template_Helper_Core::styleProperty(" . $compiler->compileAndCombineSegments($arguments[0], array_merge($options, array('varEscape' => false))) . ")";
 }
 public static function parse($raw)
 {
     $compiler = new XenForo_Template_Compiler(sprintf('<xen:if is="%s">%s</xen:if>', $raw, md5($raw)));
     $compiler->addFunctionHandler('helper', new WidgetFramework_Helper_Conditional_Function_Helper());
     $parsed = $compiler->lexAndParse();
     $compiler->setFollowExternal(false);
     $parsed = $compiler->compileParsed($parsed, __CLASS__, 0, 0);
     return $parsed;
 }
 protected function _renderTemplate($template, array $params = array())
 {
     extract($params);
     $compiler = new XenForo_Template_Compiler($template);
     XenForo_Application::disablePhpErrorHandler();
     @eval($compiler->compile());
     XenForo_Application::enablePhpErrorHandler();
     return htmlspecialchars_decode($__output, ENT_QUOTES);
 }
Exemple #10
0
 /**
  * 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')) . ')';
 }
Exemple #11
0
 /**
  * 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);
 }
 /**
  * Compiles the function 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();
     }
     $condition = $compiler->parseConditionExpression($arguments[0], $options);
     $true = $function == 'checked' ? 'checked="checked"' : 'selected="selected"';
     return '(' . $condition . ' ? \' ' . $true . '\' : \'\')';
 }
 /**
  * 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)
 {
     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;
 }
 /**
  * Compiles the function 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 && $argc != 2) {
         throw $compiler->getNewCompilerArgumentException();
     }
     if (empty($arguments[1])) {
         $arguments[1] = '0';
     }
     return 'XenForo_Template_Helper_Core::numberFormat(' . $compiler->compileAndCombineSegments($arguments[0], array_merge($options, array('varEscape' => false))) . ', ' . $compiler->compileAndCombineSegments($arguments[1], array_merge($options, array('varEscape' => false))) . ')';
 }
Exemple #16
0
 /**
  * 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')) . '))';
 }
Exemple #17
0
 /**
  * Compile the var named in the first argument and return PHP code to access and escape 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();
     }
     $compileOptions = array_merge($options, array('varEscape' => false));
     if (!empty($arguments[1])) {
         $doubleEncode = $compiler->parseConditionExpression($arguments[1], $options);
     } else {
         $doubleEncode = 'true';
     }
     return 'htmlspecialchars(' . $compiler->compileAndCombineSegments($arguments[0], $compileOptions) . ', ENT_QUOTES, \'UTF-8\', ' . $doubleEncode . ')';
 }
Exemple #18
0
 /**
  * Compile the var named in the first argument and return PHP code to access it raw.
  *
  * @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) > 2) {
         throw $compiler->getNewCompilerArgumentException();
     }
     $compileOptions = array_merge($options, array('varEscape' => false));
     $raw = $compiler->compileVarRef($arguments[0], $options);
     if (empty($arguments[1])) {
         return $raw;
     } else {
         return 'XenForo_Template_Helper_Core::rawCondition(' . $raw . ', ' . $compiler->compileAndCombineSegments($arguments[1], $compileOptions) . ')';
     }
 }
Exemple #19
0
 /**
  * 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;
 }
Exemple #20
0
 /**
  * Compile the var named in the first argument and return PHP code to access and escape 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();
     }
     $compileOptions = array_merge($options, array('varEscape' => false));
     if (!empty($arguments[1])) {
         $doubleEncode = $compiler->parseConditionExpression($arguments[1], $options);
     } else {
         $doubleEncode = 'true';
     }
     // note: ISO-8859-1 is fine since we use UTF-8 and are only replacing basic chars
     return 'htmlspecialchars(' . $compiler->compileAndCombineSegments($arguments[0], $compileOptions) . ', ENT_COMPAT, \'ISO-8859-1\', ' . $doubleEncode . ')';
 }
 /**
  * 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();
     }
     $noEscapeOptions = array_merge($options, array('varEscape' => false));
     $functionCompiled = $compiler->compileAndCombineSegments(array_shift($arguments), $noEscapeOptions);
     $outputArgs = array();
     foreach ($arguments as $argument) {
         $outputArgs[] = $compiler->compileAndCombineSegments($argument, $noEscapeOptions);
     }
     $argumentsCompiled = $compiler->buildNamedParamCode($outputArgs);
     return 'XenForo_Template_Helper_Core::callHelper(' . $functionCompiled . ', ' . $argumentsCompiled . ')';
 }
Exemple #22
0
 /**
  * Compiles the function 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 != 2 && $argc != 3) {
         throw $compiler->getNewCompilerArgumentException();
     }
     $condition = $compiler->parseConditionExpression($arguments[0], $options);
     $true = $compiler->compileAndCombineSegments($arguments[1], $options);
     if (!isset($arguments[2])) {
         $arguments[2] = '';
     }
     $false = $compiler->compileAndCombineSegments($arguments[2], $options);
     return '(' . $condition . ' ? (' . $true . ') : (' . $false . '))';
 }
Exemple #23
0
 /**
  * Compiles the children of a popup.
  *
  * @param string $newOutputVar Name of the compiler output var
  * @param array $children Children of popup
  * @param XenForo_Template_Compiler $compiler
  * @param array $options Compiler options
  *
  * @return string|XenForo_Template_Statement_Raw
  */
 public static function compilePopupChildren($newOutputVar, array $children, XenForo_Template_Compiler $compiler, array $options)
 {
     $oldOutputVar = $compiler->getOutputVar();
     $compiler->setOutputVar($newOutputVar);
     $code = array();
     foreach ($children as $child) {
         if ($compiler->isSegmentNamedTag($child, 'foreach')) {
             $inner = self::compilePopupChildren($newOutputVar, $child['children'], $compiler, $options);
             $code[] = XenForo_Template_Compiler_Tag_Foreach::compileForeach($inner, $compiler, $child['attributes'], $options);
             continue;
         }
         $choice = false;
         $tempVar = false;
         if ($compiler->isSegmentNamedTag($child, 'link')) {
             if (!isset($child['attributes']['href'])) {
                 throw $compiler->getNewCompilerException(new XenForo_Phrase('popup_links_must_specify_an_href'), $child);
             }
             $choice = array('href' => $compiler->compileAndCombineSegments($child['attributes']['href'], $options), 'text' => $compiler->compileAndCombineSegments($child['children'], $options));
         } else {
             if ($compiler->isSegmentNamedTag($child, 'html')) {
                 $code[] = $compiler->compileIntoVariable($child['children'], $htmlOutputVar, $options);
                 $choice = array('html' => '$' . $htmlOutputVar);
                 $tempVar = '$' . $htmlOutputVar;
             }
         }
         if ($choice) {
             $choiceCode = '$' . $newOutputVar . '[] = ' . $compiler->buildNamedParamCode($choice) . ";\n";
             if ($tempVar) {
                 $choiceCode .= 'unset(' . $tempVar . ");\n";
             }
             if (isset($child['attributes']['displayif'])) {
                 $condition = $compiler->parseConditionExpression($child['attributes']['displayif'], $options);
                 $code[] = 'if ' . $condition . "\n{\n" . $choiceCode . "}\n";
             } else {
                 $code[] = $choiceCode;
             }
         }
     }
     $compiler->setOutputVar($oldOutputVar);
     if ($code) {
         $statement = $compiler->getNewRawStatement();
         foreach ($code as $codeStatement) {
             $statement->addStatement($codeStatement);
         }
         return $statement;
     } else {
         return '';
     }
 }
Exemple #24
0
 /**
  * Compiles the function 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 && $argc != 2) {
         throw $compiler->getNewCompilerArgumentException();
     }
     if (empty($arguments[1])) {
         $arguments[1] = '';
     }
     switch ($function) {
         case 'date':
         case 'time':
         case 'datetime':
             $phpFunction = $function;
             break;
         default:
             $phpFunction = 'datetime';
     }
     return 'XenForo_Template_Helper_Core::' . $phpFunction . '(' . $compiler->compileAndCombineSegments($arguments[0], array_merge($options, array('varEscape' => false))) . ', ' . $compiler->compileAndCombineSegments($arguments[1], array_merge($options, array('varEscape' => false))) . ')';
 }
 /**
  * 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] . '\')';
 }
Exemple #26
0
 /**
  * Compiles the function 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 < 4) {
         throw $compiler->getNewCompilerArgumentException();
     }
     $perPage = array_shift($arguments);
     $totalItems = array_shift($arguments);
     $page = array_shift($arguments);
     $linkType = array_shift($arguments);
     $data = 'false';
     if (isset($arguments[0])) {
         $dataRef = array_shift($arguments);
         $data = $compiler->compileAndCombineSegments($dataRef, array_merge($options, array('varEscape' => false)));
     }
     $params = $compiler->getNamedParamsAsPhpCode($compiler->parseNamedArguments($arguments), array_merge($options, array('varEscape' => false)));
     $phpFunction = $function == 'adminpagenav' ? 'adminPageNav' : 'pageNav';
     return 'XenForo_Template_Helper_Core::' . $phpFunction . '(' . $compiler->compileAndCombineSegments($perPage, $options) . ', ' . $compiler->compileAndCombineSegments($totalItems, $options) . ', ' . $compiler->compileAndCombineSegments($page, $options) . ', ' . $compiler->compileAndCombineSegments($linkType, $options) . ', ' . $data . ', ' . $params . ')';
 }
Exemple #27
0
 /**
  * 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;
 }
Exemple #28
0
 /**
  * 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)
 {
     $controlOptions = $compiler->getNamedAttributes($attributes, array('save', 'name', 'reset', 'savekey', 'saveclass', 'resetkey', 'resetclass', 'explain'));
     $controlOptions = $compiler->getNamedParamsAsPhpCode($controlOptions, $options);
     $childOutput = $compiler->compileIntoVariable($children, $submitVar, $options);
     $statement = $compiler->getNewRawStatement();
     $statement->addStatement($childOutput);
     $statement->addStatement('$' . $compiler->getOutputVar() . ' .= XenForo_Template_Helper_Admin::submitUnit($' . $submitVar . ', ' . $controlOptions . ");\n" . 'unset($' . $submitVar . ");\n");
     return $statement;
 }
Exemple #29
0
 /**
  * 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) . '))';
 }
Exemple #30
0
 /**
  * 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;
 }