19 */ |
19 */ |
20 |
20 |
21 // First check to see if something already declared this function.... it happens often. |
21 // First check to see if something already declared this function.... it happens often. |
22 if ( !function_exists('microtime_float') ) |
22 if ( !function_exists('microtime_float') ) |
23 { |
23 { |
24 function microtime_float() |
24 function microtime_float() |
25 { |
25 { |
26 list($usec, $sec) = explode(" ", microtime()); |
26 list($usec, $sec) = explode(" ", microtime()); |
27 return ((float)$usec + (float)$sec); |
27 return ((float)$usec + (float)$sec); |
28 } |
28 } |
29 } |
29 } |
30 |
30 |
31 $local_start = microtime_float(); |
31 $local_start = microtime_float(); |
32 |
32 |
33 // Setup Enano |
33 // Setup Enano |
41 // using symlinks to reference the original files so as to segregate unique files from non-unique |
41 // using symlinks to reference the original files so as to segregate unique files from non-unique |
42 // and distribution-standard ones. Enano will pivot its root directory accordingly if the file |
42 // and distribution-standard ones. Enano will pivot its root directory accordingly if the file |
43 // .enanodev is found in the Enano root (not /repo/). |
43 // .enanodev is found in the Enano root (not /repo/). |
44 if ( strpos(__FILE__, '/repo/') && ( file_exists('../../.enanodev') || file_exists('../../../.enanodev') ) ) |
44 if ( strpos(__FILE__, '/repo/') && ( file_exists('../../.enanodev') || file_exists('../../../.enanodev') ) ) |
45 { |
45 { |
46 // We have a development directory. Remove /repo/ from the picture. |
46 // We have a development directory. Remove /repo/ from the picture. |
47 $filename = str_replace('/repo/', '/', __FILE__); |
47 $filename = str_replace('/repo/', '/', __FILE__); |
48 } |
48 } |
49 else |
49 else |
50 { |
50 { |
51 // Standard Enano installation |
51 // Standard Enano installation |
52 $filename = __FILE__; |
52 $filename = __FILE__; |
53 } |
53 } |
54 |
54 |
55 // ENANO_ROOT is sometimes defined by plugins like AjIM that need the constant before the Enano API is initialized |
55 // ENANO_ROOT is sometimes defined by plugins like AjIM that need the constant before the Enano API is initialized |
56 if ( !defined('ENANO_ROOT') ) |
56 if ( !defined('ENANO_ROOT') ) |
57 define('ENANO_ROOT', dirname(dirname(dirname($filename)))); |
57 define('ENANO_ROOT', dirname(dirname(dirname($filename)))); |
58 |
58 |
59 chdir(ENANO_ROOT); |
59 chdir(ENANO_ROOT); |
60 |
60 |
61 require('includes/common.php'); |
61 require('includes/common.php'); |
62 if ( !defined('ENANO_CLI') ) |
62 if ( !defined('ENANO_CLI') ) |
63 { |
63 { |
64 die_friendly('Not for web use', '<p>This script is designed to be run from a command-line environment.</p>'); |
64 die_friendly('Not for web use', '<p>This script is designed to be run from a command-line environment.</p>'); |
65 } |
65 } |
66 |
66 |
67 // if ( !getConfig('cdn_path') ) |
67 // if ( !getConfig('cdn_path') ) |
68 // { |
68 // { |
69 // die_semicritical('CDN support not enabled', 'This script is for compressing the Enano Javascript runtimes for CDN use.'); |
69 // die_semicritical('CDN support not enabled', 'This script is for compressing the Enano Javascript runtimes for CDN use.'); |
77 // do we have zip file support? |
77 // do we have zip file support? |
78 $have_zip = false; |
78 $have_zip = false; |
79 $path = ( isset($_SERVER['PATH']) ) ? $_SERVER['PATH'] : false; |
79 $path = ( isset($_SERVER['PATH']) ) ? $_SERVER['PATH'] : false; |
80 if ( !$path ) |
80 if ( !$path ) |
81 { |
81 { |
82 die_semicritical('Can\'t get your PATH', 'Unable to get the PATH environment variable'); |
82 die_semicritical('Can\'t get your PATH', 'Unable to get the PATH environment variable'); |
83 } |
83 } |
84 |
84 |
85 $path = ( strtolower(PHP_OS) === 'win32' ) ? explode(';', $path) : explode(':', $path); |
85 $path = ( strtolower(PHP_OS) === 'win32' ) ? explode(';', $path) : explode(':', $path); |
86 $pathext = ( strtolower(PHP_OS) === 'win32' ) ? '.exe' : ''; |
86 $pathext = ( strtolower(PHP_OS) === 'win32' ) ? '.exe' : ''; |
87 |
87 |
88 foreach ( $path as $dir ) |
88 foreach ( $path as $dir ) |
89 { |
89 { |
90 if ( file_exists("$dir/zip$pathext") ) |
90 if ( file_exists("$dir/zip$pathext") ) |
91 { |
91 { |
92 $have_zip = true; |
92 $have_zip = true; |
93 break; |
93 break; |
94 } |
94 } |
95 } |
95 } |
96 |
96 |
97 if ( !$have_zip ) |
97 if ( !$have_zip ) |
98 { |
98 { |
99 // no zupport zor zipping ziles |
99 // no zupport zor zipping ziles |
100 echo "\x1B[31;1mnot found\x1B[0m\n\x1B[1mPlease install the zip utility using your distribution's package manager\nand then rerun this script.\x1B[0m"; |
100 echo "\x1B[31;1mnot found\x1B[0m\n\x1B[1mPlease install the zip utility using your distribution's package manager\nand then rerun this script.\x1B[0m"; |
101 exit(1); |
101 exit(1); |
102 } |
102 } |
103 |
103 |
104 echo "\x1B[1mall good\x1B[0m\n"; |
104 echo "\x1B[1mall good\x1B[0m\n"; |
105 echo "\x1B[0;33mMinifying Javascript files..."; |
105 echo "\x1B[0;33mMinifying Javascript files..."; |
106 |
106 |
107 if ( !@mkdir('includes/clientside/staticmin') ) |
107 if ( !@mkdir('includes/clientside/staticmin') ) |
108 { |
108 { |
109 echo "\x1B[31;1mcouldn't create temp directory\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create includes/clientside/staticmin.\x1B[0m"; |
109 echo "\x1B[31;1mcouldn't create temp directory\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create includes/clientside/staticmin.\x1B[0m"; |
110 exit(1); |
110 exit(1); |
111 } |
111 } |
112 |
112 |
113 require('includes/clientside/jsres.php'); |
113 require('includes/clientside/jsres.php'); |
114 |
114 |
115 // $everything now contains the core runtimes |
115 // $everything now contains the core runtimes |
118 |
118 |
119 chdir('includes/clientside/staticmin'); |
119 chdir('includes/clientside/staticmin'); |
120 $handle = @fopen('./enano-lib-basic.js', 'w'); |
120 $handle = @fopen('./enano-lib-basic.js', 'w'); |
121 if ( !$handle ) |
121 if ( !$handle ) |
122 { |
122 { |
123 echo "\x1B[31;1mcouldn't open file\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create a file inside includes/clientside/staticmin.\x1B[0m"; |
123 echo "\x1B[31;1mcouldn't open file\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create a file inside includes/clientside/staticmin.\x1B[0m"; |
124 exit(1); |
124 exit(1); |
125 } |
125 } |
126 |
126 |
127 fwrite($handle, $everything); |
127 fwrite($handle, $everything); |
128 fclose($handle); |
128 fclose($handle); |
129 |
129 |
130 // for each JS file in includes/clientside/static, compress & write |
130 // for each JS file in includes/clientside/static, compress & write |
131 if ( $dr = @opendir('../static') ) |
131 if ( $dr = @opendir('../static') ) |
132 { |
132 { |
133 while ( $dh = @readdir($dr) ) |
133 while ( $dh = @readdir($dr) ) |
134 { |
134 { |
135 if ( !preg_match('/\.js$/', $dh) || $dh === 'enano-lib-basic.js' ) |
135 if ( !preg_match('/\.js$/', $dh) || $dh === 'enano-lib-basic.js' ) |
136 continue; |
136 continue; |
137 |
137 |
138 $contents = @file_get_contents("../static/$dh"); |
138 $contents = @file_get_contents("../static/$dh"); |
139 $compressed = jsres_cache_check($dh, $contents); |
139 $compressed = jsres_cache_check($dh, $contents); |
140 $compressed = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $compressed); |
140 $compressed = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $compressed); |
141 |
141 |
142 $handle = @fopen("./$dh", 'w'); |
142 $handle = @fopen("./$dh", 'w'); |
143 if ( !$handle ) |
143 if ( !$handle ) |
144 { |
144 { |
145 echo "\x1B[31;1mcouldn't open file\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create a file inside includes/clientside/staticmin.\x1B[0m"; |
145 echo "\x1B[31;1mcouldn't open file\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create a file inside includes/clientside/staticmin.\x1B[0m"; |
146 exit(1); |
146 exit(1); |
147 } |
147 } |
148 fwrite($handle, $compressed); |
148 fwrite($handle, $compressed); |
149 fclose($handle); |
149 fclose($handle); |
150 } |
150 } |
151 } |
151 } |
152 else |
152 else |
153 { |
153 { |
154 echo "\x1B[31;1mcouldn't open includes directory\x1B[0m\n\x1B[1mUnable to get our hands into includes/clientside/static/ to compress everything.\x1B[0m"; |
154 echo "\x1B[31;1mcouldn't open includes directory\x1B[0m\n\x1B[1mUnable to get our hands into includes/clientside/static/ to compress everything.\x1B[0m"; |
155 exit(1); |
155 exit(1); |
156 } |
156 } |
157 |
157 |
158 echo "\x1B[1mdone\x1B[0m\n"; |
158 echo "\x1B[1mdone\x1B[0m\n"; |
159 echo "\x1B[0;33mCompressing into enano-lib.zip..."; |
159 echo "\x1B[0;33mCompressing into enano-lib.zip..."; |
160 |
160 |
161 $result = system('zip -yrq9 ../enano-lib.zip *.js'); |
161 $result = system('zip -yrq9 ../enano-lib.zip *.js'); |
162 if ( $result != 0 ) |
162 if ( $result != 0 ) |
163 { |
163 { |
164 // failure |
164 // failure |
165 echo "\x1B[31;1mzip creation failed\x1B[0m\n\x1B[1mzip returned result $result\x1B[0m"; |
165 echo "\x1B[31;1mzip creation failed\x1B[0m\n\x1B[1mzip returned result $result\x1B[0m"; |
166 exit(1); |
166 exit(1); |
167 } |
167 } |
168 |
168 |
169 echo "\x1B[1mdone\x1B[0m\n"; |
169 echo "\x1B[1mdone\x1B[0m\n"; |
170 |
170 |
171 // done, clean up |
171 // done, clean up |
173 echo "\x1B[0;33mCleaning up..."; |
173 echo "\x1B[0;33mCleaning up..."; |
174 chdir('..'); |
174 chdir('..'); |
175 |
175 |
176 if ( $dr = @opendir('./staticmin') ) |
176 if ( $dr = @opendir('./staticmin') ) |
177 { |
177 { |
178 while ( $dh = @readdir($dr) ) |
178 while ( $dh = @readdir($dr) ) |
179 { |
179 { |
180 if ( preg_match('/\.js$/', $dh) ) |
180 if ( preg_match('/\.js$/', $dh) ) |
181 unlink("./staticmin/$dh"); |
181 unlink("./staticmin/$dh"); |
182 } |
182 } |
183 } |
183 } |
184 |
184 |
185 @rmdir('./staticmin'); |
185 @rmdir('./staticmin'); |
186 |
186 |
187 echo "\x1B[1mdone\x1B[0m\n"; |
187 echo "\x1B[1mdone\x1B[0m\n"; |