/** * Gets the standard data out of a list of segments. Data will be pulled from tags * in that list and their attributes only. * * @param XenForo_Template_Compiler * @param array List of segments * @param array An optional list of additional tags that are allowed * * @return array Keys are standard data types that were found */ protected function _getStandardAdminTagData(XenForo_Template_Compiler $compiler, array $segments, array $extraAllowedTags = array()) { $segments = $compiler->prepareSegmentsForIteration($segments); $output = array(); $foundContent = false; foreach ($segments as $segment) { if (is_string($segment)) { if (trim($segment) !== '') { $foundContent = true; } continue; } else { if (!isset($segment['type']) || $segment['type'] != 'TAG') { $foundContent = true; continue; } } switch ($segment['name']) { case 'label': $attributes = $segment['attributes']; if (isset($attributes['hidden'])) { $output['labelHidden'] = $attributes['hidden']; } if (isset($attributes['hint'])) { $output['hint'] = $attributes['hint']; } $output['label'] = $segment['children']; break; case 'hint': case 'explain': case 'html': $output[$segment['name']] = $segment['children']; break; default: if (!$extraAllowedTags || !in_array($segment['name'], $extraAllowedTags)) { // all other tags are "content" tags $foundContent = true; } } } if ($output && $foundContent) { // found some known tags, some content -- error throw $compiler->getNewCompilerException(new XenForo_Phrase('found_unexpected_content_within_an_admin_control_tag')); } else { if ($foundContent) { // content only -- treat it as HTML tag $output = array('html' => $segments); } } return $output; }
/** * 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); }