/** * 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 ''; } }
protected function _compileChoiceChild($newOutputVar, $child, XenForo_Template_Compiler $compiler, array $options) { if ($compiler->isSegmentNamedTag($child, 'foreach')) { $inner = ''; foreach ($child['children'] as $grandChild) { $inner .= $this->_compileChoiceChild($newOutputVar, $grandChild, $compiler, $options); } $statement = XenForo_Template_Compiler_Tag_Foreach::compileForeach($inner, $compiler, $child['attributes'], $options); return $statement->getFullStatements($newOutputVar); } else { if ($compiler->isSegmentNamedTag($child, 'option')) { $choice = $compiler->getNamedAttributes($child['attributes'], array('label', 'name', 'value', 'selected', 'hint', 'id', 'class', 'inputclass', 'title', 'depth', 'disabled', 'optdisabled', 'unselectable')); $childrenAsLabel = isset($choice['label']) ? false : true; // if label attribute, then assume children as "special" $foundOther = false; $disabledControls = array(); foreach ($child['children'] as $optionChild) { if (!is_array($optionChild) || !isset($optionChild['type']) || $optionChild['type'] != 'TAG') { continue; } $optionChildName = strtolower($optionChild['name']); switch ($optionChildName) { case 'label': case 'hint': $choice[$optionChildName] = $optionChild['children']; $childrenAsLabel = false; break; case 'checkbox': case 'combobox': case 'password': case 'radio': case 'select': case 'spinbox': case 'textbox': case 'upload': $disabledControls[] = $optionChild; $childrenAsLabel = false; break; case 'disabled': $disabledControls[] = $optionChild['children']; $childrenAsLabel = false; break; default: $foundOther = $optionChild; } } if (!isset($choice['label'])) { if (!$childrenAsLabel) { throw $compiler->getNewCompilerException(new XenForo_Phrase('missing_label_for_option_tag'), $child); } $choice['label'] = $child['children']; } $data = $this->_getDataAttributes($compiler, $child['attributes']); if ($data) { $choice['_data'] = $data; } if (!$childrenAsLabel && $foundOther) { // have special tags as child and found unexpected throw $compiler->getNewCompilerException(new XenForo_Phrase('found_unexpected_tag_x_as_disabled_control', array('tag' => $foundOther['name'])), $foundOther); } $compiled = $compiler->compileNamedParams($choice, $options, array('selected')); $disabledCode = ''; if ($disabledControls) { $compiled['disabled'] = array(); foreach ($disabledControls as $disabled) { $disabledCode .= $compiler->compileIntoVariable($disabled, $disabledOutputVar, $options, true); $compiled['disabled'][] = '$' . $disabledOutputVar; } } $additionalCode = $disabledCode . '$' . $newOutputVar . '[] = ' . $compiler->buildNamedParamCode($compiled) . ";\n"; if (!empty($compiled['disabled'])) { $additionalCode .= 'unset(' . implode(', ', $compiled['disabled']) . ");\n"; } if (!empty($child['attributes']['displayif'])) { $condition = $compiler->parseConditionExpression($child['attributes']['displayif'], $options); return 'if ' . $condition . "\n{\n" . $additionalCode . "}\n"; } else { return $additionalCode; } } else { if ($compiler->isSegmentNamedTag($child, 'options')) { if (!isset($child['attributes']['source'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('options_tag_must_have_source_attribute'), $child); } $sourceVar = $compiler->compileVarRef($child['attributes']['source'], array_merge($options, array('varEscape' => false))); if (!empty($child['attributes']['raw'])) { $raw = $compiler->parseConditionExpression($child['attributes']['raw'], $options); } else { $raw = 'false'; } return '$' . $newOutputVar . ' = XenForo_Template_Helper_Admin::mergeOptionArrays(' . '$' . $newOutputVar . ', ' . $sourceVar . ', ' . $raw . ");\n"; } else { if ($compiler->isSegmentNamedTag($child, 'optgroup')) { if (!isset($child['attributes']['label'])) { throw $compiler->getNewCompilerException(new XenForo_Phrase('optgroups_must_have_label'), $child); } $label = $compiler->compileAndCombineSegments($child['attributes']['label']); $groupVar = null; // changed by next line $code = $this->_getChoicesCode($child['children'], $compiler, $options, $groupVar); $code .= '$' . $newOutputVar . '[' . $label . '] = $' . $groupVar . ";\n"; $code .= 'unset($' . $groupVar . ");\n"; return $code; } else { return ''; } } } } }