| [7988] | 1 | <?php |
|---|
| 2 | /***************************************\ |
|---|
| 3 | | PHP OPTIMISATEUR | |
|---|
| [7991] | 4 | | Version 1.1 | |
|---|
| [7988] | 5 | \***************************************/ |
|---|
| 6 | |
|---|
| 7 | // Supprime les accents et tous caractères non conforme |
|---|
| 8 | function delete_special_car($string) { |
|---|
| 9 | global $renameORNOT; |
|---|
| 10 | $search = array ('#[éèêë]#','#[ÊËÈÉ]#','#[àâäã]#','#[ÂÄÁÀ]#','#[îïíì]#','#[ÎÏÍÌ]#','#[ûùüú]#','#[ÛÙÚÜ]#','#[ôóòõö]#','#[ÓÒÖÔÕ]#', |
|---|
| 11 | '#[ç]#','#[Ç]#','#[ñ]#','#[Ñ]#','#[ýÿ]#','#[Ý]#','#[ \&\!\#\"\(\)\{\}\'\=\+\~]#','#[^a-zA-Z0-9_\.\-]#'); |
|---|
| 12 | $replace = array ('e','E','a','A','i','I','u','U','o','O','c','C',',n','N','y','Y','_',''); |
|---|
| 13 | |
|---|
| [7991] | 14 | return preg_replace($search, $replace, $string); |
|---|
| [7988] | 15 | } |
|---|
| 16 | |
|---|
| 17 | // Teste si un dossier est vide |
|---|
| 18 | function is_dir_empty($dir) { |
|---|
| 19 | $array = scandir($dir); |
|---|
| 20 | if (count($array) > 2) { |
|---|
| 21 | return false; |
|---|
| 22 | } else { |
|---|
| 23 | return true; |
|---|
| 24 | |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | // Supprime un repertoire non-vide |
|---|
| 29 | function rrmdir($dir) { |
|---|
| 30 | if (is_dir($dir)) { |
|---|
| 31 | $objects = scandir($dir); |
|---|
| 32 | foreach ($objects as $object) { |
|---|
| 33 | if ($object !== '.' && $object !== '..') { |
|---|
| 34 | if (filetype($dir.'/'.$object) == 'dir') rrmdir($dir.'/'.$object); |
|---|
| 35 | else unlink($dir.'/'.$object); |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | reset($objects); |
|---|
| 39 | rmdir($dir); |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | // Parcours récursivement un dossier |
|---|
| 44 | function recursive_readdir($dir, $array, $dirs=false) { |
|---|
| 45 | # si $dirs=true liste les dossiers plutot que les fichiers |
|---|
| 46 | global ${$array}; // Charge la tableau pour la sortie, déclaré à l'exterieur à cause de l'appel recursif de la fonction |
|---|
| [7991] | 47 | $dir = rtrim($dir, '/'); |
|---|
| [7988] | 48 | |
|---|
| 49 | if (is_dir($dir)) { |
|---|
| 50 | $dh = opendir($dir); |
|---|
| 51 | } else { |
|---|
| 52 | exit; |
|---|
| 53 | } |
|---|
| [7991] | 54 | while (($file = readdir($dh)) !== false ) { |
|---|
| [7988] | 55 | if ($file !== '.' && $file !== '..') { |
|---|
| 56 | $path = $dir.'/'.$file; |
|---|
| [7991] | 57 | if (is_dir($path)) { |
|---|
| [7988] | 58 | if($dirs) ${$array}[] = $path; |
|---|
| [7991] | 59 | recursive_readdir($path, $array, $dirs); |
|---|
| 60 | } else { |
|---|
| [7988] | 61 | if(!$dirs) ${$array}[] = $path; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | closedir($dh); |
|---|
| 66 | } |
|---|
| [7991] | 67 | |
|---|
| 68 | // Parse le fichier de configuration |
|---|
| 69 | function XMLParse($xml) { |
|---|
| 70 | $content = array(); |
|---|
| 71 | foreach ($xml as $nom => $elem) { |
|---|
| 72 | if (trim($elem) == '') { |
|---|
| 73 | $content[$nom] = XMLParse($elem->children()); |
|---|
| 74 | } else { |
|---|
| 75 | $content[$nom] = utf8_encode(utf8_decode($elem)); |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | return $content; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | // Crée le fichier de configuration |
|---|
| 82 | function XMLCreate($array, $level) { |
|---|
| 83 | $content = null; |
|---|
| 84 | foreach ($array as $nom => $elem) { |
|---|
| 85 | if (is_array($elem)) { |
|---|
| 86 | for($i=0;$i<=$level;$i++) $content .= "\t"; |
|---|
| 87 | $content .= '<'.$nom.'>'."\n"; |
|---|
| 88 | $content .= XMLCreate($elem, $level+1); |
|---|
| 89 | for($i=0;$i<=$level;$i++) $content .= "\t"; |
|---|
| 90 | $content .= '</'.$nom.'>'."\n"; |
|---|
| 91 | } else { |
|---|
| 92 | for($i=0;$i<=$level;$i++) $content .= "\t"; |
|---|
| 93 | $content .= '<'.$nom.'>'.$elem.'</'.$nom.'>'."\n"; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | return $content; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | // Convertit les booléens, entiers et flotants d'un tableau de 'string' |
|---|
| 100 | function array_settype($array) { |
|---|
| 101 | foreach ($array as $key => $value) { |
|---|
| 102 | if (is_array($value)) { |
|---|
| 103 | $array[$key] = array_settype($value); |
|---|
| 104 | } else { |
|---|
| 105 | if ($value === 'true') { |
|---|
| 106 | $array[$key] = true; |
|---|
| 107 | } else if ($value === 'false') { |
|---|
| 108 | $array[$key] = false; |
|---|
| 109 | } else if (preg_match('#^([0-9]*)$#', $value)) { |
|---|
| 110 | settype($array[$key], 'int'); |
|---|
| 111 | } else if (preg_match('#^([0-9]*)(.|,)([0-9]*)$#', $value)) { |
|---|
| 112 | settype($array[$key], 'float'); |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | return $array; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | // Booléen vers français ou texte |
|---|
| 121 | function bool_to_string($bool, $just_echo=0) { |
|---|
| 122 | # $just_echo pour pouvoir afficher un booléen tel quel |
|---|
| 123 | if (is_bool($bool)) { |
|---|
| 124 | if ($bool) { |
|---|
| 125 | if ($just_echo) return 'true'; |
|---|
| 126 | else return 'oui'; |
|---|
| 127 | } else { |
|---|
| 128 | if ($just_echo) return 'false'; |
|---|
| 129 | else return 'non'; |
|---|
| 130 | } |
|---|
| 131 | } else { |
|---|
| 132 | return $bool; |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| [7988] | 135 | ?> |
|---|