PATH:
home
/
thecwrif
/
public_html
/
wp-content
/
plugins
/
litespeed-cache
/
src
<?php // phpcs:ignoreFile /** * The localization class. * * @since 3.3 */ namespace LiteSpeed; defined('WPINC') || exit(); class Localization extends Base { const LOG_TAG = '🛍️'; /** * Init optimizer * * @since 3.0 * @access protected */ public function init() { add_filter('litespeed_buffer_finalize', array( $this, 'finalize' ), 23); // After page optm } /** * Localize Resources * * @since 3.3 */ public function serve_static( $uri ) { $url = base64_decode($uri); if (!$this->conf(self::O_OPTM_LOCALIZE)) { // wp_redirect( $url ); exit('Not supported'); } if (substr($url, -3) !== '.js') { // wp_redirect( $url ); // exit( 'Not supported ' . $uri ); } $match = false; $domains = $this->conf(self::O_OPTM_LOCALIZE_DOMAINS); foreach ($domains as $v) { if (!$v || strpos($v, '#') === 0) { continue; } $type = 'js'; $domain = $v; // Try to parse space split value if (strpos($v, ' ')) { $v = explode(' ', $v); if (!empty($v[1])) { $type = strtolower($v[0]); $domain = $v[1]; } } if (strpos($domain, 'https://') !== 0) { continue; } if ($type != 'js') { continue; } // if ( strpos( $url, $domain ) !== 0 ) { if ($url != $domain) { continue; } $match = true; break; } if (!$match) { // wp_redirect( $url ); exit('Not supported2'); } header('Content-Type: application/javascript'); // Generate $this->_maybe_mk_cache_folder('localres'); $file = $this->_realpath($url); self::debug('localize [url] ' . $url); $response = wp_safe_remote_get($url, array( 'timeout' => 180, 'stream' => true, 'filename' => $file, )); // Parse response data if (is_wp_error($response)) { $error_message = $response->get_error_message(); file_exists($file) && unlink($file); self::debug('failed to get: ' . $error_message); wp_redirect($url); exit(); } $url = $this->_rewrite($url); wp_redirect($url); exit(); } /** * Get the final URL of local avatar * * @since 4.5 */ private function _rewrite( $url ) { return LITESPEED_STATIC_URL . '/localres/' . $this->_filepath($url); } /** * Generate realpath of the cache file * * @since 4.5 * @access private */ private function _realpath( $url ) { return LITESPEED_STATIC_DIR . '/localres/' . $this->_filepath($url); } /** * Get filepath * * @since 4.5 */ private function _filepath( $url ) { $filename = md5($url) . '.js'; if (is_multisite()) { $filename = get_current_blog_id() . '/' . $filename; } return $filename; } /** * Localize JS/Fonts * * @since 3.3 * @access public */ public function finalize( $content ) { if (is_admin()) { return $content; } if (!$this->conf(self::O_OPTM_LOCALIZE)) { return $content; } $domains = $this->conf(self::O_OPTM_LOCALIZE_DOMAINS); if (!$domains) { return $content; } foreach ($domains as $v) { if (!$v || strpos($v, '#') === 0) { continue; } $type = 'js'; $domain = $v; // Try to parse space split value if (strpos($v, ' ')) { $v = explode(' ', $v); if (!empty($v[1])) { $type = strtolower($v[0]); $domain = $v[1]; } } if (strpos($domain, 'https://') !== 0) { continue; } if ($type != 'js') { continue; } $content = str_replace($domain, LITESPEED_STATIC_URL . '/localres/' . base64_encode($domain), $content); } return $content; } }
[-] import.cls.php
[edit]
[-] doc.cls.php
[edit]
[-] control.cls.php
[edit]
[-] object-cache.cls.php
[edit]
[-] vary.cls.php
[edit]
[-] crawler.cls.php
[edit]
[-] error.cls.php
[edit]
[-] db-optm.cls.php
[edit]
[-] activation.cls.php
[edit]
[-] gui.cls.php
[edit]
[-] task.cls.php
[edit]
[-] optimizer.cls.php
[edit]
[-] purge.cls.php
[edit]
[-] data.cls.php
[edit]
[-] optimize.cls.php
[edit]
[-] base.cls.php
[edit]
[-] rest.cls.php
[edit]
[-] crawler-map.cls.php
[edit]
[-] avatar.cls.php
[edit]
[+]
cdn
[-] core.cls.php
[edit]
[-] root.cls.php
[edit]
[+]
data_structure
[-] admin.cls.php
[edit]
[-] css.cls.php
[edit]
[-] vpi.cls.php
[edit]
[+]
..
[-] router.cls.php
[edit]
[-] health.cls.php
[edit]
[-] img-optm.cls.php
[edit]
[-] media.cls.php
[edit]
[-] api.cls.php
[edit]
[-] import.preset.cls.php
[edit]
[-] htaccess.cls.php
[edit]
[-] admin-settings.cls.php
[edit]
[-] tag.cls.php
[edit]
[-] file.cls.php
[edit]
[-] admin-display.cls.php
[edit]
[-] object-cache-wp.cls.php
[edit]
[-] cdn.cls.php
[edit]
[-] localization.cls.php
[edit]
[-] cloud.cls.php
[edit]
[-] esi.cls.php
[edit]
[-] placeholder.cls.php
[edit]
[-] data.upgrade.func.php
[edit]
[-] lang.cls.php
[edit]
[-] utility.cls.php
[edit]
[-] conf.cls.php
[edit]
[-] metabox.cls.php
[edit]
[-] ucss.cls.php
[edit]
[-] tool.cls.php
[edit]
[-] report.cls.php
[edit]
[-] debug2.cls.php
[edit]
[-] object.lib.php
[edit]
[-] str.cls.php
[edit]