/** * @param string $name * @param mixed $value * @param string $cacheFileName * @return mixed|null */ public static function dailyValue( $name, $value = null, $cacheFileName = null ) { if ( $value === null && isset($memoryCache[$name]) && $cacheFileName === null ) { return self::$memoryCache[$name]; } else { if (is_null($cacheFileName)) { $cacheFileName = self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier(); } $cache = new eZPHPCreator( eZSys::cacheDirectory(), $cacheFileName . '.php', '', array() ); $expiryTime = time() - 24 * 3600; // reading if ($cache->canRestore($expiryTime)) { $values = $cache->restore(array('cacheTable' => 'cacheTable')); if (is_null($value)) { if (isset($values['cacheTable'][$name])) { return $values['cacheTable'][$name]; } else { return null; } } } else { $values = array('cacheTable' => array()); } $values['cacheTable'][$name] = $value; if ( $cacheFileName == self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier() ) self::$memoryCache = $values['cacheTable']; // writing $cache->addVariable('cacheTable', $values['cacheTable']); $cache->store(true); $cache->close(); } return null; }
/** * @param string $name * @param mixed $value * @return array */ public static function dailyValue( $name, $value = null) { if ( $value === null && isset($memoryCache[$name]) ) { return self::$memoryCache[$name]; } else { $cache = new eZPHPCreator( eZSys::cacheDirectory(), self::GLOBAL_CACHE_FILE . '.php', '', array() // removed clustering ); $expiryTime = time() - 24 * 3600; // reading if ($cache->canRestore($expiryTime)) { $values = $cache->restore(array('cacheTable' => 'cacheTable')); self::$memoryCache = $values['cacheTable']; if (is_null($value)) { if (isset($values['cacheTable'][$name])) { return $values['cacheTable'][$name]; } else { return null; } } } else { $values = array('cacheTable' => array()); } if ( !is_null($value) ) { $values['cacheTable'][$name] = $value; $cache->addVariable('cacheTable', $values['cacheTable']); $cache->store(true); $cache->close(); } } return null; }
function createOverrideCache() { if (isset($GLOBALS['eZSiteBasics'])) { if (isset($GLOBALS['eZSiteBasics']['no-cache-adviced']) and $GLOBALS['eZSiteBasics']['no-cache-adviced']) { return false; } } global $eZTemplateOverrideCacheNoPermission; if ($eZTemplateOverrideCacheNoPermission == "nocache") { return false; } $ini = eZINI::instance('site.ini'); $useOverrideCache = true; if ($ini->hasVariable('OverrideSettings', 'Cache')) { $useOverrideCache = $ini->variable('OverrideSettings', 'Cache') == 'enabled'; } $standardBase = eZTemplateDesignResource::designSetting('standard'); $siteBase = eZTemplateDesignResource::designSetting('site'); $overrideKeys = $this->overrideKeys(); $overrideKey = md5(implode(',', $overrideKeys) . $siteBase . $standardBase); $cacheDir = eZSys::cacheDirectory(); $overrideCacheFile = $cacheDir . '/override/override_' . $overrideKey . '.php'; // Build matching cache only of it does not already exists, // or override file has been updated if (!$useOverrideCache or !file_exists($overrideCacheFile)) { $matchFileArray = eZTemplateDesignResource::overrideArray($this->OverrideSiteAccess); // Generate PHP compiled cache file. $phpCache = new eZPHPCreator("{$cacheDir}/override", "override_{$overrideKey}.php"); $phpCode = "\$GLOBALS['eZOverrideTemplateCacheMap'] = array (\n"; $numMatchFiles = count($matchFileArray); $countMatchFiles = 0; // $phpCode .= "switch ( \$matchFile )\n{\n "; foreach (array_keys($matchFileArray) as $matchKey) { $countMatchFiles++; $phpCode .= '\'' . md5($matchKey) . '\' => '; if (isset($matchFileArray[$matchKey]['custom_match'])) { $baseDir = isset($matchFileArray[$matchKey]['base_dir']) ? $matchFileArray[$matchKey]['base_dir'] : ''; $defaultMatchFile = $baseDir . $matchKey; // Custom override matching // $phpCode .= " case \"$matchKey\":\n {\n"; $matchConditionArray = array(); foreach ($matchFileArray[$matchKey]['custom_match'] as $customMatch) { $matchCondition = ""; $condCount = 0; if (is_array($customMatch['conditions'])) { foreach (array_keys($customMatch['conditions']) as $conditionKey) { if ($condCount > 0) { $matchCondition .= " and "; } // Have a special substring match for subtree matching $matchCondition .= "( isset( \$matchKeys[\\'{$conditionKey}\\'] ) and "; if ($conditionKey == 'url_alias') { $matchCondition .= "( strpos( \$matchKeys[\\'url_alias\\'], \\'" . $customMatch['conditions']['url_alias'] . "\\' ) === 0 ) )"; } else { $matchCondition .= "( is_array( \$matchKeys[\\'{$conditionKey}\\'] ) ? " . "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'{$conditionKey}\\'] ) : " . "\$matchKeys[\\'{$conditionKey}\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )"; } $condCount++; } } // Only create custom match if conditions are defined if ($matchCondition != "") { // $phpCode .= " if ( $matchCondition )\n {\n"; // $phpCode .= " return '" . $customMatch['match_file'] . "';\n }\n"; if ($condCount > 1) { $matchConditionArray[] = array('condition' => '(' . $matchCondition . ')', 'matchFile' => $customMatch['match_file']); } else { $matchConditionArray[] = array('condition' => $matchCondition, 'matchFile' => $customMatch['match_file']); } } else { // No override conditions defined. Override default match file $defaultMatchFile = $customMatch['match_file']; } } $phpCode .= "array ( 'eval' => 1, 'code' => "; $phpCode .= "'"; foreach (array_keys($matchConditionArray) as $key) { $phpCode .= '(' . $matchConditionArray[$key]['condition'] . ' ? ' . "\\'" . $matchConditionArray[$key]['matchFile'] . "\\'" . ' : '; } $phpCode .= "\\'" . $defaultMatchFile . "\\'"; for ($condCount = 0; $condCount < count($matchConditionArray); $condCount++) { $phpCode .= ')'; } $phpCode .= "' )"; } else { $phpCode .= "'" . $matchFileArray[$matchKey]['base_dir'] . $matchKey . "'"; } if ($countMatchFiles < $numMatchFiles) { $phpCode .= ",\n"; } else { $phpCode .= ");\n"; } } $phpCache->addCodePiece($phpCode); if ($useOverrideCache and $phpCache->store()) { } else { if ($useOverrideCache) { 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__); } $eZTemplateOverrideCacheNoPermission = 'nocache'; $overrideCacheFile = false; } } return $overrideCacheFile; }
static function createCommonCompileTemplate() { $php = new eZPHPCreator(eZTemplateCompiler::compilationDirectory(), 'common.php'); if ($php->exists()) { return; } $php->addComment("This file contains functions which are common to all compiled templates.\n\n" . 'NOTE: This file is autogenerated and should not be modified, any changes will be lost!'); $php->addSpace(); $php->addDefine('EZ_TEMPLATE_COMPILER_COMMON_CODE', true); $php->addSpace(); $namespaceStack = array(); $php->addCodePiece("if ( !isset( \$namespaceStack ) )\n"); $php->addVariable('namespaceStack', $namespaceStack, eZPHPCreator::VARIABLE_ASSIGNMENT, array('spacing' => 4)); $php->addSpace(); $lbracket = '{'; $rbracket = '}'; $initText = "if ( !function_exists( 'compiledfetchvariable' ) )\n{$lbracket}\n function compiledFetchVariable( \$vars, \$namespace, \$name )\n {$lbracket}\n \$exists = ( array_key_exists( \$namespace, \$vars ) and\n array_key_exists( \$name, \$vars[\$namespace] ) );\n if ( \$exists )\n {$lbracket}\n return \$vars[\$namespace][\$name];\n {$rbracket}\n return null;\n {$rbracket}\n{$rbracket}\nif ( !function_exists( 'compiledfetchtext' ) )\n{$lbracket}\n function compiledFetchText( \$tpl, \$rootNamespace, \$currentNamespace, \$namespace, \$var )\n {$lbracket}\n \$text = '';\n \$tpl->appendElement( \$text, \$var, \$rootNamespace, \$currentNamespace );\n return \$text;\n {$rbracket}\n{$rbracket}\nif ( !function_exists( 'compiledAcquireResource' ) )\n{$lbracket}\n function compiledAcquireResource( \$phpScript, \$key, &\$originalText,\n \$tpl, \$rootNamespace, \$currentNamespace )\n {\n include( '" . eZTemplateCompiler::TemplatePrefix() . "' . \$phpScript );\n if ( isset( \$text ) )\n {\n \$originalText .= \$text;\n return true;\n }\n return false;\n }\n{$rbracket}\nif ( !function_exists( 'compiledfetchattribute' ) )\n{$lbracket}\n function compiledFetchAttribute( \$value, \$attributeValue )\n {$lbracket}\n if ( is_object( \$value ) )\n {$lbracket}\n if ( method_exists( \$value, \"attribute\" ) and\n method_exists( \$value, \"hasattribute\" ) )\n {$lbracket}\n if ( \$value->hasAttribute( \$attributeValue ) )\n {$lbracket}\n return \$value->attribute( \$attributeValue );\n {$rbracket}\n {$rbracket}\n {$rbracket}\n else if ( is_array( \$value ) )\n {$lbracket}\n if ( isset( \$value[\$attributeValue] ) )\n {$lbracket}\n return \$value[\$attributeValue];\n {$rbracket}\n {$rbracket}\n return null;\n {$rbracket}\n{$rbracket}\n"; $php->addCodePiece($initText); $php->store(true); }
/** * Returns the class identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classidentifier => classid */ protected static function classIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT id, identifier FROM ezcontentclass where version=0"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { self::$identifierHash[$identifierRow['identifier']] = $identifierRow['id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
/** * Return an array with activated extensions. * * @note Default extensions are those who are loaded before a siteaccess are determined while access extensions * are loaded after siteaccess is set. * * @param false|string $extensionType Decides which extension to include in the list, the follow values are possible: * - false - Means add both default and access extensions * - 'default' - Add only default extensions * - 'access' - Add only access extensions * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini * @return array */ public static function activeExtensions( $extensionType = false, eZINI $siteINI = null ) { if ( $siteINI === null ) { $siteINI = eZINI::instance(); } $activeExtensions = array(); if ( !$extensionType || $extensionType === 'default' ) { $activeExtensions = $siteINI->variable( 'ExtensionSettings', 'ActiveExtensions' ); } if ( !$extensionType || $extensionType === 'access' ) { $activeExtensions = array_merge( $activeExtensions, $siteINI->variable( 'ExtensionSettings', 'ActiveAccessExtensions' ) ); } if ( isset( $GLOBALS['eZActiveExtensions'] ) ) { $activeExtensions = array_merge( $activeExtensions, $GLOBALS['eZActiveExtensions'] ); } // return empty array as is to avoid further unneeded overhead if ( !isset( $activeExtensions[0] ) ) { return $activeExtensions; } // return array as is if ordering is disabled to avoid cache overhead $activeExtensions = array_unique( $activeExtensions ); if ( $siteINI->variable( 'ExtensionSettings', 'ExtensionOrdering' ) !== 'enabled' ) { // @todo Introduce a debug setting or re use existing dev mods to check that all extensions exists return $activeExtensions; } $cacheIdentifier = md5( serialize( $activeExtensions ) ); if ( isset ( self::$activeExtensionsCache[$cacheIdentifier] ) ) { return self::$activeExtensionsCache[$cacheIdentifier]; } // cache has to be stored by siteaccess + $extensionType $extensionDirectory = self::baseDirectory(); $expiryHandler = eZExpiryHandler::instance(); $phpCache = new eZPHPCreator( self::CACHE_DIR, "active_extensions_{$cacheIdentifier}.php" ); $expiryTime = $expiryHandler->hasTimestamp( 'active-extensions-cache' ) ? $expiryHandler->timestamp( 'active-extensions-cache' ) : 0; if ( !$phpCache->canRestore( $expiryTime ) ) { self::$activeExtensionsCache[$cacheIdentifier] = self::extensionOrdering( $activeExtensions ); // Check that all extensions defined actually exists before storing cache foreach ( self::$activeExtensionsCache[$cacheIdentifier] as $activeExtension ) { if ( !file_exists( $extensionDirectory . '/' . $activeExtension ) ) { eZDebug::writeError( "Extension '$activeExtension' does not exist, looked for directory '" . $extensionDirectory . '/' . $activeExtension . "'", __METHOD__ ); } } $phpCache->addVariable( 'activeExtensions', self::$activeExtensionsCache[$cacheIdentifier] ); $phpCache->store(); } else { $data = $phpCache->restore( array( 'activeExtensions' => 'activeExtensions' ) ); self::$activeExtensionsCache[$cacheIdentifier] = $data['activeExtensions']; } return self::$activeExtensionsCache[$cacheIdentifier]; }
static function storeCache($key, $templateFilepath) { if (!eZTemplateTreeCache::isCacheEnabled()) { return false; } $templateCache =& eZTemplateTreeCache::cacheTable(); $key = eZTemplateTreeCache::internalKey($key); if (!isset($templateCache[$key])) { eZDebug::writeDebug("Template cache for key '{$key}' does not exist, cannot store cache", __METHOD__); return; } $cacheFileName = eZTemplateTreeCache::treeCacheFilename($key, $templateFilepath); $cache =& $templateCache[$key]; $php = new eZPHPCreator(eZTemplateTreeCache::cacheDirectory(), $cacheFileName); $php->addVariable('eZTemplateTreeCacheCodeDate', eZTemplateTreeCache::CODE_DATE); $php->addSpace(); $php->addVariable('TemplateInfo', $cache['info']); $php->addSpace(); $php->addVariable('TemplateRoot', $cache['root']); $php->store(); }
static function storeCache($key) { $translationCache = eZTranslationCache::cacheTable(); if (!isset($translationCache[$key])) { eZDebug::writeWarning("Translation cache for key '{$key}' does not exist, cannot store cache", __METHOD__); return; } $internalCharset = eZTextCodec::internalCharset(); // $cacheFileKey = "$key-$internalCharset"; $cacheFileKey = $key; $cacheFileName = md5($cacheFileKey) . '.php'; $cache =& $translationCache[$key]; if (!file_exists(eZTranslationCache::cacheDirectory())) { eZDir::mkdir(eZTranslationCache::cacheDirectory(), false, true); } $php = new eZPHPCreator(eZTranslationCache::cacheDirectory(), $cacheFileName); $php->addRawVariable('eZTranslationCacheCodeDate', self::CODE_DATE); $php->addSpace(); $php->addRawVariable('CacheInfo', array('charset' => $internalCharset)); $php->addRawVariable('TranslationInfo', $cache['info']); $php->addSpace(); $php->addRawVariable('TranslationRoot', $cache['root']); $php->store(); }
/** * Returns an array of limitations useable by the policy system * * @return array */ public static function limitations() { static $limitations; if ($limitations === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'statelimitations_' . $dbName . '.php', '', array('clustering' => 'statelimitations')); $handler = eZExpiryHandler::instance(); $storedTimeStamp = $handler->hasTimestamp('state-limitations') ? $handler->timestamp('state-limitations') : false; $expiryTime = $storedTimeStamp !== false ? $storedTimeStamp : 0; if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('state_limitations' => 'state_limitations')); $limitations = $var['state_limitations']; } else { $limitations = array(); $groups = self::fetchByConditions(array("identifier NOT LIKE 'ez%'"), false, false); foreach ($groups as $group) { $name = 'StateGroup_' . $group->attribute('identifier'); $limitations[$name] = array('name' => $name, 'values' => array(), 'class' => __CLASS__, 'function' => 'limitationValues', 'parameter' => array($group->attribute('id'))); } $phpCache->addVariable('state_limitations', $limitations); $phpCache->store(); } if ($storedTimeStamp === false) { $handler->setTimestamp('state-limitations', time()); } } return $limitations; }
function storeCache($directory = false) { if (!file_exists($directory)) { eZDir::mkdir($directory, false, true); } $php = new eZPHPCreator($directory, 'package.php'); $php->addComment("Automatically created cache file for the package format\n" . "Do not modify this file"); $php->addSpace(); $php->addVariable('CacheCodeDate', eZPackage::CACHE_CODE_DATE); $php->addSpace(); $php->addVariable('Parameters', $this->Parameters, eZPHPCreator::VARIABLE_ASSIGNMENT, array('full-tree' => true)); $php->addVariable('InstallData', $this->InstallData, eZPHPCreator::VARIABLE_ASSIGNMENT, array('full-tree' => true)); $php->addVariable('RepositoryPath', $this->RepositoryPath); $php->store(); }
function storeCacheFile($filepath, $transformationData, $extraCode, $type, $charsetName) { $file = basename($filepath); $dir = dirname($filepath); $php = new eZPHPCreator($dir, $file); $php->addComment("Cached transformation data"); $php->addComment("Type: {$type}"); $php->addComment("Charset: {$charsetName}"); $php->addComment("Cached transformation data"); $php->addCodePiece('$data = ' . eZCharTransform::varExport($transformationData) . ";\n"); $php->addCodePiece("\$text = strtr( \$text, \$data['table'] );\n"); if ($extraCode) { $php->addCodePiece($extraCode); } return $php->store(true); }
function storeCacheObject($filename, $permissionArray) { $dir = dirname($filename); $file = basename($filename); $php = new eZPHPCreator($dir, $file); $php->addVariable("umap", array()); $php->addVariable("utf8map", array()); $php->addVariable("cmap", array()); $php->addVariable("utf8cmap", array()); reset($this->UnicodeMap); while (($key = key($this->UnicodeMap)) !== null) { $item = $this->UnicodeMap[$key]; $php->addVariable("umap[{$key}]", $item); next($this->UnicodeMap); } reset($this->UTF8Map); while (($key = key($this->UTF8Map)) !== null) { $item = $this->UTF8Map[$key]; if ($item == 0) { $php->addCodePiece("\$utf8map[0] = chr(0);\n"); } else { $val = str_replace(array("\\", "'"), array("\\\\", "\\'"), $item); $php->addVariable("utf8map[{$key}]", $val); } next($this->UTF8Map); } reset($this->CodeMap); while (($key = key($this->CodeMap)) !== null) { $item = $this->CodeMap[$key]; $php->addVariable("cmap[{$key}]", $item); next($this->CodeMap); } reset($this->UTF8CodeMap); while (($key = key($this->UTF8CodeMap)) !== null) { $item = $this->UTF8CodeMap[$key]; if ($item == 0) { $php->addVariable("utf8cmap[chr(0)]", 0); } else { $val = str_replace(array("\\", "'"), array("\\\\", "\\'"), $key); $php->addVariable("utf8cmap['{$val}']", $item); } next($this->UTF8CodeMap); } reset($this->ReadExtraMap); while (($key = key($this->ReadExtraMap)) !== null) { $item = $this->ReadExtraMap[$key]; $php->addVariable("read_extra[{$key}]", $item); next($this->ReadExtraMap); } $php->addVariable("eZCodePageCacheCodeDate", self::CACHE_CODE_DATE); $php->addVariable("min_char", $this->MinCharValue); $php->addVariable("max_char", $this->MaxCharValue); $php->store(true); if (file_exists($filename)) { // Store the old umask and set a new one. $oldPermissionSetting = umask(0); // Change the permission setting. @chmod($filename, $permissionArray['file_permission']); // Restore the old umask. umask($oldPermissionSetting); } }
/** * Returns the class attribute identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classattributeidentifier => classattributeid */ protected static function classAttributeIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classattributeidentifiers_' . $dbName . '.php', '', array('clustering' => 'classattridentifiers')); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT ezcontentclass_attribute.id as attribute_id, ezcontentclass_attribute.identifier as attribute_identifier, ezcontentclass.identifier as class_identifier\n FROM ezcontentclass_attribute, ezcontentclass\n WHERE ezcontentclass.id=ezcontentclass_attribute.contentclass_id"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { $combinedIdentifier = $identifierRow['class_identifier'] . '/' . $identifierRow['attribute_identifier']; self::$identifierHash[$combinedIdentifier] = (int) $identifierRow['attribute_id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
/** * Register extensions "the YMC way". * * * @return void * @access public * @author ymc-dabe * @see eZExtension::activateExtensions() * @link http://issues.ez.no/IssueView.php?Id=2709 */ public function registerExtensions($virtual_siteaccess = false) { if (!$this->attribute('is_enabled')) { eZDebug::writeError("The ymcExtensionLoader is disabled, but " . __METHOD__ . " has just been called (which really shouldn't be done)!", __METHOD__); } $siteaccess = self::getCurrentSiteaccess(); $isBasicLoad = true; $is_virtual_load = false; $cache_hit = false; $defaultActiveExtensions = self::$alwaysEnabledExtensions; if (!in_array('ymcextensionloader', $defaultActiveExtensions)) { $defaultActiveExtensions[] = 'ymcextensionloader'; } if ($this->standardLoadingCompleted === true and $virtual_siteaccess !== false and $siteaccess !== $virtual_siteaccess) { if ($this->virtualLoadingCompleted === true) { eZDebug::writeError("Unnecessary call to 'ymcExtensionLoader::registerExtensions('.{$virtual_siteaccess}.')'!", __METHOD__); return; } $siteaccess = $virtual_siteaccess; self::setInternalSiteaccess($siteaccess); eZDebug::accumulatorStart('OpenVolanoExtensionLoader_VirtualSiteaccess', 'OpenVolano: Enhanced Extension Loader', "After virtual siteaccess '{$siteaccess}' initialised "); $isBasicLoad = false; $is_virtual_load = true; $this->rebuildIniOverrideArray($siteaccess, $isBasicLoad); } else { if (null !== $siteaccess) { if ($this->standardLoadingCompleted === true) { eZDebug::writeError("Unnecessary call to " . __METHOD__ . "!", __METHOD__); return; } $isBasicLoad = false; eZDebug::accumulatorStart('OpenVolanoExtensionLoader_Siteaccess', 'OpenVolano: Enhanced Extension Loader', "After siteaccess '{$siteaccess}' initialised "); } else { if (self::$earlyLoadingCompleted === true) { eZDebug::writeWarning("Force registering additional extensions - please keep in mind, that it is not possible to unload extensions", __METHOD__); } eZDebug::accumulatorStart('OpenVolanoExtensionLoader_Basic', 'OpenVolano: Enhanced Extension Loader', 'Pre siteaccess initialised'); } } $ini = eZINI::instance(); $allExtensionsRegistered = false; if ($isBasicLoad) { self::$globalCacheDirectory = eZSys::cacheDirectory(); $cacheFileName = 'basic'; $cache_var_name = 'ymcExtensionLoaderRegisterExtensionBasicLoadInformation'; } else { if ($is_virtual_load) { $cacheFileName = 'siteaccess-' . $this->attribute('non_virtual_siteaccess') . '-virtualsiteaccess-' . $siteaccess; $cache_var_name = 'ymcExtensionLoaderRegisterExtensionVirtualSiteaccessLoadInformation'; } else { $cacheFileName = 'siteaccess-' . $siteaccess; $cache_var_name = 'ymcExtensionLoaderRegisterExtensionSiteaccessLoadInformation'; } } $write_cache = false; $can_write_cache = true; $cacheDir = eZSys::cacheDirectory() . '/openvolano/extensions'; if (!is_writable($cacheDir)) { if (!eZDir::mkdir($cacheDir, 0777, true)) { $can_write_cache = false; eZDebug::writeError("Couldn't create cache directory '{$cacheDir}', perhaps wrong permissions", __METHOD__); } } $cacheFilePath = $cacheDir . '/' . $cacheFileName; if (!file_exists($cacheFilePath)) { $write_cache = $can_write_cache; if ($isBasicLoad) { eZDebug::writeNotice("No cache found for loading basic set of extensions", __METHOD__); } else { eZDebug::writeNotice("No cache found for loading per siteaccess set of extensions for siteaccess '{$siteaccess}'", __METHOD__); } } else { include $cacheFilePath; if (!isset(${$cache_var_name})) { eZDebug::writeWarning("Cache '{$cache_var_name}' in file '{$cacheFilePath}' not found. Trying to force rewrite of this cache file...", __METHOD__); $write_cache = $can_write_cache; } else { eZDebug::writeNotice("Cache hit: {$cacheFilePath}", __METHOD__); $defaultActiveExtensions = ${$cache_var_name}; $cache_hit = true; unset($cache_var_name); } } $additional_lookups = 0; //Loop registering of extensions until all are loaded while (!$allExtensionsRegistered) { //First we asume we do not need to check for new extensions $allExtensionsRegistered = true; //these extensions are always active $activeExtensions = $defaultActiveExtensions; //Get all active extension $activeExtensions = array_unique(array_merge($activeExtensions, eZExtension::activeExtensions())); foreach ($activeExtensions as $activeExtension) { //only activate an extension if it has not been registered, yet if (!in_array($activeExtension, $this->registeredExtensions)) { $this->registeredExtensions[] = $activeExtension; $fullExtensionPath = eZExtension::baseDirectory() . '/' . $activeExtension; if (!file_exists($fullExtensionPath)) { eZDebug::writeWarning("Extension '{$activeExtension}' does not exist, looked for directory '{$fullExtensionPath}'", __METHOD__); } else { $fullExtensionAutoloadPath = $fullExtensionPath . '/autoload'; if ($activeExtension !== 'ymcextensionloader' and !in_array($activeExtension, self::$noAutoloadExtensions) and file_exists($fullExtensionAutoloadPath)) { //add the new extension's autoload-dir to the eZ compontents autoload system (if needed) ezcBase::addClassRepository($fullExtensionPath, $fullExtensionAutoloadPath); } //We are about to activate a new extension which might need to load one ore more other extension (if we do not have a cached info about this) $allExtensionsRegistered = $cache_hit; } } } $this->rebuildIniOverrideArray($siteaccess, $isBasicLoad); if (!$allExtensionsRegistered) { $additional_lookups++; } } if (!$cache_hit) { if ($isBasicLoad) { eZDebug::writeNotice("Loaded all basic extensions in {$additional_lookups} additional lookups...", __METHOD__); } else { if ($is_virtual_load) { eZDebug::writeNotice("Loaded all virtual siteaccess extensions in {$additional_lookups} additional lookups...", __METHOD__); } else { eZDebug::writeNotice("Loaded all siteaccess extensions in {$additional_lookups} additional lookups...", __METHOD__); } } } if ($write_cache) { if ($isBasicLoad) { eZDebug::writeNotice("Storing basic extension load information into cache file '{$cacheFilePath}'...", __METHOD__); } else { if ($is_virtual_load) { eZDebug::writeNotice("Storing virtual siteaccess extension load information into cache file '{$cacheFilePath}'...", __METHOD__); } else { eZDebug::writeNotice("Storing siteaccess extension load information into cache file '{$cacheFilePath}'...", __METHOD__); } } $php = new eZPHPCreator($cacheDir, $cacheFileName); $php->addRawVariable($cache_var_name, $this->registeredExtensions); $php->store(); } if ($is_virtual_load) { $this->virtualLoadingCompleted = true; eZDebug::accumulatorStop('OpenVolanoExtensionLoader_VirtualSiteaccess'); } else { if (!$isBasicLoad) { $this->standardLoadingCompleted = true; $this->non_virtual_siteaccess_name = $siteaccess; eZDebug::accumulatorStop('OpenVolanoExtensionLoader_Siteaccess'); } else { self::$earlyLoadingCompleted = true; eZDebug::accumulatorStop('OpenVolanoExtensionLoader_Basic'); } } //Use the following line to take a look into the ini-hierarchy... //ymc_pr($GLOBALS["eZINIOverrideDirList"], $siteaccess.'|'.self::getCurrentSiteaccess()); if (!$is_virtual_load and !$isBasicLoad and $ini->hasVariable('SiteAccessSettings', 'VirtualSiteaccessSystem') and $ini->variable('SiteAccessSettings', 'VirtualSiteaccessSystem') !== 'disabled') { $allowLoadingOfPreviouslyKnownSiteaccesses = false; if ($ini->hasVariable('SiteAccessSettings', 'VirtualSiteaccessSystem') and $ini->variable('VirtualSiteaccessSettings', 'AllowLoadingOfPerviouslyKnowSiteaccesses') === 'enabled') { $allowLoadingOfPreviouslyKnownSiteaccesses = true; } if (isset($GLOBALS['eZURIRequestInstance']) and is_object($GLOBALS['eZURIRequestInstance'])) { $uri = eZURI::instance(); $elements = $uri->elements(false); if (count($elements) > 0 and $elements[0] != '') { $goInVirtualSiteaccessMode = true; if ($ini->hasVariable('VirtualSiteaccessSettings', 'SkipLoadingForUri') and is_array($ini->variable('VirtualSiteaccessSettings', 'SkipLoadingForUri')) and count($ini->variable('VirtualSiteaccessSettings', 'SkipLoadingForUri')) > 0) { $uri_string = $uri->elements(true); foreach ($ini->variable('VirtualSiteaccessSettings', 'SkipLoadingForUri') as $ignoreUriForVirtualSiteaccess) { if (strpos($uri_string, $ignoreUriForVirtualSiteaccess) === 0) { $goInVirtualSiteaccessMode = false; break; } } unset($uri_string); } } else { $goInVirtualSiteaccessMode = false; } if ($goInVirtualSiteaccessMode) { $matchIndex = 1; $name = $elements[0]; //by ymc-dabe //Code taken from /access.php line 241-249 of eZ publish v4.1.3 //KEEP IT IN SYNC! //start $name = preg_replace(array('/[^a-zA-Z0-9]+/', '/_+/', '/^_/', '/_$/'), array('_', '_', '', ''), $name); //by ymc-dabe //Code taken from /access.php line 241-249 of eZ publush v4.1.3 //KEEP IT IN SYNC! //end if ($allowLoadingOfPreviouslyKnownSiteaccesses or !in_array($name, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { eZSys::addAccessPath($name); $uri->increase($matchIndex); $uri->dropBase(); $this->registerExtensions($name); //die if virtual siteaccess is not found if (!in_array($name, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { header($_SERVER['SERVER_PROTOCOL'] . " 400 Bad Request"); header("Status: 400 Bad Request"); eZExecution::cleanExit(); } } unset($name); } } else { if (isset($GLOBALS['ymcEnhancedExtensionLoaderVirtualSiteaccess']) and $GLOBALS['ymcEnhancedExtensionLoaderVirtualSiteaccess'] != '') { $virtualSiteaccessName = $GLOBALS['ymcEnhancedExtensionLoaderVirtualSiteaccess']; if ($allowLoadingOfPreviouslyKnownSiteaccesses or !in_array($virtualSiteaccessName, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { eZSys::addAccessPath($virtualSiteaccessName); $this->registerExtensions($virtualSiteaccessName); if (!in_array($virtualSiteaccessName, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { fputs(STDERR, "\n----------\nError: Invalid siteaccess '{$virtualSiteaccessName}'!\n----------\n\n"); eZExecution::cleanExit(); } } unset($virtualSiteaccessName); } } } else { if ($this->standardLoadingCompleted === true) { $this->virtualLoadingCompleted = true; } } if ($this->standardLoadingCompleted === true) { $this->loadingCompleted = true; if ($this->originalNonVirtualSiteaccessName === false) { $this->originalNonVirtualSiteaccessName = $this->attribute('non_virtual_siteaccess'); if ($this->originalVirtualSiteaccessName === false and $siteaccess != $this->attribute('non_virtual_siteaccess')) { $this->originalVirtualSiteaccessName = $siteaccess; } } } }