本文整理汇总了PHP中XenForo_Template_Compiler::getUniqueVar方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Template_Compiler::getUniqueVar方法的具体用法?PHP XenForo_Template_Compiler::getUniqueVar怎么用?PHP XenForo_Template_Compiler::getUniqueVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Template_Compiler
的用法示例。
在下文中一共展示了XenForo_Template_Compiler::getUniqueVar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compilePopup
/**
* 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: _getChoicesCode
/**
* 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: compile
/**
* 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()';
}
//.........这里部分代码省略.........
示例4: compile
/**
* 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 '';
}
}