$v) { // test cookie makes to cache not work!!! if ($n == 'wordpress_test_cookie') continue; // wp 2.5 and wp 2.3 have different cookie prefix, skip cache if a post password cookie is present, also if ( (substr($n, 0, 14) == 'wordpressuser_' || substr($n, 0, 10) == 'wordpress_' || substr($n, 0, 12) == 'wp-postpass_') && !$wp_ffpc_config['cache_loggedin'] ) { return false; } } } /* canonical redirect storage */ $wp_ffpc_redirect = null; /* fires up the backend storage array with current config */ $wp_ffpc_backend = new WP_FFPC_Backend( $wp_ffpc_config ); /* will store time of page generation */ $wp_ffpc_gentime = 0; /* backend connection failed, no caching :( */ if ( $wp_ffpc_backend->status() === false ) return false; /* try to get data & meta keys for current page */ $wp_ffpc_keys = array ( 'meta' => $wp_ffpc_config['prefix_meta'], 'data' => $wp_ffpc_config['prefix_data'] ); $wp_ffpc_values = array(); foreach ( $wp_ffpc_keys as $internal => $key ) { $value = $wp_ffpc_backend->get ( $wp_ffpc_backend->key ( $key ) ); if ( ! $value ) { /* does not matter which is missing, we need both, if one fails, no caching */ wp_ffpc_start(); return; } else { /* store results */ $wp_ffpc_values[ $internal ] = $value; } } /* serve cache 404 status */ if ( isset( $wp_ffpc_values['meta']['status'] ) && $wp_ffpc_values['meta']['status'] == 404 ) { header("HTTP/1.1 404 Not Found"); flush(); die(); } /* server redirect cache */ if ( isset( $wp_ffpc_values['meta']['redirect'] ) && $wp_ffpc_values['meta']['redirect'] ) { header('Location: ' . $wp_ffpc_values['meta']['redirect'] ); flush(); die(); } /* page is already cached on client side (chrome likes to do this, anyway, it's quite efficient) */ if ( array_key_exists( "HTTP_IF_MODIFIED_SINCE" , $_SERVER ) && !empty( $wp_ffpc_values['meta']['lastmodified'] ) ) { $if_modified_since = strtotime(preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"])); /* check is cache is still valid */ if ( $if_modified_since >= $wp_ffpc_values['meta']['lastmodified'] ) { header("HTTP/1.0 304 Not Modified"); flush(); die(); } } /*** SERVING CACHED PAGE ***/ /* if we reach this point it means data was found & correct, serve it */ header('Content-Type: ' . $wp_ffpc_values['meta']['mime']); /* don't allow browser caching of page */ header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0'); header('Pragma: no-cache'); /* expire at this very moment */ header('Expires: ' . gmdate("D, d M Y H:i:s", time() ) . " GMT"); /* if shortlinks were set */ if (!empty ( $wp_ffpc_values['meta']['shortlink'] ) ) header( 'Link:<'. $wp_ffpc_values['meta']['shortlink'] .'>; rel=shortlink' ); /* if last modifications were set (for posts & pages) */ if ( !empty($wp_ffpc_values['meta']['lastmodified']) ) header( 'Last-Modified: ' . gmdate("D, d M Y H:i:s", $wp_ffpc_values['meta']['lastmodified'] ). " GMT" ); /* pingback urls, if existx */ if ( !empty( $wp_ffpc_values['meta']['pingback'] ) ) header( 'X-Pingback: ' . $wp_ffpc_values['meta']['pingback'] ); /* for debugging */ if ( $wp_ffpc_config['response_header'] ) header( 'X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type'] ); /* HTML data */ echo $wp_ffpc_values['data']; flush(); die(); /*** END SERVING CACHED PAGE ***/ /*** GENERATING CACHE ENTRY ***/ /** * starts caching function * */ function wp_ffpc_start( ) { /* set start time */ global $wp_ffpc_gentime; $mtime = explode ( " ", microtime() ); $wp_ffpc_gentime = $mtime[1] + $mtime[0]; /* start object "colleting" and pass it the the actual storer function */ ob_start('wp_ffpc_callback'); } /** * callback function for WordPress redirect urls * */ function wp_ffpc_redirect_callback ($redirect_url, $requested_url) { global $wp_ffpc_redirect; $wp_ffpc_redirect = $redirect_url; return $redirect_url; } /** * write cache function, called when page generation ended */ function wp_ffpc_callback( $buffer ) { /* use global config */ global $wp_ffpc_config; /* backend was already set up, try to use it */ global $wp_ffpc_backend; /* check is it's a redirect */ global $wp_ffpc_redirect; /* no is_home = error, WordPress functions are not availabe */ if (!function_exists('is_home')) return $buffer; /* no
close tag = not HTML, also no