wp-super-cache
Last commit date
plugins
18 years ago
Changelog.txt
18 years ago
readme.txt
18 years ago
wp-cache-base.php
18 years ago
wp-cache-config-sample.php
18 years ago
wp-cache-phase1.php
18 years ago
wp-cache-phase2.php
18 years ago
wp-cache.php
18 years ago
wp-cache-phase1.php
121 lines
| 1 | <?php |
| 2 | if( !@include(ABSPATH . 'wp-content/wp-cache-config.php') ) { |
| 3 | return; |
| 4 | } |
| 5 | if( !defined( 'WPCACHEHOME' ) ) |
| 6 | define('WPCACHEHOME', dirname(__FILE__).'/'); |
| 7 | |
| 8 | include( WPCACHEHOME . 'wp-cache-base.php'); |
| 9 | |
| 10 | $mutex_filename = 'wp_cache_mutex.lock'; |
| 11 | $new_cache = false; |
| 12 | |
| 13 | |
| 14 | // Don't change variables behind this point |
| 15 | |
| 16 | $plugins = glob( WPCACHEHOME . 'plugins/*.php' ); |
| 17 | if( is_array( $plugins ) ) { |
| 18 | foreach ( $plugins as $plugin ) { |
| 19 | if( is_file( $plugin ) ) |
| 20 | require_once( $plugin ); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | if (!$cache_enabled || $_SERVER["REQUEST_METHOD"] == 'POST') |
| 25 | return; |
| 26 | |
| 27 | $file_expired = false; |
| 28 | $cache_filename = ''; |
| 29 | $meta_file = ''; |
| 30 | $wp_cache_gzip_encoding = ''; |
| 31 | |
| 32 | function gzip_accepted(){ |
| 33 | if( ini_get( 'zlib.output_compression' ) ) // don't compress WP-Cache data files when PHP is already doing it |
| 34 | return false; |
| 35 | |
| 36 | if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false) return false; |
| 37 | if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') === false) return 'gzip'; |
| 38 | return 'x-gzip'; |
| 39 | } |
| 40 | |
| 41 | if ($cache_compression) { |
| 42 | $wp_cache_gzip_encoding = gzip_accepted(); |
| 43 | } |
| 44 | |
| 45 | $key = $blogcacheid . md5($_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $_SERVER['REQUEST_URI'] ) ).$wp_cache_gzip_encoding.wp_cache_get_cookies_values()); |
| 46 | |
| 47 | $cache_filename = $file_prefix . $key . '.html'; |
| 48 | $meta_file = $file_prefix . $key . '.meta'; |
| 49 | $cache_file = realpath( $cache_path . $cache_filename ); |
| 50 | $meta_pathname = realpath( $cache_path . 'meta/' . $meta_file ); |
| 51 | |
| 52 | $wp_start_time = microtime(); |
| 53 | if( ($mtime = @filemtime($meta_pathname)) ) { |
| 54 | if ($mtime + $cache_max_time > time() ) { |
| 55 | $meta = new CacheMeta; |
| 56 | if (! ($meta = unserialize(@file_get_contents($meta_pathname))) ) |
| 57 | return; |
| 58 | foreach ($meta->headers as $header) { |
| 59 | header($header); |
| 60 | } |
| 61 | if ( !($content_size = @filesize($cache_file)) > 0 || $mtime < @filemtime($cache_file)) |
| 62 | return; |
| 63 | if ($meta->dynamic) { |
| 64 | include($cache_file); |
| 65 | } else { |
| 66 | /* No used to avoid problems with some PHP installations |
| 67 | $content_size += strlen($log); |
| 68 | header("Content-Length: $content_size"); |
| 69 | */ |
| 70 | if(!@readfile ($cache_file)) |
| 71 | return; |
| 72 | } |
| 73 | die; |
| 74 | } |
| 75 | $file_expired = true; // To signal this file was expired |
| 76 | } |
| 77 | |
| 78 | function wp_cache_postload() { |
| 79 | global $cache_enabled; |
| 80 | |
| 81 | if (!$cache_enabled) |
| 82 | return; |
| 83 | require( WPCACHEHOME . 'wp-cache-phase2.php'); |
| 84 | wp_cache_phase2(); |
| 85 | } |
| 86 | |
| 87 | function wp_cache_get_cookies_values() { |
| 88 | $string = ''; |
| 89 | while ($key = key($_COOKIE)) { |
| 90 | if (preg_match("/^wp-postpass|^wordpress|^comment_author_email_/", $key)) { |
| 91 | $string .= $_COOKIE[$key] . ","; |
| 92 | } |
| 93 | next($_COOKIE); |
| 94 | } |
| 95 | reset($_COOKIE); |
| 96 | if( $string != '' ) |
| 97 | return $string; |
| 98 | |
| 99 | $string = do_cacheaction( 'wp_cache_get_cookies_values', $string ); |
| 100 | return $string; |
| 101 | } |
| 102 | |
| 103 | function add_cacheaction( $action, $func ) { |
| 104 | global $wp_supercache_actions; |
| 105 | $wp_supercache_actions[ $action ][] = $func; |
| 106 | } |
| 107 | |
| 108 | function do_cacheaction( $action, $value = '' ) { |
| 109 | global $wp_supercache_actions; |
| 110 | if( is_array( $wp_supercache_actions[ $action ] ) ) { |
| 111 | $actions = $wp_supercache_actions[ $action ]; |
| 112 | foreach( $actions as $func ) { |
| 113 | $value = $func( $value ); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return $value; |
| 118 | } |
| 119 | |
| 120 | ?> |
| 121 |