130 $apex = filemtime('includes/clientside/static/enano-lib-basic.js'); |
132 $apex = filemtime('includes/clientside/static/enano-lib-basic.js'); |
131 |
133 |
132 $before_includes = substr($file, 0, $pos_start_includes); |
134 $before_includes = substr($file, 0, $pos_start_includes); |
133 $after_includes = substr($file, $pos_end_includes); |
135 $after_includes = substr($file, $pos_end_includes); |
134 |
136 |
135 $everything .= $before_includes; |
137 // compress enano-lib-basic |
136 $everything .= $after_includes; |
138 $libbasic = "$before_includes\n$after_includes"; |
|
139 $libbasic = jsres_cache_check('enano-lib-basic.js', $libbasic); |
|
140 $everything .= $libbasic; |
|
141 |
|
142 // $everything .= $before_includes; |
|
143 // $everything .= $after_includes; |
137 |
144 |
138 foreach ( $file_list as $js_file ) |
145 foreach ( $file_list as $js_file ) |
139 { |
146 { |
140 $file_contents = file_get_contents("includes/clientside/static/$js_file"); |
147 $file_contents = file_get_contents("includes/clientside/static/$js_file"); |
141 $file_md5 = md5($file_contents); |
|
142 $time = filemtime("includes/clientside/static/$js_file"); |
148 $time = filemtime("includes/clientside/static/$js_file"); |
143 if ( $time > $apex ) |
149 if ( $time > $apex ) |
144 $apex = $time; |
150 $apex = $time; |
|
151 |
|
152 $file_contents = jsres_cache_check($js_file, $file_contents); |
|
153 |
|
154 $everything .= "\n\n// $js_file\n"; |
|
155 $everything .= "\n" . $file_contents; |
|
156 } |
|
157 |
|
158 // generate ETag |
|
159 $etag = base64_encode(hexdecode(sha1($everything))); |
|
160 |
|
161 if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) ) |
|
162 { |
|
163 if ( "\"$etag\"" == $_SERVER['HTTP_IF_NONE_MATCH'] ) |
|
164 { |
|
165 header('HTTP/1.1 304 Not Modified'); |
|
166 exit(); |
|
167 } |
|
168 } |
|
169 |
|
170 $everything = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $everything); |
|
171 |
|
172 $date = date('r', $apex); |
|
173 header("Date: $date"); |
|
174 header("Last-Modified: $date"); |
|
175 header("ETag: \"$etag\""); |
|
176 |
|
177 echo $everything; |
|
178 |
|
179 if ( $do_gzip ) |
|
180 { |
|
181 gzip_output(); |
|
182 } |
|
183 |
|
184 /** |
|
185 * Check the cache for the given JS file and return the best-compressed version. |
|
186 * @param string Javascript file (acl.js) |
|
187 * @param string Default/current contents |
|
188 * @return string |
|
189 */ |
|
190 |
|
191 function jsres_cache_check($js_file, $file_contents) |
|
192 { |
|
193 global $full_compress_safe, $compress_unsafe; |
|
194 |
|
195 $file_md5 = md5($file_contents); |
|
196 |
145 // Is this file cached? |
197 // Is this file cached? |
146 $cache_path = ENANO_ROOT . "/cache/jsres_$js_file.json"; |
198 $cache_path = ENANO_ROOT . "/cache/jsres_$js_file.json"; |
147 $loaded_cache = false; |
199 $loaded_cache = false; |
148 |
200 |
149 if ( file_exists($cache_path) ) |
201 if ( file_exists($cache_path) ) |
184 fwrite($handle, $payload); |
236 fwrite($handle, $payload); |
185 fclose($handle); |
237 fclose($handle); |
186 } |
238 } |
187 } |
239 } |
188 |
240 |
189 $everything .= "\n // $js_file\n"; |
241 return $file_contents; |
190 $everything .= "\n" . $file_contents; |
242 } |
191 } |
243 |
192 |
|
193 // generate ETag |
|
194 $etag = base64_encode(hexdecode(sha1($everything))); |
|
195 |
|
196 if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) ) |
|
197 { |
|
198 if ( "\"$etag\"" == $_SERVER['HTTP_IF_NONE_MATCH'] ) |
|
199 { |
|
200 header('HTTP/1.1 304 Not Modified'); |
|
201 exit(); |
|
202 } |
|
203 } |
|
204 |
|
205 $date = date('r', $apex); |
|
206 header("Date: $date"); |
|
207 header("Last-Modified: $date"); |
|
208 header("ETag: \"$etag\""); |
|
209 |
|
210 echo $everything; |
|
211 |
|
212 if ( $do_gzip ) |
|
213 { |
|
214 gzip_output(); |
|
215 } |
|
216 |
|