PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.7
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.7
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / inc / photon / class-berqPageOptimizer.php

class-berqPageOptimizer.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.7, at inc/photon/class-berqPageOptimizer.php

70 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class berqPageOptimizer {
5 public $page_slug = null;
6
7 function start_cache() {
8 add_action('template_redirect', [$this, 'buffer_start'], 2);
9 }
10
11 function set_slug($slug) {
12 $this->page_slug = $slug;
13 }
14
15 function buffer_start() {
16 ob_start([$this, 'buffer_end']);
17 }
18
19 function store_cache($buffer) {
20 // Define the cache directory
21 $cache_directory = optifer_cache . '/html/';
22
23 // Create the cache directory if it doesn't exist
24 if (!file_exists($cache_directory)) {
25 mkdir($cache_directory, 0755, true);
26 }
27
28 $cache_file = $cache_directory . md5($this->page_slug) . '.html';
29
30 // update_option( md5($slug), $key );
31 file_put_contents($cache_file, $buffer);
32
33 if (bwp_is_gzip_supported()) {
34 $cache_file = $cache_directory . md5($this->page_slug) . '.gz';
35 $buffer = gzencode($buffer, 9);
36 file_put_contents($cache_file, $buffer);
37 }
38
39
40 do_action('berqwp_stored_page_cache', $this->page_slug);
41
42 global $berq_log;
43 $berq_log->info("Stored cache for $this->page_slug from PageOptimizer class");
44 }
45
46 function buffer_end($buffer) {
47
48 if (empty($buffer)) {
49 return $buffer;
50 }
51
52 if (!function_exists('str_get_html')) {
53 require_once optifer_PATH . '/simplehtmldom/simple_html_dom.php';
54 }
55
56 if (!class_exists('scriptSeqManipulate')) {
57 require_once optifer_PATH . '/inc/class-scriptSeqManipulate.php';
58 }
59
60 $buffer = $buffer.'<!-- Optimized with BerqWP\'s instant cache. --->';
61
62 $berqBufferOptimize = new berqBufferOptimize();
63 $berqBufferOptimize->optimize_buffer($buffer, $this->page_slug);
64
65 $buffer = apply_filters( 'berqwp_cache_buffer', $buffer );
66 $this->store_cache($buffer);
67
68 return $buffer;
69 }
70 }