Esempio n. 1
0
 /**
  * @param $xml
  * @return string
  */
 private function execBlockOfTypeJS($xml)
 {
     $consolidatedContent = '';
     if ($this->sequence === false && !$this->getXMLAttr($xml, 'sequence') || $this->sequence !== false && $this->sequence === $this->getXMLAttr($xml, 'sequence')) {
         $jsReplace = '';
         $isUrl = 0;
         $group = $this->getXMLAttr($xml, 'group') ?: 'default';
         foreach ($this->template->getJsFiles($group) as $jsFile) {
             if ($isUrl = preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $jsFile)) {
                 $file = $jsFile;
             } else {
                 $file = substr($jsFile, 0, 1) == '/' ? $jsFile : rtrim(JS_FOLDER, '/') . '/' . $jsFile;
             }
             if ($isUrl == 0 && $this->getXMLAttr($xml, 'consolidate') === true) {
                 $consolidatedContent .= file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($file, '/'));
             } else {
                 $fileHash = hash_file('crc32', 'Public/' . $file);
                 $jsReplace .= '<script type="text/javascript" src="' . $file . '?' . $fileHash . '"></script>';
             }
         }
         if ($isUrl == 0 && $this->getXMLAttr($xml, 'consolidate') === true) {
             $jsReplace = $this->consolidateJs($consolidatedContent);
         }
         if ($this->getXMLAttr($xml, 'placeholder')) {
             $this->addPlaceholderReplacement($xml, $jsReplace);
             return '';
         }
         return $jsReplace;
     }
     return $this->xmlString;
 }
Esempio n. 2
0
 /**
  * @param $xml
  * @return string
  */
 protected function execBlockOfTypeJS($xml)
 {
     $consolidatedContent = '';
     if ($this->sequence === false && !$this->getXmlAttr($xml, 'sequence') || $this->sequence !== false && $this->sequence === $this->getXmlAttr($xml, 'sequence')) {
         $jsReplace = '';
         $isUrl = 0;
         $fileHash = null;
         $group = $this->getXmlAttr($xml, 'group') ?: 'default';
         $jsFiles = $this->template->getJsFiles($group);
         $fileHash = md5(serialize($jsFiles));
         $consolidatedJsFilePath = rtrim(CONSOLIDATE_FOLDER, '/') . '/' . $fileHash . '.js';
         $consolidatedFileExists = is_file('Public' . $consolidatedJsFilePath);
         $consolidate = GLOBAL_CACHING_ENABLED ? $this->getXmlAttr($xml, 'consolidate') : false;
         foreach ($jsFiles as $jsFileData) {
             $jsFile = $jsFileData['file'];
             if ($isUrl = preg_match("#((http|https|ftp)://(\\S*?\\.\\S*?))(\\s|\\;|\\)|\\]|\\[|\\{|\\}|,|\"|'|:|\\<|\$|\\.\\s)#ie", $jsFile)) {
                 $file = $jsFile;
             } else {
                 $file = substr($jsFile, 0, 1) == '/' ? $jsFile : rtrim(JS_FOLDER, '/') . '/' . $jsFile;
             }
             if ($isUrl == 0 && $consolidatedFileExists === false && $consolidate === true) {
                 $consolidatedContent .= ";\n" . file_get_contents('Public/' . ltrim($file, '/'));
             } elseif ($isUrl !== 0 || $consolidate !== true) {
                 if (!$isUrl) {
                     $fileHash = hash_file('crc32', 'Public/' . $file);
                 }
                 $jsReplace .= '<script type="text/javascript" src="' . $file . ($fileHash ? '?' . $fileHash : '') . '"' . (count($jsFileData['attributes']) ? ' ' . implode(' ', $jsFileData['attributes']) : '') . '></script>';
             }
         }
         if ($consolidate === true && (!empty($consolidatedContent) || $consolidatedFileExists)) {
             if ($consolidatedFileExists) {
                 $jsReplace .= '<script type="text/javascript" src="' . $consolidatedJsFilePath . '"></script>';
             } else {
                 $jsReplace .= $this->consolidateJs($consolidatedJsFilePath, $consolidatedContent);
             }
         }
         if ($this->getXmlAttr($xml, 'placeholder')) {
             $this->addPlaceholderReplacement($xml, $jsReplace);
             return '';
         }
         return $jsReplace;
     }
     return $this->xmlString;
 }