Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezobjectforwarder.php
Go to the documentation of this file.
1 <?php
17 class eZObjectForwarder
18 {
24 public function __construct( $rules )
25 {
26 $this->Rules = $rules;
27 }
28
29 function functionList()
30 {
31 return array_keys( $this->Rules );
32 }
33
34 function functionTemplateHints()
35 {
36 $hints = array();
37 foreach ( $this->Rules as $name => $data )
38 {
39 $hints[$name] = array( 'parameters' => true,
40 'static' => false,
41 'transform-children' => true,
42 'tree-transformation' => true,
43 'transform-parameters' => true );
44 }
45 return $hints;
46 }
47
48 function templateNodeTransformation( $functionName, &$node,
49 $tpl, $parameters, $privateData )
50 {
51 if ( !isset( $this->Rules[$functionName] ) )
52 return false;
53 $rule = $this->Rules[$functionName];
54 $resourceData = $privateData['resource-data'];
55
56 $parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node );
57 $inputName = $rule['input_name'];
58 if ( !isset( $parameters[$inputName] ) )
59 {
60 return false;
61 }
62 $inputData = $parameters[$inputName];
63 $outputName = $rule['output_name'];
64
65 $newNodes = array();
66
67 $viewDir = '';
68 $renderMode = false;
69 if ( isset( $rule["render_mode"] ) )
70 {
71 $renderMode = $rule["render_mode"];
72 }
73 if ( isset( $parameters['render-mode'] ) )
74 {
75 $renderData = $parameters['render-mode'];
76 if ( !eZTemplateNodeTool::isConstantElement( $renderData ) )
77 {
78 return false;
79 }
80 $renderMode = eZTemplateNodeTool::elementConstantValue( $renderData );
81 }
82 if ( $renderMode )
83 $view_dir .= "/render-$renderMode";
84
85 $viewValue = false;
86 $viewName = false;
87 if ( $rule['use_views'] )
88 {
89 $viewName = $rule['use_views'];
90 if ( isset( $parameters[$viewName] ) )
91 {
92 $viewData = $parameters[$viewName];
93 if ( !eZTemplateNodeTool::isConstantElement( $viewData ) )
94 {
95 return false;
96 }
97 $viewValue = eZTemplateNodeTool::elementConstantValue( $viewData );
98 $viewDir .= '/' . $viewValue;
99 }
100 else
101 {
102 if ( !( isset( $rule['optional_views'] ) && $rule['optional_views'] ) )
103 {
104 return false;
105 }
106 }
107 }
108
109 $namespaceValue = false;
110 if ( isset( $rule['namespace'] ) )
111 {
112 $namespaceValue = $rule['namespace'];
113 }
114
115 $variableList = array();
116
117 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $inputData, false, array(),
118 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $outputName ) );
119 $variableList[] = $outputName;
120
121 foreach ( array_keys( $parameters ) as $parameterName )
122 {
123 if ( $parameterName == $inputName or
124 $parameterName == $outputName or
125 $parameterName == $viewName )
126 continue;
127
128 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters[$parameterName], false, array(),
129 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName ) );
130 $variableList[] = $parameterName;
131 }
132
133 $templateRoot = $rule["template_root"];
134 $matchFileArray = eZTemplateDesignResource::overrideArray();
135
136 if ( is_string( $templateRoot ) )
137 {
138 $resourceNodes = $this->resourceAcquisitionTransformation( $functionName, $node, $rule, $inputData,
139 $outputName, $namespaceValue,
140 $templateRoot, $viewDir, $viewValue,
141 $matchFileArray, 0, $resourceData );
142 // If the transformation failed we return false to invoke interpreted mode
143 if ( $resourceNodes === false )
144 return false;
145 $newNodes = array_merge( $newNodes, $resourceNodes );
146 }
147 else
148 {
149 if ( isset( $templateRoot['type'] ) and
150 $templateRoot['type'] == 'multi_match' and
151 isset( $templateRoot['attributes'] ) and
152 isset( $templateRoot['matches'] ) )
153 {
154 $attributeAccessData = array();
155 $attributeAccessData[] = eZTemplateNodeTool::createVariableElement( $outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE );
156 foreach ( $templateRoot['attributes'] as $rootAttributeName )
157 {
158 $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $rootAttributeName );
159 }
160 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false,
161 array( 'spacing' => 0 ), 'templateRootMatch' );
162 $rootMatchCounter = 0;
163 foreach ( $templateRoot['matches'] as $rootMatch )
164 {
165 $templateRoot = $rootMatch[1];
166
167 if ( is_array( $templateRoot ) )
168 {
169 $templateRoot = $templateRoot[0];
170 }
171
172 $resourceNodes = $this->resourceAcquisitionTransformation( $functionName, $node, $rule, $inputData,
173 $outputName, $namespaceValue,
174 $templateRoot, $viewDir, $viewValue,
175 $matchFileArray, 4, $resourceData );
176
177 // If this transformation failed we continue to the next root match
178 if ( $resourceNodes === false )
179 continue;
180
181 $rootMatchValueText = eZPHPCreator::variableText( $rootMatch[0], 0, 0, false );
182 $code = '';
183 if ( $rootMatchCounter > 0 )
184 {
185 $code .= "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "";
186 }
187 $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( \$templateRootMatch == $rootMatchValueText )\n{";
188 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code );
189 $newNodes = array_merge( $newNodes, $resourceNodes );
190 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" );
191 ++$rootMatchCounter;
192 }
193
194 // If the transformation failed we invoke interpreted mode
195 if ( $rootMatchCounter == 0 )
196 {
197 return false;
198 }
199
200 $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'templateRootMatch' );
201 }
202 }
203
204 foreach ( $variableList as $variableName )
205 {
206 $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName ) );
207 }
208
209 return $newNodes;
210 }
211
212 function resourceAcquisitionTransformation( $functionName, &$node, $rule, $inputData,
213 $outputName, $namespaceValue,
214 $templateRoot, $viewDir, $viewValue,
215 $matchFileArray, $acquisitionSpacing,
216 &$resourceData )
217 {
218 $startRoot = '/' . $templateRoot . $viewDir;
219 $viewFileMatchName = '/' . $templateRoot . '/' . $viewValue . '.tpl';
220 $startRootLength = strlen( $startRoot );
221 $matchList = array();
222 $viewFileMatch = null;
223 foreach ( $matchFileArray as $matchFile )
224 {
225 if ( !isset( $matchFile['template'] ) )
226 continue;
227
228 $path = $matchFile['template'];
229 if ( substr( $path, 0, $startRootLength ) == $startRoot and
230 $path[$startRootLength] == '/' )
231 {
232 $matchFile['match_part'] = substr( $path, $startRootLength + 1 );
233 $matchList[] = $matchFile;
234 }
235 if ( $path == $viewFileMatchName )
236 $viewFileMatch = $matchFile;
237 }
238 $designKeysName = 'dKeys';
239 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" .
240 "{\n" .
241 " \$resH = \$tpl->resourceHandler( 'design' );\n" .
242 " \$$designKeysName = \$resH->keys();\n" .
243 "}", array( 'spacing' => $acquisitionSpacing ) );
244 if ( isset( $rule["attribute_keys"] ) )
245 {
246 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$" . $designKeysName . "Stack ) )\n" .
247 "{\n" .
248 " \$" . $designKeysName . "Stack = array();\n" .
249 "}\n" .
250 "\$" . $designKeysName . "Stack[] = \$$designKeysName;",
251 array( 'spacing' => $acquisitionSpacing ) );
252 foreach ( $rule["attribute_keys"] as $designKey => $attributeKeyArray )
253 {
254 $attributeAccessData = array();
255 $attributeAccessData[] = eZTemplateNodeTool::createVariableElement( $outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE );
256 foreach ( $attributeKeyArray as $attributeKey )
257 {
258 $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeKey );
259 }
260 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false,
261 array( 'spacing' => 0 ), 'dKey' );
262 $designKeyText = eZPHPCreator::variableText( $designKey, 0, 0, false );
263 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $designKeysName . "[$designKeyText] = \$dKey;",
264 array( 'spacing' => $acquisitionSpacing ) );
265 $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'dKey' );
266 }
267 }
268
269 $attributeAccess = $rule["attribute_access"];
270
271 $hasAttributeAccess = false;
272 if ( is_array( $attributeAccess ) )
273 {
274 $hasAttributeAccess = count( $attributeAccess ) > 0;
275 $attributeAccessCount = 0;
276 foreach ( $attributeAccess as $attributeAccessEntries )
277 {
278 $attributeAccessData = $inputData;
279 $spacing = $acquisitionSpacing;
280 if ( $attributeAccessCount > 1 )
281 {
282 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " if ( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) );
283 $spacing += 4;
284 }
285 else if ( $attributeAccessCount > 0 )
286 {
287 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) );
288 $spacing += 4;
289 }
290 foreach ( $attributeAccessEntries as $attributeAccessName )
291 {
292 // $attributeAccessData[] = eZTemplateNodeTool::createCodePieceNode( "" . ( $resourceData['use-comments'] ? ( "/*TC:" . __LINE__ . "*/" ) : "" ) . "" );
293 $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeAccessName );
294 }
295 $accessNodes = array();
296 $accessNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false,
297 array( 'spacing' => $spacing ), 'attributeAccess' );
298
299 $acquisitionNodes = array();
300 $templateCounter = 0;
301 $hasAcquisitionNodes = false;
302 $matchLookupArray = array();
303 foreach ( $matchList as $matchItem )
304 {
305 $tmpAcquisitionNodes = array();
306 $matchPart = $matchItem['match_part'];
307 if ( preg_match( "/^(.+)\.tpl$/", $matchPart, $matches ) )
308 $matchPart = $matches[1];
309 $code = "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( \$attributeAccess == '$matchPart' )\n{\n";
310 if ( $templateCounter > 0 )
311 $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "" . $code;
312 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $spacing ) );
313
314 $defaultMatchSpacing = $spacing;
315 $useArrayLookup = false;
316 $addFileResource = true;
317 if ( isset( $matchItem['custom_match'] ) )
318 {
319 $customSpacing = $spacing + 4;
320 $defaultMatchSpacing = $spacing + 4;
321 $matchCount = 0;
322 foreach ( $matchItem['custom_match'] as $customMatch )
323 {
324 if( is_null( $customMatch['conditions'] ) )
325 {
326 $customMatch['conditions'] = array();
327 }
328 $matchConditionCount = count( $customMatch['conditions'] );
329 $code = '';
330 if ( $matchCount > 0 )
331 {
332 $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "";
333 }
334 if ( $matchConditionCount > 0 )
335 {
336 if ( $matchCount > 0 )
337 $code .= " ";
338 $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( ";
339 }
340 $ifLength = strlen( $code );
341 $conditionCount = 0;
342 if ( isset( $customMatch['conditions'] ) )
343 {
344 foreach ( $customMatch['conditions'] as $conditionName => $conditionValue )
345 {
346 if ( $conditionCount > 0 )
347 $code .= " and\n" . str_repeat( ' ', $ifLength );
348 $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 );
349 $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 );
350
351 $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and ";
352 if ( $conditionNameText == '"url_alias"' )
353 {
354 $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )";
355 }
356 else
357 {
358 $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " .
359 "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " .
360 "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )";
361 }
362 ++$conditionCount;
363 }
364 }
365 if ( $matchConditionCount > 0 )
366 {
367 $code .= " )\n";
368 }
369 if ( $matchConditionCount > 0 or $matchCount > 0 )
370 {
371 $code .= "{";
372 }
373 $matchFile = $customMatch['match_file'];
374 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $customSpacing ) );
375 $hasAcquisitionNodes = true;
376 // If $matchFile is an array we cannot create a transformation for this entry
377 if ( is_array( $matchFile ) )
378 return false;
379 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
380 $matchFile, $matchFile,
381 eZTemplate::RESOURCE_FETCH, false,
382 $node[4], array( 'spacing' => $customSpacing + 4 ),
383 $rule['namespace'] );
384 if ( $matchConditionCount > 0 or $matchCount > 0 )
385 {
386 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) );
387 }
388 ++$matchCount;
389 if ( $matchConditionCount == 0 )
390 {
391 $addFileResource = false;
392 break;
393 }
394 }
395 if ( $addFileResource )
396 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " \n{", array( 'spacing' => $customSpacing ) );
397 }
398 else
399 {
400 $matchFile = $matchItem['base_dir'] . $matchItem['template'];
401 $matchLookupArray[$matchPart] = $matchFile;
402 $useArrayLookup = true;
403 }
404
405 if ( !$useArrayLookup )
406 {
407 if ( $addFileResource )
408 {
409 $matchFile = $matchItem['base_dir'] . $matchItem['template'];
410 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
411 $matchFile, $matchFile,
412 eZTemplate::RESOURCE_FETCH, false,
413 $node[4], array( 'spacing' => $defaultMatchSpacing + 4 ),
414 $rule['namespace'] );
415 $hasAcquisitionNodes = true;
416 if ( isset( $matchItem['custom_match'] ) )
417 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) );
418 }
419 ++$templateCounter;
420 $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) );
421 $acquisitionNodes = array_merge( $acquisitionNodes, $tmpAcquisitionNodes );
422 }
423 }
424
425 if ( count( $matchLookupArray ) > 0 )
426 {
427 $newNodes = array_merge( $newNodes, $accessNodes );
428 $accessNodes = array();
429 // If $matchFile is an array we cannot create a transformation for this entry
430 if ( is_array( $matchLookupArray ) )
431 return false;
432 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
433 $matchLookupArray, false,
434 eZTemplate::RESOURCE_FETCH, false,
435 $node[4], array( 'spacing' => $spacing ),
436 $rule['namespace'], 'attributeAccess' );
437 if ( $hasAcquisitionNodes )
438 {
439 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $spacing ) );
440 $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
441 }
442 }
443 if ( $hasAcquisitionNodes )
444 {
445 $newNodes = array_merge( $newNodes, $accessNodes, $acquisitionNodes );
446
447 if ( $attributeAccessCount > 0 )
448 {
449 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) );
450 }
451 ++$attributeAccessCount;
452 }
453 else if ( count( $matchLookupArray ) == 0 )
454 {
455 $newNodes[] = eZTemplateNodeTool::createErrorNode( "Failed to load template",
456 $functionName,
457 eZTemplateNodeTool::extractFunctionNodePlacement( $node ),
458 array( 'spacing' => $acquisitionSpacing ) );
459 }
460 if ( count( $matchLookupArray ) > 0 and $hasAcquisitionNodes )
461 {
462 $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
463 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) );
464 }
465 }
466 }
467 if ( $viewFileMatch !== null )
468 {
469 $mainSpacing = 0;
470 if ( $hasAttributeAccess )
471 {
472 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{\n", array( 'spacing' => $acquisitionSpacing ) );
473 $mainSpacing = 4;
474 }
475 $templateCounter = 0;
476
477
478 $addFileResource = true;
479 if ( isset( $viewFileMatch['custom_match'] ) )
480 {
481 $spacing = $mainSpacing + 4;
482 $matchCount = 0;
483 foreach ( $viewFileMatch['custom_match'] as $customMatch )
484 {
485 $matchConditionCount = is_countable( $customMatch['conditions'] ) && count( $customMatch['conditions'] );
486 $code = '';
487 if ( $matchCount > 0 )
488 {
489 $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "";
490 }
491 if ( $matchConditionCount > 0 )
492 {
493 if ( $matchCount > 0 )
494 $code .= " ";
495 $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( ";
496
497 $ifLength = strlen( $code );
498 $conditionCount = 0;
499
500 if ( is_array( $customMatch['conditions'] ) )
501 {
502 foreach ( $customMatch['conditions'] as $conditionName => $conditionValue )
503 {
504 if ( $conditionCount > 0 )
505 $code .= " and\n" . str_repeat( ' ', $ifLength );
506 $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 );
507 $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 );
508
509 $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and ";
510 if ( $conditionNameText == '"url_alias"' )
511 {
512 $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )";
513 }
514 else
515 {
516 $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " .
517 "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " .
518 "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )";
519 }
520 ++$conditionCount;
521 }
522 }
523 $code .= " )\n";
524 }
525 if ( $matchConditionCount > 0 or $matchCount > 0 )
526 {
527 $code .= "{";
528 }
529 $matchFile = $customMatch['match_file'];
530 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $acquisitionSpacing ) );
531 // If $matchFile is an array we cannot create a transformation for this entry
532 if ( is_array( $matchFile ) )
533 return false;
534 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
535 $matchFile, $matchFile,
536 eZTemplate::RESOURCE_FETCH, false,
537 $node[4], array( 'spacing' => $spacing ),
538 $rule['namespace'] );
539 if ( $matchConditionCount > 0 or $matchCount > 0 )
540 {
541 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) );
542 }
543 ++$matchCount;
544 if ( $matchConditionCount == 0 )
545 {
546 if ( $matchCount > 0 )
547 $addFileResource = false;
548 break;
549 }
550 }
551 if ( $addFileResource )
552 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $acquisitionSpacing ) );
553 }
554 if ( $addFileResource )
555 {
556 $file = $viewFileMatch['base_dir'] . $viewFileMatch['template'];
557 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
558 $file, $file,
559 eZTemplate::RESOURCE_FETCH, false,
560 $node[4], array( 'spacing' => $mainSpacing ),
561 $rule['namespace'] );
562 }
563 if ( isset( $viewFileMatch['custom_match'] ) and $addFileResource )
564 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) );
565
566 if ( $hasAttributeAccess )
567 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}\n", array( 'spacing' => $acquisitionSpacing ) );
568 }
569 if ( isset( $rule["attribute_keys"] ) )
570 {
571 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$designKeysName = array_pop( \$" . $designKeysName . "Stack );",
572 array( 'spacing' => $acquisitionSpacing ) );
573 }
574 return $newNodes;
575 }
576
577 function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
578 {
579 if ( !isset( $this->Rules[$functionName] ) )
580 {
581 $tpl->undefinedFunction( $functionName );
582 return;
583 }
584 $rule = $this->Rules[$functionName];
585 $template_dir = $rule["template_root"];
586 $input_name = $rule["input_name"];
587 $outCurrentNamespace = $currentNamespace;
588 if ( isset( $rule['namespace'] ) )
589 {
590 $ruleNamespace = $rule['namespace'];
591 if ( $ruleNamespace != '' )
592 {
593 if ( $outCurrentNamespace != '' )
594 $outCurrentNamespace .= ':' . $ruleNamespace;
595 else
596 $outCurrentNamespace = $ruleNamespace;
597 }
598 }
599
600 $params = $functionParameters;
601 if ( !isset( $params[$input_name] ) )
602 {
603 $tpl->missingParameter( $functionName, $input_name );
604 return;
605 }
606
607 $old_nspace = $rootNamespace;
608
609 $input_var = $tpl->elementValue( $params[$input_name], $rootNamespace, $currentNamespace, $functionPlacement );
610 if ( !is_object( $input_var ) )
611 {
612 $tpl->warning( $functionName, "Parameter $input_name is not an object", $functionPlacement );
613 return;
614 }
615
616 $txt = "";
617 $attributeAccess = $rule["attribute_access"];
618 $view_mode = "";
619 $view_dir = "";
620 $view_var = null;
621 $renderMode = false;
622 if ( isset( $rule["render_mode"] ) )
623 {
624 $renderMode = $rule["render_mode"];
625 }
626 if ( isset( $params['render-mode'] ) )
627 {
628 $renderMode = $tpl->elementValue( $params['render-mode'], $rootNamespace, $currentNamespace, $functionPlacement );
629 }
630 if ( $renderMode )
631 $view_dir .= "/render-$renderMode";
632 if ( $rule["use_views"] )
633 {
634 $view_var = $rule["use_views"];
635 if ( !isset( $params[$view_var] ) )
636 {
637 if ( !isset( $rule['optional_views'] ) or
638 !$rule['optional_views'] )
639 $tpl->warning( $functionName, "No view specified, skipping views" );
640 }
641 else
642 {
643 $view_mode = $tpl->elementValue( $params[$view_var], $rootNamespace, $currentNamespace, $functionPlacement );
644 $view_dir .= "/" . $view_mode;
645 }
646 }
647
648 $resourceKeys = false;
649 if ( isset( $rule['attribute_keys'] ) )
650 {
651 $resourceKeys = array();
652 foreach( $rule['attribute_keys'] as $attributeKey => $attributeSelection )
653 {
654 $resourceKeys[] = array( $attributeKey, $tpl->variableAttribute( $input_var, $attributeSelection ) );
655 }
656 }
657
658 $triedFiles = array();
659 $extraParameters = array();
660 if ( $resourceKeys !== false )
661 $extraParameters['ezdesign:keys'] = $resourceKeys;
662 if ( is_array( $template_dir ) )
663 {
664 $templateRoot = $template_dir;
665 $template_dir = '';
666 if ( !isset( $templateRoot['type'] ) )
667 $tpl->error( $functionName,
668 'No template root type defined' );
669 else if ( $templateRoot['type'] == 'multi_match' )
670 {
671 if ( !isset( $templateRoot['attributes'] ) )
672 $tpl->error( $functionName,
673 'No template root attributes defined' );
674 else if ( !isset( $templateRoot['matches'] ) )
675 $tpl->error( $functionName,
676 'No template root matches defined' );
677 else
678 {
679 $templateRootValue = $tpl->variableAttribute( $input_var, $templateRoot['attributes'] );
680 foreach ( $templateRoot['matches'] as $templateRootMatch )
681 {
682 if ( $templateRootMatch[0] == $templateRootValue )
683 {
684 $template_dir = $templateRootMatch[1];
685 if ( is_array( $template_dir ) )
686 {
687 $template_dir = $template_dir[0];
688 $attributeValues = array();
689 foreach ( $template_dir[1] as $templateDirAttributes )
690 {
691 $attributeValues[] = $tpl->variableAttribute( $input_var, $templateDirAttributes );
692 }
693 $template_dir .= implode( '/', $attributeValues );
694 }
695 break;
696 }
697 }
698 }
699 }
700 else
701 $tpl->error( $functionName,
702 'Unknown template root type: ' . $templateRoot['type'] );
703 }
704
705 $resourceData = null;
706 if ( is_array( $attributeAccess ) )
707 {
708 foreach( $attributeAccess as $attributeAccessArray )
709 {
710 $incfile = $tpl->variableAttribute( $input_var, $attributeAccessArray );
711 $uri = "design:$template_dir$view_dir/$incfile.tpl";
712 $resourceData = $tpl->loadURIRoot( $uri, false, $extraParameters );
713 if ( $resourceData === null )
714 $triedFiles[] = $uri;
715 else
716 break;
717 }
718 if ( $resourceData === null )
719 {
720 $uri = "design:$template_dir/$view_mode.tpl";
721 $resourceData = $tpl->loadURIRoot( $uri, false, $extraParameters );
722 if ( $resourceData === null )
723 $triedFiles[] = $uri;
724 }
725 }
726
727 if ( $resourceData !== null )
728 {
729 $designUsedKeys = array();
730 $designMatchedKeys = array();
731 if ( isset( $extraParameters['ezdesign:used_keys'] ) )
732 $designUsedKeys = $extraParameters['ezdesign:used_keys'];
733 if ( isset( $extraParameters['ezdesign:matched_keys'] ) )
734 $designMatchedKeys = $extraParameters['ezdesign:matched_keys'];
735 if ( $outCurrentNamespace != '' )
736 $designKeyNamespace = $outCurrentNamespace . ':DesignKeys';
737 else
738 $designKeyNamespace = 'DesignKeys';
739
740 $sub_text = "";
741 $setVariableArray = array();
742 $tpl->setVariable( $rule["output_name"], $input_var, $outCurrentNamespace, true );
743 $setVariableArray[] = $rule["output_name"];
744 // Set design keys
745 $tpl->setVariable( 'used', $designUsedKeys, $designKeyNamespace );
746 $tpl->setVariable( 'matched', $designMatchedKeys, $designKeyNamespace );
747 // Set function parameters
748 foreach ( array_keys( $params ) as $paramName )
749 {
750 if ( $paramName == $input_name or
751 $paramName == $view_var )
752 {
753 continue;
754 }
755
756 $tpl->setVariable(
757 $paramName,
758 $tpl->elementValue( $params[$paramName], $old_nspace, $currentNamespace, $functionPlacement ),
759 $outCurrentNamespace,
760 true
761 );
762 $setVariableArray[] = $paramName;
763 }
764 // Set constant variables
765 if ( isset( $rule['constant_template_variables'] ) )
766 {
767 foreach ( $rule['constant_template_variables'] as $constantTemplateVariableKey => $constantTemplateVariableValue )
768 {
769 if ( $constantTemplateVariableKey == $input_name or
770 $constantTemplateVariableKey == $view_var or
771 $tpl->hasVariable( $constantTemplateVariableKey, $currentNamespace ) )
772 continue;
773 $tpl->setVariable( $constantTemplateVariableKey, $constantTemplateVariableValue, $outCurrentNamespace, true );
774 $setVariableArray[] = $constantTemplateVariableKey;
775 }
776 }
777
778 $templateCompilationUsed = false;
779 if ( $resourceData['compiled-template'] )
780 {
781 if ( $tpl->executeCompiledTemplate( $resourceData, $textElements, $outCurrentNamespace, $outCurrentNamespace, $extraParameters ) )
782 $templateCompilationUsed = true;
783 }
784 if ( !$templateCompilationUsed and
785 $resourceData['root-node'] )
786 {
787 $tpl->process( $resourceData['root-node'], $sub_text, $outCurrentNamespace, $outCurrentNamespace );
788 $tpl->setIncludeOutput( $uri, $sub_text );
789
790 $textElements[] = $sub_text;
791 }
792 foreach ( $setVariableArray as $setVariableName )
793 {
794 $tpl->unsetVariable( $setVariableName, $outCurrentNamespace );
795 }
796 }
797 else
798 {
799 $tpl->warning( $functionName,
800 "None of the templates " . implode( ", ", $triedFiles ) .
801 " could be found" );
802 }
803 }
804
805 function hasChildren()
806 {
807 return false;
808 }
809
810 public $Rules;
811 }
812
813 ?>
eZObjectForwarder
The class eZObjectForwarder does.
Definition: ezobjectforwarder.php:18
eZObjectForwarder\process
process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
Definition: ezobjectforwarder.php:577
eZObjectForwarder\$Rules
$Rules
Definition: ezobjectforwarder.php:810
eZObjectForwarder\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, $parameters, $privateData)
Definition: ezobjectforwarder.php:48
eZObjectForwarder\hasChildren
hasChildren()
Definition: ezobjectforwarder.php:805
eZObjectForwarder\functionTemplateHints
functionTemplateHints()
Definition: ezobjectforwarder.php:34
eZObjectForwarder\__construct
__construct( $rules)
Definition: ezobjectforwarder.php:24
eZObjectForwarder\functionList
functionList()
Definition: ezobjectforwarder.php:29
eZObjectForwarder\resourceAcquisitionTransformation
resourceAcquisitionTransformation( $functionName, &$node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, $acquisitionSpacing, &$resourceData)
Definition: ezobjectforwarder.php:212
eZTemplateDesignResource\overrideArray
static overrideArray( $siteAccess=false)
Definition: eztemplatedesignresource.php:828
eZTemplateNodeTool\createVariableNode
static createVariableNode( $originalNode=false, $variableData=false, $variablePlacement=false, $parameters=array(), $variableAssignmentName=false, $onlyExisting=false, $overWrite=true, $assignFromVariable=false, $rememberSet=false)
Definition: eztemplatenodetool.php:395
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createSpacingDecreaseNode
static createSpacingDecreaseNode( $spacing=4, $parameters=array())
Definition: eztemplatenodetool.php:508
eZTemplateNodeTool\createVariableUnsetNode
static createVariableUnsetNode( $variableName, $parameters=array())
Definition: eztemplatenodetool.php:462
eZTemplateNodeTool\createCodePieceNode
static createCodePieceNode( $codePiece, $parameters=array())
Definition: eztemplatenodetool.php:457
eZTemplateNodeTool\createSpacingIncreaseNode
static createSpacingIncreaseNode( $spacing=4, $parameters=array())
Definition: eztemplatenodetool.php:503
eZTemplateNodeTool\createAttributeLookupElement
static createAttributeLookupElement( $attributeValues=array(), $variablePlacement=false)
Definition: eztemplatenodetool.php:170
eZTemplateNodeTool\extractFunctionNodePlacement
static extractFunctionNodePlacement(&$node)
Definition: eztemplatenodetool.php:660
eZTemplateNodeTool\extractFunctionNodeParameters
static extractFunctionNodeParameters(&$node)
Definition: eztemplatenodetool.php:678
eZTemplateNodeTool\createResourceAcquisitionNode
static createResourceAcquisitionNode( $resourceName, $templateName, $fileName, $method, $extraParameters, $placement=false, $parameters=array(), $newRootNamespace=false, $resourceVariableName=false)
Definition: eztemplatenodetool.php:527
eZTemplateNodeTool\createVariableElement
static createVariableElement( $variableName, $namespaceName, $namespaceScope=eZTemplate::NAMESPACE_SCOPE_LOCAL, $variablePlacement=false)
Definition: eztemplatenodetool.php:159
eZTemplateNodeTool\createErrorNode
static createErrorNode( $text, $label, $placement=false, $parameters=array())
Definition: eztemplatenodetool.php:452
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
eZTemplate\NAMESPACE_SCOPE_RELATIVE
const NAMESPACE_SCOPE_RELATIVE
Definition: eztemplate.php:286
eZTemplate\RESOURCE_FETCH
const RESOURCE_FETCH
Definition: eztemplate.php:200
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.