PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.5.19
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.5.19
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 3 years ago javascript 3 years ago stylesheet 3 years ago admin.php 3 years ago connect.php 3 years ago dashboard.php 3 years ago diag.php 3 years ago help.php 3 years ago safemode.php 3 years ago safemode.tpl 4 years ago
dashboard.php
930 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"><?php esc_html_e( 'Notifications', 'nitropack' ); ?></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"><?php esc_html_e( 'Optimized Pages', 'nitropack' ); ?>
33 <span id="pending-optimizations-section" class="pull-right mt-1" style="display:none;font-size: 12px;color: #28a745"><?php esc_html_e( 'Processing', 'nitropack' ); ?>
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="<?php esc_html_e( 'Click to learn more', 'nitropack' ); ?>"></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"><?php esc_html_e( 'Last cache purge:', 'nitropack' ); ?> <span data-last-cache-purge><?php esc_html_e( 'Never', 'nitropack' ); ?></span></div>
42 <div id="last-cache-purge-reason" class="text-secondary"><?php esc_html_e( 'Reason:', 'nitropack' ); ?> <span data-purge-reason><?php esc_html_e( 'Unknown', 'nitropack' ); ?></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> <?php esc_html_e( 'mobile pages', 'nitropack' ); ?></div>
46 <div class="optimizations-subcount"><span data-optimized-pages-tablet>0</span> <?php esc_html_e( 'tablet pages', 'nitropack' ); ?></div>
47 <div class="optimizations-subcount"><span data-optimized-pages-desktop>0</span> <?php esc_html_e( 'desktop pages', 'nitropack' ); ?></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"><?php esc_html_e( 'Purge Cache', 'nitropack' ); ?></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"><?php esc_html_e( 'Plan', 'nitropack' ); ?></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"><?php esc_html_e( 'Manage plan', 'nitropack' ); ?></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"><?php esc_html_e( 'Next Reset', 'nitropack' ); ?> <span data-next-reset><?php esc_html_e( 'No ETA', 'nitropack' ); ?></span></li>
69 <li class="list-group-item px-0 d-flex justify-content-between align-items-center"><?php esc_html_e( 'Next Billing', 'nitropack' ); ?> <span data-next-billing><?php esc_html_e( 'No ETA', 'nitropack' ); ?></span></li>
70 </ul>
71 <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> <?php esc_html_e( 'You will be notified if you approach the plan resource limit', 'nitropack' ); ?></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"><?php esc_html_e( 'Optimization Mode', 'nitropack' ); ?></h5>
81 <p><small><?php esc_html_e( 'Slide to change your settings. This will update the level of optimization.', 'nitropack' ); ?></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"><?php esc_html_e( 'Dummy', 'nitropack' ); ?></h6>
94 <p><small></small></p>
95 </div>
96 <div class="text standard">
97 <h6 class="text-info"><?php esc_html_e( 'Standard', 'nitropack' ); ?></h6>
98 <p><small><?php esc_html_e( 'A basic set of optimizations enough to get you up and running. Includes CDN and lossless image optimization.', 'nitropack' ); ?></small></p>
99 </div>
100 <div class="text medium">
101 <h6 class="text-success"><?php esc_html_e( 'Medium', 'nitropack' ); ?></h6>
102 <p><small><?php esc_html_e( 'Well-balanced and suitable for many cases.', 'nitropack' ); ?></small></p>
103 </div>
104 <div class="text strong">
105 <h6 class="nitropack_success_text"><?php esc_html_e( 'Strong', 'nitropack' ); ?></h6>
106 <p><small><?php esc_html_e( 'Very stable. Includes advanced features like automatic image lazy loading and font definition modification. This is the recommended optimization mode.', 'nitropack' ); ?></small></p>
107 </div>
108 <div class="text ludicrous">
109 <h6 class="text-danger"><?php esc_html_e( 'Ludicrous', 'nitropack' ); ?></h6>
110 <p><small><?php esc_html_e( 'A pre-defined configuration aiming to achieve the fastest possible speed. Prioritizes rendering.', 'nitropack' ); ?></small></p>
111 </div>
112 <div class="text custom">
113 <h6><?php esc_html_e( 'Manual', 'nitropack' ); ?></h6>
114 <p><small><?php esc_html_e( 'Use your own settings.', 'nitropack' ); ?> <a id="manual-settings-url" href="javascript:void(0);" target="_blank"><?php esc_html_e( 'Click here', 'nitropack' ); ?></a><?php esc_html_e( 'to configure them.', 'nitropack' ); ?></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"><?php esc_html_e( 'Settings', 'nitropack' ); ?></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><?php esc_html_e( 'Cache Warmup', 'nitropack' ); ?></br>
129 <small><?php esc_html_e( 'Learn more about this feature', 'nitropack' ); ?> <a href="https://support.nitropack.io/hc/en-us/articles/1500002555901-Cache-Warmup-WordPress-" target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'here', 'nitropack' ); ?></a></small>
130 </span>
131 <span id="loading-warmup-status">
132 <?php esc_html_e( 'Loading cache warmup status', 'nitropack' ); ?> <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><?php esc_html_e( 'Safe Mode', 'nitropack' ); ?></br>
143 <small><?php esc_html_e( 'Learn more about this feature', 'nitropack' ); ?> <a href="https://support.nitropack.io/hc/en-us/articles/360060910574-Safe-Mode" target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'here', 'nitropack' ); ?></a></small>
144 </span>
145 <span id="loading-safemode-status">
146 <?php esc_html_e( 'Loading safe mode status', 'nitropack' ); ?> <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;"><?php esc_html_e( 'Testing current compression status', 'nitropack' ); ?> <a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span>
157 <span id="detected-compression"><?php esc_html_e( 'HTML Compression', 'nitropack' ); ?> <a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="<?php esc_html_e( 'Automatically detect whether compression is needed', 'nitropack' ); ?>"><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><?php esc_html_e( 'Ecommerce Cart Cache', 'nitropack' ); ?> <span class="badge badge-info"><?php echo nitropack_is_cart_cache_available() ? __( 'New', 'nitropack' ) : '<a href="https://nitropack.io/pricing" target="_blank" rel="noopener noreferrer" class="text-white">'.__( 'Requires a paid subscription', 'nitropack' ).'</a>'; ?></span></br>
168 <small><?php esc_html_e( 'Your visitors will enjoy full site speed while browsing with items in cart. Fully optimized page cache will be served.', 'nitropack' ); ?></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;<?php esc_html_e( 'Disconnect', 'nitropack' ); ?></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> <?php esc_html_e( 'You can further configure how NitroPack\'s optimization behaves through your account at', 'nitropack' ); ?> <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"><?php esc_html_e( 'Automated Behavior', 'nitropack' ); ?></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><?php esc_html_e( 'Purge affected cache when content is updated or published', 'nitropack' ); ?></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><?php esc_html_e( 'Purge NitroPack cache when Beaver Builder cache is purged', 'nitropack' ); ?><br/>
207 <small><?php esc_html_e( 'Warning: This will perform a full NitroPack cache purge', 'nitropack' ); ?></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><?php esc_html_e( 'Select what post/page types get optimized', 'nitropack' ); ?></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"><?php esc_html_e( 'Configure page types that can be optimized', 'nitropack' ); ?></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"><?php esc_html_e( 'Close', 'nitropack' ); ?></button>
271 <button type="button" class="btn btn-primary" id="save-cacheable-post-types"><?php esc_html_e( 'Save changes', 'nitropack' ); ?>&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 purgeCache();
318 });
319
320 let purgeCache = () => {
321 let purgeEvent = new Event("cache.purge.request");
322 window.dispatchEvent(purgeEvent);
323 }
324
325 $(document).on('click', '[nitropack-rc-data]', function(e) {
326 e.preventDefault();
327 if (isClearing) return;
328 let currentButton = $(this);
329 $.ajax({
330 url: ajaxurl,
331 type: "POST",
332 dataType: "text",
333 data: {
334 action: 'nitropack_clear_residual_cache',
335 gde: currentButton.attr('nitropack-rc-data')
336 },
337 beforeSend: function () {
338 currentButton.parent(".alert-warning").hide();
339 isClearing = true;
340 },
341 success: function(resp) {
342 result = JSON.parse(resp);
343 Notification[result.type](result.message);
344 },
345 error: function(resp) {
346 result = JSON.parse(resp);
347 Notification[result.type](result.message);
348 },
349 complete: function() {
350 isClearing = false;
351 setTimeout(function(){location.reload();}, 3000);
352 }
353 });
354 });
355
356 $("#btn-run-warmup").on("click", function(e) {
357 runWarmup();
358 })
359
360 $("#btn-stop-warmup").on("click", function(e) {
361 disableWarmup();
362 })
363
364 var estimateWarmup = (id, retry) => {
365 id = id || null;
366 retry = retry || 0;
367 if (!id) {
368 $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Estimating optimizations usage', 'nitropack' ); ?>"});
369 //$("#estimation-spinner").show();
370 //$("#warmup-status-slider").hide();
371
372 $.post(ajaxurl, {
373 action: 'nitropack_estimate_warmup'
374 }, function(response) {
375 var resp = JSON.parse(response);
376 if (resp.type == "success") {
377 setTimeout( (function(id){
378 estimateWarmup(id);
379 })(resp.res), 1000 );
380 } else {
381 $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Warmup estimation failed', 'nitropack' ); ?>", timeout: 3000});
382 }
383 });
384 } else {
385 $.post(ajaxurl, {
386 action: 'nitropack_estimate_warmup',
387 estId: id
388 }, function(response) {
389 var resp = JSON.parse(response);
390 if (resp.type == "success") {
391 if (isNaN(resp.res) || resp.res == -1) { // Still calculating
392 if (retry >= 10) {
393 $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Warmup estimation failed. Please try again or contact support if the issue persists.', 'nitropack' ); ?>", dismissable: true});
394 } else {
395 setTimeout( (function(id, retry){
396 estimateWarmup(id, retry);
397 })(id, retry+1), 1000 );
398 }
399 } else {
400 if (resp.res == 0) {
401 $("#settings-widget").cardOverlay("notify", {message: "<?php esc_html_e( 'We could not find any links for warming up on your home page', 'nitropack' ); ?>", timeout: 3000});
402 } else {
403 var confirmHtml = '<p>Enabling cache warmup will optimize ' + resp.res + ' pages. Would you like to continue?</p>';
404 confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectWarmup()" class="btn btn-default btn-sm"><?php esc_html_e( 'No', 'nitropack' ); ?></a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="confirmWarmup()" class="btn btn-success btn-sm"><?php esc_html_e( 'Yes', 'nitropack' ); ?></p></a>';
405 $("#settings-widget").cardOverlay("notify", {message: confirmHtml});
406 }
407 }
408 } else {
409 $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Warmup estimation failed', 'nitropack' ); ?>", timeout: 3000});
410 }
411 });
412 }
413 }
414
415 window.confirmWarmup = function() {
416 $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Enabling warmup', 'nitropack' ); ?>"});
417 enableWarmup();
418 }
419
420 window.rejectWarmup = function() {
421 $("#settings-widget").cardOverlay("clear");
422 }
423
424 var enableWarmup = () => {
425 jQuery.post(ajaxurl, {
426 action: 'nitropack_enable_warmup'
427 }, function(response) {
428 var resp = JSON.parse(response);
429 if (resp.type == "success") {
430 $("#settings-widget").cardOverlay("clear");
431 $("#warmup-status").attr("checked", true);
432 } else {
433 setTimeout(enableWarmup, 1000);
434 }
435 });
436 }
437
438 var disableWarmup = () => {
439 jQuery.post(ajaxurl, {
440 action: 'nitropack_disable_warmup'
441 }, function(response) {
442 var resp = JSON.parse(response);
443 if (resp.type == "success") {
444 // Success notification
445 } else {
446 // Error notification
447 }
448 });
449 }
450
451 var runWarmup = () => {
452 jQuery.post(ajaxurl, {
453 action: 'nitropack_run_warmup'
454 }, function(response) {
455 var resp = JSON.parse(response);
456 if (resp.type == "success") {
457 // Success notification
458 } else {
459 // Error notification
460 }
461 });
462 }
463
464 var enableSafemode = () => {
465 jQuery.post(ajaxurl, {
466 action: 'nitropack_enable_safemode'
467 }, function(response) {
468 var resp = JSON.parse(response);
469 if (resp.type == "success") {
470 $("#safemode-status").attr("checked", true);
471 // Success notification
472 } else {
473 $("#safemode-status").attr("checked", false);
474 // Error notification
475 }
476 });
477 }
478
479 var disableSafemode = () => {
480 jQuery.post(ajaxurl, {
481 action: 'nitropack_disable_safemode'
482 }, function(response) {
483 var resp = JSON.parse(response);
484 if (resp.type == "success") {
485 // Success notification
486 } else {
487 // Error notification
488 }
489 });
490 }
491
492
493
494 var getOptimizations = _ => {
495 var url = '<?php echo $optimizationDetailsUrl; ?>';
496 ((s, e, f) => {
497 if (window.fetch) {
498 fetch(url)
499 .then(resp => resp.json())
500 .then(s)
501 .catch(e)
502 .finally(f);
503 } else {
504 $.ajax({
505 url: url,
506 type: 'GET',
507 dataType: 'json',
508 success: s,
509 error: e,
510 complete: f
511 })
512 }
513 })(data => {
514 $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo);
515 if (data.last_cache_purge.reason) {
516 $('[data-purge-reason]').text(data.last_cache_purge.reason);
517 $('#last-cache-purge-reason').show();
518 } else {
519 $('#last-cache-purge-reason').hide();
520 }
521
522 if (data.pending_count) {
523 $("#pending-optimizations-count").text(data.pending_count);
524 $("#pending-optimizations-section").show();
525 } else {
526 $("#pending-optimizations-section").hide();
527 }
528
529 $('[data-optimized-pages-desktop]').text(data.optimized_pages.desktop);
530 $('[data-optimized-pages-mobile]').text(data.optimized_pages.mobile);
531 $('[data-optimized-pages-tablet]').text(data.optimized_pages.tablet);
532 $('[data-optimized-pages-total]').text(data.optimized_pages.total);
533
534 $("#optimizations-widget").cardOverlay("clear");
535 }, __ => {
536 $("#optimizations-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Error while fetching optimizations data', 'nitropack' ); ?>"});
537 }, __ => {
538 if (!getOptimizationsTimeout) {
539 getOptimizationsTimeout = setTimeout(function() {getOptimizationsTimeout = null; getOptimizations();}, 60000);
540 }
541 });
542 }
543
544 var getPlan = _ => {
545 var url = '<?php echo $planDetailsUrl; ?>';
546 ((s, e, f) => {
547 if (window.fetch) {
548 fetch(url)
549 .then(resp => resp.json())
550 .then(s)
551 .catch(e)
552 .finally(f);
553 } else {
554 $.ajax({
555 url: url,
556 type: 'GET',
557 dataType: 'json',
558 success: s,
559 error: e,
560 complete: f
561 })
562 }
563 })(data => {
564 $('[data-plan-title]').text(data.plan_title);
565 $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A');
566 $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A');
567
568 for (prop in data) {
569 if (prop.indexOf("show_") === 0) continue;
570 if (prop.indexOf("label_") === 0) continue;
571 if (prop.indexOf("max_") === 0) continue;
572 if (
573 typeof data["show_" + prop] != "undefined" &&
574 data["show_" + prop] &&
575 typeof data["label_" + prop] != "undefined" &&
576 typeof data["max_" + prop] != "undefined"
577 ) {
578 let propertyLabel = data["label_" + prop];
579 let propertyValue = data[prop];
580 let propertyLimit = data["max_" + prop];
581 $("#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>');
582 }
583 }
584
585 $("#plan-details-widget").cardOverlay("clear");
586 }, __ => {
587 $("#plan-details-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Error while fetching plan data', 'nitropack' ); ?>"});
588 }, __ => {
589 });
590 }
591
592 var getQuickSetup = _ => {
593 var url = '<?php echo $quickSetupUrl; ?>';
594 ((s, e, f) => {
595 if (window.fetch) {
596 fetch(url)
597 .then(resp => resp.json())
598 .then(s)
599 .catch(e)
600 .finally(f);
601 } else {
602 $.ajax({
603 url: url,
604 type: 'GET',
605 dataType: 'json',
606 success: s,
607 error: e,
608 complete: f
609 })
610 }
611 })(data => {
612 $('#range').val(data.optimization_level);
613 $('#manual-settings-url').attr('href', data.manual_settings_url);
614
615 document.getElementById('range').oninput(false);
616 $("#quicksetup-widget").cardOverlay("clear");
617 }, __ => {
618 $("#quicksetup-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Error while fetching the optimization level settings', 'nitropack' ); ?>"});
619 }, __ => {
620 });
621 }
622
623 window.addEventListener("cache.invalidate.success", getOptimizations);
624 if ($('#np-onstate-cache-purge').length) {
625 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)});
626 } else {
627 window.addEventListener("cache.purge.success", getOptimizations);
628 }
629
630
631 var autoDetectCompression = function() {
632 $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Testing current compression status', 'nitropack' ); ?>"});
633
634 $.post(ajaxurl, {
635 action: 'nitropack_test_compression_ajax'
636 }, function(response) {
637 var resp = JSON.parse(response);
638 if (resp.status == "success") {
639 if (resp.hasCompression) { // compression already enabled
640 $("#compression-status").attr("checked", false);
641 $("#settings-widget").cardOverlay("success", {message: "<?php esc_html_e( 'Compression is already enabled on your server! There is no need to enable it in NitroPack.', 'nitropack' ); ?>", timeout: 3000});
642 } else { // no compression - enable ours
643 $("#compression-status").attr("checked", true);
644 $("#settings-widget").cardOverlay("success", {message: "<?php esc_html_e( 'No compression was detected! We will now enable it in NitroPack.', 'nitropack' ); ?>", timeout: 3000});
645 }
646 Notification.success('Compression settings saved');
647 } else {
648 $("#settings-widget").cardOverlay("error", {message: "<?php esc_html_e( 'Could not determine compression status automatically. Please configure it manually.', 'nitropack' ); ?>", timeout: 3000});
649 }
650 });
651 }
652
653 $("#compression-status").on("click", function(e) {
654 $.post(ajaxurl, {
655 action: 'nitropack_set_compression_ajax',
656 data: {
657 compressionStatus: $(this).is(":checked") ? 1 : 0
658 }
659 }, function(response) {
660 Notification.success("<?php esc_html_e( 'Compression settings saved', 'nitropack' ); ?>");
661 });
662 });
663
664 $("#auto-purge-status").on("click", function(e) {
665 $.post(ajaxurl, {
666 action: 'nitropack_set_auto_cache_purge_ajax',
667 autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0
668 }, function(response) {
669 Notification.success("<?php esc_html_e( 'Automatic cache purge settings saved', 'nitropack' ); ?>");
670 });
671 });
672
673 $("#cart-cache-status").on("click", function(e) {
674 $.post(ajaxurl, {
675 action: 'nitropack_set_cart_cache_ajax',
676 cartCacheStatus: $(this).is(":checked") ? 1 : 0
677 }, function(response) {
678 var resp = JSON.parse(response);
679 if (resp.type == "success") {
680 Notification.success(resp.message);
681 } else {
682 Notification.error(resp.message);
683 }
684 });
685 });
686
687 $("#bb-purge-status").on("click", function(e) {
688 $.post(ajaxurl, {
689 action: 'nitropack_set_bb_cache_purge_sync_ajax',
690 bbCachePurgeSyncStatus: $(this).is(":checked") ? 1 : 0
691 }, function(response) {
692 Notification.success("<?php esc_html_e( 'Beaver Builder cache purge sync settings are saved.', 'nitropack' ); ?>");
693 });
694 });
695
696 $("#save-cacheable-post-types").on("click", function(e) {
697 $(this).find("i").removeClass("d-none");
698 $.ajax({
699 url: ajaxurl,
700 type: "POST",
701 data: {
702 action: 'nitropack_set_cacheable_post_types',
703 cacheableObjectTypes: $('.cacheable-post-type:checked').map(function(i, el){ return el.name; }).toArray()
704 },
705 success: function() {
706 Notification.success("<?php esc_html_e( 'Changes saved', 'nitropack' ); ?>");
707 },
708 error: function() {
709 Notification.error("<?php esc_html_e( 'There was an error while saving the changes. Please try again.', 'nitropack' ); ?>");
710 },
711 complete: function() {
712 $("#save-cacheable-post-types i").addClass("d-none");
713 $("#cacheable-post-types-modal").modal("hide");
714 }
715 });
716 });
717
718 $(document).on('click', "#compression-test-btn", e => {
719 e.preventDefault();
720
721 autoDetectCompression();
722 });
723
724 window.confirmDisconnect = function() {
725 $("#settings-widget").cardOverlay("loading", {message: "<?php esc_html_e( 'Disconnecting...', 'nitropack' ); ?>"});
726 $.ajax({
727 url: ajaxurl,
728 type: "POST",
729 data: {
730 action: "nitropack_disconnect"
731 },
732 complete: function() {
733 location.reload();
734 }
735 });
736 }
737
738 window.closeModalOverlay = function() {
739 $("#settings-widget").cardOverlay("clear");
740 }
741
742 window.performCachePurge = () => {
743 purgeCache();
744 closeModalOverlay();
745 }
746
747 $(document).on('click', "#disconnect-btn", e => {
748 e.preventDefault();
749
750 var confirmHtml = "<p><?php esc_html_e( 'Are you sure that you wish to disconnect?', 'nitropack' ); ?></p>";
751 confirmHtml += '<p id="disconnectConfirmBtns"><a href="javascript:void(0);" onclick="closeModalOverlay()" 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>';
752 $("#settings-widget").cardOverlay("notify", {message: confirmHtml});
753 });
754
755 $("#warmup-status-slider").on("click", function(e) {
756 e.preventDefault();
757 var isEnabled = $("#warmup-status").is(":checked");
758 if (isEnabled) {
759 disableWarmup();
760 $("#warmup-status").attr("checked", false);
761 } else {
762 estimateWarmup();
763 }
764 });
765
766 var loadWarmupStatus = function() {
767 $.ajax({
768 url: ajaxurl,
769 type: "POST",
770 data: {
771 action: "nitropack_warmup_stats"
772 },
773 dataType: "json",
774 success: function(resp) {
775 if (resp.type == "success") {
776 $("#warmup-status").attr("checked", !!resp.stats.status);
777 $("#loading-warmup-status").hide();
778 $("#warmup-toggle").show();
779 } else {
780 setTimeout(loadWarmupStatus, 500);
781 }
782 }
783 });
784 }
785 loadWarmupStatus();
786
787 $("#safemode-status-slider").on("click", function (e) {
788 e.preventDefault();
789 let isEnabled = $("#safemode-status").is(":checked");
790 if (isEnabled) {
791 let confirmHtml = '<p><strong>Purge Cache?</strong></p>' +
792 '<p>It is recommended to perform a full cache purge so all changes are correctly applied.</p>' +
793 '<p>Would you like to purge the cache now?</p>' +
794 '<p><a href="javascript:void(0);" onclick="closeModalOverlay()" class="btn btn-default btn-sm">No</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="performCachePurge()" class="btn btn-info btn-sm">Yes (Recommended)</a></p>';
795 $("#settings-widget").cardOverlay("notify", {message: confirmHtml, dismissable: false});
796 disableSafemode();
797 $("#safemode-status").attr("checked", false);
798 } else {
799 enableSafemode();
800 $("#safemode-status").attr("checked", true);
801 }
802 });
803
804 var loadSafemodeStatus = function() {
805 $.ajax({
806 url: ajaxurl,
807 type: "POST",
808 data: {
809 action: "nitropack_safemode_status"
810 },
811 dataType: "json",
812 success: function(resp) {
813 if (resp.type == "success") {
814 $("#safemode-status").attr("checked", !!resp.isEnabled);
815 $("#loading-safemode-status").hide();
816 $("#safemode-toggle").show();
817 } else {
818 setTimeout(loadSafemodeStatus, 500);
819 }
820 }
821 });
822 }
823 loadSafemodeStatus();
824 })(jQuery);
825
826 (_ => {
827 const classIndex = {
828 1: 'range-success',
829 2: 'range-warning',
830 3: 'range-danger',
831 4: 'range-ludicrous',
832 5: 'range-manual',
833 };
834
835 let rangeInputElement = document.getElementById('range');
836
837 let className = document.getElementsByClassName("label");
838
839 let min = parseInt(rangeInputElement.min);
840 let max = parseInt(rangeInputElement.max);
841
842 const atTimeout = (_ => {
843 var timeout;
844
845 return (callback, time) => {
846 clearTimeout(timeout);
847 timeout = setTimeout(callback, time)
848 };
849 })();
850
851 const saveSetting = function(value) {
852 return new Promise((resolve, reject) => {
853 var xhr = new XMLHttpRequest();
854
855 xhr.open("POST", '<?php echo $quickSetupSaveUrl; ?>', true);
856
857 //Send the proper header information along with the request
858 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
859
860 xhr.onreadystatechange = function() { // Call a function when the state changes.
861 if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
862 resolve();
863 }
864 }
865
866 xhr.send("setting=" + value);
867 });
868 }
869
870 let changeMode = function(do_save) {
871
872 let children = document.getElementById('description').children;
873 let shown;
874
875 if(this.getAttribute("value")) {
876 shown = parseInt(this.getAttribute("value"));
877 }
878 if(this.value) {
879 shown = parseInt(this.value);
880 }
881
882 for (var i = 0; i < children.length; i++) {
883 children.item(i).classList.toggle('hidden', i != shown);
884 }
885
886 document.getElementById('range').classList.remove('range-success', 'range-warning', 'range-danger', 'range-ludicrous', 'range-manual');
887
888 rangeInputElement.value = shown;
889
890 if (classIndex[shown]) {
891 document.getElementById('range').classList.add(classIndex[shown]);
892 }
893
894 if (do_save) {
895 atTimeout(async function() {
896 jQuery("#quicksetup-widget").cardOverlay("loading", {message: "Saving..."});
897 await saveSetting(shown);
898 jQuery("#quicksetup-widget").cardOverlay("clear");
899 }, 0);
900 }
901 };
902
903 rangeInputElement.oninput = changeMode;
904 //rangeInputElement.oninput(false);
905
906 for (var i = min; i <= max; i++) {
907 let divisor = document.createElement('div');
908 let textDescription = document.getElementById('description').children.item(i).getElementsByTagName('p').item(0).textContent;
909
910 let label = document.createElement('div');
911
912 divisor.classList.add("divisor");
913 document.getElementById('divisors').appendChild(divisor);
914
915 label.setAttribute('data-toggle', 'tooltip');
916 label.setAttribute('data-placement', 'top');
917 label.setAttribute('title', textDescription);
918 label.setAttribute('value', i);
919 label.textContent = document.getElementById('description').children.item(i).getElementsByTagName('h6').item(0).textContent;
920 label.classList.add("label");
921 document.getElementById('labels').appendChild(label);
922 }
923
924
925 for (var i = 0; i < className.length; i++) {
926 className[i].addEventListener('click', changeMode, false);
927 }
928 })();
929 </script>
930