images
2 years ago
javascript
2 years ago
modals
2 years ago
stylesheet
2 years ago
templates
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
diagnostics.php
2 years ago
oneclick.php
2 years ago
safemode.php
2 years ago
dashboard.php
548 lines
| 1 | <?php |
| 2 | $processing = 0; |
| 3 | $usage = '0 MB'; |
| 4 | $max_usage = '1 GB'; |
| 5 | $page_views = '0'; |
| 6 | $max_page_views = '10000'; |
| 7 | ?> |
| 8 | <?php nitropack_display_admin_notices(); ?> |
| 9 | <div class="grid grid-cols-2 gap-6 grid-col-1-tablet items-start"> |
| 10 | <div class="col-span-1"> |
| 11 | <!-- Optimized Pages Card --> |
| 12 | <div class="card card-optimized-pages"> |
| 13 | <div class="card-header"> |
| 14 | <h3><?php esc_html_e('Optimized pages', 'nitropack'); ?></h3> |
| 15 | <div class="flex flex-row items-center" style="display: none;" id="pending-optimizations-section"> |
| 16 | <img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="w-4 h-4"> |
| 17 | <span class="ml-2 mr-1 text-primary"> <?php esc_html_e('Processing', 'nitropack'); ?> |
| 18 | <span id="pending-optimizations-count">X</span> <?php esc_html_e('page(s) in the background', 'nitropack'); ?></span> |
| 19 | </div> |
| 20 | </div> |
| 21 | <div class="card-body"> |
| 22 | <div class="flex flex-row items-center"> |
| 23 | <div class="optimized-pages"><span data-optimized-pages-total>0</span></div> |
| 24 | <div class="text-box mr-2"> |
| 25 | <p class="text-md"><?php esc_html_e('Last cache purge', 'nitropack'); ?>: <span data-last-cache-purge><?php esc_html_e('Never', 'nitropack'); ?></span> </br> |
| 26 | <?php esc_html_e('Reason', 'nitropack'); ?>: <span data-purge-reason><?php esc_html_e('Unknown', 'nitropack'); ?></span></p> |
| 27 | </div> |
| 28 | <button id="optimizations-purge-cache" type="button" class="ml-auto btn btn-secondary flex-shrink-0" data-modal-target="modal-purge-cache" data-modal-toggle="modal-purge-cache"><?php esc_html_e('Purge cache', 'nitropack'); ?></button> |
| 29 | </div> |
| 30 | </div> |
| 31 | <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-purge-cache.php'; ?> |
| 32 | </div> |
| 33 | <!-- Optimized Pages Card End --> |
| 34 | <!-- Optimization Mode Card --> |
| 35 | <div class="card card-optimization-mode"> |
| 36 | <div class="card-header no-border mb-0"> |
| 37 | <div class="flex items-center"> |
| 38 | <h3 class="mb-0"><?php esc_html_e('Optimization mode', 'nitropack'); ?></h3> |
| 39 | <span class="tooltip-icon" data-tooltip-target="tooltip-optimization"> |
| 40 | <img src="<?php echo plugin_dir_url(__FILE__) . 'images/info.svg'; ?>"> |
| 41 | </span> |
| 42 | <div id="tooltip-optimization" role="tooltip" class="tooltip-container hidden"> |
| 43 | <?php esc_html_e('Select from our range of predefined optimization modes to boost your site\'s performance.', 'nitropack'); |
| 44 | ?> |
| 45 | <div class="tooltip-arrow" data-popper-arrow></div> |
| 46 | </div> |
| 47 | </div> |
| 48 | </div> |
| 49 | <?php $modes = array('standard' => esc_html__('Standard', 'nitropack'), 'medium' => esc_html__('Medium', 'nitropack'), 'strong' => esc_html__('Strong', 'nitropack'), 'ludicrous' => esc_html__('Ludicrous', 'nitropack'), 'custom' => esc_html__('Custom', 'nitropack')); ?> |
| 50 | <div class="tabs-wrapper"> |
| 51 | <div class="tabs" id="optimization-modes"> |
| 52 | <?php foreach ($modes as $mode_id => $mode) : ?> |
| 53 | <a class="btn tab-link btn-link" data-mode="<?php echo $mode_id; ?>" data-modal-target="modal-optimization-mode" data-modal-toggle="modal-optimization-mode"><?php echo $mode; ?></a> |
| 54 | <?php endforeach; ?> |
| 55 | </div> |
| 56 | <p><?php esc_html_e('Active Mode', 'nitropack'); ?>: <span class="active-mode"></span></p> |
| 57 | <div class="tab-content-wrapper"> |
| 58 | <div class="hidden tab-content" role="tabpanel" data-tab="standard-tab"> |
| 59 | <p class="text-secondary mt-2"> <?php esc_html_e('Standard optimization features enabled for your site. Ideal choice for maximum stability.', 'nitropack'); ?></p> |
| 60 | </div> |
| 61 | <div class="hidden tab-content" role="tabpanel" data-tab="medium-tab"> |
| 62 | <p class="text-secondary mt-2"> <?php esc_html_e('Adds image lazy loading to standard optimizations. Uses built-in browser techniques for loading resources.', 'nitropack'); ?></p> |
| 63 | </div> |
| 64 | <div class="hidden tab-content" role="tabpanel" data-tab="strong-tab"> |
| 65 | <p class="text-secondary mt-2"> <?php esc_html_e('Includes smart resource loading on top of Medium optimizations. Balances speed boost with stability.', 'nitropack'); ?></p> |
| 66 | </div> |
| 67 | <div class="hidden tab-content" role="tabpanel" data-tab="ludicrous-tab"> |
| 68 | <p class="text-secondary mt-2"> <?php esc_html_e('Applies deferred JS and advanced resource loading for optimal performance and Core Web Vitals.', 'nitropack'); ?></p> |
| 69 | </div> |
| 70 | <div class="hidden tab-content" role="tabpanel" data-tab="custom-tab"> |
| 71 | <p class="text-secondary mt-2"> <?php esc_html_e('Activated when manual setups are made. Ideal for advanced NitroPack optimizations.', 'nitropack'); ?></p> |
| 72 | </div> |
| 73 | </div> |
| 74 | </div> |
| 75 | <div class="card-footer"> |
| 76 | <div class="flex flex-row"> |
| 77 | <p class=""><?php esc_html_e('Which optimization mode to choose?', 'nitropack'); ?></p> |
| 78 | <a href="#" class="text-primary ml-auto" data-modal-target="modes-modal" data-modal-toggle="modes-modal"><?php esc_html_e('See modes comparison', 'nitropack'); ?></a> |
| 79 | <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-modes.php'; ?> |
| 80 | </div> |
| 81 | </div> |
| 82 | <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-optimization-mode.php'; ?> |
| 83 | </div> |
| 84 | <!-- Optimization Mode Card End --> |
| 85 | <!-- Automated Behavior Card --> |
| 86 | <div class="card card-automated-behavior"> |
| 87 | <div class="card-header"> |
| 88 | <h3><?php esc_html_e('Automated Behavior', 'nitropack'); ?></h3> |
| 89 | </div> |
| 90 | <div class="card-body"> |
| 91 | <div class="options-container"> |
| 92 | <div class="nitro-option"> |
| 93 | <div class="nitro-option-main"> |
| 94 | <div class="text-box"> |
| 95 | <h6><?php esc_html_e('Purge cache', 'nitropack'); ?></h6> |
| 96 | <p><?php esc_html_e('Purge affected cache when content is updated or published', 'nitropack'); ?></p> |
| 97 | </div> |
| 98 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 99 | <input type="checkbox" value="" class="sr-only peer" name="purge_cache" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>> |
| 100 | <div class="toggle"></div> |
| 101 | </label> |
| 102 | </div> |
| 103 | </div> |
| 104 | <div class="nitro-option"> |
| 105 | <div class="nitro-option-main"> |
| 106 | <div class="text-box"> |
| 107 | <h6><?php esc_html_e('Page optimization', 'nitropack'); ?></h6> |
| 108 | <p><?php esc_html_e('Select what post/page types get optimized', 'nitropack'); ?></p> |
| 109 | </div> |
| 110 | <a data-modal-target="modal-posttypes" data-modal-toggle="modal-posttypes" class="btn btn-secondary btn-icon" href="#"> |
| 111 | <img src="<?php echo plugin_dir_url(__FILE__); ?>images/setting-icon.svg"> |
| 112 | </a> |
| 113 | </div> |
| 114 | <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-posttypes.php'; ?> |
| 115 | </div> |
| 116 | </div> |
| 117 | </div> |
| 118 | </div> |
| 119 | <!-- Automated Behavior Card End --> |
| 120 | <!-- Go to app Card --> |
| 121 | <div class="card app-card"> |
| 122 | <div class="card-body"> |
| 123 | <div class="flex items-center justify-between"> |
| 124 | <p><?php esc_html_e('You can further configure how NitroPack\'s optimization behaves through your account', 'nitropack'); ?>.</p> |
| 125 | <a href="https://app.nitropack.io/dashboard" target="_blank" class="btn btn-primary ml-2 flex-shrink-0"><?php esc_html_e('Go to app', 'nitropack'); ?></a> |
| 126 | </div> |
| 127 | </div> |
| 128 | </div> |
| 129 | <!-- Go to app card End --> |
| 130 | </div> |
| 131 | <div class="col-span-1"> |
| 132 | <!-- Subscription Card --> |
| 133 | <div class="card card-subscription"> |
| 134 | <div class="card-header"> |
| 135 | <h3><?php esc_html_e('Subscription', 'nitropack'); ?></h3> |
| 136 | </div> |
| 137 | <div class="card-body"> |
| 138 | <div class="flex flex-row items-center"> |
| 139 | <div class="plan-name"><?php esc_html_e('Free', 'nitropack'); ?></div> |
| 140 | <a type="button" target="_blank" href="https://app.nitropack.io/account/billing" class="btn btn-secondary ml-auto"><?php esc_html_e('Manage subscription', 'nitropack'); ?></a> |
| 141 | </div> |
| 142 | <div class="table-wrapper"> |
| 143 | <table class="w-full"> |
| 144 | <tbody> |
| 145 | <tr> |
| 146 | <td class="key"><?php esc_html_e('Next reset', 'nitropack'); ?></td> |
| 147 | <td class="value" data-next-reset><?php esc_html_e('No ETA', 'nitropack'); ?></td> |
| 148 | </tr> |
| 149 | <tr> |
| 150 | <td class="key"><?php esc_html_e('Next billing', 'nitropack'); ?></td> |
| 151 | <td class="value" data-next-billing><?php esc_html_e('No ETA', 'nitropack'); ?></td> |
| 152 | </tr> |
| 153 | <tr> |
| 154 | <td class="key"><?php esc_html_e('Page views', 'nitropack'); ?></td> |
| 155 | <td class="value" data-page-views><?php printf( esc_html__('%1$s out of %2$s', 'nitropack'), $page_views, $max_page_views); ?></td> |
| 156 | </tr> |
| 157 | <tr> |
| 158 | <td class="key"><?php esc_html_e('CDN bandwidth', 'nitropack'); ?></td> |
| 159 | <td class="value" data-cdn-bandwidth><?php printf( esc_html__('%1$s out of %2$s', 'nitropack'), $usage, $max_usage); ?></td> |
| 160 | </tr> |
| 161 | </tbody> |
| 162 | </table> |
| 163 | </div> |
| 164 | </div> |
| 165 | <div class="card-footer"> |
| 166 | <p class="text-secondary text-smaller"><?php esc_html_e('You will be notified by email when your website reaches the subscription resource limits.', 'nitropack'); ?></p> |
| 167 | </div> |
| 168 | </div> |
| 169 | <!-- Subscription Card End --> |
| 170 | <!-- Basic Settings Card --> |
| 171 | <div class="card card-basic-settings"> |
| 172 | <div class="card-header"> |
| 173 | <h3><?php esc_html_e('Basic Settings', 'nitropack'); ?></h3> |
| 174 | </div> |
| 175 | <div class="card-body"> |
| 176 | <div class="options-container"> |
| 177 | <div class="nitro-option" id="settings-widget"> |
| 178 | <div class="nitro-option-main"> |
| 179 | <div class="text-box" id="warmup-status-slider"> |
| 180 | |
| 181 | <?php $sitemap = get_option('np_warmup_sitemap', false); |
| 182 | $toolTipDisplayState = $sitemap ? '' : 'hidden'; ?> |
| 183 | |
| 184 | <h6><?php esc_html_e('Cache warmup', 'nitropack'); ?> <span class="badge badge-primary ml-2"><?php esc_html_e('Recommeneded', 'nitropack'); ?></span> <span class="tooltip-icon <?php echo $toolTipDisplayState; ?>" data-tooltip-target="tooltip-sitemap"> |
| 185 | <img src="<?php echo plugin_dir_url(__FILE__) . 'images/info.svg'; ?>"> |
| 186 | </span></h6> |
| 187 | <div id="tooltip-sitemap" role="tooltip" class="tooltip-container hidden"> |
| 188 | <?php echo $sitemap; ?> |
| 189 | <div class="tooltip-arrow" data-popper-arrow></div> |
| 190 | </div> |
| 191 | <p><?php esc_html_e('Automatically pre-caches your website\'s page content', 'nitropack'); ?>. <a href="https://support.nitropack.io/en/articles/8390320-cache-warmup" class="text-blue" target="_blank"><?php esc_html_e('Learn more', 'nitropack'); ?></a></p> |
| 192 | </div> |
| 193 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 194 | <input id="warmup-status" type="checkbox" class="sr-only peer"> |
| 195 | <div class="toggle"></div> |
| 196 | </label> |
| 197 | </div> |
| 198 | <div class="msg-container" id="loading-warmup-status"> |
| 199 | <img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="icon"> <span class="msg"><?php esc_html_e('Loading cache warmup status', 'nitropack'); ?></span> |
| 200 | </div> |
| 201 | </div> |
| 202 | <div class="nitro-option" id="test-mode-widget"> |
| 203 | <div class="nitro-option-main"> |
| 204 | <div class="text-box" id="safemode-status-slider"> |
| 205 | <h6><?php esc_html_e('Test Mode', 'nitropack'); ?></h6> |
| 206 | <p><?php esc_html_e('Test NitroPack\'s features without affecting your visitors\' experience', 'nitropack'); ?>. <a href="https://support.nitropack.io/en/articles/8390292-test-mode" class="text-blue" target="_blank"><?php esc_html_e('Learn more', 'nitropack'); ?></a></p> |
| 207 | </div> |
| 208 | |
| 209 | <label class="inline-flex items-center cursor-pointer ml-auto" > |
| 210 | <input type="checkbox" class="sr-only peer" id="safemode-status"> |
| 211 | |
| 212 | <div class="toggle"></div> |
| 213 | </label> |
| 214 | </div> |
| 215 | <div class="msg-container" id="loading-safemode-status"> |
| 216 | <img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="icon"> <?php esc_html_e('Loading test mode status', 'nitropack'); ?> |
| 217 | </div> |
| 218 | <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-test-mode.php'; ?> |
| 219 | </div> |
| 220 | <div class="nitro-option" id="compression-widget"> |
| 221 | <div class="nitro-option-main"> |
| 222 | <div class="text-box"> |
| 223 | <h6><span id="detected-compression"><?php esc_html_e('HTML Compression', 'nitropack'); ?> </span></h6> |
| 224 | <p><?php esc_html_e('Compressing the structure of your HTML, ensures faster page rendering and an optimized browsing experience for your users.', 'nitropack'); ?> <a href="https://support.nitropack.io/en/articles/8390333-nitropack-plugin-settings-in-wordpress#h_29b7ab4836" class="text-blue" target="_blank"><?php esc_html_e('Learn more', 'nitropack'); ?></a></p> |
| 225 | </div> |
| 226 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 227 | <input type="checkbox" id="compression-status" class="sr-only peer" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>> |
| 228 | <div class="toggle"></div> |
| 229 | </label> |
| 230 | </div> |
| 231 | <div class="mt-4 text-primary"> |
| 232 | <a href="javascript:void(0);" id="compression-test-btn" class="text-primary"><?php esc_html_e('Run compression test', 'nitropack'); ?></a> |
| 233 | <div class="flex items-start msg-container hidden"> |
| 234 | <span class="msg"></span> |
| 235 | </div> |
| 236 | </div> |
| 237 | </div> |
| 238 | <?php if (\NitroPack\Integration\Plugin\BeaverBuilder::isActive()) { ?> |
| 239 | <div class="nitro-option" id="beaver-builder-widget"> |
| 240 | <div class="nitro-option-main"> |
| 241 | <div class="text-box"> |
| 242 | <h6><span id="detected-compression"><?php esc_html_e('Sync NitroPack Purge with Beaver Builder', 'nitropack'); ?> </span></h6> |
| 243 | <p><?php esc_html_e('When Beaver Builder cache is purged, NitroPack will perform a full cache purge keeping your site\'s content up-to-date.', 'nitropack'); ?></p> |
| 244 | </div> |
| 245 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 246 | <input type="checkbox" class="sr-only peer" id="bb-purge-status" <?php if ($bbCacheSyncPurge) echo "checked"; ?>> |
| 247 | <div class="toggle"></div> |
| 248 | </label> |
| 249 | </div> |
| 250 | </div> |
| 251 | <?php } ?> |
| 252 | |
| 253 | <?php if (nitropack_render_woocommerce_cart_cache_option()) { ?> |
| 254 | <div class="nitro-option" id="cart-cache-widget"> |
| 255 | <div class="nitro-option-main"> |
| 256 | <div class="text-box"> |
| 257 | <h6><?php esc_html_e('Cart cache', 'nitropack'); ?> <span class="badge badge-success ml-2">New</span></h6> |
| 258 | <p><?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'); ?></p> |
| 259 | |
| 260 | </div> |
| 261 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 262 | <input type="checkbox" id="cart-cache-status" class="sr-only peer" <?php if (nitropack_is_cart_cache_active()) echo "checked"; ?> <?php if (!nitropack_is_cart_cache_available()) echo "disabled"; ?>> |
| 263 | <div class="toggle"></div> |
| 264 | </label> |
| 265 | </div> |
| 266 | <?php if (!nitropack_is_cart_cache_available()) : ?> |
| 267 | <div class="msg-container bg-success paid-msg"> |
| 268 | <p><svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" class="text-success"> |
| 269 | <g clip-path="url(#clip0_1244_36215)"> |
| 270 | <path d="M10.0001 18.3333C14.6025 18.3333 18.3334 14.6023 18.3334 9.99996C18.3334 5.39759 14.6025 1.66663 10.0001 1.66663C5.39771 1.66663 1.66675 5.39759 1.66675 9.99996C1.66675 14.6023 5.39771 18.3333 10.0001 18.3333Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> |
| 271 | <path d="M13.3334 9.99996L10.0001 6.66663L6.66675 9.99996" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> |
| 272 | <path d="M10 13.3333V6.66663" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> |
| 273 | </g> |
| 274 | <defs> |
| 275 | <clipPath id="clip0_1244_36215"> |
| 276 | <rect width="20" height="20" fill="white"></rect> |
| 277 | </clipPath> |
| 278 | </defs> |
| 279 | </svg> <?php esc_html_e('This feature is available on paid subscription.', 'nitropack'); ?> <a href="https://app.nitropack.io/subscription/buy" class="text-primary" target="_blank"><b><?php esc_html_e('Upgrade here', 'nitropack'); ?></b></a> |
| 280 | </p> |
| 281 | </div> |
| 282 | <?php endif; ?> |
| 283 | </div> |
| 284 | <div class="nitro-option"> |
| 285 | <div class="nitro-option-main"> |
| 286 | <div class="text-box"> |
| 287 | <h6><?php esc_html_e('Real-time Stock Refresh', 'nitropack'); ?></h6> |
| 288 | <p><?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'); ?></p> |
| 289 | |
| 290 | </div> |
| 291 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 292 | <input type="checkbox" id="woo-stock-reduce-status" class="sr-only peer" <?php echo (int)$stockReduceStatus === 1 ? "checked" : ""; ?>> |
| 293 | <div class="toggle"></div> |
| 294 | </label> |
| 295 | </div> |
| 296 | </div> |
| 297 | <?php } ?> |
| 298 | </div> |
| 299 | </div> |
| 300 | <div class="card-footer disconnect-container"> |
| 301 | <a href="#" class="text-primary" id="disconnect-btn"><?php esc_html_e('Disconnect NitroPack plugin', 'nitropack'); ?></a> |
| 302 | <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-disconnect.php'; ?> |
| 303 | </div> |
| 304 | </div> |
| 305 | <!-- Basic Settings Card End --> |
| 306 | </div> |
| 307 | </div> |
| 308 | |
| 309 | <script> |
| 310 | ($ => { |
| 311 | var getOptimizationsTimeout = null; |
| 312 | let isClearing = false; |
| 313 | var paid_plan = false; |
| 314 | $(window).on("load", function() { |
| 315 | getOptimizations(); |
| 316 | getPlan(); |
| 317 | <?php if ($checkedCompression != 1) { ?> |
| 318 | autoDetectCompression(); |
| 319 | <?php } ?> |
| 320 | }); |
| 321 | |
| 322 | /* Cache Purge begin */ |
| 323 | window.performCachePurge = () => { |
| 324 | purgeCache(); |
| 325 | } |
| 326 | |
| 327 | let purgeCache = () => { |
| 328 | let purgeEvent = new Event("cache.purge.request"); |
| 329 | window.dispatchEvent(purgeEvent); |
| 330 | } |
| 331 | |
| 332 | var getOptimizations = _ => { |
| 333 | var url = '<?php echo $optimizationDetailsUrl; ?>'; |
| 334 | ((s, e, f) => { |
| 335 | if (window.fetch) { |
| 336 | fetch(url) |
| 337 | .then(resp => resp.json()) |
| 338 | .then(s) |
| 339 | .catch(e) |
| 340 | .finally(f); |
| 341 | } else { |
| 342 | $.ajax({ |
| 343 | url: url, |
| 344 | type: 'GET', |
| 345 | dataType: 'json', |
| 346 | success: s, |
| 347 | error: e, |
| 348 | complete: f |
| 349 | }) |
| 350 | } |
| 351 | })(data => { |
| 352 | $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo); |
| 353 | if (data.last_cache_purge.reason) { |
| 354 | $('[data-purge-reason]').text(data.last_cache_purge.reason); |
| 355 | $('#last-cache-purge-reason').show(); |
| 356 | } else { |
| 357 | $('#last-cache-purge-reason').hide(); |
| 358 | } |
| 359 | if (data.pending_count) { |
| 360 | $("#pending-optimizations-count").text(data.pending_count); |
| 361 | $("#pending-optimizations-section").show(); |
| 362 | } else { |
| 363 | $("#pending-optimizations-section").hide(); |
| 364 | } |
| 365 | |
| 366 | $('[data-optimized-pages-total]').text(data.optimized_pages.total); |
| 367 | |
| 368 | }, __ => { |
| 369 | console.error("An error occurred while fetching data for optimized pages"); |
| 370 | }, __ => { |
| 371 | if (!getOptimizationsTimeout) { |
| 372 | getOptimizationsTimeout = setTimeout(function() { |
| 373 | getOptimizationsTimeout = null; |
| 374 | getOptimizations(); |
| 375 | }, 60000); |
| 376 | } |
| 377 | }); |
| 378 | } |
| 379 | |
| 380 | var getPlan = _ => { |
| 381 | |
| 382 | var url = '<?php echo $planDetailsUrl; ?>'; |
| 383 | ((s, e, f) => { |
| 384 | if (window.fetch) { |
| 385 | fetch(url) |
| 386 | .then(resp => resp.json()) |
| 387 | .then(s) |
| 388 | .catch(e) |
| 389 | .finally(f); |
| 390 | } else { |
| 391 | $.ajax({ |
| 392 | url: url, |
| 393 | type: 'GET', |
| 394 | dataType: 'json', |
| 395 | success: s, |
| 396 | error: e, |
| 397 | complete: f |
| 398 | }) |
| 399 | } |
| 400 | })(data => { |
| 401 | |
| 402 | $('.plan-name').text(data.plan_title); |
| 403 | $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A'); |
| 404 | $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A'); |
| 405 | $('[data-page-views]').text(data.page_views ? data.page_views : 'N/A'); |
| 406 | $('[data-cdn-bandwidth]').text(data.cdn_bandwidth ? data.cdn_bandwidth + ' out of ' + data.max_cdn_bandwidth : 'N/A'); |
| 407 | |
| 408 | for (prop in data) { |
| 409 | if (prop.indexOf("show_") === 0) continue; |
| 410 | if (prop.indexOf("label_") === 0) continue; |
| 411 | if (prop.indexOf("max_") === 0) continue; |
| 412 | if ( |
| 413 | typeof data["show_" + prop] != "undefined" && |
| 414 | data["show_" + prop] && |
| 415 | typeof data["label_" + prop] != "undefined" && |
| 416 | typeof data["max_" + prop] != "undefined" |
| 417 | ) { |
| 418 | let propertyLabel = data["label_" + prop]; |
| 419 | let propertyValue = data[prop]; |
| 420 | let propertyLimit = data["max_" + prop]; |
| 421 | $("#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>'); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | }, __ => { |
| 426 | NitropackUI.triggerToast('error', '<?php esc_html_e('Error while fetching plan data', 'nitropack'); ?>'); |
| 427 | }, __ => {}); |
| 428 | } |
| 429 | |
| 430 | $(document).on('click', "#compression-test-btn", e => { |
| 431 | e.preventDefault(); |
| 432 | autoDetectCompression(); |
| 433 | }); |
| 434 | /* Compression end */ |
| 435 | |
| 436 | /* HTML Compression begin */ |
| 437 | var autoDetectCompression = function() { |
| 438 | let msg_container = $('#compression-widget .msg-container'), |
| 439 | msg_icon = msg_container.find('.icon'), |
| 440 | msg_box = msg_container.find('.msg'), |
| 441 | compression_setting = $('#compression-status'), |
| 442 | compression_btn = $('#compression-test-btn'); |
| 443 | //add spinner here |
| 444 | msg_box.html('<img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="icon"> <?php esc_html_e('Testing current compression status', 'nitropack'); ?>'); |
| 445 | compression_btn.addClass('hidden'); |
| 446 | msg_container.removeClass('hidden'); |
| 447 | $.post(ajaxurl, { |
| 448 | action: 'nitropack_test_compression_ajax', |
| 449 | nonce: nitroNonce |
| 450 | }, function(response) { |
| 451 | var resp = JSON.parse(response); |
| 452 | |
| 453 | if (resp.status == "success") { |
| 454 | if (resp.hasCompression) { // compression already enabled |
| 455 | compression_setting.attr("checked", false); |
| 456 | |
| 457 | msg_box.text('<?php esc_html_e('Compression is already enabled on your server! There is no need to enable it in NitroPack.', 'nitropack'); ?>') |
| 458 | } else { |
| 459 | compression_setting.attr("checked", true); |
| 460 | msg_box.text('<?php esc_html_e('No compression was detected! We will now enable it in NitroPack.', 'nitropack'); ?>'); |
| 461 | } |
| 462 | NitropackUI.triggerToast(resp.type, resp.message); |
| 463 | } else { |
| 464 | msg_box.text('<?php esc_html_e('Could not determine compression status automatically. Please configure it manually.', 'nitropack'); ?>'); |
| 465 | } |
| 466 | setTimeout(function() { |
| 467 | msg_container.addClass('hidden'); |
| 468 | compression_btn.removeClass('hidden'); |
| 469 | }, 5000); |
| 470 | }); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | $("#compression-status").on("click", function(e) { |
| 475 | $.post(ajaxurl, { |
| 476 | action: 'nitropack_set_compression_ajax', |
| 477 | nonce: nitroNonce, |
| 478 | data: { |
| 479 | compressionStatus: $(this).is(":checked") ? 1 : 0 |
| 480 | } |
| 481 | }, function(response) { |
| 482 | var resp = JSON.parse(response); |
| 483 | NitropackUI.triggerToast(resp.type, resp.message); |
| 484 | }); |
| 485 | }); |
| 486 | |
| 487 | $("#auto-purge-status").on("click", function(e) { |
| 488 | $.post(ajaxurl, { |
| 489 | action: 'nitropack_set_auto_cache_purge_ajax', |
| 490 | nonce: nitroNonce, |
| 491 | autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0 |
| 492 | }, function(response) { |
| 493 | var resp = JSON.parse(response); |
| 494 | NitropackUI.triggerToast(resp.type, resp.message); |
| 495 | }); |
| 496 | }); |
| 497 | |
| 498 | $("#cart-cache-status").on("click", function(e) { |
| 499 | $.post(ajaxurl, { |
| 500 | action: 'nitropack_set_cart_cache_ajax', |
| 501 | nonce: nitroNonce, |
| 502 | cartCacheStatus: $(this).is(":checked") ? 1 : 0 |
| 503 | }, function(response) { |
| 504 | var resp = JSON.parse(response); |
| 505 | NitropackUI.triggerToast(resp.type, resp.message); |
| 506 | }); |
| 507 | }); |
| 508 | |
| 509 | |
| 510 | $("#woo-stock-reduce-status").on("click", function(e) { |
| 511 | $.post(ajaxurl, { |
| 512 | action: 'nitropack_set_stock_reduce_status', |
| 513 | nonce: nitroNonce, |
| 514 | data: { |
| 515 | stockReduceStatus: $(this).is(":checked") ? 1 : 0 |
| 516 | } |
| 517 | }, function(response) { |
| 518 | var resp = JSON.parse(response); |
| 519 | NitropackUI.triggerToast(resp.type, resp.message); |
| 520 | }); |
| 521 | }); |
| 522 | |
| 523 | $("#legacy-purge-status").on("click", function(e) { |
| 524 | $.post(ajaxurl, { |
| 525 | action: 'nitropack_set_legacy_purge_ajax', |
| 526 | nonce: nitroNonce, |
| 527 | legacyPurgeStatus: $(this).is(":checked") ? 1 : 0 |
| 528 | }, function(response) { |
| 529 | var resp = JSON.parse(response); |
| 530 | NitropackUI.triggerToast(resp.type, resp.message); |
| 531 | |
| 532 | }); |
| 533 | }); |
| 534 | |
| 535 | $("#bb-purge-status").on("click", function(e) { |
| 536 | $.post(ajaxurl, { |
| 537 | action: 'nitropack_set_bb_cache_purge_sync_ajax', |
| 538 | nonce: nitroNonce, |
| 539 | bbCachePurgeSyncStatus: $(this).is(":checked") ? 1 : 0 |
| 540 | }, function(response) { |
| 541 | var resp = JSON.parse(response); |
| 542 | NitropackUI.triggerToast(resp.type, resp.message); |
| 543 | }); |
| 544 | }); |
| 545 | |
| 546 | |
| 547 | })(jQuery); |
| 548 | </script> |