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