|
|
|
@ -1,16 +1,15 @@ |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
abstract class OC_Minimizer { |
|
|
|
|
public function getLastModified($files) { |
|
|
|
|
$last_modified = 0; |
|
|
|
|
public function generateETag($files) { |
|
|
|
|
$etag = ''; |
|
|
|
|
sort($files); |
|
|
|
|
foreach($files as $file_info) { |
|
|
|
|
$file = $file_info[0] . '/' . $file_info[2]; |
|
|
|
|
$filemtime = filemtime($file); |
|
|
|
|
if ($filemtime > $last_modified) { |
|
|
|
|
$last_modified = $filemtime; |
|
|
|
|
} |
|
|
|
|
$stat = stat($file); |
|
|
|
|
$etag .= $file.$stat['mtime'].$stat['size']; |
|
|
|
|
} |
|
|
|
|
return $last_modified; |
|
|
|
|
return md5($etag); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
abstract public function minimizeFiles($files); |
|
|
|
@ -18,23 +17,21 @@ abstract class OC_Minimizer { |
|
|
|
|
public function output($files, $cache_key) { |
|
|
|
|
header('Content-Type: '.$this->contentType); |
|
|
|
|
OC_Response::enableCaching(); |
|
|
|
|
$last_modified = $this->getLastModified($files); |
|
|
|
|
OC_Response::setLastModifiedHeader($last_modified); |
|
|
|
|
$etag = $this->generateETag($files); |
|
|
|
|
$cache_key .= '-'.$etag; |
|
|
|
|
|
|
|
|
|
$gzout = false; |
|
|
|
|
$cache = OC_Cache::getGlobalCache(); |
|
|
|
|
if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)){ |
|
|
|
|
OC_Response::setETagHeader($etag); |
|
|
|
|
$gzout = $cache->get($cache_key.'.gz'); |
|
|
|
|
if ($gzout) { |
|
|
|
|
OC_Response::setETagHeader(md5($gzout)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!$gzout) { |
|
|
|
|
$out = $this->minimizeFiles($files); |
|
|
|
|
$gzout = gzencode($out); |
|
|
|
|
OC_Response::setETagHeader(md5($gzout)); |
|
|
|
|
$cache->set($cache_key.'.gz', $gzout); |
|
|
|
|
OC_Response::setETagHeader($etag); |
|
|
|
|
} |
|
|
|
|
if ($encoding = OC_Request::acceptGZip()) { |
|
|
|
|
header('Content-Encoding: '.$encoding); |
|
|
|
@ -48,8 +45,8 @@ abstract class OC_Minimizer { |
|
|
|
|
|
|
|
|
|
public function clearCache() { |
|
|
|
|
$cache = OC_Cache::getGlobalCache(); |
|
|
|
|
$cache->delete('core.css.gz'); |
|
|
|
|
$cache->delete('core.js.gz'); |
|
|
|
|
$cache->clear('core.css'); |
|
|
|
|
$cache->clear('core.js'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|