本文整理汇总了PHP中eZTemplateNodeTool::createVariableUnsetNode方法的典型用法代码示例。如果您正苦于以下问题:PHP eZTemplateNodeTool::createVariableUnsetNode方法的具体用法?PHP eZTemplateNodeTool::createVariableUnsetNode怎么用?PHP eZTemplateNodeTool::createVariableUnsetNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZTemplateNodeTool
的用法示例。
在下文中一共展示了eZTemplateNodeTool::createVariableUnsetNode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroySequenceVars
function destroySequenceVars()
{
$fName = $this->Name;
$uniqid = $this->UniqID;
$this->NewNodes[] = eZTemplateNodeTool::createVariableUnsetNode( "${fName}_sequence_array_$uniqid" );
$this->NewNodes[] = eZTemplateNodeTool::createVariableUnsetNode( "${fName}_sequence_var_$uniqid" );
$this->NewNodes[] = eZTemplateNodeTool::createVariableUnsetNode( $this->Parameters['sequence_var'][0][1] );
}
示例2: templateNodeSequenceCreate
function templateNodeSequenceCreate(&$node, $tpl, $parameters, $nameValue, $loopValue)
{
$newNodes = array();
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['loop'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array('text-result' => false), '_array');
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$GLOBALS['eZTemplateSequence-{$nameValue}'] = array( 'iteration' => 0, 'index' => 0, 'loop' => \$_array );\n");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$tpl->setVariable( 'item', \$GLOBALS['eZTemplateSequence-{$nameValue}']['loop'][0], \$namespace );\n");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$tpl->setVariable( 'iteration', 0, \$namespace );\n");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('_array');
return $newNodes;
}
示例3: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
if ($functionName != $this->BlockName) {
return false;
}
$parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node);
if (!isset($parameters['name'])) {
return false;
}
$namespaceValue = false;
$newNodes = array();
if (isset($parameters["name"])) {
$menuIni = eZINI::instance("menu.ini");
$nameData = $parameters["name"];
if (!eZTemplateNodeTool::isConstantElement($nameData)) {
return false;
}
$menuName = eZTemplateNodeTool::elementConstantValue($nameData);
if ($menuIni->hasVariable('SelectedMenu', $menuName)) {
$menuTemplate = $menuIni->variable("SelectedMenu", $menuName);
if ($menuTemplate != null) {
$uriString = "design:menu/{$menuTemplate}.tpl";
$resourceName = "";
$templateName = "";
$resource = $tpl->resourceFor($uriString, $resourceName, $templateName);
$resourceData = $tpl->resourceData($resource, $uriString, $resourceName, $templateName);
$resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
$includeNodes = $resource->templateNodeTransformation($functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue);
if ($includeNodes === false) {
return false;
}
$variableList = array();
foreach (array_keys($parameters) as $parameterName) {
if ($parameterName == 'name') {
continue;
}
$parameterData =& $parameters[$parameterName];
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName));
$variableList[] = $parameterName;
}
$newNodes = array_merge($newNodes, $includeNodes);
foreach ($variableList as $variableName) {
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName));
}
} else {
// to do: not use this function to generate empty code.
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("");
}
} else {
// to do: not use this function to generate empty code.
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("");
}
}
return $newNodes;
}
示例4: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, &$parameters, $privateData)
{
// {while <condition> [sequence <sequence_array> as $<sequence_var>]}
$tpl->WhileCounter++;
$newNodes = array();
$nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
$uniqid = md5($nodePlacement[2]) . "_" . $tpl->WhileCounter;
$loop = new eZTemplateCompiledLoop(eZTemplateWhileFunction::FUNCTION_NAME, $newNodes, $parameters, $nodePlacement, $uniqid, $node, $tpl, $privateData);
$loop->initVars();
// loop header
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("while ( 1 ) // while\n{");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['condition'], $nodePlacement, array('treat-value-as-non-object' => true), "while_cond");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( ! \$while_cond ) break;\n");
$loop->processBody();
// loop footer
$newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("} // end of while\n");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('while_cond');
$loop->cleanup();
return $newNodes;
}
示例5: resourceAcquisitionTransformation
function resourceAcquisitionTransformation( $functionName, &$node, $rule, $inputData,
$outputName, $namespaceValue,
$templateRoot, $viewDir, $viewValue,
$matchFileArray, $acquisitionSpacing,
&$resourceData )
{
$startRoot = '/' . $templateRoot . $viewDir;
$viewFileMatchName = '/' . $templateRoot . '/' . $viewValue . '.tpl';
$startRootLength = strlen( $startRoot );
$matchList = array();
$viewFileMatch = null;
foreach ( $matchFileArray as $matchFile )
{
if ( !isset( $matchFile['template'] ) )
continue;
$path = $matchFile['template'];
if ( substr( $path, 0, $startRootLength ) == $startRoot and
$path[$startRootLength] == '/' )
{
$matchFile['match_part'] = substr( $path, $startRootLength + 1 );
$matchList[] = $matchFile;
}
if ( $path == $viewFileMatchName )
$viewFileMatch = $matchFile;
}
$designKeysName = 'dKeys';
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" .
"{\n" .
" \$resH = \$tpl->resourceHandler( 'design' );\n" .
" \$$designKeysName = \$resH->keys();\n" .
"}", array( 'spacing' => $acquisitionSpacing ) );
if ( isset( $rule["attribute_keys"] ) )
{
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$" . $designKeysName . "Stack ) )\n" .
"{\n" .
" \$" . $designKeysName . "Stack = array();\n" .
"}\n" .
"\$" . $designKeysName . "Stack[] = \$$designKeysName;",
array( 'spacing' => $acquisitionSpacing ) );
foreach ( $rule["attribute_keys"] as $designKey => $attributeKeyArray )
{
$attributeAccessData = array();
$attributeAccessData[] = eZTemplateNodeTool::createVariableElement( $outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE );
foreach ( $attributeKeyArray as $attributeKey )
{
$attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeKey );
}
$newNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false,
array( 'spacing' => 0 ), 'dKey' );
$designKeyText = eZPHPCreator::variableText( $designKey, 0, 0, false );
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $designKeysName . "[$designKeyText] = \$dKey;",
array( 'spacing' => $acquisitionSpacing ) );
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'dKey' );
}
}
$attributeAccess = $rule["attribute_access"];
$hasAttributeAccess = false;
if ( is_array( $attributeAccess ) )
{
$hasAttributeAccess = count( $attributeAccess ) > 0;
$attributeAccessCount = 0;
foreach ( $attributeAccess as $attributeAccessEntries )
{
$attributeAccessData = $inputData;
$spacing = $acquisitionSpacing;
if ( $attributeAccessCount > 1 )
{
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " if ( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) );
$spacing += 4;
}
else if ( $attributeAccessCount > 0 )
{
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) );
$spacing += 4;
}
foreach ( $attributeAccessEntries as $attributeAccessName )
{
// $attributeAccessData[] = eZTemplateNodeTool::createCodePieceNode( "" . ( $resourceData['use-comments'] ? ( "/*TC:" . __LINE__ . "*/" ) : "" ) . "" );
$attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeAccessName );
}
$accessNodes = array();
$accessNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false,
array( 'spacing' => $spacing ), 'attributeAccess' );
$acquisitionNodes = array();
$templateCounter = 0;
$hasAcquisitionNodes = false;
$matchLookupArray = array();
foreach ( $matchList as $matchItem )
{
$tmpAcquisitionNodes = array();
$matchPart = $matchItem['match_part'];
if ( preg_match( "/^(.+)\.tpl$/", $matchPart, $matches ) )
$matchPart = $matches[1];
$code = "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( \$attributeAccess == '$matchPart' )\n{\n";
if ( $templateCounter > 0 )
$code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "" . $code;
//.........这里部分代码省略.........
示例6: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
$tpl->ElseifCounter++;
$newNodes = array();
$nodesToPrepend = array();
$nodesToAppend = array();
$nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
$uniqid = md5($nodePlacement[2]) . "_" . $tpl->ElseifCounter;
$children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// if begins");
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['condition'], $nodePlacement, array('treat-value-as-non-object' => true), 'if_cond');
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$if_cond )\n{");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
if (is_array($children)) {
foreach (array_keys($children) as $childKey) {
$child =& $children[$childKey];
if ($child[0] == eZTemplate::NODE_FUNCTION) {
$childFunctionName =& $child[2];
$childChildren = eZTemplateNodeTool::extractFunctionNodeChildren($child);
$childFunctionArgs =& $child[3];
if ($childFunctionName == 'elseif') {
$compiledElseifCondition = eZTemplateCompiler::processElementTransformationList($tpl, $child, $childFunctionArgs['condition'], $privateData);
$nodesToPrepend[] = eZTemplateNodeTool::createVariableNode(false, $compiledElseifCondition, $nodePlacement, array('text-result' => true), "elseif_cond_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelseif ( \$elseif_cond_{$uniqid} )\n{");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
$nodesToAppend[] = eZTemplateNodeTool::createVariableUnsetNode("elseif_cond_{$uniqid}");
// increment unique elseif counter
$uniqid = md5($nodePlacement[2]) . "_" . ++$tpl->ElseifCounter;
} elseif ($childFunctionName == 'else') {
$newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelse\n{");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
} elseif ($childFunctionName == 'break') {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("break;\n");
} elseif ($childFunctionName == 'continue') {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("continue;\n");
} elseif ($childFunctionName == 'skip') {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$skipDelimiter = true;\ncontinue;\n");
}
// let other functions (ones not listed in the conditions above) be transformed
if (in_array($childFunctionName, array('elseif', 'else', 'break', 'continue', 'skip'))) {
continue;
}
}
$newNodes[] = $child;
}
}
$newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("}");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("unset( \$if_cond );");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// if ends\n");
$newNodes = array_merge($nodesToPrepend, $newNodes, $nodesToAppend);
return $newNodes;
}
示例7: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, &$parameters, $privateData)
{
$undef = $functionName == 'undef';
$newNodes = array();
if (!$parameters) {
if (!$undef) {
// prevent execution of the function in processed mode
return array(eZTemplateNodeTool::createCodePieceNode("// an error occured in {$functionName}"));
}
// {undef} called w/o arguments => destroy all local variables
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// undef all");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$tpl->unsetLocalVariables();");
return $newNodes;
}
$nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
foreach (array_keys($parameters) as $parameterName) {
$parameterData = $parameters[$parameterName];
if ($undef) {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// undef \${$parameterName}");
// generates "$tpl->unsetLocalVariable();"
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue = false, $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL, $parameterName), array('remember_set' => false, 'local-variable' => true));
} else {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// def \${$parameterName}");
// generates "$tpl->setLocalVariable();"
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, $nodePlacement, array('local-variable' => true), array($namespaceValue = false, $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL, $parameterName), $onlyExisting = false, $overwrite = true, false, $rememberSet = false);
}
}
return $newNodes;
}
示例8: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
$newNodes = array();
$namespaceValue = false;
$varName = 'match';
if (!isset($parameters['match'])) {
return false;
}
if (isset($parameters['name'])) {
$nameData = $parameters['name'];
if (!eZTemplateNodeTool::isConstantElement($nameData)) {
return false;
}
$namespaceValue = eZTemplateNodeTool::elementConstantValue($nameData);
}
if (isset($parameters['var'])) {
$varData = $parameters['var'];
if (!eZTemplateNodeTool::isConstantElement($varData)) {
return false;
}
$varName = eZTemplateNodeTool::elementConstantValue($varData);
}
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['match'], false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName));
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['match'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array('variable-name' => 'match', 'text-result' => true), 'match');
// 'text-result' => false ) );
if (isset($parameters['name'])) {
$newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']);
}
$tmpNodes = array();
$children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
$caseNodes = array();
$caseCounter = 1;
if (is_array($children)) {
foreach ($children as $child) {
$childType = $child[0];
if ($childType == eZTemplate::NODE_FUNCTION) {
if ($this->templateNodeCaseTransformation($tpl, $tmpNodes, $caseNodes, $caseCounter, $child, $privateData) === false) {
return false;
}
}
}
}
$newNodes = array_merge($newNodes, $tmpNodes);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("switch ( \$match )\n{");
$newNodes = array_merge($newNodes, $caseNodes);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("}");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('match');
if (isset($parameters['name'])) {
$newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode();
}
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'match'));
return $newNodes;
}
示例9: templateNodeTransformation
function templateNodeTransformation( $functionName, &$node,
$tpl, $parameters, $privateData )
{
switch( $functionName )
{
case $this->SetName:
case $this->DefaultName:
case $this->LetName:
{
$scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE;
if ( isset( $parameters['-scope'] ) )
{
if ( !eZTemplateNodeTool::isConstantElement( $parameters['-scope'] ) )
return false;
$scopeText = eZTemplateNodeTool::elementConstantValue( $parameters['-scope'] );
if ( $scopeText == 'relative' )
$scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE;
else if ( $scopeText == 'root' )
$scope = eZTemplate::NAMESPACE_SCOPE_LOCAL;
else if ( $scopeText == 'global' )
$scope = eZTemplate::NAMESPACE_SCOPE_GLOBAL;
}
$parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node );
$namespaceValue = false;
if ( isset( $parameters['-name'] ) )
{
if ( !eZTemplateNodeTool::isConstantElement( $parameters['-name'] ) )
{
return false;
}
$namespaceValue = eZTemplateNodeTool::elementConstantValue( $parameters['-name'] );
}
$variableList = array();
$setVarNodes = array();
foreach ( array_keys( $parameters ) as $parameterName )
{
if ( $parameterName == '-name' or $parameterName == '-scope' )
{
continue;
}
$parameterData =& $parameters[$parameterName];
$setVarNodes[] = eZTemplateNodeTool::createVariableNode(
false, $parameterData, eZTemplateNodeTool::extractFunctionNodePlacement( $node ),
array(), array( $namespaceValue, $scope, $parameterName ),
( $functionName == $this->SetName ), ( $functionName != $this->DefaultName ),
false, ( $functionName == $this->DefaultName ) );
if ( $functionName == $this->LetName or $functionName == $this->DefaultName )
{
$variableList[] = $parameterName;
}
}
if ( ( $functionName == $this->LetName or $functionName == $this->DefaultName ) and
$namespaceValue )
{
$setVarNodes[] = eZTemplateNodeTool::createNamespaceChangeNode( $namespaceValue );
}
if ( $functionName == $this->LetName or $functionName == $this->DefaultName )
{
$childNodes = eZTemplateNodeTool::extractFunctionNodeChildren( $node );
if ( !is_array( $childNodes ) )
{
$childNodes = array();
}
}
else
{
$childNodes = array();
}
$unsetVarNodes = array();
if ( ( $functionName == $this->LetName or $functionName == $this->DefaultName ) and
$namespaceValue )
{
$unsetVarNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode();
}
if ( $functionName == $this->LetName or $functionName == $this->DefaultName )
{
foreach( $variableList as $parameterName )
{
$unsetVarNodes[] = eZTemplateNodeTool::createVariableUnsetNode( array( $namespaceValue,
eZTemplate::NAMESPACE_SCOPE_RELATIVE,
$parameterName ),
array( 'remember_set' => $functionName == $this->DefaultName ) );
}
}
return array_merge( $setVarNodes, $childNodes, $unsetVarNodes );
} break;
}
//.........这里部分代码省略.........
示例10: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
/*
{foreach <array> as [$keyVar =>] $itemVar
[sequence <array> as $sequenceVar]
[offset <offset>]
[max <max>]
[reverse]
}
*/
$tpl->ForeachCounter++;
$newNodes = array();
$nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
$uniqid = md5($nodePlacement[2]) . "_" . $tpl->ForeachCounter;
$loop = new eZTemplateCompiledLoop(eZTemplateForeachFunction::FUNCTION_NAME, $newNodes, $parameters, $nodePlacement, $uniqid, $node, $tpl, $privateData);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// foreach begins");
$loop->initVars();
$array = "fe_array_{$uniqid}";
$arrayKeys = "fe_array_keys_{$uniqid}";
$nItems = "fe_n_items_{$uniqid}";
$nItemsProcessed = "fe_n_items_processed_{$uniqid}";
$i = "fe_i_{$uniqid}";
$key = "fe_key_{$uniqid}";
$val = "fe_val_{$uniqid}";
$offset = "fe_offset_{$uniqid}";
$max = "fe_max_{$uniqid}";
$reverse = "fe_reverse_{$uniqid}";
$firstVal = "fe_first_val_{$uniqid}";
$lastVal = "fe_last_val_{$uniqid}";
$variableStack = "fe_variable_stack_{$uniqid}";
$namesArray = array($array, $arrayKeys, $nItems, $nItemsProcessed, $i, $key, $val, $offset, $max, $reverse, $firstVal, $lastVal);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !isset( \${$variableStack} ) ) \${$variableStack} = array();");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$" . $variableStack . "[] = compact( '" . implode("', '", $namesArray) . "' );");
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['array'], $nodePlacement, array('text-result' => false), $array);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$arrayKeys} = is_array( \${$array} ) ? array_keys( \${$array} ) : array();");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$nItems} = count( \${$arrayKeys} );");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$nItemsProcessed} = 0;");
// process offset, max and reverse parameters
if (isset($parameters['offset'])) {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['offset'], $nodePlacement, array('text-result' => false), $offset);
} else {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$offset} = 0;");
}
if (isset($parameters['max'])) {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['max'], $nodePlacement, array('text-result' => false), $max);
} else {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$max} = \${$nItems} - \${$offset};");
}
if (isset($parameters['reverse'])) {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['reverse'], $nodePlacement, array('text-result' => false), $reverse);
} else {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$reverse} = false;");
}
// fix definitely incorrect offset
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \${$offset} < 0 || \${$offset} >= \${$nItems} )\n{\n" . " \${$offset} = ( \${$offset} < 0 ) ? 0 : \${$nItems};\n" . " if ( \${$nItems} || \${$offset} < 0 )\n {\n" . " eZDebug::writeWarning(\"Invalid 'offset' parameter specified: '\${$offset}'. Array count: \${$nItems}\"); \n}\n}");
// fix definitely incorrect max
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \${$max} < 0 || \${$offset} + \${$max} > \${$nItems} )\n{\n" . " if ( \${$max} < 0 )\n eZDebug::writeWarning(\"Invalid 'max' parameter specified: \${$max}\");\n" . " \${$max} = \${$nItems} - \${$offset};\n}");
// initialize first and last indexes to iterate between them
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \${$reverse} )\n" . "{\n" . " \${$firstVal} = \${$nItems} - 1 - \${$offset};\n" . " \${$lastVal} = 0;\n" . "}\n" . "else\n" . "{\n" . " \${$firstVal} = \${$offset};\n" . " \${$lastVal} = \${$nItems} - 1;\n" . "}");
// generate loop header
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// foreach");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("for ( \${$i} = \${$firstVal}; " . "\${$nItemsProcessed} < \${$max} && ( \${$reverse} ? \${$i} >= \${$lastVal} : \${$i} <= \${$lastVal} ); " . "\${$reverse} ? \${$i}-- : \${$i}++ )\n" . "{");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$key} = \${$arrayKeys}[\${$i}];");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$val} = \${$array}[\${$key}];");
// export $itemVar
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, "{$val}", $nodePlacement, array(), $parameters['item_var'][0][1], false, true, true);
// export $keyVar (if specified)
if (isset($parameters['key_var'])) {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, "{$key}", $nodePlacement, array(), $parameters['key_var'][0][1], false, true, true);
}
$loop->processBody();
// generate loop footer
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$nItemsProcessed}++;");
$newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("} // foreach");
$loop->cleanup();
// unset the loop variables
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( count( \${$variableStack} ) ) extract( array_pop( \${$variableStack} ) );\n");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("else\n{\n");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($array);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($arrayKeys);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($nItems);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($nItemsProcessed);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($i);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($key);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($val);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($offset);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($max);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($reverse);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($firstVal);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($lastVal);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($variableStack);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// foreach ends");
return $newNodes;
}
示例11: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
$useLastValue = false;
if (isset($parameters['last-value']) and !eZTemplateNodeTool::isConstantElement($parameters['last-value'])) {
return false;
}
if (isset($parameters['name']) and !eZTemplateNodeTool::isConstantElement($parameters['name'])) {
return false;
}
if (isset($parameters['var']) and !eZTemplateNodeTool::isConstantElement($parameters['var'])) {
return false;
}
if (isset($parameters['reverse']) and !eZTemplateNodeTool::isConstantElement($parameters['reverse'])) {
return false;
}
$varName = false;
if (isset($parameters['var'])) {
$varName = eZTemplateNodeTool::elementConstantValue($parameters['var']);
}
if (isset($parameters['last-value'])) {
$useLastValue = (bool) eZTemplateNodeTool::elementConstantValue($parameters['last-value']);
}
if (!$varName) {
$useLastValue = false;
}
$reverseLoop = false;
if (isset($parameters['reverse'])) {
$reverseLoop = eZTemplateNodeTool::elementConstantValue($parameters['reverse']);
}
$useLoop = isset($parameters['loop']);
$allowLoop = true;
$newNodes = array();
$maxText = "false";
$useMax = false;
$maxPopText = false;
if (isset($parameters['max'])) {
if (eZTemplateNodeTool::isConstantElement($parameters['max'])) {
$maxValue = eZTemplateNodeTool::elementConstantValue($parameters['max']);
if ($maxValue > 0) {
$maxText = eZPHPCreator::variableText($maxValue);
$useMax = true;
} else {
return array(eZTemplateNodeTool::createTextNode(''));
}
} else {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['max'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'max');
$maxText = "\$max";
$maxPopText = ", \$max";
$useMax = true;
}
}
// Controls whether the 'if' statement with brackets is added
$useShow = false;
// Controls whether main nodes are handled, also controls delimiter and filters
$useMain = true;
// Controls wether else nodes are handled
$useElse = false;
$spacing = 0;
if (isset($parameters['show'])) {
if (eZTemplateNodeTool::isConstantElement($parameters['show'])) {
$showValue = eZTemplateNodeTool::elementConstantValue($parameters['show']);
if ($showValue) {
$useMain = true;
$useElse = false;
$useShow = false;
} else {
$useMain = false;
$useElse = true;
$useShow = false;
}
$newNodes[] = eZTemplateNodeTool::createTextNode('');
} else {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['show'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'show');
$spacing = 4;
$useElse = true;
$useShow = true;
}
}
$children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
if ($useShow) {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$show )\n{\n");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show');
}
if (isset($parameters['name']) and !$useLoop) {
$newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']);
}
$mainNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'before', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else')), 'filter' => array(array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('delimiter', 'section-exclude', 'section-include')))))));
$delimiterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'delimiter')))));
$filterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('section-exclude', 'section-include'))))));
$delimiterNode = false;
if (count($delimiterNodes) > 0) {
$delimiterNode = $delimiterNodes[0];
}
if ($useMain) {
// Avoid transformation if the nodes will not be used, saves time
$mainNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $mainNodes, $privateData);
}
if ($useLoop and $useMain) {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['loop'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'loopItem');
//.........这里部分代码省略.........
示例12: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
// {for <first_val> to <last_val> as $<loop_var> [sequence <sequence_array> as $<sequence_var>]}
$newNodes = array();
$tpl->ForCounter++;
$nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
$uniqid = md5($nodePlacement[2]) . "_" . $tpl->ForCounter;
$loop = new eZTemplateCompiledLoop(eZTemplateForFunction::FUNCTION_NAME, $newNodes, $parameters, $nodePlacement, $uniqid, $node, $tpl, $privateData);
$variableStack = "for_variable_stack_{$uniqid}";
$namesArray = array("for_firstval_{$uniqid}", "for_lastval_{$uniqid}", "for_i_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// for begins");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !isset( \${$variableStack} ) ) \${$variableStack} = array();");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$" . $variableStack . "[] = compact( '" . implode("', '", $namesArray) . "' );");
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['first_val'], $nodePlacement, array('treat-value-as-non-object' => true), "for_firstval_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['last_val'], $nodePlacement, array('treat-value-as-non-object' => true), "for_lastval_{$uniqid}");
$loop->initVars();
// loop header
$modifyLoopCounterCode = "\$for_firstval_{$uniqid} < \$for_lastval_{$uniqid} ? \$for_i_{$uniqid}++ : \$for_i_{$uniqid}--";
// . ";\n";
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("for ( \$for_i_{$uniqid} = \$for_firstval_{$uniqid} ; ; {$modifyLoopCounterCode} )\n{");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
// Check for index
$indexArray = isset($parameters['loop_var'][0][1]) ? $parameters['loop_var'][0][1] : array("", 2, "default_index_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, "for_i_{$uniqid}", $nodePlacement, array('text-result' => true), $indexArray, false, true, true);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !( \$for_firstval_{$uniqid} < \$for_lastval_{$uniqid} ? " . "\$for_i_{$uniqid} <= \$for_lastval_{$uniqid} : " . "\$for_i_{$uniqid} >= \$for_lastval_{$uniqid} ) )\n" . " break;\n");
$loop->processBody();
// loop footer
$newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("} // for");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( count( \${$variableStack} ) ) extract( array_pop( \${$variableStack} ) );\n");
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("else\n{\n");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($indexArray);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode("for_firstval_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode("for_lastval_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode("for_i_{$uniqid}");
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($variableStack);
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n");
$loop->cleanup();
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("// for ends\n");
return $newNodes;
}