}
return $value;
+}
+
+/**
+ * This method tries to enable output compression if possible.
+ * This function must be called before any output or headers.
+ *
+ * (IE6 is not supported at all.)
+ *
+ * @return boolean, true if compression enabled
+ */
+function min_enable_zlib_compression() {
+
+ if (headers_sent()) {
+ return false;
+ }
+
+ // zlib.output_compression is preferred over ob_gzhandler()
+ if (!empty($_SERVER['HTTP_USER_AGENT'])) {
+ $agent = $_SERVER['HTTP_USER_AGENT'];
+ // try to detect IE6 and prevent gzip because it is extremely buggy browser
+ $parts = explode(';', $agent);
+ if (isset($parts[1])) {
+ $parts = explode(' ', trim($parts[1]));
+ if (count($parts) > 1) {
+ if ($parts[0] === 'MSIE' and (float)$string[1] < 7) {
+ @ini_set('zlib.output_compression', '0');
+ return false;
+ }
+ }
+ }
+ }
+
+ @ini_set('output_handler', '');
+ @ini_set('zlib.output_compression', 'on');
+
+ return true;
}
\ No newline at end of file
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($imagepath));
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
+ // no need to gzip already compressed images ;-)
+
readfile($imagepath);
die;
}
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($imagepath));
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
readfile($imagepath);
die;
}
header('Pragma: ');
header('Accept-Ranges: none');
header('Content-Type: application/x-javascript');
- header('Content-Length: '.filesize($jspath));
+ if (!min_enable_zlib_compression()) {
+ header('Content-Length: '.filesize($jspath));
+ }
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
readfile($jspath);
die;
}
header('Content-Type: application/x-javascript');
header('Content-Length: '.strlen($js));
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
echo $js;
die;
}
header('Pragma: ');
header('Accept-Ranges: none');
header('Content-Type: text/css');
- header('Content-Length: '.strlen($css));
+ if (!min_enable_zlib_compression()) {
+ header('Content-Length: '.strlen($css));
+ }
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
echo $css;
die;
}
header('Pragma: ');
header('Accept-Ranges: none');
header('Content-Type: text/css');
- header('Content-Length: '.filesize($csspath));
+ if (!min_enable_zlib_compression()) {
+ header('Content-Length: '.filesize($csspath));
+ }
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
readfile($csspath);
die;
}
css_not_found();
}
+// no gzip compression when debugging
+
$candidatesheet = "$CFG->dataroot/cache/theme/$themename/designer.ser";
if (!file_exists($candidatesheet)) {
header('Pragma: ');
header('Accept-Ranges: none');
header('Content-Type: text/css');
- header('Content-Length: '.strlen($css));
+ //header('Content-Length: '.strlen($css));
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
echo($css);
die;
}
header('Cache-Control: max-age=315360000');
header('Accept-Ranges: none');
header('Content-Type: '.$mimetype);
- header('Content-Length: '.strlen($content));
+ if (!min_enable_zlib_compression()) {
+ header('Content-Length: '.strlen($content));
+ }
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
echo $content;
die;
}
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($imagepath));
- while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
+ // no need to gzip already compressed images ;-)
+
readfile($imagepath);
die;
}