1) { array_shift($args); return vsprintf($Lang[$code], $args); } else { return $Lang[$code]; } } else { return $code; } } // Retourne la langue de l'utilisateur et les langues installées 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('user_lang' => $_SESSION['Lang'], 'languages' => $languages); } // Supprime tous les caractères speciaux function delete_special_car($string) { global $CONF; $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 ($CONF['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) { $dir = rtrim($dir, '/'); $objects = scandir($dir); foreach ($objects as $object) { if ($object !== '.' && $object !== '..') { $path = $dir.'/'.$object; if (filetype($path) == 'dir') rrmdir($path); else unlink($path); } } 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, '/'); $dh = opendir($dir); 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=0) { $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($file) { $config = simplexml_load_file($file); $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($string, $just_echo=0) { global $Lang; # $just_echo pour pouvoir afficher un booléen tel quel (echo true; n'affiche rien) if (is_bool($string)) { if ($string) { if ($just_echo) return 'true'; else return l10n('yes'); } else { if ($just_echo) return 'false'; else return l10n('no'); } } else { return $string; } } // Converti une chaine de config (param:value;param:value[;]) en tableau associatif function ExplodeString($string, $sep1=';', $sep2=':') { $string = preg_replace('#[;]$#', '', $string); $result = array(); $a = explode($sep1, $string); foreach ($a as $s) { $v = explode($sep2, $s); $result[$v[0]] = $v[1]; } return $result; } // Converti un tableau associatif en chaine de config (param:value;param:value;) function ImplodeArray($array, $sep1=';', $sep2=':') { $result = null; foreach ($array as $key => $value) { $result .= $key.$sep2.$value.$sep1; } return $result; } // Convertit les couleurs 'numériques' et gère les 0 manquants function nice_hex_color($hex) { $hex = strval($hex); for ($i=strlen($hex); $i<6; $i++) { $hex = '0'.$hex; } return $hex; } // Converti une couleur HEX et RGB function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') { $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string if (strlen($hexStr) == 6) { //If a proper hex code, convert using bitwise operation. No overhead... faster $colorVal = hexdec($hexStr); $rgbArray['r'] = 0xFF & ($colorVal >> 0x10); $rgbArray['g'] = 0xFF & ($colorVal >> 0x8); $rgbArray['b'] = 0xFF & $colorVal; } elseif (strlen($hexStr) == 3) { //if shorthand notation, need some string manipulations $rgbArray['r'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2)); $rgbArray['g'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2)); $rgbArray['b'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2)); } else { return false; //Invalid hex color code } return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; // returns the rgb string or the associative array } // Verifie si une chaine est un nombre décimal (plus strict que is_numeric qui fonctionne avec les hexadecimaux) function is_decimal($num) { if(is_numeric($num) === true AND (float)$num == $num) { return true; } else { return false; } } // Charge le fichier de langue d'un plugin function load_plugin_lang($plugin_id) { global $CONF, $Lang; if (file_exists('plugins/'.$plugin_id.'/lang/'.$CONF['user_lang'].'.php')) { include('plugins/'.$plugin_id.'/lang/'.$CONF['user_lang'].'.php'); } else { include('plugins/'.$plugin_id.'/lang/en.php'); } } ?>