예제 #1
0
파일: Callback.php 프로젝트: Sywooch/forums
 /**
  * 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;
 }
예제 #2
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;
 }
예제 #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 (!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;
 }
예제 #4
0
파일: Popup.php 프로젝트: Sywooch/forums
 /**
  * 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 '';
     }
 }
예제 #5
0
파일: Abstract.php 프로젝트: Sywooch/forums
 /**
  * Gets the compiled output for a function call, with extra preceding statements
  * and variables to unset.
  *
  * @param XenForo_Template_Compiler $compiler
  * @param string $function Function to call in XenForo_Template_Helper_Admin namespace
  * @param string $args String of PHP code for args
  * @param string|array $extraStatements List of extra, raw PHP statements to prepend
  * @param string|array $unsetVars List of variables to unset at the end, not including leading
  *
  * @return XenForo_Template_Compiler_Statement_Raw
  */
 protected function _getCompiledOutput(XenForo_Template_Compiler $compiler, $function, $args, $extraStatements = false, $unsetVars = false)
 {
     $statement = $compiler->getNewRawStatement();
     if (!is_array($extraStatements)) {
         $extraStatements = array($extraStatements);
     }
     foreach ($extraStatements as $extra) {
         if (is_string($extra) && $extra !== '') {
             $statement->addStatement($extra);
         }
     }
     $statement->addStatement('$' . $compiler->getOutputVar() . ' .= XenForo_Template_Helper_Admin::' . $function . '(' . $args . ");\n");
     if (is_string($unsetVars)) {
         $unsetVars = array($unsetVars);
     }
     if (is_array($unsetVars)) {
         $unset = '';
         foreach ($unsetVars as $unsetVar) {
             if (!is_string($unsetVar) || $unsetVar === '') {
                 continue;
             }
             if ($unset) {
                 $unset .= ', ';
             }
             $unset .= '$' . $unsetVar;
         }
         if ($unset) {
             $statement->addStatement('unset(' . $unset . ");\n");
         }
     }
     return $statement;
 }
예제 #6
0
파일: ListItem.php 프로젝트: Sywooch/forums
 /**
  * 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)
 {
     $data = $attributes;
     $html = null;
     $popups = array();
     $links = array();
     $tempVars = array();
     $statement = $compiler->getNewRawStatement();
     foreach ($children as $child) {
         if ($compiler->isSegmentNamedTag($child, 'label')) {
             $data['label'] = $child['children'];
         } else {
             if ($compiler->isSegmentNamedTag($child, 'snippet')) {
                 $data['snippet'] = $child['children'];
             } else {
                 if ($compiler->isSegmentNamedTag($child, 'html')) {
                     $html = $child['children'];
                 } else {
                     if ($compiler->isSegmentNamedTag($child, 'popup')) {
                         $tempVar = $compiler->getUniqueVar();
                         $oldOutputVar = $compiler->getOutputVar();
                         $compiler->setOutputVar($tempVar);
                         $popupStatement = XenForo_Template_Compiler_Tag_Admin_Popup::compilePopup($compiler, $child['attributes'], $child['children'], $options, 'div', 'Left');
                         $statement->addStatement($compiler->getOutputVarInitializer() . $popupStatement->getFullStatements($tempVar));
                         $popups[] = '$' . $tempVar;
                         $tempVars[] = '$' . $tempVar;
                         $compiler->setOutputVar($oldOutputVar);
                     } else {
                         if ($compiler->isSegmentNamedTag($child, 'beforelabel')) {
                             $data['beforelabel'] = $child['children'];
                         } else {
                             if ($compiler->isSegmentNamedTag($child, 'toggle')) {
                                 $data['toggle'] = $child['children'];
                             } else {
                                 if ($compiler->isSegmentNamedTag($child, 'toggletitle')) {
                                     $data['toggletitle'] = $child['children'];
                                 }
                             }
                         }
                     }
                 }
             }
         }
         /*else if ($compiler->isSegmentNamedTag($child, 'link'))
         			{
         				$tempVar = $compiler->getUniqueVar();
         
         				$oldOutputVar = $compiler->getOutputVar();
         				$compiler->setOutputVar($tempVar);
         
         				$linkStatement = XenForo_Template_Compiler_Tag_Admin_ListItemLink::compileLink(
         					$compiler, $child['attributes'], $child['children'], $options
         				);
         
         				$statement->addStatement(
         					$compiler->getOutputVarInitializer()
         					. $linkStatement->getFullStatements($tempVar)
         				);
         
         				$links[] = '$' . $tempVar;
         				$tempVars[] = '$' . $tempVar;
         
         				$compiler->setOutputVar($oldOutputVar);
         			}*/
     }
     if (!isset($data['label'])) {
         throw $compiler->getNewCompilerException(new XenForo_Phrase('list_items_must_specify_label'));
     }
     if (!isset($data['id'])) {
         throw $compiler->getNewCompilerException(new XenForo_Phrase('list_items_must_specify_an_id'));
     }
     $compiledData = $compiler->compileNamedParams($data, $options);
     if ($html) {
         $htmlCode = $compiler->compileIntoVariable($html, $htmlOutputVar, $options);
         $statement->addStatement($htmlCode);
         $compiledData['html'] = '$' . $htmlOutputVar;
         $tempVars[] = '$' . $htmlOutputVar;
     }
     $controlData = $compiler->buildNamedParamCode($compiledData);
     if ($popups) {
         $popupData = $compiler->buildNamedParamCode($popups);
     } else {
         $popupData = 'array()';
     }
     if ($links) {
         $linkData = $compiler->buildNamedParamCode($links);
     } else {
         $linkData = 'array()';
     }
     $statement->addStatement('$' . $compiler->getOutputVar() . ' .= XenForo_Template_Helper_Admin::listItem(' . $controlData . ', ' . $popupData . ', ' . $linkData . ");\n");
     if ($tempVars) {
         $statement->addStatement('unset(' . implode(', ', $tempVars) . ");\n");
     }
     return $statement;
 }
예제 #7
0
파일: Include.php 프로젝트: Sywooch/forums
 /**
  * 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 '';
     }
 }