init
[garradin.git] / include / libs / template_lite / plugins / outputfilter.gzip.php
1 <?php
2 /*
3 * Author: Mark Dickenson, akapanamajack@wildmail.com
4 * You can stack multiple template display commands to have the entire page output as a compressed file.
5 *
6 * This output filter was specifically written to work with Alien Assault Traders but can be used on other projects.
7 *
8 * $send_now = 0 will cache the output and not send the data until $send_now = 1
9 * $_tpl_saved is a reserved variable for storing the cached output
10 * $force_compression = 1 will cause all output to be compressed and ignore what the browser or server indicates to gzip support
11 * $compression_level is the amount of compression to use on the output 0 is the leasat and 9 is maximum
12 * $template_object->enable_gzip = 0 output is not compressed $template_object->enable_gzip = 1 output is compressed
13 */
14
15 function template_outputfilter_gzip($tpl_source, &$template_object)
16 {
17 static $_tpl_saved = '';
18
19 $gzipped = 0;
20 if($template_object->enable_gzip)
21 {
22 if(extension_loaded("zlib") && !get_cfg_var('zlib.output_compression') && !$template_object->cache && (strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip") || $template_object->force_compression))
23 {
24 $_tpl_saved .= $tpl_source . "\n<!-- zlib compression level " . $template_object->compression_level . " -->\n\n";
25 $tpl_source = "";
26
27 if($template_object->send_now == 1)
28 {
29 $gzipped = 1;
30 $tpl_source = gzencode($_tpl_saved, $template_object->compression_level);
31 $_tpl_saved = "";
32 }
33 }
34 }
35 else
36 {
37 if(!$template_object->caching && !get_cfg_var('zlib.output_compression'))
38 {
39 $_tpl_saved .= $tpl_source."\n<!-- normal saved output -->\n\n";
40 $tpl_source = "";
41
42 if($template_object->send_now == 1)
43 {
44 $tpl_source = $_tpl_saved;
45 $_tpl_saved = "";
46 }
47 }
48 }
49
50 if($template_object->send_now == 1 && $template_object->enable_gzip == 1)
51 {
52 if($gzipped == 1)
53 {
54 header("Content-Encoding: gzip");
55 header("Content-Length: " . strlen($tpl_source));
56 }
57 }
58
59 return $tpl_source;
60 }
61 ?>