@@ -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 | } |
@@ -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 | /** |
@@ -23,322 +23,322 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML |
| 25 | 25 | { |
| 26 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 27 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 28 | - if ($p = strpos($name, ':')) { |
|
| 29 | - $name = substr($name, $p + 1); |
|
| 30 | - $p = isset($this->dtc->elements[$name]); |
|
| 31 | - } |
|
| 32 | - if (!$p) { |
|
| 33 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 34 | - . _T('zxml_inconnu_balise')); |
|
| 35 | - |
|
| 36 | - return; |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - // controler les filles illegitimes, ca suffit |
|
| 40 | - $depth = $this->depth; |
|
| 41 | - $ouvrant = $this->ouvrant; |
|
| 42 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 43 | - if (isset($ouvrant[$depth])) { |
|
| 44 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 45 | - $pere = $r[1]; |
|
| 46 | - #spip_log("pere $pere"); |
|
| 47 | - if (isset($this->dtc->elements[$pere])) { |
|
| 48 | - $fils = $this->dtc->elements[$pere]; |
|
| 49 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 50 | - if (!($p = @in_array($name, $fils))) { |
|
| 51 | - if ($p = strpos($name, ':')) { |
|
| 52 | - $p = substr($name, $p + 1); |
|
| 53 | - $p = @in_array($p, $fils); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - if (!$p) { |
|
| 57 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 58 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 59 | - . _T('zxml_non_fils') |
|
| 60 | - . ' <b>' |
|
| 61 | - . $pere |
|
| 62 | - . '</b>' |
|
| 63 | - . (!$bons_peres ? '' |
|
| 64 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 66 | - $frat = substr($depth, 2); |
|
| 67 | - if (!isset($this->fratrie[$frat])) { |
|
| 68 | - $this->fratrie[$frat] = ''; |
|
| 69 | - } |
|
| 70 | - $this->fratrie[$frat] .= "$name "; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 76 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 77 | - $this->fratrie[$depth] = ''; |
|
| 78 | - } |
|
| 79 | - if (isset($this->dtc->attributs[$name])) { |
|
| 80 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 81 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 82 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 83 | - . ' : ' |
|
| 84 | - . _T('zxml_obligatoire_attribut') |
|
| 85 | - . " <b>$name</b>"); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 92 | - // Si la balise est inconnue, eviter d'insister |
|
| 93 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $a = $this->dtc->attributs[$bal]; |
|
| 98 | - if (!isset($a[$name])) { |
|
| 99 | - $bons = join(', ', array_keys($a)); |
|
| 100 | - if ($bons) { |
|
| 101 | - $bons = " title=' " . |
|
| 102 | - _T('zxml_connus_attributs') . |
|
| 103 | - ' : ' . |
|
| 104 | - $bons . |
|
| 105 | - "'"; |
|
| 106 | - } |
|
| 107 | - $bons .= " style='font-weight: bold'"; |
|
| 108 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 109 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 110 | - . " <a$bons>$bal</a> (" |
|
| 111 | - . _T('zxml_survoler') |
|
| 112 | - . ')'); |
|
| 113 | - } else { |
|
| 114 | - $type = $a[$name][0]; |
|
| 115 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 116 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 117 | - } else { |
|
| 118 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 119 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 127 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 131 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 135 | - if (isset($this->ids[$val])) { |
|
| 136 | - [$l, $c] = $this->ids[$val]; |
|
| 137 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 138 | - . _T('zxml_valeur_attribut') |
|
| 139 | - . " <b>$name</b> " |
|
| 140 | - . _T('zxml_de') |
|
| 141 | - . " <b>$bal</b> " |
|
| 142 | - . _T('zxml_vu') |
|
| 143 | - . " (L$l,C$c)"); |
|
| 144 | - } else { |
|
| 145 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 146 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 151 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 159 | - if (!preg_match($motif, $val)) { |
|
| 160 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 161 | - . _T('zxml_valeur_attribut') |
|
| 162 | - . " <b>$name</b> " |
|
| 163 | - . _T('zxml_de') |
|
| 164 | - . " <b>$bal</b> " |
|
| 165 | - . _T('zxml_non_conforme') |
|
| 166 | - . '</p><p>' |
|
| 167 | - . '<b>' . $motif . '</b>'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function valider_idref($nom, $ligne, $col) { |
|
| 172 | - if (!isset($this->ids[$nom])) { |
|
| 173 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function valider_passe2() { |
|
| 178 | - if (!$this->err) { |
|
| 179 | - foreach ($this->idrefs as $idref) { |
|
| 180 | - [$nom, $ligne, $col] = $idref; |
|
| 181 | - $this->valider_idref($nom, $ligne, $col); |
|
| 182 | - } |
|
| 183 | - foreach ($this->idrefss as $idref) { |
|
| 184 | - [$noms, $ligne, $col] = $idref; |
|
| 185 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 186 | - $this->valider_idref($nom, $ligne, $col); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 193 | - if ($this->dtc->elements) { |
|
| 194 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if ($f = $this->process['debut']) { |
|
| 198 | - $f($this, $name, $attrs); |
|
| 199 | - } |
|
| 200 | - $depth = $this->depth; |
|
| 201 | - $this->debuts[$depth] = strlen($this->res); |
|
| 202 | - foreach ($attrs as $k => $v) { |
|
| 203 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - public function finElement($phraseur, $name) { |
|
| 208 | - $depth = $this->depth; |
|
| 209 | - $contenu = $this->contenu; |
|
| 210 | - |
|
| 211 | - $n = strlen($this->res); |
|
| 212 | - $c = strlen(trim($contenu[$depth])); |
|
| 213 | - $k = $this->debuts[$depth]; |
|
| 214 | - |
|
| 215 | - $regle = $this->dtc->regles[$name] ?? false; |
|
| 216 | - $vide = ($regle == 'EMPTY'); |
|
| 217 | - // controler que les balises devant etre vides le sont |
|
| 218 | - if ($vide) { |
|
| 219 | - if ($n <> ($k + $c)) { |
|
| 220 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 221 | - } |
|
| 222 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 223 | - } elseif ($regle and ($regle != '*')) { |
|
| 224 | - if ($regle == '+') { |
|
| 225 | - // iteration de disjonction non vide: 1 balise au - |
|
| 226 | - if ($n == $k) { |
|
| 227 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 228 | - . _T('zxml_vide_balise')); |
|
| 229 | - } |
|
| 230 | - } else { |
|
| 231 | - $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 232 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 233 | - coordonnees_erreur( |
|
| 234 | - $this, |
|
| 235 | - " <p>\n<b>$name</b> " |
|
| 236 | - . _T('zxml_succession_fils_incorrecte') |
|
| 237 | - . ' : <b>' |
|
| 238 | - . $f |
|
| 239 | - . '</b>' |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - if ($f = $this->process['fin']) { |
|
| 245 | - $f($this, $name, $vide); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function textElement($phraseur, $data) { |
|
| 250 | - if (trim($data)) { |
|
| 251 | - $d = $this->depth; |
|
| 252 | - $d = $this->ouvrant[$d]; |
|
| 253 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 254 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 255 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 256 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - if ($f = $this->process['text']) { |
|
| 260 | - $f($this, $data); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - public function piElement($phraseur, $target, $data) { |
|
| 265 | - if ($f = $this->process['pi']) { |
|
| 266 | - $f($this, $target, $data); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Denonciation des entitees XML inconnues |
|
| 271 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 272 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 273 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 274 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 275 | - // le source de la page laisse legitimement supposer. |
|
| 276 | - |
|
| 277 | - public function defaultElement($phraseur, $data) { |
|
| 278 | - if ( |
|
| 279 | - !preg_match('/^<!--/', $data) |
|
| 280 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 281 | - ) { |
|
| 282 | - foreach ($r as $m) { |
|
| 283 | - [$t, $e] = $m; |
|
| 284 | - if (!isset($this->dtc->entites[$e])) { |
|
| 285 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 286 | - . _T('zxml_inconnu_entite') |
|
| 287 | - . ' '); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 292 | - $f($this, $data); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - public function phraserTout($phraseur, $data) { |
|
| 297 | - xml_parsestring($this, $data); |
|
| 298 | - |
|
| 299 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 300 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 301 | - } else { |
|
| 302 | - $this->valider_passe2(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Constructeur |
|
| 308 | - * |
|
| 309 | - * @param array $process ? |
|
| 310 | - **/ |
|
| 311 | - public function __construct($process = []) { |
|
| 312 | - if (is_array($process)) { |
|
| 313 | - $this->process = $process; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - public $ids = []; |
|
| 318 | - public $idrefs = []; |
|
| 319 | - public $idrefss = []; |
|
| 320 | - public $debuts = []; |
|
| 321 | - public $fratrie = []; |
|
| 322 | - |
|
| 323 | - public $dtc = null; |
|
| 324 | - public $sax = null; |
|
| 325 | - public $depth = ''; |
|
| 326 | - public $entete = ''; |
|
| 327 | - public $page = ''; |
|
| 328 | - public $res = ''; |
|
| 329 | - public array $err = []; |
|
| 330 | - public array $contenu = []; |
|
| 331 | - public array $versions = []; |
|
| 332 | - |
|
| 333 | - public array $ouvrant = []; |
|
| 334 | - public array $reperes = []; |
|
| 335 | - public array $process = [ |
|
| 336 | - 'debut' => 'xml_debutElement', |
|
| 337 | - 'fin' => 'xml_finElement', |
|
| 338 | - 'text' => 'xml_textElement', |
|
| 339 | - 'pi' => 'xml_piElement', |
|
| 340 | - 'default' => 'xml_defaultElement' |
|
| 341 | - ]; |
|
| 26 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 27 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 28 | + if ($p = strpos($name, ':')) { |
|
| 29 | + $name = substr($name, $p + 1); |
|
| 30 | + $p = isset($this->dtc->elements[$name]); |
|
| 31 | + } |
|
| 32 | + if (!$p) { |
|
| 33 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 34 | + . _T('zxml_inconnu_balise')); |
|
| 35 | + |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + // controler les filles illegitimes, ca suffit |
|
| 40 | + $depth = $this->depth; |
|
| 41 | + $ouvrant = $this->ouvrant; |
|
| 42 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 43 | + if (isset($ouvrant[$depth])) { |
|
| 44 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 45 | + $pere = $r[1]; |
|
| 46 | + #spip_log("pere $pere"); |
|
| 47 | + if (isset($this->dtc->elements[$pere])) { |
|
| 48 | + $fils = $this->dtc->elements[$pere]; |
|
| 49 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 50 | + if (!($p = @in_array($name, $fils))) { |
|
| 51 | + if ($p = strpos($name, ':')) { |
|
| 52 | + $p = substr($name, $p + 1); |
|
| 53 | + $p = @in_array($p, $fils); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + if (!$p) { |
|
| 57 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 58 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 59 | + . _T('zxml_non_fils') |
|
| 60 | + . ' <b>' |
|
| 61 | + . $pere |
|
| 62 | + . '</b>' |
|
| 63 | + . (!$bons_peres ? '' |
|
| 64 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 66 | + $frat = substr($depth, 2); |
|
| 67 | + if (!isset($this->fratrie[$frat])) { |
|
| 68 | + $this->fratrie[$frat] = ''; |
|
| 69 | + } |
|
| 70 | + $this->fratrie[$frat] .= "$name "; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 76 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 77 | + $this->fratrie[$depth] = ''; |
|
| 78 | + } |
|
| 79 | + if (isset($this->dtc->attributs[$name])) { |
|
| 80 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 81 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 82 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 83 | + . ' : ' |
|
| 84 | + . _T('zxml_obligatoire_attribut') |
|
| 85 | + . " <b>$name</b>"); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 92 | + // Si la balise est inconnue, eviter d'insister |
|
| 93 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $a = $this->dtc->attributs[$bal]; |
|
| 98 | + if (!isset($a[$name])) { |
|
| 99 | + $bons = join(', ', array_keys($a)); |
|
| 100 | + if ($bons) { |
|
| 101 | + $bons = " title=' " . |
|
| 102 | + _T('zxml_connus_attributs') . |
|
| 103 | + ' : ' . |
|
| 104 | + $bons . |
|
| 105 | + "'"; |
|
| 106 | + } |
|
| 107 | + $bons .= " style='font-weight: bold'"; |
|
| 108 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 109 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 110 | + . " <a$bons>$bal</a> (" |
|
| 111 | + . _T('zxml_survoler') |
|
| 112 | + . ')'); |
|
| 113 | + } else { |
|
| 114 | + $type = $a[$name][0]; |
|
| 115 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 116 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 117 | + } else { |
|
| 118 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 119 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 127 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 131 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 135 | + if (isset($this->ids[$val])) { |
|
| 136 | + [$l, $c] = $this->ids[$val]; |
|
| 137 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 138 | + . _T('zxml_valeur_attribut') |
|
| 139 | + . " <b>$name</b> " |
|
| 140 | + . _T('zxml_de') |
|
| 141 | + . " <b>$bal</b> " |
|
| 142 | + . _T('zxml_vu') |
|
| 143 | + . " (L$l,C$c)"); |
|
| 144 | + } else { |
|
| 145 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 146 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 151 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 159 | + if (!preg_match($motif, $val)) { |
|
| 160 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 161 | + . _T('zxml_valeur_attribut') |
|
| 162 | + . " <b>$name</b> " |
|
| 163 | + . _T('zxml_de') |
|
| 164 | + . " <b>$bal</b> " |
|
| 165 | + . _T('zxml_non_conforme') |
|
| 166 | + . '</p><p>' |
|
| 167 | + . '<b>' . $motif . '</b>'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function valider_idref($nom, $ligne, $col) { |
|
| 172 | + if (!isset($this->ids[$nom])) { |
|
| 173 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function valider_passe2() { |
|
| 178 | + if (!$this->err) { |
|
| 179 | + foreach ($this->idrefs as $idref) { |
|
| 180 | + [$nom, $ligne, $col] = $idref; |
|
| 181 | + $this->valider_idref($nom, $ligne, $col); |
|
| 182 | + } |
|
| 183 | + foreach ($this->idrefss as $idref) { |
|
| 184 | + [$noms, $ligne, $col] = $idref; |
|
| 185 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 186 | + $this->valider_idref($nom, $ligne, $col); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 193 | + if ($this->dtc->elements) { |
|
| 194 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if ($f = $this->process['debut']) { |
|
| 198 | + $f($this, $name, $attrs); |
|
| 199 | + } |
|
| 200 | + $depth = $this->depth; |
|
| 201 | + $this->debuts[$depth] = strlen($this->res); |
|
| 202 | + foreach ($attrs as $k => $v) { |
|
| 203 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + public function finElement($phraseur, $name) { |
|
| 208 | + $depth = $this->depth; |
|
| 209 | + $contenu = $this->contenu; |
|
| 210 | + |
|
| 211 | + $n = strlen($this->res); |
|
| 212 | + $c = strlen(trim($contenu[$depth])); |
|
| 213 | + $k = $this->debuts[$depth]; |
|
| 214 | + |
|
| 215 | + $regle = $this->dtc->regles[$name] ?? false; |
|
| 216 | + $vide = ($regle == 'EMPTY'); |
|
| 217 | + // controler que les balises devant etre vides le sont |
|
| 218 | + if ($vide) { |
|
| 219 | + if ($n <> ($k + $c)) { |
|
| 220 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 221 | + } |
|
| 222 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 223 | + } elseif ($regle and ($regle != '*')) { |
|
| 224 | + if ($regle == '+') { |
|
| 225 | + // iteration de disjonction non vide: 1 balise au - |
|
| 226 | + if ($n == $k) { |
|
| 227 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 228 | + . _T('zxml_vide_balise')); |
|
| 229 | + } |
|
| 230 | + } else { |
|
| 231 | + $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 232 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 233 | + coordonnees_erreur( |
|
| 234 | + $this, |
|
| 235 | + " <p>\n<b>$name</b> " |
|
| 236 | + . _T('zxml_succession_fils_incorrecte') |
|
| 237 | + . ' : <b>' |
|
| 238 | + . $f |
|
| 239 | + . '</b>' |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + if ($f = $this->process['fin']) { |
|
| 245 | + $f($this, $name, $vide); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function textElement($phraseur, $data) { |
|
| 250 | + if (trim($data)) { |
|
| 251 | + $d = $this->depth; |
|
| 252 | + $d = $this->ouvrant[$d]; |
|
| 253 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 254 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 255 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 256 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + if ($f = $this->process['text']) { |
|
| 260 | + $f($this, $data); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + public function piElement($phraseur, $target, $data) { |
|
| 265 | + if ($f = $this->process['pi']) { |
|
| 266 | + $f($this, $target, $data); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Denonciation des entitees XML inconnues |
|
| 271 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 272 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 273 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 274 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 275 | + // le source de la page laisse legitimement supposer. |
|
| 276 | + |
|
| 277 | + public function defaultElement($phraseur, $data) { |
|
| 278 | + if ( |
|
| 279 | + !preg_match('/^<!--/', $data) |
|
| 280 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 281 | + ) { |
|
| 282 | + foreach ($r as $m) { |
|
| 283 | + [$t, $e] = $m; |
|
| 284 | + if (!isset($this->dtc->entites[$e])) { |
|
| 285 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 286 | + . _T('zxml_inconnu_entite') |
|
| 287 | + . ' '); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 292 | + $f($this, $data); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + public function phraserTout($phraseur, $data) { |
|
| 297 | + xml_parsestring($this, $data); |
|
| 298 | + |
|
| 299 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 300 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 301 | + } else { |
|
| 302 | + $this->valider_passe2(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Constructeur |
|
| 308 | + * |
|
| 309 | + * @param array $process ? |
|
| 310 | + **/ |
|
| 311 | + public function __construct($process = []) { |
|
| 312 | + if (is_array($process)) { |
|
| 313 | + $this->process = $process; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + public $ids = []; |
|
| 318 | + public $idrefs = []; |
|
| 319 | + public $idrefss = []; |
|
| 320 | + public $debuts = []; |
|
| 321 | + public $fratrie = []; |
|
| 322 | + |
|
| 323 | + public $dtc = null; |
|
| 324 | + public $sax = null; |
|
| 325 | + public $depth = ''; |
|
| 326 | + public $entete = ''; |
|
| 327 | + public $page = ''; |
|
| 328 | + public $res = ''; |
|
| 329 | + public array $err = []; |
|
| 330 | + public array $contenu = []; |
|
| 331 | + public array $versions = []; |
|
| 332 | + |
|
| 333 | + public array $ouvrant = []; |
|
| 334 | + public array $reperes = []; |
|
| 335 | + public array $process = [ |
|
| 336 | + 'debut' => 'xml_debutElement', |
|
| 337 | + 'fin' => 'xml_finElement', |
|
| 338 | + 'text' => 'xml_textElement', |
|
| 339 | + 'pi' => 'xml_piElement', |
|
| 340 | + 'default' => 'xml_defaultElement' |
|
| 341 | + ]; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | **/ |
| 350 | 350 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 351 | - $f = new ValidateurXML($process); |
|
| 352 | - $sax = charger_fonction('sax', 'xml'); |
|
| 351 | + $f = new ValidateurXML($process); |
|
| 352 | + $sax = charger_fonction('sax', 'xml'); |
|
| 353 | 353 | |
| 354 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 354 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 355 | 355 | } |
@@ -11,58 +11,58 @@ 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('xml/interfaces'); |
| 18 | 18 | |
| 19 | 19 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 20 | - $r = null; |
|
| 21 | - static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | - |
|
| 23 | - if (isset($dtd[$grammaire])) { |
|
| 24 | - return $dtd[$grammaire]; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ($avail == 'SYSTEM') { |
|
| 28 | - $grammaire = find_in_path($grammaire); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | - |
|
| 33 | - if (lire_fichier($file, $r)) { |
|
| 34 | - if (!$grammaire) { |
|
| 35 | - return []; |
|
| 36 | - } |
|
| 37 | - if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | - $r = false; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($r) { |
|
| 43 | - $dtc = unserialize($r); |
|
| 44 | - } else { |
|
| 45 | - spip_timer('dtd'); |
|
| 46 | - $dtc = new DTC(); |
|
| 47 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | - // Retourner vide en cas d'echec |
|
| 49 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | - $dtc = []; |
|
| 51 | - } else { |
|
| 52 | - // tri final pour presenter les suggestions de corrections |
|
| 53 | - foreach ($dtc->peres as $k => $v) { |
|
| 54 | - asort($v); |
|
| 55 | - $dtc->peres[$k] = $v; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $dtd[$grammaire] = $dtc; |
|
| 64 | - |
|
| 65 | - return $dtc; |
|
| 20 | + $r = null; |
|
| 21 | + static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | + |
|
| 23 | + if (isset($dtd[$grammaire])) { |
|
| 24 | + return $dtd[$grammaire]; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ($avail == 'SYSTEM') { |
|
| 28 | + $grammaire = find_in_path($grammaire); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + |
|
| 33 | + if (lire_fichier($file, $r)) { |
|
| 34 | + if (!$grammaire) { |
|
| 35 | + return []; |
|
| 36 | + } |
|
| 37 | + if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | + $r = false; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($r) { |
|
| 43 | + $dtc = unserialize($r); |
|
| 44 | + } else { |
|
| 45 | + spip_timer('dtd'); |
|
| 46 | + $dtc = new DTC(); |
|
| 47 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | + // Retourner vide en cas d'echec |
|
| 49 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | + $dtc = []; |
|
| 51 | + } else { |
|
| 52 | + // tri final pour presenter les suggestions de corrections |
|
| 53 | + foreach ($dtc->peres as $k => $v) { |
|
| 54 | + asort($v); |
|
| 55 | + $dtc->peres[$k] = $v; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $dtd[$grammaire] = $dtc; |
|
| 64 | + |
|
| 65 | + return $dtc; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -74,153 +74,153 @@ discard block |
||
| 74 | 74 | // et parentheser le tout pour que | + * ? s'applique dessus. |
| 75 | 75 | |
| 76 | 76 | function compilerRegle($val) { |
| 77 | - $x = str_replace( |
|
| 78 | - '()', |
|
| 79 | - '', |
|
| 80 | - preg_replace( |
|
| 81 | - '/\s*,\s*/', |
|
| 82 | - '', |
|
| 83 | - preg_replace( |
|
| 84 | - '/(\w+)\s*/', |
|
| 85 | - '(?:\1 )', |
|
| 86 | - preg_replace( |
|
| 87 | - '/\s*\)/', |
|
| 88 | - ')', |
|
| 89 | - preg_replace( |
|
| 90 | - '/\s*([(+*|?])\s*/', |
|
| 91 | - '\1', |
|
| 92 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 93 | - ) |
|
| 94 | - ) |
|
| 95 | - ) |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - return $x; |
|
| 77 | + $x = str_replace( |
|
| 78 | + '()', |
|
| 79 | + '', |
|
| 80 | + preg_replace( |
|
| 81 | + '/\s*,\s*/', |
|
| 82 | + '', |
|
| 83 | + preg_replace( |
|
| 84 | + '/(\w+)\s*/', |
|
| 85 | + '(?:\1 )', |
|
| 86 | + preg_replace( |
|
| 87 | + '/\s*\)/', |
|
| 88 | + ')', |
|
| 89 | + preg_replace( |
|
| 90 | + '/\s*([(+*|?])\s*/', |
|
| 91 | + '\1', |
|
| 92 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 93 | + ) |
|
| 94 | + ) |
|
| 95 | + ) |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + return $x; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | function analyser_dtd($loc, $avail, &$dtc) { |
| 104 | - // creer le repertoire de cache si ce n'est fait |
|
| 105 | - // (utile aussi pour le resultat de la compil) |
|
| 106 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 107 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 108 | - if ($avail == 'SYSTEM') { |
|
| 109 | - $file = $loc; |
|
| 110 | - if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 111 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 112 | - } |
|
| 113 | - $file = find_in_path($file); |
|
| 114 | - } else { |
|
| 115 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $dtd = ''; |
|
| 119 | - if (@is_readable($file)) { |
|
| 120 | - lire_fichier($file, $dtd); |
|
| 121 | - } else { |
|
| 122 | - if ($avail == 'PUBLIC') { |
|
| 123 | - include_spip('inc/distant'); |
|
| 124 | - $dtd = recuperer_url($loc); |
|
| 125 | - $dtd = trim($dtd['page'] ?? ''); |
|
| 126 | - if ($dtd) { |
|
| 127 | - ecrire_fichier($file, $dtd, true); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $dtd = ltrim($dtd); |
|
| 133 | - if (!$dtd) { |
|
| 134 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 135 | - |
|
| 136 | - return false; |
|
| 137 | - } else { |
|
| 138 | - spip_log("analyse de la DTD $loc "); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - while ($dtd) { |
|
| 142 | - if ($dtd[0] != '<') { |
|
| 143 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 144 | - } elseif ($dtd[1] != '!') { |
|
| 145 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 146 | - } elseif ($dtd[2] == '[') { |
|
| 147 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 148 | - } else { |
|
| 149 | - switch ($dtd[3]) { |
|
| 150 | - case '%': |
|
| 151 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 152 | - break; |
|
| 153 | - case 'T': |
|
| 154 | - $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 155 | - break; |
|
| 156 | - case 'L': |
|
| 157 | - $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 158 | - break; |
|
| 159 | - case 'N': |
|
| 160 | - $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 161 | - break; |
|
| 162 | - case 'O': |
|
| 163 | - $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 164 | - break; |
|
| 165 | - case '-': |
|
| 166 | - $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 167 | - break; |
|
| 168 | - default: |
|
| 169 | - $r = -1; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - if (!is_string($r)) { |
|
| 173 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 174 | - |
|
| 175 | - return false; |
|
| 176 | - } |
|
| 177 | - $dtd = $r; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return true; |
|
| 104 | + // creer le repertoire de cache si ce n'est fait |
|
| 105 | + // (utile aussi pour le resultat de la compil) |
|
| 106 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 107 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 108 | + if ($avail == 'SYSTEM') { |
|
| 109 | + $file = $loc; |
|
| 110 | + if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 111 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 112 | + } |
|
| 113 | + $file = find_in_path($file); |
|
| 114 | + } else { |
|
| 115 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $dtd = ''; |
|
| 119 | + if (@is_readable($file)) { |
|
| 120 | + lire_fichier($file, $dtd); |
|
| 121 | + } else { |
|
| 122 | + if ($avail == 'PUBLIC') { |
|
| 123 | + include_spip('inc/distant'); |
|
| 124 | + $dtd = recuperer_url($loc); |
|
| 125 | + $dtd = trim($dtd['page'] ?? ''); |
|
| 126 | + if ($dtd) { |
|
| 127 | + ecrire_fichier($file, $dtd, true); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $dtd = ltrim($dtd); |
|
| 133 | + if (!$dtd) { |
|
| 134 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 135 | + |
|
| 136 | + return false; |
|
| 137 | + } else { |
|
| 138 | + spip_log("analyse de la DTD $loc "); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + while ($dtd) { |
|
| 142 | + if ($dtd[0] != '<') { |
|
| 143 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 144 | + } elseif ($dtd[1] != '!') { |
|
| 145 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 146 | + } elseif ($dtd[2] == '[') { |
|
| 147 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 148 | + } else { |
|
| 149 | + switch ($dtd[3]) { |
|
| 150 | + case '%': |
|
| 151 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 152 | + break; |
|
| 153 | + case 'T': |
|
| 154 | + $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 155 | + break; |
|
| 156 | + case 'L': |
|
| 157 | + $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 158 | + break; |
|
| 159 | + case 'N': |
|
| 160 | + $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 161 | + break; |
|
| 162 | + case 'O': |
|
| 163 | + $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 164 | + break; |
|
| 165 | + case '-': |
|
| 166 | + $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 167 | + break; |
|
| 168 | + default: |
|
| 169 | + $r = -1; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + if (!is_string($r)) { |
|
| 173 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 174 | + |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | + $dtd = $r; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return true; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 184 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 185 | - // Option /s car sur plusieurs lignes parfois |
|
| 184 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 185 | + // Option /s car sur plusieurs lignes parfois |
|
| 186 | 186 | |
| 187 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 188 | - return -6; |
|
| 189 | - } |
|
| 187 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 188 | + return -6; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - return $m[1]; |
|
| 191 | + return $m[1]; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 195 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 196 | - return -10; |
|
| 197 | - } |
|
| 195 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 196 | + return -10; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $m[1]; |
|
| 199 | + return $m[1]; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 203 | 203 | |
| 204 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 205 | - return -9; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - [, $s] = $m; |
|
| 209 | - $n = $dtc->macros[$s]; |
|
| 210 | - |
|
| 211 | - if (is_array($n)) { |
|
| 212 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 213 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 214 | - if ( |
|
| 215 | - ($n[0] == 'PUBLIC') |
|
| 216 | - and !tester_url_absolue($n[1]) |
|
| 217 | - ) { |
|
| 218 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 219 | - } |
|
| 220 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 204 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 205 | + return -9; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + [, $s] = $m; |
|
| 209 | + $n = $dtc->macros[$s]; |
|
| 210 | + |
|
| 211 | + if (is_array($n)) { |
|
| 212 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 213 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 214 | + if ( |
|
| 215 | + ($n[0] == 'PUBLIC') |
|
| 216 | + and !tester_url_absolue($n[1]) |
|
| 217 | + ) { |
|
| 218 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 219 | + } |
|
| 220 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -228,83 +228,83 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 230 | 230 | |
| 231 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 232 | - return -11; |
|
| 233 | - } |
|
| 234 | - if ( |
|
| 235 | - !preg_match( |
|
| 236 | - '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 237 | - $m[2], |
|
| 238 | - $r |
|
| 239 | - ) |
|
| 240 | - ) { |
|
| 241 | - return -12; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 245 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 246 | - } else { |
|
| 247 | - $retour = substr($m[2], strlen($r[0])); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $retour; |
|
| 231 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 232 | + return -11; |
|
| 233 | + } |
|
| 234 | + if ( |
|
| 235 | + !preg_match( |
|
| 236 | + '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 237 | + $m[2], |
|
| 238 | + $r |
|
| 239 | + ) |
|
| 240 | + ) { |
|
| 241 | + return -12; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 245 | + $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 246 | + } else { |
|
| 247 | + $retour = substr($m[2], strlen($r[0])); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $retour; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 254 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 255 | - return -8; |
|
| 256 | - } |
|
| 257 | - spip_log('analyser_dtd_notation a ecrire'); |
|
| 254 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 255 | + return -8; |
|
| 256 | + } |
|
| 257 | + spip_log('analyser_dtd_notation a ecrire'); |
|
| 258 | 258 | |
| 259 | - return $m[1]; |
|
| 259 | + return $m[1]; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 263 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 264 | - return -2; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 268 | - |
|
| 269 | - if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 270 | - return $dtd; |
|
| 271 | - } |
|
| 272 | - if (isset($dtc->entites[$nom])) { |
|
| 273 | - spip_log("redefinition de l'entite $nom"); |
|
| 274 | - } |
|
| 275 | - if ($k6) { |
|
| 276 | - return $k6 . $dtd; |
|
| 277 | - } // cas du synonyme complet |
|
| 278 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 279 | - |
|
| 280 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 281 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 282 | - [$t, $type, $val, $q, $alt] = $r; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if (!$term) { |
|
| 286 | - $dtc->entites[$nom] = $val; |
|
| 287 | - } elseif (!$type) { |
|
| 288 | - $dtc->macros[$nom] = $val; |
|
| 289 | - } else { |
|
| 290 | - if (($type == 'SYSTEM') and !$alt) { |
|
| 291 | - $alt = $val; |
|
| 292 | - } |
|
| 293 | - if (!$alt) { |
|
| 294 | - $dtc->macros[$nom] = $val; |
|
| 295 | - } else { |
|
| 296 | - if ( |
|
| 297 | - ($type == 'PUBLIC') |
|
| 298 | - and (strpos($alt, '/') === false) |
|
| 299 | - ) { |
|
| 300 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 301 | - . $alt; |
|
| 302 | - } |
|
| 303 | - $dtc->macros[$nom] = [$type, $alt]; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $dtd; |
|
| 263 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 264 | + return -2; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 268 | + |
|
| 269 | + if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 270 | + return $dtd; |
|
| 271 | + } |
|
| 272 | + if (isset($dtc->entites[$nom])) { |
|
| 273 | + spip_log("redefinition de l'entite $nom"); |
|
| 274 | + } |
|
| 275 | + if ($k6) { |
|
| 276 | + return $k6 . $dtd; |
|
| 277 | + } // cas du synonyme complet |
|
| 278 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 279 | + |
|
| 280 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 281 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 282 | + [$t, $type, $val, $q, $alt] = $r; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if (!$term) { |
|
| 286 | + $dtc->entites[$nom] = $val; |
|
| 287 | + } elseif (!$type) { |
|
| 288 | + $dtc->macros[$nom] = $val; |
|
| 289 | + } else { |
|
| 290 | + if (($type == 'SYSTEM') and !$alt) { |
|
| 291 | + $alt = $val; |
|
| 292 | + } |
|
| 293 | + if (!$alt) { |
|
| 294 | + $dtc->macros[$nom] = $val; |
|
| 295 | + } else { |
|
| 296 | + if ( |
|
| 297 | + ($type == 'PUBLIC') |
|
| 298 | + and (strpos($alt, '/') === false) |
|
| 299 | + ) { |
|
| 300 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 301 | + . $alt; |
|
| 302 | + } |
|
| 303 | + $dtc->macros[$nom] = [$type, $alt]; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $dtd; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Dresser le tableau des filles potentielles de l'element |
@@ -317,76 +317,76 @@ discard block |
||
| 317 | 317 | // Fin du controle en finElement |
| 318 | 318 | |
| 319 | 319 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 320 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 321 | - return -3; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - [, $nom, $contenu, $dtd] = $m; |
|
| 325 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 326 | - |
|
| 327 | - if (isset($dtc->elements[$nom])) { |
|
| 328 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 329 | - |
|
| 330 | - return -4; |
|
| 331 | - } |
|
| 332 | - $filles = []; |
|
| 333 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 334 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 335 | - if ($val == '(?:EMPTY )') { |
|
| 336 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 337 | - } elseif ($val == '(?:ANY )') { |
|
| 338 | - $dtc->regles[$nom] = 'ANY'; |
|
| 339 | - } else { |
|
| 340 | - $last = substr($val, -1); |
|
| 341 | - if ( |
|
| 342 | - preg_match('/ \w/', $val) |
|
| 343 | - or (!empty($last) and !str_contains('*+?', $last)) |
|
| 344 | - ) { |
|
| 345 | - $dtc->regles[$nom] = "/^$val$/"; |
|
| 346 | - } else { |
|
| 347 | - $dtc->regles[$nom] = $last; |
|
| 348 | - } |
|
| 349 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 350 | - |
|
| 351 | - foreach ($filles as $k) { |
|
| 352 | - if (!isset($dtc->peres[$k])) { |
|
| 353 | - $dtc->peres[$k] = []; |
|
| 354 | - } |
|
| 355 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 356 | - $dtc->peres[$k][] = $nom; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 361 | - $dtc->elements[$nom] = $filles; |
|
| 362 | - |
|
| 363 | - return $dtd; |
|
| 320 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 321 | + return -3; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + [, $nom, $contenu, $dtd] = $m; |
|
| 325 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 326 | + |
|
| 327 | + if (isset($dtc->elements[$nom])) { |
|
| 328 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 329 | + |
|
| 330 | + return -4; |
|
| 331 | + } |
|
| 332 | + $filles = []; |
|
| 333 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 334 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 335 | + if ($val == '(?:EMPTY )') { |
|
| 336 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 337 | + } elseif ($val == '(?:ANY )') { |
|
| 338 | + $dtc->regles[$nom] = 'ANY'; |
|
| 339 | + } else { |
|
| 340 | + $last = substr($val, -1); |
|
| 341 | + if ( |
|
| 342 | + preg_match('/ \w/', $val) |
|
| 343 | + or (!empty($last) and !str_contains('*+?', $last)) |
|
| 344 | + ) { |
|
| 345 | + $dtc->regles[$nom] = "/^$val$/"; |
|
| 346 | + } else { |
|
| 347 | + $dtc->regles[$nom] = $last; |
|
| 348 | + } |
|
| 349 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 350 | + |
|
| 351 | + foreach ($filles as $k) { |
|
| 352 | + if (!isset($dtc->peres[$k])) { |
|
| 353 | + $dtc->peres[$k] = []; |
|
| 354 | + } |
|
| 355 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 356 | + $dtc->peres[$k][] = $nom; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 361 | + $dtc->elements[$nom] = $filles; |
|
| 362 | + |
|
| 363 | + return $dtd; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 368 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 369 | - return -5; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - [, $nom, $val, $dtd] = $m; |
|
| 373 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 374 | - $val = expanserEntite($val, $dtc->macros); |
|
| 375 | - if (!isset($dtc->attributs[$nom])) { |
|
| 376 | - $dtc->attributs[$nom] = []; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 380 | - foreach ($r2 as $m2) { |
|
| 381 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 382 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 383 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 384 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 385 | - $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return $dtd; |
|
| 368 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 369 | + return -5; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + [, $nom, $val, $dtd] = $m; |
|
| 373 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 374 | + $val = expanserEntite($val, $dtc->macros); |
|
| 375 | + if (!isset($dtc->attributs[$nom])) { |
|
| 376 | + $dtc->attributs[$nom] = []; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 380 | + foreach ($r2 as $m2) { |
|
| 381 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 382 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 383 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 384 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 385 | + $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return $dtd; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -402,26 +402,26 @@ discard block |
||
| 402 | 402 | * @return string|array |
| 403 | 403 | **/ |
| 404 | 404 | function expanserEntite($val, $macros = []) { |
| 405 | - static $vu = []; |
|
| 406 | - if (!is_string($val)) { |
|
| 407 | - return $vu; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 411 | - foreach ($r as $m) { |
|
| 412 | - $ent = $m[1]; |
|
| 413 | - // il peut valoir "" |
|
| 414 | - if (!isset($macros[$ent])) { |
|
| 415 | - spip_log("Entite $ent inconnu"); |
|
| 416 | - } else { |
|
| 417 | - if (!isset($vu[$ent])) { |
|
| 418 | - $vu[$ent] = 0; |
|
| 419 | - } |
|
| 420 | - ++$vu[$ent]; |
|
| 421 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 405 | + static $vu = []; |
|
| 406 | + if (!is_string($val)) { |
|
| 407 | + return $vu; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 411 | + foreach ($r as $m) { |
|
| 412 | + $ent = $m[1]; |
|
| 413 | + // il peut valoir "" |
|
| 414 | + if (!isset($macros[$ent])) { |
|
| 415 | + spip_log("Entite $ent inconnu"); |
|
| 416 | + } else { |
|
| 417 | + if (!isset($vu[$ent])) { |
|
| 418 | + $vu[$ent] = 0; |
|
| 419 | + } |
|
| 420 | + ++$vu[$ent]; |
|
| 421 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 427 | 427 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -44,70 +44,70 @@ discard block |
||
| 44 | 44 | * @return array|string |
| 45 | 45 | */ |
| 46 | 46 | function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = []) { |
| 47 | - if (!is_array($options)) { |
|
| 48 | - $options = ['id' => $options]; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if (function_exists('test_inscription')) { |
|
| 52 | - $f = 'test_inscription'; |
|
| 53 | - } else { |
|
| 54 | - $f = 'test_inscription_dist'; |
|
| 55 | - } |
|
| 56 | - $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 57 | - |
|
| 58 | - // erreur ? |
|
| 59 | - if (!is_array($desc)) { |
|
| 60 | - return _T($desc); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - include_spip('base/abstract_sql'); |
|
| 64 | - $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 65 | - // erreur ? |
|
| 66 | - if (!$res) { |
|
| 67 | - return _T('titre_probleme_technique'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $row = sql_fetch($res); |
|
| 71 | - sql_free($res); |
|
| 72 | - if ($row) { |
|
| 73 | - if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 74 | - $desc['id_auteur'] = $row['id_auteur']; |
|
| 75 | - $desc = inscription_nouveau($desc); |
|
| 76 | - } else { |
|
| 77 | - $desc = $row; |
|
| 78 | - } |
|
| 79 | - } else // s'il n'existe pas deja, creer les identifiants |
|
| 80 | - { |
|
| 81 | - $desc = inscription_nouveau($desc); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // erreur ? |
|
| 85 | - if (!is_array($desc)) { |
|
| 86 | - return $desc; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 91 | - $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 92 | - |
|
| 93 | - // attribuer un jeton pour confirmation par clic sur un lien |
|
| 94 | - $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 95 | - |
|
| 96 | - // charger de suite cette fonction, pour ses utilitaires |
|
| 97 | - $envoyer_inscription = charger_fonction('envoyer_inscription', ''); |
|
| 98 | - [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 99 | - |
|
| 100 | - $notifications = charger_fonction('notifications', 'inc'); |
|
| 101 | - notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 102 | - |
|
| 103 | - // Notifications |
|
| 104 | - $notifications( |
|
| 105 | - 'inscription', |
|
| 106 | - $desc['id_auteur'], |
|
| 107 | - ['nom' => $desc['nom'], 'email' => $desc['email']] |
|
| 108 | - ); |
|
| 109 | - |
|
| 110 | - return $desc; |
|
| 47 | + if (!is_array($options)) { |
|
| 48 | + $options = ['id' => $options]; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if (function_exists('test_inscription')) { |
|
| 52 | + $f = 'test_inscription'; |
|
| 53 | + } else { |
|
| 54 | + $f = 'test_inscription_dist'; |
|
| 55 | + } |
|
| 56 | + $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 57 | + |
|
| 58 | + // erreur ? |
|
| 59 | + if (!is_array($desc)) { |
|
| 60 | + return _T($desc); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + include_spip('base/abstract_sql'); |
|
| 64 | + $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 65 | + // erreur ? |
|
| 66 | + if (!$res) { |
|
| 67 | + return _T('titre_probleme_technique'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $row = sql_fetch($res); |
|
| 71 | + sql_free($res); |
|
| 72 | + if ($row) { |
|
| 73 | + if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 74 | + $desc['id_auteur'] = $row['id_auteur']; |
|
| 75 | + $desc = inscription_nouveau($desc); |
|
| 76 | + } else { |
|
| 77 | + $desc = $row; |
|
| 78 | + } |
|
| 79 | + } else // s'il n'existe pas deja, creer les identifiants |
|
| 80 | + { |
|
| 81 | + $desc = inscription_nouveau($desc); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // erreur ? |
|
| 85 | + if (!is_array($desc)) { |
|
| 86 | + return $desc; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 91 | + $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 92 | + |
|
| 93 | + // attribuer un jeton pour confirmation par clic sur un lien |
|
| 94 | + $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 95 | + |
|
| 96 | + // charger de suite cette fonction, pour ses utilitaires |
|
| 97 | + $envoyer_inscription = charger_fonction('envoyer_inscription', ''); |
|
| 98 | + [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 99 | + |
|
| 100 | + $notifications = charger_fonction('notifications', 'inc'); |
|
| 101 | + notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 102 | + |
|
| 103 | + // Notifications |
|
| 104 | + $notifications( |
|
| 105 | + 'inscription', |
|
| 106 | + $desc['id_auteur'], |
|
| 107 | + ['nom' => $desc['nom'], 'email' => $desc['email']] |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + return $desc; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -130,23 +130,23 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | */ |
| 132 | 132 | function test_inscription_dist($statut, $mail, $nom, $options) { |
| 133 | - include_spip('inc/filtres'); |
|
| 134 | - if (!$r = email_valide($mail)) { |
|
| 135 | - return 'info_email_invalide'; |
|
| 136 | - } |
|
| 137 | - $nom = trim(corriger_caracteres($nom)); |
|
| 138 | - $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut]; |
|
| 139 | - if (isset($options['login'])) { |
|
| 140 | - $login = trim(corriger_caracteres($options['login'])); |
|
| 141 | - if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 142 | - $res['login'] = $login; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 146 | - return 'ecrire:info_login_trop_court'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $res; |
|
| 133 | + include_spip('inc/filtres'); |
|
| 134 | + if (!$r = email_valide($mail)) { |
|
| 135 | + return 'info_email_invalide'; |
|
| 136 | + } |
|
| 137 | + $nom = trim(corriger_caracteres($nom)); |
|
| 138 | + $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut]; |
|
| 139 | + if (isset($options['login'])) { |
|
| 140 | + $login = trim(corriger_caracteres($options['login'])); |
|
| 141 | + if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 142 | + $res['login'] = $login; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 146 | + return 'ecrire:info_login_trop_court'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $res; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -159,33 +159,33 @@ discard block |
||
| 159 | 159 | * @return mixed|string |
| 160 | 160 | */ |
| 161 | 161 | function inscription_nouveau($desc) { |
| 162 | - if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 163 | - $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 164 | - } |
|
| 162 | + if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 163 | + $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - $desc['statut'] = 'nouveau'; |
|
| 167 | - include_spip('action/editer_auteur'); |
|
| 168 | - if (isset($desc['id_auteur'])) { |
|
| 169 | - $id_auteur = $desc['id_auteur']; |
|
| 170 | - } else { |
|
| 171 | - $id_auteur = auteur_inserer(); |
|
| 172 | - } |
|
| 166 | + $desc['statut'] = 'nouveau'; |
|
| 167 | + include_spip('action/editer_auteur'); |
|
| 168 | + if (isset($desc['id_auteur'])) { |
|
| 169 | + $id_auteur = $desc['id_auteur']; |
|
| 170 | + } else { |
|
| 171 | + $id_auteur = auteur_inserer(); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - if (!$id_auteur) { |
|
| 175 | - return _T('titre_probleme_technique'); |
|
| 176 | - } |
|
| 174 | + if (!$id_auteur) { |
|
| 175 | + return _T('titre_probleme_technique'); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 178 | + $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 179 | 179 | |
| 180 | - include_spip('inc/autoriser'); |
|
| 181 | - // lever l'autorisation pour pouvoir modifier le statut |
|
| 182 | - autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 183 | - auteur_modifier($id_auteur, $desc); |
|
| 184 | - autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 180 | + include_spip('inc/autoriser'); |
|
| 181 | + // lever l'autorisation pour pouvoir modifier le statut |
|
| 182 | + autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 183 | + auteur_modifier($id_auteur, $desc); |
|
| 184 | + autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 185 | 185 | |
| 186 | - $desc['id_auteur'] = $id_auteur; |
|
| 186 | + $desc['id_auteur'] = $id_auteur; |
|
| 187 | 187 | |
| 188 | - return $desc; |
|
| 188 | + return $desc; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -202,27 +202,27 @@ discard block |
||
| 202 | 202 | * @return string |
| 203 | 203 | */ |
| 204 | 204 | function test_login($nom, $mail) { |
| 205 | - include_spip('inc/charsets'); |
|
| 206 | - $nom = strtolower(translitteration($nom)); |
|
| 207 | - $login_base = preg_replace('/[^\w\d_]/', '_', $nom); |
|
| 208 | - |
|
| 209 | - // il faut eviter que le login soit vraiment trop court |
|
| 210 | - if (strlen($login_base) < 3) { |
|
| 211 | - $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 212 | - $login_base = preg_replace('/[^\w\d]/', '_', $mail); |
|
| 213 | - } |
|
| 214 | - if (strlen($login_base) < 3) { |
|
| 215 | - $login_base = 'user'; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $login = $login_base; |
|
| 219 | - |
|
| 220 | - for ($i = 1;; $i++) { |
|
| 221 | - if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 222 | - return $login; |
|
| 223 | - } |
|
| 224 | - $login = $login_base . $i; |
|
| 225 | - } |
|
| 205 | + include_spip('inc/charsets'); |
|
| 206 | + $nom = strtolower(translitteration($nom)); |
|
| 207 | + $login_base = preg_replace('/[^\w\d_]/', '_', $nom); |
|
| 208 | + |
|
| 209 | + // il faut eviter que le login soit vraiment trop court |
|
| 210 | + if (strlen($login_base) < 3) { |
|
| 211 | + $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 212 | + $login_base = preg_replace('/[^\w\d]/', '_', $mail); |
|
| 213 | + } |
|
| 214 | + if (strlen($login_base) < 3) { |
|
| 215 | + $login_base = 'user'; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $login = $login_base; |
|
| 219 | + |
|
| 220 | + for ($i = 1;; $i++) { |
|
| 221 | + if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 222 | + return $login; |
|
| 223 | + } |
|
| 224 | + $login = $login_base . $i; |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -240,26 +240,26 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | function envoyer_inscription_dist($desc, $nom, $mode, $options = []) { |
| 242 | 242 | |
| 243 | - $contexte = array_merge($desc, $options); |
|
| 244 | - $contexte['nom'] = $nom; |
|
| 245 | - $contexte['mode'] = $mode; |
|
| 246 | - $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 247 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 248 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 249 | - // S'il y a l'option redirect, on l'ajoute directement ici |
|
| 250 | - if (isset($options['redirect'])) { |
|
| 251 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $modele_mail = 'modeles/mail_inscription'; |
|
| 255 | - if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 256 | - $modele_mail = $options['modele_mail']; |
|
| 257 | - } |
|
| 258 | - $message = recuperer_fond($modele_mail, $contexte); |
|
| 259 | - $from = ($options['from'] ?? ''); |
|
| 260 | - $head = ''; |
|
| 261 | - |
|
| 262 | - return ['', $message, $from, $head]; |
|
| 243 | + $contexte = array_merge($desc, $options); |
|
| 244 | + $contexte['nom'] = $nom; |
|
| 245 | + $contexte['mode'] = $mode; |
|
| 246 | + $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 247 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 248 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 249 | + // S'il y a l'option redirect, on l'ajoute directement ici |
|
| 250 | + if (isset($options['redirect'])) { |
|
| 251 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $modele_mail = 'modeles/mail_inscription'; |
|
| 255 | + if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 256 | + $modele_mail = $options['modele_mail']; |
|
| 257 | + } |
|
| 258 | + $message = recuperer_fond($modele_mail, $contexte); |
|
| 259 | + $from = ($options['from'] ?? ''); |
|
| 260 | + $head = ''; |
|
| 261 | + |
|
| 262 | + return ['', $message, $from, $head]; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -270,12 +270,12 @@ discard block |
||
| 270 | 270 | * @return string |
| 271 | 271 | */ |
| 272 | 272 | function creer_pass_pour_auteur($id_auteur) { |
| 273 | - include_spip('inc/acces'); |
|
| 274 | - $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur); |
|
| 275 | - include_spip('action/editer_auteur'); |
|
| 276 | - auteur_instituer($id_auteur, ['pass' => $pass]); |
|
| 273 | + include_spip('inc/acces'); |
|
| 274 | + $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur); |
|
| 275 | + include_spip('action/editer_auteur'); |
|
| 276 | + auteur_instituer($id_auteur, ['pass' => $pass]); |
|
| 277 | 277 | |
| 278 | - return $pass; |
|
| 278 | + return $pass; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | * @return string |
| 289 | 289 | */ |
| 290 | 290 | function tester_statut_inscription($statut_tmp, $id) { |
| 291 | - include_spip('inc/autoriser'); |
|
| 292 | - if ($statut_tmp) { |
|
| 293 | - return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 294 | - } elseif ( |
|
| 295 | - autoriser('inscrireauteur', $statut_tmp = '1comite', $id) |
|
| 296 | - or autoriser('inscrireauteur', $statut_tmp = '6forum', $id) |
|
| 297 | - ) { |
|
| 298 | - return $statut_tmp; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - return ''; |
|
| 291 | + include_spip('inc/autoriser'); |
|
| 292 | + if ($statut_tmp) { |
|
| 293 | + return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 294 | + } elseif ( |
|
| 295 | + autoriser('inscrireauteur', $statut_tmp = '1comite', $id) |
|
| 296 | + or autoriser('inscrireauteur', $statut_tmp = '6forum', $id) |
|
| 297 | + ) { |
|
| 298 | + return $statut_tmp; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + return ''; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -312,35 +312,35 @@ discard block |
||
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | 314 | function confirmer_statut_inscription($auteur) { |
| 315 | - // securite |
|
| 316 | - if ($auteur['statut'] != 'nouveau') { |
|
| 317 | - return $auteur; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $s = $auteur['prefs']; |
|
| 321 | - // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 322 | - if (!preg_match(',^\w+$,', $s)) { |
|
| 323 | - $s = '6forum'; |
|
| 324 | - } |
|
| 325 | - include_spip('inc/autoriser'); |
|
| 326 | - if (!autoriser('inscrireauteur', $s)) { |
|
| 327 | - return $auteur; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - include_spip('inc/autoriser'); |
|
| 331 | - // accorder l'autorisation de modif du statut auteur |
|
| 332 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 333 | - include_spip('action/editer_auteur'); |
|
| 334 | - // changer le statut |
|
| 335 | - auteur_modifier($auteur['id_auteur'], ['statut' => $s]); |
|
| 336 | - unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 337 | - // lever l'autorisation de modif du statut auteur |
|
| 338 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 339 | - |
|
| 340 | - // mettre a jour le statut |
|
| 341 | - $auteur['statut'] = $s; |
|
| 342 | - |
|
| 343 | - return $auteur; |
|
| 315 | + // securite |
|
| 316 | + if ($auteur['statut'] != 'nouveau') { |
|
| 317 | + return $auteur; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $s = $auteur['prefs']; |
|
| 321 | + // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 322 | + if (!preg_match(',^\w+$,', $s)) { |
|
| 323 | + $s = '6forum'; |
|
| 324 | + } |
|
| 325 | + include_spip('inc/autoriser'); |
|
| 326 | + if (!autoriser('inscrireauteur', $s)) { |
|
| 327 | + return $auteur; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + include_spip('inc/autoriser'); |
|
| 331 | + // accorder l'autorisation de modif du statut auteur |
|
| 332 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 333 | + include_spip('action/editer_auteur'); |
|
| 334 | + // changer le statut |
|
| 335 | + auteur_modifier($auteur['id_auteur'], ['statut' => $s]); |
|
| 336 | + unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 337 | + // lever l'autorisation de modif du statut auteur |
|
| 338 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 339 | + |
|
| 340 | + // mettre a jour le statut |
|
| 341 | + $auteur['statut'] = $s; |
|
| 342 | + |
|
| 343 | + return $auteur; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -354,20 +354,20 @@ discard block |
||
| 354 | 354 | * @return string |
| 355 | 355 | */ |
| 356 | 356 | function auteur_attribuer_jeton($id_auteur): string { |
| 357 | - include_spip('base/abstract_sql'); |
|
| 358 | - include_spip('inc/acces'); |
|
| 359 | - |
|
| 360 | - // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 361 | - do { |
|
| 362 | - // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer |
|
| 363 | - // tous les jetons connus pour vérifier le jeton d’un auteur. |
|
| 364 | - $public = substr(creer_uniqid(), 0, 7) . '.'; |
|
| 365 | - $jeton = $public . creer_uniqid(); |
|
| 366 | - $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site()); |
|
| 367 | - sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur)); |
|
| 368 | - } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1); |
|
| 369 | - |
|
| 370 | - return $jeton; |
|
| 357 | + include_spip('base/abstract_sql'); |
|
| 358 | + include_spip('inc/acces'); |
|
| 359 | + |
|
| 360 | + // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 361 | + do { |
|
| 362 | + // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer |
|
| 363 | + // tous les jetons connus pour vérifier le jeton d’un auteur. |
|
| 364 | + $public = substr(creer_uniqid(), 0, 7) . '.'; |
|
| 365 | + $jeton = $public . creer_uniqid(); |
|
| 366 | + $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site()); |
|
| 367 | + sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur)); |
|
| 368 | + } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1); |
|
| 369 | + |
|
| 370 | + return $jeton; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -381,19 +381,19 @@ discard block |
||
| 381 | 381 | * @return string|null |
| 382 | 382 | */ |
| 383 | 383 | function auteur_lire_jeton(int $id_auteur, bool $autoInit = false): ?string { |
| 384 | - include_spip('base/abstract_sql'); |
|
| 385 | - $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur); |
|
| 386 | - if ($jeton_chiffre_prefixe) { |
|
| 387 | - $jeton_chiffre = substr($jeton_chiffre_prefixe, 8); |
|
| 388 | - $jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 389 | - if ($jeton) { |
|
| 390 | - return $jeton; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - if ($autoInit) { |
|
| 394 | - return auteur_attribuer_jeton($id_auteur); |
|
| 395 | - } |
|
| 396 | - return null; |
|
| 384 | + include_spip('base/abstract_sql'); |
|
| 385 | + $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur); |
|
| 386 | + if ($jeton_chiffre_prefixe) { |
|
| 387 | + $jeton_chiffre = substr($jeton_chiffre_prefixe, 8); |
|
| 388 | + $jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 389 | + if ($jeton) { |
|
| 390 | + return $jeton; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + if ($autoInit) { |
|
| 394 | + return auteur_attribuer_jeton($id_auteur); |
|
| 395 | + } |
|
| 396 | + return null; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -403,24 +403,24 @@ discard block |
||
| 403 | 403 | * @return array|bool |
| 404 | 404 | */ |
| 405 | 405 | function auteur_verifier_jeton($jeton) { |
| 406 | - // refuser un jeton corrompu |
|
| 407 | - if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - include_spip('base/abstract_sql'); |
|
| 412 | - $public = substr($jeton, 0, 8); |
|
| 413 | - |
|
| 414 | - // Les auteurs qui ont un jetons ressemblant |
|
| 415 | - $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%')); |
|
| 416 | - foreach ($auteurs as $auteur) { |
|
| 417 | - $jeton_chiffre = substr($auteur['cookie_oubli'], 8); |
|
| 418 | - $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 419 | - if ($_jeton and hash_equals($jeton, $_jeton)) { |
|
| 420 | - return $auteur; |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - return false; |
|
| 406 | + // refuser un jeton corrompu |
|
| 407 | + if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + include_spip('base/abstract_sql'); |
|
| 412 | + $public = substr($jeton, 0, 8); |
|
| 413 | + |
|
| 414 | + // Les auteurs qui ont un jetons ressemblant |
|
| 415 | + $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%')); |
|
| 416 | + foreach ($auteurs as $auteur) { |
|
| 417 | + $jeton_chiffre = substr($auteur['cookie_oubli'], 8); |
|
| 418 | + $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site()); |
|
| 419 | + if ($_jeton and hash_equals($jeton, $_jeton)) { |
|
| 420 | + return $auteur; |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + return false; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -430,6 +430,6 @@ discard block |
||
| 430 | 430 | * @return bool |
| 431 | 431 | */ |
| 432 | 432 | function auteur_effacer_jeton($id_auteur) { |
| 433 | - include_spip('base/abstract_sql'); |
|
| 434 | - return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 433 | + include_spip('base/abstract_sql'); |
|
| 434 | + return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 435 | 435 | } |
@@ -7,21 +7,21 @@ |
||
| 7 | 7 | * @internal |
| 8 | 8 | */ |
| 9 | 9 | class Collection { |
| 10 | - private array $vars = []; |
|
| 10 | + private array $vars = []; |
|
| 11 | 11 | |
| 12 | - public function add(string $var, string $value) { |
|
| 13 | - $this->vars[$var] = $value; |
|
| 14 | - } |
|
| 12 | + public function add(string $var, string $value) { |
|
| 13 | + $this->vars[$var] = $value; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function getString(): string { |
|
| 17 | - $string = ''; |
|
| 18 | - foreach ($this->vars as $key => $value) { |
|
| 19 | - $string .= "$key: $value;\n"; |
|
| 20 | - } |
|
| 21 | - return $string; |
|
| 22 | - } |
|
| 16 | + public function getString(): string { |
|
| 17 | + $string = ''; |
|
| 18 | + foreach ($this->vars as $key => $value) { |
|
| 19 | + $string .= "$key: $value;\n"; |
|
| 20 | + } |
|
| 21 | + return $string; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function __toString(): string { |
|
| 25 | - return $this->getString(); |
|
| 26 | - } |
|
| 24 | + public function __toString(): string { |
|
| 25 | + return $this->getString(); |
|
| 26 | + } |
|
| 27 | 27 | } |