Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDN - remove filetypes to replace if setting is disabled #800

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion data/const.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@
"inc_js": ["1"],
"inc_css": ["1"],
"inc_img": ["1"],
"filetype": [".aac\n.css\n.eot\n.gif\n.jpeg\n.jpg\n.js\n.less\n.mp3\n.mp4\n.ogg\n.otf\n.pdf\n.png\n.svg\n.ttf\n.webp\n.woff\n.woff2"]
"filetype": [".aac\n.eot\n.less\n.mp3\n.mp4\n.ogg\n.otf\n.pdf\n.ttf\n.webp\n.woff\n.woff2"]
}
}
14 changes: 14 additions & 0 deletions src/admin-settings.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ public function save($raw_data)
foreach ($data as $k => $v) {
if ($child == self::CDN_MAPPING_FILETYPE) {
$v = Utility::sanitize_lines($v);

// Remove from MAPPING FILETYPE extensions for IMAGES, CSS, JS
$remove_type = apply_filters('litespeed_cdn_save_filetypes_remove', array(
'.jpg',
'.jpeg',
'.png',
'.gif',
'.svg',
'.webp',
'.avif',
'.css',
'.js',
));
$v = array_diff($v, $remove_type);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
if ($child == self::CDN_MAPPING_URL) {
# If not a valid URL, turn off CDN
Expand Down
10 changes: 10 additions & 0 deletions src/cdn.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public function init()
}
}

// Add CSS to rewrite if CDN Mapping setting is enabled
if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS])) {
$this->_cfg_cdn_mapping['.css'] = $this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS];
}

// Add JS to rewrite if CDN Mapping setting is enabled
if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS])) {
$this->_cfg_cdn_mapping['.js'] = $this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS];
}

if (!$this->_cfg_url_ori || !$this->_cfg_cdn_mapping) {
if (!defined(self::BYPASS)) {
define(self::BYPASS, true);
Expand Down