Giter Site home page Giter Site logo

beapi / bea-sanitize-filename Goto Github PK

View Code? Open in Web Editor NEW
17.0 7.0 4.0 838 KB

Remove all punctuation and accents from the filename of uploaded files

Home Page: https://wordpress.org/plugins/bea-sanitize-filename

License: Other

PHP 76.52% Shell 23.48%
wordpress wordpress-plugin uploads sanitize wordpress-mu-plugin

bea-sanitize-filename's Introduction

Be API Github Banner

BEA - Sanitize Filename

This plugin will remove all punctuation and accents from the filename of uploaded files, which is pretty handy. You could then ask "Why it's not already into core?". This is make WordPress core !

How ?

Requirements

  • No requirements

Installation

As we assume this is a must have plugin, it's recommended to use at it as mu-plugin. As it is a folder, you must use a MU Loader : https://github.com/BeAPI/wp-mu-loader.

WordPress

  • Download and copy the plugin folder into your must-use plugins folder.
  • Nothing more, this plugin is ready to use !
  • Add repository source : { "type": "git", "url": "https://github.com/BeAPI/bea-sanitize-filename" }.
  • Include "bea/sanitize-filename": "dev-master" in your composer file for last master's commits or a tag released.
  • Nothing more, this plugin is ready to use !

What ?

Features

  • All accented letters will be converted to same letters without accent
  • Special characters will be deleted
  • Underscores will be replaced by hyphens

Compatibility for MAC owners

On MAC, you can also create an accented character with the combination of ` and the wanted letter. This has the effect to create a character with a special filename system encoding format which is not sanitized. An issue is open about this.

Contributing

Testing

Introduction

The tests are based on WP-Browser.

You have WPUnit and Acceptance tests.

Installation

  1. Install Lando
  2. From command line into the project folder execute ./bin/lando-start.sh
  3. From command line into the project folder execute lando composer install

The local url will be https://beasanitizefilename.lndo.site and credentials will be

  • user : admin
  • password : admin

Tools

To test the code, just launch :

  • For Wpunit tests and desktop : lando test-local
  • For desktop mobile : lando test-mobile

If you need to test the code on BrowserStack, you need to define two environments variables :

  • BROWSERSTACK_USERNAME_REAL : the usernmae of your browserStack account
  • BROWSERSTACK_KEY : the key of your browserStack account

/!\ Do not commit theses credentials /!\

Customization

Need to customize the environment variables ? every codeception file can be overrided bit by bit by creating a new file without the .dist. So to customize the .env file you'l need to :

  • Create a codeception.yml file
  • Put into the file :
params:
- .env.local
  • Create a .env.local file and change the desired environment variables like BROWSERSTACK_KEY

Changelog

Please refer to the contributing guidelines to increase the chance of your pull request to be merged and/or receive the best support for your issue.

Issues & features request / proposal

If you identify any errors or have an idea for improving the plugin, feel free to open an issue. Please provide as much info as needed in order to help us resolving / approve your request.

Who ?

Created by Be API, the French WordPress leader agency since 2009. Based in Paris, we are more than 30 people and always hiring some fun and talented guys. So we will be pleased to work with you.

This plugin is only maintained by the Be API team, which means we do not guarantee some free support. Consider reporting an issue and be patient.

If you really like what we do or want to thank us for our quick work, feel free to donate as much as you want / can, even 1€ is a great gift for buying cofee :)

License

BEA - Sanitize Filename is licensed under the GPLv3 or later.

bea-sanitize-filename's People

Contributors

herewithme avatar maximeculea avatar petitphp avatar rahe avatar romain-d avatar seomix avatar stephane-gillot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bea-sanitize-filename's Issues

PHP Notice : undefined offset

Version information

  • Plugin version : 1.0.2
  • PHP : 7.0.10
  • WordPress : 4.9.2
  • Wampserver : 3.0.9
  • Chrome with Livereload & Visual Studio Code
  • Tea & chocolate

Steps to reproduce

On localhost dev (wamp + livereload) : each time I modify code I got this debug message in a div where 3 lasts tweets are displayed by Rotating Tweets plugin :

[26-Jan-2018 13:54:25 UTC] PHP 1. {main}() Z:\www\website\wp-admin\admin-ajax.php:0 [26-Jan-2018 13:54:25 UTC] PHP 2. do_action() Z:\www\website\wp-admin\admin-ajax.php:97 [26-Jan-2018 13:54:25 UTC] PHP 3. WP_Hook->do_action() Z:\www\website\wp-includes\plugin.php:453 [26-Jan-2018 13:54:25 UTC] PHP 4. WP_Hook->apply_filters() Z:\www\website\wp-includes\class-wp-hook.php:310 [26-Jan-2018 13:54:25 UTC] PHP 5. wpc_get_my_weather() Z:\www\website\wp-includes\class-wp-hook.php:286 [26-Jan-2018 13:59:56 UTC] PHP Notice: Undefined offset: 0 in Z:\www\website\wp-content\mu-plugins\sanitize-filename\bea-sanitize-filename.php on line 48

One CTRL F5 make it disappear. until next code modification.

Not very important cause Debug not displayed on production but ... in case of... :)

Thanks !

Add a tool to punctually check all existing files

When adding this MU, all old files are will not be sanitized.
So a tool should be present to force file sanitizing.

It could be using WP_Cli ?

It should do :

  • Sanitize all files
  • Changes all file's calls (srdb?)

Thanks to Samy Rabih for the report.

Accented characters are completely removed

Version information

  • Plugin version : 2.0.6
  • PHP : 7.2
  • WordPress : 4.9.8

Steps to reproduce

  1. Upload a file with a name which contains an accented character like noël.jpg

What was expected

The file renamed to noel.jpg

What happened instead

The file renamed to nol.jpg

The problem is appeared on v2.0.6 and I think it is comes from 54a0944 commit.

WP 6.0

Test and release new version compatible with WP 6.0 if needed

Add also mac filename to be sanitized

As mac has his own filename system encoding format, they are not sanitized. So we must :

  • Find out what is the list of mac encoded common special chars
  • Apply them on the same sanitized hook

Image for retina display: @2x , @3x

Hello,

For the needs of a project we have to upload images 3 times: once for standard screens and once for retina screens (x2 and x3).

There is a specific naming for the retina screens (https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/image-size-and-resolution/):

The problem is that the last 2 images are renamed: my-image2x.jpg and [email protected].
In all other cases it is relevant, but would it be possible to put an exception when the name of the image ends with @2x and @3x please ?

Thanks in advance.

Check more french caracters

array('/À/','/Á/','/Â/','/Ã/','/Ä/','/Å/','/Ç/','/È/','/É/','/Ê/','/Ë/','/Ì/','/Í/','/Î/','/Ï/','/Ò/','/Ó/','/Ô/','/Õ/','/Ö/','/Ù/','/Ú/','/Û/','/Ü/','/Ý/','/à/','/á/','/â/','/ã/','/ä/','/å/','/ç/','/è/','/é/','/ê/','/ë/','/ì/','/í/','/î/','/ï/','/ð/','/ò/','/ó/','/ô/','/õ/','/ö/','/ù/','/ú/','/û/','/ü/','/ý/','/ÿ/', '/©/');

Undefined offset: 0 on line 41

Notice: Undefined offset: 0 in /home/sites/dev.example.com/wp-content/mu-plugins/bea-sanitize-filename.php on line 41

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.