PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.0.17
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.0.17
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 / admin / admin-page.php

admin-page.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.0.17, at admin/admin-page.php

532 lines 29.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH'))
3 exit;
4
5 $cached_pages = bwp_cached_pages_count();
6 $plugin_name = defined('BERQWP_PLUGIN_NAME') ? BERQWP_PLUGIN_NAME : 'BerqWP';
7 $berqconfigs = berqConfigs::getInstance();
8 $configs = $berqconfigs->get_configs();
9 $berqwp_can_use_cloud = berqwp_can_use_cloud();
10 ?>
11 <!--<link href="https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;500;600;&display=swap" rel="stylesheet">-->
12 <!--<link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap" rel="stylesheet">-->
13 <!--<link href="<?php echo esc_attr(optifer_URL . '/admin/css/dataTables.dataTables.min.css?v=' . BERQWP_VERSION); ?>" rel="stylesheet">-->
14 <!--<link rel="stylesheet" href="<?php echo esc_attr(optifer_URL . '/admin/css/style.css?v=' . BERQWP_VERSION); ?>">-->
15 <!--<link rel="stylesheet" href="<?php echo esc_attr(optifer_URL . '/admin/css/bootstrap-slider.min.css?v=' . BERQWP_VERSION); ?>">-->
16 <!--<link rel="stylesheet" href="<?php echo esc_attr(optifer_URL . '/admin/css/bootstrap.min.css?v=' . BERQWP_VERSION); ?>">-->
17
18 <div class="wrap1">
19 <!-- <h1 style="display:none">BerqWP</h1>
20 <div></div> -->
21 <div class="berqwp-dashbaord">
22 <div class="berqwp-header">
23 <img src="<?php
24
25 if (defined('BERQWP_LOGO')) {
26 echo esc_attr(BERQWP_LOGO);
27 } else {
28 echo esc_attr(optifer_URL . '/admin/img/logo.png');
29 }
30
31 ?>" alt="BerqWP Logo">
32 <div class="berqwp-header-right">
33 <div class="optimization-methods-switch <?php echo esc_attr($configs['optimization_method'])?>" title="Optimization method">
34 <a class="method-local" href="<?php echo esc_attr(wp_nonce_url(admin_url('admin-post.php?action=switch_optimization_method_local'), 'switch_optimization_method_local_action')); ?>">
35 <div class="icon">
36 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-server-icon lucide-server">
37 <rect width="20" height="8" x="2" y="2" rx="2" ry="2" />
38 <rect width="20" height="8" x="2" y="14" rx="2" ry="2" />
39 <line x1="6" x2="6.01" y1="6" y2="6" />
40 <line x1="6" x2="6.01" y1="18" y2="18" />
41 </svg>
42 </div>
43 Local (free)
44
45 </a>
46
47 <a class="method-cloud" href="<?php echo esc_attr(wp_nonce_url(admin_url('admin-post.php?action=switch_optimization_method_cloud'), 'switch_optimization_method_cloud_action')); ?>">
48 <div class="icon">
49 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-cloudy-icon lucide-cloudy">
50 <path d="M17.5 12a1 1 0 1 1 0 9H9.006a7 7 0 1 1 6.702-9z" />
51 <path d="M21.832 9A3 3 0 0 0 19 7h-2.207a5.5 5.5 0 0 0-10.72.61" />
52 </svg>
53 </div>
54 BerqWP Cloud
55 </a>
56 </div>
57
58 <a class="bwp-action-btn light" href="<?php echo esc_attr(wp_nonce_url(admin_url('admin-post.php?action=clear_cache'), 'clear_cache_action')); ?>">
59 Flush cache
60 </a>
61
62 <?php if ($berqwp_can_use_cloud) { ?>
63 <a class="bwp-action-btn" href="<?php echo esc_attr(wp_nonce_url(admin_url('admin-post.php?action=warmup_cache'), 'warmup_cache_action')); ?>">
64 Warmup cache
65 </a>
66 <?php } ?>
67
68 <?php if (bwp_show_docs()) { ?>
69 <!--<a href="https://wordpress.org/support/plugin/searchpro/reviews/#new-post" target="_blank"
70 class="berqwp-support">
71 <?php esc_html_e('Write a review', 'searchpro'); ?>
72 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
73 <path
74 d="M11.0001 3C10.7349 3 10.4805 3.10536 10.293 3.29289C10.1054 3.48043 10.0001 3.73478 10.0001 4C10.0001 4.26522 10.1054 4.51957 10.293 4.70711C10.4805 4.89464 10.7349 5 11.0001 5H13.5861L7.29308 11.293C7.19757 11.3852 7.12139 11.4956 7.06898 11.6176C7.01657 11.7396 6.98898 11.8708 6.98783 12.0036C6.98668 12.1364 7.01198 12.2681 7.06226 12.391C7.11254 12.5139 7.18679 12.6255 7.28069 12.7194C7.37458 12.8133 7.48623 12.8875 7.60913 12.9378C7.73202 12.9881 7.8637 13.0134 7.99648 13.0123C8.12926 13.0111 8.26048 12.9835 8.38249 12.9311C8.50449 12.8787 8.61483 12.8025 8.70708 12.707L15.0001 6.414V9C15.0001 9.26522 15.1054 9.51957 15.293 9.70711C15.4805 9.89464 15.7349 10 16.0001 10C16.2653 10 16.5197 9.89464 16.7072 9.70711C16.8947 9.51957 17.0001 9.26522 17.0001 9V4C17.0001 3.73478 16.8947 3.48043 16.7072 3.29289C16.5197 3.10536 16.2653 3 16.0001 3H11.0001Z"
75 fill="#465774" />
76 <path
77 d="M5 5C4.46957 5 3.96086 5.21071 3.58579 5.58579C3.21071 5.96086 3 6.46957 3 7V15C3 15.5304 3.21071 16.0391 3.58579 16.4142C3.96086 16.7893 4.46957 17 5 17H13C13.5304 17 14.0391 16.7893 14.4142 16.4142C14.7893 16.0391 15 15.5304 15 15V12C15 11.7348 14.8946 11.4804 14.7071 11.2929C14.5196 11.1054 14.2652 11 14 11C13.7348 11 13.4804 11.1054 13.2929 11.2929C13.1054 11.4804 13 11.7348 13 12V15H5V7H8C8.26522 7 8.51957 6.89464 8.70711 6.70711C8.89464 6.51957 9 6.26522 9 6C9 5.73478 8.89464 5.48043 8.70711 5.29289C8.51957 5.10536 8.26522 5 8 5H5Z"
78 fill="#465774" />
79 </svg>
80
81 </a>-->
82 <?php } ?>
83
84 </div>
85 </div>
86 <div class="berqwp-dashbord-body">
87 <div class="berqwp-tabs">
88 <div class="berqwp-tab <?php bwp_is_tab_nav('dashboard'); ?>" data-tab="dashboard">
89 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-layout-dashboard-icon lucide-layout-dashboard"><rect width="7" height="9" x="3" y="3" rx="1"/><rect width="7" height="5" x="14" y="3" rx="1"/><rect width="7" height="9" x="14" y="12" rx="1"/><rect width="7" height="5" x="3" y="16" rx="1"/></svg></div>
90 <?php esc_html_e('Dashboard', 'searchpro'); ?>
91 </div>
92 <div class="berqwp-tab <?php bwp_is_tab_nav('cache-management'); ?>" data-tab="cache-management">
93 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-gauge-icon lucide-gauge"><path d="m12 14 4-4"/><path d="M3.34 19a10 10 0 1 1 17.32 0"/></svg></div>
94 <?php esc_html_e('Cache Management', 'searchpro'); ?>
95 </div>
96 <div class="berqwp-tab <?php bwp_is_tab_nav('css-javascript'); ?>" data-tab="css-javascript">
97 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-icon lucide-code"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg></div>
98 <?php esc_html_e('CSS & JavaScript', 'searchpro'); ?>
99 </div>
100 <div class="berqwp-tab <?php bwp_is_tab_nav('media-optimization'); ?>" data-tab="media-optimization">
101 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-images-icon lucide-images"><path d="m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16"/><path d="M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2"/><circle cx="13" cy="7" r="1" fill="currentColor"/><rect x="8" y="2" width="14" height="14" rx="2"/></svg></div>
102 <?php esc_html_e('Media Optimization', 'searchpro'); ?>
103 </div>
104 <div class="berqwp-tab <?php bwp_is_tab_nav('content-delivery-network'); ?>" data-tab="content-delivery-network">
105 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-earth-icon lucide-earth"><path d="M21.54 15H17a2 2 0 0 0-2 2v4.54"/><path d="M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17"/><path d="M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05"/><circle cx="12" cy="12" r="10"/></svg></div>
106 <?php esc_html_e('CDN', 'searchpro'); ?>
107 </div>
108 <!--<div class="berqwp-tab <?php bwp_is_tab_nav('image-optimization'); ?>" data-tab="image-optimization">
109 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-images-icon lucide-images"><path d="m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16"/><path d="M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2"/><circle cx="13" cy="7" r="1" fill="currentColor"/><rect x="8" y="2" width="14" height="14" rx="2"/></svg></div>
110 <?php esc_html_e('Image Optimization', 'searchpro'); ?>
111 </div>
112 <div class="berqwp-tab <?php bwp_is_tab_nav('script-manager'); ?>" data-tab="script-manager">
113 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-code-corner-icon lucide-file-code-corner"><path d="M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="m5 16-3 3 3 3"/><path d="m9 22 3-3-3-3"/></svg></div>
114 <?php esc_html_e('Script Manager', 'searchpro'); ?>
115 </div>-->
116 <div class="berqwp-tab <?php bwp_is_tab_nav('integration'); ?>" data-tab="integration">
117 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-blocks-icon lucide-blocks"><path d="M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2"/><rect x="14" y="2" width="8" height="8" rx="1"/></svg></div>
118 <?php esc_html_e('Integration', 'searchpro'); ?>
119 </div>
120 <?php if ($berqwp_can_use_cloud) { ?>
121 <div class="berqwp-tab <?php bwp_is_tab_nav('activate-license'); ?>" data-tab="activate-license">
122 <div class="icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-settings2-icon lucide-settings-2"><path d="M14 17H5"/><path d="M19 7h-9"/><circle cx="17" cy="17" r="3"/><circle cx="7" cy="7" r="3"/></svg></div>
123 <?php esc_html_e('License', 'searchpro'); ?>
124 </div>
125 <?php } ?>
126 </div>
127 <div class="berqwp-tab-content">
128 <?php do_action('berqwp_notices'); ?>
129 <form action="" method="post">
130 <?php
131 wp_nonce_field('berqwp_save_settings', 'berqwp_save_nonce');
132 ?>
133 <input type="hidden" name="bwp_current_tab_id" value="<?php echo !empty($_GET['tab_id']) ? sanitize_text_field($_GET['tab_id']) : 'dashboard'; ?>">
134 <?php
135 require_once optifer_PATH . '/admin/tabs/dashboard.php';
136 require_once optifer_PATH . '/admin/tabs/cache-management.php';
137 require_once optifer_PATH . '/admin/tabs/content-delivery-network.php';
138 require_once optifer_PATH . '/admin/tabs/css-javascript.php';
139 // require_once optifer_PATH . '/admin/tabs/image-optimization.php';
140 require_once optifer_PATH . '/admin/tabs/media-optimization.php';
141 // require_once optifer_PATH . '/admin/tabs/script-manager.php';
142 require_once optifer_PATH . '/admin/tabs/integration.php';
143
144 if ($berqwp_can_use_cloud) {
145 require_once optifer_PATH . '/admin/tabs/activate-license.php';
146 }
147
148 ?>
149 </form>
150 </div>
151 </div>
152 </div>
153 </div>
154 <!-- <p class="below-settings-panel">Explore <a href="https://berqier.com" target="_blank">Berqier Ltd</a>, the creators of
155 BerqWP. Want to know more? Reach out—we love talking WordPress!</p> -->
156 <!--<script src="<?php echo esc_attr(optifer_URL . '/admin/js/bootstrap-slider.js?v=' . BERQWP_VERSION); ?>"></script>-->
157 <!--<script src="<?php echo esc_attr(optifer_URL . '/admin/js/dataTables.min.js?v=' . BERQWP_VERSION); ?>"></script>-->
158 <script>
159 (function($) {
160 $(document).ready(function() {
161 const bwp_controllers = [];
162 // $('.bwp_feedback').hide();
163 let berq_nounce = '<?php echo esc_html(wp_create_nonce('wp_rest')); ?>';
164
165 window.addEventListener('beforeunload', () => {
166 bwp_controllers.forEach(c => c.abort());
167 });
168
169
170 function numberWithCommas(x) {
171 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
172 }
173
174 function init_opt_slider() {
175 let opt_slider = new Slider('#berq_opt_mode', {
176 // min: 5,
177 // max: 30,
178 value: '<?php echo esc_html(get_option('berq_opt_mode', 4)); ?>',
179 ticks_labels: ['Basic', 'Medium', 'Blaze', 'Aggressive'],
180 ticks: [1, 2, 3, 4],
181 // ticks_positions: [0, 50, 100],
182 ticks_snap_bounds: 20,
183 tooltip_position: 'bottom',
184 // formatter: function (value) {
185 // if (value == 1) {
186 // // return '<div class="tooltip-title">Basic (stable)</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache etc</div>';
187 // $("div.tooltip-inner").html('<div class="tooltip-title">Basic (stable)</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache etc</div>')
188
189 // return '';
190 // }
191 // },
192 ticks_tooltip: true,
193 // ticks_tooltip: true,
194 // lock_to_ticks: true,
195 // step: 1
196 });
197
198 $(".optimzation-slider").mousemove(function(event) {
199 let val = $("#berq_opt_mode").val();
200
201 if ($(".slider-tick:nth-child(1)").is(":hover") || $('.tooltip-inner').html() == '1') {
202 $("div.tooltip-inner").html('<div class="tooltip-title">Basic</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache, URL prefectch etc.</div>')
203 }
204
205 if ($(".slider-tick:nth-child(2)").is(":hover") || $('.tooltip-inner').html() == '2') {
206 $("div.tooltip-inner").html('<div class="tooltip-title">Medium</div> <div class="tooltip-content">Highly stable optimization mode for many cases.</div>')
207 }
208
209 if ($(".slider-tick:nth-child(3)").is(":hover") || $('.tooltip-inner').html() == '3') {
210 $("div.tooltip-inner").html('<div class="tooltip-title">Blaze</div> <div class="tooltip-content">Balance between optimization and stability.</div>')
211 }
212
213 if ($(".slider-tick:nth-child(4)").is(":hover") || $('.tooltip-inner').html() == '4') {
214 $("div.tooltip-inner").html('<div class="tooltip-title">Aggressive</div> <div class="tooltip-content">Provide the best possible speed scores.</div>')
215 }
216 })
217
218 $("#berq_opt_mode").on("slide slideStop", function(slideEvt) {
219 let val = $("#berq_opt_mode").val();
220
221 if (val == 1) {
222 $("div.tooltip-inner").html('<div class="tooltip-title">Basic (stable)</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache etc</div>')
223 }
224
225 if (val == 2) {
226 $("div.tooltip-inner").html('<div class="tooltip-title">Medium (stable)</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache etc</div>')
227 }
228
229 if (val == 3) {
230 $("div.tooltip-inner").html('<div class="tooltip-title">Blaze</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache etc</div>')
231 }
232
233 if (val == 4) {
234 $("div.tooltip-inner").html('<div class="tooltip-title">Aggressive</div> <div class="tooltip-content">Basic optimizations like image lazy loading, page cache etc</div>')
235 }
236 })
237 }
238
239 function berq_clear_cache() {
240 $.ajax({
241 url: '<?php echo esc_html(get_site_url()); ?>/wp-json/optifer/v1/clear-cache',
242 method: 'POST',
243 beforeSend: function(xhr) {
244 xhr.setRequestHeader('X-WP-Nonce', berq_nounce);
245 },
246 success: function(response) {
247
248 }
249 })
250 }
251
252 function berq_refresh_cache_stats() {
253 const controller = new AbortController();
254 bwp_controllers.push(controller);
255
256 $.ajax({
257 url: ajaxurl,
258 type: 'POST',
259 data: {
260 action: 'berqwp_refresh_cache_stats',
261 nonce: berq_nounce,
262 },
263 signal: controller.signal,
264 beforeSend: function(xhr) {
265 xhr.setRequestHeader('X-WP-Nonce', berq_nounce);
266 },
267 success: function(data) {
268
269 if (data.success) {
270
271 $('.cache-percentage').html(`${data.data.cache_percentage}% (${data.data.cache_count}) of your pages are currently cached.`);
272
273 $('.cached-pages-bar .progress-bar').css('width', `${data.data.cache_percentage}%`);
274
275 // if (data.data.server_queue > 0) {
276 // $('.bwp-pending-optimization').html(`${data.data.server_queue} pending optimization`);
277
278 // } else {
279 // $('.bwp-pending-optimization').html('');
280 // }
281 }
282
283 },
284 error: function() {
285 console.log('Error in AJAX request.');
286 }
287 });
288 }
289
290 // init_opt_slider();
291
292 $('.berqwp-tab').click(function() {
293 let tab = $(this).attr('data-tab');
294 $("html, body").animate({
295 scrollTop: $(".berqwp-dashbaord").offset().top - 30
296 }, 200);
297
298 $('.berqwp-tab-content > form > div').css({
299 'visibility': 'hidden',
300 'opacity': 0,
301 'height': '0px',
302 'overflow': 'hidden'
303 });
304 $('.berqwp-tab').removeClass('active');
305 $(this).addClass('active');
306 // $(`.berqwp-tab-content #${tab}`).show();
307 $(`.berqwp-tab-content #${tab}`).css({
308 'visibility': 'visible',
309 'opacity': 1,
310 'height': 'auto'
311 });
312
313 let tab_id = $(`.berqwp-tab-content #${tab}`).attr('id');
314 $('input[name="bwp_current_tab_id"]').val(tab_id);
315
316
317 // Get the current URL and its parts
318 const url = new URL(window.location.href);
319
320 // Check if 'tab_id' is present
321 if (url.searchParams.has('tab_id')) {
322 // Update the 'tab_id' parameter value
323 url.searchParams.set('tab_id', tab_id);
324
325 // Update the address bar with the new URL (without reloading the page)
326 window.history.replaceState(null, null, url.toString());
327 }
328
329
330
331 })
332
333 // let tab_id = $('input[name="bwp_current_tab_id"]').val();
334 // $(`.berqwp-tab[data-tab="${tab_id}"]`).trigger('click');
335 let is_admin_page_active = true;
336
337 // Visibility tracking - pause when tab hidden
338 document.addEventListener('visibilitychange', function() {
339 is_admin_page_active = !document.hidden;
340 });
341
342 // berq_refresh_cache_stats();
343
344 // setInterval(function() {
345
346 // if (!is_admin_page_active) return;
347
348 // berq_refresh_cache_stats();
349
350 // }, 10000)
351
352
353 })
354 })(jQuery)
355 </script>
356 <?php
357 if (function_exists('pll_current_language')) {
358 $lang = !empty(pll_current_language()) ? pll_current_language() : 'all';
359 echo "<script>ajaxurl = ajaxurl + '?lang=$lang';</script>";
360 }
361 ?>
362 <script>
363 (function($) {
364 // $(document).ready(function () {
365 // let table = new DataTable('.optimized-pages > table', {
366 // // "paging": false, // Disable pagination
367 // "searching": false, // Disable the search box
368 // "pageLength": 5,
369 // "info": false, // Disable the info text (e.g., "Showing 1 to 10 of 57 entries")
370 // "lengthChange": false
371 // });
372 // })
373
374
375 jQuery(document).ready(function($) {
376 var dataTable = $('.optimized-pages > table').DataTable({
377 ordering: false,
378 paging: true,
379 searching: true,
380 processing: true,
381 serverSide: true,
382 info: false,
383 lengthChange: false,
384 pageLength: 5,
385 ajax: function(data, callback, settings) {
386 var start = settings._iDisplayStart;
387 var length = settings._iDisplayLength;
388
389 $.ajax({
390 url: ajaxurl, // WordPress AJAX URL
391 type: 'POST',
392 data: {
393 action: 'berqwp_get_optimized_pages',
394 start: start,
395 length: length,
396 search: data.search.value
397 },
398 success: function(response) {
399 if (response.success) {
400 callback({
401 draw: data.draw,
402 recordsTotal: response.data.total_entries, // Total number of records
403 recordsFiltered: response.data.records_filtered, // Total after filtering
404 data: response.data.optimized_pages // Data for the current page
405 });
406 } else {
407 console.error("Error fetching data:", response);
408 }
409 },
410 error: function(error) {
411 console.error("AJAX error:", error);
412 }
413 });
414 },
415 columns: [{
416 data: 'url',
417 title: "Page URL"
418 }, // Map 'url' to the first column
419 {
420 data: 'status',
421 title: "Cache Status"
422 }, // Map 'status' to the second column
423 {
424 data: 'last_modified',
425 title: "Last Optimized Date"
426 } // Map 'last_modified' to the third column
427 ]
428 });
429 });
430
431 $('[name="berqwp_lazyload_youtube_embed"]').on('change', function() {
432 if ($(this).is(':checked')) {
433 $('[name="berqwp_preload_yt_poster"]').parent().show();
434 } else {
435 $('[name="berqwp_preload_yt_poster"]').parent().hide();
436 }
437 });
438
439 // $(document).ready(function () {
440 // const stickyDiv = $('.berqwp-dashbaord');
441 // const offset = stickyDiv.offset().top;
442
443 // $(window).on('scroll', function () {
444 // if ($(this).scrollTop() + 30 >= offset) {
445 // stickyDiv.addClass('sticky');
446 // stickyDiv.parent().css('paddingBottom', '100vh');
447 // setTimeout(function() {
448 // var resizeEvent = new Event('resize');
449 // window.dispatchEvent(resizeEvent);
450 // document.dispatchEvent(resizeEvent);
451 // }, 300)
452 // } else {
453 // stickyDiv.removeClass('sticky');
454 // stickyDiv.parent().css('paddingBottom', '0vh');
455 // setTimeout(function() {
456 // var resizeEvent = new Event('resize');
457 // window.dispatchEvent(resizeEvent);
458 // document.dispatchEvent(resizeEvent);
459 // }, 300)
460 // }
461 // });
462 // });
463
464
465
466
467
468
469
470 })(jQuery)
471 </script>
472 <script>
473 (function($) {
474 $(document).ready(function() {
475 let cache_lifespan_options = $('input[name="berqwp_cache_lifespan"], input[name="berq_opt_mode"]');
476
477 cache_lifespan_options.change(function() {
478 cache_lifespan_options.parent('label').removeClass('selected');
479 $('input[name="berqwp_cache_lifespan"]:checked, input[name="berq_opt_mode"]:checked').parent('label').addClass('selected');
480 })
481
482 $('input[name="berqwp_cache_lifespan"]:checked, input[name="berq_opt_mode"]:checked').parent('label').addClass('selected');
483 })
484 })(jQuery)
485 </script>
486 <script>
487 (function($) {
488 $(document).ready(function() {
489 let enable_compression_btn = $('a.berqwp-enable-page-compression');
490 let berq_nounce = '<?php echo esc_html(wp_create_nonce('wp_rest')); ?>';
491
492 enable_compression_btn.click(function(e) {
493 e.preventDefault();
494
495 let loader = enable_compression_btn.find('.berqwp-loader');
496 $.ajax({
497 url: ajaxurl,
498 type: 'POST',
499 data: {
500 action: 'berqwp_enable_page_compression',
501 nonce: berq_nounce,
502 },
503 beforeSend: function(xhr) {
504 xhr.setRequestHeader('X-WP-Nonce', berq_nounce);
505 loader.show();
506 },
507 success: function(data) {
508 loader.hide();
509
510 if (data.success === true) {
511 let currentUrl = window.location.href;
512 let url = new URL(currentUrl);
513 let params = new URLSearchParams(url.search);
514 params.set('berqwp_page_compression_enabled', '');
515 url.search = params.toString();
516 window.location.href = url.toString();
517 } else {
518 alert("Page compression test failed: Your web server doesn't support Gzip compression.");
519 }
520
521
522 },
523 error: function() {
524 loader.hide();
525 alert("Page compression test failed: Please check your internet connection.");
526 }
527 });
528 })
529 })
530 })(jQuery)
531 </script>
532