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