Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-super...
File: wp-cache-phase2.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* WP Super Cache Phase 2 file.
[2] Fix | Delete
* This file is included by the files wp-cache.php and wp-cache-phase1.php
[3] Fix | Delete
* It has all the code for caching and serving requests.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_is_writable -- TODO: Fix or determine for sure that these should not be fixed.
[7] Fix | Delete
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fwrite -- TODO: Fix or determine for sure that these should not be fixed.
[8] Fix | Delete
[9] Fix | Delete
function gzip_accepted() {
[10] Fix | Delete
if ( 1 == ini_get( 'zlib.output_compression' ) || 'on' == strtolower( ini_get( 'zlib.output_compression' ) ) ) { // don't compress WP-Cache data files when PHP is already doing it
[11] Fix | Delete
return false;
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) || ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) && strpos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) === false ) ) {
[15] Fix | Delete
return false;
[16] Fix | Delete
}
[17] Fix | Delete
return 'gzip';
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
function setup_blog_cache_dir() {
[21] Fix | Delete
global $blog_cache_dir, $cache_path;
[22] Fix | Delete
if ( false == @is_dir( $blog_cache_dir ) ) {
[23] Fix | Delete
@mkdir( $cache_path . 'blogs' );
[24] Fix | Delete
@mkdir( $blog_cache_dir );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
if ( false == @is_dir( $blog_cache_dir . 'meta' ) ) {
[28] Fix | Delete
@mkdir( $blog_cache_dir . 'meta' );
[29] Fix | Delete
}
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
function get_wp_cache_key( $url = false ) {
[33] Fix | Delete
global $wp_cache_request_uri, $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
[34] Fix | Delete
if ( ! $url ) {
[35] Fix | Delete
$url = $wp_cache_request_uri;
[36] Fix | Delete
}
[37] Fix | Delete
$server_port = isset( $_SERVER['SERVER_PORT'] ) ? intval( $_SERVER['SERVER_PORT'] ) : 0;
[38] Fix | Delete
[39] Fix | Delete
// Prepare a tag to include in the cache key if the request is anything other than text/html
[40] Fix | Delete
$accept = wpsc_get_accept_header();
[41] Fix | Delete
if ( $accept === 'text/html' ) {
[42] Fix | Delete
$accept_tag = '';
[43] Fix | Delete
} else {
[44] Fix | Delete
$accept_tag = '-' . $accept;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return do_cacheaction(
[48] Fix | Delete
'wp_cache_key',
[49] Fix | Delete
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
[50] Fix | Delete
wp_cache_check_mobile( $WPSC_HTTP_HOST . $server_port . preg_replace( '/#.*$/', '', str_replace( '/index.php', '/', $url ) ) . $wp_cache_gzip_encoding . wp_cache_get_cookies_values() . '-' . wpsc_get_accept_header() . $accept_tag )
[51] Fix | Delete
);
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Parse a partial URL (only the path and query components).
[56] Fix | Delete
*
[57] Fix | Delete
* @param string $partial_uri - The path and query component of a URI to parse.
[58] Fix | Delete
*/
[59] Fix | Delete
function wpsc_parse_partial_url( $partial_uri ) {
[60] Fix | Delete
global $WPSC_HTTP_HOST;
[61] Fix | Delete
[62] Fix | Delete
$scheme = wpsc_is_https() ? 'https://' : 'http://';
[63] Fix | Delete
return parse_url( $scheme . $WPSC_HTTP_HOST . $partial_uri );
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
function wpsc_remove_tracking_params_from_uri( $uri ) {
[67] Fix | Delete
global $wpsc_tracking_parameters, $wpsc_ignore_tracking_parameters;
[68] Fix | Delete
[69] Fix | Delete
if ( ! isset( $wpsc_ignore_tracking_parameters ) || ! $wpsc_ignore_tracking_parameters ) {
[70] Fix | Delete
return $uri;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( ! isset( $wpsc_tracking_parameters ) || empty( $wpsc_tracking_parameters ) ) {
[74] Fix | Delete
return $uri;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
$parsed_url = wpsc_parse_partial_url( $uri );
[78] Fix | Delete
$query = array();
[79] Fix | Delete
[80] Fix | Delete
if ( isset( $parsed_url['query'] ) ) {
[81] Fix | Delete
parse_str( $parsed_url['query'], $query );
[82] Fix | Delete
foreach ( $wpsc_tracking_parameters as $param_name ) {
[83] Fix | Delete
unset( $query[ $param_name ] );
[84] Fix | Delete
unset( $_GET[ $param_name ] );
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
$path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
[88] Fix | Delete
$query = ! empty( $query ) ? '?' . http_build_query( $query ) : '';
[89] Fix | Delete
[90] Fix | Delete
if ( empty( $_GET ) ) {
[91] Fix | Delete
$_SERVER['REQUEST_URI'] = strtok( $_SERVER['REQUEST_URI'], '?' );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
if ( $uri !== $path . $query ) {
[95] Fix | Delete
wp_cache_debug( 'Removed tracking parameters from URL. Returning ' . $path . $query );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
return $path . $query;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
function wp_super_cache_init() {
[102] Fix | Delete
global $wp_cache_key, $key, $blogcacheid, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname;
[103] Fix | Delete
[104] Fix | Delete
$wp_cache_key = get_wp_cache_key();
[105] Fix | Delete
$key = $blogcacheid . md5( $wp_cache_key );
[106] Fix | Delete
$wp_cache_key = $blogcacheid . $wp_cache_key;
[107] Fix | Delete
[108] Fix | Delete
$cache_filename = $file_prefix . $key . '.php';
[109] Fix | Delete
$meta_file = $file_prefix . $key . '.php';
[110] Fix | Delete
[111] Fix | Delete
$cache_file = wpsc_get_realpath( $blog_cache_dir );
[112] Fix | Delete
[113] Fix | Delete
if ( $cache_file ) {
[114] Fix | Delete
$cache_file .= '/' . $cache_filename;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
$meta_pathname = wpsc_get_realpath( $blog_cache_dir . 'meta/' );
[118] Fix | Delete
[119] Fix | Delete
if ( $meta_pathname ) {
[120] Fix | Delete
$meta_pathname .= '/' . $meta_file;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' );
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
function wp_cache_serve_cache_file() {
[127] Fix | Delete
global $key, $blogcacheid, $wp_cache_request_uri, $file_prefix, $blog_cache_dir, $meta_file, $cache_file, $cache_filename, $meta_pathname, $wp_cache_gzip_encoding, $meta;
[128] Fix | Delete
global $cache_compression, $wp_cache_slash_check, $wp_supercache_304, $wp_cache_home_path, $wp_cache_no_cache_for_get;
[129] Fix | Delete
global $wp_cache_disable_utf8, $wp_cache_mfunc_enabled, $wpsc_served_header;
[130] Fix | Delete
[131] Fix | Delete
if ( wpsc_is_backend() ) {
[132] Fix | Delete
wp_cache_debug( 'Not serving wp-admin requests.', 5 );
[133] Fix | Delete
return false;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
if ( $wp_cache_no_cache_for_get && wpsc_is_get_query() ) {
[137] Fix | Delete
wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
[138] Fix | Delete
return false;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
if ( defined( 'WPSC_SERVE_DISABLED' ) ) {
[142] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: WPSC_SERVE_DISABLED defined. Not serving cached files.' );
[143] Fix | Delete
return false;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
if ( wpsc_get_accept_header() !== 'text/html' ) {
[147] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: visitor does not accept text/html. Not serving cached file.' );
[148] Fix | Delete
return false;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
extract( wp_super_cache_init() ); // $key, $cache_filename, $meta_file, $cache_file, $meta_pathname
[152] Fix | Delete
[153] Fix | Delete
// Look for wp-cache file + meta file for the current URL
[154] Fix | Delete
// If we can't find them, we will look for supercache html files. These files don't have any meta data
[155] Fix | Delete
// which is why the code below does more work setting up the headers, etc.
[156] Fix | Delete
if (
[157] Fix | Delete
! defined( 'WPSC_SUPERCACHE_ONLY' ) &&
[158] Fix | Delete
(
[159] Fix | Delete
( $cache_file && file_exists( $cache_file ) ) ||
[160] Fix | Delete
file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename )
[161] Fix | Delete
)
[162] Fix | Delete
) {
[163] Fix | Delete
if ( file_exists( get_current_url_supercache_dir() . 'meta-' . $cache_filename ) ) {
[164] Fix | Delete
$cache_file = get_current_url_supercache_dir() . $cache_filename;
[165] Fix | Delete
$meta_pathname = get_current_url_supercache_dir() . 'meta-' . $cache_filename;
[166] Fix | Delete
} elseif ( ! file_exists( $cache_file ) ) {
[167] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: found cache file but then it disappeared!' );
[168] Fix | Delete
return false;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
if ( ! $meta_pathname ) {
[172] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: meta pathname is empty. Could not load wp-cache meta file.' );
[173] Fix | Delete
return true;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
wp_cache_debug( "wp-cache file exists: $cache_file", 5 );
[177] Fix | Delete
if ( ! ( $meta = json_decode( wp_cache_get_legacy_cache( $meta_pathname ), true ) ) ) {
[178] Fix | Delete
wp_cache_debug( "couldn't load wp-cache meta file", 5 );
[179] Fix | Delete
return true;
[180] Fix | Delete
}
[181] Fix | Delete
if ( is_array( $meta ) == false ) {
[182] Fix | Delete
wp_cache_debug( "meta array corrupt, deleting $meta_pathname and $cache_file", 1 );
[183] Fix | Delete
@unlink( $meta_pathname );
[184] Fix | Delete
@unlink( $cache_file );
[185] Fix | Delete
return true;
[186] Fix | Delete
}
[187] Fix | Delete
} else { // no wp-cache file, look for a supercache file
[188] Fix | Delete
global $wpsc_save_headers;
[189] Fix | Delete
global $cache_max_time;
[190] Fix | Delete
// last chance, check if a supercache file exists. Just in case .htaccess rules don't work on this host
[191] Fix | Delete
$file = get_current_url_supercache_dir() . supercache_filename();
[192] Fix | Delete
if ( false == file_exists( $file ) ) {
[193] Fix | Delete
wp_cache_debug( "No Super Cache file found for current URL: $file" );
[194] Fix | Delete
return false;
[195] Fix | Delete
} elseif ( wpsc_is_get_query() ) {
[196] Fix | Delete
wp_cache_debug( 'GET array not empty. Cannot serve a supercache file. ' . wpsc_dump_get_request() );
[197] Fix | Delete
return false;
[198] Fix | Delete
} elseif ( wp_cache_get_cookies_values() != '' ) {
[199] Fix | Delete
wp_cache_debug( 'Cookies found. Cannot serve a supercache file. ' . wp_cache_get_cookies_values() );
[200] Fix | Delete
return false;
[201] Fix | Delete
} elseif ( wpsc_get_accept_header() !== 'text/html' ) {
[202] Fix | Delete
wp_cache_debug( 'Accept header is not text/html. Cannot serve supercache file.' . wp_cache_get_cookies_values() );
[203] Fix | Delete
return false;
[204] Fix | Delete
} elseif ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
[205] Fix | Delete
wp_cache_debug( 'Saving headers. Cannot serve a supercache file.' );
[206] Fix | Delete
return false;
[207] Fix | Delete
} elseif ( $cache_max_time > 0 && ( filemtime( $file ) + $cache_max_time ) < time() ) {
[208] Fix | Delete
wp_cache_debug( sprintf( 'Cache has expired and is older than %d seconds old.', $cache_max_time ) );
[209] Fix | Delete
return false;
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
if ( isset( $wp_cache_mfunc_enabled ) == false ) {
[213] Fix | Delete
$wp_cache_mfunc_enabled = 0;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
if ( false == isset( $wp_cache_home_path ) ) {
[217] Fix | Delete
$wp_cache_home_path = '/';
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
// make sure ending slashes are ok
[221] Fix | Delete
if ( $wp_cache_request_uri == $wp_cache_home_path || ( $wp_cache_slash_check && substr( $wp_cache_request_uri, -1 ) == '/' ) || ( $wp_cache_slash_check == 0 && substr( $wp_cache_request_uri, -1 ) != '/' ) ) {
[222] Fix | Delete
[223] Fix | Delete
if ( $wp_cache_mfunc_enabled == 0 ) {
[224] Fix | Delete
// get data from file
[225] Fix | Delete
if ( $wp_cache_gzip_encoding ) {
[226] Fix | Delete
if ( file_exists( $file . '.gz' ) ) {
[227] Fix | Delete
$cachefiledata = file_get_contents( $file . '.gz' );
[228] Fix | Delete
wp_cache_debug( "Fetched gzip static page data from supercache file using PHP. File: $file.gz" );
[229] Fix | Delete
} else {
[230] Fix | Delete
$cachefiledata = gzencode( file_get_contents( $file ), 6, FORCE_GZIP );
[231] Fix | Delete
wp_cache_debug( "Fetched static page data from supercache file using PHP and gzipped it. File: $file" );
[232] Fix | Delete
}
[233] Fix | Delete
} else {
[234] Fix | Delete
$cachefiledata = file_get_contents( $file );
[235] Fix | Delete
wp_cache_debug( "Fetched static page data from supercache file using PHP. File: $file" );
[236] Fix | Delete
}
[237] Fix | Delete
} else {
[238] Fix | Delete
// get dynamic data from filtered file
[239] Fix | Delete
$cachefiledata = do_cacheaction( 'wpsc_cachedata', file_get_contents( $file ) );
[240] Fix | Delete
if ( $wp_cache_gzip_encoding ) {
[241] Fix | Delete
$cachefiledata = gzencode( $cachefiledata, 6, FORCE_GZIP );
[242] Fix | Delete
wp_cache_debug( "Fetched dynamic page data from supercache file using PHP and gzipped it. File: $file" );
[243] Fix | Delete
} else {
[244] Fix | Delete
wp_cache_debug( "Fetched dynamic page data from supercache file using PHP. File: $file" );
[245] Fix | Delete
}
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) {
[249] Fix | Delete
header( 'Content-type: text/html; charset=UTF-8' );
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
if ( defined( 'WPSC_VARY_HEADER' ) ) {
[253] Fix | Delete
if ( WPSC_VARY_HEADER != '' ) {
[254] Fix | Delete
header( 'Vary: ' . WPSC_VARY_HEADER );
[255] Fix | Delete
}
[256] Fix | Delete
} else {
[257] Fix | Delete
header( 'Vary: Accept-Encoding, Cookie' );
[258] Fix | Delete
}
[259] Fix | Delete
if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) ) {
[260] Fix | Delete
if ( WPSC_CACHE_CONTROL_HEADER != '' ) {
[261] Fix | Delete
header( 'Cache-Control: ' . WPSC_CACHE_CONTROL_HEADER );
[262] Fix | Delete
}
[263] Fix | Delete
} else {
[264] Fix | Delete
header( 'Cache-Control: max-age=3, must-revalidate' );
[265] Fix | Delete
}
[266] Fix | Delete
$size = ( function_exists( 'mb_strlen' ) && function_exists( 'is_utf8_charset' ) ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata );
[267] Fix | Delete
if ( $wp_cache_gzip_encoding ) {
[268] Fix | Delete
if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
[269] Fix | Delete
header( 'X-WP-Super-Cache: Served supercache gzip file from PHP' );
[270] Fix | Delete
}
[271] Fix | Delete
header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
[272] Fix | Delete
header( 'Content-Length: ' . $size );
[273] Fix | Delete
} elseif ( $wp_supercache_304 ) {
[274] Fix | Delete
if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
[275] Fix | Delete
header( 'X-WP-Super-Cache: Served supercache 304 file from PHP' );
[276] Fix | Delete
}
[277] Fix | Delete
header( 'Content-Length: ' . $size );
[278] Fix | Delete
} elseif ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
[279] Fix | Delete
header( 'X-WP-Super-Cache: Served supercache file from PHP' );
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
// don't try to match modified dates if using dynamic code.
[283] Fix | Delete
if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
[284] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: checking age of cached vs served files.' );
[285] Fix | Delete
$headers = apache_request_headers();
[286] Fix | Delete
$remote_mod_time = isset( $headers['If-Modified-Since'] ) ? $headers['If-Modified-Since'] : null;
[287] Fix | Delete
[288] Fix | Delete
if ( $remote_mod_time === null && isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
[289] Fix | Delete
$remote_mod_time = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
$local_mod_time = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ) . ' GMT';
[293] Fix | Delete
if ( $remote_mod_time !== null && $remote_mod_time == $local_mod_time ) {
[294] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: Send 304 Not Modified header.' );
[295] Fix | Delete
header( $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified' );
[296] Fix | Delete
exit();
[297] Fix | Delete
} else {
[298] Fix | Delete
wp_cache_debug( 'wp_cache_serve_cache_file: 304 browser caching not possible as timestamps differ.' );
[299] Fix | Delete
}
[300] Fix | Delete
header( 'Last-Modified: ' . $local_mod_time );
[301] Fix | Delete
}
[302] Fix | Delete
echo $cachefiledata;
[303] Fix | Delete
exit();
[304] Fix | Delete
} else {
[305] Fix | Delete
wp_cache_debug( 'No wp-cache file exists. Must generate a new one.' );
[306] Fix | Delete
return false;
[307] Fix | Delete
}
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
$cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file );
[311] Fix | Delete
// Sometimes the gzip headers are lost. Make sure html returned isn't compressed!
[312] Fix | Delete
$do_not_serve_gzip_data = true;
[313] Fix | Delete
if ( $cache_compression && $wp_cache_gzip_encoding ) {
[314] Fix | Delete
if ( ! in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta['headers'], true ) ) {
[315] Fix | Delete
wp_cache_debug( 'GZIP headers not found. Force uncompressed output.' );
[316] Fix | Delete
} else {
[317] Fix | Delete
$do_not_serve_gzip_data = false;
[318] Fix | Delete
if ( isset( $meta['dynamic'] ) ) {
[319] Fix | Delete
unset( $meta['headers']['Content-Length'] ); // this is set later after the output data is compressed
[320] Fix | Delete
}
[321] Fix | Delete
wp_cache_debug( 'GZIP headers found. Serving compressed output.' );
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
foreach ( $meta['headers'] as $t => $header ) {
[326] Fix | Delete
// godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
[327] Fix | Delete
if ( strpos( $header, 'Last-Modified:' ) === false ) {
[328] Fix | Delete
header( $header );
[329] Fix | Delete
wp_cache_debug( 'Sending Header: ' . $header );
[330] Fix | Delete
}
[331] Fix | Delete
}
[332] Fix | Delete
if ( isset( $wpsc_served_header ) && $wpsc_served_header ) {
[333] Fix | Delete
header( 'X-WP-Super-Cache: Served WPCache cache file' );
[334] Fix | Delete
}
[335] Fix | Delete
if ( isset( $meta['dynamic'] ) ) {
[336] Fix | Delete
wp_cache_debug( 'Serving wp-cache dynamic file', 5 );
[337] Fix | Delete
if ( $do_not_serve_gzip_data ) {
[338] Fix | Delete
// attempt to uncompress the cached file just in case it's gzipped
[339] Fix | Delete
$cache = wp_cache_get_legacy_cache( $cache_file );
[340] Fix | Delete
$uncompressed = @gzuncompress( $cache );
[341] Fix | Delete
if ( $uncompressed ) {
[342] Fix | Delete
wp_cache_debug( 'Uncompressed gzipped cache from wp-cache: ' . $cache_file );
[343] Fix | Delete
$cache = $uncompressed;
[344] Fix | Delete
unset( $uncompressed );
[345] Fix | Delete
}
[346] Fix | Delete
$cache = do_cacheaction( 'wpsc_cachedata', $cache );
[347] Fix | Delete
} else {
[348] Fix | Delete
wp_cache_debug( 'Compressed cache data from wp-cache: ' . $cache_file );
[349] Fix | Delete
$cache = gzencode(
[350] Fix | Delete
do_cacheaction(
[351] Fix | Delete
'wpsc_cachedata',
[352] Fix | Delete
wp_cache_get_legacy_cache( $cache_file )
[353] Fix | Delete
),
[354] Fix | Delete
6,
[355] Fix | Delete
FORCE_GZIP
[356] Fix | Delete
);
[357] Fix | Delete
$size = ( function_exists( 'mb_strlen' ) && function_exists( 'is_utf8_charset' ) ) ? mb_strlen( $cache, '8bit' ) : strlen( $cache );
[358] Fix | Delete
wp_cache_debug( 'Sending Header: Content-Length: ' . $size );
[359] Fix | Delete
header( 'Content-Length: ' . $size );
[360] Fix | Delete
}
[361] Fix | Delete
} elseif ( $do_not_serve_gzip_data ) {
[362] Fix | Delete
$cache = wp_cache_get_legacy_cache( $cache_file );
[363] Fix | Delete
$uncompressed = @gzuncompress( $cache ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- there is a small chance the cache isn't gzipped despite being configured to be.
[364] Fix | Delete
if ( $uncompressed ) {
[365] Fix | Delete
$cache = $uncompressed;
[366] Fix | Delete
unset( $uncompressed );
[367] Fix | Delete
wp_cache_debug( 'Uncompressed gzipped cache data from wp-cache file: ' . $cache_file );
[368] Fix | Delete
} else {
[369] Fix | Delete
wp_cache_debug( 'Sending already uncompressed cache file from wp-cache to browser: ' . $cache_file );
[370] Fix | Delete
}
[371] Fix | Delete
} else {
[372] Fix | Delete
wp_cache_debug( 'Sending wp-cache file to browser: ' . $cache_file );
[373] Fix | Delete
$cache = wp_cache_get_legacy_cache( $cache_file );
[374] Fix | Delete
}
[375] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- this is the cached version of the current page. It will have been escaped already.
[376] Fix | Delete
echo $cache;
[377] Fix | Delete
wp_cache_debug( 'exit request', 5 );
[378] Fix | Delete
die();
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
function wp_cache_get_legacy_cache( $cache_file ) {
[382] Fix | Delete
return substr( @file_get_contents( $cache_file ), 15 );
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
function wp_cache_postload() {
[386] Fix | Delete
global $cache_enabled, $wp_super_cache_late_init;
[387] Fix | Delete
global $wp_cache_request_uri;
[388] Fix | Delete
[389] Fix | Delete
if ( empty( $wp_cache_request_uri ) ) {
[390] Fix | Delete
wp_cache_debug( 'wp_cache_postload: no request uri configured. Not running.' );
[391] Fix | Delete
return false;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
// have to sanitize here because formatting.php is loaded after wp_cache_request_uri is set
[395] Fix | Delete
$wp_cache_request_uri = esc_url_raw( wp_unslash( $wp_cache_request_uri ) );
[396] Fix | Delete
[397] Fix | Delete
if ( ! $cache_enabled ) {
[398] Fix | Delete
return true;
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) {
[402] Fix | Delete
wp_cache_debug( 'Supercache Late Init: add wp_cache_serve_cache_file to init', 3 );
[403] Fix | Delete
add_action( 'init', 'wp_cache_late_loader', 9999 );
[404] Fix | Delete
} else {
[405] Fix | Delete
wp_super_cache_init();
[406] Fix | Delete
wp_cache_phase2();
[407] Fix | Delete
}
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
function wp_cache_late_loader() {
[411] Fix | Delete
wp_cache_debug( 'Supercache Late Loader running on init', 3 );
[412] Fix | Delete
wp_cache_serve_cache_file();
[413] Fix | Delete
wp_cache_phase2();
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
function wpsc_get_auth_cookies() {
[417] Fix | Delete
static $cached_cookies;
[418] Fix | Delete
[419] Fix | Delete
if ( isset( $cached_cookies ) && is_array( $cached_cookies ) ) {
[420] Fix | Delete
return $cached_cookies;
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
$cookies = array_keys( $_COOKIE );
[424] Fix | Delete
if ( empty( $cookies ) ) {
[425] Fix | Delete
return array();
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
$auth_cookies = array();
[429] Fix | Delete
$duplicate_cookies = array();
[430] Fix | Delete
[431] Fix | Delete
$wp_cookies = array(
[432] Fix | Delete
'AUTH_COOKIE' => 'wordpress_',
[433] Fix | Delete
'SECURE_AUTH_COOKIE' => 'wordpress_sec_',
[434] Fix | Delete
'LOGGED_IN_COOKIE' => 'wordpress_logged_in_',
[435] Fix | Delete
);
[436] Fix | Delete
[437] Fix | Delete
foreach ( $wp_cookies as $cookie_const => $cookie_prefix ) {
[438] Fix | Delete
$cookie_key = strtolower( $cookie_const );
[439] Fix | Delete
[440] Fix | Delete
if ( defined( $cookie_const ) ) {
[441] Fix | Delete
if ( in_array( constant( $cookie_const ), $cookies, true ) ) {
[442] Fix | Delete
$auth_cookies[ $cookie_key ] = constant( $cookie_const );
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
continue;
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
$found_cookies = preg_grep( '`^' . preg_quote( $cookie_prefix, '`' ) . '([0-9a-f]+)$`', $cookies );
[449] Fix | Delete
[450] Fix | Delete
if ( count( $found_cookies ) === 1 ) {
[451] Fix | Delete
$auth_cookies[ $cookie_key ] = reset( $found_cookies );
[452] Fix | Delete
} elseif ( count( $found_cookies ) > 1 ) {
[453] Fix | Delete
$duplicate_cookies = array_merge( $duplicate_cookies, $found_cookies );
[454] Fix | Delete
$auth_cookies[ $cookie_key ] = $found_cookies;
[455] Fix | Delete
}
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
$cookie_hash = defined( 'COOKIEHASH' ) ? COOKIEHASH : '';
[459] Fix | Delete
$other_cookies = array(
[460] Fix | Delete
'comment_cookie' => 'comment_author_',
[461] Fix | Delete
'postpass_cookie' => 'wp-postpass_',
[462] Fix | Delete
);
[463] Fix | Delete
[464] Fix | Delete
foreach ( $other_cookies as $cookie_key => $cookie_prefix ) {
[465] Fix | Delete
[466] Fix | Delete
if ( $cookie_hash ) {
[467] Fix | Delete
if ( in_array( $cookie_prefix . $cookie_hash, $cookies, true ) ) {
[468] Fix | Delete
$auth_cookies[ $cookie_key ] = $cookie_prefix . $cookie_hash;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
continue;
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
$found_cookies = preg_grep( '`^' . preg_quote( $cookie_prefix, '`' ) . '([0-9a-f]+)$`', $cookies );
[475] Fix | Delete
[476] Fix | Delete
if ( count( $found_cookies ) === 1 ) {
[477] Fix | Delete
$auth_cookies[ $cookie_key ] = reset( $found_cookies );
[478] Fix | Delete
} elseif ( count( $found_cookies ) > 1 ) {
[479] Fix | Delete
$duplicate_cookies = array_merge( $duplicate_cookies, $found_cookies );
[480] Fix | Delete
$auth_cookies[ $cookie_key ] = $found_cookies;
[481] Fix | Delete
}
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
if ( ! $duplicate_cookies ) {
[485] Fix | Delete
$cached_cookies = $auth_cookies;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
if ( empty( $auth_cookies ) ) {
[489] Fix | Delete
wp_cache_debug( 'wpsc_get_auth_cookies: no auth cookies detected', 5 );
[490] Fix | Delete
} elseif ( $duplicate_cookies ) {
[491] Fix | Delete
wp_cache_debug( 'wpsc_get_auth_cookies: duplicate cookies detected( ' . implode( ', ', $duplicate_cookies ) . ' )', 5 );
[492] Fix | Delete
} else {
[493] Fix | Delete
wp_cache_debug( 'wpsc_get_auth_cookies: cookies detected: ' . implode( ', ', $auth_cookies ), 5 );
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
return $auth_cookies;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function