public function setTemplate($mTemplate) { $aCssUrls = array(); //Important for CSS if (!isset($this->aModuleSettings['css_files'])) { if (is_string($mTemplate)) { $mTemplate = new Template($mTemplate); } $oIncluder = new ResourceIncluder(); foreach ($mTemplate->identifiersMatching('addResourceInclude', Template::$ANY_VALUE) as $oIdentifier) { $oIncluder->addResourceFromTemplateIdentifier($oIdentifier); } $aResources = $oIncluder->getAllIncludedResources(); foreach ($aResources as $aResourceInfo) { if (!(isset($aResourceInfo['resource_type']) && $aResourceInfo['resource_type'] === ResourceIncluder::RESOURCE_TYPE_CSS)) { continue; } if (isset($aResourceInfo['ie_condition'])) { continue; } if (isset($aResourceInfo['media']) && !preg_match('/\\b(screen|all)\\b/', $aResourceInfo['media'])) { continue; } $aCssUrls[] = $aResourceInfo['location']; } //Always include an editor.css file if found foreach (ResourceFinder::findAllResourceObjects(array(DIRNAME_WEB, 'css', 'editor.css')) as $oFileUrl) { $aCssUrls[] = $oFileUrl->getFrontendPath(); } } $this->setSetting('contentsCss', $aCssUrls); }
public function writeDirectInclude($oIdentifier) { $oResourceIncluder = new ResourceIncluder(); $oResourceIncluder->addResourceFromTemplateIdentifier($oIdentifier); return $oResourceIncluder->getIncludes(false); }
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); }