WebPageCache
7 months ago
external
2 months ago
ExcludeJsFromDelay.php
2 years ago
OptimizerBanner.php
11 months ago
OptimizerBase.php
2 years ago
OptimizerCSSMin.php
2 years ago
OptimizerCache.php
1 year ago
OptimizerCacheStructure.php
2 years ago
OptimizerCriticalCss.php
1 year ago
OptimizerElementor.php
2 years ago
OptimizerFonts.php
2 years ago
OptimizerImages.php
1 year ago
OptimizerLogger.php
1 year ago
OptimizerMain.php
2 months ago
OptimizerOnInit.php
11 months ago
OptimizerScripts.php
2 years ago
OptimizerSettings.php
2 months ago
OptimizerStyles.php
2 years ago
OptimizerUrl.php
1 year ago
OptimizerUtils.php
2 months ago
OptimizerWhiteLabel.php
2 years ago
OptimizerUrl.php
798 lines
| 1 | <?php |
| 2 | |
| 3 | namespace TenWebOptimizer; |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | if (!defined('ABSPATH')) { |
| 8 | exit; |
| 9 | } |
| 10 | |
| 11 | class OptimizerUrl |
| 12 | { |
| 13 | public const TWO_FASTCGI_NON_CACHED_URLS = [ |
| 14 | '/wp-admin/', |
| 15 | '/xmlrpc.php', |
| 16 | 'wp-.*.php', |
| 17 | 'feed', |
| 18 | 'index.php', |
| 19 | 'sitemap(_index)?.xml', |
| 20 | '/store.*', |
| 21 | '/cart.*', |
| 22 | '/my-account.*', |
| 23 | '/checkout.*', |
| 24 | '/addons.*', |
| 25 | 'well-known', |
| 26 | 'acme-challenge' |
| 27 | ]; |
| 28 | |
| 29 | /* only for 10web.io, specially for Dianna */ |
| 30 | public const TWO_FASTCGI_CACHED_URLS = [ |
| 31 | 'wordpress-instagram-feed', |
| 32 | 'wordpress-facebook-feed', |
| 33 | ]; |
| 34 | |
| 35 | public const TWO_FASTCGI_NON_CACHED_PAGES_IF_COOKIE_EXISTS = [ |
| 36 | 'comment_author', |
| 37 | 'wordpress_[a-f0-9]+', |
| 38 | 'wordpress_logged_in_', |
| 39 | 'wp-postpass', |
| 40 | 'wordpress_no_cache', |
| 41 | 'woocommerce_cart_hash', |
| 42 | 'fm_cookie_[a-zA-Z0-9]+', |
| 43 | 'woocommerce_items_in_cart', |
| 44 | 'wp_woocommerce_session', |
| 45 | 'woocommerce_recently_viewed', |
| 46 | ]; |
| 47 | |
| 48 | public const EXCLUDED_FROM_FULL_LIST_USER_AGENTS = [ |
| 49 | '^curl', |
| 50 | 'Chrome-Lighthouse' |
| 51 | ]; |
| 52 | |
| 53 | public const TWO_FASTCGI_NON_CACHED_PAGES_IF_USER_AGENT = [ |
| 54 | // Source: https://raw.githubusercontent.com/monperrus/crawler-user-agents/master/crawler-user-agents.json |
| 55 | 'Googlebot\\/', |
| 56 | 'Googlebot-Mobile', |
| 57 | 'Googlebot-Image', |
| 58 | 'Googlebot-News', |
| 59 | 'Googlebot-Video', |
| 60 | 'AdsBot-Google([^-]|$)', |
| 61 | 'AdsBot-Google-Mobile', |
| 62 | 'Feedfetcher-Google', |
| 63 | 'Mediapartners-Google', |
| 64 | 'Mediapartners \\(Googlebot\\)', |
| 65 | 'APIs-Google', |
| 66 | 'bingbot', |
| 67 | 'Slurp', |
| 68 | '[wW]get', |
| 69 | 'LinkedInBot', |
| 70 | 'Python-urllib', |
| 71 | 'python-requests', |
| 72 | 'aiohttp', |
| 73 | 'httpx', |
| 74 | 'libwww-perl', |
| 75 | 'httpunit', |
| 76 | 'nutch', |
| 77 | 'Go-http-client', |
| 78 | 'phpcrawl', |
| 79 | 'msnbot', |
| 80 | 'jyxobot', |
| 81 | 'FAST-WebCrawler', |
| 82 | 'FAST Enterprise Crawler', |
| 83 | 'BIGLOTRON', |
| 84 | 'Teoma', |
| 85 | 'convera', |
| 86 | 'seekbot', |
| 87 | 'Gigabot', |
| 88 | 'Gigablast', |
| 89 | 'exabot', |
| 90 | 'ia_archiver', |
| 91 | 'GingerCrawler', |
| 92 | 'webmon ', |
| 93 | 'HTTrack', |
| 94 | 'grub.org', |
| 95 | 'UsineNouvelleCrawler', |
| 96 | 'antibot', |
| 97 | 'netresearchserver', |
| 98 | 'speedy', |
| 99 | 'fluffy', |
| 100 | 'findlink', |
| 101 | 'msrbot', |
| 102 | 'panscient', |
| 103 | 'yacybot', |
| 104 | 'AISearchBot', |
| 105 | 'ips-agent', |
| 106 | 'tagoobot', |
| 107 | 'MJ12bot', |
| 108 | 'woriobot', |
| 109 | 'yanga', |
| 110 | 'buzzbot', |
| 111 | 'mlbot', |
| 112 | 'YandexBot', |
| 113 | 'YandexImages', |
| 114 | 'YandexAccessibilityBot', |
| 115 | 'YandexMobileBot', |
| 116 | 'YandexMetrika', |
| 117 | 'YandexTurbo', |
| 118 | 'YandexImageResizer', |
| 119 | 'YandexVideo', |
| 120 | 'YandexAdNet', |
| 121 | 'YandexBlogs', |
| 122 | 'YandexCalendar', |
| 123 | 'YandexDirect', |
| 124 | 'YandexFavicons', |
| 125 | 'YaDirectFetcher', |
| 126 | 'YandexForDomain', |
| 127 | 'YandexMarket', |
| 128 | 'YandexMedia', |
| 129 | 'YandexMobileScreenShotBot', |
| 130 | 'YandexNews', |
| 131 | 'YandexOntoDB', |
| 132 | 'YandexPagechecker', |
| 133 | 'YandexPartner', |
| 134 | 'YandexRCA', |
| 135 | 'YandexSearchShop', |
| 136 | 'YandexSitelinks', |
| 137 | 'YandexSpravBot', |
| 138 | 'YandexTracker', |
| 139 | 'YandexVertis', |
| 140 | 'YandexVerticals', |
| 141 | 'YandexWebmaster', |
| 142 | 'YandexScreenshotBot', |
| 143 | 'purebot', |
| 144 | 'Linguee Bot', |
| 145 | 'CyberPatrol', |
| 146 | 'voilabot', |
| 147 | 'Baiduspider', |
| 148 | 'citeseerxbot', |
| 149 | 'spbot', |
| 150 | 'twengabot', |
| 151 | 'postrank', |
| 152 | 'TurnitinBot', |
| 153 | 'scribdbot', |
| 154 | 'page2rss', |
| 155 | 'sitebot', |
| 156 | 'linkdex', |
| 157 | 'Adidxbot', |
| 158 | 'ezooms', |
| 159 | 'dotbot', |
| 160 | 'Mail.RU_Bot', |
| 161 | 'discobot', |
| 162 | 'heritrix', |
| 163 | 'findthatfile', |
| 164 | 'europarchive.org', |
| 165 | 'NerdByNature.Bot', |
| 166 | 'sistrix crawler', |
| 167 | 'Ahrefs(Bot|SiteAudit)', |
| 168 | 'fuelbot', |
| 169 | 'CrunchBot', |
| 170 | 'IndeedBot', |
| 171 | 'mappydata', |
| 172 | 'woobot', |
| 173 | 'ZoominfoBot', |
| 174 | 'PrivacyAwareBot', |
| 175 | 'Multiviewbot', |
| 176 | 'SWIMGBot', |
| 177 | 'Grobbot', |
| 178 | 'eright', |
| 179 | 'Apercite', |
| 180 | 'semanticbot', |
| 181 | 'Aboundex', |
| 182 | 'domaincrawler', |
| 183 | 'wbsearchbot', |
| 184 | 'summify', |
| 185 | 'CCBot', |
| 186 | 'edisterbot', |
| 187 | 'seznambot', |
| 188 | 'ec2linkfinder', |
| 189 | 'gslfbot', |
| 190 | 'aiHitBot', |
| 191 | 'intelium_bot', |
| 192 | 'facebookexternalhit', |
| 193 | 'Yeti', |
| 194 | 'RetrevoPageAnalyzer', |
| 195 | 'lb-spider', |
| 196 | 'Sogou', |
| 197 | 'lssbot', |
| 198 | 'careerbot', |
| 199 | 'wotbox', |
| 200 | 'wocbot', |
| 201 | 'ichiro', |
| 202 | 'DuckDuckBot', |
| 203 | 'lssrocketcrawler', |
| 204 | 'drupact', |
| 205 | 'webcompanycrawler', |
| 206 | 'acoonbot', |
| 207 | 'openindexspider', |
| 208 | 'gnam gnam spider', |
| 209 | 'web-archive-net.com.bot', |
| 210 | 'backlinkcrawler', |
| 211 | 'coccoc', |
| 212 | 'integromedb', |
| 213 | 'content crawler spider', |
| 214 | 'toplistbot', |
| 215 | 'it2media-domain-crawler', |
| 216 | 'ip-web-crawler.com', |
| 217 | 'siteexplorer.info', |
| 218 | 'elisabot', |
| 219 | 'proximic', |
| 220 | 'changedetection', |
| 221 | 'arabot', |
| 222 | 'WeSEE:Search', |
| 223 | 'niki-bot', |
| 224 | 'CrystalSemanticsBot', |
| 225 | 'rogerbot', |
| 226 | '360Spider', |
| 227 | 'psbot', |
| 228 | 'InterfaxScanBot', |
| 229 | 'CC Metadata Scaper', |
| 230 | 'g00g1e.net', |
| 231 | 'GrapeshotCrawler', |
| 232 | 'urlappendbot', |
| 233 | 'brainobot', |
| 234 | 'fr-crawler', |
| 235 | 'binlar', |
| 236 | 'SimpleCrawler', |
| 237 | 'Twitterbot', |
| 238 | 'cXensebot', |
| 239 | 'smtbot', |
| 240 | 'bnf.fr_bot', |
| 241 | 'A6-Indexer', |
| 242 | 'ADmantX', |
| 243 | 'Facebot', |
| 244 | 'OrangeBot\\/', |
| 245 | 'memorybot', |
| 246 | 'AdvBot', |
| 247 | 'MegaIndex', |
| 248 | 'SemanticScholarBot', |
| 249 | 'ltx71', |
| 250 | 'nerdybot', |
| 251 | 'xovibot', |
| 252 | 'BUbiNG', |
| 253 | 'Qwantify', |
| 254 | 'archive.org_bot', |
| 255 | 'Applebot', |
| 256 | 'TweetmemeBot', |
| 257 | 'crawler4j', |
| 258 | 'findxbot', |
| 259 | 'S[eE][mM]rushBot', |
| 260 | 'yoozBot', |
| 261 | 'lipperhey', |
| 262 | 'Y!J', |
| 263 | 'Domain Re-Animator Bot', |
| 264 | 'AddThis', |
| 265 | 'Screaming Frog SEO Spider', |
| 266 | 'MetaURI', |
| 267 | 'Scrapy', |
| 268 | 'Livelap[bB]ot', |
| 269 | 'OpenHoseBot', |
| 270 | 'CapsuleChecker', |
| 271 | 'collection@infegy.com', |
| 272 | 'IstellaBot', |
| 273 | 'DeuSu\\/', |
| 274 | 'betaBot', |
| 275 | 'Cliqzbot\\/', |
| 276 | 'MojeekBot\\/', |
| 277 | 'netEstate NE Crawler', |
| 278 | 'SafeSearch microdata crawler', |
| 279 | 'Gluten Free Crawler\\/', |
| 280 | 'Sonic', |
| 281 | 'Sysomos', |
| 282 | 'Trove', |
| 283 | 'deadlinkchecker', |
| 284 | 'Slack-ImgProxy', |
| 285 | 'Embedly', |
| 286 | 'RankActiveLinkBot', |
| 287 | 'iskanie', |
| 288 | 'SafeDNSBot', |
| 289 | 'SkypeUriPreview', |
| 290 | 'Veoozbot', |
| 291 | 'Slackbot', |
| 292 | 'redditbot', |
| 293 | 'datagnionbot', |
| 294 | 'Google-Adwords-Instant', |
| 295 | 'adbeat_bot', |
| 296 | 'WhatsApp', |
| 297 | 'contxbot', |
| 298 | 'pinterest.com.bot', |
| 299 | 'electricmonk', |
| 300 | 'GarlikCrawler', |
| 301 | 'BingPreview\\/', |
| 302 | 'vebidoobot', |
| 303 | 'FemtosearchBot', |
| 304 | 'Yahoo Link Preview', |
| 305 | 'MetaJobBot', |
| 306 | 'DomainStatsBot', |
| 307 | 'mindUpBot', |
| 308 | 'Daum\\/', |
| 309 | 'Jugendschutzprogramm-Crawler', |
| 310 | 'Xenu Link Sleuth', |
| 311 | 'Pcore-HTTP', |
| 312 | 'moatbot', |
| 313 | 'KosmioBot', |
| 314 | '[pP]ingdom', |
| 315 | 'AppInsights', |
| 316 | 'PhantomJS', |
| 317 | 'Gowikibot', |
| 318 | 'PiplBot', |
| 319 | 'Discordbot', |
| 320 | 'TelegramBot', |
| 321 | 'Jetslide', |
| 322 | 'newsharecounts', |
| 323 | 'James BOT', |
| 324 | 'Bark[rR]owler', |
| 325 | 'TinEye', |
| 326 | 'SocialRankIOBot', |
| 327 | 'trendictionbot', |
| 328 | 'Ocarinabot', |
| 329 | 'epicbot', |
| 330 | 'Primalbot', |
| 331 | 'DuckDuckGo-Favicons-Bot', |
| 332 | 'GnowitNewsbot', |
| 333 | 'Leikibot', |
| 334 | 'LinkArchiver', |
| 335 | 'YaK\\/', |
| 336 | 'PaperLiBot', |
| 337 | 'Digg Deeper', |
| 338 | 'dcrawl', |
| 339 | 'Snacktory', |
| 340 | 'AndersPinkBot', |
| 341 | 'Fyrebot', |
| 342 | 'EveryoneSocialBot', |
| 343 | 'Mediatoolkitbot', |
| 344 | 'Luminator-robots', |
| 345 | 'ExtLinksBot', |
| 346 | 'SurveyBot', |
| 347 | 'NING\\/', |
| 348 | 'okhttp', |
| 349 | 'Nuzzel', |
| 350 | 'omgili', |
| 351 | 'PocketParser', |
| 352 | 'YisouSpider', |
| 353 | 'um-LN', |
| 354 | 'ToutiaoSpider', |
| 355 | 'MuckRack', |
| 356 | "Jamie's Spider", |
| 357 | 'AHC\\/', |
| 358 | 'NetcraftSurveyAgent', |
| 359 | 'Laserlikebot', |
| 360 | '^Apache-HttpClient', |
| 361 | 'AppEngine-Google', |
| 362 | 'Jetty', |
| 363 | 'Upflow', |
| 364 | 'Thinklab', |
| 365 | 'Traackr.com', |
| 366 | 'Twurly', |
| 367 | 'Mastodon', |
| 368 | 'http_get', |
| 369 | 'DnyzBot', |
| 370 | 'botify', |
| 371 | '007ac9 Crawler', |
| 372 | 'BehloolBot', |
| 373 | 'BrandVerity', |
| 374 | 'check_http', |
| 375 | 'BDCbot', |
| 376 | 'ZumBot', |
| 377 | 'EZID', |
| 378 | 'ICC-Crawler', |
| 379 | 'ArchiveBot', |
| 380 | '^LCC ', |
| 381 | 'filterdb.iss.net\\/crawler', |
| 382 | 'BLP_bbot', |
| 383 | 'BomboraBot', |
| 384 | 'Buck\\/', |
| 385 | 'Companybook-Crawler', |
| 386 | 'Genieo', |
| 387 | 'magpie-crawler', |
| 388 | 'MeltwaterNews', |
| 389 | 'Moreover', |
| 390 | 'newspaper\\/', |
| 391 | 'ScoutJet', |
| 392 | '(^| )sentry\\/', |
| 393 | 'StorygizeBot', |
| 394 | 'UptimeRobot', |
| 395 | 'OutclicksBot', |
| 396 | 'seoscanners', |
| 397 | 'Hatena', |
| 398 | 'Google Web Preview', |
| 399 | 'MauiBot', |
| 400 | 'AlphaBot', |
| 401 | 'SBL-BOT', |
| 402 | 'IAS crawler', |
| 403 | 'adscanner', |
| 404 | 'Netvibes', |
| 405 | 'acapbot', |
| 406 | 'Baidu-YunGuanCe', |
| 407 | 'bitlybot', |
| 408 | 'blogmuraBot', |
| 409 | 'Bot.AraTurka.com', |
| 410 | 'bot-pge.chlooe.com', |
| 411 | 'BoxcarBot', |
| 412 | 'BTWebClient', |
| 413 | 'ContextAd Bot', |
| 414 | 'Digincore bot', |
| 415 | 'Disqus', |
| 416 | 'Feedly', |
| 417 | 'Fetch\\/', |
| 418 | 'Fever', |
| 419 | 'Flamingo_SearchEngine', |
| 420 | 'FlipboardProxy', |
| 421 | 'g2reader-bot', |
| 422 | 'G2 Web Services', |
| 423 | 'imrbot', |
| 424 | 'K7MLWCBot', |
| 425 | 'Kemvibot', |
| 426 | 'Landau-Media-Spider', |
| 427 | 'linkapediabot', |
| 428 | 'vkShare', |
| 429 | 'Siteimprove.com', |
| 430 | 'BLEXBot\\/', |
| 431 | 'DareBoost', |
| 432 | 'ZuperlistBot\\/', |
| 433 | 'Miniflux\\/', |
| 434 | 'Feedspot', |
| 435 | 'Diffbot\\/', |
| 436 | 'SEOkicks', |
| 437 | 'tracemyfile', |
| 438 | 'Nimbostratus-Bot', |
| 439 | 'zgrab', |
| 440 | 'PR-CY.RU', |
| 441 | 'AdsTxtCrawler', |
| 442 | 'Datafeedwatch', |
| 443 | 'Zabbix', |
| 444 | 'TangibleeBot', |
| 445 | 'google-xrawler', |
| 446 | 'axios', |
| 447 | 'Amazon CloudFront', |
| 448 | 'Pulsepoint', |
| 449 | 'CloudFlare-AlwaysOnline', |
| 450 | 'Google-Structured-Data-Testing-Tool', |
| 451 | 'WordupInfoSearch', |
| 452 | 'WebDataStats', |
| 453 | 'HttpUrlConnection', |
| 454 | 'Seekport Crawler', |
| 455 | 'ZoomBot', |
| 456 | 'VelenPublicWebCrawler', |
| 457 | 'MoodleBot', |
| 458 | 'jpg-newsbot', |
| 459 | 'outbrain', |
| 460 | 'W3C_Validator', |
| 461 | 'Validator\\.nu', |
| 462 | 'W3C-checklink', |
| 463 | 'W3C-mobileOK', |
| 464 | 'W3C_I18n-Checker', |
| 465 | 'FeedValidator', |
| 466 | 'W3C_CSS_Validator', |
| 467 | 'W3C_Unicorn', |
| 468 | 'Google-PhysicalWeb', |
| 469 | 'Blackboard', |
| 470 | 'ICBot\\/', |
| 471 | 'BazQux', |
| 472 | 'Twingly', |
| 473 | 'Rivva', |
| 474 | 'Experibot', |
| 475 | 'awesomecrawler', |
| 476 | 'Dataprovider.com', |
| 477 | 'GroupHigh\\/', |
| 478 | 'theoldreader.com', |
| 479 | 'AnyEvent', |
| 480 | 'Uptimebot\\.org', |
| 481 | 'Nmap Scripting Engine', |
| 482 | '2ip.ru', |
| 483 | 'Clickagy', |
| 484 | 'Caliperbot', |
| 485 | 'MBCrawler', |
| 486 | 'online-webceo-bot', |
| 487 | 'B2B Bot', |
| 488 | 'AddSearchBot', |
| 489 | 'Google Favicon', |
| 490 | 'HubSpot', |
| 491 | 'HeadlessChrome', |
| 492 | 'CheckMarkNetwork\\/', |
| 493 | 'www\\.uptime\\.com', |
| 494 | 'Streamline3Bot\\/', |
| 495 | 'serpstatbot\\/', |
| 496 | 'MixnodeCache\\/', |
| 497 | 'SimpleScraper', |
| 498 | 'RSSingBot', |
| 499 | 'Jooblebot', |
| 500 | 'fedoraplanet', |
| 501 | 'Friendica', |
| 502 | 'NextCloud', |
| 503 | 'Tiny Tiny RSS', |
| 504 | 'RegionStuttgartBot', |
| 505 | 'Bytespider', |
| 506 | 'Datanyze', |
| 507 | 'Google-Site-Verification', |
| 508 | 'TrendsmapResolver', |
| 509 | 'tweetedtimes', |
| 510 | 'NTENTbot', |
| 511 | 'Gwene', |
| 512 | 'SimplePie', |
| 513 | 'SearchAtlas', |
| 514 | 'Superfeedr', |
| 515 | 'feedbot', |
| 516 | 'UT-Dorkbot', |
| 517 | 'Amazonbot', |
| 518 | 'SerendeputyBot', |
| 519 | 'Eyeotabot', |
| 520 | 'officestorebot', |
| 521 | 'Neticle Crawler', |
| 522 | 'SurdotlyBot', |
| 523 | 'LinkisBot', |
| 524 | 'AwarioSmartBot', |
| 525 | 'AwarioRssBot', |
| 526 | 'RyteBot', |
| 527 | 'FreeWebMonitoring SiteChecker', |
| 528 | 'AspiegelBot', |
| 529 | 'NAVER Blog Rssbot', |
| 530 | 'zenback bot', |
| 531 | 'SentiBot', |
| 532 | 'Domains Project\\/', |
| 533 | 'Pandalytics', |
| 534 | 'VKRobot', |
| 535 | 'bidswitchbot', |
| 536 | 'tigerbot', |
| 537 | 'NIXStatsbot', |
| 538 | 'Atom Feed Robot', |
| 539 | 'Curebot', |
| 540 | 'PagePeeker\\/', |
| 541 | 'Vigil\\/', |
| 542 | 'rssbot\\/', |
| 543 | 'startmebot\\/', |
| 544 | 'JobboerseBot', |
| 545 | 'seewithkids', |
| 546 | 'NINJA bot', |
| 547 | 'Cutbot', |
| 548 | 'BublupBot', |
| 549 | 'BrandONbot', |
| 550 | 'RidderBot', |
| 551 | 'Taboolabot', |
| 552 | 'Dubbotbot', |
| 553 | 'FindITAnswersbot', |
| 554 | 'infoobot', |
| 555 | 'Refindbot', |
| 556 | 'BlogTraffic\\/\\d\\.\\d+ Feed-Fetcher', |
| 557 | 'SeobilityBot', |
| 558 | 'Cincraw', |
| 559 | 'Dragonbot', |
| 560 | 'VoluumDSP-content-bot', |
| 561 | 'FreshRSS', |
| 562 | 'BitBot', |
| 563 | '^PHP-Curl-Class', |
| 564 | 'Google-Certificates-Bridge', |
| 565 | 'centurybot', |
| 566 | 'Viber', |
| 567 | 'e\\.ventures Investment Crawler', |
| 568 | 'evc-batch', |
| 569 | 'PetalBot', |
| 570 | 'virustotal', |
| 571 | 'S[eE][mM]rushBot', |
| 572 | |
| 573 | // Source: https://www.keycdn.com/blog/web-crawlers |
| 574 | 'Sogou Pic Spider', 'Sogou head spider', 'Sogou web spider', 'Sogou Orion spider', 'Sogou-Test-Spider', |
| 575 | 'Konqueror', |
| 576 | 'coccocbot', |
| 577 | ]; |
| 578 | |
| 579 | /** |
| 580 | * Returns whether page should be optimized or not based on page url and fastcgi excluded pages merged with option |
| 581 | * |
| 582 | * @return bool |
| 583 | */ |
| 584 | public static function urlIsOptimizable($url = null, $is_admin = false) |
| 585 | { |
| 586 | $is_optimizable = self::urlIsOptimizableWithReason($url, $is_admin); |
| 587 | |
| 588 | if (is_bool($is_optimizable)) { |
| 589 | return $is_optimizable; |
| 590 | } |
| 591 | |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Returns whether page should be optimized or not based on page url and fastcgi excluded pages merged with option |
| 597 | * Returns boolean or string. If returns string, it contains the reason why page should not be optimized |
| 598 | * |
| 599 | * @return bool|string |
| 600 | * */ |
| 601 | public static function urlIsOptimizableWithReason($url = null, $is_admin = false) |
| 602 | { |
| 603 | if (self::has_donotoptimizepage()) { |
| 604 | return 'DONOTOPTIMIZEPAGE is set'; |
| 605 | } |
| 606 | |
| 607 | $server_data = $_SERVER; |
| 608 | |
| 609 | if (isset($url)) { |
| 610 | $url_data = wp_parse_url($url); |
| 611 | unset($server_data['REQUEST_URI'], $server_data['HTTP_HOST']); |
| 612 | |
| 613 | if (isset($url_data['path'])) { |
| 614 | $server_data['REQUEST_URI'] = $url_data['path']; |
| 615 | } |
| 616 | |
| 617 | if (isset($url_data['host'])) { |
| 618 | $server_data['HTTP_HOST'] = $url_data['host']; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | global $TwoSettings; |
| 623 | $optimizerDisabledPages = array_filter( |
| 624 | array_map('trim', explode(',', $TwoSettings->get_settings('two_disabled_speed_optimizer_pages', ''))) |
| 625 | ); |
| 626 | |
| 627 | if (!isset($server_data['REQUEST_URI']) || preg_match('~\.xml|\.txt|wp-login\.php|wp-register\.php~', $server_data[ 'REQUEST_URI' ])) { |
| 628 | return 'Not allowed REQUEST_URI'; |
| 629 | } |
| 630 | |
| 631 | if (!empty($optimizerDisabledPages)) { |
| 632 | //check excluded pages |
| 633 | foreach ($optimizerDisabledPages as $optimizerDisabledPage) { |
| 634 | if (preg_match('~' . $optimizerDisabledPage . '~', $server_data['REQUEST_URI'])) { |
| 635 | return 'Page optimization is disabled from TWO options'; |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | $no_optimize_pages_list = $TwoSettings->get_settings('no_optimize_pages', []); |
| 641 | |
| 642 | if (is_array($no_optimize_pages_list)) { |
| 643 | foreach ($no_optimize_pages_list as $no_optimize_page) { |
| 644 | $no_optimize_page = str_replace('/', '', $no_optimize_page); |
| 645 | |
| 646 | if ($no_optimize_page == str_replace('/', '', (isset($server_data['HTTPS']) && $server_data['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $server_data['HTTP_HOST'] . $server_data['REQUEST_URI'])) { |
| 647 | return 'Page is in no_optimize_pages list'; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | // fix for first request from crawler |
| 653 | if ((isset($_GET['two_preview']) && $_GET['two_preview'] === '1')) { // phpcs:ignore |
| 654 | return true; |
| 655 | } |
| 656 | |
| 657 | // Disable cache for bots. |
| 658 | if (isset($server_data['HTTP_USER_AGENT']) && preg_match('#(' . implode('|', self::get_non_cached_user_agents()) . ')#', $server_data['HTTP_USER_AGENT'])) { |
| 659 | // DO NOT CACHE BECAUSE OF HIGH DATABASE LOAD, but serve optimized |
| 660 | global $disableTwoCacheStructureCache; |
| 661 | $disableTwoCacheStructureCache = true; |
| 662 | } |
| 663 | |
| 664 | if (!empty($TwoSettings->get_settings('two_all_pages_are_optimizable', ''))) { |
| 665 | return true; |
| 666 | } |
| 667 | |
| 668 | //check explicitly cached pages |
| 669 | foreach (self::TWO_FASTCGI_CACHED_URLS as $cachedUrl) { |
| 670 | if (preg_match('~' . $cachedUrl . '~', $server_data['REQUEST_URI'])) { |
| 671 | return true; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | //check non-cached pages |
| 676 | $two_non_optimizable_speed_optimizer_pages = array_filter( |
| 677 | array_map('trim', explode(',', $TwoSettings->get_settings('two_non_optimizable_speed_optimizer_pages', ''))) |
| 678 | ); |
| 679 | |
| 680 | foreach ($two_non_optimizable_speed_optimizer_pages as $nonCachedUrl) { |
| 681 | if (!isset($server_data['REQUEST_URI']) || preg_match('~' . $nonCachedUrl . '~', $server_data['REQUEST_URI'])) { |
| 682 | return 'URL is in two_non_optimizable_speed_optimizer_pages list'; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | if (isset($url) || $is_admin) { |
| 687 | return true; |
| 688 | } |
| 689 | |
| 690 | //check non-cached cookies |
| 691 | if ('on' !== $TwoSettings->get_settings('two_page_cache_user')) { |
| 692 | foreach (self::TWO_FASTCGI_NON_CACHED_PAGES_IF_COOKIE_EXISTS as $nonCachedCookieName) { |
| 693 | if (!empty(OptimizerUtils::preg_grep_keys('~' . $nonCachedCookieName . '~', $_COOKIE))) { // phpcs:ignore |
| 694 | return 'Page has not allowed cookie: ' . $nonCachedCookieName; |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | return true; |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Tell if the constant DONOTOPTIMIZEPAGE is set and not overridden. |
| 704 | * When defined, the page must not be cached. |
| 705 | * |
| 706 | * @return bool |
| 707 | */ |
| 708 | public static function has_donotoptimizepage() |
| 709 | { |
| 710 | if (! defined('DONOTOPTIMIZEPAGE') || ! DONOTOPTIMIZEPAGE) { |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * At this point the constant DONOTOPTIMIZEPAGE is set to true. |
| 716 | * This filter allows to force the page optimization. |
| 717 | * It prevents conflict with some plugins like Thrive Leads. |
| 718 | * |
| 719 | * @since 2.5 |
| 720 | * |
| 721 | * @param bool $override_donotoptimizepage True will force the page to be cached. |
| 722 | */ |
| 723 | return ! apply_filters('two_override_donotoptimizepage', false); |
| 724 | } |
| 725 | |
| 726 | public static function isUrlOptimizableByContent($content) |
| 727 | { |
| 728 | if (preg_match('#<script[^>]*src=("|\')([^>]*cdn.ampproject.org[^>]*)("|\')[^>]*>#Usmi', $content)) { |
| 729 | return 'Do not optimize AMP pages'; |
| 730 | } |
| 731 | $current_url = get_permalink(); |
| 732 | $current_scheme = wp_parse_url($current_url); |
| 733 | |
| 734 | if (isset($current_scheme['scheme']) && !in_array($current_scheme['scheme'], ['http', 'https'])) { |
| 735 | return 'Do not optimize ' . $current_scheme . ' pages'; |
| 736 | } |
| 737 | |
| 738 | if (preg_grep('#^Content-Type:(?! *text\/html;)#is', headers_list())) { |
| 739 | return 'Do not optimize non html pages'; |
| 740 | } |
| 741 | |
| 742 | return true; |
| 743 | } |
| 744 | |
| 745 | public static function isCriticalSavedInSettings($page_id) |
| 746 | { |
| 747 | return 'front_page' == $page_id || false !== strpos($page_id, 'term_') || false !== strpos($page_id, 'user_'); |
| 748 | } |
| 749 | |
| 750 | public static function getPageModeByID($page_id) |
| 751 | { |
| 752 | $id = $page_id; |
| 753 | $type = 'page_'; |
| 754 | $page_mode = false; |
| 755 | |
| 756 | if (false !== strpos($page_id, 'term_')) { |
| 757 | $id = (int) ltrim($page_id, 'term_'); |
| 758 | $type = 'term_'; |
| 759 | } |
| 760 | |
| 761 | if (false !== strpos($page_id, 'user_')) { |
| 762 | $id = (int) ltrim($page_id, 'user_'); |
| 763 | $type = 'user_'; |
| 764 | } |
| 765 | |
| 766 | if ('term_' == $type) { |
| 767 | $page_mode = get_term_meta($id, 'two_mode', true); |
| 768 | } elseif ('user_' == $type) { |
| 769 | $page_mode = get_user_meta($id, 'two_mode', true); |
| 770 | } else { |
| 771 | $page_mode = get_post_meta($id, 'two_mode', true); |
| 772 | } |
| 773 | |
| 774 | return [ 'id' => $id, 'type' => $type, 'page_mode' => $page_mode ]; |
| 775 | } |
| 776 | |
| 777 | public static function get_non_cached_user_agents() |
| 778 | { |
| 779 | try { |
| 780 | $crawlerUserAgentsFile = __DIR__ . '/../vendor/monperrus/crawler-user-agents/crawler-user-agents.json'; |
| 781 | |
| 782 | if (is_readable($crawlerUserAgentsFile)) { |
| 783 | $allAgents = json_decode(file_get_contents($crawlerUserAgentsFile), true); //phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown |
| 784 | $allAgents = array_column($allAgents, 'pattern'); |
| 785 | $allAgents = array_diff($allAgents, self::EXCLUDED_FROM_FULL_LIST_USER_AGENTS); |
| 786 | |
| 787 | if (!empty($allAgents)) { |
| 788 | return $allAgents; |
| 789 | } |
| 790 | } |
| 791 | } catch (Exception $exception) { |
| 792 | return self::TWO_FASTCGI_NON_CACHED_PAGES_IF_USER_AGENT; |
| 793 | } |
| 794 | |
| 795 | return self::TWO_FASTCGI_NON_CACHED_PAGES_IF_USER_AGENT; |
| 796 | } |
| 797 | } |
| 798 |