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