contributions/jcssmanager/behaviour/commands/jcssmanager/csstidy/compress.css.cmd.php
Go to the documentation of this file.00001 <?php 00002 Load::commands('jcssmanager/yui/compress.base'); 00003 00004 class JCSSManagerCompressCSSCsstidyCommand extends JCSSManagerCompressBaseCommand { 00005 protected $type; 00006 00007 /** 00008 * COnstructor 00009 * 00010 * @param $in_files array 00011 * @param $out_file string 00012 * @return void 00013 */ 00014 public function __construct($in_files, $out_file, $type) { 00015 $this->type = $type; 00016 parent::__construct($in_files, $out_file); 00017 } 00018 00019 /** 00020 * COmpress given files 00021 * 00022 * @return Status 00023 */ 00024 protected function compress($in_files, $out_file, &$files_to_unlink) { 00025 $ret = new Status(); 00026 if (count($in_files) > 0) { 00027 $ret->merge($this->run_csstidy(JCSSManager::concat_css_files($in_files), $out_file)); 00028 } 00029 00030 return $ret; 00031 } 00032 00033 /** 00034 * Returns type of compressed file 00035 * 00036 * @return string One of TYPE_X constants 00037 */ 00038 protected function get_db_type() { 00039 return $this->type; 00040 } 00041 00042 /** 00043 * Invoke CSS Tidy 00044 * 00045 * @param strnig $css 00046 * @param string $out_file 00047 * @return Status 00048 */ 00049 protected function run_csstidy($css, $out_file) { 00050 $ret = new Status(); 00051 00052 $old_lang = GyroLocale::set_locale('C'); 00053 $module_dir = Load::get_module_dir('jcssmanager'); 00054 require_once $module_dir . '3rdparty/csstidy/class.csstidy.php'; 00055 00056 $tidy = new csstidy(); 00057 $tidy->set_cfg('remove_last_;',TRUE); 00058 //$tidy->set_cfg('merge_selectors', 0); 00059 $tidy->load_template('highest_compression'); 00060 $tidy->parse($css); 00061 00062 if (file_put_contents($out_file, $tidy->print->plain()) === false) { 00063 $ret->append('CSS Tidy: Could not write output file ' . $out_file); 00064 } 00065 GyroLocale::set_locale($old_lang); 00066 return $ret; 00067 } 00068 }