コード例 #1
0
ファイル: combiner.php プロジェクト: irovast/eyedock
 /**
  * Get aggregated and possibly minified content from js and css files
  *
  * @param array $aUrlArray      Array of urls of css or js files for aggregation
  * @param string $sType         css or js
  * @return string               Aggregated (and possibly minified) contents of files
  */
 public function getContents($aUrlArray, $sType, $oParser)
 {
     JCH_DEBUG ? JchPlatformProfiler::start('GetContents - ' . $sType, TRUE) : null;
     $oCssParser = $this->oCssParser;
     $sCriticalCss = '';
     $aSpriteCss = array();
     $aFontFace = array();
     $aContentsArray = array();
     foreach ($aUrlArray as $index => $aUrlInnerArray) {
         $sContents = $this->combineFiles($aUrlInnerArray, $sType, $oCssParser);
         $sContents = $this->prepareContents($sContents);
         $aContentsArray[$index] = $sContents;
     }
     if ($sType == 'css') {
         if ($this->params->get('csg_enable', 0)) {
             try {
                 $oSpriteGenerator = new JchOptimizeSpriteGenerator($this->params);
                 $aSpriteCss = $oSpriteGenerator->getSprite($this->{$sType});
             } catch (Exception $ex) {
                 JchOptimizeLogger::log($ex->getMessage(), $this->params);
                 $aSpriteCss = array();
             }
         }
         if ($this->params->get('pro_optimizeCssDelivery', '0')) {
             if (is_array($aSpriteCss) && !empty($aSpriteCss) && isset($aSpriteCss['needles']) && isset($aSpriteCss['replacements'])) {
                 $this->{$sType} = str_replace($aSpriteCss['needles'], $aSpriteCss['replacements'], $this->{$sType});
             }
             $oParser->params->set('pro_InlineScripts', '1');
             $oParser->params->set('pro_InlineStyles', '1');
             $sHtml = $oParser->cleanHtml();
             $aCssContents = $oCssParser->optimizeCssDelivery($this->{$sType}, $sHtml);
             $sCriticalCss .= $oCssParser->sortImports($aCssContents['criticalcss']);
             $sCriticalCss = $sCriticalCss;
             $aFontFace = preg_split('#}\\K[^@]*+#', $aCssContents['font-face'], -1, PREG_SPLIT_NO_EMPTY);
         }
     }
     try {
         $oAdmin = new JchOptimizeAdmin($this->params);
         $oAdmin->getAdminLinks($oParser, JchPlatformUtility::menuId(), $this->css);
     } catch (Exception $ex) {
         JchOptimizeLogger::log($ex->getMessage(), $this->params);
     }
     $aContents = array('filemtime' => JchPlatformUtility::unixCurrentDate(), 'file' => $aContentsArray, 'criticalcss' => $sCriticalCss, 'spritecss' => $aSpriteCss, 'font-face' => $aFontFace);
     JCH_DEBUG ? JchPlatformProfiler::stop('GetContents - ' . $sType) : null;
     return $aContents;
 }
コード例 #2
0
ファイル: combiner.php プロジェクト: educakanchay/educa
 /**
  * Get aggregated and possibly minified content from js and css files
  *
  * @param array $aUrlArray      Array of urls of css or js files for aggregation
  * @param string $sType         css or js
  * @return string               Aggregated (and possibly minified) contents of files
  */
 public function getContents($aUrlArray, $sType, $oParser)
 {
     $oCssParser = new JchOptimizeCssParser($oParser, $this->bBackend);
     $sCriticalCss = '';
     $aSpriteCss = array();
     $aFontFace = array();
     $aContentsArray = array();
     foreach ($aUrlArray as $index => $aUrlInnerArray) {
         $sContents = $this->combineFiles($aUrlInnerArray, $sType, $oCssParser);
         $sContents = $this->prepareContents($sContents);
         $aContentsArray[$index] = $sContents;
     }
     if ($sType == 'css') {
         if ($this->params->get('csg_enable', 0)) {
             try {
                 $oSpriteGenerator = new JchOptimizeSpriteGenerator($this->params);
                 $aSpriteCss = $oSpriteGenerator->getSprite($this->{$sType});
             } catch (Exception $ex) {
                 JchOptimizeLogger::log($ex->getMessage(), $this->params);
                 $aSpriteCss = array();
             }
         }
         if ($this->params->get('pro_optimizeCssDelivery', '0')) {
             if (!empty($aSpriteCss)) {
                 $this->{$sType} = str_replace($aSpriteCss['needles'], $aSpriteCss['replacements'], $this->{$sType});
             }
             $oParser->params->set('pro_InlineScripts', '0');
             $oParser->params->set('pro_InlineStyles', '0');
             $sHtml = $oParser->cleanHtml();
             $aCssContents = $oCssParser->optimizeCssDelivery($this->{$sType}, $sHtml);
             $sCriticalCss .= $aCssContents['criticalcss'];
             $aFontFace = preg_split('#}\\K[^@]*+#', $aCssContents['font-face'], -1, PREG_SPLIT_NO_EMPTY);
         }
     }
     $aContents = array('filemtime' => JchPlatformUtility::unixCurrentDate(), 'file' => $aContentsArray, 'criticalcss' => $sCriticalCss, 'spritecss' => $aSpriteCss, 'font-face' => $aFontFace);
     return $aContents;
 }