| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 4 |
|
| 5 |
/** |
| 6 |
* File based page cache drop in |
| 7 |
*/ |
| 8 |
require_once(dirname(__FILE__) . '/file-based-page-cache-functions.php'); |
| 9 |
|
| 10 |
// Don't cache robots.txt or htacesss. |
| 11 |
if (false !== strpos($_SERVER['REQUEST_URI'], 'robots.txt') || false !== strpos($_SERVER['REQUEST_URI'], '.htaccess')) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
// Don't cache non-GET requests. |
| 16 |
if (!isset($_SERVER['REQUEST_METHOD']) || 'GET' !== $_SERVER['REQUEST_METHOD']) return; |
| 17 |
|
| 18 |
$file_extension = $_SERVER['REQUEST_URI']; |
| 19 |
$file_extension = preg_replace('#^(.*?)\?.*$#', '$1', $file_extension); |
| 20 |
$file_extension = trim(preg_replace('#^.*\.(.*)$#', '$1', $file_extension)); |
| 21 |
|
| 22 |
// Don't cache disallowed extensions. Prevents wp-cron.php, xmlrpc.php, etc. |
| 23 |
if (!preg_match('#index\.php$#i', $_SERVER['REQUEST_URI']) && in_array($file_extension, array( 'php', 'xml', 'xsl' ))) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
// Don't cache if logged in. |
| 28 |
if (!empty($_COOKIE)) { |
| 29 |
$wp_cookies = array( 'wordpressuser_', 'wordpresspass_', 'wordpress_sec_', 'wordpress_logged_in_' ); |
| 30 |
|
| 31 |
foreach ($_COOKIE as $key => $value) { |
| 32 |
foreach ($wp_cookies as $cookie) { |
| 33 |
if (strpos($key, $cookie) !== false) { |
| 34 |
// Logged in! |
| 35 |
return; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
if (!empty($_COOKIE['wpo_commented_posts'])) { |
| 41 |
foreach ($_COOKIE['wpo_commented_posts'] as $path) { |
| 42 |
if (rtrim($path, '/') === rtrim($_SERVER['REQUEST_URI'], '/')) { |
| 43 |
// User commented on this post. |
| 44 |
return; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
// Deal with optional cache exceptions. |
| 51 |
if (!empty($GLOBALS['wpo_cache_config']['cache_exception_urls'])) { |
| 52 |
$exceptions = preg_split('#(\n|\r)#', $GLOBALS['wpo_cache_config']['cache_exception_urls']); |
| 53 |
$regex = !empty($GLOBALS['wpo_cache_config']['enable_url_exemption_regex']); |
| 54 |
|
| 55 |
foreach ($exceptions as $exception) { |
| 56 |
if (wpo_url_exception_match($exception, $regex)) { |
| 57 |
// Exception match. |
| 58 |
return; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
wpo_serve_cache(); |
| 64 |
|
| 65 |
ob_start('wpo_cache'); |
| 66 |
|