images
5 years ago
javascript
5 years ago
stylesheet
5 years ago
admin.php
5 years ago
connect.php
5 years ago
dashboard.php
5 years ago
diag.php
5 years ago
help.php
6 years ago
dashboard.php
731 lines
| 1 | <div> |
| 2 | <div class="row"> |
| 3 | <div class="col-md-12"> |
| 4 | <?php nitropack_display_admin_notices(); ?> |
| 5 | </div> |
| 6 | </div> |
| 7 | <div class="row"> |
| 8 | <div class="col-md-6 mb-3"> |
| 9 | <div class="card-overlay-blurrable np-widget" id="optimizations-widget"> |
| 10 | <div class="card card-d-item"> |
| 11 | <div class="card-body"> |
| 12 | <h5 class="card-title">Optimized Pages<span id="pending-optimizations-section" class="pull-right" style="display:none;font-size: 12px;color: #28a745">Processing <span id="pending-optimizations-count">X</span> page(s) in the background <i class="fa fa-spinner fa-spin"></i></span></h5> |
| 13 | <div class="row mt-4" data-hideable> |
| 14 | <div id="optimized-pages"><span data-optimized-pages-total>0</span></div> |
| 15 | <div id="last-cache-purge" class="text-secondary">Last cache purge: <span data-last-cache-purge>Never</span></div> |
| 16 | <div id="last-cache-purge-reason" class="text-secondary">Reason: <span data-purge-reason>Unknown</span></div> |
| 17 | </div> |
| 18 | <div class="row mt-4 optimizations-hidden" data-hideable> |
| 19 | <div class="optimizations-subcount"><span data-optimized-pages-mobile>0</span> mobile pages</div> |
| 20 | <div class="optimizations-subcount"><span data-optimized-pages-tablet>0</span> tablet pages</div> |
| 21 | <div class="optimizations-subcount"><span data-optimized-pages-desktop>0</span> desktop pages</div> |
| 22 | </div> |
| 23 | <div class="row mt-5 justify-content-center"> |
| 24 | <button id="optimizations-purge-cache" class="btn btn-light btn-outline-secondary btn-widget-optimizations">Purge Cache</button> |
| 25 | </div> |
| 26 | </div> |
| 27 | </div> |
| 28 | </div> |
| 29 | </div> |
| 30 | <div class="col-md-6 mb-3"> |
| 31 | <div class="card-overlay-blurrable np-widget" id="plan-details-widget"> |
| 32 | <div class="card card-d-item"> |
| 33 | <div class="card-body"> |
| 34 | <h5 class="card-title">Plan</h5> |
| 35 | <div class="mt-3"> |
| 36 | <h5 class="font-weight-lighter"><span data-plan-title>Unknown</span> <a target="_blank" href="https://nitropack.io/user/billing" class="btn btn-primary btn-sm ml-3">Manage plan</a></h5> |
| 37 | </div> |
| 38 | <ul class="list-group list-group-flush" id="plan-quotas"> |
| 39 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center">Next Reset <span data-next-reset>No ETA</span></li> |
| 40 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center">Next Billing <span data-next-billing>No ETA</span></li> |
| 41 | </ul> |
| 42 | <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> You will be notified if you approach the plan resource limit</p> |
| 43 | </div> |
| 44 | </div> |
| 45 | </div> |
| 46 | </div> |
| 47 | <div class="col-md-6 mb-3"> |
| 48 | <div class="card-overlay-blurrable np-widget" id="quicksetup-widget"> |
| 49 | <div class="card card-d-item"> |
| 50 | <div class="card-body"> |
| 51 | <h5 class="card-title">Optimization Mode</h5> |
| 52 | <p><small>Slide to change your settings. This will update the level of optimization.</small></p> |
| 53 | |
| 54 | <div id="range-container"> |
| 55 | <div id="labels"></div> |
| 56 | <div id="range-element"> |
| 57 | <div id="divisors"></div> |
| 58 | <input id="range" type="range" min="1" max="5" step="1" value="0" /> |
| 59 | </div> |
| 60 | </div> |
| 61 | |
| 62 | <div id="description"> |
| 63 | <div class="text dummy"> |
| 64 | <h6 class="text-success">Dummy</h6> |
| 65 | <p><small></small></p> |
| 66 | </div> |
| 67 | <div class="text standard"> |
| 68 | <h6 class="text-info">Standard</h6> |
| 69 | <p><small>A pre-defined configuration without much regard for a high score. Enough to get you up and running.</small></p> |
| 70 | </div> |
| 71 | <div class="text medium"> |
| 72 | <h6 class="text-success">Medium</h6> |
| 73 | <p><small>Well-balanced and suitable for most cases.</small></p> |
| 74 | </div> |
| 75 | <div class="text strong"> |
| 76 | <h6 class="text-warning">Strong</h6> |
| 77 | <p><small>Includes advanced features like automatic image lazy loading and font definition modification. May cause issues in some cases.</small></p> |
| 78 | </div> |
| 79 | <div class="text ludicrous"> |
| 80 | <h6 class="text-danger">Ludicrous</h6> |
| 81 | <p><small>A pre-defined configuration aiming to achieve the highest possible score. In some cases, it may cause issues with your site.</small></p> |
| 82 | </div> |
| 83 | <div class="text custom"> |
| 84 | <h6>Manual</h6> |
| 85 | <p><small>Use your own settings. <a id="manual-settings-url" href="javascript:void(0);" target="_blank">Click here</a> to configure them.</small></p> |
| 86 | </div> |
| 87 | </div> |
| 88 | </div> |
| 89 | </div> |
| 90 | </div> |
| 91 | </div> |
| 92 | <div class="col-md-6 mb-3"> |
| 93 | <div class="card-overlay-blurrable np-widget" id="settings-widget"> |
| 94 | <div class="card card-d-item"> |
| 95 | <div class="card-body"> |
| 96 | <h5 class="card-title">Settings</h5> |
| 97 | <ul class="list-group list-group-flush"> |
| 98 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 99 | <span>Cache Warmup</br> |
| 100 | <small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/1500002555901-Cache-Warmup-WordPress-" target="_blank" rel="noreferrer noopener">here</a></small> |
| 101 | </span> |
| 102 | <span id="loading-warmup-status"> |
| 103 | Loading cache warmup status <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i> |
| 104 | </span> |
| 105 | <span id="warmup-toggle" style="display: none;"> |
| 106 | <label id="warmup-status-slider" class="switch"> |
| 107 | <input type="checkbox" id="warmup-status"> |
| 108 | <span class="slider"></span> |
| 109 | </label> |
| 110 | </span> |
| 111 | </li> |
| 112 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 113 | <span>Safe Mode</br> |
| 114 | <small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/360060910574-Safe-Mode" target="_blank" rel="noreferrer noopener">here</a></small> |
| 115 | </span> |
| 116 | <span id="loading-safemode-status"> |
| 117 | Loading safe mode status <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i> |
| 118 | </span> |
| 119 | <span id="safemode-toggle" style="display: none;"> |
| 120 | <label id="safemode-status-slider" class="switch"> |
| 121 | <input type="checkbox" id="safemode-status"> |
| 122 | <span class="slider"></span> |
| 123 | </label> |
| 124 | </span> |
| 125 | </li> |
| 126 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 127 | <span id="detecting-compression" style="display: none;">Testing current compression status <a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span> |
| 128 | <span id="detected-compression">HTML Compression <a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="Automatically detect whether compression is needed"><i class="fa fa-refresh" style="color: var(--blue);"></i></a></span> |
| 129 | <span> |
| 130 | <label class="switch"> |
| 131 | <input type="checkbox" id="compression-status" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>> |
| 132 | <span class="slider"></span> |
| 133 | </label> |
| 134 | </span> |
| 135 | </li> |
| 136 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 137 | <span> |
| 138 | <a href="javascript:void(0);" class="btn btn-danger text-white" id="disconnect-btn"><i class="fa fa-power-off text-white"></i> Disconnect</a> |
| 139 | </span> |
| 140 | </li> |
| 141 | </ul> |
| 142 | <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> You can further configure how NitroPack's optimization behaves through your account at <a href="https://nitropack.io/" target="_blank">https://nitropack.io/ <i class="fa fa-external-link"></i></a>.</p> |
| 143 | </div> |
| 144 | </div> |
| 145 | </div> |
| 146 | </div> |
| 147 | <div class="col-md-6 mb-3"> |
| 148 | <div class="card-overlay-blurrable np-widget" id="automations-widget"> |
| 149 | <div class="card card-d-item"> |
| 150 | <div class="card-body"> |
| 151 | <h5 class="card-title">Automated Behavior</h5> |
| 152 | <ul class="list-group list-group-flush"> |
| 153 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 154 | <span>Purge affected cache when content is updated or published</span> |
| 155 | <span id="auto-purge-toggle"> |
| 156 | <label id="auto-purge-status-slider" class="switch"> |
| 157 | <input type="checkbox" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>> |
| 158 | <span class="slider"></span> |
| 159 | </label> |
| 160 | </span> |
| 161 | </li> |
| 162 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 163 | <span>Select what post/page types get optimized</span> |
| 164 | <span id="cacheable-post-types-btn"> |
| 165 | <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> |
| 166 | </span> |
| 167 | </li> |
| 168 | </ul> |
| 169 | </div> |
| 170 | </div> |
| 171 | </div> |
| 172 | </div> |
| 173 | </div> |
| 174 | </div> |
| 175 | |
| 176 | <!-- Post Types Modal --> |
| 177 | <div class="modal" id="cacheable-post-types-modal" tabindex="-1" role="dialog" aria-labelledby="cacheable-post-types-title" aria-hidden="true" data-backdrop="false"> |
| 178 | <div class="modal-dialog modal-dialog-centered" role="document"> |
| 179 | <div class="modal-content"> |
| 180 | <div class="modal-header"> |
| 181 | <h5 class="modal-title" id="cacheable-post-types-title">Configure page types that can be optimized</h5> |
| 182 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> |
| 183 | <span aria-hidden="true">×</span> |
| 184 | </button> |
| 185 | </div> |
| 186 | <div class="modal-body nitropack-scrollable-modal-body"> |
| 187 | <ul class="list-group list-group-flush"> |
| 188 | <?php foreach ($objectTypes as $objectType) {?> |
| 189 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center border-0"> |
| 190 | <span><?php echo $objectType->label; ?></span> |
| 191 | <span id="post-type-<?php echo $objectType->name; ?>-toggle"> |
| 192 | <label id="post-type-<?php echo $objectType->name; ?>-status-slider" class="switch"> |
| 193 | <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'; ?>> |
| 194 | <span class="slider"></span> |
| 195 | </label> |
| 196 | </span> |
| 197 | </li> |
| 198 | <?php if (!empty($objectType->taxonomies)) {?> |
| 199 | <?php foreach ($objectType->taxonomies as $taxonomyType) {?> |
| 200 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center list-group-item-indented border-0"> |
| 201 | <span><?php echo $taxonomyType->label; ?></span> |
| 202 | <span id="post-type-<?php echo $taxonomyType->name; ?>-toggle"> |
| 203 | <label id="post-type-<?php echo $taxonomyType->name; ?>-status-slider" class="switch"> |
| 204 | <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'; ?>> |
| 205 | <span class="slider"></span> |
| 206 | </label> |
| 207 | </span> |
| 208 | </li> |
| 209 | <?php }?> |
| 210 | <?php }?> |
| 211 | <?php }?> |
| 212 | </ul> |
| 213 | </div> |
| 214 | <div class="modal-footer"> |
| 215 | <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> |
| 216 | <button type="button" class="btn btn-primary" id="save-cacheable-post-types">Save changes <i class="fa fa-spinner fa-spin d-none"></i></button> |
| 217 | </div> |
| 218 | </div> |
| 219 | </div> |
| 220 | </div> |
| 221 | <script> |
| 222 | ($ => { |
| 223 | var getOptimizationsTimeout = null; |
| 224 | |
| 225 | $(window).on("load",function() { |
| 226 | $("#optimizations-widget").cardOverlay("loading", {message: "Loading optimizations data"}); |
| 227 | $("#plan-details-widget").cardOverlay("loading", {message: "Loading plan data"}); |
| 228 | $("#quicksetup-widget").cardOverlay("loading", {message: "Loading settings"}); |
| 229 | getOptimizations(); |
| 230 | getPlan(); |
| 231 | getQuickSetup(); |
| 232 | |
| 233 | <?php if ($checkedCompression != 1) { ?> |
| 234 | autoDetectCompression(); |
| 235 | <?php } ?> |
| 236 | }); |
| 237 | |
| 238 | $(document).on('click', '[data-hideable]', function(e) { |
| 239 | e.preventDefault(); |
| 240 | |
| 241 | $('[data-hideable]').removeClass('optimizations-hidden'); |
| 242 | |
| 243 | $(this).addClass('optimizations-hidden'); |
| 244 | }); |
| 245 | |
| 246 | $(document).on('click', '#optimizations-invalidate-cache', function(e) { |
| 247 | e.preventDefault(); |
| 248 | //Overlay.loading("Invalidating cache..."); |
| 249 | |
| 250 | invalidateEvent = new Event("cache.invalidate.request"); |
| 251 | window.dispatchEvent(invalidateEvent); |
| 252 | }); |
| 253 | |
| 254 | $(document).on('click', '#optimizations-purge-cache', function(e) { |
| 255 | e.preventDefault(); |
| 256 | //Overlay.loading("Purging cache..."); |
| 257 | |
| 258 | purgeEvent = new Event("cache.purge.request"); |
| 259 | window.dispatchEvent(purgeEvent); |
| 260 | }); |
| 261 | |
| 262 | $("#btn-run-warmup").on("click", function(e) { |
| 263 | runWarmup(); |
| 264 | }) |
| 265 | |
| 266 | $("#btn-stop-warmup").on("click", function(e) { |
| 267 | disableWarmup(); |
| 268 | }) |
| 269 | |
| 270 | var estimateWarmup = (id, retry) => { |
| 271 | id = id || null; |
| 272 | retry = retry || 0; |
| 273 | if (!id) { |
| 274 | $("#settings-widget").cardOverlay("loading", {message: "Estimating optimizations usage"}); |
| 275 | //$("#estimation-spinner").show(); |
| 276 | //$("#warmup-status-slider").hide(); |
| 277 | |
| 278 | $.post(ajaxurl, { |
| 279 | action: 'nitropack_estimate_warmup' |
| 280 | }, function(response) { |
| 281 | var resp = JSON.parse(response); |
| 282 | if (resp.type == "success") { |
| 283 | setTimeout( (function(id){ |
| 284 | estimateWarmup(id); |
| 285 | })(resp.res), 1000 ); |
| 286 | } else { |
| 287 | $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000}); |
| 288 | } |
| 289 | }); |
| 290 | } else { |
| 291 | $.post(ajaxurl, { |
| 292 | action: 'nitropack_estimate_warmup', |
| 293 | estId: id |
| 294 | }, function(response) { |
| 295 | var resp = JSON.parse(response); |
| 296 | if (resp.type == "success") { |
| 297 | if (isNaN(resp.res) || resp.res == -1) { // Still calculating |
| 298 | if (retry >= 10) { |
| 299 | $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed. Please try again or contact support if the issue persists.", dismissable: true}); |
| 300 | } else { |
| 301 | setTimeout( (function(id, retry){ |
| 302 | estimateWarmup(id, retry); |
| 303 | })(id, retry+1), 1000 ); |
| 304 | } |
| 305 | } else { |
| 306 | if (resp.res == 0) { |
| 307 | $("#settings-widget").cardOverlay("notify", {message: "We could not find any links for warming up on your home page", timeout: 3000}); |
| 308 | } else { |
| 309 | var confirmHtml = '<p>Enabling cache warmup will use ' + resp.res + ' page optimizations. Would you like to continue?</p>'; |
| 310 | confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectWarmup()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="confirmWarmup()" class="btn btn-success btn-sm">Yes</p></a>'; |
| 311 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml}); |
| 312 | } |
| 313 | } |
| 314 | } else { |
| 315 | $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000}); |
| 316 | } |
| 317 | }); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | window.confirmWarmup = function() { |
| 322 | $("#settings-widget").cardOverlay("loading", {message: "Enabling warmup"}); |
| 323 | enableWarmup(); |
| 324 | } |
| 325 | |
| 326 | window.rejectWarmup = function() { |
| 327 | $("#settings-widget").cardOverlay("clear"); |
| 328 | } |
| 329 | |
| 330 | var enableWarmup = () => { |
| 331 | jQuery.post(ajaxurl, { |
| 332 | action: 'nitropack_enable_warmup' |
| 333 | }, function(response) { |
| 334 | var resp = JSON.parse(response); |
| 335 | if (resp.type == "success") { |
| 336 | $("#settings-widget").cardOverlay("clear"); |
| 337 | $("#warmup-status").attr("checked", true); |
| 338 | } else { |
| 339 | setTimeout(enableWarmup, 1000); |
| 340 | } |
| 341 | }); |
| 342 | } |
| 343 | |
| 344 | var disableWarmup = () => { |
| 345 | jQuery.post(ajaxurl, { |
| 346 | action: 'nitropack_disable_warmup' |
| 347 | }, function(response) { |
| 348 | var resp = JSON.parse(response); |
| 349 | if (resp.type == "success") { |
| 350 | // Success notification |
| 351 | } else { |
| 352 | // Error notification |
| 353 | } |
| 354 | }); |
| 355 | } |
| 356 | |
| 357 | var runWarmup = () => { |
| 358 | jQuery.post(ajaxurl, { |
| 359 | action: 'nitropack_run_warmup' |
| 360 | }, function(response) { |
| 361 | var resp = JSON.parse(response); |
| 362 | if (resp.type == "success") { |
| 363 | // Success notification |
| 364 | } else { |
| 365 | // Error notification |
| 366 | } |
| 367 | }); |
| 368 | } |
| 369 | |
| 370 | var enableSafemode = () => { |
| 371 | jQuery.post(ajaxurl, { |
| 372 | action: 'nitropack_enable_safemode' |
| 373 | }, function(response) { |
| 374 | var resp = JSON.parse(response); |
| 375 | if (resp.type == "success") { |
| 376 | $("#safemode-status").attr("checked", true); |
| 377 | // Success notification |
| 378 | } else { |
| 379 | $("#safemode-status").attr("checked", false); |
| 380 | // Error notification |
| 381 | } |
| 382 | }); |
| 383 | } |
| 384 | |
| 385 | var disableSafemode = () => { |
| 386 | jQuery.post(ajaxurl, { |
| 387 | action: 'nitropack_disable_safemode' |
| 388 | }, function(response) { |
| 389 | var resp = JSON.parse(response); |
| 390 | if (resp.type == "success") { |
| 391 | // Success notification |
| 392 | } else { |
| 393 | // Error notification |
| 394 | } |
| 395 | }); |
| 396 | } |
| 397 | |
| 398 | var getOptimizations = _ => { |
| 399 | $.ajax({ |
| 400 | url: '<?php echo $optimizationDetailsUrl; ?>', |
| 401 | type: 'GET', |
| 402 | dataType: 'json', |
| 403 | success: function(data) { |
| 404 | $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo); |
| 405 | if (data.last_cache_purge.reason) { |
| 406 | $('[data-purge-reason]').text(data.last_cache_purge.reason); |
| 407 | $('#last-cache-purge-reason').show(); |
| 408 | } else { |
| 409 | $('#last-cache-purge-reason').hide(); |
| 410 | } |
| 411 | |
| 412 | if (data.pending_count) { |
| 413 | $("#pending-optimizations-count").text(data.pending_count); |
| 414 | $("#pending-optimizations-section").show(); |
| 415 | } else { |
| 416 | $("#pending-optimizations-section").hide(); |
| 417 | } |
| 418 | |
| 419 | $('[data-optimized-pages-desktop]').text(data.optimized_pages.desktop); |
| 420 | $('[data-optimized-pages-mobile]').text(data.optimized_pages.mobile); |
| 421 | $('[data-optimized-pages-tablet]').text(data.optimized_pages.tablet); |
| 422 | $('[data-optimized-pages-total]').text(data.optimized_pages.total); |
| 423 | |
| 424 | $("#optimizations-widget").cardOverlay("clear"); |
| 425 | }, |
| 426 | error: function() { |
| 427 | //Overlay.error("An unexpected error has occurred.", 10000, true); |
| 428 | }, |
| 429 | complete: function() { |
| 430 | if (!getOptimizationsTimeout) { |
| 431 | getOptimizationsTimeout = setTimeout(function() {getOptimizationsTimeout = null; getOptimizations();}, 60000); |
| 432 | } |
| 433 | } |
| 434 | }) |
| 435 | } |
| 436 | |
| 437 | var getPlan = _ => { |
| 438 | $.ajax({ |
| 439 | url: '<?php echo $planDetailsUrl; ?>', |
| 440 | type: 'GET', |
| 441 | dataType: 'json', |
| 442 | success: function(data) { |
| 443 | $('[data-plan-title]').text(data.plan_title); |
| 444 | $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A'); |
| 445 | $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A'); |
| 446 | |
| 447 | for (prop in data) { |
| 448 | if (prop.indexOf("show_") === 0) continue; |
| 449 | if (prop.indexOf("label_") === 0) continue; |
| 450 | if (prop.indexOf("max_") === 0) continue; |
| 451 | if ( |
| 452 | typeof data["show_" + prop] != "undefined" && |
| 453 | data["show_" + prop] && |
| 454 | typeof data["label_" + prop] != "undefined" && |
| 455 | typeof data["max_" + prop] != "undefined" |
| 456 | ) { |
| 457 | let propertyLabel = data["label_" + prop]; |
| 458 | let propertyValue = data[prop]; |
| 459 | let propertyLimit = data["max_" + prop]; |
| 460 | $("#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>'); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | $("#plan-details-widget").cardOverlay("clear"); |
| 465 | }, |
| 466 | error: function() { |
| 467 | $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching plan data"}); |
| 468 | } |
| 469 | }) |
| 470 | } |
| 471 | |
| 472 | var getQuickSetup = _ => { |
| 473 | $.ajax({ |
| 474 | url: '<?php echo $quickSetupUrl; ?>', |
| 475 | type: 'GET', |
| 476 | dataType: 'json', |
| 477 | success: function(data) { |
| 478 | $('#range').val(data.optimization_level); |
| 479 | $('#manual-settings-url').attr('href', data.manual_settings_url); |
| 480 | |
| 481 | document.getElementById('range').oninput(false); |
| 482 | $("#quicksetup-widget").cardOverlay("clear"); |
| 483 | }, |
| 484 | error: function() { |
| 485 | $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching the optimization level settings"}); |
| 486 | } |
| 487 | }) |
| 488 | } |
| 489 | |
| 490 | window.addEventListener("cache.invalidate.success", getOptimizations); |
| 491 | window.addEventListener("cache.purge.success", getOptimizations); |
| 492 | |
| 493 | |
| 494 | var autoDetectCompression = function() { |
| 495 | $("#settings-widget").cardOverlay("loading", {message: "Testing current compression status"}); |
| 496 | |
| 497 | $.post(ajaxurl, { |
| 498 | action: 'nitropack_test_compression_ajax' |
| 499 | }, function(response) { |
| 500 | var resp = JSON.parse(response); |
| 501 | if (resp.status == "success") { |
| 502 | if (resp.hasCompression) { // compression already enabled |
| 503 | $("#compression-status").attr("checked", false); |
| 504 | $("#settings-widget").cardOverlay("success", {message: "Compression is already enabled on your server! There is no need to enable it in NitroPack.", timeout: 3000}); |
| 505 | } else { // no compression - enable ours |
| 506 | $("#compression-status").attr("checked", true); |
| 507 | $("#settings-widget").cardOverlay("success", {message: "No compression was detected! We will now enable it in NitroPack.", timeout: 3000}); |
| 508 | } |
| 509 | Notification.success('Compression settings saved'); |
| 510 | } else { |
| 511 | $("#settings-widget").cardOverlay("error", {message: "Could not determine compression status automatically. Please configure it manually.", timeout: 3000}); |
| 512 | } |
| 513 | }); |
| 514 | } |
| 515 | |
| 516 | $("#compression-status").on("click", function(e) { |
| 517 | $.post(ajaxurl, { |
| 518 | action: 'nitropack_set_compression_ajax', |
| 519 | data: { |
| 520 | compressionStatus: $(this).is(":checked") ? 1 : 0 |
| 521 | } |
| 522 | }, function(response) { |
| 523 | Notification.success('Compression settings saved'); |
| 524 | }); |
| 525 | }); |
| 526 | |
| 527 | $("#auto-purge-status").on("click", function(e) { |
| 528 | $.post(ajaxurl, { |
| 529 | action: 'nitropack_set_auto_cache_purge_ajax', |
| 530 | autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0 |
| 531 | }, function(response) { |
| 532 | Notification.success('Automatic cache purge settings saved'); |
| 533 | }); |
| 534 | }); |
| 535 | |
| 536 | $("#save-cacheable-post-types").on("click", function(e) { |
| 537 | $(this).find("i").removeClass("d-none"); |
| 538 | $.ajax({ |
| 539 | url: ajaxurl, |
| 540 | type: "POST", |
| 541 | data: { |
| 542 | action: 'nitropack_set_cacheable_post_types', |
| 543 | cacheableObjectTypes: $('.cacheable-post-type:checked').map(function(i, el){ return el.name; }).toArray() |
| 544 | }, |
| 545 | success: function() { |
| 546 | Notification.success('Changes saved'); |
| 547 | }, |
| 548 | error: function() { |
| 549 | Notification.error('There was an error while saving the changes. Please try again.'); |
| 550 | }, |
| 551 | complete: function() { |
| 552 | $("#save-cacheable-post-types i").addClass("d-none"); |
| 553 | $("#cacheable-post-types-modal").modal("hide"); |
| 554 | } |
| 555 | }); |
| 556 | }); |
| 557 | |
| 558 | $(document).on('click', "#compression-test-btn", e => { |
| 559 | e.preventDefault(); |
| 560 | |
| 561 | autoDetectCompression(); |
| 562 | }); |
| 563 | |
| 564 | window.confirmDisconnect = function() { |
| 565 | $("#settings-widget").cardOverlay("loading", {message: "Disconnecting..."}); |
| 566 | $.ajax({ |
| 567 | url: ajaxurl, |
| 568 | type: "POST", |
| 569 | data: { |
| 570 | action: "nitropack_disconnect" |
| 571 | }, |
| 572 | complete: function() { |
| 573 | location.reload(); |
| 574 | } |
| 575 | }); |
| 576 | } |
| 577 | |
| 578 | window.rejectDisconnect = function() { |
| 579 | $("#settings-widget").cardOverlay("clear"); |
| 580 | } |
| 581 | |
| 582 | window.safemodeOnDisconnect = function() { |
| 583 | enableSafemode(); |
| 584 | $("#settings-widget").cardOverlay("clear"); |
| 585 | } |
| 586 | |
| 587 | $(document).on('click', "#disconnect-btn", e => { |
| 588 | e.preventDefault(); |
| 589 | |
| 590 | var confirmHtml = '<p>Did you know that NitroPack offers a safe mode? We recommend using it instead of disconnecting. Are you sure that you wish to disconnect?</p>'; |
| 591 | confirmHtml += '<p id="disconnectConfirmBtns"><a href="javascript:void(0);" onclick="rejectDisconnect()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="safemodeOnDisconnect()" class="btn btn-primary btn-sm">Enable Safe Mode</a> <a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-info btn-sm">Disconnect</a></p>'; |
| 592 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml}); |
| 593 | }); |
| 594 | |
| 595 | $("#warmup-status-slider").on("click", function(e) { |
| 596 | e.preventDefault(); |
| 597 | var isEnabled = $("#warmup-status").is(":checked"); |
| 598 | if (isEnabled) { |
| 599 | disableWarmup(); |
| 600 | $("#warmup-status").attr("checked", false); |
| 601 | } else { |
| 602 | estimateWarmup(); |
| 603 | } |
| 604 | }); |
| 605 | |
| 606 | var loadWarmupStatus = function() { |
| 607 | $.ajax({ |
| 608 | url: ajaxurl, |
| 609 | type: "POST", |
| 610 | data: { |
| 611 | action: "nitropack_warmup_stats" |
| 612 | }, |
| 613 | dataType: "json", |
| 614 | success: function(resp) { |
| 615 | if (resp.type == "success") { |
| 616 | $("#warmup-status").attr("checked", !!resp.stats.status); |
| 617 | $("#loading-warmup-status").hide(); |
| 618 | $("#warmup-toggle").show(); |
| 619 | } else { |
| 620 | setTimeout(loadWarmupStatus, 500); |
| 621 | } |
| 622 | } |
| 623 | }); |
| 624 | } |
| 625 | loadWarmupStatus(); |
| 626 | |
| 627 | $("#safemode-status-slider").on("click", function(e) { |
| 628 | e.preventDefault(); |
| 629 | var isEnabled = $("#safemode-status").is(":checked"); |
| 630 | if (isEnabled) { |
| 631 | disableSafemode(); |
| 632 | $("#safemode-status").attr("checked", false); |
| 633 | } else { |
| 634 | enableSafemode(); |
| 635 | $("#safemode-status").attr("checked", true); |
| 636 | } |
| 637 | }); |
| 638 | |
| 639 | var loadSafemodeStatus = function() { |
| 640 | $.ajax({ |
| 641 | url: ajaxurl, |
| 642 | type: "POST", |
| 643 | data: { |
| 644 | action: "nitropack_safemode_status" |
| 645 | }, |
| 646 | dataType: "json", |
| 647 | success: function(resp) { |
| 648 | if (resp.type == "success") { |
| 649 | $("#safemode-status").attr("checked", !!resp.isEnabled); |
| 650 | $("#loading-safemode-status").hide(); |
| 651 | $("#safemode-toggle").show(); |
| 652 | } else { |
| 653 | setTimeout(loadSafemodeStatus, 500); |
| 654 | } |
| 655 | } |
| 656 | }); |
| 657 | } |
| 658 | loadSafemodeStatus(); |
| 659 | })(jQuery); |
| 660 | |
| 661 | (_ => { |
| 662 | const classIndex = { |
| 663 | 1: 'range-success', |
| 664 | 2: 'range-warning', |
| 665 | 3: 'range-danger', |
| 666 | 4: 'range-ludicrous', |
| 667 | 5: 'range-manual', |
| 668 | } |
| 669 | |
| 670 | const atTimeout = (_ => { |
| 671 | var timeout; |
| 672 | |
| 673 | return (callback, time) => { |
| 674 | clearTimeout(timeout); |
| 675 | timeout = setTimeout(callback, time) |
| 676 | }; |
| 677 | })(); |
| 678 | |
| 679 | const saveSetting = function(value) { |
| 680 | return new Promise((resolve, reject) => { |
| 681 | var xhr = new XMLHttpRequest(); |
| 682 | |
| 683 | xhr.open("POST", '<?php echo $quickSetupSaveUrl; ?>', true); |
| 684 | |
| 685 | //Send the proper header information along with the request |
| 686 | xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
| 687 | |
| 688 | xhr.onreadystatechange = function() { // Call a function when the state changes. |
| 689 | if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { |
| 690 | resolve(); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | xhr.send("setting=" + value); |
| 695 | }); |
| 696 | } |
| 697 | |
| 698 | document.getElementById('range').oninput = function() { |
| 699 | var children = document.getElementById('description').children; |
| 700 | var shown = parseInt(this.value); |
| 701 | |
| 702 | for (var i = 0; i < children.length; i++) { |
| 703 | children.item(i).classList.toggle('hidden', i != shown); |
| 704 | } |
| 705 | |
| 706 | document.getElementById('range').classList.remove('range-success', 'range-warning', 'range-danger', 'range-ludicrous', 'range-manual'); |
| 707 | |
| 708 | if (classIndex[shown]) { |
| 709 | document.getElementById('range').classList.add(classIndex[shown]); |
| 710 | } |
| 711 | |
| 712 | atTimeout(async function() { |
| 713 | await saveSetting(shown); |
| 714 | }, 500); |
| 715 | }; |
| 716 | |
| 717 | var min = parseInt(document.getElementById('range').min); |
| 718 | var max = parseInt(document.getElementById('range').max); |
| 719 | for (var i = min; i <= max; i++) { |
| 720 | let divisor = document.createElement('div'); |
| 721 | divisor.classList.add("divisor"); |
| 722 | document.getElementById('divisors').appendChild(divisor); |
| 723 | |
| 724 | let label = document.createElement('div'); |
| 725 | label.textContent = document.getElementById('description').children.item(i).getElementsByTagName('h6').item(0).textContent; |
| 726 | label.classList.add("label"); |
| 727 | document.getElementById('labels').appendChild(label); |
| 728 | } |
| 729 | })(); |
| 730 | </script> |
| 731 |