1) { array_shift($args); return vsprintf($Lang[$code], $args); } else { return $Lang[$code]; } } else { return $code; } } // Trouve la langue function GetLanguage(){ // tableau avec les langues installées $dh = opendir('language'); while ($file = readdir($dh)) { if ($file !== '.' && $file !== '..' && is_dir('language/'.$file)) $languages[] = $file; } closedir($dh); // recherche du paramètre get ou session, ou langue du navigateur if(isset($_GET['Lang'])) $_SESSION['Lang'] = $_GET['Lang']; else if(!isset($_SESSION['Lang']) OR $_SESSION['Lang'] == NULL) $_SESSION['Lang'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2); if(!in_array($_SESSION['Lang'], $languages)) $_SESSION['Lang'] = 'en'; return array('Lang' => $_SESSION['Lang'], 'languages' => $languages); } // Supprime les accents et tous caractères non conforme function delete_special_car($string) { global $renameORNOT; $search = array ('#[éèêë]#','#[ÊËÈÉ]#','#[àâäã]#','#[ÂÄÁÀ]#','#[îïíì]#','#[ÎÏÍÌ]#','#[ûùüúµ]#','#[ÛÙÚÜ]#','#[ôóòõö]#','#[ÓÒÖÔÕ]#', '#[ç]#','#[Ç]#','#[ñ]#','#[Ñ]#','#[ýÿ]#','#[Ý]#','#[ \&\!\?\#\"\(\)\{\}\[\]\=\+\~\%]#','#[^a-zA-Z0-9_\.\-]#'); $replace = array ('e','E','a','A','i','I','u','U','o','O','c','C',',n','N','y','Y','_',''); if ($renameORNOT) { return preg_replace($search, $replace, $string); } else { return str_replace(array('%','$'), '_', $string); } } // Teste si un dossier est vide function is_dir_empty($dir) { $array = scandir($dir); if (count($array) > 2) { return false; } else { return true; } } // Supprime un repertoire non-vide function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object !== '.' && $object !== '..') { if (filetype($dir.'/'.$object) == 'dir') rrmdir($dir.'/'.$object); else unlink($dir.'/'.$object); } } reset($objects); rmdir($dir); } } // Parcours récursivement un dossier function recursive_readdir($dir, $array, $dirs=false) { # si $dirs=true liste les dossiers plutot que les fichiers global ${$array}; // Charge la tableau pour la sortie, déclaré à l'exterieur à cause de l'appel recursif de la fonction $dir = rtrim($dir, '/'); if (is_dir($dir)) { $dh = opendir($dir); } else { exit('Dossier inexistant'); } while (($file = readdir($dh)) !== false ) { if ($file !== '.' && $file !== '..') { $path = $dir.'/'.$file; if (is_dir($path)) { if($dirs) ${$array}[] = $path; recursive_readdir($path, $array, $dirs); } else { if(!$dirs) ${$array}[] = $path; } } } closedir($dh); } // Parse le fichier de configuration function XMLParse($xml) { $content = array(); foreach ($xml as $nom => $elem) { if (trim($elem) == '') { $content[$nom] = XMLParse($elem->children()); } else { $content[$nom] = utf8_encode(utf8_decode($elem)); } } return $content; } // Crée le fichier de configuration function XMLCreate($array, $level) { $content = null; foreach ($array as $nom => $elem) { if (is_array($elem)) { for($i=0;$i<=$level;$i++) $content .= "\t"; $content .= '<'.$nom.'>'."\n"; $content .= XMLCreate($elem, $level+1); for($i=0;$i<=$level;$i++) $content .= "\t"; $content .= ''."\n"; } else { for($i=0;$i<=$level;$i++) $content .= "\t"; $content .= '<'.$nom.'>'.$elem.''."\n"; } } return $content; } // Charge la configuration function load_config() { $config = simplexml_load_file('config.xml'); $config = XMLParse($config); $config = array_settype($config); return $config; } // Convertit les booléens, entiers et flotants d'un tableau de 'string' function array_settype($array) { foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = array_settype($value); } else { if ($value === 'true') { $array[$key] = true; } else if ($value === 'false') { $array[$key] = false; } else if (preg_match('#^([0-9]*)$#', $value)) { settype($array[$key], 'int'); } else if (preg_match('#^([0-9]*)(.|,)([0-9]*)$#', $value)) { settype($array[$key], 'float'); } } } return $array; } // Booléen vers français ou texte function bool_to_string($bool, $just_echo=0) { global $Lang; # $just_echo pour pouvoir afficher un booléen tel quel if (is_bool($bool)) { if ($bool) { if ($just_echo) return 'true'; else return l10n('yes'); } else { if ($just_echo) return 'false'; else return l10n('no'); } } else { return $bool; } } ?>