217 |
221 |
218 return true; |
222 return true; |
219 } |
223 } |
220 |
224 |
221 function wp_cache_writers_exit() { |
225 function wp_cache_writers_exit() { |
222 global $use_flock, $mutex, $cache_path, $mutex_filename, $wp_cache_mutex_disabled; |
226 global $mutex, $wp_cache_mutex_disabled, $use_flock; |
223 |
227 |
224 if( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) |
228 if( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) |
225 return true; |
229 return true; |
226 |
230 |
227 if( !$mutex ) { |
231 if( !$mutex ) { |
228 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "(writers exit) mutex lock not created. not caching.", 2 ); |
232 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "(writers exit) mutex lock not created. not caching.", 2 ); |
229 return false; |
233 return false; |
230 } |
234 } |
231 |
235 |
232 if ($use_flock) { |
236 if ( $use_flock ) { |
233 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "releasing lock using flock()", 5 ); |
237 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "releasing lock using flock()", 5 ); |
234 flock($mutex, LOCK_UN); |
238 flock($mutex, LOCK_UN); |
235 } else { |
239 } else { |
236 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "releasing lock using sem_release()", 5 ); |
240 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "releasing lock using sem_release()", 5 ); |
237 sem_release($mutex); |
241 sem_release($mutex); |
238 } |
242 } |
239 } |
243 } |
240 |
244 |
241 function get_current_url_supercache_dir() { |
245 function wp_super_cache_query_vars() { |
242 global $cached_direct_pages, $cache_path, $wp_cache_request_uri; |
246 global $wp_super_cache_query; |
243 $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $wp_cache_request_uri ) ) ) ); |
247 if ( is_search() ) |
244 $uri = str_replace( '\\', '', $uri ); |
248 $wp_super_cache_query[ 'is_search' ] = 1; |
245 $dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])) . $uri; // To avoid XSS attacks |
249 if ( is_page() ) |
246 $dir = apply_filters( 'supercache_dir', $dir ); |
250 $wp_super_cache_query[ 'is_page' ] = 1; |
247 $dir = trailingslashit( $cache_path . 'supercache/' . $dir ); |
251 if ( is_archive() ) |
248 if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) { |
252 $wp_super_cache_query[ 'is_archive' ] = 1; |
249 $dir = trailingslashit( ABSPATH . $uri ); |
253 if ( is_tag() ) |
250 } |
254 $wp_super_cache_query[ 'is_tag' ] = 1; |
251 $dir = str_replace( '//', '/', $dir ); |
255 if ( is_single() ) |
252 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "supercache dir: $dir", 5 ); |
256 $wp_super_cache_query[ 'is_single' ] = 1; |
253 return $dir; |
257 if ( is_category() ) |
|
258 $wp_super_cache_query[ 'is_category' ] = 1; |
|
259 if ( is_front_page() ) |
|
260 $wp_super_cache_query[ 'is_front_page' ] = 1; |
|
261 if ( is_home() ) |
|
262 $wp_super_cache_query[ 'is_home' ] = 1; |
|
263 if ( is_author() ) |
|
264 $wp_super_cache_query[ 'is_author' ] = 1; |
|
265 if ( is_feed() ) |
|
266 $wp_super_cache_query[ 'is_feed' ] = 1; |
254 } |
267 } |
255 |
268 |
256 function wp_cache_ob_callback( $buffer ) { |
269 function wp_cache_ob_callback( $buffer ) { |
257 global $wp_cache_pages; |
270 global $wp_cache_pages, $wp_query, $wp_super_cache_query; |
258 if( defined( 'DONOTCACHEPAGE' ) ) |
271 $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer ); |
|
272 if( defined( 'DONOTCACHEPAGE' ) ) { |
|
273 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 ); |
259 return $buffer; |
274 return $buffer; |
|
275 } |
|
276 |
|
277 if ( isset( $wp_cache_pages[ 'single' ] ) && $wp_cache_pages[ 'single' ] == 1 && isset( $wp_super_cache_query[ 'is_single' ] ) ) { |
|
278 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching single post.', 2 ); |
|
279 return $buffer; |
|
280 } elseif ( isset( $wp_cache_pages[ 'pages' ] ) && $wp_cache_pages[ 'pages' ] == 1 && isset( $wp_super_cache_query[ 'is_page' ] ) ) { |
|
281 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching single page.', 2 ); |
|
282 return $buffer; |
|
283 } elseif ( isset( $wp_cache_pages[ 'archives' ] ) && $wp_cache_pages[ 'archives' ] == 1 && isset( $wp_super_cache_query[ 'is_archive' ] ) ) { |
|
284 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching archive page.', 2 ); |
|
285 return $buffer; |
|
286 } elseif ( isset( $wp_cache_pages[ 'tag' ] ) && $wp_cache_pages[ 'tag' ] == 1 && isset( $wp_super_cache_query[ 'is_tag' ] ) ) { |
|
287 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching tag page.', 2 ); |
|
288 return $buffer; |
|
289 } elseif ( isset( $wp_cache_pages[ 'category' ] ) && $wp_cache_pages[ 'category' ] == 1 && isset( $wp_super_cache_query[ 'is_category' ] ) ) { |
|
290 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching category page.', 2 ); |
|
291 return $buffer; |
|
292 } elseif ( isset( $wp_cache_pages[ 'frontpage' ] ) && $wp_cache_pages[ 'frontpage' ] == 1 && isset( $wp_super_cache_query[ 'is_front_page' ] ) ) { |
|
293 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching front page.', 2 ); |
|
294 return $buffer; |
|
295 } elseif ( isset( $wp_cache_pages[ 'home' ] ) && $wp_cache_pages[ 'home' ] == 1 && isset( $wp_super_cache_query[ 'is_home' ] ) ) { |
|
296 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching home page.', 2 ); |
|
297 return $buffer; |
|
298 } elseif ( isset( $wp_cache_pages[ 'search' ] ) && $wp_cache_pages[ 'search' ] == 1 && isset( $wp_super_cache_query[ 'is_search' ] ) ) { |
|
299 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching search page.', 2 ); |
|
300 return $buffer; |
|
301 } elseif ( isset( $wp_cache_pages[ 'author' ] ) && $wp_cache_pages[ 'author' ] == 1 && isset( $wp_super_cache_query[ 'is_author' ] ) ) { |
|
302 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching author page.', 2 ); |
|
303 return $buffer; |
|
304 } elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && isset( $wp_super_cache_query[ 'is_feed' ] ) ) { |
|
305 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching feed.', 2 ); |
|
306 return $buffer; |
|
307 } |
|
308 |
|
309 if ( !isset( $wp_query ) ) |
|
310 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'wp_cache_ob_callback: WARNING! $query not defined but the plugin has worked around that problem.', 4 ); |
|
311 |
260 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Output buffer callback', 4 ); |
312 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Output buffer callback', 4 ); |
261 |
313 |
262 if ( isset( $wp_cache_pages[ 'single' ] ) && $wp_cache_pages[ 'single' ] == 1 && is_single() ) { |
|
263 return $buffer; |
|
264 } elseif ( isset( $wp_cache_pages[ 'pages' ] ) && $wp_cache_pages[ 'pages' ] == 1 && is_page() ) { |
|
265 return $buffer; |
|
266 } elseif ( isset( $wp_cache_pages[ 'archives' ] ) && $wp_cache_pages[ 'archives' ] == 1 && is_archive() ) { |
|
267 return $buffer; |
|
268 } elseif ( isset( $wp_cache_pages[ 'tag' ] ) && $wp_cache_pages[ 'tag' ] == 1 && is_tag() ) { |
|
269 return $buffer; |
|
270 } elseif ( isset( $wp_cache_pages[ 'category' ] ) && $wp_cache_pages[ 'category' ] == 1 && is_category() ) { |
|
271 return $buffer; |
|
272 } elseif ( isset( $wp_cache_pages[ 'frontpage' ] ) && $wp_cache_pages[ 'frontpage' ] == 1 && is_front_page() ) { |
|
273 return $buffer; |
|
274 } elseif ( isset( $wp_cache_pages[ 'home' ] ) && $wp_cache_pages[ 'home' ] == 1 && is_home() ) { |
|
275 return $buffer; |
|
276 } elseif ( isset( $wp_cache_pages[ 'search' ] ) && $wp_cache_pages[ 'search' ] == 1 && is_search() ) { |
|
277 return $buffer; |
|
278 } elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && is_feed() ) { |
|
279 return $buffer; |
|
280 } |
|
281 $buffer = &wp_cache_get_ob( $buffer ); |
314 $buffer = &wp_cache_get_ob( $buffer ); |
282 wp_cache_shutdown_callback(); |
315 wp_cache_shutdown_callback(); |
283 return $buffer; |
316 return $buffer; |
284 } |
317 } |
285 |
318 |
|
319 function wp_cache_append_tag( &$buffer ) { |
|
320 global $wp_cache_gmt_offset, $wp_super_cache_comments; |
|
321 global $cache_enabled, $super_cache_enabled; |
|
322 |
|
323 if ( false == isset( $wp_super_cache_comments ) ) |
|
324 $wp_super_cache_comments = 1; |
|
325 |
|
326 if ( $wp_super_cache_comments == 0 ) |
|
327 return false; |
|
328 |
|
329 $timestamp = gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600))); |
|
330 if ( $cache_enabled || $super_cache_enabled ) { |
|
331 $buffer .= "\n<!-- Cached page generated by WP-Super-Cache on $timestamp -->\n"; |
|
332 } else { |
|
333 $buffer .= "\n<!-- Live page served on $timestamp -->\n"; |
|
334 } |
|
335 } |
|
336 |
|
337 function wp_cache_add_to_buffer( &$buffer, $text ) { |
|
338 global $wp_super_cache_comments; |
|
339 |
|
340 if ( false == isset( $wp_super_cache_comments ) ) |
|
341 $wp_super_cache_comments = 1; |
|
342 |
|
343 if ( $wp_super_cache_comments == 0 ) |
|
344 return false; |
|
345 |
|
346 $buffer .= "\n<!-- $text -->"; |
|
347 } |
286 |
348 |
287 function wp_cache_get_ob(&$buffer) { |
349 function wp_cache_get_ob(&$buffer) { |
288 global $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir; |
350 global $cache_enabled, $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir; |
289 global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression; |
351 global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression; |
290 global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages; |
352 global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages; |
291 global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first, $wp_cache_gmt_offset; |
353 global $wp_cache_404, $gzsize, $supercacheonly; |
292 global $blog_cache_dir, $wp_cache_request_uri, $wp_supercache_cache_list; |
354 global $blog_cache_dir, $wp_cache_request_uri, $wp_supercache_cache_list; |
|
355 global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time; |
|
356 global $wp_cache_is_home, $wp_cache_front_page_checks; |
293 |
357 |
294 $new_cache = true; |
358 $new_cache = true; |
295 $wp_cache_meta = ''; |
359 $wp_cache_meta = ''; |
296 |
360 |
297 /* Mode paranoic, check for closing tags |
361 /* Mode paranoic, check for closing tags |
298 * we avoid caching incomplete files */ |
362 * we avoid caching incomplete files */ |
299 if ( $buffer == '' ) { |
363 if ( $buffer == '' ) { |
300 $new_cache = false; |
364 $new_cache = false; |
301 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { |
365 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { |
302 wp_cache_debug( "Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.", 2 ); |
366 wp_cache_debug( "Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.", 2 ); |
303 $buffer .= "\n<!-- Page not cached by WP Super Cache. Blank Page. Check output buffer usage by plugins. -->\n"; |
367 wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Blank Page. Check output buffer usage by plugins." ); |
304 } |
368 } |
305 } |
369 } |
306 |
370 |
307 if ( $wp_cache_404 && false == apply_filters( 'wpsupercache_404', false ) ) { |
371 if ( $wp_cache_404 && false == apply_filters( 'wpsupercache_404', false ) ) { |
308 $new_cache = false; |
372 $new_cache = false; |
309 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { |
373 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { |
310 wp_cache_debug( "404 file not found not cached", 2 ); |
374 wp_cache_debug( "404 file not found not cached", 2 ); |
311 $buffer .= "\n<!-- Page not cached by WP Super Cache. 404. -->\n"; |
375 wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. 404." ); |
312 } |
376 } |
313 } |
377 } |
314 |
378 |
315 if (!preg_match('/(<\/html>|<\/rss>|<\/feed>)/i',$buffer) ) { |
379 if ( !preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) { |
316 $new_cache = false; |
380 $new_cache = false; |
317 if( false === strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) ) { |
381 if( false === strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) ) { |
318 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { |
382 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) { |
319 wp_cache_debug( "No closing html tag. Not caching.", 2 ); |
383 wp_cache_debug( "No closing html tag. Not caching.", 2 ); |
320 $buffer .= "\n<!-- Page not cached by WP Super Cache. No closing HTML tag. Check your theme. -->\n"; |
384 wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." ); |
321 } |
385 } |
322 } else { |
386 } else { |
323 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "robots.txt detected. Not caching.", 2 ); |
387 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "robots.txt detected. Not caching.", 2 ); |
324 } |
388 } |
325 } |
389 } |
327 if( !$new_cache ) |
391 if( !$new_cache ) |
328 return $buffer; |
392 return $buffer; |
329 |
393 |
330 $duration = wp_cache_microtime_diff($wp_start_time, microtime()); |
394 $duration = wp_cache_microtime_diff($wp_start_time, microtime()); |
331 $duration = sprintf("%0.3f", $duration); |
395 $duration = sprintf("%0.3f", $duration); |
332 $buffer .= "\n<!-- Dynamic page generated in $duration seconds. -->\n"; |
396 wp_cache_add_to_buffer( $buffer, "Dynamic page generated in $duration seconds." ); |
333 |
397 |
334 if( !wp_cache_writers_entry() ) { |
398 if( !wp_cache_writers_entry() ) { |
335 $buffer .= "\n<!-- Page not cached by WP Super Cache. Could not get mutex lock. -->\n"; |
399 wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Could not get mutex lock." ); |
336 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Could not get mutex lock. Not caching.", 1 ); |
400 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Could not get mutex lock. Not caching.", 1 ); |
337 return $buffer; |
401 return $buffer; |
338 } |
402 } |
339 |
403 |
|
404 if ( $wp_cache_not_logged_in && is_feed() ) { |
|
405 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Feed detected. Writing legacy cache files.", 5 ); |
|
406 $wp_cache_not_logged_in = false; |
|
407 } |
|
408 |
|
409 $home_url = parse_url( trailingslashit( get_bloginfo( 'url' ) ) ); |
|
410 |
340 $dir = get_current_url_supercache_dir(); |
411 $dir = get_current_url_supercache_dir(); |
341 $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]); |
412 $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]); |
342 if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) { |
413 if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) { |
343 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Supercache disabled: GET or feed detected or disabled by config.", 2 ); |
414 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Supercache disabled: GET or feed detected or disabled by config.", 2 ); |
344 $super_cache_enabled = false; |
415 $super_cache_enabled = false; |
345 } |
416 } |
346 |
417 |
347 $tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp'; |
418 $tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp'; |
348 |
419 |
349 // Don't create wp-cache files for anon users |
|
350 $supercacheonly = false; |
420 $supercacheonly = false; |
351 if( $super_cache_enabled && wp_cache_get_cookies_values() == '' ) { |
421 if( $super_cache_enabled ) { |
352 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Anonymous user detected. Only creating Supercache file.", 3 ); |
422 if ( wp_cache_get_cookies_values() == '' && empty( $_GET ) ) { |
353 $supercacheonly = true; |
423 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Anonymous user detected. Only creating Supercache file.", 3 ); |
354 } |
424 $supercacheonly = true; |
355 |
425 } |
356 if( !$supercacheonly ) { |
426 } |
357 if ( !@file_exists( $blog_cache_dir . $cache_filename ) || ( @file_exists( $blog_cache_dir . $cache_filename ) && ( time() - @filemtime( $blog_cache_dir . $cache_filename ) ) > 5 ) ) { |
427 |
|
428 $cache_error = ''; |
|
429 if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() != '' ) { |
|
430 $super_cache_enabled = false; |
|
431 $cache_enabled = false; |
|
432 $cache_error = 'Not caching requests by known users. (See Advanced Settings page)'; |
|
433 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Not caching for known user.', 5 ); |
|
434 } |
|
435 |
|
436 if ( $wp_cache_object_cache ) { // half on mode when using the object cache |
|
437 if ( wp_cache_get_cookies_values() != '' ) { |
|
438 $cache_enabled = false; |
|
439 $cache_error = 'Known User and using object. Only anonymous users cached.'; |
|
440 } |
|
441 $super_cache_enabled = false; |
|
442 $supercacheonly = false; |
|
443 wp_cache_init(); // PHP5 destroys objects during shutdown |
|
444 } |
|
445 |
|
446 if ( !$cache_enabled ) { |
|
447 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Cache is not enabled. Sending buffer to browser.', 5 ); |
|
448 wp_cache_writers_exit(); |
|
449 wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Check your settings page. $cache_error" ); |
|
450 return $buffer; |
|
451 } |
|
452 |
|
453 if( @is_dir( $dir ) == false ) |
|
454 @wp_mkdir_p( $dir ); |
|
455 |
|
456 $fr = $fr2 = $gz = false; |
|
457 // Open wp-cache cache file |
|
458 if ( !$supercacheonly ) { |
|
459 if ( false == $wp_cache_object_cache ) { |
358 $fr = @fopen($tmp_wpcache_filename, 'w'); |
460 $fr = @fopen($tmp_wpcache_filename, 'w'); |
359 if (!$fr) { |
461 if (!$fr) { |
360 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename, 1 ); |
462 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename, 1 ); |
361 $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename . " -->\n"; |
463 wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename ); |
|
464 wp_cache_writers_exit(); |
362 return $buffer; |
465 return $buffer; |
363 } |
466 } |
364 } |
467 } |
365 } |
468 } else { |
366 if( $super_cache_enabled ) { |
|
367 $user_info = wp_cache_get_cookies_values(); |
469 $user_info = wp_cache_get_cookies_values(); |
368 $do_cache = apply_filters( 'do_createsupercache', $user_info ); |
470 $do_cache = apply_filters( 'do_createsupercache', $user_info ); |
369 if( $user_info == '' || $do_cache === true ) { |
471 if ( $super_cache_enabled && ( $user_info == '' || $do_cache === true ) ) { |
370 |
472 |
371 if( @is_dir( $dir ) == false ) |
473 $cache_fname = $dir . supercache_filename(); |
372 @wp_mkdir_p( $dir ); |
|
373 |
|
374 $cache_fname = "{$dir}index.html"; |
|
375 $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; |
474 $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; |
376 if ( !@file_exists( $cache_fname ) || ( @file_exists( $cache_fname ) && ( time() - @filemtime( $cache_fname ) ) > 5 ) ) { |
475 $fr2 = @fopen( $tmp_cache_filename, 'w' ); |
377 $fr2 = @fopen( $tmp_cache_filename, 'w' ); |
476 if ( !$fr2 ) { |
378 if (!$fr2) { |
477 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 ); |
379 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 ); |
478 wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) ); |
380 $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . " -->\n"; |
479 @fclose( $fr ); |
|
480 @unlink( $tmp_wpcache_filename ); |
|
481 wp_cache_writers_exit(); |
|
482 return $buffer; |
|
483 } elseif ( $cache_compression ) { |
|
484 $gz = @fopen( $tmp_cache_filename . ".gz", 'w'); |
|
485 if (!$gz) { |
|
486 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 ); |
|
487 wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz" ); |
381 @fclose( $fr ); |
488 @fclose( $fr ); |
382 @unlink( $tmp_wpcache_filename ); |
489 @unlink( $tmp_wpcache_filename ); |
|
490 @fclose( $fr2 ); |
|
491 @unlink( $tmp_cache_filename ); |
|
492 wp_cache_writers_exit(); |
383 return $buffer; |
493 return $buffer; |
384 } elseif( $cache_compression ) { |
494 } |
385 $gz = @fopen( $tmp_cache_filename . ".gz", 'w'); |
495 } |
386 if (!$gz) { |
496 } |
387 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 ); |
497 } |
388 $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz -->\n"; |
498 |
389 @fclose( $fr ); |
499 $added_cache = 0; |
390 @unlink( $tmp_wpcache_filename ); |
500 $oc_key = get_oc_key(); |
391 @fclose( $fr2 ); |
501 if ( preg_match( '/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $buffer ) ) { //Dynamic content |
392 @unlink( $tmp_cache_filename ); |
|
393 return $buffer; |
|
394 } |
|
395 } |
|
396 } |
|
397 } |
|
398 } |
|
399 |
|
400 if (preg_match('/<!--mclude|<!--mfunc/', $buffer)) { //Dynamic content |
|
401 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Dynamic content found in buffer.", 4 ); |
502 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Dynamic content found in buffer.", 4 ); |
402 $store = preg_replace('|<!--mclude (.*?)-->(.*?)<!--/mclude-->|is', |
503 $store = preg_replace('|<!--mclude (.*?)-->(.*?)<!--/mclude-->|is', |
403 "<!--mclude-->\n<?php include_once('" . ABSPATH . "$1'); ?>\n<!--/mclude-->", $buffer); |
504 "<!--mclude-->\n<?php include_once('" . ABSPATH . "$1'); ?>\n<!--/mclude-->", $buffer); |
404 $store = preg_replace('|<!--mfunc (.*?)-->(.*?)<!--/mfunc-->|is', |
505 $store = preg_replace('|<!--mfunc (.*?)-->(.*?)<!--/mfunc-->|is', |
405 "<!--mfunc-->\n<?php $1 ;?>\n<!--/mfunc-->", $store); |
506 "<!--mfunc-->\n<?php $1 ;?>\n<!--/mfunc-->", $store); |
406 $store = apply_filters( 'wpsupercache_buffer', $store ); |
507 $store = preg_replace('|<!--dynamic-cached-content-->(.*?)<!--(.*?)--><!--/dynamic-cached-content-->|is', |
|
508 "<!--dynamic-cached-content-->\n<?php$2?>\n<!--/dynamic-cached-content-->", $store); |
407 $wp_cache_meta[ 'dynamic' ] = true; |
509 $wp_cache_meta[ 'dynamic' ] = true; |
408 /* Clean function calls in tag */ |
510 /* Clean function calls in tag */ |
409 $buffer = preg_replace('|<!--mclude (.*?)-->|is', '<!--mclude-->', $buffer); |
511 $buffer = preg_replace('|<!--mclude (.*?)-->|is', '<!--mclude-->', $buffer); |
410 $buffer = preg_replace('|<!--mfunc (.*?)-->|is', '<!--mfunc-->', $buffer); |
512 $buffer = preg_replace('|<!--mfunc (.*?)-->|is', '<!--mfunc-->', $buffer); |
411 if( $fr ) |
513 $buffer = preg_replace('|<!--dynamic-cached-content-->(.*?)<!--(.*?)--><!--/dynamic-cached-content-->|is', |
412 fputs($fr, $store); |
514 "<!--dynamic-cached-content-->$1<!--/dynamic-cached-content-->", $buffer); |
413 if( $fr2 ) |
515 $store = apply_filters( 'wpsupercache_buffer', $store ); |
414 fputs($fr2, $store . '<!-- super cache -->' ); |
516 // Append WP Super Cache or Live page comment tag |
415 if( $gz ) |
517 wp_cache_append_tag($buffer); |
416 fputs($gz, gzencode( $store . '<!-- super cache gz -->', 1, FORCE_GZIP ) ); |
518 wp_cache_append_tag($store); |
|
519 global $wp_super_cache_late_init; |
|
520 if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) |
|
521 wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.' ); |
|
522 |
|
523 if ( false == $wp_cache_object_cache ) { |
|
524 if( $fr ) { // legacy caching |
|
525 fputs($fr, $store); |
|
526 } elseif ( isset( $fr2 ) ) { // supercache active |
|
527 $php_fname = "{$dir}" . supercache_filename() . ".php"; |
|
528 $tmp_php_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; |
|
529 $php_fd = @fopen( $tmp_php_filename, 'w' ); |
|
530 if ( !$php_fd ) { |
|
531 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_php_filename ), 1 ); |
|
532 wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache couldn't write to: " . str_replace( ABSPATH, '', $tmp_php_filename ) ); |
|
533 @fclose( $php_fd ); |
|
534 @unlink( $tmp_php_filename ); |
|
535 wp_cache_writers_exit(); |
|
536 return $buffer; |
|
537 } |
|
538 fputs( $php_fd, $store ); |
|
539 } |
|
540 } else { |
|
541 wp_cache_set( $oc_key, $store, 'supercache', $cache_max_time ); |
|
542 } |
|
543 if ( $cache_compression && $wp_cache_gzip_encoding ) { |
|
544 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Gzipping dynamic buffer.", 5 ); |
|
545 wp_cache_add_to_buffer( $buffer, "Compression = gzip" ); |
|
546 $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); |
|
547 $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); |
|
548 } |
417 } else { |
549 } else { |
418 $buffer = apply_filters( 'wpsupercache_buffer', $buffer ); |
550 $buffer = apply_filters( 'wpsupercache_buffer', $buffer ); |
419 $buffer .= "<!-- Cached page generated by WP-Super-Cache on " . gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600))) . " -->\n"; |
551 // Append WP Super Cache or Live page comment tag |
420 |
552 wp_cache_append_tag($buffer); |
421 if( $gz || $wp_cache_gzip_encoding ) { |
553 if( $gz || $wp_cache_gzip_encoding ) { |
422 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Gzipping buffer.", 5 ); |
554 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Gzipping buffer.", 5 ); |
423 $gzdata = gzencode( $buffer . "<!-- Compression = gzip -->", 3, FORCE_GZIP ); |
555 wp_cache_add_to_buffer( $buffer, "Compression = gzip" ); |
424 $gzsize = strlen($gzdata); |
556 $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); |
|
557 $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); |
425 } |
558 } |
426 if ($wp_cache_gzip_encoding) { |
559 if ($wp_cache_gzip_encoding) { |
427 $wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; |
560 $wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; |
428 $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie'; |
561 $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie'; |
429 // Return uncompressed data & store compressed for later use |
562 // Return uncompressed data & store compressed for later use |
430 if( $fr ) { |
563 if ( false == $wp_cache_object_cache ) { |
431 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 ); |
564 if( $fr ) { |
432 fputs($fr, $gzdata); |
565 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 ); |
|
566 fputs($fr, $gzdata); |
|
567 } |
|
568 } elseif ( $cache_enabled ) { |
|
569 wp_cache_set( $oc_key . ".gz", $gzdata, 'supercache', $cache_max_time ); |
|
570 $added_cache = 1; |
433 } |
571 } |
434 } else { // no compression |
572 } else { // no compression |
435 $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Cookie'; |
573 $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Cookie'; |
436 if( $fr ) { |
574 if ( false == $wp_cache_object_cache ) { |
437 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file.", 5 ); |
575 if( $fr ) { |
438 fputs($fr, $buffer); |
576 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file.", 5 ); |
|
577 fputs($fr, $buffer); |
|
578 } |
|
579 } elseif ( $cache_enabled ) { |
|
580 wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time ); |
|
581 $added_cache = 1; |
|
582 } |
|
583 } |
|
584 if ( false == $wp_cache_object_cache ) { |
|
585 if( $fr2 ) { |
|
586 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing non-gzipped buffer to supercache file.", 5 ); |
|
587 wp_cache_add_to_buffer( $buffer, "super cache" ); |
|
588 fputs($fr2, $buffer ); |
|
589 } |
|
590 if( $gz ) { |
|
591 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzipped buffer to supercache file.", 5 ); |
|
592 fwrite($gz, $gzdata ); |
|
593 } |
|
594 } |
|
595 } |
|
596 $new_cache = true; |
|
597 if ( false == $wp_cache_object_cache ) { |
|
598 if( $fr ) { |
|
599 $supercacheonly = false; |
|
600 fclose($fr); |
|
601 if ( filesize( $tmp_wpcache_filename ) == 0 ) { |
|
602 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Warning! The file $tmp_wpcache_filename was empty. Did not rename to {$blog_cache_dir}{$cache_filename}", 5 ); |
|
603 @unlink( $tmp_wpcache_filename ); |
|
604 } else { |
|
605 if ( !rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename ) ) { |
|
606 if ( false == is_dir( $blog_cache_dir ) ) |
|
607 @wp_mkdir_p( $blog_cache_dir ); |
|
608 unlink( $blog_cache_dir . $cache_filename ); |
|
609 rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename ); |
|
610 } |
|
611 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp wp-cache file to {$blog_cache_dir}$cache_filename", 5 ); |
|
612 $added_cache = 1; |
439 } |
613 } |
440 } |
614 } |
441 if( $fr2 ) { |
615 if( $fr2 ) { |
442 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing non-gzipped buffer to supercache file.", 5 ); |
616 fclose($fr2); |
443 fputs($fr2, $buffer . '<!-- super cache -->' ); |
617 if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() && !( $wp_cache_is_home ) ) { |
|
618 wp_cache_writers_exit(); |
|
619 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Warning! Not writing another page to front page cache.", 1 ); |
|
620 return $buffer; |
|
621 } elseif ( filesize( $tmp_cache_filename ) == 0 ) { |
|
622 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Warning! The file $tmp_cache_filename was empty. Did not rename to {$cache_fname}", 5 ); |
|
623 @unlink( $tmp_cache_filename ); |
|
624 } else { |
|
625 if ( !@rename( $tmp_cache_filename, $cache_fname ) ) { |
|
626 @unlink( $cache_fname ); |
|
627 @rename( $tmp_cache_filename, $cache_fname ); |
|
628 } |
|
629 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp supercache file to $cache_fname", 5 ); |
|
630 $added_cache = 1; |
|
631 } |
|
632 } |
|
633 if ( isset( $php_fd ) ) { |
|
634 fclose( $php_fd ); |
|
635 if ( $php_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() . '.php' && !( $wp_cache_is_home ) ) { |
|
636 wp_cache_writers_exit(); |
|
637 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Warning! Not writing another page to front page cache.", 1 ); |
|
638 return $buffer; |
|
639 } elseif ( filesize( $tmp_php_filename ) == 0 ) { |
|
640 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Warning! The file $tmp_php_filename was empty. Did not rename to {$php_fname}", 5 ); |
|
641 @unlink( $tmp_php_filename ); |
|
642 } else { |
|
643 if ( !@rename( $tmp_php_filename, $php_fname ) ) { |
|
644 @unlink( $php_fname ); |
|
645 @rename( $tmp_php_filename, $php_fname ); |
|
646 } |
|
647 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp supercache file to $php_fname", 5 ); |
|
648 $added_cache = 1; |
|
649 } |
444 } |
650 } |
445 if( $gz ) { |
651 if( $gz ) { |
446 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzipped buffer to supercache file.", 5 ); |
652 fclose($gz); |
447 fwrite($gz, $gzdata ); |
653 if ( filesize( $tmp_cache_filename . '.gz' ) == 0 ) { |
448 } |
654 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5 ); |
449 $buffer .= $log; |
655 @unlink( $tmp_cache_filename . '.gz' ); |
450 } |
656 } else { |
451 $new_cache = true; |
657 if ( !@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) { |
452 $added_cache = 0; |
658 @unlink( $cache_fname . '.gz' ); |
453 if( $fr ) { |
659 @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ); |
454 $supercacheonly = false; |
660 } |
455 fclose($fr); |
661 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp supercache gz file to {$cache_fname}.gz", 5 ); |
456 if( !rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename ) ) { |
662 $added_cache = 1; |
457 unlink( $blog_cache_dir . $cache_filename ); |
663 } |
458 rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename ); |
664 } |
459 } |
|
460 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp wp-cache file to {$blog_cache_dir}$cache_filename", 5 ); |
|
461 $added_cache = 1; |
|
462 } |
|
463 if( $fr2 ) { |
|
464 fclose($fr2); |
|
465 if( !@rename( $tmp_cache_filename, $cache_fname ) ) { |
|
466 @unlink( $cache_fname ); |
|
467 @rename( $tmp_cache_filename, $cache_fname ); |
|
468 } |
|
469 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp supercache file to $cache_fname", 5 ); |
|
470 $added_cache = 1; |
|
471 } |
|
472 if( $gz ) { |
|
473 fclose($gz); |
|
474 if( !@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) { |
|
475 @unlink( $cache_fname . '.gz' ); |
|
476 @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ); |
|
477 } |
|
478 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Renamed temp supercache gz file to {$cache_fname}.gz", 5 ); |
|
479 $added_cache = 1; |
|
480 } |
665 } |
481 if ( $added_cache && isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) { |
666 if ( $added_cache && isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) { |
482 update_option( 'wpsupercache_count', ( get_option( 'wpsupercache_count' ) + 1 ) ); |
667 update_option( 'wpsupercache_count', ( get_option( 'wpsupercache_count' ) + 1 ) ); |
483 $last_urls = (array)get_option( 'supercache_last_cached' ); |
668 $last_urls = (array)get_option( 'supercache_last_cached' ); |
484 if ( count( $last_urls ) >= 10 ) |
669 if ( count( $last_urls ) >= 10 ) |
485 $last_urls = array_slice( $last_urls, 1, 9 ); |
670 $last_urls = array_slice( $last_urls, 1, 9 ); |
486 $last_urls[] = array( 'url' => $_SERVER[ 'REQUEST_URI' ], 'date' => date( 'Y-m-d H:i:s' ) ); |
671 $last_urls[] = array( 'url' => $_SERVER[ 'REQUEST_URI' ], 'date' => date( 'Y-m-d H:i:s' ) ); |
487 update_option( 'supercache_last_cached', $last_urls ); |
672 update_option( 'supercache_last_cached', $last_urls ); |
488 } |
673 } |
489 wp_cache_writers_exit(); |
674 wp_cache_writers_exit(); |
490 if ( !headers_sent() && isset( $wp_cache_gzip_first ) && 1 == $wp_cache_gzip_first && $wp_cache_gzip_encoding && $gzdata) { |
675 if ( !headers_sent() && $wp_cache_gzip_encoding && $gzdata) { |
491 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzip content headers. Sending buffer to browser", 5 ); |
676 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzip content headers. Sending buffer to browser", 5 ); |
492 header( 'Content-Encoding: ' . $wp_cache_gzip_encoding ); |
677 header( 'Content-Encoding: ' . $wp_cache_gzip_encoding ); |
493 header( 'Vary: Accept-Encoding, Cookie' ); |
678 header( 'Vary: Accept-Encoding, Cookie' ); |
494 header( 'Content-Length: ' . $gzsize ); |
679 header( 'Content-Length: ' . $gzsize ); |
495 return $gzdata; |
680 return $gzdata; |
719 $comment = get_comment($comment_id, ARRAY_A); |
937 $comment = get_comment($comment_id, ARRAY_A); |
720 if ( $status != 'NA' ) { |
938 if ( $status != 'NA' ) { |
721 $comment[ 'old_comment_approved' ] = $comment[ 'comment_approved' ]; |
939 $comment[ 'old_comment_approved' ] = $comment[ 'comment_approved' ]; |
722 $comment[ 'comment_approved' ] = $status; |
940 $comment[ 'comment_approved' ] = $status; |
723 } |
941 } |
|
942 |
|
943 if ( ( $status == 'trash' || $status == 'spam' ) && $comment[ 'old_comment_approved' ] != 1 ) { |
|
944 // don't modify cache if moderated comments are trashed or spammed |
|
945 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated comment deleted or spammed. Don't delete any cache files.", 4 ); |
|
946 define( 'DONOTDELETECACHE', 1 ); |
|
947 return wp_cache_post_id(); |
|
948 } |
724 $postid = $comment['comment_post_ID']; |
949 $postid = $comment['comment_post_ID']; |
725 // Do nothing if comment is not moderated |
950 // Do nothing if comment is not moderated |
726 // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world |
951 // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world |
727 if ( !preg_match('/wp-admin\//', $wp_cache_request_uri) ) { |
952 if ( !preg_match('/wp-admin\//', $wp_cache_request_uri) ) { |
728 if ( $comment['comment_approved'] == 'delete' && ( isset( $comment[ 'old_comment_approved' ] ) && $comment[ 'old_comment_approved' ] == 0 ) ) { // do nothing if moderated comments are deleted |
953 if ( $comment['comment_approved'] == 'delete' && ( isset( $comment[ 'old_comment_approved' ] ) && $comment[ 'old_comment_approved' ] == 0 ) ) { // do nothing if moderated comments are deleted |
729 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated comment deleted. Don't delete any cache files.", 4 ); |
954 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated comment deleted. Don't delete any cache files.", 4 ); |
|
955 define( 'DONOTDELETECACHE', 1 ); |
730 return $postid; |
956 return $postid; |
731 } elseif ( $comment['comment_approved'] == 'spam' ) { |
957 } elseif ( $comment['comment_approved'] == 'spam' ) { |
732 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Spam comment. Don't delete any cache files.", 4 ); |
958 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Spam comment. Don't delete any cache files.", 4 ); |
|
959 define( 'DONOTDELETECACHE', 1 ); |
733 return $postid; |
960 return $postid; |
734 } elseif( $comment['comment_approved'] == '0' ) { |
961 } elseif( $comment['comment_approved'] == '0' ) { |
735 if ( $comment[ 'content_type' ] == '' ) { |
962 if ( $comment[ 'content_type' ] == '' ) { |
736 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated comment. Don't delete supercache file until comment approved.", 4 ); |
963 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated comment. Don't delete supercache file until comment approved.", 4 ); |
737 $super_cache_enabled = 0; // don't remove the super cache static file until comment is approved |
964 $super_cache_enabled = 0; // don't remove the super cache static file until comment is approved |
|
965 define( 'DONOTDELETECACHE', 1 ); |
738 } else { |
966 } else { |
739 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated ping or trackback. Not deleting cache files..", 4 ); |
967 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Moderated ping or trackback. Not deleting cache files..", 4 ); |
|
968 define( 'DONOTDELETECACHE', 1 ); |
740 return $postid; |
969 return $postid; |
741 } |
970 } |
742 } |
971 } |
743 } |
972 } |
744 // We must check it up again due to WP bugs calling two different actions |
973 // We must check it up again due to WP bugs calling two different actions |
745 // for delete, for example both wp_set_comment_status and delete_comment |
974 // for delete, for example both wp_set_comment_status and delete_comment |
746 // are called when deleting a comment |
975 // are called when deleting a comment |
747 if ($postid > 0) { |
976 if ($postid > 0) { |
748 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Post $postid changed. Update cache.", 4 ); |
977 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Post $postid changed. Update cache.", 4 ); |
749 return wp_cache_post_change($postid); |
978 return wp_cache_post_change( $postid ); |
|
979 } elseif ( $_GET[ 'delete_all' ] != 'Empty Trash' && $_GET[ 'delete_all2' ] != 'Empty Spam' ) { |
|
980 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Unknown post changed. Update cache.", 4 ); |
|
981 return wp_cache_post_change( wp_cache_post_id() ); |
|
982 } |
|
983 } |
|
984 |
|
985 /* Used by wp_update_nav_menu action to clear current blog's cache files when navigation menu is modified */ |
|
986 function wp_cache_clear_cache_on_menu() { |
|
987 global $wpdb; |
|
988 wp_cache_clear_cache( $wpdb->blogid ); |
|
989 } |
|
990 |
|
991 /* Clear out the cache directory. */ |
|
992 function wp_cache_clear_cache( $blog_id = 0 ) { |
|
993 global $cache_path, $wp_cache_object_cache; |
|
994 if ( $wp_cache_object_cache ) { |
|
995 reset_oc_version(); |
750 } else { |
996 } else { |
751 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Unknown post changed. Update cache.", 4 ); |
997 if ( $blog_id == 0 ) { |
752 return wp_cache_post_change(wp_cache_post_id()); |
998 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Clearing all cached files in wp_cache_clear_cache()", 4 ); |
753 } |
999 prune_super_cache( $cache_path . 'supercache/', true ); |
754 } |
1000 prune_super_cache( $cache_path, true ); |
755 |
1001 } else { |
756 /* Clear out the cache directory. */ |
1002 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Clearing all cached files for blog $blog_id in wp_cache_clear_cache()", 4 ); |
757 function wp_cache_clear_cache() { |
1003 prune_super_cache( get_supercache_dir( $blog_id ), true ); |
758 global $cache_path; |
1004 prune_super_cache( $cache_path . 'blogs/', true ); |
759 prune_super_cache( $cache_path . 'supercache/', true ); |
1005 } |
760 prune_super_cache( $cache_path, true ); |
1006 } |
761 } |
1007 } |
762 |
1008 |
|
1009 /* check if we want to clear out all cached files on post updates, otherwise call standard wp_cache_post_change() */ |
763 function wp_cache_post_edit($post_id) { |
1010 function wp_cache_post_edit($post_id) { |
764 global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir; |
1011 global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir; |
|
1012 static $last_post_edited = -1; |
|
1013 |
|
1014 if ( $post_id == $last_post_edited ) { |
|
1015 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_edit: Already processed post $post_id.", 4 ); |
|
1016 return $post_id; |
|
1017 } |
|
1018 |
|
1019 $post = get_post( $post_id ); |
|
1020 // Some users are inexplicibly seeing this error on scheduled posts. |
|
1021 // define this constant to disable the post status check. |
|
1022 if ( false == defined( 'WPSCFORCEUPDATE' ) && $post->post_status != 'publish' ) { |
|
1023 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_edit: draft post, not deleting any cache files.", 4 ); |
|
1024 return $post_id; |
|
1025 } |
|
1026 |
|
1027 // we want to process the post again just in case it becomes published before the second time this function is called. |
|
1028 $last_post_edited = $post_id; |
765 if( $wp_cache_clear_on_post_edit ) { |
1029 if( $wp_cache_clear_on_post_edit ) { |
766 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Clearing cache $blog_cache_dir and {$cache_path}supercache/ on post edit per config.", 2 ); |
1030 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_edit: Clearing cache $blog_cache_dir and {$cache_path}supercache/ on post edit per config.", 2 ); |
767 prune_super_cache( $blog_cache_dir, true ); |
1031 if ( $wp_cache_object_cache ) { |
768 prune_super_cache( $cache_path . 'supercache/', true ); |
1032 reset_oc_version(); |
|
1033 } else { |
|
1034 prune_super_cache( $blog_cache_dir, true ); |
|
1035 prune_super_cache( get_supercache_dir(), true ); |
|
1036 } |
769 } else { |
1037 } else { |
770 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Clearing cache for post $post_id on post edit.", 2 ); |
1038 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_edit: Clearing cache for post $post_id on post edit.", 2 ); |
771 wp_cache_post_change( $post_id ); |
1039 wp_cache_post_change( $post_id ); |
772 } |
1040 } |
773 } |
1041 } |
774 |
1042 |
775 function wp_cache_post_id_gc( $siteurl, $post_id ) { |
1043 function wp_cache_post_id_gc( $siteurl, $post_id, $all = 'all' ) { |
776 global $cache_path; |
1044 global $cache_path, $wp_cache_object_cache, $wp_cache_refresh_single_only; |
777 |
1045 |
|
1046 if ( $wp_cache_object_cache ) |
|
1047 reset_oc_version(); |
|
1048 |
778 $post_id = intval( $post_id ); |
1049 $post_id = intval( $post_id ); |
779 if( $post_id == 0 ) |
1050 if( $post_id == 0 ) |
780 return; |
1051 return; |
781 |
1052 |
782 $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( $post_id ) ) ); |
1053 $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( $post_id ) ) ); |
783 $dir = $cache_path . 'supercache/' . $siteurl; |
1054 $dir = get_current_url_supercache_dir( $post_id ); |
784 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_id_gc clearing cache in $dir{$permalink}.", 4 ); |
1055 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_id_gc post_id: $post_id " . post_permalink( $post_id ) . " clearing cache in $dir.", 4 ); |
785 prune_super_cache( $dir . $permalink, true, true ); |
1056 if ( $all == 'all' ) { |
786 @rmdir( $dir . $permalink ); |
1057 prune_super_cache( $dir, true, true ); |
787 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_id_gc clearing cache in {$dir}page/.", 4 ); |
1058 do_action( 'gc_cache', 'prune', $permalink ); |
788 prune_super_cache( $dir . 'page/', true ); |
1059 @rmdir( $dir ); |
789 } |
1060 } else { |
790 |
1061 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_id_gc clearing cached index files in $dir.", 4 ); |
791 function wp_cache_post_change($post_id) { |
1062 prune_super_cache( $dir, true, true ); |
792 global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $blogcacheid; |
1063 do_action( 'gc_cache', 'prune', $permalink ); |
|
1064 } |
|
1065 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_id_gc clearing cache in {$dir}/page/.", 4 ); |
|
1066 prune_super_cache( $dir . '/page/', true ); |
|
1067 $supercache_home = get_supercache_dir(); |
|
1068 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_id_gc clearing cache in {$supercache_home}/page/.", 4 ); |
|
1069 prune_super_cache( $supercache_home . '/page/', true ); |
|
1070 do_action( 'gc_cache', 'prune', '/page/' ); |
|
1071 } |
|
1072 |
|
1073 function wp_cache_post_change( $post_id ) { |
|
1074 global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $blogcacheid, $wp_cache_refresh_single_only; |
793 static $last_processed = -1; |
1075 static $last_processed = -1; |
794 |
1076 |
795 if ($post_id == $last_processed) return $post_id; |
1077 if ( $post_id == $last_processed ) { |
|
1078 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_change: Already processed post $post_id.", 4 ); |
|
1079 return $post_id; |
|
1080 } |
|
1081 $post = get_post( $post_id ); |
|
1082 // Some users are inexplicibly seeing this error on scheduled posts. |
|
1083 // define this constant to disable the post status check. |
|
1084 if ( false == defined( 'WPSCFORCEUPDATE' ) && $post->post_status != 'publish' ) { |
|
1085 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_change: draft post, not deleting any cache files.", 4 ); |
|
1086 return $post_id; |
|
1087 } |
796 $last_processed = $post_id; |
1088 $last_processed = $post_id; |
|
1089 |
797 if( !wp_cache_writers_entry() ) |
1090 if( !wp_cache_writers_entry() ) |
798 return $post_id; |
1091 return $post_id; |
799 |
1092 |
|
1093 if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only && ( strpos( $_SERVER[ 'HTTP_REFERER' ], 'edit-comments.php' ) || strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) ) { |
|
1094 if ( defined( 'DONOTDELETECACHE' ) ) { |
|
1095 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_change: comment detected and it's moderated or spam. Not deleting cached files.", 4 ); |
|
1096 return $post_id; |
|
1097 } else { |
|
1098 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_change: comment detected. only deleting post page.", 4 ); |
|
1099 $all = false; |
|
1100 } |
|
1101 } else { |
|
1102 $all = true; |
|
1103 } |
|
1104 |
|
1105 if ( $wp_cache_object_cache ) |
|
1106 reset_oc_version(); |
|
1107 |
800 $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) ); |
1108 $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) ); |
801 if( $super_cache_enabled ) { |
1109 if( $super_cache_enabled ) { |
|
1110 $dir = get_supercache_dir(); |
802 $siteurl = trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', get_option( 'home' ) ) ) ) ); |
1111 $siteurl = trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', get_option( 'home' ) ) ) ) ); |
803 // make sure the front page has a rebuild file |
1112 // make sure the front page has a rebuild file |
804 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Post change: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4 ); |
|
805 prune_super_cache( $cache_path . 'supercache/' . $siteurl . 'index.html', true, true ); |
|
806 prune_super_cache( $cache_path . 'supercache/' . $siteurl . 'index.html.gz', true, true ); |
|
807 wp_cache_post_id_gc( $siteurl, $post_id ); |
1113 wp_cache_post_id_gc( $siteurl, $post_id ); |
808 if( get_option( 'show_on_front' ) == 'page' ) { |
1114 if ( $all == true ) { |
809 wp_cache_post_id_gc( $siteurl, get_option( 'page_on_front' ) ); |
1115 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Post change: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4 ); |
810 wp_cache_post_id_gc( $siteurl, get_option( 'page_for_posts' ) ); |
1116 $files_to_check = get_all_supercache_filenames( $dir ); |
|
1117 foreach( $files_to_check as $cache_file ) { |
|
1118 prune_super_cache( $dir . $cache_file, true, true ); |
|
1119 } |
|
1120 do_action( 'gc_cache', 'prune', 'homepage' ); |
|
1121 } |
|
1122 if( $all == true && get_option( 'show_on_front' ) == 'page' ) { |
|
1123 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 ); |
|
1124 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 ); |
|
1125 wp_cache_post_id_gc( $siteurl, get_option( 'page_on_front' ), 'single' ); |
|
1126 $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( get_option( 'page_for_posts' ) ) ) ); |
|
1127 $files_to_check = get_all_supercache_filenames( $dir . $permalink ); |
|
1128 foreach( $files_to_check as $cache_file ) { |
|
1129 prune_super_cache( $dir . $permalink . $cache_file, true, true ); |
|
1130 } |
|
1131 do_action( 'gc_cache', 'prune', $permalink ); |
811 } |
1132 } |
812 } |
1133 } |
813 |
1134 |
814 $matches = array(); |
1135 $matches = array(); |
815 if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) { |
1136 if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) { |
860 if (isset( $_GET[ 'p' ] ) && $_GET['p'] > 0) return $_GET['p']; |
1192 if (isset( $_GET[ 'p' ] ) && $_GET['p'] > 0) return $_GET['p']; |
861 if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p']; |
1193 if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p']; |
862 return 0; |
1194 return 0; |
863 } |
1195 } |
864 |
1196 |
|
1197 function maybe_stop_gc( $flag ) { |
|
1198 |
|
1199 if ( @file_exists( $flag ) ) { |
|
1200 if ( time() - filemtime( $flag ) > 3600 ) { |
|
1201 @unlink( $flag ); |
|
1202 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "maybe_stop_gc: GC flag found but deleted because it's older than 3600 seconds.", 5 ); |
|
1203 return false; |
|
1204 } else { |
|
1205 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'maybe_stop_gc: GC flag found. GC cancelled.', 5 ); |
|
1206 return true; |
|
1207 } |
|
1208 } else { |
|
1209 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'maybe_stop_gc: GC flag not found. GC will go ahead..', 5 ); |
|
1210 return false; |
|
1211 } |
|
1212 } |
|
1213 function get_gc_flag() { |
|
1214 global $cache_path; |
|
1215 return $cache_path . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . "_wp_cache_gc.txt"; |
|
1216 } |
|
1217 |
865 function wp_cache_gc_cron() { |
1218 function wp_cache_gc_cron() { |
866 global $file_prefix, $cache_max_time; |
1219 global $file_prefix, $cache_max_time, $cache_gc_email_me, $cache_time_interval; |
|
1220 |
|
1221 $msg = ''; |
|
1222 if ( $cache_max_time == 0 ) { |
|
1223 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Cache garbage collection disabled because cache expiry time is zero.', 5 ); |
|
1224 return false; |
|
1225 } |
|
1226 |
|
1227 $gc_flag = get_gc_flag(); |
|
1228 if ( maybe_stop_gc( $gc_flag ) ) { |
|
1229 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'GC flag found. GC cancelled.', 5 ); |
|
1230 return false; |
|
1231 } |
|
1232 |
|
1233 update_option( 'wpsupercache_gc_time', time() ); |
|
1234 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_gc_cron: Set GC Flag. ($gc_flag)", 5 ); |
|
1235 $fp = @fopen( $gc_flag, 'w' ); |
|
1236 @fclose( $fp ); |
|
1237 |
867 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Cache garbage collection.', 5 ); |
1238 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Cache garbage collection.', 5 ); |
868 |
1239 |
869 if( !isset( $cache_max_time ) ) |
1240 if( !isset( $cache_max_time ) ) |
870 $cache_max_time = 600; |
1241 $cache_max_time = 600; |
871 |
1242 |
872 $start = time(); |
1243 $start = time(); |
873 if( !wp_cache_phase2_clean_expired($file_prefix ) ) { |
1244 $num = 0; |
|
1245 if( false === ( $num = wp_cache_phase2_clean_expired( $file_prefix ) ) ) { |
874 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Cache Expiry cron job failed. Probably mutex locked.', 1 ); |
1246 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Cache Expiry cron job failed. Probably mutex locked.', 1 ); |
875 update_option( 'wpsupercache_gc_time', time() - ( $cache_max_time - 10 ) ); // if GC failed then run it again in one minute |
1247 update_option( 'wpsupercache_gc_time', time() - ( $cache_time_interval - 10 ) ); // if GC failed then run it again in one minute |
876 } |
1248 $msg .= __( 'Cache expiry cron job failed. Job will run again in 10 seconds.', 'wp-super-cache' ) . "\n"; |
877 if( time() - $start > 30 ) |
1249 } |
|
1250 if( time() - $start > 30 ) { |
878 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Cache Expiry cron job took more than 30 seconds to execute.\nYou should reduce the Expiry Time in the WP Super Cache admin page\nas you probably have more cache files than your server can handle efficiently.", 1 ); |
1251 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Cache Expiry cron job took more than 30 seconds to execute.\nYou should reduce the Expiry Time in the WP Super Cache admin page\nas you probably have more cache files than your server can handle efficiently.", 1 ); |
|
1252 $msg .= __( 'Cache expiry cron job took more than 30 seconds. You should probably run the garbage collector more often.', 'wp-super-cache' ) . "\n"; |
|
1253 } |
|
1254 |
|
1255 if ( $cache_gc_email_me ) { |
|
1256 if ( $msg != '' ) |
|
1257 $msg = "The following warnings were generated by the WP Super Cache Garbage Collector:\n" . $msg; |
|
1258 |
|
1259 $msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int)$num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector."; |
|
1260 |
|
1261 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] WP Super Cache GC Report', 'wp-super-cache' ), site_url() ), $msg ); |
|
1262 } |
|
1263 @unlink( $gc_flag ); |
|
1264 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'GC completed. GC flag deleted.', 5 ); |
|
1265 schedule_wp_gc( 1 ); |
|
1266 } |
|
1267 |
|
1268 function schedule_wp_gc( $forced = 0 ) { |
|
1269 global $cache_schedule_type, $cache_max_time, $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval; |
|
1270 |
|
1271 if ( false == isset( $cache_time_interval ) ) |
|
1272 $cache_time_interval = 3600; |
|
1273 |
|
1274 if ( false == isset( $cache_schedule_type ) ) { |
|
1275 $cache_schedule_type = 'interval'; |
|
1276 $cache_schedule_interval = $cache_max_time; |
|
1277 } |
|
1278 if ( $cache_schedule_type == 'interval' ) { |
|
1279 if ( !isset( $cache_max_time ) ) |
|
1280 $cache_max_time = 600; |
|
1281 if ( $cache_max_time == 0 ) |
|
1282 return false; |
|
1283 $last_gc = get_option( "wpsupercache_gc_time" ); |
|
1284 |
|
1285 if ( !$last_gc ) { |
|
1286 update_option( 'wpsupercache_gc_time', time() ); |
|
1287 $last_gc = get_option( "wpsupercache_gc_time" ); |
|
1288 } |
|
1289 if ( $forced || ( $last_gc < ( time() - 60 ) ) ) { // Allow up to 60 seconds for the previous job to run |
|
1290 global $wp_cache_shutdown_gc; |
|
1291 if ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) { |
|
1292 if ( !($t = wp_next_scheduled( 'wp_cache_gc' ) ) ) { |
|
1293 wp_clear_scheduled_hook( 'wp_cache_gc' ); |
|
1294 wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' ); |
|
1295 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_gc for 10 seconds time.', 5 ); |
|
1296 } |
|
1297 } else { |
|
1298 global $time_to_gc_cache; |
|
1299 $time_to_gc_cache = 1; // tell the "shutdown gc" to run! |
|
1300 } |
|
1301 } |
|
1302 } elseif ( $cache_schedule_type == 'time' && !wp_next_scheduled( 'wp_cache_gc' ) ) { |
|
1303 wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' ); |
|
1304 } |
|
1305 return true; |
|
1306 } |
|
1307 |
|
1308 function wp_cache_gc_watcher() { |
|
1309 if ( false == wp_next_scheduled( 'wp_cache_gc' ) ) { |
|
1310 if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'GC Watcher: scheduled new gc cron.', 5 ); |
|
1311 schedule_wp_gc(); |
|
1312 } |
879 } |
1313 } |
880 |
1314 |
881 ?> |
1315 ?> |