Beispiel #1
0
 /**
  * Loads all the static strings from either the cache or the ini files. Note that ini files in modules are not verified for outdatedness, so if they were updated, just clear all the caches or hard reload a page
  * This method should not be called directly from outsite TranslationPeer except for testing and debugging purposes
  */
 public static function getStaticStrings($sLanguageId)
 {
     if (!isset(self::$STATIC_STRINGS[$sLanguageId])) {
         $oCache = new Cache($sLanguageId, DIRNAME_LANG);
         $aLanguageFiles = ResourceFinder::create()->addPath(DIRNAME_LANG, "{$sLanguageId}.ini")->all()->baseFirst()->find();
         if ($oCache->entryExists() && !$oCache->isOutdated($aLanguageFiles)) {
             self::$STATIC_STRINGS[$sLanguageId] = $oCache->getContentsAsVariable();
         } else {
             self::$STATIC_STRINGS[$sLanguageId] = array();
             //Get default strings
             foreach ($aLanguageFiles as $sLanguageFile) {
                 self::$STATIC_STRINGS[$sLanguageId] = array_merge(self::$STATIC_STRINGS[$sLanguageId], parse_ini_file($sLanguageFile));
             }
             //Get strings for modules
             foreach (ResourceFinder::create()->addExpression(DIRNAME_MODULES, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN, DIRNAME_LANG, "{$sLanguageId}.ini")->all()->baseFirst()->find() as $sLanguageFile) {
                 self::$STATIC_STRINGS[$sLanguageId] = array_merge(self::$STATIC_STRINGS[$sLanguageId], parse_ini_file($sLanguageFile));
             }
             //Fix string encoding
             foreach (self::$STATIC_STRINGS[$sLanguageId] as $sStringKey => $sValue) {
                 self::$STATIC_STRINGS[$sLanguageId][$sStringKey] = StringUtil::encodeForDbFromFile($sValue);
             }
             $oCache->setContents(self::$STATIC_STRINGS[$sLanguageId]);
         }
     }
     return self::$STATIC_STRINGS[$sLanguageId];
 }
 public function renderFile()
 {
     //Send Content-Type
     $sCharset = Settings::getSetting('encoding', 'browser', 'utf-8');
     if ($this->sType === ResourceIncluder::RESOURCE_TYPE_CSS) {
         header("Content-Type: text/css;charset={$sCharset}");
     } else {
         if ($this->sType === ResourceIncluder::RESOURCE_TYPE_JS) {
             header("Content-Type: text/javascript;charset={$sCharset}");
         }
     }
     //Find consolidated resources
     $aKeys = array();
     while (Manager::hasNextPathItem()) {
         $aKeys[] = Manager::usePath();
     }
     $sKey = 'consolidated-output-' . $this->sType . '-' . implode('|', $aKeys);
     $oCachingStrategy = clone CachingStrategy::fromConfig('file');
     $oCache = new Cache($sKey, 'resource', $oCachingStrategy);
     $oItemCachingStrategy = clone $oCachingStrategy;
     $oItemCachingStrategy->init(array('key_encode' => null));
     $oCache->sendCacheControlHeaders();
     if (!$oCache->entryExists(false)) {
         foreach ($aKeys as $sItemKey) {
             $oItemCache = new Cache($sItemKey, DIRNAME_PRELOAD, $oItemCachingStrategy);
             if (!$oItemCache->entryExists(false)) {
                 throw new Exception("Consolidated resource {$sItemKey} does not exist.");
             }
             $oCache->setContents($oItemCache->getContentsAsString() . "\n", false, true);
         }
     }
     $oCache->sendCacheControlHeaders();
     $oCache->passContents(true);
 }
Beispiel #3
0
 public function cachedFrontend($bIsPreview = false)
 {
     $oCacheKey = $this->cacheKey();
     $oCache = null;
     if ($oCacheKey !== null && !$bIsPreview) {
         $sPrefix = 'frontend_module_' . $this->getModuleName() . '_' . ($this->oLanguageObject ? $this->oLanguageObject->getPKString() : 'data_' . $this->oData);
         $oCache = new Cache($oCacheKey->render($sPrefix), DIRNAME_FULL_PAGE);
         $bIsCached = $oCache->entryExists();
         $bIsOutdated = false;
         if ($bIsCached) {
             if ($this->oLanguageObject) {
                 $bIsOutdated = $oCache->isOlderThan($this->oLanguageObject);
             }
             if (!$bIsOutdated) {
                 return $oCache->getContentsAsString();
             }
         }
     }
     $sResult = $this->renderFrontend();
     if ($sResult instanceof Template) {
         $sResult = $sResult->render();
     }
     if ($oCache) {
         $oCache->setContents($sResult);
     }
     return $sResult;
 }
 public static function processCSSContent($sContent, $oFile)
 {
     $oCache = new Cache('preview_css' . $oFile->getInternalPath(), DIRNAME_TEMPLATES);
     header("Content-Type: text/css;charset=" . Settings::getSetting('encoding', 'browser', 'utf-8'));
     if ($oCache->entryExists() && !$oCache->isOutdated($oFile->getFullPath())) {
         $oCache->sendCacheControlHeaders();
         $oCache->passContents();
         exit;
     }
     $oParser = new Sabberworm\CSS\Parser($sContent, Sabberworm\CSS\Settings::create()->withDefaultCharset(Settings::getSetting('encoding', 'browser', 'utf-8')));
     $oCssContents = $oParser->parse();
     //Make all rules important
     // foreach($oCssContents->getAllRuleSets() as $oCssRuleSet) {
     //	foreach($oCssRuleSet->getRules() as $oRule) {
     //		$oRule->setIsImportant(true);
     //	}
     // }
     //Multiply all rules and prepend specific strings
     $aPrependages = array('#rapila_admin_menu', '.filled-container.editing', '.ui-dialog', '.cke_dialog_contents', '#widget-notifications', '.cke_reset', 'body > .cke_reset_all', '.tag_panel');
     foreach ($oCssContents->getAllDeclarationBlocks() as $oBlock) {
         $aNewSelector = array();
         foreach ($oBlock->getSelectors() as $iKey => $oSelector) {
             $sSelector = $oSelector->getSelector();
             if (StringUtil::startsWith($sSelector, "body ") || StringUtil::startsWith($sSelector, "html ")) {
                 $aNewSelector[] = $sSelector;
             } else {
                 foreach ($aPrependages as $sPrependage) {
                     if (StringUtil::startsWith($sSelector, "{$sPrependage} ") || StringUtil::startsWith($sSelector, "{$sPrependage}.") || $sSelector === $sPrependage) {
                         $aNewSelector[] = $sSelector;
                     } else {
                         $aNewSelector[] = "{$sPrependage} {$sSelector}";
                     }
                 }
             }
         }
         $oBlock->setSelector($aNewSelector);
     }
     //Absolutize all URLs
     foreach ($oCssContents->getAllValues() as $oValue) {
         if ($oValue instanceof Sabberworm\CSS\Value\URL) {
             $sURL = $oValue->getURL()->getString();
             if (!StringUtil::startsWith($sURL, '/') && !preg_match('/^\\w+:/', $sURL)) {
                 $sURL = $oFile->getFrontendDirectoryPath() . DIRECTORY_SEPARATOR . $sURL;
             }
             $oValue->setURL(new Sabberworm\CSS\Value\CSSString($sURL));
         }
     }
     $sContents = $oCssContents->render(Sabberworm\CSS\OutputFormat::createCompact());
     $oCache->setContents($sContents);
     $oCache->sendCacheControlHeaders();
     print $sContents;
 }
Beispiel #5
0
 public static function getFilters()
 {
     if (self::$FILTERS === null) {
         $oCache = new Cache("preconfigured_filter_handlers", DIRNAME_PRELOAD);
         if ($oCache->entryExists()) {
             self::$FILTERS = $oCache->getContentsAsVariable();
         } else {
             self::$FILTERS = new Filters();
             $oCache->setContents(self::$FILTERS);
         }
     }
     return self::$FILTERS;
 }
 public static function dataForPart($sDocumentationPart, $sLanguageId)
 {
     $oCache = new Cache("documentation_content_{$sLanguageId}:{$sDocumentationPart}", DIRNAME_CONFIG);
     $oSettingsCache = new Cache(Settings::createCacheKey('documentation'), DIRNAME_CONFIG);
     if ($oCache->entryExists() && !$oCache->isOlderThan($oSettingsCache->getModificationDate())) {
         return $oCache->getContentsAsVariable();
     }
     $aMetadata = self::completeMetaData();
     if (!isset($aMetadata[$sDocumentationPart]) || !isset($aMetadata[$sDocumentationPart][$sLanguageId])) {
         $aMetadata = null;
     } else {
         $aMetadata = $aMetadata[$sDocumentationPart][$sLanguageId];
         $aMetadata['content'] = self::providerInstance($aMetadata['provider'])->contentForPart($sDocumentationPart, $sLanguageId);
     }
     $oCache->setContents($aMetadata);
     return $aMetadata;
 }
 public function renderFile()
 {
     $oCache = new Cache(implode('/', Manager::getUsedPath()), 'versioned');
     header("Content-Type: text/javascript;charset=utf-8");
     if ($oCache->entryExists()) {
         $oCache->sendCacheControlHeaders();
         $oCache->passContents();
         exit;
     }
     $oIncluder = new ResourceIncluder();
     // Don’t use SSL for downloads
     // Don’t include dependencies either
     $oIncluder->addJavaScriptLibrary($this->aLibraryName, $this->aVersion, $this->bUseCompression, false, false, ResourceIncluder::PRIORITY_NORMAL, false);
     $sContents = self::getResourceIncluderContents($oIncluder);
     $oCache->setContents($sContents);
     $oCache->sendCacheControlHeaders();
     print $sContents;
 }
 public function renderFile()
 {
     $oCache = new Cache('license_' . $this->sLicense, DIRNAME_IMAGES);
     $sExtension = substr($this->sURL, strrpos($this->sURL, '.') + 1);
     $oDocumentType = DocumentTypePeer::getDocumentTypeByExtension($sExtension);
     $sMimeType = 'image/' . $sExtension;
     if ($oDocumentType !== null) {
         $sMimeType = $oDocumentType->getMimetype();
     }
     header('Content-Type: ' . $sMimeType);
     if ($oCache->entryExists()) {
         $oCache->sendCacheControlHeaders();
         $oCache->passContents(true);
     } else {
         $sImage = file_get_contents($this->sURL);
         $oCache->setContents($sImage);
         $oCache->sendCacheControlHeaders();
         header("Content-Length: " . strlen($sImage));
         print $sImage;
     }
 }
 public function renderFile()
 {
     $iTemplateFlags = 0;
     $oResourceFinder = ResourceFinder::create(array(DIRNAME_MODULES, $this->sModuleType, $this->sModuleName, DIRNAME_TEMPLATES))->returnObjects();
     $sFileName = "{$this->sModuleName}.{$this->sModuleType}.{$this->sResourceType}";
     $oResourceFinder->addPath($sFileName . Template::$SUFFIX);
     if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_CSS) {
         header("Content-Type: text/css;charset=utf-8");
         $oResourceFinder->all();
     } else {
         if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_JS) {
             header("Content-Type: text/javascript;charset=utf-8");
             $iTemplateFlags = Template::ESCAPE | Template::NO_HTML_ESCAPE;
         } else {
             header("Content-Type: text/html;charset=utf-8");
         }
     }
     $oCache = new Cache('template_resource-' . $sFileName . '-' . Session::language(), 'resource');
     $oTemplate = null;
     if ($oCache->entryExists() && !$oCache->isOutdated($oResourceFinder)) {
         $oCache->sendCacheControlHeaders();
         $oTemplate = $oCache->getContentsAsVariable();
     } else {
         $oTemplate = new Template(TemplateIdentifier::constructIdentifier('contents'), null, true, false, null, $sFileName);
         $aResources = $oResourceFinder->find();
         if (!$aResources) {
             $aResources = array();
         }
         if ($aResources instanceof FileResource) {
             $aResources = array($aResources);
         }
         foreach ($aResources as $oResource) {
             $oSubTemplate = new Template($oResource, null, false, false, null, null, $iTemplateFlags);
             $oTemplate->replaceIdentifierMultiple('contents', $oSubTemplate, null, Template::LEAVE_IDENTIFIERS);
         }
         $oCache->setContents($oTemplate);
         $oCache->sendCacheControlHeaders();
     }
     print $oTemplate->render();
 }
Beispiel #10
0
 private function prepareChildren()
 {
     if ($this->aCustomChildren !== null) {
         return;
     }
     $sCacheKey = Session::language() . '/' . $this->getId();
     $oCache = new Cache("{$sCacheKey}/custom-children", 'navigation');
     if ($oCache->entryExists()) {
         // Not setting validators will result in the cache being always up-to-date
         $bIsOutdated = false;
         FilterModule::getFilters()->handleNavigationItemChildrenCacheDetectOutdated($this, $oCache, array(&$bIsOutdated));
         if (!$bIsOutdated) {
             $this->aCustomChildren = $oCache->getContentsAsVariable();
             foreach ($this->aCustomChildren as $oChildNavigationItem) {
                 $oChildNavigationItem->oParent = $this;
             }
             return;
         }
     }
     $this->aCustomChildren = array();
     FilterModule::getFilters()->handleNavigationItemChildrenRequested($this);
     $oCache->setContents($this->aCustomChildren, true);
 }
Beispiel #11
0
 /**
  * Fetches all module metadata (including module info obtained from the info.yml files) and stores it into a static field, returns it
  */
 public static function getModuleMetadataByTypeAndName($sType, $sName)
 {
     $aModuleMetadata = @self::$MODULES_METADATA_LIST[$sType][$sName];
     if ($aModuleMetadata !== null) {
         return $aModuleMetadata;
     }
     $oInfoFileFinder = ResourceFinder::create(array(DIRNAME_MODULES, $sType, $sName, self::INFO_FILE))->all();
     $oCache = new Cache("module_md_{$sType}-{$sName}", DIRNAME_PRELOAD);
     if ($oCache->entryExists() && !$oCache->isOutdated($oInfoFileFinder)) {
         $aModuleMetadata = $oCache->getContentsAsVariable();
     } else {
         //Module exists?
         $aModulePath = array(DIRNAME_MODULES, $sType, $sName);
         if (ResourceFinder::findResource($aModulePath) === null) {
             $aModuleMetadata = null;
             return null;
         }
         $aModuleMetadata = array();
         //General info
         $aModuleMetadata['path'] = $aModulePath;
         $aModuleMetadata['type'] = $sType;
         $aModuleMetadata['name'] = $sName;
         //Folders
         $aModuleMetadata['folders'] = array();
         $aFolders = ResourceFinder::findResourceObjectsByExpressions(array(DIRNAME_MODULES, $sType, $sName, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN));
         foreach ($aFolders as $oFolder) {
             $aModuleMetadata['folders'][] = $oFolder->getFileName();
         }
         //Module-info
         $aModuleInfo = array();
         require_once "spyc/Spyc.php";
         foreach ($oInfoFileFinder->find() as $sPath) {
             $aModuleInfo = array_merge($aModuleInfo, Spyc::YAMLLoad($sPath));
         }
         if (!isset($aModuleInfo['enabled'])) {
             $aModuleInfo['enabled'] = true;
         }
         $aModuleMetadata['module_info'] = $aModuleInfo;
         if (!isset(self::$MODULES_METADATA_LIST[$sType])) {
             self::$MODULES_METADATA_LIST[$sType] = array();
         }
         $oCache->setContents($aModuleMetadata);
     }
     self::$MODULES_METADATA_LIST[$sType][$sName] = $aModuleMetadata;
     return $aModuleMetadata;
 }
Beispiel #12
0
 public static function getInstance($sFile = null)
 {
     if ($sFile === null) {
         $sFile = "config";
     }
     $sCacheKey = self::createCacheKey($sFile);
     $sFileName = "{$sFile}.yml";
     if (!isset(self::$INSTANCES[$sCacheKey])) {
         $oCache = new Cache($sCacheKey, DIRNAME_CONFIG, CachingStrategyFile::create());
         $oFinder = ResourceFinder::create(array(DIRNAME_CONFIG))->addOptionalPath(ErrorHandler::getEnvironment())->addPath($sFileName)->byExpressions()->searchBaseFirst()->all();
         if ($oCache->entryExists() && !$oCache->isOutdated($oFinder)) {
             self::$INSTANCES[$sCacheKey] = $oCache->getContentsAsVariable();
         } else {
             self::$INSTANCES[$sCacheKey] = new Settings($oFinder, $sFile);
             $oCache->setContents(self::$INSTANCES[$sCacheKey]);
         }
     }
     return self::$INSTANCES[$sCacheKey];
 }
Beispiel #13
0
 /**
  * @param string $sTemplateName template name
  * @param string|array $mPath template dir path
  * @param boolean $bTemplateIsTextOnly template is text only (name will be used as content, path can be used to decide origin [null=filesystem, "db"=database, "browser"=request])
  * @param boolean $bDirectOutput template will output directly to stream? only one the main template should have set this to true
  * @param string $sTargetEncoding target encoding. usually the browser encoding. text will be converted from the source encoding (default is utf-8, at the moment only changed when using text-only templates) into the target encoding
  * @param string $sRootTemplateName root template name, used internally when including subtemplates, default=null
  * @param int $iDefaultFlags default flags, will be ORed to the flags you provide when calling {@link replaceIdentifier()} and {@link replaceIdentifierMultiple()}
  */
 public function __construct($sTemplateName, $mPath = null, $bTemplateIsTextOnly = false, $bDirectOutput = false, $sTargetEncoding = null, $sRootTemplateName = null, $iDefaultFlags = 0)
 {
     if ($sTargetEncoding === null) {
         $sTargetEncoding = Settings::getSetting("encoding", "browser", "utf-8");
     }
     if ($mPath === "db") {
         $this->sEncoding = Settings::getSetting("encoding", "db", "utf-8");
     } else {
         if ($mPath === "browser") {
             $this->sEncoding = Settings::getSetting("encoding", "browser", "utf-8");
         }
     }
     if ($mPath === null || $mPath === "db" || $mPath === "browser") {
         $mPath = DIRNAME_TEMPLATES;
     }
     $sTemplateText = "";
     $this->aTemplateContents = array();
     $oCache = null;
     $bCacheIsCurrent = false;
     if ($bTemplateIsTextOnly) {
         $sTemplateText = $sTemplateName;
         $sTemplateName = $sRootTemplateName;
     } else {
         if ($sTemplateName instanceof FileResource) {
             $oPath = $sTemplateName;
             $aPath = explode('/', $oPath->getRelativePath());
             $sTemplateName = $oPath->getFileName(self::$SUFFIX);
         } else {
             $aPath = ResourceFinder::parsePathArguments(null, $mPath, $sTemplateName . self::$SUFFIX);
             $oPath = ResourceFinder::findResourceObject($aPath);
         }
         if ($oPath === null) {
             throw new Exception("Error in Template construct: Template file " . implode("/", $aPath + array($sTemplateName . self::$SUFFIX)) . " does not exist");
         }
         if (Settings::getSetting('general', 'template_caching', false)) {
             $oCache = new Cache($oPath->getFullPath() . "_" . LocaleUtil::getLocaleId() . "_" . $sTargetEncoding . "_" . $sRootTemplateName, DIRNAME_TEMPLATES);
             $bCacheIsCurrent = $oCache->entryExists() && !$oCache->isOutdated($oPath->getFullPath());
         }
         if (!$bCacheIsCurrent) {
             $sTemplateText = file_get_contents($oPath->getFullPath());
         }
         $mPath = $aPath;
         array_pop($mPath);
     }
     if ($sRootTemplateName === null && !$bTemplateIsTextOnly) {
         $sRootTemplateName = $sTemplateName;
     }
     if ($sRootTemplateName === null) {
         $sRootTemplateName = '';
     }
     $this->sTemplateName = $sRootTemplateName;
     if (StringUtil::startsWith($sTemplateName, 'e_mail_') || StringUtil::startsWith($sTemplateName, 'email_')) {
         $iDefaultFlags |= self::NO_HTML_ESCAPE;
     } else {
         if (StringUtil::endsWith($sTemplateName, '.js') || StringUtil::endsWith($sTemplateName, '.css')) {
             $iDefaultFlags |= self::NO_HTML_ESCAPE | self::ESCAPE;
         } else {
             if (StringUtil::endsWith($this->sTemplateName, '.js') || StringUtil::endsWith($this->sTemplateName, '.css')) {
                 //I’m not a js template but my parent is
                 $iDefaultFlags &= ~(self::NO_HTML_ESCAPE | self::ESCAPE);
             }
         }
     }
     $this->mPath = $mPath;
     $this->oSpecialTemplateIdentifierActions = new SpecialTemplateIdentifierActions($this);
     $this->iDefaultFlags = $iDefaultFlags;
     if ($bCacheIsCurrent) {
         $this->aTemplateContents = $oCache->getContentsAsVariable();
         foreach ($this->aTemplateContents as &$mContent) {
             if ($mContent instanceof TemplatePart) {
                 $mContent->setTemplate($this);
             }
         }
     } else {
         if (is_array($sTemplateText)) {
             $this->aTemplateContents = $sTemplateText;
         } else {
             $sTemplateText = StringUtil::encode($sTemplateText, $this->sEncoding, $sTargetEncoding);
             $this->aTemplateContents = self::templateContentsFromText($sTemplateText, $this);
             $this->replaceConditionals(true);
             $this->renderDirectOutput();
         }
         $this->replaceSpecialIdentifiersOnStart();
         if ($oCache !== null) {
             $oCache->setContents($this->aTemplateContents);
         }
     }
     $this->sEncoding = $sTargetEncoding;
     $this->bDirectOutput = $bDirectOutput;
     $this->replaceConditionals(true);
     $this->renderDirectOutput();
 }
Beispiel #14
0
 public static function allParts()
 {
     $oCache = new Cache("system_parts", DIRNAME_CONFIG, CachingStrategyFile::create());
     if ($oCache->entryExists()) {
         return $oCache->getContentsAsVariable();
     }
     $oBasePart = new BasePart();
     $oSitePart = new SitePart();
     $aParts = array(DIRNAME_BASE => $oBasePart);
     // Get all plugins
     foreach (ResourceFinder::pluginFinder()->returnObjects()->find() as $oPath) {
         $oPluginPart = SystemPart::getPart($oPath->getRelativePath());
         // Plugins depend on base implicitly
         $oPluginPart->dependOn($oBasePart);
         // Site depends on plugins implicitly
         $oSitePart->dependOn($oPluginPart);
         $aParts[$oPath->getRelativePath()] = $oPluginPart;
     }
     $oSitePart->dependOn($oBasePart);
     $aParts[DIRNAME_SITE] = $oSitePart;
     // Add dependencies from info
     foreach ($aParts as $oPart) {
         $aInfo = $oPart->getInfo();
         foreach ($aInfo['dependencies'] as $sDependencyPrefix => $sVersion) {
             if (isset($aParts[$sDependencyPrefix])) {
                 $oPart->dependOn($aParts[$sDependencyPrefix]);
             } else {
                 throw new Exception("Dependency of {$oPart->getPrefix()} on {$sDependencyPrefix} can not be satisfied");
             }
         }
         foreach ($aInfo['optional_dependencies'] as $sDependencyPrefix => $sVersion) {
             if (isset($aParts[$sDependencyPrefix])) {
                 $oPart->dependOn($aParts[$sDependencyPrefix]);
             }
         }
     }
     // Order list by dependencies
     $aParts = self::orderedParts($aParts);
     // Cache ordered list
     $oCache->setContents($aParts);
     return $aParts;
 }
Beispiel #15
0
 /**
  * @return bool|string|FileResource|array the matched path(s)
  */
 public function find()
 {
     if ($this->mResult === false) {
         if (!$this->bNoCache && ErrorHandler::isProduction()) {
             $oCache = new Cache(serialize($this), 'resource_finder', CachingStrategyFile::create());
             if ($oCache->entryExists()) {
                 $this->mResult = $oCache->getContentsAsVariable();
             } else {
                 $this->mResult = $this->doFind();
                 $oCache->setContents($this->mResult, true);
             }
         } else {
             $this->mResult = $this->doFind();
         }
     }
     return $this->mResult;
 }
Beispiel #16
0
 private function consolidationStepForResourceType($sType, $bExcludeExternal, $iPriority, $sKey, &$aConsolidatorInfo, &$resource_type, &$file_resource, &$location, &$content, &$template, &$media, $aResourceInfo)
 {
     $sSSLMode = 'default';
     if ($resource_type !== $sType && $resource_type !== "inline_{$sType}") {
         return;
     }
     //External location (no file_resource given) or location not determinable
     $bIsExternal = $file_resource === null && $content === null;
     // Files with external references should only be consolidated if explicitly requested (resource_includer.yml/general/consolidate_resources == 'internal' disables this)
     $bShouldNotBeConsolidated = $bIsExternal && ($bExcludeExternal || $location === null);
     // Files with an IE condition can’t be consolidated because the condition (unlike CSS media queries) can only be set in HTML
     $bShouldNotBeConsolidated = $bShouldNotBeConsolidated || isset($aResourceInfo['ie_condition']);
     if ($bShouldNotBeConsolidated) {
         $this->cleanupConsolidator($aConsolidatorInfo);
     } else {
         $this->initConsolidator($sType, $iPriority, $sKey, $aConsolidatorInfo);
         $oCache = new Cache('consolidated-' . $sKey, DIRNAME_PRELOAD, CachingStrategy::fromConfig('file'));
         if (!$oCache->entryExists()) {
             $sRelativeLocationRoot = null;
             $sContents = '';
             if ($file_resource !== null) {
                 // We have a file resource
                 $sContents = file_get_contents($file_resource->getFullPath());
                 $sRelativeLocationRoot = LinkUtil::absoluteLink($file_resource->getFrontendPath(), null, $sSSLMode, true);
             } else {
                 if ($location !== null) {
                     // No file resource given, we only have a URL to go on
                     if (StringUtil::startsWith($location, '//')) {
                         $location = substr($location, strlen('//'));
                         // The path is a protocol-relative URL. Absolutize for file_get_contents and relativize for linking (according to linking/always_link_absolutely)
                         $sRelativeLocationRoot = LinkUtil::getProtocol() . $location;
                         $mProtocolSetting = 'auto';
                         $location = LinkUtil::getProtocol($mProtocolSetting) . $location;
                     } else {
                         if (StringUtil::startsWith($location, '/')) {
                             // The path is a domain-relative-URL. Absolutize for file_get_contents and relativize for linking (according to linking/always_link_absolutely)
                             $sRelativeLocationRoot = LinkUtil::absoluteLink($location, null, $sSSLMode, true);
                             $location = LinkUtil::absoluteLink($location, null, LinkUtil::isSSL());
                         } else {
                             $sRelativeLocationRoot = $location;
                         }
                     }
                     $sContents = file_get_contents($location);
                 } else {
                     if ($content !== null) {
                         if ($content instanceof Template) {
                             $content = $content->render();
                         }
                         $sContents = $content;
                     }
                 }
             }
             if ($sType === self::RESOURCE_TYPE_CSS && $media) {
                 $sContents = "@media {$media} { {$sContents} }";
             }
             // Fix relative locations in CSS
             if ($sType === self::RESOURCE_TYPE_CSS && $sRelativeLocationRoot !== null) {
                 //Remove the protocol so our slash-detection logic works correctly (because the protocol may also contain slashes)
                 if (preg_match(',^([a-z][a-z.\\-+]*:)?//,', $sRelativeLocationRoot, $sProtocol) === 1) {
                     $sProtocol = $sProtocol[0];
                 } else {
                     $sProtocol = '';
                 }
                 $sRelativeLocationRoot = substr($sRelativeLocationRoot, strlen($sProtocol));
                 $sAbsoluteLocationRoot = $sRelativeLocationRoot;
                 $bHasTruncatedTail = false;
                 $iSlashPosition = null;
                 // Calculate the absolute location root (will be "" most of the time unless the CSS was loaded from an external domain or linking/always_link_absolutely is true)
                 while (($iSlashPosition = strrpos($sAbsoluteLocationRoot, '/')) !== false) {
                     $sAbsoluteLocationRoot = substr($sAbsoluteLocationRoot, 0, $iSlashPosition);
                     if (!$bHasTruncatedTail) {
                         // Remove the last part from the relative location as it’s the resource itself
                         $sRelativeLocationRoot = "{$sAbsoluteLocationRoot}/";
                         $bHasTruncatedTail = true;
                     }
                 }
                 // Re-add the protocol part
                 $sRelativeLocationRoot = $sProtocol . $sRelativeLocationRoot;
                 $sAbsoluteLocationRoot = $sProtocol . $sAbsoluteLocationRoot;
                 // Find url() tokens
                 $sContents = preg_replace_callback(',url\\s*\\(\\s*(\'[^\']+\'|\\"[^\\"]+\\"|[^(\'\\"]+?)\\s*\\),', function ($aMatches) use($sRelativeLocationRoot, $sAbsoluteLocationRoot) {
                     // Convert /something/../ to /
                     $sQuote = '';
                     $sUrl = $aMatches[1];
                     $sFirst = substr($sUrl, 0, 1);
                     if ($sFirst === '"' || $sFirst === "'") {
                         $sQuote = $sFirst;
                         $sUrl = substr($sUrl, 1, -1);
                     }
                     if (StringUtil::startsWith($sUrl, '//')) {
                         // URL is protocol-relative. Do nothing.
                         // If this were pointing to the local host, we’d need to respect linking/ssl_in_absolute_links
                         // but if it did come from a file resource, we’d already have that
                     } else {
                         if (StringUtil::startsWith($sUrl, '/')) {
                             // URL absolute. That means relative to $sAbsoluteLocationRoot
                             $sUrl = $sAbsoluteLocationRoot . $sUrl;
                         } else {
                             if (!preg_match(',^[a-z][a-z.\\-+]*:,', $sUrl)) {
                                 // URL is relative to the resource being changed. That means relative to $sRelativeLocationRoot
                                 // Absolutize only relative URLs (the ones not starting with a protocol)
                                 // Prepend the coomon root for the relative location
                                 $sUrl = $sRelativeLocationRoot . $sUrl;
                                 // Fix explicit relative URLs (./)
                                 $sUrl = preg_replace(',/\\./,', '/', $sUrl);
                                 // Resolve Uplinks (/some-place/../)
                                 $sParentPattern = ',/[^/]+/\\.\\./,';
                                 while (preg_match($sParentPattern, $sUrl) === 1) {
                                     $sUrl = preg_replace($sParentPattern, '/', $sUrl, 1);
                                 }
                             }
                         }
                     }
                     return "url({$sQuote}{$sUrl}{$sQuote})";
                 }, $sContents);
             }
             $oCache->setContents($sContents);
         }
         $aConsolidatorInfo['contents'][$sKey] = $oCache;
     }
 }
 public function adminGetContainers()
 {
     $oTemplate = $this->oPage->getTemplate();
     foreach ($oTemplate->identifiersMatching('container', Template::$ANY_VALUE) as $oIdentifier) {
         $oInheritedFrom = null;
         $sContainerName = $oIdentifier->getValue();
         if (BooleanParser::booleanForString($oIdentifier->getParameter('inherit'))) {
             $oInheritedFrom = $this->oPage;
             $iInheritedObjectCount = 0;
             while ($iInheritedObjectCount === 0 && ($oInheritedFrom = $oInheritedFrom->getParent()) !== null) {
                 $iInheritedObjectCount = $oInheritedFrom->countObjectsForContainer($sContainerName);
             }
         }
         $sInheritedFrom = $oInheritedFrom ? $oInheritedFrom->getName() : '';
         $aTagParams = array('class' => 'template-container template-container-' . $sContainerName, 'data-container-name' => $sContainerName, 'data-container-string' => TranslationPeer::getString('container_name.' . $sContainerName, null, $sContainerName), 'data-inherited-from' => $sInheritedFrom);
         $oContainerTag = TagWriter::quickTag('ol', $aTagParams);
         $mInnerTemplate = new Template(TemplateIdentifier::constructIdentifier('content'), null, true);
         //Replace container info
         //…name
         $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-description'), TranslationPeer::getString('wns.page.template_container', null, null, array('container' => TranslationPeer::getString('template_container.' . $sContainerName, null, $sContainerName)), true)));
         //…additional info
         $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-info')));
         //…tag
         $mInnerTemplate->replaceIdentifierMultiple('content', $oContainerTag);
         //Replace actual container
         $oTemplate->replaceIdentifier($oIdentifier, $mInnerTemplate);
     }
     $bUseParsedCss = Settings::getSetting('admin', 'use_parsed_css_in_config', true);
     $oStyle = null;
     if ($bUseParsedCss) {
         $sTemplateName = $this->oPage->getTemplateNameUsed() . Template::$SUFFIX;
         $sCacheKey = 'parsed-css-' . $sTemplateName;
         $oCssCache = new Cache($sCacheKey, DIRNAME_PRELOAD);
         $sCssContents = "";
         if (!$oCssCache->entryExists() || $oCssCache->isOutdated(ResourceFinder::create(array(DIRNAME_TEMPLATES, $sTemplateName)))) {
             $oIncluder = new ResourceIncluder();
             foreach ($oTemplate->identifiersMatching('addResourceInclude', Template::$ANY_VALUE) as $oIdentifier) {
                 $oIncluder->addResourceFromTemplateIdentifier($oIdentifier);
             }
             foreach ($oIncluder->getAllIncludedResources() as $sIdentifier => $aResource) {
                 if ($aResource['resource_type'] === ResourceIncluder::RESOURCE_TYPE_CSS && !isset($aResource['ie_condition']) && !isset($aResource['frontend_specific'])) {
                     if (isset($aResource['media'])) {
                         $sCssContents .= "@media {$aResource['media']} {";
                     }
                     if (isset($aResource['file_resource'])) {
                         $sCssContents .= file_get_contents($aResource['file_resource']->getFullPath());
                     } else {
                         // Absolute link, requires fopen wrappers
                         $sCssContents .= file_get_contents($aResource['location']);
                     }
                     if (isset($aResource['media'])) {
                         $sCssContents .= "}";
                     }
                 }
             }
             $oParser = new Sabberworm\CSS\Parser($sCssContents, Sabberworm\CSS\Settings::create()->withDefaultCharset(Settings::getSetting("encoding", "browser", "utf-8")));
             $oCss = $oParser->parse();
             $this->cleanupCSS($oCss);
             $sCssContents = Template::htmlEncode($oCss->render(Sabberworm\CSS\OutputFormat::createCompact()));
             $oCssCache->setContents($sCssContents);
         } else {
             $sCssContents = $oCssCache->getContentsAsString();
         }
         $oStyle = new HtmlTag('style');
         $oStyle->addParameters(array('scoped' => 'scoped'));
         $oStyle->appendChild($sCssContents);
     }
     $sTemplate = $oTemplate->render();
     $sTemplate = substr($sTemplate, strpos($sTemplate, '<body') + 5);
     $sTemplate = substr($sTemplate, strpos($sTemplate, '>') + 1);
     $sTemplate = substr($sTemplate, 0, strpos($sTemplate, '</body'));
     $oParser = new TagParser("<body>{$sTemplate}</body>");
     $oTag = $oParser->getTag();
     $this->cleanupContainerStructure($oTag);
     if ($bUseParsedCss) {
         $oTag->appendChild($oStyle);
     }
     $sResult = $oTag->__toString();
     $sResult = substr($sResult, strpos($sResult, '<body>') + 6);
     $sResult = substr($sResult, 0, strrpos($sResult, '</body>'));
     return array('html' => $sResult, 'css_parsed' => $bUseParsedCss);
 }