PluginProbe
Autoptimize / 1.6.5
Autoptimize v1.6.5
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
autoptimize / classes / autoptimizeYUI.php

autoptimizeYUI.php in Autoptimize 1.6.5, at classes/autoptimizeYUI.php

46 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class autoptimizeYUI
4 {
5 static function available()
6 {
7 //If we can run apps
8 if(function_exists('shell_exec') && is_callable('shell_exec'))
9 {
10 //And if YUI is there for us
11 if(file_exists('/usr/bin/java') && file_exists(WP_PLUGIN_DIR.'/autoptimize/yui/yuicompressor.jar'))
12 {
13 //And we have a dir in where to work
14 if(is_writable(WP_PLUGIN_DIR.'/autoptimize/yui/'))
15 {
16 //Then we're available
17 return true;
18 }
19 }
20 }
21 //We can't use YUI :(
22 return false;
23 }
24
25 static function compress($type,$code)
26 {
27 //Check for supported types
28 if(!in_array($type,array('js','css')))
29 return false;
30
31 //Write temp file
32 $file = tempnam(WP_PLUGIN_DIR.'/autoptimize/yui/',$type);
33 file_put_contents($file,$code);
34
35 //Call YUI
36 $yuipath = escapeshellarg(WP_PLUGIN_DIR.'/autoptimize/yui/yuicompressor.jar');
37 $code = shell_exec('/usr/bin/java -jar '.$yuipath.' --type '.$type.' '.escapeshellarg($file));
38
39 //Delete temp file
40 unlink($file);
41
42 //Give the code!
43 return $code;
44 }
45 }
46