Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplateloop.php
Go to the documentation of this file.
1 <?php
11 // private class, should not be used outside of this file
12 class eZTemplateLoopSequence
13 {
19 public function __construct( $array )
20 {
21 $this->ArrayRef = $array;
22 $this->CurVal = current( $this->ArrayRef );
23 }
24
25 function val()
26 {
27 return $this->CurVal;
28 }
29
30 function next()
31 {
32 if( ( $this->CurVal = next( $this->ArrayRef ) ) === false )
33 {
34 reset( $this->ArrayRef );
35 $this->CurVal = current( $this->ArrayRef );
36 }
37 }
38
39 public $ArrayRef;
40 public $CurVal;
41 }
42
48 class eZTemplateLoop
49 {
50 public $Delimiter;
51 public function __construct( $functionName, &$functionParameters, $functionChildren, $functionPlacement,
52 $tpl, &$textElements, $rootNamespace, $currentNamespace )
53 {
54 $this->SkipDelimiter = true;
55 $this->SkipSequenceIncrement = false;
56 $this->Delimiter = null;
57 $this->Initialized = true;
58 $this->SequenceVarName = null;
59 $this->Sequence = null;
60 $this->LoopVariablesNames = array();
61
62
63 $this->FunctionName = $functionName;
64 $this->FunctionParameters =& $functionParameters;
65 $this->FunctionChildren = $functionChildren;
66
67 $this->Tpl = $tpl;
68 $this->TextElements =& $textElements;
69 $this->RootNamespace = $rootNamespace;
70 $this->CurrentNamespace = $currentNamespace;
71 $this->FunctionPlacement = $functionPlacement;
72
73 $this->Initialized = $this->processFunctionParameters();
74 }
75
79 function processFunctionParameters()
80 {
81 $params =& $this->FunctionParameters;
82
83 if ( !isset( $params['sequence_array'] ) || !count( $params['sequence_array'] ) )
84 return true;
85
86 $this->parseParamVarName( 'sequence_var', $seqVarName );
87
88 if ( !$seqVarName )
89 {
90 $this->Tpl->error( $this->FunctionName, "Empty sequence variable name." );
91 return false;
92 }
93
94 $this->initLoopVariable( $seqVarName );
95
96 $seqArray = $this->Tpl->elementValue( $params['sequence_array'],
97 $this->RootNamespace, $this->CurrentNamespace, $this->FunctionPlacement );
98
99 $this->Sequence = new eZTemplateLoopSequence( $seqArray );
100 $this->SequenceVarName = $seqVarName;
101
102 return true;
103 }
104
108 function initialized()
109 {
110 return $this->Initialized;
111 }
112
116 function setSequenceVar()
117 {
118 if ( !$this->hasSequence() )
119 return;
120
121 $this->Tpl->setVariable( $this->SequenceVarName, $this->Sequence->val(), $this->RootNamespace );
122 }
123
128 function resetIteration()
129 {
130 $this->SkipDelimiter = false;
131 $this->SkipSequenceIncrement = false;
132 }
133
137 function incrementSequence()
138 {
139 if ( $this->hasSequence() && !$this->SkipSequenceIncrement )
140 $this->Sequence->next();
141 }
142
146 function hasSequence()
147 {
148 return $this->Sequence !== null;
149 }
150
151
155 function cleanup()
156 {
157 // destroy loop variable(s)
158 foreach ( $this->LoopVariablesNames as $varName )
159 $this->Tpl->unsetVariable( $varName, $this->RootNamespace );
160 }
161
162 /*
163 * Processes loop children, i.e. all tags and text that is
164 * between start and end tags of the loop.
165 * Besides, does special handling of {break}, {skip}, {continue} and {delimiter} tags.
166 *
167 * \return true if the caller loop should break, false otherwise
168 */
169 function processChildren()
170 {
171 if ( !is_array( $this->FunctionChildren ) )
172 {
173 return false;
174 }
175 foreach ( array_keys( $this->FunctionChildren ) as $childKey )
176 {
177 $child = $this->FunctionChildren[$childKey];
178
179 if ( $child[0] == eZTemplate::NODE_FUNCTION ) // check child type
180 {
181 $childFunctionName = $child[2];
182
183 if ( $childFunctionName == 'break' )
184 return true;
185 elseif ( $childFunctionName == 'continue' )
186 {
187 $this->SkipSequenceIncrement = true;
188 break;
189 }
190 elseif ( $childFunctionName == 'skip' )
191 {
192 $this->SkipSequenceIncrement = true;
193 $this->SkipDelimiter = true;
194 break;
195 }
196 elseif ( $childFunctionName == 'delimiter' )
197 {
198 if ( $this->Delimiter === null )
199 $this->Delimiter = $child;
200 continue;
201 }
202 }
203
204 $rslt = $this->Tpl->processNode( $child, $this->TextElements, $this->RootNamespace, $this->CurrentNamespace );
205
206 // break/continue/skip might be found in a child function's (usually {if}) children
207 if ( is_array( $rslt ) )
208 {
209 if ( array_key_exists( 'breakFunctionFound', $rslt ) )
210 return true;
211 elseif ( array_key_exists( 'continueFunctionFound', $rslt ) )
212 {
213 $this->SkipSequenceIncrement = true;
214 break;
215 }
216 elseif ( array_key_exists( 'skipFunctionFound', $rslt ) )
217 {
218 $this->SkipSequenceIncrement = true;
219 $this->SkipDelimiter = true;
220 break;
221 }
222 }
223
224 } // foreach
225
226 return false;
227 }
228
235 function processDelimiter( $index = false )
236 {
237 if ( $this->Delimiter === null || $this->SkipDelimiter )
238 return false;
239
240 $delimiterChildren = $this->Delimiter[1];
241 $delimiterParameters = $this->Delimiter[3]; // Get parameters
242 $delimiterMatch = true;
243 // Check for "modulo"
244 if ( isset( $delimiterParameters["modulo"] ) and $index !== false )
245 {
246 $delimiterModulo = $delimiterParameters["modulo"];
247 $modulo = $this->Tpl->elementValue( $delimiterModulo, $this->RootNamespace, $this->FunctionName, $this->FunctionPlacement );
248 $modulo = trim( $modulo );
249 if ( is_numeric( $modulo ) )
250 $delimiterMatch = ( $index % $modulo ) == 0;
251 }
252 if ( $delimiterMatch )
253 {
254 foreach ( $delimiterChildren as $delimiterChild )
255 {
256 $this->Tpl->processNode( $delimiterChild, $this->TextElements, $this->RootNamespace, $this->CurrentNamespace );
257 }
258 }
259
260 return false;
261 }
262
271 function parseParamVarName( $paramName, &$dst )
272 {
273 $dst = null;
274
275 if ( !isset( $this->FunctionParameters[$paramName] ) ||
276 !count( $this->FunctionParameters[$paramName] ) )
277 return false;
278
279 list( $varNsName, $varNsType, $varName ) = $this->FunctionParameters[$paramName][0][1];
280
281 if ( $varNsType != eZTemplate::NAMESPACE_SCOPE_LOCAL || $varNsName )
282 {
283 $this->Tpl->error( $this->FunctionName,
284 'Loop variables can be defined in root namespace only (e.g. $foo, but not $#foo or $:foo.)' );
285 return false;
286 }
287
288 $dst = $varName;
289 return true;
290 }
291
300 function parseScalarParamValue( $paramName, &$dst, &$isProxyObject )
301 {
302 $dst = null;
303
304 if ( !isset( $this->FunctionParameters[$paramName] ) || !count( $this->FunctionParameters[$paramName] ) )
305 return false;
306
307 // get parameter value
308 $dst = $this->Tpl->elementValue( $this->FunctionParameters[$paramName], $this->RootNamespace,
309 $this->CurrentNamespace, $this->FunctionPlacement, false, true );
310
311 // check if a proxy object ({section} loop iterator) was involved in the parameter value
312 if ( isset( $this->FunctionParameters[$paramName]['proxy-object-found'] ) )
313 {
314 $isProxyObject = true;
315 unset( $this->FunctionParameters[$paramName]['proxy-object-found'] ); // just not to leave garbage
316 }
317 else
318 $isProxyObject = false;
319
320 return true;
321 }
322
330 function parseParamValue( $paramName, &$dst )
331 {
332 $dst = null;
333
334 if ( !isset( $this->FunctionParameters[$paramName] ) || !count( $this->FunctionParameters[$paramName] ) )
335 return false;
336
337 $dst = $this->Tpl->elementValue( $this->FunctionParameters[$paramName], $this->RootNamespace,
338 $this->CurrentNamespace, $this->FunctionPlacement );
339 return true;
340 }
341
348 function initLoopVariable( $varName )
349 {
350 if ( $this->Tpl->hasVariable( $varName, $this->RootNamespace ) )
351 $this->Tpl->warning( $this->FunctionName, "Variable '$varName' already exists." );
352 else
353 $this->LoopVariablesNames[] = $varName;
354 }
355
359
360 public $FunctionName;
361 public $FunctionParameters;
362 public $FunctionChildren;
363 public $FunctionPlacement;
364
365 public $SkipDelimiter;
366 public $SkipSequenceIncrement;
367 public $delimiter;
368
369 public $Tpl;
370 public $TextElements;
371 public $RootNamespace;
372 public $CurrentNamespace;
373
374 public $Initialized;
375 public $Sequence;
376 public $SequenceVarName;
382 public $LoopVariablesNames;
383 }
384
385 ?>
eZTemplateLoopSequence
Definition: eztemplateloop.php:13
eZTemplateLoopSequence\__construct
__construct( $array)
Definition: eztemplateloop.php:19
eZTemplateLoopSequence\$CurVal
$CurVal
Definition: eztemplateloop.php:40
eZTemplateLoopSequence\val
val()
Definition: eztemplateloop.php:25
eZTemplateLoopSequence\next
next()
Definition: eztemplateloop.php:30
eZTemplateLoopSequence\$ArrayRef
$ArrayRef
Definition: eztemplateloop.php:39
eZTemplateLoop
Code common for the loop functions in processed mode.
Definition: eztemplateloop.php:49
eZTemplateLoop\$FunctionParameters
$FunctionParameters
Definition: eztemplateloop.php:361
eZTemplateLoop\initLoopVariable
initLoopVariable( $varName)
Definition: eztemplateloop.php:348
eZTemplateLoop\$SkipDelimiter
$SkipDelimiter
Definition: eztemplateloop.php:365
eZTemplateLoop\$SequenceVarName
$SequenceVarName
Definition: eztemplateloop.php:376
eZTemplateLoop\processDelimiter
processDelimiter( $index=false)
Definition: eztemplateloop.php:235
eZTemplateLoop\$SkipSequenceIncrement
$SkipSequenceIncrement
Definition: eztemplateloop.php:366
eZTemplateLoop\processChildren
processChildren()
Definition: eztemplateloop.php:169
eZTemplateLoop\parseParamValue
parseParamValue( $paramName, &$dst)
Definition: eztemplateloop.php:330
eZTemplateLoop\resetIteration
resetIteration()
Definition: eztemplateloop.php:128
eZTemplateLoop\hasSequence
hasSequence()
Definition: eztemplateloop.php:146
eZTemplateLoop\cleanup
cleanup()
Definition: eztemplateloop.php:155
eZTemplateLoop\initialized
initialized()
Definition: eztemplateloop.php:108
eZTemplateLoop\$Initialized
$Initialized
Definition: eztemplateloop.php:374
eZTemplateLoop\setSequenceVar
setSequenceVar()
Definition: eztemplateloop.php:116
eZTemplateLoop\__construct
__construct( $functionName, &$functionParameters, $functionChildren, $functionPlacement, $tpl, &$textElements, $rootNamespace, $currentNamespace)
Definition: eztemplateloop.php:51
eZTemplateLoop\$Delimiter
$Delimiter
Definition: eztemplateloop.php:50
eZTemplateLoop\$LoopVariablesNames
$LoopVariablesNames
Definition: eztemplateloop.php:382
eZTemplateLoop\$FunctionPlacement
$FunctionPlacement
Definition: eztemplateloop.php:363
eZTemplateLoop\parseParamVarName
parseParamVarName( $paramName, &$dst)
Definition: eztemplateloop.php:271
eZTemplateLoop\$TextElements
$TextElements
Definition: eztemplateloop.php:370
eZTemplateLoop\$RootNamespace
$RootNamespace
Definition: eztemplateloop.php:371
eZTemplateLoop\$FunctionName
$FunctionName
Definition: eztemplateloop.php:360
eZTemplateLoop\$delimiter
$delimiter
Definition: eztemplateloop.php:367
eZTemplateLoop\incrementSequence
incrementSequence()
Definition: eztemplateloop.php:137
eZTemplateLoop\$FunctionChildren
$FunctionChildren
Definition: eztemplateloop.php:362
eZTemplateLoop\$Tpl
$Tpl
Definition: eztemplateloop.php:369
eZTemplateLoop\parseScalarParamValue
parseScalarParamValue( $paramName, &$dst, &$isProxyObject)
Definition: eztemplateloop.php:300
eZTemplateLoop\$Sequence
$Sequence
Definition: eztemplateloop.php:375
eZTemplateLoop\$CurrentNamespace
$CurrentNamespace
Definition: eztemplateloop.php:372
eZTemplateLoop\processFunctionParameters
processFunctionParameters()
Definition: eztemplateloop.php:79
eZTemplate\NAMESPACE_SCOPE_LOCAL
const NAMESPACE_SCOPE_LOCAL
Definition: eztemplate.php:285
eZTemplate\NODE_FUNCTION
const NODE_FUNCTION
Definition: eztemplate.php:213
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.