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