Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatearrayoperator.php
Go to the documentation of this file.
1 <?php
27 class eZTemplateArrayOperator
28 {
29 public function __construct( $arrayName = 'array',
30 $hashName = 'hash',
31 $arrayPrependName = 'array_prepend', // DEPRECATED/OBSOLETE
32 $prependName = 'prepend', // New, replaces array_prepend.
33 $arrayAppendName = 'array_append', // DEPRECATED/OBSOLETE
34 $appendName = 'append', // New, replaces array_append.
35 $arrayMergeName = 'array_merge', // DEPRECATED/OBSOLETE
36 $mergeName = 'merge', // New, replaces array_merge.
37 $containsName = 'contains',
38 $compareName = 'compare',
39 $extractName = 'extract',
40 $extractLeftName = 'extract_left',
41 $extractRightName = 'extract_right',
42 $beginsWithName = 'begins_with',
43 $endsWithName = 'ends_with',
44 $implodeName = 'implode',
45 $explodeName = 'explode',
46 $repeatName = 'repeat',
47 $reverseName = 'reverse',
48 $insertName = 'insert',
49 $removeName = 'remove',
50 $replaceName = 'replace',
51 $uniqueName = 'unique',
52 $arraySumName = 'array_sum' )
53 {
54 $this->ArrayName = $arrayName;
55 $this->HashName = $hashName;
56 $this->ArrayPrependName = $arrayPrependName; // DEPRECATED/OBSOLETE
57 $this->PrependName = $prependName; // New, replaces ArrayPrependName.
58 $this->ArrayAppendName = $arrayAppendName; // DEPRECATED/OBSOLETE
59 $this->AppendName = $appendName; // New, replaces ArrayAppendName.
60 $this->ArrayMergeName = $arrayMergeName; // DEPRECATED/OBSOLETE
61 $this->MergeName = $mergeName; // New, replaces ArrayMergeName.
62 $this->ContainsName = $containsName;
63 $this->CompareName = $compareName;
64 $this->ExtractName = $extractName;
65 $this->ExtractLeftName = $extractLeftName;
66 $this->ExtractRightName = $extractRightName;
67 $this->BeginsWithName = $beginsWithName;
68 $this->EndsWithName = $endsWithName;
69 $this->ImplodeName = $implodeName;
70 $this->ExplodeName = $explodeName;
71 $this->RepeatName = $repeatName;
72 $this->ReverseName = $reverseName;
73 $this->InsertName = $insertName;
74 $this->RemoveName = $removeName;
75 $this->ReplaceName = $replaceName;
76 $this->UniqueName = $uniqueName;
77 $this->ArraySumName = $arraySumName;
78
79 $this->Operators = array( $arrayName,
80 $hashName,
81 $arrayPrependName, // DEPRECATED/OBSOLETE
82 $prependName, // New, replaces arrayPrependName.
83 $arrayAppendName, // DEPRECATED/OBSOLETE
84 $appendName, // New, replaces arrayAppendName.
85 $arrayMergeName, // DEPRECATED/OBSOLETE
86 $mergeName, // New, replaces arrayMergeName.
87 $containsName,
88 $compareName,
89 $extractName,
90 $extractLeftName,
91 $extractRightName,
92 $beginsWithName,
93 $endsWithName,
94 $implodeName,
95 $explodeName,
96 $repeatName,
97 $reverseName,
98 $insertName,
99 $removeName,
100 $replaceName,
101 $uniqueName,
102 $arraySumName );
103 }
104
108 function operatorList()
109 {
110 return $this->Operators;
111 }
112
113 function operatorTemplateHints()
114 {
115 return array( $this->ArrayName => array( 'input' => true,
116 'output' => true,
117 'parameters' => true,
118 'element-transformation' => true,
119 'transform-parameters' => true,
120 'element-transformation-func' => 'arrayTrans' ),
121 $this->HashName => array( 'input' => true,
122 'output' => true,
123 'parameters' => true,
124 'element-transformation' => true,
125 'transform-parameters' => true,
126 'element-transformation-func' => 'arrayTrans'),
127 $this->ArrayPrependName => array( 'input' => true,
128 'output' => true,
129 'parameters' => true,
130 'element-transformation' => true,
131 'transform-parameters' => true,
132 'input-as-parameter' => 'always',
133 'element-transformation-func' => 'mergeTrans' ),
134 $this->PrependName => array( 'input' => true,
135 'output' => true,
136 'parameters' => true,
137 'element-transformation' => true,
138 'transform-parameters' => true,
139 'input-as-parameter' => 'always',
140 'element-transformation-func' => 'mergeTrans' ),
141 $this->ArrayAppendName => array( 'input' => true,
142 'output' => true,
143 'parameters' => true,
144 'element-transformation' => true,
145 'transform-parameters' => true,
146 'input-as-parameter' => 'always',
147 'element-transformation-func' => 'mergeTrans' ),
148 $this->AppendName => array( 'input' => true,
149 'output' => true,
150 'parameters' => true,
151 'element-transformation' => true,
152 'transform-parameters' => true,
153 'input-as-parameter' => 'always',
154 'element-transformation-func' => 'mergeTrans' ),
155 $this->ArrayMergeName => array( 'input' => true,
156 'output' => true,
157 'parameters' => true,
158 'element-transformation' => true,
159 'transform-parameters' => true,
160 'input-as-parameter' => 'always',
161 'element-transformation-func' => 'mergeTrans' ),
162 $this->MergeName => array( 'input' => true,
163 'output' => true,
164 'parameters' => true,
165 'element-transformation' => true,
166 'transform-parameters' => true,
167 'input-as-parameter' => 'always',
168 'element-transformation-func' => 'mergeTrans' ),
169 $this->ContainsName => array( 'input' => true,
170 'output' => true,
171 'parameters' => 1,
172 'element-transformation' => true,
173 'transform-parameters' => true,
174 'input-as-parameter' => 'always',
175 'element-transformation-func' => 'arrayTrans'),
176 $this->CompareName => array( 'input' => true,
177 'output' => true,
178 'parameters' => 1,
179 'element-transformation' => true,
180 'transform-parameters' => true,
181 'input-as-parameter' => 'always',
182 'element-transformation-func' => 'arrayTrans'),
183 $this->ExtractName => array( 'input' => true,
184 'output' => true,
185 'parameters' => 2,
186 'element-transformation' => true,
187 'transform-parameters' => true,
188 'input-as-parameter' => 'always',
189 'element-transformation-func' => 'extractTrans'),
190 $this->ExtractLeftName => array( 'input' => true,
191 'output' => true,
192 'parameters' => 1,
193 'element-transformation' => true,
194 'transform-parameters' => true,
195 'input-as-parameter' => 'always',
196 'element-transformation-func' => 'extractTrans'),
197 $this->ExtractRightName => array( 'input' => true,
198 'output' => true,
199 'parameters' => 1,
200 'element-transformation' => true,
201 'transform-parameters' => true,
202 'input-as-parameter' => 'always',
203 'element-transformation-func' => 'extractTrans'),
204 $this->BeginsWithName => array( 'input' => true,
205 'output' => true,
206 'parameters' => true,
207 'element-transformation' => true,
208 'transform-parameters' => true,
209 'input-as-parameter' => 'always',
210 'element-transformation-func' => 'compareTrans'),
211 $this->EndsWithName => array( 'input' => true,
212 'output' => true,
213 'parameters' => true,
214 'element-transformation' => true,
215 'transform-parameters' => true,
216 'input-as-parameter' => 'always',
217 'element-transformation-func' => 'compareTrans'),
218 $this->ImplodeName => array( 'input' => true,
219 'output' => true,
220 'parameters' => 1,
221 'element-transformation' => true,
222 'transform-parameters' => true,
223 'input-as-parameter' => 'always',
224 'element-transformation-func' => 'arrayTrans'),
225 $this->ExplodeName => array( 'input' => true,
226 'output' => true,
227 'parameters' => 1,
228 'element-transformation' => true,
229 'transform-parameters' => true,
230 'input-as-parameter' => 'always',
231 'element-transformation-func' => 'arrayTrans'),
232 $this->RepeatName => array( 'input' => true,
233 'output' => true,
234 'parameters' => 1,
235 'element-transformation' => true,
236 'transform-parameters' => true,
237 'input-as-parameter' => 'always',
238 'element-transformation-func' => 'arrayTrans'),
239 $this->ReverseName => array( 'input' => true,
240 'output' => true,
241 'parameters' => false,
242 'element-transformation' => true,
243 'transform-parameters' => true,
244 'input-as-parameter' => 'always',
245 'element-transformation-func' => 'arrayTrans' ),
246 $this->InsertName => array( 'input' => true,
247 'output' => true,
248 'parameters' => true,
249 'element-transformation' => true,
250 'transform-parameters' => true,
251 'input-as-parameter' => 'always',
252 'element-transformation-func' => 'arrayTrans' ),
253 $this->RemoveName => array( 'input' => true,
254 'output' => true,
255 'parameters' => 2,
256 'element-transformation' => true,
257 'transform-parameters' => true,
258 'input-as-parameter' => 'always',
259 'element-transformation-func' => 'arrayTrans'),
260 $this->ReplaceName => array( 'input' => true,
261 'output' => true,
262 'parameters' => true ),
263 $this->UniqueName => array( 'input' => true,
264 'output' => true,
265 'parameters' => false,
266 'element-transformation' => true,
267 'transform-parameters' => true,
268 'input-as-parameter' => 'always',
269 'element-transformation-func' => 'arrayTrans'),
270 $this->ArraySumName => array( 'input' => true,
271 'output' => true,
272 'parameters' => false,
273 'element-transformation' => true,
274 'transform-parameters' => true,
275 'input-as-parameter' => 'always',
276 'element-transformation-func' => 'arrayTrans' ) );
277 }
278
279 function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
280 $element, $lastElement, $elementList, $elementTree, &$parameters )
281 {
282 switch( $operatorName )
283 {
284 case $this->ArrayName:
285 {
286 $code = '';
287 $paramCount = 0;
288 $values = array();
289 $staticArray = array();
290 for ( $i = 0; $i < count( $parameters ); ++$i )
291 {
292 if ( $i != 0 )
293 {
294 $code .= ', ';
295 }
296 else
297 {
298 $code .= '%output% = array( ';
299 }
300
301 if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
302 {
303 $values[] = $parameters[$i];
304 ++$paramCount;
305 $code .= '%' . $paramCount . '%';
306 }
307 else
308 {
309 if ( $paramCount == 0 )
310 {
311 $staticArray[] = eZTemplateNodeTool::elementConstantValue( $parameters[$i] );
312 }
313
314 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false );
315 }
316 }
317
318 if ( $paramCount == 0 )
319 {
320 return array( eZTemplateNodeTool::createArrayElement( $staticArray ) );
321 }
322
323 $code .= ' );';
324
325 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
326 } break;
327
328 case $this->HashName:
329 {
330 $code = '';
331 $paramCount = 0;
332 $values = array();
333 $staticArray = array();
334 $staticKeys = true;
335 $keys = array();
336 $vals = array();
337 $hashCount = (int)( count( $parameters ) / 2 );
338 for ( $i = 0; $i < $hashCount; ++$i )
339 {
340 if ( $i != 0 )
341 {
342 $code .= ', ';
343 }
344 else
345 {
346 $code .= '%output% = array( ';
347 }
348
349 if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i*2] ) )
350 {
351 $staticKeys = false;
352 $values[] = $parameters[$i*2];
353 ++$paramCount;
354 $code .= '%' . $paramCount . '%';
355 }
356 else
357 {
358 $keys[] = eZTemplateNodeTool::elementConstantValue( $parameters[$i*2] );
359 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i*2] ), 0, 0, false );
360 }
361
362 $code .= ' => ';
363
364 if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i*2+1] ) )
365 {
366 $values[] = $parameters[$i*2 + 1];
367 ++$paramCount;
368 $code .= '%' . $paramCount . '%';
369 }
370 else
371 {
372 if ( $paramCount == 0 )
373 {
374 $staticArray[ eZTemplateNodeTool::elementConstantValue( $parameters[$i*2] ) ] = eZTemplateNodeTool::elementConstantValue( $parameters[$i*2+1] );
375 }
376 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i*2+1] ), 0, 0, false );
377 }
378
379 if ( $staticKeys )
380 {
381 $vals[$keys[count( $keys ) - 1]] = $parameters[$i*2 + 1];
382 }
383 }
384
385 if ( $paramCount == 0 )
386 {
387 return array( eZTemplateNodeTool::createArrayElement( $staticArray ) );
388 }
389
390 if ( $staticKeys )
391 {
392 return array( eZTemplateNodeTool::createDynamicArrayElement( $keys, $vals ) );
393 }
394
395 $code .= ' );';
396
397 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
398 } break;
399
400 case $this->ContainsName:
401 {
402 $values = array();
403 $inParam = null;
404 $isString = false;
405 $isArray = false;
406
407 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
408 {
409 $inParam = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
410 if ( is_string( $inParam ) )
411 {
412 $isString = true;
413 }
414 else if( is_array( $inParam ) )
415 {
416 $isArray = true;
417 }
418
419 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false );
420 }
421 else
422 {
423 $values[] = $parameters[0];
424 $inParamCode = '%' . count( $values ) . '%';
425 }
426
427 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
428 {
429 $matchParam = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
430 if ( count( $values ) == 0 )
431 {
432 if ( $isString )
433 {
434 $result = ( mb_strpos( $inParam, $matchParam ) !== false );
435 }
436 else if( $isArray )
437 {
438 $result = in_array( $matchParam, $inParam );
439 }
440
441 return array( eZTemplateNodeTool::createBooleanElement( $result ) );
442 }
443 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false );
444 }
445 else
446 {
447 $values[] = $parameters[1];
448 $matchParamCode = '%' . count( $values ) . '%';
449 }
450
451 if ( $isString )
452 {
453 $code = '%output% = ( mb_strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );';
454 }
455 else if ( $isArray )
456 {
457 $code = '%output% = in_array( ' . $matchParamCode . ', ' . $inParamCode . ' );';
458 }
459 else
460 {
461 $code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" .
462 '{' . "\n" .
463 ' %output% = ( mb_strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );' . "\n" .
464 '}' . "\n" .
465 'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" .
466 '{' . "\n" .
467 ' %output% = in_array( ' . $matchParamCode . ', ' . $inParamCode . ' );' . "\n" .
468 '}' . "\n" .
469 'else' ."\n" .
470 '{' . "\n" .
471 '%output% = false;' . "\n" .
472 '}';
473 }
474
475 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
476 } break;
477
478 case $this->CompareName:
479 {
480 $inParam = null;
481 $isString = false;
482 $isArray = false;
483 $values = array();
484
485 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
486 {
487 $inParam = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
488 if ( is_string( $inParam ) )
489 {
490 $isString = true;
491 }
492 else if( is_array( $inParam ) )
493 {
494 $isArray = true;
495 }
496
497 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false );
498 }
499 else
500 {
501 $values[] = $parameters[0];
502 $inParamCode = '%' . count( $values ) . '%';
503 }
504
505 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
506 {
507 $matchParam = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
508 if ( count( $values ) == 0 )
509 {
510 if ( $isString )
511 {
512 $result = strcmp( $inParam, $matchParam ) === 0;
513 }
514 else if( $isArray )
515 {
516 $result = ( count( array_diff( $matchParam, $inParam ) ) == 0 and
517 count( array_diff( $inParam, $matchParam ) ) == 0 );
518 }
519
520 return array( eZTemplateNodeTool::createBooleanElement( $result ) );
521 }
522 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false );
523 }
524 else
525 {
526 $values[] = $parameters[1];
527 $matchParamCode = '%' . count( $values ) . '%';
528 }
529
530 if ( $isString )
531 {
532 $code = '%output% = strcmp( ' . $inParamCode . ', ' . $matchParamCode . ' ) === 0;';
533 }
534 else if ( $isArray )
535 {
536 $code = '%output% = ( ( count( array_diff( ' . $inParamCode . ', ' . $matchParamCode . " ) ) == 0 ) and\n" .
537 ' ( count( array_diff( ' . $matchParamCode . ', ' . $inParamCode . ' ) ) == 0 ) );';
538 }
539 else
540 {
541 $code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" .
542 '{' . "\n" .
543 ' %output% = strcmp( ' . $inParamCode . ', ' . $matchParamCode . ') === 0;' . "\n" .
544 '}' . "\n" .
545 'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" .
546 '{' . "\n" .
547 ' %output% = ( ( count( array_diff( ' . $inParamCode . ', ' . $matchParamCode . " ) ) == 0 ) and\n" .
548 '( count( array_diff( ' . $matchParamCode . ', ' . $inParamCode . ' ) ) == 0 ) );' . "\n" .
549 '}';
550 }
551
552 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
553 } break;
554
555 case $this->ImplodeName:
556 {
557 $values = array();
558 if ( !eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
559 {
560 $values[] = $parameters[1];
561 $code = '%1%, ';
562 }
563 else
564 {
565 $code = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[1] ), 0, 0, false ) . ', ';
566 }
567
568 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
569 {
570 if ( count( $values ) == 0 )
571 {
572 return array( eZTemplateNodeTool::createStringElement( implode( eZTemplateNodeTool::elementConstantValue( $parameters[1] ),
573 eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) ) );
574 }
575 else
576 {
577 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[0] ), 0, 0, false );
578 }
579 }
580 else
581 {
582 $values[] = $parameters[0];
583 $code .= '%' . count( $values ) . '%';
584 }
585
586 $code = '%output% = implode( ' . $code . ' );';
587
588 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
589 } break;
590
591 case $this->UniqueName:
592 {
593 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
594 {
595 return array( eZTemplateNodeTool::createArrayElement( array_unique( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) ) );
596 }
597
598 $values = array( $parameters[0] );
599 $code = '%output% = array_unique( %1% );';
600 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
601 } break;
602
603 case $this->ExplodeName:
604 {
605 $values = array();
606 $inParam = null;
607 $isString = false;
608 $isArray = false;
609
610 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
611 {
612 $inParam = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
613 if ( is_string( $inParam ) )
614 {
615 $isString = true;
616 }
617 else if( is_array( $inParam ) )
618 {
619 $isArray = true;
620 }
621
622 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false );
623 }
624 else
625 {
626 $values[] = $parameters[0];
627 $inParamCode = '%' . count( $values ) . '%';
628 }
629
630 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
631 {
632 $matchParam = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
633 if ( count( $values ) == 0 )
634 {
635 if ( $isString )
636 {
637 $result = explode( $matchParam, $inParam );
638 }
639 else if( $isArray )
640 {
641 $result = array( array_slice( $inParam, 0, $matchParam ), array_slice( $inParam, $matchParam ) );
642 }
643
644 return array( eZTemplateNodeTool::createArrayElement( $result ) );
645 }
646 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false );
647 }
648 else
649 {
650 $values[] = $parameters[1];
651 $matchParamCode = '%' . count( $values ) . '%';
652 }
653
654 if ( $isString )
655 {
656 $code = '%output% = explode( ' . $matchParamCode . ', ' . $inParamCode . ' );';
657 }
658 else if ( $isArray )
659 {
660 $code = '%output% = array( array_slice( ' . $inParamCode . ', 0,' . $matchParamCode . ' ), array_slice( ' . $inParamCode . ', ' . $matchParamCode .' ) );';
661 }
662 else
663 {
664 $code = "if ( is_string( $inParamCode ) )\n" .
665 "{\n" .
666 "\t%output% = explode( $matchParamCode, $inParamCode );\n" .
667 "}\n" .
668 "else if ( is_array( $inParamCode ) )\n" .
669 "{\n" .
670 "\t%output% = array( array_slice( $inParamCode, 0, $matchParamCode ), array_slice( $inParamCode, $matchParamCode ) );\n" .
671 "}\n" .
672 "else\n" .
673 "{\n" .
674 "\t%output% = null;\n" .
675 "}\n";
676 }
677
678 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
679 } break;
680
681 case $this->RemoveName:
682 {
683 $values = array();
684 $isArray = false;
685 $isString = false;
686
687 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
688 {
689 $inputArray = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
690 $inputArrayCode = eZPHPCreator::variableText( $inputArray, 0, 0, false );
691 $isString = is_string( $inputArray );
692 $isArray = is_array( $inputArray );
693 }
694 else
695 {
696 $values[] = $parameters[0];
697 $inputArrayCode = '%' . count( $values ) . '%';
698 }
699
700 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
701 {
702 $offset = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
703 $offsetCode = eZPHPCreator::variableText( $offset, 0, 0, false );
704 }
705 else
706 {
707 $values[] = $parameters[1];
708 $offsetCode = '%' . count( $values ) . '%';
709 }
710
711 $length = false;
712 $lengthCode = '';
713 if ( count( $parameters ) > 2 )
714 {
715 if ( eZTemplateNodeTool::isConstantElement( $parameters[2] ) )
716 {
717 $length = eZTemplateNodeTool::elementConstantValue( $parameters[2] );
718 $lengthCode = eZPHPCreator::variableText( $length, 0, 0, false );
719 }
720 else
721 {
722 $values[] = $parameters[2];
723 $lengthCode = '%' . count( $values ) . '%';
724 }
725 }
726
727 if ( count( $values ) == 0 )
728 {
729 if ( $isString )
730 {
731 return array( eZTemplateNodeTool::createStringElement( mb_substr( $inputArray, $offset, $length ) ) );
732 }
733 else if ( $isArray )
734 {
735 if ( $length === false )
736 $length = 1;
737
738 $array_one = array_slice( $inputArray, 0, $offset );
739 $array_two = array_slice( $inputArray, $offset + $length );
740
741 return array ( eZTemplateNodeTool::createArrayElement( array_merge( $array_one, $array_two ) ) );
742 }
743 }
744
745 if ( $isString )
746 {
747 $code = '%output% = mb_substr( ' . $inputArrayCode . ', ' . $offsetCode;
748 if ( $lengthCode )
749 $code .= ', ' . $lengthCode;
750 $code .= ' );';
751 }
752 else if ( $isArray )
753 {
754 $code = '%output% = array_merge( array_slice( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ), array_slice( ' . $inputArrayCode . ', ' . $offsetCode;
755 if ( $lengthCode )
756 $code .= ' + ' . $lengthCode;
757 $code .= ' ) );';
758 }
759 else
760 {
761 $code = ( '%tmp1% = ' . $inputArrayCode . ';' . "\n" .
762 'if ( is_string( %tmp1% ) )' . "\n" .
763 '{' . "\n" .
764 ' %output% = ( mb_substr( %tmp1%, 0, ' . $offsetCode . ' )' );
765
766 $lengthCode = !$lengthCode ? 1 : $lengthCode;
767
768 if ( $lengthCode )
769 {
770 $code .= ' . mb_substr( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )';
771 }
772 $code .= ( ' );' . "\n" .
773 '}' . "\n" .
774 'else if ( is_array( %tmp1% ) )' . "\n" .
775 '{' . "\n" .
776 ' %output% = array_merge( array_slice( %tmp1%, 0, ' . $offsetCode . ' )' );
777 if ( $lengthCode )
778 {
779 $code .= ', array_slice( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )';
780 }
781 $code .= ( ' );' . "\n" .
782 '}' );
783 }
784
785 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) );
786 } break;
787
788 case $this->InsertName:
789 {
790 $values = array();
791 $isArray = false;
792 $isString = false;
793
794 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
795 {
796 $inputArray = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
797 $inputArrayCode = eZPHPCreator::variableText( $inputArray, 0, 0, false );
798 $isString = is_string( $inputArray );
799 $isArray = is_array( $inputArray );
800 }
801 else
802 {
803 $values[] = $parameters[0];
804 $inputArrayCode = '%' . count( $values ) . '%';
805 }
806
807 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
808 {
809 $offset = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
810 $offsetCode = eZPHPCreator::variableText( $offset, 0, 0, false );
811 }
812 else
813 {
814 $values[] = $parameters[1];
815 $offsetCode = '%' . count( $values ) . '%';
816 }
817
818 if ( count( $parameters ) > 2 )
819 {
820 if ( eZTemplateNodeTool::isConstantElement( $parameters[2] ) )
821 {
822 $insertText = eZTemplateNodeTool::elementConstantValue( $parameters[2] );
823 }
824 }
825
826 $insertElemCode = array();
827
828 for( $i = 2; $i < count( $parameters ); ++$i )
829 {
830 if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
831 {
832 $insertElemCode[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false );
833 }
834 else
835 {
836 $values[] = $parameters[$i];
837 $insertElemCode[] = '%' . count( $values ) . '%';
838 }
839 }
840
841 if ( count( $values ) == 0 )
842 {
843 if ( $isString )
844 {
845 return array( eZTemplateNodeTool::createStringElement( mb_substr( $inputArray, 0, $offset ) . $insertText . mb_substr( $inputArray, $offset ) ) );
846 }
847 else if ( $isArray )
848 {
849 $array_one = array_slice( $inputArray, 0, $offset );
850 $array_two = array_slice( $inputArray, $offset );
851
852 $array_to_insert = array();
853 for ( $i = 2; $i < count( $parameters ); ++$i )
854 {
855 $array_to_insert[] = eZTemplateNodeTool::elementConstantValue( $parameters[$i] );
856 }
857
858 return array( eZTemplateNodeTool::createArrayElement( array_merge( $array_one, $array_to_insert, $array_two ) ) );
859 }
860 }
861
862 $tmpCount = 0;
863 if ( $isString )
864 {
865 $code = '%output% = mb_substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . mb_substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );';
866 }
867 else if ( $isArray )
868 {
869 $code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" .
870 '%tmp2% = array_slice( %tmp1%, 0, ' . $offsetCode . ' );' . "\n" .
871 '%tmp3% = array_slice( %tmp1%, ' . $offsetCode . ' );' . "\n" .
872 '%tmp4% = array( ';
873 for( $i = 0; $i < count( $insertElemCode ); ++$i )
874 {
875 if ( $i != 0 )
876 {
877 $code .= ", ";
878 }
879 $code .= $insertElemCode[$i];
880 }
881 $code .= ' );' . "\n" .
882 '%output% = array_merge( %tmp2%, %tmp4%, %tmp3% );' . "\n";
883 $tmpCount = 4;
884 }
885 else
886 {
887 $code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" .
888 'if ( is_string( %tmp1% ) )' . "\n" .
889 '{' . "\n" .
890 ' %output% = mb_substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . mb_substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );' . "\n" .
891 '}' . "\n" .
892 'else if ( is_array( %tmp1% ) )' . "\n" .
893 '{' . "\n" .
894 ' %tmp2% = array_slice( %tmp1%, 0, ' . $offsetCode . ' );' . "\n" .
895 ' %tmp3% = array_slice( %tmp1%, ' . $offsetCode . ' );' . "\n" .
896 ' %tmp4% = array( ';
897 for( $i = 0; $i < count( $insertElemCode ); ++$i )
898 {
899 if ( $i != 0 )
900 {
901 $code .= ", ";
902 }
903 $code .= $insertElemCode[$i];
904 }
905 $code .= ' );' . "\n" .
906 ' %output% = array_merge( %tmp2%, %tmp4%, %tmp3% );' . "\n" .
907 '}' . "\n";
908 $tmpCount = 4;
909 }
910
911 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) );
912 } break;
913
914 case $this->ReverseName:
915 {
916 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
917 {
918 if ( is_string( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) )
919 {
920 return array( eZTemplateNodeTool::createStringElement( strrev( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) ) );
921 }
922 else if ( is_array( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) )
923 {
924 return array( eZTemplateNodeTool::createArrayElement( array_reverse( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) ) );
925 }
926 }
927
928 $values = array( $parameters[0] );
929 $code = 'if ( is_string( %1% ) )' . "\n" .
930 '{' . "\n".
931 ' %output% = strrev( %1% );' . "\n" .
932 '}' . "\n" .
933 'else if( is_array( %1% ) )' . "\n" .
934 '{' . "\n" .
935 ' %output% = array_reverse( %1% );' . "\n" .
936 '}' . "\n";
937
938 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
939 } break;
940
941 case $this->ArraySumName:
942 {
943 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
944 {
945 return array( eZTemplateNodeTool::createNumericElement( array_sum( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) ) );
946 }
947
948 $values = array( $parameters[0] );
949 $code = '%output% = array_sum( %1% );';
950
951 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
952 } break;
953
954 case $this->RepeatName:
955 {
956 $values = array();
957 $isString = false;
958 $isArray = false;
959
960 if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
961 {
962 $values[] = $parameters[0];
963 $arrayCode = '%' . count( $values ) . '%';
964 }
965 else
966 {
967 $arrayCode = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[0] ), 0, 0, false );
968 $isString = is_string( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
969 $isArray = is_array( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
970 }
971
972 if ( !eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
973 {
974 $values[] = $parameters[1];
975 $countCode = '%' . count( $values ) . '%';
976 }
977 else
978 {
979 $count = (int)eZTemplateNodeTool::elementConstantValue( $parameters[1] );
980
981 if ( count( $values ) == 0 )
982 {
983 if ( $isString )
984 {
985 $retText = '';
986 $origText = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
987 for ( $i = 0; $i < $count; $i++)
988 {
989 $retText .= $origText;
990 }
991
992 return array( eZTemplateNodeTool::createStringElement( $retText ) );
993 }
994 else if ( $isArray )
995 {
996 $retArray = array();
997 $origArray = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
998 for ( $i = 0; $i < $count; $i++)
999 {
1000 $retArray = array_merge( $retArray, $origArray );
1001 }
1002
1003 return array( eZTemplateNodeTool::createArrayElement( $retArray ) );
1004 }
1005 }
1006
1007 $countCode = (string)$count;
1008 }
1009
1010 $code = '%tmp2% = ' . $arrayCode . ';' . "\n" .
1011 'if ( is_string( %tmp2% ) )' . "\n" .
1012 ' %output% = \'\';' . "\n" .
1013 'else if ( is_array( %tmp2% ) )' . "\n" .
1014 ' %output% = array();' . "\n" .
1015 'for( %tmp1% = 0; %tmp1% < ' . $countCode . '; ++%tmp1% )' . "\n" .
1016 '{' . "\n" .
1017 ' if ( is_string( %tmp2% ) )' . "\n" .
1018 ' %output% .= %tmp2%;' . "\n" .
1019 ' else if ( is_array( %tmp2% ) )' . "\n" .
1020 ' %output% = array_merge( %output%, %tmp2% );' . "\n" .
1021 '}' . "\n";
1022
1023 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 2 ) );
1024 } break;
1025 }
1026 }
1027
1028 function compareTrans( $operatorName, &$node, $tpl, &$resourceData,
1029 $element, $lastElement, $elementList, $elementTree, &$parameters )
1030 {
1031 $isArray = false;
1032 $isString = false;
1033 $inParam = null;
1034 $inParamCode = '';
1035 $compareParams = array();
1036 $compareParamsCode = array();
1037 $offset = 0;
1038 $values = array();
1039 $tmpCount = 0;
1040
1041 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
1042 {
1043 $inParam = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
1044 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false );
1045 $isString = is_string( $inParam );
1046 $isArray = is_array( $inParam );
1047 }
1048 else
1049 {
1050 $values[] = $parameters[0];
1051 $inParamCode = '%' . count( $values ) . '%';
1052 }
1053
1054 for( $i = 1; $i < count( $parameters ); $i++ )
1055 {
1056 if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
1057 {
1058 $compareParams[] = eZTemplateNodeTool::elementConstantValue( $parameters[$i] );
1059 $compareParamsCode[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false );
1060 }
1061 else
1062 {
1063 $values[] = $parameters[$i];
1064 $compareParamsCode[] = '%' . count( $values ) . '%';
1065 }
1066 }
1067
1068 switch( $operatorName )
1069 {
1070 case $this->EndsWithName:
1071 {
1072 if ( count( $values ) == 0 )
1073 {
1074 if ( $isString )
1075 {
1076 $result = ( mb_strrpos( $inParam, $compareParams[0] ) === ( mb_strlen( $inParam ) - mb_strlen ( $compareParams[0] ) ) );
1077 }
1078 else if ( $isArray )
1079 {
1080 $length = count( $inParam );
1081 $params = count( $compareParams );
1082 $start = $length - $params;
1083
1084 $result = true;
1085 for ( $i = 0; $i < $params; ++$i )
1086 {
1087 if ( $inParam[$start + $i] != $compareParams[$i] )
1088 {
1089 $result = false;
1090 break;
1091 }
1092 }
1093 }
1094
1095 return array( eZTemplateNodeTool::createBooleanElement( $result ) );
1096 }
1097
1098 if ( $isString )
1099 {
1100 $code = '%output% = ( mb_strrpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === ( mb_strlen( ' . $inParamCode . ' ) - mb_strlen( ' . $compareParamsCode[0] . ' ) ) );';
1101 }
1102 else if ( $isArray )
1103 {
1104 $code = '%tmp4% = ' . $inParamCode . ';' . "\n" .
1105 '%tmp1% = count( %tmp4% );' . "\n" .
1106 '%tmp2% = ' . count( $compareParamsCode ) . ';' . "\n" .
1107 '%tmp3% = %tmp1% - %tmp2%;' . "\n" .
1108 '%output% = true;' . "\n";
1109 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i )
1110 {
1111 if( $i != 0 )
1112 $code .= 'else ';
1113 $code .= 'if ( %tmp4%[%tmp3% + ' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" .
1114 ' %output% = false;' . "\n";
1115 }
1116
1117 $tmpCount = 4;
1118 }
1119 else
1120 {
1121 $code = '%tmp4% = ' . $inParamCode . ';' . "\n" .
1122 'if ( is_string( %tmp4% ) )' . "\n" .
1123 '{' . "\n" .
1124 ' %output% = ( mb_strrpos( %tmp4%, ' . $compareParamsCode[0] . ' ) === ( mb_strlen( %tmp4% ) - mb_strlen( ' . $compareParamsCode[0] . ' ) ) );' . "\n" .
1125 '}' . "\n" .
1126 'else if( is_array( %tmp4% ) )' . "\n" .
1127 '{' . "\n" .
1128 ' %tmp1% = count( %tmp4% );' . "\n" .
1129 ' %tmp2% = ' . count( $compareParamsCode ) . ';' . "\n" .
1130 ' %tmp3% = %tmp1% - %tmp2%;' . "\n" .
1131 ' %output% = true;' . "\n";
1132 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i )
1133 {
1134 if( $i != 0 )
1135 $code .= ' else ';
1136 $code .= 'if ( %tmp4%[%tmp3% + ' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" .
1137 ' %output% = false;' . "\n";
1138 }
1139 $code .= '}';
1140
1141 $tmpCount = 4;
1142 }
1143
1144 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) );
1145 } break;
1146
1147 case $this->BeginsWithName:
1148 {
1149 if ( count( $values ) == 0 )
1150 {
1151 if ( $isString )
1152 {
1153 $result = ( mb_strpos ( $inParam, $compareParams[0] ) === 0 );
1154 }
1155 else if ( $isArray )
1156 {
1157 $result = true;
1158 for ( $i = 0; $i < count( $compareParams ); ++$i )
1159 {
1160 if ( $inParam[$i] != $compareParams[$i] )
1161 {
1162 $result = false;
1163 break;
1164 }
1165 }
1166 }
1167
1168 return array( eZTemplateNodeTool::createBooleanElement( $result ) );
1169 }
1170
1171 if ( $isString )
1172 {
1173 $code = '%output% = ( ' . $compareParamsCode[0] . ' && mb_strpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === 0 );';
1174 }
1175 else if ( $isArray )
1176 {
1177 $code = '%tmp1% = ' . $inParamCode . ';' . "\n" .
1178 '%output% = true;' . "\n";
1179 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i )
1180 {
1181 if( $i != 0 )
1182 $code .= 'else ';
1183 $code .= 'if ( %tmp1%[' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" .
1184 ' %output% = false;' . "\n";
1185 }
1186
1187 $tmpCount = 1;
1188 }
1189 else
1190 {
1191 $code = '%tmp1% = ' . $inParamCode . ';' . "\n" .
1192 'if ( is_string( %tmp1% ) )' . "\n" .
1193 '{' . "\n" .
1194 " if ( {$compareParamsCode[0]} == '' )\n" .
1195 " %output% = false;\n" .
1196 " else\n" .
1197 ' %output% = ( mb_strpos( %tmp1%, ' . $compareParamsCode[0] . ' ) === 0 );' . "\n" .
1198 '}' . "\n" .
1199 'else if( is_array( %tmp1% ) )' . "\n" .
1200 '{' . "\n" .
1201 ' %output% = true;' . "\n";
1202 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i )
1203 {
1204 if( $i != 0 )
1205 $code .= ' else ';
1206 $code .= 'if ( %tmp1%[' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" .
1207 ' %output% = false;' . "\n";
1208 }
1209 $code .= '}';
1210
1211 $tmpCount = 1;
1212 }
1213
1214 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) );
1215 } break;
1216 }
1217 }
1218
1219 function extractTrans( $operatorName, &$node, $tpl, &$resourceData,
1220 $element, $lastElement, $elementList, $elementTree, &$parameters )
1221 {
1222 $offset = 0;
1223 $length = false;
1224 $values = array();
1225 $code = '';
1226 if ( $operatorName == $this->ExtractName )
1227 {
1228 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
1229 {
1230 $offset = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
1231 $code .= (string)$offset;
1232 }
1233 else
1234 {
1235 $values[] = $parameters[1];
1236 $code .= '%' . count ( $values ) . '%';
1237 }
1238 }
1239 else if ( $operatorName == $this->ExtractRightName )
1240 {
1241 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
1242 {
1243 $offset = -1 * eZTemplateNodeTool::elementConstantValue( $parameters[1] );
1244 $code .= (string)$offset;
1245 }
1246 else
1247 {
1248 $values[] = $parameters[1];
1249 $code .= '-1 * %' . count ( $values ) . '%';
1250 }
1251 }
1252 else
1253 {
1254 $code .= '0';
1255 }
1256
1257 if ( $operatorName == $this->ExtractName )
1258 {
1259 if ( isset( $parameters[2] ) and eZTemplateNodeTool::isConstantElement( $parameters[2] ) )
1260 {
1261 $length = eZTemplateNodeTool::elementConstantValue( $parameters[2] );
1262 $code .= ', ' . (string)$length;
1263 }
1264 else if ( isset( $parameters[2] ) )
1265 {
1266 $values[] = $parameters[2];
1267 $code .= ', ' . '%' . count ( $values ) . '%';
1268 }
1269 }
1270 else if ( $operatorName == $this->ExtractLeftName )
1271 {
1272 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
1273 {
1274 $length = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
1275 $code .= ', ' . (string)$length;
1276 }
1277 else
1278 {
1279 $values[] = $parameters[1];
1280 $code .= ', ' . '%' . count ( $values ) . '%';
1281 }
1282 }
1283
1284 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
1285 {
1286 if ( count( $values ) == 0 )
1287 {
1288 $input = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
1289 if ( $operatorName == $this->ExtractRightName or !$length )
1290 {
1291 if ( is_string( $input ) )
1292 $output = mb_substr( $input, $offset );
1293 else
1294 $output = array_slice( $input, $offset );
1295 }
1296 else
1297 {
1298 if ( is_string( $input ) )
1299 $output = mb_substr( $input, $offset, $length );
1300 else
1301 $output = array_slice( $input, $offset, $length );
1302 }
1303 return array( eZTemplateNodeTool::createConstantElement( $output ) );
1304 }
1305 else
1306 {
1307 $code = '%output% = array_slice( ' . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[0] ), 0, 0, false ) . ', ' . $code . ' );';
1308 }
1309 }
1310 else
1311 {
1312 $values[] = $parameters[0];
1313 $code = ( "if ( is_string( %" . count( $values ) . "% ) )\n" .
1314 " %output% = mb_substr( %" . count( $values ) . "%, " . $code . " );\n" .
1315 "else\n" .
1316 " %output% = array_slice( %" . count( $values ) . "%, " . $code . " );" );
1317 }
1318
1319 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
1320 }
1321
1322 function mergeTrans( $operatorName, &$node, $tpl, &$resourceData,
1323 $element, $lastElement, $elementList, $elementTree, &$parameters )
1324 {
1325 $code = '';
1326 $stringCode = '';
1327
1328 $paramCount = 0;
1329 $values = array();
1330 $staticArray = array();
1331 for ( $i = 1; $i < count( $parameters ); ++$i )
1332 {
1333 if ( $i != 1 )
1334 {
1335 $code .= ', ';
1336 $stringCode .= ', ';
1337 }
1338
1339 if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
1340 {
1341 $values[] = $parameters[$i];
1342 ++$paramCount;
1343 if ( $operatorName == $this->MergeName or
1344 $operatorName == $this->ArrayMergeName )
1345 $code .= '%' . $paramCount . '%';
1346 else
1347 $code .= 'array( %' . $paramCount . '% )';
1348 $stringCode .= '%' . $paramCount . '%';
1349 }
1350 else
1351 {
1352 if ( $paramCount == 0 )
1353 {
1354 $staticArray[] = eZTemplateNodeTool::elementConstantValue( $parameters[$i] );
1355 }
1356 if ( $operatorName == $this->MergeName or
1357 $operatorName == $this->ArrayMergeName )
1358 $code .= '' . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false ) . '';
1359 else
1360 {
1361 $tmp_check = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false );
1362 // hiding "%1%", "%output%" etc. in static input string to avoid replacing it on "$var" inside compiler.
1363 $tmp_check = str_replace( "%", '"."%"."', $tmp_check );
1364 $code .= 'array( ' . $tmp_check . ' )';
1365 }
1366 $stringCode .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false );
1367 }
1368 }
1369
1370 $isString = false;
1371 $isArray = false;
1372 $code2 = false;
1373 if ( $parameters[0] )
1374 {
1375 if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
1376 {
1377 $values[] = $parameters[0];
1378 ++$paramCount;
1379 $code2 = '%' . $paramCount . '%';
1380 }
1381 else
1382 {
1383 $isString = is_string( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
1384 $isArray = is_array( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
1385 if ( $paramCount == 0 )
1386 {
1387 // $staticArray[] = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
1388 }
1389 else
1390 {
1391 $code2 = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[0] ), 0, 0, false );
1392 }
1393 }
1394 }
1395
1396 if ( $paramCount == 0 )
1397 {
1398 if ( $operatorName == $this->AppendName or
1399 $operatorName == $this->ArrayAppendName or
1400 $operatorName == $this->MergeName or
1401 $operatorName == $this->ArrayMergeName )
1402 {
1403 if ( $isString )
1404 {
1405 $str = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
1406 for( $i = 0; $i < count( $staticArray ); ++$i )
1407 {
1408 $str .= $staticArray[$i];
1409 }
1410
1411 return array( eZTemplateNodeTool::createStringElement( $str ) );
1412 }
1413 else if ( $isArray )
1414 {
1415 $returnArray = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
1416 for( $i = 0; $i < count( $staticArray ); ++$i )
1417 {
1418 if ( is_array( $staticArray[$i] ) )
1419 {
1420 $returnArray = array_merge( $returnArray, $staticArray[$i] );
1421 }
1422 else
1423 {
1424 $returnArray[] = $staticArray[$i];
1425 }
1426 }
1427 return array( eZTemplateNodeTool::createArrayElement( $returnArray ) );
1428 }
1429 }
1430 else if ( $operatorName == $this->PrependName or
1431 $operatorName == $this->ArrayPrependName )
1432 {
1433 if ( $isString )
1434 {
1435 return array( eZTemplateNodeTool::createStringElement( eZTemplateNodeTool::elementConstantValue( $parameters[1] ) . eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) );
1436 }
1437 else if ( $isArray )
1438 {
1439 return array( eZTemplateNodeTool::createArrayElement( array_merge( $staticArray, eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) ) );
1440 }
1441 }
1442 }
1443
1444 if ( $code2 )
1445 {
1446 if ( $operatorName == $this->AppendName )
1447 {
1448 $code = ( 'if ( is_string( ' . $code2 . ' ) )' . "\n" .
1449 ' %output% = ' . $code2 . ' . implode( \'\', array( ' . $stringCode . ' ) );' . "\n" .
1450 'else if( is_array( ' . $code2 . ' ) )' . "\n" .
1451 ' %output% = array_merge( ' . $code2 . ', ' . $code . ' );' );
1452 }
1453 else if ( $operatorName == $this->ArrayAppendName )
1454 {
1455 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );';
1456 }
1457 else if ( $operatorName == $this->MergeName )
1458 {
1459 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );';
1460 }
1461 else if ( $operatorName == $this->ArrayMergeName )
1462 {
1463 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );';
1464 }
1465 else if ( $operatorName == $this->PrependName )
1466 {
1467 $code = ( 'if ( is_string( ' . $code2 . ' ) )' . "\n" .
1468 ' %output% = implode( \'\', array( ' . $stringCode . ' ) ) . ' . $code2 . ';' . "\n" .
1469 'else if( is_array( ' . $code2 . ' ) )' . "\n" .
1470 ' %output% = array_merge( ' . $code . ', ' . $code2 . ' );' );
1471 }
1472 else if ( $operatorName == $this->ArrayPrependName )
1473 {
1474 $code = '%output% = array_merge( ' . $code . ', ' . $code2 . ' );';
1475 }
1476 }
1477 else
1478 {
1479 if ( $operatorName == $this->MergeName )
1480 {
1481 $code = '%output% = array_merge( ' . $code . ' );';
1482 }
1483 else
1484 {
1485 $code = '%output% = array(' . $code . ');';
1486 }
1487 }
1488
1489 return array( eZTemplateNodeTool::createCodePieceElement( $code . "\n", $values ) );
1490 }
1491
1495 function namedParameterPerOperator()
1496 {
1497 return true;
1498 }
1502 function namedParameterList()
1503 {
1504 return array( $this->RemoveName => array( 'offset' => array( "type" => "integer",
1505 "required" => true,
1506 "default" => false ),
1507 'length' => array( "type" => "integer",
1508 "required" => false,
1509 "default" => 1 ) ),
1510 $this->RepeatName => array( 'repeat_times' => array( "type" => "integer",
1511 "required" => false,
1512 "default" => 1 ) ),
1513 $this->InsertName => array( 'insert_position' => array( "type" => "integer",
1514 "required" => true,
1515 "default" => false ),
1516 'insert_string' => array( "type" => "string",
1517 "required" => true,
1518 "default" => false ) ),
1519 $this->ExplodeName => array( 'explode_first' => array( "type" => "mixed",
1520 "required" => true,
1521 "default" => false ) ),
1522 $this->ExtractName => array( 'extract_start' => array( "type" => "integer",
1523 "required" => true,
1524 "default" => false ),
1525 'extract_length' => array( "type" => "integer",
1526 "required" => false,
1527 "default" => false ) ),
1528 $this->ExtractLeftName => array( 'length' => array( "type" => "integer",
1529 "required" => true,
1530 "default" => false ) ),
1531 $this->ExtractRightName => array( 'length' => array( "type" => "integer",
1532 "required" => true,
1533 "default" => false ) ),
1534 $this->ReplaceName => array( 'offset' => array( "type" => "integer",
1535 "required" => true,
1536 "default" => false),
1537 'length' => array( "type" => "integer",
1538 "required" => false,
1539 "default" => false) ),
1540 $this->PrependName => array( 'prepend_string' => array( "type" => "string",
1541 "required" => false,
1542 "default" => false ) ),
1543 $this->ContainsName => array( 'match' => array( "type" => "string",
1544 "required" => true,
1545 "default" => false ) ),
1546 $this->BeginsWithName => array( 'match' => array( "type" => "string",
1547 "required" => true,
1548 "default" => false ) ),
1549 $this->EndsWithName => array( 'match' => array( "type" => "string",
1550 "required" => true,
1551 "default" => false ) ),
1552 $this->ImplodeName => array( 'separator' => array( "type" => "string",
1553 "required" => true,
1554 "default" => false) ),
1555 $this->CompareName => array( 'compare' => array( "type" => "mixed",
1556 "required" => true,
1557 "default" => false ) ) );
1558 }
1559
1560 function modify( $tpl, $operatorName, $operatorParameters,
1561 $rootNamespace, $currentNamespace, &$operatorValue,
1562 $namedParameters, $placement )
1563 {
1564 switch( $operatorName )
1565 {
1566 case $this->ArrayName:
1567 {
1568 $operatorValue = array();
1569 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
1570 {
1571 $operatorValue[] = $tpl->elementValue( $operatorParameters[$i],
1572 $rootNamespace,
1573 $currentNamespace,
1574 $placement );
1575 }
1576 return;
1577 }break;
1578
1579 case $this->HashName:
1580 {
1581 $operatorValue = array();
1582 $hashCount = (int)( count( $operatorParameters ) / 2 );
1583 for ( $i = 0; $i < $hashCount; ++$i )
1584 {
1585 $hashName = $tpl->elementValue( $operatorParameters[$i*2],
1586 $rootNamespace,
1587 $currentNamespace,
1588 $placement );
1589 if ( is_string( $hashName ) or
1590 is_numeric( $hashName ) )
1591 $operatorValue[$hashName] = $tpl->elementValue( $operatorParameters[($i*2)+1],
1592 $rootNamespace,
1593 $currentNamespace,
1594 $placement );
1595 else
1596 $tpl->error( $operatorName,
1597 "Unknown hash key type '" . gettype( $hashName ) . "', skipping",
1598 $placement );
1599 }
1600 return;
1601 }
1602 break;
1603
1604 case $this->ArraySumName:
1605 {
1606 if ( is_array( $operatorValue ) )
1607 {
1608 $operatorValue = array_sum( $operatorValue );
1609 }
1610 else
1611 {
1612 $tpl->error( $operatorName,
1613 "Unknown input type, can only work with arrays '" . gettype( $operatorValue ) . "'",
1614 $placement );
1615 }
1616 return;
1617 }
1618 break;
1619 }
1620
1621 $isArray = false;
1622 if ( isset( $operatorParameters[0] ) and
1623 is_array( $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ) ) )
1624 $isArray = true;
1625
1626 if ( is_array( $operatorValue ) )
1627 $isArray = true;
1628
1629 if ( $isArray )
1630 {
1631 switch( $operatorName )
1632 {
1633 // Append or prepend an array (or single elements) to the target array:
1634 case $this->ArrayPrependName:
1635 case $this->ArrayAppendName:
1636 case $this->PrependName:
1637 case $this->AppendName:
1638 {
1639 $i = 0;
1640 if ( is_array( $operatorValue ) )
1641 {
1642 if ( count( $operatorParameters ) < 1 )
1643 {
1644 $tpl->error( $operatorName,
1645 "Requires at least one item!",
1646 $placement );
1647 return;
1648 }
1649 $mainArray = $operatorValue;
1650 }
1651 else
1652 {
1653 if ( count( $operatorParameters ) < 2 )
1654 {
1655 $tpl->error( $operatorName,
1656 "Requires an array (and at least one item)!",
1657 $placement );
1658 return;
1659 }
1660 $mainArray = $tpl->elementValue( $operatorParameters[$i++],
1661 $rootNamespace,
1662 $currentNamespace,
1663 $placement );
1664 }
1665 $tmpArray = array();
1666 for ( ; $i < count( $operatorParameters ); ++$i )
1667 {
1668 $tmpArray[] = $tpl->elementValue( $operatorParameters[$i],
1669 $rootNamespace,
1670 $currentNamespace,
1671 $placement );
1672 }
1673 if ( $operatorName == $this->ArrayPrependName or $operatorName == $this->PrependName )
1674 $operatorValue = array_merge( $tmpArray, $mainArray );
1675 else
1676 $operatorValue = array_merge( $mainArray, $tmpArray );
1677
1678 }
1679 break;
1680
1681 // Merge two arrays:
1682 case $this->ArrayMergeName:
1683 case $this->MergeName:
1684 {
1685 $tmpArray = array();
1686 if ( $operatorValue === null ) {
1687 $tmpArray[] = array(); // set to empty array in case of
1688 } else {
1689 $tmpArray[] = $operatorValue;
1690 }
1691
1692 if ( count( $operatorParameters ) < 1 )
1693 {
1694 $tpl->error( $operatorName, "Requires an array (and at least one item!)",
1695 $placement );
1696 return;
1697 }
1698
1699 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
1700 {
1701 $tmpVal = $tpl->elementValue( $operatorParameters[$i],
1702 $rootNamespace,
1703 $currentNamespace,
1704 $placement );
1705 if ( $tmpVal !== null )
1706 {
1707 $tmpArray[] = $tmpVal;
1708 }
1709 }
1710 $operatorValue = call_user_func_array( 'array_merge', $tmpArray );
1711 }break;
1712
1713 // Check if the array contains a specified element:
1714 case $this->ContainsName:
1715 {
1716 if ( count( $operatorParameters ) < 1 )
1717 {
1718 $tpl->error( $operatorName, "Missing matching value!",
1719 $placement );
1720 return;
1721 }
1722 $matchValue = $tpl->elementValue( $operatorParameters[0],
1723 $rootNamespace,
1724 $currentNamespace,
1725 $placement );
1726
1727 $operatorValue = in_array( $matchValue, $operatorValue );
1728 }
1729 break;
1730
1731 // Compare two arrays:
1732 case $this->CompareName:
1733 {
1734 $operatorValue = ( count( array_diff( $operatorValue, $namedParameters['compare'] ) ) == 0 and
1735 count( array_diff( $namedParameters['compare'], $operatorValue ) ) == 0 );
1736 }
1737 break;
1738
1739 // Extract a portion of the array:
1740 case $this->ExtractName:
1741 {
1742 if ( $namedParameters['extract_length'] === false )
1743 $operatorValue = array_slice( $operatorValue, $namedParameters['extract_start'] );
1744 else
1745 $operatorValue = array_slice( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] );
1746 }
1747 break;
1748
1749 // Extract a portion from the start of the array:
1750 case $this->ExtractLeftName:
1751 {
1752 $operatorValue = array_slice( $operatorValue, 0, $namedParameters['length'] );
1753 }break;
1754
1755 // Extract a portion from the end of the array:
1756 case $this->ExtractRightName:
1757 {
1758 $index = count( $operatorValue ) - $namedParameters['length'];
1759 $operatorValue = array_slice( $operatorValue, $index );
1760 }break;
1761
1762 // Check if the array begins with a given sequence:
1763 case $this->BeginsWithName:
1764 {
1765 for ( $i = 0; $i < count( $operatorParameters ); $i++ )
1766 {
1767 $test = $tpl->elementValue( $operatorParameters[$i],
1768 $rootNamespace,
1769 $currentNamespace,
1770 $placement );
1771
1772 if ( $operatorValue[$i] != $test )
1773 {
1774 $operatorValue = false;
1775 return;
1776 }
1777 }
1778
1779 $operatorValue = true;
1780 }break;
1781
1782 // Check if the array ends with a given sequence:
1783 case $this->EndsWithName:
1784 {
1785 $length = count( $operatorValue );
1786 $params = count( $operatorParameters );
1787
1788 $start = $length - $params;
1789
1790 for ( $i = 0; $i < $params; $i++ )
1791 {
1792 $test = $tpl->elementValue( $operatorParameters[$i],
1793 $rootNamespace,
1794 $currentNamespace,
1795 $placement );
1796
1797 if ( $operatorValue[$start+$i] != $test )
1798 {
1799 $operatorValue = false;
1800 return;
1801 }
1802 }
1803 $operatorValue = true;
1804 }break;
1805
1806 // Create a string containing the array elements with the separator string between elements.
1807 case $this->ImplodeName:
1808 {
1809 $operatorValue = implode( (string)$namedParameters['separator'], (array)$operatorValue );
1810 }break;
1811
1812 // Explode the array by making smaller arrays of it:
1813 case $this->ExplodeName:
1814 {
1815 $array_one = array();
1816 $array_two = array();
1817
1818 $array_one = array_slice( $operatorValue, 0, $namedParameters['explode_first'] );
1819 $array_two = array_slice( $operatorValue, $namedParameters['explode_first'] );
1820
1821 $operatorValue = array( $array_one, $array_two );
1822 }break;
1823
1824 // Repeat the contents of an array a specified number of times:
1825 case $this->RepeatName:
1826 {
1827 $arrayElement = $operatorValue;
1828 $count = $namedParameters['repeat_times'];
1829 $operatorValue = array();
1830 for ( $i = 0; $i < $count; $i++)
1831 {
1832 $operatorValue = array_merge( $operatorValue, $arrayElement );
1833 }
1834 }break;
1835
1836 // Reverse the contents of the array:
1837 case $this->ReverseName:
1838 {
1839 $operatorValue = array_reverse( $operatorValue );
1840 }break;
1841
1842 // Insert an array (or element) into a position in the target array:
1843 case $this->InsertName:
1844 {
1845 $array_one = array_slice( $operatorValue, 0, $namedParameters['insert_position'] );
1846 $array_two = array_slice( $operatorValue, $namedParameters['insert_position'] );
1847
1848
1849 $array_to_insert = array();
1850 for ( $i = 1; $i < count( $operatorParameters ); ++$i )
1851 {
1852 $array_to_insert[] = $tpl->elementValue( $operatorParameters[$i],
1853 $rootNamespace,
1854 $currentNamespace,
1855 $placement );
1856 }
1857
1858 $operatorValue = array_merge( $array_one, $array_to_insert, $array_two );
1859 }break;
1860
1861 // Remove a specified element (or portion) from the target array:
1862 case $this->RemoveName:
1863 {
1864 $array_one = array_slice( $operatorValue, 0, $namedParameters['offset'] );
1865 $array_two = array_slice( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
1866
1867 $operatorValue = array_merge( $array_one, $array_two );
1868 }break;
1869
1870 // Replace a portion of the array:
1871 case $this->ReplaceName:
1872 {
1873 $array_one = array_slice( $operatorValue, 0, $namedParameters['offset'] );
1874 $array_two = array_slice( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
1875 $array_mid = array();
1876
1877 for ( $i = 2; $i < count( $operatorParameters ); ++ $i )
1878 {
1879 $array_mid[] = $tpl->elementValue( $operatorParameters[$i],
1880 $rootNamespace,
1881 $currentNamespace,
1882 $placement );
1883 }
1884
1885 $operatorValue = array_merge( $array_one, $array_mid, $array_two );
1886 } break;
1887
1888 // Removes duplicate values from array:
1889 case $this->UniqueName:
1890 {
1891 $operatorValue = array_unique( $operatorValue );
1892 }break;
1893
1894 // Default case:
1895 default:
1896 {
1897 $tpl->warning( $operatorName, "Unknown operatorname: $operatorName", $placement );
1898 }
1899 break;
1900 }
1901 }
1902 else if ( is_string( $operatorValue ) )
1903 {
1904 switch( $operatorName )
1905 {
1906 // Not implemented.
1907 case $this->ArrayName:
1908 {
1909 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement );
1910 }break;
1911
1912 // Not implemented.
1913 case $this->HashName:
1914 {
1915 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement );
1916 }
1917 break;
1918
1919 // Add a string at the beginning of the input/target string:
1920 case $this->PrependName:
1921 {
1922 $operatorValue = $namedParameters['prepend_string'].$operatorValue;
1923 }break;
1924
1925 // Add a string at the end of the input/target string:
1926 case $this->AppendName:
1927 {
1928 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
1929 {
1930 $operatorValue .= $tpl->elementValue( $operatorParameters[$i],
1931 $rootNamespace,
1932 $currentNamespace,
1933 $placement );
1934 }
1935
1936 }break;
1937
1938 // Not implemented.
1939 case $this->MergeName:
1940 {
1941 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement );
1942 }break;
1943
1944 // Check if the string contains a specified sequence of chars/string.
1945 case $this->ContainsName:
1946 {
1947 $operatorValue = ( mb_strpos( $operatorValue, $namedParameters['match'] ) !== false );
1948 }
1949 break;
1950
1951 // Compare two strings:
1952 case $this->CompareName:
1953 {
1954 if ( strcmp( $operatorValue, $namedParameters['compare'] ) === 0 )
1955 {
1956 $operatorValue = true;
1957 }
1958 else
1959 {
1960 $operatorValue = false;
1961 }
1962 }
1963 break;
1964
1965 // Extract a portion from/of a string:
1966 case $this->ExtractName:
1967 {
1968 if ( $namedParameters['extract_length'] === false )
1969 $operatorValue = mb_substr( $operatorValue, $namedParameters['extract_start'] );
1970 else
1971 $operatorValue = mb_substr( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] );
1972 }
1973 break;
1974
1975 // Extract string/portion from the start of the string.
1976 case $this->ExtractLeftName:
1977 {
1978 $operatorValue = mb_substr( $operatorValue, 0, $namedParameters['length'] );
1979 }break;
1980
1981 // Extract string/portion from the end of the string.
1982 case $this->ExtractRightName:
1983 {
1984 $offset = mb_strlen( $operatorValue ) - $namedParameters['length'];
1985 $operatorValue = mb_substr( $operatorValue, $offset );
1986 }break;
1987
1988 // Check if string begins with specified sequence:
1989 case $this->BeginsWithName:
1990 {
1991 if ( mb_strpos( $operatorValue, $namedParameters['match'] ) === 0 )
1992 {
1993 $operatorValue = true;
1994 }
1995 else
1996 {
1997 $operatorValue = false;
1998 }
1999 }break;
2000
2001 // Check if string ends with specified sequence:
2002 case $this->EndsWithName:
2003 {
2004 if ( mb_strrpos( $operatorValue, $namedParameters['match'] ) === ( mb_strlen( $operatorValue ) - mb_strlen ($namedParameters['match'] ) ) )
2005 {
2006 $operatorValue = true;
2007 }
2008 else
2009 {
2010 $operatorValue = false;
2011 }
2012 }break;
2013
2014 // Only works with arrays.
2015 case $this->ImplodeName:
2016 {
2017 $tpl->warning( $operatorName, "$operatorName only works with arrays", $placement );
2018 }break;
2019
2020 // Explode string (split a string by string).
2021 case $this->ExplodeName:
2022 {
2023 $operatorValue = explode( $namedParameters['explode_first'], $operatorValue );
2024 }break;
2025
2026 // Repeat string n times:
2027 case $this->RepeatName:
2028 {
2029 $operatorValue = str_repeat( $operatorValue, $namedParameters['repeat_times'] );
2030 }break;
2031
2032 // Reverse contents of string:
2033 case $this->ReverseName:
2034 {
2035 $operatorValue = strrev( $operatorValue );
2036 }break;
2037
2038 // Insert a given string at a specified position:
2039 case $this->InsertName:
2040 {
2041 $first = mb_substr( $operatorValue, 0, $namedParameters['insert_position'] );
2042 $second = mb_substr( $operatorValue, $namedParameters['insert_position'] );
2043 $operatorValue = $first . $namedParameters['insert_string'] . $second;
2044 }break;
2045
2046 // Remove a portion from a string:
2047 case $this->RemoveName:
2048 {
2049 $first = mb_substr( $operatorValue, 0, $namedParameters['offset'] );
2050 $second = mb_substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
2051 $operatorValue = $first . $second;
2052 }break;
2053
2054 // Replace a portion of a string:
2055 case $this->ReplaceName:
2056 {
2057 $first = mb_substr( $operatorValue, 0, $namedParameters['offset'] );
2058 $second = mb_substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
2059 $mid = '';
2060
2061 for ( $i = 2; $i < count( $operatorParameters ); ++ $i )
2062 {
2063 $mid .= $tpl->elementValue( $operatorParameters[$i],
2064 $rootNamespace,
2065 $currentNamespace,
2066 $placement );
2067 }
2068
2069 $operatorValue = $first . $mid . $second;
2070 }break;
2071
2072 // Not implemented.
2073 case $this->UniqueName:
2074 {
2075 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement );
2076 }break;
2077
2078 // Default case:
2079 default:
2080 {
2081 $tpl->warning( $operatorName, "Unknown operatorname: $operatorName", $placement );
2082 }
2083 break;
2084 }
2085 }
2086 // ..or something else? -> We're building the array:
2087 else
2088 {
2089 $operatorValue = array();
2090 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
2091 {
2092 $operatorValue[] = $tpl->elementValue( $operatorParameters[$i],
2093 $rootNamespace,
2094 $currentNamespace,
2095 $placement );
2096 }
2097 }
2098 }
2099
2101 public $Operators;
2102 public $ArrayName;
2103 public $HashName;
2104 public $ArrayPrependName;
2105 public $PrependName;
2106 public $ArrayAppendName;
2107 public $AppendName;
2108 public $ArrayMergeName;
2109 public $MergeName;
2110 public $ContainsName;
2111 public $CompareName;
2112 public $ExtractName;
2113 public $ExtractLeftName;
2114 public $ExtractRightName;
2115 public $BeginsWithName;
2116 public $EndsWithName;
2117 public $ImplodeName;
2118 public $ExplodeName;
2119 public $RepeatName;
2120 public $ReverseName;
2121 public $InsertName;
2122 public $RemoveName;
2123 public $ReplaceName;
2124 public $UniqueName;
2125 public $ArraySumName;
2126 }
2127
2128 ?>
eZTemplateArrayOperator
Dynamic creation of arrays using operator "array".
Definition: eztemplatearrayoperator.php:28
eZTemplateArrayOperator\$EndsWithName
$EndsWithName
Definition: eztemplatearrayoperator.php:2116
eZTemplateArrayOperator\$InsertName
$InsertName
Definition: eztemplatearrayoperator.php:2121
eZTemplateArrayOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplatearrayoperator.php:113
eZTemplateArrayOperator\$AppendName
$AppendName
Definition: eztemplatearrayoperator.php:2107
eZTemplateArrayOperator\$Operators
$Operators
Definition: eztemplatearrayoperator.php:2101
eZTemplateArrayOperator\$ExtractRightName
$ExtractRightName
Definition: eztemplatearrayoperator.php:2114
eZTemplateArrayOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztemplatearrayoperator.php:1560
eZTemplateArrayOperator\$ContainsName
$ContainsName
Definition: eztemplatearrayoperator.php:2110
eZTemplateArrayOperator\compareTrans
compareTrans( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearrayoperator.php:1028
eZTemplateArrayOperator\$ArrayMergeName
$ArrayMergeName
Definition: eztemplatearrayoperator.php:2108
eZTemplateArrayOperator\arrayTrans
arrayTrans( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearrayoperator.php:279
eZTemplateArrayOperator\$ExtractLeftName
$ExtractLeftName
Definition: eztemplatearrayoperator.php:2113
eZTemplateArrayOperator\mergeTrans
mergeTrans( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearrayoperator.php:1322
eZTemplateArrayOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplatearrayoperator.php:1495
eZTemplateArrayOperator\$HashName
$HashName
Definition: eztemplatearrayoperator.php:2103
eZTemplateArrayOperator\$PrependName
$PrependName
Definition: eztemplatearrayoperator.php:2105
eZTemplateArrayOperator\extractTrans
extractTrans( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearrayoperator.php:1219
eZTemplateArrayOperator\$ArraySumName
$ArraySumName
Definition: eztemplatearrayoperator.php:2125
eZTemplateArrayOperator\$ArrayPrependName
$ArrayPrependName
Definition: eztemplatearrayoperator.php:2104
eZTemplateArrayOperator\$ImplodeName
$ImplodeName
Definition: eztemplatearrayoperator.php:2117
eZTemplateArrayOperator\$BeginsWithName
$BeginsWithName
Definition: eztemplatearrayoperator.php:2115
eZTemplateArrayOperator\$UniqueName
$UniqueName
Definition: eztemplatearrayoperator.php:2124
eZTemplateArrayOperator\$ArrayAppendName
$ArrayAppendName
Definition: eztemplatearrayoperator.php:2106
eZTemplateArrayOperator\$ReverseName
$ReverseName
Definition: eztemplatearrayoperator.php:2120
eZTemplateArrayOperator\$MergeName
$MergeName
Definition: eztemplatearrayoperator.php:2109
eZTemplateArrayOperator\$ExplodeName
$ExplodeName
Definition: eztemplatearrayoperator.php:2118
eZTemplateArrayOperator\$ReplaceName
$ReplaceName
Definition: eztemplatearrayoperator.php:2123
eZTemplateArrayOperator\$ArrayName
$ArrayName
Definition: eztemplatearrayoperator.php:2102
eZTemplateArrayOperator\__construct
__construct( $arrayName='array', $hashName='hash', $arrayPrependName='array_prepend', $prependName='prepend', $arrayAppendName='array_append', $appendName='append', $arrayMergeName='array_merge', $mergeName='merge', $containsName='contains', $compareName='compare', $extractName='extract', $extractLeftName='extract_left', $extractRightName='extract_right', $beginsWithName='begins_with', $endsWithName='ends_with', $implodeName='implode', $explodeName='explode', $repeatName='repeat', $reverseName='reverse', $insertName='insert', $removeName='remove', $replaceName='replace', $uniqueName='unique', $arraySumName='array_sum')
Definition: eztemplatearrayoperator.php:29
eZTemplateArrayOperator\operatorList
operatorList()
Definition: eztemplatearrayoperator.php:108
eZTemplateArrayOperator\$RemoveName
$RemoveName
Definition: eztemplatearrayoperator.php:2122
eZTemplateArrayOperator\$ExtractName
$ExtractName
Definition: eztemplatearrayoperator.php:2112
eZTemplateArrayOperator\$RepeatName
$RepeatName
Definition: eztemplatearrayoperator.php:2119
eZTemplateArrayOperator\$CompareName
$CompareName
Definition: eztemplatearrayoperator.php:2111
eZTemplateArrayOperator\namedParameterList
namedParameterList()
Definition: eztemplatearrayoperator.php:1502
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateNodeTool\createNumericElement
static createNumericElement( $number, $variablePlacement=false)
Definition: eztemplatenodetool.php:89
eZTemplateNodeTool\createConstantElement
static createConstantElement( $constant, $variablePlacement=false)
Definition: eztemplatenodetool.php:61
eZTemplateNodeTool\createBooleanElement
static createBooleanElement( $boolean, $variablePlacement=false)
Definition: eztemplatenodetool.php:133
eZTemplateNodeTool\createStringElement
static createStringElement( $string, $variablePlacement=false)
Definition: eztemplatenodetool.php:79
eZTemplateNodeTool\createArrayElement
static createArrayElement( $array, $variablePlacement=false)
Definition: eztemplatenodetool.php:123
eZTemplateNodeTool\createDynamicArrayElement
static createDynamicArrayElement(&$arrayKeys, &$arrayValues, $variablePlacement=false)
Definition: eztemplatenodetool.php:113
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.