Exemplo n.º 1
0
 /**
  * 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))) . ')';
 }
Exemplo n.º 2
0
 /**
  * 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))) . ")";
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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) {
         throw $compiler->getNewCompilerArgumentException();
     }
     $condition = $compiler->parseConditionExpression($arguments[0], $options);
     $true = $function == 'checked' ? 'checked="checked"' : 'selected="selected"';
     return '(' . $condition . ' ? \' ' . $true . '\' : \'\')';
 }
Exemplo n.º 5
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] = '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))) . ')';
 }
Exemplo n.º 6
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) . ')';
     }
 }
Exemplo n.º 7
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 . ')';
 }
Exemplo n.º 8
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 . ')';
 }
Exemplo n.º 9
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 . '))';
 }
Exemplo n.º 10
0
 /**
  * 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 . ')';
 }
Exemplo n.º 11
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 . ')';
 }
Exemplo n.º 12
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))) . ')';
 }
Exemplo n.º 13
0
 /**
  * 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] . '\')';
 }
Exemplo n.º 14
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) {
         throw $compiler->getNewCompilerArgumentException();
     }
     $type = 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 == 'adminlink' ? 'adminLink' : 'link';
     if ($options['varEscape'] != 'htmlspecialchars') {
         $varEscapeParam = ', ' . ($options['varEscape'] ? "'{$options['varEscape']}'" : 'false');
     } else {
         $varEscapeParam = '';
     }
     return 'XenForo_Template_Helper_Core::' . $phpFunction . "(" . $compiler->compileAndCombineSegments($type, $options) . ', ' . $data . ', ' . $params . $varEscapeParam . ')';
 }
Exemplo n.º 15
0
 /**
  * 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 . "'";
 }
Exemplo n.º 16
0
 /**
  * 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);
 }