| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; |
| 3 |
|
| 4 |
$status = sanitize_text_field($request->get_param('status')); |
| 5 |
$key = sanitize_text_field($request->get_param('key')); |
| 6 |
$html = base64_decode($request->get_param('html')); |
| 7 |
$slug = sanitize_text_field($request->get_param('page_slug')); |
| 8 |
|
| 9 |
if ($status == 'success' && !empty($request->get_param('html'))) { |
| 10 |
|
| 11 |
// Allow other plugins to modify cache html |
| 12 |
$html = apply_filters( 'berqwp_cache_buffer', $html ); |
| 13 |
|
| 14 |
// Define the cache directory |
| 15 |
$cache_directory = optifer_cache . '/html/'; |
| 16 |
|
| 17 |
// Create the cache directory if it doesn't exist |
| 18 |
if (!file_exists($cache_directory)) { |
| 19 |
mkdir($cache_directory, 0755, true); |
| 20 |
} |
| 21 |
|
| 22 |
$cache_file = $cache_directory . md5($slug) . '.html'; |
| 23 |
|
| 24 |
// update_option( md5($slug), $key ); |
| 25 |
file_put_contents($cache_file, $html); |
| 26 |
|
| 27 |
if (bwp_is_gzip_supported()) { |
| 28 |
$cache_file = $cache_directory . md5($slug) . '.gz'; |
| 29 |
$html = gzencode($html, 9); |
| 30 |
file_put_contents($cache_file, $html); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
do_action('berqwp_stored_page_cache', $slug); |
| 35 |
|
| 36 |
global $berq_log; |
| 37 |
$berq_log->info("Stored cache for $slug"); |
| 38 |
|
| 39 |
|
| 40 |
} |
| 41 |
unset($html); // release memory |