Exemple #1
0
 /**
  * @param $xml
  * @return string
  */
 private function execBlockOfTypeCSS($xml)
 {
     $consolidatedContent = '';
     if ($this->sequence === false && !$this->getXMLAttr($xml, 'sequence') || $this->sequence !== false && $this->sequence === $this->getXMLAttr($xml, 'sequence')) {
         $cssReplace = '';
         $group = $this->getXMLAttr($xml, 'group') ?: 'default';
         foreach ($this->template->getCssFiles($group) as $cssFile) {
             if ($isUrl = preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $cssFile)) {
                 $file = $cssFile;
             } else {
                 $file = substr($cssFile, 0, 1) == '/' ? $cssFile : rtrim(CSS_FOLDER, '/') . '/' . $cssFile;
             }
             if ($this->getXMLAttr($xml, 'consolidate') === true) {
                 $consolidatedContent .= file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($file, '/'));
             } else {
                 $fileHash = hash_file('crc32', 'Public/' . $file);
                 $cssReplace .= '<link rel="stylesheet" type="text/css" href="' . $file . '?' . $fileHash . '" />';
             }
         }
         if ($this->getXMLAttr($xml, 'consolidate') === true) {
             $cssReplace = $this->consolidateCss($consolidatedContent);
         }
         if ($this->getXMLAttr($xml, 'placeholder')) {
             $this->addPlaceholderReplacement($xml, $cssReplace);
             return '';
         }
         return $cssReplace;
     }
     return $this->xmlString;
 }
Exemple #2
0
 /**
  * @param $xml
  * @return string
  */
 protected function execBlockOfTypeCss($xml)
 {
     $consolidatedContent = '';
     if ($this->sequence === false && !$this->getXmlAttr($xml, 'sequence') || $this->sequence !== false && $this->sequence === $this->getXmlAttr($xml, 'sequence')) {
         $cssReplace = '';
         $group = $this->getXmlAttr($xml, 'group') ?: 'default';
         $fileHash = null;
         $cssFiles = $this->template->getCssFiles($group);
         $fileHash = md5(serialize($cssFiles));
         $consolidatedCssFilePath = rtrim(CONSOLIDATE_FOLDER, '/') . '/' . $fileHash . '.css';
         $consolidatedFileExists = is_file('Public' . $consolidatedCssFilePath);
         $consolidate = GLOBAL_CACHING_ENABLED ? $this->getXmlAttr($xml, 'consolidate') : false;
         foreach ($cssFiles as $cssFileData) {
             $cssFile = $cssFileData['file'];
             if ($isUrl = preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $cssFile)) {
                 $file = $cssFile;
             } else {
                 $file = substr($cssFile, 0, 1) == '/' ? $cssFile : rtrim(CSS_FOLDER, '/') . '/' . $cssFile;
             }
             if ($isUrl == 0 && $consolidatedFileExists === false && $consolidate === true) {
                 $consolidatedContent .= file_get_contents('Public/' . ltrim($file, '/'));
             } elseif ($isUrl !== 0 || $consolidate !== true) {
                 if (!$isUrl) {
                     $fileHash = hash_file('crc32', 'Public/' . $file);
                 }
                 $cssReplace .= '<link rel="stylesheet" type="text/css" href="' . $file . ($fileHash ? '?' . $fileHash : '') . '"' . (count($cssFileData['attributes']) ? ' ' . implode(' ', $cssFileData['attributes']) : '') . ' />';
             }
         }
         if ($consolidate === true && (!empty($consolidatedContent) || $consolidatedFileExists)) {
             if ($consolidatedFileExists) {
                 $cssReplace .= '<link rel="stylesheet" type="text/css" href="' . $consolidatedCssFilePath . '" />';
             } else {
                 $cssReplace .= $this->consolidateCss($consolidatedCssFilePath, $consolidatedContent);
             }
         }
         if ($this->getXmlAttr($xml, 'placeholder')) {
             $this->addPlaceholderReplacement($xml, $cssReplace);
             return '';
         }
         return $cssReplace;
     }
     return $this->xmlString;
 }