| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTemplatedesignresource class 4 // 5 // Created on: <14-Sep-2002 15:37:17 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file eztemplatedesignresource.php 30 */ 31 32 /*! 33 \class eZTemplatedesignresource eztemplatedesignresource.php 34 \brief Handles template file loading with override support 35 36 */ 37 38 include_once ( "lib/eztemplate/classes/eztemplatefileresource.php" ); 39 include_once ( "lib/ezutils/classes/ezini.php" ); 40 41 class eZTemplateDesignResource extends eZTemplateFileResource 42 { 43 /*! 44 Initializes with a default resource name "design". 45 */ 46 function eZTemplateDesignResource( $name = "design", $onlyStandard = false ) 47 { 48 $this->eZTemplateFileResource( $name, true ); 49 $this->Keys = array(); 50 $this->KeyStack = array(); 51 $this->OnlyStandard = $onlyStandard; 52 } 53 54 /*! 55 */ 56 function templateNodeTransformation( $functionName, &$node, 57 &$tpl, &$resourceData, $parameters, $namespaceValue ) 58 { 59 if ( $this->Name != 'design' and $this->Name != 'standard' ) 60 return false; 61 62 $file = $resourceData['template-name']; 63 $matchFileArray = $this->overrideArray( $this->OverrideSiteAccess ); 64 $matchList = array(); 65 foreach ( $matchFileArray as $matchFile ) 66 { 67 if ( !isset( $matchFile['template'] ) ) 68 continue; 69 if ( $matchFile['template'] == ('/' . $file) ) 70 { 71 $matchList[] = $matchFile; 72 } 73 } 74 75 $resourceName = $resourceData['resource']; 76 $resourceNameText = eZPHPCreator::variableText( $resourceName ); 77 78 $designKeysName = 'dKeys'; 79 if ( $resourceName == 'standard' ) 80 $designKeysName = 'rKeys'; 81 82 $newNodes = array(); 83 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" . 84 "{\n" . 85 " \$resH =& \$tpl->resourceHandler( $resourceNameText );\n" . 86 " \$$designKeysName =& \$resH->keys();" . 87 "\n" . 88 "}\n" ); 89 foreach ( $matchList as $match ) 90 { 91 $basedir = $match['base_dir']; 92 $template = $match['template']; 93 $file = $basedir . $template; 94 $spacing = 0; 95 $addFileResource = true; 96 if ( isset( $match['custom_match'] ) ) 97 { 98 $spacing = 4; 99 $customMatchList = $match['custom_match']; 100 $matchCount = 0; 101 foreach ( $customMatchList as $customMatch ) 102 { 103 $matchConditionCount = count( $customMatch['conditions'] ); 104 $code = ''; 105 if ( $matchCount > 0 ) 106 { 107 $code = "else " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . ""; 108 } 109 if ( $matchConditionCount > 0 ) 110 { 111 if ( $matchCount > 0 ) 112 $code .= " "; 113 $code .= "if " . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "( "; 114 } 115 $ifLength = strlen( $code ); 116 $conditionCount = 0; 117 foreach ( $customMatch['conditions'] as $conditionName => $conditionValue ) 118 { 119 if ( $conditionCount > 0 ) 120 $code .= " and\n" . str_repeat( ' ', $ifLength ); 121 $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 ); 122 $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 ); 123 if ( $conditionName == 'url_alias' ) 124 { 125 $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and strpos( \$" . $designKeysName . "[$conditionNameText], $conditionValueText ) ===0 "; 126 } 127 else 128 $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and \$" . $designKeysName . "[$conditionNameText] == $conditionValueText"; 129 ++$conditionCount; 130 } 131 if ( $matchConditionCount > 0 ) 132 { 133 $code .= " )\n"; 134 } 135 if ( $matchConditionCount > 0 or $matchCount > 0 ) 136 { 137 $code .= "{"; 138 } 139 $matchFile = $customMatch['match_file']; 140 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code ); 141 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', 142 $matchFile, $matchFile, 143 EZ_RESOURCE_FETCH, false, 144 $node[4], array( 'spacing' => $spacing ), 145 $namespaceValue ); 146 if ( $matchConditionCount > 0 or $matchCount > 0 ) 147 { 148 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" ); 149 } 150 ++$matchCount; 151 if ( $matchConditionCount == 0 ) 152 { 153 $addFileResource = false; 154 break; 155 } 156 } 157 if ( $addFileResource ) 158 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else" . ( $resourceData['use-comments'] ? ( "/*TDR:" . __LINE__ . "*/" ) : "" ) . "\n{" ); 159 } 160 if ( $addFileResource ) 161 { 162 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', 163 $file, $file, 164 EZ_RESOURCE_FETCH, false, 165 $node[4], array( 'spacing' => $spacing ), 166 $namespaceValue ); 167 } 168 if ( isset( $match['custom_match'] ) and $addFileResource ) 169 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" ); 170 } 171 172 return $newNodes; 173 } 174 175 /*! 176 \static 177 \return the sitedesign for the design type \a $type, currently \c standard and \c site is allowed. 178 If no sitedesign is set it will fetch it from site.ini. 179 */ 180 function designSetting( $type = 'standard' ) 181 { 182 if ( $type != 'standard' and 183 $type != 'site' ) 184 { 185 eZDebug::writeWarning( "Cannot retrieve designsetting for type '$type'", 'eZTemplateDesignResource::designSetting' ); 186 $retValue = null; 187 return $retValue; 188 } 189 $designSettings =& $GLOBALS['eZTemplateDesignSetting']; 190 if ( !isset( $designSettings ) ) 191 $designSettings = array(); 192 $designSetting =& $designSettings[$type]; 193 $siteBasics =& $GLOBALS['eZSiteBasics']; 194 if ( $type == 'site' and 195 isset( $siteBasics['site-design-override'] ) and 196 is_string( $siteBasics['site-design-override'] ) ) 197 { 198 return $siteBasics['site-design-override']; 199 } 200 201 if ( isset( $designSetting ) ) 202 { 203 return $designSetting; 204 } 205 $ini =& eZINI::instance(); 206 if ( $type == 'standard' ) 207 $designSetting = $ini->variable( "DesignSettings", "StandardDesign" ); 208 else if ( $type == 'site' ) 209 $designSetting = $ini->variable( "DesignSettings", "SiteDesign" ); 210 return $designSetting; 211 } 212 213 /*! 214 Sets the sitedesign for the design type \a $type, currently \c standard and \c site is allowed. 215 The design is set to \a $designSetting. 216 */ 217 function setDesignSetting( $designSetting, $type = 'standard' ) 218 { 219 if ( $type != 'standard' and 220 $type != 'site' ) 221 { 222 eZDebug::writeWarning( "Cannot set designsetting '$designSetting' for type '$type'", 'eZTemplateDesignResource::setDesignSetting' ); 223 return; 224 } 225 $designSettings =& $GLOBALS['eZTemplateDesignSetting']; 226 if ( !isset( $designSettings ) ) 227 $designSettings = array(); 228 $designSettings[$type] = $designSetting; 229 } 230 231 /*! 232 \return the rules used for matching design elements. \a $element defines the element type. 233 */ 234 function fileMatchingRules( $element, $path, $onlyStandard = false ) 235 { 236 eZDebug::accumulatorStart( 'matching_rules', 'override', 'Matching rules' ); 237 238 $standardBase = eZTemplateDesignResource::designSetting( 'standard' ); 239 if ( !$onlyStandard ) 240 $siteBase = eZTemplateDesignResource::designSetting( 'site' ); 241 242 $ini =& eZINI::instance(); 243 $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" ); 244 245 include_once ( 'lib/ezutils/classes/ezextension.php' ); 246 $extensionDirectory = eZExtension::baseDirectory(); 247 248 $designINI =& eZINI::instance( 'design.ini' ); 249 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' ); 250 251 $matches = array(); 252 253 $elementText = ''; 254 if ( $element !== false ) 255 $elementText = $element . '/'; 256 257 $designStartPath = eZTemplateDesignResource::designStartPath(); 258 259 $designList = $additionalSiteDesignList; 260 array_unshift( $designList, $siteBase ); 261 $designList[] = $standardBase; 262 263 if ( $onlyStandard ) 264 $designList = array( $standardBase ); 265 266 267 foreach ( $designList as $design ) 268 { 269 foreach ( $extensions as $extension ) 270 { 271 $matches[] = array( 'file' => "$extensionDirectory/$extension/$designStartPath/$design/override/$elementText$path", 272 'type' => 'override' ); 273 } 274 $matches[] = array( 'file' => "$designStartPath/$design/override/$elementText$path", 275 'type' => 'override' ); 276 } 277 278 foreach ( $designList as $design ) 279 { 280 foreach ( $extensions as $extension ) 281 { 282 $matches[] = array( 'file' => "$extensionDirectory/$extension/$designStartPath/$design/$elementText$path", 283 'type' => 'normal' ); 284 } 285 $matches[] = array( 'file' => "$designStartPath/$design/$elementText$path", 286 'type' => 'normal' ); 287 } 288 eZDebug::accumulatorStop( 'matching_rules' ); 289 return $matches; 290 } 291 292 /*! 293 Loads the template file if it exists, also sets the modification timestamp. 294 Returns true if the file exists. 295 */ 296 function handleResource( &$tpl, &$resourceData, $method, &$extraParameters ) 297 { 298 $path =& $resourceData['template-name']; 299 300 $matchKeys = $this->Keys; 301 if ( isset( $GLOBALS['eZDesignKeys'] ) ) 302 { 303 $matchKeys = array_merge( $matchKeys, $GLOBALS['eZDesignKeys'] ); 304 unset( $GLOBALS['eZDesignKeys'] ); 305 $this->Keys = $matchKeys; 306 } 307 if ( is_array( $extraParameters ) and 308 isset( $extraParameters['ezdesign:keys'] ) ) 309 { 310 $this->mergeKeys( $matchKeys, $extraParameters['ezdesign:keys'] ); 311 } 312 $this->KeyStack[] = $this->Keys; 313 $this->Keys = $matchKeys; 314 315 eZDebug::accumulatorStart( 'override_cache', 'override', 'Cache load' ); 316 317 $overrideCacheFile = $this->createOverrideCache(); 318 319 if ( $overrideCacheFile ) 320 { 321 include_once( $overrideCacheFile ); 322 $cacheMap =& $GLOBALS['eZOverrideTemplateCacheMap'][eZSys::ezcrc32( '/' . $path )]; 323 if ( !is_string( $cacheMap ) and trim( $cacheMap['code'] ) ) 324 { 325 eval( "\$matchFile = " . $cacheMap['code'] . ";" ); 326 } 327 else 328 { 329 $matchFile =& $cacheMap; 330 } 331 $match['file'] = $matchFile; 332 } 333 else 334 { 335 $template = "/" . $path; 336 // TODO add correct memory cache 337 // $matchFileArray = false; 338 $matchFileArray =& $GLOBALS['eZTemplateOverrideArray_' . $this->OverrideSiteAccess]; 339 if ( !is_array( $matchFileArray ) ) 340 { 341 $matchFileArray = $this->overrideArray( $this->OverrideSiteAccess ); 342 } 343 344 $matchFile = $matchFileArray[$template]; 345 346 if ( isset( $matchFile['custom_match'] ) ) 347 { 348 $matchFound = false; 349 foreach ( $matchFile['custom_match'] as $customMatch ) 350 { 351 $matchOverride = true; 352 if ( count( $customMatch['conditions'] ) > 0 ) 353 { 354 foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey ) 355 { 356 // Create special substring match for subtree override 357 if ( $conditionKey == 'url_alias' ) 358 { 359 if ( strpos( $matchKeys['url_alias'], $customMatch['conditions'][$conditionKey] ) === 0 ) 360 { 361 } 362 else 363 { 364 $matchOverride = false; 365 } 366 } 367 else if ( isset( $matchKeys[$conditionKey] ) and 368 isset( $customMatch['conditions'][$conditionKey] ) ) 369 { 370 if ( is_array( $matchKeys[$conditionKey] ) ) 371 { 372 if ( !in_array( $customMatch['conditions'][$conditionKey], $matchKeys[$conditionKey] ) ) 373 { 374 $matchOverride = false; 375 } 376 } 377 else if ( $matchKeys[$conditionKey] != $customMatch['conditions'][$conditionKey] ) 378 { 379 $matchOverride = false; 380 } 381 } 382 else 383 { 384 $matchOverride = false; 385 } 386 } 387 if ( $matchOverride == true ) 388 { 389 $match['file'] = $customMatch['match_file']; 390 $matchFound = true; 391 break; 392 } 393 else 394 { 395 } 396 } 397 else 398 { 399 // Default match without conditions 400 $match['file'] = $customMatch['match_file']; 401 $matchFound = true; 402 } 403 } 404 if ( !$matchFound ) 405 $match['file'] = $matchFile['base_dir'] . $matchFile['template']; 406 } 407 else 408 { 409 $match['file'] = $matchFile['base_dir'] . $matchFile['template']; 410 } 411 } 412 eZDebug::accumulatorStop( 'override_cache' ); 413 if ( !isset( $match ) or $match === null ) 414 return false; 415 416 $file = $match["file"]; 417 418 $matchedKeys = array(); 419 $usedKeys = array(); 420 foreach ( $matchKeys as $matchKeyName => $matchKeyValue ) 421 { 422 $usedKeys[$matchKeyName] = $matchKeyValue; 423 } 424 $extraParameters['ezdesign:used_keys'] = $usedKeys; 425 $extraParameters['ezdesign:matched_keys'] = $matchedKeys; 426 $tpl->setVariable( 'used', $usedKeys, 'DesignKeys' ); 427 $tpl->setVariable( 'matched', $matchedKeys, 'DesignKeys' ); 428 $resourceData['template-filename'] = $file; 429 $result = eZTemplateFileResource::handleResourceData( $tpl, $this, $resourceData, $method, $extraParameters ); 430 $oldKeys = array_pop( $this->KeyStack ); 431 $this->Keys = $oldKeys; 432 return $result; 433 } 434 435 /*! 436 Generates the cache for the template override matching. 437 */ 438 function createOverrideCache() 439 { 440 if ( isset( $GLOBALS['eZSiteBasics'] ) ) 441 { 442 if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and 443 $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) 444 return false; 445 } 446 global $eZTemplateOverrideCacheNoPermission; 447 if ( $eZTemplateOverrideCacheNoPermission == "nocache" ) 448 { 449 return false; 450 } 451 452 $ini =& eZINI::instance( 'site.ini' ); 453 $useOverrideCache = true; 454 if ( $ini->hasVariable( 'OverrideSettings', 'Cache' ) ) 455 $useOverrideCache = $ini->variable( 'OverrideSettings', 'Cache' ) == 'enabled'; 456 457 $standardBase = eZTemplateDesignResource::designSetting( 'standard' ); 458 if ( !$this->OnlyStandard ) 459 $siteBase = eZTemplateDesignResource::designSetting( 'site' ); 460 461 $overrideKeys = $this->overrideKeys(); 462 463 $overrideKey = eZSys::ezcrc32( implode( ',', $overrideKeys ) . $siteBase . $standardBase ); 464 $cacheDir = eZSys::cacheDirectory(); 465 466 $overrideCacheFile = $cacheDir.'/override/override_'.$overrideKey.'.php'; 467 468 // Build matching cache only of it does not already exists, 469 // or override file has been updated 470 if ( !$useOverrideCache or 471 !file_exists( $overrideCacheFile ) ) 472 { 473 $matchFileArray = $this->overrideArray( $this->OverrideSiteAccess ); 474 475 // Generate PHP compiled cache file. 476 include_once ( 'lib/ezutils/classes/ezphpcreator.php' ); 477 $phpCache = new eZPHPCreator( "$cacheDir/override", "override_$overrideKey.php" ); 478 479 $phpCode = "\$GLOBALS['eZOverrideTemplateCacheMap'] = array (\n"; 480 $numMatchFiles = count ( $matchFileArray ); 481 $countMatchFiles = 0; 482 // $phpCode .= "switch ( \$matchFile )\n{\n "; 483 foreach ( array_keys( $matchFileArray ) as $matchKey ) 484 { 485 $countMatchFiles++; 486 $phpCode .= '\'' . eZSys::ezcrc32( $matchKey ) . '\' => '; 487 if ( isset( $matchFileArray[$matchKey]['custom_match'] ) ) 488 { 489 $baseDir = isset( $matchFileArray[$matchKey]['base_dir'] ) ? $matchFileArray[$matchKey]['base_dir'] : ''; 490 $defaultMatchFile = $baseDir . $matchKey; 491 // Custom override matching 492 // $phpCode .= " case \"$matchKey\":\n {\n"; 493 494 $matchConditionArray = array(); 495 foreach ( $matchFileArray[$matchKey]['custom_match'] as $customMatch ) 496 { 497 $matchCondition = ""; 498 $condCount = 0; 499 if ( is_array( $customMatch['conditions'] ) ) 500 { 501 foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey ) 502 { 503 if ( $condCount > 0 ) 504 $matchCondition .= " and "; 505 506 // Have a special substring match for subtree matching 507 if ( $conditionKey == 'url_alias' ) 508 $matchCondition .= "( strpos( \$matchKeys[\\'url_alias\\'], \\'" . $customMatch['conditions'][$conditionKey] . "\\' ) === 0 )"; 509 else 510 $matchCondition .= "( isset( \$matchKeys[\\'$conditionKey\\'] ) and ( ( is_array( \$matchKeys[\\'$conditionKey\\'] ) and " . 511 "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'$conditionKey\\'] ) ) or " . 512 "\$matchKeys[\\'$conditionKey\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )"; 513 514 $condCount++; 515 } 516 } 517 518 // Only create custom match if conditions are defined 519 if ( $matchCondition != "" ) 520 { 521 // $phpCode .= " if ( $matchCondition )\n {\n"; 522 // $phpCode .= " return '" . $customMatch['match_file'] . "';\n }\n"; 523 if ( $condCount > 1 ) 524 $matchConditionArray[] = array( 'condition' => '(' . $matchCondition . ')', 525 'matchFile' => $customMatch['match_file'] ); 526 else 527 $matchConditionArray[] = array( 'condition' => $matchCondition, 528 'matchFile' => $customMatch['match_file'] ); 529 } 530 else 531 { 532 // No override conditions defined. Override default match file 533 $defaultMatchFile = $customMatch['match_file']; 534 } 535 } 536 537 $phpCode .= "array ( 'eval' => 1, 'code' => "; 538 539 $phpCode .= "'"; 540 541 foreach ( array_keys( $matchConditionArray ) as $key ) 542 { 543 $phpCode .= '(' . $matchConditionArray[$key]['condition'] . '?' . "\\'" . $matchConditionArray[$key]['matchFile'] . "\\'" . ':'; 544 } 545 546 $phpCode .= "\\'" . $defaultMatchFile . "\\'"; 547 548 for ( $condCount = 0; $condCount < count( $matchConditionArray ); $condCount++) 549 { 550 $phpCode .= ')'; 551 } 552 553 $phpCode .= "' )"; 554 } 555 else 556 { 557 $phpCode .= "'". $matchFileArray[$matchKey]['base_dir'] . $matchKey . "'"; 558 // Plain matching without custom override 559 // $phpCode .= "case \"$matchKey\":\n {\n 560 // return '" . 561 // $matchFileArray[$matchKey]['base_dir'] . $matchKey . "';}\nbreak;\n"; 562 } 563 564 if ( $countMatchFiles < $numMatchFiles ) 565 { 566 $phpCode .= ",\n"; 567 } 568 else 569 { 570 $phpCode .= ");\n"; 571 } 572 } 573 // $phpCode .= "default:\n {\n}break;\n}"; 574 575 // $phpCode .= "}\n"; 576 577 // $phpCode .= "function overrideFile( \$matchFile, \$matchKeys )\n{\n "; 578 // $phpCode .= ' eval( "\$return = " . $GLOBALS[\'eZOverrideTemplateCacheMap\'][$matchFile] . ";" );' . "\n"; 579 // $phpCode .= ' return $return;' . "\n}\n\n"; 580 581 $phpCache->addCodePiece( $phpCode ); 582 if ( $useOverrideCache and 583 $phpCache->store() ) 584 { 585 586 } 587 else 588 { 589 if ( $useOverrideCache ) 590 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" ); 591 592 // $GLOBALS['eZTemplateOverrideArray'] =& $matchFileArray; 593 $eZTemplateOverrideCacheNoPermission = 'nocache'; 594 $overrideCacheFile = false; 595 596 } 597 } 598 599 return $overrideCacheFile; 600 } 601 602 /*! 603 \static 604 \return an array with keys that define the current override. 605 */ 606 function overrideKeys( $siteAccess = false ) 607 { 608 // print( "<br>" . xdebug_call_function() . "<br>" ); 609 $keys = array(); 610 $designStartPath = eZTemplateDesignResource::designStartPath(); 611 $keys[] = $designStartPath; 612 613 // fetch the override array from a specific siteacces 614 if ( $siteAccess ) 615 { 616 // Get the design resources 617 $ini =& eZINI::instance( 'site.ini', 'settings', null, null, true ); 618 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 619 eZExtension::prependExtensionSiteAccesses( $siteAccess, $ini, false, 'siteaccess' ); 620 $ini->loadCache(); 621 622 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true ); 623 $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 624 eZExtension::prependExtensionSiteAccesses( $siteAccess, $overrideINI, false, 'siteaccess', false ); 625 $overrideINI->loadCache(); 626 627 $standardBase = $ini->variable( "DesignSettings", "StandardDesign" ); 628 $keys[] = "siteaccess/$siteAccess"; 629 $keys[] = $standardBase; 630 if ( !$this->OnlyStandard ) 631 { 632 $siteBase = $ini->variable( "DesignSettings", "SiteDesign" ); 633 $keys[] = $siteBase; 634 } 635 } 636 else 637 { 638 $ini =& eZINI::instance(); 639 if ( $this->OverrideSiteAccess != false ) 640 { 641 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true ); 642 eZExtension::prependExtensionSiteAccesses( $siteAccess, $overrideINI, false, 'siteaccess' ); 643 $overrideINI->prependOverrideDir( "siteaccess/$this->OverrideSiteAccess", false, 'siteaccess', false ); 644 $overrideINI->loadCache(); 645 $keys[] = "siteaccess/$this->OverrideSiteAccess"; 646 } 647 else 648 { 649 $overrideINI =& eZINI::instance( 'override.ini' ); 650 $currentAccess = $GLOBALS['eZCurrentAccess']; 651 $siteAccess = $currentAccess['name']; 652 $keys[] = "siteaccess/$siteAccess"; 653 } 654 655 $standardBase = eZTemplateDesignResource::designSetting( 'standard' ); 656 $keys[] = $standardBase; 657 $siteBase = eZTemplateDesignResource::designSetting( 'site' ); 658 if ( !$this->OnlyStandard ) 659 $keys[] = $siteBase; 660 } 661 662 663 $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" ); 664 $keys = array_merge( $keys, $additionalSiteDesignList ); 665 666 // Add extension paths 667 include_once ( 'lib/ezutils/classes/ezextension.php' ); 668 $extensionDirectory = eZExtension::baseDirectory(); 669 670 $designINI =& eZINI::instance( 'design.ini' ); 671 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' ); 672 673 return array_merge( $keys, $extensions ); 674 } 675 676 /*! 677 \static 678 */ 679 function serializeOverrides( $siteAccess = false, 680 $matchKeys = array() ) 681 { 682 } 683 684 /*! 685 \static 686 \return Gives all knows bases for avialable sitedesign folders. 687 */ 688 function allDesignBases() 689 { 690 $ini =& eZINI::instance(); 691 692 include_once ( 'lib/ezutils/classes/ezextension.php' ); 693 $extensionDirectory = eZExtension::baseDirectory(); 694 $designINI =& eZINI::instance( 'design.ini' ); 695 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' ); 696 697 $bases = array(); 698 699 $std_base = eZTemplateDesignResource::designSetting( 'standard' ); 700 $site_base = eZTemplateDesignResource::designSetting( 'site' ); 701 $SiteDesignList = $ini->variable( 'DesignSettings', 'AdditionalSiteDesignList' ); 702 array_unshift( $SiteDesignList, $site_base ); 703 $SiteDesignList[] = $std_base; 704 $designStartPath = eZTemplateDesignResource::designStartPath(); 705 foreach ( $SiteDesignList as $design ) 706 { 707 $bases[] = "$designStartPath/$design"; 708 foreach( $extensions as $extension ) 709 { 710 $bases[] = "$extensionDirectory/$extension/$designStartPath/$design"; 711 } 712 } 713 return $bases; 714 } 715 716 /*! 717 \static 718 \return The start path of the design directory, by default it will return \c 'design' 719 To change the directory use setDesignStartPath(). 720 */ 721 function designStartPath() 722 { 723 $designStartPath = false; 724 if ( isset( $GLOBALS['eZTemplateDesignResourceStartPath'] ) ) 725 { 726 $designStartPath = $GLOBALS['eZTemplateDesignResourceStartPath']; 727 } 728 if ( !$designStartPath ) 729 $designStartPath = 'design'; 730 return $designStartPath; 731 } 732 733 /*! 734 \static 735 Changes the design start path which is used to find design files. 736 \param $path Must be a string defining the path or \c false to use default start path. 737 \sa designStartPath(); 738 */ 739 function setDesignStartPath( $path ) 740 { 741 $GLOBALS['eZTemplateDesignResourceStartPath'] = $path; 742 } 743 744 /*! 745 \static 746 \return an array of all the current templates and overrides for them. 747 The current siteaccess is used if none is specified. 748 */ 749 function overrideArray( $siteAccess = false, $onlyStandard = null ) 750 { 751 if ( $onlyStandard === null and 752 isset( $this ) and 753 get_class( $this ) == 'eztemplatedesignresource' ) 754 $onlyStandard = $this->OnlyStandard; 755 756 // fetch the override array from a specific siteacces 757 if ( $siteAccess ) 758 { 759 // Get the design resources 760 $ini =& eZINI::instance( 'site.ini', 'settings', null, null, true ); 761 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 762 eZExtension::prependExtensionSiteAccesses( $siteAccess, $ini, false, 'siteaccess' ); 763 $ini->loadCache(); 764 765 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true ); 766 $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 767 eZExtension::prependExtensionSiteAccesses( $siteAccess, $overrideINI, false, 'siteaccess', false ); 768 $overrideINI->loadCache(); 769 770 $standardBase = $ini->variable( "DesignSettings", "StandardDesign" ); 771 if ( !$onlyStandard ) 772 $siteBase = $ini->variable( "DesignSettings", "SiteDesign" ); 773 } 774 else 775 { 776 $ini =& eZINI::instance(); 777 $overrideINI =& eZINI::instance( 'override.ini' ); 778 $standardBase = eZTemplateDesignResource::designSetting( 'standard' ); 779 $siteBase = eZTemplateDesignResource::designSetting( 'site' ); 780 } 781 782 $designStartPath = eZTemplateDesignResource::designStartPath(); 783 784 $additionalSiteDesignList = $ini->variable( 'DesignSettings', 'AdditionalSiteDesignList' ); 785 // Reverse additionalSiteDesignList so that most prefered design is last 786 $additionalSiteDesignList = array_reverse( $additionalSiteDesignList ); 787 788 // Generate match cache for all templates 789 include_once ( 'lib/ezfile/classes/ezdir.php' ); 790 791 // Build arrays of available files, start with base design and end with most prefered design 792 $matchFilesArray = array(); 793 794 // For each override dir overwrite current default file 795 // TODO: fetch all resource repositories 796 $resourceArray[] = "$designStartPath/$standardBase/templates"; 797 $resourceArray[] = "$designStartPath/$standardBase/override/templates"; 798 799 // Add the additional sitedesigns 800 foreach ( $additionalSiteDesignList as $additionalSiteDesign ) 801 { 802 $resourceArray[] = "$designStartPath/$additionalSiteDesign/override/templates"; 803 $resourceArray[] = "$designStartPath/$additionalSiteDesign/templates"; 804 } 805 806 $resourceArray[] = "$designStartPath/$siteBase/override/templates"; 807 $resourceArray[] = "$designStartPath/$siteBase/templates"; 808 809 // Add extension paths 810 include_once ( 'lib/ezutils/classes/ezextension.php' ); 811 $extensionDirectory = eZExtension::baseDirectory(); 812 813 $designINI =& eZINI::instance( 'design.ini' ); 814 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' ); 815 816 foreach ( $extensions as $extension ) 817 { 818 // Look for standard design in extension 819 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$standardBase/templates"; 820 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$standardBase/override/templates"; 821 822 // Look for aditional sitedesigns in extension 823 foreach ( $additionalSiteDesignList as $additionalSiteDesign ) 824 { 825 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$additionalSiteDesign/override/templates"; 826 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$additionalSiteDesign/templates"; 827 } 828 829 // Look for site base in extention 830 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$siteBase/override/templates"; 831 $resourceArray[] = "$extensionDirectory/$extension/$designStartPath/$siteBase/templates"; 832 } 833 834 foreach ( $resourceArray as $resource ) 835 { 836 $sourceFileArray = eZDir::recursiveFindRelative( $resource, "", "tpl" ); 837 foreach ( array_keys( $sourceFileArray ) as $sourceKey ) 838 { 839 $matchFileArray[$sourceFileArray[$sourceKey]]['base_dir'] = $resource; 840 $matchFileArray[$sourceFileArray[$sourceKey]]['template'] = $sourceFileArray[$sourceKey]; 841 } 842 } 843 844 845 // Load complex/custom override templates 846 $overrideSettingGroupArray =& $overrideINI->groups(); 847 if ( isset( $GLOBALS['eZDesignOverrides'] ) ) 848 { 849 $overrideSettingGroupArray = array_merge( $overrideSettingGroupArray, $GLOBALS['eZDesignOverrides'] ); 850 } 851 852 foreach ( array_keys( $overrideSettingGroupArray ) as $overrideSettingKey ) 853 { 854 $overrideName = $overrideSettingKey; 855 $overrideSource = "/" . $overrideSettingGroupArray[$overrideSettingKey]['Source']; 856 857 $overrideMatchConditionArray =& $overrideSettingGroupArray[$overrideSettingKey]['Match']; 858 $overrideMatchFile =& $overrideSettingGroupArray[$overrideSettingKey]['MatchFile']; 859 860 $overrideMatchFilePath = false; 861 // Find the matching file in the available resources 862 $triedFiles = array(); 863 $resourceInUse = false; 864 foreach ( $resourceArray as $resource ) 865 { 866 if ( file_exists( $resource . "/" . $overrideMatchFile ) ) 867 { 868 $overrideMatchFilePath = $resource . "/" . $overrideMatchFile; 869 $resourceInUse = $resource; 870 } 871 else 872 $triedFiles[] = $resource . '/' . $overrideMatchFile; 873 } 874 875 $customMatchArray = array(); 876 $customMatchArray['conditions'] = $overrideMatchConditionArray; 877 $customMatchArray['match_file'] = $overrideMatchFilePath; 878 $customMatchArray['override_name'] = $overrideName; 879 $matchFileArray[$overrideSource]['custom_match'][] = $customMatchArray; 880 if( $resourceInUse && !isset($matchFileArray[$overrideSource]['base_dir'])) 881 { 882 $matchFileArray[$overrideSource]['base_dir'] = $resource; 883 $matchFileArray[$overrideSource]['template'] = $overrideSource; 884 } 885 if ( ! $overrideMatchFilePath ) 886 { 887 eZDebug::writeError( "Custom match file: path '$overrideMatchFile' not found in any resource. Check template settings in settings/override.ini", 888 "eZTemplateDesignResource::overrideArray" ); 889 eZDebug::writeError( implode( ', ', $triedFiles ), 890 "eZTemplateDesignResource::overrideArray, tried files" ); 891 } 892 893 } 894 895 return $matchFileArray; 896 } 897 898 /*! 899 Sets the override keys to \a $keys, if some of the keys already exists they are overriden 900 by the new keys. 901 \sa clearKeys 902 */ 903 function setKeys( $keys ) 904 { 905 $this->mergeKeys( $this->Keys, $keys ); 906 } 907 908 /*! 909 Removes the given key 910 */ 911 function removeKey( $key ) 912 { 913 if ( isset( $this->Keys[$key] ) ) 914 unset( $this->Keys[$key] ); 915 } 916 917 /*! 918 \private 919 Merges keys set in \a $keys with the array in \a $originalKeys. 920 */ 921 function mergeKeys( &$originalKeys, $keys ) 922 { 923 foreach ( $keys as $key ) 924 { 925 if ( count( $key ) >= 2 ) 926 $originalKeys[$key[0]] = $key[1]; 927 } 928 } 929 930 /*! 931 Removes all override keys. 932 \sa setKeys 933 */ 934 function clearKeys() 935 { 936 $this->Keys = array(); 937 } 938 939 /*! 940 \return the match keys. 941 \sa setKeys 942 */ 943 function &keys() 944 { 945 $keys =& $this->Keys; 946 if ( isset( $GLOBALS['eZDesignKeys'] ) ) 947 { 948 $keys = array_merge( $keys, $GLOBALS['eZDesignKeys'] ); 949 // $this->Keys = $keys; 950 } 951 return $keys; 952 } 953 954 /*! 955 \static 956 */ 957 function addGlobalOverride( $name, $source, $match, $subdir, $matches ) 958 { 959 if ( !isset( $GLOBALS['eZDesignOverrides'] ) ) 960 $GLOBALS['eZDesignOverrides'] = array(); 961 $GLOBALS['eZDesignOverrides'][$name] = array( 'Source' => $source, 962 'MatchFile' => $match, 963 'Subdir' => $subdir, 964 'Match' => $matches ); 965 } 966 967 /*! 968 \return the unique instance of the design resource. 969 */ 970 function &instance() 971 { 972 $instance =& $GLOBALS["eZTemplateDesignResourceInstance"]; 973 if ( get_class( $instance ) != "eztemplatedesignresource" ) 974 { 975 $instance = new eZTemplateDesignResource(); 976 } 977 return $instance; 978 } 979 980 /*! 981 \return the unique instance of the standard resource. 982 */ 983 function &standardInstance() 984 { 985 $instance =& $GLOBALS["eZTemplateStandardResourceInstance"]; 986 if ( get_class( $instance ) != "eztemplatedesignresource" ) 987 { 988 $instance = new eZTemplateDesignResource( 'standard', true ); 989 } 990 return $instance; 991 } 992 993 /*! 994 Sets the siteaccess which are to be used for loading the override settings. 995 */ 996 function setOverrideAccess( $siteAccess ) 997 { 998 $this->OverrideSiteAccess = $siteAccess; 999 } 1000 1001 var $Keys; 1002 var $OnlyStandard; 1003 var $OverrideSiteAccess = false; 1004 } 1005 1006 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |