00001 <?php
00002 Load::commands('jcssmanager/base/compress.base');
00003
00004 class JCSSManagerCompressBaseYuiCommand extends JCSSManagerCompressBaseCommand {
00005
00006
00007
00008
00009
00010 protected function compress($in_files, $out_file, &$files_to_unlink) {
00011 $ret = new Status();
00012 if (count($in_files) > 0) {
00013 $sourcefile = $this->concat($in_files, $ret);
00014 $files_to_unlink[] = $sourcefile;
00015
00016 $ret->merge($this->invoke_yui($sourcefile, $out_file));
00017 }
00018
00019 return $ret;
00020 }
00021
00022
00023
00024
00025
00026
00027
00028
00029 protected function concat($arr_files, Status $err) {
00030 $tmp_file = tempnam('/tmp', 'jcss');
00031 if ($tmp_file === false) {
00032 $err->merge('JCSSManager: Could not create tempfile');
00033 }
00034 else {
00035 $handle = fopen($tmp_file, 'w');
00036 foreach($arr_files as $file) {
00037 if (substr($file, 0, 1) !== '/') {
00038 $file = Config::get_value(Config::URL_ABSPATH) . $file;
00039 }
00040 fwrite($handle, $this->get_file_contents($file));
00041 }
00042 fclose($handle);
00043 }
00044 return $tmp_file;
00045 }
00046
00047
00048
00049
00050
00051
00052
00053 protected function get_file_contents($file) {
00054 return file_get_contents($file);
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 protected function invoke_yui($in_file, $out_file) {
00065 $ret = new Status();
00066 return $ret;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 protected function run_yui($in_file, $out_file, $type) {
00078 $module_dir = Load::get_module_dir('jcssmanager');
00079 $yui_cmd = 'java -jar ' . $module_dir . '3rdparty/yuicompressor/yuicompressor.jar';
00080
00081 $yui_options = array();
00082 $yui_options['--type'] = $type;
00083 $yui_options['--charset'] = GyroLocale::get_charset();
00084 $yui_options['--line-break'] = 1000;
00085 $yui_options['-o'] = $out_file;
00086
00087 $yui_cmd = $yui_cmd . ' ' . Arr::implode(' ', $yui_options, ' ') . ' ' . $in_file;
00088
00089 $output = array();
00090 $return = 0;
00091 exec($yui_cmd, $output, $return);
00092
00093 $ret = new Status();
00094 if ($return) {
00095 $ret->append('JCSSManager: Error running yuicompressor.');
00096 $ret->append(implode(' ', $output));
00097 }
00098
00099 return $ret;
00100 }
00101 }