PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.5.8
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.5.8
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / view / dashboard.php
nitropack / view Last commit date
images 5 years ago javascript 4 years ago stylesheet 4 years ago admin.php 4 years ago connect.php 5 years ago dashboard.php 4 years ago diag.php 4 years ago help.php 6 years ago safemode.tpl 4 years ago
dashboard.php
843 lines
1 <div>
2 <div class="row">
3 <div class="col-md-12">
4 <?php nitropack_display_admin_notices(); ?>
5 </div>
6 </div>
7 <?php if (count(get_nitropack()->Notifications->get('system')) > 0) { ?>
8 <div class="row">
9 <div class="col-12 mb-3">
10 <div class="card-overlay-blurrable np-widget" id="notifications">
11 <div class="card card-d-item">
12 <div class="card-body">
13 <h5 class="card-title">Notifications</h5>
14 <ul class="list-group list-group-flush" id="notifications-list">
15 <?php foreach(get_nitropack()->Notifications->get('system') as $notification) : ?>
16 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
17 <?php echo $notification['message']; ?>
18 </li>
19 <?php endforeach; ?>
20 </ul>
21 </div>
22 </div>
23 </div>
24 </div>
25 </div>
26 <?php } ?>
27 <div class="row">
28 <div class="col-md-6 mb-3">
29 <div class="card-overlay-blurrable np-widget" id="optimizations-widget">
30 <div class="card card-d-item">
31 <div class="card-body">
32 <h5 class="card-title">Optimized Pages<span id="pending-optimizations-section" class="pull-right" style="display:none;font-size: 12px;color: #28a745">Processing <span id="pending-optimizations-count">X</span> page(s) in the background&nbsp;&nbsp;<i class="fa fa-spinner fa-spin"></i></span></h5>
33 <div class="row mt-4" data-hideable>
34 <div id="optimized-pages"><span data-optimized-pages-total>0</span></div>
35 <div id="last-cache-purge" class="text-secondary">Last cache purge: <span data-last-cache-purge>Never</span></div>
36 <div id="last-cache-purge-reason" class="text-secondary">Reason: <span data-purge-reason>Unknown</span></div>
37 </div>
38 <div class="row mt-4 optimizations-hidden" data-hideable>
39 <div class="optimizations-subcount"><span data-optimized-pages-mobile>0</span> mobile pages</div>
40 <div class="optimizations-subcount"><span data-optimized-pages-tablet>0</span> tablet pages</div>
41 <div class="optimizations-subcount"><span data-optimized-pages-desktop>0</span> desktop pages</div>
42 </div>
43 <div class="row mt-5 justify-content-center">
44 <i id="np-purge-cache-loading"class="fa fa-refresh fa-spin" style="margin:5px;font-size:48px;display:none;"></i>
45 <i id="np-purge-cache-success" class="fa fa-check-circle" style="margin:5px;font-size:48px;display:none;"></i>
46 <i id="np-purge-cache-error" class="fa fa-times-circle" style="margin:5px;font-size:48px;display:none;"></i>
47 <button id="optimizations-purge-cache" class="btn btn-light btn-outline-secondary btn-widget-optimizations">Purge Cache</button>
48 </div>
49 </div>
50 </div>
51 </div>
52 </div>
53 <div class="col-md-6 mb-3">
54 <div class="card-overlay-blurrable np-widget" id="plan-details-widget">
55 <div class="card card-d-item">
56 <div class="card-body">
57 <h5 class="card-title">Plan</h5>
58 <div class="mt-3">
59 <h5 class="font-weight-lighter"><span data-plan-title>Unknown</span> <a target="_blank" href="https://nitropack.io/user/billing" class="btn btn-primary btn-sm ml-3">Manage plan</a></h5>
60 </div>
61 <ul class="list-group list-group-flush" id="plan-quotas">
62 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">Next Reset <span data-next-reset>No ETA</span></li>
63 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">Next Billing <span data-next-billing>No ETA</span></li>
64 </ul>
65 <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> You will be notified if you approach the plan resource limit</p>
66 </div>
67 </div>
68 </div>
69 </div>
70 <div class="col-md-6 mb-3">
71 <div class="card-overlay-blurrable np-widget" id="quicksetup-widget">
72 <div class="card card-d-item">
73 <div class="card-body">
74 <h5 class="card-title">Optimization Mode</h5>
75 <p><small>Slide to change your settings. This will update the level of optimization.</small></p>
76
77 <div id="range-container">
78 <div id="labels"></div>
79 <div id="range-element">
80 <div id="divisors"></div>
81 <input id="range" type="range" min="1" max="5" step="1" value="0" />
82 </div>
83 </div>
84
85 <div id="description">
86 <div class="text dummy">
87 <h6 class="text-success">Dummy</h6>
88 <p><small></small></p>
89 </div>
90 <div class="text standard">
91 <h6 class="text-info">Standard</h6>
92 <p><small>A pre-defined configuration without much regard for a high score. Enough to get you up and running.</small></p>
93 </div>
94 <div class="text medium">
95 <h6 class="text-success">Medium</h6>
96 <p><small>Well-balanced and suitable for most cases.</small></p>
97 </div>
98 <div class="text strong">
99 <h6 class="text-warning">Strong</h6>
100 <p><small>Includes advanced features like automatic image lazy loading and font definition modification. May cause issues in some cases.</small></p>
101 </div>
102 <div class="text ludicrous">
103 <h6 class="text-danger">Ludicrous</h6>
104 <p><small>A pre-defined configuration aiming to achieve the highest possible score. In some cases, it may cause issues with your site.</small></p>
105 </div>
106 <div class="text custom">
107 <h6>Manual</h6>
108 <p><small>Use your own settings. <a id="manual-settings-url" href="javascript:void(0);" target="_blank">Click here</a> to configure them.</small></p>
109 </div>
110 </div>
111 </div>
112 </div>
113 </div>
114 </div>
115 <div class="col-md-6 mb-3">
116 <div class="card-overlay-blurrable np-widget" id="settings-widget">
117 <div class="card card-d-item">
118 <div class="card-body">
119 <h5 class="card-title">Settings</h5>
120 <ul class="list-group list-group-flush">
121 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
122 <span>Cache Warmup</br>
123 <small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/1500002555901-Cache-Warmup-WordPress-" target="_blank" rel="noreferrer noopener">here</a></small>
124 </span>
125 <span id="loading-warmup-status">
126 Loading cache warmup status&nbsp;&nbsp;<i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
127 </span>
128 <span id="warmup-toggle" style="display: none;">
129 <label id="warmup-status-slider" class="switch">
130 <input type="checkbox" id="warmup-status">
131 <span class="slider"></span>
132 </label>
133 </span>
134 </li>
135 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
136 <span>Safe Mode</br>
137 <small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/360060910574-Safe-Mode" target="_blank" rel="noreferrer noopener">here</a></small>
138 </span>
139 <span id="loading-safemode-status">
140 Loading safe mode status&nbsp;&nbsp;<i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
141 </span>
142 <span id="safemode-toggle" style="display: none;">
143 <label id="safemode-status-slider" class="switch">
144 <input type="checkbox" id="safemode-status">
145 <span class="slider"></span>
146 </label>
147 </span>
148 </li>
149 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
150 <span id="detecting-compression" style="display: none;">Testing current compression status&nbsp;&nbsp;<a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span>
151 <span id="detected-compression">HTML Compression&nbsp;&nbsp;<a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="Automatically detect whether compression is needed"><i class="fa fa-refresh" style="color: var(--blue);"></i></a></span>
152 <span>
153 <label class="switch">
154 <input type="checkbox" id="compression-status" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>>
155 <span class="slider"></span>
156 </label>
157 </span>
158 </li>
159 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
160 <span>
161 <a href="javascript:void(0);" class="btn btn-danger text-white" id="disconnect-btn"><i class="fa fa-power-off text-white"></i>&nbsp;&nbsp;Disconnect</a>
162 </span>
163 </li>
164 </ul>
165 <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> You can further configure how NitroPack's optimization behaves through your account at <a href="https://nitropack.io/" target="_blank">https://nitropack.io/&nbsp;&nbsp;<i class="fa fa-external-link"></i></a>.</p>
166 </div>
167 </div>
168 </div>
169 </div>
170 <div class="col-md-6 mb-3">
171 <div class="card-overlay-blurrable np-widget" id="automations-widget">
172 <div class="card card-d-item">
173 <div class="card-body">
174 <h5 class="card-title">Automated Behavior</h5>
175 <ul class="list-group list-group-flush">
176 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
177 <span>Purge affected cache when content is updated or published</span>
178 <span id="auto-purge-toggle">
179 <label id="auto-purge-status-slider" class="switch">
180 <input type="checkbox" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>>
181 <span class="slider"></span>
182 </label>
183 </span>
184 </li>
185 <?php if (\NitroPack\Integration\Plugin\BeaverBuilder::isActive()) { ?>
186 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
187 <span>Purge NitroPack cache when Beaver Builder cache is purged<br/>
188 <small>Warning: This will perform a full NitroPack cache purge</small>
189 </span>
190 <span id="bb-purge-toggle">
191 <label id="bb-purge-status-slider" class="switch">
192 <input type="checkbox" id="bb-purge-status" <?php if ($bbCacheSyncPurge) echo "checked"; ?>>
193 <span class="slider"></span>
194 </label>
195 </span>
196 </li>
197 <?php } ?>
198 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
199 <span>Select what post/page types get optimized</span>
200 <span id="cacheable-post-types-btn">
201 <a href="javascript:void(0);" class="btn btn-light btn-outline-secondary" data-toggle="modal" data-target="#cacheable-post-types-modal"><i class="fa fa-cog"></i></a>
202 </span>
203 </li>
204 </ul>
205 </div>
206 </div>
207 </div>
208 </div>
209 </div>
210 </div>
211
212 <!-- Post Types Modal -->
213 <div class="modal" id="cacheable-post-types-modal" tabindex="-1" role="dialog" aria-labelledby="cacheable-post-types-title" aria-hidden="true" data-backdrop="false">
214 <div class="modal-dialog modal-dialog-centered" role="document">
215 <div class="modal-content">
216 <div class="modal-header">
217 <h5 class="modal-title" id="cacheable-post-types-title">Configure page types that can be optimized</h5>
218 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
219 <span aria-hidden="true">&times;</span>
220 </button>
221 </div>
222 <div class="modal-body nitropack-scrollable-modal-body">
223 <ul class="list-group list-group-flush">
224 <?php foreach ($objectTypes as $objectType) {?>
225 <li class="list-group-item px-0 d-flex justify-content-between align-items-center border-0">
226 <span><?php echo $objectType->label; ?></span>
227 <span id="post-type-<?php echo $objectType->name; ?>-toggle">
228 <label id="post-type-<?php echo $objectType->name; ?>-status-slider" class="switch">
229 <input class="cacheable-post-type" name="<?php echo $objectType->name; ?>" type="checkbox" id="post-type-post-status" <?php if (in_array($objectType->name, $cacheableObjectTypes)) echo 'checked'; ?>>
230 <span class="slider"></span>
231 </label>
232 </span>
233 </li>
234 <?php if (!empty($objectType->taxonomies)) {?>
235 <?php foreach ($objectType->taxonomies as $taxonomyType) {?>
236 <li class="list-group-item px-0 d-flex justify-content-between align-items-center list-group-item-indented border-0">
237 <span><?php echo $taxonomyType->label; ?></span>
238 <span id="post-type-<?php echo $taxonomyType->name; ?>-toggle">
239 <label id="post-type-<?php echo $taxonomyType->name; ?>-status-slider" class="switch">
240 <input class="cacheable-post-type" name="<?php echo $taxonomyType->name; ?>" type="checkbox" id="post-type-post-status" <?php if (in_array($taxonomyType->name, $cacheableObjectTypes)) echo 'checked'; ?>>
241 <span class="slider"></span>
242 </label>
243 </span>
244 </li>
245 <?php }?>
246 <?php }?>
247 <?php }?>
248 </ul>
249 </div>
250 <div class="modal-footer">
251 <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
252 <button type="button" class="btn btn-primary" id="save-cacheable-post-types">Save changes&nbsp;&nbsp;<i class="fa fa-spinner fa-spin d-none"></i></button>
253 </div>
254 </div>
255 </div>
256 </div>
257 <script>
258 ($ => {
259 var getOptimizationsTimeout = null;
260 let isClearing = false;
261
262 $(window).on("load",function() {
263 $("#optimizations-widget").cardOverlay("loading", {message: "Loading optimizations data"});
264 $("#plan-details-widget").cardOverlay("loading", {message: "Loading plan data"});
265 $("#quicksetup-widget").cardOverlay("loading", {message: "Loading settings"});
266 getOptimizations();
267 getPlan();
268 getQuickSetup();
269
270 <?php if ($checkedCompression != 1) { ?>
271 autoDetectCompression();
272 <?php } ?>
273 });
274
275 $(document).on('click', '[data-hideable]', function(e) {
276 e.preventDefault();
277
278 $('[data-hideable]').removeClass('optimizations-hidden');
279
280 $(this).addClass('optimizations-hidden');
281 });
282
283 $(document).on('click', '#optimizations-invalidate-cache', function(e) {
284 e.preventDefault();
285 //Overlay.loading("Invalidating cache...");
286
287 invalidateEvent = new Event("cache.invalidate.request");
288 window.dispatchEvent(invalidateEvent);
289 });
290
291 $(document).on('click', '#optimizations-purge-cache', function(e) {
292 e.preventDefault();
293 //Overlay.loading("Purging cache...");
294 purgeEvent = new Event("cache.purge.request");
295 window.dispatchEvent(purgeEvent);
296 });
297
298 $(document).on('click', '[nitropack-rc-data]', function(e) {
299 e.preventDefault();
300 if (isClearing) return;
301 let currentButton = $(this);
302 $.ajax({
303 url: ajaxurl,
304 type: "POST",
305 dataType: "text",
306 data: {
307 action: 'nitropack_clear_residual_cache',
308 gde: currentButton.attr('nitropack-rc-data')
309 },
310 beforeSend: function () {
311 currentButton.parent(".alert-warning").hide();
312 isClearing = true;
313 },
314 success: function(resp) {
315 result = JSON.parse(resp);
316 Notification[result.type](result.message);
317 },
318 error: function(resp) {
319 result = JSON.parse(resp);
320 Notification[result.type](result.message);
321 },
322 complete: function() {
323 isClearing = false;
324 setTimeout(function(){location.reload();}, 3000);
325 }
326 });
327 });
328
329 $("#btn-run-warmup").on("click", function(e) {
330 runWarmup();
331 })
332
333 $("#btn-stop-warmup").on("click", function(e) {
334 disableWarmup();
335 })
336
337 var estimateWarmup = (id, retry) => {
338 id = id || null;
339 retry = retry || 0;
340 if (!id) {
341 $("#settings-widget").cardOverlay("loading", {message: "Estimating optimizations usage"});
342 //$("#estimation-spinner").show();
343 //$("#warmup-status-slider").hide();
344
345 $.post(ajaxurl, {
346 action: 'nitropack_estimate_warmup'
347 }, function(response) {
348 var resp = JSON.parse(response);
349 if (resp.type == "success") {
350 setTimeout( (function(id){
351 estimateWarmup(id);
352 })(resp.res), 1000 );
353 } else {
354 $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000});
355 }
356 });
357 } else {
358 $.post(ajaxurl, {
359 action: 'nitropack_estimate_warmup',
360 estId: id
361 }, function(response) {
362 var resp = JSON.parse(response);
363 if (resp.type == "success") {
364 if (isNaN(resp.res) || resp.res == -1) { // Still calculating
365 if (retry >= 10) {
366 $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed. Please try again or contact support if the issue persists.", dismissable: true});
367 } else {
368 setTimeout( (function(id, retry){
369 estimateWarmup(id, retry);
370 })(id, retry+1), 1000 );
371 }
372 } else {
373 if (resp.res == 0) {
374 $("#settings-widget").cardOverlay("notify", {message: "We could not find any links for warming up on your home page", timeout: 3000});
375 } else {
376 var confirmHtml = '<p>Enabling cache warmup will use ' + resp.res + ' page optimizations. Would you like to continue?</p>';
377 confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectWarmup()" class="btn btn-default btn-sm">No</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="confirmWarmup()" class="btn btn-success btn-sm">Yes</p></a>';
378 $("#settings-widget").cardOverlay("notify", {message: confirmHtml});
379 }
380 }
381 } else {
382 $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000});
383 }
384 });
385 }
386 }
387
388 window.confirmWarmup = function() {
389 $("#settings-widget").cardOverlay("loading", {message: "Enabling warmup"});
390 enableWarmup();
391 }
392
393 window.rejectWarmup = function() {
394 $("#settings-widget").cardOverlay("clear");
395 }
396
397 var enableWarmup = () => {
398 jQuery.post(ajaxurl, {
399 action: 'nitropack_enable_warmup'
400 }, function(response) {
401 var resp = JSON.parse(response);
402 if (resp.type == "success") {
403 $("#settings-widget").cardOverlay("clear");
404 $("#warmup-status").attr("checked", true);
405 } else {
406 setTimeout(enableWarmup, 1000);
407 }
408 });
409 }
410
411 var disableWarmup = () => {
412 jQuery.post(ajaxurl, {
413 action: 'nitropack_disable_warmup'
414 }, function(response) {
415 var resp = JSON.parse(response);
416 if (resp.type == "success") {
417 // Success notification
418 } else {
419 // Error notification
420 }
421 });
422 }
423
424 var runWarmup = () => {
425 jQuery.post(ajaxurl, {
426 action: 'nitropack_run_warmup'
427 }, function(response) {
428 var resp = JSON.parse(response);
429 if (resp.type == "success") {
430 // Success notification
431 } else {
432 // Error notification
433 }
434 });
435 }
436
437 var enableSafemode = () => {
438 jQuery.post(ajaxurl, {
439 action: 'nitropack_enable_safemode'
440 }, function(response) {
441 var resp = JSON.parse(response);
442 if (resp.type == "success") {
443 $("#safemode-status").attr("checked", true);
444 // Success notification
445 } else {
446 $("#safemode-status").attr("checked", false);
447 // Error notification
448 }
449 });
450 }
451
452 var disableSafemode = () => {
453 jQuery.post(ajaxurl, {
454 action: 'nitropack_disable_safemode'
455 }, function(response) {
456 var resp = JSON.parse(response);
457 if (resp.type == "success") {
458 // Success notification
459 } else {
460 // Error notification
461 }
462 });
463 }
464
465 var getOptimizations = _ => {
466 var url = '<?php echo $optimizationDetailsUrl; ?>';
467 ((s, e, f) => {
468 if (window.fetch) {
469 fetch(url)
470 .then(resp => resp.json())
471 .then(s)
472 .catch(e)
473 .finally(f);
474 } else {
475 $.ajax({
476 url: url,
477 type: 'GET',
478 dataType: 'json',
479 success: s,
480 error: e,
481 complete: f
482 })
483 }
484 })(data => {
485 $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo);
486 if (data.last_cache_purge.reason) {
487 $('[data-purge-reason]').text(data.last_cache_purge.reason);
488 $('#last-cache-purge-reason').show();
489 } else {
490 $('#last-cache-purge-reason').hide();
491 }
492
493 if (data.pending_count) {
494 $("#pending-optimizations-count").text(data.pending_count);
495 $("#pending-optimizations-section").show();
496 } else {
497 $("#pending-optimizations-section").hide();
498 }
499
500 $('[data-optimized-pages-desktop]').text(data.optimized_pages.desktop);
501 $('[data-optimized-pages-mobile]').text(data.optimized_pages.mobile);
502 $('[data-optimized-pages-tablet]').text(data.optimized_pages.tablet);
503 $('[data-optimized-pages-total]').text(data.optimized_pages.total);
504
505 $("#optimizations-widget").cardOverlay("clear");
506 }, __ => {
507 $("#optimizations-widget").cardOverlay("error", {message: "Error while fetching optimizations data"});
508 }, __ => {
509 if (!getOptimizationsTimeout) {
510 getOptimizationsTimeout = setTimeout(function() {getOptimizationsTimeout = null; getOptimizations();}, 60000);
511 }
512 });
513 }
514
515 var getPlan = _ => {
516 var url = '<?php echo $planDetailsUrl; ?>';
517 ((s, e, f) => {
518 if (window.fetch) {
519 fetch(url)
520 .then(resp => resp.json())
521 .then(s)
522 .catch(e)
523 .finally(f);
524 } else {
525 $.ajax({
526 url: url,
527 type: 'GET',
528 dataType: 'json',
529 success: s,
530 error: e,
531 complete: f
532 })
533 }
534 })(data => {
535 $('[data-plan-title]').text(data.plan_title);
536 $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A');
537 $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A');
538
539 for (prop in data) {
540 if (prop.indexOf("show_") === 0) continue;
541 if (prop.indexOf("label_") === 0) continue;
542 if (prop.indexOf("max_") === 0) continue;
543 if (
544 typeof data["show_" + prop] != "undefined" &&
545 data["show_" + prop] &&
546 typeof data["label_" + prop] != "undefined" &&
547 typeof data["max_" + prop] != "undefined"
548 ) {
549 let propertyLabel = data["label_" + prop];
550 let propertyValue = data[prop];
551 let propertyLimit = data["max_" + prop];
552 $("#plan-quotas").append('<li class="list-group-item px-0 d-flex justify-content-between align-items-center">' + propertyLabel + ' <span><span data-optimizations>' + propertyValue + '</span> out of <span data-max-optimizations>' + propertyLimit + '</span></span></li>');
553 }
554 }
555
556 $("#plan-details-widget").cardOverlay("clear");
557 }, __ => {
558 $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching plan data"});
559 }, __ => {
560 });
561 }
562
563 var getQuickSetup = _ => {
564 var url = '<?php echo $quickSetupUrl; ?>';
565 ((s, e, f) => {
566 if (window.fetch) {
567 fetch(url)
568 .then(resp => resp.json())
569 .then(s)
570 .catch(e)
571 .finally(f);
572 } else {
573 $.ajax({
574 url: url,
575 type: 'GET',
576 dataType: 'json',
577 success: s,
578 error: e,
579 complete: f
580 })
581 }
582 })(data => {
583 $('#range').val(data.optimization_level);
584 $('#manual-settings-url').attr('href', data.manual_settings_url);
585
586 document.getElementById('range').oninput(false);
587 $("#quicksetup-widget").cardOverlay("clear");
588 }, __ => {
589 $("#quicksetup-widget").cardOverlay("error", {message: "Error while fetching the optimization level settings"});
590 }, __ => {
591 });
592 }
593
594 window.addEventListener("cache.invalidate.success", getOptimizations);
595 if ($('#np-onstate-cache-purge').length) {
596 window.addEventListener("cache.purge.success", function(){setTimeout(function(){document.cookie = "nitropack_apwarning=1; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=<?php echo nitropack_cookiepath(); ?>"; window.location.reload()}, 1500)});
597 } else {
598 window.addEventListener("cache.purge.success", getOptimizations);
599 }
600
601
602 var autoDetectCompression = function() {
603 $("#settings-widget").cardOverlay("loading", {message: "Testing current compression status"});
604
605 $.post(ajaxurl, {
606 action: 'nitropack_test_compression_ajax'
607 }, function(response) {
608 var resp = JSON.parse(response);
609 if (resp.status == "success") {
610 if (resp.hasCompression) { // compression already enabled
611 $("#compression-status").attr("checked", false);
612 $("#settings-widget").cardOverlay("success", {message: "Compression is already enabled on your server! There is no need to enable it in NitroPack.", timeout: 3000});
613 } else { // no compression - enable ours
614 $("#compression-status").attr("checked", true);
615 $("#settings-widget").cardOverlay("success", {message: "No compression was detected! We will now enable it in NitroPack.", timeout: 3000});
616 }
617 Notification.success('Compression settings saved');
618 } else {
619 $("#settings-widget").cardOverlay("error", {message: "Could not determine compression status automatically. Please configure it manually.", timeout: 3000});
620 }
621 });
622 }
623
624 $("#compression-status").on("click", function(e) {
625 $.post(ajaxurl, {
626 action: 'nitropack_set_compression_ajax',
627 data: {
628 compressionStatus: $(this).is(":checked") ? 1 : 0
629 }
630 }, function(response) {
631 Notification.success('Compression settings saved');
632 });
633 });
634
635 $("#auto-purge-status").on("click", function(e) {
636 $.post(ajaxurl, {
637 action: 'nitropack_set_auto_cache_purge_ajax',
638 autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0
639 }, function(response) {
640 Notification.success('Automatic cache purge settings saved');
641 });
642 });
643
644 $("#bb-purge-status").on("click", function(e) {
645 $.post(ajaxurl, {
646 action: 'nitropack_set_bb_cache_purge_sync_ajax',
647 bbCachePurgeSyncStatus: $(this).is(":checked") ? 1 : 0
648 }, function(response) {
649 Notification.success('Beaver Builder cache purge sync settings are saved.');
650 });
651 });
652
653 $("#save-cacheable-post-types").on("click", function(e) {
654 $(this).find("i").removeClass("d-none");
655 $.ajax({
656 url: ajaxurl,
657 type: "POST",
658 data: {
659 action: 'nitropack_set_cacheable_post_types',
660 cacheableObjectTypes: $('.cacheable-post-type:checked').map(function(i, el){ return el.name; }).toArray()
661 },
662 success: function() {
663 Notification.success('Changes saved');
664 },
665 error: function() {
666 Notification.error('There was an error while saving the changes. Please try again.');
667 },
668 complete: function() {
669 $("#save-cacheable-post-types i").addClass("d-none");
670 $("#cacheable-post-types-modal").modal("hide");
671 }
672 });
673 });
674
675 $(document).on('click', "#compression-test-btn", e => {
676 e.preventDefault();
677
678 autoDetectCompression();
679 });
680
681 window.confirmDisconnect = function() {
682 $("#settings-widget").cardOverlay("loading", {message: "Disconnecting..."});
683 $.ajax({
684 url: ajaxurl,
685 type: "POST",
686 data: {
687 action: "nitropack_disconnect"
688 },
689 complete: function() {
690 location.reload();
691 }
692 });
693 }
694
695 window.rejectDisconnect = function() {
696 $("#settings-widget").cardOverlay("clear");
697 }
698
699 $(document).on('click', "#disconnect-btn", e => {
700 e.preventDefault();
701
702 var confirmHtml = '<p>Are you sure that you wish to disconnect?</p>';
703 confirmHtml += '<p id="disconnectConfirmBtns"><a href="javascript:void(0);" onclick="rejectDisconnect()" class="btn btn-default btn-sm">No</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-info btn-sm">Disconnect</a></p>';
704 $("#settings-widget").cardOverlay("notify", {message: confirmHtml});
705 });
706
707 $("#warmup-status-slider").on("click", function(e) {
708 e.preventDefault();
709 var isEnabled = $("#warmup-status").is(":checked");
710 if (isEnabled) {
711 disableWarmup();
712 $("#warmup-status").attr("checked", false);
713 } else {
714 estimateWarmup();
715 }
716 });
717
718 var loadWarmupStatus = function() {
719 $.ajax({
720 url: ajaxurl,
721 type: "POST",
722 data: {
723 action: "nitropack_warmup_stats"
724 },
725 dataType: "json",
726 success: function(resp) {
727 if (resp.type == "success") {
728 $("#warmup-status").attr("checked", !!resp.stats.status);
729 $("#loading-warmup-status").hide();
730 $("#warmup-toggle").show();
731 } else {
732 setTimeout(loadWarmupStatus, 500);
733 }
734 }
735 });
736 }
737 loadWarmupStatus();
738
739 $("#safemode-status-slider").on("click", function(e) {
740 e.preventDefault();
741 var isEnabled = $("#safemode-status").is(":checked");
742 if (isEnabled) {
743 disableSafemode();
744 $("#safemode-status").attr("checked", false);
745 } else {
746 enableSafemode();
747 $("#safemode-status").attr("checked", true);
748 }
749 });
750
751 var loadSafemodeStatus = function() {
752 $.ajax({
753 url: ajaxurl,
754 type: "POST",
755 data: {
756 action: "nitropack_safemode_status"
757 },
758 dataType: "json",
759 success: function(resp) {
760 if (resp.type == "success") {
761 $("#safemode-status").attr("checked", !!resp.isEnabled);
762 $("#loading-safemode-status").hide();
763 $("#safemode-toggle").show();
764 } else {
765 setTimeout(loadSafemodeStatus, 500);
766 }
767 }
768 });
769 }
770 loadSafemodeStatus();
771 })(jQuery);
772
773 (_ => {
774 const classIndex = {
775 1: 'range-success',
776 2: 'range-warning',
777 3: 'range-danger',
778 4: 'range-ludicrous',
779 5: 'range-manual',
780 }
781
782 const atTimeout = (_ => {
783 var timeout;
784
785 return (callback, time) => {
786 clearTimeout(timeout);
787 timeout = setTimeout(callback, time)
788 };
789 })();
790
791 const saveSetting = function(value) {
792 return new Promise((resolve, reject) => {
793 var xhr = new XMLHttpRequest();
794
795 xhr.open("POST", '<?php echo $quickSetupSaveUrl; ?>', true);
796
797 //Send the proper header information along with the request
798 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
799
800 xhr.onreadystatechange = function() { // Call a function when the state changes.
801 if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
802 resolve();
803 }
804 }
805
806 xhr.send("setting=" + value);
807 });
808 }
809
810 document.getElementById('range').oninput = function() {
811 var children = document.getElementById('description').children;
812 var shown = parseInt(this.value);
813
814 for (var i = 0; i < children.length; i++) {
815 children.item(i).classList.toggle('hidden', i != shown);
816 }
817
818 document.getElementById('range').classList.remove('range-success', 'range-warning', 'range-danger', 'range-ludicrous', 'range-manual');
819
820 if (classIndex[shown]) {
821 document.getElementById('range').classList.add(classIndex[shown]);
822 }
823
824 atTimeout(async function() {
825 await saveSetting(shown);
826 }, 500);
827 };
828
829 var min = parseInt(document.getElementById('range').min);
830 var max = parseInt(document.getElementById('range').max);
831 for (var i = min; i <= max; i++) {
832 let divisor = document.createElement('div');
833 divisor.classList.add("divisor");
834 document.getElementById('divisors').appendChild(divisor);
835
836 let label = document.createElement('div');
837 label.textContent = document.getElementById('description').children.item(i).getElementsByTagName('h6').item(0).textContent;
838 label.classList.add("label");
839 document.getElementById('labels').appendChild(label);
840 }
841 })();
842 </script>
843