| 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 = $request->get_param('page_slug'); |
| 8 |
|
| 9 |
if ($status == 'success' && !empty($request->get_param('html'))) { |
| 10 |
global $berq_log; |
| 11 |
|
| 12 |
// Allow other plugins to modify cache html |
| 13 |
$html = apply_filters( 'berqwp_cache_buffer', $html ); |
| 14 |
|
| 15 |
// Define the cache directory |
| 16 |
$cache_directory = bwp_get_cache_dir(); |
| 17 |
|
| 18 |
// Create the cache directory if it doesn't exist |
| 19 |
if (!file_exists($cache_directory)) { |
| 20 |
mkdir($cache_directory, 0755, true); |
| 21 |
} |
| 22 |
|
| 23 |
$cache_file = $cache_directory . md5($slug) . '.html'; |
| 24 |
|
| 25 |
if ($html) { |
| 26 |
$berq_log->info("Empty html cache: $page_url"); |
| 27 |
exit; |
| 28 |
} |
| 29 |
|
| 30 |
// update_option( md5($slug), $key ); |
| 31 |
file_put_contents($cache_file, $html); |
| 32 |
|
| 33 |
if (bwp_is_gzip_supported()) { |
| 34 |
$cache_file = $cache_directory . md5($slug) . '.gz'; |
| 35 |
$html = gzencode($html, 9); |
| 36 |
file_put_contents($cache_file, $html); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
do_action('berqwp_stored_page_cache', $slug); |
| 41 |
|
| 42 |
$berq_log->info("Stored cache for $slug"); |
| 43 |
|
| 44 |
// Cache is stored which means connection is stable |
| 45 |
// Delete connection test error transient |
| 46 |
$check_connection = bwp_check_connection(); |
| 47 |
if ( $check_connection['status'] == 'error' ) { |
| 48 |
delete_transient('berqwp_connection_status'); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
} |
| 53 |
unset($html); // release memory |