dudaster / ele-custom-skin

Create a skin for Elementor Pro Post and Post Archive widgets using Elementor templates
GNU General Public License v3.0
59 stars 10 forks source link

AJAX loads do improper URL encoding of characters in filenames #895

Open magestyx opened 1 year ago

magestyx commented 1 year ago

Hi, Dudaster. We have an issue on a site we manage that we purchased ECS Pro for and tracked it down specifically to the AJAX loading of posts with special characters in their associated filenames. (We've installed a plugin to remove all special characters from new uploads, but hundreds of old posts still have them.)

Here's an example page: https://culturaldaily.com/author/elisa_leonelli/ Scroll down and the initially-loaded featured images in the grid are fine, but once you AJAX-load in more, many images are missing. The author uploaded many of her featured images with a copyright symbol in the filename (ugh - right?). Wordpress' media library and most places on the site URL encode images like: https://culturaldaily.com/wp-content/uploads/2021/03/Aretha-Queen-of-Soul-**%C2%A9**-Richard-DuCree-National-Geographic-cropped.jpg Which is ugly, but correct (the copyright is between Soul and Richard). However, when the posts are loaded via AJAX, instead of URL encoding, they're being HTML encoded like ASCII: https://culturaldaily.com/wp-content/uploads/2020/11/Jeff-Bridges-**©**-Elisa-Leonelli-1986-scaled.jpg

How can we fix this? I've looked through these forums and see there's a ECS_do_action that can be triggered to run other JS after a different plugin does some kind of AJAX. But it seems what we're needing, short of a plugin-itself-fix, is some way that ECS will trigger some custom JS upon its own AJAX and we can do a search and replace for such characters. A PHP fix in the plugin would no doubt be better, though.

Thanks,

Magestyx

magestyx commented 1 year ago

Actually, I realized after I posted that the ECS_do_action will help here - code is below and it does now load these missing images. However, it'd be great to have the URLencoding method fixed, otherwise we'd have to do one of these search/replaces for every special character that could be used.

function ECS_correct_urlencoding(args){ jQuery(".elementor-section").each(function(){ var oldUrl = jQuery(this).css("background-image"); // Get current url var newUrl = oldUrl.replace("©", "%C2%A9"); // Create new url jQuery(this).css("background-image", newUrl); // Set value }); }

jQuery( document ).ready(function() { ECS_add_action("ajax", function(args){ECS_correct_urlencoding(args)}); });

magestyx commented 1 year ago

Note that in the code I just posted, github is encoding the copyright symbol. In the raw code it's the standard code like below with no spaces: & copy ;