| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTemplateWhileFunction class 4 // 5 // Created on: <18-Feb-2005 14:57:37 vs> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZTemplateWhileFunction eztemplatewhilefunction.php 31 \ingroup eZTemplateFunctions 32 \brief WHILE loop 33 34 Syntax: 35 \code 36 {while <condition> [sequence <array> as $seqVar] } 37 [{delimiter}...{/delimiter}] 38 [{break}] 39 [{continue}] 40 [{skip}] 41 {/while} 42 \endcode 43 44 Example: 45 \code 46 {while ne( $var, false() ) } 47 I like big trucks 48 {/while} 49 \endcode 50 */ 51 52 define ( 'EZ_TEMPLATE_WHILE_FUNCTION_NAME', 'while' ); 53 class eZTemplateWhileFunction 54 { 55 /*! 56 * Returns an array of the function names, required for eZTemplate::registerFunctions. 57 */ 58 function &functionList() 59 { 60 $functionList = array( EZ_TEMPLATE_WHILE_FUNCTION_NAME ); 61 return $functionList; 62 } 63 64 /*! 65 * Returns the attribute list. 66 * key: parameter name 67 * value: can have children 68 */ 69 function attributeList() 70 { 71 return array( 'delimiter' => true, 72 'break' => false, 73 'continue' => false, 74 'skip' => false ); 75 } 76 77 78 /*! 79 * Returns the array with hits for the template compiler. 80 */ 81 function functionTemplateHints() 82 { 83 return array( EZ_TEMPLATE_WHILE_FUNCTION_NAME => array( 'parameters' => true, 84 'static' => false, 85 'transform-parameters' => true, 86 'tree-transformation' => true ) ); 87 } 88 89 /*! 90 * Compiles the function and its children into PHP code. 91 */ 92 function templateNodeTransformation( $functionName, &$node, 93 &$tpl, &$parameters, $privateData ) 94 { 95 // {while <condition> [sequence <sequence_array> as $<sequence_var>]} 96 97 $tpl->WhileCounter++; 98 $newNodes = array(); 99 $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement( $node ); 100 $uniqid = md5( $nodePlacement[2] ) . "_" . $tpl->WhileCounter; 101 102 require_once ( 'lib/eztemplate/classes/eztemplatecompiledloop.php' ); 103 $loop = new eZTemplateCompiledLoop( EZ_TEMPLATE_WHILE_FUNCTION_NAME, 104 $newNodes, $parameters, $nodePlacement, $uniqid, 105 $node, $tpl, $privateData ); 106 107 108 $loop->initVars(); 109 110 // loop header 111 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "while ( 1 ) // while\n{" ); 112 $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); 113 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters['condition'], $nodePlacement, array( 'treat-value-as-non-object' => true ), 114 "while_cond" ); 115 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( ! \$while_cond ) break;\n" ); 116 117 $loop->processBody(); 118 119 // loop footer 120 $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); 121 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "} // end of while\n" ); 122 $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'while_cond' ); 123 $loop->cleanup(); 124 125 return $newNodes; 126 } 127 128 /*! 129 * Actually executes the function and its children (in processed mode). 130 */ 131 function process( &$tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace ) 132 { 133 if ( count( $functionParameters ) == 0 ) 134 { 135 eZDebug::writeError( "Not enough arguments passed to 'while' function." ); 136 return; 137 } 138 139 require_once ( 'lib/eztemplate/classes/eztemplateloop.php' ); 140 $loop = new eZTemplateLoop( EZ_TEMPLATE_WHILE_FUNCTION_NAME, 141 $functionParameters, $functionChildren, $functionPlacement, 142 $tpl, $textElements, $rootNamespace, $currentNamespace ); 143 144 if ( !$loop->initialized() ) 145 return; 146 147 while ( $tpl->elementValue( $functionParameters['condition'], $rootNamespace, $currentNamespace, $functionPlacement ) ) 148 { 149 $loop->setSequenceVar(); // set sequence variable (if specified) 150 $loop->processDelimiter(); 151 $loop->resetIteration(); 152 153 if ( $loop->processChildren() ) 154 break; 155 156 $loop->incrementSequence(); 157 } 158 159 $loop->cleanup(); 160 } 161 162 /*! 163 * Returns true, telling the template parser that the function can have children. 164 */ 165 function hasChildren() 166 { 167 return true; 168 } 169 } 170 171 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |