Move cleanchar librairie avec compatibilité autoloading
This commit is contained in:
parent
2c4a3c0c87
commit
7516f12a57
@ -170,9 +170,8 @@ class RechercheController extends Zend_Controller_Action
|
||||
|
||||
} else {
|
||||
|
||||
require_once 'i18n/cleanchar.php';
|
||||
//Suppression des caractères accentués
|
||||
$txt = cleanstring($params['formA']['txt']);
|
||||
$txt = Scores_Locale_String::cleanstring($params['formA']['txt']);
|
||||
//Remplacement du caractère § par ~
|
||||
$txt = str_replace('$', '~', $txt);
|
||||
// Recherche siren tenant compte des anomalies d'OCR
|
||||
@ -423,14 +422,12 @@ class RechercheController extends Zend_Controller_Action
|
||||
//Criteres recherche entreprise
|
||||
if ( $type=='ent' ) {
|
||||
|
||||
require_once 'i18n/cleanchar.php';
|
||||
|
||||
// Type de recherche = entreprises
|
||||
$telFax = trim(preg_replace('/[^0-9]/', '', $params['telFax']));
|
||||
$naf = trim(preg_replace('/[^0-9A-Z]/i', '', $params['naf']));
|
||||
|
||||
// Traitement des données formulaire
|
||||
$raisonSociale = cleanutf8($params['raisonSociale']);
|
||||
$raisonSociale = Scores_Locale_String::cleanutf8($params['raisonSociale']);
|
||||
$raisonSociale = str_replace(array('(',')', '/'), array('', '', ' '), $raisonSociale);
|
||||
|
||||
$numVoie = preg_replace('/[^0-9]/', '', $params['numero']);
|
||||
@ -438,10 +435,10 @@ class RechercheController extends Zend_Controller_Action
|
||||
$numVoie = '';
|
||||
}
|
||||
|
||||
$libVoie = cleanutf8($params['voie']);
|
||||
$libVoie = Scores_Locale_String::cleanutf8($params['voie']);
|
||||
$libVoie = str_replace(array('(',')', '/'), array('', '', ' '), $libVoie);
|
||||
|
||||
$cpVille = cleanutf8($params['cpVille']);
|
||||
$cpVille = Scores_Locale_String::cleanutf8($params['cpVille']);
|
||||
$cpVille = str_replace(array('(',')', '/'), array('', '', ' '), $cpVille);
|
||||
|
||||
|
||||
@ -1108,8 +1105,6 @@ class RechercheController extends Zend_Controller_Action
|
||||
//Criteres recherche entreprise
|
||||
if ($type=='ent'){
|
||||
|
||||
require_once 'i18n/cleanchar.php';
|
||||
|
||||
// Type de recherche = entreprises
|
||||
$telFax = trim(preg_replace('/[^0-9]/', '', $params['telFax']));
|
||||
$naf = trim(preg_replace('/[^0-9A-Z]/i', '', $params['naf']));
|
||||
@ -1123,8 +1118,8 @@ class RechercheController extends Zend_Controller_Action
|
||||
die('Numéro de voie incorrecte !');
|
||||
}
|
||||
|
||||
$libVoie = cleanutf8($params['voie']);
|
||||
$cpVille = cleanutf8($params['cpVille']);
|
||||
$libVoie = Scores_Locale_String::cleanutf8($params['voie']);
|
||||
$cpVille = Scores_Locale_String::cleanutf8($params['cpVille']);
|
||||
|
||||
if (preg_match("/^([0-9]{2,5})([\D]*)/i", $cpVille, $matches)) {
|
||||
$cp = trim($matches[1]);
|
||||
|
87
library/Scores/Locale/String.php
Normal file
87
library/Scores/Locale/String.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Miscellaneous functions to clean string.
|
||||
*/
|
||||
class Scores_Locale_String
|
||||
{
|
||||
/**
|
||||
* Clean up a string value.
|
||||
*
|
||||
* Resulting string contains only alphanumerics and separators.
|
||||
*
|
||||
* @param $string
|
||||
* A string to clean.
|
||||
* @param $clean_slash
|
||||
* Whether to clean slashes from the given string.
|
||||
* @return
|
||||
* The cleaned string.
|
||||
*/
|
||||
public static function cleanstring($string)
|
||||
{
|
||||
$transliterate = TRUE;
|
||||
$reduce_ascii = FALSE;
|
||||
$output = $string;
|
||||
|
||||
// Remove accents and transliterate
|
||||
if ($transliterate) {
|
||||
static $i18n_loaded = false;
|
||||
static $translations = array();
|
||||
if (!$i18n_loaded) {
|
||||
$path = realpath(dirname(__FILE__));
|
||||
if (is_file($path .'/i18n-ascii.txt')) {
|
||||
$translations = parse_ini_file($path .'/String/i18n-ascii.txt');
|
||||
}
|
||||
$i18n_loaded = true;
|
||||
}
|
||||
|
||||
$output = strtr($output, $translations);
|
||||
}
|
||||
|
||||
// Reduce to the subset of ASCII96 letters and numbers
|
||||
if ($reduce_ascii) {
|
||||
$pattern = '/[^a-zA-Z0-9\/]+/ ';
|
||||
$output = preg_replace($pattern, $separator, $output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function cleanutf8($string)
|
||||
{
|
||||
$transliterate = TRUE;
|
||||
$output = $string;
|
||||
|
||||
// Remove accents and transliterate
|
||||
if ($transliterate) {
|
||||
static $i18n_loaded = false;
|
||||
static $translations = array();
|
||||
if (!$i18n_loaded) {
|
||||
$path = realpath(dirname(__FILE__));
|
||||
if (is_file($path .'/i18n-ascii.txt')) {
|
||||
$translations = parse_ini_file($path .'/String/i18n-ascii.txt');
|
||||
}
|
||||
$i18n_loaded = true;
|
||||
}
|
||||
|
||||
$output = strtr($output, $translations);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Fixes the encoding to uf8
|
||||
public static function fixEncoding($in_str)
|
||||
{
|
||||
$cur_encoding = mb_detect_encoding($in_str) ;
|
||||
if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
|
||||
return $in_str;
|
||||
else
|
||||
return utf8_encode($in_str);
|
||||
} // fixEncoding
|
||||
|
||||
public static function cleanstring_deep($value)
|
||||
{
|
||||
$value = is_array($value) ?
|
||||
array_map('self::cleanstring_deep', $value) :
|
||||
cleanstring($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@
|
||||
Ù = "U"
|
||||
Ú = "U"
|
||||
Û = "U"
|
||||
Ü = "U"
|
||||
Ü = "Ue"
|
||||
Ū = "U"
|
||||
Ů = "U"
|
||||
Ű = "U"
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Miscellaneous functions to clean string.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Clean up a string value.
|
||||
*
|
||||
* Resulting string contains only alphanumerics and separators.
|
||||
*
|
||||
* @param $string
|
||||
* A string to clean.
|
||||
* @param $clean_slash
|
||||
* Whether to clean slashes from the given string.
|
||||
* @return
|
||||
* The cleaned string.
|
||||
*/
|
||||
function cleanstring($string) {
|
||||
$transliterate = TRUE;
|
||||
$reduce_ascii = FALSE;
|
||||
$output = $string;
|
||||
|
||||
// Remove accents and transliterate
|
||||
if ($transliterate) {
|
||||
static $i18n_loaded = false;
|
||||
static $translations = array();
|
||||
if (!$i18n_loaded) {
|
||||
$path = realpath(dirname(__FILE__));
|
||||
if (is_file($path .'/i18n-ascii.txt')) {
|
||||
$translations = parse_ini_file($path .'/i18n-ascii.txt');
|
||||
}
|
||||
$i18n_loaded = true;
|
||||
}
|
||||
|
||||
$output = strtr($output, $translations);
|
||||
}
|
||||
|
||||
// Reduce to the subset of ASCII96 letters and numbers
|
||||
if ($reduce_ascii) {
|
||||
$pattern = '/[^a-zA-Z0-9\/]+/ ';
|
||||
$output = preg_replace($pattern, $separator, $output);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function cleanutf8($string) {
|
||||
$transliterate = TRUE;
|
||||
$output = $string;
|
||||
|
||||
// Remove accents and transliterate
|
||||
if ($transliterate) {
|
||||
static $i18n_loaded = false;
|
||||
static $translations = array();
|
||||
if (!$i18n_loaded) {
|
||||
$path = realpath(dirname(__FILE__));
|
||||
if (is_file($path .'/i18n-ascii.txt')) {
|
||||
$translations = parse_ini_file($path .'/i18n-ascii.txt');
|
||||
}
|
||||
$i18n_loaded = true;
|
||||
}
|
||||
|
||||
$output = strtr($output, $translations);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Fixes the encoding to uf8
|
||||
function fixEncoding($in_str)
|
||||
{
|
||||
$cur_encoding = mb_detect_encoding($in_str) ;
|
||||
if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
|
||||
return $in_str;
|
||||
else
|
||||
return utf8_encode($in_str);
|
||||
} // fixEncoding
|
||||
|
||||
|
||||
function cleanstring_deep($value)
|
||||
{
|
||||
$value = is_array($value) ?
|
||||
array_map('cleanstring_deep', $value) :
|
||||
cleanstring($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user