Пример #1
0
 /**
  * Helper to compile a popup statically. Used to allow list rows to modify
  * the compilation behavior.
  *
  * @param XenForo_Template_Compiler $compiler
  * @param array $attributes
  * @param array $children Child tags
  * @param array $options Compiler option
  * @param string $wrapTag The HTML tag to wrap with (probably div or li)
  * @param string $extraMenuClass An extra menu class (or multiple to add)
  *
  * @return XenForo_Compiler_Statement_Raw
  */
 public static function compilePopup(XenForo_Template_Compiler $compiler, array $attributes, array $children, array $options, $wrapTag, $extraMenuClass = '')
 {
     if (!isset($attributes['title'])) {
         throw $compiler->getNewCompilerException(new XenForo_Phrase('popups_must_specify_title'));
     }
     $choiceOutputVar = $compiler->getUniqueVar();
     $choicesCode = self::compilePopupChildren($choiceOutputVar, $children, $compiler, $options);
     $controlData = $compiler->getNamedParamsAsPhpCode($attributes, $options);
     $statement = $compiler->getNewRawStatement();
     $statement->addStatement('$' . $choiceOutputVar . " = array();\n");
     $statement->addStatement($choicesCode);
     $statement->addStatement('$' . $compiler->getOutputVar() . ' .= XenForo_Template_Helper_Admin::popup(' . $controlData . ', $' . $choiceOutputVar . ', \'' . $compiler->escapeSingleQuotedString($wrapTag) . '\', \'' . $compiler->escapeSingleQuotedString($extraMenuClass) . "');\n");
     $statement->addStatement('unset($' . $choiceOutputVar . ");\n");
     return $statement;
 }
Пример #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;
 }
Пример #4
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' => '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 '';
     }
 }