Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatedesignresource.php
Go to the documentation of this file.
1 <?php
17 class eZTemplateDesignResource extends eZTemplateFileResource
18 {
19 const DESIGN_BASE_CACHE_NAME = 'designbase_';
20
28 protected static $overrideArrayCache = null;
29
35 public function __construct( $name = "design" )
36 {
37 parent::__construct( $name, true );
38 $this->Keys = array();
39 $this->KeyStack = array();
40 }
41
42 function templateNodeTransformation( $functionName, &$node,
43 $tpl, &$resourceData, $parameters, $namespaceValue )
44 {
45 if ( $this->Name != 'design' and $this->Name != 'standard' )
46 return false;
47
48 $file = $resourceData['template-name'];
49 $matchFileArray = eZTemplateDesignResource::overrideArray( $this->OverrideSiteAccess );
50 $matchList = array();
51 foreach ( $matchFileArray as $matchFile )
52 {
53 if ( !isset( $matchFile['template'] ) )
54 continue;
55 if ( $matchFile['template'] == ('/' . $file) )
56 {
57 $matchList[] = $matchFile;
58 }
59 }
60
61 $resourceName = $resourceData['resource'];
62 $resourceNameText = eZPHPCreator::variableText( $resourceName );
63
64 $designKeysName = 'dKeys';
65 if ( $resourceName == 'standard' )
66 $designKeysName = 'rKeys';
67
68 $newNodes = array();
69 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" .
70 "{\n" .
71 " \$resH = \$tpl->resourceHandler( $resourceNameText );\n" .
72 " \$$designKeysName = \$resH->keys();" .
73 "\n" .
74 "}\n" );
75 foreach ( $matchList as $match )
76 {
77 $basedir = $match['base_dir'];
78 $template = $match['template'];
79 $file = $basedir . $template;
80 $spacing = 0;
81 $addFileResource = true;
82 if ( isset( $match['custom_match'] ) )
83 {
84 $spacing = 4;
85 $customMatchList = $match['custom_match'];
86 $matchCount = 0;
87 foreach ( $customMatchList as $customMatch )
88 {
89 $matchConditionCount = is_countable( $customMatch['conditions'] ) ? count( $customMatch['conditions'] ) : 0;
90 $code = '';
91 if ( $matchCount > 0 )
92 {
93 $code = "else " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "";
94 }
95 if ( $matchConditionCount > 0 )
96 {
97 if ( $matchCount > 0 )
98 $code .= " ";
99 $code .= "if " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "( ";
100 }
101 $ifLength = strlen( $code );
102 $conditionCount = 0;
103 if ( is_array( $customMatch['conditions'] ) )
104 {
105 foreach ( $customMatch['conditions'] as $conditionName => $conditionValue )
106 {
107 if ( $conditionCount > 0 )
108 $code .= " and\n" . str_repeat( ' ', $ifLength );
109 $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 );
110 $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 );
111
112 $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and ";
113 if ( $conditionName == 'url_alias' )
114 {
115 $code .= "(strpos( \$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )";
116 }
117 else
118 {
119 $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " .
120 "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " .
121 "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )";
122 }
123 ++$conditionCount;
124 }
125 }
126 if ( $matchConditionCount > 0 )
127 {
128 $code .= " )\n";
129 }
130 if ( $matchConditionCount > 0 or $matchCount > 0 )
131 {
132 $code .= "{";
133 }
134 $matchFile = $customMatch['match_file'];
135 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code );
136 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
137 $matchFile, $matchFile,
138 eZTemplate::RESOURCE_FETCH, false,
139 $node[4], array( 'spacing' => $spacing ),
140 $namespaceValue );
141 if ( $matchConditionCount > 0 or $matchCount > 0 )
142 {
143 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" );
144 }
145 ++$matchCount;
146 if ( $matchConditionCount == 0 )
147 {
148 $addFileResource = false;
149 break;
150 }
151 }
152 if ( $addFileResource )
153 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else" . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "\n{" );
154 }
155 if ( $addFileResource )
156 {
157 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
158 $file, $file,
159 eZTemplate::RESOURCE_FETCH, false,
160 $node[4], array( 'spacing' => $spacing ),
161 $namespaceValue );
162 }
163 if ( isset( $match['custom_match'] ) and $addFileResource )
164 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" );
165 }
166
167 return $newNodes;
168 }
169
175 static function designSetting( $type = 'standard' )
176 {
177 if ( $type != 'standard' and
178 $type != 'site' )
179 {
180 eZDebug::writeWarning( "Cannot retrieve designsetting for type '$type'", __METHOD__ );
181 return null;
182 }
183 if ( $type == 'site' )
184 {
185 if ( !empty( $GLOBALS['eZSiteBasics']['site-design-override'] ) )
186 {
187 return $GLOBALS['eZSiteBasics']['site-design-override'];
188 }
189 }
190 if ( isset( $GLOBALS['eZTemplateDesignSetting'][$type] ) )
191 {
192 return $GLOBALS['eZTemplateDesignSetting'][$type];
193 }
194 $ini = eZINI::instance();
195 if ( $type == 'standard' )
196 {
197 $GLOBALS['eZTemplateDesignSetting'][$type] = $ini->variable( "DesignSettings", "StandardDesign" );
198 }
199 else if ( $type == 'site' )
200 {
201 $GLOBALS['eZTemplateDesignSetting'][$type] = $ini->variable( "DesignSettings", "SiteDesign" );
202 }
203 return $GLOBALS['eZTemplateDesignSetting'][$type];
204 }
205
210 function setDesignSetting( $designSetting, $type = 'standard' )
211 {
212 if ( $type != 'standard' and
213 $type != 'site' )
214 {
215 eZDebug::writeWarning( "Cannot set designsetting '$designSetting' for type '$type'", __METHOD__ );
216 return;
217 }
218 if ( !isset( $GLOBALS['eZTemplateDesignSetting'] ) )
219 {
220 $GLOBALS['eZTemplateDesignSetting'] = array();
221 }
222 $GLOBALS['eZTemplateDesignSetting'][$type] = $designSetting;
223 }
224
229 static function fileMatch( $bases, $element, $path, &$triedFiles )
230 {
231 $bases = array_unique( $bases );
232 foreach ( $bases as $base )
233 {
234 $resource = $element != '' ? "$base/$element" : $base;
235 $possibleMatchFile = $resource . '/' . $path;
236
237 $triedFiles[] = $possibleMatchFile;
238
239 if ( file_exists( $possibleMatchFile ) )
240 {
241 return array( 'resource' => $resource,
242 'path' => $possibleMatchFile );
243 }
244 }
245
246 return false;
247 }
248
253 function handleResource( $tpl, &$resourceData, $method, &$extraParameters )
254 {
255 if ( !is_array( $extraParameters ) )
256 {
257 $extraParameters = array();
258 }
259
260 $path = $resourceData['template-name'];
261
262 $matchKeys = $this->Keys;
263 if ( isset( $GLOBALS['eZDesignKeys'] ) )
264 {
265 $matchKeys = array_merge( $matchKeys, $GLOBALS['eZDesignKeys'] );
266 unset( $GLOBALS['eZDesignKeys'] );
267 $this->Keys = $matchKeys;
268 }
269 if ( is_array( $extraParameters ) and
270 isset( $extraParameters['ezdesign:keys'] ) )
271 {
272 $this->mergeKeys( $matchKeys, $extraParameters['ezdesign:keys'] );
273 }
274 $this->KeyStack[] = $this->Keys;
275 $this->Keys = $matchKeys;
276
277 eZDebug::accumulatorStart( 'override_cache', 'Override', 'Cache load' );
278
279 if( !isset( $GLOBALS['eZOverrideTemplateCacheMap'] ) )
280 {
281 $overrideCacheFile = $this->createOverrideCache();
282
283 if ( $overrideCacheFile )
284 {
285 include_once( $overrideCacheFile );
286 }
287 }
288
289 if ( isset( $GLOBALS['eZOverrideTemplateCacheMap'] ) )
290 {
291 if( isset( $GLOBALS['eZOverrideTemplateCacheMap'][md5( '/' . $path )] ) )
292 {
293 $cacheMap = $GLOBALS['eZOverrideTemplateCacheMap'][md5( '/' . $path )];
294 if ( !is_string( $cacheMap ) and trim( $cacheMap['code'] ) )
295 {
296 eval( "\$matchFile = " . $cacheMap['code'] . ";" );
297 }
298 else
299 {
300 $matchFile = $cacheMap;
301 }
302 $match['file'] = $matchFile;
303 }
304 }
305 else
306 {
307 $template = "/" . $path;
308 $matchFileArray = eZTemplateDesignResource::overrideArray( $this->OverrideSiteAccess );
309
310 $matchFile = $matchFileArray[$template];
311
312 if ( isset( $matchFile['custom_match'] ) )
313 {
314 $matchFound = false;
315 foreach ( $matchFile['custom_match'] as $customMatch )
316 {
317 $matchOverride = true;
318 if ( count( $customMatch['conditions'] ) > 0 )
319 {
320 foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey )
321 {
322 // Create special substring match for subtree override
323 if ( $conditionKey == 'url_alias' )
324 {
325 if ( strpos( $matchKeys['url_alias'], $customMatch['conditions'][$conditionKey] ) === 0 )
326 {
327 }
328 else
329 {
330 $matchOverride = false;
331 }
332 }
333 else if ( isset( $matchKeys[$conditionKey] ) and
334 isset( $customMatch['conditions'][$conditionKey] ) )
335 {
336 if ( is_array( $matchKeys[$conditionKey] ) )
337 {
338 if ( !in_array( $customMatch['conditions'][$conditionKey], $matchKeys[$conditionKey] ) )
339 {
340 $matchOverride = false;
341 }
342 }
343 else if ( $matchKeys[$conditionKey] != $customMatch['conditions'][$conditionKey] )
344 {
345 $matchOverride = false;
346 }
347 }
348 else
349 {
350 $matchOverride = false;
351 }
352 }
353 if ( $matchOverride == true )
354 {
355 $match['file'] = $customMatch['match_file'];
356 $matchFound = true;
357 break;
358 }
359 else
360 {
361 }
362 }
363 else
364 {
365 // Default match without conditions
366 $match['file'] = $customMatch['match_file'];
367 $matchFound = true;
368 }
369 }
370 if ( !$matchFound )
371 $match['file'] = $matchFile['base_dir'] . $matchFile['template'];
372 }
373 else
374 {
375 $match['file'] = $matchFile['base_dir'] . $matchFile['template'];
376 }
377 }
378 eZDebug::accumulatorStop( 'override_cache' );
379 if ( isset( $match ) )
380 {
381 $file = $match["file"];
382
383 $matchedKeys = array();
384 $usedKeys = array();
385 foreach ( $matchKeys as $matchKeyName => $matchKeyValue )
386 {
387 $usedKeys[$matchKeyName] = $matchKeyValue;
388 }
389 $extraParameters['ezdesign:used_keys'] = $usedKeys;
390 $extraParameters['ezdesign:matched_keys'] = $matchedKeys;
391 $tpl->setVariable( 'used', $usedKeys, 'DesignKeys' );
392 $tpl->setVariable( 'matched', $matchedKeys, 'DesignKeys' );
393 $resourceData['template-filename'] = $file;
394 $result = eZTemplateFileResource::handleResourceData( $tpl, $this, $resourceData, $method, $extraParameters );
395 }
396 else
397 {
398 $result = false;
399 }
400 $this->Keys = array_pop( $this->KeyStack );
401 return $result;
402 }
403
407 function createOverrideCache()
408 {
409 if ( isset( $GLOBALS['eZSiteBasics'] ) )
410 {
411 if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and
412 $GLOBALS['eZSiteBasics']['no-cache-adviced'] )
413 return false;
414 }
415 global $eZTemplateOverrideCacheNoPermission;
416 if ( $eZTemplateOverrideCacheNoPermission == "nocache" )
417 {
418 return false;
419 }
420
421 $ini = eZINI::instance( 'site.ini' );
422 $useOverrideCache = true;
423 if ( $ini->hasVariable( 'OverrideSettings', 'Cache' ) )
424 $useOverrideCache = $ini->variable( 'OverrideSettings', 'Cache' ) == 'enabled';
425
426 $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
427 $siteBase = eZTemplateDesignResource::designSetting( 'site' );
428
429 $overrideKeys = $this->overrideKeys();
430
431 $overrideKey = md5( implode( ',', $overrideKeys ) . $siteBase . $standardBase );
432 $cacheDir = eZSys::cacheDirectory();
433
434 $overrideCacheFile = $cacheDir.'/override/override_'.$overrideKey.'.php';
435
436 // Build matching cache only of it does not already exists,
437 // or override file has been updated
438 if ( !$useOverrideCache or
439 !file_exists( $overrideCacheFile ) )
440 {
441 $matchFileArray = eZTemplateDesignResource::overrideArray( $this->OverrideSiteAccess );
442
443 // Generate PHP compiled cache file.
444 $phpCache = new eZPHPCreator( "$cacheDir/override", "override_$overrideKey.php" );
445
446 $phpCode = "\$GLOBALS['eZOverrideTemplateCacheMap'] = array (\n";
447 $numMatchFiles = count ( $matchFileArray );
448 $countMatchFiles = 0;
449 // $phpCode .= "switch ( \$matchFile )\n{\n ";
450 foreach ( array_keys( $matchFileArray ) as $matchKey )
451 {
452 $countMatchFiles++;
453 $phpCode .= '\'' . md5( $matchKey ) . '\' => ';
454 if ( isset( $matchFileArray[$matchKey]['custom_match'] ) )
455 {
456 $baseDir = isset( $matchFileArray[$matchKey]['base_dir'] ) ? $matchFileArray[$matchKey]['base_dir'] : '';
457 $defaultMatchFile = $baseDir . $matchKey;
458 // Custom override matching
459 // $phpCode .= " case \"$matchKey\":\n {\n";
460
461 $matchConditionArray = array();
462 foreach ( $matchFileArray[$matchKey]['custom_match'] as $customMatch )
463 {
464 $matchCondition = "";
465 $condCount = 0;
466 if ( is_array( $customMatch['conditions'] ) )
467 {
468 foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey )
469 {
470 if ( $condCount > 0 )
471 $matchCondition .= " and ";
472
473 // Have a special substring match for subtree matching
474
475 $matchCondition .= "( isset( \$matchKeys[\\'$conditionKey\\'] ) and ";
476 if ( $conditionKey == 'url_alias' )
477 {
478 $matchCondition .=
479 "( strpos( \$matchKeys[\\'url_alias\\'], \\'" . $customMatch['conditions']['url_alias'] . "\\' ) === 0 ) )";
480 }
481 else
482 {
483 $matchCondition .=
484 "( is_array( \$matchKeys[\\'$conditionKey\\'] ) ? " .
485 "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'$conditionKey\\'] ) : " .
486 "\$matchKeys[\\'$conditionKey\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )";
487 }
488
489 $condCount++;
490 }
491 }
492
493 // Only create custom match if conditions are defined
494 if ( $matchCondition != "" )
495 {
496 // $phpCode .= " if ( $matchCondition )\n {\n";
497 // $phpCode .= " return '" . $customMatch['match_file'] . "';\n }\n";
498 if ( $condCount > 1 )
499 $matchConditionArray[] = array( 'condition' => '(' . $matchCondition . ')',
500 'matchFile' => $customMatch['match_file'] );
501 else
502 $matchConditionArray[] = array( 'condition' => $matchCondition,
503 'matchFile' => $customMatch['match_file'] );
504 }
505 else
506 {
507 // No override conditions defined. Override default match file
508 $defaultMatchFile = $customMatch['match_file'];
509 }
510 }
511
512 $phpCode .= "array ( 'eval' => 1, 'code' => ";
513
514 $phpCode .= "'";
515
516 foreach ( array_keys( $matchConditionArray ) as $key )
517 {
518 $phpCode .= '(' . $matchConditionArray[$key]['condition'] . ' ? ' . "\\'" . $matchConditionArray[$key]['matchFile'] . "\\'" . ' : ';
519 }
520
521 $phpCode .= "\\'" . $defaultMatchFile . "\\'";
522
523 for ( $condCount = 0; $condCount < count( $matchConditionArray ); $condCount++)
524 {
525 $phpCode .= ')';
526 }
527
528 $phpCode .= "' )";
529 }
530 else
531 {
532 $phpCode .= "'". $matchFileArray[$matchKey]['base_dir'] . $matchKey . "'";
533 }
534
535 if ( $countMatchFiles < $numMatchFiles )
536 {
537 $phpCode .= ",\n";
538 }
539 else
540 {
541 $phpCode .= ");\n";
542 }
543 }
544
545 $phpCache->addCodePiece( $phpCode );
546 if ( $useOverrideCache and
547 $phpCache->store() )
548 {
549
550 }
551 else
552 {
553 if ( $useOverrideCache )
554 {
555 eZDebug::writeError( "Could not write template override cache file, check permissions in $cacheDir/override/.\nRunning eZ Publish without this cache will have a performance impact.", __METHOD__ );
556 }
557 $eZTemplateOverrideCacheNoPermission = 'nocache';
558 $overrideCacheFile = false;
559 }
560 }
561
562 return $overrideCacheFile;
563 }
564
569 function overrideKeys( $siteAccess = false )
570 {
571 // print( "<br>" . xdebug_call_function() . "<br>" );
572 $keys = array();
573 $designStartPath = eZTemplateDesignResource::designStartPath();
574 $keys[] = $designStartPath;
575
576 // fetch the override array from a specific siteacces
577 if ( $siteAccess )
578 {
579 // Get the design resources
580 $ini = eZSiteAccess::getIni( $siteAccess, 'site.ini' );
581
582 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true );
583
584 // overwrite overrideDirs from siteIni instance
585 $overrideINI->setOverrideDirs( $ini->overrideDirs( false ) );
586 $overrideINI->load();
587
588 $standardBase = $ini->variable( "DesignSettings", "StandardDesign" );
589 $keys[] = "siteaccess/$siteAccess";
590 $keys[] = $standardBase;
591 $siteBase = $ini->variable( "DesignSettings", "SiteDesign" );
592 $keys[] = $siteBase;
593 }
594 else
595 {
596 $ini = eZINI::instance();
597 if ( $this->OverrideSiteAccess != false )
598 {
599 $overrideINI = eZSiteAccess::getIni( $siteAccess, 'override.ini' );
600 $keys[] = "siteaccess/$this->OverrideSiteAccess";
601 }
602 else
603 {
604 $overrideINI = eZINI::instance( 'override.ini' );
605 $siteAccess = $GLOBALS['eZCurrentAccess']['name'];
606 $keys[] = "siteaccess/$siteAccess";
607 }
608
609 $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
610 $keys[] = $standardBase;
611 $siteBase = eZTemplateDesignResource::designSetting( 'site' );
612 $keys[] = $siteBase;
613 }
614
615
616 $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" );
617 $keys = array_merge( $keys, $additionalSiteDesignList );
618
619 // Add extension paths
620 $extensionDirectory = eZExtension::baseDirectory();
621
622 $designINI = eZINI::instance( 'design.ini' );
623 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );
624
625 return array_merge( $keys, $extensions );
626 }
627
631 static function serializeOverrides( $siteAccess = false,
632 $matchKeys = array() )
633 {
634 }
635
641 static function designExtensions()
642 {
643 $designINI = eZINI::instance( 'design.ini' );
644 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );
645 return array_reverse( $extensions );
646 }
647
652 static function allDesignBases( $siteAccess = false )
653 {
654 // in memory caching
655 if ( $siteAccess )
656 {
657 if ( isset( $GLOBALS['eZTemplateDesignResourceSiteAccessBases'] ) )
658 {
659 if ( isset( $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess] ) )
660 {
661 return $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess];
662 }
663 }
664 else
665 {
666 $GLOBALS['eZTemplateDesignResourceSiteAccessBases'] = array();
667 }
668 }
669 else
670 {
671 if ( isset( $GLOBALS['eZTemplateDesignResourceBases'] ) )
672 {
673 return $GLOBALS['eZTemplateDesignResourceBases'];
674 }
675 }
676
677 if ( eZINI::instance( 'site.ini' )->variable( 'DesignSettings', 'DesignLocationCache' ) === 'enabled' )
678 {
679 // Using current SA if none given
680 $siteAccessName = $siteAccess !== false ? $siteAccess : $GLOBALS['eZCurrentAccess']['name'];
681
682 $cachePath = eZSys::cacheDirectory()
683 . '/'
684 . self::DESIGN_BASE_CACHE_NAME
685 . md5( $siteAccessName )
686 . '.php';
687
688 $clusterFileHandler = eZClusterFileHandler::instance( $cachePath );
689
690 if( $clusterFileHandler->fileExists( $cachePath ) )
691 {
692 $designBaseList = unserialize( $clusterFileHandler->fetchContents() );
693
694 self::savesMemoryCache( $designBaseList, $siteAccess );
695 }
696 else
697 {
698 // find design locations
699 $designBaseList = self::findDesignBase( eZINI::instance( 'file.ini' ), $siteAccess );
700
701 // stores it on the disk
702 $clusterFileHandler->fileStoreContents( $cachePath,
703 serialize( $designBaseList ),
704 'designbases',
705 'php' );
706
707 self::savesMemoryCache( $designBaseList, $siteAccess );
708 }
709 }
710 else
711 {
712 // find design locations
713 $designBaseList = self::findDesignBase( eZINI::instance( 'file.ini' ), $siteAccess );
714
715 self::savesMemoryCache( $designBaseList, $siteAccess );
716 }
717
718 return $designBaseList;
719 }
720
728 private static function findDesignBase( eZINI $ini, $siteAccess = false )
729 {
730 if( $siteAccess )
731 {
732 $ini = eZSiteAccess::getIni( $siteAccess, 'site.ini' );
733
734 $standardDesign = $ini->variable( 'DesignSettings', 'StandardDesign' );
735 $siteDesign = $ini->variable( 'DesignSettings', 'SiteDesign' );
736
737 }
738 else
739 {
740 $ini = eZINI::instance();
741 $standardDesign = eZTemplateDesignResource::designSetting( 'standard' );
742 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
743 }
744
745 $siteDesignList = $ini->variable( 'DesignSettings', 'AdditionalSiteDesignList' );
746
747 array_unshift( $siteDesignList, $siteDesign );
748 $siteDesignList[] = $standardDesign;
749 $siteDesignList = array_unique( $siteDesignList );
750
751 $designBaseList = array();
752 $extensionDirectory = eZExtension::baseDirectory();
753 $designStartPath = eZTemplateDesignResource::designStartPath();
754 $extensions = eZTemplateDesignResource::designExtensions();
755
756 foreach ( $siteDesignList as $design )
757 {
758 foreach ( $extensions as $extension )
759 {
760 $path = "$extensionDirectory/$extension/$designStartPath/$design";
761 if ( file_exists( $path ) )
762 {
763 $designBaseList[] = $path;
764 }
765 }
766
767 $path = "$designStartPath/$design";
768 if ( file_exists( $path ) )
769 {
770 $designBaseList[] = $path;
771 }
772 }
773
774 return $designBaseList;
775 }
776
784 private static function savesMemoryCache( array $designBaseList, $siteAccess = false )
785 {
786 // store design base list in memory for the current request
787 if ( $siteAccess )
788 $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess] = $designBaseList;
789 else
790 $GLOBALS['eZTemplateDesignResourceBases'] = $designBaseList;
791 }
792
798 static function designStartPath()
799 {
800 $designStartPath = false;
801 if ( isset( $GLOBALS['eZTemplateDesignResourceStartPath'] ) )
802 {
803 $designStartPath = $GLOBALS['eZTemplateDesignResourceStartPath'];
804 }
805 if ( !$designStartPath )
806 $designStartPath = 'design';
807 return $designStartPath;
808 }
809
816 static function setDesignStartPath( $path )
817 {
818 $GLOBALS['eZTemplateDesignResourceStartPath'] = $path;
819 }
820
828 static function overrideArray( $siteAccess = false )
829 {
830
831 if ( $siteAccess === false and self::$overrideArrayCache !== null )
832 {
833 return self::$overrideArrayCache;
834 }
835
836 $bases = eZTemplateDesignResource::allDesignBases( $siteAccess );
837
838 // fetch the override array from a specific siteacces
839 if ( $siteAccess )
840 {
841 $overrideINI = eZSiteAccess::getIni( $siteAccess, 'override.ini' );
842 }
843 else
844 {
845 $overrideINI = eZINI::instance( 'override.ini' );
846 }
847
848 $designStartPath = eZTemplateDesignResource::designStartPath();
849
850 // Generate match cache for all templates
851
852 // Build arrays of available files, start with standard design and end with most prefered design
853 $matchFileArray = array();
854
855 $reverseBases = array_reverse( $bases );
856
857 foreach ( $reverseBases as $base )
858 {
859 $templateResource = $base . '/templates';
860 $sourceFileArray = eZDir::recursiveFindRelative( $templateResource, "", "tpl" );
861 foreach ( $sourceFileArray as $source )
862 {
863 $matchFileArray[$source]['base_dir'] = $templateResource;
864 $matchFileArray[$source]['template'] = $source;
865 }
866 }
867
868 // Load override templates
869 $overrideSettingGroups = $overrideINI->groups();
870 if ( isset( $GLOBALS['eZDesignOverrides'] ) )
871 {
872 $overrideSettingGroups = array_merge( $overrideSettingGroups, $GLOBALS['eZDesignOverrides'] );
873 }
874
875 foreach ( $overrideSettingGroups as $overrideName => $overrideSetting )
876 {
877 if( !isset( $overrideSetting['Source'] ) )
878 {
879 continue;
880 }
881 $overrideSource = "/" . $overrideSetting['Source'];
882 $overrideMatchFile = $overrideSetting['MatchFile'];
883
884 // Find the matching file in the available resources
885 $triedFiles = array();
886 $fileInfo = eZTemplateDesignResource::fileMatch( $bases, 'override/templates', $overrideMatchFile, $triedFiles );
887
888 $resourceInUse = is_array( $fileInfo ) ? $fileInfo['resource'] : false;
889 $overrideMatchFilePath = is_array( $fileInfo ) ? $fileInfo['path'] : false;
890
891 // if the override template is not found
892 // then we probably shouldn't use it
893 // there should be added a check around the following code
894 // if ( $overrideMatchFilePath )
895 // {
896 $customMatchArray = array();
897 $customMatchArray['conditions'] = isset( $overrideSetting['Match'] ) ? $overrideSetting['Match'] : null;
898 $customMatchArray['match_file'] = $overrideMatchFilePath;
899 $customMatchArray['override_name'] = $overrideName;
900
901 $matchFileArray[$overrideSource]['custom_match'][] = $customMatchArray;
902 // }
903
904 // if overriding a non-existing template
905 // then we use the override template as main template
906 // this code should probably be removed
907 // because we should not allow an override if the main template is missing
908 if ( $resourceInUse && !isset( $matchFileArray[$overrideSource]['base_dir'] ) )
909 {
910 $matchFileArray[$overrideSource]['base_dir'] = $resourceInUse;
911 $matchFileArray[$overrideSource]['template'] = $overrideSource;
912 }
913
914 if ( ! $overrideMatchFilePath )
915 {
916 eZDebug::writeError( "Custom match file: path '$overrideMatchFile' not found in any resource. Check the template settings in settings/override.ini", __METHOD__ );
917 eZDebug::writeError( implode( ', ', $triedFiles ), __METHOD__ . ' tried files' );
918 }
919
920 }
921
922 if ( $siteAccess === false )
923 {
924 self::$overrideArrayCache = $matchFileArray;
925 }
926
927 return $matchFileArray;
928 }
929
936 static public function clearInMemoryOverrideArray( )
937 {
938 self::$overrideArrayCache = null;
939 unset( $GLOBALS['eZOverrideTemplateCacheMap'] );
940 }
941
948 static public function clearInMemoryCache( )
949 {
950 $GLOBALS['eZTemplateDesignSetting'] = array();
951 self::clearInMemoryOverrideArray();
952 }
953
959 function setKeys( $keys )
960 {
961 $this->mergeKeys( $this->Keys, $keys );
962 }
963
967 function removeKey( $key )
968 {
969 if ( isset( $this->Keys[$key] ) )
970 unset( $this->Keys[$key] );
971 }
972
977 function mergeKeys( &$originalKeys, $keys )
978 {
979 foreach ( $keys as $key )
980 {
981 if ( count( $key ) >= 2 )
982 $originalKeys[$key[0]] = $key[1];
983 }
984 }
985
990 function clearKeys()
991 {
992 $this->Keys = array();
993 }
994
999 function keys()
1000 {
1001 if ( isset( $GLOBALS['eZDesignKeys'] ) )
1002 {
1003 return array_merge( $this->Keys, $GLOBALS['eZDesignKeys'] );
1004 }
1005 return $this->Keys;
1006 }
1007
1011 static function addGlobalOverride( $name, $source, $match, $subdir, $matches )
1012 {
1013 if ( !isset( $GLOBALS['eZDesignOverrides'] ) )
1014 $GLOBALS['eZDesignOverrides'] = array();
1015 $GLOBALS['eZDesignOverrides'][$name] = array( 'Source' => $source,
1016 'MatchFile' => $match,
1017 'Subdir' => $subdir,
1018 'Match' => $matches );
1019 }
1020
1026 static function instance()
1027 {
1028 if ( !isset( $GLOBALS['eZTemplateDesignResourceInstance'] ) )
1029 {
1030 $GLOBALS['eZTemplateDesignResourceInstance'] = new eZTemplateDesignResource();
1031 }
1032 return $GLOBALS['eZTemplateDesignResourceInstance'];
1033 }
1034
1038 function setOverrideAccess( $siteAccess )
1039 {
1040 $this->OverrideSiteAccess = $siteAccess;
1041 }
1042
1043 public $Keys;
1044 public $OverrideSiteAccess = false;
1045 public $KeyStack;
1046 }
1047
1048 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1361
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1389
eZPHPCreator
eZPHPCreator provides a simple interface for creating and executing PHP code.
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
eZTemplateDesignResource
Definition: eztemplatedesignresource.php:18
eZTemplateDesignResource\DESIGN_BASE_CACHE_NAME
const DESIGN_BASE_CACHE_NAME
Definition: eztemplatedesignresource.php:19
eZTemplateDesignResource\createOverrideCache
createOverrideCache()
Definition: eztemplatedesignresource.php:407
eZTemplateDesignResource\$Keys
$Keys
Definition: eztemplatedesignresource.php:1043
eZTemplateDesignResource\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, &$resourceData, $parameters, $namespaceValue)
Definition: eztemplatedesignresource.php:42
eZTemplateDesignResource\setDesignSetting
setDesignSetting( $designSetting, $type='standard')
Definition: eztemplatedesignresource.php:210
eZTemplateDesignResource\mergeKeys
mergeKeys(&$originalKeys, $keys)
Definition: eztemplatedesignresource.php:977
eZTemplateDesignResource\removeKey
removeKey( $key)
Definition: eztemplatedesignresource.php:967
eZTemplateDesignResource\setOverrideAccess
setOverrideAccess( $siteAccess)
Definition: eztemplatedesignresource.php:1038
eZTemplateDesignResource\designSetting
static designSetting( $type='standard')
Definition: eztemplatedesignresource.php:175
eZTemplateDesignResource\fileMatch
static fileMatch( $bases, $element, $path, &$triedFiles)
Definition: eztemplatedesignresource.php:229
eZTemplateDesignResource\$KeyStack
$KeyStack
Definition: eztemplatedesignresource.php:1045
eZTemplateDesignResource\clearInMemoryCache
static clearInMemoryCache()
Definition: eztemplatedesignresource.php:948
eZTemplateDesignResource\instance
static instance()
Definition: eztemplatedesignresource.php:1026
eZTemplateDesignResource\handleResource
handleResource( $tpl, &$resourceData, $method, &$extraParameters)
Definition: eztemplatedesignresource.php:253
eZTemplateDesignResource\clearKeys
clearKeys()
Definition: eztemplatedesignresource.php:990
eZTemplateDesignResource\overrideKeys
overrideKeys( $siteAccess=false)
Definition: eztemplatedesignresource.php:569
eZTemplateDesignResource\setKeys
setKeys( $keys)
Definition: eztemplatedesignresource.php:959
eZTemplateDesignResource\__construct
__construct( $name="design")
Definition: eztemplatedesignresource.php:35
eZTemplateDesignResource\$OverrideSiteAccess
$OverrideSiteAccess
Definition: eztemplatedesignresource.php:1044
eZTemplateDesignResource\keys
keys()
Definition: eztemplatedesignresource.php:999
eZTemplateDesignResource\clearInMemoryOverrideArray
static clearInMemoryOverrideArray()
Definition: eztemplatedesignresource.php:936
eZTemplateDesignResource\$overrideArrayCache
static $overrideArrayCache
Definition: eztemplatedesignresource.php:28
eZTemplateDesignResource\overrideArray
static overrideArray( $siteAccess=false)
Definition: eztemplatedesignresource.php:828
eZTemplateDesignResource\addGlobalOverride
static addGlobalOverride( $name, $source, $match, $subdir, $matches)
Definition: eztemplatedesignresource.php:1011
eZTemplateFileResource
Handles filesystem retrieval of templates.
Definition: eztemplatefileresource.php:20
eZTemplateFileResource\handleResourceData
handleResourceData( $tpl, $handler, &$resourceData, $method, &$extraParameters)
Definition: eztemplatefileresource.php:173
eZTemplateNodeTool\createCodePieceNode
static createCodePieceNode( $codePiece, $parameters=array())
Definition: eztemplatenodetool.php:457
eZTemplateNodeTool\createResourceAcquisitionNode
static createResourceAcquisitionNode( $resourceName, $templateName, $fileName, $method, $extraParameters, $placement=false, $parameters=array(), $newRootNamespace=false, $resourceVariableName=false)
Definition: eztemplatenodetool.php:527
eZTemplate\RESOURCE_FETCH
const RESOURCE_FETCH
Definition: eztemplate.php:200
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.