Use php-unidecode instead of incomplete without_accent() function

This commit is contained in:
Benjamin Renard 2021-07-28 16:12:01 +02:00
parent 47a1d09e54
commit ec452a1ff4
5 changed files with 42 additions and 29 deletions

View file

@ -1,6 +1,7 @@
{
"require": {
"envms/fluentpdo": "^1.1",
"pear/console_table": "^1.3"
"pear/console_table": "^1.3",
"brenard/php-unidecode": "dev-master"
}
}

38
composer.lock generated
View file

@ -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"
}

View file

@ -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;
}

View file

@ -1,5 +1,7 @@
<?php
use Unidecode\Unidecode;
try {
$pdo = new PDO($db_dsn, $db_user, $db_pwd, $db_options);
$pdo -> 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

View file

@ -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
*/