Ejemplo n.º 1
0
 public static function minify($css, $options = array())
 {
     $options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
     set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_CSSTIDY_DIR);
     require_once 'class.csstidy.php';
     $csstidy = new csstidy();
     foreach ($options as $option => $value) {
         $csstidy->set_cfg($option, $value);
     }
     $csstidy->load_template($options['template']);
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     if (isset($options['currentDir']) || isset($options['prependRelativePath'])) {
         require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
         $browsercache_id = isset($options['browserCacheId']) ? $options['browserCacheId'] : 0;
         $browsercache_extensions = isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array();
         if (isset($options['currentDir'])) {
             $document_root = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
             $symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
             return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $document_root, $symlinks, $browsercache_id, $browsercache_extensions);
         } else {
             return Minify_CSS_UriRewriter::prepend($css, $options['prependRelativePath'], $browsercache_id, $browsercache_extensions);
         }
     }
     return $css;
 }
Ejemplo n.º 2
0
/**
 * 压缩css文件
 * 
 * @param mixed $sourceFile
 * @param mixed $targetFile
 * @return void
 */
function minify_css($sourceFile, $targetFile)
{
    $css = new csstidy();
    $css->load_template('highest_compression');
    /*	$css->set_cfg('remove_bslash',false);
    		$css->set_cfg('compress_colors',false);
    		$css->set_cfg('compress_font-weight',false);
    		$css->set_cfg('lowercase_s',true);
    		$css->set_cfg('optimise_shorthands',$_REQUEST['optimise_shorthands']);
    		$css->set_cfg('remove_last_;',true);
    		$css->set_cfg('case_properties',$_REQUEST['case_properties']);
    		$css->set_cfg('sort_properties',true);
    		$css->set_cfg('sort_selectors',true);
    		$css->set_cfg('merge_selectors', $_REQUEST['merge_selectors']);
    		$css->set_cfg('discard_invalid_properties',true);
    		$css->set_cfg('preserve_css',true);
    		$css->set_cfg('timestamp',true);
    		*/
    $strSourceCSS = file_get_contents($sourceFile);
    $strResult = $css->parse($strSourceCSS);
    $handle = fopen($targetFile, 'w');
    if ($handle) {
        if (fwrite($handle, $css->print->plain())) {
            $file_ok = true;
        }
    }
    fclose($handle);
}
Ejemplo n.º 3
0
 function compress($Media)
 {
     $Tidy = new csstidy();
     $Tidy->load_template($this->_template);
     $Tidy->parse($Media->contents['raw']);
     if ($compressed = $Tidy->print->plain()) {
         $Media->content['raw'] = $compressed;
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 public static function minify($css, $options = array())
 {
     $options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
     set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_DIR . '/CSSTidy');
     require_once 'class.csstidy.php';
     $csstidy = new csstidy();
     foreach ($options as $option => $value) {
         $csstidy->set_cfg($option, $value);
     }
     $csstidy->load_template($options['template']);
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     $css = Minify_CSS_UriRewriter::rewrite($css, $options);
     return $css;
 }
Ejemplo n.º 5
0
 /**
  * @access public
  * @param $source
  * @return string
  */
 public function post_format($source, $scaffold)
 {
     $css = new csstidy();
     $css->set_cfg('case_properties', false);
     $css->set_cfg('lowercase_s', true);
     $css->set_cfg('compress_colors', false);
     $css->set_cfg('compress_font-weight', false);
     $css->set_cfg('merge_selectors', true);
     $css->set_cfg('optimise_shorthands', true);
     $css->set_cfg('remove_bslash', false);
     $css->set_cfg('preserve_css', true);
     $css->set_cfg('sort_selectors', true);
     $css->set_cfg('sort_properties', true);
     $css->set_cfg('remove_last_;', true);
     $css->set_cfg('discard_invalid_properties', true);
     $css->set_cfg('css_level', '2.1');
     $css->set_cfg('timestamp', false);
     $css->load_template('highest_compression');
     $result = $css->parse($source->contents);
     $output = $css->print->plain();
     $source->contents = $output;
 }
Ejemplo n.º 6
0
			</label><br />

          </fieldset>
        <input type="hidden" name="post" />
        </div>
      </div>
    </form>
    <?php 
$file_ok = false;
$result = false;
$url = isset($_REQUEST['url']) && !empty($_REQUEST['url']) ? $_REQUEST['url'] : false;
if (isset($_REQUEST['template'])) {
    switch ($_REQUEST['template']) {
        case 4:
            if ($is_custom) {
                $css->load_template($_REQUEST['custom'], false);
            }
            break;
        case 3:
            $css->load_template('highest_compression');
            break;
        case 2:
            $css->load_template('high_compression');
            break;
        case 0:
            $css->load_template('low_compression');
            break;
    }
}
if ($url) {
    if (substr($_REQUEST['url'], 0, 7) !== 'http://') {
Ejemplo n.º 7
0
error_reporting(0);
switch ($_GET['action']) {
    /**
     * Compress a css file.
     *
     * @param {string} path The path of the file to compress
     * @param {string} advanced Either advanced or standard_compression
     */
    case 'compressCSS':
        if (isset($_GET['path']) && isset($_POST['advanced'])) {
            $path = getWorkspacePath($_GET['path']);
            $css_code = file_get_contents($path);
            $css = new csstidy();
            $css->parse($css_code);
            if ($_POST['compression'] != "standard_compression") {
                $css->load_template($_POST['compression']);
            }
            if ($_POST['advanced']) {
                $css->set_cfg('compress_colors', $_POST['color']);
                $css->set_cfg('compress_font-weight', $_POST['fontw']);
                $css->set_cfg('remove_last_;', $_POST['bslash']);
                $css->set_cfg('remove_bslash', $_POST['last']);
            }
            $code = $css->print->plain();
            $nFile = substr($path, 0, strrpos($path, ".css"));
            $nFile = $nFile . ".min.css";
            file_put_contents($nFile, $code);
            echo '{"status":"success","message":"CSS tidied!"}';
        } else {
            echo '{"status":"error","message":"Missing Parameter!"}';
        }
	/**
	 * Yii-ified version of CSS.php of the Minify packages with fixed options
	 *
	 * @param <type> $css
	 */
	private function minifyCss($css)
	{
		Yii::import('application.extensions.csstidy.*');
		require_once('class.csstidy.php');

		$cssTidy = new csstidy();
		$cssTidy->load_template($this->cssTidyTemplate);

		foreach($this->cssTidyConfig as $k => $v)
			$cssTidy->set_cfg($k, $v);

		$cssTidy->parse($css);
		return $cssTidy->print->plain();
	}
Ejemplo n.º 9
0
// Get scripts from servlet
$json = file_get_contents($getScripts);
$scripts = json_decode($json, true);
//print_r($scripts);
//$css_core = array();
$core_files = array();
$errors = array();
$warnings = array();
$completed = array();
$script_hash = array();
$script_size = array();
$full_script_size = array();
// Load, concat and minify css
foreach ($scripts['css'] as $core_name => $core_group) {
    $cssTidy = new csstidy();
    $cssTidy->load_template('highest_compression');
    $cssTidy->settings['merge_selectors'] = 2;
    $core_files[$core_name] = "";
    $script_hash[$core_name] = getFileHash($pathToCore . "/{$core_name}");
    $script_size[$core_name] = getFileSize($pathToCore . "/{$core_name}");
    $full_script_size[$core_name] = 0;
    foreach ($core_group as $script) {
        $filePath = $pathToRoot . $script;
        if (file_exists($filePath)) {
            /*
            $core_files[$core_name] .= Minify_CSS::minify(file_get_contents($filePath), array(
                'currentDir' => dirname($filePath)
                ));
            */
            //echo "Proccessing: $filePath<br />\n";
            $full_script_size[$core_name] += getFileSize($filePath);
Ejemplo n.º 10
0
#!/usr/bin/php
<?php 
# Uses the CSS Tidy package <http://csstidy.sourceforge.net/index.php>, licensed under the GPL
include dirname(__FILE__) . '/../../SharedSupport/csstidy/class.csstidy.php';
$input = file_get_contents('php://stdin');
# might need to add some options to the css tidy
# class.
$css = new csstidy();
$css->parse($input);
$css->load_template('low_compression');
echo $css->print->plain();
Ejemplo n.º 11
0
header('Content-Type: text/css');
$cache_dir = "/cache/csscache";
if (!file_exists($cache_dir)) {
    $status = @mkdir($cache_dir, 0755);
}
$cssdata = file_get_contents($css_file);
$cssmd5 = md5($cssdata);
$cache_file = $cache_dir . "/" . base64_encode($_SERVER['SERVER_NAME'] . "/" . $css_file);
$data = array();
if (file_exists($cache_file)) {
    $data = unserialize(file_get_contents($cache_file));
}
if (!isset($data['md5']) || $cssmd5 != $data['md5']) {
    require_once 'external/csstidy/class.csstidy.php';
    $css = new csstidy();
    $css->load_template('high_compression');
    $result = $css->parse($cssdata);
    $css->set_cfg('optimise_shorthands', 1);
    $css->set_cfg('merge_selectors', 2);
    $css->set_cfg('compress_colors', true);
    $css->set_cfg('compress_font-weight', true);
    $css->set_cfg('remove_bslash', true);
    $output = $css->print->plain();
    $fp = @fopen($cache_file, 'w');
    $data['md5'] = $cssmd5;
    $data['css'] = $output;
    @fwrite($fp, serialize($data));
    @fclose($fp);
}
if (!isset($data['css'])) {
    $data['css'] = $cssdata;
Ejemplo n.º 12
0
 /**
  * Создает css-компрессор и инициализирует его конфигурацию
  *
  * @return bool
  */
 protected function InitCssCompressor()
 {
     /**
      * Получаем параметры из конфигурации
      */
     $aParams = Config::Get('compress.css');
     $this->oCssCompressor = $aParams['use'] ? new csstidy() : null;
     /**
      * Если компрессор не создан, завершаем работу инициализатора
      */
     if (!$this->oCssCompressor) {
         return false;
     }
     /**
      * Устанавливаем параметры
      */
     $this->oCssCompressor->set_cfg('case_properties', $aParams['case_properties']);
     $this->oCssCompressor->set_cfg('merge_selectors', $aParams['merge_selectors']);
     $this->oCssCompressor->set_cfg('optimise_shorthands', $aParams['optimise_shorthands']);
     $this->oCssCompressor->set_cfg('remove_last_;', $aParams['remove_last_;']);
     $this->oCssCompressor->set_cfg('css_level', $aParams['css_level']);
     $this->oCssCompressor->load_template($aParams['template']);
     return true;
 }
Ejemplo n.º 13
0
<?php
	include('class.csstidy.php');
	
	$css_file = dirname(__FILE__). "/tmp_csstidy_code.css";
	
	$f = fopen($css_file, "r");
	$css_code = fread($f, filesize($css_file));
	fclose($f);



	$css = new csstidy();
	$css->load_template("highest_compression");
	
	$css->set_cfg('remove_last_;',TRUE);

	$css->parse($css_code);

	print $css->print->plain();

?>
Ejemplo n.º 14
0
<?php

require_once 'csstidy/csstidy.class.php';
require_once 'csstidy.config.php';
$config = parse_ini_file("./simpleconfig.ini", true);
$config['csstidy']['vendor_prefix'] = '-moz-';
$csstidy = new csstidy($csstidy_config, $config['csstidy']);
$csstidy->load_template('no_compression');
$file = file_get_contents("./qutim.pure.css");
$csstidy->parse($file);
//var_dump($csstidy);
echo $csstidy->return_plain_output_css();
//print_r($csstidy->get_log());
foreach ($csstidy->get_log() as $l => $m) {
    foreach ($m as $me => $t) {
        echo $t['t'] . ": " . $t['m'] . "\n";
    }
}
$csstidy->get_diff();
Ejemplo n.º 15
0
 function process($type, $data)
 {
     switch ($type) {
         case 'js':
             $path = JS;
             break;
         case 'css':
             $path = CSS;
             break;
     }
     $folder = new Folder();
     //make sure the cache folder exists
     if ($folder->create($path . $this->cachePath, "777")) {
         /* trigger_error('Could not create ' . $path . $this->cachePath
            . '. Please create it manually with 777 permissions', E_USER_WARNING);*/
     }
     //check if the cached file exists
     $names = Set::extract($data, '{n}.name');
     $folder->cd($path . $this->cachePath);
     $fileName = $folder->find($this->__generateFileName($names) . '_([0-9]{10}).' . $type);
     if ($fileName) {
         //take the first file...really should only be one.
         $fileName = $fileName[0];
     }
     //make sure all the pieces that went into the packed script
     //are OLDER then the packed version
     if ($this->checkTS && $fileName) {
         $packed_ts = filemtime($path . $this->cachePath . $fileName);
         $latest_ts = 0;
         $scripts = Set::extract($data, '{n}.script');
         foreach ($scripts as $script) {
             $latest_ts = max($latest_ts, filemtime($path . $script . '.' . $type));
         }
         //an original file is newer.  need to rebuild
         if ($latest_ts > $packed_ts) {
             unlink($path . $this->cachePath . $fileName);
             $fileName = null;
         }
     }
     //file doesn't exist.  create it.
     if (!$fileName) {
         $ts = time();
         //merge the script
         $scriptBuffer = '';
         $scripts = Set::extract($data, '{n}.script');
         foreach ($scripts as $script) {
             $buffer = file_get_contents($path . $script . '.' . $type);
             switch ($type) {
                 case 'js':
                     //jsmin only works with PHP5
                     if (PHP5) {
                         App::import('Vendor', 'jsmin/jsmin');
                         $buffer = trim(JSMin::minify($buffer));
                     }
                     break;
                 case 'css':
                     vendor('csstidy/class.csstidy');
                     $tidy = new csstidy();
                     $tidy->load_template($this->cssCompression);
                     $tidy->parse($buffer);
                     $buffer = $tidy->print->plain();
                     break;
             }
             $scriptBuffer .= "\n/* {$script}.{$type} */\n" . $buffer;
         }
         //write the file
         $fileName = $this->__generateFileName($names) . '_' . $ts . '.' . $type;
         $file = new File($path . $this->cachePath . $fileName);
         $file->write(trim($scriptBuffer));
     }
     if ($type == 'css') {
         //$html->css doesn't check if the file already has
         //the .css extension and adds it automatically, so we need to remove it.
         $fileName = str_replace('.css', '', $fileName);
     }
     return $fileName;
 }
Ejemplo n.º 16
0
 /**
  * Compress the JavaScripts or CSS files
  * 
  * @param string $type Can be js or css
  * @param string $prefix
  * @return Core_View_Helper_Compressor The compressor instance
  */
 public function compressor($type = 'js', $prefix = 'head')
 {
     $type = strtolower($type);
     $this->_type = $type;
     /**
      * Check whether the compression is enable or not
      */
     $config = Pandamp_Config::getConfig();
     $compressCss = isset($config->cache->compress->css) ? (string) $config->cache->compress->css : 'false';
     $compressJs = isset($config->cache->compress->js) ? (string) $config->cache->compress->js : 'false';
     if ($type == 'css' && $compressCss == 'false') {
         $return = $this->view->headLink()->toString() . $this->view->headStyle()->toString();
         return $return;
     } elseif ($type == 'js' && $compressJs == 'false') {
         $return = $this->view->headScript()->toString();
         $this->_resetHeadScript();
         return $return;
     }
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $cacheFile = md5(implode('_', array($prefix, $module, $controller, $action))) . '.' . $type;
     /**
      * Build cache dir and URL to show cache data
      */
     $cacheDir = TEMP_DIR . DS . 'cache' . DS . $type;
     $htaccess = $cacheDir . DS . '.htaccess';
     if (!file_exists($cacheDir)) {
         mkdir($cacheDir);
     }
     /**
      * Create .htaccess file that allows browser to access
      */
     if (!file_exists($htaccess)) {
         if ($fp = fopen($htaccess, 'wb')) {
             fwrite($fp, 'Allow from all');
             fclose($fp);
         }
     }
     $staticUrl = $config->web->static_server;
     $cachePath = $cacheDir . DS . $cacheFile;
     $this->_cacheUrl = $staticUrl . '/temp/cache/' . $type . '/' . $cacheFile;
     $files = array();
     $urls = array();
     $cssStyles = array();
     $jsScripts = array();
     switch ($type) {
         case 'css':
             $iterator = $this->view->headLink()->getIterator();
             foreach ($iterator as $item) {
                 if ($item->type == 'text/css') {
                     $urls[] = $item->href;
                 }
             }
             $styleIterator = $this->view->headStyle()->getIterator();
             foreach ($styleIterator as $item) {
                 $cssStyles[] = $item->content;
             }
             break;
         case 'js':
             $iterator = $this->view->headScript()->getIterator();
             foreach ($iterator as $item) {
                 if ($item->source == null) {
                     $urls[] = $item->attributes['src'];
                 } else {
                     $jsScripts[] = $item->source;
                 }
             }
             $this->_resetHeadScript();
             break;
     }
     if (count($urls) == 0) {
         return '';
     }
     $start = strlen($staticUrl);
     foreach ($urls as $url) {
         if (substr($url, 0, $start) == $staticUrl) {
             $url = substr($url, $start);
             $url = ltrim($url, '/');
             $url = str_replace('/', DS, $url);
             $url = ROOT_DIR . DS . $url;
         }
         $files[] = $url;
     }
     /**
      * Compare the timestamp of the cached file with
      * timestamp of all included file
      */
     $maxTimeStamp = 0;
     foreach ($files as $index => $f) {
         if (file_exists($f)) {
             $maxTimeStamp = max($maxTimeStamp, filemtime($f));
         }
     }
     if (file_exists($cachePath) && $maxTimeStamp > filemtime($cachePath)) {
         unlink($cachePath);
     }
     if (!file_exists($cachePath)) {
         $content = '';
         switch ($type) {
             case 'css':
                 foreach ($files as $index => $f) {
                     $path = pathinfo($f);
                     $url = $urls[$index];
                     $url = substr($url, 0, -strlen($path['basename']));
                     $url = rtrim($url, '/');
                     $str = file_get_contents($f);
                     /**
                      * Replace value of background and background-image properties
                      * with the full URL.
                      * We have to handle some expressions:
                      * - background: #Color_Code url(images/...)
                      * - background-image: url(images/...)
                      * - background: url('images/...')
                      * - jQueryUI theme (/js/jquery.ui/themes/base/ui.theme.css)
                      */
                     $str = preg_replace("/background([-image]*):(\\s*)([#0-9a-zA-Z]*)([\\/\\*\\{a-zA-Z\\}\\*\\/]*)(\\s*)url\\(([']*)images\\/([\\w-.]+)([']*)\\)/", 'background$1: $3 url(' . $url . '/images/$7)', $str);
                     $content .= "\n\n" . trim($str);
                 }
                 foreach ($cssStyles as $style) {
                     $content .= "\n\n" . trim($style);
                 }
                 /**
                  * Use CSSTidy to compress CSS content
                  */
                 require_once 'csstidy/class.csstidy.php';
                 $csstidy = new csstidy();
                 $csstidy->set_cfg('remove_last_;', true);
                 $csstidy->load_template(self::$_CSS_COMPRESS);
                 $csstidy->parse($content);
                 $content = $csstidy->print->plain();
                 break;
             case 'js':
                 require_once 'jsmin/jsmin.php';
                 foreach ($files as $index => $f) {
                     if (file_exists($f)) {
                         $str = file_get_contents($f);
                     } else {
                         $str = file_get_contents($urls[$index]);
                     }
                     $content .= "\n\n" . trim(JSMin::minify($str));
                 }
                 foreach ($jsScripts as $script) {
                     $content .= "\n\n" . trim(JSMin::minify($script));
                 }
                 break;
         }
         if ($fp = fopen($cachePath, 'wb')) {
             fwrite($fp, $content);
             fclose($fp);
         }
     }
     return $this;
 }
Ejemplo n.º 17
0
 protected function csstidy($filescontent = '')
 {
     $css = new csstidy();
     $css->set_cfg('sort_selectors', false);
     $css->set_cfg('sort_properties', false);
     $css->set_cfg('merge_selectors', 0);
     $css->set_cfg('optimise_shorthands', 1);
     $css->set_cfg('compress_colors', true);
     $css->set_cfg('compress_font-weight', true);
     $css->set_cfg('lowercase_s', false);
     $css->set_cfg('case_properties', 1);
     $css->set_cfg('remove_bslash', false);
     $css->set_cfg('remove_last_;', true);
     $css->set_cfg('discard_invalid_properties', false);
     $css->load_template('high_compression');
     $result = $css->parse($filescontent);
     $filescontent = $css->print->plain();
     return $filescontent;
 }
Ejemplo n.º 18
0
 function __process($type, $assets)
 {
     $path = $this->__getPath($type);
     $folder = new Folder($this->paths['wwwRoot'] . $this->cachePaths[$type], true);
     //check if the cached file exists
     $scripts = Set::extract('/script', $assets);
     $fileName = $folder->find($this->__generateFileName($scripts) . '_([0-9]{10}).' . $type);
     if ($fileName) {
         //take the first file...really should only be one.
         $fileName = $fileName[0];
     }
     //make sure all the pieces that went into the packed script
     //are OLDER then the packed version
     if ($this->checkTs && $fileName) {
         $packed_ts = filemtime($this->paths['wwwRoot'] . $this->cachePaths[$type] . DS . $fileName);
         $latest_ts = 0;
         foreach ($assets as $asset) {
             $assetFile = $this->__findFile($asset, $type);
             if (!$assetFile) {
                 continue;
             }
             $latest_ts = max($latest_ts, filemtime($assetFile));
         }
         //an original file is newer. need to rebuild
         if ($latest_ts > $packed_ts) {
             unlink($this->paths['wwwRoot'] . $this->cachePaths[$type] . DS . $fileName);
             $fileName = null;
         }
     }
     //file doesn't exist. create it.
     if (!$fileName) {
         $ts = time();
         switch ($type) {
             case 'js':
                 if (PHP5) {
                     App::import('Vendor', 'jsmin/jsmin');
                 }
                 break;
             case 'css':
                 App::import('Vendor', 'csstidy', array('file' => 'class.csstidy.php'));
                 $tidy = new csstidy();
                 $tidy->load_template($this->cssCompression);
                 break;
         }
         //merge the script
         $scriptBuffer = '';
         foreach ($assets as $asset) {
             $buffer = $this->__getFileContents($asset, $type);
             $origSize = strlen($buffer);
             switch ($type) {
                 case 'js':
                     //jsmin only works with PHP5
                     if (PHP5) {
                         $buffer = trim(JSMin::minify($buffer));
                     }
                     break;
                 case 'css':
                     $tidy->parse($buffer);
                     $buffer = $tidy->print->plain();
                     break;
             }
             $delta = 0;
             if ($origSize > 0) {
                 $delta = strlen($buffer) / $origSize * 100;
             }
             $scriptBuffer .= sprintf("/* %s.%s (%d%%) */\n", $asset['script'], $type, $delta);
             $scriptBuffer .= $buffer . "\n\n";
         }
         //write the file
         $fileName = $this->__generateFileName($scripts) . '_' . $ts . '.' . $type;
         $file = new File($this->paths['wwwRoot'] . $this->cachePaths[$type] . DS . $fileName);
         $file->write(trim($scriptBuffer));
     }
     if ($type == 'css') {
         //$html->css doesn't check if the file already has
         //the .css extension and adds it automatically, so we need to remove it.
         $fileName = str_replace('.css', '', $fileName);
     }
     return $fileName;
 }
Ejemplo n.º 19
0
<?php
	include('class.csstidy.php');
	
	$css_file = dirname(__FILE__). "/tmp_csstidy_code.css";
	
	$f = fopen($css_file, "r");
	$css_code = fread($f, filesize($css_file));
	fclose($f);



	$css = new csstidy();
	$css->load_template("low_compression");
	
	$css->set_cfg('preserve_css', true);
	$css->set_cfg('compress_colors', false);
	$css->set_cfg('sort_properties', true);

	$css->parse($css_code);

	print $css->print->plain();

?>
Ejemplo n.º 20
0
 static function _compressCss($str)
 {
     require_once sysPATH . 'core/lib/3part/csstidy/class.csstidy.php';
     $css = new csstidy();
     $css->set_cfg('remove_last_;', true);
     //$css->set_cfg('preserve_css',true);
     $css->load_template('highest_compression');
     $css->parse($str);
     $str = $css->print->plain();
     /*csstidy fix: ff needs font-face format value in '"' */
     $str = preg_replace('/ format\\("?([^\\")]+)"?\\)/', ' format("$1")', $str);
     return $str;
 }
Ejemplo n.º 21
0
 private function get_css_html($cachefile)
 {
     if (Configure::read('debug') > 0) {
         $ret = "";
         foreach ($this->libs['css'] as $lib) {
             $ret .= $this->Html->css($lib);
         }
         return $ret;
     }
     if (file_exists($this->cachePath['css'] . '/' . $cachefile)) {
         return $this->Html->css($cachefile);
     }
     // Get the content
     $file_content = '';
     foreach ($this->libs['css'] as $lib) {
         $file_content .= "\n\n" . file_get_contents($this->basePath['css'] . '/' . $lib);
     }
     // Get inline code if exist
     if (!empty($this->inline_code['css'])) {
         foreach ($this->inline_code['css'] as $inlineCss) {
             $file_content .= "\n\n" . $inlineCss;
         }
     }
     // If compression is enable, compress it !
     if ($this->__options['css']['enableCompression']) {
         App::import('Vendor', 'csstidy', array('file' => 'class.csstidy.php'));
         $tidy = new csstidy();
         $tidy->load_template($this->__options['css']['compression']);
         $tidy->set_cfg('sort_selectors', FALSE);
         $tidy->set_cfg('sort_properties', FALSE);
         $tidy->parse($file_content);
         $file_content = $tidy->print->plain();
     }
     if ($fp = fopen($this->cachePath['css'] . '/' . $cachefile, 'wb')) {
         fwrite($fp, $file_content);
         fclose($fp);
     }
     return $this->Html->css($cachefile);
 }
Ejemplo n.º 22
0
 /**
  * Returns the compiled an minified version of the css files suplied
  *
  * @param array $assets array of asset files to process
  * @return string the compiled and minified version of the css
  * @access private
  */
 function compileCss($assets)
 {
     App::import('Vendor', 'csstidy', array('file' => 'class.csstidy.php'));
     $tidy = new csstidy();
     $tidy->load_template($this->cssCompression);
     $contents = '';
     foreach ($assets as $asset) {
         $contents .= $this->fixReferences($this->__getFileContents($asset, 'css'), $asset) . "\n";
     }
     $tidy->parse($contents);
     return $tidy->print->plain();
 }