PluginProbe
Autoptimize / 2.2.2
Autoptimize v2.2.2
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 / config / delayed.php

delayed.php in Autoptimize 2.2.2, at config/delayed.php

86 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php exit;
2
3 //Check everything exists before using it
4 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
5 $_SERVER['HTTP_ACCEPT_ENCODING'] = '';
6 if(!isset($_SERVER['HTTP_USER_AGENT']))
7 $_SERVER['HTTP_USER_AGENT'] = '';
8
9 // Determine supported compression method
10 $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
11 $deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');
12
13 // Determine used compression method
14 $encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
15
16 // Check for buggy versions of Internet Explorer
17 if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') &&
18 preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches))
19 {
20 $version = floatval($matches[1]);
21
22 if ($version < 6)
23 $encoding = 'none';
24
25 if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1'))
26 $encoding = 'none';
27 }
28
29 //Some servers compress the output of PHP - Don't break in those cases
30 if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1)
31 $encoding = 'none';
32
33 $iscompressed = file_exists(__FILE__.'.'.$encoding);
34 if($encoding != 'none' && $iscompressed == false)
35 {
36 $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE);
37 $code = file_get_contents(__FILE__.'.none');
38 $contents = gzencode($code,9,$flag);
39 }else{
40 //Get data
41 $contents = file_get_contents(__FILE__.'.'.$encoding);
42 }
43
44 // first check if we have to send 304
45 // inspired by http://www.jonasjohn.de/snippets/php/caching.htm
46
47 $eTag=md5($contents);
48 $modTime=filemtime(__FILE__.'.none');
49
50 $eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'],$eTag));
51 $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime);
52
53 if (($modTimeMatch)||($eTagMatch)) {
54 header('HTTP/1.1 304 Not Modified');
55 header('Connection: close');
56 } else {
57 // send all sorts of headers
58 $expireTime=60*60*24*355; // 1y max according to RFC
59 if ($encoding != 'none') {
60 header('Content-Encoding: '.$encoding);
61 }
62 header('Vary: Accept-Encoding');
63 header('Content-Length: '.strlen($contents));
64 header('Content-type: %%CONTENT%%; charset=utf-8');
65 header('Cache-Control: max-age='.$expireTime.', public, immutable');
66 header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT');
67 header('ETag: ' . $eTag);
68 header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT');
69
70 // send output
71 echo $contents;
72
73 //And write to filesystem cache if not done yet
74 if($encoding != 'none' && $iscompressed == false)
75 {
76 //Write the content we sent
77 file_put_contents(__FILE__.'.'.$encoding,$contents);
78
79 //And write the new content
80 $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP);
81 $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip');
82 $contents = gzencode($code,9,$flag);
83 file_put_contents(__FILE__.'.'.$ext,$contents);
84 }
85 }
86