예제 #1
0
 public function addResourceFromTemplateIdentifier($oIdentifier)
 {
     $mLocation = $oIdentifier->getValue();
     $iPriority = $oIdentifier->hasParameter('priority') ? constant("ResourceIncluder::PRIORITY_" . strtoupper($oIdentifier->getParameter('priority'))) : ResourceIncluder::PRIORITY_NORMAL;
     $sIeCondition = $oIdentifier->hasParameter('ie_condition') ? $oIdentifier->getParameter('ie_condition') : null;
     if ($oIdentifier->hasParameter('library')) {
         $bUseSsl = $oIdentifier->hasParameter('use_ssl') ? null : 'default';
         if ($oIdentifier->getParameter('use_ssl')) {
             $bUseSsl = $oIdentifier->getParameter('use_ssl');
             if ($bUseSsl !== 'auto' && $bUseSsl !== 'default') {
                 $bUseSsl = BooleanParser::booleanForString($bUseSsl);
             }
         }
         $this->addJavaScriptLibrary($mLocation, $oIdentifier->getParameter('library'), $oIdentifier->hasParameter('uncompressed') ? false : null, !$oIdentifier->hasParameter('nodeps'), $bUseSsl, $iPriority, null, $sIeCondition);
         return null;
     }
     if ($oIdentifier->hasParameter('inline')) {
         if ($oIdentifier->getParameter('inline') === 'css') {
             $this->addCustomCss($mLocation);
         } else {
             if ($oIdentifier->getParameter('inline') === 'js') {
                 $this->addCustomJs($mLocation);
             }
         }
         return null;
     }
     if ($oIdentifier->hasParameter('fromBase')) {
         //Is named the same in include so we leave it in camel case
         $mLocation = explode('/', $mLocation);
     }
     $aParams = $oIdentifier->getParameters();
     $aParams['from_template'] = true;
     $sResourceType = $oIdentifier->hasParameter('type') ? $oIdentifier->getParameter('type') : null;
     // Fall back to 'resource_type' param for backwards compatiblity
     if ($sResourceType === null && $oIdentifier->hasParameter('resource_type')) {
         $sResourceType = $oIdentifier->getParameter('resource_type');
     }
     $bIncludeAll = $oIdentifier->hasParameter('include_all');
     $this->addResource($mLocation, $sResourceType, null, $aParams, $iPriority, $sIeCondition, $bIncludeAll);
 }
예제 #2
0
 private function replaceConditionals($bFinalOnly = false)
 {
     $iStartPosition = 0;
     $oIf = null;
     while (true) {
         $oIf = $this->identifiersMatching("if", self::$ANY_VALUE, null, true, $iStartPosition);
         if (!$oIf) {
             break;
         }
         if ($bFinalOnly && !$oIf->isFinal()) {
             $iStartPosition = $this->identifierPosition($oIf) + 1;
             continue;
         }
         $oEndIf = $this->findEndIfForIf($oIf);
         if (!$oEndIf) {
             $oIf->destroy();
             continue;
         }
         $sComparison = $oIf->getValue() !== null ? $oIf->getValue() : "=";
         $sFirst = $oIf->getParameter('1');
         $sSecond = $oIf->hasParameter('2') && $oIf->getParameter('2') !== null ? $oIf->getParameter('2') : "";
         $sCompareMode = $oIf->hasParameter('strict') && $oIf->getParameter('strict') === 'true' ? "strict" : "normal";
         $sComparisonString = '==';
         $mUnexpectedResult = false;
         $aFuncArgs = array($sFirst, $sSecond);
         switch ($sComparison) {
             case 'ne':
             case 'notEqual':
             case 'not_eqal':
             case '!=':
             case '!==':
             case '<>':
                 $sComparisonString = "!=";
                 break;
             case 'gt':
             case 'greaterThan':
             case 'greater_than':
             case '>':
                 $sComparisonString = ">";
                 $sCompareMode = "normal";
                 break;
             case 'lt':
             case 'lessThan':
             case 'less_than':
             case '<':
                 $sComparisonString = "<";
                 $sCompareMode = "normal";
                 break;
             case 'gte':
             case 'greaterThanEqual':
             case 'greater_than_equal':
             case '>=':
                 $sComparisonString = ">=";
                 $sCompareMode = "normal";
                 break;
             case 'lte':
             case 'lessThanEqual':
             case 'less_than_equal':
             case '<=':
                 $sComparisonString = "<=";
                 $sCompareMode = "normal";
                 break;
             case '~':
                 $sComparisonString = "preg_match";
                 $sCompareMode = "function";
                 $mUnexpectedResult = 0;
                 break;
             case '|=':
                 $sComparisonString = "in_array";
                 $aFuncArgs = array($sFirst, explode('|', $sSecond));
                 $sCompareMode = "function";
                 break;
             case '~=':
                 $sComparisonString = "in_array";
                 $aFuncArgs = array($sFirst, preg_split('/\\s+/', $sSecond, -1, PREG_SPLIT_NO_EMPTY));
                 $sCompareMode = "function";
                 break;
             case 'contains':
                 $sComparisonString = "stripos";
                 if ($sCompareMode === "strict") {
                     $sComparisonString = "strpos";
                 }
                 $sCompareMode = "function";
                 break;
             case 'file_exists':
                 $sComparisonString = "file_exists";
                 $sFirst = MAIN_DIR . $sFirst;
                 $mUnexpectedResult = !BooleanParser::booleanForString($sSecond);
                 $aFuncArgs = array($sFirst);
                 $sCompareMode = "function";
                 break;
         }
         if ($sCompareMode === "function") {
             $bResult = call_user_func_array($sComparisonString, $aFuncArgs) !== $mUnexpectedResult;
         } else {
             if ($sCompareMode === "strict") {
                 $sComparisonString .= "=";
             }
             $bResult = eval('return $sFirst ' . $sComparisonString . ' $sSecond;') !== $mUnexpectedResult;
         }
         if (!$bResult) {
             $this->replaceAt($oIf, null, $oEndIf);
         } else {
             $oIf->destroy();
             $oEndIf->destroy();
         }
     }
 }
예제 #3
0
 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);
 }