streamline zlib checking #1410
Instead of having various function_exists checks all over the place, this introduces the constants DOKU_HAS_GZIP and DOKU_HAS_BZIP. All non-3rdparty parts of the code using gz* functions should now check if zlib is actually available.
This commit is contained in:
parent
4a0b76690b
commit
13c3790029
|
@ -197,6 +197,8 @@ function http_rangeRequest($fh,$size,$mime){
|
|||
* @return bool
|
||||
*/
|
||||
function http_gzip_valid($uncompressed_file) {
|
||||
if(!DOKU_HAS_GZIP) return false;
|
||||
|
||||
$gzip = $uncompressed_file.'.gz';
|
||||
if (filemtime($gzip) < filemtime($uncompressed_file)) { // filemtime returns false (0) if file doesn't exist
|
||||
return copy($uncompressed_file, 'compress.zlib://'.$gzip);
|
||||
|
@ -252,10 +254,10 @@ function http_cached_finish($file, $content) {
|
|||
|
||||
// save cache file
|
||||
io_saveFile($file, $content);
|
||||
if(function_exists('gzopen')) io_saveFile("$file.gz",$content);
|
||||
if(DOKU_HAS_GZIP) io_saveFile("$file.gz",$content);
|
||||
|
||||
// finally send output
|
||||
if ($conf['gzip_output'] && function_exists('gzencode')) {
|
||||
if ($conf['gzip_output'] && DOKU_HAS_GZIP) {
|
||||
header('Vary: Accept-Encoding');
|
||||
header('Content-Encoding: gzip');
|
||||
print gzencode($content,9,FORCE_GZIP);
|
||||
|
|
|
@ -195,10 +195,12 @@ require_once(DOKU_INC.'vendor/autoload.php');
|
|||
require_once(DOKU_INC.'inc/load.php');
|
||||
|
||||
// disable gzip if not available
|
||||
if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
|
||||
define('DOKU_HAS_BZIP', function_exists('bzopen'));
|
||||
define('DOKU_HAS_GZIP', function_exists('gzopen'));
|
||||
if($conf['compression'] == 'bz2' && !DOKU_HAS_BZIP) {
|
||||
$conf['compression'] = 'gz';
|
||||
}
|
||||
if($conf['compression'] == 'gz' && !function_exists('gzopen')){
|
||||
if($conf['compression'] == 'gz' && !DOKU_HAS_GZIP) {
|
||||
$conf['compression'] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,9 +107,11 @@ function io_readFile($file,$clean=true){
|
|||
$ret = '';
|
||||
if(file_exists($file)){
|
||||
if(substr($file,-3) == '.gz'){
|
||||
if(!DOKU_HAS_GZIP) return false;
|
||||
$ret = gzfile($file);
|
||||
if(is_array($ret)) $ret = join('', $ret);
|
||||
}else if(substr($file,-4) == '.bz2'){
|
||||
if(!DOKU_HAS_BZIP) return false;
|
||||
$ret = bzfile($file);
|
||||
}else{
|
||||
$ret = file_get_contents($file);
|
||||
|
@ -222,11 +224,13 @@ function _io_saveFile($file, $content, $append) {
|
|||
$fileexists = file_exists($file);
|
||||
|
||||
if(substr($file,-3) == '.gz'){
|
||||
if(!DOKU_HAS_GZIP) return false;
|
||||
$fh = @gzopen($file,$mode.'9');
|
||||
if(!$fh) return false;
|
||||
gzwrite($fh, $content);
|
||||
gzclose($fh);
|
||||
}else if(substr($file,-4) == '.bz2'){
|
||||
if(!DOKU_HAS_BZIP) return false;
|
||||
if($append) {
|
||||
$bzcontent = bzfile($file);
|
||||
if($bzcontent === false) return false;
|
||||
|
@ -313,8 +317,10 @@ function io_replaceInFile($file, $oldline, $newline, $regex=false, $maxlines=0)
|
|||
|
||||
// load into array
|
||||
if(substr($file,-3) == '.gz'){
|
||||
if(!DOKU_HAS_GZIP) return false;
|
||||
$lines = gzfile($file);
|
||||
}else if(substr($file,-4) == '.bz2'){
|
||||
if(!DOKU_HAS_BZIP) return false;
|
||||
$lines = bzfile($file, true);
|
||||
}else{
|
||||
$lines = file($file);
|
||||
|
|
Loading…
Reference in New Issue