[44] | 1 | <?php
|
---|
| 2 | // Pre-2.6 compatibility
|
---|
| 3 | if( !defined('WP_CONTENT_DIR') )
|
---|
| 4 | define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
|
---|
| 5 |
|
---|
| 6 | if( !include( WP_CONTENT_DIR . '/wp-cache-config.php' ) )
|
---|
| 7 | return true;
|
---|
| 8 | if( !defined( 'WPCACHEHOME' ) )
|
---|
| 9 | define('WPCACHEHOME', dirname(__FILE__).'/');
|
---|
| 10 |
|
---|
| 11 | include( WPCACHEHOME . 'wp-cache-base.php');
|
---|
| 12 |
|
---|
| 13 | if( $blogcacheid != '' ) {
|
---|
| 14 | $blog_cache_dir = str_replace( '//', '/', $cache_path . "blogs/" . $blogcacheid . '/' );
|
---|
| 15 | } else {
|
---|
| 16 | $blog_cache_dir = $cache_path;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | if(defined('DOING_CRON')) {
|
---|
| 20 | require_once( WPCACHEHOME . 'wp-cache-phase2.php');
|
---|
| 21 | return true;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | $mutex_filename = 'wp_cache_mutex.lock';
|
---|
| 25 | $new_cache = false;
|
---|
| 26 |
|
---|
| 27 | // Don't change variables behind this point
|
---|
| 28 |
|
---|
| 29 | if( !isset( $wp_cache_plugins_dir ) )
|
---|
| 30 | $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
|
---|
| 31 | $plugins = glob( $wp_cache_plugins_dir . '/*.php' );
|
---|
| 32 | if( is_array( $plugins ) ) {
|
---|
| 33 | foreach ( $plugins as $plugin ) {
|
---|
| 34 | if( is_file( $plugin ) )
|
---|
| 35 | require_once( $plugin );
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | if (!$cache_enabled || $_SERVER["REQUEST_METHOD"] == 'POST')
|
---|
| 40 | return true;
|
---|
| 41 |
|
---|
| 42 | $file_expired = false;
|
---|
| 43 | $cache_filename = '';
|
---|
| 44 | $meta_file = '';
|
---|
| 45 | $wp_cache_gzip_encoding = '';
|
---|
| 46 |
|
---|
| 47 | $gzipped = 0;
|
---|
| 48 | $gzsize = 0;
|
---|
| 49 |
|
---|
| 50 | function gzip_accepted(){
|
---|
| 51 | if( ini_get( 'zlib.output_compression' ) ) // don't compress WP-Cache data files when PHP is already doing it
|
---|
| 52 | return false;
|
---|
| 53 |
|
---|
| 54 | if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false) return false;
|
---|
| 55 | return 'gzip';
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | if ($cache_compression) {
|
---|
| 59 | $wp_cache_gzip_encoding = gzip_accepted();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | add_cacheaction( 'wp_cache_get_cookies_values', 'wp_cache_check_mobile' );
|
---|
| 63 |
|
---|
| 64 | $wp_cache_request_uri = $_SERVER[ 'REQUEST_URI' ]; // Cache this in case any plugin modifies it.
|
---|
| 65 |
|
---|
| 66 | $key = $blogcacheid . md5( do_cacheaction( 'wp_cache_key', $_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $wp_cache_request_uri ) ).$wp_cache_gzip_encoding.wp_cache_get_cookies_values() ) );
|
---|
| 67 |
|
---|
| 68 | if( false == @is_dir( $blog_cache_dir ) ) {
|
---|
| 69 | @mkdir( $cache_path . "blogs" );
|
---|
| 70 | @mkdir( $blog_cache_dir );
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if( false == @is_dir( $blog_cache_dir . 'meta' ) )
|
---|
| 74 | @mkdir( $blog_cache_dir . 'meta' );
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | $cache_filename = $file_prefix . $key . '.html';
|
---|
| 78 | $meta_file = $file_prefix . $key . '.meta';
|
---|
| 79 | $cache_file = realpath( $blog_cache_dir . $cache_filename );
|
---|
| 80 | $meta_pathname = realpath( $blog_cache_dir . 'meta/' . $meta_file );
|
---|
| 81 |
|
---|
| 82 | $wp_start_time = microtime();
|
---|
| 83 | if( file_exists( $cache_file ) && !wp_cache_user_agent_is_rejected() ) {
|
---|
| 84 | if (! ($meta = unserialize(@file_get_contents($meta_pathname))) )
|
---|
| 85 | return true;
|
---|
| 86 | if( is_array( $meta ) == false ) {
|
---|
| 87 | @unlink( $meta_pathname );
|
---|
| 88 | @unlink( $cache_file );
|
---|
| 89 | return true;
|
---|
| 90 | }
|
---|
| 91 | $cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file );
|
---|
| 92 | // Sometimes the gzip headers are lost. If this is a gzip capable client, send those headers.
|
---|
| 93 | if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) {
|
---|
| 94 | $meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
|
---|
| 95 | $meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
|
---|
| 96 | wp_cache_debug( "Had to add gzip headers to the page {$_SERVER[ 'REQUEST_URI' ]}." );
|
---|
| 97 | }
|
---|
| 98 | foreach ($meta[ 'headers' ] as $t => $header) {
|
---|
| 99 | // 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/
|
---|
| 100 | if( strpos( $header, 'Last-Modified:' ) === false )
|
---|
| 101 | header($header);
|
---|
| 102 | }
|
---|
| 103 | header( 'WP-Super-Cache: WP-Cache' );
|
---|
| 104 | if ( $meta[ 'dynamic' ] ) {
|
---|
| 105 | include($cache_file);
|
---|
| 106 | } else {
|
---|
| 107 | readfile( $cache_file );
|
---|
| 108 | }
|
---|
| 109 | die();
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | function wp_cache_postload() {
|
---|
| 113 | global $cache_enabled;
|
---|
| 114 |
|
---|
| 115 | if ( !$cache_enabled || isset( $_GET[ 'preview' ] ) )
|
---|
| 116 | return true;
|
---|
| 117 | require_once( WPCACHEHOME . 'wp-cache-phase2.php');
|
---|
| 118 | wp_cache_phase2();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | function wp_cache_get_cookies_values() {
|
---|
| 122 | $string = '';
|
---|
| 123 | while ($key = key($_COOKIE)) {
|
---|
| 124 | if ( preg_match( "/^wp-postpass|^wordpress|^comment_author_/", $key ) && $_COOKIE[ $key ] != 'WP Cookie check' ) {
|
---|
| 125 | $string .= $_COOKIE[$key] . ",";
|
---|
| 126 | }
|
---|
| 127 | next($_COOKIE);
|
---|
| 128 | }
|
---|
| 129 | reset($_COOKIE);
|
---|
| 130 |
|
---|
| 131 | // If you use this hook, make sure you update your .htaccess rules with the same conditions
|
---|
| 132 | $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
|
---|
| 133 | return $string;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | function add_cacheaction( $action, $func ) {
|
---|
| 137 | global $wp_supercache_actions;
|
---|
| 138 | $wp_supercache_actions[ $action ][] = $func;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | function do_cacheaction( $action, $value = '' ) {
|
---|
| 142 | global $wp_supercache_actions;
|
---|
| 143 | if( is_array( $wp_supercache_actions[ $action ] ) ) {
|
---|
| 144 | $actions = $wp_supercache_actions[ $action ];
|
---|
| 145 | foreach( $actions as $func ) {
|
---|
| 146 | $value = $func( $value );
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | return $value;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | // From http://wordpress.org/extend/plugins/wordpress-mobile-edition/ by Alex King
|
---|
| 154 | function wp_cache_check_mobile( $cache_key ) {
|
---|
| 155 | global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_whitelist;
|
---|
| 156 | if( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled )
|
---|
| 157 | return $cache_key;
|
---|
| 158 |
|
---|
| 159 | if (!isset($_SERVER["HTTP_USER_AGENT"])) {
|
---|
| 160 | return $cache_key;
|
---|
| 161 | }
|
---|
| 162 | $whitelist = explode( ',', $wp_cache_mobile_whitelist );
|
---|
| 163 | foreach ($whitelist as $browser) {
|
---|
| 164 | if (strstr($_SERVER["HTTP_USER_AGENT"], trim($browser))) {
|
---|
| 165 | return $cache_key;
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | $browsers = explode( ',', $wp_cache_mobile_browsers );
|
---|
| 170 | foreach ($browsers as $browser) {
|
---|
| 171 | if (strstr($_SERVER["HTTP_USER_AGENT"], trim( $browser ))) {
|
---|
| 172 | return $cache_key . $browser;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | return $cache_key;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | function wp_cache_debug( $message ) {
|
---|
| 179 | global $wp_cache_debug;
|
---|
| 180 | if( !isset( $wp_cache_debug ) )
|
---|
| 181 | return;
|
---|
| 182 | $message .= "\n\nDisable these emails by commenting out or deleting the line containing\n\$wp_cache_debug in wp-content/wp-cache-config.php on your server.\n";
|
---|
| 183 | mail( $wp_cache_debug, '[' . addslashes( $_SERVER[ 'HTTP_HOST' ] ) . "] WP Super Cache Debug", $message );
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | function wp_cache_user_agent_is_rejected() {
|
---|
| 187 | global $cache_rejected_user_agent;
|
---|
| 188 |
|
---|
| 189 | if (!function_exists('apache_request_headers')) return false;
|
---|
| 190 | $headers = apache_request_headers();
|
---|
| 191 | if (!isset($headers["User-Agent"])) return false;
|
---|
| 192 | foreach ($cache_rejected_user_agent as $expr) {
|
---|
| 193 | if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
|
---|
| 194 | return true;
|
---|
| 195 | }
|
---|
| 196 | return false;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | ?>
|
---|