/**
  * Prepare css or js files for aggregation and minification
  *
  * @param array $aUrlArray   Array of urls of css or js files for aggregation
  * @param string $sType       css or js
  * @param string $sLnEnd     line end
  * @return string         Aggregated (and possibly minified) contents of files
  */
 public function getContents($aUrlArray, $sType, $sLnEnd, $iMinify, $iImport, $iSprite, $sId)
 {
     ksort($aUrlArray);
     $sContents = $this->combineFiles($aUrlArray, $sLnEnd, $sType);
     if ($sType == 'css') {
         if ($iImport) {
             $sContents = $this->replaceImports($sContents, $sLnEnd);
         }
         $sContents = trim($this->sortImports($sContents, $sLnEnd));
         if ($iSprite) {
             $sContents = $this->generateSprite($sContents, $sLnEnd);
         }
         if ($iMinify) {
             $sContents = Minify_CSS::process($sContents);
         }
     }
     if ($iMinify && $sType == 'js') {
         try {
             $sContents = JSMin::minify($sContents);
         } catch (JSMinException $e) {
             //Need to test how this handles
             JError::raiseWarning(101, $e->getMessage());
             //return false;
         }
     }
     $sContents = str_replace('LINE_END', $sLnEnd, $sContents);
     return $sContents;
 }
Beispiel #2
0
 /**
  * override method: get content of css files
  */
 function getCssContents($files, $isCompressed = true, $isYUI = false)
 {
     $contents = "/**ICE-ENGINE-CSS**/";
     foreach ($files as $key => $file) {
         $subpath = str_replace('/', DS, $file);
         $fullpath = JPATH_ROOT . DS . $subpath;
         $basepath = preg_replace('/^\\//', '', dirname($this->getRequestURI() . $file));
         $contentFile = '';
         if (preg_match('/\\.php/', $file)) {
             $contentFile = @file_get_contents(JURI::base() . str_replace("&", "&", $file));
         } else {
             if (file_exists($fullpath)) {
                 // get Content Of File;
                 $contentFile = @file_get_contents($fullpath);
             }
         }
         if ($contentFile) {
             //$contentFile = str_replace('url(..', 'url(/'.dirname($basepath), $contentFile );
             //$contentFile = str_replace('url(\'..', 'url(\'/'.dirname($basepath), $contentFile );
             //$contentFile = str_replace('url("..', 'url("/'.dirname($basepath), $contentFile );
             $contentFile = str_replace('url("', 'url("123', $contentFile);
             $contentFile = str_replace('url(\'', 'url(\'123', $contentFile);
             $contentFile = str_replace('url(', 'url(123', $contentFile);
             $path = dirname($this->getRequestURI() . $file) . '/';
             $contentFile = str_replace('url(123../', 'url(' . dirname($path) . '/', $contentFile);
             $contentFile = str_replace('url(\'123../', 'url(\'' . dirname($path) . '/', $contentFile);
             $contentFile = str_replace('url("123../', 'url("' . dirname($path) . '/', $contentFile);
             $contentFile = str_replace('url(123\'123', 'url(\'' . $path, $contentFile);
             $contentFile = str_replace('url(123"123', 'url("' . $path, $contentFile);
             $contentFile = str_replace('url(123', 'url(' . $path, $contentFile);
             // start clean up file
             $contents .= "/** '.{$subpath}.' **/\t";
             $contents .= $this->cleanUpText($contentFile);
         }
     }
     if ($isCompressed) {
         if ($isYUI) {
             $app =& JFactory::getApplication();
             Minify_YUICompressor::$jarFile = dirname(__FILE__) . DS . 'Minify' . DS . 'yuicompressor-2.4.6.jar';
             Minify_YUICompressor::$tempDir = $app->getCfg("tmp_path");
             $contents = Minify_YUICompressor::minifyCss($contents, array('nomunge' => true, 'line-break' => 1000));
         } else {
             $contents = Minify_CSS::process($contents);
         }
     }
     return $contents;
 }