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;
 }
 function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
 {
     $ini = eZINI::instance();
     $children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
     if ($ini->variable('TemplateSettings', 'TemplateCache') != 'enabled') {
         return $children;
     }
     $functionPlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
     $placementKeyString = eZTemplateCacheBlock::placementString($functionPlacement);
     $newNodes = array();
     $ignoreContentExpiry = false;
     if (isset($parameters['expiry'])) {
         if (eZTemplateNodeTool::isConstantElement($parameters['expiry'])) {
             $expiryValue = eZTemplateNodeTool::elementConstantValue($parameters['expiry']);
             $ttlCode = $expiryValue > 0 ? eZPHPCreator::variableText($expiryValue, 0, 0, false) : 'null';
         } else {
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['expiry'], false, array(), 'localExpiry');
             $ttlCode = "( \$localExpiry > 0 ? \$localExpiry : null )";
         }
     } else {
         $ttlCode = eZPHPCreator::variableText(self::DEFAULT_TTL, 0, 0, false);
     }
     if (isset($parameters['ignore_content_expiry'])) {
         $ignoreContentExpiry = eZTemplateNodeTool::elementConstantValue($parameters['ignore_content_expiry']);
     }
     $keysData = false;
     $hasKeys = false;
     $subtreeExpiryData = null;
     $subtreeValue = null;
     if (isset($parameters['keys'])) {
         $keysData = $parameters['keys'];
         $hasKeys = true;
     }
     if (isset($parameters['subtree_expiry'])) {
         $subtreeExpiryData = $parameters['subtree_expiry'];
         if (!eZTemplateNodeTool::isConstantElement($subtreeExpiryData)) {
             $hasKeys = true;
         } else {
             $subtreeValue = eZTemplateNodeTool::elementConstantValue($subtreeExpiryData);
         }
         $ignoreContentExpiry = true;
     }
     $accessName = false;
     if (isset($GLOBALS['eZCurrentAccess']['name'])) {
         $accessName = $GLOBALS['eZCurrentAccess']['name'];
     }
     if ($hasKeys) {
         $placementKeyStringText = eZPHPCreator::variableText($placementKeyString, 0, 0, false);
         $accessNameText = eZPHPCreator::variableText($accessName, 0, 0, false);
         $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $keysData, false, array(), 'cacheKeys');
         $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $subtreeExpiryData, false, array(), 'subtreeExpiry');
         $code = "\$cacheKeys = array( \$cacheKeys, {$placementKeyStringText}, {$accessNameText} );\n";
         $cachePathText = "\$cachePath";
     } else {
         $nodeID = $subtreeValue ? eZTemplateCacheBlock::decodeNodeID($subtreeValue) : false;
         $cachePath = eZTemplateCacheBlock::cachePath(eZTemplateCacheBlock::keyString(array($placementKeyString, $accessName)), $nodeID);
         $code = "";
         $cachePathText = eZPHPCreator::variableText($cachePath, 0, 0, false);
     }
     $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code);
     $code = '';
     $codePlacementHash = md5($placementKeyString);
     if ($hasKeys) {
         $code .= "list(\$cacheHandler_{$codePlacementHash}, \$contentData) =\n  eZTemplateCacheBlock::retrieve( \$cacheKeys, \$subtreeExpiry, {$ttlCode}, " . ($ignoreContentExpiry ? "false" : "true") . " );\n";
     } else {
         $nodeIDText = var_export($nodeID, true);
         $code .= "list(\$cacheHandler_{$codePlacementHash}, \$contentData) =\n  eZTemplateCacheBlock::handle( {$cachePathText}, {$nodeIDText}, {$ttlCode}, " . ($ignoreContentExpiry ? "false" : "true") . " );\n";
     }
     $code .= "if ( !( \$contentData instanceof eZClusterFileFailure ) )\n" . "{\n";
     $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => 0));
     $newNodes[] = eZTemplateNodeTool::createWriteToOutputVariableNode('contentData', array('spacing' => 4));
     $newNodes[] = eZTemplateNodeTool::createCodePieceNode("    unset( \$contentData );\n" . "}\n" . "else\n" . "{\n" . "    unset( \$contentData );");
     $newNodes[] = eZTemplateNodeTool::createOutputVariableIncreaseNode(array('spacing' => 4));
     $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4);
     $newNodes = array_merge($newNodes, $children);
     $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4);
     $newNodes[] = eZTemplateNodeTool::createAssignFromOutputVariableNode('cachedText', array('spacing' => 4));
     $code = "\$cacheHandler_{$codePlacementHash}->storeCache( array( 'scope' => 'template-block', 'binarydata' => \$cachedText ) );\n";
     $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => 4));
     $newNodes[] = eZTemplateNodeTool::createOutputVariableDecreaseNode(array('spacing' => 4));
     $newNodes[] = eZTemplateNodeTool::createWriteToOutputVariableNode('cachedText', array('spacing' => 4));
     $newNodes[] = eZTemplateNodeTool::createCodePieceNode("    unset( \$cachedText, \$cacheHandler_{$codePlacementHash} );\n}\n");
     return $newNodes;
 }
    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;
                    $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $spacing ) );

                    $defaultMatchSpacing = $spacing;
                    $useArrayLookup = false;
                    $addFileResource = true;
                    if ( isset( $matchItem['custom_match'] ) )
                    {
                        $customSpacing = $spacing + 4;
                        $defaultMatchSpacing = $spacing + 4;
                        $matchCount = 0;
                        foreach ( $matchItem['custom_match'] as $customMatch )
                        {
                            $matchConditionCount = count( $customMatch['conditions'] );
                            $code = '';
                            if ( $matchCount > 0 )
                            {
                                $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "";
                            }
                            if ( $matchConditionCount > 0 )
                            {
                                if ( $matchCount > 0 )
                                    $code .= " ";
                                $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( ";
                            }
                            $ifLength = strlen( $code );
                            $conditionCount = 0;
                            if ( isset( $customMatch['conditions'] ) )
                            {
                                foreach ( $customMatch['conditions'] as $conditionName => $conditionValue )
                                {
                                    if ( $conditionCount > 0 )
                                        $code .= " and\n" . str_repeat( ' ', $ifLength );
                                    $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 );
                                    $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 );

                                    $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and ";
                                    if ( $conditionNameText == '"url_alias"' )
                                    {
                                        $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )";
                                    }
                                    else
                                    {
                                        $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " .
                                                 "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " .
                                                 "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )";
                                    }
                                    ++$conditionCount;
                                }
                            }
                            if ( $matchConditionCount > 0 )
                            {
                                $code .= " )\n";
                            }
                            if ( $matchConditionCount > 0 or $matchCount > 0 )
                            {
                                $code .= "{";
                            }
                            $matchFile = $customMatch['match_file'];
                            $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $customSpacing ) );
                            $hasAcquisitionNodes = true;
                            // If $matchFile is an array we cannot create a transformation for this entry
                            if ( is_array( $matchFile ) )
                                return false;
                            $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
                                                                                                     $matchFile, $matchFile,
                                                                                                     eZTemplate::RESOURCE_FETCH, false,
                                                                                                     $node[4], array( 'spacing' => $customSpacing + 4 ),
                                                                                                     $rule['namespace'] );
                            if ( $matchConditionCount > 0 or $matchCount > 0 )
                            {
                                $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) );
                            }
                            ++$matchCount;
                            if ( $matchConditionCount == 0 )
                            {
                                $addFileResource = false;
                                break;
                            }
                        }
                        if ( $addFileResource )
                            $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " \n{", array( 'spacing' => $customSpacing ) );
                    }
                    else
                    {
                        $matchFile = $matchItem['base_dir'] . $matchItem['template'];
                        $matchLookupArray[$matchPart] = $matchFile;
                        $useArrayLookup = true;
                    }

                    if ( !$useArrayLookup )
                    {
                        if ( $addFileResource )
                        {
                            $matchFile = $matchItem['base_dir'] . $matchItem['template'];
                            $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
                                                                                                        $matchFile, $matchFile,
                                                                                                        eZTemplate::RESOURCE_FETCH, false,
                                                                                                        $node[4], array( 'spacing' => $defaultMatchSpacing + 4 ),
                                                                                                        $rule['namespace'] );
                            $hasAcquisitionNodes = true;
                            if ( isset( $matchItem['custom_match'] ) )
                                $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) );
                        }
                        ++$templateCounter;
                        $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) );
                        $acquisitionNodes = array_merge( $acquisitionNodes, $tmpAcquisitionNodes );
                    }
                }

                if ( count( $matchLookupArray ) > 0 )
                {
                    $newNodes = array_merge( $newNodes, $accessNodes );
                    $accessNodes = array();
                    // If $matchFile is an array we cannot create a transformation for this entry
                    if ( is_array( $matchLookupArray ) )
                        return false;
                    $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
                                                                                     $matchLookupArray, false,
                                                                                     eZTemplate::RESOURCE_FETCH, false,
                                                                                     $node[4], array( 'spacing' => $spacing ),
                                                                                     $rule['namespace'], 'attributeAccess' );
                    if ( $hasAcquisitionNodes )
                    {
                        $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $spacing ) );
                        $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
                    }
                }
                if ( $hasAcquisitionNodes )
                {
                    $newNodes = array_merge( $newNodes, $accessNodes, $acquisitionNodes );

                    if ( $attributeAccessCount > 0 )
                    {
                        $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) );
                    }
                    ++$attributeAccessCount;
                }
                else if ( count( $matchLookupArray ) == 0 )
                {
                    $newNodes[] = eZTemplateNodeTool::createErrorNode( "Failed to load template",
                                                                       $functionName,
                                                                       eZTemplateNodeTool::extractFunctionNodePlacement( $node ),
                                                                       array( 'spacing' => $acquisitionSpacing ) );
                }
                if ( count( $matchLookupArray ) > 0 and $hasAcquisitionNodes )
                {
                    $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
                    $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) );
                }
            }
        }
        if ( $viewFileMatch !== null )
        {
            $mainSpacing = 0;
            if ( $hasAttributeAccess )
            {
                $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{\n", array( 'spacing' => $acquisitionSpacing ) );
                $mainSpacing = 4;
            }
            $templateCounter = 0;


            $addFileResource = true;
            if ( isset( $viewFileMatch['custom_match'] ) )
            {
                $spacing = $mainSpacing + 4;
                $matchCount = 0;
                foreach ( $viewFileMatch['custom_match'] as $customMatch )
                {
                    $matchConditionCount = count( $customMatch['conditions'] );
                    $code = '';
                    if ( $matchCount > 0 )
                    {
                        $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "";
                    }
                    if ( $matchConditionCount > 0 )
                    {
                        if ( $matchCount > 0 )
                            $code .= " ";
                        $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( ";

                        $ifLength = strlen( $code );
                        $conditionCount = 0;

                        if ( is_array( $customMatch['conditions'] ) )
                        {
                            foreach ( $customMatch['conditions'] as $conditionName => $conditionValue )
                            {
                                if ( $conditionCount > 0 )
                                    $code .= " and\n" . str_repeat( ' ', $ifLength );
                                $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 );
                                $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 );

                                $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and ";
                                if ( $conditionNameText == '"url_alias"' )
                                {
                                    $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )";
                                }
                                else
                                {
                                    $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " .
                                             "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " .
                                             "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )";
                                }
                                ++$conditionCount;
                            }
                        }
                        $code .= " )\n";
                    }
                    if ( $matchConditionCount > 0 or $matchCount > 0 )
                    {
                        $code .= "{";
                    }
                    $matchFile = $customMatch['match_file'];
                    $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $acquisitionSpacing ) );
                    // If $matchFile is an array we cannot create a transformation for this entry
                    if ( is_array( $matchFile ) )
                        return false;
                    $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
                                                                                     $matchFile, $matchFile,
                                                                                     eZTemplate::RESOURCE_FETCH, false,
                                                                                     $node[4], array( 'spacing' => $spacing ),
                                                                                     $rule['namespace'] );
                    if ( $matchConditionCount > 0 or $matchCount > 0 )
                    {
                        $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) );
                    }
                    ++$matchCount;
                    if ( $matchConditionCount == 0 )
                    {
                        if ( $matchCount > 0 )
                            $addFileResource = false;
                        break;
                    }
                }
                if ( $addFileResource )
                    $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $acquisitionSpacing ) );
            }
            if ( $addFileResource )
            {
                $file = $viewFileMatch['base_dir'] . $viewFileMatch['template'];
                $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
                                                                                 $file, $file,
                                                                                 eZTemplate::RESOURCE_FETCH, false,
                                                                                 $node[4], array( 'spacing' => $mainSpacing ),
                                                                                 $rule['namespace'] );
            }
            if ( isset( $viewFileMatch['custom_match'] ) and $addFileResource )
                $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) );

            if ( $hasAttributeAccess )
                $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}\n", array( 'spacing' => $acquisitionSpacing ) );
        }
        if ( isset( $rule["attribute_keys"] ) )
        {
            $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$designKeysName = array_pop( \$" . $designKeysName . "Stack );",
                                                                   array( 'spacing' => $acquisitionSpacing ) );
        }
        return $newNodes;
    }
 function templateNodeCaseTransformation($tpl, &$newNodes, &$caseNodes, &$caseCounter, &$node, $privateData)
 {
     if ($node[2] == 'case') {
         if (is_array($node[3]) && count($node[3])) {
             if (isset($node[3]['match'])) {
                 $match = $node[3]['match'];
                 $match = eZTemplateCompiler::processElementTransformationList($tpl, $node, $match, $privateData);
                 $dynamicCase = false;
                 if (eZTemplateNodeTool::isConstantElement($match)) {
                     $matchValue = eZTemplateNodeTool::elementConstantValue($match);
                     $caseText = eZPHPCreator::variableText($matchValue, 0, 0, false);
                 } else {
                     $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $match, false, array(), 'case' . $caseCounter);
                     $caseText = "\$case" . $caseCounter;
                     ++$caseCounter;
                     $dynamicCase = true;
                 }
                 $caseNodes[] = eZTemplateNodeTool::createCodePieceNode("    case {$caseText}:\n    {");
                 if ($dynamicCase) {
                     $caseNodes[] = eZTemplateNodeTool::createCodePieceNode("        unset( {$caseText} );");
                 }
             } else {
                 if (isset($node[3]['in'])) {
                     return false;
                 }
             }
         } else {
             $caseNodes[] = eZTemplateNodeTool::createCodePieceNode("    default:\n    {");
         }
         $children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
         if ($children === false) {
             $children = array();
         } else {
             $children = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $children, $privateData);
         }
         $caseNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(8);
         $caseNodes = array_merge($caseNodes, $children);
         $caseNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(8);
         $caseNodes[] = eZTemplateNodeTool::createCodePieceNode("    } break;");
     }
 }
 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;
 }
 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;
 }
Esempio n. 7
0
 function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
 {
     if ($functionName == $this->BlockName or $functionName == $this->AppendBlockName) {
         if (!isset($parameters['variable'])) {
             return false;
         }
         $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;
                     }
                 }
             }
         }
         $name = '';
         if (isset($parameters['name'])) {
             if (!eZTemplateNodeTool::isConstantElement($parameters['name'])) {
                 return false;
             }
             $name = eZTemplateNodeTool::elementConstantValue($parameters['name']);
         }
         $variableName = eZTemplateNodeTool::elementConstantValue($parameters['variable']);
         $newNodes = array();
         $children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
         $newNodes[] = eZTemplateNodeTool::createOutputVariableIncreaseNode();
         $newNodes = array_merge($newNodes, $children);
         $newNodes[] = eZTemplateNodeTool::createAssignFromOutputVariableNode('blockText');
         if ($functionName == $this->AppendBlockName) {
             $data = array(eZTemplateNodeTool::createVariableElement($variableName, $name, $scope));
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $data, false, array(), 'blockData');
             // This block checks whether the append-block variable is an array or not.
             // TODO: This is a temporary solution and should also check whether the template variable exists.
             // This new solution requires probably writing the createVariableElement and createVariableNode your self.
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_null ( \$blockData ) ) \$blockData = array();");
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array ( \$blockData ) ) \$blockData[] = \$blockText;");
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("else eZDebug::writeError( \"Variable '{$variableName}' is already in use.\" );");
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'blockData', false, array(), array($name, $scope, $variableName), false, true, true);
             $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('blockData');
         } else {
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'blockText', false, array(), array($name, $scope, $variableName), false, true, true);
         }
         $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('blockText');
         $newNodes[] = eZTemplateNodeTool::createOutputVariableDecreaseNode();
         return $newNodes;
     } else {
         if ($functionName == $this->OnceName) {
             $functionPlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node);
             $key = $this->placementKey($functionPlacement);
             $newNodes = array();
             if ($key !== false) {
                 $keyText = eZPHPCreator::variableText($key, 0, 0, false);
                 $placementText = eZPHPCreator::variableText($functionPlacement, 0, 0, false);
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !isset( \$GLOBALS['eZTemplateRunOnceKeys'][{$keyText}] ) )\n" . "{\n" . "    \$GLOBALS['eZTemplateRunOnceKeys'][{$keyText}] = {$placementText};");
                 $children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
                 $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4);
                 $newNodes = array_merge($newNodes, $children);
                 $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4);
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}");
             }
             return $newNodes;
         }
     }
     return false;
 }
Esempio n. 8
0
 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');
         $hasSequence = false;
         if (isset($parameters['sequence'])) {
             $sequenceParameter = $parameters['sequence'];
             $hasSequence = true;
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $sequenceParameter, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'sequence');
         }
         if (isset($parameters['name'])) {
             $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']);
         }
         $code = "if ( !isset( \$sectionStack ) )\n" . "    \$sectionStack = array();\n";
         $variableValuePushText = '';
         $variableValuePopText = '';
         if ($varName) {
             $code .= "\$variableValue = new eZTemplateSectionIterator();\n" . "\$lastVariableValue = false;\n";
             $variableValuePushText = "&\$variableValue, ";
             $variableValuePopText = "\$variableValue, ";
         }
         $code .= "\$index = 0;\n" . "\$currentIndex = 1;\n";
         $arrayCode = '';
         $numericCode = '';
         $stringCode = '';
         $offsetText = '0';
         if (isset($parameters['offset'])) {
             $offsetParameter = $parameters['offset'];
             if (eZTemplateNodeTool::isConstantElement($offsetParameter)) {
                 $iterationValue = (int) eZTemplateNodeTool::elementConstantValue($offsetParameter);
                 if ($iterationValue > 0) {
                     $arrayCode = "    \$loopKeys = array_splice( \$loopKeys, {$iterationValue} );\n";
                 }
                 $offsetText = $iterationValue;
             } else {
                 $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $offsetParameter, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'offset');
                 $arrayCode = "    if ( \$offset > 0 )\n" . "        \$loopKeys = array_splice( \$loopKeys, \$offset );\n";
                 $offsetText = "\$offset";
             }
         }
         // Initialization for array
         $code .= "if ( is_array( \$loopItem ) )\n{\n" . "    \$loopKeys = array_keys( \$loopItem );\n";
         if ($reverseLoop) {
             $code .= "    \$loopKeys = array_reverse( \$loopKeys );\n";
         }
         $code .= $arrayCode;
         $code .= "    \$loopCount = count( \$loopKeys );\n";
         $code .= "}\n";
         // Initialization for numeric
         $code .= "else if ( is_numeric( \$loopItem ) )\n{\n" . "    \$loopKeys = false;\n" . $numericCode . "    if ( \$loopItem < 0 )\n" . "        \$loopCountValue = -\$loopItem;\n" . "    else\n" . "        \$loopCountValue = \$loopItem;\n" . "    \$loopCount = \$loopCountValue - {$offsetText};\n" . "}\n";
         // Initialization for string
         $code .= "else if ( is_string( \$loopItem ) )\n{\n" . "    \$loopKeys = false;\n" . $stringCode . "    \$loopCount = strlen( \$loopItem ) - {$offsetText};\n" . "}\n";
         // Fallback for no item
         $code .= "else\n{\n" . "    \$loopKeys = false;\n" . "    \$loopCount = 0;\n" . "}";
         // Initialization end
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code);
         $code = "while ( \$index < \$loopCount )\n" . "{\n";
         if ($useMax) {
             $code .= "    if ( \$currentIndex > {$maxText} )\n" . "        break;\n" . "    unset( \$item );\n";
         }
         // Iterator check for array
         $code .= "    if ( is_array( \$loopItem ) )\n" . "    {\n" . "        \$loopKey = \$loopKeys[\$index];\n" . "        unset( \$item );\n" . "        \$item = \$loopItem[\$loopKey];\n" . "    }\n";
         // Iterator check for numeric
         $code .= "    else if ( is_numeric( \$loopItem ) )\n" . "    {\n" . "        unset( \$item );\n";
         if ($reverseLoop) {
             $code .= "        \$item = \$loopCountValue - \$index - {$offsetText};\n";
         } else {
             $code .= "        \$item = \$index + {$offsetText} + 1;\n";
         }
         $code .= "        if ( \$loopItem < 0 )\n" . "            \$item = -\$item;\n";
         if ($reverseLoop) {
             $code .= "        \$loopKey = \$loopCountValue - \$index - {$offsetText} - 1;\n";
         } else {
             $code .= "        \$loopKey = \$index + {$offsetText};\n";
         }
         $code .= "    }\n";
         // Iterator check for string
         $code .= "    else if ( is_string( \$loopItem ) )\n" . "    {\n" . "        unset( \$item );\n";
         if ($reverseLoop) {
             $code .= "        \$loopKey = \$loopCount - \$index - {$offsetText} + 1;\n";
         } else {
             $code .= "        \$loopKey = \$index + {$offsetText};\n";
         }
         $code .= "        \$item = \$loopItem[\$loopKey];\n" . "    }\n";
         // Iterator check end
         $code .= "    unset( \$last );\n" . "    \$last = false;\n";
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code);
         $code = '';
         if ($useLastValue) {
             $code .= "    if ( \$currentIndex > 1 )\n" . "    {\n" . "        \$last = \$lastVariableValue;\n" . "        \$variableValue = new eZTemplateSectionIterator();\n" . "    }\n";
         }
         if ($varName) {
             $code .= "    \$variableValue->setIteratorValues( \$item, \$loopKey, \$currentIndex - 1, \$currentIndex, false, \$last );";
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code);
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'variableValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName), false, true, true);
         } else {
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'loopKey', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'key'), false, true, true);
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'item', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'item'), false, true, true);
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$currentIndexInc = \$currentIndex - 1;\n");
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'currentIndexInc', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'index'), false, true, true);
             $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'currentIndex', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'number'), false, true, true);
         }
         $mainSpacing = 0;
         $hasFilter = false;
         if (count($filterNodes) > 0) {
             $newFilterNodes = array();
             $matchValue = true;
             $hasDynamicFilter = false;
             foreach ($filterNodes as $filterNode) {
                 $filterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($filterNode);
                 if (!isset($filterParameters['match'])) {
                     continue;
                 }
                 $hasFilter = true;
                 $filterParameterMatch = $filterParameters['match'];
                 $filterParameterMatch = eZTemplateCompiler::processElementTransformationList($tpl, $filterNode, $filterParameterMatch, $privateData);
                 if (eZTemplateNodeTool::isConstantElement($filterParameterMatch)) {
                     $matchValue = eZTemplateNodeTool::elementConstantValue($filterParameterMatch);
                     if (eZTemplateNodeTool::extractFunctionNodeName($filterNode) == 'section-exclude') {
                         if ($matchValue) {
                             $matchValue = false;
                         }
                     } else {
                         if ($matchValue) {
                             $matchValue = true;
                         }
                     }
                     $newFilterNodes = array();
                     $hasDynamicFilter = false;
                 } else {
                     $newFilterNodes[] = eZTemplateNodeTool::createVariableNode(false, $filterParameterMatch, eZTemplateNodeTool::extractFunctionNodePlacement($filterNode), array('spacing' => 4), 'tmpMatchValue');
                     if (eZTemplateNodeTool::extractFunctionNodeName($filterNode) == 'section-exclude') {
                         $newFilterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$tmpMatchValue )\n    \$matchValue = false;", array('spacing' => 4));
                     } else {
                         $newFilterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$tmpMatchValue )\n    \$matchValue = true;", array('spacing' => 4));
                     }
                     $hasDynamicFilter = true;
                 }
             }
             if ($hasFilter) {
                 $mainSpacing += 4;
                 $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $matchValue, eZTemplateNodeTool::extractFunctionNodePlacement($filterNode), array('spacing' => 4), 'matchValue');
                 if ($hasDynamicFilter) {
                     $newNodes = array_merge($newNodes, $newFilterNodes);
                 }
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$matchValue )\n{\n", array('spacing' => 4));
             }
         }
         $sequencePopText = '';
         if ($hasSequence) {
             $sequencePopText = ", \$sequence";
             if ($varName) {
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array( \$sequence ) )\n" . "{\n" . "    \$sequenceValue = array_shift( \$sequence );\n" . "    \$variableValue->setSequence( \$sequenceValue );\n" . "    \$sequence[] = \$sequenceValue;\n" . "    unset( \$sequenceValue );\n" . "}", array('spacing' => $mainSpacing + 4));
                 $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'variableValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName), false, true, true);
             } else {
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array( \$sequence ) )\n" . "{\n" . "    \$sequenceValue = array_shift( \$sequence );\n", array('spacing' => $mainSpacing + 4));
                 $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'sequenceValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => $mainSpacing + 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'sequence'), false, true, true);
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("    \$sequence[] = \$sequenceValue;\n" . "    unset( \$sequenceValue );\n" . "}", array('spacing' => $mainSpacing + 4));
             }
         }
         $code = "\$sectionStack[] = array( " . $variableValuePushText . "&\$loopItem, \$loopKeys, \$loopCount, \$currentIndex, \$index" . $sequencePopText . $maxPopText . " );\n" . "unset( \$loopItem, \$loopKeys );\n";
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => $mainSpacing + 4));
         $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($mainSpacing + 4);
         if ($delimiterNode) {
             $delimiterChildren = eZTemplateNodeTool::extractFunctionNodeChildren($delimiterNode);
             $delimiterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($delimiterNode);
             $delimiterChildren = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $delimiterChildren, $privateData);
             $delimiterModulo = false;
             $matchCode = false;
             $useModulo = true;
             if (isset($delimiterParameters['match'])) {
                 $delimiterMatch = $delimiterParameters['match'];
                 $delimiterMatch = eZTemplateCompiler::processElementTransformationList($tpl, $delimiterNode, $delimiterMatch, $privateData);
                 if (eZTemplateNodeTool::isConstantElement($delimiterMatch)) {
                     $moduloValue = eZTemplateNodeTool::elementConstantValue($delimiterMatch);
                     $useModulo = false;
                 } else {
                     $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $delimiterMatch, eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 0), 'matchValue');
                     $matchCode = " and \$matchValue";
                 }
             } else {
                 if (isset($delimiterParameters['modulo'])) {
                     $delimiterModulo = $delimiterParameters['modulo'];
                     $delimiterModulo = eZTemplateCompiler::processElementTransformationList($tpl, $delimiterModulo, $delimiterModulo, $privateData);
                     if (eZTemplateNodeTool::isConstantElement($delimiterModulo)) {
                         $moduloValue = (int) eZTemplateNodeTool::elementConstantValue($delimiterModulo);
                         $matchCode = " and ( ( \$currentIndex - 1 ) % {$moduloValue} ) == 0";
                     } else {
                         $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $delimiterModulo, eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 0), 'moduloValue');
                         $matchCode = " and ( ( \$currentIndex - 1 ) % \$moduloValue ) == 0";
                     }
                 }
             }
             if ($useModulo) {
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$currentIndex > 1{$matchCode} )\n{");
                 $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4);
                 $newNodes = array_merge($newNodes, $delimiterChildren);
                 $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4);
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n");
             }
         }
         $newNodes = array_merge($newNodes, $mainNodes);
         $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($mainSpacing + 4);
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode("list( " . $variableValuePopText . "\$loopItem, \$loopKeys, \$loopCount, \$currentIndex, \$index" . $sequencePopText . $maxPopText . " ) = array_pop( \$sectionStack );", array('spacing' => $mainSpacing + 4));
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode("++\$currentIndex;\n", array('spacing' => $mainSpacing + 4));
         if ($varName) {
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$lastVariableValue = \$variableValue;", array('spacing' => $mainSpacing + 4));
         }
         if ($hasFilter) {
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("    }");
             $mainSpacing -= 4;
         }
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode("++\$index;\n", array('spacing' => $mainSpacing + 4));
         $code = "}\n" . "unset( \$loopKeys, \$loopCount, \$index, \$last, \$loopIndex, \$loopItem";
         if ($hasSequence) {
             $code .= ", \$sequence";
         }
         $code .= " );";
         $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code);
     } else {
         if ($useMain) {
             $newNodes = array_merge($newNodes, $mainNodes);
         }
     }
     if (isset($parameters['name'])) {
         $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode();
     }
     if ($useShow) {
         $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($spacing);
     }
     if ($useElse) {
         $elseNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'after', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else')))));
         $elseNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $elseNodes, $privateData);
         if (count($elseNodes) > 0) {
             if ($useShow) {
                 // This is needed if a 'if ( $show )' was used earlier
                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelse\n{\n");
                 $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing);
                 $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show');
             }
             if (isset($parameters['name'])) {
                 $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']);
             }
             $newNodes = array_merge($newNodes, $elseNodes);
             if (isset($parameters['name'])) {
                 $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode();
             }
             if ($useShow) {
                 // This is needed if a 'if ( $show )' was used earlier
                 $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($spacing);
             }
         }
         if ($useShow) {
             // This is needed if a 'if ( $show )' was used earlier
             $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n");
         }
     }
     return $newNodes;
 }
Esempio n. 9
0
 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;
 }
    function processChildren()
    {
        // process the loop body
        $children            = eZTemplateNodeTool::extractFunctionNodeChildren( $this->Node );
        $transformedChildren = eZTemplateCompiler::processNodeTransformationNodes( $this->Tpl, $this->Node, $children, $this->PrivateData );

        $childrenNodes = array();
        $delimiter = null;

        if ( is_array( $transformedChildren ) )
        {
            foreach ( $transformedChildren as $child )
            {
                if ( $child[0] == eZTemplate::NODE_FUNCTION ) // check child type
                {
                    $childFunctionName = $child[2];
                    if ( $childFunctionName == 'delimiter' )
                    {
                        // save delimiter for it to be processed below
                        $delimiter = $child;
                        continue;
                    }
                    elseif ( $childFunctionName == 'break' )
                    {
                        $childrenNodes[] = eZTemplateNodeTool::createCodePieceNode( "break;\n" );
                        continue;
                    }
                    elseif ( $childFunctionName == 'continue' )
                    {
                        $childrenNodes[] = eZTemplateNodeTool::createCodePieceNode( "continue;\n" );
                        continue;
                    }
                    elseif ( $childFunctionName == 'skip' )
                    {
                        $childrenNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$skipDelimiter = true;\ncontinue;\n" );
                        continue;
                    }
                }

                $childrenNodes[] = $child;
            }
        }

        if ( $delimiter ) // if delimiter is specified
        {
            $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' ) ) ) ) );
            $delimiterNode = false;
            if ( count( $delimiterNodes ) > 0 )
                $delimiterNode = $delimiterNodes[0];

            $delimiterChildren = eZTemplateNodeTool::extractFunctionNodeChildren( $delimiterNode );
            $delimiterParameters = eZTemplateNodeTool::extractFunctionNodeParameters( $delimiterNode );

            $checkModulo = array();
            $checkModuloEnd = array();
            $delemiterModuloValue = array();
            if ( isset( $delimiterParameters['modulo'] ) )
            {
                switch ( $this->Name )
                {
                    case 'foreach':
                    {
                        $delimiterModulo = $delimiterParameters['modulo'];
                        $delimiterModulo = eZTemplateCompiler::processElementTransformationList( $this->Tpl, $delimiterModulo, $delimiterModulo, $this->PrivateData );
                        // Get unique index
                        $currentIndex = "\$fe_i_$this->UniqID";

                        if ( eZTemplateNodeTool::isConstantElement( $delimiterModulo ) )
                        {
                            $moduloValue = (int)eZTemplateNodeTool::elementConstantValue( $delimiterModulo );
                            $matchCode = "( ( $currentIndex ) % $moduloValue ) == 0";
                        }
                        else
                        {
                            $delemiterModuloValue[] = eZTemplateNodeTool::createVariableNode( false, $delimiterModulo, eZTemplateNodeTool::extractFunctionNodePlacement( $this->Node ),
                                                                                        array( 'spacing' => 0 ), 'moduloValue' );
                            $matchCode = "( ( $currentIndex ) % \$moduloValue ) == 0";
                        }
                        $checkModulo[] = eZTemplateNodeTool::createCodePieceNode( "if ( $matchCode ) // Check modulo\n{" );
                        $checkModulo[] = eZTemplateNodeTool::createSpacingIncreaseNode( 4 );

                        $checkModuloEnd[] = eZTemplateNodeTool::createSpacingDecreaseNode( 4 );
                        $checkModuloEnd[] = eZTemplateNodeTool::createCodePieceNode( "}\n" );
                    }
                }
            }
            $delimiterNodes = array();
            $delimiterNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( \$skipDelimiter )\n" .
                                                                         "    \$skipDelimiter = false;\n" .
                                                                         "else\n" .
                                                                         "{ // delimiter begins" );
            $delimiterNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
            if ( is_array( $delimiter[1] ) ) // if delimiter has children
            {
                // If modulo is specified
                $delimiterNodes = array_merge( $delimiterNodes, $checkModulo );

                foreach ( $delimiter[1] as $delimiterChild )
                    $delimiterNodes[] = $delimiterChild;

                // Set end of checking for modulo
                $delimiterNodes = array_merge( $delimiterNodes, $checkModuloEnd );
            }

            $delimiterNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
            $delimiterNodes[] = eZTemplateNodeTool::createCodePieceNode( "} // delimiter ends\n" );

            // we place its code right before other loop children,
            // if delemiter and modulo are specified and value of modulo is not static
            // $delemiterModuloValue is initialization of variable
            // we should place initialization of moduloValue before checking for delimiter
            $childrenNodes = array_merge( $delemiterModuloValue, $delimiterNodes, $childrenNodes );
        }

        $this->NewNodes = array_merge( $this->NewNodes, $childrenNodes );
    }