示例#1
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 '';
     }
 }
示例#2
0
 /**
  * Gets the choices that apply to this tag, via option/optgroup/options tags.
  *
  * @param array $children Child tags to search
  * @param XenForo_Template_Compiler $compiler Compiler
  * @param array $options Compiler options
  * @param string $newOutputVar
  *
  * @return string
  */
 protected function _getChoicesCode(array $children, XenForo_Template_Compiler $compiler, array $options, &$newOutputVar = '')
 {
     $oldOutputVar = $compiler->getOutputVar();
     $newOutputVar = $compiler->getUniqueVar();
     $compiler->setOutputVar($newOutputVar);
     $code = '$' . $newOutputVar . " = array();\n";
     foreach ($children as $child) {
         $compiler->setLastVistedSegment($child);
         $code .= $this->_compileChoiceChild($newOutputVar, $child, $compiler, $options);
     }
     $compiler->setOutputVar($oldOutputVar);
     return $code;
 }
示例#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)
 {
     $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;
 }