| 1 |
<?php |
| 2 |
/** |
| 3 |
* BerqWP Advanced Cache Drop-in |
| 4 |
*/ |
| 5 |
|
| 6 |
if (!defined('ABSPATH')) exit; |
| 7 |
|
| 8 |
require_once ABSPATH . '/wp-content/plugins/searchpro/inc/class-ignoreparams.php'; |
| 9 |
require_once ABSPATH . '/wp-content/plugins/searchpro/inc/dropin-functions.php'; |
| 10 |
|
| 11 |
if ($_SERVER['REQUEST_METHOD'] !== 'POST' && !bwp_is_user_logged_in() && !bwp_is_ajax()) { |
| 12 |
$slug = $_SERVER['REQUEST_URI']; |
| 13 |
$slug = dropin_remove_ignore_params($slug); |
| 14 |
$cache_key = md5($slug); |
| 15 |
$cache_directory = ABSPATH . '/wp-content/cache/berqwp/html/'; |
| 16 |
$cache_file = $cache_directory . $cache_key . '.html'; |
| 17 |
$gzip_support = function_exists('gzencode') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false; |
| 18 |
$cache_max_life = @filemtime($cache_file) + (18 * 60 * 60); |
| 19 |
$is_litespeed = isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false; |
| 20 |
|
| 21 |
if (file_exists($cache_file) && $cache_max_life > time()) { |
| 22 |
if ($gzip_support && file_exists($cache_directory . $cache_key . '.gz') && !$is_litespeed) { |
| 23 |
$cache_file = $cache_directory . $cache_key . '.gz'; |
| 24 |
header('Content-Encoding: gzip'); |
| 25 |
header('Content-Type: text/html; charset=UTF-8'); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
if (!isset($_GET['creating_cache']) && file_exists($cache_file)) { |
| 30 |
$lastModified = filemtime($cache_file); |
| 31 |
$etag = md5_file($cache_file); |
| 32 |
header('ETag: ' . $etag); |
| 33 |
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
| 34 |
|
| 35 |
// Check if the client has a cached copy and if it's still valid using Last-Modified |
| 36 |
if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified) || (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag)) { |
| 37 |
// The client's cache is still valid based on Last-Modified, respond with a 304 Not Modified |
| 38 |
header('HTTP/1.1 304 Not Modified'); |
| 39 |
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 40 |
header('Cache-Control: no-cache, must-revalidate'); |
| 41 |
exit(); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
header('Cache-Control: public, max-age=86400'); |
| 46 |
|
| 47 |
if (file_exists($cache_file)) { |
| 48 |
readfile($cache_file); |
| 49 |
exit(); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
// add_action('wp', function () { |
| 58 |
// if (class_exists('berqCache') && !is_admin()) { |
| 59 |
// global $berqwp_is_dropin; |
| 60 |
// $berqwp_is_dropin = true; |
| 61 |
// $berqCache = new berqCache(); |
| 62 |
// $berqCache->html_cache(); |
| 63 |
// } |
| 64 |
// }); |
| 65 |
|