3
abstract class OC_Minimizer {
4
public function generateETag($files) {
5
$fullpath_files = array();
6
foreach($files as $file_info) {
7
$fullpath_files[] = $file_info[0] . '/' . $file_info[2];
9
return OC_Cache::generateCacheKeyFromFiles($fullpath_files);
12
abstract public function minimizeFiles($files);
14
public function output($files, $cache_key) {
15
header('Content-Type: '.$this->contentType);
16
OC_Response::enableCaching();
17
$etag = $this->generateETag($files);
18
$cache_key .= '-'.$etag;
21
$cache = OC_Cache::getGlobalCache();
22
if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)) {
23
OC_Response::setETagHeader($etag);
24
$gzout = $cache->get($cache_key.'.gz');
28
$out = $this->minimizeFiles($files);
29
$gzout = gzencode($out);
30
$cache->set($cache_key.'.gz', $gzout);
31
OC_Response::setETagHeader($etag);
33
// on some systems (e.g. SLES 11, but not Ubuntu) mod_deflate and zlib compression will compress the output twice.
34
// This results in broken core.css and core.js. To avoid it, we switch off zlib compression.
35
// Since mod_deflate is still active, Apache will compress what needs to be compressed, i.e. no disadvantage.
36
if(function_exists('apache_get_modules') && ini_get('zlib.output_compression') && in_array('mod_deflate', apache_get_modules())) {
37
ini_set('zlib.output_compression', 'Off');
39
if ($encoding = OC_Request::acceptGZip()) {
40
header('Content-Encoding: '.$encoding);
43
$out = gzdecode($gzout);
45
header('Content-Length: '.strlen($out));
49
public function clearCache() {
50
$cache = OC_Cache::getGlobalCache();
51
$cache->clear('core.css');
52
$cache->clear('core.js');
56
if (!function_exists('gzdecode')) {
57
function gzdecode($data, $maxlength=null, &$filename='', &$error='')
59
if (strcmp(substr($data, 0, 9),"\x1f\x8b\x8\0\0\0\0\0\0")) {
60
return null; // Not the GZIP format we expect (See RFC 1952)
62
return gzinflate(substr($data, 10, -8));