modxcms / fred

The friendly front-end editor for visual, drag-and-drop content building in MODX CMS
https://fred.modx.com
MIT License
58 stars 25 forks source link

Sanitisation of file names in elFinder #421

Closed lottaar closed 3 years ago

lottaar commented 3 years ago

Not sure if this is a bug or a request, but I'm wondering if there is any way to sanitise file names upon upload? For example, if the client uploads an image called Jättegod smörgås.JPG it should be automatically be renamed jattegod-smorgas.jpg. In MODX I normally use Filesluggy for this, but when using Fred for uploads Filesluggy doesn't seem to work.

matdave commented 3 years ago

elFinder has some built-in plugins, but we currently don't have a straight forward way to access them. I'll take a look at this to think on a good way to tap into it.

matdave commented 3 years ago

@lottaar I've created an example Gist here: https://gist.github.com/matdave/6167ae9d4860139f00837162172c862d

Basically, you can use the plugin event 'FredOnElfinderRoots' to customize elFinder. We've used it to attach unique media sources, but it can also be used to configure/add plugins to your elFinder instance.

lottaar commented 3 years ago

Thanks @matdave for looking into this! Would you mind explaining to a non-programmer where to put the code you linked to, please?

I've tried creating a plugin called elFinderPlugins with the code from your link, and checked FredOnElfinderRoots under system events. Then tried uploading an image called Kerstin Andersson, porträtt.JPG but the name isn't changed.