|
|
||
|
|
|
||
|
function wp_cache_phase2() { |
function wp_cache_phase2() { |
||
|
global $cache_filename, $cache_acceptable_files, $wp_cache_meta_object; |
global $cache_filename, $cache_acceptable_files, $wp_cache_meta_object; |
||
|
|
//+mod http://blog.saddey.net 11-feb-07 encoding flag $cache_gzip |
||
|
|
global $wp_cache_gzip_encoding; |
||
|
|
|
||
|
wp_cache_mutex_init(); |
wp_cache_mutex_init(); |
||
|
if(function_exists('add_action')) { |
if(function_exists('add_action')) { |
||
|
|
||
|
function wp_cache_is_rejected($uri) { |
function wp_cache_is_rejected($uri) { |
||
|
global $cache_rejected_uri; |
global $cache_rejected_uri; |
||
|
|
|
||
|
if (strstr($uri, '/wp-admin/')) |
|
||
|
return true; //we don't allow cacheing wp-admin for security |
|
||
|
foreach ($cache_rejected_uri as $expr) { |
foreach ($cache_rejected_uri as $expr) { |
||
|
if (strlen($expr) > 0 && strstr($uri, $expr)) |
if (strlen($expr) > 0 && strstr($uri, $expr) && !strpos($uri,'/upgraded-to-wordpress-21-and-wp-cache-21/')) |
||
|
return true; |
return true; |
||
|
} |
} |
||
|
|
if (strstr($uri, '/wp-admin/')) |
||
|
|
return true; //we don't allow cacheing wp-admin for security |
||
|
return false; |
return false; |
||
|
} |
} |
||
|
|
|
||
|
|
||
|
sem_release($mutex); |
sem_release($mutex); |
||
|
} |
} |
||
|
|
|
||
|
|
//mod http://blog.saddey.net adopt Nick Georgakis compression mods for WP-Cache 2.1 |
||
|
function wp_cache_ob_callback($buffer) { |
function wp_cache_ob_callback($buffer) { |
||
|
global $cache_path, $cache_filename, $meta_file, $wp_start_time; |
global $cache_path, $cache_filename, $meta_file, $wp_start_time; |
||
|
global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id; |
global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id; |
||
|
|
//+mod http://blog.saddey.net 11-feb-07 encoding flag |
||
|
|
global $wp_cache_gzip_encoding; |
||
|
|
|
||
|
|
|
||
|
/* Mode paranoic, check for closing tags |
/* Mode paranoic, check for closing tags |
||
|
|
||
|
the file was expired and its mtime is less than 5 seconds |
the file was expired and its mtime is less than 5 seconds |
||
|
*/ |
*/ |
||
|
if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) { |
if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) { |
||
|
$fr = fopen($cache_path . $cache_filename, 'w'); |
$fr = fopen($cache_path . $cache_filename, 'wb'); // wb - should be default anyway |
||
|
if (!$fr) |
if (!$fr) |
||
|
$buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n"; |
$buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n"; |
||
|
|
|
||
|
if (preg_match('/<!--mclude|<!--mfunc/', $buffer)) { //Dynamic content |
if (preg_match('/<!--mclude|<!--mfunc/', $buffer)) { //Dynamic content |
||
|
|
//Nick Georgakis Notes: We DO NOT GZIP DYNAMIC PAGES since they need to be included later !!! |
||
|
$store = preg_replace('|<!--mclude (.*?)-->(.*?)<!--/mclude-->|is', |
$store = preg_replace('|<!--mclude (.*?)-->(.*?)<!--/mclude-->|is', |
||
|
"<!--mclude-->\n<?php include_once('" . ABSPATH . "$1'); ?>\n<!--/mclude-->", $buffer); |
"<!--mclude-->\n<?php include_once('" . ABSPATH . "$1'); ?>\n<!--/mclude-->", $buffer); |
||
|
$store = preg_replace('|<!--mfunc (.*?)-->(.*?)<!--/mfunc-->|is', |
$store = preg_replace('|<!--mfunc (.*?)-->(.*?)<!--/mfunc-->|is', |
||
|
|
||
|
$buffer = preg_replace('|<!--mfunc (.*?)-->|is', '<!--mfunc-->', $buffer); |
$buffer = preg_replace('|<!--mfunc (.*?)-->|is', '<!--mfunc-->', $buffer); |
||
|
fputs($fr, $store); |
fputs($fr, $store); |
||
|
} else { |
} else { |
||
|
fputs($fr, $buffer); |
//Nick Georgakis Notes: Compress the content here if browser asked for it |
||
|
|
//Modified Gzip Code from http://elliottback.com/wp/archives/2005/07/12/getting-wp-cache-to-work/ |
||
|
|
$log = "<!-- Cached page served by WP-Cache -->\n"; |
||
|
|
//+mod http://blog.saddey.net 11-feb-07 encoding flag |
||
|
|
// $encoding = gzip_accepted(); |
||
|
|
|
||
|
|
if ($wp_cache_gzip_encoding){ |
||
|
|
$log .= "<!-- Compression = " . $wp_cache_gzip_encoding ." -->"; |
||
|
|
//mod http://blog.saddey.net 11-feb-07 use PHP >= 4.2 gzencode instead of elliottback |
||
|
|
// $buffer2 = $buffer . $log; |
||
|
|
// $gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00"; // gzip header |
||
|
|
// $size = strlen($buffer2); |
||
|
|
// $crc = crc32($buffer2); |
||
|
|
// $gzdata .= gzcompress($buffer2, 9); |
||
|
|
// $gzdata = substr($gzdata, 0, strlen($gzdata) - 4); // fix crc bug |
||
|
|
// $gzdata .= pack("V",$crc) . pack("V", $size); |
||
|
|
$gzdata = gzencode($buffer . $log, 9, FORCE_GZIP); |
||
|
|
$gzsize = strlen($gzdata); |
||
|
|
|
||
|
|
//+mod http://blog.saddey.net 11-feb-07 adopt for WP-Cache 2.1 (glob var names changed) |
||
|
|
//header('Content-Encoding: ' . $wp_cache_gzip_encoding); |
||
|
|
array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding); |
||
|
|
//header('Vary: Accept-Encoding'); |
||
|
|
array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding'); |
||
|
|
//header('Content-Length: ' . strlen($gzdata)); |
||
|
|
array_push($wp_cache_meta_object->headers, 'Content-Length: ' . strlen($gzdata)); |
||
|
|
//Return UnCompressed Data & store compressed for later use |
||
|
|
fputs($fr, $gzdata); |
||
|
|
}else{ // no compression |
||
|
|
fputs($fr, $buffer.$log); |
||
|
|
} |
||
|
} |
} |
||
|
$new_cache = true; |
$new_cache = true; |
||
|
fclose($fr); |
fclose($fr); |