@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php exit; |
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
4 | +if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
6 | +if (!isset($_SERVER['HTTP_USER_AGENT'])) |
|
7 | 7 | $_SERVER['HTTP_USER_AGENT'] = ''; |
8 | 8 | |
9 | 9 | // Determine supported compression method |
@@ -27,27 +27,27 @@ discard block |
||
27 | 27 | } |
28 | 28 | |
29 | 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) |
|
30 | +if (ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
31 | 31 | $encoding = 'none'; |
32 | 32 | |
33 | 33 | //Get data |
34 | 34 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
35 | 35 | |
36 | 36 | // first check if we have to send 304 |
37 | -$eTag=md5($contents); |
|
38 | -$modTime=filemtime(__FILE__.'.none'); |
|
37 | +$eTag = md5($contents); |
|
38 | +$modTime = filemtime(__FILE__.'.none'); |
|
39 | 39 | |
40 | -$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'],$eTag)); |
|
40 | +$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $eTag)); |
|
41 | 41 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
42 | 42 | |
43 | -if (($modTimeMatch)||($eTagMatch)) { |
|
43 | +if (($modTimeMatch) || ($eTagMatch)) { |
|
44 | 44 | header('HTTP/1.1 304 Not Modified'); |
45 | 45 | header('Connection: close'); |
46 | 46 | } else { |
47 | 47 | // send all sorts of headers |
48 | - $expireTime=60*60*24*356; // 1y max according to RFC |
|
48 | + $expireTime = 60*60*24*356; // 1y max according to RFC |
|
49 | 49 | |
50 | - if(isset($encoding) && $encoding != 'none') |
|
50 | + if (isset($encoding) && $encoding != 'none') |
|
51 | 51 | { |
52 | 52 | header('Content-Encoding: '.$encoding); |
53 | 53 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | header('Content-type: %%CONTENT%%; charset=utf-8'); |
57 | 57 | header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
58 | 58 | header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); //10 years |
59 | - header('ETag: ' . $eTag); |
|
59 | + header('ETag: '.$eTag); |
|
60 | 60 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
61 | 61 | |
62 | 62 | // send output |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php exit; |
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
4 | +if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
6 | +if (!isset($_SERVER['HTTP_USER_AGENT'])) |
|
7 | 7 | $_SERVER['HTTP_USER_AGENT'] = ''; |
8 | 8 | |
9 | 9 | // Determine supported compression method |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | } |
28 | 28 | |
29 | 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) |
|
30 | +if (ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
31 | 31 | $encoding = 'none'; |
32 | 32 | |
33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | -if($encoding != 'none' && $iscompressed == false) |
|
34 | +if ($encoding != 'none' && $iscompressed == false) |
|
35 | 35 | { |
36 | 36 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
37 | 37 | $code = file_get_contents(__FILE__.'.none'); |
38 | - $contents = gzencode($code,9,$flag); |
|
39 | -}else{ |
|
38 | + $contents = gzencode($code, 9, $flag); |
|
39 | +} else { |
|
40 | 40 | //Get data |
41 | 41 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
42 | 42 | } |
@@ -44,18 +44,18 @@ discard block |
||
44 | 44 | // first check if we have to send 304 |
45 | 45 | // inspired by http://www.jonasjohn.de/snippets/php/caching.htm |
46 | 46 | |
47 | -$eTag=md5($contents); |
|
48 | -$modTime=filemtime(__FILE__.'.none'); |
|
47 | +$eTag = md5($contents); |
|
48 | +$modTime = filemtime(__FILE__.'.none'); |
|
49 | 49 | |
50 | -$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'],$eTag)); |
|
50 | +$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $eTag)); |
|
51 | 51 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
52 | 52 | |
53 | -if (($modTimeMatch)||($eTagMatch)) { |
|
53 | +if (($modTimeMatch) || ($eTagMatch)) { |
|
54 | 54 | header('HTTP/1.1 304 Not Modified'); |
55 | 55 | header('Connection: close'); |
56 | 56 | } else { |
57 | 57 | // send all sorts of headers |
58 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
58 | + $expireTime = 60*60*24*355; // 1y max according to RFC |
|
59 | 59 | if ($encoding != 'none') { |
60 | 60 | header('Content-Encoding: '.$encoding); |
61 | 61 | } |
@@ -64,22 +64,22 @@ discard block |
||
64 | 64 | header('Content-type: %%CONTENT%%; charset=utf-8'); |
65 | 65 | header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
66 | 66 | header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
67 | - header('ETag: ' . $eTag); |
|
67 | + header('ETag: '.$eTag); |
|
68 | 68 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
69 | 69 | |
70 | 70 | // send output |
71 | 71 | echo $contents; |
72 | 72 | |
73 | 73 | //And write to filesystem cache if not done yet |
74 | - if($encoding != 'none' && $iscompressed == false) |
|
74 | + if ($encoding != 'none' && $iscompressed == false) |
|
75 | 75 | { |
76 | 76 | //Write the content we sent |
77 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
77 | + file_put_contents(__FILE__.'.'.$encoding, $contents); |
|
78 | 78 | |
79 | 79 | //And write the new content |
80 | 80 | $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
81 | 81 | $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
82 | - $contents = gzencode($code,9,$flag); |
|
83 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
82 | + $contents = gzencode($code, 9, $flag); |
|
83 | + file_put_contents(__FILE__.'.'.$ext, $contents); |
|
84 | 84 | } |
85 | 85 | } |