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

Conversation

timotei-litespeed
Copy link
Contributor

In CDN, at mapping settings if Include Images/CSS/JS is disabled it removes the file types from "Include File Types" setting.
Before:
image
After save:
image

@timotei-litespeed timotei-litespeed marked this pull request as draft January 30, 2025 13:57
@timotei-litespeed timotei-litespeed marked this pull request as ready for review January 30, 2025 20:01
// Remove from MAPPING FILETYPE IMAGES/CSS/JS if settings are disabled
$remove_type = array();
if (empty($data2[$k][self::CDN_MAPPING_INC_IMG])) {
$remove_type = array_merge($remove_type, array('jpg', 'jpeg', 'png', 'gif', 'svg', 'webp', 'avif'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

These types should be always removed, no matter if the option checked or not. Append them dynamically in cdn::init()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the conditions

@Tymotey Tymotey force-pushed the CDN-filetype_remove branch from 9d2f0f8 to 5678ab8 Compare January 30, 2025 21:20
@timotei-litespeed
Copy link
Contributor Author

@hi-hai added the rewrite to happen on content html

@@ -117,6 +117,22 @@ 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 = array('jpg', 'jpeg', 'png', 'gif', 'svg', 'webp', 'avif', 'css', 'js');
Copy link
Collaborator

Choose a reason for hiding this comment

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

give it a filter plz

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added


// Remove from MAPPING FILETYPE extensions for IMAGES, CSS, JS
$remove_type = array('jpg', 'jpeg', 'png', 'gif', 'svg', 'webp', 'avif', 'css', 'js');
$temp = array_filter($v, function ($i_v) use ($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.

just a simple loop to unset it, easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

$leave_value = true;

foreach ($remove_type as $remove) {
if (strpos($i_v, $remove) !== false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not correct. Need to full match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed with above

src/cdn.cls.php Outdated
@@ -209,9 +209,28 @@ private function _finalize()
$this->_replace_inline_css();
}

// Temporary add file types to mapping filetype rewrite
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should append them in init()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved

'.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.

👍

@Tymotey Tymotey force-pushed the CDN-filetype_remove branch from 1bed608 to a692a9e Compare February 4, 2025 23:55
@timotei-litespeed
Copy link
Contributor Author

@hi-hai fixed the file types to include images.
Also removed extra code that I wrote and was not necessary.
Tested .attribute + element.attribute both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants