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.
6 * This output filter was specifically written to work with Alien Assault Traders but can be used on other projects.
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
15 function template_outputfilter_gzip($tpl_source, &$template_object)
17 static $_tpl_saved = '';
20 if($template_object->enable_gzip
)
22 if(extension_loaded("zlib") && !get_cfg_var('zlib.output_compression') && !$template_object->cache
&& (strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip") ||
$template_object->force_compression
))
24 $_tpl_saved .= $tpl_source . "\n<!-- zlib compression level " . $template_object->compression_level
. " -->\n\n";
27 if($template_object->send_now
== 1)
30 $tpl_source = gzencode($_tpl_saved, $template_object->compression_level
);
37 if(!$template_object->caching
&& !get_cfg_var('zlib.output_compression'))
39 $_tpl_saved .= $tpl_source."\n<!-- normal saved output -->\n\n";
42 if($template_object->send_now
== 1)
44 $tpl_source = $_tpl_saved;
50 if($template_object->send_now
== 1 && $template_object->enable_gzip
== 1)
54 header("Content-Encoding: gzip");
55 header("Content-Length: " . strlen($tpl_source));