From b690ba152aea076ba0906308a8c53ba45f81ae47 Mon Sep 17 00:00:00 2001 From: tynanbe Date: Sat, 11 Nov 2023 12:08:28 -0600 Subject: [PATCH] npm run format --- assets/css/litespeed-legacy.css | 14 +- assets/css/litespeed.css | 709 +++++---- assets/js/component.cdn.js | 155 +- assets/js/component.crawler.js | 83 +- assets/js/guest.docref.js | 14 +- assets/js/guest.js | 26 +- assets/js/js_delay.js | 60 +- assets/js/lazyload.init.js | 29 +- assets/js/lazyload.lib.js | 1620 ++++++++++---------- assets/js/litespeed-cache-admin.js | 598 ++++---- autoload.php | 31 +- cli/crawler.cls.php | 6 +- cli/debug.cls.php | 7 +- cli/image.cls.php | 50 +- cli/online.cls.php | 67 +- cli/option.cls.php | 233 ++- cli/presets.cls.php | 42 +- cli/purge.cls.php | 102 +- inc/object.lib.php | 2 +- litespeed-cache.php | 18 +- src/activation.cls.php | 372 ++--- src/admin-display.cls.php | 59 +- src/admin-settings.cls.php | 94 +- src/admin.cls.php | 122 +- src/api.cls.php | 210 +-- src/avatar.cls.php | 173 ++- src/base.cls.php | 928 ++++++----- src/cdn-setup.cls.php | 62 +- src/cdn.cls.php | 357 +++-- src/cdn/cloudflare.cls.php | 221 +-- src/cdn/quic.cls.php | 11 +- src/cloud.cls.php | 192 +-- src/conf.cls.php | 27 +- src/control.cls.php | 501 +++--- src/core.cls.php | 40 +- src/crawler-map.cls.php | 47 +- src/crawler.cls.php | 120 +- src/css.cls.php | 60 +- src/data.cls.php | 462 +++--- src/data.upgrade.func.php | 832 +++++----- src/db-optm.cls.php | 219 +-- src/debug2.cls.php | 12 +- src/doc.cls.php | 45 +- src/error.cls.php | 48 +- src/esi.cls.php | 40 +- src/file.cls.php | 273 ++-- src/gui.cls.php | 916 +++++------ src/health.cls.php | 82 +- src/htaccess.cls.php | 41 +- src/img-optm.cls.php | 212 +-- src/import.cls.php | 5 +- src/instance.cls.php | 7 +- src/lang.cls.php | 388 ++--- src/localization.cls.php | 126 +- src/media.cls.php | 108 +- src/metabox.cls.php | 121 +- src/object-cache.cls.php | 441 +++--- src/object.lib.php | 528 ++++--- src/optimize.cls.php | 45 +- src/optimizer.cls.php | 256 ++-- src/placeholder.cls.php | 32 +- src/preset.cls.php | 165 +- src/purge.cls.php | 20 +- src/report.cls.php | 122 +- src/rest.cls.php | 32 +- src/root.cls.php | 14 +- src/router.cls.php | 370 ++--- src/str.cls.php | 48 +- src/tag.cls.php | 2 +- src/task.cls.php | 34 +- src/tool.cls.php | 104 +- src/ucss.cls.php | 60 +- src/utility.cls.php | 608 ++++---- src/vary.cls.php | 21 +- src/vpi.cls.php | 25 +- thirdparty/aelia-currencyswitcher.cls.php | 37 +- thirdparty/amp.cls.php | 41 +- thirdparty/autoptimize.cls.php | 10 +- thirdparty/avada.cls.php | 12 +- thirdparty/bbpress.cls.php | 44 +- thirdparty/beaver-builder.cls.php | 17 +- thirdparty/caldera-forms.cls.php | 16 +- thirdparty/divi-theme-builder.cls.php | 22 +- thirdparty/elementor.cls.php | 31 +- thirdparty/entry.inc.php | 22 +- thirdparty/facetwp.cls.php | 23 +- thirdparty/gravity-forms.cls.php | 28 +- thirdparty/litespeed-check.cls.php | 73 +- thirdparty/nextgengallery.cls.php | 136 +- thirdparty/perfmatters.cls.php | 25 +- thirdparty/theme-my-login.cls.php | 15 +- thirdparty/user-switching.cls.php | 10 +- thirdparty/wc-pdf-product-vouchers.cls.php | 22 +- thirdparty/wcml.cls.php | 34 +- thirdparty/woo-paypal.cls.php | 12 +- thirdparty/woocommerce.cls.php | 80 +- thirdparty/wp-polls.cls.php | 9 +- thirdparty/wp-postratings.cls.php | 12 +- thirdparty/wpdiscuz.cls.php | 23 +- thirdparty/wplister.cls.php | 9 +- thirdparty/wpml.cls.php | 20 +- thirdparty/wptouch.cls.php | 12 +- thirdparty/yith-wishlist.cls.php | 104 +- tpl/cache/network_settings-browser.tpl.php | 2 +- tpl/cache/network_settings-object.tpl.php | 2 +- tpl/cache/settings-browser.tpl.php | 2 +- tpl/cache/settings-object.tpl.php | 2 +- tpl/inc/admin_footer.php | 29 +- tpl/inc/disabled_all.php | 9 +- tpl/inc/in_upgrading.php | 7 +- tpl/inc/metabox.php | 24 +- tpl/inc/show_display_installed.php | 47 +- tpl/inc/show_error_cookie.php | 14 +- tpl/inc/show_rule_conflict.php | 20 +- 114 files changed, 7853 insertions(+), 7530 deletions(-) diff --git a/assets/css/litespeed-legacy.css b/assets/css/litespeed-legacy.css index af1e5d2a1..2e71731ae 100644 --- a/assets/css/litespeed-legacy.css +++ b/assets/css/litespeed-legacy.css @@ -1,20 +1,18 @@ -.litespeed-wrap h2.nav-tab-wrapper, .litespeed-wrap h3.nav-tab-wrapper{ - margin-bottom:0; +.litespeed-wrap h2.nav-tab-wrapper, +.litespeed-wrap h3.nav-tab-wrapper { + margin-bottom: 0; } -.litespeed-wrap h2 .nav-tab{ - font-size:14px; +.litespeed-wrap h2 .nav-tab { + font-size: 14px; } - .litespeed-wrap .striped > tbody > :nth-child(odd), .litespeed-wrap ul.striped > :nth-child(odd), .litespeed-wrap .alternate { background-color: #f9f9f9; } - - .litespeed-wrap .notice, .litespeed-wrap div.updated, .litespeed-wrap div.error { @@ -55,4 +53,4 @@ .litespeed-wrap .notice-info.notice-alt { background-color: #e5f5fa; -} \ No newline at end of file +} diff --git a/assets/css/litespeed.css b/assets/css/litespeed.css index 239530f87..cbdde6786 100644 --- a/assets/css/litespeed.css +++ b/assets/css/litespeed.css @@ -1,7 +1,8 @@ @font-face { font-family: 'litespeedfont'; src: url('fonts/litespeedfont.eot?rs8ttq'); - src: url('fonts/litespeedfont.eot?rs8ttq#iefix') format('embedded-opentype'), + src: + url('fonts/litespeedfont.eot?rs8ttq#iefix') format('embedded-opentype'), url('fonts/litespeedfont.ttf?rs8ttq') format('truetype'), url('fonts/litespeedfont.woff?rs8ttq') format('woff'), url('fonts/litespeedfont.svg?rs8ttq#litespeedfont') format('svg'); @@ -12,7 +13,7 @@ #adminmenu #toplevel_page_lscache-settings .menu-icon-generic div.wp-menu-image:before, #adminmenu #toplevel_page_litespeed .menu-icon-generic div.wp-menu-image:before, .litespeed-top-toolbar .ab-icon::before { - content: "\e900"; + content: '\e900'; font-family: 'litespeedfont' !important; speak: none; font-style: normal; @@ -24,92 +25,90 @@ /* Better Font Rendering =========== */ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; - } *[litespeed-accesskey]:before { - content: '['attr(litespeed-accesskey) '] '; + content: '[' attr(litespeed-accesskey) '] '; } - /* ======================================= UTILITIES - toggle UI ======================================= */ -input[type="checkbox"].litespeed-tiny-toggle { - -webkit-appearance: none; - -moz-appearance: none; - appearance: none; - - -webkit-tap-highlight-color: transparent; - - width: auto; - height: auto; - vertical-align: middle; - position: relative; - border: 0; - outline: 0; - cursor: pointer; - margin: 0 4px; - background: none; - box-shadow: none; -} -input[type="checkbox"].litespeed-tiny-toggle:focus { - box-shadow: none; -} -input[type="checkbox"].litespeed-tiny-toggle:after { - content: ''; - font-size: 8px; - font-weight: 400; - line-height: 18px; - text-indent: -14px; - color: #ffffff; - width: 36px; - height: 18px; - display: inline-block; - background-color: #a7aaad; - border-radius: 72px; - box-shadow: 0 0 12px rgb(0 0 0 / 15%) inset; -} -input[type="checkbox"].litespeed-tiny-toggle:before { - content: ''; - width: 14px; - height: 14px; - display: block; - position: absolute; - top: 2px; - left: 2px; - margin: 0; - border-radius: 50%; - background-color: #ffffff; -} - -input[type="checkbox"].litespeed-tiny-toggle:checked:before { - left: 20px; - margin: 0; - background-color: #ffffff; -} - -input[type="checkbox"].litespeed-tiny-toggle, -input[type="checkbox"].litespeed-tiny-toggle:before, -input[type="checkbox"].litespeed-tiny-toggle:after, -input[type="checkbox"].litespeed-tiny-toggle:checked:before, -input[type="checkbox"].litespeed-tiny-toggle:checked:after { - transition: ease .15s; -} -input[type="checkbox"].litespeed-tiny-toggle:checked:after { - /*content: 'ON';*/ - background-color: #2271b1; -} - -.block-editor__container input[type="checkbox"].litespeed-tiny-toggle { +input[type='checkbox'].litespeed-tiny-toggle { + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + + -webkit-tap-highlight-color: transparent; + + width: auto; + height: auto; + vertical-align: middle; + position: relative; + border: 0; + outline: 0; + cursor: pointer; + margin: 0 4px; + background: none; + box-shadow: none; +} +input[type='checkbox'].litespeed-tiny-toggle:focus { + box-shadow: none; +} +input[type='checkbox'].litespeed-tiny-toggle:after { + content: ''; + font-size: 8px; + font-weight: 400; + line-height: 18px; + text-indent: -14px; + color: #ffffff; + width: 36px; + height: 18px; + display: inline-block; + background-color: #a7aaad; + border-radius: 72px; + box-shadow: 0 0 12px rgb(0 0 0 / 15%) inset; +} +input[type='checkbox'].litespeed-tiny-toggle:before { + content: ''; + width: 14px; + height: 14px; + display: block; + position: absolute; + top: 2px; + left: 2px; + margin: 0; + border-radius: 50%; + background-color: #ffffff; +} + +input[type='checkbox'].litespeed-tiny-toggle:checked:before { + left: 20px; + margin: 0; + background-color: #ffffff; +} + +input[type='checkbox'].litespeed-tiny-toggle, +input[type='checkbox'].litespeed-tiny-toggle:before, +input[type='checkbox'].litespeed-tiny-toggle:after, +input[type='checkbox'].litespeed-tiny-toggle:checked:before, +input[type='checkbox'].litespeed-tiny-toggle:checked:after { + transition: ease 0.15s; +} +input[type='checkbox'].litespeed-tiny-toggle:checked:after { + /*content: 'ON';*/ + background-color: #2271b1; +} + +.block-editor__container input[type='checkbox'].litespeed-tiny-toggle { border: 0 !important; } -.block-editor__container input[type="checkbox"].litespeed-tiny-toggle:before { +.block-editor__container input[type='checkbox'].litespeed-tiny-toggle:before { top: 5px; left: 7px; } -.block-editor__container input[type="checkbox"].litespeed-tiny-toggle:checked:before { +.block-editor__container input[type='checkbox'].litespeed-tiny-toggle:checked:before { left: 23px; } @@ -121,7 +120,7 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { /* content: "\e900"; font-family: 'litespeedfont' !important; */ content: ''; - background-image:url('../img/lscwp_grayscale_font-icon_22px.svg'); + background-image: url('../img/lscwp_grayscale_font-icon_22px.svg'); /* filter: grayscale(1); */ background-size: 22px; background-repeat: no-repeat; @@ -130,8 +129,8 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { vertical-align: middle; display: inline-block; position: absolute; - left:5px; - top:8px; + left: 5px; + top: 8px; } .rtl .litespeed_icon:before { @@ -157,7 +156,6 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { display: inline-block; } - .litespeed-row { margin-top: 5px; } @@ -177,7 +175,7 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { height: auto; } -.litespeed-flex-container>* { +.litespeed-flex-container > * { box-sizing: border-box; } @@ -300,7 +298,7 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { } .litespeed-wrap .litespeed-bg-quic-cloud { - background: linear-gradient(rgba(230,242,242,1) 10%, rgba(250,255,255,1) 30%); + background: linear-gradient(rgba(230, 242, 242, 1) 10%, rgba(250, 255, 255, 1) 30%); } .litespeed-left50 { @@ -336,7 +334,6 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { margin-bottom: 0px !important; } - .litespeed-empty-space-xlarge { margin-top: 8em; } @@ -357,7 +354,6 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { margin-top: 1em; } - /* ======================================= UTILITIES - typography ======================================= */ @@ -367,7 +363,7 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { } .litespeed-text-large { - font-size: .75em !important; + font-size: 0.75em !important; } .litespeed-text-md { @@ -395,11 +391,11 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { } .litespeed-primary { - color: #3366CC !important; + color: #3366cc !important; } .litespeed-info { - color: #3FBFBF !important; + color: #3fbfbf !important; } .litespeed-success { @@ -407,7 +403,7 @@ input[type="checkbox"].litespeed-tiny-toggle:checked:after { } .litespeed-warning { - color: #FF8C00 !important; + color: #ff8c00 !important; } .litespeed-danger { @@ -437,7 +433,7 @@ button.litespeed-form-action:hover { } .litespeed-bg-primary { - background-color: #3366CC !important; + background-color: #3366cc !important; } .litespeed-bg-info { @@ -449,7 +445,7 @@ button.litespeed-form-action:hover { } .litespeed-bg-warning { - background-color: #FF8C00 !important; + background-color: #ff8c00 !important; } .litespeed-bg-danger { @@ -494,11 +490,11 @@ button.litespeed-form-action:hover { .litespeed-body { background: #fff; border: 1px solid #e5e5e5; - box-shadow: 0 1px 1px rgba(0, 0, 0, .04); + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); padding: 1px 20px 20px 20px; } -.litespeed-header+.litespeed-body { +.litespeed-header + .litespeed-body { border-top: none; } @@ -529,11 +525,11 @@ button.litespeed-form-action:hover { /*max-width: 840px;*/ } -.litespeed-desc+.litespeed-desc { - margin-top: -5px +.litespeed-desc + .litespeed-desc { + margin-top: -5px; } -td>.litespeed-desc:first-child { +td > .litespeed-desc:first-child { margin-top: 0px; line-height: 2.24; } @@ -609,7 +605,6 @@ h3 .litespeed-learn-more { padding-right: 50px; padding-left: 3px; padding-bottom: 3px; - } .litespeed-title .button { @@ -661,7 +656,6 @@ h3 .litespeed-learn-more { color: #72777c; } - /* ======================================= LAYOUT - table ======================================= */ @@ -670,7 +664,7 @@ h3 .litespeed-learn-more { font-size: 14px; } -.litespeed-body tbody>tr>th { +.litespeed-body tbody > tr > th { padding-left: 20px; } @@ -688,20 +682,19 @@ h3 .litespeed-learn-more { vertical-align: middle; } -.litespeed-body .widefat td input+p { - margin-top: .8em; +.litespeed-body .widefat td input + p { + margin-top: 0.8em; } -.litespeed-body .striped>tbody>:nth-child(even) .notice { +.litespeed-body .striped > tbody > :nth-child(even) .notice { background-color: #f9f9f9; - box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .05); + box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.05); border-top: 1px solid #e5e5e5; border-bottom: 1px solid #e5e5e5; border-right: 1px solid #e5e5e5; - } -.litespeed-body .striped>tbody>:nth-child(even) .notice:first-child { +.litespeed-body .striped > tbody > :nth-child(even) .notice:first-child { margin-top: 0; } @@ -801,7 +794,7 @@ h3 .litespeed-learn-more { min-height: 75px; box-sizing: border-box; background: #f9fafc; - transition: .25s; + transition: 0.25s; } .litespeed-panel:hover { @@ -814,7 +807,7 @@ h3 .litespeed-learn-more { height: 100%; } -[class*="litespeed-panel-icon-"] { +[class*='litespeed-panel-icon-'] { background-size: contain; width: 60px; height: 60px; @@ -824,91 +817,91 @@ h3 .litespeed-learn-more { } .litespeed-panel-icon-all { - background-image: url("../img/icons/all.svg"); + background-image: url('../img/icons/all.svg'); } .litespeed-panel-icon-revision { - background-image: url("../img/icons/revision.svg"); + background-image: url('../img/icons/revision.svg'); } .litespeed-panel-icon-auto_draft { - background-image: url("../img/icons/auto_draft.svg"); + background-image: url('../img/icons/auto_draft.svg'); } .litespeed-panel-icon-trash_post { - background-image: url("../img/icons/trash_post.svg"); + background-image: url('../img/icons/trash_post.svg'); } .litespeed-panel-icon-spam_comment { - background-image: url("../img/icons/spam_comment.svg"); + background-image: url('../img/icons/spam_comment.svg'); } .litespeed-panel-icon-trash_comment { - background-image: url("../img/icons/trash_comment.svg"); + background-image: url('../img/icons/trash_comment.svg'); } .litespeed-panel-icon-trackback-pingback { - background-image: url("../img/icons/trackback-pingback.svg"); + background-image: url('../img/icons/trackback-pingback.svg'); } .litespeed-panel-icon-expired_transient { - background-image: url("../img/icons/expired_transient.svg"); + background-image: url('../img/icons/expired_transient.svg'); } .litespeed-panel-icon-all_transients { - background-image: url("../img/icons/all_transients.svg"); + background-image: url('../img/icons/all_transients.svg'); } .litespeed-panel-icon-optimize_tables { - background-image: url("../img/icons/optimize_tables.svg"); + background-image: url('../img/icons/optimize_tables.svg'); } .litespeed-panel-icon-purge-front { - background-image: url("../img/icons/purge-front.svg"); + background-image: url('../img/icons/purge-front.svg'); } .litespeed-panel-icon-purge-pages { - background-image: url("../img/icons/purge-pages.svg"); + background-image: url('../img/icons/purge-pages.svg'); } .litespeed-panel-icon-purge-cssjs { - background-image: url("../img/icons/purge-cssjs.svg"); + background-image: url('../img/icons/purge-cssjs.svg'); } .litespeed-panel-icon-purge-object { - background-image: url("../img/icons/purge-object.svg"); + background-image: url('../img/icons/purge-object.svg'); } .litespeed-panel-icon-purge-opcache { - background-image: url("../img/icons/purge-opcache.svg"); + background-image: url('../img/icons/purge-opcache.svg'); } .litespeed-panel-icon-purge-all { - background-image: url("../img/icons/purge-all.svg"); + background-image: url('../img/icons/purge-all.svg'); } .litespeed-panel-icon-empty-cache { - background-image: url("../img/icons/empty-cache.svg"); + background-image: url('../img/icons/empty-cache.svg'); } .litespeed-panel-icon-purge-403 { - background-image: url("../img/icons/purge-403.svg"); + background-image: url('../img/icons/purge-403.svg'); } .litespeed-panel-icon-purge-404 { - background-image: url("../img/icons/purge-404.svg"); + background-image: url('../img/icons/purge-404.svg'); } .litespeed-panel-icon-purge-500 { - background-image: url("../img/icons/purge-500.svg"); + background-image: url('../img/icons/purge-500.svg'); } .litespeed-panel-top-right-icon-cross { - background-image: url("../img/icons/cross_icon.svg"); + background-image: url('../img/icons/cross_icon.svg'); } .litespeed-panel-top-right-icon-tick { - background-image: url("../img/icons/success_icon.svg"); + background-image: url('../img/icons/success_icon.svg'); } .litespeed-panel-content { @@ -1036,7 +1029,11 @@ h3 .litespeed-learn-more { border-color: #538ac6 #2264ad #2264ad; color: #fff; box-shadow: 0 1px 0 #2264ad; - text-shadow: 0 -1px 1px #2264ad, 1px 0 1px #2264ad, 0 1px 1px #2264ad, -1px 0 1px #2264ad; + text-shadow: + 0 -1px 1px #2264ad, + 1px 0 1px #2264ad, + 0 1px 1px #2264ad, + -1px 0 1px #2264ad; } .litespeed-wrap .button-primary:focus, @@ -1054,7 +1051,9 @@ h3 .litespeed-learn-more { background: #5891ce; border-color: #2264ad; color: #fff; - box-shadow: 0 1px 0 #0073aa, 0 0 2px 1px #33b3db; + box-shadow: + 0 1px 0 #0073aa, + 0 0 2px 1px #33b3db; } .litespeed .litespeed-btn-primary, @@ -1084,7 +1083,7 @@ h3 .litespeed-learn-more { margin-left: 5px; } -.litespeed-wrap .button+.button { +.litespeed-wrap .button + .button { margin-left: 10px; } @@ -1143,8 +1142,8 @@ h3 .litespeed-learn-more { .litespeed-wrap .litespeed-btn-large { font-size: 1.5em; - padding: .75em 1.5em; - margin: 0 .25em; + padding: 0.75em 1.5em; + margin: 0 0.25em; height: auto; } @@ -1153,7 +1152,6 @@ h3 .litespeed-learn-more { width: auto; } - /* ======================================= SWITCH ======================================= */ @@ -1166,17 +1164,23 @@ h3 .litespeed-learn-more { position: relative; } -.litespeed-switch input:checked:active+label { - box-shadow: 0 2px 0 rgba(27, 146, 146, 0.7), inset 0 2px 5px -3px rgba(0, 0, 0, .5); +.litespeed-switch input:checked:active + label { + box-shadow: + 0 2px 0 rgba(27, 146, 146, 0.7), + inset 0 2px 5px -3px rgba(0, 0, 0, 0.5); } -.litespeed-switch input:checked+label { +.litespeed-switch input:checked + label { background-color: #36b0b0; color: #fff; border: 1px solid #36b0b0; box-shadow: 0 2px 0 #1b9292; z-index: 2; - text-shadow: 0 -1px 1px #1b9292, 1px 0 1px #1b9292, 0 1px 1px #1b9292, -1px 0 1px #1b9292; + text-shadow: + 0 -1px 1px #1b9292, + 1px 0 1px #1b9292, + 0 1px 1px #1b9292, + -1px 0 1px #1b9292; } .litespeed-switch label { @@ -1208,37 +1212,35 @@ h3 .litespeed-learn-more { border-bottom-left-radius: 3px; } -.litespeed-switch input:hover+label { +.litespeed-switch input:hover + label { border-color: #1a9292; box-shadow: 0 2px 0 #1a9292; z-index: 2; color: #117171; - } -.litespeed-switch input:focus+label { +.litespeed-switch input:focus + label { color: #117171; box-shadow: 0 0px 0px 2px rgba(28, 138, 128, 0.85); border-color: transparent; z-index: 2; - } -.litespeed-switch input:focus+label+input+input:hover+label, -.litespeed-switch input:focus+label+input:hover+label { +.litespeed-switch input:focus + label + input + input:hover + label, +.litespeed-switch input:focus + label + input:hover + label { z-index: 1; } -.litespeed-switch input:active+label { - box-shadow: 0 2px 0 #1b9292, inset 0 2px 5px -3px rgba(0, 0, 0, .5); +.litespeed-switch input:active + label { + box-shadow: + 0 2px 0 #1b9292, + inset 0 2px 5px -3px rgba(0, 0, 0, 0.5); } -.litespeed-switch input:checked:hover+label, -.litespeed-switch input:checked:focus+label { +.litespeed-switch input:checked:hover + label, +.litespeed-switch input:checked:focus + label { background-color: #36b0b0; color: #fff; - - } .litespeed-switch input { @@ -1271,7 +1273,7 @@ h3 .litespeed-learn-more { align-items: center; } -.litespeed-toggle-wrapper+.litespeed-toggle-wrapper { +.litespeed-toggle-wrapper + .litespeed-toggle-wrapper { margin-top: 0.75rem; } @@ -1393,8 +1395,8 @@ h3 .litespeed-learn-more { .litespeed-toggle-btn.litespeed-toggle-active { background-image: none; outline: 0; - -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125); - box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125); + -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); + box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); } .litespeed-toggle-btn-default:active, @@ -1405,9 +1407,9 @@ h3 .litespeed-learn-more { /* ======================================= LABEL/TAG ======================================= */ -[class*="litespeed-label-"] { +[class*='litespeed-label-'] { display: inline; - padding: .2em .6em .3em; + padding: 0.2em 0.6em 0.3em; font-size: 75%; font-weight: bold; line-height: 1; @@ -1415,17 +1417,17 @@ h3 .litespeed-learn-more { text-align: center; white-space: nowrap; vertical-align: baseline; - border-radius: .25em; + border-radius: 0.25em; } -[class*="litespeed-label-"]:hover, -[class*="litespeed-label-"]:focus { +[class*='litespeed-label-']:hover, +[class*='litespeed-label-']:focus { color: #fff; text-decoration: none; cursor: pointer; } -[class*="litespeed-label-"]:empty { +[class*='litespeed-label-']:empty { display: none; } @@ -1514,7 +1516,7 @@ h3 .litespeed-learn-more { .litespeed-shell-header-bg { opacity: 0.4; - background-color: #CCCCCC; + background-color: #cccccc; position: absolute; top: 0; bottom: 0; @@ -1532,7 +1534,7 @@ h3 .litespeed-learn-more { left: 0; z-index: 10; height: 2px; - background-color: #F48024; + background-color: #f48024; } .litespeed-shell-header-icon-container { @@ -1555,8 +1557,11 @@ ul.litespeed-shell-body { padding: 5px; list-style: none; background: #141414; - color: #45D40C; - font: 0.8em 'Andale Mono', Consolas, 'Courier New'; + color: #45d40c; + font: + 0.8em 'Andale Mono', + Consolas, + 'Courier New'; line-height: 1.6em; -webkit-border-bottom-right-radius: 3px; @@ -1565,7 +1570,6 @@ ul.litespeed-shell-body { -moz-border-radius-bottomleft: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; - } .litespeed-shell-body li:before { @@ -1588,7 +1592,6 @@ ul.litespeed-shell-body { margin: 5px -15px; } - /* ======================================= CALLOUT / NOTICE ======================================= */ @@ -1657,7 +1660,7 @@ ul.litespeed-shell-body { background: none; } -.litespeed-tick-list .litespeed-tick input[type="checkbox"] { +.litespeed-tick-list .litespeed-tick input[type='checkbox'] { margin-left: 0; } @@ -1665,8 +1668,7 @@ ul.litespeed-shell-body { color: inherit; } - -.litespeed-tick input[type="checkbox"] { +.litespeed-tick input[type='checkbox'] { height: 18px; width: 18px; vertical-align: middle; @@ -1680,20 +1682,19 @@ ul.litespeed-shell-body { cursor: pointer; } -.litespeed-tick input[type="checkbox"]:not(:disabled):hover { +.litespeed-tick input[type='checkbox']:not(:disabled):hover { border-color: #538ac6; - } -.litespeed-tick input[type="checkbox"]:active:not(:disabled) { +.litespeed-tick input[type='checkbox']:active:not(:disabled) { border-color: #538ac6; } -.litespeed-tick input[type="checkbox"]:focus { +.litespeed-tick input[type='checkbox']:focus { outline: none; } -.litespeed-tick input[type="checkbox"]:checked { +.litespeed-tick input[type='checkbox']:checked { border-color: #538ac6; background-color: #538ac6; -moz-box-shadow: none; @@ -1701,7 +1702,7 @@ ul.litespeed-shell-body { box-shadow: none; } -.litespeed-tick input[type="checkbox"]:checked:before { +.litespeed-tick input[type='checkbox']:checked:before { content: ''; display: block; width: 5px; @@ -1736,7 +1737,7 @@ ul.litespeed-shell-body { padding-left: 1.5rem; } -.litespeed-radio-row input[type=radio] { +.litespeed-radio-row input[type='radio'] { margin-top: 0; margin-bottom: 0; position: absolute; @@ -1815,11 +1816,11 @@ ul.litespeed-shell-body { min-width: 110px; } -input.litespeed-input[type="file"] { +input.litespeed-input[type='file'] { padding: 9px; min-width: 500px; border: 1px solid #ddd; - box-shadow: inset 0 1px 2px rgba(0, 0, 0, .07); + box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07); background-color: #fff; color: #32373c; outline: 0; @@ -1851,7 +1852,7 @@ input.litespeed-input-warning { margin: 0; } -.litespeed-textarea-recommended>div:first-child { +.litespeed-textarea-recommended > div:first-child { margin-top: 1.7em; font-size: 12px; margin-right: 25px; @@ -1863,7 +1864,7 @@ input.litespeed-input-warning { text-align: center; } -.litespeed-collection-button[data-action="add"] { +.litespeed-collection-button[data-action='add'] { margin-top: -5px; margin-left: -5px; } @@ -1879,8 +1880,7 @@ input.litespeed-input-warning { } @media screen and (max-width: 680px) { - - .litespeed-body tbody>tr>th { + .litespeed-body tbody > tr > th { display: block; padding: 18px 0 5px 12px; } @@ -1901,7 +1901,7 @@ input.litespeed-input-warning { flex-direction: column; } - .litespeed-textarea-recommended>div:first-child { + .litespeed-textarea-recommended > div:first-child { margin-bottom: 1.7em; margin-top: 0; } @@ -1981,7 +1981,7 @@ input.litespeed-input-warning { } .litespeed-banner-promo-slacklogo { - background-image: url("../img/slack-logo.png"); + background-image: url('../img/slack-logo.png'); background-size: contain; width: 75px; height: 75px; @@ -2009,7 +2009,7 @@ input.litespeed-input-warning { .litespeed-banner-promo-slack-line2 { font-size: 15px; margin: 0px; - line-height: .75em; + line-height: 0.75em; } .litespeed-banner-promo-slack-link { @@ -2080,7 +2080,15 @@ a.litespeed-btn-xs.litespeed-banner-promo-slack-btn { } .litespeed-tweet-text { - font: 14px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif; + font: + 14px system-ui, + -apple-system, + BlinkMacSystemFont, + 'Segoe UI', + Roboto, + Ubuntu, + 'Helvetica Neue', + sans-serif; line-height: 1.3125; } @@ -2089,9 +2097,8 @@ a.litespeed-btn-xs.litespeed-banner-promo-slack-btn { margin-top: 1em; } - .litespeed-tweet-cta a { - background-color: #1DA1F2; + background-color: #1da1f2; line-height: 1.3125; color: #fff; font-weight: bold; @@ -2103,7 +2110,7 @@ a.litespeed-btn-xs.litespeed-banner-promo-slack-btn { } .litespeed-tweet-cta a:hover { - background-color: #1E98E1; + background-color: #1e98e1; } .litespeed-tweet-cta a svg { @@ -2127,7 +2134,7 @@ a.litespeed-btn-xs.litespeed-banner-promo-slack-btn { vertical-align: middle; } -.litespeed-tweet-img+p { +.litespeed-tweet-img + p { margin-top: 0; } @@ -2139,7 +2146,7 @@ a.litespeed-btn-xs.litespeed-banner-promo-slack-btn { display: inline-table; } -[class*="litespeed-icon-media-"] { +[class*='litespeed-icon-media-'] { background-size: contain; width: 25px; height: 25px; @@ -2149,24 +2156,24 @@ a.litespeed-btn-xs.litespeed-banner-promo-slack-btn { display: inline-block; } -[class*="litespeed-icon-media-"]:hover { +[class*='litespeed-icon-media-']:hover { opacity: 0.7; } .litespeed-icon-media-webp { - background-image: url("../img/icons/img_webp.svg"); + background-image: url('../img/icons/img_webp.svg'); } .litespeed-icon-media-webp-disabled { - background-image: url("../img/icons/img_webp_disabled.svg"); + background-image: url('../img/icons/img_webp_disabled.svg'); } .litespeed-icon-media-optm { - background-image: url("../img/icons/img_optm.svg"); + background-image: url('../img/icons/img_optm.svg'); } .litespeed-icon-media-optm-disabled { - background-image: url("../img/icons/img_optm_disabled.svg"); + background-image: url('../img/icons/img_optm_disabled.svg'); } p.litespeed-media-p { @@ -2207,7 +2214,6 @@ p.litespeed-txt-disabled { margin: 5px 5px 5px 0; } - circle.litespeed-pie_bg { stroke: #efefef; stroke-width: 2; @@ -2227,7 +2233,6 @@ circle.litespeed-pie_circle { fill: none; } - .litespeed-pie.litespeed-pie-tiny { margin: 0 2px 0 0; } @@ -2235,7 +2240,6 @@ circle.litespeed-pie_circle { .litespeed-pie.litespeed-pie-tiny text { font-weight: bold; fill: #828282; - } .litespeed-pie.litespeed-pie-tiny circle { @@ -2332,7 +2336,7 @@ g.litespeed-pie_info .litespeed-pie-done { margin-left: 10px; } -#cookie_crawler>p:first-child { +#cookie_crawler > p:first-child { margin-top: 5px; } @@ -2354,7 +2358,7 @@ g.litespeed-pie_info .litespeed-pie-done { color: #fff; text-align: center; background-color: #007bff; - transition: width .6s ease; + transition: width 0.6s ease; } .litespeed-progress-bar-yellow { @@ -2367,7 +2371,7 @@ g.litespeed-pie_info .litespeed-pie-done { display: flex; height: 12px; overflow: hidden; - font-size: .75rem; + font-size: 0.75rem; background-color: #e9ecef; border: 1px solid #dddddd; border-radius: 8px; @@ -2423,10 +2427,9 @@ g.litespeed-pie_info .litespeed-pie-done { } .litespeed-guide li.litespeed-guide-done { - opacity: .9; + opacity: 0.9; } - /* ======================================= VIEW - image optimization ======================================= */ @@ -2435,7 +2438,6 @@ g.litespeed-pie_info .litespeed-pie-done { padding: 0; } - .litespeed-cache_page_litespeed-img_optm .nav-tab-wrapper { border-bottom: none; position: relative; @@ -2452,7 +2454,7 @@ g.litespeed-pie_info .litespeed-pie-done { .litespeed-cache_page_litespeed-img_optm [data-litespeed-layout]:not([data-litespeed-layout='summary']) { background: #fff; border: 1px solid #e5e5e5; - box-shadow: 0 1px 1px rgba(0, 0, 0, .04); + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); padding: 1px 20px 20px 20px; } @@ -2460,23 +2462,23 @@ g.litespeed-pie_info .litespeed-pie-done { background: #f9fafc; } -.litespeed-column-with-boxes>div:first-child { +.litespeed-column-with-boxes > div:first-child { padding-right: 25px; } -.litespeed-column-with-boxes>div:last-child { +.litespeed-column-with-boxes > div:last-child { background: #f1f1f1; padding-top: 0; padding-right: 0; padding-left: 0; } -.litespeed-column-with-boxes>div:last-child .litespeed-postbox:last-child { +.litespeed-column-with-boxes > div:last-child .litespeed-postbox:last-child { margin-bottom: 0; } .litespeed-image-optim-summary { - box-shadow: 0 1px 1px rgba(0, 0, 0, .04); + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); position: relative; padding: 1px 20px 20px 20px; background: #fff; @@ -2508,12 +2510,12 @@ g.litespeed-pie_info .litespeed-pie-done { margin-top: 0; } -.litespeed-image-optim-summary>h3:first-child { +.litespeed-image-optim-summary > h3:first-child { margin-top: 1.6em; font-size: 1.2em; } -.litespeed-image-optim-summary>h3:first-child .litespeed-quic-icon { +.litespeed-image-optim-summary > h3:first-child .litespeed-quic-icon { width: 1.2em; height: 1.4em; background-size: contain; @@ -2542,7 +2544,7 @@ g.litespeed-pie_info .litespeed-pie-done { } @media screen and (max-width: 814px) { - .litespeed-column-with-boxes>div:first-child { + .litespeed-column-with-boxes > div:first-child { padding-right: 0; margin-bottom: 1rem; } @@ -2561,7 +2563,7 @@ g.litespeed-pie_info .litespeed-pie-done { margin-top: 0; } -.imgoptm.column-imgoptm p+.row-actions { +.imgoptm.column-imgoptm p + .row-actions { margin-top: 0.5em; } @@ -2594,7 +2596,7 @@ g.litespeed-pie_info .litespeed-pie-done { margin-bottom: 1rem; } -.litespeed-dashboard-group>.litespeed-flex-container { +.litespeed-dashboard-group > .litespeed-flex-container { margin: 0 -10px; min-width: 100%; width: auto; @@ -2602,7 +2604,6 @@ g.litespeed-pie_info .litespeed-pie-done { .litespeed-dashboard .litespeed-postbox { margin: 10px; - } .litespeed-dashboard-title a { @@ -2646,7 +2647,7 @@ g.litespeed-pie_info .litespeed-pie-done { color: #777; } -.litespeed-dashboard-stats h3+p { +.litespeed-dashboard-stats h3 + p { margin-top: 0; margin-bottom: 0; } @@ -2692,7 +2693,7 @@ g.litespeed-pie_info .litespeed-pie-done { height: 60px; } -.litespeed-dashboard-stats-wrapper .litespeed-flex-container+p:not(:last-child) { +.litespeed-dashboard-stats-wrapper .litespeed-flex-container + p:not(:last-child) { margin-bottom: 0.55em; } @@ -2704,12 +2705,11 @@ g.litespeed-pie_info .litespeed-pie-done { color: #444; } -.postbox .inside>p.litespeed-dashboard-stats-payg { +.postbox .inside > p.litespeed-dashboard-stats-payg { margin-top: 1.35em; } -.postbox .inside>p.litespeed-dashboard-stats-payg:last-child { - +.postbox .inside > p.litespeed-dashboard-stats-payg:last-child { margin-bottom: -5px !important; } @@ -2800,16 +2800,16 @@ g.litespeed-pie_info .litespeed-pie-done { .litespeed-label-dashboard { font-size: 0.92em; - padding: .3em .6em .35em .6em; + padding: 0.3em 0.6em 0.35em 0.6em; font-weight: normal; display: inline-block; - margin-left: .2em; + margin-left: 0.2em; min-width: 2em; } .litespeed-label-dashboard:first-child { margin-left: 0; - margin-right: .35em; + margin-right: 0.35em; } .litespeed-postbox .inside { @@ -2831,7 +2831,8 @@ g.litespeed-pie_info .litespeed-pie-done { margin-top: 0; } -.litespeed-postbox-footer a, a.litespeed-redetect { +.litespeed-postbox-footer a, +a.litespeed-redetect { text-decoration: none; } @@ -2840,7 +2841,6 @@ g.litespeed-pie_info .litespeed-pie-done { font-size: 12px; } - .litespeed-postbox-imgopt .litespeed-pie { width: 55px; height: 55px; @@ -2851,15 +2851,15 @@ g.litespeed-pie_info .litespeed-pie-done { margin-bottom: 10px; } -.litespeed-postbox-imgopt .litespeed-flex-container .litespeed-icon-vertical-middle+div h3 { +.litespeed-postbox-imgopt .litespeed-flex-container .litespeed-icon-vertical-middle + div h3 { margin-top: 0; } -.litespeed-postbox-imgopt .litespeed-flex-container .litespeed-icon-vertical-middle+div p { +.litespeed-postbox-imgopt .litespeed-flex-container .litespeed-icon-vertical-middle + div p { line-height: 1.2; } -.litespeed-postbox-imgopt .litespeed-postbox-double-col:last-child>*:first-child { +.litespeed-postbox-imgopt .litespeed-postbox-double-col:last-child > *:first-child { margin-top: 7px; } @@ -2903,7 +2903,7 @@ g.litespeed-pie_info .litespeed-pie-done { margin-bottom: 1em; } -.litespeed-links-group>span:not(:last-child):after { +.litespeed-links-group > span:not(:last-child):after { content: '|'; margin: 0 10px; color: #ddd; @@ -2964,7 +2964,6 @@ g.litespeed-pie_info .litespeed-pie-done { } @media screen and (max-width: 1023px) { - .litespeed-dashboard-stats-wrapper { flex-wrap: wrap; } @@ -3018,12 +3017,10 @@ g.litespeed-pie_info .litespeed-pie-done { /********************************* todo *******************************/ - /* image optimize page */ - .litespeed-column-java { - background: #5CADAD !important; + background: #5cadad !important; } .litespeed-text-shipgrey { @@ -3039,19 +3036,19 @@ g.litespeed-pie_info .litespeed-pie-done { } .litespeed-text-whisper { - color: #E6E6E6 !important; + color: #e6e6e6 !important; } .litespeed-text-malibu { - color: #5CBDDE !important; + color: #5cbdde !important; } .litespeed-text-morningglory { - color: #99CCCC !important; + color: #99cccc !important; } .litespeed-text-fern { - color: #66CC66 !important; + color: #66cc66 !important; } .litespeed-text-persiangreen { @@ -3081,7 +3078,7 @@ g.litespeed-pie_info .litespeed-pie-done { .litespeed-hr { padding-bottom: 1.5em; - border-bottom: .5px solid #97CACA; + border-bottom: 0.5px solid #97caca; } .litespeed-hr-with-space { @@ -3096,7 +3093,6 @@ g.litespeed-pie_info .litespeed-pie-done { margin: 0px 10px 0px 10px; } - .litespeed-column-java .litespeed-danger { color: #c1c53a !important; } @@ -3119,7 +3115,7 @@ g.litespeed-pie_info .litespeed-pie-done { } .litespeed-refresh:after { - content: "⟳"; + content: '⟳'; width: 20px; height: 20px; color: #40ad3a; @@ -3140,7 +3136,7 @@ g.litespeed-pie_info .litespeed-pie-done { } .litespeed-silence { - color: #B1B1B1; + color: #b1b1b1; } .litespeed-column-java .litespeed-congratulate { @@ -3166,11 +3162,11 @@ g.litespeed-pie_info .litespeed-pie-done { } .litespeed-column-java svg.litespeed-pie circle.litespeed-pie_circle { - stroke: #97CACA; + stroke: #97caca; } .litespeed-column-java svg .litespeed-pie_info text { - fill: #F5FFEB; + fill: #f5ffeb; } .litespeed-column-java svg g.litespeed-pie_info .litespeed-pie-done { @@ -3186,12 +3182,12 @@ g.litespeed-pie_info .litespeed-pie-done { } .litespeed-progress-bar-blue { - background-color: #33ADFF; + background-color: #33adff; } .litespeed-status-current { font-size: 3.5em; - margin: 1.25em 0em .75em 0em; + margin: 1.25em 0em 0.75em 0em; } /* .litespeed-title, .litespeed-title-short { @@ -3201,71 +3197,70 @@ g.litespeed-pie_info .litespeed-pie-done { } */ .litespeed-column-java .litespeed-desc { - color: #CAE4E4; + color: #cae4e4; } .litespeed-column-java .litespeed-warning { - color: #FFD597 !important; + color: #ffd597 !important; } .litespeed-column-java .litespeed-btn-success { - color: #DDF1E4; - border: 1px solid #33AD5C; - background: #33AD5C; + color: #ddf1e4; + border: 1px solid #33ad5c; + background: #33ad5c; } .litespeed-column-java .litespeed-btn-success:hover { - color: #FFFFFF; - border: 1px solid #7DCA97; + color: #ffffff; + border: 1px solid #7dca97; background: #009933; } .litespeed-column-java .litespeed-btn-warning { - color: #FFF1DD; - border: 1px solid #FF9933; - background-color: #FF9933; + color: #fff1dd; + border: 1px solid #ff9933; + background-color: #ff9933; } .litespeed-column-java .litespeed-btn-warning:hover { - color: #FFFFFF; - border-color: #FFCA7D; - background: #FF9900; + color: #ffffff; + border-color: #ffca7d; + background: #ff9900; } .litespeed-column-java .litespeed-btn-danger { - color: #FFEADD !important; - border: 1px solid #FF6600 !important; - background: #FF5C5C; + color: #ffeadd !important; + border: 1px solid #ff6600 !important; + background: #ff5c5c; } .litespeed-column-java .litespeed-btn-danger:hover { - color: #FFFFFF; - border: 1px solid #FF9797 !important; - background: #FF0000; + color: #ffffff; + border: 1px solid #ff9797 !important; + background: #ff0000; } .litespeed-column-java .litepseed-dash-icon-success, .litepseed-dash-icon-success { - color: #5CDEDE; + color: #5cdede; font-size: 2em; - margin-top: -.25em; + margin-top: -0.25em; } .litespeed-column-java .litepseed-dash-icon-success:hover, .litepseed-dash-icon-success:hover { - color: #7DE5E5; + color: #7de5e5; } .litespeed-dashicons-large { font-size: 2em; } - .litespeed-column-java p { - color: #FFFFFF; + color: #ffffff; } -.litespeed-body tbody>tr>th.litespeed-padding-left { +.litespeed-body tbody > tr > th.litespeed-padding-left { padding-left: 3em; } @@ -3291,9 +3286,9 @@ g.litespeed-pie_info .litespeed-pie-done { a.litespeed-media-href svg:hover { border-radius: 50%; - background: #F1FCFF; - fill: #5CCAD7; - box-shadow: 0 0 5px 1px #7DD5DF; + background: #f1fcff; + fill: #5ccad7; + box-shadow: 0 0 5px 1px #7dd5df; transition: all 0.2s ease-out; transform: scale(1.05); } @@ -3307,21 +3302,21 @@ a.litespeed-media-href svg:hover { } .litespeed-media-p a .dashicons-trash:hover { - transition: all .2s ease-out; - color: #FFA500 !important; - background: #FFF5E6; - box-shadow: 0 0 10px 1px #FF8C00; + transition: all 0.2s ease-out; + color: #ffa500 !important; + background: #fff5e6; + box-shadow: 0 0 10px 1px #ff8c00; } -.litespeed-media-p div>svg circle.litespeed-pie_bg { +.litespeed-media-p div > svg circle.litespeed-pie_bg { stroke: #ecf2f9; } -.litespeed-media-p div>svg circle.litespeed-pie_circle { +.litespeed-media-p div > svg circle.litespeed-pie_circle { stroke: #9fbfdf; } -.litespeed-media-p div>svg { +.litespeed-media-p div > svg { fill: #538cc6; background: rgba(236, 242, 249, 0.1); border-radius: 50%; @@ -3369,16 +3364,9 @@ a.litespeed-media-href svg:hover { .litespeed-notice-dismiss:hover, .litespeed-notice-dismiss:active, .litespeed-notice-dismiss:focus { - color: #CC2929; + color: #cc2929; } - - - - - - - .litespeed-dot { display: inline-block; border-radius: 50%; @@ -3397,7 +3385,6 @@ a.litespeed-media-href svg:hover { text-align: center; } - /* ======================================= Comparison Cards - Presets ======================================= */ @@ -3406,7 +3393,7 @@ a.litespeed-media-href svg:hover { box-sizing: border-box; } -.litespeed-comparison-card-rec .litespeed-card-content>div.litespeed-card-body { +.litespeed-comparison-card-rec .litespeed-card-content > div.litespeed-card-body { font-size: 14px; } @@ -3418,7 +3405,7 @@ a.litespeed-media-href svg:hover { font-size: 20px; } -.litespeed-card-content>div, +.litespeed-card-content > div, .litespeed-card-action { padding: 0.85rem 1.25rem; } @@ -3428,7 +3415,7 @@ a.litespeed-media-href svg:hover { background: #f9fafc; } -.litespeed-card-content>div.litespeed-card-body { +.litespeed-card-content > div.litespeed-card-body { align-self: stretch; justify-content: flex-end; font-size: 15px; @@ -3436,12 +3423,11 @@ a.litespeed-media-href svg:hover { padding-top: 1rem; } -.litespeed-card-content>div.litespeed-card-footer { +.litespeed-card-content > div.litespeed-card-footer { align-self: stretch; justify-content: flex-end; padding-bottom: 0; padding-top: 0.25rem; - } .litespeed-card-action { @@ -3467,7 +3453,7 @@ a.litespeed-media-href svg:hover { .litespeed-comparison-card ul li:before { content: '✓'; margin-left: -1em; - margin-right: .350em; + margin-right: 0.35em; color: #329c74; } @@ -3491,19 +3477,19 @@ a.litespeed-media-href svg:hover { width: 100%; } - .litespeed-card-content>div.litespeed-card-body { + .litespeed-card-content > div.litespeed-card-body { align-self: initial; width: 50%; box-sizing: border-box; } - .litespeed-card-content>div.litespeed-card-footer { + .litespeed-card-content > div.litespeed-card-footer { width: 50%; align-self: initial; box-sizing: border-box; } - .litespeed-card-content>div.litespeed-card-footer h4 { + .litespeed-card-content > div.litespeed-card-footer h4 { margin-top: 1rem; } } @@ -3539,7 +3525,7 @@ a.litespeed-media-href svg:hover { .litespeed-comparison-card-rec { width: 23%; padding-top: 1rem; - padding-bottom: .75rem; + padding-bottom: 0.75rem; margin-top: -1rem; margin-bottom: 0.25rem; border-radius: 5px; @@ -3575,7 +3561,7 @@ a.litespeed-media-href svg:hover { .litespeed-wrap [aria-label][data-balloon-pos]:after { opacity: 0; pointer-events: none; - transition: all .2s ease .05s; + transition: all 0.2s ease 0.05s; text-indent: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; font-weight: normal; @@ -3586,7 +3572,7 @@ a.litespeed-media-href svg:hover { border-radius: 2px; color: #fff; content: attr(aria-label); - padding: .5em 1em; + padding: 0.5em 1em; position: absolute; white-space: nowrap; z-index: 10; @@ -3600,8 +3586,8 @@ a.litespeed-media-href svg:hover { border-top-color: var(--balloon-color); opacity: 0; pointer-events: none; - transition: all .2s ease .05s; - content: ""; + transition: all 0.2s ease 0.05s; + content: ''; position: absolute; z-index: 10; } @@ -3617,7 +3603,18 @@ a.litespeed-media-href svg:hover { } .litespeed-wrap [aria-label][data-balloon-pos].font-awesome:after { - font-family: FontAwesome, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + font-family: + FontAwesome, + -apple-system, + BlinkMacSystemFont, + 'Segoe UI', + Roboto, + Oxygen, + Ubuntu, + Cantarell, + 'Open Sans', + 'Helvetica Neue', + sans-serif; } .litespeed-wrap [aria-label][data-balloon-pos][data-balloon-break]:after { @@ -3634,7 +3631,7 @@ a.litespeed-media-href svg:hover { transition: none; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up']:after { bottom: 100%; left: 50%; margin-bottom: 10px; @@ -3642,24 +3639,24 @@ a.litespeed-media-href svg:hover { transform-origin: top; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up']:before { bottom: 100%; left: 50%; transform: translate(-50%, var(--balloon-move)); transform-origin: top; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up'][data-balloon-visible]:after { transform: translate(-50%, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up'][data-balloon-visible]:before { transform: translate(-50%, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-left"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-left']:after { bottom: 100%; left: 0; margin-bottom: 10px; @@ -3667,24 +3664,24 @@ a.litespeed-media-href svg:hover { transform-origin: top; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-left"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-left']:before { bottom: 100%; left: 5px; transform: translate(0, var(--balloon-move)); transform-origin: top; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-left"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-left"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-left']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-left'][data-balloon-visible]:after { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-left"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-left"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-left']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-left'][data-balloon-visible]:before { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-right"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-right']:after { bottom: 100%; right: 0; margin-bottom: 10px; @@ -3692,31 +3689,31 @@ a.litespeed-media-href svg:hover { transform-origin: top; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-right"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-right']:before { bottom: 100%; right: 5px; transform: translate(0, var(--balloon-move)); transform-origin: top; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-right"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-right"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-right']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-right'][data-balloon-visible]:after { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-right"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="up-right"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-right']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='up-right'][data-balloon-visible]:before { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down']:after { left: 50%; margin-top: 10px; top: 100%; transform: translate(-50%, calc(var(--balloon-move) * -1)); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down']:before { width: 0; height: 0; border: 5px solid transparent; @@ -3726,24 +3723,24 @@ a.litespeed-media-href svg:hover { transform: translate(-50%, calc(var(--balloon-move) * -1)); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down'][data-balloon-visible]:after { transform: translate(-50%, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down'][data-balloon-visible]:before { transform: translate(-50%, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-left"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-left']:after { left: 0; margin-top: 10px; top: 100%; transform: translate(0, calc(var(--balloon-move) * -1)); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-left"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-left']:before { width: 0; height: 0; border: 5px solid transparent; @@ -3753,24 +3750,24 @@ a.litespeed-media-href svg:hover { transform: translate(0, calc(var(--balloon-move) * -1)); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-left"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-left"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-left']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-left'][data-balloon-visible]:after { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-left"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-left"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-left']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-left'][data-balloon-visible]:before { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-right"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-right']:after { right: 0; margin-top: 10px; top: 100%; transform: translate(0, calc(var(--balloon-move) * -1)); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-right"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-right']:before { width: 0; height: 0; border: 5px solid transparent; @@ -3780,24 +3777,24 @@ a.litespeed-media-href svg:hover { transform: translate(0, calc(var(--balloon-move) * -1)); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-right"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-right"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-right']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-right'][data-balloon-visible]:after { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-right"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="down-right"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-right']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='down-right'][data-balloon-visible]:before { transform: translate(0, 0); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="left"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='left']:after { margin-right: 10px; right: 100%; top: 50%; transform: translate(var(--balloon-move), -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="left"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='left']:before { width: 0; height: 0; border: 5px solid transparent; @@ -3807,24 +3804,24 @@ a.litespeed-media-href svg:hover { transform: translate(var(--balloon-move), -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="left"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="left"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='left']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='left'][data-balloon-visible]:after { transform: translate(0, -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="left"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="left"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='left']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='left'][data-balloon-visible]:before { transform: translate(0, -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="right"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='right']:after { left: 100%; margin-left: 10px; top: 50%; transform: translate(calc(var(--balloon-move) * -1), -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="right"]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='right']:before { width: 0; height: 0; border: 5px solid transparent; @@ -3834,44 +3831,44 @@ a.litespeed-media-href svg:hover { transform: translate(calc(var(--balloon-move) * -1), -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="right"]:hover:after, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="right"][data-balloon-visible]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='right']:hover:after, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='right'][data-balloon-visible]:after { transform: translate(0, -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="right"]:hover:before, -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos="right"][data-balloon-visible]:before { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='right']:hover:before, +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-pos='right'][data-balloon-visible]:before { transform: translate(0, -50%); } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length="small"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length='small']:after { white-space: normal; width: 80px; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length="medium"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length='medium']:after { white-space: normal; width: 150px; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length="large"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length='large']:after { white-space: normal; width: 260px; } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length="xlarge"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length='xlarge']:after { white-space: normal; width: 380px; } @media screen and (max-width: 768px) { - .litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length="xlarge"]:after { + .litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length='xlarge']:after { white-space: normal; width: 90vw; } } -.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length="fit"]:after { +.litespeed-wrap [aria-label][data-balloon-pos][data-balloon-length='fit']:after { white-space: normal; width: 100%; } diff --git a/assets/js/component.cdn.js b/assets/js/component.cdn.js index 36f275f8d..d186dc407 100644 --- a/assets/js/component.cdn.js +++ b/assets/js/component.cdn.js @@ -3,50 +3,51 @@ * @author Hai Zheng */ class CDNMapping extends React.Component { - constructor( props ) { - super( props ); + constructor(props) { + super(props); this.state = { - list: props.list + list: props.list, }; - this.onChange = this.onChange.bind( this ); - this.delRow = this.delRow.bind( this ); - this.addNew = this.addNew.bind( this ); + this.onChange = this.onChange.bind(this); + this.delRow = this.delRow.bind(this); + this.addNew = this.addNew.bind(this); } - onChange( e, index ) { + onChange(e, index) { const target = e.currentTarget; - const value = target.dataset.hasOwnProperty('value') ? Boolean(target.dataset.value*1) : target.value; + const value = target.dataset.hasOwnProperty('value') ? Boolean(target.dataset.value * 1) : target.value; const list = this.state.list; - list[ index ][ target.dataset.type ] = value; + list[index][target.dataset.type] = value; - this.setState( { - list: list - } ); + this.setState({ + list: list, + }); } - delRow( index ) { + delRow(index) { const data = this.state.list; - data.splice( index, 1 ); - this.setState( { list: data } ); + data.splice(index, 1); + this.setState({ list: data }); } addNew() { const list = this.state.list; - list.push( { url: '' } ); - this.setState( { list: list } ); + list.push({ url: '' }); + this.setState({ list: list }); } render() { return ( - { this.state.list.map( (item, i) => ( - - ) ) } + {this.state.list.map((item, i) => ( + + ))}

@@ -56,94 +57,114 @@ class CDNMapping extends React.Component { // { url: '', inc_img: true, inc_css: false, inc_js: false, filetype: [ '.aac', '.eot', ... ] } class CDNMappingBlock extends React.Component { - constructor( props ) { - super( props ); + constructor(props) { + super(props); - this.onChange = this.onChange.bind( this ); - this.delRow = this.delRow.bind( this ); + this.onChange = this.onChange.bind(this); + this.delRow = this.delRow.bind(this); } - onChange( e ) { - this.props.onChange( e, this.props.index ); + onChange(e) { + this.props.onChange(e, this.props.index); } delRow() { - this.props.delRow( this.props.index ); + this.props.delRow(this.props.index); } render() { - const name_prefix = litespeed_data[ 'ids' ][ 'cdn_mapping' ]; + const name_prefix = litespeed_data['ids']['cdn_mapping']; const item = this.props.item; - const filetype = item.filetype ? Array.isArray(item.filetype) ? item.filetype.join("\n") : item.filetype : ''; + const filetype = item.filetype ? (Array.isArray(item.filetype) ? item.filetype.join('\n') : item.filetype) : ''; return (
-
- - +
+ +
- +
-
- { litespeed_data[ 'lang' ][ 'cdn_mapping_inc_img' ] } -
-
- -
- - - +
{litespeed_data['lang']['cdn_mapping_inc_img']}
+
+ +
+ + +
-
- { litespeed_data[ 'lang' ][ 'cdn_mapping_inc_css' ] } -
-
- -
- - - +
{litespeed_data['lang']['cdn_mapping_inc_css']}
+
+ +
+ + +
-
- { litespeed_data[ 'lang' ][ 'cdn_mapping_inc_js' ] } -
-
- -
- - - +
{litespeed_data['lang']['cdn_mapping_inc_js']}
+
+ +
+ + +
- - "; + echo "'; $this->_check_overwritten($id); } @@ -960,10 +973,7 @@ public function build_switch($id, $title_list = false) echo '
'; if (!$title_list) { - $title_list = array( - __('OFF', 'litespeed-cache'), - __('ON', 'litespeed-cache'), - ); + $title_list = array(__('OFF', 'litespeed-cache'), __('ON', 'litespeed-cache')); } foreach ($title_list as $k => $v) { @@ -1083,7 +1093,7 @@ public function recommended($id) $val = "$val"; $val = __('Default value', 'litespeed-cache') . ': ' . $val; } - echo $val; + echo $val; } } @@ -1215,9 +1225,10 @@ protected function _api_env_var() $args = func_get_args(); $s = '' . implode(', ', $args) . ''; - echo ' ' - . __('API', 'litespeed-cache') . ': ' - . sprintf(__('Server variable(s) %s available to override this setting.', 'litespeed-cache'), $s); + echo ' ' . + __('API', 'litespeed-cache') . + ': ' . + sprintf(__('Server variable(s) %s available to override this setting.', 'litespeed-cache'), $s); Doc::learn_more('https://docs.litespeedtech.com/lscache/lscwp/admin/#limiting-the-crawler'); } @@ -1284,11 +1295,9 @@ public static function guidance($title, $steps, $current_step) $current_step = count($steps) + 1; } - $percentage = ' (' . floor(($current_step - 1) * 100 / count($steps)) . '%)'; + $percentage = ' (' . floor((($current_step - 1) * 100) / count($steps)) . '%)'; - $html = '
' - . '

' . $title . $percentage . '

' - . '
    '; + $html = '
    ' . '

    ' . $title . $percentage . '

    ' . '
      '; foreach ($steps as $k => $v) { $step = $k + 1; if ($current_step > $step) { diff --git a/src/admin-settings.cls.php b/src/admin-settings.cls.php index f2f57e326..4fda7c85c 100644 --- a/src/admin-settings.cls.php +++ b/src/admin-settings.cls.php @@ -12,7 +12,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Admin_Settings extends Base { @@ -44,7 +44,8 @@ public function save($raw_data) $child = false; // Drop array format if (strpos($id, '[') !== false) { - if (strpos($id, self::O_CDN_MAPPING) === 0 || strpos($id, self::O_CRAWLER_COOKIES) === 0) { // CDN child | Cookie Crawler settings + if (strpos($id, self::O_CDN_MAPPING) === 0 || strpos($id, self::O_CRAWLER_COOKIES) === 0) { + // CDN child | Cookie Crawler settings $child = substr($id, strpos($id, '[') + 1, strpos($id, ']') - strpos($id, '[') - 1); $id = substr($id, 0, strpos($id, '[')); // Drop ending []; Compatible with xx[0] way from CLI } else { @@ -58,21 +59,12 @@ public function save($raw_data) // Validate $child if ($id == self::O_CDN_MAPPING) { - if (!in_array($child, array( - self::CDN_MAPPING_URL, - self::CDN_MAPPING_INC_IMG, - self::CDN_MAPPING_INC_CSS, - self::CDN_MAPPING_INC_JS, - self::CDN_MAPPING_FILETYPE, - ))) { + if (!in_array($child, array(self::CDN_MAPPING_URL, self::CDN_MAPPING_INC_IMG, self::CDN_MAPPING_INC_CSS, self::CDN_MAPPING_INC_JS, self::CDN_MAPPING_FILETYPE))) { continue; } } if ($id == self::O_CRAWLER_COOKIES) { - if (!in_array($child, array( - self::CRWL_COOKIE_NAME, - self::CRWL_COOKIE_VALS, - ))) { + if (!in_array($child, array(self::CRWL_COOKIE_NAME, self::CRWL_COOKIE_VALS))) { continue; } } @@ -106,32 +98,30 @@ public function save($raw_data) * cdn-mapping[ 0 ][ url ] = 'xxx' * cdn-mapping[ 2 ][ url ] = 'xxx2' */ - if ($data) foreach ($data as $k => $v) { - if ($child == self::CDN_MAPPING_FILETYPE) { - $v = Utility::sanitize_lines($v); - } - if ($child == self::CDN_MAPPING_URL) { - # If not a valid URL, turn off CDN - if (strpos($v, 'https://') !== 0) { - self::debug('❌ CDN mapping set to OFF due to invalid URL'); - $the_matrix[self::O_CDN] = false; + if ($data) { + foreach ($data as $k => $v) { + if ($child == self::CDN_MAPPING_FILETYPE) { + $v = Utility::sanitize_lines($v); + } + if ($child == self::CDN_MAPPING_URL) { + # If not a valid URL, turn off CDN + if (strpos($v, 'https://') !== 0) { + self::debug('❌ CDN mapping set to OFF due to invalid URL'); + $the_matrix[self::O_CDN] = false; + } + $v = trailingslashit($v); + } + if (in_array($child, array(self::CDN_MAPPING_INC_IMG, self::CDN_MAPPING_INC_CSS, self::CDN_MAPPING_INC_JS))) { + // Because these can't be auto detected in `config->update()`, need to format here + $v = $v === 'false' ? 0 : (bool) $v; } - $v = trailingslashit($v); - } - if (in_array($child, array( - self::CDN_MAPPING_INC_IMG, - self::CDN_MAPPING_INC_CSS, - self::CDN_MAPPING_INC_JS, - ))) { - // Because these can't be auto detected in `config->update()`, need to format here - $v = $v === 'false' ? 0 : (bool) $v; - } - if (empty($data2[$k])) { - $data2[$k] = array(); - } + if (empty($data2[$k])) { + $data2[$k] = array(); + } - $data2[$k][$child] = $v; + $data2[$k][$child] = $v; + } } $data = $data2; @@ -154,22 +144,24 @@ public function save($raw_data) * * empty line for `vals` use literal `_null` */ - if ($data) foreach ($data as $k => $v) { - if ($child == self::CRWL_COOKIE_VALS) { - $v = Utility::sanitize_lines($v); - } + if ($data) { + foreach ($data as $k => $v) { + if ($child == self::CRWL_COOKIE_VALS) { + $v = Utility::sanitize_lines($v); + } - if (empty($data2[$k])) { - $data2[$k] = array(); - } + if (empty($data2[$k])) { + $data2[$k] = array(); + } - $data2[$k][$child] = $v; + $data2[$k][$child] = $v; + } } $data = $data2; break; - // Cache exclude cat + // Cache exclude cat case self::O_CACHE_EXC_CAT: $data2 = array(); $data = Utility::sanitize_lines($data); @@ -184,7 +176,7 @@ public function save($raw_data) $data = $data2; break; - // Cache exclude tag + // Cache exclude tag case self::O_CACHE_EXC_TAG: $data2 = array(); $data = Utility::sanitize_lines($data); @@ -234,7 +226,8 @@ public function save($raw_data) if ($id == self::O_CRAWLER_COOKIES) { $existed = array(); foreach ($the_matrix[$id] as $k => $v) { - if (!$v[self::CRWL_COOKIE_NAME] || in_array($v[self::CRWL_COOKIE_NAME], $existed)) { // Filter repeated or empty name + if (!$v[self::CRWL_COOKIE_NAME] || in_array($v[self::CRWL_COOKIE_NAME], $existed)) { + // Filter repeated or empty name unset($the_matrix[$id][$k]); continue; } @@ -248,12 +241,12 @@ public function save($raw_data) // tmp fix the 3rd part woo update hook issue when enabling vary cookie if ($id == 'wc_cart_vary') { - if ($data) + if ($data) { add_filter('litespeed_vary_cookies', function ($list) { $list[] = 'woocommerce_cart_hash'; return array_unique($list); }); - else { + } else { add_filter('litespeed_vary_cookies', function ($list) { if (in_array('woocommerce_cart_hash', $list)) { unset($list[array_search('woocommerce_cart_hash', $list)]); @@ -350,7 +343,8 @@ public static function validate_widget_save($instance, $new_instance, $old_insta return false; // invalid ttl. } - if (empty($instance[Conf::OPTION_NAME])) { // todo: to be removed + if (empty($instance[Conf::OPTION_NAME])) { + // todo: to be removed $instance[Conf::OPTION_NAME] = array(); } $instance[Conf::OPTION_NAME][ESI::WIDGET_O_ESIENABLE] = $esi; diff --git a/src/admin.cls.php b/src/admin.cls.php index 6627d96e0..542ee760d 100644 --- a/src/admin.cls.php +++ b/src/admin.cls.php @@ -10,9 +10,10 @@ */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class Admin extends Root { +class Admin extends Root +{ const LOG_TAG = '👮'; const PAGE_EDIT_HTACCESS = 'litespeed-edit-htaccess'; @@ -23,24 +24,24 @@ class Admin extends Root { * * @since 1.0.0 */ - public function __construct() { + public function __construct() + { // Define LSCWP_MU_PLUGIN if is mu-plugins - if ( defined( 'WPMU_PLUGIN_DIR' ) && dirname( LSCWP_DIR ) == WPMU_PLUGIN_DIR ) { - define( 'LSCWP_MU_PLUGIN', true ); + if (defined('WPMU_PLUGIN_DIR') && dirname(LSCWP_DIR) == WPMU_PLUGIN_DIR) { + define('LSCWP_MU_PLUGIN', true); } - self::debug( 'No cache due to Admin page' ); - defined( 'DONOTCACHEPAGE' ) || define( 'DONOTCACHEPAGE', true ); + self::debug('No cache due to Admin page'); + defined('DONOTCACHEPAGE') || define('DONOTCACHEPAGE', true); // Additional litespeed assets on admin display // Also register menu - $this->cls( 'Admin_Display' ); + $this->cls('Admin_Display'); // initialize admin actions - add_action( 'admin_init', array( $this, 'admin_init' ) ); + add_action('admin_init', array($this, 'admin_init')); // add link to plugin list page - add_filter( 'plugin_action_links_' . LSCWP_BASENAME, array( $this->cls( 'Admin_Display' ), 'add_plugin_links' ) ); - + add_filter('plugin_action_links_' . LSCWP_BASENAME, array($this->cls('Admin_Display'), 'add_plugin_links')); } /** @@ -49,22 +50,22 @@ public function __construct() { * @since 1.0.0 * @access public */ - public function admin_init() { + public function admin_init() + { // Hook attachment upload - if ( $this->conf( Base::O_IMG_OPTM_AUTO ) ) { - add_filter( 'wp_update_attachment_metadata', array( $this, 'wp_update_attachment_metadata' ), 9999, 2 ); + if ($this->conf(Base::O_IMG_OPTM_AUTO)) { + add_filter('wp_update_attachment_metadata', array($this, 'wp_update_attachment_metadata'), 9999, 2); } $this->_proceed_admin_action(); // Terminate if user doesn't have the access to settings - if( is_network_admin() ) { + if (is_network_admin()) { $capability = 'manage_network_options'; - } - else { + } else { $capability = 'manage_options'; } - if ( ! current_user_can($capability) ) { + if (!current_user_can($capability)) { return; } @@ -73,17 +74,17 @@ public function admin_init() { // Add privacy policy // @since 2.2.6 - if ( function_exists( 'wp_add_privacy_policy_content' ) ) { - wp_add_privacy_policy_content( Core::NAME, Doc::privacy_policy() ); + if (function_exists('wp_add_privacy_policy_content')) { + wp_add_privacy_policy_content(Core::NAME, Doc::privacy_policy()); } - $this->cls( 'Media' )->after_admin_init(); + $this->cls('Media')->after_admin_init(); - do_action( 'litspeed_after_admin_init' ); + do_action('litspeed_after_admin_init'); - if ( $this->cls( 'Router' )->esi_enabled() ) { - add_action( 'in_widget_form', array( $this->cls( 'Admin_Display' ), 'show_widget_edit' ), 100, 3 ); - add_filter( 'widget_update_callback', __NAMESPACE__ . '\Admin_Settings::validate_widget_save', 10, 4 ); + if ($this->cls('Router')->esi_enabled()) { + add_action('in_widget_form', array($this->cls('Admin_Display'), 'show_widget_edit'), 100, 3); + add_filter('widget_update_callback', __NAMESPACE__ . '\Admin_Settings::validate_widget_save', 10, 4); } } @@ -91,8 +92,9 @@ public function admin_init() { * Handle attachment update * @since 4.0 */ - public function wp_update_attachment_metadata( $data, $post_id ) { - $this->cls( 'Img_Optm' )->wp_update_attachment_metadata( $data, $post_id ); + public function wp_update_attachment_metadata($data, $post_id) + { + $this->cls('Img_Optm')->wp_update_attachment_metadata($data, $post_id); return $data; } @@ -101,23 +103,22 @@ public function wp_update_attachment_metadata( $data, $post_id ) { * * @since 1.1.0 */ - private function _proceed_admin_action() { + private function _proceed_admin_action() + { // handle actions - switch ( Router::get_action() ) { + switch (Router::get_action()) { case Router::ACTION_SAVE_SETTINGS: - $this->cls( 'Admin_Settings' )->save( $_POST ); + $this->cls('Admin_Settings')->save($_POST); break; - // Save network settings case Router::ACTION_SAVE_SETTINGS_NETWORK: - $this->cls( 'Admin_Settings' )->network_save( $_POST ); + $this->cls('Admin_Settings')->network_save($_POST); break; default: break; } - } /** @@ -128,12 +129,13 @@ private function _proceed_admin_action() { * @param string $input The input string to clean. * @return string The cleaned up input. */ - public static function cleanup_text( $input ) { - if ( is_array( $input ) ) { - return array_map( __CLASS__ . '::cleanup_text', $input ); + public static function cleanup_text($input) + { + if (is_array($input)) { + return array_map(__CLASS__ . '::cleanup_text', $input); } - return stripslashes( trim( $input ) ); + return stripslashes(trim($input)); } /** @@ -146,42 +148,42 @@ public static function cleanup_text( $input ) { * @access public * @global string $pagenow */ - public static function redirect( $url = false ) { + public static function redirect($url = false) + { global $pagenow; - if ( ! empty( $_GET[ '_litespeed_ori' ] ) ) { - wp_safe_redirect( wp_get_referer() ?: get_home_url() ); - exit; + if (!empty($_GET['_litespeed_ori'])) { + wp_safe_redirect(wp_get_referer() ?: get_home_url()); + exit(); } $qs = ''; - if ( ! $url ) { - if ( ! empty( $_GET ) ) { - if ( isset( $_GET[ Router::ACTION ] ) ) { - unset( $_GET[ Router::ACTION ] ); + if (!$url) { + if (!empty($_GET)) { + if (isset($_GET[Router::ACTION])) { + unset($_GET[Router::ACTION]); } - if ( isset( $_GET[ Router::NONCE ] ) ) { - unset( $_GET[ Router::NONCE ] ); + if (isset($_GET[Router::NONCE])) { + unset($_GET[Router::NONCE]); } - if ( isset( $_GET[ Router::TYPE ] ) ) { - unset( $_GET[ Router::TYPE ] ); + if (isset($_GET[Router::TYPE])) { + unset($_GET[Router::TYPE]); } - if ( isset( $_GET[ 'litespeed_i' ] ) ) { - unset( $_GET[ 'litespeed_i' ] ); + if (isset($_GET['litespeed_i'])) { + unset($_GET['litespeed_i']); } - if ( ! empty( $_GET ) ) { - $qs = '?' . http_build_query( $_GET ); + if (!empty($_GET)) { + $qs = '?' . http_build_query($_GET); } } - if ( is_network_admin() ) { - $url = network_admin_url( $pagenow . $qs ); - } - else { - $url = admin_url( $pagenow . $qs ); + if (is_network_admin()) { + $url = network_admin_url($pagenow . $qs); + } else { + $url = admin_url($pagenow . $qs); } } - wp_redirect( $url ); - exit; + wp_redirect($url); + exit(); } } diff --git a/src/api.cls.php b/src/api.cls.php index 728ec303f..ad44a8a01 100644 --- a/src/api.cls.php +++ b/src/api.cls.php @@ -10,37 +10,39 @@ */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; - -class API extends Base { - const VERSION = Core::VER; - - const TYPE_FEED = Tag::TYPE_FEED ; - const TYPE_FRONTPAGE = Tag::TYPE_FRONTPAGE ; - const TYPE_HOME = Tag::TYPE_HOME ; - const TYPE_PAGES = Tag::TYPE_PAGES ; - const TYPE_PAGES_WITH_RECENT_POSTS = Tag::TYPE_PAGES_WITH_RECENT_POSTS ; - const TYPE_HTTP = Tag::TYPE_HTTP ; - const TYPE_ARCHIVE_POSTTYPE = Tag::TYPE_ARCHIVE_POSTTYPE ; - const TYPE_ARCHIVE_TERM = Tag::TYPE_ARCHIVE_TERM ; - const TYPE_AUTHOR = Tag::TYPE_AUTHOR ; - const TYPE_ARCHIVE_DATE = Tag::TYPE_ARCHIVE_DATE ; - const TYPE_BLOG = Tag::TYPE_BLOG ; - const TYPE_LOGIN = Tag::TYPE_LOGIN ; - const TYPE_URL = Tag::TYPE_URL ; - - const TYPE_ESI = Tag::TYPE_ESI ; - - const PARAM_NAME = ESI::PARAM_NAME ; - const WIDGET_O_ESIENABLE = ESI::WIDGET_O_ESIENABLE ; - const WIDGET_O_TTL = ESI::WIDGET_O_TTL ; +defined('WPINC') || exit(); + +class API extends Base +{ + const VERSION = Core::VER; + + const TYPE_FEED = Tag::TYPE_FEED; + const TYPE_FRONTPAGE = Tag::TYPE_FRONTPAGE; + const TYPE_HOME = Tag::TYPE_HOME; + const TYPE_PAGES = Tag::TYPE_PAGES; + const TYPE_PAGES_WITH_RECENT_POSTS = Tag::TYPE_PAGES_WITH_RECENT_POSTS; + const TYPE_HTTP = Tag::TYPE_HTTP; + const TYPE_ARCHIVE_POSTTYPE = Tag::TYPE_ARCHIVE_POSTTYPE; + const TYPE_ARCHIVE_TERM = Tag::TYPE_ARCHIVE_TERM; + const TYPE_AUTHOR = Tag::TYPE_AUTHOR; + const TYPE_ARCHIVE_DATE = Tag::TYPE_ARCHIVE_DATE; + const TYPE_BLOG = Tag::TYPE_BLOG; + const TYPE_LOGIN = Tag::TYPE_LOGIN; + const TYPE_URL = Tag::TYPE_URL; + + const TYPE_ESI = Tag::TYPE_ESI; + + const PARAM_NAME = ESI::PARAM_NAME; + const WIDGET_O_ESIENABLE = ESI::WIDGET_O_ESIENABLE; + const WIDGET_O_TTL = ESI::WIDGET_O_TTL; /** * Instance * * @since 3.0 */ - public function __construct() { + public function __construct() + { } /** @@ -50,7 +52,8 @@ public function __construct() { * * @since 3.0 */ - public function init() { + public function init() + { /** * Init */ @@ -59,110 +62,110 @@ public function init() { /** * Conf */ - add_filter( 'litespeed_conf', array( $this, 'conf' ) ); // @previous API::config($id) + add_filter('litespeed_conf', array($this, 'conf')); // @previous API::config($id) // Action `litespeed_conf_append` // @previous API::conf_append( $name, $default ) - add_action( 'litespeed_conf_multi_switch', __NAMESPACE__ . '\Base::set_multi_switch', 10, 2 ); + add_action('litespeed_conf_multi_switch', __NAMESPACE__ . '\Base::set_multi_switch', 10, 2); // Action ``litespeed_conf_force` // @previous API::force_option( $k, $v ) /** * Cache Control Hooks */ // Action `litespeed_control_finalize` // @previous API::hook_control($tags) && action `litespeed_api_control` - add_action( 'litespeed_control_set_private', __NAMESPACE__ . '\Control::set_private' ); // @previous API::set_cache_private() - add_action( 'litespeed_control_set_nocache', __NAMESPACE__ . '\Control::set_nocache' ); // @previous API::set_nocache( $reason = false ) - add_action( 'litespeed_control_set_cacheable', array( $this, 'set_cacheable' ) ); // Might needed if not call hook `wp` // @previous API::set_cacheable( $reason ) - add_action( 'litespeed_control_force_cacheable', __NAMESPACE__ . '\Control::force_cacheable' ); // Set cache status to force cacheable ( Will ignore most kinds of non-cacheable conditions ) // @previous API::set_force_cacheable( $reason ) - add_action( 'litespeed_control_force_public', __NAMESPACE__ . '\Control::set_public_forced' ); // Set cache to force public cache if cacheable ( Will ignore most kinds of non-cacheable conditions ) // @previous API::set_force_public( $reason ) - add_filter( 'litespeed_control_cacheable', __NAMESPACE__ . '\Control::is_cacheable', 3 ); // Note: Read-Only. Directly append to this filter won't work. Call actions above to set cacheable or not // @previous API::not_cacheable() - add_action( 'litespeed_control_set_ttl', __NAMESPACE__ . '\Control::set_custom_ttl', 10, 2 ); // @previous API::set_ttl( $val ) - add_filter( 'litespeed_control_ttl', array( $this, 'get_ttl' ), 3 ); // @previous API::get_ttl() + add_action('litespeed_control_set_private', __NAMESPACE__ . '\Control::set_private'); // @previous API::set_cache_private() + add_action('litespeed_control_set_nocache', __NAMESPACE__ . '\Control::set_nocache'); // @previous API::set_nocache( $reason = false ) + add_action('litespeed_control_set_cacheable', array($this, 'set_cacheable')); // Might needed if not call hook `wp` // @previous API::set_cacheable( $reason ) + add_action('litespeed_control_force_cacheable', __NAMESPACE__ . '\Control::force_cacheable'); // Set cache status to force cacheable ( Will ignore most kinds of non-cacheable conditions ) // @previous API::set_force_cacheable( $reason ) + add_action('litespeed_control_force_public', __NAMESPACE__ . '\Control::set_public_forced'); // Set cache to force public cache if cacheable ( Will ignore most kinds of non-cacheable conditions ) // @previous API::set_force_public( $reason ) + add_filter('litespeed_control_cacheable', __NAMESPACE__ . '\Control::is_cacheable', 3); // Note: Read-Only. Directly append to this filter won't work. Call actions above to set cacheable or not // @previous API::not_cacheable() + add_action('litespeed_control_set_ttl', __NAMESPACE__ . '\Control::set_custom_ttl', 10, 2); // @previous API::set_ttl( $val ) + add_filter('litespeed_control_ttl', array($this, 'get_ttl'), 3); // @previous API::get_ttl() /** * Tag Hooks */ // Action `litespeed_tag_finalize` // @previous API::hook_tag( $hook ) - add_action( 'litespeed_tag', __NAMESPACE__ . '\Tag::add' ); // Shorter alias of `litespeed_tag_add` - add_action( 'litespeed_tag_post', __NAMESPACE__ . '\Tag::add_post' ); // Shorter alias of `litespeed_tag_add_post` - add_action( 'litespeed_tag_widget', __NAMESPACE__ . '\Tag::add_widget' ); // Shorter alias of `litespeed_tag_add_widget` - add_action( 'litespeed_tag_private', __NAMESPACE__ . '\Tag::add_private' ); // Shorter alias of `litespeed_tag_add_private` - add_action( 'litespeed_tag_private_esi', __NAMESPACE__ . '\Tag::add_private_esi' ); // Shorter alias of `litespeed_tag_add_private_esi` - - add_action( 'litespeed_tag_add', __NAMESPACE__ . '\Tag::add' ); // @previous API::tag_add( $tag ) - add_action( 'litespeed_tag_add_post', __NAMESPACE__ . '\Tag::add_post' ); - add_action( 'litespeed_tag_add_widget', __NAMESPACE__ . '\Tag::add_widget' ); - add_action( 'litespeed_tag_add_private', __NAMESPACE__ . '\Tag::add_private' ); // @previous API::tag_add_private( $tags ) - add_action( 'litespeed_tag_add_private_esi', __NAMESPACE__ . '\Tag::add_private_esi' ); + add_action('litespeed_tag', __NAMESPACE__ . '\Tag::add'); // Shorter alias of `litespeed_tag_add` + add_action('litespeed_tag_post', __NAMESPACE__ . '\Tag::add_post'); // Shorter alias of `litespeed_tag_add_post` + add_action('litespeed_tag_widget', __NAMESPACE__ . '\Tag::add_widget'); // Shorter alias of `litespeed_tag_add_widget` + add_action('litespeed_tag_private', __NAMESPACE__ . '\Tag::add_private'); // Shorter alias of `litespeed_tag_add_private` + add_action('litespeed_tag_private_esi', __NAMESPACE__ . '\Tag::add_private_esi'); // Shorter alias of `litespeed_tag_add_private_esi` + + add_action('litespeed_tag_add', __NAMESPACE__ . '\Tag::add'); // @previous API::tag_add( $tag ) + add_action('litespeed_tag_add_post', __NAMESPACE__ . '\Tag::add_post'); + add_action('litespeed_tag_add_widget', __NAMESPACE__ . '\Tag::add_widget'); + add_action('litespeed_tag_add_private', __NAMESPACE__ . '\Tag::add_private'); // @previous API::tag_add_private( $tags ) + add_action('litespeed_tag_add_private_esi', __NAMESPACE__ . '\Tag::add_private_esi'); /** * Purge Hooks */ // Action `litespeed_purge_finalize` // @previous API::hook_purge($tags) - add_action( 'litespeed_purge', __NAMESPACE__ . '\Purge::add' ); // @previous API::purge($tags) - add_action( 'litespeed_purge_all', __NAMESPACE__ . '\Purge::purge_all' ); - add_action( 'litespeed_purge_post', array( $this, 'purge_post' ) ); // @previous API::purge_post( $pid ) - add_action( 'litespeed_purge_posttype', __NAMESPACE__ . '\Purge::purge_posttype' ); - add_action( 'litespeed_purge_url', array( $this, 'purge_url' ) ); - add_action( 'litespeed_purge_widget', __NAMESPACE__ . '\Purge::purge_widget' ); - add_action( 'litespeed_purge_esi', __NAMESPACE__ . '\Purge::purge_esi' ); - add_action( 'litespeed_purge_private', __NAMESPACE__ . '\Purge::add_private' ); // @previous API::purge_private( $tags ) - add_action( 'litespeed_purge_private_esi', __NAMESPACE__ . '\Purge::add_private_esi' ); - add_action( 'litespeed_purge_private_all', __NAMESPACE__ . '\Purge::add_private_all' ); // @previous API::purge_private_all() + add_action('litespeed_purge', __NAMESPACE__ . '\Purge::add'); // @previous API::purge($tags) + add_action('litespeed_purge_all', __NAMESPACE__ . '\Purge::purge_all'); + add_action('litespeed_purge_post', array($this, 'purge_post')); // @previous API::purge_post( $pid ) + add_action('litespeed_purge_posttype', __NAMESPACE__ . '\Purge::purge_posttype'); + add_action('litespeed_purge_url', array($this, 'purge_url')); + add_action('litespeed_purge_widget', __NAMESPACE__ . '\Purge::purge_widget'); + add_action('litespeed_purge_esi', __NAMESPACE__ . '\Purge::purge_esi'); + add_action('litespeed_purge_private', __NAMESPACE__ . '\Purge::add_private'); // @previous API::purge_private( $tags ) + add_action('litespeed_purge_private_esi', __NAMESPACE__ . '\Purge::add_private_esi'); + add_action('litespeed_purge_private_all', __NAMESPACE__ . '\Purge::add_private_all'); // @previous API::purge_private_all() // Action `litespeed_api_purge_post` // Triggered when purge a post // @previous API::hook_purge_post($hook) // Action `litespeed_purged_all` // Triggered after purged all. - add_action( 'litespeed_purge_all_object', __NAMESPACE__ . '\Purge::purge_all_object' ); - add_action( 'litespeed_purge_ucss', __NAMESPACE__ . '\Purge::purge_ucss' ); + add_action('litespeed_purge_all_object', __NAMESPACE__ . '\Purge::purge_all_object'); + add_action('litespeed_purge_ucss', __NAMESPACE__ . '\Purge::purge_ucss'); /** * ESI */ // Action `litespeed_nonce` // @previous API::nonce_action( $action ) & API::nonce( $action = -1, $defence_for_html_filter = true ) // NOTE: only available after `init` hook - add_filter( 'litespeed_esi_status', array( $this, 'esi_enabled' ) ); // Get ESI enable status // @previous API::esi_enabled() - add_filter( 'litespeed_esi_url', array( $this, 'sub_esi_block' ), 10, 8 ); // Generate ESI block url // @previous API::esi_url( $block_id, $wrapper, $params = array(), $control = 'private,no-vary', $silence = false, $preserved = false, $svar = false, $inline_val = false ) + add_filter('litespeed_esi_status', array($this, 'esi_enabled')); // Get ESI enable status // @previous API::esi_enabled() + add_filter('litespeed_esi_url', array($this, 'sub_esi_block'), 10, 8); // Generate ESI block url // @previous API::esi_url( $block_id, $wrapper, $params = array(), $control = 'private,no-vary', $silence = false, $preserved = false, $svar = false, $inline_val = false ) // Filter `litespeed_widget_default_options` // Hook widget default settings value. Currently used in Woo 3rd // @previous API::hook_widget_default_options( $hook ) // Filter `litespeed_esi_params` // @previous API::hook_esi_param( $hook ) // Action `litespeed_tpl_normal` // @previous API::hook_tpl_not_esi($hook) && Action `litespeed_is_not_esi_template` // Action `litespeed_esi_load-$block` // @usage add_action( 'litespeed_esi_load-' . $block, $hook ) // @previous API::hook_tpl_esi($block, $hook) - add_action( 'litespeed_esi_combine', __NAMESPACE__ . '\ESI::combine' ); + add_action('litespeed_esi_combine', __NAMESPACE__ . '\ESI::combine'); /** * Vary * * To modify default vary, There are two ways: Action `litespeed_vary_append` or Filter `litespeed_vary` */ - add_action( 'litespeed_vary_ajax_force', __NAMESPACE__ . '\Vary::can_ajax_vary' ); // API::force_vary() -> Action `litespeed_vary_ajax_force` // Force finalize vary even if its in an AJAX call + add_action('litespeed_vary_ajax_force', __NAMESPACE__ . '\Vary::can_ajax_vary'); // API::force_vary() -> Action `litespeed_vary_ajax_force` // Force finalize vary even if its in an AJAX call // Filter `litespeed_vary_curr_cookies` to generate current in use vary, which will be used for response vary header. // Filter `litespeed_vary_cookies` to register the final vary cookies, which will be written to rewrite rule. (litespeed_vary_curr_cookies are always equal to or less than litespeed_vary_cookies) // Filter `litespeed_vary` // Previous API::hook_vary_finalize( $hook ) - add_action( 'litespeed_vary_no', __NAMESPACE__ . '\Control::set_no_vary' ); // API::set_cache_no_vary() -> Action `litespeed_vary_no` // Set cache status to no vary + add_action('litespeed_vary_no', __NAMESPACE__ . '\Control::set_no_vary'); // API::set_cache_no_vary() -> Action `litespeed_vary_no` // Set cache status to no vary // add_filter( 'litespeed_is_mobile', __NAMESPACE__ . '\Control::is_mobile' ); // API::set_mobile() -> Filter `litespeed_is_mobile` /** * Cloud */ - add_filter( 'litespeed_is_from_cloud', array( $this, 'is_from_cloud' ) ); // Check if current request is from QC (usally its to check REST access) // @see https://wordpress.org/support/topic/image-optimization-not-working-3/ + add_filter('litespeed_is_from_cloud', array($this, 'is_from_cloud')); // Check if current request is from QC (usally its to check REST access) // @see https://wordpress.org/support/topic/image-optimization-not-working-3/ /** * Media */ - add_action( 'litespeed_media_reset', __NAMESPACE__ . '\Media::delete_attachment' ); // Reset one media row + add_action('litespeed_media_reset', __NAMESPACE__ . '\Media::delete_attachment'); // Reset one media row /** * GUI */ // API::clean_wrapper_begin( $counter = false ) -> Filter `litespeed_clean_wrapper_begin` // Start a to-be-removed html wrapper - add_filter( 'litespeed_clean_wrapper_begin', __NAMESPACE__ . '\GUI::clean_wrapper_begin' ); + add_filter('litespeed_clean_wrapper_begin', __NAMESPACE__ . '\GUI::clean_wrapper_begin'); // API::clean_wrapper_end( $counter = false ) -> Filter `litespeed_clean_wrapper_end` // End a to-be-removed html wrapper - add_filter( 'litespeed_clean_wrapper_end', __NAMESPACE__ . '\GUI::clean_wrapper_end' ); + add_filter('litespeed_clean_wrapper_end', __NAMESPACE__ . '\GUI::clean_wrapper_end'); /** * Mist */ - add_action( 'litespeed_debug', __NAMESPACE__ . '\Debug2::debug', 10, 2 ); // API::debug()-> Action `litespeed_debug` - add_action( 'litespeed_debug2', __NAMESPACE__ . '\Debug2::debug2', 10, 2 ); // API::debug2()-> Action `litespeed_debug2` - add_action( 'litespeed_disable_all', array( $this, '_disable_all' ) ); // API::disable_all( $reason ) -> Action `litespeed_disable_all` + add_action('litespeed_debug', __NAMESPACE__ . '\Debug2::debug', 10, 2); // API::debug()-> Action `litespeed_debug` + add_action('litespeed_debug2', __NAMESPACE__ . '\Debug2::debug2', 10, 2); // API::debug2()-> Action `litespeed_debug2` + add_action('litespeed_disable_all', array($this, '_disable_all')); // API::disable_all( $reason ) -> Action `litespeed_disable_all` - add_action( 'litspeed_after_admin_init', array( $this, '_after_admin_init' ) ); + add_action('litspeed_after_admin_init', array($this, '_after_admin_init')); } /** @@ -171,12 +174,13 @@ public function init() { * @since 3.0 * @access public */ - public function _after_admin_init() { + public function _after_admin_init() + { /** * GUI */ - add_action( 'litespeed_setting_enroll', array( $this->cls( 'Admin_Display' ), 'enroll' ), 10, 4 ); // API::enroll( $id ) // Register a field in setting form to save - add_action( 'litespeed_build_switch', array( $this->cls( 'Admin_Display' ), 'build_switch' ) ); // API::build_switch( $id ) // Build a switch div html snippet + add_action('litespeed_setting_enroll', array($this->cls('Admin_Display'), 'enroll'), 10, 4); // API::enroll( $id ) // Register a field in setting form to save + add_action('litespeed_build_switch', array($this->cls('Admin_Display'), 'build_switch')); // API::build_switch( $id ) // Build a switch div html snippet // API::hook_setting_content( $hook, $priority = 10, $args = 1 ) -> Action `litespeed_settings_content` // API::hook_setting_tab( $hook, $priority = 10, $args = 1 ) -> Action `litespeed_settings_tab` } @@ -187,17 +191,19 @@ public function _after_admin_init() { * @since 2.9.7.2 * @access public */ - public function _disable_all( $reason ) { - do_action( 'litespeed_debug', '[API] Disabled_all due to ' . $reason ); + public function _disable_all($reason) + { + do_action('litespeed_debug', '[API] Disabled_all due to ' . $reason); - ! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true ); + !defined('LITESPEED_DISABLE_ALL') && define('LITESPEED_DISABLE_ALL', true); } /** * @since 3.0 */ - public static function vary_append_commenter() { - Vary::cls()->append_commenter() ; + public static function vary_append_commenter() + { + Vary::cls()->append_commenter(); } /** @@ -205,32 +211,46 @@ public static function vary_append_commenter() { * * @since 4.2 */ - public function is_from_cloud() { - return $this->cls( 'Cloud' )->is_from_cloud(); + public function is_from_cloud() + { + return $this->cls('Cloud')->is_from_cloud(); } - public function purge_post( $pid ) { - $this->cls( 'Purge' )->purge_post( $pid ); + public function purge_post($pid) + { + $this->cls('Purge')->purge_post($pid); } - public function purge_url( $url ) { - $this->cls( 'Purge' )->purge_url( $url ); + public function purge_url($url) + { + $this->cls('Purge')->purge_url($url); } - public function set_cacheable( $reason = false ) { - $this->cls( 'Control' )->set_cacheable( $reason ); + public function set_cacheable($reason = false) + { + $this->cls('Control')->set_cacheable($reason); } - public function esi_enabled() { - return $this->cls( 'Router' )->esi_enabled(); + public function esi_enabled() + { + return $this->cls('Router')->esi_enabled(); } - public function get_ttl() { - return $this->cls( 'Control' )->get_ttl(); + public function get_ttl() + { + return $this->cls('Control')->get_ttl(); } - public function sub_esi_block( $block_id, $wrapper, $params = array(), $control = 'private,no-vary', $silence = false, $preserved = false, $svar = false, $inline_param = array() ) { - return $this->cls( 'ESI' )->sub_esi_block( $block_id, $wrapper, $params, $control, $silence, $preserved, $svar, $inline_param ); + public function sub_esi_block( + $block_id, + $wrapper, + $params = array(), + $control = 'private,no-vary', + $silence = false, + $preserved = false, + $svar = false, + $inline_param = array() + ) { + return $this->cls('ESI')->sub_esi_block($block_id, $wrapper, $params, $control, $silence, $preserved, $svar, $inline_param); } - } diff --git a/src/avatar.cls.php b/src/avatar.cls.php index 621dfd1da..5ddc6a1c4 100644 --- a/src/avatar.cls.php +++ b/src/avatar.cls.php @@ -9,9 +9,10 @@ */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class Avatar extends Base { +class Avatar extends Base +{ const TYPE_GENERATE = 'generate'; private $_conf_cache_ttl; @@ -25,18 +26,19 @@ class Avatar extends Base { * * @since 1.4 */ - public function __construct() { - if ( ! $this->conf( self::O_DISCUSS_AVATAR_CACHE ) ) { + public function __construct() + { + if (!$this->conf(self::O_DISCUSS_AVATAR_CACHE)) { return; } - Debug2::debug2( '[Avatar] init' ); + Debug2::debug2('[Avatar] init'); - $this->_tb = $this->cls( 'Data' )->tb( 'avatar' ); + $this->_tb = $this->cls('Data')->tb('avatar'); - $this->_conf_cache_ttl = $this->conf( self::O_DISCUSS_AVATAR_CACHE_TTL ); + $this->_conf_cache_ttl = $this->conf(self::O_DISCUSS_AVATAR_CACHE_TTL); - add_filter( 'get_avatar_url', array( $this, 'crawl_avatar' ) ); + add_filter('get_avatar_url', array($this, 'crawl_avatar')); $this->_summary = self::get_summary(); } @@ -47,8 +49,9 @@ public function __construct() { * @since 3.0 * @access public */ - public function need_db() { - if ( $this->conf( self::O_DISCUSS_AVATAR_CACHE ) ) { + public function need_db() + { + if ($this->conf(self::O_DISCUSS_AVATAR_CACHE)) { return true; } @@ -60,28 +63,29 @@ public function need_db() { * @since 3.0 * @access public */ - public function serve_static( $md5 ) { + public function serve_static($md5) + { global $wpdb; - Debug2::debug( '[Avatar] is avatar request' ); + Debug2::debug('[Avatar] is avatar request'); - if ( strlen( $md5 ) !== 32 ) { - Debug2::debug( '[Avatar] wrong md5 ' . $md5 ); + if (strlen($md5) !== 32) { + Debug2::debug('[Avatar] wrong md5 ' . $md5); return; } $q = "SELECT url FROM `$this->_tb` WHERE md5=%s"; - $url = $wpdb->get_var( $wpdb->prepare( $q, $md5 ) ); + $url = $wpdb->get_var($wpdb->prepare($q, $md5)); - if ( ! $url ) { - Debug2::debug( '[Avatar] no matched url for md5 ' . $md5 ); + if (!$url) { + Debug2::debug('[Avatar] no matched url for md5 ' . $md5); return; } - $url = $this->_generate( $url ); + $url = $this->_generate($url); - wp_redirect( $url ); - exit; + wp_redirect($url); + exit(); } /** @@ -90,38 +94,39 @@ public function serve_static( $md5 ) { * @since 3.0 * @access public */ - public function crawl_avatar( $url ) { - if ( ! $url ) { + public function crawl_avatar($url) + { + if (!$url) { return $url; } // Check if its already in dict or not - if ( ! empty( $this->_avatar_realtime_gen_dict[ $url ] ) ) { - Debug2::debug2( '[Avatar] already in dict [url] ' . $url ); + if (!empty($this->_avatar_realtime_gen_dict[$url])) { + Debug2::debug2('[Avatar] already in dict [url] ' . $url); - return $this->_avatar_realtime_gen_dict[ $url ]; + return $this->_avatar_realtime_gen_dict[$url]; } - $realpath = $this->_realpath( $url ); - if ( file_exists( $realpath ) && time() - filemtime( $realpath ) <= $this->_conf_cache_ttl ) { - Debug2::debug2( '[Avatar] cache file exists [url] ' . $url ); - return $this->_rewrite( $url, filemtime( $realpath ) ); + $realpath = $this->_realpath($url); + if (file_exists($realpath) && time() - filemtime($realpath) <= $this->_conf_cache_ttl) { + Debug2::debug2('[Avatar] cache file exists [url] ' . $url); + return $this->_rewrite($url, filemtime($realpath)); } - if ( ! strpos( $url, 'gravatar.com' ) ) { + if (!strpos($url, 'gravatar.com')) { return $url; } // Send request - if ( ! empty( $this->_summary[ 'curr_request' ] ) && time() - $this->_summary[ 'curr_request' ] < 300 ) { - Debug2::debug2( '[Avatar] Bypass generating due to interval limit [url] ' . $url ); + if (!empty($this->_summary['curr_request']) && time() - $this->_summary['curr_request'] < 300) { + Debug2::debug2('[Avatar] Bypass generating due to interval limit [url] ' . $url); return $url; } // Generate immediately - $this->_avatar_realtime_gen_dict[ $url ] = $this->_generate( $url ); + $this->_avatar_realtime_gen_dict[$url] = $this->_generate($url); - return $this->_avatar_realtime_gen_dict[ $url ]; + return $this->_avatar_realtime_gen_dict[$url]; } /** @@ -130,16 +135,17 @@ public function crawl_avatar( $url ) { * @since 3.0 * @access public */ - public function queue_count() { + public function queue_count() + { global $wpdb; // If var not exists, mean table not exists // todo: not true - if ( ! $this->_tb ) { + if (!$this->_tb) { return false; } - $q = "SELECT COUNT(*) FROM `$this->_tb` WHERE dateline<" . ( time() - $this->_conf_cache_ttl ); - return $wpdb->get_var( $q ); + $q = "SELECT COUNT(*) FROM `$this->_tb` WHERE dateline<" . (time() - $this->_conf_cache_ttl); + return $wpdb->get_var($q); } /** @@ -149,8 +155,9 @@ public function queue_count() { * * @since 3.0 */ - private function _rewrite( $url, $time = null ) { - return LITESPEED_STATIC_URL . '/avatar/' . $this->_filepath( $url ) . ( $time ? '?ver=' . $time : '' ); + private function _rewrite($url, $time = null) + { + return LITESPEED_STATIC_URL . '/avatar/' . $this->_filepath($url) . ($time ? '?ver=' . $time : ''); } /** @@ -159,8 +166,9 @@ private function _rewrite( $url, $time = null ) { * @since 3.0 * @access private */ - private function _realpath( $url ) { - return LITESPEED_STATIC_DIR . '/avatar/' . $this->_filepath( $url ); + private function _realpath($url) + { + return LITESPEED_STATIC_DIR . '/avatar/' . $this->_filepath($url); } /** @@ -168,9 +176,10 @@ private function _realpath( $url ) { * * @since 4.0 */ - private function _filepath( $url ) { - $filename = md5( $url ) . '.jpg'; - if ( is_multisite() ) { + private function _filepath($url) + { + $filename = md5($url) . '.jpg'; + if (is_multisite()) { $filename = get_current_blog_id() . '/' . $filename; } return $filename; @@ -182,33 +191,34 @@ private function _filepath( $url ) { * @since 3.0 * @access public */ - public static function cron( $force = false ) { + public static function cron($force = false) + { global $wpdb; $_instance = self::cls(); - if ( ! $_instance->queue_count() ) { - Debug2::debug( '[Avatar] no queue' ); + if (!$_instance->queue_count()) { + Debug2::debug('[Avatar] no queue'); return; } // For cron, need to check request interval too - if ( ! $force ) { - if ( ! empty( $_instance->_summary[ 'curr_request' ] ) && time() - $_instance->_summary[ 'curr_request' ] < 300 ) { - Debug2::debug( '[Avatar] curr_request too close' ); + if (!$force) { + if (!empty($_instance->_summary['curr_request']) && time() - $_instance->_summary['curr_request'] < 300) { + Debug2::debug('[Avatar] curr_request too close'); return; } } $q = "SELECT url FROM `$_instance->_tb` WHERE dateline < %d ORDER BY id DESC LIMIT %d"; - $q = $wpdb->prepare( $q, array( time() - $_instance->_conf_cache_ttl, apply_filters( 'litespeed_avatar_limit', 30 ) ) ); + $q = $wpdb->prepare($q, array(time() - $_instance->_conf_cache_ttl, apply_filters('litespeed_avatar_limit', 30))); - $list = $wpdb->get_results( $q ); - Debug2::debug( '[Avatar] cron job [count] ' . count( $list ) ); + $list = $wpdb->get_results($q); + Debug2::debug('[Avatar] cron job [count] ' . count($list)); - foreach ( $list as $v ) { - Debug2::debug( '[Avatar] cron job [url] ' . $v->url ); + foreach ($list as $v) { + Debug2::debug('[Avatar] cron job [url] ' . $v->url); - $_instance->_generate( $v->url ); + $_instance->_generate($v->url); } } @@ -218,50 +228,51 @@ public static function cron( $force = false ) { * @since 3.0 * @access private */ - private function _generate( $url ) { + private function _generate($url) + { global $wpdb; // Record the data - $file = $this->_realpath( $url ); + $file = $this->_realpath($url); // Update request status - self::save_summary( array( 'curr_request' => time() ) ); + self::save_summary(array('curr_request' => time())); // Generate - $this->_maybe_mk_cache_folder( 'avatar' ); + $this->_maybe_mk_cache_folder('avatar'); - $response = wp_remote_get( $url, array( 'timeout' => 180, 'stream' => true, 'filename' => $file ) ); + $response = wp_remote_get($url, array('timeout' => 180, 'stream' => true, 'filename' => $file)); - Debug2::debug( '[Avatar] _generate [url] ' . $url ); + Debug2::debug('[Avatar] _generate [url] ' . $url); // Parse response data - if ( is_wp_error( $response ) ) { + if (is_wp_error($response)) { $error_message = $response->get_error_message(); - file_exists( $file ) && unlink( $file ); - Debug2::debug( '[Avatar] failed to get: ' . $error_message ); + file_exists($file) && unlink($file); + Debug2::debug('[Avatar] failed to get: ' . $error_message); return $url; } // Save summary data - self::save_summary( array( - 'last_spent' => time() - $this->_summary[ 'curr_request' ], - 'last_request' => $this->_summary[ 'curr_request' ], + self::save_summary(array( + 'last_spent' => time() - $this->_summary['curr_request'], + 'last_request' => $this->_summary['curr_request'], 'curr_request' => 0, - ) ); + )); // Update DB - $md5 = md5( $url ); + $md5 = md5($url); $q = "UPDATE `$this->_tb` SET dateline=%d WHERE md5=%s"; - $existed = $wpdb->query( $wpdb->prepare( $q, array( time(), $md5 ) ) ); - if ( ! $existed ) { + $existed = $wpdb->query($wpdb->prepare($q, array(time(), $md5))); + if (!$existed) { $q = "INSERT INTO `$this->_tb` SET url=%s, md5=%s, dateline=%d"; - $wpdb->query( $wpdb->prepare( $q, array( $url, $md5, time() ) ) ); + $wpdb->query($wpdb->prepare($q, array($url, $md5, time()))); } - Debug2::debug( '[Avatar] saved avatar ' . $file ); + Debug2::debug('[Avatar] saved avatar ' . $file); - return $this->_rewrite( $url ); + return $this->_rewrite($url); } /** @@ -270,12 +281,13 @@ private function _generate( $url ) { * @since 3.0 * @access public */ - public function handler() { + public function handler() + { $type = Router::verify_type(); - switch ( $type ) { - case self::TYPE_GENERATE : - self::cron( true ); + switch ($type) { + case self::TYPE_GENERATE: + self::cron(true); break; default: @@ -284,5 +296,4 @@ public function handler() { Admin::redirect(); } - } diff --git a/src/base.cls.php b/src/base.cls.php index 06d32fb03..870f9f960 100644 --- a/src/base.cls.php +++ b/src/base.cls.php @@ -8,7 +8,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Base extends Root { @@ -21,257 +21,257 @@ class Base extends Root ## -------------------------------------------------- ## ## -------------- General ----------------- ## ## -------------------------------------------------- ## - const _VER = '_version'; // Not set-able - const HASH = 'hash'; // Not set-able - const O_AUTO_UPGRADE = 'auto_upgrade'; - const O_API_KEY = 'api_key'; - const O_SERVER_IP = 'server_ip'; - const O_GUEST = 'guest'; - const O_GUEST_OPTM = 'guest_optm'; - const O_NEWS = 'news'; - const O_GUEST_UAS = 'guest_uas'; - const O_GUEST_IPS = 'guest_ips'; + const _VER = '_version'; // Not set-able + const HASH = 'hash'; // Not set-able + const O_AUTO_UPGRADE = 'auto_upgrade'; + const O_API_KEY = 'api_key'; + const O_SERVER_IP = 'server_ip'; + const O_GUEST = 'guest'; + const O_GUEST_OPTM = 'guest_optm'; + const O_NEWS = 'news'; + const O_GUEST_UAS = 'guest_uas'; + const O_GUEST_IPS = 'guest_ips'; ## -------------------------------------------------- ## ## -------------- Cache ----------------- ## ## -------------------------------------------------- ## - const O_CACHE = 'cache'; - const O_CACHE_PRIV = 'cache-priv'; - const O_CACHE_COMMENTER = 'cache-commenter'; - const O_CACHE_REST = 'cache-rest'; - const O_CACHE_PAGE_LOGIN = 'cache-page_login'; - const O_CACHE_FAVICON = 'cache-favicon'; - const O_CACHE_RES = 'cache-resources'; - const O_CACHE_MOBILE = 'cache-mobile'; - const O_CACHE_MOBILE_RULES = 'cache-mobile_rules'; - const O_CACHE_BROWSER = 'cache-browser'; - const O_CACHE_EXC_USERAGENTS = 'cache-exc_useragents'; - const O_CACHE_EXC_COOKIES = 'cache-exc_cookies'; - const O_CACHE_EXC_QS = 'cache-exc_qs'; - const O_CACHE_EXC_CAT = 'cache-exc_cat'; - const O_CACHE_EXC_TAG = 'cache-exc_tag'; - const O_CACHE_FORCE_URI = 'cache-force_uri'; - const O_CACHE_FORCE_PUB_URI = 'cache-force_pub_uri'; - const O_CACHE_PRIV_URI = 'cache-priv_uri'; - const O_CACHE_EXC = 'cache-exc'; - const O_CACHE_EXC_ROLES = 'cache-exc_roles'; - const O_CACHE_DROP_QS = 'cache-drop_qs'; - const O_CACHE_TTL_PUB = 'cache-ttl_pub'; - const O_CACHE_TTL_PRIV = 'cache-ttl_priv'; - const O_CACHE_TTL_FRONTPAGE = 'cache-ttl_frontpage'; - const O_CACHE_TTL_FEED = 'cache-ttl_feed'; - const O_CACHE_TTL_REST = 'cache-ttl_rest'; - const O_CACHE_TTL_STATUS = 'cache-ttl_status'; - const O_CACHE_TTL_BROWSER = 'cache-ttl_browser'; - const O_CACHE_LOGIN_COOKIE = 'cache-login_cookie'; - const O_CACHE_VARY_COOKIES = 'cache-vary_cookies'; - const O_CACHE_VARY_GROUP = 'cache-vary_group'; + const O_CACHE = 'cache'; + const O_CACHE_PRIV = 'cache-priv'; + const O_CACHE_COMMENTER = 'cache-commenter'; + const O_CACHE_REST = 'cache-rest'; + const O_CACHE_PAGE_LOGIN = 'cache-page_login'; + const O_CACHE_FAVICON = 'cache-favicon'; + const O_CACHE_RES = 'cache-resources'; + const O_CACHE_MOBILE = 'cache-mobile'; + const O_CACHE_MOBILE_RULES = 'cache-mobile_rules'; + const O_CACHE_BROWSER = 'cache-browser'; + const O_CACHE_EXC_USERAGENTS = 'cache-exc_useragents'; + const O_CACHE_EXC_COOKIES = 'cache-exc_cookies'; + const O_CACHE_EXC_QS = 'cache-exc_qs'; + const O_CACHE_EXC_CAT = 'cache-exc_cat'; + const O_CACHE_EXC_TAG = 'cache-exc_tag'; + const O_CACHE_FORCE_URI = 'cache-force_uri'; + const O_CACHE_FORCE_PUB_URI = 'cache-force_pub_uri'; + const O_CACHE_PRIV_URI = 'cache-priv_uri'; + const O_CACHE_EXC = 'cache-exc'; + const O_CACHE_EXC_ROLES = 'cache-exc_roles'; + const O_CACHE_DROP_QS = 'cache-drop_qs'; + const O_CACHE_TTL_PUB = 'cache-ttl_pub'; + const O_CACHE_TTL_PRIV = 'cache-ttl_priv'; + const O_CACHE_TTL_FRONTPAGE = 'cache-ttl_frontpage'; + const O_CACHE_TTL_FEED = 'cache-ttl_feed'; + const O_CACHE_TTL_REST = 'cache-ttl_rest'; + const O_CACHE_TTL_STATUS = 'cache-ttl_status'; + const O_CACHE_TTL_BROWSER = 'cache-ttl_browser'; + const O_CACHE_LOGIN_COOKIE = 'cache-login_cookie'; + const O_CACHE_VARY_COOKIES = 'cache-vary_cookies'; + const O_CACHE_VARY_GROUP = 'cache-vary_group'; ## -------------------------------------------------- ## ## -------------- Purge ----------------- ## ## -------------------------------------------------- ## - const O_PURGE_ON_UPGRADE = 'purge-upgrade'; - const O_PURGE_STALE = 'purge-stale'; - const O_PURGE_POST_ALL = 'purge-post_all'; - const O_PURGE_POST_FRONTPAGE = 'purge-post_f'; - const O_PURGE_POST_HOMEPAGE = 'purge-post_h'; - const O_PURGE_POST_PAGES = 'purge-post_p'; + const O_PURGE_ON_UPGRADE = 'purge-upgrade'; + const O_PURGE_STALE = 'purge-stale'; + const O_PURGE_POST_ALL = 'purge-post_all'; + const O_PURGE_POST_FRONTPAGE = 'purge-post_f'; + const O_PURGE_POST_HOMEPAGE = 'purge-post_h'; + const O_PURGE_POST_PAGES = 'purge-post_p'; const O_PURGE_POST_PAGES_WITH_RECENT_POSTS = 'purge-post_pwrp'; - const O_PURGE_POST_AUTHOR = 'purge-post_a'; - const O_PURGE_POST_YEAR = 'purge-post_y'; - const O_PURGE_POST_MONTH = 'purge-post_m'; - const O_PURGE_POST_DATE = 'purge-post_d'; - const O_PURGE_POST_TERM = 'purge-post_t'; // include category|tag|tax - const O_PURGE_POST_POSTTYPE = 'purge-post_pt'; - const O_PURGE_TIMED_URLS = 'purge-timed_urls'; - const O_PURGE_TIMED_URLS_TIME = 'purge-timed_urls_time'; - const O_PURGE_HOOK_ALL = 'purge-hook_all'; + const O_PURGE_POST_AUTHOR = 'purge-post_a'; + const O_PURGE_POST_YEAR = 'purge-post_y'; + const O_PURGE_POST_MONTH = 'purge-post_m'; + const O_PURGE_POST_DATE = 'purge-post_d'; + const O_PURGE_POST_TERM = 'purge-post_t'; // include category|tag|tax + const O_PURGE_POST_POSTTYPE = 'purge-post_pt'; + const O_PURGE_TIMED_URLS = 'purge-timed_urls'; + const O_PURGE_TIMED_URLS_TIME = 'purge-timed_urls_time'; + const O_PURGE_HOOK_ALL = 'purge-hook_all'; ## -------------------------------------------------- ## ## -------------- ESI ----------------- ## ## -------------------------------------------------- ## - const O_ESI = 'esi'; - const O_ESI_CACHE_ADMBAR = 'esi-cache_admbar'; - const O_ESI_CACHE_COMMFORM = 'esi-cache_commform'; - const O_ESI_NONCE = 'esi-nonce'; + const O_ESI = 'esi'; + const O_ESI_CACHE_ADMBAR = 'esi-cache_admbar'; + const O_ESI_CACHE_COMMFORM = 'esi-cache_commform'; + const O_ESI_NONCE = 'esi-nonce'; ## -------------------------------------------------- ## ## -------------- Utilities ----------------- ## ## -------------------------------------------------- ## - const O_UTIL_INSTANT_CLICK = 'util-instant_click'; - const O_UTIL_NO_HTTPS_VARY = 'util-no_https_vary'; + const O_UTIL_INSTANT_CLICK = 'util-instant_click'; + const O_UTIL_NO_HTTPS_VARY = 'util-no_https_vary'; ## -------------------------------------------------- ## ## -------------- Debug ----------------- ## ## -------------------------------------------------- ## - const O_DEBUG_DISABLE_ALL = 'debug-disable_all'; - const O_DEBUG = 'debug'; - const O_DEBUG_IPS = 'debug-ips'; - const O_DEBUG_LEVEL = 'debug-level'; - const O_DEBUG_FILESIZE = 'debug-filesize'; - const O_DEBUG_COOKIE = 'debug-cookie'; - const O_DEBUG_COLLAPS_QS = 'debug-collaps_qs'; - const O_DEBUG_INC = 'debug-inc'; - const O_DEBUG_EXC = 'debug-exc'; - const O_DEBUG_EXC_STRINGS = 'debug-exc_strings'; + const O_DEBUG_DISABLE_ALL = 'debug-disable_all'; + const O_DEBUG = 'debug'; + const O_DEBUG_IPS = 'debug-ips'; + const O_DEBUG_LEVEL = 'debug-level'; + const O_DEBUG_FILESIZE = 'debug-filesize'; + const O_DEBUG_COOKIE = 'debug-cookie'; + const O_DEBUG_COLLAPS_QS = 'debug-collaps_qs'; + const O_DEBUG_INC = 'debug-inc'; + const O_DEBUG_EXC = 'debug-exc'; + const O_DEBUG_EXC_STRINGS = 'debug-exc_strings'; ## -------------------------------------------------- ## ## -------------- DB Optm ----------------- ## ## -------------------------------------------------- ## - const O_DB_OPTM_REVISIONS_MAX = 'db_optm-revisions_max'; - const O_DB_OPTM_REVISIONS_AGE = 'db_optm-revisions_age'; + const O_DB_OPTM_REVISIONS_MAX = 'db_optm-revisions_max'; + const O_DB_OPTM_REVISIONS_AGE = 'db_optm-revisions_age'; ## -------------------------------------------------- ## ## -------------- HTML Optm ----------------- ## ## -------------------------------------------------- ## - const O_OPTM_CSS_MIN = 'optm-css_min'; - const O_OPTM_CSS_COMB = 'optm-css_comb'; - const O_OPTM_CSS_COMB_EXT_INL = 'optm-css_comb_ext_inl'; - const O_OPTM_UCSS = 'optm-ucss'; - const O_OPTM_UCSS_INLINE = 'optm-ucss_inline'; - const O_OPTM_UCSS_SELECTOR_WHITELIST = 'optm-ucss_whitelist'; - const O_OPTM_UCSS_FILE_EXC_INLINE = 'optm-ucss_file_exc_inline'; - const O_OPTM_UCSS_EXC = 'optm-ucss_exc'; - const O_OPTM_CSS_EXC = 'optm-css_exc'; - const O_OPTM_JS_MIN = 'optm-js_min'; - const O_OPTM_JS_COMB = 'optm-js_comb'; - const O_OPTM_JS_COMB_EXT_INL = 'optm-js_comb_ext_inl'; - const O_OPTM_JS_DELAY_INC = 'optm-js_delay_inc'; - const O_OPTM_JS_EXC = 'optm-js_exc'; - const O_OPTM_HTML_MIN = 'optm-html_min'; - const O_OPTM_HTML_LAZY = 'optm-html_lazy'; - const O_OPTM_QS_RM = 'optm-qs_rm'; - const O_OPTM_GGFONTS_RM = 'optm-ggfonts_rm'; - const O_OPTM_CSS_ASYNC = 'optm-css_async'; - const O_OPTM_CCSS_PER_URL = 'optm-ccss_per_url'; - const O_OPTM_CCSS_SEP_POSTTYPE = 'optm-ccss_sep_posttype'; - const O_OPTM_CCSS_SEP_URI = 'optm-ccss_sep_uri'; - const O_OPTM_CSS_ASYNC_INLINE = 'optm-css_async_inline'; - const O_OPTM_CSS_FONT_DISPLAY = 'optm-css_font_display'; - const O_OPTM_JS_DEFER = 'optm-js_defer'; - const O_OPTM_LOCALIZE = 'optm-localize'; - const O_OPTM_LOCALIZE_DOMAINS = 'optm-localize_domains'; - const O_OPTM_EMOJI_RM = 'optm-emoji_rm'; - const O_OPTM_NOSCRIPT_RM = 'optm-noscript_rm'; - const O_OPTM_GGFONTS_ASYNC = 'optm-ggfonts_async'; - const O_OPTM_EXC_ROLES = 'optm-exc_roles'; - const O_OPTM_CCSS_CON = 'optm-ccss_con'; - const O_OPTM_JS_DEFER_EXC = 'optm-js_defer_exc'; - const O_OPTM_GM_JS_EXC = 'optm-gm_js_exc'; - const O_OPTM_DNS_PREFETCH = 'optm-dns_prefetch'; - const O_OPTM_DNS_PREFETCH_CTRL = 'optm-dns_prefetch_ctrl'; - const O_OPTM_DNS_PRECONNECT = 'optm-dns_preconnect'; - const O_OPTM_EXC = 'optm-exc'; - const O_OPTM_GUEST_ONLY = 'optm-guest_only'; + const O_OPTM_CSS_MIN = 'optm-css_min'; + const O_OPTM_CSS_COMB = 'optm-css_comb'; + const O_OPTM_CSS_COMB_EXT_INL = 'optm-css_comb_ext_inl'; + const O_OPTM_UCSS = 'optm-ucss'; + const O_OPTM_UCSS_INLINE = 'optm-ucss_inline'; + const O_OPTM_UCSS_SELECTOR_WHITELIST = 'optm-ucss_whitelist'; + const O_OPTM_UCSS_FILE_EXC_INLINE = 'optm-ucss_file_exc_inline'; + const O_OPTM_UCSS_EXC = 'optm-ucss_exc'; + const O_OPTM_CSS_EXC = 'optm-css_exc'; + const O_OPTM_JS_MIN = 'optm-js_min'; + const O_OPTM_JS_COMB = 'optm-js_comb'; + const O_OPTM_JS_COMB_EXT_INL = 'optm-js_comb_ext_inl'; + const O_OPTM_JS_DELAY_INC = 'optm-js_delay_inc'; + const O_OPTM_JS_EXC = 'optm-js_exc'; + const O_OPTM_HTML_MIN = 'optm-html_min'; + const O_OPTM_HTML_LAZY = 'optm-html_lazy'; + const O_OPTM_QS_RM = 'optm-qs_rm'; + const O_OPTM_GGFONTS_RM = 'optm-ggfonts_rm'; + const O_OPTM_CSS_ASYNC = 'optm-css_async'; + const O_OPTM_CCSS_PER_URL = 'optm-ccss_per_url'; + const O_OPTM_CCSS_SEP_POSTTYPE = 'optm-ccss_sep_posttype'; + const O_OPTM_CCSS_SEP_URI = 'optm-ccss_sep_uri'; + const O_OPTM_CSS_ASYNC_INLINE = 'optm-css_async_inline'; + const O_OPTM_CSS_FONT_DISPLAY = 'optm-css_font_display'; + const O_OPTM_JS_DEFER = 'optm-js_defer'; + const O_OPTM_LOCALIZE = 'optm-localize'; + const O_OPTM_LOCALIZE_DOMAINS = 'optm-localize_domains'; + const O_OPTM_EMOJI_RM = 'optm-emoji_rm'; + const O_OPTM_NOSCRIPT_RM = 'optm-noscript_rm'; + const O_OPTM_GGFONTS_ASYNC = 'optm-ggfonts_async'; + const O_OPTM_EXC_ROLES = 'optm-exc_roles'; + const O_OPTM_CCSS_CON = 'optm-ccss_con'; + const O_OPTM_JS_DEFER_EXC = 'optm-js_defer_exc'; + const O_OPTM_GM_JS_EXC = 'optm-gm_js_exc'; + const O_OPTM_DNS_PREFETCH = 'optm-dns_prefetch'; + const O_OPTM_DNS_PREFETCH_CTRL = 'optm-dns_prefetch_ctrl'; + const O_OPTM_DNS_PRECONNECT = 'optm-dns_preconnect'; + const O_OPTM_EXC = 'optm-exc'; + const O_OPTM_GUEST_ONLY = 'optm-guest_only'; ## -------------------------------------------------- ## ## -------------- Object Cache ----------------- ## ## -------------------------------------------------- ## - const O_OBJECT = 'object'; - const O_OBJECT_KIND = 'object-kind'; - const O_OBJECT_HOST = 'object-host'; - const O_OBJECT_PORT = 'object-port'; - const O_OBJECT_LIFE = 'object-life'; - const O_OBJECT_PERSISTENT = 'object-persistent'; - const O_OBJECT_ADMIN = 'object-admin'; - const O_OBJECT_TRANSIENTS = 'object-transients'; - const O_OBJECT_DB_ID = 'object-db_id'; - const O_OBJECT_USER = 'object-user'; - const O_OBJECT_PSWD = 'object-pswd'; + const O_OBJECT = 'object'; + const O_OBJECT_KIND = 'object-kind'; + const O_OBJECT_HOST = 'object-host'; + const O_OBJECT_PORT = 'object-port'; + const O_OBJECT_LIFE = 'object-life'; + const O_OBJECT_PERSISTENT = 'object-persistent'; + const O_OBJECT_ADMIN = 'object-admin'; + const O_OBJECT_TRANSIENTS = 'object-transients'; + const O_OBJECT_DB_ID = 'object-db_id'; + const O_OBJECT_USER = 'object-user'; + const O_OBJECT_PSWD = 'object-pswd'; const O_OBJECT_GLOBAL_GROUPS = 'object-global_groups'; const O_OBJECT_NON_PERSISTENT_GROUPS = 'object-non_persistent_groups'; ## -------------------------------------------------- ## ## -------------- Discussion ----------------- ## ## -------------------------------------------------- ## - const O_DISCUSS_AVATAR_CACHE = 'discuss-avatar_cache'; - const O_DISCUSS_AVATAR_CRON = 'discuss-avatar_cron'; - const O_DISCUSS_AVATAR_CACHE_TTL = 'discuss-avatar_cache_ttl'; + const O_DISCUSS_AVATAR_CACHE = 'discuss-avatar_cache'; + const O_DISCUSS_AVATAR_CRON = 'discuss-avatar_cron'; + const O_DISCUSS_AVATAR_CACHE_TTL = 'discuss-avatar_cache_ttl'; ## -------------------------------------------------- ## ## -------------- Media ----------------- ## ## -------------------------------------------------- ## - const O_MEDIA_PRELOAD_FEATURED = 'media-preload_featured'; - const O_MEDIA_LAZY = 'media-lazy'; - const O_MEDIA_LAZY_PLACEHOLDER = 'media-lazy_placeholder'; - const O_MEDIA_PLACEHOLDER_RESP = 'media-placeholder_resp'; - const O_MEDIA_PLACEHOLDER_RESP_COLOR = 'media-placeholder_resp_color'; - const O_MEDIA_PLACEHOLDER_RESP_SVG = 'media-placeholder_resp_svg'; - const O_MEDIA_LQIP = 'media-lqip'; - const O_MEDIA_LQIP_QUAL = 'media-lqip_qual'; - const O_MEDIA_LQIP_MIN_W = 'media-lqip_min_w'; - const O_MEDIA_LQIP_MIN_H = 'media-lqip_min_h'; - const O_MEDIA_PLACEHOLDER_RESP_ASYNC = 'media-placeholder_resp_async'; - const O_MEDIA_IFRAME_LAZY = 'media-iframe_lazy'; - const O_MEDIA_ADD_MISSING_SIZES = 'media-add_missing_sizes'; - const O_MEDIA_LAZY_EXC = 'media-lazy_exc'; - const O_MEDIA_LAZY_CLS_EXC = 'media-lazy_cls_exc'; - const O_MEDIA_LAZY_PARENT_CLS_EXC = 'media-lazy_parent_cls_exc'; - const O_MEDIA_IFRAME_LAZY_CLS_EXC = 'media-iframe_lazy_cls_exc'; - const O_MEDIA_IFRAME_LAZY_PARENT_CLS_EXC = 'media-iframe_lazy_parent_cls_exc'; - const O_MEDIA_LAZY_URI_EXC = 'media-lazy_uri_exc'; - const O_MEDIA_LQIP_EXC = 'media-lqip_exc'; - const O_MEDIA_VPI = 'media-vpi'; - const O_MEDIA_VPI_CRON = 'media-vpi_cron'; + const O_MEDIA_PRELOAD_FEATURED = 'media-preload_featured'; + const O_MEDIA_LAZY = 'media-lazy'; + const O_MEDIA_LAZY_PLACEHOLDER = 'media-lazy_placeholder'; + const O_MEDIA_PLACEHOLDER_RESP = 'media-placeholder_resp'; + const O_MEDIA_PLACEHOLDER_RESP_COLOR = 'media-placeholder_resp_color'; + const O_MEDIA_PLACEHOLDER_RESP_SVG = 'media-placeholder_resp_svg'; + const O_MEDIA_LQIP = 'media-lqip'; + const O_MEDIA_LQIP_QUAL = 'media-lqip_qual'; + const O_MEDIA_LQIP_MIN_W = 'media-lqip_min_w'; + const O_MEDIA_LQIP_MIN_H = 'media-lqip_min_h'; + const O_MEDIA_PLACEHOLDER_RESP_ASYNC = 'media-placeholder_resp_async'; + const O_MEDIA_IFRAME_LAZY = 'media-iframe_lazy'; + const O_MEDIA_ADD_MISSING_SIZES = 'media-add_missing_sizes'; + const O_MEDIA_LAZY_EXC = 'media-lazy_exc'; + const O_MEDIA_LAZY_CLS_EXC = 'media-lazy_cls_exc'; + const O_MEDIA_LAZY_PARENT_CLS_EXC = 'media-lazy_parent_cls_exc'; + const O_MEDIA_IFRAME_LAZY_CLS_EXC = 'media-iframe_lazy_cls_exc'; + const O_MEDIA_IFRAME_LAZY_PARENT_CLS_EXC = 'media-iframe_lazy_parent_cls_exc'; + const O_MEDIA_LAZY_URI_EXC = 'media-lazy_uri_exc'; + const O_MEDIA_LQIP_EXC = 'media-lqip_exc'; + const O_MEDIA_VPI = 'media-vpi'; + const O_MEDIA_VPI_CRON = 'media-vpi_cron'; ## -------------------------------------------------- ## ## -------------- Image Optm ----------------- ## ## -------------------------------------------------- ## - const O_IMG_OPTM_AUTO = 'img_optm-auto'; - const O_IMG_OPTM_CRON = 'img_optm-cron'; - const O_IMG_OPTM_ORI = 'img_optm-ori'; - const O_IMG_OPTM_RM_BKUP = 'img_optm-rm_bkup'; - const O_IMG_OPTM_WEBP = 'img_optm-webp'; - const O_IMG_OPTM_LOSSLESS = 'img_optm-lossless'; - const O_IMG_OPTM_EXIF = 'img_optm-exif'; - const O_IMG_OPTM_WEBP_ATTR = 'img_optm-webp_attr'; + const O_IMG_OPTM_AUTO = 'img_optm-auto'; + const O_IMG_OPTM_CRON = 'img_optm-cron'; + const O_IMG_OPTM_ORI = 'img_optm-ori'; + const O_IMG_OPTM_RM_BKUP = 'img_optm-rm_bkup'; + const O_IMG_OPTM_WEBP = 'img_optm-webp'; + const O_IMG_OPTM_LOSSLESS = 'img_optm-lossless'; + const O_IMG_OPTM_EXIF = 'img_optm-exif'; + const O_IMG_OPTM_WEBP_ATTR = 'img_optm-webp_attr'; const O_IMG_OPTM_WEBP_REPLACE_SRCSET = 'img_optm-webp_replace_srcset'; - const O_IMG_OPTM_JPG_QUALITY = 'img_optm-jpg_quality'; + const O_IMG_OPTM_JPG_QUALITY = 'img_optm-jpg_quality'; ## -------------------------------------------------- ## ## -------------- Crawler ----------------- ## ## -------------------------------------------------- ## - const O_CRAWLER = 'crawler'; - const O_CRAWLER_USLEEP = 'crawler-usleep'; - const O_CRAWLER_RUN_DURATION = 'crawler-run_duration'; - const O_CRAWLER_RUN_INTERVAL = 'crawler-run_interval'; - const O_CRAWLER_CRAWL_INTERVAL = 'crawler-crawl_interval'; - const O_CRAWLER_THREADS = 'crawler-threads'; - const O_CRAWLER_TIMEOUT = 'crawler-timeout'; - const O_CRAWLER_LOAD_LIMIT = 'crawler-load_limit'; - const O_CRAWLER_SITEMAP = 'crawler-sitemap'; - const O_CRAWLER_DROP_DOMAIN = 'crawler-drop_domain'; - const O_CRAWLER_MAP_TIMEOUT = 'crawler-map_timeout'; - const O_CRAWLER_ROLES = 'crawler-roles'; - const O_CRAWLER_COOKIES = 'crawler-cookies'; + const O_CRAWLER = 'crawler'; + const O_CRAWLER_USLEEP = 'crawler-usleep'; + const O_CRAWLER_RUN_DURATION = 'crawler-run_duration'; + const O_CRAWLER_RUN_INTERVAL = 'crawler-run_interval'; + const O_CRAWLER_CRAWL_INTERVAL = 'crawler-crawl_interval'; + const O_CRAWLER_THREADS = 'crawler-threads'; + const O_CRAWLER_TIMEOUT = 'crawler-timeout'; + const O_CRAWLER_LOAD_LIMIT = 'crawler-load_limit'; + const O_CRAWLER_SITEMAP = 'crawler-sitemap'; + const O_CRAWLER_DROP_DOMAIN = 'crawler-drop_domain'; + const O_CRAWLER_MAP_TIMEOUT = 'crawler-map_timeout'; + const O_CRAWLER_ROLES = 'crawler-roles'; + const O_CRAWLER_COOKIES = 'crawler-cookies'; ## -------------------------------------------------- ## ## -------------- Misc ----------------- ## ## -------------------------------------------------- ## - const O_MISC_HEARTBEAT_FRONT = 'misc-heartbeat_front'; - const O_MISC_HEARTBEAT_FRONT_TTL = 'misc-heartbeat_front_ttl'; - const O_MISC_HEARTBEAT_BACK = 'misc-heartbeat_back'; - const O_MISC_HEARTBEAT_BACK_TTL = 'misc-heartbeat_back_ttl'; - const O_MISC_HEARTBEAT_EDITOR = 'misc-heartbeat_editor'; - const O_MISC_HEARTBEAT_EDITOR_TTL = 'misc-heartbeat_editor_ttl'; + const O_MISC_HEARTBEAT_FRONT = 'misc-heartbeat_front'; + const O_MISC_HEARTBEAT_FRONT_TTL = 'misc-heartbeat_front_ttl'; + const O_MISC_HEARTBEAT_BACK = 'misc-heartbeat_back'; + const O_MISC_HEARTBEAT_BACK_TTL = 'misc-heartbeat_back_ttl'; + const O_MISC_HEARTBEAT_EDITOR = 'misc-heartbeat_editor'; + const O_MISC_HEARTBEAT_EDITOR_TTL = 'misc-heartbeat_editor_ttl'; ## -------------------------------------------------- ## ## -------------- CDN ----------------- ## ## -------------------------------------------------- ## - const O_CDN = 'cdn'; - const O_CDN_ORI = 'cdn-ori'; - const O_CDN_ORI_DIR = 'cdn-ori_dir'; - const O_CDN_EXC = 'cdn-exc'; - const O_CDN_QUIC = 'cdn-quic'; - const O_CDN_CLOUDFLARE = 'cdn-cloudflare'; + const O_CDN = 'cdn'; + const O_CDN_ORI = 'cdn-ori'; + const O_CDN_ORI_DIR = 'cdn-ori_dir'; + const O_CDN_EXC = 'cdn-exc'; + const O_CDN_QUIC = 'cdn-quic'; + const O_CDN_CLOUDFLARE = 'cdn-cloudflare'; const O_CDN_CLOUDFLARE_EMAIL = 'cdn-cloudflare_email'; - const O_CDN_CLOUDFLARE_KEY = 'cdn-cloudflare_key'; + const O_CDN_CLOUDFLARE_KEY = 'cdn-cloudflare_key'; const O_CDN_CLOUDFLARE_NAME = 'cdn-cloudflare_name'; const O_CDN_CLOUDFLARE_ZONE = 'cdn-cloudflare_zone'; - const O_CDN_MAPPING = 'cdn-mapping'; - const O_CDN_ATTR = 'cdn-attr'; - const O_QC_TOKEN = 'qc-token'; - const O_QC_NAMESERVERS = 'qc-nameservers'; + const O_CDN_MAPPING = 'cdn-mapping'; + const O_CDN_ATTR = 'cdn-attr'; + const O_QC_TOKEN = 'qc-token'; + const O_QC_NAMESERVERS = 'qc-nameservers'; const NETWORK_O_USE_PRIMARY = 'use_primary_settings'; @@ -285,24 +285,24 @@ class Base extends Root // const O_FAVICON = 'litespeed-cache-favicon'; - const CRWL_COOKIE_NAME = 'name'; - const CRWL_COOKIE_VALS = 'vals'; + const CRWL_COOKIE_NAME = 'name'; + const CRWL_COOKIE_VALS = 'vals'; - const CDN_MAPPING_URL = 'url'; - const CDN_MAPPING_INC_IMG = 'inc_img'; - const CDN_MAPPING_INC_CSS = 'inc_css'; - const CDN_MAPPING_INC_JS = 'inc_js'; - const CDN_MAPPING_FILETYPE = 'filetype'; + const CDN_MAPPING_URL = 'url'; + const CDN_MAPPING_INC_IMG = 'inc_img'; + const CDN_MAPPING_INC_CSS = 'inc_css'; + const CDN_MAPPING_INC_JS = 'inc_js'; + const CDN_MAPPING_FILETYPE = 'filetype'; - const VAL_OFF = 0; - const VAL_ON = 1; - const VAL_ON2 = 2; + const VAL_OFF = 0; + const VAL_ON = 1; + const VAL_ON2 = 2; /* This is for API hook usage */ - const IMG_OPTM_BM_ORI = 1; - const IMG_OPTM_BM_WEBP = 2; - const IMG_OPTM_BM_LOSSLESS = 4; - const IMG_OPTM_BM_EXIF = 8; + const IMG_OPTM_BM_ORI = 1; + const IMG_OPTM_BM_WEBP = 2; + const IMG_OPTM_BM_LOSSLESS = 4; + const IMG_OPTM_BM_EXIF = 8; /* Site related options (Will not overwrite other sites' config) */ protected static $SINGLE_SITE_OPTIONS = array( @@ -327,290 +327,287 @@ class Base extends Root ); protected static $_default_options = array( - self::_VER => '', - self::HASH => '', - self::O_AUTO_UPGRADE => false, - self::O_API_KEY => '', - self::O_SERVER_IP => '', - self::O_GUEST => false, - self::O_GUEST_OPTM => false, - self::O_NEWS => false, - self::O_GUEST_UAS => array(), - self::O_GUEST_IPS => array(), + self::_VER => '', + self::HASH => '', + self::O_AUTO_UPGRADE => false, + self::O_API_KEY => '', + self::O_SERVER_IP => '', + self::O_GUEST => false, + self::O_GUEST_OPTM => false, + self::O_NEWS => false, + self::O_GUEST_UAS => array(), + self::O_GUEST_IPS => array(), // Cache - self::O_CACHE => false, - self::O_CACHE_PRIV => false, - self::O_CACHE_COMMENTER => false, - self::O_CACHE_REST => false, - self::O_CACHE_PAGE_LOGIN => false, - self::O_CACHE_FAVICON => false, - self::O_CACHE_RES => false, - self::O_CACHE_MOBILE => false, - self::O_CACHE_MOBILE_RULES => array(), - self::O_CACHE_BROWSER => false, - self::O_CACHE_EXC_USERAGENTS => array(), - self::O_CACHE_EXC_COOKIES => array(), - self::O_CACHE_EXC_QS => array(), - self::O_CACHE_EXC_CAT => array(), - self::O_CACHE_EXC_TAG => array(), - self::O_CACHE_FORCE_URI => array(), - self::O_CACHE_FORCE_PUB_URI => array(), - self::O_CACHE_PRIV_URI => array(), - self::O_CACHE_EXC => array(), - self::O_CACHE_EXC_ROLES => array(), - self::O_CACHE_DROP_QS => array(), - self::O_CACHE_TTL_PUB => 0, - self::O_CACHE_TTL_PRIV => 0, - self::O_CACHE_TTL_FRONTPAGE => 0, - self::O_CACHE_TTL_FEED => 0, - self::O_CACHE_TTL_REST => 0, - self::O_CACHE_TTL_BROWSER => 0, - self::O_CACHE_TTL_STATUS => array(), - self::O_CACHE_LOGIN_COOKIE => '', - self::O_CACHE_VARY_COOKIES => array(), - self::O_CACHE_VARY_GROUP => array(), + self::O_CACHE => false, + self::O_CACHE_PRIV => false, + self::O_CACHE_COMMENTER => false, + self::O_CACHE_REST => false, + self::O_CACHE_PAGE_LOGIN => false, + self::O_CACHE_FAVICON => false, + self::O_CACHE_RES => false, + self::O_CACHE_MOBILE => false, + self::O_CACHE_MOBILE_RULES => array(), + self::O_CACHE_BROWSER => false, + self::O_CACHE_EXC_USERAGENTS => array(), + self::O_CACHE_EXC_COOKIES => array(), + self::O_CACHE_EXC_QS => array(), + self::O_CACHE_EXC_CAT => array(), + self::O_CACHE_EXC_TAG => array(), + self::O_CACHE_FORCE_URI => array(), + self::O_CACHE_FORCE_PUB_URI => array(), + self::O_CACHE_PRIV_URI => array(), + self::O_CACHE_EXC => array(), + self::O_CACHE_EXC_ROLES => array(), + self::O_CACHE_DROP_QS => array(), + self::O_CACHE_TTL_PUB => 0, + self::O_CACHE_TTL_PRIV => 0, + self::O_CACHE_TTL_FRONTPAGE => 0, + self::O_CACHE_TTL_FEED => 0, + self::O_CACHE_TTL_REST => 0, + self::O_CACHE_TTL_BROWSER => 0, + self::O_CACHE_TTL_STATUS => array(), + self::O_CACHE_LOGIN_COOKIE => '', + self::O_CACHE_VARY_COOKIES => array(), + self::O_CACHE_VARY_GROUP => array(), // Purge - self::O_PURGE_ON_UPGRADE => false, - self::O_PURGE_STALE => false, - self::O_PURGE_POST_ALL => false, - self::O_PURGE_POST_FRONTPAGE => false, - self::O_PURGE_POST_HOMEPAGE => false, - self::O_PURGE_POST_PAGES => false, - self::O_PURGE_POST_PAGES_WITH_RECENT_POSTS => false, - self::O_PURGE_POST_AUTHOR => false, - self::O_PURGE_POST_YEAR => false, - self::O_PURGE_POST_MONTH => false, - self::O_PURGE_POST_DATE => false, - self::O_PURGE_POST_TERM => false, - self::O_PURGE_POST_POSTTYPE => false, - self::O_PURGE_TIMED_URLS => array(), - self::O_PURGE_TIMED_URLS_TIME => '', - self::O_PURGE_HOOK_ALL => array(), + self::O_PURGE_ON_UPGRADE => false, + self::O_PURGE_STALE => false, + self::O_PURGE_POST_ALL => false, + self::O_PURGE_POST_FRONTPAGE => false, + self::O_PURGE_POST_HOMEPAGE => false, + self::O_PURGE_POST_PAGES => false, + self::O_PURGE_POST_PAGES_WITH_RECENT_POSTS => false, + self::O_PURGE_POST_AUTHOR => false, + self::O_PURGE_POST_YEAR => false, + self::O_PURGE_POST_MONTH => false, + self::O_PURGE_POST_DATE => false, + self::O_PURGE_POST_TERM => false, + self::O_PURGE_POST_POSTTYPE => false, + self::O_PURGE_TIMED_URLS => array(), + self::O_PURGE_TIMED_URLS_TIME => '', + self::O_PURGE_HOOK_ALL => array(), // ESI - self::O_ESI => false, - self::O_ESI_CACHE_ADMBAR => false, - self::O_ESI_CACHE_COMMFORM => false, - self::O_ESI_NONCE => array(), + self::O_ESI => false, + self::O_ESI_CACHE_ADMBAR => false, + self::O_ESI_CACHE_COMMFORM => false, + self::O_ESI_NONCE => array(), // Util - self::O_UTIL_INSTANT_CLICK => false, - self::O_UTIL_NO_HTTPS_VARY => false, + self::O_UTIL_INSTANT_CLICK => false, + self::O_UTIL_NO_HTTPS_VARY => false, // Debug - self::O_DEBUG_DISABLE_ALL => false, - self::O_DEBUG => false, - self::O_DEBUG_IPS => array(), - self::O_DEBUG_LEVEL => false, - self::O_DEBUG_FILESIZE => 0, - self::O_DEBUG_COOKIE => false, - self::O_DEBUG_COLLAPS_QS => false, - self::O_DEBUG_INC => array(), - self::O_DEBUG_EXC => array(), - self::O_DEBUG_EXC_STRINGS => array(), + self::O_DEBUG_DISABLE_ALL => false, + self::O_DEBUG => false, + self::O_DEBUG_IPS => array(), + self::O_DEBUG_LEVEL => false, + self::O_DEBUG_FILESIZE => 0, + self::O_DEBUG_COOKIE => false, + self::O_DEBUG_COLLAPS_QS => false, + self::O_DEBUG_INC => array(), + self::O_DEBUG_EXC => array(), + self::O_DEBUG_EXC_STRINGS => array(), // DB Optm - self::O_DB_OPTM_REVISIONS_MAX => 0, - self::O_DB_OPTM_REVISIONS_AGE => 0, + self::O_DB_OPTM_REVISIONS_MAX => 0, + self::O_DB_OPTM_REVISIONS_AGE => 0, // HTML Optm - self::O_OPTM_CSS_MIN => false, - self::O_OPTM_CSS_COMB => false, - self::O_OPTM_CSS_COMB_EXT_INL => false, - self::O_OPTM_UCSS => false, - self::O_OPTM_UCSS_INLINE => false, - self::O_OPTM_UCSS_SELECTOR_WHITELIST => array(), - self::O_OPTM_UCSS_FILE_EXC_INLINE => array(), - self::O_OPTM_UCSS_EXC => array(), - self::O_OPTM_CSS_EXC => array(), - self::O_OPTM_JS_MIN => false, - self::O_OPTM_JS_COMB => false, - self::O_OPTM_JS_COMB_EXT_INL => false, - self::O_OPTM_JS_DELAY_INC => array(), - self::O_OPTM_JS_EXC => array(), - self::O_OPTM_HTML_MIN => false, - self::O_OPTM_HTML_LAZY => array(), - self::O_OPTM_QS_RM => false, - self::O_OPTM_GGFONTS_RM => false, - self::O_OPTM_CSS_ASYNC => false, - self::O_OPTM_CCSS_PER_URL => false, - self::O_OPTM_CCSS_SEP_POSTTYPE => array(), - self::O_OPTM_CCSS_SEP_URI => array(), - self::O_OPTM_CSS_ASYNC_INLINE => false, - self::O_OPTM_CSS_FONT_DISPLAY => false, - self::O_OPTM_JS_DEFER => false, - self::O_OPTM_EMOJI_RM => false, - self::O_OPTM_NOSCRIPT_RM => false, - self::O_OPTM_GGFONTS_ASYNC => false, - self::O_OPTM_EXC_ROLES => array(), - self::O_OPTM_CCSS_CON => '', - self::O_OPTM_JS_DEFER_EXC => array(), - self::O_OPTM_GM_JS_EXC => array(), - self::O_OPTM_DNS_PREFETCH => array(), - self::O_OPTM_DNS_PREFETCH_CTRL => false, - self::O_OPTM_DNS_PRECONNECT => array(), - self::O_OPTM_EXC => array(), - self::O_OPTM_GUEST_ONLY => false, + self::O_OPTM_CSS_MIN => false, + self::O_OPTM_CSS_COMB => false, + self::O_OPTM_CSS_COMB_EXT_INL => false, + self::O_OPTM_UCSS => false, + self::O_OPTM_UCSS_INLINE => false, + self::O_OPTM_UCSS_SELECTOR_WHITELIST => array(), + self::O_OPTM_UCSS_FILE_EXC_INLINE => array(), + self::O_OPTM_UCSS_EXC => array(), + self::O_OPTM_CSS_EXC => array(), + self::O_OPTM_JS_MIN => false, + self::O_OPTM_JS_COMB => false, + self::O_OPTM_JS_COMB_EXT_INL => false, + self::O_OPTM_JS_DELAY_INC => array(), + self::O_OPTM_JS_EXC => array(), + self::O_OPTM_HTML_MIN => false, + self::O_OPTM_HTML_LAZY => array(), + self::O_OPTM_QS_RM => false, + self::O_OPTM_GGFONTS_RM => false, + self::O_OPTM_CSS_ASYNC => false, + self::O_OPTM_CCSS_PER_URL => false, + self::O_OPTM_CCSS_SEP_POSTTYPE => array(), + self::O_OPTM_CCSS_SEP_URI => array(), + self::O_OPTM_CSS_ASYNC_INLINE => false, + self::O_OPTM_CSS_FONT_DISPLAY => false, + self::O_OPTM_JS_DEFER => false, + self::O_OPTM_EMOJI_RM => false, + self::O_OPTM_NOSCRIPT_RM => false, + self::O_OPTM_GGFONTS_ASYNC => false, + self::O_OPTM_EXC_ROLES => array(), + self::O_OPTM_CCSS_CON => '', + self::O_OPTM_JS_DEFER_EXC => array(), + self::O_OPTM_GM_JS_EXC => array(), + self::O_OPTM_DNS_PREFETCH => array(), + self::O_OPTM_DNS_PREFETCH_CTRL => false, + self::O_OPTM_DNS_PRECONNECT => array(), + self::O_OPTM_EXC => array(), + self::O_OPTM_GUEST_ONLY => false, // Object - self::O_OBJECT => false, - self::O_OBJECT_KIND => false, - self::O_OBJECT_HOST => '', - self::O_OBJECT_PORT => 0, - self::O_OBJECT_LIFE => 0, - self::O_OBJECT_PERSISTENT => false, - self::O_OBJECT_ADMIN => false, - self::O_OBJECT_TRANSIENTS => false, - self::O_OBJECT_DB_ID => 0, - self::O_OBJECT_USER => '', - self::O_OBJECT_PSWD => '', - self::O_OBJECT_GLOBAL_GROUPS => array(), + self::O_OBJECT => false, + self::O_OBJECT_KIND => false, + self::O_OBJECT_HOST => '', + self::O_OBJECT_PORT => 0, + self::O_OBJECT_LIFE => 0, + self::O_OBJECT_PERSISTENT => false, + self::O_OBJECT_ADMIN => false, + self::O_OBJECT_TRANSIENTS => false, + self::O_OBJECT_DB_ID => 0, + self::O_OBJECT_USER => '', + self::O_OBJECT_PSWD => '', + self::O_OBJECT_GLOBAL_GROUPS => array(), self::O_OBJECT_NON_PERSISTENT_GROUPS => array(), // Discuss - self::O_DISCUSS_AVATAR_CACHE => false, - self::O_DISCUSS_AVATAR_CRON => false, - self::O_DISCUSS_AVATAR_CACHE_TTL => 0, - self::O_OPTM_LOCALIZE => false, - self::O_OPTM_LOCALIZE_DOMAINS => array(), + self::O_DISCUSS_AVATAR_CACHE => false, + self::O_DISCUSS_AVATAR_CRON => false, + self::O_DISCUSS_AVATAR_CACHE_TTL => 0, + self::O_OPTM_LOCALIZE => false, + self::O_OPTM_LOCALIZE_DOMAINS => array(), // Media - self::O_MEDIA_PRELOAD_FEATURED => false, - self::O_MEDIA_LAZY => false, - self::O_MEDIA_LAZY_PLACEHOLDER => '', - self::O_MEDIA_PLACEHOLDER_RESP => false, - self::O_MEDIA_PLACEHOLDER_RESP_COLOR => '', - self::O_MEDIA_PLACEHOLDER_RESP_SVG => '', - self::O_MEDIA_LQIP => false, - self::O_MEDIA_LQIP_QUAL => 0, - self::O_MEDIA_LQIP_MIN_W => 0, - self::O_MEDIA_LQIP_MIN_H => 0, - self::O_MEDIA_PLACEHOLDER_RESP_ASYNC => false, - self::O_MEDIA_IFRAME_LAZY => false, - self::O_MEDIA_ADD_MISSING_SIZES => false, - self::O_MEDIA_LAZY_EXC => array(), - self::O_MEDIA_LAZY_CLS_EXC => array(), - self::O_MEDIA_LAZY_PARENT_CLS_EXC => array(), - self::O_MEDIA_IFRAME_LAZY_CLS_EXC => array(), - self::O_MEDIA_IFRAME_LAZY_PARENT_CLS_EXC => array(), - self::O_MEDIA_LAZY_URI_EXC => array(), - self::O_MEDIA_LQIP_EXC => array(), - self::O_MEDIA_VPI => false, - self::O_MEDIA_VPI_CRON => false, + self::O_MEDIA_PRELOAD_FEATURED => false, + self::O_MEDIA_LAZY => false, + self::O_MEDIA_LAZY_PLACEHOLDER => '', + self::O_MEDIA_PLACEHOLDER_RESP => false, + self::O_MEDIA_PLACEHOLDER_RESP_COLOR => '', + self::O_MEDIA_PLACEHOLDER_RESP_SVG => '', + self::O_MEDIA_LQIP => false, + self::O_MEDIA_LQIP_QUAL => 0, + self::O_MEDIA_LQIP_MIN_W => 0, + self::O_MEDIA_LQIP_MIN_H => 0, + self::O_MEDIA_PLACEHOLDER_RESP_ASYNC => false, + self::O_MEDIA_IFRAME_LAZY => false, + self::O_MEDIA_ADD_MISSING_SIZES => false, + self::O_MEDIA_LAZY_EXC => array(), + self::O_MEDIA_LAZY_CLS_EXC => array(), + self::O_MEDIA_LAZY_PARENT_CLS_EXC => array(), + self::O_MEDIA_IFRAME_LAZY_CLS_EXC => array(), + self::O_MEDIA_IFRAME_LAZY_PARENT_CLS_EXC => array(), + self::O_MEDIA_LAZY_URI_EXC => array(), + self::O_MEDIA_LQIP_EXC => array(), + self::O_MEDIA_VPI => false, + self::O_MEDIA_VPI_CRON => false, // Image Optm - self::O_IMG_OPTM_AUTO => false, - self::O_IMG_OPTM_CRON => false, - self::O_IMG_OPTM_ORI => false, - self::O_IMG_OPTM_RM_BKUP => false, - self::O_IMG_OPTM_WEBP => false, - self::O_IMG_OPTM_LOSSLESS => false, - self::O_IMG_OPTM_EXIF => false, - self::O_IMG_OPTM_WEBP_ATTR => array(), - self::O_IMG_OPTM_WEBP_REPLACE_SRCSET => false, - self::O_IMG_OPTM_JPG_QUALITY => 0, + self::O_IMG_OPTM_AUTO => false, + self::O_IMG_OPTM_CRON => false, + self::O_IMG_OPTM_ORI => false, + self::O_IMG_OPTM_RM_BKUP => false, + self::O_IMG_OPTM_WEBP => false, + self::O_IMG_OPTM_LOSSLESS => false, + self::O_IMG_OPTM_EXIF => false, + self::O_IMG_OPTM_WEBP_ATTR => array(), + self::O_IMG_OPTM_WEBP_REPLACE_SRCSET => false, + self::O_IMG_OPTM_JPG_QUALITY => 0, // Crawler - self::O_CRAWLER => false, - self::O_CRAWLER_USLEEP => 0, - self::O_CRAWLER_RUN_DURATION => 0, - self::O_CRAWLER_RUN_INTERVAL => 0, - self::O_CRAWLER_CRAWL_INTERVAL => 0, - self::O_CRAWLER_THREADS => 0, - self::O_CRAWLER_TIMEOUT => 0, - self::O_CRAWLER_LOAD_LIMIT => 0, - self::O_CRAWLER_SITEMAP => '', - self::O_CRAWLER_DROP_DOMAIN => false, - self::O_CRAWLER_MAP_TIMEOUT => 0, - self::O_CRAWLER_ROLES => array(), - self::O_CRAWLER_COOKIES => array(), + self::O_CRAWLER => false, + self::O_CRAWLER_USLEEP => 0, + self::O_CRAWLER_RUN_DURATION => 0, + self::O_CRAWLER_RUN_INTERVAL => 0, + self::O_CRAWLER_CRAWL_INTERVAL => 0, + self::O_CRAWLER_THREADS => 0, + self::O_CRAWLER_TIMEOUT => 0, + self::O_CRAWLER_LOAD_LIMIT => 0, + self::O_CRAWLER_SITEMAP => '', + self::O_CRAWLER_DROP_DOMAIN => false, + self::O_CRAWLER_MAP_TIMEOUT => 0, + self::O_CRAWLER_ROLES => array(), + self::O_CRAWLER_COOKIES => array(), // Misc - self::O_MISC_HEARTBEAT_FRONT => false, - self::O_MISC_HEARTBEAT_FRONT_TTL => 0, - self::O_MISC_HEARTBEAT_BACK => false, - self::O_MISC_HEARTBEAT_BACK_TTL => 0, - self::O_MISC_HEARTBEAT_EDITOR => false, - self::O_MISC_HEARTBEAT_EDITOR_TTL => 0, + self::O_MISC_HEARTBEAT_FRONT => false, + self::O_MISC_HEARTBEAT_FRONT_TTL => 0, + self::O_MISC_HEARTBEAT_BACK => false, + self::O_MISC_HEARTBEAT_BACK_TTL => 0, + self::O_MISC_HEARTBEAT_EDITOR => false, + self::O_MISC_HEARTBEAT_EDITOR_TTL => 0, // CDN - self::O_CDN => false, - self::O_CDN_ORI => array(), - self::O_CDN_ORI_DIR => array(), - self::O_CDN_EXC => array(), - self::O_CDN_QUIC => false, - self::O_CDN_CLOUDFLARE => false, + self::O_CDN => false, + self::O_CDN_ORI => array(), + self::O_CDN_ORI_DIR => array(), + self::O_CDN_EXC => array(), + self::O_CDN_QUIC => false, + self::O_CDN_CLOUDFLARE => false, self::O_CDN_CLOUDFLARE_EMAIL => '', - self::O_CDN_CLOUDFLARE_KEY => '', + self::O_CDN_CLOUDFLARE_KEY => '', self::O_CDN_CLOUDFLARE_NAME => '', self::O_CDN_CLOUDFLARE_ZONE => '', - self::O_CDN_MAPPING => array(), - self::O_CDN_ATTR => array(), - - self::O_QC_TOKEN => '', - self::O_QC_NAMESERVERS => '', + self::O_CDN_MAPPING => array(), + self::O_CDN_ATTR => array(), + self::O_QC_TOKEN => '', + self::O_QC_NAMESERVERS => '', ); protected static $_default_site_options = array( - self::_VER => '', - self::O_CACHE => false, - self::NETWORK_O_USE_PRIMARY => false, - self::O_AUTO_UPGRADE => false, - self::O_GUEST => false, - - self::O_CACHE_FAVICON => false, - self::O_CACHE_RES => false, - self::O_CACHE_BROWSER => false, - self::O_CACHE_MOBILE => false, - self::O_CACHE_MOBILE_RULES => array(), - self::O_CACHE_LOGIN_COOKIE => '', - self::O_CACHE_VARY_COOKIES => array(), - self::O_CACHE_EXC_COOKIES => array(), - self::O_CACHE_EXC_USERAGENTS => array(), - self::O_CACHE_TTL_BROWSER => 0, - - self::O_PURGE_ON_UPGRADE => false, - - self::O_OBJECT => false, - self::O_OBJECT_KIND => false, - self::O_OBJECT_HOST => '', - self::O_OBJECT_PORT => 0, - self::O_OBJECT_LIFE => 0, - self::O_OBJECT_PERSISTENT => false, - self::O_OBJECT_ADMIN => false, - self::O_OBJECT_TRANSIENTS => false, - self::O_OBJECT_DB_ID => 0, - self::O_OBJECT_USER => '', - self::O_OBJECT_PSWD => '', - self::O_OBJECT_GLOBAL_GROUPS => array(), + self::_VER => '', + self::O_CACHE => false, + self::NETWORK_O_USE_PRIMARY => false, + self::O_AUTO_UPGRADE => false, + self::O_GUEST => false, + + self::O_CACHE_FAVICON => false, + self::O_CACHE_RES => false, + self::O_CACHE_BROWSER => false, + self::O_CACHE_MOBILE => false, + self::O_CACHE_MOBILE_RULES => array(), + self::O_CACHE_LOGIN_COOKIE => '', + self::O_CACHE_VARY_COOKIES => array(), + self::O_CACHE_EXC_COOKIES => array(), + self::O_CACHE_EXC_USERAGENTS => array(), + self::O_CACHE_TTL_BROWSER => 0, + + self::O_PURGE_ON_UPGRADE => false, + + self::O_OBJECT => false, + self::O_OBJECT_KIND => false, + self::O_OBJECT_HOST => '', + self::O_OBJECT_PORT => 0, + self::O_OBJECT_LIFE => 0, + self::O_OBJECT_PERSISTENT => false, + self::O_OBJECT_ADMIN => false, + self::O_OBJECT_TRANSIENTS => false, + self::O_OBJECT_DB_ID => 0, + self::O_OBJECT_USER => '', + self::O_OBJECT_PSWD => '', + self::O_OBJECT_GLOBAL_GROUPS => array(), self::O_OBJECT_NON_PERSISTENT_GROUPS => array(), // Debug - self::O_DEBUG_DISABLE_ALL => false, - self::O_DEBUG => false, - self::O_DEBUG_IPS => array(), - self::O_DEBUG_LEVEL => false, - self::O_DEBUG_FILESIZE => 0, - self::O_DEBUG_COOKIE => false, - self::O_DEBUG_COLLAPS_QS => false, - self::O_DEBUG_INC => array(), - self::O_DEBUG_EXC => array(), - self::O_DEBUG_EXC_STRINGS => array(), - - self::O_IMG_OPTM_WEBP => false, - + self::O_DEBUG_DISABLE_ALL => false, + self::O_DEBUG => false, + self::O_DEBUG_IPS => array(), + self::O_DEBUG_LEVEL => false, + self::O_DEBUG_FILESIZE => 0, + self::O_DEBUG_COOKIE => false, + self::O_DEBUG_COLLAPS_QS => false, + self::O_DEBUG_INC => array(), + self::O_DEBUG_EXC => array(), + self::O_DEBUG_EXC_STRINGS => array(), + + self::O_IMG_OPTM_WEBP => false, ); // NOTE: all the val of following items will be int while not bool protected static $_multi_switch_list = array( - self::O_DEBUG => 2, - self::O_OPTM_JS_DEFER => 2, + self::O_DEBUG => 2, + self::O_OPTM_JS_DEFER => 2, ); - /** * Correct the option type * @@ -725,7 +722,8 @@ public function load_default_vals() self::CDN_MAPPING_FILETYPE, // Array ); $ini_v2 = array(); - foreach ($ini_v[self::CDN_MAPPING_URL] as $k2 => $v2) { // $k2 is numeric + foreach ($ini_v[self::CDN_MAPPING_URL] as $k2 => $v2) { + // $k2 is numeric $this_row = array(); foreach ($mapping_fields as $v3) { $this_v = !empty($ini_v[$v3][$k2]) ? $ini_v[$v3][$k2] : false; @@ -827,22 +825,22 @@ public static function conf_const($id) protected function _conf_filter($id) { $filters = array( - self::O_MEDIA_LAZY_EXC => 'uri', - self::O_DEBUG_INC => 'relative', - self::O_DEBUG_EXC => 'relative', - self::O_MEDIA_LAZY_URI_EXC => 'relative', - self::O_CACHE_PRIV_URI => 'relative', - self::O_PURGE_TIMED_URLS => 'relative', - self::O_CACHE_FORCE_URI => 'relative', - self::O_CACHE_FORCE_PUB_URI => 'relative', - self::O_CACHE_EXC => 'relative', + self::O_MEDIA_LAZY_EXC => 'uri', + self::O_DEBUG_INC => 'relative', + self::O_DEBUG_EXC => 'relative', + self::O_MEDIA_LAZY_URI_EXC => 'relative', + self::O_CACHE_PRIV_URI => 'relative', + self::O_PURGE_TIMED_URLS => 'relative', + self::O_CACHE_FORCE_URI => 'relative', + self::O_CACHE_FORCE_PUB_URI => 'relative', + self::O_CACHE_EXC => 'relative', // self::O_OPTM_CSS_EXC => 'uri', // Need to comment out for inline & external CSS // self::O_OPTM_JS_EXC => 'uri', - self::O_OPTM_EXC => 'relative', - self::O_OPTM_CCSS_SEP_URI => 'uri', + self::O_OPTM_EXC => 'relative', + self::O_OPTM_CCSS_SEP_URI => 'uri', // self::O_OPTM_JS_DEFER_EXC => 'uri', - self::O_OPTM_DNS_PREFETCH => 'domain', - self::O_CDN_ORI => 'noprotocol,trailingslash', // `Original URLs` + self::O_OPTM_DNS_PREFETCH => 'domain', + self::O_CDN_ORI => 'noprotocol,trailingslash', // `Original URLs` // self::O_OPTM_LOCALIZE_DOMAINS => 'noprotocol', // `Localize Resources` // self:: => '', // self:: => '', @@ -882,12 +880,7 @@ protected function _conf_purge($id) */ protected function _conf_purge_all($id) { - $check_ids = array( - self::O_CACHE, - self::O_ESI, - self::O_DEBUG_DISABLE_ALL, - self::NETWORK_O_USE_PRIMARY, - ); + $check_ids = array(self::O_CACHE, self::O_ESI, self::O_DEBUG_DISABLE_ALL, self::NETWORK_O_USE_PRIMARY); return in_array($id, $check_ids); } @@ -899,12 +892,7 @@ protected function _conf_purge_all($id) */ protected function _conf_pswd($id) { - $check_ids = array( - self::O_CDN_CLOUDFLARE_KEY, - self::O_OBJECT_PSWD, - self::O_API_KEY, - self::O_QC_TOKEN, - ); + $check_ids = array(self::O_CDN_CLOUDFLARE_KEY, self::O_OBJECT_PSWD, self::O_API_KEY, self::O_QC_TOKEN); return in_array($id, $check_ids); } @@ -936,7 +924,7 @@ protected function _conf_cron($id) protected function _conf_purge_tag($id) { $check_ids = array( - self::O_CACHE_PAGE_LOGIN => Tag::TYPE_LOGIN, + self::O_CACHE_PAGE_LOGIN => Tag::TYPE_LOGIN, ); if (!empty($check_ids[$id])) { @@ -971,7 +959,7 @@ public function server_vars() ); $server_vars = array(); foreach ($consts as $v) { - $server_vars[$v] = defined($v) ? constant($v) : NULL; + $server_vars[$v] = defined($v) ? constant($v) : null; } return $server_vars; diff --git a/src/cdn-setup.cls.php b/src/cdn-setup.cls.php index 11402b717..d77b0b829 100644 --- a/src/cdn-setup.cls.php +++ b/src/cdn-setup.cls.php @@ -8,18 +8,18 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Cdn_Setup extends Base { const LOG_TAG = '👷'; - const TYPE_LINK = 'link'; - const TYPE_NOLINK = 'nolink'; - const TYPE_RUN = 'setup'; - const TYPE_STATUS = 'status'; - const TYPE_RESET = 'reset'; - const TYPE_DELETE = 'delete'; + const TYPE_LINK = 'link'; + const TYPE_NOLINK = 'nolink'; + const TYPE_RUN = 'setup'; + const TYPE_STATUS = 'status'; + const TYPE_RESET = 'reset'; + const TYPE_DELETE = 'delete'; private $_setup_token; protected $_summary; @@ -42,7 +42,7 @@ public function __construct() */ public function maybe_extract_token() { - $params = $this->cls('Cloud')->parse_qc_redir(['token']); + $params = $this->cls('Cloud')->parse_qc_redir(array('token')); if (isset($params['token'])) { $this->_setup_token = $params['token']; @@ -92,12 +92,11 @@ public function update_cdn_status() */ private function _qc_refresh() { - $json = $this->cls('Cloud')->req_rest_api('/user/cdn/status'); if (!$json) { return; - } else if (is_string($json)) { + } elseif (is_string($json)) { self::save_summary(array('cdn_setup_err' => $json)); return; } @@ -117,7 +116,6 @@ private function _qc_refresh() */ private function _process_cdn_status($result) { - if (isset($result['nameservers'])) { if (isset($this->_summary['cdn_setup_err'])) { unset($this->_summary['cdn_setup_err']); @@ -128,8 +126,10 @@ private function _process_cdn_status($result) $this->cls('Cloud')->set_linked(); $nameservers = esc_html($result['nameservers']); $this->cls('Conf')->update_confs(array(self::O_QC_NAMESERVERS => $nameservers, self::O_CDN_QUIC => true)); - Admin_Display::succeed('🎊 ' . __('Congratulations, QUIC.cloud successfully set this domain up for the CDN. Please update your nameservers to:', 'litespeed-cache') . $nameservers); - } else if (isset($result['done'])) { + Admin_Display::succeed( + '🎊 ' . __('Congratulations, QUIC.cloud successfully set this domain up for the CDN. Please update your nameservers to:', 'litespeed-cache') . $nameservers + ); + } elseif (isset($result['done'])) { if (isset($this->_summary['cdn_setup_err'])) { unset($this->_summary['cdn_setup_err']); } @@ -140,7 +140,7 @@ private function _process_cdn_status($result) $this->_setup_token = ''; $this->cls('Conf')->update_confs(array(self::O_QC_TOKEN => '', self::O_QC_NAMESERVERS => '')); - } else if (isset($result['_msg'])) { + } elseif (isset($result['_msg'])) { $notice = esc_html($result['_msg']); if ($this->conf(Base::O_QC_NAMESERVERS)) { $this->_summary['cdn_verify_msg'] = $notice; @@ -176,18 +176,16 @@ private function _qc_reset($delete) if (!$json) { return; - } else if (is_string($json) && $json != 'unauthorized access to REST API.') { + } elseif (is_string($json) && $json != 'unauthorized access to REST API.') { self::save_summary(array('cdn_setup_err' => $json)); return; } - } else if (!isset($this->_summary['cdn_setup_done_ts']) || !$this->_summary['cdn_setup_done_ts']) { + } elseif (!isset($this->_summary['cdn_setup_done_ts']) || !$this->_summary['cdn_setup_done_ts']) { Admin_Display::info(__('Notice: CDN Setup only reset locally.', 'litespeed-cache')); - } else if (!Cloud::get_summary('is_linked')) { - + } elseif (!Cloud::get_summary('is_linked')) { Admin_Display::error(__('Cannot delete, site is not linked.', 'litespeed-cache')); return; } else { - $json = Cloud::post(Cloud::SVC_D_DEL_CDN_DNS, $data); if (!is_array($json)) { @@ -216,9 +214,15 @@ private function _qc_reset($delete) $this->cls('Conf')->update_confs(array(self::O_QC_TOKEN => '', self::O_QC_NAMESERVERS => '', self::O_CDN_QUIC => false)); $msg = ''; if ($delete) { - $msg = __('CDN Setup Token and DNS zone deleted. Note: if my.quic.cloud account deletion is desired, that the account still exists and must be deleted separately.', 'litespeed-cache'); + $msg = __( + 'CDN Setup Token and DNS zone deleted. Note: if my.quic.cloud account deletion is desired, that the account still exists and must be deleted separately.', + 'litespeed-cache' + ); } else { - $msg = __('CDN Setup Token reset. Note: if my.quic.cloud account deletion is desired, that the account still exists and must be deleted separately.', 'litespeed-cache'); + $msg = __( + 'CDN Setup Token reset. Note: if my.quic.cloud account deletion is desired, that the account still exists and must be deleted separately.', + 'litespeed-cache' + ); } Admin_Display::succeed($msg); return self::ok(); @@ -248,8 +252,8 @@ private function _qc_link() } $data = array( - 'site_url' => home_url(), - 'ref' => get_admin_url(null, 'admin.php?page=litespeed-cdn'), + 'site_url' => home_url(), + 'ref' => get_admin_url(null, 'admin.php?page=litespeed-cdn'), ); $api_key = $this->conf(self::O_API_KEY); if ($api_key) { @@ -257,7 +261,7 @@ private function _qc_link() } wp_redirect(Cloud::CLOUD_SERVER_DASH . '/u/wptoken?data=' . Utility::arr2str($data)); - exit; + exit(); } /** @@ -274,7 +278,7 @@ private function _qc_nolink() } $data = array( - 'site_url' => home_url(), + 'site_url' => home_url(), ); $json = Cloud::post(Cloud::SVC_D_SETUP_TOKEN, $data); @@ -293,11 +297,10 @@ private function _qc_nolink() */ private function _qc_run() { - $data = array( 'site_url' => home_url(), - 'rest' => function_exists('rest_get_url_prefix') ? rest_get_url_prefix() : apply_filters('rest_url_prefix', 'wp-json'), - 'server_ip' => $this->conf(self::O_SERVER_IP), + 'rest' => function_exists('rest_get_url_prefix') ? rest_get_url_prefix() : apply_filters('rest_url_prefix', 'wp-json'), + 'server_ip' => $this->conf(self::O_SERVER_IP), ); $api_key = $this->conf(self::O_API_KEY); @@ -310,7 +313,7 @@ private function _qc_run() if (!$json) { return; - } else if (is_string($json)) { + } elseif (is_string($json)) { self::save_summary(array('cdn_setup_err' => $json)); return; } @@ -382,7 +385,6 @@ public function handler() $type = Router::verify_type(); switch ($type) { - case self::TYPE_LINK: $this->_qc_link(); break; diff --git a/src/cdn.cls.php b/src/cdn.cls.php index 8bbe7c5a5..36543562b 100644 --- a/src/cdn.cls.php +++ b/src/cdn.cls.php @@ -10,9 +10,10 @@ */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class CDN extends Root { +class CDN extends Root +{ const BYPASS = 'LITESPEED_BYPASS_CDN'; private $content; @@ -30,108 +31,105 @@ class CDN extends Root { * * @since 1.2.3 */ - public function init() { - Debug2::debug2( '[CDN] init' ); + public function init() + { + Debug2::debug2('[CDN] init'); - if ( defined( self::BYPASS ) ) { - Debug2::debug2( 'CDN bypass' ); + if (defined(self::BYPASS)) { + Debug2::debug2('CDN bypass'); return; } - if ( ! Router::can_cdn() ) { - if ( ! defined( self::BYPASS ) ) { - define( self::BYPASS, true ); + if (!Router::can_cdn()) { + if (!defined(self::BYPASS)) { + define(self::BYPASS, true); } return; } - $this->_cfg_cdn = $this->conf( Base::O_CDN ); - if ( ! $this->_cfg_cdn ) { - if ( ! defined( self::BYPASS ) ) { - define( self::BYPASS, true ); + $this->_cfg_cdn = $this->conf(Base::O_CDN); + if (!$this->_cfg_cdn) { + if (!defined(self::BYPASS)) { + define(self::BYPASS, true); } return; } - $this->_cfg_url_ori = $this->conf( Base::O_CDN_ORI ); + $this->_cfg_url_ori = $this->conf(Base::O_CDN_ORI); // Parse cdn mapping data to array( 'filetype' => 'url' ) - $mapping_to_check = array( - Base::CDN_MAPPING_INC_IMG, - Base::CDN_MAPPING_INC_CSS, - Base::CDN_MAPPING_INC_JS - ); - foreach ( $this->conf( Base::O_CDN_MAPPING ) as $v ) { - if ( ! $v[ Base::CDN_MAPPING_URL ] ) { + $mapping_to_check = array(Base::CDN_MAPPING_INC_IMG, Base::CDN_MAPPING_INC_CSS, Base::CDN_MAPPING_INC_JS); + foreach ($this->conf(Base::O_CDN_MAPPING) as $v) { + if (!$v[Base::CDN_MAPPING_URL]) { continue; } - $this_url = $v[ Base::CDN_MAPPING_URL ]; - $this_host = parse_url( $this_url, PHP_URL_HOST ); + $this_url = $v[Base::CDN_MAPPING_URL]; + $this_host = parse_url($this_url, PHP_URL_HOST); // Check img/css/js - foreach ( $mapping_to_check as $to_check ) { - if ( $v[ $to_check ] ) { - Debug2::debug2( '[CDN] mapping ' . $to_check . ' -> ' . $this_url ); + foreach ($mapping_to_check as $to_check) { + if ($v[$to_check]) { + Debug2::debug2('[CDN] mapping ' . $to_check . ' -> ' . $this_url); // If filetype to url is one to many, make url be an array - $this->_append_cdn_mapping( $to_check, $this_url ); + $this->_append_cdn_mapping($to_check, $this_url); - if ( ! in_array( $this_host, $this->cdn_mapping_hosts ) ) { + if (!in_array($this_host, $this->cdn_mapping_hosts)) { $this->cdn_mapping_hosts[] = $this_host; } } } // Check file types - if ( $v[ Base::CDN_MAPPING_FILETYPE ] ) { - foreach ( $v[ Base::CDN_MAPPING_FILETYPE ] as $v2 ) { - $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_FILETYPE ] = true; + if ($v[Base::CDN_MAPPING_FILETYPE]) { + foreach ($v[Base::CDN_MAPPING_FILETYPE] as $v2) { + $this->_cfg_cdn_mapping[Base::CDN_MAPPING_FILETYPE] = true; // If filetype to url is one to many, make url be an array - $this->_append_cdn_mapping( $v2, $this_url ); + $this->_append_cdn_mapping($v2, $this_url); - if ( ! in_array( $this_host, $this->cdn_mapping_hosts ) ) { + if (!in_array($this_host, $this->cdn_mapping_hosts)) { $this->cdn_mapping_hosts[] = $this_host; } } - Debug2::debug2( '[CDN] mapping ' . implode( ',', $v[ Base::CDN_MAPPING_FILETYPE ] ) . ' -> ' . $this_url ); + Debug2::debug2('[CDN] mapping ' . implode(',', $v[Base::CDN_MAPPING_FILETYPE]) . ' -> ' . $this_url); } } - if ( ! $this->_cfg_url_ori || ! $this->_cfg_cdn_mapping ) { - if ( ! defined( self::BYPASS ) ) { - define( self::BYPASS, true ); + if (!$this->_cfg_url_ori || !$this->_cfg_cdn_mapping) { + if (!defined(self::BYPASS)) { + define(self::BYPASS, true); } return; } - $this->_cfg_ori_dir = $this->conf( Base::O_CDN_ORI_DIR ); + $this->_cfg_ori_dir = $this->conf(Base::O_CDN_ORI_DIR); // In case user customized upload path - if ( defined( 'UPLOADS' ) ) { + if (defined('UPLOADS')) { $this->_cfg_ori_dir[] = UPLOADS; } // Check if need preg_replace - $this->_cfg_url_ori = Utility::wildcard2regex( $this->_cfg_url_ori ); + $this->_cfg_url_ori = Utility::wildcard2regex($this->_cfg_url_ori); - $this->_cfg_cdn_exclude = $this->conf( Base::O_CDN_EXC ); + $this->_cfg_cdn_exclude = $this->conf(Base::O_CDN_EXC); - if ( ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_IMG ] ) ) { + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_IMG])) { // Hook to srcset - if ( function_exists( 'wp_calculate_image_srcset' ) ) { - add_filter( 'wp_calculate_image_srcset', array( $this, 'srcset' ), 999 ); + if (function_exists('wp_calculate_image_srcset')) { + add_filter('wp_calculate_image_srcset', array($this, 'srcset'), 999); } // Hook to mime icon - add_filter( 'wp_get_attachment_image_src', array( $this, 'attach_img_src' ), 999 ); - add_filter( 'wp_get_attachment_url', array( $this, 'url_img' ), 999 ); + add_filter('wp_get_attachment_image_src', array($this, 'attach_img_src'), 999); + add_filter('wp_get_attachment_url', array($this, 'url_img'), 999); } - if ( ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_CSS ] ) ) { - add_filter( 'style_loader_src', array( $this, 'url_css' ), 999 ); + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS])) { + add_filter('style_loader_src', array($this, 'url_css'), 999); } - if ( ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_JS ] ) ) { - add_filter( 'script_loader_src', array( $this, 'url_js' ), 999 ); + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS])) { + add_filter('script_loader_src', array($this, 'url_js'), 999); } - add_filter( 'litespeed_buffer_finalize', array( $this, 'finalize' ), 30 ); + add_filter('litespeed_buffer_finalize', array($this, 'finalize'), 30); } /** @@ -140,18 +138,17 @@ public function init() { * @since 2.0 * @access private */ - private function _append_cdn_mapping( $filetype, $url ) { + private function _append_cdn_mapping($filetype, $url) + { // If filetype to url is one to many, make url be an array - if ( empty( $this->_cfg_cdn_mapping[ $filetype ] ) ) { - $this->_cfg_cdn_mapping[ $filetype ] = $url; - } - elseif ( is_array( $this->_cfg_cdn_mapping[ $filetype ] ) ) { + if (empty($this->_cfg_cdn_mapping[$filetype])) { + $this->_cfg_cdn_mapping[$filetype] = $url; + } elseif (is_array($this->_cfg_cdn_mapping[$filetype])) { // Append url to filetype - $this->_cfg_cdn_mapping[ $filetype ][] = $url; - } - else { + $this->_cfg_cdn_mapping[$filetype][] = $url; + } else { // Convert _cfg_cdn_mapping from string to array - $this->_cfg_cdn_mapping[ $filetype ] = array( $this->_cfg_cdn_mapping[ $filetype ], $url ); + $this->_cfg_cdn_mapping[$filetype] = array($this->_cfg_cdn_mapping[$filetype], $url); } } @@ -161,12 +158,13 @@ private function _append_cdn_mapping( $filetype, $url ) { * @since 1.6.2.1 * @return bool true if included in CDN */ - public function inc_type( $type ) { - if ( $type == 'css' && ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_CSS ] ) ) { + public function inc_type($type) + { + if ($type == 'css' && !empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS])) { return true; } - if ( $type == 'js' && ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_JS ] ) ) { + if ($type == 'js' && !empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS])) { return true; } @@ -181,7 +179,8 @@ public function inc_type( $type ) { * @access public * @return string The content that is after optimization */ - public function finalize( $content ) { + public function finalize($content) + { $this->content = $content; $this->_finalize(); @@ -194,23 +193,23 @@ public function finalize( $content ) { * @since 1.2.3 * @access private */ - private function _finalize() { - if ( defined( self::BYPASS ) ) { + private function _finalize() + { + if (defined(self::BYPASS)) { return; } - Debug2::debug( 'CDN _finalize' ); + Debug2::debug('CDN _finalize'); // Start replacing img src - if ( ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_IMG ] ) ) { + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_IMG])) { $this->_replace_img(); $this->_replace_inline_css(); } - if ( ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_FILETYPE ] ) ) { + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_FILETYPE])) { $this->_replace_file_types(); } - } /** @@ -219,48 +218,48 @@ private function _finalize() { * @since 1.2.3 * @access private */ - private function _replace_file_types() { - $ele_to_check = $this->conf( Base::O_CDN_ATTR ); + private function _replace_file_types() + { + $ele_to_check = $this->conf(Base::O_CDN_ATTR); - foreach ( $ele_to_check as $v ) { - if ( ! $v || strpos( $v, '.' ) === false ) { - Debug2::debug2( '[CDN] replace setting bypassed: no . attribute ' . $v ); + foreach ($ele_to_check as $v) { + if (!$v || strpos($v, '.') === false) { + Debug2::debug2('[CDN] replace setting bypassed: no . attribute ' . $v); continue; } - Debug2::debug2( '[CDN] replace attribute ' . $v ); + Debug2::debug2('[CDN] replace attribute ' . $v); - $v = explode( '.', $v ); - $attr = preg_quote( $v[ 1 ], '#' ); - if ( $v[ 0 ] ) { - $pattern = '#<' . preg_quote( $v[ 0 ], '#' ) . '([^>]+)' . $attr . '=([\'"])(.+)\g{2}#iU'; - } - else { + $v = explode('.', $v); + $attr = preg_quote($v[1], '#'); + if ($v[0]) { + $pattern = '#<' . preg_quote($v[0], '#') . '([^>]+)' . $attr . '=([\'"])(.+)\g{2}#iU'; + } else { $pattern = '# ' . $attr . '=([\'"])(.+)\g{1}#iU'; } - preg_match_all( $pattern, $this->content, $matches ); + preg_match_all($pattern, $this->content, $matches); - if ( empty( $matches[ $v[ 0 ] ? 3 : 2 ] ) ) { + if (empty($matches[$v[0] ? 3 : 2])) { continue; } - foreach ( $matches[ $v[ 0 ] ? 3 : 2 ] as $k2 => $url ) { + foreach ($matches[$v[0] ? 3 : 2] as $k2 => $url) { // Debug2::debug2( '[CDN] check ' . $url ); - $postfix = '.' . pathinfo( (string) parse_url( $url, PHP_URL_PATH ), PATHINFO_EXTENSION ); - if ( ! array_key_exists( $postfix, $this->_cfg_cdn_mapping ) ) { + $postfix = '.' . pathinfo((string) parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION); + if (!array_key_exists($postfix, $this->_cfg_cdn_mapping)) { // Debug2::debug2( '[CDN] non-existed postfix ' . $postfix ); continue; } - Debug2::debug2( '[CDN] matched file_type ' . $postfix . ' : ' . $url ); + Debug2::debug2('[CDN] matched file_type ' . $postfix . ' : ' . $url); - if( ! $url2 = $this->rewrite( $url, Base::CDN_MAPPING_FILETYPE, $postfix ) ) { + if (!($url2 = $this->rewrite($url, Base::CDN_MAPPING_FILETYPE, $postfix))) { continue; } - $attr = str_replace( $url, $url2, $matches[ 0 ][ $k2 ] ); - $this->content = str_replace( $matches[ 0 ][ $k2 ], $attr, $this->content ); + $attr = str_replace($url, $url2, $matches[0][$k2]); + $this->content = str_replace($matches[0][$k2], $attr, $this->content); } } } @@ -271,25 +270,21 @@ private function _replace_file_types() { * @since 1.2.3 * @access private */ - private function _replace_img() { - preg_match_all( '#]+?)src=([\'"\\\]*)([^\'"\s\\\>]+)([\'"\\\]*)([^>]*)>#i', $this->content, $matches ); - foreach ( $matches[ 3 ] as $k => $url ) { + private function _replace_img() + { + preg_match_all('#]+?)src=([\'"\\\]*)([^\'"\s\\\>]+)([\'"\\\]*)([^>]*)>#i', $this->content, $matches); + foreach ($matches[3] as $k => $url) { // Check if is a DATA-URI - if ( strpos( $url, 'data:image' ) !== false ) { + if (strpos($url, 'data:image') !== false) { continue; } - if ( ! $url2 = $this->rewrite( $url, Base::CDN_MAPPING_INC_IMG ) ) { + if (!($url2 = $this->rewrite($url, Base::CDN_MAPPING_INC_IMG))) { continue; } - $html_snippet = sprintf( - '', - $matches[ 1 ][ $k ], - $matches[ 2 ][ $k ] . $url2 . $matches[ 4 ][ $k ], - $matches[ 5 ][ $k ] - ); - $this->content = str_replace( $matches[ 0 ][ $k ], $html_snippet, $this->content ); + $html_snippet = sprintf('', $matches[1][$k], $matches[2][$k] . $url2 . $matches[4][$k], $matches[5][$k]); + $this->content = str_replace($matches[0][$k], $html_snippet, $this->content); } } @@ -299,8 +294,9 @@ private function _replace_img() { * @since 1.2.3 * @access private */ - private function _replace_inline_css() { - Debug2::debug2( '[CDN] _replace_inline_css', $this->_cfg_cdn_mapping ); + private function _replace_inline_css() + { + Debug2::debug2('[CDN] _replace_inline_css', $this->_cfg_cdn_mapping); /** * Excludes `\` from URL matching @@ -308,26 +304,25 @@ private function _replace_inline_css() { * @see #685485 * @since 3.0 */ - preg_match_all( '/url\((?![\'"]?data)[\'"]?([^\)\'"\\\]+)[\'"]?\)/i', $this->content, $matches ); - foreach ( $matches[ 1 ] as $k => $url ) { - $url = str_replace( array( ' ', '\t', '\n', '\r', '\0', '\x0B', '"', "'", '"', ''' ), '', $url ); + preg_match_all('/url\((?![\'"]?data)[\'"]?([^\)\'"\\\]+)[\'"]?\)/i', $this->content, $matches); + foreach ($matches[1] as $k => $url) { + $url = str_replace(array(' ', '\t', '\n', '\r', '\0', '\x0B', '"', "'", '"', '''), '', $url); // Parse file postfix - $postfix = '.' . pathinfo( parse_url( $url, PHP_URL_PATH ), PATHINFO_EXTENSION ); - if ( array_key_exists( $postfix, $this->_cfg_cdn_mapping ) ) { - Debug2::debug2( '[CDN] matched file_type ' . $postfix . ' : ' . $url ); - if( ! $url2 = $this->rewrite( $url, Base::CDN_MAPPING_FILETYPE, $postfix ) ) { + $postfix = '.' . pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION); + if (array_key_exists($postfix, $this->_cfg_cdn_mapping)) { + Debug2::debug2('[CDN] matched file_type ' . $postfix . ' : ' . $url); + if (!($url2 = $this->rewrite($url, Base::CDN_MAPPING_FILETYPE, $postfix))) { continue; } - } - else { - if ( ! $url2 = $this->rewrite( $url, Base::CDN_MAPPING_INC_IMG ) ) { + } else { + if (!($url2 = $this->rewrite($url, Base::CDN_MAPPING_INC_IMG))) { continue; } } - $attr = str_replace( $matches[ 1 ][ $k ], $url2, $matches[ 0 ][ $k ] ); - $this->content = str_replace( $matches[ 0 ][ $k ], $attr, $this->content ); + $attr = str_replace($matches[1][$k], $url2, $matches[0][$k]); + $this->content = str_replace($matches[0][$k], $attr, $this->content); } } @@ -340,9 +335,10 @@ private function _replace_inline_css() { * @param array $img The URL of the attachment image src, the width, the height * @return array */ - public function attach_img_src( $img ) { - if ( $img && $url = $this->rewrite( $img[ 0 ], Base::CDN_MAPPING_INC_IMG ) ) { - $img[ 0 ] = $url; + public function attach_img_src($img) + { + if ($img && ($url = $this->rewrite($img[0], Base::CDN_MAPPING_INC_IMG))) { + $img[0] = $url; } return $img; } @@ -353,8 +349,9 @@ public function attach_img_src( $img ) { * @since 1.7 * @access public */ - public function url_img( $url ) { - if ( $url && $url2 = $this->rewrite( $url, Base::CDN_MAPPING_INC_IMG ) ) { + public function url_img($url) + { + if ($url && ($url2 = $this->rewrite($url, Base::CDN_MAPPING_INC_IMG))) { $url = $url2; } return $url; @@ -366,8 +363,9 @@ public function url_img( $url ) { * @since 1.7 * @access public */ - public function url_css( $url ) { - if ( $url && $url2 = $this->rewrite( $url, Base::CDN_MAPPING_INC_CSS ) ) { + public function url_css($url) + { + if ($url && ($url2 = $this->rewrite($url, Base::CDN_MAPPING_INC_CSS))) { $url = $url2; } return $url; @@ -379,8 +377,9 @@ public function url_css( $url ) { * @since 1.7 * @access public */ - public function url_js( $url ) { - if ( $url && $url2 = $this->rewrite( $url, Base::CDN_MAPPING_INC_JS ) ) { + public function url_js($url) + { + if ($url && ($url2 = $this->rewrite($url, Base::CDN_MAPPING_INC_JS))) { $url = $url2; } return $url; @@ -395,13 +394,14 @@ public function url_js( $url ) { * @param array $srcs * @return array */ - public function srcset( $srcs ) { - if ( $srcs ) { - foreach ( $srcs as $w => $data ) { - if( ! $url = $this->rewrite( $data[ 'url' ], Base::CDN_MAPPING_INC_IMG ) ) { + public function srcset($srcs) + { + if ($srcs) { + foreach ($srcs as $w => $data) { + if (!($url = $this->rewrite($data['url'], Base::CDN_MAPPING_INC_IMG))) { continue; } - $srcs[ $w ][ 'url' ] = $url; + $srcs[$w]['url'] = $url; } } return $srcs; @@ -415,76 +415,75 @@ public function srcset( $srcs ) { * @param string $url * @return string Replaced URL */ - public function rewrite( $url, $mapping_kind, $postfix = false ) { - Debug2::debug2( '[CDN] rewrite ' . $url ); - $url_parsed = parse_url( $url ); + public function rewrite($url, $mapping_kind, $postfix = false) + { + Debug2::debug2('[CDN] rewrite ' . $url); + $url_parsed = parse_url($url); - if ( empty( $url_parsed[ 'path' ] ) ) { - Debug2::debug2( '[CDN] -rewrite bypassed: no path' ); + if (empty($url_parsed['path'])) { + Debug2::debug2('[CDN] -rewrite bypassed: no path'); return false; } // Only images under wp-cotnent/wp-includes can be replaced - $is_internal_folder = Utility::str_hit_array( $url_parsed[ 'path' ], $this->_cfg_ori_dir ); - if ( ! $is_internal_folder ) { - Debug2::debug2( '[CDN] -rewrite failed: path not match: ' . LSCWP_CONTENT_FOLDER ); + $is_internal_folder = Utility::str_hit_array($url_parsed['path'], $this->_cfg_ori_dir); + if (!$is_internal_folder) { + Debug2::debug2('[CDN] -rewrite failed: path not match: ' . LSCWP_CONTENT_FOLDER); return false; } // Check if is external url - if ( ! empty( $url_parsed[ 'host' ] ) ) { - if ( ! Utility::internal( $url_parsed[ 'host' ] ) && ! $this->_is_ori_url( $url ) ) { - Debug2::debug2( '[CDN] -rewrite failed: host not internal' ); + if (!empty($url_parsed['host'])) { + if (!Utility::internal($url_parsed['host']) && !$this->_is_ori_url($url)) { + Debug2::debug2('[CDN] -rewrite failed: host not internal'); return false; } } - $exclude = Utility::str_hit_array( $url, $this->_cfg_cdn_exclude ); - if ( $exclude ) { - Debug2::debug2( '[CDN] -abort excludes ' . $exclude ); + $exclude = Utility::str_hit_array($url, $this->_cfg_cdn_exclude); + if ($exclude) { + Debug2::debug2('[CDN] -abort excludes ' . $exclude); return false; } // Fill full url before replacement - if ( empty( $url_parsed[ 'host' ] ) ) { - $url = Utility::uri2url( $url ); - Debug2::debug2( '[CDN] -fill before rewritten: ' . $url ); + if (empty($url_parsed['host'])) { + $url = Utility::uri2url($url); + Debug2::debug2('[CDN] -fill before rewritten: ' . $url); - $url_parsed = parse_url( $url ); + $url_parsed = parse_url($url); } - $scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : ''; - if ( $scheme ) { + $scheme = !empty($url_parsed['scheme']) ? $url_parsed['scheme'] . ':' : ''; + if ($scheme) { // Debug2::debug2( '[CDN] -scheme from url: ' . $scheme ); } // Find the mapping url to be replaced to - if ( empty( $this->_cfg_cdn_mapping[ $mapping_kind ] ) ) { + if (empty($this->_cfg_cdn_mapping[$mapping_kind])) { return false; } - if ( $mapping_kind !== Base::CDN_MAPPING_FILETYPE ) { - $final_url = $this->_cfg_cdn_mapping[ $mapping_kind ]; - } - else { + if ($mapping_kind !== Base::CDN_MAPPING_FILETYPE) { + $final_url = $this->_cfg_cdn_mapping[$mapping_kind]; + } else { // select from file type - $final_url = $this->_cfg_cdn_mapping[ $postfix ]; + $final_url = $this->_cfg_cdn_mapping[$postfix]; } // If filetype to url is one to many, need to random one - if ( is_array( $final_url ) ) { - $final_url = $final_url[ mt_rand( 0, count( $final_url ) - 1 ) ]; + if (is_array($final_url)) { + $final_url = $final_url[mt_rand(0, count($final_url) - 1)]; } // Now lets replace CDN url - foreach ( $this->_cfg_url_ori as $v ) { - if ( strpos( $v, '*' ) !== false ) { - $url = preg_replace( '#' . $scheme . $v . '#iU', $final_url, $url ); - } - else { - $url = str_replace( $scheme . $v, $final_url, $url ); + foreach ($this->_cfg_url_ori as $v) { + if (strpos($v, '*') !== false) { + $url = preg_replace('#' . $scheme . $v . '#iU', $final_url, $url); + } else { + $url = str_replace($scheme . $v, $final_url, $url); } } - Debug2::debug2( '[CDN] -rewritten: ' . $url ); + Debug2::debug2('[CDN] -rewritten: ' . $url); return $url; } @@ -495,20 +494,20 @@ public function rewrite( $url, $mapping_kind, $postfix = false ) { * @since 2.1 * @access private */ - private function _is_ori_url( $url ) { - $url_parsed = parse_url( $url ); + private function _is_ori_url($url) + { + $url_parsed = parse_url($url); - $scheme = ! empty( $url_parsed[ 'scheme' ] ) ? $url_parsed[ 'scheme' ] . ':' : ''; + $scheme = !empty($url_parsed['scheme']) ? $url_parsed['scheme'] . ':' : ''; - foreach ( $this->_cfg_url_ori as $v ) { + foreach ($this->_cfg_url_ori as $v) { $needle = $scheme . $v; - if ( strpos( $v, '*' ) !== false ) { - if( preg_match( '#' . $needle . '#iU', $url ) ) { + if (strpos($v, '*') !== false) { + if (preg_match('#' . $needle . '#iU', $url)) { return true; } - } - else { - if ( strpos( $url, $needle ) === 0 ) { + } else { + if (strpos($url, $needle) === 0) { return true; } } @@ -523,14 +522,14 @@ private function _is_ori_url( $url ) { * @since 1.2.3 * */ - public static function internal( $host ) { - if ( defined( self::BYPASS ) ) { + public static function internal($host) + { + if (defined(self::BYPASS)) { return false; } $instance = self::cls(); - return in_array( $host, $instance->cdn_mapping_hosts );// todo: can add $this->_is_ori_url() check in future + return in_array($host, $instance->cdn_mapping_hosts); // todo: can add $this->_is_ori_url() check in future } - } diff --git a/src/cdn/cloudflare.cls.php b/src/cdn/cloudflare.cls.php index 2282328be..527f7df06 100644 --- a/src/cdn/cloudflare.cls.php +++ b/src/cdn/cloudflare.cls.php @@ -16,9 +16,10 @@ use LiteSpeed\Admin; use LiteSpeed\Admin_Display; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class Cloudflare extends Base { +class Cloudflare extends Base +{ const TYPE_PURGE_ALL = 'purge_all'; const TYPE_GET_DEVMODE = 'get_devmode'; const TYPE_SET_DEVMODE_ON = 'set_devmode_on'; @@ -32,24 +33,23 @@ class Cloudflare extends Base { * @since 3.0 * @access public */ - public function try_refresh_zone() { - if ( ! $this->conf( self::O_CDN_CLOUDFLARE ) ) { + public function try_refresh_zone() + { + if (!$this->conf(self::O_CDN_CLOUDFLARE)) { return; } $zone = $this->_fetch_zone(); - if ( $zone ) { - $this->cls( 'Conf' )->update( self::O_CDN_CLOUDFLARE_NAME, $zone[ 'name' ] ); + if ($zone) { + $this->cls('Conf')->update(self::O_CDN_CLOUDFLARE_NAME, $zone['name']); - $this->cls( 'Conf' )->update( self::O_CDN_CLOUDFLARE_ZONE, $zone[ 'id' ] ); + $this->cls('Conf')->update(self::O_CDN_CLOUDFLARE_ZONE, $zone['id']); - Debug2::debug( "[Cloudflare] Get zone successfully \t\t[ID] $zone[id]" ); + Debug2::debug("[Cloudflare] Get zone successfully \t\t[ID] $zone[id]"); + } else { + $this->cls('Conf')->update(self::O_CDN_CLOUDFLARE_ZONE, ''); + Debug2::debug('[Cloudflare] ❌ Get zone failed, clean zone'); } - else { - $this->cls( 'Conf' )->update( self::O_CDN_CLOUDFLARE_ZONE, '' ); - Debug2::debug( '[Cloudflare] ❌ Get zone failed, clean zone' ); - } - } /** @@ -58,29 +58,29 @@ public function try_refresh_zone() { * @since 1.7.2 * @access private */ - private function _get_devmode( $show_msg = true ) { - Debug2::debug( '[Cloudflare] _get_devmode' ); + private function _get_devmode($show_msg = true) + { + Debug2::debug('[Cloudflare] _get_devmode'); $zone = $this->_zone(); - if ( ! $zone ) { + if (!$zone) { return; } $url = 'https://api.cloudflare.com/client/v4/zones/' . $zone . '/settings/development_mode'; - $res = $this->_cloudflare_call( $url, 'GET', false, $show_msg ); + $res = $this->_cloudflare_call($url, 'GET', false, $show_msg); - if ( ! $res ) { + if (!$res) { return; } - Debug2::debug( '[Cloudflare] _get_devmode result ', $res ); + Debug2::debug('[Cloudflare] _get_devmode result ', $res); - $curr_status = self::get_option( self::ITEM_STATUS, array() ); - $curr_status[ 'devmode' ] = $res[ 'value' ]; - $curr_status[ 'devmode_expired' ] = $res[ 'time_remaining' ] + time(); + $curr_status = self::get_option(self::ITEM_STATUS, array()); + $curr_status['devmode'] = $res['value']; + $curr_status['devmode_expired'] = $res['time_remaining'] + time(); // update status - self::update_option( self::ITEM_STATUS, $curr_status ); - + self::update_option(self::ITEM_STATUS, $curr_status); } /** @@ -89,30 +89,30 @@ private function _get_devmode( $show_msg = true ) { * @since 1.7.2 * @access private */ - private function _set_devmode( $type ) { - Debug2::debug( '[Cloudflare] _set_devmode' ); + private function _set_devmode($type) + { + Debug2::debug('[Cloudflare] _set_devmode'); $zone = $this->_zone(); - if ( ! $zone ) { + if (!$zone) { return; } $url = 'https://api.cloudflare.com/client/v4/zones/' . $zone . '/settings/development_mode'; $new_val = $type == self::TYPE_SET_DEVMODE_ON ? 'on' : 'off'; - $data = array( 'value' => $new_val ); - $res = $this->_cloudflare_call( $url, 'PATCH', $data ); + $data = array('value' => $new_val); + $res = $this->_cloudflare_call($url, 'PATCH', $data); - if ( ! $res ) { + if (!$res) { return; } - $res = $this->_get_devmode( false ); + $res = $this->_get_devmode(false); - if ( $res ) { - $msg = sprintf( __( 'Notified Cloudflare to set development mode to %s successfully.', 'litespeed-cache' ), strtoupper( $new_val ) ); - Admin_Display::succeed( $msg ); + if ($res) { + $msg = sprintf(__('Notified Cloudflare to set development mode to %s successfully.', 'litespeed-cache'), strtoupper($new_val)); + Admin_Display::succeed($msg); } - } /** @@ -121,29 +121,30 @@ private function _set_devmode( $type ) { * @since 1.7.2 * @access private */ - private function _purge_all() { - Debug2::debug( '[Cloudflare] _purge_all' ); - - $cf_on = $this->conf( self::O_CDN_CLOUDFLARE ); - if ( ! $cf_on ) { - $msg = __( 'Cloudflare API is set to off.', 'litespeed-cache' ); - Admin_Display::error( $msg ); + private function _purge_all() + { + Debug2::debug('[Cloudflare] _purge_all'); + + $cf_on = $this->conf(self::O_CDN_CLOUDFLARE); + if (!$cf_on) { + $msg = __('Cloudflare API is set to off.', 'litespeed-cache'); + Admin_Display::error($msg); return; } $zone = $this->_zone(); - if ( ! $zone ) { + if (!$zone) { return; } $url = 'https://api.cloudflare.com/client/v4/zones/' . $zone . '/purge_cache'; - $data = array( 'purge_everything' => true ); + $data = array('purge_everything' => true); - $res = $this->_cloudflare_call( $url, 'DELETE', $data ); + $res = $this->_cloudflare_call($url, 'DELETE', $data); - if ( $res ) { - $msg = __( 'Notified Cloudflare to purge all successfully.', 'litespeed-cache' ); - Admin_Display::succeed( $msg ); + if ($res) { + $msg = __('Notified Cloudflare to purge all successfully.', 'litespeed-cache'); + Admin_Display::succeed($msg); } } @@ -153,11 +154,12 @@ private function _purge_all() { * @since 1.7.2 * @access private */ - private function _zone() { - $zone = $this->conf( self::O_CDN_CLOUDFLARE_ZONE ); - if ( ! $zone ) { - $msg = __( 'No available Cloudflare zone', 'litespeed-cache' ); - Admin_Display::error( $msg ); + private function _zone() + { + $zone = $this->conf(self::O_CDN_CLOUDFLARE_ZONE); + if (!$zone) { + $msg = __('No available Cloudflare zone', 'litespeed-cache'); + Admin_Display::error($msg); return false; } @@ -170,43 +172,44 @@ private function _zone() { * @since 1.7.2 * @access private */ - private function _fetch_zone() { - $kw = $this->conf( self::O_CDN_CLOUDFLARE_NAME ); + private function _fetch_zone() + { + $kw = $this->conf(self::O_CDN_CLOUDFLARE_NAME); $url = 'https://api.cloudflare.com/client/v4/zones?status=active&match=all'; // Try exact match first - if ( $kw && strpos( $kw, '.' ) ) { - $zones = $this->_cloudflare_call( $url . '&name=' . $kw, 'GET', false, false ); - if ( $zones ) { - Debug2::debug( '[Cloudflare] fetch_zone exact matched' ); - return $zones[ 0 ]; + if ($kw && strpos($kw, '.')) { + $zones = $this->_cloudflare_call($url . '&name=' . $kw, 'GET', false, false); + if ($zones) { + Debug2::debug('[Cloudflare] fetch_zone exact matched'); + return $zones[0]; } } // Can't find, try to get default one - $zones = $this->_cloudflare_call( $url, 'GET', false, false ); + $zones = $this->_cloudflare_call($url, 'GET', false, false); - if ( ! $zones ) { - Debug2::debug( '[Cloudflare] fetch_zone no zone' ); + if (!$zones) { + Debug2::debug('[Cloudflare] fetch_zone no zone'); return false; } - if ( ! $kw ) { - Debug2::debug( '[Cloudflare] fetch_zone no set name, use first one by default' ); - return $zones[ 0 ]; + if (!$kw) { + Debug2::debug('[Cloudflare] fetch_zone no set name, use first one by default'); + return $zones[0]; } - foreach ( $zones as $v ) { - if ( strpos( $v[ 'name' ], $kw ) !== false ) { - Debug2::debug( '[Cloudflare] fetch_zone matched ' . $kw . ' [name] ' . $v[ 'name' ] ); + foreach ($zones as $v) { + if (strpos($v['name'], $kw) !== false) { + Debug2::debug('[Cloudflare] fetch_zone matched ' . $kw . ' [name] ' . $v['name']); return $v; } } // Can't match current name, return default one - Debug2::debug( '[Cloudflare] fetch_zone failed match name, use first one by default' ); - return $zones[ 0 ]; + Debug2::debug('[Cloudflare] fetch_zone failed match name, use first one by default'); + return $zones[0]; } /** @@ -215,20 +218,20 @@ private function _fetch_zone() { * @since 1.7.2 * @access private */ - private function _cloudflare_call( $url, $method = 'GET', $data = false, $show_msg = true ) { - Debug2::debug( "[Cloudflare] _cloudflare_call \t\t[URL] $url" ); + private function _cloudflare_call($url, $method = 'GET', $data = false, $show_msg = true) + { + Debug2::debug("[Cloudflare] _cloudflare_call \t\t[URL] $url"); - if ( 40 == strlen($this->conf( self::O_CDN_CLOUDFLARE_KEY ))){ + if (40 == strlen($this->conf(self::O_CDN_CLOUDFLARE_KEY))) { $headers = array( 'Content-Type' => 'application/json', - 'Authorization' => 'Bearer ' . $this->conf( self::O_CDN_CLOUDFLARE_KEY ), + 'Authorization' => 'Bearer ' . $this->conf(self::O_CDN_CLOUDFLARE_KEY), ); - } - else { + } else { $headers = array( 'Content-Type' => 'application/json', - 'X-Auth-Email' => $this->conf( self::O_CDN_CLOUDFLARE_EMAIL ), - 'X-Auth-Key' => $this->conf( self::O_CDN_CLOUDFLARE_KEY ), + 'X-Auth-Email' => $this->conf(self::O_CDN_CLOUDFLARE_EMAIL), + 'X-Auth-Key' => $this->conf(self::O_CDN_CLOUDFLARE_KEY), ); } @@ -237,40 +240,40 @@ private function _cloudflare_call( $url, $method = 'GET', $data = false, $show_m 'headers' => $headers, ); - if ( $data ) { - if ( is_array( $data ) ) { - $data = json_encode( $data ); + if ($data) { + if (is_array($data)) { + $data = json_encode($data); } - $wp_args[ 'body' ] = $data; + $wp_args['body'] = $data; } - $resp = wp_remote_request( $url, $wp_args ); - if ( is_wp_error( $resp ) ) { - Debug2::debug( '[Cloudflare] error in response' ); - if ( $show_msg ) { - $msg = __( 'Failed to communicate with Cloudflare', 'litespeed-cache' ); - Admin_Display::error( $msg ); + $resp = wp_remote_request($url, $wp_args); + if (is_wp_error($resp)) { + Debug2::debug('[Cloudflare] error in response'); + if ($show_msg) { + $msg = __('Failed to communicate with Cloudflare', 'litespeed-cache'); + Admin_Display::error($msg); } return false; } - $result = wp_remote_retrieve_body( $resp ); + $result = wp_remote_retrieve_body($resp); - $json = json_decode( $result, true ); + $json = json_decode($result, true); - if ( $json && $json[ 'success' ] && $json[ 'result' ] ) { - Debug2::debug( "[Cloudflare] _cloudflare_call called successfully" ); - if ( $show_msg ) { - $msg = __( 'Communicated with Cloudflare successfully.', 'litespeed-cache' ); - Admin_Display::succeed( $msg ); + if ($json && $json['success'] && $json['result']) { + Debug2::debug('[Cloudflare] _cloudflare_call called successfully'); + if ($show_msg) { + $msg = __('Communicated with Cloudflare successfully.', 'litespeed-cache'); + Admin_Display::succeed($msg); } - return $json[ 'result' ]; + return $json['result']; } - Debug2::debug( "[Cloudflare] _cloudflare_call called failed: $result" ); - if ( $show_msg ) { - $msg = __( 'Failed to communicate with Cloudflare', 'litespeed-cache' ); - Admin_Display::error( $msg ); + Debug2::debug("[Cloudflare] _cloudflare_call called failed: $result"); + if ($show_msg) { + $msg = __('Failed to communicate with Cloudflare', 'litespeed-cache'); + Admin_Display::error($msg); } return false; @@ -282,21 +285,22 @@ private function _cloudflare_call( $url, $method = 'GET', $data = false, $show_m * @since 1.7.2 * @access public */ - public function handler() { + public function handler() + { $type = Router::verify_type(); - switch ( $type ) { - case self::TYPE_PURGE_ALL : + switch ($type) { + case self::TYPE_PURGE_ALL: $this->_purge_all(); break; - case self::TYPE_GET_DEVMODE : + case self::TYPE_GET_DEVMODE: $this->_get_devmode(); break; - case self::TYPE_SET_DEVMODE_ON : - case self::TYPE_SET_DEVMODE_OFF : - $this->_set_devmode( $type ); + case self::TYPE_SET_DEVMODE_ON: + case self::TYPE_SET_DEVMODE_OFF: + $this->_set_devmode($type); break; default: @@ -305,5 +309,4 @@ public function handler() { Admin::redirect(); } - } diff --git a/src/cdn/quic.cls.php b/src/cdn/quic.cls.php index 209070225..58b2d8236 100644 --- a/src/cdn/quic.cls.php +++ b/src/cdn/quic.cls.php @@ -14,7 +14,7 @@ use LiteSpeed\Cloud; use LiteSpeed\Base; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Quic extends Base { @@ -43,15 +43,14 @@ public function try_sync_conf($force = false) $options = $this->get_options(); if (!$options[self::O_CDN_QUIC]) { - if (!empty($this->_summary['conf_md5'])) self::save_summary(array('conf_md5' => '')); + if (!empty($this->_summary['conf_md5'])) { + self::save_summary(array('conf_md5' => '')); + } return false; } // Security: Remove cf key in report - $secure_fields = array( - self::O_CDN_CLOUDFLARE_KEY, - self::O_OBJECT_PSWD, - ); + $secure_fields = array(self::O_CDN_CLOUDFLARE_KEY, self::O_OBJECT_PSWD); foreach ($secure_fields as $v) { if (!empty($options[$v])) { $options[$v] = str_repeat('*', strlen($options[$v])); diff --git a/src/cloud.cls.php b/src/cloud.cls.php index 686fe6dfa..836026f99 100644 --- a/src/cloud.cls.php +++ b/src/cloud.cls.php @@ -8,7 +8,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Cloud extends Base { @@ -18,37 +18,37 @@ class Cloud extends Base const CLOUD_SERVER_DASH = 'https://my.quic.cloud'; const CLOUD_SERVER_WP = 'https://wpapi.quic.cloud'; - const SVC_D_NODES = 'd/nodes'; - const SVC_D_SYNC_CONF = 'd/sync_conf'; - const SVC_D_USAGE = 'd/usage'; - const SVC_D_SETUP_TOKEN = 'd/get_token'; - const SVC_D_DEL_CDN_DNS = 'd/del_cdn_dns'; - const SVC_PAGE_OPTM = 'page_optm'; - const SVC_CCSS = 'ccss'; - const SVC_UCSS = 'ucss'; - const SVC_VPI = 'vpi'; - const SVC_LQIP = 'lqip'; - const SVC_QUEUE = 'queue'; - const SVC_IMG_OPTM = 'img_optm'; - const SVC_HEALTH = 'health'; - const SVC_CDN = 'cdn'; + const SVC_D_NODES = 'd/nodes'; + const SVC_D_SYNC_CONF = 'd/sync_conf'; + const SVC_D_USAGE = 'd/usage'; + const SVC_D_SETUP_TOKEN = 'd/get_token'; + const SVC_D_DEL_CDN_DNS = 'd/del_cdn_dns'; + const SVC_PAGE_OPTM = 'page_optm'; + const SVC_CCSS = 'ccss'; + const SVC_UCSS = 'ucss'; + const SVC_VPI = 'vpi'; + const SVC_LQIP = 'lqip'; + const SVC_QUEUE = 'queue'; + const SVC_IMG_OPTM = 'img_optm'; + const SVC_HEALTH = 'health'; + const SVC_CDN = 'cdn'; const BM_IMG_OPTM_PRIO = 16; const BM_IMG_OPTM_JUMBO_GROUP = 32; const IMG_OPTM_JUMBO_GROUP = 1000; const IMG_OPTM_DEFAULT_GROUP = 200; - const IMGOPTM_TAKEN = 'img_optm-taken'; + const IMGOPTM_TAKEN = 'img_optm-taken'; const TTL_NODE = 3; // Days before node expired const EXPIRATION_REQ = 300; // Seconds of min interval between two unfinished requests const EXPIRATION_TOKEN = 900; // Min intval to request a token 15m const TTL_IPS = 3; // Days for node ip list cache - const API_REPORT = 'wp/report'; - const API_NEWS = 'news'; - const API_VER = 'ver'; - const API_BETA_TEST = 'beta_test'; + const API_REPORT = 'wp/report'; + const API_NEWS = 'news'; + const API_VER = 'ver'; + const API_BETA_TEST = 'beta_test'; private static $CENTER_SVC_SET = array( self::SVC_D_NODES, @@ -62,24 +62,12 @@ class Cloud extends Base self::SVC_D_DEL_CDN_DNS, ); - private static $WP_SVC_SET = array( - self::API_NEWS, - self::API_VER, - self::API_BETA_TEST, - ); + private static $WP_SVC_SET = array(self::API_NEWS, self::API_VER, self::API_BETA_TEST); // No api key needed for these services - private static $_PUB_SVC_SET = array( - self::API_NEWS, - self::API_REPORT, - self::API_VER, - self::API_BETA_TEST, - ); + private static $_PUB_SVC_SET = array(self::API_NEWS, self::API_REPORT, self::API_VER, self::API_BETA_TEST); - private static $_QUEUE_SVC_SET = array( - self::SVC_UCSS, - self::SVC_VPI, - ); + private static $_QUEUE_SVC_SET = array(self::SVC_UCSS, self::SVC_VPI); public static $SERVICES_LOAD_CHECK = array( self::SVC_CCSS, @@ -101,12 +89,12 @@ class Cloud extends Base // self::SVC_QUEUE, ); - const TYPE_CLEAR_PROMO = 'clear_promo'; - const TYPE_REDETECT_CLOUD = 'redetect_cloud'; - const TYPE_CLEAR_CLOUD = 'clear_cloud'; - const TYPE_GEN_KEY = 'gen_key'; - const TYPE_LINK = 'link'; - const TYPE_SYNC_USAGE = 'sync_usage'; + const TYPE_CLEAR_PROMO = 'clear_promo'; + const TYPE_REDETECT_CLOUD = 'redetect_cloud'; + const TYPE_CLEAR_CLOUD = 'clear_cloud'; + const TYPE_GEN_KEY = 'gen_key'; + const TYPE_LINK = 'link'; + const TYPE_SYNC_USAGE = 'sync_usage'; private $_setup_token; protected $_summary; @@ -174,8 +162,8 @@ public function check_dev_version() public static function version_check($src = false) { $req_data = array( - 'v' => defined('LSCWP_CUR_V') ? LSCWP_CUR_V : '', - 'src' => $src, + 'v' => defined('LSCWP_CUR_V') ? LSCWP_CUR_V : '', + 'src' => $src, ); if (defined('LITESPEED_ERR')) { $req_data['err'] = base64_encode(!is_string(LITESPEED_ERR) ? json_encode(LITESPEED_ERR) : LITESPEED_ERR); @@ -272,7 +260,8 @@ public function allowance($service, &$err = false) $this->sync_usage(); } - if (in_array($service, array(self::SVC_CCSS, self::SVC_UCSS, self::SVC_VPI))) { // @since 4.2 + if (in_array($service, array(self::SVC_CCSS, self::SVC_UCSS, self::SVC_VPI))) { + // @since 4.2 $service = self::SVC_PAGE_OPTM; } @@ -385,7 +374,11 @@ public function detect_cloud($service, $force = false) // Check if the stored server needs to be refreshed if (!$force) { - if (!empty($this->_summary['server.' . $service]) && !empty($this->_summary['server_date.' . $service]) && $this->_summary['server_date.' . $service] > time() - 86400 * self::TTL_NODE) { + if ( + !empty($this->_summary['server.' . $service]) && + !empty($this->_summary['server_date.' . $service]) && + $this->_summary['server_date.' . $service] > time() - 86400 * self::TTL_NODE + ) { return $this->_summary['server.' . $service]; } } @@ -411,7 +404,6 @@ public function detect_cloud($service, $force = false) return false; } - // Ping closest cloud $speed_list = array(); foreach ($json['list'] as $v) { @@ -443,7 +435,7 @@ public function detect_cloud($service, $force = false) $valid_clouds[] = $node; } // Append the lower speed ones - else if ($speed < $min * 4) { + elseif ($speed < $min * 4) { $valid_clouds[] = $node; } } @@ -503,7 +495,9 @@ public function detect_cloud($service, $force = false) */ private function _maybe_queue($service) { - if (in_array($service, self::$_QUEUE_SVC_SET)) return self::SVC_QUEUE; + if (in_array($service, self::$_QUEUE_SVC_SET)) { + return self::SVC_QUEUE; + } return $service; } @@ -544,10 +538,10 @@ private function _get($service, $data = false) $url = $server . '/' . $service; $param = array( - 'site_url' => home_url(), - 'domain_key' => $this->_api_key(), - 'main_domain' => !empty($this->_summary['main_domain']) ? $this->_summary['main_domain'] : '', - 'ver' => Core::VER, + 'site_url' => home_url(), + 'domain_key' => $this->_api_key(), + 'main_domain' => !empty($this->_summary['main_domain']) ? $this->_summary['main_domain'] : '', + 'ver' => Core::VER, ); if ($data) { @@ -581,7 +575,7 @@ private function _maybe_cloud($service_tag) // Deny if is IP if (preg_match('#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', Utility::parse_url_safe($home_url, PHP_URL_HOST))) { - self::debug("IP home url is not allowed for cloud service."); + self::debug('IP home url is not allowed for cloud service.'); $msg = __('In order to use QC services, need a real domain name, cannot use an IP.', 'litespeed-cache'); Admin_Display::error($msg); return false; @@ -599,7 +593,7 @@ private function _maybe_cloud($service_tag) } if ($service_tag == self::SVC_D_SYNC_CONF && $this->_setup_token && !$this->_api_key()) { - self::debug("Skip sync conf if API key is not available yet."); + self::debug('Skip sync conf if API key is not available yet.'); return false; } @@ -624,7 +618,10 @@ private function _maybe_cloud($service_tag) self::debug("❌ try [$service_tag] after $expired seconds"); if ($service_tag !== self::API_VER) { - $msg = __('Cloud Error', 'litespeed-cache') . ': ' . sprintf(__('Please try after %1$s for service %2$s.', 'litespeed-cache'), Utility::readable_time($expired, 0, true), '' . $service_tag . ''); + $msg = + __('Cloud Error', 'litespeed-cache') . + ': ' . + sprintf(__('Please try after %1$s for service %2$s.', 'litespeed-cache'), Utility::readable_time($expired, 0, true), '' . $service_tag . ''); Admin_Display::error(array('cloud_trylater' => $msg)); } @@ -687,11 +684,11 @@ private function _post($service, $data = false, $time_out = false) } $param = array( - 'site_url' => home_url(), - 'domain_key' => $this->_api_key(), - 'main_domain' => !empty($this->_summary['main_domain']) ? $this->_summary['main_domain'] : '', - 'ver' => Core::VER, - 'data' => $data, + 'site_url' => home_url(), + 'domain_key' => $this->_api_key(), + 'main_domain' => !empty($this->_summary['main_domain']) ? $this->_summary['main_domain'] : '', + 'ver' => Core::VER, + 'data' => $data, ); self::save_summary(array('curr_request.' . $service_tag => time())); @@ -718,7 +715,9 @@ private function _parse_response($response, $service, $service_tag, $server) Admin_Display::error($msg); // Tmp disabled this node from reusing in 1 day - if (empty($this->_summary['disabled_node'])) $this->_summary['disabled_node'] = array(); + if (empty($this->_summary['disabled_node'])) { + $this->_summary['disabled_node'] = array(); + } $this->_summary['disabled_node'][$server] = time(); self::save_summary(); @@ -739,7 +738,9 @@ private function _parse_response($response, $service, $service_tag, $server) Admin_Display::error($msg); // Tmp disabled this node from reusing in 1 day - if (empty($this->_summary['disabled_node'])) $this->_summary['disabled_node'] = array(); + if (empty($this->_summary['disabled_node'])) { + $this->_summary['disabled_node'] = array(); + } $this->_summary['disabled_node'][$server] = time(); self::save_summary(); @@ -782,7 +783,10 @@ private function _parse_response($response, $service, $service_tag, $server) if (!empty($json['_503'])) { self::debug('service 503 unavailable temporarily. ' . $json['_503']); - $msg = __('We are working hard to improve your online service experience. The service will be unavailable while we work. We apologize for any inconvenience.', 'litespeed-cache'); + $msg = __( + 'We are working hard to improve your online service experience. The service will be unavailable while we work. We apologize for any inconvenience.', + 'litespeed-cache' + ); $msg .= ' ' . $json['_503'] . " [server] $server [service] $service"; Admin_Display::error($msg); @@ -794,11 +798,13 @@ private function _parse_response($response, $service, $service_tag, $server) } list($json, $return) = $this->extract_msg($json, $service, $server); - if ($return) return; + if ($return) { + return; + } self::save_summary(array( 'last_request.' . $service_tag => $this->_summary['curr_request.' . $service_tag], - 'curr_request.' . $service_tag => 0 + 'curr_request.' . $service_tag => 0, )); if ($json) { @@ -844,7 +850,9 @@ public function extract_msg($json, $service, $server = false, $is_callback = fal // Upgrade is required if (!empty($json['_err_req_v'])) { self::debug('_err_req_v: ' . $json['_err_req_v']); - $msg = sprintf(__('%1$s plugin version %2$s required for this action.', 'litespeed-cache'), Core::NAME, 'v' . $json['_err_req_v'] . '+') . " [server] $server [service] $service"; + $msg = + sprintf(__('%1$s plugin version %2$s required for this action.', 'litespeed-cache'), Core::NAME, 'v' . $json['_err_req_v'] . '+') . + " [server] $server [service] $service"; // Append upgrade link $msg2 = ' ' . GUI::plugin_upgrade_link(Core::NAME, Core::PLUGIN_NAME, $json['_err_req_v']); @@ -968,7 +976,9 @@ public function rest_err_domains() list($post_data) = $this->extract_msg($_POST, 'Quic.cloud', false, true); if ($this->_is_err_domain($_POST['alias'])) { - if ($_POST['alias'] == home_url()) $this->_remove_domain_from_err_list($_POST['alias']); + if ($_POST['alias'] == home_url()) { + $this->_remove_domain_from_err_list($_POST['alias']); + } $res_hash = substr($this->_api_key(), 2, 4); @@ -996,23 +1006,27 @@ private function _remove_domain_from_err_list($url) */ private function _is_err_domain($home_url) { - if (empty($this->_summary['err_domains'])) return false; - if (!array_key_exists($home_url, $this->_summary['err_domains'])) return false; + if (empty($this->_summary['err_domains'])) { + return false; + } + if (!array_key_exists($home_url, $this->_summary['err_domains'])) { + return false; + } // Auto delete if too long ago if (time() - $this->_summary['err_domains'][$home_url] > 86400 * 10) { $this->_remove_domain_from_err_list($home_url); } - if (time() - $this->_summary['err_domains'][$home_url] > 86400) return false; + if (time() - $this->_summary['err_domains'][$home_url] > 86400) { + return false; + } return true; } public function req_rest_api($api, $body = array()) { - $token = $this->_setup_token; if (empty($token)) { - Admin_Display::error(__('Cannot request REST API, no token saved.', 'litespeed-cache')); return; } @@ -1036,12 +1050,11 @@ public function req_rest_api($api, $body = array()) private function _parse_rest_response($response) { if (is_wp_error($response)) { - $error_message = $response->get_error_message(); self::debug('failed to request REST API: ' . $error_message); Admin_Display::error(__('Cloud REST Error', 'litespeed-cache') . ': ' . $error_message); return $error_message; - } else if (wp_remote_retrieve_response_code($response) == '401') { + } elseif (wp_remote_retrieve_response_code($response) == '401') { return 'unauthorized access to REST API.'; } @@ -1191,9 +1204,9 @@ public function set_keygen_token($token) public function gen_key() { $data = array( - 'site_url' => home_url(), - 'rest' => function_exists('rest_get_url_prefix') ? rest_get_url_prefix() : apply_filters('rest_url_prefix', 'wp-json'), - 'server_ip' => $this->conf(self::O_SERVER_IP), + 'site_url' => home_url(), + 'rest' => function_exists('rest_get_url_prefix') ? rest_get_url_prefix() : apply_filters('rest_url_prefix', 'wp-json'), + 'server_ip' => $this->conf(self::O_SERVER_IP), ); if (!empty($this->_summary['token'])) { $data['token'] = $this->_summary['token']; @@ -1348,21 +1361,21 @@ private function _link_to_qc() } $data = array( - 'site_url' => home_url(), - 'domain_hash' => md5(substr($this->_api_key(), 0, 8)), - 'ref' => get_admin_url(null, 'admin.php?page=litespeed-general'), + 'site_url' => home_url(), + 'domain_hash' => md5(substr($this->_api_key(), 0, 8)), + 'ref' => get_admin_url(null, 'admin.php?page=litespeed-general'), ); wp_redirect(self::CLOUD_SERVER_DASH . '/u/wp?data=' . Utility::arr2str($data)); - exit; + exit(); } public function qc_link() { $data = array( - 'site_url' => home_url(), - 'domain_hash' => md5(substr($this->_api_key(), 0, 8)), - 'ver' => LSCWP_V, + 'site_url' => home_url(), + 'domain_hash' => md5(substr($this->_api_key(), 0, 8)), + 'ver' => LSCWP_V, ); return self::CLOUD_SERVER_DASH . '/u/wp?data=' . Utility::arr2str($data); // . (!empty($this->_summary['is_linked']) ? '?wplogin=1' : ''); } @@ -1384,7 +1397,6 @@ public function set_linked() */ public function parse_qc_redir($extra = array()) { - $extraRet = array(); $qsDrop = array(); if (!$this->_api_key() && !empty($this->_summary['is_linked'])) { @@ -1397,14 +1409,16 @@ public function parse_qc_redir($extra = array()) } if ($_GET['qc_res'] == 'registered') { - if (!empty($_GET['qc_new'])) Admin_Display::succeed(__('QUIC.cloud account has been created and successfully linked.', 'litespeed-cache'), true); - else Admin_Display::succeed(__('QUIC.cloud account has been successfully linked.', 'litespeed-cache'), true); + if (!empty($_GET['qc_new'])) { + Admin_Display::succeed(__('QUIC.cloud account has been created and successfully linked.', 'litespeed-cache'), true); + } else { + Admin_Display::succeed(__('QUIC.cloud account has been successfully linked.', 'litespeed-cache'), true); + } } $qsDrop[] = ".replace( '&qc_res=" . sanitize_key($_GET['qc_res']) . ', \'\' )'; if (!empty($_GET['domain_hash'])) { - if (md5(substr($this->_api_key(), 2, 8)) !== $_GET['domain_hash']) { Admin_Display::error(__('Domain Key hash mismatch', 'litespeed-cache'), true); return $extraRet; @@ -1426,7 +1440,7 @@ public function parse_qc_redir($extra = array()) $replaceStr = implode('', $qsDrop); // Drop QS - echo ""; + echo "'; return $extraRet; } diff --git a/src/conf.cls.php b/src/conf.cls.php index 3e6653e59..897b6fcce 100644 --- a/src/conf.cls.php +++ b/src/conf.cls.php @@ -14,8 +14,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; - +defined('WPINC') || exit(); class Conf extends Base { @@ -41,7 +40,7 @@ public function init() * @since 2.9.7 */ if ($this->conf(self::O_CDN_QUIC)) { - !defined('LITESPEED_ALLOWED') && define('LITESPEED_ALLOWED', true); + !defined('LITESPEED_ALLOWED') && define('LITESPEED_ALLOWED', true); } add_action('litespeed_conf_append', array($this, 'option_append'), 10, 2); @@ -73,7 +72,8 @@ private function _conf_db_init() */ $has_delay_conf_tag = self::get_option('__activation'); if (!$ver || $ver != Core::VER) { - if ((!is_admin() && !defined('LITESPEED_CLI')) || (!$has_delay_conf_tag || $has_delay_conf_tag == -1)) { // Reuse __activation to control the delay conf update + if ((!is_admin() && !defined('LITESPEED_CLI')) || (!$has_delay_conf_tag || $has_delay_conf_tag == -1)) { + // Reuse __activation to control the delay conf update if (!$has_delay_conf_tag || $has_delay_conf_tag == -1) { self::update_option('__activation', Core::VER); } @@ -114,7 +114,8 @@ private function _conf_db_init() if (!$ver || $ver != Core::VER) { // Load default values $this->load_default_vals(); - if (!$ver) { // New install + if (!$ver) { + // New install $this->set_conf(self::$_default_options); } @@ -180,7 +181,8 @@ public function load_options($blog_id = null, $dry_run = false) } // Bypass site special settings - if ($blog_id !== null) { // This is to load the primary settings ONLY + if ($blog_id !== null) { + // This is to load the primary settings ONLY // These options are the ones that can be overwritten by primary $options = array_diff_key($options, array_flip(self::$SINGLE_SITE_OPTIONS)); @@ -189,7 +191,6 @@ public function load_options($blog_id = null, $dry_run = false) $this->set_conf($options); } - // Append const options if (defined('LITESPEED_CONF') && LITESPEED_CONF) { foreach (self::$_default_options as $k => $v) { @@ -218,7 +219,8 @@ private function _try_load_site_options() $this->_is_primary = get_current_blog_id() == BLOG_ID_CURRENT_SITE; // If network set to use primary setting - if ($this->network_conf(self::NETWORK_O_USE_PRIMARY) && !$this->_is_primary) { // subsites or network admin + if ($this->network_conf(self::NETWORK_O_USE_PRIMARY) && !$this->_is_primary) { + // subsites or network admin // Get the primary site settings // If it's just upgraded, 2nd blog is being visited before primary blog, can just load default config (won't hurt as this could only happen shortly) $this->load_options(BLOG_ID_CURRENT_SITE); @@ -241,7 +243,8 @@ private function _try_load_site_options() } } else { if ($this->network_conf(self::NETWORK_O_USE_PRIMARY)) { - if ($this->has_primary_conf($k) && $this->primary_conf($k) != self::VAL_ON2) { // This case will use primary_options override always + if ($this->has_primary_conf($k) && $this->primary_conf($k) != self::VAL_ON2) { + // This case will use primary_options override always continue; } } else { @@ -279,11 +282,12 @@ private function _if_need_site_options() * @since 2.0 */ if (!function_exists('is_plugin_active_for_network')) { - require_once(ABSPATH . '/wp-admin/includes/plugin.php'); + require_once ABSPATH . '/wp-admin/includes/plugin.php'; } // If is not activated on network, it will not have site options if (!is_plugin_active_for_network(Core::PLUGIN_FILE)) { - if ((int)$this->conf(self::O_CACHE) == self::VAL_ON2) { // Default to cache on + if ((int) $this->conf(self::O_CACHE) == self::VAL_ON2) { + // Default to cache on $this->set_conf(self::_CACHE, true); } return false; @@ -651,7 +655,6 @@ public function network_update($id, $val) // No need to update cron here, Cron will register in each init - if ($this->has_conf($id)) { $this->set_conf($id, $val); } diff --git a/src/control.cls.php b/src/control.cls.php index 170f9d42c..323475fe0 100644 --- a/src/control.cls.php +++ b/src/control.cls.php @@ -9,9 +9,10 @@ */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class Control extends Root { +class Control extends Root +{ const LOG_TAG = '💵'; const BM_CACHEABLE = 1; @@ -35,27 +36,28 @@ class Control extends Root { * * @since 1.6.2 */ - public function init() { + public function init() + { /** * Add vary filter for Role Excludes * @since 1.6.2 */ - add_filter( 'litespeed_vary', array( $this, 'vary_add_role_exclude' ) ); + add_filter('litespeed_vary', array($this, 'vary_add_role_exclude')); // 301 redirect hook - add_filter( 'wp_redirect', array( $this, 'check_redirect' ), 10, 2 ); + add_filter('wp_redirect', array($this, 'check_redirect'), 10, 2); // Load response header conf - $this->_response_header_ttls = $this->conf( Base::O_CACHE_TTL_STATUS ); - foreach ( $this->_response_header_ttls as $k => $v ) { - $v = explode( ' ', $v ); - if ( empty( $v[ 0 ] ) || empty( $v[ 1 ] ) ) { + $this->_response_header_ttls = $this->conf(Base::O_CACHE_TTL_STATUS); + foreach ($this->_response_header_ttls as $k => $v) { + $v = explode(' ', $v); + if (empty($v[0]) || empty($v[1])) { continue; } - $this->_response_header_ttls[ $v[ 0 ] ] = $v[ 1 ]; + $this->_response_header_ttls[$v[0]] = $v[1]; } - if ( $this->conf( Base::O_PURGE_STALE ) ) { + if ($this->conf(Base::O_PURGE_STALE)) { $this->set_stale(); } } @@ -66,9 +68,10 @@ public function init() { * @since 1.6.2 * @access public */ - public function vary_add_role_exclude( $vary ) { - if ( $this->in_cache_exc_roles() ) { - $vary[ 'role_exclude_cache' ] = 1; + public function vary_add_role_exclude($vary) + { + if ($this->in_cache_exc_roles()) { + $vary['role_exclude_cache'] = 1; } return $vary; @@ -83,20 +86,21 @@ public function vary_add_role_exclude( $vary ) { * @param string $role The user role * @return int The set value if already set */ - public function in_cache_exc_roles( $role = null ) { + public function in_cache_exc_roles($role = null) + { // Get user role - if ( $role === null ) { + if ($role === null) { $role = Router::get_role(); } - if ( ! $role ) { + if (!$role) { return false; } - $roles = explode( ',', $role ); - $found = array_intersect( $roles, $this->conf( Base::O_CACHE_EXC_ROLES ) ); + $roles = explode(',', $role); + $found = array_intersect($roles, $this->conf(Base::O_CACHE_EXC_ROLES)); - return $found ? implode( ',', $found ) : false; + return $found ? implode(',', $found) : false; } /** @@ -106,32 +110,32 @@ public function in_cache_exc_roles( $role = null ) { * @since 1.1.3 * @access public */ - public function init_cacheable() { + public function init_cacheable() + { // Hook `wp` to mark default cacheable status // NOTE: Any process that does NOT run into `wp` hook will not get cacheable by default - add_action( 'wp', array( $this, 'set_cacheable' ), 5 ); + add_action('wp', array($this, 'set_cacheable'), 5); // Hook WP REST to be cacheable - if ( $this->conf( Base::O_CACHE_REST ) ) { - add_action( 'rest_api_init', array( $this, 'set_cacheable' ), 5 ); + if ($this->conf(Base::O_CACHE_REST)) { + add_action('rest_api_init', array($this, 'set_cacheable'), 5); } // Cache resources // NOTE: If any strange resource doesn't use normal WP logic `wp_loaded` hook, rewrite rule can handle it - $cache_res = $this->conf( Base::O_CACHE_RES ); - if ( $cache_res ) { - $uri = esc_url( $_SERVER["REQUEST_URI"] );// todo: check if need esc_url() + $cache_res = $this->conf(Base::O_CACHE_RES); + if ($cache_res) { + $uri = esc_url($_SERVER['REQUEST_URI']); // todo: check if need esc_url() $pattern = '!' . LSCWP_CONTENT_FOLDER . Htaccess::RW_PATTERN_RES . '!'; - if ( preg_match( $pattern, $uri ) ) { - add_action( 'wp_loaded', array( $this, 'set_cacheable' ), 5 ); + if (preg_match($pattern, $uri)) { + add_action('wp_loaded', array($this, 'set_cacheable'), 5); } } // Check error page - add_filter( 'status_header', array( $this, 'check_error_codes' ), 10, 2 ); + add_filter('status_header', array($this, 'check_error_codes'), 10, 2); } - /** * Check if the page returns any error code. * @@ -141,23 +145,23 @@ public function init_cacheable() { * @param $code * @return $eror_status */ - public function check_error_codes( $status_header, $code ) { - if ( array_key_exists( $code, $this->_response_header_ttls ) ) { - if ( self::is_cacheable() && ! $this->_response_header_ttls[ $code ] ) { - self::set_nocache( '[Ctrl] TTL is set to no cache [status_header] ' . $code ); + public function check_error_codes($status_header, $code) + { + if (array_key_exists($code, $this->_response_header_ttls)) { + if (self::is_cacheable() && !$this->_response_header_ttls[$code]) { + self::set_nocache('[Ctrl] TTL is set to no cache [status_header] ' . $code); } // Set TTL - self::set_custom_ttl( $this->_response_header_ttls[ $code ] ); - } - elseif (self::is_cacheable()) { - if ( substr($code, 0, 1)==4 || substr($code, 0, 1)==5 ) { - self::set_nocache( '[Ctrl] 4xx/5xx default to no cache [status_header] ' . $code ); + self::set_custom_ttl($this->_response_header_ttls[$code]); + } elseif (self::is_cacheable()) { + if (substr($code, 0, 1) == 4 || substr($code, 0, 1) == 5) { + self::set_nocache('[Ctrl] 4xx/5xx default to no cache [status_header] ' . $code); } } // Set cache tag - Tag::add( Tag::TYPE_HTTP . $code ); + Tag::add(Tag::TYPE_HTTP . $code); // Give the default status_header back return $status_header; @@ -169,12 +173,13 @@ public function check_error_codes( $status_header, $code ) { * @access public * @since 1.1.3 */ - public static function set_no_vary() { - if ( self::is_no_vary() ) { + public static function set_no_vary() + { + if (self::is_no_vary()) { return; } self::$_control |= self::BM_NO_VARY; - Debug2::debug( '[Ctrl] X Cache_control -> no-vary', 3 ); + Debug2::debug('[Ctrl] X Cache_control -> no-vary', 3); } /** @@ -183,7 +188,8 @@ public static function set_no_vary() { * @access public * @since 1.1.3 */ - public static function is_no_vary() { + public static function is_no_vary() + { return self::$_control & self::BM_NO_VARY; } @@ -193,8 +199,9 @@ public static function is_no_vary() { * @access public * @since 1.1.3 */ - public function set_stale() { - if ( self::is_stale() ) { + public function set_stale() + { + if (self::is_stale()) { return; } self::$_control |= self::BM_STALE; @@ -207,7 +214,8 @@ public function set_stale() { * @access public * @since 1.1.3 */ - public static function is_stale() { + public static function is_stale() + { return self::$_control & self::BM_STALE; } @@ -218,21 +226,22 @@ public static function is_stale() { * @since 1.1.3 * @param string $reason The reason to no cache */ - public static function set_shared( $reason = false ) { - if ( self::is_shared() ) { + public static function set_shared($reason = false) + { + if (self::is_shared()) { return; } self::$_control |= self::BM_SHARED; self::set_private(); - if ( ! is_string( $reason ) ) { + if (!is_string($reason)) { $reason = false; } - if ( $reason ) { + if ($reason) { $reason = "( $reason )"; } - Debug2::debug( '[Ctrl] X Cache_control -> shared ' . $reason ); + Debug2::debug('[Ctrl] X Cache_control -> shared ' . $reason); } /** @@ -241,8 +250,9 @@ public static function set_shared( $reason = false ) { * @access public * @since 1.1.3 */ - public static function is_shared() { - return (self::$_control & self::BM_SHARED) && self::is_private(); + public static function is_shared() + { + return self::$_control & self::BM_SHARED && self::is_private(); } /** @@ -251,20 +261,21 @@ public static function is_shared() { * @access public * @since 1.7.1 */ - public static function set_public_forced( $reason = false ) { - if ( self::is_public_forced() ) { + public static function set_public_forced($reason = false) + { + if (self::is_public_forced()) { return; } self::$_control |= self::BM_PUBLIC_FORCED; - if ( ! is_string( $reason ) ) { + if (!is_string($reason)) { $reason = false; } - if ( $reason ) { + if ($reason) { $reason = "( $reason )"; } - Debug2::debug( '[Ctrl] X Cache_control -> public forced ' . $reason ); + Debug2::debug('[Ctrl] X Cache_control -> public forced ' . $reason); } /** @@ -273,7 +284,8 @@ public static function set_public_forced( $reason = false ) { * @access public * @since 1.7.1 */ - public static function is_public_forced() { + public static function is_public_forced() + { return self::$_control & self::BM_PUBLIC_FORCED; } @@ -284,20 +296,21 @@ public static function is_public_forced() { * @since 1.1.3 * @param string $reason The reason to no cache */ - public static function set_private( $reason = false ) { - if ( self::is_private() ) { + public static function set_private($reason = false) + { + if (self::is_private()) { return; } self::$_control |= self::BM_PRIVATE; - if ( ! is_string( $reason ) ) { + if (!is_string($reason)) { $reason = false; } - if ( $reason ) { + if ($reason) { $reason = "( $reason )"; } - Debug2::debug( '[Ctrl] X Cache_control -> private ' . $reason ); + Debug2::debug('[Ctrl] X Cache_control -> private ' . $reason); } /** @@ -306,12 +319,13 @@ public static function set_private( $reason = false ) { * @access public * @since 1.1.3 */ - public static function is_private() { - if ( defined( 'LITESPEED_GUEST' ) && LITESPEED_GUEST ) { + public static function is_private() + { + if (defined('LITESPEED_GUEST') && LITESPEED_GUEST) { // return false; } - return self::$_control & self::BM_PRIVATE && ! self::is_public_forced(); + return self::$_control & self::BM_PRIVATE && !self::is_public_forced(); } /** @@ -320,17 +334,18 @@ public static function is_private() { * @access public * @since 1.1.3 */ - public function set_cacheable( $reason = false ) { + public function set_cacheable($reason = false) + { self::$_control |= self::BM_CACHEABLE; - if ( ! is_string( $reason ) ) { + if (!is_string($reason)) { $reason = false; } - if ( $reason ) { + if ($reason) { $reason = ' [reason] ' . $reason; } - Debug2::debug( '[Ctrl] X Cache_control init on' . $reason ); + Debug2::debug('[Ctrl] X Cache_control init on' . $reason); } /** @@ -339,17 +354,18 @@ public function set_cacheable( $reason = false ) { * @access public * @since 2.2 */ - public static function force_cacheable( $reason = false ) { + public static function force_cacheable($reason = false) + { self::$_control |= self::BM_FORCED_CACHEABLE; - if ( ! is_string( $reason ) ) { + if (!is_string($reason)) { $reason = false; } - if ( $reason ) { + if ($reason) { $reason = ' [reason] ' . $reason; } - Debug2::debug( '[Ctrl] Forced cacheable' . $reason ); + Debug2::debug('[Ctrl] Forced cacheable' . $reason); } /** @@ -359,17 +375,18 @@ public static function force_cacheable( $reason = false ) { * @since 1.1.3 * @param string $reason The reason to no cache */ - public static function set_nocache( $reason = false ) { + public static function set_nocache($reason = false) + { self::$_control |= self::BM_NOTCACHEABLE; - if ( ! is_string( $reason ) ) { + if (!is_string($reason)) { $reason = false; } - if ( $reason ) { + if ($reason) { $reason = "( $reason )"; } - Debug2::debug( '[Ctrl] X Cache_control -> no Cache ' . $reason, 5 ); + Debug2::debug('[Ctrl] X Cache_control -> no Cache ' . $reason, 5); } /** @@ -379,7 +396,8 @@ public static function set_nocache( $reason = false ) { * @since 1.1.3 * @return bool True if notcacheable bit is set, otherwise false. */ - public static function isset_notcacheable() { + public static function isset_notcacheable() + { return self::$_control & self::BM_NOTCACHEABLE; } @@ -389,7 +407,8 @@ public static function isset_notcacheable() { * @access public * @since 2.2 */ - public static function is_forced_cacheable() { + public static function is_forced_cacheable() + { return self::$_control & self::BM_FORCED_CACHEABLE; } @@ -400,28 +419,29 @@ public static function is_forced_cacheable() { * @since 1.1.3 * @return bool True if is still cacheable, otherwise false. */ - public static function is_cacheable() { - if ( defined( 'LSCACHE_NO_CACHE' ) && LSCACHE_NO_CACHE ) { - Debug2::debug( '[Ctrl] LSCACHE_NO_CACHE constant defined' ); + public static function is_cacheable() + { + if (defined('LSCACHE_NO_CACHE') && LSCACHE_NO_CACHE) { + Debug2::debug('[Ctrl] LSCACHE_NO_CACHE constant defined'); return false; } // Guest mode always cacheable - if ( defined( 'LITESPEED_GUEST' ) && LITESPEED_GUEST ) { + if (defined('LITESPEED_GUEST') && LITESPEED_GUEST) { // return true; } // If its forced public cacheable - if ( self::is_public_forced() ) { + if (self::is_public_forced()) { return true; } // If its forced cacheable - if ( self::is_forced_cacheable() ) { + if (self::is_forced_cacheable()) { return true; } - return ! self::isset_notcacheable() && self::$_control & self::BM_CACHEABLE; + return !self::isset_notcacheable() && self::$_control & self::BM_CACHEABLE; } /** @@ -431,10 +451,11 @@ public static function is_cacheable() { * @since 1.1.3 * @param mixed $ttl An integer or string to use as the TTL. Must be numeric. */ - public static function set_custom_ttl( $ttl, $reason = false ) { - if ( is_numeric( $ttl ) ) { + public static function set_custom_ttl($ttl, $reason = false) + { + if (is_numeric($ttl)) { self::$_custom_ttl = $ttl; - Debug2::debug( '[Ctrl] X Cache_control TTL -> ' . $ttl . ( $reason ? ' [reason] ' . $ttl : '' ) ); + Debug2::debug('[Ctrl] X Cache_control TTL -> ' . $ttl . ($reason ? ' [reason] ' . $ttl : '')); } } @@ -444,32 +465,32 @@ public static function set_custom_ttl( $ttl, $reason = false ) { * @access public * @since 1.1.3 */ - public function get_ttl() { - if ( self::$_custom_ttl != 0 ) { + public function get_ttl() + { + if (self::$_custom_ttl != 0) { return self::$_custom_ttl; } // Check if is in timed url list or not - $timed_urls = Utility::wildcard2regex( $this->conf( Base::O_PURGE_TIMED_URLS ) ); - $timed_urls_time = $this->conf( Base::O_PURGE_TIMED_URLS_TIME ); - if ( $timed_urls && $timed_urls_time ) { - $current_url = Tag::build_uri_tag( true ); + $timed_urls = Utility::wildcard2regex($this->conf(Base::O_PURGE_TIMED_URLS)); + $timed_urls_time = $this->conf(Base::O_PURGE_TIMED_URLS_TIME); + if ($timed_urls && $timed_urls_time) { + $current_url = Tag::build_uri_tag(true); // Use time limit ttl - $scheduled_time = strtotime( $timed_urls_time ); + $scheduled_time = strtotime($timed_urls_time); $ttl = $scheduled_time - time(); - if ( $ttl < 0 ) { - $ttl += 86400;// add one day + if ($ttl < 0) { + $ttl += 86400; // add one day } - foreach ( $timed_urls as $v ) { - if ( strpos( $v, '*' ) !== false ) { - if( preg_match( '#' . $v . '#iU', $current_url ) ) { - Debug2::debug( '[Ctrl] X Cache_control TTL is limited to ' . $ttl . ' due to scheduled purge regex ' . $v ); + foreach ($timed_urls as $v) { + if (strpos($v, '*') !== false) { + if (preg_match('#' . $v . '#iU', $current_url)) { + Debug2::debug('[Ctrl] X Cache_control TTL is limited to ' . $ttl . ' due to scheduled purge regex ' . $v); return $ttl; } - } - else { - if ( $v == $current_url ) { - Debug2::debug( '[Ctrl] X Cache_control TTL is limited to ' . $ttl . ' due to scheduled purge rule ' . $v ); + } else { + if ($v == $current_url) { + Debug2::debug('[Ctrl] X Cache_control TTL is limited to ' . $ttl . ' due to scheduled purge rule ' . $v); return $ttl; } } @@ -477,24 +498,24 @@ public function get_ttl() { } // Private cache uses private ttl setting - if ( self::is_private() ) { - return $this->conf( Base::O_CACHE_TTL_PRIV ); + if (self::is_private()) { + return $this->conf(Base::O_CACHE_TTL_PRIV); } - if ( is_front_page() ){ - return $this->conf( Base::O_CACHE_TTL_FRONTPAGE ); + if (is_front_page()) { + return $this->conf(Base::O_CACHE_TTL_FRONTPAGE); } - $feed_ttl = $this->conf( Base::O_CACHE_TTL_FEED ); - if ( is_feed() && $feed_ttl > 0 ) { + $feed_ttl = $this->conf(Base::O_CACHE_TTL_FEED); + if (is_feed() && $feed_ttl > 0) { return $feed_ttl; } - if ( $this->cls( 'REST' )->is_rest() || $this->cls( 'REST' )->is_internal_rest() ) { - return $this->conf( Base::O_CACHE_TTL_REST ); + if ($this->cls('REST')->is_rest() || $this->cls('REST')->is_internal_rest()) { + return $this->conf(Base::O_CACHE_TTL_REST); } - return $this->conf( Base::O_CACHE_TTL_PUB ); + return $this->conf(Base::O_CACHE_TTL_PUB); } /** @@ -503,40 +524,38 @@ public function get_ttl() { * @access public * @since 1.1.3 */ - public function check_redirect( $location, $status ) { // TODO: some env don't have SCRIPT_URI but only REQUEST_URI, need to be compatible - if ( ! empty( $_SERVER[ 'SCRIPT_URI' ] ) ) { // dont check $status == '301' anymore - self::debug( "301 from " . $_SERVER[ 'SCRIPT_URI' ] ); - self::debug( "301 to $location" ); - - $to_check = array( - PHP_URL_SCHEME, - PHP_URL_HOST, - PHP_URL_PATH, - PHP_URL_QUERY, - ); + public function check_redirect($location, $status) + { + // TODO: some env don't have SCRIPT_URI but only REQUEST_URI, need to be compatible + if (!empty($_SERVER['SCRIPT_URI'])) { + // dont check $status == '301' anymore + self::debug('301 from ' . $_SERVER['SCRIPT_URI']); + self::debug("301 to $location"); + + $to_check = array(PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PATH, PHP_URL_QUERY); $is_same_redirect = true; - foreach ( $to_check as $v ) { - $url_parsed = $v == PHP_URL_QUERY ? $_SERVER[ 'QUERY_STRING' ] : parse_url( $_SERVER[ 'SCRIPT_URI' ], $v ); - $target = parse_url( $location, $v ); + foreach ($to_check as $v) { + $url_parsed = $v == PHP_URL_QUERY ? $_SERVER['QUERY_STRING'] : parse_url($_SERVER['SCRIPT_URI'], $v); + $target = parse_url($location, $v); self::debug("Compare [from] $url_parsed [to] $target"); - if($v==PHP_URL_QUERY) { + if ($v == PHP_URL_QUERY) { $url_parsed = urldecode($url_parsed); $target = urldecode($target); } - if ( $url_parsed != $target ) { + if ($url_parsed != $target) { $is_same_redirect = false; - self::debug( "301 different redirection" ); + self::debug('301 different redirection'); break; } } - if ( $is_same_redirect ) { - self::set_nocache( '301 to same url' ); + if ($is_same_redirect) { + self::set_nocache('301 to same url'); } } @@ -550,16 +569,17 @@ public function check_redirect( $location, $status ) { // TODO: some env don't h * @access public * @return string empty string if empty, otherwise the cache control header. */ - public function output() { + public function output() + { $esi_hdr = ''; - if ( ESI::has_esi() ) { + if (ESI::has_esi()) { $esi_hdr = ',esi=on'; } $hdr = self::X_HEADER . ': '; - if ( defined( 'DONOTCACHEPAGE' ) && apply_filters( 'litespeed_const_DONOTCACHEPAGE', DONOTCACHEPAGE ) ) { - Debug2::debug( "[Ctrl] ❌ forced no cache [reason] DONOTCACHEPAGE const" ); + if (defined('DONOTCACHEPAGE') && apply_filters('litespeed_const_DONOTCACHEPAGE', DONOTCACHEPAGE)) { + Debug2::debug('[Ctrl] ❌ forced no cache [reason] DONOTCACHEPAGE const'); $hdr .= 'no-cache' . $esi_hdr; return $hdr; } @@ -587,22 +607,20 @@ public function output() { // Fix cli `uninstall --deactivate` fatal err - if ( ! self::is_cacheable() ) { + if (!self::is_cacheable()) { $hdr .= 'no-cache' . $esi_hdr; return $hdr; } - if ( self::is_shared() ) { + if (self::is_shared()) { $hdr .= 'shared,private'; - } - elseif ( self::is_private() ) { + } elseif (self::is_private()) { $hdr .= 'private'; - } - else { + } else { $hdr .= 'public'; } - if ( self::is_no_vary() ) { + if (self::is_no_vary()) { $hdr .= ',no-vary'; } @@ -616,105 +634,104 @@ public function output() { * @access public * @since 1.1.3 */ - public function finalize() { - if ( defined( 'LITESPEED_GUEST' ) && LITESPEED_GUEST ) { + public function finalize() + { + if (defined('LITESPEED_GUEST') && LITESPEED_GUEST) { // return; } - if ( is_preview() ) { - self::set_nocache( 'preview page' ); + if (is_preview()) { + self::set_nocache('preview page'); return; } // Check if has metabox non-cacheable setting or not - if ( file_exists( LSCWP_DIR . 'src/metabox.cls.php' ) && $this->cls( 'Metabox' )->setting( 'litespeed_no_cache' ) ) { - self::set_nocache( 'per post metabox setting' ); + if (file_exists(LSCWP_DIR . 'src/metabox.cls.php') && $this->cls('Metabox')->setting('litespeed_no_cache')) { + self::set_nocache('per post metabox setting'); return; } // Check if URI is forced public cache - $excludes = $this->conf( Base::O_CACHE_FORCE_PUB_URI ); - $hit = Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes, true ); - if ( $hit ) { - list( $result, $this_ttl ) = $hit; - self::set_public_forced( 'Setting: ' . $result ); - Debug2::debug( '[Ctrl] Forced public cacheable due to setting: ' . $result ); - if ( $this_ttl ) { - self::set_custom_ttl( $this_ttl ); + $excludes = $this->conf(Base::O_CACHE_FORCE_PUB_URI); + $hit = Utility::str_hit_array($_SERVER['REQUEST_URI'], $excludes, true); + if ($hit) { + list($result, $this_ttl) = $hit; + self::set_public_forced('Setting: ' . $result); + Debug2::debug('[Ctrl] Forced public cacheable due to setting: ' . $result); + if ($this_ttl) { + self::set_custom_ttl($this_ttl); } } - if ( self::is_public_forced() ) { + if (self::is_public_forced()) { return; } // Check if URI is forced cache - $excludes = $this->conf( Base::O_CACHE_FORCE_URI ); - $hit = Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes, true ); - if ( $hit ) { - list( $result, $this_ttl ) = $hit; + $excludes = $this->conf(Base::O_CACHE_FORCE_URI); + $hit = Utility::str_hit_array($_SERVER['REQUEST_URI'], $excludes, true); + if ($hit) { + list($result, $this_ttl) = $hit; self::force_cacheable(); - Debug2::debug( '[Ctrl] Forced cacheable due to setting: ' . $result ); - if ( $this_ttl ) { - self::set_custom_ttl( $this_ttl ); + Debug2::debug('[Ctrl] Forced cacheable due to setting: ' . $result); + if ($this_ttl) { + self::set_custom_ttl($this_ttl); } } // if is not cacheable, terminate check // Even no need to run 3rd party hook - if ( ! self::is_cacheable() ) { - Debug2::debug( '[Ctrl] not cacheable before ctrl finalize' ); + if (!self::is_cacheable()) { + Debug2::debug('[Ctrl] not cacheable before ctrl finalize'); return; } // Apply 3rd party filter // NOTE: Hook always needs to run asap because some 3rd party set is_mobile in this hook - do_action('litespeed_control_finalize', defined( 'LSCACHE_IS_ESI' ) ? LSCACHE_IS_ESI : false ); // Pass ESI block id + do_action('litespeed_control_finalize', defined('LSCACHE_IS_ESI') ? LSCACHE_IS_ESI : false); // Pass ESI block id // if is not cacheable, terminate check - if ( ! self::is_cacheable() ) { - Debug2::debug( '[Ctrl] not cacheable after api_control' ); + if (!self::is_cacheable()) { + Debug2::debug('[Ctrl] not cacheable after api_control'); return; } // Check litespeed setting to set cacheable status - if ( ! $this->_setting_cacheable() ) { + if (!$this->_setting_cacheable()) { self::set_nocache(); return; } // If user has password cookie, do not cache (moved from vary) global $post; - if ( ! empty($post->post_password) && isset($_COOKIE['wp-postpass_' . COOKIEHASH]) ) { + if (!empty($post->post_password) && isset($_COOKIE['wp-postpass_' . COOKIEHASH])) { // If user has password cookie, do not cache self::set_nocache('pswd cookie'); return; } // The following check to the end is ONLY for mobile - $is_mobile = apply_filters( 'litespeed_is_mobile', false ); - if ( ! $this->conf( Base::O_CACHE_MOBILE ) ) { - if ( $is_mobile ) { - self::set_nocache( 'mobile' ); + $is_mobile = apply_filters('litespeed_is_mobile', false); + if (!$this->conf(Base::O_CACHE_MOBILE)) { + if ($is_mobile) { + self::set_nocache('mobile'); } return; } - $env_vary = isset( $_SERVER[ 'LSCACHE_VARY_VALUE' ] ) ? $_SERVER[ 'LSCACHE_VARY_VALUE' ] : false; - if ( ! $env_vary ) { - $env_vary = isset( $_SERVER[ 'HTTP_X_LSCACHE_VARY_VALUE' ] ) ? $_SERVER[ 'HTTP_X_LSCACHE_VARY_VALUE' ] : false; + $env_vary = isset($_SERVER['LSCACHE_VARY_VALUE']) ? $_SERVER['LSCACHE_VARY_VALUE'] : false; + if (!$env_vary) { + $env_vary = isset($_SERVER['HTTP_X_LSCACHE_VARY_VALUE']) ? $_SERVER['HTTP_X_LSCACHE_VARY_VALUE'] : false; } - if ( $env_vary && strpos( $env_vary, 'ismobile' ) !== false ) { - if ( ! wp_is_mobile() && ! $is_mobile ) { - self::set_nocache( 'is not mobile' ); // todo: no need to uncache, it will correct vary value in vary finalize anyways + if ($env_vary && strpos($env_vary, 'ismobile') !== false) { + if (!wp_is_mobile() && !$is_mobile) { + self::set_nocache('is not mobile'); // todo: no need to uncache, it will correct vary value in vary finalize anyways return; } - } - elseif ( wp_is_mobile() || $is_mobile ) { - self::set_nocache( 'is mobile' ); + } elseif (wp_is_mobile() || $is_mobile) { + self::set_nocache('is mobile'); return; } - } /** @@ -723,7 +740,8 @@ public function finalize() { * @since 3.0 * @access public */ - public static function is_mobile() { + public static function is_mobile() + { return wp_is_mobile(); } @@ -734,85 +752,85 @@ public static function is_mobile() { * @access private * @return boolean True if cacheable, false otherwise. */ - private function _setting_cacheable() { + private function _setting_cacheable() + { // logged_in users already excluded, no hook added - if( ! empty( $_REQUEST[ Router::ACTION ] ) ) { - return $this->_no_cache_for( 'Query String Action' ); + if (!empty($_REQUEST[Router::ACTION])) { + return $this->_no_cache_for('Query String Action'); } - $method = isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : 'unknown'; - if ( 'GET' !== $method && 'HEAD' !== $method ) { + $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'unknown'; + if ('GET' !== $method && 'HEAD' !== $method) { return $this->_no_cache_for('Not GET method: ' . $method); } - if ( is_feed() && $this->conf( Base::O_CACHE_TTL_FEED ) == 0 ) { + if (is_feed() && $this->conf(Base::O_CACHE_TTL_FEED) == 0) { return $this->_no_cache_for('feed'); } - if ( is_trackback() ) { + if (is_trackback()) { return $this->_no_cache_for('trackback'); } - if ( is_search() ) { + if (is_search()) { return $this->_no_cache_for('search'); } -// if ( !defined('WP_USE_THEMES') || !WP_USE_THEMES ) { -// return $this->_no_cache_for('no theme used'); -// } + // if ( !defined('WP_USE_THEMES') || !WP_USE_THEMES ) { + // return $this->_no_cache_for('no theme used'); + // } // Check private cache URI setting - $excludes = $this->conf( Base::O_CACHE_PRIV_URI ); - $result = Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ); - if ( $result ) { - self::set_private( 'Admin cfg Private Cached URI: ' . $result ); + $excludes = $this->conf(Base::O_CACHE_PRIV_URI); + $result = Utility::str_hit_array($_SERVER['REQUEST_URI'], $excludes); + if ($result) { + self::set_private('Admin cfg Private Cached URI: ' . $result); } - if ( ! self::is_forced_cacheable() ) { - + if (!self::is_forced_cacheable()) { // Check if URI is excluded from cache - $excludes = $this->conf( Base::O_CACHE_EXC ); - $result = Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ); - if ( $result ) { - return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ); + $excludes = $this->conf(Base::O_CACHE_EXC); + $result = Utility::str_hit_array($_SERVER['REQUEST_URI'], $excludes); + if ($result) { + return $this->_no_cache_for('Admin configured URI Do not cache: ' . $result); } // Check QS excluded setting - $excludes = $this->conf( Base::O_CACHE_EXC_QS ); - if ( ! empty( $excludes ) && $qs = $this->_is_qs_excluded( $excludes ) ) { - return $this->_no_cache_for( 'Admin configured QS Do not cache: ' . $qs ); + $excludes = $this->conf(Base::O_CACHE_EXC_QS); + if (!empty($excludes) && ($qs = $this->_is_qs_excluded($excludes))) { + return $this->_no_cache_for('Admin configured QS Do not cache: ' . $qs); } - $excludes = $this->conf( Base::O_CACHE_EXC_CAT ); - if ( ! empty( $excludes ) && has_category( $excludes ) ) { - return $this->_no_cache_for( 'Admin configured Category Do not cache.' ); + $excludes = $this->conf(Base::O_CACHE_EXC_CAT); + if (!empty($excludes) && has_category($excludes)) { + return $this->_no_cache_for('Admin configured Category Do not cache.'); } - $excludes = $this->conf( Base::O_CACHE_EXC_TAG ); - if ( ! empty( $excludes ) && has_tag( $excludes ) ) { - return $this->_no_cache_for( 'Admin configured Tag Do not cache.' ); + $excludes = $this->conf(Base::O_CACHE_EXC_TAG); + if (!empty($excludes) && has_tag($excludes)) { + return $this->_no_cache_for('Admin configured Tag Do not cache.'); } - $excludes = $this->conf( Base::O_CACHE_EXC_COOKIES ); - if ( ! empty( $excludes ) && ! empty( $_COOKIE ) ) { - $cookie_hit = array_intersect( array_keys( $_COOKIE ), $excludes ); - if ( $cookie_hit ) { - return $this->_no_cache_for( 'Admin configured Cookie Do not cache.' ); + $excludes = $this->conf(Base::O_CACHE_EXC_COOKIES); + if (!empty($excludes) && !empty($_COOKIE)) { + $cookie_hit = array_intersect(array_keys($_COOKIE), $excludes); + if ($cookie_hit) { + return $this->_no_cache_for('Admin configured Cookie Do not cache.'); } } - $excludes = $this->conf( Base::O_CACHE_EXC_USERAGENTS ); - if ( ! empty( $excludes ) && isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) ) { - $nummatches = preg_match( Utility::arr2regex( $excludes ), $_SERVER[ 'HTTP_USER_AGENT' ] ); - if ( $nummatches ) { - return $this->_no_cache_for('Admin configured User Agent Do not cache.'); + $excludes = $this->conf(Base::O_CACHE_EXC_USERAGENTS); + if (!empty($excludes) && isset($_SERVER['HTTP_USER_AGENT'])) { + $nummatches = preg_match(Utility::arr2regex($excludes), $_SERVER['HTTP_USER_AGENT']); + if ($nummatches) { + return $this->_no_cache_for('Admin configured User Agent Do not cache.'); } } // Check if is exclude roles ( Need to set Vary too ) - if ( $result = $this->in_cache_exc_roles() ) { - return $this->_no_cache_for( 'Role Excludes setting ' . $result ); + if ($result = $this->in_cache_exc_roles()) { + return $this->_no_cache_for('Role Excludes setting ' . $result); } } @@ -827,7 +845,8 @@ private function _setting_cacheable() { * @param string $reason An explanation for why the page is not cacheable. * @return boolean Return false. */ - private function _no_cache_for( $reason ) { + private function _no_cache_for($reason) + { Debug2::debug('[Ctrl] X Cache_control off - ' . $reason); return false; } @@ -840,11 +859,11 @@ private function _no_cache_for( $reason ) { * @param array $excludes QS excludes setting * @return boolean|string False if not excluded, otherwise the hit qs list */ - private function _is_qs_excluded( $excludes ) { - if ( ! empty( $_GET ) && $intersect = array_intersect( array_keys( $_GET ), $excludes ) ) { - return implode( ',', $intersect ); + private function _is_qs_excluded($excludes) + { + if (!empty($_GET) && ($intersect = array_intersect(array_keys($_GET), $excludes))) { + return implode(',', $intersect); } return false; } - -} \ No newline at end of file +} diff --git a/src/core.cls.php b/src/core.cls.php index 69f39f69b..905289c5a 100644 --- a/src/core.cls.php +++ b/src/core.cls.php @@ -10,7 +10,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Core extends Root { @@ -239,7 +239,6 @@ public function init() // test: Simulate a purge all // if (defined( 'LITESPEED_CLI' )) Purge::add('test'.date('Ymd.His')); - } /** @@ -262,7 +261,7 @@ public function after_user_init() */ $this->cls('ESI')->init(); - if (!is_admin() && !defined('LITESPEED_GUEST_OPTM') && $result = $this->cls('Conf')->in_optm_exc_roles()) { + if (!is_admin() && !defined('LITESPEED_GUEST_OPTM') && ($result = $this->cls('Conf')->in_optm_exc_roles())) { Debug2::debug('[Core] ⛑️ bypass_optm: hit Role Excludes setting: ' . $result); !defined('LITESPEED_NO_OPTM') && define('LITESPEED_NO_OPTM', true); } @@ -362,7 +361,7 @@ public function proceed_action($action) } if (Router::is_ajax()) { - exit; + exit(); } } @@ -486,7 +485,6 @@ public function send_headers_force($buffer) $this->send_headers(true); - // Init comment info $running_info_showing = defined('LITESPEED_IS_HTML') || defined('LSCACHE_IS_ESI'); if (defined('LSCACHE_ESI_SILENCE')) { @@ -525,7 +523,7 @@ public function send_headers_force($buffer) } if (apply_filters('litespeed_is_json', false)) { - if (json_decode($buffer, true) == NULL) { + if (json_decode($buffer, true) == null) { Debug2::debug('[Core] Buffer converting to JSON'); $buffer = json_encode($buffer); $buffer = trim($buffer, '"'); @@ -595,13 +593,15 @@ public function send_headers($is_forced = false) $cache_support = Control::is_cacheable() ? 'cached' : 'uncached'; } - $this->_comment(sprintf( - '%1$s %2$s by LiteSpeed Cache %4$s on %3$s', - defined('LSCACHE_IS_ESI') ? 'Block' : 'Page', - $cache_support, - date('Y-m-d H:i:s', time() + LITESPEED_TIME_OFFSET), - self::VER - )); + $this->_comment( + sprintf( + '%1$s %2$s by LiteSpeed Cache %4$s on %3$s', + defined('LSCACHE_IS_ESI') ? 'Block' : 'Page', + $cache_support, + date('Y-m-d H:i:s', time() + LITESPEED_TIME_OFFSET), + self::VER + ) + ); // send Control header if (defined('LITESPEED_ON') && $control_header) { @@ -629,7 +629,9 @@ public function send_headers($is_forced = false) if (defined('LITESPEED_ON') && defined('LSCWP_LOG')) { $vary = $this->cls('Vary')->finalize_full_varies(); - if ($vary) $this->_comment('Full varies: ' . $vary); + if ($vary) { + $this->_comment('Full varies: ' . $vary); + } } // Admin QS show header action @@ -707,7 +709,7 @@ public static function comment($data) private function _comment($data) { - $this->_footer_comment .= "\n"; + $this->_footer_comment .= "\n'; } /** @@ -716,11 +718,15 @@ private function _comment($data) */ private function _http_header($header) { - if (defined('LITESPEED_CLI')) return; + if (defined('LITESPEED_CLI')) { + return; + } @header($header); - if (!defined('LSCWP_LOG')) return; + if (!defined('LSCWP_LOG')) { + return; + } Debug2::debug('💰 ' . $header); } } diff --git a/src/crawler-map.cls.php b/src/crawler-map.cls.php index bb519e81d..633b10088 100644 --- a/src/crawler-map.cls.php +++ b/src/crawler-map.cls.php @@ -8,7 +8,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Crawler_Map extends Root { @@ -55,7 +55,8 @@ public function save_map_status($list, $curr_crawler) // Replace current crawler's position $curr_crawler = (int) $curr_crawler; - foreach ($list as $bit => $ids) { // $ids = [ id => [ url, code ], ... ] + foreach ($list as $bit => $ids) { + // $ids = [ id => [ url, code ], ... ] if (!$ids) { continue; } @@ -75,7 +76,7 @@ public function save_map_status($list, $curr_crawler) $existing = $wpdb->get_results($q, ARRAY_A); // Update current crawler status tag in existing blacklist if ($existing) { - $count = $wpdb->query("UPDATE `$this->_tb_blacklist` SET res = $sql_res WHERE id IN ( " . implode(',', array_column($existing, 'id')) . " )"); + $count = $wpdb->query("UPDATE `$this->_tb_blacklist` SET res = $sql_res WHERE id IN ( " . implode(',', array_column($existing, 'id')) . ' )'); self::debug('Update blacklist [count] ' . $count); } @@ -103,11 +104,11 @@ public function save_map_status($list, $curr_crawler) // Update sitemap reason w/ HTTP code $reason_array = array(); foreach ($ids as $id => $v2) { - $code = (int)$v2['code']; + $code = (int) $v2['code']; if (empty($reason_array[$code])) { $reason_array[$code] = array(); } - $reason_array[$code][] = (int)$id; + $reason_array[$code][] = (int) $id; } foreach ($reason_array as $code => $v2) { @@ -119,13 +120,21 @@ public function save_map_status($list, $curr_crawler) $code .= ','; } - $count = $wpdb->query("UPDATE `$this->_tb` SET reason=CONCAT(SUBSTRING_INDEX(reason, ',', $curr_crawler), '$code', SUBSTRING_INDEX(reason, ',', -$right_pos)) WHERE id IN (" . implode(',', $v2) . ")"); + $count = $wpdb->query( + "UPDATE `$this->_tb` SET reason=CONCAT(SUBSTRING_INDEX(reason, ',', $curr_crawler), '$code', SUBSTRING_INDEX(reason, ',', -$right_pos)) WHERE id IN (" . + implode(',', $v2) . + ')' + ); self::debug("Update map reason [code] $code [pos] left $curr_crawler right -$right_pos [count] $count"); // Update blacklist reason if ($bit == 'B' || $bit == 'N') { - $count = $wpdb->query("UPDATE `$this->_tb_blacklist` a LEFT JOIN `$this->_tb` b ON b.url = a.url SET a.reason=CONCAT(SUBSTRING_INDEX(a.reason, ',', $curr_crawler), '$code', SUBSTRING_INDEX(a.reason, ',', -$right_pos)) WHERE b.id IN (" . implode(',', $v2) . ")"); + $count = $wpdb->query( + "UPDATE `$this->_tb_blacklist` a LEFT JOIN `$this->_tb` b ON b.url = a.url SET a.reason=CONCAT(SUBSTRING_INDEX(a.reason, ',', $curr_crawler), '$code', SUBSTRING_INDEX(a.reason, ',', -$right_pos)) WHERE b.id IN (" . + implode(',', $v2) . + ')' + ); self::debug("Update blacklist [code] $code [pos] left $curr_crawler right -$right_pos [count] $count"); } @@ -148,7 +157,7 @@ public function blacklist_add($id) { global $wpdb; - $id = (int)$id; + $id = (int) $id; // Build res&reason $total_crawler = count(Crawler::cls()->list_crawlers()); @@ -188,7 +197,7 @@ public function blacklist_del($id) return; } - $id = (int)$id; + $id = (int) $id; self::debug('blacklist delete [id] ' . $id); $wpdb->query("UPDATE `$this->_tb` SET res=REPLACE(REPLACE(res, 'N', '-'), 'B', '-') WHERE url=(SELECT url FROM `$this->_tb_blacklist` WHERE id='$id')"); @@ -235,7 +244,7 @@ public function list_blacklist($limit = false, $offset = false) $total = $this->count_blacklist(); $offset = Utility::pagination($total, $limit, true); } - $q .= " LIMIT %d, %d"; + $q .= ' LIMIT %d, %d'; $q = $wpdb->prepare($q, $offset, $limit); } return $wpdb->get_results($q, ARRAY_A); @@ -356,7 +365,7 @@ private function _gen() } // use custom sitemap - if (!$sitemap = $this->conf(Base::O_CRAWLER_SITEMAP)) { + if (!($sitemap = $this->conf(Base::O_CRAWLER_SITEMAP))) { return false; } @@ -396,7 +405,8 @@ private function _gen() $full_blacklisted = array(); $partial_blacklisted = array(); foreach ($blacklist as $v) { - if (strpos($v['res'], '-') === false) { // Full blacklisted + if (strpos($v['res'], '-') === false) { + // Full blacklisted $full_blacklisted[] = $v['url']; } else { // Replace existing reason @@ -488,13 +498,15 @@ private function _parse($sitemap) } // start parsing - $xml_array = (array)$xml_object; - if (!empty($xml_array['sitemap'])) { // parse sitemap set + $xml_array = (array) $xml_object; + if (!empty($xml_array['sitemap'])) { + // parse sitemap set if (is_object($xml_array['sitemap'])) { - $xml_array['sitemap'] = (array)$xml_array['sitemap']; + $xml_array['sitemap'] = (array) $xml_array['sitemap']; } - if (!empty($xml_array['sitemap']['loc'])) { // is single sitemap + if (!empty($xml_array['sitemap']['loc'])) { + // is single sitemap $this->_parse($xml_array['sitemap']['loc']); } else { // parse multiple sitemaps @@ -505,7 +517,8 @@ private function _parse($sitemap) } } } - } elseif (!empty($xml_array['url'])) { // parse url set + } elseif (!empty($xml_array['url'])) { + // parse url set if (is_object($xml_array['url'])) { $xml_array['url'] = (array) $xml_array['url']; } diff --git a/src/crawler.cls.php b/src/crawler.cls.php index babdea7d0..5d79c00f2 100644 --- a/src/crawler.cls.php +++ b/src/crawler.cls.php @@ -8,7 +8,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Crawler extends Root { @@ -34,17 +34,17 @@ class Crawler extends Root private $_crawler_conf = array( 'cookies' => array(), 'headers' => array(), - 'ua' => '', + 'ua' => '', ); private $_crawlers = array(); private $_cur_threads = -1; private $_max_run_time; private $_cur_thread_time; private $_map_status_list = array( - 'H' => array(), - 'M' => array(), - 'B' => array(), - 'N' => array(), + 'H' => array(), + 'M' => array(), + 'B' => array(), + 'N' => array(), ); protected $_summary; @@ -76,10 +76,14 @@ private function _get_server_cpu() { $cpuinfo_file = '/proc/cpuinfo'; $setting_open_dir = ini_get('open_basedir'); - if ($setting_open_dir) return 1; // Server has limit + if ($setting_open_dir) { + return 1; + } // Server has limit try { - if (!@is_file($cpuinfo_file)) return 1; + if (!@is_file($cpuinfo_file)) { + return 1; + } } catch (\Exception $e) { return 1; } @@ -106,14 +110,17 @@ public function is_active($curr) * @since 4.3 */ public function toggle_activeness($curr) - { // param type: int + { + // param type: int $bypass_list = self::get_option('bypass_list', array()); - if (in_array($curr, $bypass_list)) { // when the ith opt was off / in the bypassed list, turn it on / remove it from the list + if (in_array($curr, $bypass_list)) { + // when the ith opt was off / in the bypassed list, turn it on / remove it from the list unset($bypass_list[array_search($curr, $bypass_list)]); $bypass_list = array_values($bypass_list); self::update_option('bypass_list', $bypass_list); return true; - } else { // when the ith opt was on / not in the bypassed list, turn it off / add it to the list + } else { + // when the ith opt was on / not in the bypassed list, turn it off / add it to the list $bypass_list[] = (int) $curr; self::update_option('bypass_list', $bypass_list); return false; @@ -145,24 +152,24 @@ public function clear_disabled_list() public static function get_summary($field = false) { $_default = array( - 'list_size' => 0, - 'last_update_time' => 0, - 'curr_crawler' => 0, - 'curr_crawler_beginning_time' => 0, - 'last_pos' => 0, - 'last_count' => 0, - 'last_crawled' => 0, - 'last_start_time' => 0, - 'last_status' => '', - 'is_running' => 0, - 'end_reason' => '', - 'meta_save_time' => 0, - 'pos_reset_check' => 0, - 'done' => 0, - 'this_full_beginning_time' => 0, - 'last_full_time_cost' => 0, - 'last_crawler_total_cost' => 0, - 'crawler_stats' => array(), // this will store all crawlers hit/miss crawl status + 'list_size' => 0, + 'last_update_time' => 0, + 'curr_crawler' => 0, + 'curr_crawler_beginning_time' => 0, + 'last_pos' => 0, + 'last_count' => 0, + 'last_crawled' => 0, + 'last_start_time' => 0, + 'last_status' => '', + 'is_running' => 0, + 'end_reason' => '', + 'meta_save_time' => 0, + 'pos_reset_check' => 0, + 'done' => 0, + 'this_full_beginning_time' => 0, + 'last_full_time_cost' => 0, + 'last_crawler_total_cost' => 0, + 'crawler_stats' => array(), // this will store all crawlers hit/miss crawl status ); wp_cache_delete('alloptions', 'options'); // ensure the summary is current @@ -486,7 +493,7 @@ private function _adjust_current_threads() // init if ($curload > $this->_crawler_conf['load_limit']) { $curthreads = 0; - } elseif ($curload >= ($this->_crawler_conf['load_limit'] - 1)) { + } elseif ($curload >= $this->_crawler_conf['load_limit'] - 1) { $curthreads = 1; } else { $curthreads = intval($this->_crawler_conf['load_limit'] - $curload); @@ -498,7 +505,7 @@ private function _adjust_current_threads() // adjust $curthreads = $this->_cur_threads; if ($curload >= $this->_crawler_conf['load_limit'] + 1) { - sleep(5); // sleep 5 secs + sleep(5); // sleep 5 secs if ($curthreads >= 1) { $curthreads--; } @@ -506,7 +513,7 @@ private function _adjust_current_threads() // if ( $curthreads > 1 ) {// if already 1, keep $curthreads--; // } - } elseif (($curload + 1) < $this->_crawler_conf['load_limit']) { + } elseif ($curload + 1 < $this->_crawler_conf['load_limit']) { if ($curthreads < $this->conf(Base::O_CRAWLER_THREADS)) { $curthreads++; } @@ -573,12 +580,14 @@ private function _do_running() // check result headers foreach ($rows as $row) { // self::debug('chunk fetching 553'); - if (empty($rets[$row['id']])) { // If already in blacklist, no curl happened, no corresponding record + if (empty($rets[$row['id']])) { + // If already in blacklist, no curl happened, no corresponding record continue; } // self::debug('chunk fetching 557'); // check response - if ($rets[$row['id']]['code'] == 428) { // HTTP/1.1 428 Precondition Required (need to test) + if ($rets[$row['id']]['code'] == 428) { + // HTTP/1.1 428 Precondition Required (need to test) $this->_end_reason = 'crawler_disabled'; self::debug('crawler_disabled'); return; @@ -586,8 +595,8 @@ private function _do_running() $status = $this->_status_parse($rets[$row['id']]['header'], $rets[$row['id']]['code'], $row['url']); // B or H or M or N(nocache) $this->_map_status_list[$status][$row['id']] = array( - 'url' => $row['url'], - 'code' => $rets[$row['id']]['code'], // 201 or 200 or 404 + 'url' => $row['url'], + 'code' => $rets[$row['id']]['code'], // 201 or 200 or 404 ); if (empty($this->_summary['crawler_stats'][$this->_summary['curr_crawler']][$status])) { $this->_summary['crawler_stats'][$this->_summary['curr_crawler']][$status] = 0; @@ -668,7 +677,9 @@ private function _do_running() */ private function _multi_request($rows, $options) { - if (!function_exists('curl_multi_init')) exit('curl_multi_init disabled'); + if (!function_exists('curl_multi_init')) { + exit('curl_multi_init disabled'); + } $mh = curl_multi_init(); $curls = array(); foreach ($rows as $row) { @@ -679,7 +690,9 @@ private function _multi_request($rows, $options) continue; } - if (!function_exists('curl_init')) exit('curl_init disabled'); + if (!function_exists('curl_init')) { + exit('curl_init disabled'); + } $curls[$row['id']] = curl_init(); @@ -725,7 +738,7 @@ private function _multi_request($rows, $options) $ret[$row['id']] = array( 'header' => $header, - 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), + 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), ); // self::debug('-----debug4'); curl_multi_remove_handle($mh, $ch); @@ -756,18 +769,17 @@ private function _status_parse($header, $code, $url) } // If blacklist is disabled - if ((defined('LITESPEED_CRAWLER_DISABLE_BLOCKLIST') && LITESPEED_CRAWLER_DISABLE_BLOCKLIST) || apply_filters('litespeed_crawler_disable_blocklist', '__return_false', $url)) { + if ( + (defined('LITESPEED_CRAWLER_DISABLE_BLOCKLIST') && LITESPEED_CRAWLER_DISABLE_BLOCKLIST) || + apply_filters('litespeed_crawler_disable_blocklist', '__return_false', $url) + ) { return 'M'; } return 'N'; // Blacklist } - $_cache_headers = array( - 'x-litespeed-cache', - 'x-lsadc-cache', - 'x-qc-cache', - ); + $_cache_headers = array('x-litespeed-cache', 'x-lsadc-cache', 'x-qc-cache'); foreach ($_cache_headers as $_header) { if (stripos($header, $_header) !== false) { @@ -779,7 +791,10 @@ private function _status_parse($header, $code, $url) } // If blacklist is disabled - if ((defined('LITESPEED_CRAWLER_DISABLE_BLOCKLIST') && LITESPEED_CRAWLER_DISABLE_BLOCKLIST) || apply_filters('litespeed_crawler_disable_blocklist', '__return_false', $url)) { + if ( + (defined('LITESPEED_CRAWLER_DISABLE_BLOCKLIST') && LITESPEED_CRAWLER_DISABLE_BLOCKLIST) || + apply_filters('litespeed_crawler_disable_blocklist', '__return_false', $url) + ) { return 'M'; } @@ -881,7 +896,8 @@ private function _get_curl_options($crawler_only = false) * @since 3.3 */ public function self_curl($url, $ua, $uid = false, $accept = false) - { // $accept not in use yet + { + // $accept not in use yet $this->_crawler_conf['base'] = home_url(); $this->_crawler_conf['ua'] = $ua; if ($accept) { @@ -921,7 +937,8 @@ private function _terminate_running() { $this->_map_status_list = $this->cls('Crawler_Map')->save_map_status($this->_map_status_list, $this->_summary['curr_crawler']); - if ($this->_end_reason == 'end') { // Current crawler is fully done + if ($this->_end_reason == 'end') { + // Current crawler is fully done // $end_reason = sprintf( __( 'Crawler %s reached end of sitemap file.', 'litespeed-cache' ), '#' . ( $this->_summary['curr_crawler'] + 1 ) ); $this->_summary['curr_crawler']++; // Jump to next cralwer // $this->_summary[ 'crawler_stats' ][ $this->_summary[ 'curr_crawler' ] ] = array(); // reset this at next crawl time @@ -1006,7 +1023,8 @@ public function list_crawlers() $crawler_factors[$this_cookie_key] = array(); foreach ($v['vals'] as $v2) { - $crawler_factors[$this_cookie_key][$v2] = $v2 == '_null' ? '' : '🍪' . esc_html($v['name']) . '=' . esc_html($v2); + $crawler_factors[$this_cookie_key][$v2] = + $v2 == '_null' ? '' : '🍪' . esc_html($v['name']) . '=' . esc_html($v2); } } @@ -1032,7 +1050,6 @@ private function _recursive_build_crawler($crawler_factors, $group = array(), $i $final_list = array(); foreach ($crawler_factors[$current_factor] as $k => $v) { - // Don't alter $group bcos of loop usage $item = $group; $item['title'] = !empty($group['title']) ? $group['title'] : ''; @@ -1070,7 +1087,6 @@ public function json_path() return LITESPEED_STATIC_URL . '/crawler/' . $this->_sitemeta; } - /** * Create reset pos file * @@ -1177,7 +1193,7 @@ public function handler() } break; - // Handle the ajax request to proceed crawler manually by admin + // Handle the ajax request to proceed crawler manually by admin case self::TYPE_START: self::start_async(); break; diff --git a/src/css.cls.php b/src/css.cls.php index c4d259d1a..fa2957b6c 100644 --- a/src/css.cls.php +++ b/src/css.cls.php @@ -8,7 +8,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class CSS extends Base { @@ -82,7 +82,7 @@ private function _gen_ccss_file_tag($request_url) } $sep_uri = $this->conf(self::O_OPTM_CCSS_SEP_URI); - if ($sep_uri && $hit = Utility::str_hit_array($request_url, $sep_uri)) { + if ($sep_uri && ($hit = Utility::str_hit_array($request_url, $sep_uri))) { Debug2::debug('[CCSS] Separate CCSS due to separate URI setting: ' . $hit); return $request_url; } @@ -127,7 +127,6 @@ private function _ccss() $ua = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; - // Store it to prepare for cron Core::comment('QUIC.cloud CCSS in queue'); $this->_queue = $this->load_queue('ccss'); @@ -139,16 +138,16 @@ private function _ccss() $queue_k = (strlen($vary) > 32 ? md5($vary) : $vary) . ' ' . $url_tag; $this->_queue[$queue_k] = array( - 'url' => apply_filters('litespeed_ccss_url', $request_url), - 'user_agent' => substr($ua, 0, 200), - 'is_mobile' => $this->_separate_mobile(), - 'is_webp' => $this->cls('Media')->webp_support() ? 1 : 0, - 'uid' => $uid, - 'vary' => $vary, - 'url_tag' => $url_tag, + 'url' => apply_filters('litespeed_ccss_url', $request_url), + 'user_agent' => substr($ua, 0, 200), + 'is_mobile' => $this->_separate_mobile(), + 'is_webp' => $this->cls('Media')->webp_support() ? 1 : 0, + 'uid' => $uid, + 'vary' => $vary, + 'url_tag' => $url_tag, ); // Current UA will be used to request $this->save_queue('ccss', $this->_queue); - self::debug('Added queue_ccss [url_tag] ' . $url_tag . ' [UA] ' . $ua . ' [vary] ' . $vary . ' [uid] ' . $uid); + self::debug('Added queue_ccss [url_tag] ' . $url_tag . ' [UA] ' . $ua . ' [vary] ' . $vary . ' [uid] ' . $uid); // Prepare cache tag for later purge Tag::add('CCSS.' . md5($queue_k)); @@ -226,7 +225,8 @@ private function _cron_handler($type, $continue) $i++; $res = $this->_send_req($v['url'], $k, $v['uid'], $v['user_agent'], $v['vary'], $v['url_tag'], $type, $v['is_mobile'], $v['is_webp']); - if (!$res) { // Status is wrong, drop this this->_queue + if (!$res) { + // Status is wrong, drop this this->_queue unset($this->_queue[$k]); $this->save_queue($type, $this->_queue); @@ -302,13 +302,13 @@ private function _send_req($request_url, $queue_k, $uid, $user_agent, $vary, $ur // Generate critical css $data = array( - 'url' => $request_url, - 'queue_k' => $queue_k, - 'user_agent' => $user_agent, - 'is_mobile' => $is_mobile ? 1 : 0, // todo:compatible w/ tablet - 'is_webp' => $is_webp ? 1 : 0, - 'html' => $html, - 'css' => $css, + 'url' => $request_url, + 'queue_k' => $queue_k, + 'user_agent' => $user_agent, + 'is_mobile' => $is_mobile ? 1 : 0, // todo:compatible w/ tablet + 'is_webp' => $is_webp ? 1 : 0, + 'html' => $html, + 'css' => $css, ); self::debug('Generating: ', $data); @@ -394,13 +394,13 @@ public function test_url($request_url) // EOT; $data = array( - 'url' => $request_url, - 'ccss_type' => 'test', - 'user_agent' => $user_agent, - 'is_mobile' => 0, - 'html' => $html, - 'css' => $css, - 'type' => 'CCSS', + 'url' => $request_url, + 'ccss_type' => 'test', + 'user_agent' => $user_agent, + 'is_mobile' => 0, + 'html' => $html, + 'css' => $css, + 'type' => 'CCSS', ); // self::debug( 'Generating: ', $data ); @@ -420,7 +420,7 @@ public function prepare_html($request_url, $user_agent, $uid = false) $html = $this->cls('Crawler')->self_curl(add_query_arg('LSCWP_CTRL', 'before_optm', $request_url), $user_agent, $uid); Debug2::debug2('[CSS] self_curl result....', $html); - if ( ! $html ) { + if (!$html) { return false; } @@ -473,7 +473,8 @@ public function prepare_css($html, $is_webp = false, $dryrun = false) $debug_info = $attrs['href']; // Load CSS content - if (!$dryrun) { // Dryrun will not load CSS but just drop them + if (!$dryrun) { + // Dryrun will not load CSS but just drop them $con = $this->cls('Optimizer')->load_file($attrs['href']); if (!$con) { continue; @@ -481,7 +482,8 @@ public function prepare_css($html, $is_webp = false, $dryrun = false) } else { $con = ''; } - } else { // Inline style + } else { + // Inline style $attrs = Utility::parse_attr($match[2]); if (!empty($attrs['media']) && strpos($attrs['media'], 'print') !== false) { diff --git a/src/data.cls.php b/src/data.cls.php index a9a653fbf..6b6afbe90 100644 --- a/src/data.cls.php +++ b/src/data.cls.php @@ -8,30 +8,19 @@ * @author LiteSpeed Technologies */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class Data extends Root { +class Data extends Root +{ const LOG_TAG = '[Data]'; private $_db_updater = array( - '3.5.0.3' => array( - 'litespeed_update_3_5', - ), - '4.0' => array( - 'litespeed_update_4', - ), - '4.1' => array( - 'litespeed_update_4_1', - ), - '4.3' => array( - 'litespeed_update_4_3', - ), - '4.4.4-b1' => array( - 'litespeed_update_4_4_4', - ), - '5.3-a5' => array( - 'litespeed_update_5_3', - ), + '3.5.0.3' => array('litespeed_update_3_5'), + '4.0' => array('litespeed_update_4'), + '4.1' => array('litespeed_update_4_1'), + '4.3' => array('litespeed_update_4_3'), + '4.4.4-b1' => array('litespeed_update_4_4_4'), + '5.3-a5' => array('litespeed_update_5_3'), ); private $_db_site_updater = array( @@ -61,7 +50,8 @@ class Data extends Root { * * @since 1.3.1 */ - public function __construct() { + public function __construct() + { } /** @@ -73,21 +63,22 @@ public function __construct() { * @since 3.0 * @access public */ - public function correct_tb_existance() { + public function correct_tb_existance() + { // Gravatar - if ( $this->conf( Base::O_DISCUSS_AVATAR_CACHE ) ) { - $this->tb_create( 'avatar' ); + if ($this->conf(Base::O_DISCUSS_AVATAR_CACHE)) { + $this->tb_create('avatar'); } // Crawler - if ( $this->conf( Base::O_CRAWLER ) ) { - $this->tb_create( 'crawler' ); - $this->tb_create( 'crawler_blacklist' ); + if ($this->conf(Base::O_CRAWLER)) { + $this->tb_create('crawler'); + $this->tb_create('crawler_blacklist'); } // URL mapping - $this->tb_create( 'url' ); - $this->tb_create( 'url_file' ); + $this->tb_create('url'); + $this->tb_create('url_file'); // Image optm is a bit different. Only trigger creation when sending requests. Drop when destroying. } @@ -100,56 +91,57 @@ public function correct_tb_existance() { * @since 3.0 * @access public */ - public function conf_upgrade( $ver ) { + public function conf_upgrade($ver) + { // Skip count check if `Use Primary Site Configurations` is on // Deprecated since v3.0 as network primary site didn't override the subsites conf yet // if ( ! is_main_site() && ! empty ( $this->_site_options[ self::NETWORK_O_USE_PRIMARY ] ) ) { // return; // } - if ( $this->_get_upgrade_lock() ) { + if ($this->_get_upgrade_lock()) { return; } - $this->_set_upgrade_lock( true ); + $this->_set_upgrade_lock(true); require_once LSCWP_DIR . 'src/data.upgrade.func.php'; // Init log manually - if ( $this->conf( Base::O_DEBUG ) ) { - $this->cls( 'Debug2' )->init(); + if ($this->conf(Base::O_DEBUG)) { + $this->cls('Debug2')->init(); } - foreach ( $this->_db_updater as $k => $v ) { - if ( version_compare( $ver, $k, '<' ) ) { + foreach ($this->_db_updater as $k => $v) { + if (version_compare($ver, $k, '<')) { // run each callback - foreach ( $v as $v2 ) { - Debug2::debug( "[Data] Updating [ori_v] $ver \t[to] $k \t[func] $v2" ); - call_user_func( $v2 ); + foreach ($v as $v2) { + Debug2::debug("[Data] Updating [ori_v] $ver \t[to] $k \t[func] $v2"); + call_user_func($v2); } } } // Reload options - $this->cls( 'Conf' )->load_options(); + $this->cls('Conf')->load_options(); $this->correct_tb_existance(); // Update related files - $this->cls( 'Activation' )->update_files(); + $this->cls('Activation')->update_files(); // Update version to latest - Conf::delete_option( Base::_VER ); - Conf::add_option( Base::_VER, Core::VER ); + Conf::delete_option(Base::_VER); + Conf::add_option(Base::_VER, Core::VER); - Debug2::debug( '[Data] Updated version to ' . Core::VER ); + Debug2::debug('[Data] Updated version to ' . Core::VER); - $this->_set_upgrade_lock( false ); + $this->_set_upgrade_lock(false); - ! defined( 'LSWCP_EMPTYCACHE') && define( 'LSWCP_EMPTYCACHE', true );// clear all sites caches + !defined('LSWCP_EMPTYCACHE') && define('LSWCP_EMPTYCACHE', true); // clear all sites caches Purge::purge_all(); - Cloud::version_check( 'upgrade' ); + Cloud::version_check('upgrade'); } /** @@ -160,36 +152,37 @@ public function conf_upgrade( $ver ) { * @since 3.0 * @access public */ - public function conf_site_upgrade( $ver ) { - if ( $this->_get_upgrade_lock() ) { + public function conf_site_upgrade($ver) + { + if ($this->_get_upgrade_lock()) { return; } - $this->_set_upgrade_lock( true ); + $this->_set_upgrade_lock(true); require_once LSCWP_DIR . 'src/data.upgrade.func.php'; - foreach ( $this->_db_site_updater as $k => $v ) { - if ( version_compare( $ver, $k, '<' ) ) { + foreach ($this->_db_site_updater as $k => $v) { + if (version_compare($ver, $k, '<')) { // run each callback - foreach ( $v as $v2 ) { - Debug2::debug( "[Data] Updating site [ori_v] $ver \t[to] $k \t[func] $v2" ); - call_user_func( $v2 ); + foreach ($v as $v2) { + Debug2::debug("[Data] Updating site [ori_v] $ver \t[to] $k \t[func] $v2"); + call_user_func($v2); } } } // Reload options - $this->cls( 'Conf' )->load_site_options(); + $this->cls('Conf')->load_site_options(); - Conf::delete_site_option( Base::_VER ); - Conf::add_site_option( Base::_VER, Core::VER ); + Conf::delete_site_option(Base::_VER); + Conf::add_site_option(Base::_VER, Core::VER); - Debug2::debug( '[Data] Updated site_version to ' . Core::VER ); + Debug2::debug('[Data] Updated site_version to ' . Core::VER); - $this->_set_upgrade_lock( false ); + $this->_set_upgrade_lock(false); - ! defined( 'LSWCP_EMPTYCACHE') && define( 'LSWCP_EMPTYCACHE', true );// clear all sites caches + !defined('LSWCP_EMPTYCACHE') && define('LSWCP_EMPTYCACHE', true); // clear all sites caches Purge::purge_all(); } @@ -198,12 +191,13 @@ public function conf_site_upgrade( $ver ) { * * @since 3.0.1 */ - private function _get_upgrade_lock() { - $is_upgrading = get_option( 'litespeed.data.upgrading' ); - if ( ! $is_upgrading ) { - $this->_set_upgrade_lock( false ); // set option value to existed to avoid repeated db query next time + private function _get_upgrade_lock() + { + $is_upgrading = get_option('litespeed.data.upgrading'); + if (!$is_upgrading) { + $this->_set_upgrade_lock(false); // set option value to existed to avoid repeated db query next time } - if ( $is_upgrading && time() - $is_upgrading < 3600 ) { + if ($is_upgrading && time() - $is_upgrading < 3600) { return $is_upgrading; } @@ -215,13 +209,20 @@ private function _get_upgrade_lock() { * * @since 3.0.1 */ - public function check_upgrading_msg() { + public function check_upgrading_msg() + { $is_upgrading = $this->_get_upgrade_lock(); - if ( ! $is_upgrading ) { + if (!$is_upgrading) { return; } - Admin_Display::info( sprintf( __( 'The database has been upgrading in the background since %s. This message will disappear once upgrade is complete.', 'litespeed-cache' ), '' . Utility::readable_time( $is_upgrading ) . '' ) . ' [LiteSpeed]', true ); + Admin_Display::info( + sprintf( + __('The database has been upgrading in the background since %s. This message will disappear once upgrade is complete.', 'litespeed-cache'), + '' . Utility::readable_time($is_upgrading) . '' + ) . ' [LiteSpeed]', + true + ); } /** @@ -229,12 +230,12 @@ public function check_upgrading_msg() { * * @since 3.0.1 */ - private function _set_upgrade_lock( $lock ) { - if ( ! $lock ) { - update_option( 'litespeed.data.upgrading', -1 ); - } - else { - update_option( 'litespeed.data.upgrading', time() ); + private function _set_upgrade_lock($lock) + { + if (!$lock) { + update_option('litespeed.data.upgrading', -1); + } else { + update_option('litespeed.data.upgrading', time()); } } @@ -246,53 +247,53 @@ private function _set_upgrade_lock( $lock ) { * @since 3.0 * @access public */ - public function try_upgrade_conf_3_0() { - $previous_options = get_option( 'litespeed-cache-conf' ); - if ( ! $previous_options ) { - Cloud::version_check( 'new' ); + public function try_upgrade_conf_3_0() + { + $previous_options = get_option('litespeed-cache-conf'); + if (!$previous_options) { + Cloud::version_check('new'); return; } - $ver = $previous_options[ 'version' ]; + $ver = $previous_options['version']; - ! defined( 'LSCWP_CUR_V' ) && define( 'LSCWP_CUR_V', $ver ); + !defined('LSCWP_CUR_V') && define('LSCWP_CUR_V', $ver); // Init log manually - if ( $this->conf( Base::O_DEBUG ) ) { - $this->cls( 'Debug2' )->init(); + if ($this->conf(Base::O_DEBUG)) { + $this->cls('Debug2')->init(); } - Debug2::debug( '[Data] Upgrading previous settings [from] ' . $ver . ' [to] v3.0' ); + Debug2::debug('[Data] Upgrading previous settings [from] ' . $ver . ' [to] v3.0'); - if ( $this->_get_upgrade_lock() ) { + if ($this->_get_upgrade_lock()) { return; } - $this->_set_upgrade_lock( true ); + $this->_set_upgrade_lock(true); require_once LSCWP_DIR . 'src/data.upgrade.func.php'; // Here inside will update the version to v3.0 - litespeed_update_3_0( $ver ); + litespeed_update_3_0($ver); - $this->_set_upgrade_lock( false ); + $this->_set_upgrade_lock(false); - Debug2::debug( '[Data] Upgraded to v3.0' ); + Debug2::debug('[Data] Upgraded to v3.0'); // Upgrade from 3.0 to latest version $ver = '3.0'; - if ( Core::VER != $ver ) { - $this->conf_upgrade( $ver ); - } - else { + if (Core::VER != $ver) { + $this->conf_upgrade($ver); + } else { // Reload options - $this->cls( 'Conf' )->load_options(); + $this->cls('Conf')->load_options(); $this->correct_tb_existance(); - ! defined( 'LSWCP_EMPTYCACHE') && define( 'LSWCP_EMPTYCACHE', true );// clear all sites caches + !defined('LSWCP_EMPTYCACHE') && define('LSWCP_EMPTYCACHE', true); // clear all sites caches Purge::purge_all(); - Cloud::version_check( 'upgrade' ); + Cloud::version_check('upgrade'); } } @@ -302,10 +303,11 @@ public function try_upgrade_conf_3_0() { * @since 3.0 * @access public */ - public function tb( $tb ) { + public function tb($tb) + { global $wpdb; - switch ( $tb ) { + switch ($tb) { case 'img_optm': return $wpdb->prefix . self::TB_IMG_OPTM; break; @@ -337,7 +339,6 @@ public function tb( $tb ) { default: break; } - } /** @@ -346,9 +347,10 @@ public function tb( $tb ) { * @since 3.0 * @access public */ - public function tb_exist( $tb ) { + public function tb_exist($tb) + { global $wpdb; - return $wpdb->get_var( "SHOW TABLES LIKE '" . $this->tb( $tb ) . "'" ); + return $wpdb->get_var("SHOW TABLES LIKE '" . $this->tb($tb) . "'"); } /** @@ -357,8 +359,9 @@ public function tb_exist( $tb ) { * @since 2.0 * @access private */ - private function _tb_structure( $tb ) { - return File::read( LSCWP_DIR . 'src/data_structure/' . $tb . '.sql' ); + private function _tb_structure($tb) + { + return File::read(LSCWP_DIR . 'src/data_structure/' . $tb . '.sql'); } /** @@ -367,29 +370,30 @@ private function _tb_structure( $tb ) { * @since 3.0 * @access public */ - public function tb_create( $tb ) { + public function tb_create($tb) + { global $wpdb; - Debug2::debug2( '[Data] Checking table ' . $tb ); + Debug2::debug2('[Data] Checking table ' . $tb); // Check if table exists first - if ( $this->tb_exist( $tb ) ) { - Debug2::debug2( '[Data] Existed' ); + if ($this->tb_exist($tb)) { + Debug2::debug2('[Data] Existed'); return; } - Debug2::debug( '[Data] Creating ' . $tb ); + Debug2::debug('[Data] Creating ' . $tb); $sql = sprintf( - 'CREATE TABLE IF NOT EXISTS `%1$s` (' . $this->_tb_structure( $tb ) . ') %2$s;', - $this->tb( $tb ), + 'CREATE TABLE IF NOT EXISTS `%1$s` (' . $this->_tb_structure($tb) . ') %2$s;', + $this->tb($tb), $wpdb->get_charset_collate() // 'DEFAULT CHARSET=utf8' ); - $res = $wpdb->query( $sql ); - if ( $res !== true ) { - Debug2::debug( '[Data] Warning! Creating table failed!', $sql ); - Admin_Display::error( Error::msg( 'failed_tb_creation', array( '' . $tb . '', '' . $sql . '' ) ) ); + $res = $wpdb->query($sql); + if ($res !== true) { + Debug2::debug('[Data] Warning! Creating table failed!', $sql); + Admin_Display::error(Error::msg('failed_tb_creation', array('' . $tb . '', '' . $sql . ''))); } } @@ -399,17 +403,18 @@ public function tb_create( $tb ) { * @since 3.0 * @access public */ - public function tb_del( $tb ) { + public function tb_del($tb) + { global $wpdb; - if ( ! $this->tb_exist( $tb ) ) { + if (!$this->tb_exist($tb)) { return; } - Debug2::debug( '[Data] Deleting table ' . $tb ); + Debug2::debug('[Data] Deleting table ' . $tb); - $q = 'DROP TABLE IF EXISTS ' . $this->tb( $tb ); - $wpdb->query( $q ); + $q = 'DROP TABLE IF EXISTS ' . $this->tb($tb); + $wpdb->query($q); } /** @@ -418,12 +423,13 @@ public function tb_del( $tb ) { * @since 3.0 * @access public */ - public function tables_del() { - $this->tb_del( 'avatar' ); - $this->tb_del( 'crawler' ); - $this->tb_del( 'crawler_blacklist' ); - $this->tb_del( 'url' ); - $this->tb_del( 'url_file' ); + public function tables_del() + { + $this->tb_del('avatar'); + $this->tb_del('crawler'); + $this->tb_del('crawler_blacklist'); + $this->tb_del('url'); + $this->tb_del('url_file'); // Deleting img_optm only can be done when destroy all optm images } @@ -433,10 +439,11 @@ public function tables_del() { * * @since 4.0 */ - public function table_truncate( $tb ) { + public function table_truncate($tb) + { global $wpdb; - $q = 'TRUNCATE TABLE ' . $this->tb( $tb ); - $wpdb->query( $q ); + $q = 'TRUNCATE TABLE ' . $this->tb($tb); + $wpdb->query($q); } /** @@ -444,88 +451,89 @@ public function table_truncate( $tb ) { * * @since 4.0 */ - public function url_file_clean( $file_type ) { + public function url_file_clean($file_type) + { global $wpdb; - $type = $this->_url_file_types[ $file_type ]; - $q = 'DELETE FROM ' . $this->tb( 'url_file' ) . ' WHERE `type` = %d'; - $wpdb->query( $wpdb->prepare( $q, $type ) ); + $type = $this->_url_file_types[$file_type]; + $q = 'DELETE FROM ' . $this->tb('url_file') . ' WHERE `type` = %d'; + $wpdb->query($wpdb->prepare($q, $type)); } /** * Generate filename based on URL, if content md5 existed, reuse existing file. * @since 4.0 */ - public function save_url( $request_url, $vary, $file_type, $filecon_md5, $path, $mobile = false, $webp = false ) { + public function save_url($request_url, $vary, $file_type, $filecon_md5, $path, $mobile = false, $webp = false) + { global $wpdb; - if ( strlen( $vary ) > 32 ) { - $vary = md5( $vary ); + if (strlen($vary) > 32) { + $vary = md5($vary); } - $type = $this->_url_file_types[ $file_type ]; + $type = $this->_url_file_types[$file_type]; - $tb_url = $this->tb( 'url' ); - $tb_url_file = $this->tb( 'url_file' ); + $tb_url = $this->tb('url'); + $tb_url_file = $this->tb('url_file'); $q = "SELECT * FROM `$tb_url` WHERE url=%s"; - $url_row = $wpdb->get_row( $wpdb->prepare( $q, $request_url ), ARRAY_A ); - if ( ! $url_row ) { + $url_row = $wpdb->get_row($wpdb->prepare($q, $request_url), ARRAY_A); + if (!$url_row) { $q = "INSERT INTO `$tb_url` SET url=%s"; - $wpdb->query( $wpdb->prepare( $q, $request_url ) ); + $wpdb->query($wpdb->prepare($q, $request_url)); $url_id = $wpdb->insert_id; - } - else { - $url_id = $url_row[ 'id' ]; + } else { + $url_id = $url_row['id']; } $q = "SELECT * FROM `$tb_url_file` WHERE url_id=%d AND vary=%s AND type=%d AND expired=0"; - $file_row = $wpdb->get_row( $wpdb->prepare( $q, array( $url_id, $vary, $type ) ), ARRAY_A ); + $file_row = $wpdb->get_row($wpdb->prepare($q, array($url_id, $vary, $type)), ARRAY_A); // Check if has previous file or not - if ( $file_row && $file_row[ 'filename' ] == $filecon_md5 ) { + if ($file_row && $file_row['filename'] == $filecon_md5) { return; } // If the new $filecon_md5 is marked as expired by previous records, clear those records $q = "DELETE FROM `$tb_url_file` WHERE filename = %s AND expired > 0"; - $wpdb->query( $wpdb->prepare( $q, $filecon_md5 ) ); + $wpdb->query($wpdb->prepare($q, $filecon_md5)); // Check if there is any other record used the same filename or not $q = "SELECT id FROM `$tb_url_file` WHERE filename = %s AND expired = 0 AND id != %d LIMIT 1"; - if ( $file_row && $wpdb->get_var( $wpdb->prepare( $q, array( $file_row[ 'filename' ], $file_row[ 'id' ] ) ) ) ) { + if ($file_row && $wpdb->get_var($wpdb->prepare($q, array($file_row['filename'], $file_row['id'])))) { $q = "UPDATE `$tb_url_file` SET filename=%s WHERE id=%d"; - $wpdb->query( $wpdb->prepare( $q, array( $filecon_md5, $file_row[ 'id' ] ) ) ); + $wpdb->query($wpdb->prepare($q, array($filecon_md5, $file_row['id']))); return; } // New record needed $q = "INSERT INTO `$tb_url_file` SET url_id=%d, vary=%s, filename=%s, type=%d, mobile=%d, webp=%d, expired=0"; - $wpdb->query( $wpdb->prepare( $q, array( $url_id, $vary, $filecon_md5, $type, $mobile?1:0, $webp?1:0 ) ) ); + $wpdb->query($wpdb->prepare($q, array($url_id, $vary, $filecon_md5, $type, $mobile ? 1 : 0, $webp ? 1 : 0))); // Mark existing rows as expired - if ( $file_row ) { + if ($file_row) { $q = "UPDATE `$tb_url_file` SET expired=%d WHERE id=%d"; - $expired = time() + 86400 * apply_filters( 'litespeed_url_file_expired_days', 20 ); - $wpdb->query( $wpdb->prepare( $q, array( $expired, $file_row[ 'id' ] ) ) ); + $expired = time() + 86400 * apply_filters('litespeed_url_file_expired_days', 20); + $wpdb->query($wpdb->prepare($q, array($expired, $file_row['id']))); // Also check if has other files expired already to be deleted $q = "SELECT * FROM `$tb_url_file` WHERE url_id = %d AND expired BETWEEN 1 AND %d"; - $q = $wpdb->prepare( $q, array( $url_id, time() ) ); - $list = $wpdb->get_results( $q, ARRAY_A ); - if ( $list ) { - foreach ( $list as $v ) { - $file_to_del = $path . '/' . $v[ 'filename' ] . '.' . ( $file_type == 'js' ? 'js' : 'css' ); - if ( file_exists( $file_to_del ) ) { + $q = $wpdb->prepare($q, array($url_id, time())); + $list = $wpdb->get_results($q, ARRAY_A); + if ($list) { + foreach ($list as $v) { + $file_to_del = $path . '/' . $v['filename'] . '.' . ($file_type == 'js' ? 'js' : 'css'); + if (file_exists($file_to_del)) { // Safe to delete - Debug2::debug( '[Data] Delete expired unused file: ' . $file_to_del ); + Debug2::debug('[Data] Delete expired unused file: ' . $file_to_del); // Clear related lscache first to avoid cache copy of same URL w/ diff QS // Purge::add( Tag::TYPE_MIN . '.' . $file_row[ 'filename' ] . '.' . $file_type ); - unlink( $file_to_del ); + unlink($file_to_del); } } $q = "DELETE FROM `$tb_url_file` WHERE url_id = %d AND expired BETWEEN 1 AND %d"; - $wpdb->query( $wpdb->prepare( $q, array( $url_id, time() ) ) ); + $wpdb->query($wpdb->prepare($q, array($url_id, time()))); } } @@ -537,65 +545,67 @@ public function save_url( $request_url, $vary, $file_type, $filecon_md5, $path, * Load CCSS related file * @since 4.0 */ - public function load_url_file( $request_url, $vary, $file_type ) { + public function load_url_file($request_url, $vary, $file_type) + { global $wpdb; - if ( strlen( $vary ) > 32 ) { - $vary = md5( $vary ); + if (strlen($vary) > 32) { + $vary = md5($vary); } - $type = $this->_url_file_types[ $file_type ]; + $type = $this->_url_file_types[$file_type]; - self::debug2( 'load url file: ' . $request_url ); + self::debug2('load url file: ' . $request_url); - $tb_url = $this->tb( 'url' ); + $tb_url = $this->tb('url'); $q = "SELECT * FROM `$tb_url` WHERE url=%s"; - $url_row = $wpdb->get_row( $wpdb->prepare( $q, $request_url ), ARRAY_A ); - if ( ! $url_row ) { + $url_row = $wpdb->get_row($wpdb->prepare($q, $request_url), ARRAY_A); + if (!$url_row) { return false; } - $url_id = $url_row[ 'id' ]; + $url_id = $url_row['id']; - $tb_url_file = $this->tb( 'url_file' ); + $tb_url_file = $this->tb('url_file'); $q = "SELECT * FROM `$tb_url_file` WHERE url_id=%d AND vary=%s AND type=%d AND expired=0"; - $file_row = $wpdb->get_row( $wpdb->prepare( $q, array( $url_id, $vary, $type ) ), ARRAY_A ); - if ( ! $file_row ) { + $file_row = $wpdb->get_row($wpdb->prepare($q, array($url_id, $vary, $type)), ARRAY_A); + if (!$file_row) { return false; } - return $file_row[ 'filename' ]; + return $file_row['filename']; } /** * Mark all entries of one URL to expired * @since 4.5 */ - public function mark_as_expired( $request_url, $auto_q = false ) { + public function mark_as_expired($request_url, $auto_q = false) + { global $wpdb; - Debug2::debug( '[Data] Try to mark as expired: ' . $request_url ); - $tb_url = $this->tb( 'url' ); + Debug2::debug('[Data] Try to mark as expired: ' . $request_url); + $tb_url = $this->tb('url'); $q = "SELECT * FROM `$tb_url` WHERE url=%s"; - $url_row = $wpdb->get_row( $wpdb->prepare( $q, $request_url ), ARRAY_A ); - if ( ! $url_row ) { + $url_row = $wpdb->get_row($wpdb->prepare($q, $request_url), ARRAY_A); + if (!$url_row) { return; } - Debug2::debug( '[Data] Mark url_id=' . $url_row[ 'id' ] . ' as expired' ); + Debug2::debug('[Data] Mark url_id=' . $url_row['id'] . ' as expired'); - $tb_url = $this->tb( 'url' ); - $tb_url_file = $this->tb( 'url_file' ); + $tb_url = $this->tb('url'); + $tb_url_file = $this->tb('url_file'); $existing_url_files = array(); - if ( $auto_q ) { + if ($auto_q) { $q = "SELECT a.*, b.url FROM `$tb_url_file` a LEFT JOIN `$tb_url` b ON b.id=a.url_id WHERE a.url_id=%d AND a.type=4 AND a.expired=0"; - $q = $wpdb->prepare( $q, $url_row[ 'id' ] ); - $existing_url_files = $wpdb->get_results( $q, ARRAY_A ); + $q = $wpdb->prepare($q, $url_row['id']); + $existing_url_files = $wpdb->get_results($q, ARRAY_A); } $q = "UPDATE `$tb_url_file` SET expired=%d WHERE url_id=%d AND type=4 AND expired=0"; - $expired = time() + 86400 * apply_filters( 'litespeed_url_file_expired_days', 20 ); - $wpdb->query( $wpdb->prepare( $q, array( $expired, $url_row[ 'id' ] ) ) ); + $expired = time() + 86400 * apply_filters('litespeed_url_file_expired_days', 20); + $wpdb->query($wpdb->prepare($q, array($expired, $url_row['id']))); return $existing_url_files; } @@ -605,10 +615,11 @@ public function mark_as_expired( $request_url, $auto_q = false ) { * * @since 3.6 */ - public function load_css_exc( $list ) { - $data = $this->_load_per_line( 'css_excludes.txt' ); - if ( $data ) { - $list = array_unique( array_filter( array_merge( $list, $data ) ) ); + public function load_css_exc($list) + { + $data = $this->_load_per_line('css_excludes.txt'); + if ($data) { + $list = array_unique(array_filter(array_merge($list, $data))); } return $list; @@ -619,10 +630,11 @@ public function load_css_exc( $list ) { * * @since 4.0 */ - public function load_ucss_whitelist( $list ) { - $data = $this->_load_per_line( 'ucss_whitelist.txt' ); - if ( $data ) { - $list = array_unique( array_filter( array_merge( $list, $data ) ) ); + public function load_ucss_whitelist($list) + { + $data = $this->_load_per_line('ucss_whitelist.txt'); + if ($data) { + $list = array_unique(array_filter(array_merge($list, $data))); } return $list; @@ -633,10 +645,11 @@ public function load_ucss_whitelist( $list ) { * * @since 3.5 */ - public function load_js_exc( $list ) { - $data = $this->_load_per_line( 'js_excludes.txt' ); - if ( $data ) { - $list = array_unique( array_filter( array_merge( $list, $data ) ) ); + public function load_js_exc($list) + { + $data = $this->_load_per_line('js_excludes.txt'); + if ($data) { + $list = array_unique(array_filter(array_merge($list, $data))); } return $list; @@ -647,10 +660,11 @@ public function load_js_exc( $list ) { * * @since 3.6 */ - public function load_js_defer_exc( $list ) { - $data = $this->_load_per_line( 'js_defer_excludes.txt' ); - if ( $data ) { - $list = array_unique( array_filter( array_merge( $list, $data ) ) ); + public function load_js_defer_exc($list) + { + $data = $this->_load_per_line('js_defer_excludes.txt'); + if ($data) { + $list = array_unique(array_filter(array_merge($list, $data))); } return $list; @@ -661,10 +675,11 @@ public function load_js_defer_exc( $list ) { * * @since 5.4 */ - public function load_optm_uri_exc( $list ) { - $data = $this->_load_per_line( 'optm_uri_exc.txt' ); - if ( $data ) { - $list = array_unique( array_filter( array_merge( $list, $data ) ) ); + public function load_optm_uri_exc($list) + { + $data = $this->_load_per_line('optm_uri_exc.txt'); + if ($data) { + $list = array_unique(array_filter(array_merge($list, $data))); } return $list; @@ -675,10 +690,11 @@ public function load_optm_uri_exc( $list ) { * * @since 3.5 */ - public function load_esi_nonces( $list ) { - $data = $this->_load_per_line( 'esi.nonces.txt' ); - if ( $data ) { - $list = array_unique( array_filter( array_merge( $list, $data ) ) ); + public function load_esi_nonces($list) + { + $data = $this->_load_per_line('esi.nonces.txt'); + if ($data) { + $list = array_unique(array_filter(array_merge($list, $data))); } return $list; @@ -693,20 +709,21 @@ public function load_esi_nonces( $list ) { * * @since 3.5 */ - private function _load_per_line( $file ) { - $data = File::read( LSCWP_DIR . 'data/' . $file ); - $data = explode( PHP_EOL, $data ); + private function _load_per_line($file) + { + $data = File::read(LSCWP_DIR . 'data/' . $file); + $data = explode(PHP_EOL, $data); $list = array(); - foreach ( $data as $v ) { + foreach ($data as $v) { // Drop two kinds of comments - if ( strpos( $v, '##' ) !== false ) { - $v = trim( substr( $v, 0, strpos( $v, '##' ) ) ); + if (strpos($v, '##') !== false) { + $v = trim(substr($v, 0, strpos($v, '##'))); } - if ( strpos( $v, '# ' ) !== false ) { - $v = trim( substr( $v, 0, strpos( $v, '# ' ) ) ); + if (strpos($v, '# ') !== false) { + $v = trim(substr($v, 0, strpos($v, '# '))); } - if ( ! $v ) { + if (!$v) { continue; } @@ -715,5 +732,4 @@ private function _load_per_line( $file ) { return $list; } - -} \ No newline at end of file +} diff --git a/src/data.upgrade.func.php b/src/data.upgrade.func.php index 0d79ecde3..60cff570a 100644 --- a/src/data.upgrade.func.php +++ b/src/data.upgrade.func.php @@ -6,7 +6,7 @@ * * @since 3.0 */ -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); use LiteSpeed\Debug2; use LiteSpeed\Conf; @@ -17,16 +17,20 @@ * Append webp/mobile to url_file * @since 5.3 */ -function litespeed_update_5_3() { +function litespeed_update_5_3() +{ global $wpdb; - Debug2::debug( "[Data] Upgrade url_file table" ); - $tb_exists = $wpdb->get_var( 'SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_url_file"' ); - if ( $tb_exists ) { - $q = 'ALTER TABLE `' . $wpdb->prefix . 'litespeed_url_file` + Debug2::debug('[Data] Upgrade url_file table'); + $tb_exists = $wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_url_file"'); + if ($tb_exists) { + $q = + 'ALTER TABLE `' . + $wpdb->prefix . + 'litespeed_url_file` ADD COLUMN `mobile` tinyint(4) NOT NULL COMMENT "mobile=1", ADD COLUMN `webp` tinyint(4) NOT NULL COMMENT "webp=1" '; - $wpdb->query( $q ); + $wpdb->query($q); } } @@ -34,17 +38,21 @@ function litespeed_update_5_3() { * Add expired to url_file table * @since 4.4.4 */ -function litespeed_update_4_4_4() { +function litespeed_update_4_4_4() +{ global $wpdb; - Debug2::debug( "[Data] Upgrade url_file table" ); - $tb_exists = $wpdb->get_var( 'SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_url_file"' ); - if ( $tb_exists ) { - $q = 'ALTER TABLE `' . $wpdb->prefix . 'litespeed_url_file` + Debug2::debug('[Data] Upgrade url_file table'); + $tb_exists = $wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_url_file"'); + if ($tb_exists) { + $q = + 'ALTER TABLE `' . + $wpdb->prefix . + 'litespeed_url_file` ADD COLUMN `expired` int(11) NOT NULL DEFAULT 0, ADD KEY `filename_2` (`filename`,`expired`), ADD KEY `url_id` (`url_id`,`expired`) '; - $wpdb->query( $q ); + $wpdb->query($q); } } @@ -52,9 +60,10 @@ function litespeed_update_4_4_4() { * Drop cssjs table and rm cssjs folder * @since 4.3 */ -function litespeed_update_4_3() { - if ( file_exists( LITESPEED_STATIC_DIR . '/ccsjs' ) ) { - File::rrmdir( LITESPEED_STATIC_DIR . '/ccsjs' ); +function litespeed_update_4_3() +{ + if (file_exists(LITESPEED_STATIC_DIR . '/ccsjs')) { + File::rrmdir(LITESPEED_STATIC_DIR . '/ccsjs'); } } @@ -62,9 +71,10 @@ function litespeed_update_4_3() { * Drop object cache data file * @since 4.1 */ -function litespeed_update_4_1() { - if ( file_exists( WP_CONTENT_DIR . '/.object-cache.ini' ) ) { - unlink( WP_CONTENT_DIR . '/.object-cache.ini' ); +function litespeed_update_4_1() +{ + if (file_exists(WP_CONTENT_DIR . '/.object-cache.ini')) { + unlink(WP_CONTENT_DIR . '/.object-cache.ini'); } } @@ -72,19 +82,20 @@ function litespeed_update_4_1() { * Drop cssjs table and rm cssjs folder * @since 4.0 */ -function litespeed_update_4() { +function litespeed_update_4() +{ global $wpdb; $tb = $wpdb->prefix . 'litespeed_cssjs'; - $existed = $wpdb->get_var( "SHOW TABLES LIKE '$tb'" ); - if ( ! $existed ) { + $existed = $wpdb->get_var("SHOW TABLES LIKE '$tb'"); + if (!$existed) { return; } $q = 'DROP TABLE IF EXISTS ' . $tb; - $wpdb->query( $q ); + $wpdb->query($q); - if ( file_exists( LITESPEED_STATIC_DIR . '/ccsjs' ) ) { - File::rrmdir( LITESPEED_STATIC_DIR . '/ccsjs' ); + if (file_exists(LITESPEED_STATIC_DIR . '/ccsjs')) { + File::rrmdir(LITESPEED_STATIC_DIR . '/ccsjs'); } } @@ -94,30 +105,38 @@ function litespeed_update_4() { * * @since 3.5.1 */ -function litespeed_update_3_5() { +function litespeed_update_3_5() +{ $__conf = Conf::cls(); // Excludes jQuery - foreach ( array( 'optm-js_exc', 'optm-js_defer_exc' ) as $v ) { - $curr_setting = $__conf->conf( $v ); + foreach (array('optm-js_exc', 'optm-js_defer_exc') as $v) { + $curr_setting = $__conf->conf($v); $curr_setting[] = 'jquery.js'; $curr_setting[] = 'jquery.min.js'; - $__conf->update( $v, $curr_setting ); + $__conf->update($v, $curr_setting); } // Turn off JS Combine and defer $show_msg = false; - foreach ( array( 'optm-js_comb', 'optm-js_defer', 'optm-js_inline_defer' ) as $v ) { - $curr_setting = $__conf->conf( $v ); - if ( ! $curr_setting ) { + foreach (array('optm-js_comb', 'optm-js_defer', 'optm-js_inline_defer') as $v) { + $curr_setting = $__conf->conf($v); + if (!$curr_setting) { continue; } $show_msg = true; - $__conf->update( $v, false ); + $__conf->update($v, false); } - if ( $show_msg ) { - $msg = sprintf( __( 'LiteSpeed Cache upgraded successfully. NOTE: Due to changes in this version, the settings %1$s and %2$s have been turned OFF. Please turn them back on manually and verify that your site layout is correct, and you have no JS errors.', 'litespeed-cache' ), '' . __( 'JS Combine', 'litespeed-cache' ) . '', '' . __( 'JS Defer', 'litespeed-cache' ) . '' ); - $msg .= sprintf( ' %s.', __( 'Click here to settings', 'litespeed-cache' ) ); - Admin_Display::info( $msg, false, true ); + if ($show_msg) { + $msg = sprintf( + __( + 'LiteSpeed Cache upgraded successfully. NOTE: Due to changes in this version, the settings %1$s and %2$s have been turned OFF. Please turn them back on manually and verify that your site layout is correct, and you have no JS errors.', + 'litespeed-cache' + ), + '' . __('JS Combine', 'litespeed-cache') . '', + '' . __('JS Defer', 'litespeed-cache') . '' + ); + $msg .= sprintf(' %s.', __('Click here to settings', 'litespeed-cache')); + Admin_Display::info($msg, false, true); } } @@ -126,327 +145,318 @@ function litespeed_update_3_5() { * * @since 3.0 */ -function litespeed_update_2_0( $ver ) { - global $wpdb ; +function litespeed_update_2_0($ver) +{ + global $wpdb; // Table version only exists after all old data migrated // Last modified is v2.4.2 - if ( version_compare( $ver, '2.4.2', '<' ) ) { + if (version_compare($ver, '2.4.2', '<')) { /** * Convert old data from postmeta to img_optm table * @since 2.0 */ // Migrate data from `wp_postmeta` to `wp_litespeed_img_optm` - $mids_to_del = array() ; - $q = "SELECT * FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_id" ; - $meta_value_list = $wpdb->get_results( $wpdb->prepare( $q, 'litespeed-optimize-data' ) ) ; - if ( $meta_value_list ) { - $max_k = count( $meta_value_list ) - 1 ; - foreach ( $meta_value_list as $k => $v ) { - $md52src_list = maybe_unserialize( $v->meta_value ) ; - foreach ( $md52src_list as $md5 => $v2 ) { + $mids_to_del = array(); + $q = "SELECT * FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_id"; + $meta_value_list = $wpdb->get_results($wpdb->prepare($q, 'litespeed-optimize-data')); + if ($meta_value_list) { + $max_k = count($meta_value_list) - 1; + foreach ($meta_value_list as $k => $v) { + $md52src_list = maybe_unserialize($v->meta_value); + foreach ($md52src_list as $md5 => $v2) { $f = array( - 'post_id' => $v->post_id, - 'optm_status' => $v2[ 1 ], - 'src' => $v2[ 0 ], - 'srcpath_md5' => md5( $v2[ 0 ] ), - 'src_md5' => $md5, - 'server' => $v2[ 2 ], - ) ; - $wpdb->replace( $wpdb->prefix . 'litespeed_img_optm', $f ) ; + 'post_id' => $v->post_id, + 'optm_status' => $v2[1], + 'src' => $v2[0], + 'srcpath_md5' => md5($v2[0]), + 'src_md5' => $md5, + 'server' => $v2[2], + ); + $wpdb->replace($wpdb->prefix . 'litespeed_img_optm', $f); } - $mids_to_del[] = $v->meta_id ; + $mids_to_del[] = $v->meta_id; // Delete from postmeta - if ( count( $mids_to_del ) > 100 || $k == $max_k ) { - $q = "DELETE FROM $wpdb->postmeta WHERE meta_id IN ( " . implode( ',', array_fill( 0, count( $mids_to_del ), '%s' ) ) . " ) " ; - $wpdb->query( $wpdb->prepare( $q, $mids_to_del ) ) ; + if (count($mids_to_del) > 100 || $k == $max_k) { + $q = "DELETE FROM $wpdb->postmeta WHERE meta_id IN ( " . implode(',', array_fill(0, count($mids_to_del), '%s')) . ' ) '; + $wpdb->query($wpdb->prepare($q, $mids_to_del)); - $mids_to_del = array() ; + $mids_to_del = array(); } } - Debug2::debug( '[Data] img_optm inserted records: ' . $k ) ; + Debug2::debug('[Data] img_optm inserted records: ' . $k); } - $q = "DELETE FROM $wpdb->postmeta WHERE meta_key = %s" ; - $rows = $wpdb->query( $wpdb->prepare( $q, 'litespeed-optimize-status' ) ) ; - Debug2::debug( '[Data] img_optm delete optm_status records: ' . $rows ) ; - + $q = "DELETE FROM $wpdb->postmeta WHERE meta_key = %s"; + $rows = $wpdb->query($wpdb->prepare($q, 'litespeed-optimize-status')); + Debug2::debug('[Data] img_optm delete optm_status records: ' . $rows); } /** * Add target_md5 field to table * @since 2.4.2 */ - if ( version_compare( $ver, '2.4.2', '<' ) && version_compare( $ver, '2.0', '>=' ) ) {// NOTE: For new users, need to bypass this section - $sql = sprintf( - 'ALTER TABLE `%1$s` ADD `server_info` text NOT NULL, DROP COLUMN `server`', - $wpdb->prefix . 'litespeed_img_optm' - ) ; - - $res = $wpdb->query( $sql ) ; - if ( $res !== true ) { - Debug2::debug( '[Data] Warning: Alter table img_optm failed!', $sql ) ; + if (version_compare($ver, '2.4.2', '<') && version_compare($ver, '2.0', '>=')) { + // NOTE: For new users, need to bypass this section + $sql = sprintf('ALTER TABLE `%1$s` ADD `server_info` text NOT NULL, DROP COLUMN `server`', $wpdb->prefix . 'litespeed_img_optm'); + + $res = $wpdb->query($sql); + if ($res !== true) { + Debug2::debug('[Data] Warning: Alter table img_optm failed!', $sql); + } else { + Debug2::debug('[Data] Successfully upgraded table img_optm.'); } - else { - Debug2::debug( '[Data] Successfully upgraded table img_optm.' ) ; - } - } // Delete img optm tb version - delete_option( $wpdb->prefix . 'litespeed_img_optm' ) ; - + delete_option($wpdb->prefix . 'litespeed_img_optm'); // Delete possible HTML optm data from wp_options - delete_option( 'litespeed-cache-optimized' ) ; + delete_option('litespeed-cache-optimized'); // Delete HTML optm tb version - delete_option( $wpdb->prefix . 'litespeed_optimizer' ) ; - + delete_option($wpdb->prefix . 'litespeed_optimizer'); } - - /** * Move all options in litespeed-cache-conf from v3.0- to separate records * * @since 3.0 */ -function litespeed_update_3_0( $ver ) { +function litespeed_update_3_0($ver) +{ global $wpdb; // Upgrade v2.0- to v2.0 first - if ( version_compare( $ver, '2.0', '<' ) ) { - litespeed_update_2_0( $ver ) ; + if (version_compare($ver, '2.0', '<')) { + litespeed_update_2_0($ver); } - set_time_limit( 86400 ); + set_time_limit(86400); // conv items to litespeed.conf.* - Debug2::debug( "[Data] Conv items to litespeed.conf.*" ); + Debug2::debug('[Data] Conv items to litespeed.conf.*'); $data = array( - 'litespeed-cache-exclude-cache-roles' => 'cache-exc_roles', - 'litespeed-cache-drop_qs' => 'cache-drop_qs', - 'litespeed-forced_cache_uri' => 'cache-force_uri', - 'litespeed-cache_uri_priv' => 'cache-priv_uri', - 'litespeed-excludes_uri' => 'cache-exc', - 'litespeed-cache-vary-group' => 'cache-vary_group', - 'litespeed-adv-purge_all_hooks' => 'purge-hook_all', - 'litespeed-object_global_groups' => 'object-global_groups', - 'litespeed-object_non_persistent_groups' => 'object-non_persistent_groups', - 'litespeed-media-lazy-img-excludes' => 'media-lazy_exc', - 'litespeed-media-lazy-img-cls-excludes' => 'media-lazy_cls_exc', - 'litespeed-media-webp_attribute' => 'img_optm-webp_attr', - 'litespeed-optm-css' => 'optm-ccss_con', - 'litespeed-optm_excludes' => 'optm-exc', - 'litespeed-optm-ccss-separate_posttype' => 'optm-ccss_sep_posttype', - 'litespeed-optm-css-separate_uri' => 'optm-ccss_sep_uri', - 'litespeed-optm-js-defer-excludes' => 'optm-js_defer_exc', - 'litespeed-cache-dns_prefetch' => 'optm-dns_prefetch', + 'litespeed-cache-exclude-cache-roles' => 'cache-exc_roles', + 'litespeed-cache-drop_qs' => 'cache-drop_qs', + 'litespeed-forced_cache_uri' => 'cache-force_uri', + 'litespeed-cache_uri_priv' => 'cache-priv_uri', + 'litespeed-excludes_uri' => 'cache-exc', + 'litespeed-cache-vary-group' => 'cache-vary_group', + 'litespeed-adv-purge_all_hooks' => 'purge-hook_all', + 'litespeed-object_global_groups' => 'object-global_groups', + 'litespeed-object_non_persistent_groups' => 'object-non_persistent_groups', + 'litespeed-media-lazy-img-excludes' => 'media-lazy_exc', + 'litespeed-media-lazy-img-cls-excludes' => 'media-lazy_cls_exc', + 'litespeed-media-webp_attribute' => 'img_optm-webp_attr', + 'litespeed-optm-css' => 'optm-ccss_con', + 'litespeed-optm_excludes' => 'optm-exc', + 'litespeed-optm-ccss-separate_posttype' => 'optm-ccss_sep_posttype', + 'litespeed-optm-css-separate_uri' => 'optm-ccss_sep_uri', + 'litespeed-optm-js-defer-excludes' => 'optm-js_defer_exc', + 'litespeed-cache-dns_prefetch' => 'optm-dns_prefetch', 'litespeed-cache-exclude-optimization-roles' => 'optm-exc_roles', - 'litespeed-log_ignore_filters' => 'debug-log_no_filters', // depreciated - 'litespeed-log_ignore_part_filters' => 'debug-log_no_part_filters', // depreciated - 'litespeed-cdn-ori_dir' => 'cdn-ori_dir', - 'litespeed-cache-cdn_mapping' => 'cdn-mapping', - 'litespeed-crawler-as-uids' => 'crawler-roles', - 'litespeed-crawler-cookies' => 'crawler-cookies', - ) ; - foreach ( $data as $k => $v ) { - $old_data = get_option( $k ) ; - if ( $old_data ) { - Debug2::debug( "[Data] Convert $k" ); + 'litespeed-log_ignore_filters' => 'debug-log_no_filters', // depreciated + 'litespeed-log_ignore_part_filters' => 'debug-log_no_part_filters', // depreciated + 'litespeed-cdn-ori_dir' => 'cdn-ori_dir', + 'litespeed-cache-cdn_mapping' => 'cdn-mapping', + 'litespeed-crawler-as-uids' => 'crawler-roles', + 'litespeed-crawler-cookies' => 'crawler-cookies', + ); + foreach ($data as $k => $v) { + $old_data = get_option($k); + if ($old_data) { + Debug2::debug("[Data] Convert $k"); // They must be an array - if ( ! is_array( $old_data ) && $v != 'optm-ccss_con' ) { - $old_data = explode( "\n", $old_data ) ; + if (!is_array($old_data) && $v != 'optm-ccss_con') { + $old_data = explode("\n", $old_data); } - if ( $v == 'crawler-cookies' ) { - $tmp = array() ; - $i = 0 ; - foreach ( $old_data as $k2 => $v2 ) { - $tmp[ $i ][ 'name' ] = $k2 ; - $tmp[ $i ][ 'vals' ] = explode( "\n", $v2 ) ; - $i ++ ; + if ($v == 'crawler-cookies') { + $tmp = array(); + $i = 0; + foreach ($old_data as $k2 => $v2) { + $tmp[$i]['name'] = $k2; + $tmp[$i]['vals'] = explode("\n", $v2); + $i++; } - $old_data = $tmp ; + $old_data = $tmp; } - add_option( 'litespeed.conf.' . $v, $old_data ) ; + add_option('litespeed.conf.' . $v, $old_data); } - Debug2::debug( "[Data] Delete $k" ); - delete_option( $k ) ; + Debug2::debug("[Data] Delete $k"); + delete_option($k); } // conv other items $data = array( - 'litespeed-setting-mode' => 'litespeed.setting.mode', - 'litespeed-media-need-pull' => 'litespeed.img_optm.need_pull', - 'litespeed-env-ref' => 'litespeed.env.ref', + 'litespeed-setting-mode' => 'litespeed.setting.mode', + 'litespeed-media-need-pull' => 'litespeed.img_optm.need_pull', + 'litespeed-env-ref' => 'litespeed.env.ref', 'litespeed-cache-cloudflare_status' => 'litespeed.cdn.cloudflare.status', - - ) ; - foreach ( $data as $k => $v ) { - $old_data = get_option( $k ) ; - if ( $old_data ) { - add_option( $v, $old_data ) ; + ); + foreach ($data as $k => $v) { + $old_data = get_option($k); + if ($old_data) { + add_option($v, $old_data); } - delete_option( $k ) ; + delete_option($k); } // Conv conf from litespeed-cache-conf child to litespeed.conf.* - Debug2::debug( "[Data] Conv conf from litespeed-cache-conf child to litespeed.conf.*" ); - $previous_options = get_option( 'litespeed-cache-conf' ) ; + Debug2::debug('[Data] Conv conf from litespeed-cache-conf child to litespeed.conf.*'); + $previous_options = get_option('litespeed-cache-conf'); $data = array( - 'radio_select' => 'cache', - 'hash' => 'hash', - 'auto_upgrade' => 'auto_upgrade', - 'news' => 'news', - 'crawler_domain_ip' => 'server_ip', - - 'esi_enabled' => 'esi', - 'esi_cached_admbar' => 'esi-cache_admbar', - 'esi_cached_commform' => 'esi-cache_commform', - - 'heartbeat' => 'misc-heartbeat_front', - - 'cache_browser' => 'cache-browser', - 'cache_browser_ttl' => 'cache-ttl_browser', - 'instant_click' => 'util-instant_click', - 'use_http_for_https_vary' => 'util-no_https_vary', - - 'purge_upgrade' => 'purge-upgrade', - 'timed_urls' => 'purge-timed_urls', - 'timed_urls_time' => 'purge-timed_urls_time', - - 'cache_priv' => 'cache-priv', - 'cache_commenter' => 'cache-commenter', - 'cache_rest' => 'cache-rest', - 'cache_page_login' => 'cache-page_login', - 'cache_favicon' => 'cache-favicon', - 'cache_resources' => 'cache-resources', - 'mobileview_enabled' => 'cache-mobile', - 'mobileview_rules' => 'cache-mobile_rules', - 'nocache_useragents' => 'cache-exc_useragents', - 'nocache_cookies' => 'cache-exc_cookies', - 'excludes_qs' => 'cache-exc_qs', - 'excludes_cat' => 'cache-exc_cat', - 'excludes_tag' => 'cache-exc_tag', - 'public_ttl' => 'cache-ttl_pub', - 'private_ttl' => 'cache-ttl_priv', - 'front_page_ttl' => 'cache-ttl_frontpage', - 'feed_ttl' => 'cache-ttl_feed', - 'login_cookie' => 'cache-login_cookie', - - 'debug_disable_all' => 'debug-disable_all', - 'debug' => 'debug', - 'admin_ips' => 'debug-ips', - 'debug_level' => 'debug-level', - 'log_file_size' => 'debug-filesize', - 'debug_cookie' => 'debug-cookie', - 'collaps_qs' => 'debug-collaps_qs', + 'radio_select' => 'cache', + 'hash' => 'hash', + 'auto_upgrade' => 'auto_upgrade', + 'news' => 'news', + 'crawler_domain_ip' => 'server_ip', + + 'esi_enabled' => 'esi', + 'esi_cached_admbar' => 'esi-cache_admbar', + 'esi_cached_commform' => 'esi-cache_commform', + + 'heartbeat' => 'misc-heartbeat_front', + + 'cache_browser' => 'cache-browser', + 'cache_browser_ttl' => 'cache-ttl_browser', + 'instant_click' => 'util-instant_click', + 'use_http_for_https_vary' => 'util-no_https_vary', + + 'purge_upgrade' => 'purge-upgrade', + 'timed_urls' => 'purge-timed_urls', + 'timed_urls_time' => 'purge-timed_urls_time', + + 'cache_priv' => 'cache-priv', + 'cache_commenter' => 'cache-commenter', + 'cache_rest' => 'cache-rest', + 'cache_page_login' => 'cache-page_login', + 'cache_favicon' => 'cache-favicon', + 'cache_resources' => 'cache-resources', + 'mobileview_enabled' => 'cache-mobile', + 'mobileview_rules' => 'cache-mobile_rules', + 'nocache_useragents' => 'cache-exc_useragents', + 'nocache_cookies' => 'cache-exc_cookies', + 'excludes_qs' => 'cache-exc_qs', + 'excludes_cat' => 'cache-exc_cat', + 'excludes_tag' => 'cache-exc_tag', + 'public_ttl' => 'cache-ttl_pub', + 'private_ttl' => 'cache-ttl_priv', + 'front_page_ttl' => 'cache-ttl_frontpage', + 'feed_ttl' => 'cache-ttl_feed', + 'login_cookie' => 'cache-login_cookie', + + 'debug_disable_all' => 'debug-disable_all', + 'debug' => 'debug', + 'admin_ips' => 'debug-ips', + 'debug_level' => 'debug-level', + 'log_file_size' => 'debug-filesize', + 'debug_cookie' => 'debug-cookie', + 'collaps_qs' => 'debug-collaps_qs', // 'log_filters' => 'debug-log_filters', - 'crawler_cron_active' => 'crawler', + 'crawler_cron_active' => 'crawler', // 'crawler_include_posts' => 'crawler-inc_posts', // 'crawler_include_pages' => 'crawler-inc_pages', // 'crawler_include_cats' => 'crawler-inc_cats', // 'crawler_include_tags' => 'crawler-inc_tags', // 'crawler_excludes_cpt' => 'crawler-exc_cpt', // 'crawler_order_links' => 'crawler-order_links', - 'crawler_usleep' => 'crawler-usleep', - 'crawler_run_duration' => 'crawler-run_duration', - 'crawler_run_interval' => 'crawler-run_interval', - 'crawler_crawl_interval' => 'crawler-crawl_interval', - 'crawler_threads' => 'crawler-threads', - 'crawler_load_limit' => 'crawler-load_limit', - 'crawler_custom_sitemap' => 'crawler-sitemap', - - 'cache_object' => 'object', - 'cache_object_kind' => 'object-kind', - 'cache_object_host' => 'object-host', - 'cache_object_port' => 'object-port', - 'cache_object_life' => 'object-life', - 'cache_object_persistent' => 'object-persistent', - 'cache_object_admin' => 'object-admin', - 'cache_object_transients' => 'object-transients', - 'cache_object_db_id' => 'object-db_id', - 'cache_object_user' => 'object-user', - 'cache_object_pswd' => 'object-psw', - - 'cdn' => 'cdn', - 'cdn_ori' => 'cdn-ori', - 'cdn_exclude' => 'cdn-exc', + 'crawler_usleep' => 'crawler-usleep', + 'crawler_run_duration' => 'crawler-run_duration', + 'crawler_run_interval' => 'crawler-run_interval', + 'crawler_crawl_interval' => 'crawler-crawl_interval', + 'crawler_threads' => 'crawler-threads', + 'crawler_load_limit' => 'crawler-load_limit', + 'crawler_custom_sitemap' => 'crawler-sitemap', + + 'cache_object' => 'object', + 'cache_object_kind' => 'object-kind', + 'cache_object_host' => 'object-host', + 'cache_object_port' => 'object-port', + 'cache_object_life' => 'object-life', + 'cache_object_persistent' => 'object-persistent', + 'cache_object_admin' => 'object-admin', + 'cache_object_transients' => 'object-transients', + 'cache_object_db_id' => 'object-db_id', + 'cache_object_user' => 'object-user', + 'cache_object_pswd' => 'object-psw', + + 'cdn' => 'cdn', + 'cdn_ori' => 'cdn-ori', + 'cdn_exclude' => 'cdn-exc', // 'cdn_remote_jquery' => 'cdn-remote_jq', - 'cdn_quic' => 'cdn-quic', - 'cdn_cloudflare' => 'cdn-cloudflare', - 'cdn_cloudflare_email' => 'cdn-cloudflare_email', - 'cdn_cloudflare_key' => 'cdn-cloudflare_key', - 'cdn_cloudflare_name' => 'cdn-cloudflare_name', - 'cdn_cloudflare_zone' => 'cdn-cloudflare_zone', - - 'media_img_lazy' => 'media-lazy', - 'media_img_lazy_placeholder' => 'media-lazy_placeholder', - 'media_placeholder_resp' => 'media-placeholder_resp', - 'media_placeholder_resp_color' => 'media-placeholder_resp_color', - 'media_placeholder_resp_async' => 'media-placeholder_resp_async', - 'media_iframe_lazy' => 'media-iframe_lazy', + 'cdn_quic' => 'cdn-quic', + 'cdn_cloudflare' => 'cdn-cloudflare', + 'cdn_cloudflare_email' => 'cdn-cloudflare_email', + 'cdn_cloudflare_key' => 'cdn-cloudflare_key', + 'cdn_cloudflare_name' => 'cdn-cloudflare_name', + 'cdn_cloudflare_zone' => 'cdn-cloudflare_zone', + + 'media_img_lazy' => 'media-lazy', + 'media_img_lazy_placeholder' => 'media-lazy_placeholder', + 'media_placeholder_resp' => 'media-placeholder_resp', + 'media_placeholder_resp_color' => 'media-placeholder_resp_color', + 'media_placeholder_resp_async' => 'media-placeholder_resp_async', + 'media_iframe_lazy' => 'media-iframe_lazy', // 'media_img_lazyjs_inline' => 'media-lazyjs_inline', - 'media_optm_auto' => 'img_optm-auto', - 'media_optm_cron' => 'img_optm-cron', - 'media_optm_ori' => 'img_optm-ori', - 'media_rm_ori_bkup' => 'img_optm-rm_bkup', + 'media_optm_auto' => 'img_optm-auto', + 'media_optm_cron' => 'img_optm-cron', + 'media_optm_ori' => 'img_optm-ori', + 'media_rm_ori_bkup' => 'img_optm-rm_bkup', // 'media_optm_webp' => 'img_optm-webp', - 'media_webp_replace' => 'img_optm-webp', - 'media_optm_lossless' => 'img_optm-lossless', - 'media_optm_exif' => 'img_optm-exif', - 'media_webp_replace_srcset' => 'img_optm-webp_replace_srcset', + 'media_webp_replace' => 'img_optm-webp', + 'media_optm_lossless' => 'img_optm-lossless', + 'media_optm_exif' => 'img_optm-exif', + 'media_webp_replace_srcset' => 'img_optm-webp_replace_srcset', - 'css_minify' => 'optm-css_min', + 'css_minify' => 'optm-css_min', // 'css_inline_minify' => 'optm-css_inline_min', - 'css_combine' => 'optm-css_comb', + 'css_combine' => 'optm-css_comb', // 'css_combined_priority' => 'optm-css_comb_priority', // 'css_http2' => 'optm-css_http2', - 'css_exclude' => 'optm-css_exc', - 'js_minify' => 'optm-js_min', + 'css_exclude' => 'optm-css_exc', + 'js_minify' => 'optm-js_min', // 'js_inline_minify' => 'optm-js_inline_min', - 'js_combine' => 'optm-js_comb', + 'js_combine' => 'optm-js_comb', // 'js_combined_priority' => 'optm-js_comb_priority', // 'js_http2' => 'optm-js_http2', - 'js_exclude' => 'optm-js_exc', + 'js_exclude' => 'optm-js_exc', // 'optimize_ttl' => 'optm-ttl', - 'html_minify' => 'optm-html_min', - 'optm_qs_rm' => 'optm-qs_rm', - 'optm_ggfonts_rm' => 'optm-ggfonts_rm', - 'optm_css_async' => 'optm-css_async', + 'html_minify' => 'optm-html_min', + 'optm_qs_rm' => 'optm-qs_rm', + 'optm_ggfonts_rm' => 'optm-ggfonts_rm', + 'optm_css_async' => 'optm-css_async', // 'optm_ccss_gen' => 'optm-ccss_gen', // 'optm_ccss_async' => 'optm-ccss_async', - 'optm_css_async_inline' => 'optm-css_async_inline', - 'optm_js_defer' => 'optm-js_defer', - 'optm_emoji_rm' => 'optm-emoji_rm', + 'optm_css_async_inline' => 'optm-css_async_inline', + 'optm_js_defer' => 'optm-js_defer', + 'optm_emoji_rm' => 'optm-emoji_rm', // 'optm_exclude_jquery' => 'optm-exc_jq', - 'optm_ggfonts_async' => 'optm-ggfonts_async', + 'optm_ggfonts_async' => 'optm-ggfonts_async', // 'optm_max_size' => 'optm-max_size', // 'optm_rm_comment' => 'optm-rm_comment', - ) ; - foreach ( $data as $k => $v ) { - if ( ! isset( $previous_options[ $k ] ) ) { - continue ; + ); + foreach ($data as $k => $v) { + if (!isset($previous_options[$k])) { + continue; } // The folllowing values must be array - if ( ! is_array( $previous_options[ $k ] ) ) { - if ( in_array( $v, array( 'cdn-ori', 'cache-exc_cat', 'cache-exc_tag' ) ) ) { - $previous_options[ $k ] = explode( ',', $previous_options[ $k ] ) ; - $previous_options[ $k ] = array_filter( $previous_options[ $k ] ) ; - } - elseif ( in_array( $v, array( 'cache-mobile_rules', 'cache-exc_useragents', 'cache-exc_cookies' ) ) ) { - $previous_options[ $k ] = explode( '|', str_replace( '\\ ', ' ', $previous_options[ $k ] ) ) ; - $previous_options[ $k ] = array_filter( $previous_options[ $k ] ) ; - } - elseif ( in_array( $v, array( + if (!is_array($previous_options[$k])) { + if (in_array($v, array('cdn-ori', 'cache-exc_cat', 'cache-exc_tag'))) { + $previous_options[$k] = explode(',', $previous_options[$k]); + $previous_options[$k] = array_filter($previous_options[$k]); + } elseif (in_array($v, array('cache-mobile_rules', 'cache-exc_useragents', 'cache-exc_cookies'))) { + $previous_options[$k] = explode('|', str_replace('\\ ', ' ', $previous_options[$k])); + $previous_options[$k] = array_filter($previous_options[$k]); + } elseif ( + in_array($v, array( 'purge-timed_urls', 'cache-exc_qs', 'debug-ips', @@ -454,59 +464,60 @@ function litespeed_update_3_0( $ver ) { 'cdn-exc', 'optm-css_exc', 'optm-js_exc', - ) ) ) { - $previous_options[ $k ] = explode( "\n", $previous_options[ $k ] ) ; - $previous_options[ $k ] = array_filter( $previous_options[ $k ] ) ; + )) + ) { + $previous_options[$k] = explode("\n", $previous_options[$k]); + $previous_options[$k] = array_filter($previous_options[$k]); } } // Special handler for heartbeat - if ( $v == 'misc-heartbeat_front' ) { - if ( ! $previous_options[ $k ] ) { - add_option( 'litespeed.conf.misc-heartbeat_front', true ) ; - add_option( 'litespeed.conf.misc-heartbeat_back', true ) ; - add_option( 'litespeed.conf.misc-heartbeat_editor', true ) ; - add_option( 'litespeed.conf.misc-heartbeat_front_ttl', 0 ) ; - add_option( 'litespeed.conf.misc-heartbeat_back_ttl', 0 ) ; - add_option( 'litespeed.conf.misc-heartbeat_editor_ttl', 0 ) ; + if ($v == 'misc-heartbeat_front') { + if (!$previous_options[$k]) { + add_option('litespeed.conf.misc-heartbeat_front', true); + add_option('litespeed.conf.misc-heartbeat_back', true); + add_option('litespeed.conf.misc-heartbeat_editor', true); + add_option('litespeed.conf.misc-heartbeat_front_ttl', 0); + add_option('litespeed.conf.misc-heartbeat_back_ttl', 0); + add_option('litespeed.conf.misc-heartbeat_editor_ttl', 0); } - continue ; + continue; } - add_option( 'litespeed.conf.' . $v, $previous_options[ $k ] ) ; + add_option('litespeed.conf.' . $v, $previous_options[$k]); } // Conv purge_by_post $data = array( - '-' => 'purge-post_all', - 'F' => 'purge-post_f', - 'H' => 'purge-post_h', - 'PGS' => 'purge-post_p', - 'PGSRP' => 'purge-post_pwrp', - 'A' => 'purge-post_a', - 'Y' => 'purge-post_y', - 'M' => 'purge-post_m', - 'D' => 'purge-post_d', - 'T' => 'purge-post_t', - 'PT' => 'purge-post_pt', - ) ; - if ( isset( $previous_options[ 'purge_by_post' ] ) ) { - $purge_by_post = explode( '.', $previous_options[ 'purge_by_post' ] ) ; - foreach ( $data as $k => $v ) { - add_option( 'litespeed.conf.' . $v, in_array( $k, $purge_by_post ) ) ; + '-' => 'purge-post_all', + 'F' => 'purge-post_f', + 'H' => 'purge-post_h', + 'PGS' => 'purge-post_p', + 'PGSRP' => 'purge-post_pwrp', + 'A' => 'purge-post_a', + 'Y' => 'purge-post_y', + 'M' => 'purge-post_m', + 'D' => 'purge-post_d', + 'T' => 'purge-post_t', + 'PT' => 'purge-post_pt', + ); + if (isset($previous_options['purge_by_post'])) { + $purge_by_post = explode('.', $previous_options['purge_by_post']); + foreach ($data as $k => $v) { + add_option('litespeed.conf.' . $v, in_array($k, $purge_by_post)); } } // Conv 404/403/500 TTL - $ttl_status = array() ; - if ( isset( $previous_options[ '403_ttl' ] ) ) { - $ttl_status[] = '403 ' . $previous_options[ '403_ttl' ] ; + $ttl_status = array(); + if (isset($previous_options['403_ttl'])) { + $ttl_status[] = '403 ' . $previous_options['403_ttl']; } - if ( isset( $previous_options[ '404_ttl' ] ) ) { - $ttl_status[] = '404 ' . $previous_options[ '404_ttl' ] ; + if (isset($previous_options['404_ttl'])) { + $ttl_status[] = '404 ' . $previous_options['404_ttl']; } - if ( isset( $previous_options[ '500_ttl' ] ) ) { - $ttl_status[] = '500 ' . $previous_options[ '500_ttl' ] ; + if (isset($previous_options['500_ttl'])) { + $ttl_status[] = '500 ' . $previous_options['500_ttl']; } - add_option( 'litespeed.conf.cache-ttl_status', $ttl_status ) ; + add_option('litespeed.conf.cache-ttl_status', $ttl_status); /** * Resave cdn cfg from lscfg to separate cfg when upgrade to v1.7 @@ -515,16 +526,16 @@ function litespeed_update_3_0( $ver ) { * * @since 1.7 */ - if ( isset( $previous_options[ 'cdn_url' ] ) ) { + if (isset($previous_options['cdn_url'])) { $cdn_mapping = array( - 'url' => $previous_options[ 'cdn_url' ], - 'inc_img' => $previous_options[ 'cdn_inc_img' ], - 'inc_css' => $previous_options[ 'cdn_inc_css' ], - 'inc_js' => $previous_options[ 'cdn_inc_js' ], - 'filetype' => $previous_options[ 'cdn_filetype' ], - ) ; - add_option( 'litespeed.conf.cdn-mapping', array( $cdn_mapping ) ) ; - Debug2::debug( "[Data] plugin_upgrade option adding CDN map" ) ; + 'url' => $previous_options['cdn_url'], + 'inc_img' => $previous_options['cdn_inc_img'], + 'inc_css' => $previous_options['cdn_inc_css'], + 'inc_js' => $previous_options['cdn_inc_js'], + 'filetype' => $previous_options['cdn_filetype'], + ); + add_option('litespeed.conf.cdn-mapping', array($cdn_mapping)); + Debug2::debug('[Data] plugin_upgrade option adding CDN map'); } /** @@ -534,122 +545,121 @@ function litespeed_update_3_0( $ver ) { * * @since 2.3 */ - if ( isset( $previous_options[ 'forced_cache_uri' ] ) ) { - add_option( 'litespeed.conf.cache-force_uri', $previous_options[ 'forced_cache_uri' ] ) ; + if (isset($previous_options['forced_cache_uri'])) { + add_option('litespeed.conf.cache-force_uri', $previous_options['forced_cache_uri']); } - if ( isset( $previous_options[ 'cache_uri_priv' ] ) ) { - add_option( 'litespeed.conf.cache-priv_uri', $previous_options[ 'cache_uri_priv' ] ) ; + if (isset($previous_options['cache_uri_priv'])) { + add_option('litespeed.conf.cache-priv_uri', $previous_options['cache_uri_priv']); } - if ( isset( $previous_options[ 'optm_excludes' ] ) ) { - add_option( 'litespeed.conf.optm-exc', $previous_options[ 'optm_excludes' ] ) ; + if (isset($previous_options['optm_excludes'])) { + add_option('litespeed.conf.optm-exc', $previous_options['optm_excludes']); } - if ( isset( $previous_options[ 'excludes_uri' ] ) ) { - add_option( 'litespeed.conf.cache-exc', $previous_options[ 'excludes_uri' ] ) ; + if (isset($previous_options['excludes_uri'])) { + add_option('litespeed.conf.cache-exc', $previous_options['excludes_uri']); } // Backup stale conf - Debug2::debug( "[Data] Backup stale conf" ); - delete_option( 'litespeed-cache-conf' ); - add_option( 'litespeed-cache-conf.bk', $previous_options ); + Debug2::debug('[Data] Backup stale conf'); + delete_option('litespeed-cache-conf'); + add_option('litespeed-cache-conf.bk', $previous_options); // Upgrade site_options if is network - if ( is_multisite() ) { - $ver = get_site_option( 'litespeed.conf._version' ) ; - if ( ! $ver ) { - Debug2::debug( "[Data] Conv multisite" ); - $previous_site_options = get_site_option( 'litespeed-cache-conf' ) ; + if (is_multisite()) { + $ver = get_site_option('litespeed.conf._version'); + if (!$ver) { + Debug2::debug('[Data] Conv multisite'); + $previous_site_options = get_site_option('litespeed-cache-conf'); $data = array( - 'network_enabled' => 'cache', - 'use_primary_settings' => 'use_primary_settings', - 'auto_upgrade' => 'auto_upgrade', - 'purge_upgrade' => 'purge-upgrade', - - 'cache_favicon' => 'cache-favicon', - 'cache_resources' => 'cache-resources', - 'mobileview_enabled' => 'cache-mobile', - 'mobileview_rules' => 'cache-mobile_rules', - 'login_cookie' => 'cache-login_cookie', - 'nocache_cookies' => 'cache-exc_cookies', - 'nocache_useragents' => 'cache-exc_useragents', - - 'cache_object' => 'object', - 'cache_object_kind' => 'object-kind', - 'cache_object_host' => 'object-host', - 'cache_object_port' => 'object-port', - 'cache_object_life' => 'object-life', - 'cache_object_persistent' => 'object-persistent', - 'cache_object_admin' => 'object-admin', - 'cache_object_transients' => 'object-transients', - 'cache_object_db_id' => 'object-db_id', - 'cache_object_user' => 'object-user', - 'cache_object_pswd' => 'object-psw', - - 'cache_browser' => 'cache-browser', - 'cache_browser_ttl' => 'cache-ttl_browser', - - 'media_webp_replace' => 'img_optm-webp', - ) ; - foreach ( $data as $k => $v ) { - if ( ! isset( $previous_site_options[ $k ] ) ) { - continue ; + 'network_enabled' => 'cache', + 'use_primary_settings' => 'use_primary_settings', + 'auto_upgrade' => 'auto_upgrade', + 'purge_upgrade' => 'purge-upgrade', + + 'cache_favicon' => 'cache-favicon', + 'cache_resources' => 'cache-resources', + 'mobileview_enabled' => 'cache-mobile', + 'mobileview_rules' => 'cache-mobile_rules', + 'login_cookie' => 'cache-login_cookie', + 'nocache_cookies' => 'cache-exc_cookies', + 'nocache_useragents' => 'cache-exc_useragents', + + 'cache_object' => 'object', + 'cache_object_kind' => 'object-kind', + 'cache_object_host' => 'object-host', + 'cache_object_port' => 'object-port', + 'cache_object_life' => 'object-life', + 'cache_object_persistent' => 'object-persistent', + 'cache_object_admin' => 'object-admin', + 'cache_object_transients' => 'object-transients', + 'cache_object_db_id' => 'object-db_id', + 'cache_object_user' => 'object-user', + 'cache_object_pswd' => 'object-psw', + + 'cache_browser' => 'cache-browser', + 'cache_browser_ttl' => 'cache-ttl_browser', + + 'media_webp_replace' => 'img_optm-webp', + ); + foreach ($data as $k => $v) { + if (!isset($previous_site_options[$k])) { + continue; } // The folllowing values must be array - if ( ! is_array( $previous_site_options[ $k ] ) ) { - if ( in_array( $v, array( 'cache-mobile_rules', 'cache-exc_useragents', 'cache-exc_cookies' ) ) ) { - $previous_site_options[ $k ] = explode( '|', str_replace( '\\ ', ' ', $previous_site_options[ $k ] ) ) ; - $previous_site_options[ $k ] = array_filter( $previous_site_options[ $k ] ) ; + if (!is_array($previous_site_options[$k])) { + if (in_array($v, array('cache-mobile_rules', 'cache-exc_useragents', 'cache-exc_cookies'))) { + $previous_site_options[$k] = explode('|', str_replace('\\ ', ' ', $previous_site_options[$k])); + $previous_site_options[$k] = array_filter($previous_site_options[$k]); } } - add_site_option( 'litespeed.conf.' . $v, $previous_site_options[ $k ] ) ; + add_site_option('litespeed.conf.' . $v, $previous_site_options[$k]); } // These are already converted to single record in single site - $data = array( - 'object-global_groups', - 'object-non_persistent_groups', - ) ; - foreach ( $data as $v ) { - $old_data = get_option( $v ) ; - if ( $old_data ) { - add_site_option( 'litespeed.conf.' . $v, $old_data ) ; + $data = array('object-global_groups', 'object-non_persistent_groups'); + foreach ($data as $v) { + $old_data = get_option($v); + if ($old_data) { + add_site_option('litespeed.conf.' . $v, $old_data); } } - delete_site_option( 'litespeed-cache-conf' ) ; + delete_site_option('litespeed-cache-conf'); - add_site_option( 'litespeed.conf._version', '3.0' ) ; + add_site_option('litespeed.conf._version', '3.0'); } - } // delete tables - Debug2::debug( "[Data] Drop litespeed_optimizer" ); - $q = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'litespeed_optimizer' ; - $wpdb->query( $q ) ; + Debug2::debug('[Data] Drop litespeed_optimizer'); + $q = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'litespeed_optimizer'; + $wpdb->query($q); // Update image optm table - Debug2::debug( "[Data] Upgrade img_optm table" ); - $tb_exists = $wpdb->get_var( 'SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_img_optm"' ); - if ( $tb_exists ) { + Debug2::debug('[Data] Upgrade img_optm table'); + $tb_exists = $wpdb->get_var('SHOW TABLES LIKE "' . $wpdb->prefix . 'litespeed_img_optm"'); + if ($tb_exists) { $status_mapping = array( - 'requested' => 3, - 'notified' => 6, - 'pulled' => 9, - 'failed' => -1, - 'miss' => -3, - 'err' => -9, - 'err_fetch' => -5, - 'err_optm' => -7, - 'xmeta' => -8, + 'requested' => 3, + 'notified' => 6, + 'pulled' => 9, + 'failed' => -1, + 'miss' => -3, + 'err' => -9, + 'err_fetch' => -5, + 'err_optm' => -7, + 'xmeta' => -8, ); - foreach ( $status_mapping as $k => $v ) { - $q = "UPDATE `" . $wpdb->prefix . "litespeed_img_optm` SET optm_status='$v' WHERE optm_status='$k'"; - $wpdb->query( $q ) ; + foreach ($status_mapping as $k => $v) { + $q = 'UPDATE `' . $wpdb->prefix . "litespeed_img_optm` SET optm_status='$v' WHERE optm_status='$k'"; + $wpdb->query($q); } - $q = 'ALTER TABLE `' . $wpdb->prefix . 'litespeed_img_optm` + $q = + 'ALTER TABLE `' . + $wpdb->prefix . + 'litespeed_img_optm` DROP INDEX `post_id_2`, DROP INDEX `root_id`, DROP INDEX `src_md5`, @@ -664,36 +674,12 @@ function litespeed_update_3_0( $ver ) { MODIFY COLUMN `optm_status` tinyint(4) NOT NULL DEFAULT 0, MODIFY COLUMN `src` text COLLATE utf8mb4_unicode_ci NOT NULL '; - $wpdb->query( $q ) ; + $wpdb->query($q); } - delete_option( 'litespeed-recommended' ); - - Debug2::debug( "[Data] litespeed_update_3_0 done!" ); + delete_option('litespeed-recommended'); - add_option( 'litespeed.conf._version', '3.0' ) ; + Debug2::debug('[Data] litespeed_update_3_0 done!'); + add_option('litespeed.conf._version', '3.0'); } - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/db-optm.cls.php b/src/db-optm.cls.php index 78788a2f5..87dd1eceb 100644 --- a/src/db-optm.cls.php +++ b/src/db-optm.cls.php @@ -10,12 +10,23 @@ */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class DB_Optm extends Root { +class DB_Optm extends Root +{ private static $_hide_more = false; - private static $TYPES = array( 'revision', 'auto_draft', 'trash_post', 'spam_comment', 'trash_comment', 'trackback-pingback', 'expired_transient', 'all_transients', 'optimize_tables' ); + private static $TYPES = array( + 'revision', + 'auto_draft', + 'trash_post', + 'spam_comment', + 'trash_comment', + 'trackback-pingback', + 'expired_transient', + 'all_transients', + 'optimize_tables', + ); const TYPE_CONV_TB = 'conv_innodb'; /** @@ -23,7 +34,8 @@ class DB_Optm extends Root { * * @since 3.0 */ - public static function hide_more() { + public static function hide_more() + { return self::$_hide_more; } @@ -36,27 +48,28 @@ public static function hide_more() { * @param bool $ignore_multisite If ignore multisite check * @return int The rows that will be affected */ - public function db_count( $type, $ignore_multisite = false ) { - if ( $type === 'all' ) { + public function db_count($type, $ignore_multisite = false) + { + if ($type === 'all') { $num = 0; - foreach ( self::$TYPES as $v ) { - $num += $this->db_count( $v ); + foreach (self::$TYPES as $v) { + $num += $this->db_count($v); } return $num; } - if ( ! $ignore_multisite ) { - if ( is_multisite() && is_network_admin() ) { + if (!$ignore_multisite) { + if (is_multisite() && is_network_admin()) { $num = 0; $blogs = Activation::get_network_ids(); - foreach ( $blogs as $k => $blog_id ) { - if ( $k > 3 ) { + foreach ($blogs as $k => $blog_id) { + if ($k > 3) { self::$_hide_more = true; break; } - switch_to_blog( $blog_id ); - $num += $this->db_count( $type, true ); + switch_to_blog($blog_id); + $num += $this->db_count($type, true); restore_current_blog(); } return $num; @@ -65,48 +78,48 @@ public function db_count( $type, $ignore_multisite = false ) { global $wpdb; - switch ( $type ) { + switch ($type) { case 'revision': - $rev_max = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_MAX ); - $rev_age = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_AGE ); + $rev_max = (int) $this->conf(Base::O_DB_OPTM_REVISIONS_MAX); + $rev_age = (int) $this->conf(Base::O_DB_OPTM_REVISIONS_AGE); $sql_add = ''; - if ( $rev_age ) { + if ($rev_age) { $sql_add = " and post_modified < DATE_SUB( NOW(), INTERVAL $rev_age DAY ) "; } $sql = "SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_type = 'revision' $sql_add"; - if ( ! $rev_max ) { - return $wpdb->get_var( $sql ); + if (!$rev_max) { + return $wpdb->get_var($sql); } // Has count limit $sql = "SELECT COUNT(*)-$rev_max FROM `$wpdb->posts` WHERE post_type = 'revision' $sql_add GROUP BY post_parent HAVING count(*)>$rev_max"; - $res = $wpdb->get_results( $sql, ARRAY_N ); + $res = $wpdb->get_results($sql, ARRAY_N); Utility::compatibility(); - return array_sum( array_column( $res, 0 ) ); + return array_sum(array_column($res, 0)); case 'auto_draft': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'auto-draft'" ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'auto-draft'"); case 'trash_post': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'trash'" ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'trash'"); case 'spam_comment': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'spam'" ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'spam'"); case 'trash_comment': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'trash'" ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'trash'"); case 'trackback-pingback': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback'" ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback'"); case 'expired_transient': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE '_transient_timeout%' AND option_value < " . time() ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE '_transient_timeout%' AND option_value < " . time()); case 'all_transients': - return $wpdb->get_var( "SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE '%_transient_%'" ); + return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE '%_transient_%'"); case 'optimize_tables': - return $wpdb->get_var( "SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA = '" . DB_NAME . "' and ENGINE <> 'InnoDB' and DATA_FREE > 0" ); + return $wpdb->get_var("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA = '" . DB_NAME . "' and ENGINE <> 'InnoDB' and DATA_FREE > 0"); } return '-'; @@ -119,19 +132,20 @@ public function db_count( $type, $ignore_multisite = false ) { * @since 3.0 changed to private * @access private */ - private function _db_clean( $type ) { - if ( $type === 'all' ) { - foreach ( self::$TYPES as $v ) { - $this->_db_clean( $v ); + private function _db_clean($type) + { + if ($type === 'all') { + foreach (self::$TYPES as $v) { + $this->_db_clean($v); } - return __( 'Clean all successfully.', 'litespeed-cache' ); + return __('Clean all successfully.', 'litespeed-cache'); } global $wpdb; - switch ( $type ) { + switch ($type) { case 'revision': - $rev_max = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_MAX ); - $rev_age = (int) $this->conf( Base::O_DB_OPTM_REVISIONS_AGE ); + $rev_max = (int) $this->conf(Base::O_DB_OPTM_REVISIONS_MAX); + $rev_age = (int) $this->conf(Base::O_DB_OPTM_REVISIONS_AGE); $postmeta = "`$wpdb->postmeta`"; $posts = "`$wpdb->posts`"; @@ -144,14 +158,12 @@ private function _db_clean( $type ) { $sql_where = "WHERE $posts.post_type = 'revision'"; - $sql_add = $rev_age - ? "AND $posts.post_modified < DATE_SUB( NOW(), INTERVAL $rev_age DAY )" - : ''; + $sql_add = $rev_age ? "AND $posts.post_modified < DATE_SUB( NOW(), INTERVAL $rev_age DAY )" : ''; - if ( ! $rev_max ) { + if (!$rev_max) { $sql_where = "$sql_where $sql_add"; - $wpdb->query( "DELETE $postmeta FROM $sql_postmeta $sql_where" ); - $wpdb->query( "DELETE FROM $posts $sql_where" ); + $wpdb->query("DELETE $postmeta FROM $sql_postmeta $sql_where"); + $wpdb->query("DELETE FROM $posts $sql_where"); } else { // Has count limit $sql = " @@ -163,63 +175,62 @@ private function _db_clean( $type ) { GROUP BY post_parent HAVING COUNT(*) > $rev_max "; - $res = $wpdb->get_results( $sql ); + $res = $wpdb->get_results($sql); $sql_where = " $sql_where AND $posts.post_parent = %d ORDER BY $posts.ID LIMIT %d "; - foreach ( $res as $v ) { - $args = array( $v->post_parent, $v->del_max ); - $sql = $wpdb->prepare( "DELETE $postmeta FROM $sql_postmeta $sql_where", $args ); - $wpdb->query( $sql ); - $sql = $wpdb->prepare( "DELETE FROM $posts $sql_where", $args ); - $wpdb->query( $sql ); + foreach ($res as $v) { + $args = array($v->post_parent, $v->del_max); + $sql = $wpdb->prepare("DELETE $postmeta FROM $sql_postmeta $sql_where", $args); + $wpdb->query($sql); + $sql = $wpdb->prepare("DELETE FROM $posts $sql_where", $args); + $wpdb->query($sql); } } - return __( 'Clean post revisions successfully.', 'litespeed-cache' ); + return __('Clean post revisions successfully.', 'litespeed-cache'); case 'auto_draft': - $wpdb->query( "DELETE FROM `$wpdb->posts` WHERE post_status = 'auto-draft'" ); - return __( 'Clean auto drafts successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_status = 'auto-draft'"); + return __('Clean auto drafts successfully.', 'litespeed-cache'); case 'trash_post': - $wpdb->query( "DELETE FROM `$wpdb->posts` WHERE post_status = 'trash'" ); - return __( 'Clean trashed posts and pages successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_status = 'trash'"); + return __('Clean trashed posts and pages successfully.', 'litespeed-cache'); case 'spam_comment': - $wpdb->query( "DELETE FROM `$wpdb->comments` WHERE comment_approved = 'spam'" ); - return __( 'Clean spam comments successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_approved = 'spam'"); + return __('Clean spam comments successfully.', 'litespeed-cache'); case 'trash_comment': - $wpdb->query( "DELETE FROM `$wpdb->comments` WHERE comment_approved = 'trash'" ); - return __( 'Clean trashed comments successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_approved = 'trash'"); + return __('Clean trashed comments successfully.', 'litespeed-cache'); case 'trackback-pingback': - $wpdb->query( "DELETE FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback'" ); - return __( 'Clean trackbacks and pingbacks successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback'"); + return __('Clean trackbacks and pingbacks successfully.', 'litespeed-cache'); case 'expired_transient': - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE option_name LIKE '_transient_timeout%' AND option_value < " . time() ); - return __( 'Clean expired transients successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->options` WHERE option_name LIKE '_transient_timeout%' AND option_value < " . time()); + return __('Clean expired transients successfully.', 'litespeed-cache'); case 'all_transients': - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE option_name LIKE '%\\_transient\\_%'" ); - return __( 'Clean all transients successfully.', 'litespeed-cache' ); + $wpdb->query("DELETE FROM `$wpdb->options` WHERE option_name LIKE '%\\_transient\\_%'"); + return __('Clean all transients successfully.', 'litespeed-cache'); case 'optimize_tables': $sql = "SELECT table_name, DATA_FREE FROM information_schema.tables WHERE TABLE_SCHEMA = '" . DB_NAME . "' and ENGINE <> 'InnoDB' and DATA_FREE > 0"; - $result = $wpdb->get_results( $sql ); - if ( $result ) { - foreach ( $result as $row ) { - $wpdb->query( 'OPTIMIZE TABLE ' . $row->table_name ); + $result = $wpdb->get_results($sql); + if ($result) { + foreach ($result as $row) { + $wpdb->query('OPTIMIZE TABLE ' . $row->table_name); } } - return __( 'Optimized all tables.', 'litespeed-cache' ); + return __('Optimized all tables.', 'litespeed-cache'); } - } /** @@ -228,10 +239,11 @@ private function _db_clean( $type ) { * @since 3.0 * @access public */ - public function list_myisam() { + public function list_myisam() + { global $wpdb; $q = "SELECT * FROM information_schema.tables WHERE TABLE_SCHEMA = '" . DB_NAME . "' and ENGINE = 'myisam' AND TABLE_NAME LIKE '{$wpdb->prefix}%'"; - return $wpdb->get_results( $q ); + return $wpdb->get_results($q); } /** @@ -240,37 +252,37 @@ public function list_myisam() { * @since 3.0 * @access private */ - private function _conv_innodb() { + private function _conv_innodb() + { global $wpdb; - if ( empty( $_GET[ 'tb' ] ) ) { - Admin_Display::error( 'No table to convert' ); + if (empty($_GET['tb'])) { + Admin_Display::error('No table to convert'); return; } $tb = false; $list = $this->list_myisam(); - foreach ( $list as $v ) { - if ( $v->TABLE_NAME == $_GET[ 'tb' ] ) { + foreach ($list as $v) { + if ($v->TABLE_NAME == $_GET['tb']) { $tb = $v->TABLE_NAME; break; } } - if ( ! $tb ) { - Admin_Display::error( 'No existing table' ); + if (!$tb) { + Admin_Display::error('No existing table'); return; } $q = 'ALTER TABLE ' . DB_NAME . '.' . $tb . ' ENGINE = InnoDB'; - $wpdb->query( $q ); - - Debug2::debug( "[DB] Converted $tb to InnoDB" ); + $wpdb->query($q); - $msg = __( 'Converted to InnoDB successfully.', 'litespeed-cache' ); - Admin_Display::succeed( $msg ); + Debug2::debug("[DB] Converted $tb to InnoDB"); + $msg = __('Converted to InnoDB successfully.', 'litespeed-cache'); + Admin_Display::succeed($msg); } /** @@ -279,12 +291,15 @@ private function _conv_innodb() { * @since 3.0 * @access public */ - public function autoload_summary() { + public function autoload_summary() + { global $wpdb; - $summary = $wpdb->get_row( "SELECT SUM(LENGTH(option_value)) AS autoload_size,COUNT(*) AS autload_entries FROM `$wpdb->options` WHERE autoload='yes'" ); + $summary = $wpdb->get_row("SELECT SUM(LENGTH(option_value)) AS autoload_size,COUNT(*) AS autload_entries FROM `$wpdb->options` WHERE autoload='yes'"); - $summary->autoload_toplist = $wpdb->get_results( "SELECT option_name, LENGTH(option_value) AS option_value_length FROM `$wpdb->options` WHERE autoload='yes' ORDER BY option_value_length DESC LIMIT 20" ); + $summary->autoload_toplist = $wpdb->get_results( + "SELECT option_name, LENGTH(option_value) AS option_value_length FROM `$wpdb->options` WHERE autoload='yes' ORDER BY option_value_length DESC LIMIT 20" + ); return $summary; } @@ -295,27 +310,27 @@ public function autoload_summary() { * @since 3.0 * @access public */ - public function handler() { + public function handler() + { $type = Router::verify_type(); - switch ( $type ) { + switch ($type) { case 'all': - case in_array( $type, self::$TYPES ): - if ( is_multisite() && is_network_admin() ) { + case in_array($type, self::$TYPES): + if (is_multisite() && is_network_admin()) { $blogs = Activation::get_network_ids(); - foreach ( $blogs as $blog_id ) { - switch_to_blog( $blog_id ); - $msg = $this->_db_clean( $type ); + foreach ($blogs as $blog_id) { + switch_to_blog($blog_id); + $msg = $this->_db_clean($type); restore_current_blog(); } + } else { + $msg = $this->_db_clean($type); } - else { - $msg = $this->_db_clean( $type ); - } - Admin_Display::succeed( $msg ); + Admin_Display::succeed($msg); break; - case self::TYPE_CONV_TB : + case self::TYPE_CONV_TB: $this->_conv_innodb(); break; @@ -325,6 +340,4 @@ public function handler() { Admin::redirect(); } - } - diff --git a/src/debug2.cls.php b/src/debug2.cls.php index e9e8d34cf..d7a1b3c1b 100644 --- a/src/debug2.cls.php +++ b/src/debug2.cls.php @@ -6,7 +6,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Debug2 extends Root { @@ -119,7 +119,7 @@ public function beta_test($zip = false) private function _package_zip($commit) { $data = array( - 'commit' => $commit, + 'commit' => $commit, ); $res = Cloud::get(Cloud::API_BETA_TEST, $data); @@ -189,7 +189,8 @@ public function init() } } - if (!defined('LSCWP_LOG')) { // If not initialized, do it now + if (!defined('LSCWP_LOG')) { + // If not initialized, do it now $this->_init_request(); define('LSCWP_LOG', true); } @@ -322,7 +323,7 @@ private static function format_message($msg) } // Generate a unique string per request - self::$_prefix = sprintf(" [%s %s %s] ", $addr, LSCWP_LOG_TAG, Str::rrand(3)); + self::$_prefix = sprintf(' [%s %s %s] ', $addr, LSCWP_LOG_TAG, Str::rrand(3)); } list($usec, $sec) = explode(' ', microtime()); return date('m/d/y H:i:s', $sec + LITESPEED_TIME_OFFSET) . substr($usec, 1, 4) . self::$_prefix . $msg . "\n"; @@ -420,7 +421,8 @@ private static function _backtrace_info($backtrace_limit) $msg = ''; $trace = version_compare(PHP_VERSION, '5.4.0', '<') ? debug_backtrace() : debug_backtrace(false, $backtrace_limit + 3); - for ($i = 2; $i <= $backtrace_limit + 2; $i++) { // 0st => _backtrace_info(), 1st => push() + for ($i = 2; $i <= $backtrace_limit + 2; $i++) { + // 0st => _backtrace_info(), 1st => push() if (empty($trace[$i]['class'])) { if (empty($trace[$i]['file'])) { break; diff --git a/src/doc.cls.php b/src/doc.cls.php index 44452d966..28d61ab38 100644 --- a/src/doc.cls.php +++ b/src/doc.cls.php @@ -11,7 +11,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Doc { @@ -25,11 +25,22 @@ class Doc */ public static function maybe_on_by_gm($id) { - if (apply_filters('litespeed_conf', $id)) return; - if (!apply_filters('litespeed_conf', Base::O_GUEST)) return; - if (!apply_filters('litespeed_conf', Base::O_GUEST_OPTM)) return; + if (apply_filters('litespeed_conf', $id)) { + return; + } + if (!apply_filters('litespeed_conf', Base::O_GUEST)) { + return; + } + if (!apply_filters('litespeed_conf', Base::O_GUEST_OPTM)) { + return; + } echo ''; - echo '⚠️ ' . sprintf(__('This setting is %1$s for certain qualifying requests due to %2$s!', 'litespeed-cache'), '' . __('ON', 'litespeed-cache') . '', Lang::title(Base::O_GUEST_OPTM)); + echo '⚠️ ' . + sprintf( + __('This setting is %1$s for certain qualifying requests due to %2$s!', 'litespeed-cache'), + '' . __('ON', 'litespeed-cache') . '', + Lang::title(Base::O_GUEST_OPTM) + ); self::learn_more('https://docs.litespeedtech.com/lscache/lscwp/general/#guest-optimization'); echo ''; } @@ -55,11 +66,16 @@ public static function crawler_affected() */ public static function privacy_policy() { - return __('This site utilizes caching in order to facilitate a faster response time and better user experience. Caching potentially stores a duplicate copy of every web page that is on display on this site. All cache files are temporary, and are never accessed by any third party, except as necessary to obtain technical support from the cache plugin vendor. Cache files expire on a schedule set by the site administrator, but may easily be purged by the admin before their natural expiration, if necessary. We may use QUIC.cloud services to process & cache your data temporarily.', 'litespeed-cache') - . sprintf(__('Please see %s for more details.', 'litespeed-cache'), 'https://quic.cloud/privacy-policy/'); + return __( + 'This site utilizes caching in order to facilitate a faster response time and better user experience. Caching potentially stores a duplicate copy of every web page that is on display on this site. All cache files are temporary, and are never accessed by any third party, except as necessary to obtain technical support from the cache plugin vendor. Cache files expire on a schedule set by the site administrator, but may easily be purged by the admin before their natural expiration, if necessary. We may use QUIC.cloud services to process & cache your data temporarily.', + 'litespeed-cache' + ) . + sprintf( + __('Please see %s for more details.', 'litespeed-cache'), + 'https://quic.cloud/privacy-policy/' + ); } - /** * Learn more link * @@ -127,7 +143,9 @@ public static function notice_htaccess() { echo ''; echo '⚠️ ' . __('This setting will edit the .htaccess file.', 'litespeed-cache'); - echo ' ' . __('Learn More', 'litespeed-cache') . ''; + echo ' ' . + __('Learn More', 'litespeed-cache') . + ''; echo ''; } @@ -154,10 +172,11 @@ public static function notice_ips() */ public static function queue_issues($return = false) { - $str = '
      ' - . esc_html__('The queue is processed asynchronously. It may take time.', 'litespeed-cache') - . self::learn_more('https://docs.litespeedtech.com/lscache/lscwp/troubleshoot/#quiccloud-queue-issues', false, false, false, true) - . '
      '; + $str = + '
      ' . + esc_html__('The queue is processed asynchronously. It may take time.', 'litespeed-cache') . + self::learn_more('https://docs.litespeedtech.com/lscache/lscwp/troubleshoot/#quiccloud-queue-issues', false, false, false, true) . + '
      '; if ($return) { return $str; } diff --git a/src/error.cls.php b/src/error.cls.php index 7ca0d1865..df72b0f3a 100644 --- a/src/error.cls.php +++ b/src/error.cls.php @@ -11,17 +11,17 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class Error { private static $CODE_SET = array( 'HTA_LOGIN_COOKIE_INVALID' => 4300, // .htaccess did not find. - 'HTA_DNF' => 4500, // .htaccess did not find. - 'HTA_BK' => 9010, // backup - 'HTA_R' => 9041, // read htaccess - 'HTA_W' => 9042, // write - 'HTA_GET' => 9030, // failed to get + 'HTA_DNF' => 4500, // .htaccess did not find. + 'HTA_BK' => 9010, // backup + 'HTA_R' => 9041, // read htaccess + 'HTA_W' => 9042, // write + 'HTA_GET' => 9030, // failed to get ); /** @@ -42,14 +42,21 @@ public static function t($code, $args = null) public static function msg($code, $args = null) { switch ($code) { - case 'disabled_all': - $msg = sprintf(__('The setting %s is currently enabled.', 'litespeed-cache'), '' . Lang::title(Base::O_DEBUG_DISABLE_ALL) . '') . - Doc::learn_more(is_network_admin() ? network_admin_url('admin.php?page=litespeed-toolbox') : admin_url('admin.php?page=litespeed-toolbox'), __('Click here to change.', 'litespeed-cache'), true, false, true); + $msg = + sprintf(__('The setting %s is currently enabled.', 'litespeed-cache'), '' . Lang::title(Base::O_DEBUG_DISABLE_ALL) . '') . + Doc::learn_more( + is_network_admin() ? network_admin_url('admin.php?page=litespeed-toolbox') : admin_url('admin.php?page=litespeed-toolbox'), + __('Click here to change.', 'litespeed-cache'), + true, + false, + true + ); break; case 'lack_of_api_key': - $msg = sprintf(__('You will need to set %s to use the online services.', 'litespeed-cache'), '' . Lang::title(Base::O_API_KEY) . '') . + $msg = + sprintf(__('You will need to set %s to use the online services.', 'litespeed-cache'), '' . Lang::title(Base::O_API_KEY) . '') . Doc::learn_more(admin_url('admin.php?page=litespeed-general'), __('Click here to set.', 'litespeed-cache'), true, false, true); break; @@ -82,7 +89,10 @@ public static function msg($code, $args = null) break; case strpos($code, 'unfinished_queue ') === 0: - $msg = sprintf(__('There is proceeding queue not pulled yet. Queue info: %s.', 'litespeed-cache'), '' . substr($code, strlen('unfinished_queue ')) . ''); + $msg = sprintf( + __('There is proceeding queue not pulled yet. Queue info: %s.', 'litespeed-cache'), + '' . substr($code, strlen('unfinished_queue ')) . '' + ); break; case 'err_alias': @@ -149,13 +159,16 @@ public static function msg($code, $args = null) $msg = __('Crawler disabled by the server admin.', 'litespeed-cache'); break; - /*** QC error code ***/ + /*** QC error code ***/ case 'try_later': $msg = __('Previous request too recent. Please try again later.', 'litespeed-cache'); break; case strpos($code, 'try_later ') === 0: - $msg = sprintf(__('Previous request too recent. Please try again after %s.', 'litespeed-cache'), '' . Utility::readable_time(substr($code, strlen('try_later ')), 3600, true) . ''); + $msg = sprintf( + __('Previous request too recent. Please try again after %s.', 'litespeed-cache'), + '' . Utility::readable_time(substr($code, strlen('try_later ')), 3600, true) . '' + ); break; case 'waiting_for_approval': @@ -171,7 +184,9 @@ public static function msg($code, $args = null) break; case substr($code, 0, 14) === 'callback_fail ': - $msg = __('The callback validation to your domain failed. Please make sure there is no firewall blocking our servers. Response code: ', 'litespeed-cache') . substr($code, 14); + $msg = + __('The callback validation to your domain failed. Please make sure there is no firewall blocking our servers. Response code: ', 'litespeed-cache') . + substr($code, 14); break; case 'forbidden': @@ -179,7 +194,10 @@ public static function msg($code, $args = null) break; case 'err_dns_active': - $msg = __('You cannot remove this DNS zone, because it is still in use. Please update the domain\'s nameservers, then try to delete this zone again, otherwise your site will become inaccessible.', 'litespeed-cache'); + $msg = __( + 'You cannot remove this DNS zone, because it is still in use. Please update the domain\'s nameservers, then try to delete this zone again, otherwise your site will become inaccessible.', + 'litespeed-cache' + ); break; default: diff --git a/src/esi.cls.php b/src/esi.cls.php index 841de03c1..55333dba2 100644 --- a/src/esi.cls.php +++ b/src/esi.cls.php @@ -13,7 +13,7 @@ namespace LiteSpeed; -defined('WPINC') || exit; +defined('WPINC') || exit(); class ESI extends Root { @@ -277,8 +277,12 @@ private function _register_esi_actions() */ if (!empty($_SERVER['ESI_REFERER']) && !$this->cls('REST')->is_rest($_SERVER['ESI_REFERER'])) { self::debug('overwrite REQUEST_URI to ESI_REFERER [from] ' . $_SERVER['REQUEST_URI'] . ' [to] ' . $_SERVER['ESI_REFERER']); - if (!empty($_SERVER['ESI_REFERER'])) - $_SERVER['REQUEST_URI'] = substr(get_option('permalink_structure'), -1) === '/' && strpos($_SERVER['ESI_REFERER'], '?') === false ? trailingslashit($_SERVER['ESI_REFERER']) : $_SERVER['ESI_REFERER']; + if (!empty($_SERVER['ESI_REFERER'])) { + $_SERVER['REQUEST_URI'] = + substr(get_option('permalink_structure'), -1) === '/' && strpos($_SERVER['ESI_REFERER'], '?') === false + ? trailingslashit($_SERVER['ESI_REFERER']) + : $_SERVER['ESI_REFERER']; + } # Prevent from 301 redirecting if (!empty($_SERVER['SCRIPT_URI'])) { $SCRIPT_URI = parse_url($_SERVER['SCRIPT_URI']); @@ -433,7 +437,7 @@ private static function _build_inline($url, $inline_param) $control = esc_attr($inline_param['control']); $tag = esc_attr($inline_param['tag']); - return "" . $inline_param['val'] . ""; + return "" . $inline_param['val'] . ''; } /** @@ -452,8 +456,16 @@ private static function _build_inline($url, $inline_param) * @param bool $svar If store the value in memory or not, in memory wil be faster * @param array $inline_val If show the current value for current request( this can avoid multiple esi requests in first time cache generating process ) */ - public function sub_esi_block($block_id, $wrapper, $params = array(), $control = 'private,no-vary', $silence = false, $preserved = false, $svar = false, $inline_param = array()) - { + public function sub_esi_block( + $block_id, + $wrapper, + $params = array(), + $control = 'private,no-vary', + $silence = false, + $preserved = false, + $svar = false, + $inline_param = array() + ) { if (empty($block_id) || !is_array($params) || preg_match('/[^\w-]/', $block_id)) { return false; } @@ -484,7 +496,7 @@ public function sub_esi_block($block_id, $wrapper, $params = array(), $control = // Build params for URL $appended_params = array( - self::QS_ACTION => $block_id, + self::QS_ACTION => $block_id, ); if (!empty($control)) { $appended_params['_control'] = $control; @@ -525,7 +537,7 @@ public function sub_esi_block($block_id, $wrapper, $params = array(), $control = if ($block_id == self::COMBO && isset($_SERVER['X-LSCACHE']) && strpos($_SERVER['X-LSCACHE'], 'combine') !== false) { $output .= " combine='main'"; } - $output .= " />"; + $output .= ' />'; if (!$silence) { $output = "$output"; @@ -557,11 +569,7 @@ public function sub_esi_block($block_id, $wrapper, $params = array(), $control = */ private function _gen_esi_md5($params) { - $keys = array( - self::QS_ACTION, - '_control', - self::QS_PARAMS, - ); + $keys = array(self::QS_ACTION, '_control', self::QS_PARAMS); $str = ''; foreach ($keys as $v) { @@ -733,7 +741,7 @@ public function sub_widget_block($instance, $widget, $args) self::PARAM_NAME => $name, self::PARAM_ID => $widget->id, self::PARAM_INSTANCE => $instance, - self::PARAM_ARGS => $args + self::PARAM_ARGS => $args, ); echo $this->sub_esi_block('widget', 'widget ' . $name, $params, $esi_private . 'no-vary'); @@ -805,7 +813,6 @@ public function load_widget_block($params) */ public function load_admin_bar_block($params) { - if (!empty($params['ref'])) { $ref_qs = parse_url($params['ref'], PHP_URL_QUERY); if (!empty($ref_qs)) { @@ -830,7 +837,6 @@ public function load_admin_bar_block($params) defined('LSCWP_LOG') && Debug2::debug('ESI: adminbar ref: ' . $_SERVER['REQUEST_URI']); } - /** * Parses the esi input parameters and generates the comment form for esi display. * @@ -910,7 +916,7 @@ public function load_esi_shortcode($params) Tag::add(Tag::TYPE_ESI . "esi.$shortcode"); // Output original shortcode final content - echo do_shortcode("[$shortcode " . implode(' ', $atts_ori) . " ]"); + echo do_shortcode("[$shortcode " . implode(' ', $atts_ori) . ' ]'); } /** diff --git a/src/file.cls.php b/src/file.cls.php index 16b4efd0f..36ea4febf 100644 --- a/src/file.cls.php +++ b/src/file.cls.php @@ -1,15 +1,16 @@ seek($start_line); - if ( $lines === null) { - while ( ! $file->eof() ) { + if ($lines === null) { + while (!$file->eof()) { $res[] = rtrim($file->current(), "\n"); $file->next(); } - } - else{ - for ( $i=0; $i < $lines; $i++ ) { - if ( $file->eof() ) { + } else { + for ($i = 0; $i < $lines; $i++) { + if ($file->eof()) { break; } $res[] = rtrim($file->current(), "\n"); @@ -95,9 +98,9 @@ public static function read($filename, $start_line = null, $lines = null) { return $res; } - $content = file_get_contents( $filename ); + $content = file_get_contents($filename); - $content = self::remove_zero_space( $content ); + $content = self::remove_zero_space($content); return $content; } @@ -112,8 +115,9 @@ public static function read($filename, $start_line = null, $lines = null) { * @param boolean $mkdir * @param boolean $silence Used to avoid WP's functions are used */ - public static function append( $filename, $data, $mkdir = false, $silence = true ) { - return self::save( $filename, $data, $mkdir, true, $silence ); + public static function append($filename, $data, $mkdir = false, $silence = true) + { + return self::save($filename, $data, $mkdir, true, $silence); } /** @@ -126,50 +130,48 @@ public static function append( $filename, $data, $mkdir = false, $silence = true * @param boolean $append If the content needs to be appended * @param boolean $silence Used to avoid WP's functions are used */ - public static function save( $filename, $data, $mkdir = false, $append = false, $silence = true ) { + public static function save($filename, $data, $mkdir = false, $append = false, $silence = true) + { $error = false; - $folder = dirname( $filename ); + $folder = dirname($filename); // mkdir if folder does not exist - if ( ! file_exists( $folder ) ) { - if ( ! $mkdir ) { - return $silence ? false : sprintf( __( 'Folder does not exist: %s', 'litespeed-cache' ), $folder ); + if (!file_exists($folder)) { + if (!$mkdir) { + return $silence ? false : sprintf(__('Folder does not exist: %s', 'litespeed-cache'), $folder); } - set_error_handler( 'litespeed_exception_handler' ); + set_error_handler('litespeed_exception_handler'); try { - mkdir( $folder, 0755, true ); - } - catch ( \ErrorException $ex ) { - return $silence ? false : sprintf( __( 'Can not create folder: %1$s. Error: %2$s', 'litespeed-cache' ), $folder, $ex->getMessage() ); + mkdir($folder, 0755, true); + } catch (\ErrorException $ex) { + return $silence ? false : sprintf(__('Can not create folder: %1$s. Error: %2$s', 'litespeed-cache'), $folder, $ex->getMessage()); } restore_error_handler(); } - if ( ! file_exists( $filename ) ) { - if ( ! is_writable( $folder ) ) { - return $silence ? false : sprintf( __( 'Folder is not writable: %s.', 'litespeed-cache' ), $folder ); + if (!file_exists($filename)) { + if (!is_writable($folder)) { + return $silence ? false : sprintf(__('Folder is not writable: %s.', 'litespeed-cache'), $folder); } - set_error_handler( 'litespeed_exception_handler' ); + set_error_handler('litespeed_exception_handler'); try { - touch( $filename ); - } - catch ( \ErrorException $ex ){ - return $silence ? false : sprintf( __( 'File %s is not writable.', 'litespeed-cache' ), $filename ); + touch($filename); + } catch (\ErrorException $ex) { + return $silence ? false : sprintf(__('File %s is not writable.', 'litespeed-cache'), $filename); } restore_error_handler(); - } - elseif ( ! is_writable( $filename ) ) { - return $silence ? false : sprintf( __( 'File %s is not writable.', 'litespeed-cache' ), $filename ); + } elseif (!is_writable($filename)) { + return $silence ? false : sprintf(__('File %s is not writable.', 'litespeed-cache'), $filename); } - $data = self::remove_zero_space( $data ); + $data = self::remove_zero_space($data); - $ret = file_put_contents( $filename, $data, $append ? FILE_APPEND : LOCK_EX ); - if ( $ret === false ) { - return $silence ? false : sprintf( __( 'Failed to write to %s.', 'litespeed-cache' ), $filename ); + $ret = file_put_contents($filename, $data, $append ? FILE_APPEND : LOCK_EX); + if ($ret === false) { + return $silence ? false : sprintf(__('Failed to write to %s.', 'litespeed-cache'), $filename); } return true; @@ -181,20 +183,21 @@ public static function save( $filename, $data, $mkdir = false, $append = false, * @since 2.1.2 * @since 2.9 changed to public */ - public static function remove_zero_space( $content ) { - if ( is_array( $content ) ) { - $content = array_map( __CLASS__ . '::remove_zero_space', $content ); + public static function remove_zero_space($content) + { + if (is_array($content)) { + $content = array_map(__CLASS__ . '::remove_zero_space', $content); return $content; } // Remove UTF-8 BOM if present - if ( substr( $content, 0, 3 ) === "\xEF\xBB\xBF" ) { - $content = substr( $content, 3 ); + if (substr($content, 0, 3) === "\xEF\xBB\xBF") { + $content = substr($content, 3); } - $content = str_replace( "\xe2\x80\x8b", '', $content ); - $content = str_replace( "\xe2\x80\x8c", '', $content ); - $content = str_replace( "\xe2\x80\x8d", '', $content ); + $content = str_replace("\xe2\x80\x8b", '', $content); + $content = str_replace("\xe2\x80\x8c", '', $content); + $content = str_replace("\xe2\x80\x8d", '', $content); return $content; } @@ -212,16 +215,17 @@ public static function remove_zero_space( $content ) { * @param bool $prepend Prepend insertion if not exist. * @return bool True on write success, false on failure. */ - public static function insert_with_markers($filename, $insertion = false, $marker = false, $prepend = false) { - if ( !$marker ) { + public static function insert_with_markers($filename, $insertion = false, $marker = false, $prepend = false) + { + if (!$marker) { $marker = self::MARKER; } - if ( !$insertion ) { + if (!$insertion) { $insertion = array(); } - return self::_insert_with_markers($filename, $marker, $insertion, $prepend);//todo: capture exceptions + return self::_insert_with_markers($filename, $marker, $insertion, $prepend); //todo: capture exceptions } /** @@ -231,18 +235,15 @@ public static function insert_with_markers($filename, $insertion = false, $marke * @param string $marker * @return string The block data */ - public static function wrap_marker_data($insertion, $marker = false) { - if ( ! $marker ) { + public static function wrap_marker_data($insertion, $marker = false) + { + if (!$marker) { $marker = self::MARKER; } $start_marker = "# BEGIN {$marker}"; - $end_marker = "# END {$marker}"; + $end_marker = "# END {$marker}"; - $new_data = implode( "\n", array_merge( - array( $start_marker ), - $insertion, - array( $end_marker ) - ) ); + $new_data = implode("\n", array_merge(array($start_marker), $insertion, array($end_marker))); return $new_data; } @@ -253,24 +254,21 @@ public static function wrap_marker_data($insertion, $marker = false) { * @param string $marker * @return string The current block data */ - public static function touch_marker_data($filename, $marker = false) { - if( ! $marker ) { + public static function touch_marker_data($filename, $marker = false) + { + if (!$marker) { $marker = self::MARKER; } $result = self::_extract_from_markers($filename, $marker); - if( ! $result ) { + if (!$result) { return false; } $start_marker = "# BEGIN {$marker}"; - $end_marker = "# END {$marker}"; - $new_data = implode( "\n", array_merge( - array( $start_marker ), - $result, - array( $end_marker ) - ) ); + $end_marker = "# END {$marker}"; + $new_data = implode("\n", array_merge(array($start_marker), $result, array($end_marker))); return $new_data; } @@ -281,8 +279,9 @@ public static function touch_marker_data($filename, $marker = false) { * @param string $marker * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers. */ - public static function extract_from_markers($filename, $marker = false) { - if( ! $marker ) { + public static function extract_from_markers($filename, $marker = false) + { + if (!$marker) { $marker = self::MARKER; } return self::_extract_from_markers($filename, $marker); @@ -295,20 +294,21 @@ public static function extract_from_markers($filename, $marker = false) { * @param string $marker * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers. */ - private static function _extract_from_markers( $filename, $marker ) { + private static function _extract_from_markers($filename, $marker) + { $result = array(); - if (!file_exists($filename) ) { + if (!file_exists($filename)) { return $result; } - if ( $markerdata = explode( "\n", implode( '', file($filename) ) ) ) { + if ($markerdata = explode("\n", implode('', file($filename)))) { $state = false; - foreach ( $markerdata as $markerline ) { - if ( strpos($markerline, '# END ' . $marker) !== false ) { + foreach ($markerdata as $markerline) { + if (strpos($markerline, '# END ' . $marker) !== false) { $state = false; } - if ( $state ) { + if ($state) { $result[] = $markerline; } if (strpos($markerline, '# BEGIN ' . $marker) !== false) { @@ -331,70 +331,67 @@ private static function _extract_from_markers( $filename, $marker ) { * @since 3.0 Throw errors if failed * @access private */ - private static function _insert_with_markers( $filename, $marker, $insertion, $prepend = false) { - if ( ! file_exists( $filename ) ) { - if ( ! is_writable( dirname( $filename ) ) ) { - Error::t( 'W', dirname( $filename ) ); + private static function _insert_with_markers($filename, $marker, $insertion, $prepend = false) + { + if (!file_exists($filename)) { + if (!is_writable(dirname($filename))) { + Error::t('W', dirname($filename)); } - set_error_handler("litespeed_exception_handler"); + set_error_handler('litespeed_exception_handler'); try { - touch( $filename ); - } catch ( \ErrorException $ex ) { - Error::t( 'W', $filename ); + touch($filename); + } catch (\ErrorException $ex) { + Error::t('W', $filename); } restore_error_handler(); - } - elseif ( ! is_writable( $filename ) ) { - Error::t( 'W', $filename ); + } elseif (!is_writable($filename)) { + Error::t('W', $filename); } - if ( ! is_array( $insertion ) ) { - $insertion = explode( "\n", $insertion ); + if (!is_array($insertion)) { + $insertion = explode("\n", $insertion); } $start_marker = "# BEGIN {$marker}"; - $end_marker = "# END {$marker}"; + $end_marker = "# END {$marker}"; - $fp = fopen( $filename, 'r+' ); - if ( ! $fp ) { - Error::t( 'W', $filename ); + $fp = fopen($filename, 'r+'); + if (!$fp) { + Error::t('W', $filename); } // Attempt to get a lock. If the filesystem supports locking, this will block until the lock is acquired. - flock( $fp, LOCK_EX ); + flock($fp, LOCK_EX); $lines = array(); - while ( ! feof($fp) ) { - $lines[] = rtrim(fgets($fp), "\r\n" ); + while (!feof($fp)) { + $lines[] = rtrim(fgets($fp), "\r\n"); } // Split out the existing file into the preceding lines, and those that appear after the marker $pre_lines = $post_lines = $existing_lines = array(); $found_marker = $found_end_marker = false; - foreach ( $lines as $line ) { - if ( ! $found_marker && false !== strpos($line, $start_marker) ) { + foreach ($lines as $line) { + if (!$found_marker && false !== strpos($line, $start_marker)) { $found_marker = true; continue; - } - elseif ( ! $found_end_marker && false !== strpos($line, $end_marker) ) { + } elseif (!$found_end_marker && false !== strpos($line, $end_marker)) { $found_end_marker = true; continue; } - if ( ! $found_marker ) { + if (!$found_marker) { $pre_lines[] = $line; - } - elseif ( $found_marker && $found_end_marker ) { + } elseif ($found_marker && $found_end_marker) { $post_lines[] = $line; - } - else { + } else { $existing_lines[] = $line; } } // Check to see if there was a change - if ( $existing_lines === $insertion ) { + if ($existing_lines === $insertion) { flock($fp, LOCK_UN); fclose($fp); @@ -402,32 +399,18 @@ private static function _insert_with_markers( $filename, $marker, $insertion, $p } // Check if need to prepend data if not exist - if( $prepend && ! $post_lines ) { + if ($prepend && !$post_lines) { // Generate the new file data - $new_file_data = implode( "\n", array_merge( - array( $start_marker ), - $insertion, - array( $end_marker ), - $pre_lines - ) ); - - } - else { + $new_file_data = implode("\n", array_merge(array($start_marker), $insertion, array($end_marker), $pre_lines)); + } else { // Generate the new file data - $new_file_data = implode( "\n", array_merge( - $pre_lines, - array( $start_marker ), - $insertion, - array( $end_marker ), - $post_lines - ) ); + $new_file_data = implode("\n", array_merge($pre_lines, array($start_marker), $insertion, array($end_marker), $post_lines)); } - // Write to the start of the file, and truncate it to that length fseek($fp, 0); $bytes = fwrite($fp, $new_file_data); - if ( $bytes ) { + if ($bytes) { ftruncate($fp, ftell($fp)); } fflush($fp); @@ -437,5 +420,3 @@ private static function _insert_with_markers( $filename, $marker, $insertion, $p return (bool) $bytes; } } - - diff --git a/src/gui.cls.php b/src/gui.cls.php index 8d13531ce..3317958af 100644 --- a/src/gui.cls.php +++ b/src/gui.cls.php @@ -7,17 +7,18 @@ * @author LiteSpeed Technologies */ namespace LiteSpeed; -defined( 'WPINC' ) || exit; +defined('WPINC') || exit(); -class GUI extends Base { +class GUI extends Base +{ private static $_clean_counter = 0; private $_promo_true; // [ file_tag => [ days, litespeed_only ], ... ] private $_promo_list = array( - 'new_version' => array( 7, false ), - 'score' => array( 14, false ), + 'new_version' => array(7, false), + 'score' => array(14, false), // 'slack' => array( 3, false ), ); @@ -40,9 +41,9 @@ class GUI extends Base { * * @since 1.3 */ - public function __construct() { + public function __construct() + { $this->_summary = self::get_summary(); - } /** @@ -50,33 +51,35 @@ public function __construct() { * * @since 3.0 */ - public function init() { - Debug2::debug2( '[GUI] init' ); - if ( is_admin_bar_showing() && current_user_can( 'manage_options' ) ) { - add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue_style' ) ); - add_action( 'admin_bar_menu', array( $this, 'frontend_shortcut' ), 95 ); + public function init() + { + Debug2::debug2('[GUI] init'); + if (is_admin_bar_showing() && current_user_can('manage_options')) { + add_action('wp_enqueue_scripts', array($this, 'frontend_enqueue_style')); + add_action('admin_bar_menu', array($this, 'frontend_shortcut'), 95); } /** * Turn on instant click * @since 1.8.2 */ - if ( $this->conf( self::O_UTIL_INSTANT_CLICK ) ) { - add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue_style_public' ) ); + if ($this->conf(self::O_UTIL_INSTANT_CLICK)) { + add_action('wp_enqueue_scripts', array($this, 'frontend_enqueue_style_public')); } // NOTE: this needs to be before optimizer to avoid wrapper being removed - add_filter( 'litespeed_buffer_finalize', array( $this, 'finalize' ), 8 ); + add_filter('litespeed_buffer_finalize', array($this, 'finalize'), 8); } /** - * Print a loading message when redirecting CCSS/UCSS page to aviod whiteboard confusion - */ - public static function print_loading( $counter, $type ) { + * Print a loading message when redirecting CCSS/UCSS page to aviod whiteboard confusion + */ + public static function print_loading($counter, $type) + { echo '
      '; echo " "; - echo sprintf( __( '%1$s %2$s files left in queue', 'litespeed-cache' ), $counter, $type ); - echo '

      ' . __( 'Cancel', 'litespeed-cache' ) . '

      '; + echo sprintf(__('%1$s %2$s files left in queue', 'litespeed-cache'), $counter, $type); + echo '

      ' . __('Cancel', 'litespeed-cache') . '

      '; echo '
      '; } @@ -85,10 +88,11 @@ public static function print_loading( $counter, $type ) { * * @since 1.6.6 */ - public static function pie( $percent, $width = 50, $finished_tick = false, $without_percentage = false, $append_cls = false ) { - $percentage = '' . $percent . ( $without_percentage ? '' : '%' ) . ''; + public static function pie($percent, $width = 50, $finished_tick = false, $without_percentage = false, $append_cls = false) + { + $percentage = '' . $percent . ($without_percentage ? '' : '%') . ''; - if ( $percent == 100 && $finished_tick ) { + if ($percent == 100 && $finished_tick) { $percentage = ''; } @@ -106,10 +110,10 @@ public static function pie( $percent, $width = 50, $finished_tick = false, $with * * @since 3.0 */ - public static function pie_tiny( $percent, $width = 50, $tooltip = '', $tooltip_pos = 'up', $append_cls = false ) { - + public static function pie_tiny($percent, $width = 50, $tooltip = '', $tooltip_pos = 'up', $append_cls = false) + { // formula C = 2πR - $dasharray = 2 * 3.1416 * 9 * ( $percent / 100 ); + $dasharray = 2 * 3.1416 * 9 * ($percent / 100); return "