core
core copied to clipboard
Added 'getImageCacheName' hook to allow modification of the cache name.
The 'getImageCacheName' hook allows modification of the image cache name. This could be useful to filter out filenames that might get blocked by Adblockers.
What file names are blocked by ad blockers?
I know that EasyList (German) has at least one rule that blocks everything with advert or advertising in the name which is kind of a problem if you are building a website for a company that sells online ads. And I would not be surprised if names like banner, tracker, etc.. would also be blocked.
But if the original image name does not contain those keywords, the cached version will not either.
I know. But how do I prevent the customer from using certain keywords when uploading files via the contao backend? I may be able to hook into the upload process and throw an error if certain keywords are used. But that would require me to know all the endangered keywords beforehand and it is kind of a pain for the customer not being able to use the actual product names for their product example images.
So my first instinct was to get rid of the original filename part in the cache path. The customer can use whatever filenames he wants. I don't have to maintain some sort of blacklist and Adblock is also happy.
I understand if this is too much of an edge case (happened to me for the first time in many years with the current project). But I thought I might give it a try anyway.
how do I prevent the customer from using certain keywords when uploading files
Have you tried the postUpload hook?
It was more like a rhetorical question ;) The problem is that i would still need to know what keywords to filter and it might confuse the user if he uploads a file "banner-ad-example.jpg" and the file gets renamed to something else. I don't want to restrict the user in his choice of filenames. I'd rather just rewrite the filenames in the frontend.