/wp-super-cache/tags/0.6.6/wp-cache-phase1.php

https://github.com/brandonburke/WordPress-Plugin-Baseline · PHP · 125 lines · 96 code · 22 blank · 7 comment · 27 complexity · e1740301023858c5bae3251d44d8fd83 MD5 · raw file

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