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