00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( "lib/eztemplate/classes/eztemplatefileresource.php" );
00041 include_once( "lib/ezutils/classes/ezini.php" );
00042
00043 class eZTemplateDesignResource extends eZTemplateFileResource
00044 {
00045
00046
00047
00048 function eZTemplateDesignResource( $name = "design", $onlyStandard = false )
00049 {
00050 $this->eZTemplateFileResource( $name, true );
00051 $this->Keys = array();
00052 $this->KeyStack = array();
00053 $this->OnlyStandard = $onlyStandard;
00054 }
00055
00056
00057
00058 function templateNodeTransformation( $functionName, &$node,
00059 &$tpl, &$resourceData, $parameters, $namespaceValue )
00060 {
00061 if ( $this->Name != 'design' and $this->Name != 'standard' )
00062 return false;
00063
00064 $file = $resourceData['template-name'];
00065 $matchFileArray = $this->overrideArray( $this->OverrideSiteAccess );
00066 $matchList = array();
00067 foreach ( $matchFileArray as $matchFile )
00068 {
00069 if ( !isset( $matchFile['template'] ) )
00070 continue;
00071 if ( $matchFile['template'] == ('/' . $file) )
00072 {
00073 $matchList[] = $matchFile;
00074 }
00075 }
00076
00077 $resourceName = $resourceData['resource'];
00078 $resourceNameText = eZPHPCreator::variableText( $resourceName );
00079
00080 $designKeysName = 'dKeys';
00081 if ( $resourceName == 'standard' )
00082 $designKeysName = 'rKeys';
00083
00084 $newNodes = array();
00085 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" .
00086 "{\n" .
00087 " \$resH =& \$tpl->resourceHandler( $resourceNameText );\n" .
00088 " \$$designKeysName =& \$resH->keys();" .
00089 "\n" .
00090 "}\n" );
00091 foreach ( $matchList as $match )
00092 {
00093 $basedir = $match['base_dir'];
00094 $template = $match['template'];
00095 $file = $basedir . $template;
00096 $spacing = 0;
00097 $addFileResource = true;
00098 if ( isset( $match['custom_match'] ) )
00099 {
00100 $spacing = 4;
00101 $customMatchList = $match['custom_match'];
00102 $matchCount = 0;
00103 foreach ( $customMatchList as $customMatch )
00104 {
00105 $matchConditionCount = count( $customMatch['conditions'] );
00106 $code = '';
00107 if ( $matchCount > 0 )
00108 {
00109 $code = "else " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "";
00110 }
00111 if ( $matchConditionCount > 0 )
00112 {
00113 if ( $matchCount > 0 )
00114 $code .= " ";
00115 $code .= "if " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "( ";
00116 }
00117 $ifLength = strlen( $code );
00118 $conditionCount = 0;
00119 if ( is_array( $customMatch['conditions'] ) )
00120 {
00121 foreach ( $customMatch['conditions'] as $conditionName => $conditionValue )
00122 {
00123 if ( $conditionCount > 0 )
00124 $code .= " and\n" . str_repeat( ' ', $ifLength );
00125 $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 );
00126 $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 );
00127
00128 $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and ";
00129 if ( $conditionName == 'url_alias' )
00130 {
00131 $code .= "(strpos( \$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )";
00132 }
00133 else
00134 {
00135 $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " .
00136 "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " .
00137 "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )";
00138 }
00139 ++$conditionCount;
00140 }
00141 }
00142 if ( $matchConditionCount > 0 )
00143 {
00144 $code .= " )\n";
00145 }
00146 if ( $matchConditionCount > 0 or $matchCount > 0 )
00147 {
00148 $code .= "{";
00149 }
00150 $matchFile = $customMatch['match_file'];
00151 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code );
00152 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
00153 $matchFile, $matchFile,
00154 EZ_RESOURCE_FETCH, false,
00155 $node[4], array( 'spacing' => $spacing ),
00156 $namespaceValue );
00157 if ( $matchConditionCount > 0 or $matchCount > 0 )
00158 {
00159 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" );
00160 }
00161 ++$matchCount;
00162 if ( $matchConditionCount == 0 )
00163 {
00164 $addFileResource = false;
00165 break;
00166 }
00167 }
00168 if ( $addFileResource )
00169 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else" . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "\n{" );
00170 }
00171 if ( $addFileResource )
00172 {
00173 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '',
00174 $file, $file,
00175 EZ_RESOURCE_FETCH, false,
00176 $node[4], array( 'spacing' => $spacing ),
00177 $namespaceValue );
00178 }
00179 if ( isset( $match['custom_match'] ) and $addFileResource )
00180 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" );
00181 }
00182
00183 return $newNodes;
00184 }
00185
00186
00187
00188
00189
00190
00191 function designSetting( $type = 'standard' )
00192 {
00193 if ( $type != 'standard' and
00194 $type != 'site' )
00195 {
00196 eZDebug::writeWarning( "Cannot retrieve designsetting for type '$type'", 'eZTemplateDesignResource::designSetting' );
00197 $retValue = null;
00198 return $retValue;
00199 }
00200 $designSettings =& $GLOBALS['eZTemplateDesignSetting'];
00201 if ( !isset( $designSettings ) )
00202 $designSettings = array();
00203 $designSetting =& $designSettings[$type];
00204 $siteBasics =& $GLOBALS['eZSiteBasics'];
00205 if ( $type == 'site' and
00206 isset( $siteBasics['site-design-override'] ) and
00207 is_string( $siteBasics['site-design-override'] ) )
00208 {
00209 return $siteBasics['site-design-override'];
00210 }
00211
00212 if ( isset( $designSetting ) )
00213 {
00214 return $designSetting;
00215 }
00216 $ini =& eZINI::instance();
00217 if ( $type == 'standard' )
00218 $designSetting = $ini->variable( "DesignSettings", "StandardDesign" );
00219 else if ( $type == 'site' )
00220 $designSetting = $ini->variable( "DesignSettings", "SiteDesign" );
00221 return $designSetting;
00222 }
00223
00224
00225
00226
00227
00228 function setDesignSetting( $designSetting, $type = 'standard' )
00229 {
00230 if ( $type != 'standard' and
00231 $type != 'site' )
00232 {
00233 eZDebug::writeWarning( "Cannot set designsetting '$designSetting' for type '$type'", 'eZTemplateDesignResource::setDesignSetting' );
00234 return;
00235 }
00236 $designSettings =& $GLOBALS['eZTemplateDesignSetting'];
00237 if ( !isset( $designSettings ) )
00238 $designSettings = array();
00239 $designSettings[$type] = $designSetting;
00240 }
00241
00242
00243
00244
00245 function fileMatchingRules( $element, $path, $onlyStandard = false )
00246 {
00247 eZDebug::accumulatorStart( 'matching_rules', 'override', 'Matching rules' );
00248
00249 $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
00250 if ( !$onlyStandard )
00251 $siteBase = eZTemplateDesignResource::designSetting( 'site' );
00252
00253 $ini =& eZINI::instance();
00254 $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" );
00255
00256 include_once( 'lib/ezutils/classes/ezextension.php' );
00257 $extensionDirectory = eZExtension::baseDirectory();
00258
00259 $designINI =& eZINI::instance( 'design.ini' );
00260 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );
00261
00262 $matches = array();
00263
00264 $elementText = '';
00265 if ( $element !== false )
00266 $elementText = $element . '/';
00267
00268 $designStartPath = eZTemplateDesignResource::designStartPath();
00269
00270 $designList = $additionalSiteDesignList;
00271 array_unshift( $designList, $siteBase );
00272 $designList[] = $standardBase;
00273
00274 if ( $onlyStandard )
00275 $designList = array( $standardBase );
00276
00277
00278 foreach ( $designList as $design )
00279 {
00280 foreach ( $extensions as $extension )
00281 {
00282 $matches[] = array( 'file' => "$extensionDirectory/$extension/$designStartPath/$design/override/$elementText$path",
00283 'type' => 'override' );
00284 }
00285 $matches[] = array( 'file' => "$designStartPath/$design/override/$elementText$path",
00286 'type' => 'override' );
00287 }
00288
00289 foreach ( $designList as $design )
00290 {
00291 foreach ( $extensions as $extension )
00292 {
00293 $matches[] = array( 'file' => "$extensionDirectory/$extension/$designStartPath/$design/$elementText$path",
00294 'type' => 'normal' );
00295 }
00296 $matches[] = array( 'file' => "$designStartPath/$design/$elementText$path",
00297 'type' => 'normal' );
00298 }
00299 eZDebug::accumulatorStop( 'matching_rules' );
00300 return $matches;
00301 }
00302
00303
00304
00305
00306
00307 function handleResource( &$tpl, &$resourceData, $method, &$extraParameters )
00308 {
00309 $path =& $resourceData['template-name'];
00310
00311 $matchKeys = $this->Keys;
00312 if ( isset( $GLOBALS['eZDesignKeys'] ) )
00313 {
00314 $matchKeys = array_merge( $matchKeys, $GLOBALS['eZDesignKeys'] );
00315 unset( $GLOBALS['eZDesignKeys'] );
00316 $this->Keys = $matchKeys;
00317 }
00318 if ( is_array( $extraParameters ) and
00319 isset( $extraParameters['ezdesign:keys'] ) )
00320 {
00321 $this->mergeKeys( $matchKeys, $extraParameters['ezdesign:keys'] );
00322 }
00323 $this->KeyStack[] = $this->Keys;
00324 $this->Keys = $matchKeys;
00325
00326 eZDebug::accumulatorStart( 'override_cache', 'override', 'Cache load' );
00327
00328 $overrideCacheFile = $this->createOverrideCache();
00329
00330 if ( $overrideCacheFile )
00331 {
00332 include_once( $overrideCacheFile );
00333 $cacheMap =& $GLOBALS['eZOverrideTemplateCacheMap'][eZSys::ezcrc32( '/' . $path )];
00334 if ( !is_string( $cacheMap ) and trim( $cacheMap['code'] ) )
00335 {
00336 eval( "\$matchFile = " . $cacheMap['code'] . ";" );
00337 }
00338 else
00339 {
00340 $matchFile =& $cacheMap;
00341 }
00342 $match['file'] = $matchFile;
00343 }
00344 else
00345 {
00346 $template = "/" . $path;
00347
00348
00349 $matchFileArray =& $GLOBALS['eZTemplateOverrideArray_' . $this->OverrideSiteAccess];
00350 if ( !is_array( $matchFileArray ) )
00351 {
00352 $matchFileArray = $this->overrideArray( $this->OverrideSiteAccess );
00353 }
00354
00355 $matchFile = $matchFileArray[$template];
00356
00357 if ( isset( $matchFile['custom_match'] ) )
00358 {
00359 $matchFound = false;
00360 foreach ( $matchFile['custom_match'] as $customMatch )
00361 {
00362 $matchOverride = true;
00363 if ( count( $customMatch['conditions'] ) > 0 )
00364 {
00365 foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey )
00366 {
00367
00368 if ( $conditionKey == 'url_alias' )
00369 {
00370 if ( strpos( $matchKeys['url_alias'], $customMatch['conditions'][$conditionKey] ) === 0 )
00371 {
00372 }
00373 else
00374 {
00375 $matchOverride = false;
00376 }
00377 }
00378 else if ( isset( $matchKeys[$conditionKey] ) and
00379 isset( $customMatch['conditions'][$conditionKey] ) )
00380 {
00381 if ( is_array( $matchKeys[$conditionKey] ) )
00382 {
00383 if ( !in_array( $customMatch['conditions'][$conditionKey], $matchKeys[$conditionKey] ) )
00384 {
00385 $matchOverride = false;
00386 }
00387 }
00388 else if ( $matchKeys[$conditionKey] != $customMatch['conditions'][$conditionKey] )
00389 {
00390 $matchOverride = false;
00391 }
00392 }
00393 else
00394 {
00395 $matchOverride = false;
00396 }
00397 }
00398 if ( $matchOverride == true )
00399 {
00400 $match['file'] = $customMatch['match_file'];
00401 $matchFound = true;
00402 break;
00403 }
00404 else
00405 {
00406 }
00407 }
00408 else
00409 {
00410
00411 $match['file'] = $customMatch['match_file'];
00412 $matchFound = true;
00413 }
00414 }
00415 if ( !$matchFound )
00416 $match['file'] = $matchFile['base_dir'] . $matchFile['template'];
00417 }
00418 else
00419 {
00420 $match['file'] = $matchFile['base_dir'] . $matchFile['template'];
00421 }
00422 }
00423 eZDebug::accumulatorStop( 'override_cache' );
00424 if ( !isset( $match ) or $match === null )
00425 return false;
00426
00427 $file = $match["file"];
00428
00429 $matchedKeys = array();
00430 $usedKeys = array();
00431 foreach ( $matchKeys as $matchKeyName => $matchKeyValue )
00432 {
00433 $usedKeys[$matchKeyName] = $matchKeyValue;
00434 }
00435 $extraParameters['ezdesign:used_keys'] = $usedKeys;
00436 $extraParameters['ezdesign:matched_keys'] = $matchedKeys;
00437 $tpl->setVariable( 'used', $usedKeys, 'DesignKeys' );
00438 $tpl->setVariable( 'matched', $matchedKeys, 'DesignKeys' );
00439 $resourceData['template-filename'] = $file;
00440 $result = eZTemplateFileResource::handleResourceData( $tpl, $this, $resourceData, $method, $extraParameters );
00441 $oldKeys = array_pop( $this->KeyStack );
00442 $this->Keys = $oldKeys;
00443 return $result;
00444 }
00445
00446
00447
00448
00449 function createOverrideCache()
00450 {
00451 if ( isset( $GLOBALS['eZSiteBasics'] ) )
00452 {
00453 if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and
00454 $GLOBALS['eZSiteBasics']['no-cache-adviced'] )
00455 return false;
00456 }
00457 global $eZTemplateOverrideCacheNoPermission;
00458 if ( $eZTemplateOverrideCacheNoPermission == "nocache" )
00459 {
00460 return false;
00461 }
00462
00463 $ini =& eZINI::instance( 'site.ini' );
00464 $useOverrideCache = true;
00465 if ( $ini->hasVariable( 'OverrideSettings', 'Cache' ) )
00466 $useOverrideCache = $ini->variable( 'OverrideSettings', 'Cache' ) == 'enabled';
00467
00468 $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
00469 if ( !$this->OnlyStandard )
00470 $siteBase = eZTemplateDesignResource::designSetting( 'site' );
00471
00472 $overrideKeys = $this->overrideKeys();
00473
00474 $overrideKey = eZSys::ezcrc32( implode( ',', $overrideKeys ) . $siteBase . $standardBase );
00475 $cacheDir = eZSys::cacheDirectory();
00476
00477 $overrideCacheFile = $cacheDir.'/override/override_'.$overrideKey.'.php';
00478
00479
00480
00481 if ( !$useOverrideCache or
00482 !file_exists( $overrideCacheFile ) )
00483 {
00484 $matchFileArray = $this->overrideArray( $this->OverrideSiteAccess );
00485
00486
00487 include_once( 'lib/ezutils/classes/ezphpcreator.php' );
00488 $phpCache = new eZPHPCreator( "$cacheDir/override", "override_$overrideKey.php" );
00489
00490 $phpCode = "\$GLOBALS['eZOverrideTemplateCacheMap'] = array (\n";
00491 $numMatchFiles = count ( $matchFileArray );
00492 $countMatchFiles = 0;
00493
00494 foreach ( array_keys( $matchFileArray ) as $matchKey )
00495 {
00496 $countMatchFiles++;
00497 $phpCode .= '\'' . eZSys::ezcrc32( $matchKey ) . '\' => ';
00498 if ( isset( $matchFileArray[$matchKey]['custom_match'] ) )
00499 {
00500 $baseDir = isset( $matchFileArray[$matchKey]['base_dir'] ) ? $matchFileArray[$matchKey]['base_dir'] : '';
00501 $defaultMatchFile = $baseDir . $matchKey;
00502 // Custom override matching
00503 // $phpCode .= " case \"$matchKey\":\n {\n";
00504
00505 $matchConditionArray = array();
00506 foreach ( $matchFileArray[$matchKey]['custom_match'] as $customMatch )
00507 {
00508 $matchCondition = "";
00509 $condCount = 0;
00510 if ( is_array( $customMatch['conditions'] ) )
00511 {
00512 foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey )
00513 {
00514 if ( $condCount > 0 )
00515 $matchCondition .= " and ";
00516
00517 // Have a special substring match for subtree matching
00518
00519 $matchCondition .= "( isset( \$matchKeys[\\'$conditionKey\\'] ) and ";
00520 if ( $conditionKey == 'url_alias' )
00521 {
00522 $matchCondition .=
00523 "( strpos( \$matchKeys[\\'url_alias\\'], \\'" . $customMatch['conditions']['url_alias'] . "\\' ) === 0 ) )";
00524 }
00525 else
00526 {
00527 $matchCondition .=
00528 "( is_array( \$matchKeys[\\'$conditionKey\\'] ) ? " .
00529 "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'$conditionKey\\'] ) : " .
00530 "\$matchKeys[\\'$conditionKey\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )";
00531 }
00532
00533 $condCount++;
00534 }
00535 }
00536
00537 // Only create custom match if conditions are defined
00538 if ( $matchCondition != "" )
00539 {
00540 // $phpCode .= " if ( $matchCondition )\n {\n";
00541 // $phpCode .= " return '" . $customMatch['match_file'] . "';\n }\n";
00542 if ( $condCount > 1 )
00543 $matchConditionArray[] = array( 'condition' => '(' . $matchCondition . ')',
00544 'matchFile' => $customMatch['match_file'] );
00545 else
00546 $matchConditionArray[] = array( 'condition' => $matchCondition,
00547 'matchFile' => $customMatch['match_file'] );
00548 }
00549 else
00550 {
00551 // No override conditions defined. Override default match file
00552 $defaultMatchFile = $customMatch['match_file'];
00553 }
00554 }
00555
00556 $phpCode .= "array ( 'eval' => 1, 'code' => ";
00557
00558 $phpCode .= "'";
00559
00560 foreach ( array_keys( $matchConditionArray ) as $key )
00561 {
00562 $phpCode .= '(' . $matchConditionArray[$key]['condition'] . ' ? ' . "\\'" . $matchConditionArray[$key]['matchFile'] . "\\'" . ' : ';
00563 }
00564
00565 $phpCode .= "\\'" . $defaultMatchFile . "\\'";
00566
00567 for ( $condCount = 0; $condCount < count( $matchConditionArray ); $condCount++)
00568 {
00569 $phpCode .= ')';
00570 }
00571
00572 $phpCode .= "' )";
00573 }
00574 else
00575 {
00576 $phpCode .= "'". $matchFileArray[$matchKey]['base_dir'] . $matchKey . "'";
00577 // Plain matching without custom override
00578 // $phpCode .= "case \"$matchKey\":\n {\n
00579 // return '" .
00580 // $matchFileArray[$matchKey]['base_dir'] . $matchKey . "';}\nbreak;\n";
00581 }
00582
00583 if ( $countMatchFiles < $numMatchFiles )
00584 {
00585 $phpCode .= ",\n";
00586 }
00587 else
00588 {
00589 $phpCode .= ");\n";
00590 }
00591 }
00592 // $phpCode .= "default:\n {\n}break;\n}";
00593
00594 // $phpCode .= "}\n";
00595
00596 // $phpCode .= "function overrideFile( \$matchFile, \$matchKeys )\n{\n ";
00597 // $phpCode .= ' eval( "\$return = " . $GLOBALS[\'eZOverrideTemplateCacheMap\'][$matchFile] . ";" );' . "\n";
00598
00599
00600 $phpCache->addCodePiece( $phpCode );
00601 if ( $useOverrideCache and
00602 $phpCache->store() )
00603 {
00604
00605 }
00606 else
00607 {
00608 if ( $useOverrideCache )
00609 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.", "eZTemplateDesignResource::createOverrideCache" );
00610
00611
00612 $eZTemplateOverrideCacheNoPermission = 'nocache';
00613 $overrideCacheFile = false;
00614
00615 }
00616 }
00617
00618 return $overrideCacheFile;
00619 }
00620
00621
00622
00623
00624
00625 function overrideKeys( $siteAccess = false )
00626 {
00627
00628 $keys = array();
00629 $designStartPath = eZTemplateDesignResource::designStartPath();
00630 $keys[] = $designStartPath;
00631
00632
00633 if ( $siteAccess )
00634 {
00635
00636 $ini =& eZINI::instance( 'site.ini', 'settings', null, null, true );
00637 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
00638 eZExtension::prependExtensionSiteAccesses( $siteAccess, $ini, false, 'siteaccess' );
00639 $ini->loadCache();
00640
00641 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true );
00642 $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
00643 eZExtension::prependExtensionSiteAccesses( $siteAccess, $overrideINI, false, 'siteaccess', false );
00644 $overrideINI->loadCache();
00645
00646 $standardBase = $ini->variable( "DesignSettings", "StandardDesign" );
00647 $keys[] = "siteaccess/$siteAccess";
00648 $keys[] = $standardBase;
00649 if ( !$this->OnlyStandard )
00650 {
00651 $siteBase = $ini->variable( "DesignSettings", "SiteDesign" );
00652 $keys[] = $siteBase;
00653 }
00654 }
00655 else
00656 {
00657 $ini =& eZINI::instance();
00658 if ( $this->OverrideSiteAccess != false )
00659 {
00660 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true );
00661 eZExtension::prependExtensionSiteAccesses( $siteAccess, $overrideINI, false, 'siteaccess' );
00662 $overrideINI->prependOverrideDir( "siteaccess/$this->OverrideSiteAccess", false, 'siteaccess', false );
00663 $overrideINI->loadCache();
00664 $keys[] = "siteaccess/$this->OverrideSiteAccess";
00665 }
00666 else
00667 {
00668 $overrideINI =& eZINI::instance( 'override.ini' );
00669 $currentAccess = $GLOBALS['eZCurrentAccess'];
00670 $siteAccess = $currentAccess['name'];
00671 $keys[] = "siteaccess/$siteAccess";
00672 }
00673
00674 $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
00675 $keys[] = $standardBase;
00676 $siteBase = eZTemplateDesignResource::designSetting( 'site' );
00677 if ( !$this->OnlyStandard )
00678 $keys[] = $siteBase;
00679 }
00680
00681
00682 $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" );
00683 $keys = array_merge( $keys, $additionalSiteDesignList );
00684
00685
00686 include_once( 'lib/ezutils/classes/ezextension.php' );
00687 $extensionDirectory = eZExtension::baseDirectory();
00688
00689 $designINI =& eZINI::instance( 'design.ini' );
00690 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );
00691
00692 return array_merge( $keys, $extensions );
00693 }
00694
00695
00696
00697
00698 function serializeOverrides( $siteAccess = false,
00699 $matchKeys = array() )
00700 {
00701 }
00702
00703
00704
00705
00706
00707 function allDesignBases()
00708 {
00709 $ini =& eZINI::instance();
00710
00711 include_once( 'lib/ezutils/classes/ezextension.php' );
00712 $extensionDirectory = eZExtension::baseDirectory();
00713 $designINI =& eZINI::instance( 'design.ini' );
00714 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );
00715
00716 $bases = array();
00717
00718 $std_base = eZTemplateDesignResource::designSetting( 'standard' );
00719 $site_base = eZTemplateDesignResource::designSetting( 'site' );
00720 $SiteDesignList = $ini->variable( 'DesignSettings', 'AdditionalSiteDesignList' );
00721 array_unshift( $SiteDesignList, $site_base );
00722 $SiteDesignList[] = $std_base;
00723 $designStartPath = eZTemplateDesignResource::designStartPath();
00724 foreach ( $SiteDesignList as $design )
00725 {
00726 $bases[] = "$designStartPath/$design";
00727 foreach( $extensions as $extension )
00728 {
00729 $bases[] = "$extensionDirectory/$extension/$designStartPath/$design";
00730 }
00731 }
00732 return $bases;
00733 }
00734
00735
00736
00737
00738
00739
00740 function designStartPath()
00741 {
00742 $designStartPath = false;
00743 if ( isset( $GLOBALS['eZTemplateDesignResourceStartPath'] ) )
00744 {
00745 $designStartPath = $GLOBALS['eZTemplateDesignResourceStartPath'];
00746 }
00747 if ( !$designStartPath )
00748 $designStartPath = 'design';
00749 return $designStartPath;
00750 }
00751
00752
00753
00754
00755
00756
00757
00758 function setDesignStartPath( $path )
00759 {
00760 $GLOBALS['eZTemplateDesignResourceStartPath'] = $path;
00761 }
00762
00763
00764
00765
00766
00767
00768 function overrideArray( $siteAccess = false, $onlyStandard = null )
00769 {
00770 if ( $onlyStandard === null and
00771 isset( $this ) and
00772 get_class( $this ) == 'eztemplatedesignresource' )
00773 $onlyStandard = $this->OnlyStandard;
00774
00775
00776 if ( $siteAccess )
00777 {
00778
00779 $ini =& eZINI::instance( 'site.ini', 'settings', null, null, true );
00780 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
00781 eZExtension::prependExtensionSiteAccesses( $siteAccess, $ini, false, 'siteaccess' );
00782 $ini->loadCache();
00783
00784 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true );
00785 $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
00786 eZExtension::prependExtensionSiteAccesses( $siteAccess, $overrideINI, false, 'siteaccess', false );
00787 $overrideINI->loadCache();
00788
00789 $standardBase = $ini->variable( "DesignSettings", "StandardDesign" );
00790 if ( !$onlyStandard )
00791 $siteBase = $ini->variable( "DesignSettings", "SiteDesign" );
00792 }
00793 else
00794 {
00795 $ini =& eZINI::instance();
00796 $overrideINI =& eZINI::instance( 'override.ini' );
00797 $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
00798 $siteBase = eZTemplateDesignResource::designSetting( 'site' );
00799 }
00800
00801 $designStartPath = eZTemplateDesignResource::designStartPath();
00802
00803 $additionalSiteDesignList = $ini->variable( 'DesignSettings', 'AdditionalSiteDesignList' );
00804
00805 $additionalSiteDesignList = array_reverse( $additionalSiteDesignList );
00806
00807
00808 include_once( 'lib/ezfile/classes/ezdir.php' );
00809
00810
00811 $matchFilesArray = array();
00812
00813
00814
00815 $resourceArray[] = "$designStartPath/$standardBase/templates";
00816 $resourceArray[] = "$designStartPath/$standardBase/override/templates";
00817
00818
00819 foreach ( $additionalSiteDesignList as $additionalSiteDesign )
00820 {
00821 $resourceArray[] = "$designStartPath/$additionalSiteDesign/override/templates";
00822 $resourceArray[] = "$designStartPath/$additionalSiteDesign/templates";
00823 }
00824
00825 $resourceArray[] = "$designStartPath/$siteBase/override/templates";
00826 $resourceArray[] = "$designStartPath/$siteBase/templates";
00827
00828
00829 include_once( 'lib/ezutils/classes/ezextension.php' );
00830 $extensionDirectory = eZExtension::baseDirectory();
00831
00832 $designINI =& eZINI::instance( 'design.ini' );
00833 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' );
00834
00835 foreach ( $extensions as $extension )
00836 {
00837
00838 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$standardBase/templates";
00839 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$standardBase/override/templates";
00840
00841
00842 foreach ( $additionalSiteDesignList as $additionalSiteDesign )
00843 {
00844 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$additionalSiteDesign/override/templates";
00845 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$additionalSiteDesign/templates";
00846 }
00847
00848
00849 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$siteBase/override/templates";
00850 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$siteBase/templates";
00851 }
00852
00853 foreach ( $resourceArray as $resource )
00854 {
00855 $sourceFileArray = eZDir::recursiveFindRelative( $resource, "", "tpl" );
00856 foreach ( array_keys( $sourceFileArray ) as $sourceKey )
00857 {
00858 $matchFileArray[$sourceFileArray[$sourceKey]]['base_dir'] = $resource;
00859 $matchFileArray[$sourceFileArray[$sourceKey]]['template'] = $sourceFileArray[$sourceKey];
00860 }
00861 }
00862
00863
00864
00865 $overrideSettingGroupArray =& $overrideINI->groups();
00866 if ( isset( $GLOBALS['eZDesignOverrides'] ) )
00867 {
00868 $overrideSettingGroupArray = array_merge( $overrideSettingGroupArray, $GLOBALS['eZDesignOverrides'] );
00869 }
00870
00871 foreach ( array_keys( $overrideSettingGroupArray ) as $overrideSettingKey )
00872 {
00873 $overrideName = $overrideSettingKey;
00874 $overrideSource = "/" . $overrideSettingGroupArray[$overrideSettingKey]['Source'];
00875
00876 $overrideMatchConditionArray =& $overrideSettingGroupArray[$overrideSettingKey]['Match'];
00877 $overrideMatchFile =& $overrideSettingGroupArray[$overrideSettingKey]['MatchFile'];
00878
00879 $overrideMatchFilePath = false;
00880
00881 $triedFiles = array();
00882 $resourceInUse = false;
00883 foreach ( $resourceArray as $resource )
00884 {
00885 if ( file_exists( $resource . "/" . $overrideMatchFile ) )
00886 {
00887 $overrideMatchFilePath = $resource . "/" . $overrideMatchFile;
00888 $resourceInUse = $resource;
00889 }
00890 else
00891 $triedFiles[] = $resource . '/' . $overrideMatchFile;
00892 }
00893
00894 $customMatchArray = array();
00895 $customMatchArray['conditions'] = $overrideMatchConditionArray;
00896 $customMatchArray['match_file'] = $overrideMatchFilePath;
00897 $customMatchArray['override_name'] = $overrideName;
00898 $matchFileArray[$overrideSource]['custom_match'][] = $customMatchArray;
00899 if( $resourceInUse && !isset($matchFileArray[$overrideSource]['base_dir']))
00900 {
00901 $matchFileArray[$overrideSource]['base_dir'] = $resource;
00902 $matchFileArray[$overrideSource]['template'] = $overrideSource;
00903 }
00904 if ( ! $overrideMatchFilePath )
00905 {
00906 eZDebug::writeError( "Custom match file: path '$overrideMatchFile' not found in any resource. Check template settings in settings/override.ini",
00907 "eZTemplateDesignResource::overrideArray" );
00908 eZDebug::writeError( implode( ', ', $triedFiles ),
00909 "eZTemplateDesignResource::overrideArray, tried files" );
00910 }
00911
00912 }
00913
00914 return $matchFileArray;
00915 }
00916
00917
00918
00919
00920
00921
00922 function setKeys( $keys )
00923 {
00924 $this->mergeKeys( $this->Keys, $keys );
00925 }
00926
00927
00928
00929
00930 function removeKey( $key )
00931 {
00932 if ( isset( $this->Keys[$key] ) )
00933 unset( $this->Keys[$key] );
00934 }
00935
00936
00937
00938
00939
00940 function mergeKeys( &$originalKeys, $keys )
00941 {
00942 foreach ( $keys as $key )
00943 {
00944 if ( count( $key ) >= 2 )
00945 $originalKeys[$key[0]] = $key[1];
00946 }
00947 }
00948
00949
00950
00951
00952
00953 function clearKeys()
00954 {
00955 $this->Keys = array();
00956 }
00957
00958
00959
00960
00961
00962 function &keys()
00963 {
00964 $keys =& $this->Keys;
00965 if ( isset( $GLOBALS['eZDesignKeys'] ) )
00966 {
00967 $keys = array_merge( $keys, $GLOBALS['eZDesignKeys'] );
00968
00969 }
00970 return $keys;
00971 }
00972
00973
00974
00975
00976 function addGlobalOverride( $name, $source, $match, $subdir, $matches )
00977 {
00978 if ( !isset( $GLOBALS['eZDesignOverrides'] ) )
00979 $GLOBALS['eZDesignOverrides'] = array();
00980 $GLOBALS['eZDesignOverrides'][$name] = array( 'Source' => $source,
00981 'MatchFile' => $match,
00982 'Subdir' => $subdir,
00983 'Match' => $matches );
00984 }
00985
00986
00987
00988
00989 function &instance()
00990 {
00991 $instance =& $GLOBALS["eZTemplateDesignResourceInstance"];
00992 if ( get_class( $instance ) != "eztemplatedesignresource" )
00993 {
00994 $instance = new eZTemplateDesignResource();
00995 }
00996 return $instance;
00997 }
00998
00999
01000
01001
01002 function &standardInstance()
01003 {
01004 $instance =& $GLOBALS["eZTemplateStandardResourceInstance"];
01005 if ( get_class( $instance ) != "eztemplatedesignresource" )
01006 {
01007 $instance = new eZTemplateDesignResource( 'standard', true );
01008 }
01009 return $instance;
01010 }
01011
01012
01013
01014
01015 function setOverrideAccess( $siteAccess )
01016 {
01017 $this->OverrideSiteAccess = $siteAccess;
01018 }
01019
01020 var $Keys;
01021 var $OnlyStandard;
01022 var $OverrideSiteAccess = false;
01023 }
01024
01025 ?>