From ec452a1ff469ea20df60dc3be58f43ad23d99399 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 28 Jul 2021 16:12:01 +0200 Subject: [PATCH] Use php-unidecode instead of incomplete without_accent() function --- composer.json | 3 ++- composer.lock | 38 +++++++++++++++++++++++++++++++++++--- includes/cli.php | 4 ++-- includes/db.php | 4 +++- includes/functions.php | 22 ---------------------- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index e3156e7..4855452 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "require": { "envms/fluentpdo": "^1.1", - "pear/console_table": "^1.3" + "pear/console_table": "^1.3", + "brenard/php-unidecode": "dev-master" } } diff --git a/composer.lock b/composer.lock index 4890fd6..581c9d3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,37 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d36f1a4ac9401421d8e903d01224c8f5", + "content-hash": "d1f16b984c121a9716a4827bce42ea09", "packages": [ + { + "name": "brenard/php-unidecode", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://gitlab.easter-eggs.com/brenard/php-unidecode.git", + "reference": "55f352a0ca3bf6057aa11f44804406ed38f19157" + }, + "default-branch": true, + "type": "library", + "autoload": { + "files": [ + "Unidecode/Unidecode.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0+" + ], + "authors": [ + { + "name": "Benjamin Renard", + "homepage": "https://gitlab.easter-eggs.com/brenard" + } + ], + "description": "Transliterate Unicode text into plain 7-bit ASCII.", + "homepage": "https://gitlab.easter-eggs.com/brenard/php-unidecode", + "time": "2021-07-27T10:40:43+00:00" + }, { "name": "envms/fluentpdo", "version": "v1.1.3", @@ -111,9 +140,12 @@ "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "brenard/php-unidecode": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "2.0.0" } diff --git a/includes/cli.php b/includes/cli.php index 5ea3877..729b948 100644 --- a/includes/cli.php +++ b/includes/cli.php @@ -4,12 +4,12 @@ $cli_commands=array(); function add_cli_command($command, $handler, $short_desc, $usage_args=false, $long_desc=false, $override=false) { global $cli_commands; if (array_key_exists($command, $cli_commands) && !$override) { - logging('ERROR', "The CLI command '$command' already exists."); + logging('ERROR', sprintf(_("The CLI command '%s' already exists.", $command))); return False; } if (!is_callable($handler)) { - logging('ERROR', "The CLI command '$command' handler is not callable !"); + logging('ERROR', sprintf(_("The CLI command '%s' handler is not callable !"), $command)); return False; } diff --git a/includes/db.php b/includes/db.php index dea0c39..1bbc7eb 100644 --- a/includes/db.php +++ b/includes/db.php @@ -1,5 +1,7 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -235,7 +237,7 @@ function search_items($params) { // Text pattern foreach (array('name', 'description') as $field) { if ($is_pgsql) { - $word = without_accents($word); + $word = Unidecode::unidecode($word); $patterns_word["unaccent($field) ILIKE ?"] = "%$word%"; } else diff --git a/includes/functions.php b/includes/functions.php index dc2b26e..d4e5a06 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -245,28 +245,6 @@ function check_is_empty($val) { } } -/** - * Supprime les accents d'une chaine - * - * @param[in] $string La chaine originale - * - * @retval string La chaine sans les accents - */ -function withoutAccents($string){ - $replaceAccent = Array( - "à" => "a", "á" => "a", "â" => "a", "ã" => "a", "ä" => "a", "ç" => "c", - "è" => "e", "é" => "e", "ê" => "e", "ë" => "e", "ì" => "i", "í" => "i", - "î" => "i", "ï" => "i", "ñ" => "n", "ò" => "o", "ó" => "o", "ô" => "o", - "õ" => "o", "ö" => "o", "ù" => "u", "ú" => "u", "û" => "u", "ü" => "u", - "ý" => "y", "ÿ" => "y", "À" => "A", "Á" => "A", "Â" => "A", "Ã" => "A", - "Ä" => "A", "Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E", "Ë" => "E", - "Ì" => "I", "Í" => "I", "Î" => "I", "Ï" => "I", "Ñ" => "N", "Ò" => "O", - "Ó" => "O", "Ô" => "O", "Õ" => "O", "Ö" => "O", "Ù" => "U", "Ú" => "U", - "Û" => "U", "Ü" => "U", "Ý" => "Y" - ); - return strtr($string, $replaceAccent); -} - /* * Generic file/directory helpers */