/** * Get an array of all the current templates and overrides for them. * The current siteaccess is used if none is specified. * * @static * @return array */ static function overrideArray($siteAccess = false) { if ($siteAccess === false and self::$overrideArrayCache !== null) { return self::$overrideArrayCache; } $bases = eZTemplateDesignResource::allDesignBases($siteAccess); // fetch the override array from a specific siteacces if ($siteAccess) { $overrideINI = eZSiteAccess::getIni($siteAccess, 'override.ini'); } else { $overrideINI = eZINI::instance('override.ini'); } $designStartPath = eZTemplateDesignResource::designStartPath(); // Generate match cache for all templates // Build arrays of available files, start with standard design and end with most prefered design $matchFileArray = array(); $reverseBases = array_reverse($bases); foreach ($reverseBases as $base) { $templateResource = $base . '/templates'; $sourceFileArray = eZDir::recursiveFindRelative($templateResource, "", "tpl"); foreach ($sourceFileArray as $source) { $matchFileArray[$source]['base_dir'] = $templateResource; $matchFileArray[$source]['template'] = $source; } } // Load override templates $overrideSettingGroups = $overrideINI->groups(); if (isset($GLOBALS['eZDesignOverrides'])) { $overrideSettingGroups = array_merge($overrideSettingGroups, $GLOBALS['eZDesignOverrides']); } foreach ($overrideSettingGroups as $overrideName => $overrideSetting) { if (!isset($overrideSetting['Source'])) { continue; } $overrideSource = "/" . $overrideSetting['Source']; $overrideMatchFile = $overrideSetting['MatchFile']; // Find the matching file in the available resources $triedFiles = array(); $fileInfo = eZTemplateDesignResource::fileMatch($bases, 'override/templates', $overrideMatchFile, $triedFiles); $resourceInUse = is_array($fileInfo) ? $fileInfo['resource'] : false; $overrideMatchFilePath = is_array($fileInfo) ? $fileInfo['path'] : false; // if the override template is not found // then we probably shouldn't use it // there should be added a check around the following code // if ( $overrideMatchFilePath ) // { $customMatchArray = array(); $customMatchArray['conditions'] = isset($overrideSetting['Match']) ? $overrideSetting['Match'] : null; $customMatchArray['match_file'] = $overrideMatchFilePath; $customMatchArray['override_name'] = $overrideName; $matchFileArray[$overrideSource]['custom_match'][] = $customMatchArray; // } // if overriding a non-existing template // then we use the override template as main template // this code should probably be removed // because we should not allow an override if the main template is missing if ($resourceInUse && !isset($matchFileArray[$overrideSource]['base_dir'])) { $matchFileArray[$overrideSource]['base_dir'] = $resourceInUse; $matchFileArray[$overrideSource]['template'] = $overrideSource; } if (!$overrideMatchFilePath) { eZDebug::writeError("Custom match file: path '{$overrideMatchFile}' not found in any resource. Check the template settings in settings/override.ini", __METHOD__); eZDebug::writeError(implode(', ', $triedFiles), __METHOD__ . ' tried files'); } } if ($siteAccess === false) { self::$overrideArrayCache = $matchFileArray; } return $matchFileArray; }
function installTemplates( $templateList, $package, $subdirectory, &$installParameters ) { if ( !$templateList ) { return true; } $siteAccessDesignPathArray = array(); $templateRootPath = $package->path() . '/' . $subdirectory; foreach( $templateList->getElementsByTagName( 'file' ) as $fileNode ) { $originalSiteAccess = $fileNode->getAttribute( 'site-access' ); if ( isset( $installParameters['site_access_map'][$originalSiteAccess] ) ) { $newSiteAccess = $installParameters['site_access_map'][$originalSiteAccess]; } else { $newSiteAccess = $installParameters['site_access_map']['*']; } if ( !isset( $siteAccessDesignPathArray[$newSiteAccess] ) ) { $ini = eZINI::instance( 'site.ini', 'settings', null, null, true ); $ini->prependOverrideDir( "siteaccess/$newSiteAccess", false, 'siteaccess' ); $ini->loadCache(); if ( isset( $installParameters['design_map'] ) ) { $designMap = $installParameters['design_map']; if ( isset( $designMap[$originalSiteAccess] ) ) $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $designMap[$originalSiteAccess]; else $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $designMap['*']; } else { $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $ini->variable( "DesignSettings", "StandardDesign" ); } } $path = ''; foreach( $fileNode->childNodes as $pathNode ) { if ( $pathNode->nodeName == 'path' ) { $path = $pathNode->nodeValue; break; } } $sourcePath = $templateRootPath . $path; $destinationPath = $siteAccessDesignPathArray[$newSiteAccess] . $path; eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true ); if ( !eZFileHandler::copy( $sourcePath, $destinationPath ) ) return false; // eZDebug::writeNotice( 'Copied: "' . $sourcePath . '" to: "' . $destinationPath . '"', __METHOD__ ); } return true; }