@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/boutons'); |
@@ -39,33 +39,33 @@ discard block |
||
| 39 | 39 | * contexte |
| 40 | 40 | **/ |
| 41 | 41 | function definir_barre_contexte($contexte = null) { |
| 42 | - if (is_null($contexte)) { |
|
| 43 | - $contexte = $_GET; |
|
| 44 | - } elseif (is_string($contexte)) { |
|
| 45 | - $contexte = unserialize($contexte); |
|
| 46 | - } |
|
| 47 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 48 | - if (!function_exists('trouver_objet_exec')) { |
|
| 49 | - include_spip('inc/pipelines_ecrire'); |
|
| 50 | - } |
|
| 51 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 52 | - $_id = $e['id_table_objet']; |
|
| 53 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 54 | - $table = $e['table_objet_sql']; |
|
| 55 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 56 | - if (isset($row['id_rubrique'])) { |
|
| 57 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 58 | - if (isset($row['id_secteur'])) { |
|
| 59 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 60 | - } |
|
| 61 | - } elseif (isset($row['id_groupe'])) { |
|
| 62 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 63 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - return $contexte; |
|
| 42 | + if (is_null($contexte)) { |
|
| 43 | + $contexte = $_GET; |
|
| 44 | + } elseif (is_string($contexte)) { |
|
| 45 | + $contexte = unserialize($contexte); |
|
| 46 | + } |
|
| 47 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 48 | + if (!function_exists('trouver_objet_exec')) { |
|
| 49 | + include_spip('inc/pipelines_ecrire'); |
|
| 50 | + } |
|
| 51 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 52 | + $_id = $e['id_table_objet']; |
|
| 53 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 54 | + $table = $e['table_objet_sql']; |
|
| 55 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 56 | + if (isset($row['id_rubrique'])) { |
|
| 57 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 58 | + if (isset($row['id_secteur'])) { |
|
| 59 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 60 | + } |
|
| 61 | + } elseif (isset($row['id_groupe'])) { |
|
| 62 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 63 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + return $contexte; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -81,89 +81,89 @@ discard block |
||
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | 83 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 84 | - include_spip('inc/autoriser'); |
|
| 85 | - $boutons_admin = []; |
|
| 84 | + include_spip('inc/autoriser'); |
|
| 85 | + $boutons_admin = []; |
|
| 86 | 86 | |
| 87 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 88 | - $liste_boutons = []; |
|
| 87 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 88 | + $liste_boutons = []; |
|
| 89 | 89 | |
| 90 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 91 | - if ( |
|
| 92 | - function_exists('boutons_plugins') |
|
| 93 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 94 | - ) { |
|
| 95 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 96 | - } |
|
| 90 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 91 | + if ( |
|
| 92 | + function_exists('boutons_plugins') |
|
| 93 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 94 | + ) { |
|
| 95 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - foreach ($liste_boutons as $id => $infos) { |
|
| 99 | - $parent = ''; |
|
| 100 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 101 | - if ( |
|
| 102 | - !isset($infos['parent']) |
|
| 103 | - or !($parent = $infos['parent']) |
|
| 104 | - or !$autorise |
|
| 105 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 106 | - ) { |
|
| 107 | - if ( |
|
| 108 | - $parent |
|
| 109 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 110 | - and isset($boutons_admin[$parent]) |
|
| 111 | - ) { |
|
| 112 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 113 | - if ($position < 0) { |
|
| 114 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 115 | - } |
|
| 116 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 117 | - + [ |
|
| 118 | - $id => new Bouton( |
|
| 119 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 120 | - $infos['titre'], // titre |
|
| 121 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 122 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 123 | - ) |
|
| 124 | - ] |
|
| 125 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 126 | - } |
|
| 127 | - if ( |
|
| 128 | - !$parent |
|
| 129 | - // provisoire, eviter les vieux boutons |
|
| 130 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 131 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 132 | - ) { |
|
| 133 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 134 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 135 | - + [ |
|
| 136 | - $id => new Bouton( |
|
| 137 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 138 | - $infos['titre'], // titre |
|
| 139 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 140 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 141 | - ) |
|
| 142 | - ] |
|
| 143 | - + array_slice($boutons_admin, $position, 100); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 98 | + foreach ($liste_boutons as $id => $infos) { |
|
| 99 | + $parent = ''; |
|
| 100 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 101 | + if ( |
|
| 102 | + !isset($infos['parent']) |
|
| 103 | + or !($parent = $infos['parent']) |
|
| 104 | + or !$autorise |
|
| 105 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 106 | + ) { |
|
| 107 | + if ( |
|
| 108 | + $parent |
|
| 109 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 110 | + and isset($boutons_admin[$parent]) |
|
| 111 | + ) { |
|
| 112 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 113 | + if ($position < 0) { |
|
| 114 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 115 | + } |
|
| 116 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 117 | + + [ |
|
| 118 | + $id => new Bouton( |
|
| 119 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 120 | + $infos['titre'], // titre |
|
| 121 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 122 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 123 | + ) |
|
| 124 | + ] |
|
| 125 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 126 | + } |
|
| 127 | + if ( |
|
| 128 | + !$parent |
|
| 129 | + // provisoire, eviter les vieux boutons |
|
| 130 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 131 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 132 | + ) { |
|
| 133 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 134 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 135 | + + [ |
|
| 136 | + $id => new Bouton( |
|
| 137 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 138 | + $infos['titre'], // titre |
|
| 139 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 140 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 141 | + ) |
|
| 142 | + ] |
|
| 143 | + + array_slice($boutons_admin, $position, 100); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 148 | 148 | |
| 149 | - // définir les favoris et positions d’origine |
|
| 150 | - if ($boutons_admin) { |
|
| 151 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 152 | - $i = 1; |
|
| 153 | - foreach ($boutons_admin as $key => $menu) { |
|
| 154 | - $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 155 | - $menu->position = $i++; |
|
| 156 | - if ($menu->sousmenu) { |
|
| 157 | - $j = 1; |
|
| 158 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 159 | - $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 160 | - $bouton->position = $j++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 149 | + // définir les favoris et positions d’origine |
|
| 150 | + if ($boutons_admin) { |
|
| 151 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 152 | + $i = 1; |
|
| 153 | + foreach ($boutons_admin as $key => $menu) { |
|
| 154 | + $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 155 | + $menu->position = $i++; |
|
| 156 | + if ($menu->sousmenu) { |
|
| 157 | + $j = 1; |
|
| 158 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 159 | + $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 160 | + $bouton->position = $j++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return $boutons_admin; |
|
| 166 | + return $boutons_admin; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -175,22 +175,22 @@ discard block |
||
| 175 | 175 | * @return Bouton[] |
| 176 | 176 | */ |
| 177 | 177 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 178 | - foreach ($menus as $menu) { |
|
| 179 | - if ($menu->sousmenu) { |
|
| 180 | - $libelles = $isfavoris = $favoris = []; |
|
| 181 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 182 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 183 | - $isfavoris[$key] = (bool) $item->favori; |
|
| 184 | - $favoris[$key] = $item->favori; |
|
| 185 | - } |
|
| 186 | - if ($avec_favoris) { |
|
| 187 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | - } else { |
|
| 189 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - return $menus; |
|
| 178 | + foreach ($menus as $menu) { |
|
| 179 | + if ($menu->sousmenu) { |
|
| 180 | + $libelles = $isfavoris = $favoris = []; |
|
| 181 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 182 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 183 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 184 | + $favoris[$key] = $item->favori; |
|
| 185 | + } |
|
| 186 | + if ($avec_favoris) { |
|
| 187 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | + } else { |
|
| 189 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + return $menus; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return Bouton[] |
| 202 | 202 | */ |
| 203 | 203 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 204 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 204 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
@@ -214,23 +214,23 @@ discard block |
||
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | 216 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 217 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 218 | - $url = generer_url_ecrire($url, $args, true); |
|
| 219 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 220 | - // &truc=@machin@ |
|
| 221 | - // @machin@ etant remplace par _request('machin') |
|
| 222 | - $url = str_replace('&', '&', $url); |
|
| 223 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 224 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 225 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | - } |
|
| 227 | - $val = _request($matches[2], $contexte); |
|
| 228 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 229 | - } |
|
| 230 | - $url = str_replace('&', '&', $url); |
|
| 231 | - } |
|
| 217 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 218 | + $url = generer_url_ecrire($url, $args, true); |
|
| 219 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 220 | + // &truc=@machin@ |
|
| 221 | + // @machin@ etant remplace par _request('machin') |
|
| 222 | + $url = str_replace('&', '&', $url); |
|
| 223 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 224 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 225 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | + } |
|
| 227 | + $val = _request($matches[2], $contexte); |
|
| 228 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 229 | + } |
|
| 230 | + $url = str_replace('&', '&', $url); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - return $url; |
|
| 233 | + return $url; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * Code HTML du bandeau |
| 241 | 241 | */ |
| 242 | 242 | function inc_bandeau_dist() { |
| 243 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 243 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | 251 | function obtenir_menus_favoris() { |
| 252 | - if ( |
|
| 253 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 256 | - ) { |
|
| 257 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 258 | - } |
|
| 259 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 260 | - return $definir_menus_favoris(); |
|
| 252 | + if ( |
|
| 253 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 256 | + ) { |
|
| 257 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 258 | + } |
|
| 259 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 260 | + return $definir_menus_favoris(); |
|
| 261 | 261 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -40,20 +40,20 @@ discard block |
||
| 40 | 40 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 41 | 41 | */ |
| 42 | 42 | function find_langs_in_path($file, $dirname = 'lang') { |
| 43 | - static $dirs = []; |
|
| 44 | - $liste = []; |
|
| 45 | - foreach (creer_chemin() as $dir) { |
|
| 46 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 47 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 48 | - } |
|
| 49 | - if ($dirs[$a]) { |
|
| 50 | - if (is_readable($a .= $file)) { |
|
| 51 | - $liste[] = $a; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 43 | + static $dirs = []; |
|
| 44 | + $liste = []; |
|
| 45 | + foreach (creer_chemin() as $dir) { |
|
| 46 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 47 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 48 | + } |
|
| 49 | + if ($dirs[$a]) { |
|
| 50 | + if (is_readable($a .= $file)) { |
|
| 51 | + $liste[] = $a; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return array_reverse($liste); |
|
| 56 | + return array_reverse($liste); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -68,23 +68,23 @@ discard block |
||
| 68 | 68 | * Liste des fichiers touvés pour ce module et cette langue. |
| 69 | 69 | **/ |
| 70 | 70 | function chercher_module_lang($module, $lang = '') { |
| 71 | - if ($lang) { |
|
| 72 | - $lang = '_' . $lang; |
|
| 73 | - } |
|
| 71 | + if ($lang) { |
|
| 72 | + $lang = '_' . $lang; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 76 | - if ( |
|
| 77 | - $f = ($module == 'local' |
|
| 78 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 80 | - ) { |
|
| 81 | - return is_array($f) ? $f : [$f]; |
|
| 82 | - } |
|
| 75 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 76 | + if ( |
|
| 77 | + $f = ($module == 'local' |
|
| 78 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 80 | + ) { |
|
| 81 | + return is_array($f) ? $f : [$f]; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 85 | - return (($module == 'local') or strpos($module, '/')) |
|
| 86 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 87 | - : false; |
|
| 84 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 85 | + return (($module == 'local') or strpos($module, '/')) |
|
| 86 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 87 | + : false; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -106,33 +106,33 @@ discard block |
||
| 106 | 106 | * @return void |
| 107 | 107 | **/ |
| 108 | 108 | function charger_langue($lang, $module = 'spip') { |
| 109 | - static $langs = []; |
|
| 110 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 111 | - if (!isset($langs[$lang])) { |
|
| 112 | - $langs[$lang] = []; |
|
| 113 | - if ($lang) { |
|
| 114 | - $langs[$lang][] = $lang; |
|
| 115 | - if (strpos($lang, '_') !== false) { |
|
| 116 | - $l = explode('_', $lang); |
|
| 117 | - $langs[$lang][] = reset($l); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 121 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 122 | - } |
|
| 123 | - foreach ($langs[$lang] as $l) { |
|
| 124 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 125 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 126 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 127 | - surcharger_langue($fichiers_lang); |
|
| 128 | - if ($l !== $lang) { |
|
| 129 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 130 | - } |
|
| 131 | - $GLOBALS['lang_' . $var] = $l; |
|
| 132 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 109 | + static $langs = []; |
|
| 110 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 111 | + if (!isset($langs[$lang])) { |
|
| 112 | + $langs[$lang] = []; |
|
| 113 | + if ($lang) { |
|
| 114 | + $langs[$lang][] = $lang; |
|
| 115 | + if (strpos($lang, '_') !== false) { |
|
| 116 | + $l = explode('_', $lang); |
|
| 117 | + $langs[$lang][] = reset($l); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 121 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 122 | + } |
|
| 123 | + foreach ($langs[$lang] as $l) { |
|
| 124 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 125 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 126 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 127 | + surcharger_langue($fichiers_lang); |
|
| 128 | + if ($l !== $lang) { |
|
| 129 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 130 | + } |
|
| 131 | + $GLOBALS['lang_' . $var] = $l; |
|
| 132 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -145,21 +145,21 @@ discard block |
||
| 145 | 145 | * @return array<string, string> |
| 146 | 146 | */ |
| 147 | 147 | function lire_fichier_langue(string $fichier): array { |
| 148 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 149 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 150 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 151 | - $idx_lang = include $fichier; |
|
| 152 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 153 | - if (!is_array($idx_lang)) { |
|
| 154 | - if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 155 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 156 | - } else { |
|
| 157 | - $idx_lang = []; |
|
| 158 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 159 | - } |
|
| 160 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 161 | - } |
|
| 162 | - return $idx_lang; |
|
| 148 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 149 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 150 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 151 | + $idx_lang = include $fichier; |
|
| 152 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 153 | + if (!is_array($idx_lang)) { |
|
| 154 | + if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 155 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 156 | + } else { |
|
| 157 | + $idx_lang = []; |
|
| 158 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 159 | + } |
|
| 160 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 161 | + } |
|
| 162 | + return $idx_lang; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -179,29 +179,29 @@ discard block |
||
| 179 | 179 | * Liste des chemins de fichiers de langue à surcharger. |
| 180 | 180 | **/ |
| 181 | 181 | function surcharger_langue($fichiers) { |
| 182 | - static $surcharges = []; |
|
| 183 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 184 | - return; |
|
| 185 | - } |
|
| 182 | + static $surcharges = []; |
|
| 183 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - if (!is_array($fichiers)) { |
|
| 188 | - $fichiers = [$fichiers]; |
|
| 189 | - } |
|
| 190 | - if (!count($fichiers)) { |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - foreach ($fichiers as $fichier) { |
|
| 194 | - if (!isset($surcharges[$fichier])) { |
|
| 195 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 196 | - } |
|
| 197 | - if (is_array($surcharges[$fichier])) { |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 199 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 200 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 201 | - $surcharges[$fichier] |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 187 | + if (!is_array($fichiers)) { |
|
| 188 | + $fichiers = [$fichiers]; |
|
| 189 | + } |
|
| 190 | + if (!count($fichiers)) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + foreach ($fichiers as $fichier) { |
|
| 194 | + if (!isset($surcharges[$fichier])) { |
|
| 195 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 196 | + } |
|
| 197 | + if (is_array($surcharges[$fichier])) { |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 199 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 200 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 201 | + $surcharges[$fichier] |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -242,99 +242,99 @@ discard block |
||
| 242 | 242 | * - Description : traduction et description (texte, module, langue) |
| 243 | 243 | **/ |
| 244 | 244 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 245 | - static $deja_vu = []; |
|
| 246 | - static $local = []; |
|
| 245 | + static $deja_vu = []; |
|
| 246 | + static $local = []; |
|
| 247 | 247 | |
| 248 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 249 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 250 | - } |
|
| 248 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 249 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 253 | - if (strpos($ori, ':')) { |
|
| 254 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 255 | - $modules = explode('|', $modules); |
|
| 256 | - $ori_complet = $ori; |
|
| 257 | - } else { |
|
| 258 | - $modules = ['spip', 'ecrire']; |
|
| 259 | - $code = $ori; |
|
| 260 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 261 | - } |
|
| 252 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 253 | + if (strpos($ori, ':')) { |
|
| 254 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 255 | + $modules = explode('|', $modules); |
|
| 256 | + $ori_complet = $ori; |
|
| 257 | + } else { |
|
| 258 | + $modules = ['spip', 'ecrire']; |
|
| 259 | + $code = $ori; |
|
| 260 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - $desc = new Description(); |
|
| 263 | + $desc = new Description(); |
|
| 264 | 264 | |
| 265 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 266 | - foreach ($modules as $module) { |
|
| 267 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 265 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 266 | + foreach ($modules as $module) { |
|
| 267 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 268 | 268 | |
| 269 | - if (empty($GLOBALS[$var])) { |
|
| 270 | - charger_langue($lang, $module); |
|
| 271 | - // surcharges persos -- on cherche |
|
| 272 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 273 | - if (!isset($local['local_' . $lang])) { |
|
| 274 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 275 | - $GLOBALS['idx_lang'] = $var; |
|
| 276 | - // ... (lang/)local_xx.php |
|
| 277 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 278 | - } |
|
| 279 | - if ($local['local_' . $lang]) { |
|
| 280 | - surcharger_langue($local['local_' . $lang]); |
|
| 281 | - } |
|
| 282 | - // ... puis (lang/)local.php |
|
| 283 | - if (!isset($local['local'])) { |
|
| 284 | - $local['local'] = chercher_module_lang('local'); |
|
| 285 | - } |
|
| 286 | - if ($local['local']) { |
|
| 287 | - surcharger_langue($local['local']); |
|
| 288 | - } |
|
| 289 | - } |
|
| 269 | + if (empty($GLOBALS[$var])) { |
|
| 270 | + charger_langue($lang, $module); |
|
| 271 | + // surcharges persos -- on cherche |
|
| 272 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 273 | + if (!isset($local['local_' . $lang])) { |
|
| 274 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 275 | + $GLOBALS['idx_lang'] = $var; |
|
| 276 | + // ... (lang/)local_xx.php |
|
| 277 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 278 | + } |
|
| 279 | + if ($local['local_' . $lang]) { |
|
| 280 | + surcharger_langue($local['local_' . $lang]); |
|
| 281 | + } |
|
| 282 | + // ... puis (lang/)local.php |
|
| 283 | + if (!isset($local['local'])) { |
|
| 284 | + $local['local'] = chercher_module_lang('local'); |
|
| 285 | + } |
|
| 286 | + if ($local['local']) { |
|
| 287 | + surcharger_langue($local['local']); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - if (isset($GLOBALS[$var][$code])) { |
|
| 292 | - $desc->code = $code; |
|
| 293 | - $desc->module = $module; |
|
| 294 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 295 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 296 | - break; |
|
| 297 | - } |
|
| 298 | - } |
|
| 291 | + if (isset($GLOBALS[$var][$code])) { |
|
| 292 | + $desc->code = $code; |
|
| 293 | + $desc->module = $module; |
|
| 294 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 295 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 296 | + break; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - if (!$desc->corrections) { |
|
| 301 | - $desc->corrections = true; |
|
| 302 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 303 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 304 | - if ( |
|
| 305 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 306 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 307 | - ) { |
|
| 308 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 309 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 310 | - } else { |
|
| 311 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 312 | - } |
|
| 313 | - } |
|
| 300 | + if (!$desc->corrections) { |
|
| 301 | + $desc->corrections = true; |
|
| 302 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 303 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 304 | + if ( |
|
| 305 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 306 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 307 | + ) { |
|
| 308 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 309 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 310 | + } else { |
|
| 311 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 316 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 317 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 318 | - } |
|
| 315 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 316 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 317 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 321 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 322 | - if ( |
|
| 323 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 324 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 325 | - ) { |
|
| 326 | - include_spip('inc/charsets'); |
|
| 327 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 328 | - } |
|
| 329 | - } |
|
| 320 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 321 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 322 | + if ( |
|
| 323 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 324 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 325 | + ) { |
|
| 326 | + include_spip('inc/charsets'); |
|
| 327 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - if (_request('var_mode') == 'traduction') { |
|
| 332 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 333 | - } else { |
|
| 334 | - $deja_vu[$lang][$ori] = $desc; |
|
| 335 | - } |
|
| 331 | + if (_request('var_mode') == 'traduction') { |
|
| 332 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 333 | + } else { |
|
| 334 | + $deja_vu[$lang][$ori] = $desc; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - return $raw ? $desc : $desc->texte; |
|
| 337 | + return $raw ? $desc : $desc->texte; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -346,23 +346,23 @@ discard block |
||
| 346 | 346 | * @return Description |
| 347 | 347 | */ |
| 348 | 348 | function definir_details_traduction($desc, $modules) { |
| 349 | - if (!$desc->mode and $desc->texte) { |
|
| 350 | - // ne pas modifier 2 fois l'affichage |
|
| 351 | - $desc->mode = 'traduction'; |
|
| 352 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | - $desc->texte = '<span ' |
|
| 354 | - . 'lang=' . $desc->langue |
|
| 355 | - . ' class=' . $classe |
|
| 356 | - . ' data-module=' . $desc->module |
|
| 357 | - . ' data-code=' . $desc->code |
|
| 358 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 359 | - . $desc->texte |
|
| 360 | - . '</span>'; |
|
| 361 | - $desc->texte = str_replace( |
|
| 362 | - ["$desc->module:", "$desc->module|"], |
|
| 363 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 364 | - $desc->texte |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - return $desc; |
|
| 349 | + if (!$desc->mode and $desc->texte) { |
|
| 350 | + // ne pas modifier 2 fois l'affichage |
|
| 351 | + $desc->mode = 'traduction'; |
|
| 352 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | + $desc->texte = '<span ' |
|
| 354 | + . 'lang=' . $desc->langue |
|
| 355 | + . ' class=' . $classe |
|
| 356 | + . ' data-module=' . $desc->module |
|
| 357 | + . ' data-code=' . $desc->code |
|
| 358 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 359 | + . $desc->texte |
|
| 360 | + . '</span>'; |
|
| 361 | + $desc->texte = str_replace( |
|
| 362 | + ["$desc->module:", "$desc->module|"], |
|
| 363 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 364 | + $desc->texte |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + return $desc; |
|
| 368 | 368 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext'); |
@@ -35,198 +35,198 @@ discard block |
||
| 35 | 35 | * @return array Couples (type d'objet => Couples (champ => score)) |
| 36 | 36 | */ |
| 37 | 37 | function liste_des_champs() { |
| 38 | - static $liste = null; |
|
| 39 | - if (is_null($liste)) { |
|
| 40 | - $liste = []; |
|
| 41 | - // recuperer les tables_objets_sql declarees |
|
| 42 | - include_spip('base/objets'); |
|
| 43 | - $tables_objets = lister_tables_objets_sql(); |
|
| 44 | - foreach ($tables_objets as $t => $infos) { |
|
| 45 | - if ($infos['rechercher_champs']) { |
|
| 46 | - $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - // puis passer dans le pipeline |
|
| 50 | - $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $liste; |
|
| 38 | + static $liste = null; |
|
| 39 | + if (is_null($liste)) { |
|
| 40 | + $liste = []; |
|
| 41 | + // recuperer les tables_objets_sql declarees |
|
| 42 | + include_spip('base/objets'); |
|
| 43 | + $tables_objets = lister_tables_objets_sql(); |
|
| 44 | + foreach ($tables_objets as $t => $infos) { |
|
| 45 | + if ($infos['rechercher_champs']) { |
|
| 46 | + $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + // puis passer dans le pipeline |
|
| 50 | + $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $liste; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // Recherche des auteurs et mots-cles associes |
| 58 | 58 | // en ne regardant que le titre ou le nom |
| 59 | 59 | function liste_des_jointures() { |
| 60 | - static $liste = null; |
|
| 61 | - if (is_null($liste)) { |
|
| 62 | - $liste = []; |
|
| 63 | - // recuperer les tables_objets_sql declarees |
|
| 64 | - include_spip('base/objets'); |
|
| 65 | - $tables_objets = lister_tables_objets_sql(); |
|
| 66 | - foreach ($tables_objets as $t => $infos) { |
|
| 67 | - if ($infos['rechercher_jointures']) { |
|
| 68 | - $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - // puis passer dans le pipeline |
|
| 72 | - $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $liste; |
|
| 60 | + static $liste = null; |
|
| 61 | + if (is_null($liste)) { |
|
| 62 | + $liste = []; |
|
| 63 | + // recuperer les tables_objets_sql declarees |
|
| 64 | + include_spip('base/objets'); |
|
| 65 | + $tables_objets = lister_tables_objets_sql(); |
|
| 66 | + foreach ($tables_objets as $t => $infos) { |
|
| 67 | + if ($infos['rechercher_jointures']) { |
|
| 68 | + $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + // puis passer dans le pipeline |
|
| 72 | + $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $liste; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function expression_recherche($recherche, $options) { |
| 79 | - // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | - // (meme si utilisee dans plusieurs boucles) |
|
| 81 | - static $expression = []; |
|
| 82 | - $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | - if (isset($expression[$key])) { |
|
| 84 | - return $expression[$key]; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | - if ($u and !str_contains($options['preg_flags'], (string) $u)) { |
|
| 89 | - $options['preg_flags'] .= $u; |
|
| 90 | - } |
|
| 91 | - include_spip('inc/charsets'); |
|
| 92 | - $recherche = trim($recherche); |
|
| 93 | - |
|
| 94 | - // retirer les + de +truc et les * de truc* |
|
| 95 | - $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | - $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | - |
|
| 98 | - $is_preg = false; |
|
| 99 | - if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | - // c'est une preg |
|
| 101 | - $recherche_trans = translitteration($recherche); |
|
| 102 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | - $is_preg = true; |
|
| 104 | - } else { |
|
| 105 | - // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | - // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | - // 'une', 'des' ...) |
|
| 108 | - |
|
| 109 | - // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | - $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | - |
|
| 112 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | - // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | - foreach ($matches as $match) { |
|
| 116 | - $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | - $word = trim($word, '"'); |
|
| 118 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | - $is_preg = true; |
|
| 124 | - |
|
| 125 | - $recherche_inter = '|'; |
|
| 126 | - $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | - $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | - $petits_mots = true; |
|
| 129 | - foreach ($recherche_mots as $mot) { |
|
| 130 | - if (strlen($mot) >= $min_long) { |
|
| 131 | - // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | - $petits_mots = false; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | - |
|
| 138 | - // mais on cherche quand même l'expression complète, même si elle |
|
| 139 | - // comporte des mots de moins de quatre lettres |
|
| 140 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | - if (!$recherche or $petits_mots) { |
|
| 142 | - $recherche = preg_quote($recherche_org); |
|
| 143 | - } |
|
| 144 | - $recherche_trans = translitteration($recherche); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | - // ou si l'expression reguliere est invalide |
|
| 152 | - if ( |
|
| 153 | - !$is_preg |
|
| 154 | - or (@preg_match($preg, '') === false) |
|
| 155 | - ) { |
|
| 156 | - $methode = 'LIKE'; |
|
| 157 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | - |
|
| 159 | - // echapper les % et _ |
|
| 160 | - $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | - |
|
| 162 | - // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | - $recherche = preg_quote($recherche, '/'); |
|
| 164 | - $recherche_trans = translitteration($recherche); |
|
| 165 | - $recherche_mod = $recherche_trans; |
|
| 166 | - |
|
| 167 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | - // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | - // corriger le like dans le $q |
|
| 170 | - if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | - foreach ($matches as $match) { |
|
| 172 | - $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | - $word = trim($word, '"'); |
|
| 174 | - $q = str_replace($match, $word, $q); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - // corriger la regexp |
|
| 178 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | - foreach ($matches as $match) { |
|
| 180 | - $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | - $word = trim($word, '"'); |
|
| 182 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - $q = sql_quote( |
|
| 186 | - '%' |
|
| 187 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | - . '%' |
|
| 189 | - ); |
|
| 190 | - |
|
| 191 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | - } else { |
|
| 193 | - $methode = 'REGEXP'; |
|
| 194 | - $q = sql_quote(trim($recherche, '/')); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | - // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | - $q_t = $q; |
|
| 200 | - for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | - $char = spip_substr($q, $i, 1); |
|
| 202 | - if ( |
|
| 203 | - !is_ascii($char) |
|
| 204 | - and $char_t = translitteration($char) |
|
| 205 | - and $char_t !== $char |
|
| 206 | - ) { |
|
| 207 | - // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | - // mais c'est un pis aller cf #4354 |
|
| 209 | - $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $q = $q_t; |
|
| 214 | - |
|
| 215 | - // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | - // les plus frequents qui peuvent etre accentues |
|
| 217 | - // (oui c'est tres dicustable...) |
|
| 218 | - if ( |
|
| 219 | - isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | - and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | - ) { |
|
| 222 | - $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | - // si il reste au moins un char significatif... |
|
| 224 | - if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | - $q = $q_t; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $expression[$key] = [$methode, $q, $preg]; |
|
| 79 | + // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | + // (meme si utilisee dans plusieurs boucles) |
|
| 81 | + static $expression = []; |
|
| 82 | + $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | + if (isset($expression[$key])) { |
|
| 84 | + return $expression[$key]; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | + if ($u and !str_contains($options['preg_flags'], (string) $u)) { |
|
| 89 | + $options['preg_flags'] .= $u; |
|
| 90 | + } |
|
| 91 | + include_spip('inc/charsets'); |
|
| 92 | + $recherche = trim($recherche); |
|
| 93 | + |
|
| 94 | + // retirer les + de +truc et les * de truc* |
|
| 95 | + $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | + $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | + |
|
| 98 | + $is_preg = false; |
|
| 99 | + if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | + // c'est une preg |
|
| 101 | + $recherche_trans = translitteration($recherche); |
|
| 102 | + $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | + $is_preg = true; |
|
| 104 | + } else { |
|
| 105 | + // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | + // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | + // 'une', 'des' ...) |
|
| 108 | + |
|
| 109 | + // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | + $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | + |
|
| 112 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | + // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | + foreach ($matches as $match) { |
|
| 116 | + $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | + $word = trim($word, '"'); |
|
| 118 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | + $is_preg = true; |
|
| 124 | + |
|
| 125 | + $recherche_inter = '|'; |
|
| 126 | + $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | + $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | + $petits_mots = true; |
|
| 129 | + foreach ($recherche_mots as $mot) { |
|
| 130 | + if (strlen($mot) >= $min_long) { |
|
| 131 | + // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | + $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | + $petits_mots = false; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | + |
|
| 138 | + // mais on cherche quand même l'expression complète, même si elle |
|
| 139 | + // comporte des mots de moins de quatre lettres |
|
| 140 | + $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | + if (!$recherche or $petits_mots) { |
|
| 142 | + $recherche = preg_quote($recherche_org); |
|
| 143 | + } |
|
| 144 | + $recherche_trans = translitteration($recherche); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | + // ou si l'expression reguliere est invalide |
|
| 152 | + if ( |
|
| 153 | + !$is_preg |
|
| 154 | + or (@preg_match($preg, '') === false) |
|
| 155 | + ) { |
|
| 156 | + $methode = 'LIKE'; |
|
| 157 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | + |
|
| 159 | + // echapper les % et _ |
|
| 160 | + $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | + |
|
| 162 | + // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | + $recherche = preg_quote($recherche, '/'); |
|
| 164 | + $recherche_trans = translitteration($recherche); |
|
| 165 | + $recherche_mod = $recherche_trans; |
|
| 166 | + |
|
| 167 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | + // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | + // corriger le like dans le $q |
|
| 170 | + if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | + foreach ($matches as $match) { |
|
| 172 | + $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | + $word = trim($word, '"'); |
|
| 174 | + $q = str_replace($match, $word, $q); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + // corriger la regexp |
|
| 178 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | + foreach ($matches as $match) { |
|
| 180 | + $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | + $word = trim($word, '"'); |
|
| 182 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + $q = sql_quote( |
|
| 186 | + '%' |
|
| 187 | + . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | + . '%' |
|
| 189 | + ); |
|
| 190 | + |
|
| 191 | + $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | + } else { |
|
| 193 | + $methode = 'REGEXP'; |
|
| 194 | + $q = sql_quote(trim($recherche, '/')); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | + // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | + $q_t = $q; |
|
| 200 | + for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | + $char = spip_substr($q, $i, 1); |
|
| 202 | + if ( |
|
| 203 | + !is_ascii($char) |
|
| 204 | + and $char_t = translitteration($char) |
|
| 205 | + and $char_t !== $char |
|
| 206 | + ) { |
|
| 207 | + // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | + // mais c'est un pis aller cf #4354 |
|
| 209 | + $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $q = $q_t; |
|
| 214 | + |
|
| 215 | + // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | + // les plus frequents qui peuvent etre accentues |
|
| 217 | + // (oui c'est tres dicustable...) |
|
| 218 | + if ( |
|
| 219 | + isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | + and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | + ) { |
|
| 222 | + $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | + // si il reste au moins un char significatif... |
|
| 224 | + if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | + $q = $q_t; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $expression[$key] = [$methode, $q, $preg]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -253,142 +253,142 @@ discard block |
||
| 253 | 253 | * @return array |
| 254 | 254 | */ |
| 255 | 255 | function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') { |
| 256 | - include_spip('base/abstract_sql'); |
|
| 257 | - |
|
| 258 | - if (!is_array($tables)) { |
|
| 259 | - $liste = liste_des_champs(); |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - is_string($tables) |
|
| 263 | - and $tables != '' |
|
| 264 | - ) { |
|
| 265 | - $toutes = []; |
|
| 266 | - foreach (explode(',', $tables) as $t) { |
|
| 267 | - $t = trim($t); |
|
| 268 | - if (isset($liste[$t])) { |
|
| 269 | - $toutes[$t] = $liste[$t]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $tables = $toutes; |
|
| 273 | - unset($toutes); |
|
| 274 | - } else { |
|
| 275 | - $tables = $liste; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if (!strlen($recherche) or !count($tables)) { |
|
| 280 | - return []; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - include_spip('inc/autoriser'); |
|
| 284 | - |
|
| 285 | - // options par defaut |
|
| 286 | - $options = array_merge( |
|
| 287 | - [ |
|
| 288 | - 'preg_flags' => 'UimsS', |
|
| 289 | - 'toutvoir' => false, |
|
| 290 | - 'champs' => false, |
|
| 291 | - 'score' => false, |
|
| 292 | - 'matches' => false, |
|
| 293 | - 'jointures' => false, |
|
| 294 | - 'serveur' => $serveur |
|
| 295 | - ], |
|
| 296 | - $options |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - $results = []; |
|
| 300 | - |
|
| 301 | - // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | - // pour recuperer les couples (id_objet, score) |
|
| 303 | - // Le resultat est au format { |
|
| 304 | - // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | - // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | - // } |
|
| 307 | - |
|
| 308 | - include_spip('inc/recherche_to_array'); |
|
| 309 | - |
|
| 310 | - foreach ($tables as $table => $champs) { |
|
| 311 | - # lock via memoization, si dispo |
|
| 312 | - if (function_exists('cache_lock')) { |
|
| 313 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - spip_timer('rech'); |
|
| 317 | - |
|
| 318 | - # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | - $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | - $results[$table] = $to_array( |
|
| 321 | - $recherche, |
|
| 322 | - array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | - ); |
|
| 324 | - ##var_dump($results[$table]); |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - spip_log( |
|
| 328 | - "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | - 'recherche' |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - if (isset($lock)) { |
|
| 333 | - cache_unlock($lock); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return $results; |
|
| 256 | + include_spip('base/abstract_sql'); |
|
| 257 | + |
|
| 258 | + if (!is_array($tables)) { |
|
| 259 | + $liste = liste_des_champs(); |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + is_string($tables) |
|
| 263 | + and $tables != '' |
|
| 264 | + ) { |
|
| 265 | + $toutes = []; |
|
| 266 | + foreach (explode(',', $tables) as $t) { |
|
| 267 | + $t = trim($t); |
|
| 268 | + if (isset($liste[$t])) { |
|
| 269 | + $toutes[$t] = $liste[$t]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $tables = $toutes; |
|
| 273 | + unset($toutes); |
|
| 274 | + } else { |
|
| 275 | + $tables = $liste; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if (!strlen($recherche) or !count($tables)) { |
|
| 280 | + return []; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + include_spip('inc/autoriser'); |
|
| 284 | + |
|
| 285 | + // options par defaut |
|
| 286 | + $options = array_merge( |
|
| 287 | + [ |
|
| 288 | + 'preg_flags' => 'UimsS', |
|
| 289 | + 'toutvoir' => false, |
|
| 290 | + 'champs' => false, |
|
| 291 | + 'score' => false, |
|
| 292 | + 'matches' => false, |
|
| 293 | + 'jointures' => false, |
|
| 294 | + 'serveur' => $serveur |
|
| 295 | + ], |
|
| 296 | + $options |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + $results = []; |
|
| 300 | + |
|
| 301 | + // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | + // pour recuperer les couples (id_objet, score) |
|
| 303 | + // Le resultat est au format { |
|
| 304 | + // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | + // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | + // } |
|
| 307 | + |
|
| 308 | + include_spip('inc/recherche_to_array'); |
|
| 309 | + |
|
| 310 | + foreach ($tables as $table => $champs) { |
|
| 311 | + # lock via memoization, si dispo |
|
| 312 | + if (function_exists('cache_lock')) { |
|
| 313 | + cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + spip_timer('rech'); |
|
| 317 | + |
|
| 318 | + # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | + $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | + $results[$table] = $to_array( |
|
| 321 | + $recherche, |
|
| 322 | + array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | + ); |
|
| 324 | + ##var_dump($results[$table]); |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + spip_log( |
|
| 328 | + "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | + 'recherche' |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + if (isset($lock)) { |
|
| 333 | + cache_unlock($lock); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return $results; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
| 341 | 341 | // Effectue une recherche sur toutes les tables de la base de donnees |
| 342 | 342 | function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) { |
| 343 | - include_spip('inc/modifier'); |
|
| 344 | - |
|
| 345 | - // options par defaut |
|
| 346 | - $options = array_merge( |
|
| 347 | - [ |
|
| 348 | - 'preg_flags' => 'UimsS', |
|
| 349 | - 'toutmodifier' => false |
|
| 350 | - ], |
|
| 351 | - $options |
|
| 352 | - ); |
|
| 353 | - $options['champs'] = true; |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - if (!is_array($tables)) { |
|
| 357 | - $tables = liste_des_champs(); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | - |
|
| 362 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | - |
|
| 364 | - foreach ($results as $table => $r) { |
|
| 365 | - $_id_table = id_table_objet($table); |
|
| 366 | - foreach ($r as $id => $x) { |
|
| 367 | - if ( |
|
| 368 | - $options['toutmodifier'] |
|
| 369 | - or autoriser('modifier', $table, $id) |
|
| 370 | - ) { |
|
| 371 | - $modifs = []; |
|
| 372 | - foreach ($x['champs'] as $key => $val) { |
|
| 373 | - if ($key == $_id_table) { |
|
| 374 | - continue; |
|
| 375 | - } |
|
| 376 | - $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | - if ($repl <> $val) { |
|
| 378 | - $modifs[$key] = $repl; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - if ($modifs) { |
|
| 382 | - objet_modifier_champs( |
|
| 383 | - $table, |
|
| 384 | - $id, |
|
| 385 | - [ |
|
| 386 | - 'champs' => array_keys($modifs), |
|
| 387 | - ], |
|
| 388 | - $modifs |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 343 | + include_spip('inc/modifier'); |
|
| 344 | + |
|
| 345 | + // options par defaut |
|
| 346 | + $options = array_merge( |
|
| 347 | + [ |
|
| 348 | + 'preg_flags' => 'UimsS', |
|
| 349 | + 'toutmodifier' => false |
|
| 350 | + ], |
|
| 351 | + $options |
|
| 352 | + ); |
|
| 353 | + $options['champs'] = true; |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + if (!is_array($tables)) { |
|
| 357 | + $tables = liste_des_champs(); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | + |
|
| 362 | + $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | + |
|
| 364 | + foreach ($results as $table => $r) { |
|
| 365 | + $_id_table = id_table_objet($table); |
|
| 366 | + foreach ($r as $id => $x) { |
|
| 367 | + if ( |
|
| 368 | + $options['toutmodifier'] |
|
| 369 | + or autoriser('modifier', $table, $id) |
|
| 370 | + ) { |
|
| 371 | + $modifs = []; |
|
| 372 | + foreach ($x['champs'] as $key => $val) { |
|
| 373 | + if ($key == $_id_table) { |
|
| 374 | + continue; |
|
| 375 | + } |
|
| 376 | + $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | + if ($repl <> $val) { |
|
| 378 | + $modifs[$key] = $repl; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + if ($modifs) { |
|
| 382 | + objet_modifier_champs( |
|
| 383 | + $table, |
|
| 384 | + $id, |
|
| 385 | + [ |
|
| 386 | + 'champs' => array_keys($modifs), |
|
| 387 | + ], |
|
| 388 | + $modifs |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -35,35 +35,35 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function definir_barre_onglets($script) { |
| 37 | 37 | |
| 38 | - $onglets = []; |
|
| 39 | - $liste_onglets = []; |
|
| 38 | + $onglets = []; |
|
| 39 | + $liste_onglets = []; |
|
| 40 | 40 | |
| 41 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 42 | - if (function_exists('onglets_plugins')) { |
|
| 43 | - $liste_onglets = onglets_plugins(); |
|
| 44 | - } |
|
| 41 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 42 | + if (function_exists('onglets_plugins')) { |
|
| 43 | + $liste_onglets = onglets_plugins(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - foreach ($liste_onglets as $id => $infos) { |
|
| 48 | - if ( |
|
| 49 | - ($parent = $infos['parent']) |
|
| 50 | - && $parent == $script |
|
| 51 | - && autoriser('onglet', "_$id") |
|
| 52 | - ) { |
|
| 53 | - $onglets[$id] = new Bouton( |
|
| 54 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 55 | - $infos['titre'], // titre |
|
| 56 | - (isset($infos['action']) and $infos['action']) |
|
| 57 | - ? generer_url_ecrire( |
|
| 58 | - $infos['action'], |
|
| 59 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 60 | - ) |
|
| 61 | - : null |
|
| 62 | - ); |
|
| 63 | - } |
|
| 64 | - } |
|
| 47 | + foreach ($liste_onglets as $id => $infos) { |
|
| 48 | + if ( |
|
| 49 | + ($parent = $infos['parent']) |
|
| 50 | + && $parent == $script |
|
| 51 | + && autoriser('onglet', "_$id") |
|
| 52 | + ) { |
|
| 53 | + $onglets[$id] = new Bouton( |
|
| 54 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 55 | + $infos['titre'], // titre |
|
| 56 | + (isset($infos['action']) and $infos['action']) |
|
| 57 | + ? generer_url_ecrire( |
|
| 58 | + $infos['action'], |
|
| 59 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 60 | + ) |
|
| 61 | + : null |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 66 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | 83 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 84 | - include_spip('inc/presentation'); |
|
| 84 | + include_spip('inc/presentation'); |
|
| 85 | 85 | |
| 86 | - $res = ''; |
|
| 86 | + $res = ''; |
|
| 87 | 87 | |
| 88 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 89 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 90 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 91 | - } |
|
| 88 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 89 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 90 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 93 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 94 | 94 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | // securité |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // se faciliter la lecture du charset |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | * Initialisation |
| 33 | 33 | */ |
| 34 | 34 | function init_charset(): void { |
| 35 | - // Initialisation |
|
| 36 | - $GLOBALS['CHARSET'] = []; |
|
| 37 | - |
|
| 38 | - // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 39 | - // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 40 | - // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 41 | - if ( |
|
| 42 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 43 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 44 | - ) { |
|
| 45 | - include_spip('inc/meta'); |
|
| 46 | - ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 47 | - } |
|
| 35 | + // Initialisation |
|
| 36 | + $GLOBALS['CHARSET'] = []; |
|
| 37 | + |
|
| 38 | + // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 39 | + // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 40 | + // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 41 | + if ( |
|
| 42 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 43 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 44 | + ) { |
|
| 45 | + include_spip('inc/meta'); |
|
| 46 | + ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // TODO: code d’exécution en dehors du fichier. |
@@ -65,39 +65,39 @@ discard block |
||
| 65 | 65 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 66 | 66 | **/ |
| 67 | 67 | function load_charset($charset = 'AUTO') { |
| 68 | - if ($charset == 'AUTO') { |
|
| 69 | - $charset = $GLOBALS['meta']['charset']; |
|
| 70 | - } |
|
| 71 | - $charset = trim(strtolower($charset)); |
|
| 72 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 73 | - return $charset; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($charset == 'utf-8') { |
|
| 77 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 78 | - |
|
| 79 | - return $charset; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // Quelques synonymes |
|
| 83 | - if ($charset === '') { |
|
| 84 | - $charset = 'iso-8859-1'; |
|
| 85 | - } elseif ($charset === 'windows-1250') { |
|
| 86 | - $charset = 'cp1250'; |
|
| 87 | - } elseif ($charset === 'windows-1251') { |
|
| 88 | - $charset = 'cp1251'; |
|
| 89 | - } elseif ($charset === 'windows-1256') { |
|
| 90 | - $charset = 'cp1256'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 94 | - return $charset; |
|
| 95 | - } else { |
|
| 96 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 97 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 98 | - |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 68 | + if ($charset == 'AUTO') { |
|
| 69 | + $charset = $GLOBALS['meta']['charset']; |
|
| 70 | + } |
|
| 71 | + $charset = trim(strtolower($charset)); |
|
| 72 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 73 | + return $charset; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($charset == 'utf-8') { |
|
| 77 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 78 | + |
|
| 79 | + return $charset; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // Quelques synonymes |
|
| 83 | + if ($charset === '') { |
|
| 84 | + $charset = 'iso-8859-1'; |
|
| 85 | + } elseif ($charset === 'windows-1250') { |
|
| 86 | + $charset = 'cp1250'; |
|
| 87 | + } elseif ($charset === 'windows-1251') { |
|
| 88 | + $charset = 'cp1251'; |
|
| 89 | + } elseif ($charset === 'windows-1256') { |
|
| 90 | + $charset = 'cp1256'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 94 | + return $charset; |
|
| 95 | + } else { |
|
| 96 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 97 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * true si notre charset est utilisable par mb_strsing |
| 111 | 111 | **/ |
| 112 | 112 | function init_mb_string(): bool { |
| 113 | - static $mb; |
|
| 114 | - |
|
| 115 | - // verifier que le charset interne est connu de mb_string |
|
| 116 | - if (!$mb) { |
|
| 117 | - if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 118 | - mb_internal_encoding('utf-8'); |
|
| 119 | - $mb = 1; |
|
| 120 | - } else { |
|
| 121 | - $mb = -1; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return ($mb === 1); |
|
| 113 | + static $mb; |
|
| 114 | + |
|
| 115 | + // verifier que le charset interne est connu de mb_string |
|
| 116 | + if (!$mb) { |
|
| 117 | + if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 118 | + mb_internal_encoding('utf-8'); |
|
| 119 | + $mb = 1; |
|
| 120 | + } else { |
|
| 121 | + $mb = -1; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return ($mb === 1); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -137,21 +137,21 @@ discard block |
||
| 137 | 137 | * true si iconv fonctionne correctement |
| 138 | 138 | **/ |
| 139 | 139 | function test_iconv(): bool { |
| 140 | - static $iconv_ok; |
|
| 141 | - |
|
| 142 | - if (!$iconv_ok) { |
|
| 143 | - if (!function_exists('iconv')) { |
|
| 144 | - $iconv_ok = -1; |
|
| 145 | - } else { |
|
| 146 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') { |
|
| 147 | - $iconv_ok = 1; |
|
| 148 | - } else { |
|
| 149 | - $iconv_ok = -1; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return ($iconv_ok === 1); |
|
| 140 | + static $iconv_ok; |
|
| 141 | + |
|
| 142 | + if (!$iconv_ok) { |
|
| 143 | + if (!function_exists('iconv')) { |
|
| 144 | + $iconv_ok = -1; |
|
| 145 | + } else { |
|
| 146 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') { |
|
| 147 | + $iconv_ok = 1; |
|
| 148 | + } else { |
|
| 149 | + $iconv_ok = -1; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return ($iconv_ok === 1); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -171,75 +171,75 @@ discard block |
||
| 171 | 171 | * texte corrigé |
| 172 | 172 | **/ |
| 173 | 173 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 174 | - static $trans; |
|
| 175 | - |
|
| 176 | - if (is_array($texte)) { |
|
| 177 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if ($charset == 'AUTO') { |
|
| 181 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 182 | - } |
|
| 183 | - if ($charset == 'utf-8') { |
|
| 184 | - $p = chr(194); |
|
| 185 | - if (strpos($texte, $p) == false) { |
|
| 186 | - return $texte; |
|
| 187 | - } |
|
| 188 | - } else { |
|
| 189 | - if ($charset == 'iso-8859-1') { |
|
| 190 | - $p = ''; |
|
| 191 | - } else { |
|
| 192 | - return $texte; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 197 | - $trans[$charset][$charset_cible] = [ |
|
| 198 | - $p . chr(128) => '€', |
|
| 199 | - $p . chr(129) => ' ', # pas affecte |
|
| 200 | - $p . chr(130) => '‚', |
|
| 201 | - $p . chr(131) => 'ƒ', |
|
| 202 | - $p . chr(132) => '„', |
|
| 203 | - $p . chr(133) => '…', |
|
| 204 | - $p . chr(134) => '†', |
|
| 205 | - $p . chr(135) => '‡', |
|
| 206 | - $p . chr(136) => 'ˆ', |
|
| 207 | - $p . chr(137) => '‰', |
|
| 208 | - $p . chr(138) => 'Š', |
|
| 209 | - $p . chr(139) => '‹', |
|
| 210 | - $p . chr(140) => 'Œ', |
|
| 211 | - $p . chr(141) => ' ', # pas affecte |
|
| 212 | - $p . chr(142) => 'Ž', |
|
| 213 | - $p . chr(143) => ' ', # pas affecte |
|
| 214 | - $p . chr(144) => ' ', # pas affecte |
|
| 215 | - $p . chr(145) => '‘', |
|
| 216 | - $p . chr(146) => '’', |
|
| 217 | - $p . chr(147) => '“', |
|
| 218 | - $p . chr(148) => '”', |
|
| 219 | - $p . chr(149) => '•', |
|
| 220 | - $p . chr(150) => '–', |
|
| 221 | - $p . chr(151) => '—', |
|
| 222 | - $p . chr(152) => '˜', |
|
| 223 | - $p . chr(153) => '™', |
|
| 224 | - $p . chr(154) => 'š', |
|
| 225 | - $p . chr(155) => '›', |
|
| 226 | - $p . chr(156) => 'œ', |
|
| 227 | - $p . chr(157) => ' ', # pas affecte |
|
| 228 | - $p . chr(158) => 'ž', |
|
| 229 | - $p . chr(159) => 'Ÿ', |
|
| 230 | - ]; |
|
| 231 | - if ($charset_cible != 'unicode') { |
|
| 232 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 233 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return @str_replace( |
|
| 239 | - array_keys($trans[$charset][$charset_cible]), |
|
| 240 | - array_values($trans[$charset][$charset_cible]), |
|
| 241 | - $texte |
|
| 242 | - ); |
|
| 174 | + static $trans; |
|
| 175 | + |
|
| 176 | + if (is_array($texte)) { |
|
| 177 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if ($charset == 'AUTO') { |
|
| 181 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 182 | + } |
|
| 183 | + if ($charset == 'utf-8') { |
|
| 184 | + $p = chr(194); |
|
| 185 | + if (strpos($texte, $p) == false) { |
|
| 186 | + return $texte; |
|
| 187 | + } |
|
| 188 | + } else { |
|
| 189 | + if ($charset == 'iso-8859-1') { |
|
| 190 | + $p = ''; |
|
| 191 | + } else { |
|
| 192 | + return $texte; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 197 | + $trans[$charset][$charset_cible] = [ |
|
| 198 | + $p . chr(128) => '€', |
|
| 199 | + $p . chr(129) => ' ', # pas affecte |
|
| 200 | + $p . chr(130) => '‚', |
|
| 201 | + $p . chr(131) => 'ƒ', |
|
| 202 | + $p . chr(132) => '„', |
|
| 203 | + $p . chr(133) => '…', |
|
| 204 | + $p . chr(134) => '†', |
|
| 205 | + $p . chr(135) => '‡', |
|
| 206 | + $p . chr(136) => 'ˆ', |
|
| 207 | + $p . chr(137) => '‰', |
|
| 208 | + $p . chr(138) => 'Š', |
|
| 209 | + $p . chr(139) => '‹', |
|
| 210 | + $p . chr(140) => 'Œ', |
|
| 211 | + $p . chr(141) => ' ', # pas affecte |
|
| 212 | + $p . chr(142) => 'Ž', |
|
| 213 | + $p . chr(143) => ' ', # pas affecte |
|
| 214 | + $p . chr(144) => ' ', # pas affecte |
|
| 215 | + $p . chr(145) => '‘', |
|
| 216 | + $p . chr(146) => '’', |
|
| 217 | + $p . chr(147) => '“', |
|
| 218 | + $p . chr(148) => '”', |
|
| 219 | + $p . chr(149) => '•', |
|
| 220 | + $p . chr(150) => '–', |
|
| 221 | + $p . chr(151) => '—', |
|
| 222 | + $p . chr(152) => '˜', |
|
| 223 | + $p . chr(153) => '™', |
|
| 224 | + $p . chr(154) => 'š', |
|
| 225 | + $p . chr(155) => '›', |
|
| 226 | + $p . chr(156) => 'œ', |
|
| 227 | + $p . chr(157) => ' ', # pas affecte |
|
| 228 | + $p . chr(158) => 'ž', |
|
| 229 | + $p . chr(159) => 'Ÿ', |
|
| 230 | + ]; |
|
| 231 | + if ($charset_cible != 'unicode') { |
|
| 232 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 233 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return @str_replace( |
|
| 239 | + array_keys($trans[$charset][$charset_cible]), |
|
| 240 | + array_values($trans[$charset][$charset_cible]), |
|
| 241 | + $texte |
|
| 242 | + ); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
@@ -256,26 +256,26 @@ discard block |
||
| 256 | 256 | * texte converti |
| 257 | 257 | **/ |
| 258 | 258 | function html2unicode($texte, $secure = false) { |
| 259 | - if (strpos($texte, '&') === false) { |
|
| 260 | - return $texte; |
|
| 261 | - } |
|
| 262 | - static $trans = []; |
|
| 263 | - if (!$trans) { |
|
| 264 | - load_charset('html'); |
|
| 265 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 266 | - $trans["&$key;"] = $val; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - if ($secure) { |
|
| 271 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 272 | - } else { |
|
| 273 | - return str_replace( |
|
| 274 | - ['&', '"', '<', '>'], |
|
| 275 | - ['&', '"', '<', '>'], |
|
| 276 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 277 | - ); |
|
| 278 | - } |
|
| 259 | + if (strpos($texte, '&') === false) { |
|
| 260 | + return $texte; |
|
| 261 | + } |
|
| 262 | + static $trans = []; |
|
| 263 | + if (!$trans) { |
|
| 264 | + load_charset('html'); |
|
| 265 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 266 | + $trans["&$key;"] = $val; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + if ($secure) { |
|
| 271 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 272 | + } else { |
|
| 273 | + return str_replace( |
|
| 274 | + ['&', '"', '<', '>'], |
|
| 275 | + ['&', '"', '<', '>'], |
|
| 276 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -290,16 +290,16 @@ discard block |
||
| 290 | 290 | * texte converti |
| 291 | 291 | **/ |
| 292 | 292 | function mathml2unicode($texte) { |
| 293 | - static $trans; |
|
| 294 | - if (!$trans) { |
|
| 295 | - load_charset('mathml'); |
|
| 293 | + static $trans; |
|
| 294 | + if (!$trans) { |
|
| 295 | + load_charset('mathml'); |
|
| 296 | 296 | |
| 297 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 298 | - $trans["&$key;"] = $val; |
|
| 299 | - } |
|
| 300 | - } |
|
| 297 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 298 | + $trans["&$key;"] = $val; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 302 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -321,75 +321,75 @@ discard block |
||
| 321 | 321 | * texte converti en unicode |
| 322 | 322 | **/ |
| 323 | 323 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 324 | - static $trans; |
|
| 325 | - |
|
| 326 | - if ($charset === 'AUTO') { |
|
| 327 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if ($charset === '') { |
|
| 331 | - $charset = 'iso-8859-1'; |
|
| 332 | - } |
|
| 333 | - $charset = strtolower($charset); |
|
| 334 | - |
|
| 335 | - switch ($charset) { |
|
| 336 | - case 'utf-8': |
|
| 337 | - case 'utf8': |
|
| 338 | - return utf_8_to_unicode($texte); |
|
| 339 | - |
|
| 340 | - case 'iso-8859-1': |
|
| 341 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 342 | - // pas de break; ici, on suit sur default: |
|
| 343 | - |
|
| 344 | - default: |
|
| 345 | - // mbstring presente ? |
|
| 346 | - if (init_mb_string()) { |
|
| 347 | - $order = mb_detect_order(); |
|
| 348 | - try { |
|
| 349 | - # mb_string connait-il $charset? |
|
| 350 | - if ($order and mb_detect_order($charset)) { |
|
| 351 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 352 | - if ($s && $s != $texte) { |
|
| 353 | - return utf_8_to_unicode($s); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } catch (\Error $e) { |
|
| 357 | - // Le charset n'existe probablement pas |
|
| 358 | - } finally { |
|
| 359 | - mb_detect_order($order); # remettre comme precedemment |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 364 | - if (!isset($trans[$charset])) { |
|
| 365 | - if ( |
|
| 366 | - $cset = load_charset($charset) |
|
| 367 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 368 | - ) { |
|
| 369 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 370 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 375 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 379 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 380 | - // surtout en utf-8, gere ci-dessus) |
|
| 381 | - if (test_iconv()) { |
|
| 382 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 383 | - if ($s) { |
|
| 384 | - return utf_32_to_unicode($s); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // Au pire ne rien faire |
|
| 389 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 390 | - |
|
| 391 | - return $texte; |
|
| 392 | - } |
|
| 324 | + static $trans; |
|
| 325 | + |
|
| 326 | + if ($charset === 'AUTO') { |
|
| 327 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if ($charset === '') { |
|
| 331 | + $charset = 'iso-8859-1'; |
|
| 332 | + } |
|
| 333 | + $charset = strtolower($charset); |
|
| 334 | + |
|
| 335 | + switch ($charset) { |
|
| 336 | + case 'utf-8': |
|
| 337 | + case 'utf8': |
|
| 338 | + return utf_8_to_unicode($texte); |
|
| 339 | + |
|
| 340 | + case 'iso-8859-1': |
|
| 341 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 342 | + // pas de break; ici, on suit sur default: |
|
| 343 | + |
|
| 344 | + default: |
|
| 345 | + // mbstring presente ? |
|
| 346 | + if (init_mb_string()) { |
|
| 347 | + $order = mb_detect_order(); |
|
| 348 | + try { |
|
| 349 | + # mb_string connait-il $charset? |
|
| 350 | + if ($order and mb_detect_order($charset)) { |
|
| 351 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 352 | + if ($s && $s != $texte) { |
|
| 353 | + return utf_8_to_unicode($s); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } catch (\Error $e) { |
|
| 357 | + // Le charset n'existe probablement pas |
|
| 358 | + } finally { |
|
| 359 | + mb_detect_order($order); # remettre comme precedemment |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 364 | + if (!isset($trans[$charset])) { |
|
| 365 | + if ( |
|
| 366 | + $cset = load_charset($charset) |
|
| 367 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 368 | + ) { |
|
| 369 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 370 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 375 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 379 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 380 | + // surtout en utf-8, gere ci-dessus) |
|
| 381 | + if (test_iconv()) { |
|
| 382 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 383 | + if ($s) { |
|
| 384 | + return utf_32_to_unicode($s); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // Au pire ne rien faire |
|
| 389 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 390 | + |
|
| 391 | + return $texte; |
|
| 392 | + } |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -408,43 +408,43 @@ discard block |
||
| 408 | 408 | * texte transformé dans le charset souhaité |
| 409 | 409 | **/ |
| 410 | 410 | function unicode2charset($texte, $charset = 'AUTO') { |
| 411 | - static $CHARSET_REVERSE = []; |
|
| 412 | - static $trans = []; |
|
| 413 | - |
|
| 414 | - if ($charset == 'AUTO') { |
|
| 415 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - switch ($charset) { |
|
| 419 | - case 'utf-8': |
|
| 420 | - return unicode_to_utf_8($texte); |
|
| 421 | - |
|
| 422 | - default: |
|
| 423 | - $charset = load_charset($charset); |
|
| 424 | - |
|
| 425 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 426 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - if (!isset($trans[$charset])) { |
|
| 430 | - $trans[$charset] = []; |
|
| 431 | - $t = &$trans[$charset]; |
|
| 432 | - for ($e = 128; $e < 255; $e++) { |
|
| 433 | - $h = dechex($e); |
|
| 434 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 435 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 436 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 437 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 438 | - } else { |
|
| 439 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 440 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 445 | - |
|
| 446 | - return $texte; |
|
| 447 | - } |
|
| 411 | + static $CHARSET_REVERSE = []; |
|
| 412 | + static $trans = []; |
|
| 413 | + |
|
| 414 | + if ($charset == 'AUTO') { |
|
| 415 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + switch ($charset) { |
|
| 419 | + case 'utf-8': |
|
| 420 | + return unicode_to_utf_8($texte); |
|
| 421 | + |
|
| 422 | + default: |
|
| 423 | + $charset = load_charset($charset); |
|
| 424 | + |
|
| 425 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 426 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + if (!isset($trans[$charset])) { |
|
| 430 | + $trans[$charset] = []; |
|
| 431 | + $t = &$trans[$charset]; |
|
| 432 | + for ($e = 128; $e < 255; $e++) { |
|
| 433 | + $h = dechex($e); |
|
| 434 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 435 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 436 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 437 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 438 | + } else { |
|
| 439 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 440 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 445 | + |
|
| 446 | + return $texte; |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
@@ -462,40 +462,40 @@ discard block |
||
| 462 | 462 | * texte transformé dans le charset site |
| 463 | 463 | **/ |
| 464 | 464 | function importer_charset($texte, $charset = 'AUTO') { |
| 465 | - $s = null; |
|
| 466 | - static $trans = []; |
|
| 467 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 468 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 469 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 470 | - if (init_mb_string()) { |
|
| 471 | - if ( |
|
| 472 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 473 | - and mb_detect_order($charset) |
|
| 474 | - ) { |
|
| 475 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 476 | - } |
|
| 477 | - mb_detect_order($order); # remettre comme precedemment |
|
| 478 | - return $s; |
|
| 479 | - } |
|
| 480 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 481 | - if (!isset($trans[$charset])) { |
|
| 482 | - if ( |
|
| 483 | - $cset = load_charset($charset) |
|
| 484 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 485 | - ) { |
|
| 486 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 487 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 492 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - return $texte; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 465 | + $s = null; |
|
| 466 | + static $trans = []; |
|
| 467 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 468 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 469 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 470 | + if (init_mb_string()) { |
|
| 471 | + if ( |
|
| 472 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 473 | + and mb_detect_order($charset) |
|
| 474 | + ) { |
|
| 475 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 476 | + } |
|
| 477 | + mb_detect_order($order); # remettre comme precedemment |
|
| 478 | + return $s; |
|
| 479 | + } |
|
| 480 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 481 | + if (!isset($trans[$charset])) { |
|
| 482 | + if ( |
|
| 483 | + $cset = load_charset($charset) |
|
| 484 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 485 | + ) { |
|
| 486 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 487 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 492 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + return $texte; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | |
@@ -511,92 +511,92 @@ discard block |
||
| 511 | 511 | **/ |
| 512 | 512 | function utf_8_to_unicode($source) { |
| 513 | 513 | |
| 514 | - // mb_string : methode rapide |
|
| 515 | - if (init_mb_string()) { |
|
| 516 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 517 | - |
|
| 518 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Sinon methode pas a pas |
|
| 522 | - static $decrement; |
|
| 523 | - static $shift; |
|
| 524 | - |
|
| 525 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 526 | - if (!is_array($decrement)) { |
|
| 527 | - // array used to figure what number to decrement from character order value |
|
| 528 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 529 | - $decrement[4] = 240; |
|
| 530 | - $decrement[3] = 224; |
|
| 531 | - $decrement[2] = 192; |
|
| 532 | - $decrement[1] = 0; |
|
| 533 | - // the number of bits to shift each charNum by |
|
| 534 | - $shift[1][0] = 0; |
|
| 535 | - $shift[2][0] = 6; |
|
| 536 | - $shift[2][1] = 0; |
|
| 537 | - $shift[3][0] = 12; |
|
| 538 | - $shift[3][1] = 6; |
|
| 539 | - $shift[3][2] = 0; |
|
| 540 | - $shift[4][0] = 18; |
|
| 541 | - $shift[4][1] = 12; |
|
| 542 | - $shift[4][2] = 6; |
|
| 543 | - $shift[4][3] = 0; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - $pos = 0; |
|
| 547 | - $len = strlen($source); |
|
| 548 | - $encodedString = ''; |
|
| 549 | - while ($pos < $len) { |
|
| 550 | - $char = ''; |
|
| 551 | - $ischar = false; |
|
| 552 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 553 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 554 | - // 4 chars representing one unicode character |
|
| 555 | - $thisLetter = substr($source, $pos, 4); |
|
| 556 | - $pos += 4; |
|
| 557 | - } else { |
|
| 558 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 559 | - // 3 chars representing one unicode character |
|
| 560 | - $thisLetter = substr($source, $pos, 3); |
|
| 561 | - $pos += 3; |
|
| 562 | - } else { |
|
| 563 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 564 | - // 2 chars representing one unicode character |
|
| 565 | - $thisLetter = substr($source, $pos, 2); |
|
| 566 | - $pos += 2; |
|
| 567 | - } else { |
|
| 568 | - // 1 char (lower ascii) |
|
| 569 | - $thisLetter = substr($source, $pos, 1); |
|
| 570 | - $pos += 1; |
|
| 571 | - $char = $thisLetter; |
|
| 572 | - $ischar = true; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - if ($ischar) { |
|
| 578 | - $encodedString .= $char; |
|
| 579 | - } else { // process the string representing the letter to a unicode entity |
|
| 580 | - $thisLen = strlen($thisLetter); |
|
| 581 | - $thisPos = 0; |
|
| 582 | - $decimalCode = 0; |
|
| 583 | - while ($thisPos < $thisLen) { |
|
| 584 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 585 | - if ($thisPos == 0) { |
|
| 586 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 587 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 588 | - } else { |
|
| 589 | - $charNum = intval($thisCharOrd - 128); |
|
| 590 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 591 | - } |
|
| 592 | - $thisPos++; |
|
| 593 | - } |
|
| 594 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 595 | - $encodedString .= $encodedLetter; |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return $encodedString; |
|
| 514 | + // mb_string : methode rapide |
|
| 515 | + if (init_mb_string()) { |
|
| 516 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 517 | + |
|
| 518 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Sinon methode pas a pas |
|
| 522 | + static $decrement; |
|
| 523 | + static $shift; |
|
| 524 | + |
|
| 525 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 526 | + if (!is_array($decrement)) { |
|
| 527 | + // array used to figure what number to decrement from character order value |
|
| 528 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 529 | + $decrement[4] = 240; |
|
| 530 | + $decrement[3] = 224; |
|
| 531 | + $decrement[2] = 192; |
|
| 532 | + $decrement[1] = 0; |
|
| 533 | + // the number of bits to shift each charNum by |
|
| 534 | + $shift[1][0] = 0; |
|
| 535 | + $shift[2][0] = 6; |
|
| 536 | + $shift[2][1] = 0; |
|
| 537 | + $shift[3][0] = 12; |
|
| 538 | + $shift[3][1] = 6; |
|
| 539 | + $shift[3][2] = 0; |
|
| 540 | + $shift[4][0] = 18; |
|
| 541 | + $shift[4][1] = 12; |
|
| 542 | + $shift[4][2] = 6; |
|
| 543 | + $shift[4][3] = 0; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + $pos = 0; |
|
| 547 | + $len = strlen($source); |
|
| 548 | + $encodedString = ''; |
|
| 549 | + while ($pos < $len) { |
|
| 550 | + $char = ''; |
|
| 551 | + $ischar = false; |
|
| 552 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 553 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 554 | + // 4 chars representing one unicode character |
|
| 555 | + $thisLetter = substr($source, $pos, 4); |
|
| 556 | + $pos += 4; |
|
| 557 | + } else { |
|
| 558 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 559 | + // 3 chars representing one unicode character |
|
| 560 | + $thisLetter = substr($source, $pos, 3); |
|
| 561 | + $pos += 3; |
|
| 562 | + } else { |
|
| 563 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 564 | + // 2 chars representing one unicode character |
|
| 565 | + $thisLetter = substr($source, $pos, 2); |
|
| 566 | + $pos += 2; |
|
| 567 | + } else { |
|
| 568 | + // 1 char (lower ascii) |
|
| 569 | + $thisLetter = substr($source, $pos, 1); |
|
| 570 | + $pos += 1; |
|
| 571 | + $char = $thisLetter; |
|
| 572 | + $ischar = true; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + if ($ischar) { |
|
| 578 | + $encodedString .= $char; |
|
| 579 | + } else { // process the string representing the letter to a unicode entity |
|
| 580 | + $thisLen = strlen($thisLetter); |
|
| 581 | + $thisPos = 0; |
|
| 582 | + $decimalCode = 0; |
|
| 583 | + while ($thisPos < $thisLen) { |
|
| 584 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 585 | + if ($thisPos == 0) { |
|
| 586 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 587 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 588 | + } else { |
|
| 589 | + $charNum = intval($thisCharOrd - 128); |
|
| 590 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 591 | + } |
|
| 592 | + $thisPos++; |
|
| 593 | + } |
|
| 594 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 595 | + $encodedString .= $encodedLetter; |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return $encodedString; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -615,32 +615,32 @@ discard block |
||
| 615 | 615 | **/ |
| 616 | 616 | function utf_32_to_unicode($source) { |
| 617 | 617 | |
| 618 | - // mb_string : methode rapide |
|
| 619 | - if (init_mb_string()) { |
|
| 620 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 621 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 622 | - |
|
| 623 | - return str_replace(chr(0), '', $source); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // Sinon methode lente |
|
| 627 | - $texte = ''; |
|
| 628 | - while ($source) { |
|
| 629 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 630 | - $source = substr($source, 1024); |
|
| 631 | - foreach ($words as $word) { |
|
| 632 | - if ($word < 128) { |
|
| 633 | - $texte .= chr($word); |
|
| 634 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 635 | - else { |
|
| 636 | - if ($word != 65279) { |
|
| 637 | - $texte .= '&#' . $word . ';'; |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - return $texte; |
|
| 618 | + // mb_string : methode rapide |
|
| 619 | + if (init_mb_string()) { |
|
| 620 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 621 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 622 | + |
|
| 623 | + return str_replace(chr(0), '', $source); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // Sinon methode lente |
|
| 627 | + $texte = ''; |
|
| 628 | + while ($source) { |
|
| 629 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 630 | + $source = substr($source, 1024); |
|
| 631 | + foreach ($words as $word) { |
|
| 632 | + if ($word < 128) { |
|
| 633 | + $texte .= chr($word); |
|
| 634 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 635 | + else { |
|
| 636 | + if ($word != 65279) { |
|
| 637 | + $texte .= '&#' . $word . ';'; |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + return $texte; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | |
@@ -657,21 +657,21 @@ discard block |
||
| 657 | 657 | * Caractère utf8 si trouvé, '' sinon |
| 658 | 658 | **/ |
| 659 | 659 | function caractere_utf_8($num) { |
| 660 | - $num = intval($num); |
|
| 661 | - if ($num < 128) { |
|
| 662 | - return chr($num); |
|
| 663 | - } |
|
| 664 | - if ($num < 2048) { |
|
| 665 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 666 | - } |
|
| 667 | - if ($num < 65536) { |
|
| 668 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 669 | - } |
|
| 670 | - if ($num < 1_114_112) { |
|
| 671 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return ''; |
|
| 660 | + $num = intval($num); |
|
| 661 | + if ($num < 128) { |
|
| 662 | + return chr($num); |
|
| 663 | + } |
|
| 664 | + if ($num < 2048) { |
|
| 665 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 666 | + } |
|
| 667 | + if ($num < 65536) { |
|
| 668 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 669 | + } |
|
| 670 | + if ($num < 1_114_112) { |
|
| 671 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return ''; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -684,42 +684,42 @@ discard block |
||
| 684 | 684 | **/ |
| 685 | 685 | function unicode_to_utf_8($texte) { |
| 686 | 686 | |
| 687 | - // 1. Entites € et suivantes |
|
| 688 | - $vu = []; |
|
| 689 | - if ( |
|
| 690 | - preg_match_all( |
|
| 691 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 692 | - $texte, |
|
| 693 | - $regs, |
|
| 694 | - PREG_SET_ORDER |
|
| 695 | - ) |
|
| 696 | - ) { |
|
| 697 | - foreach ($regs as $reg) { |
|
| 698 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 699 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 704 | - |
|
| 705 | - // 2. Entites > ÿ |
|
| 706 | - //$vu = array(); |
|
| 707 | - if ( |
|
| 708 | - preg_match_all( |
|
| 709 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 710 | - $texte, |
|
| 711 | - $regs, |
|
| 712 | - PREG_SET_ORDER |
|
| 713 | - ) |
|
| 714 | - ) { |
|
| 715 | - foreach ($regs as $reg) { |
|
| 716 | - if (!isset($vu[$reg[0]])) { |
|
| 717 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 687 | + // 1. Entites € et suivantes |
|
| 688 | + $vu = []; |
|
| 689 | + if ( |
|
| 690 | + preg_match_all( |
|
| 691 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 692 | + $texte, |
|
| 693 | + $regs, |
|
| 694 | + PREG_SET_ORDER |
|
| 695 | + ) |
|
| 696 | + ) { |
|
| 697 | + foreach ($regs as $reg) { |
|
| 698 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 699 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 704 | + |
|
| 705 | + // 2. Entites > ÿ |
|
| 706 | + //$vu = array(); |
|
| 707 | + if ( |
|
| 708 | + preg_match_all( |
|
| 709 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 710 | + $texte, |
|
| 711 | + $regs, |
|
| 712 | + PREG_SET_ORDER |
|
| 713 | + ) |
|
| 714 | + ) { |
|
| 715 | + foreach ($regs as $reg) { |
|
| 716 | + if (!isset($vu[$reg[0]])) { |
|
| 717 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -731,15 +731,15 @@ discard block |
||
| 731 | 731 | * texte converti |
| 732 | 732 | **/ |
| 733 | 733 | function unicode_to_javascript($texte) { |
| 734 | - $vu = []; |
|
| 735 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 736 | - $num = $regs[1]; |
|
| 737 | - $vu[$num] = true; |
|
| 738 | - $s = '\u' . sprintf('%04x', $num); |
|
| 739 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - return $texte; |
|
| 734 | + $vu = []; |
|
| 735 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 736 | + $num = $regs[1]; |
|
| 737 | + $vu[$num] = true; |
|
| 738 | + $s = '\u' . sprintf('%04x', $num); |
|
| 739 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + return $texte; |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | /** |
@@ -751,11 +751,11 @@ discard block |
||
| 751 | 751 | * texte converti |
| 752 | 752 | **/ |
| 753 | 753 | function javascript_to_unicode($texte) { |
| 754 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 755 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 756 | - } |
|
| 754 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 755 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 756 | + } |
|
| 757 | 757 | |
| 758 | - return $texte; |
|
| 758 | + return $texte; |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -767,11 +767,11 @@ discard block |
||
| 767 | 767 | * texte converti |
| 768 | 768 | **/ |
| 769 | 769 | function javascript_to_binary($texte) { |
| 770 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 771 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 772 | - } |
|
| 770 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 771 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 772 | + } |
|
| 773 | 773 | |
| 774 | - return $texte; |
|
| 774 | + return $texte; |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | |
@@ -789,26 +789,26 @@ discard block |
||
| 789 | 789 | * @return string |
| 790 | 790 | */ |
| 791 | 791 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string { |
| 792 | - static $trans = []; |
|
| 793 | - if ($charset == 'AUTO') { |
|
| 794 | - $charset = $GLOBALS['meta']['charset']; |
|
| 795 | - } |
|
| 796 | - if (!strlen($texte)) { |
|
| 797 | - return $texte; |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - $table_translit = 'translit' . $complexe; |
|
| 801 | - |
|
| 802 | - // 2. Translitterer grace a la table predefinie |
|
| 803 | - if (!isset($trans[$complexe])) { |
|
| 804 | - $trans[$complexe] = []; |
|
| 805 | - load_charset($table_translit); |
|
| 806 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 807 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 792 | + static $trans = []; |
|
| 793 | + if ($charset == 'AUTO') { |
|
| 794 | + $charset = $GLOBALS['meta']['charset']; |
|
| 795 | + } |
|
| 796 | + if (!strlen($texte)) { |
|
| 797 | + return $texte; |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + $table_translit = 'translit' . $complexe; |
|
| 801 | + |
|
| 802 | + // 2. Translitterer grace a la table predefinie |
|
| 803 | + if (!isset($trans[$complexe])) { |
|
| 804 | + $trans[$complexe] = []; |
|
| 805 | + load_charset($table_translit); |
|
| 806 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 807 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -831,14 +831,14 @@ discard block |
||
| 831 | 831 | * @return string |
| 832 | 832 | */ |
| 833 | 833 | function translitteration($texte, $charset = 'AUTO', $complexe = ''): string { |
| 834 | - // 0. Supprimer les caracteres illegaux |
|
| 835 | - include_spip('inc/filtres'); |
|
| 836 | - $texte = corriger_caracteres($texte); |
|
| 834 | + // 0. Supprimer les caracteres illegaux |
|
| 835 | + include_spip('inc/filtres'); |
|
| 836 | + $texte = corriger_caracteres($texte); |
|
| 837 | 837 | |
| 838 | - // 1. Passer le charset et les é en utf-8 |
|
| 839 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 838 | + // 1. Passer le charset et les é en utf-8 |
|
| 839 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 840 | 840 | |
| 841 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 841 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | /** |
@@ -853,17 +853,17 @@ discard block |
||
| 853 | 853 | * @return string |
| 854 | 854 | */ |
| 855 | 855 | function translitteration_complexe($texte, $chiffres = false): string { |
| 856 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 856 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 857 | 857 | |
| 858 | - if ($chiffres) { |
|
| 859 | - $texte = preg_replace_callback( |
|
| 860 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 861 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 862 | - $texte |
|
| 863 | - ); |
|
| 864 | - } |
|
| 858 | + if ($chiffres) { |
|
| 859 | + $texte = preg_replace_callback( |
|
| 860 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 861 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 862 | + $texte |
|
| 863 | + ); |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - return $texte; |
|
| 866 | + return $texte; |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | /** |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | * @return string |
| 876 | 876 | */ |
| 877 | 877 | function translitteration_chiffree($car): string { |
| 878 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 878 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | * true s'il a un BOM |
| 889 | 889 | **/ |
| 890 | 890 | function bom_utf8($texte): bool { |
| 891 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 891 | + return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | /** |
@@ -905,21 +905,21 @@ discard block |
||
| 905 | 905 | * true si c'est le cas |
| 906 | 906 | **/ |
| 907 | 907 | function is_utf8($string): bool { |
| 908 | - return !strlen( |
|
| 909 | - preg_replace( |
|
| 910 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 911 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 912 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 913 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 914 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 915 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 916 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 917 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 918 | - . ',sS', |
|
| 919 | - '', |
|
| 920 | - $string |
|
| 921 | - ) |
|
| 922 | - ); |
|
| 908 | + return !strlen( |
|
| 909 | + preg_replace( |
|
| 910 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 911 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 912 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 913 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 914 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 915 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 916 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 917 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 918 | + . ',sS', |
|
| 919 | + '', |
|
| 920 | + $string |
|
| 921 | + ) |
|
| 922 | + ); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -931,13 +931,13 @@ discard block |
||
| 931 | 931 | * true si c'est le cas |
| 932 | 932 | **/ |
| 933 | 933 | function is_ascii($string): bool { |
| 934 | - return !strlen( |
|
| 935 | - preg_replace( |
|
| 936 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 937 | - '', |
|
| 938 | - $string |
|
| 939 | - ) |
|
| 940 | - ); |
|
| 934 | + return !strlen( |
|
| 935 | + preg_replace( |
|
| 936 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 937 | + '', |
|
| 938 | + $string |
|
| 939 | + ) |
|
| 940 | + ); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -956,53 +956,53 @@ discard block |
||
| 956 | 956 | **/ |
| 957 | 957 | function transcoder_page($texte, $headers = ''): string { |
| 958 | 958 | |
| 959 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 960 | - if (is_ascii($texte)) { |
|
| 961 | - #spip_log('charset: ascii'); |
|
| 962 | - return $texte; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - if (bom_utf8($texte)) { |
|
| 966 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 967 | - $charset = 'utf-8'; |
|
| 968 | - $texte = substr($texte, 3); |
|
| 969 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 970 | - // charset precise par le contenu (xml) |
|
| 971 | - $charset = trim(strtolower($regs[1])); |
|
| 972 | - } elseif ( |
|
| 973 | - // charset precise par le contenu (html) |
|
| 974 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 975 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 976 | - and !str_contains($regs[2], '#') |
|
| 977 | - and $tmp = trim(strtolower($regs[2])) |
|
| 978 | - ) { |
|
| 979 | - $charset = $tmp; |
|
| 980 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 981 | - // charset de la reponse http |
|
| 982 | - $charset = trim(strtolower($regs[1])); |
|
| 983 | - } else { |
|
| 984 | - $charset = ''; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - // normaliser les noms du shif-jis japonais |
|
| 989 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 990 | - $charset = 'shift-jis'; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - if ($charset) { |
|
| 994 | - spip_log("charset: $charset"); |
|
| 995 | - } else { |
|
| 996 | - // valeur par defaut |
|
| 997 | - if (is_utf8($texte)) { |
|
| 998 | - $charset = 'utf-8'; |
|
| 999 | - } else { |
|
| 1000 | - $charset = 'iso-8859-1'; |
|
| 1001 | - } |
|
| 1002 | - spip_log("charset probable: $charset"); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return importer_charset($texte, $charset); |
|
| 959 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 960 | + if (is_ascii($texte)) { |
|
| 961 | + #spip_log('charset: ascii'); |
|
| 962 | + return $texte; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + if (bom_utf8($texte)) { |
|
| 966 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 967 | + $charset = 'utf-8'; |
|
| 968 | + $texte = substr($texte, 3); |
|
| 969 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 970 | + // charset precise par le contenu (xml) |
|
| 971 | + $charset = trim(strtolower($regs[1])); |
|
| 972 | + } elseif ( |
|
| 973 | + // charset precise par le contenu (html) |
|
| 974 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 975 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 976 | + and !str_contains($regs[2], '#') |
|
| 977 | + and $tmp = trim(strtolower($regs[2])) |
|
| 978 | + ) { |
|
| 979 | + $charset = $tmp; |
|
| 980 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 981 | + // charset de la reponse http |
|
| 982 | + $charset = trim(strtolower($regs[1])); |
|
| 983 | + } else { |
|
| 984 | + $charset = ''; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + // normaliser les noms du shif-jis japonais |
|
| 989 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 990 | + $charset = 'shift-jis'; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + if ($charset) { |
|
| 994 | + spip_log("charset: $charset"); |
|
| 995 | + } else { |
|
| 996 | + // valeur par defaut |
|
| 997 | + if (is_utf8($texte)) { |
|
| 998 | + $charset = 'utf-8'; |
|
| 999 | + } else { |
|
| 1000 | + $charset = 'iso-8859-1'; |
|
| 1001 | + } |
|
| 1002 | + spip_log("charset probable: $charset"); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return importer_charset($texte, $charset); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | |
@@ -1026,19 +1026,19 @@ discard block |
||
| 1026 | 1026 | * Le texte coupé |
| 1027 | 1027 | **/ |
| 1028 | 1028 | function spip_substr($c, $start = 0, $length = null) { |
| 1029 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1030 | - if ($length) { |
|
| 1031 | - return substr($c, $start, $length); |
|
| 1032 | - } else { |
|
| 1033 | - return substr($c, $start); |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - if ($length) { |
|
| 1038 | - return mb_substr($c, $start, $length); |
|
| 1039 | - } else { |
|
| 1040 | - return mb_substr($c, $start); |
|
| 1041 | - } |
|
| 1029 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1030 | + if ($length) { |
|
| 1031 | + return substr($c, $start, $length); |
|
| 1032 | + } else { |
|
| 1033 | + return substr($c, $start); |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + if ($length) { |
|
| 1038 | + return mb_substr($c, $start, $length); |
|
| 1039 | + } else { |
|
| 1040 | + return mb_substr($c, $start); |
|
| 1041 | + } |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1052,13 +1052,13 @@ discard block |
||
| 1052 | 1052 | * La chaîne avec une majuscule sur le premier mot |
| 1053 | 1053 | */ |
| 1054 | 1054 | function spip_ucfirst($c) { |
| 1055 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1056 | - return ucfirst($c); |
|
| 1057 | - } |
|
| 1055 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1056 | + return ucfirst($c); |
|
| 1057 | + } |
|
| 1058 | 1058 | |
| 1059 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1059 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1060 | 1060 | |
| 1061 | - return $lettre1 . spip_substr($c, 1); |
|
| 1061 | + return $lettre1 . spip_substr($c, 1); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -1072,11 +1072,11 @@ discard block |
||
| 1072 | 1072 | * La chaîne en minuscules |
| 1073 | 1073 | */ |
| 1074 | 1074 | function spip_strtolower($c) { |
| 1075 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1076 | - return strtolower($c); |
|
| 1077 | - } |
|
| 1075 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1076 | + return strtolower($c); |
|
| 1077 | + } |
|
| 1078 | 1078 | |
| 1079 | - return mb_strtolower($c); |
|
| 1079 | + return mb_strtolower($c); |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1090,15 +1090,15 @@ discard block |
||
| 1090 | 1090 | * Longueur de la chaîne |
| 1091 | 1091 | */ |
| 1092 | 1092 | function spip_strlen($c) { |
| 1093 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1094 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1093 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1094 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1095 | 1095 | |
| 1096 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1097 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1098 | - return strlen($c); |
|
| 1099 | - } |
|
| 1096 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1097 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1098 | + return strlen($c); |
|
| 1099 | + } |
|
| 1100 | 1100 | |
| 1101 | - return mb_strlen($c); |
|
| 1101 | + return mb_strlen($c); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | /** |
@@ -1113,17 +1113,17 @@ discard block |
||
| 1113 | 1113 | * en unicode : 💩 |
| 1114 | 1114 | */ |
| 1115 | 1115 | function utf8_noplanes($x): string { |
| 1116 | - $regexp_utf8_4bytes = '/( |
|
| 1116 | + $regexp_utf8_4bytes = '/( |
|
| 1117 | 1117 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1118 | 1118 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1119 | 1119 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1120 | 1120 | )/xS'; |
| 1121 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1122 | - foreach ($z[0] as $k) { |
|
| 1123 | - $ku = utf_8_to_unicode($k); |
|
| 1124 | - $x = str_replace($k, $ku, $x); |
|
| 1125 | - } |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - return $x; |
|
| 1121 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1122 | + foreach ($z[0] as $k) { |
|
| 1123 | + $ku = utf_8_to_unicode($k); |
|
| 1124 | + $x = str_replace($k, $ku, $x); |
|
| 1125 | + } |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + return $x; |
|
| 1129 | 1129 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,18 +44,18 @@ discard block |
||
| 44 | 44 | * Pile complétée par le code à générer |
| 45 | 45 | */ |
| 46 | 46 | function balise_BOITE_OUVRIR_dist($p) { |
| 47 | - $_titre = interprete_argument_balise(1, $p); |
|
| 48 | - $_class = interprete_argument_balise(2, $p); |
|
| 49 | - $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | - $_titre = ($_titre ?: "''"); |
|
| 51 | - $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | - $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | - |
|
| 54 | - $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | - $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | - $p->interdire_scripts = false; |
|
| 57 | - |
|
| 58 | - return $p; |
|
| 47 | + $_titre = interprete_argument_balise(1, $p); |
|
| 48 | + $_class = interprete_argument_balise(2, $p); |
|
| 49 | + $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | + $_titre = ($_titre ?: "''"); |
|
| 51 | + $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | + $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | + |
|
| 54 | + $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | + $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | + $p->interdire_scripts = false; |
|
| 57 | + |
|
| 58 | + return $p; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * Pile complétée par le code à générer |
| 76 | 76 | */ |
| 77 | 77 | function balise_BOITE_PIED_dist($p) { |
| 78 | - $_class = interprete_argument_balise(1, $p); |
|
| 79 | - $_class = ($_class ? "$_class" : ''); |
|
| 78 | + $_class = interprete_argument_balise(1, $p); |
|
| 79 | + $_class = ($_class ? "$_class" : ''); |
|
| 80 | 80 | |
| 81 | - $f = chercher_filtre('boite_pied'); |
|
| 82 | - $p->code = "$f($_class)"; |
|
| 83 | - $p->interdire_scripts = false; |
|
| 81 | + $f = chercher_filtre('boite_pied'); |
|
| 82 | + $p->code = "$f($_class)"; |
|
| 83 | + $p->interdire_scripts = false; |
|
| 84 | 84 | |
| 85 | - return $p; |
|
| 85 | + return $p; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * Pile complétée par le code à générer |
| 103 | 103 | */ |
| 104 | 104 | function balise_BOITE_FERMER_dist($p) { |
| 105 | - $f = chercher_filtre('boite_fermer'); |
|
| 106 | - $p->code = "$f()"; |
|
| 107 | - $p->interdire_scripts = false; |
|
| 105 | + $f = chercher_filtre('boite_fermer'); |
|
| 106 | + $p->code = "$f()"; |
|
| 107 | + $p->interdire_scripts = false; |
|
| 108 | 108 | |
| 109 | - return $p; |
|
| 109 | + return $p; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | * HTML du début de la boîte |
| 129 | 129 | */ |
| 130 | 130 | function boite_ouvrir($titre, $class = '', $head_class = '', $id = '') { |
| 131 | - $class = "box $class"; |
|
| 132 | - $head_class = "box__header $head_class clearfix"; |
|
| 133 | - // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | - if (test_espace_prive() and strlen($titre) and !str_contains($titre, '<h')) { |
|
| 135 | - $titre = "<h3>$titre</h3>"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | - . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | - . '<div class="box__body clearfix">'; |
|
| 131 | + $class = "box $class"; |
|
| 132 | + $head_class = "box__header $head_class clearfix"; |
|
| 133 | + // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | + if (test_espace_prive() and strlen($titre) and !str_contains($titre, '<h')) { |
|
| 135 | + $titre = "<h3>$titre</h3>"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | + . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | + . '<div class="box__body clearfix">'; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | * HTML de transition vers le pied de la boîte |
| 155 | 155 | */ |
| 156 | 156 | function boite_pied($class = 'act') { |
| 157 | - $class = "box__footer $class"; |
|
| 157 | + $class = "box__footer $class"; |
|
| 158 | 158 | |
| 159 | - return '</div>' |
|
| 160 | - . "<div class=\"$class clearfix\">"; |
|
| 159 | + return '</div>' |
|
| 160 | + . "<div class=\"$class clearfix\">"; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -172,6 +172,6 @@ discard block |
||
| 172 | 172 | * HTML de fin de la boîte |
| 173 | 173 | */ |
| 174 | 174 | function boite_fermer() { |
| 175 | - return '</div>' |
|
| 176 | - . '</div>'; |
|
| 175 | + return '</div>' |
|
| 176 | + . '</div>'; |
|
| 177 | 177 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 28 | - return; |
|
| 28 | + return; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** Version de l'API SQL */ |
@@ -45,39 +45,39 @@ discard block |
||
| 45 | 45 | * contexte de l'erreur |
| 46 | 46 | **/ |
| 47 | 47 | function sql_error_backtrace($compil_info = false) { |
| 48 | - $trace = debug_backtrace(); |
|
| 49 | - $caller = array_shift($trace); |
|
| 50 | - while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | - array_shift($trace); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($compil_info) { |
|
| 55 | - $contexte_compil = [ |
|
| 56 | - $trace[0]['file'],// sourcefile |
|
| 57 | - '', //nom |
|
| 58 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | - . $trace[0]['function'] . '();' |
|
| 60 | - . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | - $trace[0]['line'], // ligne |
|
| 62 | - $GLOBALS['spip_lang'], // lang |
|
| 63 | - ]; |
|
| 64 | - |
|
| 65 | - return $contexte_compil; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | - $f = []; |
|
| 70 | - while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | - if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | - break; |
|
| 73 | - } |
|
| 74 | - $f[] = $t['function']; |
|
| 75 | - } |
|
| 76 | - if (count($f)) { |
|
| 77 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $message; |
|
| 48 | + $trace = debug_backtrace(); |
|
| 49 | + $caller = array_shift($trace); |
|
| 50 | + while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | + array_shift($trace); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($compil_info) { |
|
| 55 | + $contexte_compil = [ |
|
| 56 | + $trace[0]['file'],// sourcefile |
|
| 57 | + '', //nom |
|
| 58 | + (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | + . $trace[0]['function'] . '();' |
|
| 60 | + . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | + $trace[0]['line'], // ligne |
|
| 62 | + $GLOBALS['spip_lang'], // lang |
|
| 63 | + ]; |
|
| 64 | + |
|
| 65 | + return $contexte_compil; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | + $f = []; |
|
| 70 | + while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | + if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | + break; |
|
| 73 | + } |
|
| 74 | + $f[] = $t['function']; |
|
| 75 | + } |
|
| 76 | + if (count($f)) { |
|
| 77 | + $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $message; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | **/ |
| 104 | 104 | function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
| 105 | - static $sql_serveur = []; |
|
| 106 | - if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | - $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | - if (!is_string($f) or !$f) { |
|
| 109 | - return $f; |
|
| 110 | - } |
|
| 111 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 105 | + static $sql_serveur = []; |
|
| 106 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | + $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | + if (!is_string($f) or !$f) { |
|
| 109 | + return $f; |
|
| 110 | + } |
|
| 111 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -133,23 +133,23 @@ discard block |
||
| 133 | 133 | * Retourne le nom du charset si effectivement trouvé, sinon false. |
| 134 | 134 | **/ |
| 135 | 135 | function sql_get_charset($charset, $serveur = '', $option = true) { |
| 136 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | - $desc = sql_serveur('', $serveur, true); |
|
| 138 | - $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | - $c = $desc['charsets'][$charset]; |
|
| 140 | - if ($c) { |
|
| 141 | - if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | - if ($f($c, $serveur, $option !== false)) { |
|
| 143 | - return $c; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - spip_log( |
|
| 148 | - "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | - _LOG_AVERTISSEMENT |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - return false; |
|
| 136 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | + $desc = sql_serveur('', $serveur, true); |
|
| 138 | + $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | + $c = $desc['charsets'][$charset]; |
|
| 140 | + if ($c) { |
|
| 141 | + if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | + if ($f($c, $serveur, $option !== false)) { |
|
| 143 | + return $c; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + spip_log( |
|
| 148 | + "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | + _LOG_AVERTISSEMENT |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + return false; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | * Retourne true si elle reussie. |
| 176 | 176 | **/ |
| 177 | 177 | function sql_set_charset($charset, $serveur = '', $option = true) { |
| 178 | - $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | - if (!is_string($f) or !$f) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 178 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | + if (!is_string($f) or !$f) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $f($charset, $serveur, $option !== false); |
|
| 183 | + return $f($charset, $serveur, $option !== false); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -231,59 +231,59 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | **/ |
| 233 | 233 | function sql_select( |
| 234 | - $select = [], |
|
| 235 | - $from = [], |
|
| 236 | - $where = [], |
|
| 237 | - $groupby = [], |
|
| 238 | - $orderby = [], |
|
| 239 | - $limit = '', |
|
| 240 | - $having = [], |
|
| 241 | - $serveur = '', |
|
| 242 | - $option = true |
|
| 234 | + $select = [], |
|
| 235 | + $from = [], |
|
| 236 | + $where = [], |
|
| 237 | + $groupby = [], |
|
| 238 | + $orderby = [], |
|
| 239 | + $limit = '', |
|
| 240 | + $having = [], |
|
| 241 | + $serveur = '', |
|
| 242 | + $option = true |
|
| 243 | 243 | ) { |
| 244 | - $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | - if (!is_string($f) or !$f) { |
|
| 246 | - return false; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | - if (($option !== false) and !$debug) { |
|
| 251 | - $res = $f( |
|
| 252 | - $select, |
|
| 253 | - $from, |
|
| 254 | - $where, |
|
| 255 | - $groupby, |
|
| 256 | - $orderby, |
|
| 257 | - $limit, |
|
| 258 | - $having, |
|
| 259 | - $serveur, |
|
| 260 | - is_array($option) ? true : $option |
|
| 261 | - ); |
|
| 262 | - } else { |
|
| 263 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | - if (!$option) { |
|
| 265 | - return $query; |
|
| 266 | - } |
|
| 267 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | - [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | - } |
|
| 273 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // en cas d'erreur |
|
| 277 | - if (!is_string($res)) { |
|
| 278 | - return $res; |
|
| 279 | - } |
|
| 280 | - // denoncer l'erreur SQL dans sa version brute |
|
| 281 | - spip_sql_erreur($serveur); |
|
| 282 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | - $contexte_compil = sql_error_backtrace(true); |
|
| 284 | - erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | - |
|
| 286 | - return false; |
|
| 244 | + $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | + if (!is_string($f) or !$f) { |
|
| 246 | + return false; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | + if (($option !== false) and !$debug) { |
|
| 251 | + $res = $f( |
|
| 252 | + $select, |
|
| 253 | + $from, |
|
| 254 | + $where, |
|
| 255 | + $groupby, |
|
| 256 | + $orderby, |
|
| 257 | + $limit, |
|
| 258 | + $having, |
|
| 259 | + $serveur, |
|
| 260 | + is_array($option) ? true : $option |
|
| 261 | + ); |
|
| 262 | + } else { |
|
| 263 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | + if (!$option) { |
|
| 265 | + return $query; |
|
| 266 | + } |
|
| 267 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | + [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | + } |
|
| 273 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // en cas d'erreur |
|
| 277 | + if (!is_string($res)) { |
|
| 278 | + return $res; |
|
| 279 | + } |
|
| 280 | + // denoncer l'erreur SQL dans sa version brute |
|
| 281 | + spip_sql_erreur($serveur); |
|
| 282 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | + $contexte_compil = sql_error_backtrace(true); |
|
| 284 | + erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | + |
|
| 286 | + return false; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -320,16 +320,16 @@ discard block |
||
| 320 | 320 | * |
| 321 | 321 | **/ |
| 322 | 322 | function sql_get_select( |
| 323 | - $select = [], |
|
| 324 | - $from = [], |
|
| 325 | - $where = [], |
|
| 326 | - $groupby = [], |
|
| 327 | - $orderby = [], |
|
| 328 | - $limit = '', |
|
| 329 | - $having = [], |
|
| 330 | - $serveur = '' |
|
| 323 | + $select = [], |
|
| 324 | + $from = [], |
|
| 325 | + $where = [], |
|
| 326 | + $groupby = [], |
|
| 327 | + $orderby = [], |
|
| 328 | + $limit = '', |
|
| 329 | + $having = [], |
|
| 330 | + $serveur = '' |
|
| 331 | 331 | ) { |
| 332 | - return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 332 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -373,23 +373,23 @@ discard block |
||
| 373 | 373 | * |
| 374 | 374 | **/ |
| 375 | 375 | function sql_countsel( |
| 376 | - $from = [], |
|
| 377 | - $where = [], |
|
| 378 | - $groupby = [], |
|
| 379 | - $having = [], |
|
| 380 | - $serveur = '', |
|
| 381 | - $option = true |
|
| 376 | + $from = [], |
|
| 377 | + $where = [], |
|
| 378 | + $groupby = [], |
|
| 379 | + $having = [], |
|
| 380 | + $serveur = '', |
|
| 381 | + $option = true |
|
| 382 | 382 | ) { |
| 383 | - $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | - if (!is_string($f) or !$f) { |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | - if ($r === false) { |
|
| 389 | - spip_sql_erreur($serveur); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $r; |
|
| 383 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | + if (!is_string($f) or !$f) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | + if ($r === false) { |
|
| 389 | + spip_sql_erreur($serveur); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $r; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -421,16 +421,16 @@ discard block |
||
| 421 | 421 | * Ce retour n'est pas pertinent pour savoir si l'opération est correctement réalisée. |
| 422 | 422 | **/ |
| 423 | 423 | function sql_alter($q, $serveur = '', $option = true) { |
| 424 | - $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | - if (!is_string($f) or !$f) { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - $r = $f($q, $serveur, $option !== false); |
|
| 429 | - if ($r === false) { |
|
| 430 | - spip_sql_erreur($serveur); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return $r; |
|
| 424 | + $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | + if (!is_string($f) or !$f) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + $r = $f($q, $serveur, $option !== false); |
|
| 429 | + if ($r === false) { |
|
| 430 | + spip_sql_erreur($serveur); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return $r; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -453,12 +453,12 @@ discard block |
||
| 453 | 453 | * presentant une ligne de resultat d'une selection |
| 454 | 454 | */ |
| 455 | 455 | function sql_fetch($res, $serveur = '', $option = true) { |
| 456 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | - if (!is_string($f) or !$f) { |
|
| 458 | - return false; |
|
| 459 | - } |
|
| 456 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | + if (!is_string($f) or !$f) { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - return $f($res, null, $serveur, $option !== false); |
|
| 461 | + return $f($res, null, $serveur, $option !== false); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | * presentant une ligne de resultat d'une selection |
| 486 | 486 | */ |
| 487 | 487 | function sql_fetch_all($res, $serveur = '', $option = true) { |
| 488 | - $rows = []; |
|
| 489 | - if (!$res) { |
|
| 490 | - return $rows; |
|
| 491 | - } |
|
| 492 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | - if (!is_string($f) or !$f) { |
|
| 494 | - return []; |
|
| 495 | - } |
|
| 496 | - while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | - $rows[] = $r; |
|
| 498 | - } |
|
| 499 | - sql_free($res, $serveur); |
|
| 500 | - |
|
| 501 | - return $rows; |
|
| 488 | + $rows = []; |
|
| 489 | + if (!$res) { |
|
| 490 | + return $rows; |
|
| 491 | + } |
|
| 492 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | + if (!is_string($f) or !$f) { |
|
| 494 | + return []; |
|
| 495 | + } |
|
| 496 | + while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | + $rows[] = $r; |
|
| 498 | + } |
|
| 499 | + sql_free($res, $serveur); |
|
| 500 | + |
|
| 501 | + return $rows; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -526,16 +526,16 @@ discard block |
||
| 526 | 526 | * Operation effectuée (true), sinon false. |
| 527 | 527 | **/ |
| 528 | 528 | function sql_seek($res, $row_number, $serveur = '', $option = true) { |
| 529 | - $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | - if (!is_string($f) or !$f) { |
|
| 531 | - return false; |
|
| 532 | - } |
|
| 533 | - $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | - if ($r === false) { |
|
| 535 | - spip_sql_erreur($serveur); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $r; |
|
| 529 | + $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | + if (!is_string($f) or !$f) { |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | + if ($r === false) { |
|
| 535 | + spip_sql_erreur($serveur); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $r; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | * False en cas d'erreur. |
| 561 | 561 | **/ |
| 562 | 562 | function sql_listdbs($serveur = '', $option = true) { |
| 563 | - $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | - if (!is_string($f) or !$f) { |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $r = $f($serveur); |
|
| 568 | - if ($r === false) { |
|
| 569 | - spip_sql_erreur($serveur); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $r; |
|
| 563 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | + if (!is_string($f) or !$f) { |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $r = $f($serveur); |
|
| 568 | + if ($r === false) { |
|
| 569 | + spip_sql_erreur($serveur); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $r; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
@@ -592,16 +592,16 @@ discard block |
||
| 592 | 592 | * - False en cas d'erreur. |
| 593 | 593 | **/ |
| 594 | 594 | function sql_selectdb($nom, $serveur = '', $option = true) { |
| 595 | - $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | - if (!is_string($f) or !$f) { |
|
| 597 | - return false; |
|
| 598 | - } |
|
| 599 | - $r = $f($nom, $serveur, $option !== false); |
|
| 600 | - if ($r === false) { |
|
| 601 | - spip_sql_erreur($serveur); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return $r; |
|
| 595 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | + if (!is_string($f) or !$f) { |
|
| 597 | + return false; |
|
| 598 | + } |
|
| 599 | + $r = $f($nom, $serveur, $option !== false); |
|
| 600 | + if ($r === false) { |
|
| 601 | + spip_sql_erreur($serveur); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return $r; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -626,16 +626,16 @@ discard block |
||
| 626 | 626 | * - false en cas d'erreur. |
| 627 | 627 | **/ |
| 628 | 628 | function sql_count($res, $serveur = '', $option = true) { |
| 629 | - $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | - if (!is_string($f) or !$f) { |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - $r = $f($res, $serveur, $option !== false); |
|
| 634 | - if ($r === false) { |
|
| 635 | - spip_sql_erreur($serveur); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return $r; |
|
| 629 | + $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | + if (!is_string($f) or !$f) { |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + $r = $f($res, $serveur, $option !== false); |
|
| 634 | + if ($r === false) { |
|
| 635 | + spip_sql_erreur($serveur); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return $r; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | * True si réussi |
| 658 | 658 | */ |
| 659 | 659 | function sql_free($res, $serveur = '', $option = true) { |
| 660 | - $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | - if (!is_string($f) or !$f) { |
|
| 662 | - return false; |
|
| 663 | - } |
|
| 660 | + $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | + if (!is_string($f) or !$f) { |
|
| 662 | + return false; |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - return $f($res); |
|
| 665 | + return $f($res); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -700,17 +700,17 @@ discard block |
||
| 700 | 700 | * - False en cas d'erreur. |
| 701 | 701 | **/ |
| 702 | 702 | function sql_insert($table, $noms, $valeurs, $desc = [], $serveur = '', $option = true) { |
| 703 | - $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | - if (!is_string($f) or !$f) { |
|
| 705 | - return false; |
|
| 706 | - } |
|
| 707 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | - if ($r === false or $r === null) { |
|
| 709 | - spip_sql_erreur($serveur); |
|
| 710 | - $r = false; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - return $r; |
|
| 703 | + $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | + if (!is_string($f) or !$f) { |
|
| 705 | + return false; |
|
| 706 | + } |
|
| 707 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | + if ($r === false or $r === null) { |
|
| 709 | + spip_sql_erreur($serveur); |
|
| 710 | + $r = false; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + return $r; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -751,17 +751,17 @@ discard block |
||
| 751 | 751 | * - False en cas d'erreur. |
| 752 | 752 | **/ |
| 753 | 753 | function sql_insertq($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 754 | - $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | - if (!is_string($f) or !$f) { |
|
| 756 | - return false; |
|
| 757 | - } |
|
| 758 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | - if ($r === false or $r === null) { |
|
| 760 | - spip_sql_erreur($serveur); |
|
| 761 | - $r = false; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - return $r; |
|
| 754 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | + if (!is_string($f) or !$f) { |
|
| 756 | + return false; |
|
| 757 | + } |
|
| 758 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | + if ($r === false or $r === null) { |
|
| 760 | + spip_sql_erreur($serveur); |
|
| 761 | + $r = false; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return $r; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -796,17 +796,17 @@ discard block |
||
| 796 | 796 | * - false en cas d'erreur. |
| 797 | 797 | **/ |
| 798 | 798 | function sql_insertq_multi($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 799 | - $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | - if (!is_string($f) or !$f) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | - if ($r === false or $r === null) { |
|
| 805 | - spip_sql_erreur($serveur); |
|
| 806 | - $r = false; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $r; |
|
| 799 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | + if (!is_string($f) or !$f) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | + if ($r === false or $r === null) { |
|
| 805 | + spip_sql_erreur($serveur); |
|
| 806 | + $r = false; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $r; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -846,16 +846,16 @@ discard block |
||
| 846 | 846 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 847 | 847 | */ |
| 848 | 848 | function sql_update($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 849 | - $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | - if (!is_string($f) or !$f) { |
|
| 851 | - return false; |
|
| 852 | - } |
|
| 853 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | - if ($r === false) { |
|
| 855 | - spip_sql_erreur($serveur); |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return $r; |
|
| 849 | + $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | + if (!is_string($f) or !$f) { |
|
| 851 | + return false; |
|
| 852 | + } |
|
| 853 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | + if ($r === false) { |
|
| 855 | + spip_sql_erreur($serveur); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return $r; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | |
@@ -901,16 +901,16 @@ discard block |
||
| 901 | 901 | * - false en cas d'erreur. |
| 902 | 902 | **/ |
| 903 | 903 | function sql_updateq($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 904 | - $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | - if (!is_string($f) or !$f) { |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | - if ($r === false) { |
|
| 910 | - spip_sql_erreur($serveur); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - return $r; |
|
| 904 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | + if (!is_string($f) or !$f) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | + if ($r === false) { |
|
| 910 | + spip_sql_erreur($serveur); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + return $r; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
@@ -941,16 +941,16 @@ discard block |
||
| 941 | 941 | * - false en cas d'erreur. |
| 942 | 942 | **/ |
| 943 | 943 | function sql_delete($table, $where = '', $serveur = '', $option = true) { |
| 944 | - $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | - if (!is_string($f) or !$f) { |
|
| 946 | - return false; |
|
| 947 | - } |
|
| 948 | - $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | - if ($r === false) { |
|
| 950 | - spip_sql_erreur($serveur); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - return $r; |
|
| 944 | + $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | + if (!is_string($f) or !$f) { |
|
| 946 | + return false; |
|
| 947 | + } |
|
| 948 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | + if ($r === false) { |
|
| 950 | + spip_sql_erreur($serveur); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + return $r; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
@@ -986,16 +986,16 @@ discard block |
||
| 986 | 986 | * - false en cas d'erreur. |
| 987 | 987 | **/ |
| 988 | 988 | function sql_replace($table, $couples, $desc = [], $serveur = '', $option = true) { |
| 989 | - $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | - if (!is_string($f) or !$f) { |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | - if ($r === false) { |
|
| 995 | - spip_sql_erreur($serveur); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - return $r; |
|
| 989 | + $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | + if (!is_string($f) or !$f) { |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | + if ($r === false) { |
|
| 995 | + spip_sql_erreur($serveur); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + return $r; |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | |
@@ -1033,16 +1033,16 @@ discard block |
||
| 1033 | 1033 | * - false en cas d'erreur. |
| 1034 | 1034 | **/ |
| 1035 | 1035 | function sql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $option = true) { |
| 1036 | - $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | - if (!is_string($f) or !$f) { |
|
| 1038 | - return false; |
|
| 1039 | - } |
|
| 1040 | - $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | - if ($r === false) { |
|
| 1042 | - spip_sql_erreur($serveur); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return $r; |
|
| 1036 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | + if (!is_string($f) or !$f) { |
|
| 1038 | + return false; |
|
| 1039 | + } |
|
| 1040 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | + if ($r === false) { |
|
| 1042 | + spip_sql_erreur($serveur); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return $r; |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1070,16 +1070,16 @@ discard block |
||
| 1070 | 1070 | * - false en cas d'erreur. |
| 1071 | 1071 | **/ |
| 1072 | 1072 | function sql_drop_table($table, $exist = '', $serveur = '', $option = true) { |
| 1073 | - $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | - if (!is_string($f) or !$f) { |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | - if ($r === false) { |
|
| 1079 | - spip_sql_erreur($serveur); |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - return $r; |
|
| 1073 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | + if (!is_string($f) or !$f) { |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | + if ($r === false) { |
|
| 1079 | + spip_sql_erreur($serveur); |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + return $r; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * - true si la requête a réussie, false sinon |
| 1104 | 1104 | */ |
| 1105 | 1105 | function sql_drop_view($table, $exist = '', $serveur = '', $option = true) { |
| 1106 | - $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | - if (!is_string($f) or !$f) { |
|
| 1108 | - return false; |
|
| 1109 | - } |
|
| 1110 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | - if ($r === false) { |
|
| 1112 | - spip_sql_erreur($serveur); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - return $r; |
|
| 1106 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | + if (!is_string($f) or !$f) { |
|
| 1108 | + return false; |
|
| 1109 | + } |
|
| 1110 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | + if ($r === false) { |
|
| 1112 | + spip_sql_erreur($serveur); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + return $r; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1136,18 +1136,18 @@ discard block |
||
| 1136 | 1136 | * Ressource à utiliser avec sql_fetch() |
| 1137 | 1137 | **/ |
| 1138 | 1138 | function sql_showbase($spip = null, $serveur = '', $option = true) { |
| 1139 | - $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | - if (!is_string($f) or !$f) { |
|
| 1141 | - return false; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | - if ($spip == null) { |
|
| 1146 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - return $f($spip, $serveur, $option !== false); |
|
| 1139 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | + if (!is_string($f) or !$f) { |
|
| 1141 | + return false; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | + if ($spip == null) { |
|
| 1146 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + return $f($spip, $serveur, $option !== false); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1170,15 +1170,15 @@ discard block |
||
| 1170 | 1170 | * Liste des tables SQL |
| 1171 | 1171 | **/ |
| 1172 | 1172 | function sql_alltable($spip = null, $serveur = '', $option = true) { |
| 1173 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | - $r = []; |
|
| 1175 | - if ($q) { |
|
| 1176 | - while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | - $r[] = array_shift($t); |
|
| 1178 | - } |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return $r; |
|
| 1173 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | + $r = []; |
|
| 1175 | + if ($q) { |
|
| 1176 | + while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | + $r[] = array_shift($t); |
|
| 1178 | + } |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + return $r; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1211,31 +1211,31 @@ discard block |
||
| 1211 | 1211 | * - 'join' => array() // jointures, si déclarées. |
| 1212 | 1212 | **/ |
| 1213 | 1213 | function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) { |
| 1214 | - $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | - if (!is_string($f) or !$f) { |
|
| 1216 | - return false; |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | - if ($table_spip) { |
|
| 1221 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | - $prefixe = $connexion['prefixe']; |
|
| 1223 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | - } else { |
|
| 1225 | - $vraie_table = $table; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | - if (!$f) { |
|
| 1230 | - return []; |
|
| 1231 | - } |
|
| 1232 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - return $f; |
|
| 1214 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | + if (!is_string($f) or !$f) { |
|
| 1216 | + return false; |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | + if ($table_spip) { |
|
| 1221 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | + $prefixe = $connexion['prefixe']; |
|
| 1223 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | + } else { |
|
| 1225 | + $vraie_table = $table; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | + if (!$f) { |
|
| 1230 | + return []; |
|
| 1231 | + } |
|
| 1232 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + return $f; |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | |
@@ -1262,21 +1262,21 @@ discard block |
||
| 1262 | 1262 | * - false en cas d'erreur. |
| 1263 | 1263 | **/ |
| 1264 | 1264 | function sql_table_exists(string $table, bool $table_spip = true, $serveur = '', $option = true) { |
| 1265 | - $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1266 | - if (!is_string($f) or !$f) { |
|
| 1267 | - return false; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1271 | - if ($table_spip) { |
|
| 1272 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1273 | - $prefixe = $connexion['prefixe']; |
|
| 1274 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1275 | - } else { |
|
| 1276 | - $vraie_table = $table; |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - return $f($vraie_table, $serveur, $option !== false); |
|
| 1265 | + $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1266 | + if (!is_string($f) or !$f) { |
|
| 1267 | + return false; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1271 | + if ($table_spip) { |
|
| 1272 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1273 | + $prefixe = $connexion['prefixe']; |
|
| 1274 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1275 | + } else { |
|
| 1276 | + $vraie_table = $table; |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + return $f($vraie_table, $serveur, $option !== false); |
|
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | |
@@ -1322,24 +1322,24 @@ discard block |
||
| 1322 | 1322 | * true si succès, false en cas d'echec |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function sql_create( |
| 1325 | - $nom, |
|
| 1326 | - $champs, |
|
| 1327 | - $cles = [], |
|
| 1328 | - $autoinc = false, |
|
| 1329 | - $temporary = false, |
|
| 1330 | - $serveur = '', |
|
| 1331 | - $option = true |
|
| 1325 | + $nom, |
|
| 1326 | + $champs, |
|
| 1327 | + $cles = [], |
|
| 1328 | + $autoinc = false, |
|
| 1329 | + $temporary = false, |
|
| 1330 | + $serveur = '', |
|
| 1331 | + $option = true |
|
| 1332 | 1332 | ) { |
| 1333 | - $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1334 | - if (!is_string($f) or !$f) { |
|
| 1335 | - return false; |
|
| 1336 | - } |
|
| 1337 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1338 | - if ($r === false) { |
|
| 1339 | - spip_sql_erreur($serveur); |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - return $r; |
|
| 1333 | + $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1334 | + if (!is_string($f) or !$f) { |
|
| 1335 | + return false; |
|
| 1336 | + } |
|
| 1337 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1338 | + if ($r === false) { |
|
| 1339 | + spip_sql_erreur($serveur); |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + return $r; |
|
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | /** |
@@ -1357,16 +1357,16 @@ discard block |
||
| 1357 | 1357 | * @return bool true si la base est créee. |
| 1358 | 1358 | **/ |
| 1359 | 1359 | function sql_create_base($nom, $serveur = '', $option = true) { |
| 1360 | - $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1361 | - if (!is_string($f) or !$f) { |
|
| 1362 | - return false; |
|
| 1363 | - } |
|
| 1364 | - $r = $f($nom, $serveur, $option !== false); |
|
| 1365 | - if ($r === false) { |
|
| 1366 | - spip_sql_erreur($serveur); |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - return $r; |
|
| 1360 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1361 | + if (!is_string($f) or !$f) { |
|
| 1362 | + return false; |
|
| 1363 | + } |
|
| 1364 | + $r = $f($nom, $serveur, $option !== false); |
|
| 1365 | + if ($r === false) { |
|
| 1366 | + spip_sql_erreur($serveur); |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + return $r; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | |
@@ -1396,16 +1396,16 @@ discard block |
||
| 1396 | 1396 | * - false en cas d'échec. |
| 1397 | 1397 | **/ |
| 1398 | 1398 | function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
| 1399 | - $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1400 | - if (!is_string($f) or !$f) { |
|
| 1401 | - return false; |
|
| 1402 | - } |
|
| 1403 | - $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1404 | - if ($r === false) { |
|
| 1405 | - spip_sql_erreur($serveur); |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - return $r; |
|
| 1399 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1400 | + if (!is_string($f) or !$f) { |
|
| 1401 | + return false; |
|
| 1402 | + } |
|
| 1403 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1404 | + if ($r === false) { |
|
| 1405 | + spip_sql_erreur($serveur); |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + return $r; |
|
| 1409 | 1409 | } |
| 1410 | 1410 | |
| 1411 | 1411 | /** |
@@ -1434,12 +1434,12 @@ discard block |
||
| 1434 | 1434 | * texte de sélection pour la requête |
| 1435 | 1435 | */ |
| 1436 | 1436 | function sql_multi($sel, $lang, $serveur = '', $option = true) { |
| 1437 | - $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1438 | - if (!is_string($f) or !$f) { |
|
| 1439 | - return false; |
|
| 1440 | - } |
|
| 1437 | + $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1438 | + if (!is_string($f) or !$f) { |
|
| 1439 | + return false; |
|
| 1440 | + } |
|
| 1441 | 1441 | |
| 1442 | - return $f($sel, $lang); |
|
| 1442 | + return $f($sel, $lang); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | |
@@ -1454,12 +1454,12 @@ discard block |
||
| 1454 | 1454 | * False si le serveur est indisponible |
| 1455 | 1455 | */ |
| 1456 | 1456 | function sql_error($serveur = '') { |
| 1457 | - $f = sql_serveur('error', $serveur, true); |
|
| 1458 | - if (!is_string($f) or !$f) { |
|
| 1459 | - return false; |
|
| 1460 | - } |
|
| 1457 | + $f = sql_serveur('error', $serveur, true); |
|
| 1458 | + if (!is_string($f) or !$f) { |
|
| 1459 | + return false; |
|
| 1460 | + } |
|
| 1461 | 1461 | |
| 1462 | - return $f('query inconnue', $serveur); |
|
| 1462 | + return $f('query inconnue', $serveur); |
|
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | 1465 | /** |
@@ -1473,12 +1473,12 @@ discard block |
||
| 1473 | 1473 | * False si le serveur est indisponible |
| 1474 | 1474 | */ |
| 1475 | 1475 | function sql_errno($serveur = '') { |
| 1476 | - $f = sql_serveur('errno', $serveur, true); |
|
| 1477 | - if (!is_string($f) or !$f) { |
|
| 1478 | - return false; |
|
| 1479 | - } |
|
| 1476 | + $f = sql_serveur('errno', $serveur, true); |
|
| 1477 | + if (!is_string($f) or !$f) { |
|
| 1478 | + return false; |
|
| 1479 | + } |
|
| 1480 | 1480 | |
| 1481 | - return $f($serveur); |
|
| 1481 | + return $f($serveur); |
|
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | /** |
@@ -1496,16 +1496,16 @@ discard block |
||
| 1496 | 1496 | * @return array|false Tableau de l'explication |
| 1497 | 1497 | */ |
| 1498 | 1498 | function sql_explain($q, $serveur = '', $option = true) { |
| 1499 | - $f = sql_serveur('explain', $serveur, true); |
|
| 1500 | - if (!is_string($f) or !$f) { |
|
| 1501 | - return false; |
|
| 1502 | - } |
|
| 1503 | - $r = $f($q, $serveur, $option !== false); |
|
| 1504 | - if ($r === false) { |
|
| 1505 | - spip_sql_erreur($serveur); |
|
| 1506 | - } |
|
| 1507 | - |
|
| 1508 | - return $r; |
|
| 1499 | + $f = sql_serveur('explain', $serveur, true); |
|
| 1500 | + if (!is_string($f) or !$f) { |
|
| 1501 | + return false; |
|
| 1502 | + } |
|
| 1503 | + $r = $f($q, $serveur, $option !== false); |
|
| 1504 | + if ($r === false) { |
|
| 1505 | + spip_sql_erreur($serveur); |
|
| 1506 | + } |
|
| 1507 | + |
|
| 1508 | + return $r; |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | /** |
@@ -1523,16 +1523,16 @@ discard block |
||
| 1523 | 1523 | * @return bool Toujours true |
| 1524 | 1524 | */ |
| 1525 | 1525 | function sql_optimize($table, $serveur = '', $option = true) { |
| 1526 | - $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1527 | - if (!is_string($f) or !$f) { |
|
| 1528 | - return false; |
|
| 1529 | - } |
|
| 1530 | - $r = $f($table, $serveur, $option !== false); |
|
| 1531 | - if ($r === false) { |
|
| 1532 | - spip_sql_erreur($serveur); |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - return $r; |
|
| 1526 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1527 | + if (!is_string($f) or !$f) { |
|
| 1528 | + return false; |
|
| 1529 | + } |
|
| 1530 | + $r = $f($table, $serveur, $option !== false); |
|
| 1531 | + if ($r === false) { |
|
| 1532 | + spip_sql_erreur($serveur); |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + return $r; |
|
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | 1538 | /** |
@@ -1552,16 +1552,16 @@ discard block |
||
| 1552 | 1552 | * - true si la requête a réussie, false sinon |
| 1553 | 1553 | */ |
| 1554 | 1554 | function sql_repair($table, $serveur = '', $option = true) { |
| 1555 | - $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1556 | - if (!is_string($f) or !$f) { |
|
| 1557 | - return false; |
|
| 1558 | - } |
|
| 1559 | - $r = $f($table, $serveur, $option !== false); |
|
| 1560 | - if ($r === false) { |
|
| 1561 | - spip_sql_erreur($serveur); |
|
| 1562 | - } |
|
| 1563 | - |
|
| 1564 | - return $r; |
|
| 1555 | + $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1556 | + if (!is_string($f) or !$f) { |
|
| 1557 | + return false; |
|
| 1558 | + } |
|
| 1559 | + $r = $f($table, $serveur, $option !== false); |
|
| 1560 | + if ($r === false) { |
|
| 1561 | + spip_sql_erreur($serveur); |
|
| 1562 | + } |
|
| 1563 | + |
|
| 1564 | + return $r; |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | |
@@ -1586,16 +1586,16 @@ discard block |
||
| 1586 | 1586 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1587 | 1587 | */ |
| 1588 | 1588 | function sql_query($ins, $serveur = '', $option = true) { |
| 1589 | - $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1590 | - if (!is_string($f) or !$f) { |
|
| 1591 | - return false; |
|
| 1592 | - } |
|
| 1593 | - $r = $f($ins, $serveur, $option !== false); |
|
| 1594 | - if ($r === false) { |
|
| 1595 | - spip_sql_erreur($serveur); |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - return $r; |
|
| 1589 | + $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1590 | + if (!is_string($f) or !$f) { |
|
| 1591 | + return false; |
|
| 1592 | + } |
|
| 1593 | + $r = $f($ins, $serveur, $option !== false); |
|
| 1594 | + if ($r === false) { |
|
| 1595 | + spip_sql_erreur($serveur); |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + return $r; |
|
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | 1601 | /** |
@@ -1643,27 +1643,27 @@ discard block |
||
| 1643 | 1643 | * |
| 1644 | 1644 | **/ |
| 1645 | 1645 | function sql_fetsel( |
| 1646 | - $select = [], |
|
| 1647 | - $from = [], |
|
| 1648 | - $where = [], |
|
| 1649 | - $groupby = [], |
|
| 1650 | - $orderby = [], |
|
| 1651 | - $limit = '', |
|
| 1652 | - $having = [], |
|
| 1653 | - $serveur = '', |
|
| 1654 | - $option = true |
|
| 1646 | + $select = [], |
|
| 1647 | + $from = [], |
|
| 1648 | + $where = [], |
|
| 1649 | + $groupby = [], |
|
| 1650 | + $orderby = [], |
|
| 1651 | + $limit = '', |
|
| 1652 | + $having = [], |
|
| 1653 | + $serveur = '', |
|
| 1654 | + $option = true |
|
| 1655 | 1655 | ) { |
| 1656 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1657 | - if ($option === false) { |
|
| 1658 | - return $q; |
|
| 1659 | - } |
|
| 1660 | - if (!$q) { |
|
| 1661 | - return []; |
|
| 1662 | - } |
|
| 1663 | - $r = sql_fetch($q, $serveur, $option); |
|
| 1664 | - sql_free($q, $serveur, $option); |
|
| 1665 | - |
|
| 1666 | - return $r; |
|
| 1656 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1657 | + if ($option === false) { |
|
| 1658 | + return $q; |
|
| 1659 | + } |
|
| 1660 | + if (!$q) { |
|
| 1661 | + return []; |
|
| 1662 | + } |
|
| 1663 | + $r = sql_fetch($q, $serveur, $option); |
|
| 1664 | + sql_free($q, $serveur, $option); |
|
| 1665 | + |
|
| 1666 | + return $r; |
|
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | 1669 | |
@@ -1720,22 +1720,22 @@ discard block |
||
| 1720 | 1720 | * |
| 1721 | 1721 | **/ |
| 1722 | 1722 | function sql_allfetsel( |
| 1723 | - $select = [], |
|
| 1724 | - $from = [], |
|
| 1725 | - $where = [], |
|
| 1726 | - $groupby = [], |
|
| 1727 | - $orderby = [], |
|
| 1728 | - $limit = '', |
|
| 1729 | - $having = [], |
|
| 1730 | - $serveur = '', |
|
| 1731 | - $option = true |
|
| 1723 | + $select = [], |
|
| 1724 | + $from = [], |
|
| 1725 | + $where = [], |
|
| 1726 | + $groupby = [], |
|
| 1727 | + $orderby = [], |
|
| 1728 | + $limit = '', |
|
| 1729 | + $having = [], |
|
| 1730 | + $serveur = '', |
|
| 1731 | + $option = true |
|
| 1732 | 1732 | ) { |
| 1733 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1734 | - if ($option === false) { |
|
| 1735 | - return $q; |
|
| 1736 | - } |
|
| 1733 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1734 | + if ($option === false) { |
|
| 1735 | + return $q; |
|
| 1736 | + } |
|
| 1737 | 1737 | |
| 1738 | - return sql_fetch_all($q, $serveur, $option); |
|
| 1738 | + return sql_fetch_all($q, $serveur, $option); |
|
| 1739 | 1739 | } |
| 1740 | 1740 | |
| 1741 | 1741 | |
@@ -1782,33 +1782,33 @@ discard block |
||
| 1782 | 1782 | * |
| 1783 | 1783 | **/ |
| 1784 | 1784 | function sql_getfetsel( |
| 1785 | - $select, |
|
| 1786 | - $from = [], |
|
| 1787 | - $where = [], |
|
| 1788 | - $groupby = [], |
|
| 1789 | - $orderby = [], |
|
| 1790 | - $limit = '', |
|
| 1791 | - $having = [], |
|
| 1792 | - $serveur = '', |
|
| 1793 | - $option = true |
|
| 1785 | + $select, |
|
| 1786 | + $from = [], |
|
| 1787 | + $where = [], |
|
| 1788 | + $groupby = [], |
|
| 1789 | + $orderby = [], |
|
| 1790 | + $limit = '', |
|
| 1791 | + $having = [], |
|
| 1792 | + $serveur = '', |
|
| 1793 | + $option = true |
|
| 1794 | 1794 | ) { |
| 1795 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1796 | - $id = $c[1]; |
|
| 1797 | - } elseif (!preg_match('/\W/', $select)) { |
|
| 1798 | - $id = $select; |
|
| 1799 | - } else { |
|
| 1800 | - $id = 'n'; |
|
| 1801 | - $select .= ' AS n'; |
|
| 1802 | - } |
|
| 1803 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1804 | - if ($option === false) { |
|
| 1805 | - return $r; |
|
| 1806 | - } |
|
| 1807 | - if (!$r) { |
|
| 1808 | - return null; |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - return $r[$id]; |
|
| 1795 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1796 | + $id = $c[1]; |
|
| 1797 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1798 | + $id = $select; |
|
| 1799 | + } else { |
|
| 1800 | + $id = 'n'; |
|
| 1801 | + $select .= ' AS n'; |
|
| 1802 | + } |
|
| 1803 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1804 | + if ($option === false) { |
|
| 1805 | + return $r; |
|
| 1806 | + } |
|
| 1807 | + if (!$r) { |
|
| 1808 | + return null; |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + return $r[$id]; |
|
| 1812 | 1812 | } |
| 1813 | 1813 | |
| 1814 | 1814 | /** |
@@ -1826,9 +1826,9 @@ discard block |
||
| 1826 | 1826 | * Numero de version du serveur SQL |
| 1827 | 1827 | **/ |
| 1828 | 1828 | function sql_version($serveur = '', $option = true) { |
| 1829 | - $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1829 | + $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1830 | 1830 | |
| 1831 | - return ($row['n']); |
|
| 1831 | + return ($row['n']); |
|
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | 1834 | /** |
@@ -1864,16 +1864,16 @@ discard block |
||
| 1864 | 1864 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 1865 | 1865 | **/ |
| 1866 | 1866 | function sql_preferer_transaction($serveur = '', $option = true) { |
| 1867 | - $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1868 | - if (!is_string($f) or !$f) { |
|
| 1869 | - return false; |
|
| 1870 | - } |
|
| 1871 | - $r = $f($serveur, $option !== false); |
|
| 1872 | - if ($r === false) { |
|
| 1873 | - spip_sql_erreur($serveur); |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - return $r; |
|
| 1867 | + $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1868 | + if (!is_string($f) or !$f) { |
|
| 1869 | + return false; |
|
| 1870 | + } |
|
| 1871 | + $r = $f($serveur, $option !== false); |
|
| 1872 | + if ($r === false) { |
|
| 1873 | + spip_sql_erreur($serveur); |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + return $r; |
|
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | 1879 | ; |
@@ -1898,16 +1898,16 @@ discard block |
||
| 1898 | 1898 | * false en cas d'erreur |
| 1899 | 1899 | **/ |
| 1900 | 1900 | function sql_demarrer_transaction($serveur = '', $option = true) { |
| 1901 | - $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1902 | - if (!is_string($f) or !$f) { |
|
| 1903 | - return false; |
|
| 1904 | - } |
|
| 1905 | - $r = $f($serveur, $option !== false); |
|
| 1906 | - if ($r === false) { |
|
| 1907 | - spip_sql_erreur($serveur); |
|
| 1908 | - } |
|
| 1909 | - |
|
| 1910 | - return $r; |
|
| 1901 | + $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1902 | + if (!is_string($f) or !$f) { |
|
| 1903 | + return false; |
|
| 1904 | + } |
|
| 1905 | + $r = $f($serveur, $option !== false); |
|
| 1906 | + if ($r === false) { |
|
| 1907 | + spip_sql_erreur($serveur); |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + return $r; |
|
| 1911 | 1911 | } |
| 1912 | 1912 | |
| 1913 | 1913 | ; |
@@ -1932,16 +1932,16 @@ discard block |
||
| 1932 | 1932 | * false en cas d'erreur |
| 1933 | 1933 | **/ |
| 1934 | 1934 | function sql_terminer_transaction($serveur = '', $option = true) { |
| 1935 | - $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1936 | - if (!is_string($f) or !$f) { |
|
| 1937 | - return false; |
|
| 1938 | - } |
|
| 1939 | - $r = $f($serveur, $option !== false); |
|
| 1940 | - if ($r === false) { |
|
| 1941 | - spip_sql_erreur($serveur); |
|
| 1942 | - } |
|
| 1943 | - |
|
| 1944 | - return $r; |
|
| 1935 | + $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1936 | + if (!is_string($f) or !$f) { |
|
| 1937 | + return false; |
|
| 1938 | + } |
|
| 1939 | + $r = $f($serveur, $option !== false); |
|
| 1940 | + if ($r === false) { |
|
| 1941 | + spip_sql_erreur($serveur); |
|
| 1942 | + } |
|
| 1943 | + |
|
| 1944 | + return $r; |
|
| 1945 | 1945 | } |
| 1946 | 1946 | |
| 1947 | 1947 | ; |
@@ -1968,12 +1968,12 @@ discard block |
||
| 1968 | 1968 | * Valeur hexadécimale attendue par le serveur SQL |
| 1969 | 1969 | **/ |
| 1970 | 1970 | function sql_hex($val, $serveur = '', $option = true) { |
| 1971 | - $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1972 | - if (!is_string($f) or !$f) { |
|
| 1973 | - return false; |
|
| 1974 | - } |
|
| 1971 | + $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1972 | + if (!is_string($f) or !$f) { |
|
| 1973 | + return false; |
|
| 1974 | + } |
|
| 1975 | 1975 | |
| 1976 | - return $f($val); |
|
| 1976 | + return $f($val); |
|
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | 1979 | /** |
@@ -1999,12 +1999,12 @@ discard block |
||
| 1999 | 1999 | * La chaine echappee |
| 2000 | 2000 | **/ |
| 2001 | 2001 | function sql_quote($val, $serveur = '', $type = '') { |
| 2002 | - $f = sql_serveur('quote', $serveur, true); |
|
| 2003 | - if (!is_string($f) or !$f) { |
|
| 2004 | - $f = '_q'; |
|
| 2005 | - } |
|
| 2002 | + $f = sql_serveur('quote', $serveur, true); |
|
| 2003 | + if (!is_string($f) or !$f) { |
|
| 2004 | + $f = '_q'; |
|
| 2005 | + } |
|
| 2006 | 2006 | |
| 2007 | - return $f($val, $type); |
|
| 2007 | + return $f($val, $type); |
|
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | 2010 | /** |
@@ -2029,12 +2029,12 @@ discard block |
||
| 2029 | 2029 | * - false si le serveur SQL est indisponible |
| 2030 | 2030 | **/ |
| 2031 | 2031 | function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) { |
| 2032 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 2033 | - if (!is_string($f) or !$f) { |
|
| 2034 | - return false; |
|
| 2035 | - } |
|
| 2032 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 2033 | + if (!is_string($f) or !$f) { |
|
| 2034 | + return false; |
|
| 2035 | + } |
|
| 2036 | 2036 | |
| 2037 | - return $f($champ, $interval, $unite); |
|
| 2037 | + return $f($champ, $interval, $unite); |
|
| 2038 | 2038 | } |
| 2039 | 2039 | |
| 2040 | 2040 | /** |
@@ -2070,26 +2070,26 @@ discard block |
||
| 2070 | 2070 | * Expression de requête SQL |
| 2071 | 2071 | **/ |
| 2072 | 2072 | function sql_in_quote($champ, $valeurs, $not = '', $serveur = '', $type = '', $option = true) { |
| 2073 | - $quote = sql_serveur('quote', $serveur, true); |
|
| 2074 | - if (!is_string($quote) or !$quote) { |
|
| 2075 | - return false; |
|
| 2076 | - } |
|
| 2077 | - |
|
| 2078 | - // sql_quote produit une chaine dans tous les cas |
|
| 2079 | - $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2080 | - $valeurs = array_unique($valeurs); |
|
| 2081 | - $valeurs = $quote($valeurs, $type); |
|
| 2082 | - |
|
| 2083 | - if (!strlen(trim($valeurs))) { |
|
| 2084 | - return ($not ? '0=0' : '0=1'); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2088 | - if (!is_string($f) or !$f) { |
|
| 2089 | - return false; |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2073 | + $quote = sql_serveur('quote', $serveur, true); |
|
| 2074 | + if (!is_string($quote) or !$quote) { |
|
| 2075 | + return false; |
|
| 2076 | + } |
|
| 2077 | + |
|
| 2078 | + // sql_quote produit une chaine dans tous les cas |
|
| 2079 | + $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2080 | + $valeurs = array_unique($valeurs); |
|
| 2081 | + $valeurs = $quote($valeurs, $type); |
|
| 2082 | + |
|
| 2083 | + if (!strlen(trim($valeurs))) { |
|
| 2084 | + return ($not ? '0=0' : '0=1'); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2088 | + if (!is_string($f) or !$f) { |
|
| 2089 | + return false; |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | /** |
@@ -2106,19 +2106,19 @@ discard block |
||
| 2106 | 2106 | * @param bool $option |
| 2107 | 2107 | */ |
| 2108 | 2108 | function sql_in($champ, $valeurs, $not = '', $serveur = '', $option = true) { |
| 2109 | - $type = ''; |
|
| 2110 | - if (!is_array($valeurs)) { |
|
| 2111 | - $valeurs = strval($valeurs); |
|
| 2112 | - if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2113 | - $valeurs = substr($valeurs, 1); |
|
| 2114 | - } |
|
| 2115 | - // on explode en tableau pour pouvoir securiser le contenu |
|
| 2116 | - $valeurs = explode(',', $valeurs); |
|
| 2117 | - // et on force un cast de type int donc |
|
| 2118 | - $type = 'int'; |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2109 | + $type = ''; |
|
| 2110 | + if (!is_array($valeurs)) { |
|
| 2111 | + $valeurs = strval($valeurs); |
|
| 2112 | + if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2113 | + $valeurs = substr($valeurs, 1); |
|
| 2114 | + } |
|
| 2115 | + // on explode en tableau pour pouvoir securiser le contenu |
|
| 2116 | + $valeurs = explode(',', $valeurs); |
|
| 2117 | + // et on force un cast de type int donc |
|
| 2118 | + $type = 'int'; |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | 2124 | |
@@ -2159,24 +2159,24 @@ discard block |
||
| 2159 | 2159 | * Expression de requête SQL |
| 2160 | 2160 | **/ |
| 2161 | 2161 | function sql_in_select( |
| 2162 | - $in, |
|
| 2163 | - $select, |
|
| 2164 | - $from = [], |
|
| 2165 | - $where = [], |
|
| 2166 | - $groupby = [], |
|
| 2167 | - $orderby = [], |
|
| 2168 | - $limit = '', |
|
| 2169 | - $having = [], |
|
| 2170 | - $serveur = '' |
|
| 2162 | + $in, |
|
| 2163 | + $select, |
|
| 2164 | + $from = [], |
|
| 2165 | + $where = [], |
|
| 2166 | + $groupby = [], |
|
| 2167 | + $orderby = [], |
|
| 2168 | + $limit = '', |
|
| 2169 | + $having = [], |
|
| 2170 | + $serveur = '' |
|
| 2171 | 2171 | ) { |
| 2172 | - $liste = []; |
|
| 2173 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2174 | - while ($r = sql_fetch($res)) { |
|
| 2175 | - $liste[] = array_shift($r); |
|
| 2176 | - } |
|
| 2177 | - sql_free($res); |
|
| 2178 | - |
|
| 2179 | - return sql_in($in, $liste); |
|
| 2172 | + $liste = []; |
|
| 2173 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2174 | + while ($r = sql_fetch($res)) { |
|
| 2175 | + $liste[] = array_shift($r); |
|
| 2176 | + } |
|
| 2177 | + sql_free($res); |
|
| 2178 | + |
|
| 2179 | + return sql_in($in, $liste); |
|
| 2180 | 2180 | } |
| 2181 | 2181 | |
| 2182 | 2182 | /** |
@@ -2208,29 +2208,29 @@ discard block |
||
| 2208 | 2208 | * Position apres le saut. |
| 2209 | 2209 | */ |
| 2210 | 2210 | function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
| 2211 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2212 | - if (($saut = intval($saut)) <= 0) { |
|
| 2213 | - return $pos; |
|
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - $seek = $pos + $saut; |
|
| 2217 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 2218 | - // et on sort |
|
| 2219 | - if ($seek >= $count) { |
|
| 2220 | - sql_free($res, $serveur, $option); |
|
| 2221 | - |
|
| 2222 | - return $count; |
|
| 2223 | - } |
|
| 2224 | - |
|
| 2225 | - if (sql_seek($res, $seek)) { |
|
| 2226 | - $pos = $seek; |
|
| 2227 | - } else { |
|
| 2228 | - while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2229 | - $pos++; |
|
| 2230 | - } |
|
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - return $pos; |
|
| 2211 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2212 | + if (($saut = intval($saut)) <= 0) { |
|
| 2213 | + return $pos; |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + $seek = $pos + $saut; |
|
| 2217 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 2218 | + // et on sort |
|
| 2219 | + if ($seek >= $count) { |
|
| 2220 | + sql_free($res, $serveur, $option); |
|
| 2221 | + |
|
| 2222 | + return $count; |
|
| 2223 | + } |
|
| 2224 | + |
|
| 2225 | + if (sql_seek($res, $seek)) { |
|
| 2226 | + $pos = $seek; |
|
| 2227 | + } else { |
|
| 2228 | + while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2229 | + $pos++; |
|
| 2230 | + } |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + return $pos; |
|
| 2234 | 2234 | } |
| 2235 | 2235 | |
| 2236 | 2236 | |
@@ -2250,7 +2250,7 @@ discard block |
||
| 2250 | 2250 | * True si le champ est de type entier |
| 2251 | 2251 | */ |
| 2252 | 2252 | function sql_test_int($type, $serveur = '', $option = true) { |
| 2253 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2253 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | 2256 | /** |
@@ -2269,7 +2269,7 @@ discard block |
||
| 2269 | 2269 | * True si le champ est de type entier |
| 2270 | 2270 | */ |
| 2271 | 2271 | function sql_test_date($type, $serveur = '', $option = true) { |
| 2272 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2272 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2273 | 2273 | } |
| 2274 | 2274 | |
| 2275 | 2275 | /** |
@@ -2291,19 +2291,19 @@ discard block |
||
| 2291 | 2291 | * La date formatee |
| 2292 | 2292 | */ |
| 2293 | 2293 | function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
| 2294 | - $annee = sprintf('%04s', $annee); |
|
| 2295 | - $mois = sprintf('%02s', $mois); |
|
| 2296 | - |
|
| 2297 | - if ($annee == '0000') { |
|
| 2298 | - $mois = 0; |
|
| 2299 | - } |
|
| 2300 | - if ($mois == '00') { |
|
| 2301 | - $jour = 0; |
|
| 2302 | - } |
|
| 2303 | - |
|
| 2304 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2305 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2306 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2294 | + $annee = sprintf('%04s', $annee); |
|
| 2295 | + $mois = sprintf('%02s', $mois); |
|
| 2296 | + |
|
| 2297 | + if ($annee == '0000') { |
|
| 2298 | + $mois = 0; |
|
| 2299 | + } |
|
| 2300 | + if ($mois == '00') { |
|
| 2301 | + $jour = 0; |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2305 | + . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2306 | + . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2307 | 2307 | } |
| 2308 | 2308 | |
| 2309 | 2309 | |
@@ -2326,32 +2326,32 @@ discard block |
||
| 2326 | 2326 | **/ |
| 2327 | 2327 | function description_table($nom, $serveur = '') { |
| 2328 | 2328 | |
| 2329 | - static $trouver_table; |
|
| 2329 | + static $trouver_table; |
|
| 2330 | 2330 | |
| 2331 | - /* toujours utiliser trouver_table |
|
| 2331 | + /* toujours utiliser trouver_table |
|
| 2332 | 2332 | qui renverra la description theorique |
| 2333 | 2333 | car sinon on va se comporter differement selon que la table est declaree |
| 2334 | 2334 | ou non |
| 2335 | 2335 | */ |
| 2336 | - if (!$trouver_table) { |
|
| 2337 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2338 | - } |
|
| 2339 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2340 | - return $desc; |
|
| 2341 | - } |
|
| 2342 | - |
|
| 2343 | - // sauf a l'installation : |
|
| 2344 | - include_spip('base/serial'); |
|
| 2345 | - if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2346 | - return $GLOBALS['tables_principales'][$nom]; |
|
| 2347 | - } |
|
| 2348 | - |
|
| 2349 | - include_spip('base/auxiliaires'); |
|
| 2350 | - if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2351 | - return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2352 | - } |
|
| 2353 | - |
|
| 2354 | - return false; |
|
| 2336 | + if (!$trouver_table) { |
|
| 2337 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2338 | + } |
|
| 2339 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2340 | + return $desc; |
|
| 2341 | + } |
|
| 2342 | + |
|
| 2343 | + // sauf a l'installation : |
|
| 2344 | + include_spip('base/serial'); |
|
| 2345 | + if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2346 | + return $GLOBALS['tables_principales'][$nom]; |
|
| 2347 | + } |
|
| 2348 | + |
|
| 2349 | + include_spip('base/auxiliaires'); |
|
| 2350 | + if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2351 | + return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2352 | + } |
|
| 2353 | + |
|
| 2354 | + return false; |
|
| 2355 | 2355 | } |
| 2356 | 2356 | |
| 2357 | 2357 | /** |
@@ -2364,8 +2364,8 @@ discard block |
||
| 2364 | 2364 | * @return string Table sql éventuellement renommée |
| 2365 | 2365 | */ |
| 2366 | 2366 | function prefixer_table_spip($table, $prefixe) { |
| 2367 | - if ($prefixe) { |
|
| 2368 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2369 | - } |
|
| 2370 | - return $table; |
|
| 2367 | + if ($prefixe) { |
|
| 2368 | + $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2369 | + } |
|
| 2370 | + return $table; |
|
| 2371 | 2371 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Installation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/acces'); |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | 35 | function base_determine_autoinc($table, $desc = []) { |
| 36 | - if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | - $autoinc = true; |
|
| 38 | - } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | - $autoinc = false; |
|
| 40 | - } else { |
|
| 41 | - // essayer de faire au mieux ! |
|
| 42 | - $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | - and !str_contains($desc['key']['PRIMARY KEY'], ',') |
|
| 44 | - and !str_contains($desc['field'][$desc['key']['PRIMARY KEY']], 'default')); |
|
| 45 | - } |
|
| 36 | + if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | + $autoinc = true; |
|
| 38 | + } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | + $autoinc = false; |
|
| 40 | + } else { |
|
| 41 | + // essayer de faire au mieux ! |
|
| 42 | + $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | + and !str_contains($desc['key']['PRIMARY KEY'], ',') |
|
| 44 | + and !str_contains($desc['field'][$desc['key']['PRIMARY KEY']], 'default')); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $autoinc; |
|
| 47 | + return $autoinc; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -61,58 +61,58 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | function creer_ou_upgrader_table($table, $desc, $autoinc, $upgrade = false, $serveur = '') { |
| 64 | - #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | - $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | - #if (!$sql_desc) $sql_desc = false; |
|
| 67 | - #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | - if (!$sql_desc) { |
|
| 69 | - if ($autoinc === 'auto') { |
|
| 70 | - $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | - } |
|
| 72 | - #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | - if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | - } |
|
| 76 | - // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | - #if (!$sql_desc) $sql_desc = false; |
|
| 79 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | - if (!$sql_desc) { |
|
| 81 | - // on retente avec un sleep ? |
|
| 82 | - sleep(1); |
|
| 83 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | - #if (!$sql_desc) $sql_desc = false; |
|
| 86 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | - if (!$sql_desc) { |
|
| 88 | - spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | - // ajouter les champs manquants |
|
| 94 | - // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | - // c'est toujours a faire manuellement |
|
| 96 | - $last = ''; |
|
| 97 | - if (isset($desc['field'])) { |
|
| 98 | - foreach ($desc['field'] as $field => $type) { |
|
| 99 | - if (!isset($sql_desc['field'][$field])) { |
|
| 100 | - sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 101 | - } |
|
| 102 | - $last = $field; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - if (isset($desc['key'])) { |
|
| 106 | - foreach ($desc['key'] as $key => $type) { |
|
| 107 | - // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | - // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | - if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | - sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | - } |
|
| 112 | - $last = $field; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 64 | + #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | + $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | + #if (!$sql_desc) $sql_desc = false; |
|
| 67 | + #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | + if (!$sql_desc) { |
|
| 69 | + if ($autoinc === 'auto') { |
|
| 70 | + $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | + } |
|
| 72 | + #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | + if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | + } |
|
| 76 | + // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | + #if (!$sql_desc) $sql_desc = false; |
|
| 79 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | + if (!$sql_desc) { |
|
| 81 | + // on retente avec un sleep ? |
|
| 82 | + sleep(1); |
|
| 83 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | + #if (!$sql_desc) $sql_desc = false; |
|
| 86 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | + if (!$sql_desc) { |
|
| 88 | + spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | + // ajouter les champs manquants |
|
| 94 | + // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | + // c'est toujours a faire manuellement |
|
| 96 | + $last = ''; |
|
| 97 | + if (isset($desc['field'])) { |
|
| 98 | + foreach ($desc['field'] as $field => $type) { |
|
| 99 | + if (!isset($sql_desc['field'][$field])) { |
|
| 100 | + sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 101 | + } |
|
| 102 | + $last = $field; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + if (isset($desc['key'])) { |
|
| 106 | + foreach ($desc['key'] as $key => $type) { |
|
| 107 | + // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | + // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | + if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | + sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | + } |
|
| 112 | + $last = $field; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -134,26 +134,26 @@ discard block |
||
| 134 | 134 | * @return void |
| 135 | 135 | */ |
| 136 | 136 | function alterer_base($tables_inc, $tables_noinc, $up = false, $serveur = '') { |
| 137 | - if ($up === false) { |
|
| 138 | - $old = false; |
|
| 139 | - $up = []; |
|
| 140 | - } else { |
|
| 141 | - $old = true; |
|
| 142 | - if (!is_array($up)) { |
|
| 143 | - $up = [$up]; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - foreach ($tables_inc as $k => $v) { |
|
| 147 | - if (!$old or in_array($k, $up)) { |
|
| 148 | - creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 149 | - } |
|
| 150 | - } |
|
| 137 | + if ($up === false) { |
|
| 138 | + $old = false; |
|
| 139 | + $up = []; |
|
| 140 | + } else { |
|
| 141 | + $old = true; |
|
| 142 | + if (!is_array($up)) { |
|
| 143 | + $up = [$up]; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + foreach ($tables_inc as $k => $v) { |
|
| 147 | + if (!$old or in_array($k, $up)) { |
|
| 148 | + creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - foreach ($tables_noinc as $k => $v) { |
|
| 153 | - if (!$old or in_array($k, $up)) { |
|
| 154 | - creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 155 | - } |
|
| 156 | - } |
|
| 152 | + foreach ($tables_noinc as $k => $v) { |
|
| 153 | + if (!$old or in_array($k, $up)) { |
|
| 154 | + creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function creer_base($serveur = '') { |
| 175 | 175 | |
| 176 | - // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 177 | - // de la conformite de la base |
|
| 178 | - // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 176 | + // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 177 | + // de la conformite de la base |
|
| 178 | + // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 179 | 179 | |
| 180 | - alterer_base( |
|
| 181 | - lister_tables_principales(), |
|
| 182 | - lister_tables_auxiliaires(), |
|
| 183 | - false, |
|
| 184 | - $serveur |
|
| 185 | - ); |
|
| 180 | + alterer_base( |
|
| 181 | + lister_tables_principales(), |
|
| 182 | + lister_tables_auxiliaires(), |
|
| 183 | + false, |
|
| 184 | + $serveur |
|
| 185 | + ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | * @return void |
| 203 | 203 | */ |
| 204 | 204 | function maj_tables($upgrade_tables = [], $serveur = '') { |
| 205 | - alterer_base( |
|
| 206 | - lister_tables_principales(), |
|
| 207 | - lister_tables_auxiliaires(), |
|
| 208 | - $upgrade_tables, |
|
| 209 | - $serveur |
|
| 210 | - ); |
|
| 205 | + alterer_base( |
|
| 206 | + lister_tables_principales(), |
|
| 207 | + lister_tables_auxiliaires(), |
|
| 208 | + $upgrade_tables, |
|
| 209 | + $serveur |
|
| 210 | + ); |
|
| 211 | 211 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -24,222 +24,222 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function xml_entites_html($texte) { |
| 27 | - if ( |
|
| 28 | - !is_string($texte) or !$texte |
|
| 29 | - or strpbrk($texte, "&\"'<>") == false |
|
| 30 | - ) { |
|
| 31 | - return $texte; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | - include_spip('inc/filtres_mini'); |
|
| 36 | - } |
|
| 37 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | - |
|
| 39 | - return $texte; |
|
| 27 | + if ( |
|
| 28 | + !is_string($texte) or !$texte |
|
| 29 | + or strpbrk($texte, "&\"'<>") == false |
|
| 30 | + ) { |
|
| 31 | + return $texte; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | + include_spip('inc/filtres_mini'); |
|
| 36 | + } |
|
| 37 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | + |
|
| 39 | + return $texte; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function xml_debutElement($phraseur, $name, $attrs) { |
| 43 | - $depth = $phraseur->depth; |
|
| 44 | - |
|
| 45 | - $t = $phraseur->ouvrant[$depth] ?? ' '; |
|
| 46 | - // espace initial signifie: deja integree au resultat |
|
| 47 | - if ($t[0] != ' ') { |
|
| 48 | - $phraseur->res .= '<' . $t . '>'; |
|
| 49 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 50 | - } |
|
| 51 | - $t = $phraseur->contenu[$depth]; |
|
| 52 | - // n'indenter que s'il y a un separateur avant |
|
| 53 | - $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 54 | - $phraseur->contenu[$depth] = ''; |
|
| 55 | - $att = ''; |
|
| 56 | - $sep = ' '; |
|
| 57 | - foreach ($attrs as $k => $v) { |
|
| 58 | - $delim = !str_contains($v, "'") ? "'" : '"'; |
|
| 59 | - $val = xml_entites_html($v); |
|
| 60 | - $att .= $sep . $k . '=' . $delim |
|
| 61 | - . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 62 | - . $delim; |
|
| 63 | - $sep = "\n $depth"; |
|
| 64 | - } |
|
| 65 | - $phraseur->depth .= ' '; |
|
| 66 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 67 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | - $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 43 | + $depth = $phraseur->depth; |
|
| 44 | + |
|
| 45 | + $t = $phraseur->ouvrant[$depth] ?? ' '; |
|
| 46 | + // espace initial signifie: deja integree au resultat |
|
| 47 | + if ($t[0] != ' ') { |
|
| 48 | + $phraseur->res .= '<' . $t . '>'; |
|
| 49 | + $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 50 | + } |
|
| 51 | + $t = $phraseur->contenu[$depth]; |
|
| 52 | + // n'indenter que s'il y a un separateur avant |
|
| 53 | + $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 54 | + $phraseur->contenu[$depth] = ''; |
|
| 55 | + $att = ''; |
|
| 56 | + $sep = ' '; |
|
| 57 | + foreach ($attrs as $k => $v) { |
|
| 58 | + $delim = !str_contains($v, "'") ? "'" : '"'; |
|
| 59 | + $val = xml_entites_html($v); |
|
| 60 | + $att .= $sep . $k . '=' . $delim |
|
| 61 | + . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 62 | + . $delim; |
|
| 63 | + $sep = "\n $depth"; |
|
| 64 | + } |
|
| 65 | + $phraseur->depth .= ' '; |
|
| 66 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 67 | + $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | + $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function xml_finElement($phraseur, $name, $fusion_bal = false) { |
| 72 | - $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 73 | - |
|
| 74 | - if ($ouv[0] != ' ') { |
|
| 75 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | - } else { |
|
| 77 | - $ouv = ''; |
|
| 78 | - } |
|
| 79 | - $t = $phraseur->contenu[$phraseur->depth]; |
|
| 80 | - $phraseur->depth = substr($phraseur->depth, 2); |
|
| 81 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | - |
|
| 83 | - // fusion <balise></balise> en <balise />. |
|
| 84 | - // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 85 | - // en particulier pour les balises Script et A. |
|
| 86 | - // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 87 | - // (param fusion_bal) |
|
| 88 | - |
|
| 89 | - if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 90 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 91 | - } else { |
|
| 92 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 93 | - } |
|
| 72 | + $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 73 | + |
|
| 74 | + if ($ouv[0] != ' ') { |
|
| 75 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | + } else { |
|
| 77 | + $ouv = ''; |
|
| 78 | + } |
|
| 79 | + $t = $phraseur->contenu[$phraseur->depth]; |
|
| 80 | + $phraseur->depth = substr($phraseur->depth, 2); |
|
| 81 | + $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | + |
|
| 83 | + // fusion <balise></balise> en <balise />. |
|
| 84 | + // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 85 | + // en particulier pour les balises Script et A. |
|
| 86 | + // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 87 | + // (param fusion_bal) |
|
| 88 | + |
|
| 89 | + if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 90 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 91 | + } else { |
|
| 92 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function xml_textElement($phraseur, $data) { |
| 97 | - $depth = $phraseur->depth; |
|
| 98 | - $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 99 | - ? $data |
|
| 100 | - : xml_entites_html($data); |
|
| 97 | + $depth = $phraseur->depth; |
|
| 98 | + $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 99 | + ? $data |
|
| 100 | + : xml_entites_html($data); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function xml_piElement($phraseur, $target, $data) { |
| 104 | - $depth = $phraseur->depth; |
|
| 105 | - |
|
| 106 | - if (strtolower($target) != 'php') { |
|
| 107 | - $phraseur->contenu[$depth] .= $data; |
|
| 108 | - } else { |
|
| 109 | - ob_start(); |
|
| 110 | - eval($data); |
|
| 111 | - $data = ob_get_contents(); |
|
| 112 | - ob_end_clean(); |
|
| 113 | - $phraseur->contenu[$depth] .= $data; |
|
| 114 | - } |
|
| 104 | + $depth = $phraseur->depth; |
|
| 105 | + |
|
| 106 | + if (strtolower($target) != 'php') { |
|
| 107 | + $phraseur->contenu[$depth] .= $data; |
|
| 108 | + } else { |
|
| 109 | + ob_start(); |
|
| 110 | + eval($data); |
|
| 111 | + $data = ob_get_contents(); |
|
| 112 | + ob_end_clean(); |
|
| 113 | + $phraseur->contenu[$depth] .= $data; |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | function xml_defaultElement($phraseur, $data) { |
| 119 | - $depth = $phraseur->depth; |
|
| 119 | + $depth = $phraseur->depth; |
|
| 120 | 120 | |
| 121 | - if (!isset($phraseur->contenu[$depth])) { |
|
| 122 | - $phraseur->contenu[$depth] = ''; |
|
| 123 | - } |
|
| 124 | - $phraseur->contenu[$depth] .= $data; |
|
| 121 | + if (!isset($phraseur->contenu[$depth])) { |
|
| 122 | + $phraseur->contenu[$depth] = ''; |
|
| 123 | + } |
|
| 124 | + $phraseur->contenu[$depth] .= $data; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | function xml_parsestring($phraseur, $data) { |
| 128 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 129 | - |
|
| 130 | - if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 131 | - coordonnees_erreur( |
|
| 132 | - $phraseur, |
|
| 133 | - xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 134 | - . "<br />\n" . |
|
| 135 | - (!$phraseur->depth ? '' : |
|
| 136 | - ('(' . |
|
| 137 | - _T('erreur_balise_non_fermee') . |
|
| 138 | - ' <tt>' . |
|
| 139 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 140 | - '</tt> ' . |
|
| 141 | - _T('ligne') . |
|
| 142 | - ' ' . |
|
| 143 | - $phraseur->reperes[$phraseur->depth] . |
|
| 144 | - ") <br />\n")) |
|
| 145 | - ); |
|
| 146 | - } |
|
| 128 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 129 | + |
|
| 130 | + if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 131 | + coordonnees_erreur( |
|
| 132 | + $phraseur, |
|
| 133 | + xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 134 | + . "<br />\n" . |
|
| 135 | + (!$phraseur->depth ? '' : |
|
| 136 | + ('(' . |
|
| 137 | + _T('erreur_balise_non_fermee') . |
|
| 138 | + ' <tt>' . |
|
| 139 | + $phraseur->ouvrant[$phraseur->depth] . |
|
| 140 | + '</tt> ' . |
|
| 141 | + _T('ligne') . |
|
| 142 | + ' ' . |
|
| 143 | + $phraseur->reperes[$phraseur->depth] . |
|
| 144 | + ") <br />\n")) |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function coordonnees_erreur($phraseur, $msg) { |
| 150 | - $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 151 | - $phraseur->err[] = [ |
|
| 152 | - $msg, |
|
| 153 | - xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 154 | - xml_get_current_column_number($phraseur->sax) |
|
| 155 | - ]; |
|
| 150 | + $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 151 | + $phraseur->err[] = [ |
|
| 152 | + $msg, |
|
| 153 | + xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 154 | + xml_get_current_column_number($phraseur->sax) |
|
| 155 | + ]; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) { |
| 159 | - if (is_null($charset)) { |
|
| 160 | - $charset = $GLOBALS['meta']['charset']; |
|
| 161 | - } |
|
| 162 | - if ($apply) { |
|
| 163 | - ob_start(); |
|
| 164 | - if (is_array($apply)) { |
|
| 165 | - $r = $page(...$apply); |
|
| 166 | - } else { |
|
| 167 | - $r = $page(); |
|
| 168 | - } |
|
| 169 | - $page = ob_get_contents(); |
|
| 170 | - ob_end_clean(); |
|
| 171 | - // fonction sans aucun "echo", ca doit etre le resultat |
|
| 172 | - if (!$page) { |
|
| 173 | - $page = $r; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if (!$page) { |
|
| 178 | - return ''; |
|
| 179 | - } |
|
| 180 | - // charger la DTD et transcoder les entites, |
|
| 181 | - // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 182 | - if (!$doctype) { |
|
| 183 | - if (!$r = analyser_doctype($page)) { |
|
| 184 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 185 | - . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 186 | - $r = analyser_doctype($page); |
|
| 187 | - } |
|
| 188 | - [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null); |
|
| 189 | - $page = substr($page, strlen($entete)); |
|
| 190 | - } else { |
|
| 191 | - $avail = 'SYSTEM'; |
|
| 192 | - $grammaire = $doctype; |
|
| 193 | - $rotlvl = basename($grammaire); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - include_spip('xml/analyser_dtd'); |
|
| 197 | - $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 198 | - $page = sax_bug($page, $dtc, $charset); |
|
| 199 | - |
|
| 200 | - // compatibilite Tidy espace public |
|
| 201 | - if (!$phraseur) { |
|
| 202 | - $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 203 | - |
|
| 204 | - return $indenter_xml($page, $apply); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $xml_parser = xml_parser_create($charset); |
|
| 208 | - |
|
| 209 | - xml_set_element_handler( |
|
| 210 | - $xml_parser, |
|
| 211 | - [$phraseur, 'debutElement'], |
|
| 212 | - [$phraseur, 'finElement'] |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - xml_set_character_data_handler( |
|
| 216 | - $xml_parser, |
|
| 217 | - [$phraseur, 'textElement'] |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - xml_set_processing_instruction_handler( |
|
| 221 | - $xml_parser, |
|
| 222 | - [$phraseur, 'piElement'] |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - xml_set_default_handler( |
|
| 226 | - $xml_parser, |
|
| 227 | - [$phraseur, 'defaultElement'] |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 231 | - |
|
| 232 | - $phraseur->sax = $xml_parser; |
|
| 233 | - if (isset($entete)) { |
|
| 234 | - $phraseur->entete = $entete; |
|
| 235 | - } |
|
| 236 | - $phraseur->page = $page; |
|
| 237 | - $phraseur->dtc = $dtc; |
|
| 238 | - $phraseur->phraserTout($xml_parser, $page); |
|
| 239 | - xml_parser_free($xml_parser); |
|
| 240 | - $phraseur->sax = ''; |
|
| 241 | - |
|
| 242 | - return $phraseur; |
|
| 159 | + if (is_null($charset)) { |
|
| 160 | + $charset = $GLOBALS['meta']['charset']; |
|
| 161 | + } |
|
| 162 | + if ($apply) { |
|
| 163 | + ob_start(); |
|
| 164 | + if (is_array($apply)) { |
|
| 165 | + $r = $page(...$apply); |
|
| 166 | + } else { |
|
| 167 | + $r = $page(); |
|
| 168 | + } |
|
| 169 | + $page = ob_get_contents(); |
|
| 170 | + ob_end_clean(); |
|
| 171 | + // fonction sans aucun "echo", ca doit etre le resultat |
|
| 172 | + if (!$page) { |
|
| 173 | + $page = $r; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if (!$page) { |
|
| 178 | + return ''; |
|
| 179 | + } |
|
| 180 | + // charger la DTD et transcoder les entites, |
|
| 181 | + // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 182 | + if (!$doctype) { |
|
| 183 | + if (!$r = analyser_doctype($page)) { |
|
| 184 | + $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 185 | + . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 186 | + $r = analyser_doctype($page); |
|
| 187 | + } |
|
| 188 | + [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null); |
|
| 189 | + $page = substr($page, strlen($entete)); |
|
| 190 | + } else { |
|
| 191 | + $avail = 'SYSTEM'; |
|
| 192 | + $grammaire = $doctype; |
|
| 193 | + $rotlvl = basename($grammaire); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + include_spip('xml/analyser_dtd'); |
|
| 197 | + $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 198 | + $page = sax_bug($page, $dtc, $charset); |
|
| 199 | + |
|
| 200 | + // compatibilite Tidy espace public |
|
| 201 | + if (!$phraseur) { |
|
| 202 | + $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 203 | + |
|
| 204 | + return $indenter_xml($page, $apply); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $xml_parser = xml_parser_create($charset); |
|
| 208 | + |
|
| 209 | + xml_set_element_handler( |
|
| 210 | + $xml_parser, |
|
| 211 | + [$phraseur, 'debutElement'], |
|
| 212 | + [$phraseur, 'finElement'] |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + xml_set_character_data_handler( |
|
| 216 | + $xml_parser, |
|
| 217 | + [$phraseur, 'textElement'] |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + xml_set_processing_instruction_handler( |
|
| 221 | + $xml_parser, |
|
| 222 | + [$phraseur, 'piElement'] |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + xml_set_default_handler( |
|
| 226 | + $xml_parser, |
|
| 227 | + [$phraseur, 'defaultElement'] |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 231 | + |
|
| 232 | + $phraseur->sax = $xml_parser; |
|
| 233 | + if (isset($entete)) { |
|
| 234 | + $phraseur->entete = $entete; |
|
| 235 | + } |
|
| 236 | + $phraseur->page = $page; |
|
| 237 | + $phraseur->dtc = $dtc; |
|
| 238 | + $phraseur->phraserTout($xml_parser, $page); |
|
| 239 | + xml_parser_free($xml_parser); |
|
| 240 | + $phraseur->sax = ''; |
|
| 241 | + |
|
| 242 | + return $phraseur; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // SAX ne dit pas si une Entite est dans un attribut ou non. |
@@ -250,24 +250,24 @@ discard block |
||
| 250 | 250 | // sinon on se rabat sur ce qu'en connait SPIP en standard. |
| 251 | 251 | |
| 252 | 252 | function sax_bug($data, $dtc, $charset = null) { |
| 253 | - if (is_null($charset)) { |
|
| 254 | - $charset = $GLOBALS['meta']['charset']; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($dtc) { |
|
| 258 | - $trans = []; |
|
| 259 | - |
|
| 260 | - foreach ($dtc->entites as $k => $v) { |
|
| 261 | - if (!strpos(' amp lt gt quot ', (string) $k)) { |
|
| 262 | - $trans["&$k;"] = $v; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - $data = strtr($data, $trans); |
|
| 266 | - } else { |
|
| 267 | - $data = html2unicode($data, true); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return unicode2charset($data, $charset); |
|
| 253 | + if (is_null($charset)) { |
|
| 254 | + $charset = $GLOBALS['meta']['charset']; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($dtc) { |
|
| 258 | + $trans = []; |
|
| 259 | + |
|
| 260 | + foreach ($dtc->entites as $k => $v) { |
|
| 261 | + if (!strpos(' amp lt gt quot ', (string) $k)) { |
|
| 262 | + $trans["&$k;"] = $v; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + $data = strtr($data, $trans); |
|
| 266 | + } else { |
|
| 267 | + $data = html2unicode($data, true); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return unicode2charset($data, $charset); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut |
@@ -277,52 +277,52 @@ discard block |
||
| 277 | 277 | // les autres formats RSS n'ont pas de DTD, |
| 278 | 278 | // mais un XML Schema que SPIP ne fait pas encore lire. |
| 279 | 279 | function analyser_doctype($data) { |
| 280 | - if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 281 | - if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 282 | - [, $entete, $topelement] = $page; |
|
| 283 | - if ($topelement == 'rss') { |
|
| 284 | - return [ |
|
| 285 | - $entete, |
|
| 286 | - 'PUBLIC', |
|
| 287 | - _DOCTYPE_RSS, |
|
| 288 | - 'rss-0.91.dtd' |
|
| 289 | - ]; |
|
| 290 | - } else { |
|
| 291 | - $dtd = $topelement . '.dtd'; |
|
| 292 | - $f = find_in_path($dtd); |
|
| 293 | - if (file_exists($f)) { |
|
| 294 | - return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 299 | - |
|
| 300 | - return []; |
|
| 301 | - } |
|
| 302 | - [$entete, , $topelement, $avail, $suite] = $page; |
|
| 303 | - |
|
| 304 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 305 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 306 | - return []; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - [, $rotlvl, $suite] = $r; |
|
| 310 | - |
|
| 311 | - if (!$suite) { |
|
| 312 | - if ($avail != 'SYSTEM') { |
|
| 313 | - return []; |
|
| 314 | - } |
|
| 315 | - $grammaire = $rotlvl; |
|
| 316 | - $rotlvl = ''; |
|
| 317 | - } else { |
|
| 318 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 319 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 320 | - return []; |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - $grammaire = $r[1]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 280 | + if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 281 | + if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 282 | + [, $entete, $topelement] = $page; |
|
| 283 | + if ($topelement == 'rss') { |
|
| 284 | + return [ |
|
| 285 | + $entete, |
|
| 286 | + 'PUBLIC', |
|
| 287 | + _DOCTYPE_RSS, |
|
| 288 | + 'rss-0.91.dtd' |
|
| 289 | + ]; |
|
| 290 | + } else { |
|
| 291 | + $dtd = $topelement . '.dtd'; |
|
| 292 | + $f = find_in_path($dtd); |
|
| 293 | + if (file_exists($f)) { |
|
| 294 | + return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 299 | + |
|
| 300 | + return []; |
|
| 301 | + } |
|
| 302 | + [$entete, , $topelement, $avail, $suite] = $page; |
|
| 303 | + |
|
| 304 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 305 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 306 | + return []; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + [, $rotlvl, $suite] = $r; |
|
| 310 | + |
|
| 311 | + if (!$suite) { |
|
| 312 | + if ($avail != 'SYSTEM') { |
|
| 313 | + return []; |
|
| 314 | + } |
|
| 315 | + $grammaire = $rotlvl; |
|
| 316 | + $rotlvl = ''; |
|
| 317 | + } else { |
|
| 318 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 319 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 320 | + return []; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + $grammaire = $r[1]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 328 | 328 | } |