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