Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Commit

Permalink
v 0.9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Furniel committed Dec 24, 2017
1 parent 96a0963 commit 56f1c45
Show file tree
Hide file tree
Showing 221 changed files with 9,203 additions and 5,055 deletions.
32 changes: 17 additions & 15 deletions BrowserCache_Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private function rules_cache_generate_apache( $config ) {
$rules .= " BrowserMatch \\bMSI[E] !no-gzip !gzip-only-text/html\n";
$rules .= " </IfModule>\n";
}
if ( version_compare( $this->_get_server_version(), '2.3.7', '>=' ) ) {
if ( version_compare( Util_Environment::get_server_version(), '2.3.7', '>=' ) ) {
$rules .= " <IfModule mod_filter.c>\n";
}
$rules .= " AddOutputFilterByType DEFLATE " . implode( ' ', $compression_types ) . "\n";
Expand All @@ -325,7 +325,7 @@ private function rules_cache_generate_apache( $config ) {
$rules .= " AddOutputFilter DEFLATE js css htm html xml\n";
$rules .= " </IfModule>\n";

if ( version_compare( $this->_get_server_version(), '2.3.7', '>=' ) ) {
if ( version_compare( Util_Environment::get_server_version(), '2.3.7', '>=' ) ) {
$rules .= " </IfModule>\n";
}
$rules .= "</IfModule>\n";
Expand Down Expand Up @@ -585,10 +585,12 @@ private function _rules_cache_generate_nginx_for_type( $config, &$rules,
$mime_types, $section ) {

$expires = $config->get_boolean( 'browsercache.' . $section . '.expires' );
$etag = $config->get_boolean( 'browsercache.' . $section . '.etag' );
$cache_control = $config->get_boolean( 'browsercache.' . $section . '.cache.control' );
$w3tc = $config->get_boolean( 'browsercache.' . $section . '.w3tc' );
$last_modified = $config->get_boolean( 'browsercache.' . $section . '.last_modified' );

if ( $expires || $cache_control || $w3tc ) {
if ( $etag || $expires || $cache_control || $w3tc || !$last_modified ) {
$lifetime = $config->get_integer( 'browsercache.' . $section . '.lifetime' );

$extensions = array_keys( $mime_types );
Expand All @@ -604,6 +606,18 @@ private function _rules_cache_generate_nginx_for_type( $config, &$rules,
if ( $expires ) {
$rules .= " expires " . $lifetime . "s;\n";
}
if ( version_compare( Util_Environment::get_server_version(), '1.3.3', '>=' ) ) {
if ( $etag ) {
$rules .= " etag on;\n";
} else {
$rules .= " etag off;\n";
}
}
if ( $last_modified ) {
$rules .= " if_modified_since exact;\n";
} else {
$rules .= " if_modified_since off;\n";
}

$add_header_rules = '';

Expand Down Expand Up @@ -794,18 +808,6 @@ private function rules_no404wp_generate_apache( $config ) {
return $rules;
}

/**
* Returns the apache, nginx version
*
* @return string
*/
private function _get_server_version() {
$sig= explode( '/', $_SERVER['SERVER_SOFTWARE'] );
$temp = isset( $sig[1] ) ? explode( ' ', $sig[1] ) : array( '0' );
$version = $temp[0];
return $version;
}

/**
* Takes an array of extensions single per row and/or extensions delimited by |
*
Expand Down
4 changes: 0 additions & 4 deletions Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ static public function engine_name( $engine, $module = '' ) {
$engine_name = 'mirror';
break;

case 'netdna':
$engine_name = 'netdna';
break;

case 'maxcdn':
$engine_name = 'maxcdn';
break;
Expand Down
8 changes: 4 additions & 4 deletions CacheFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ function opcache_flush_file( $filename ) {
/**
* Purges/Flushes post page
*/
function flush_post( $post_id ) {
return $this->_executor->flush_post( $post_id );
function flush_post( $post_id, $extras = null ) {
return $this->_executor->flush_post( $post_id, $extras );
}

/**
Expand Down Expand Up @@ -162,12 +162,12 @@ function flush_all( $extras = null ) {
/**
* Purges/Flushes url
*/
function flush_url( $url ) {
function flush_url( $url, $extras = null ) {
static $flushed_urls = array();

if ( !in_array( $url, $flushed_urls ) ) {
$flushed_urls[] = $url;
return $this->_executor->flush_url( $url );
return $this->_executor->flush_url( $url, $extras );
}
return true;
}
Expand Down
22 changes: 15 additions & 7 deletions CacheFlush_Locally.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function minifycache_flush( $extras = array() ) {
function minifycache_flush_all( $extras = array() ) {
if ( $extras['minify'] == 'purge_map' )
delete_option( 'w3tc_minify' );

$this->minifycache_flush( $extras );
}

Expand Down Expand Up @@ -156,16 +156,20 @@ function opcache_flush_file( $filename ) {
/**
* Purges/Flushes post from page cache, varnish and cdn cache
*/
function flush_post( $post_id ) {
do_action( 'w3tc_flush_post', $post_id );
function flush_post( $post_id, $extras = null ) {
$do_flush = apply_filters( 'w3tc_preflush_post', true, $extras );
if ( $do_flush )
do_action( 'w3tc_flush_post', $post_id );
}

/**
* Purges/Flushes page contents - page cache, varnish and cdn cache
* When global changes affect whole content but not internal data structures
*/
function flush_posts( $extras = null ) {
do_action( 'w3tc_flush_posts', $extras );
$do_flush = apply_filters( 'w3tc_preflush_posts', true, $extras );
if ( $do_flush )
do_action( 'w3tc_flush_posts', $extras );
}

/**
Expand Down Expand Up @@ -198,14 +202,18 @@ function flush_all( $extras ) {
$default_actions_added = true;
}

do_action( 'w3tc_flush_all', $extras );
$do_flush = apply_filters( 'w3tc_preflush_all', true, $extras );
if ( $do_flush )
do_action( 'w3tc_flush_all', $extras );
}

/**
* Purges/Flushes url from page cache, varnish and cdn cache
*/
function flush_url( $url ) {
do_action( 'w3tc_flush_url', $url );
function flush_url( $url, $extras = null ) {
$do_flush = apply_filters( 'w3tc_preflush_url', true, $extras );
if ( $do_flush )
do_action( 'w3tc_flush_url', $url );
}

/**
Expand Down
59 changes: 40 additions & 19 deletions Cache_File_Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
namespace W3TC;

/**
* Generic file cache
*/



/**
* class Cache_File_Generic
* Disk:Enhanced file cache
*/
class Cache_File_Generic extends Cache_File {
/**
Expand Down Expand Up @@ -56,7 +50,7 @@ function set( $key, $var, $expire = 0, $group = '' ) {

$tmppath = $path . '.' . getmypid();

$fp = @fopen( $tmppath, 'w' );
$fp = @fopen( $tmppath, 'wb' );
if ( !$fp )
return false;

Expand All @@ -83,16 +77,43 @@ function set( $key, $var, $expire = 0, $group = '' ) {
$old_entry_path = $path . '_old';
@unlink( $old_entry_path );

if ( Util_Environment::is_apache() && isset( $var['headers'] ) &&
isset( $var['headers']['Content-Type'] ) &&
substr( $var['headers']['Content-Type'], 0, 8 ) == 'text/xml' ) {
file_put_contents( dirname( $path ) . '/.htaccess',
"<IfModule mod_mime.c>\n" .
" RemoveType .html_gzip\n" .
" AddType text/xml .html_gzip\n" .
" RemoveType .html\n" .
" AddType text/xml .html\n".
"</IfModule>" );
if ( Util_Environment::is_apache() && isset( $var['headers'] ) ) {
$rules = '';

if ( isset( $var['headers']['Content-Type'] ) &&
substr( $var['headers']['Content-Type'], 0, 8 ) == 'text/xml' ) {

$rules .= "<IfModule mod_mime.c>\n";
$rules .= " RemoveType .html_gzip\n";
$rules .= " AddType text/xml .html_gzip\n";
$rules .= " RemoveType .html\n";
$rules .= " AddType text/xml .html\n";
$rules .= "</IfModule>\n";
}

if ( isset( $var['headers'] ) ) {
$links = '';

foreach ( $var['headers'] as $h ) {
if ( isset($h['n']) && isset($h['v']) && $h['n'] == 'Link' ) {
$value = $h['v'];
if ( false !== strpos( $value, 'rel=preload' ) ) {
$links .= " Header add Link '" . trim($value) . "'\n";
}
}
}

if ( !empty( $links) ) {
$rules .= "<IfModule mod_headers.c>\n";
$rules .= " Header unset Link\n";
$rules .= $links;
$rules .= "</IfModule>\n";
}
}

if ( !empty($rules) ) {
@file_put_contents( dirname( $path ) . '/.htaccess', $rules );
}
}

return true;
Expand Down Expand Up @@ -147,7 +168,7 @@ private function _read( $path ) {
if ( !is_readable( $path ) )
return null;

$fp = @fopen( $path, 'r' );
$fp = @fopen( $path, 'rb' );
if ( !$fp )
return null;

Expand Down
8 changes: 8 additions & 0 deletions Cache_Memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ function __construct( $config ) {
return false;
}

// when disabled - no extra requests are made to obtain key version,
// but flush operations not supported as a result
// group should be always empty
if ( isset( $config['key_version_mode'] ) &&
$config['key_version_mode'] == 'disabled' ) {
$this->_key_version[''] = 1;
}

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions Cache_Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ private function initialize( $config ) {
$this->_memcache->setSaslAuthData( $config['username'],
$config['password'] );

// when disabled - no extra requests are made to obtain key version,
// but flush operations not supported as a result
// group should be always empty
if ( isset( $config['key_version_mode'] ) &&
$config['key_version_mode'] == 'disabled' ) {
$this->_key_version[''] = 1;
}

return true;
}

Expand Down
14 changes: 12 additions & 2 deletions Cache_Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function __construct( $config ) {
$this->_servers = (array)$config['servers'];
$this->_password = $config['password'];
$this->_dbid = $config['dbid'];

// when disabled - no extra requests are made to obtain key version,
// but flush operations not supported as a result
// group should be always empty
if ( isset( $config['key_version_mode'] ) &&
$config['key_version_mode'] == 'disabled' ) {
$this->_key_version[''] = 1;
}
}

/**
Expand Down Expand Up @@ -325,14 +333,16 @@ private function _get_accessor( $key ) {

if ( substr( $server, 0, 5 ) == 'unix:' ) {
if ( $this->_persistent )
$accessor->pconnect( trim( substr( $server, 5 ) ) );
$accessor->pconnect( trim( substr( $server, 5 ) ),
null, null, $this->_instance_id . '_' . $this->_dbid );
else
$accessor->connect( trim( substr( $server, 5 ) ) );
} else {
list( $ip, $port ) = explode( ':', $server );

if ( $this->_persistent )
$accessor->pconnect( trim( $ip ), (integer) trim( $port ) );
$accessor->pconnect( trim( $ip ), (integer) trim( $port ),
null, $this->_instance_id . '_' . $this->_dbid );
else
$accessor->connect( trim( $ip ), (integer) trim( $port ) );
}
Expand Down
4 changes: 0 additions & 4 deletions CdnEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ static function instance( $engine, $config = array() ) {
$instances[$instance_key] = new CdnEngine_Mirror( $config );
break;

case 'netdna':
$instances[$instance_key] = new CdnEngine_Mirror_Netdna( $config );
break;

case 'rackspace_cdn':
$instances[$instance_key] = new CdnEngine_Mirror_RackSpaceCdn( $config );
break;
Expand Down
11 changes: 8 additions & 3 deletions CdnEngine_Azure.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ function upload( $files, &$results, $force_rewrite = false,
}

foreach ( $files as $file ) {
if ( !is_null( $timeout_time ) && time() > $timeout_time )
break;

$remote_path = $file['remote_path'];
$local_path = $file['local_path'];

// process at least one item before timeout so that progress goes on
if ( !empty( $results ) ) {
if ( !is_null( $timeout_time ) && time() > $timeout_time ) {
return 'timeout';
}
}

$results[] = $this->_upload( $file, $force_rewrite );
}
Expand Down
14 changes: 13 additions & 1 deletion CdnEngine_Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,15 @@ function get_domain( $path = '' ) {
break;

default:
if ( $count > 4 ) {
if ( !isset( $domains[0] ) ) {
$scheme = $this->_get_scheme();
if ( 'https' == $scheme && isset( $domains['https_default'] ) ) {
return $domains['https_default'];
} else {
return isset( $domains['http_default'] ) ? $domains['http_default'] :
$domains['https_default'];
}
} elseif ( $count > 4 ) {
$domain = $this->_get_domain( array_slice( $domains, 4 ),
$path );
} else {
Expand Down Expand Up @@ -579,6 +587,10 @@ function _is_js_footer( $path ) {
*/
function _get_domain( $domains, $path ) {
$count = count( $domains );
if ( isset( $domains['http_default'] ) )
$count--;
if ( isset( $domains['https_default'] ) )
$count--;

if ( $count ) {
/**
Expand Down
10 changes: 7 additions & 3 deletions CdnEngine_Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,16 @@ function upload( $files, &$results, $force_rewrite = false,
}

foreach ( $files as $file ) {
if ( !is_null( $timeout_time ) && time() > $timeout_time )
break;

$local_path = $file['local_path'];
$remote_path = $file['remote_path'];

// process at least one item before timeout so that progress goes on
if ( !empty( $results ) ) {
if ( !is_null( $timeout_time ) && time() > $timeout_time ) {
return 'timeout';
}
}

if ( !file_exists( $local_path ) ) {
$results[] = $this->_get_result( $local_path, $remote_path,
W3TC_CDN_RESULT_ERROR, 'Source file not found.', $file );
Expand Down
Loading

0 comments on commit 56f1c45

Please sign in to comment.