@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 76 | + if (find_in_path($charset.'.php', 'charsets/', true)) { |
|
| 77 | 77 | return $charset; |
| 78 | 78 | } else { |
| 79 | 79 | spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | static $pcre_ok = 0; |
| 161 | 161 | |
| 162 | 162 | if (!$pcre_ok) { |
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 163 | + $s = ' '.chr(195).chr(169).'t'.chr(195).chr(169).' '; |
|
| 164 | 164 | if (preg_match(',\W...\W,u', $s)) { |
| 165 | 165 | $pcre_ok = 1; |
| 166 | 166 | } else { |
@@ -261,38 +261,38 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | if (!isset($trans[$charset][$charset_cible])) { |
| 263 | 263 | $trans[$charset][$charset_cible] = [ |
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 264 | + $p.chr(128) => '€', |
|
| 265 | + $p.chr(129) => ' ', # pas affecte |
|
| 266 | + $p.chr(130) => '‚', |
|
| 267 | + $p.chr(131) => 'ƒ', |
|
| 268 | + $p.chr(132) => '„', |
|
| 269 | + $p.chr(133) => '…', |
|
| 270 | + $p.chr(134) => '†', |
|
| 271 | + $p.chr(135) => '‡', |
|
| 272 | + $p.chr(136) => 'ˆ', |
|
| 273 | + $p.chr(137) => '‰', |
|
| 274 | + $p.chr(138) => 'Š', |
|
| 275 | + $p.chr(139) => '‹', |
|
| 276 | + $p.chr(140) => 'Œ', |
|
| 277 | + $p.chr(141) => ' ', # pas affecte |
|
| 278 | + $p.chr(142) => 'Ž', |
|
| 279 | + $p.chr(143) => ' ', # pas affecte |
|
| 280 | + $p.chr(144) => ' ', # pas affecte |
|
| 281 | + $p.chr(145) => '‘', |
|
| 282 | + $p.chr(146) => '’', |
|
| 283 | + $p.chr(147) => '“', |
|
| 284 | + $p.chr(148) => '”', |
|
| 285 | + $p.chr(149) => '•', |
|
| 286 | + $p.chr(150) => '–', |
|
| 287 | + $p.chr(151) => '—', |
|
| 288 | + $p.chr(152) => '˜', |
|
| 289 | + $p.chr(153) => '™', |
|
| 290 | + $p.chr(154) => 'š', |
|
| 291 | + $p.chr(155) => '›', |
|
| 292 | + $p.chr(156) => 'œ', |
|
| 293 | + $p.chr(157) => ' ', # pas affecte |
|
| 294 | + $p.chr(158) => 'ž', |
|
| 295 | + $p.chr(159) => 'Ÿ', |
|
| 296 | 296 | ]; |
| 297 | 297 | if ($charset_cible != 'unicode') { |
| 298 | 298 | foreach ($trans[$charset][$charset_cible] as $k => $c) { |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 434 | 434 | ) { |
| 435 | 435 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 436 | + $trans[$charset][chr($key)] = '&#'.$val.';'; |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -500,11 +500,11 @@ discard block |
||
| 500 | 500 | $h = dechex($e); |
| 501 | 501 | if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
| 502 | 502 | $s = $CHARSET_REVERSE[$charset][$e]; |
| 503 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 503 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($s); |
|
| 504 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($s); |
|
| 505 | 505 | } else { |
| 506 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 506 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($e); |
|
| 507 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($e); |
|
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 552 | 552 | ) { |
| 553 | 553 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 554 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 554 | + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | } |
| 659 | 659 | $thisPos++; |
| 660 | 660 | } |
| 661 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 661 | + $encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';'; |
|
| 662 | 662 | $encodedString .= $encodedLetter; |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
| 702 | 702 | else { |
| 703 | 703 | if ($word != 65279) { |
| 704 | - $texte .= '&#' . $word . ';'; |
|
| 704 | + $texte .= '&#'.$word.';'; |
|
| 705 | 705 | } |
| 706 | 706 | } |
| 707 | 707 | } |
@@ -729,13 +729,13 @@ discard block |
||
| 729 | 729 | return chr($num); |
| 730 | 730 | } |
| 731 | 731 | if ($num < 2048) { |
| 732 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 732 | + return chr(($num >> 6) + 192).chr(($num & 63) + 128); |
|
| 733 | 733 | } |
| 734 | 734 | if ($num < 65536) { |
| 735 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 735 | + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 736 | 736 | } |
| 737 | 737 | if ($num < 1_114_112) { |
| 738 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 738 | + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | return ''; |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
| 803 | 803 | $num = $regs[1]; |
| 804 | 804 | $vu[$num] = true; |
| 805 | - $s = '\u' . sprintf('%04x', $num); |
|
| 805 | + $s = '\u'.sprintf('%04x', $num); |
|
| 806 | 806 | $texte = str_replace($regs[0], $s, $texte); |
| 807 | 807 | } |
| 808 | 808 | |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | **/ |
| 820 | 820 | function javascript_to_unicode($texte) { |
| 821 | 821 | while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
| 822 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 822 | + $texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | return $texte; |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | return $texte; |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | - $table_translit = 'translit' . $complexe; |
|
| 867 | + $table_translit = 'translit'.$complexe; |
|
| 868 | 868 | |
| 869 | 869 | // 2. Translitterer grace a la table predefinie |
| 870 | 870 | if (!isset($trans[$complexe])) { |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * true s'il a un BOM |
| 956 | 956 | **/ |
| 957 | 957 | function bom_utf8($texte) { |
| 958 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 958 | + return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF)); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -1151,7 +1151,7 @@ discard block |
||
| 1151 | 1151 | // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
| 1152 | 1152 | // (un caractere utf-8 prenant au maximum n bytes) |
| 1153 | 1153 | $n = 0; |
| 1154 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1154 | + while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) { |
|
| 1155 | 1155 | ; |
| 1156 | 1156 | } |
| 1157 | 1157 | $c = substr($c, 0, $n * $length); |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 1185 | |
| 1186 | 1186 | $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
| 1187 | 1187 | |
| 1188 | - return $lettre1 . spip_substr($c, 1); |
|
| 1188 | + return $lettre1.spip_substr($c, 1); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | /** |
@@ -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 |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 43 | 43 | **/ |
| 44 | 44 | function load_charset($charset = 'AUTO') { |
| 45 | - if ($charset == 'AUTO') { |
|
| 46 | - $charset = $GLOBALS['meta']['charset']; |
|
| 47 | - } |
|
| 48 | - $charset = trim(strtolower($charset)); |
|
| 49 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | - return $charset; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($charset == 'utf-8') { |
|
| 54 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | - |
|
| 56 | - return $charset; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Quelques synonymes |
|
| 60 | - if ($charset == '') { |
|
| 61 | - $charset = 'iso-8859-1'; |
|
| 62 | - } else { |
|
| 63 | - if ($charset == 'windows-1250') { |
|
| 64 | - $charset = 'cp1250'; |
|
| 65 | - } else { |
|
| 66 | - if ($charset == 'windows-1251') { |
|
| 67 | - $charset = 'cp1251'; |
|
| 68 | - } else { |
|
| 69 | - if ($charset == 'windows-1256') { |
|
| 70 | - $charset = 'cp1256'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | - return $charset; |
|
| 78 | - } else { |
|
| 79 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | - |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 45 | + if ($charset == 'AUTO') { |
|
| 46 | + $charset = $GLOBALS['meta']['charset']; |
|
| 47 | + } |
|
| 48 | + $charset = trim(strtolower($charset)); |
|
| 49 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | + return $charset; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($charset == 'utf-8') { |
|
| 54 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | + |
|
| 56 | + return $charset; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Quelques synonymes |
|
| 60 | + if ($charset == '') { |
|
| 61 | + $charset = 'iso-8859-1'; |
|
| 62 | + } else { |
|
| 63 | + if ($charset == 'windows-1250') { |
|
| 64 | + $charset = 'cp1250'; |
|
| 65 | + } else { |
|
| 66 | + if ($charset == 'windows-1251') { |
|
| 67 | + $charset = 'cp1251'; |
|
| 68 | + } else { |
|
| 69 | + if ($charset == 'windows-1256') { |
|
| 70 | + $charset = 'cp1256'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | + return $charset; |
|
| 78 | + } else { |
|
| 79 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | + |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * true si toutes les fonctions mb nécessaires sont présentes |
| 92 | 92 | **/ |
| 93 | 93 | function init_mb_string() { |
| 94 | - static $mb; |
|
| 95 | - |
|
| 96 | - // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | - // et que le charset interne est connu de mb_string |
|
| 98 | - if (!$mb) { |
|
| 99 | - if ( |
|
| 100 | - function_exists('mb_internal_encoding') |
|
| 101 | - and function_exists('mb_detect_order') |
|
| 102 | - and function_exists('mb_substr') |
|
| 103 | - and function_exists('mb_strlen') |
|
| 104 | - and function_exists('mb_strtolower') |
|
| 105 | - and function_exists('mb_strtoupper') |
|
| 106 | - and function_exists('mb_encode_mimeheader') |
|
| 107 | - and function_exists('mb_encode_numericentity') |
|
| 108 | - and function_exists('mb_decode_numericentity') |
|
| 109 | - and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | - ) { |
|
| 111 | - mb_internal_encoding('utf-8'); |
|
| 112 | - $mb = 1; |
|
| 113 | - } else { |
|
| 114 | - $mb = -1; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return ($mb == 1); |
|
| 94 | + static $mb; |
|
| 95 | + |
|
| 96 | + // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | + // et que le charset interne est connu de mb_string |
|
| 98 | + if (!$mb) { |
|
| 99 | + if ( |
|
| 100 | + function_exists('mb_internal_encoding') |
|
| 101 | + and function_exists('mb_detect_order') |
|
| 102 | + and function_exists('mb_substr') |
|
| 103 | + and function_exists('mb_strlen') |
|
| 104 | + and function_exists('mb_strtolower') |
|
| 105 | + and function_exists('mb_strtoupper') |
|
| 106 | + and function_exists('mb_encode_mimeheader') |
|
| 107 | + and function_exists('mb_encode_numericentity') |
|
| 108 | + and function_exists('mb_decode_numericentity') |
|
| 109 | + and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | + ) { |
|
| 111 | + mb_internal_encoding('utf-8'); |
|
| 112 | + $mb = 1; |
|
| 113 | + } else { |
|
| 114 | + $mb = -1; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return ($mb == 1); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -130,21 +130,21 @@ discard block |
||
| 130 | 130 | * true si iconv fonctionne correctement |
| 131 | 131 | **/ |
| 132 | 132 | function test_iconv() { |
| 133 | - static $iconv_ok; |
|
| 134 | - |
|
| 135 | - if (!$iconv_ok) { |
|
| 136 | - if (!function_exists('iconv')) { |
|
| 137 | - $iconv_ok = -1; |
|
| 138 | - } else { |
|
| 139 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | - $iconv_ok = 1; |
|
| 141 | - } else { |
|
| 142 | - $iconv_ok = -1; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ($iconv_ok == 1); |
|
| 133 | + static $iconv_ok; |
|
| 134 | + |
|
| 135 | + if (!$iconv_ok) { |
|
| 136 | + if (!function_exists('iconv')) { |
|
| 137 | + $iconv_ok = -1; |
|
| 138 | + } else { |
|
| 139 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | + $iconv_ok = 1; |
|
| 141 | + } else { |
|
| 142 | + $iconv_ok = -1; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ($iconv_ok == 1); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -157,18 +157,18 @@ discard block |
||
| 157 | 157 | * true si PCRE supporte l'UTF-8 correctement |
| 158 | 158 | **/ |
| 159 | 159 | function test_pcre_unicode() { |
| 160 | - static $pcre_ok = 0; |
|
| 161 | - |
|
| 162 | - if (!$pcre_ok) { |
|
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | - if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | - $pcre_ok = 1; |
|
| 166 | - } else { |
|
| 167 | - $pcre_ok = -1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $pcre_ok == 1; |
|
| 160 | + static $pcre_ok = 0; |
|
| 161 | + |
|
| 162 | + if (!$pcre_ok) { |
|
| 163 | + $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | + if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | + $pcre_ok = 1; |
|
| 166 | + } else { |
|
| 167 | + $pcre_ok = -1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $pcre_ok == 1; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -184,22 +184,22 @@ discard block |
||
| 184 | 184 | * Plage de caractères |
| 185 | 185 | **/ |
| 186 | 186 | function pcre_lettres_unicode() { |
| 187 | - static $plage_unicode; |
|
| 188 | - |
|
| 189 | - if (!$plage_unicode) { |
|
| 190 | - if (test_pcre_unicode()) { |
|
| 191 | - // cf. http://www.unicode.org/charts/ |
|
| 192 | - $plage_unicode = '\w' // iso-latin |
|
| 193 | - . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | - . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | - ; |
|
| 196 | - } else { |
|
| 197 | - // fallback a trois sous |
|
| 198 | - $plage_unicode = '\w'; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $plage_unicode; |
|
| 187 | + static $plage_unicode; |
|
| 188 | + |
|
| 189 | + if (!$plage_unicode) { |
|
| 190 | + if (test_pcre_unicode()) { |
|
| 191 | + // cf. http://www.unicode.org/charts/ |
|
| 192 | + $plage_unicode = '\w' // iso-latin |
|
| 193 | + . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | + . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | + ; |
|
| 196 | + } else { |
|
| 197 | + // fallback a trois sous |
|
| 198 | + $plage_unicode = '\w'; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $plage_unicode; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * Plage de caractères |
| 218 | 218 | **/ |
| 219 | 219 | function plage_punct_unicode() { |
| 220 | - return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 220 | + return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -237,75 +237,75 @@ discard block |
||
| 237 | 237 | * Texte corrigé |
| 238 | 238 | **/ |
| 239 | 239 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 240 | - static $trans; |
|
| 241 | - |
|
| 242 | - if (is_array($texte)) { |
|
| 243 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ($charset == 'AUTO') { |
|
| 247 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | - } |
|
| 249 | - if ($charset == 'utf-8') { |
|
| 250 | - $p = chr(194); |
|
| 251 | - if (strpos($texte, $p) == false) { |
|
| 252 | - return $texte; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - if ($charset == 'iso-8859-1') { |
|
| 256 | - $p = ''; |
|
| 257 | - } else { |
|
| 258 | - return $texte; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | - $trans[$charset][$charset_cible] = [ |
|
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 296 | - ]; |
|
| 297 | - if ($charset_cible != 'unicode') { |
|
| 298 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return @str_replace( |
|
| 305 | - array_keys($trans[$charset][$charset_cible]), |
|
| 306 | - array_values($trans[$charset][$charset_cible]), |
|
| 307 | - $texte |
|
| 308 | - ); |
|
| 240 | + static $trans; |
|
| 241 | + |
|
| 242 | + if (is_array($texte)) { |
|
| 243 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ($charset == 'AUTO') { |
|
| 247 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | + } |
|
| 249 | + if ($charset == 'utf-8') { |
|
| 250 | + $p = chr(194); |
|
| 251 | + if (strpos($texte, $p) == false) { |
|
| 252 | + return $texte; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + if ($charset == 'iso-8859-1') { |
|
| 256 | + $p = ''; |
|
| 257 | + } else { |
|
| 258 | + return $texte; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | + $trans[$charset][$charset_cible] = [ |
|
| 264 | + $p . chr(128) => '€', |
|
| 265 | + $p . chr(129) => ' ', # pas affecte |
|
| 266 | + $p . chr(130) => '‚', |
|
| 267 | + $p . chr(131) => 'ƒ', |
|
| 268 | + $p . chr(132) => '„', |
|
| 269 | + $p . chr(133) => '…', |
|
| 270 | + $p . chr(134) => '†', |
|
| 271 | + $p . chr(135) => '‡', |
|
| 272 | + $p . chr(136) => 'ˆ', |
|
| 273 | + $p . chr(137) => '‰', |
|
| 274 | + $p . chr(138) => 'Š', |
|
| 275 | + $p . chr(139) => '‹', |
|
| 276 | + $p . chr(140) => 'Œ', |
|
| 277 | + $p . chr(141) => ' ', # pas affecte |
|
| 278 | + $p . chr(142) => 'Ž', |
|
| 279 | + $p . chr(143) => ' ', # pas affecte |
|
| 280 | + $p . chr(144) => ' ', # pas affecte |
|
| 281 | + $p . chr(145) => '‘', |
|
| 282 | + $p . chr(146) => '’', |
|
| 283 | + $p . chr(147) => '“', |
|
| 284 | + $p . chr(148) => '”', |
|
| 285 | + $p . chr(149) => '•', |
|
| 286 | + $p . chr(150) => '–', |
|
| 287 | + $p . chr(151) => '—', |
|
| 288 | + $p . chr(152) => '˜', |
|
| 289 | + $p . chr(153) => '™', |
|
| 290 | + $p . chr(154) => 'š', |
|
| 291 | + $p . chr(155) => '›', |
|
| 292 | + $p . chr(156) => 'œ', |
|
| 293 | + $p . chr(157) => ' ', # pas affecte |
|
| 294 | + $p . chr(158) => 'ž', |
|
| 295 | + $p . chr(159) => 'Ÿ', |
|
| 296 | + ]; |
|
| 297 | + if ($charset_cible != 'unicode') { |
|
| 298 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return @str_replace( |
|
| 305 | + array_keys($trans[$charset][$charset_cible]), |
|
| 306 | + array_values($trans[$charset][$charset_cible]), |
|
| 307 | + $texte |
|
| 308 | + ); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -322,26 +322,26 @@ discard block |
||
| 322 | 322 | * Texte converti |
| 323 | 323 | **/ |
| 324 | 324 | function html2unicode($texte, $secure = false) { |
| 325 | - if (strpos($texte, '&') === false) { |
|
| 326 | - return $texte; |
|
| 327 | - } |
|
| 328 | - static $trans = []; |
|
| 329 | - if (!$trans) { |
|
| 330 | - load_charset('html'); |
|
| 331 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | - $trans["&$key;"] = $val; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ($secure) { |
|
| 337 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | - } else { |
|
| 339 | - return str_replace( |
|
| 340 | - ['&', '"', '<', '>'], |
|
| 341 | - ['&', '"', '<', '>'], |
|
| 342 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | - ); |
|
| 344 | - } |
|
| 325 | + if (strpos($texte, '&') === false) { |
|
| 326 | + return $texte; |
|
| 327 | + } |
|
| 328 | + static $trans = []; |
|
| 329 | + if (!$trans) { |
|
| 330 | + load_charset('html'); |
|
| 331 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | + $trans["&$key;"] = $val; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ($secure) { |
|
| 337 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | + } else { |
|
| 339 | + return str_replace( |
|
| 340 | + ['&', '"', '<', '>'], |
|
| 341 | + ['&', '"', '<', '>'], |
|
| 342 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -356,16 +356,16 @@ discard block |
||
| 356 | 356 | * Texte converti |
| 357 | 357 | **/ |
| 358 | 358 | function mathml2unicode($texte) { |
| 359 | - static $trans; |
|
| 360 | - if (!$trans) { |
|
| 361 | - load_charset('mathml'); |
|
| 359 | + static $trans; |
|
| 360 | + if (!$trans) { |
|
| 361 | + load_charset('mathml'); |
|
| 362 | 362 | |
| 363 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | - $trans["&$key;"] = $val; |
|
| 365 | - } |
|
| 366 | - } |
|
| 363 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | + $trans["&$key;"] = $val; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 368 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -387,75 +387,75 @@ discard block |
||
| 387 | 387 | * Texte converti en unicode |
| 388 | 388 | **/ |
| 389 | 389 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 390 | - static $trans; |
|
| 391 | - |
|
| 392 | - if ($charset == 'AUTO') { |
|
| 393 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($charset == '') { |
|
| 397 | - $charset = 'iso-8859-1'; |
|
| 398 | - } |
|
| 399 | - $charset = strtolower($charset); |
|
| 400 | - |
|
| 401 | - switch ($charset) { |
|
| 402 | - case 'utf-8': |
|
| 403 | - case 'utf8': |
|
| 404 | - return utf_8_to_unicode($texte); |
|
| 405 | - |
|
| 406 | - case 'iso-8859-1': |
|
| 407 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | - // pas de break; ici, on suit sur default: |
|
| 409 | - |
|
| 410 | - default: |
|
| 411 | - // mbstring presente ? |
|
| 412 | - if (init_mb_string()) { |
|
| 413 | - $order = mb_detect_order(); |
|
| 414 | - try { |
|
| 415 | - # mb_string connait-il $charset? |
|
| 416 | - if ($order and mb_detect_order($charset)) { |
|
| 417 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | - if ($s && $s != $texte) { |
|
| 419 | - return utf_8_to_unicode($s); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } catch (\Error $e) { |
|
| 423 | - // Le charset n'existe probablement pas |
|
| 424 | - } finally { |
|
| 425 | - mb_detect_order($order); # remettre comme precedemment |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | - if (!isset($trans[$charset])) { |
|
| 431 | - if ( |
|
| 432 | - $cset = load_charset($charset) |
|
| 433 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | - ) { |
|
| 435 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | - // surtout en utf-8, gere ci-dessus) |
|
| 447 | - if (test_iconv()) { |
|
| 448 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | - if ($s) { |
|
| 450 | - return utf_32_to_unicode($s); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // Au pire ne rien faire |
|
| 455 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | - |
|
| 457 | - return $texte; |
|
| 458 | - } |
|
| 390 | + static $trans; |
|
| 391 | + |
|
| 392 | + if ($charset == 'AUTO') { |
|
| 393 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($charset == '') { |
|
| 397 | + $charset = 'iso-8859-1'; |
|
| 398 | + } |
|
| 399 | + $charset = strtolower($charset); |
|
| 400 | + |
|
| 401 | + switch ($charset) { |
|
| 402 | + case 'utf-8': |
|
| 403 | + case 'utf8': |
|
| 404 | + return utf_8_to_unicode($texte); |
|
| 405 | + |
|
| 406 | + case 'iso-8859-1': |
|
| 407 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | + // pas de break; ici, on suit sur default: |
|
| 409 | + |
|
| 410 | + default: |
|
| 411 | + // mbstring presente ? |
|
| 412 | + if (init_mb_string()) { |
|
| 413 | + $order = mb_detect_order(); |
|
| 414 | + try { |
|
| 415 | + # mb_string connait-il $charset? |
|
| 416 | + if ($order and mb_detect_order($charset)) { |
|
| 417 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | + if ($s && $s != $texte) { |
|
| 419 | + return utf_8_to_unicode($s); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } catch (\Error $e) { |
|
| 423 | + // Le charset n'existe probablement pas |
|
| 424 | + } finally { |
|
| 425 | + mb_detect_order($order); # remettre comme precedemment |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | + if (!isset($trans[$charset])) { |
|
| 431 | + if ( |
|
| 432 | + $cset = load_charset($charset) |
|
| 433 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | + ) { |
|
| 435 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | + // surtout en utf-8, gere ci-dessus) |
|
| 447 | + if (test_iconv()) { |
|
| 448 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | + if ($s) { |
|
| 450 | + return utf_32_to_unicode($s); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // Au pire ne rien faire |
|
| 455 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | + |
|
| 457 | + return $texte; |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -474,43 +474,43 @@ discard block |
||
| 474 | 474 | * Texte transformé dans le charset souhaité |
| 475 | 475 | **/ |
| 476 | 476 | function unicode2charset($texte, $charset = 'AUTO') { |
| 477 | - static $CHARSET_REVERSE = []; |
|
| 478 | - static $trans = []; |
|
| 479 | - |
|
| 480 | - if ($charset == 'AUTO') { |
|
| 481 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - switch ($charset) { |
|
| 485 | - case 'utf-8': |
|
| 486 | - return unicode_to_utf_8($texte); |
|
| 487 | - |
|
| 488 | - default: |
|
| 489 | - $charset = load_charset($charset); |
|
| 490 | - |
|
| 491 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 492 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if (!isset($trans[$charset])) { |
|
| 496 | - $trans[$charset] = []; |
|
| 497 | - $t = &$trans[$charset]; |
|
| 498 | - for ($e = 128; $e < 255; $e++) { |
|
| 499 | - $h = dechex($e); |
|
| 500 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 501 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 502 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 503 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 504 | - } else { |
|
| 505 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 506 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 511 | - |
|
| 512 | - return $texte; |
|
| 513 | - } |
|
| 477 | + static $CHARSET_REVERSE = []; |
|
| 478 | + static $trans = []; |
|
| 479 | + |
|
| 480 | + if ($charset == 'AUTO') { |
|
| 481 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + switch ($charset) { |
|
| 485 | + case 'utf-8': |
|
| 486 | + return unicode_to_utf_8($texte); |
|
| 487 | + |
|
| 488 | + default: |
|
| 489 | + $charset = load_charset($charset); |
|
| 490 | + |
|
| 491 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 492 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if (!isset($trans[$charset])) { |
|
| 496 | + $trans[$charset] = []; |
|
| 497 | + $t = &$trans[$charset]; |
|
| 498 | + for ($e = 128; $e < 255; $e++) { |
|
| 499 | + $h = dechex($e); |
|
| 500 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 501 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 502 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 503 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 504 | + } else { |
|
| 505 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 506 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 511 | + |
|
| 512 | + return $texte; |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | |
@@ -528,40 +528,40 @@ discard block |
||
| 528 | 528 | * Texte transformé dans le charset site |
| 529 | 529 | **/ |
| 530 | 530 | function importer_charset($texte, $charset = 'AUTO') { |
| 531 | - $s = null; |
|
| 532 | - static $trans = []; |
|
| 533 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 534 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 535 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 536 | - if (init_mb_string()) { |
|
| 537 | - if ( |
|
| 538 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 539 | - and mb_detect_order($charset) |
|
| 540 | - ) { |
|
| 541 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 542 | - } |
|
| 543 | - mb_detect_order($order); # remettre comme precedemment |
|
| 544 | - return $s; |
|
| 545 | - } |
|
| 546 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 547 | - if (!isset($trans[$charset])) { |
|
| 548 | - if ( |
|
| 549 | - $cset = load_charset($charset) |
|
| 550 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 551 | - ) { |
|
| 552 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 553 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 558 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return $texte; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 531 | + $s = null; |
|
| 532 | + static $trans = []; |
|
| 533 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 534 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 535 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 536 | + if (init_mb_string()) { |
|
| 537 | + if ( |
|
| 538 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 539 | + and mb_detect_order($charset) |
|
| 540 | + ) { |
|
| 541 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 542 | + } |
|
| 543 | + mb_detect_order($order); # remettre comme precedemment |
|
| 544 | + return $s; |
|
| 545 | + } |
|
| 546 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 547 | + if (!isset($trans[$charset])) { |
|
| 548 | + if ( |
|
| 549 | + $cset = load_charset($charset) |
|
| 550 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 551 | + ) { |
|
| 552 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 553 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 558 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return $texte; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -577,92 +577,92 @@ discard block |
||
| 577 | 577 | **/ |
| 578 | 578 | function utf_8_to_unicode($source) { |
| 579 | 579 | |
| 580 | - // mb_string : methode rapide |
|
| 581 | - if (init_mb_string()) { |
|
| 582 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 583 | - |
|
| 584 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - // Sinon methode pas a pas |
|
| 588 | - static $decrement; |
|
| 589 | - static $shift; |
|
| 590 | - |
|
| 591 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 592 | - if (!is_array($decrement)) { |
|
| 593 | - // array used to figure what number to decrement from character order value |
|
| 594 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 595 | - $decrement[4] = 240; |
|
| 596 | - $decrement[3] = 224; |
|
| 597 | - $decrement[2] = 192; |
|
| 598 | - $decrement[1] = 0; |
|
| 599 | - // the number of bits to shift each charNum by |
|
| 600 | - $shift[1][0] = 0; |
|
| 601 | - $shift[2][0] = 6; |
|
| 602 | - $shift[2][1] = 0; |
|
| 603 | - $shift[3][0] = 12; |
|
| 604 | - $shift[3][1] = 6; |
|
| 605 | - $shift[3][2] = 0; |
|
| 606 | - $shift[4][0] = 18; |
|
| 607 | - $shift[4][1] = 12; |
|
| 608 | - $shift[4][2] = 6; |
|
| 609 | - $shift[4][3] = 0; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $pos = 0; |
|
| 613 | - $len = strlen($source); |
|
| 614 | - $encodedString = ''; |
|
| 615 | - while ($pos < $len) { |
|
| 616 | - $char = ''; |
|
| 617 | - $ischar = false; |
|
| 618 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 619 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 620 | - // 4 chars representing one unicode character |
|
| 621 | - $thisLetter = substr($source, $pos, 4); |
|
| 622 | - $pos += 4; |
|
| 623 | - } else { |
|
| 624 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 625 | - // 3 chars representing one unicode character |
|
| 626 | - $thisLetter = substr($source, $pos, 3); |
|
| 627 | - $pos += 3; |
|
| 628 | - } else { |
|
| 629 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 630 | - // 2 chars representing one unicode character |
|
| 631 | - $thisLetter = substr($source, $pos, 2); |
|
| 632 | - $pos += 2; |
|
| 633 | - } else { |
|
| 634 | - // 1 char (lower ascii) |
|
| 635 | - $thisLetter = substr($source, $pos, 1); |
|
| 636 | - $pos += 1; |
|
| 637 | - $char = $thisLetter; |
|
| 638 | - $ischar = true; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if ($ischar) { |
|
| 644 | - $encodedString .= $char; |
|
| 645 | - } else { // process the string representing the letter to a unicode entity |
|
| 646 | - $thisLen = strlen($thisLetter); |
|
| 647 | - $thisPos = 0; |
|
| 648 | - $decimalCode = 0; |
|
| 649 | - while ($thisPos < $thisLen) { |
|
| 650 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 651 | - if ($thisPos == 0) { |
|
| 652 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 653 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 654 | - } else { |
|
| 655 | - $charNum = intval($thisCharOrd - 128); |
|
| 656 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 657 | - } |
|
| 658 | - $thisPos++; |
|
| 659 | - } |
|
| 660 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 661 | - $encodedString .= $encodedLetter; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return $encodedString; |
|
| 580 | + // mb_string : methode rapide |
|
| 581 | + if (init_mb_string()) { |
|
| 582 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 583 | + |
|
| 584 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + // Sinon methode pas a pas |
|
| 588 | + static $decrement; |
|
| 589 | + static $shift; |
|
| 590 | + |
|
| 591 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 592 | + if (!is_array($decrement)) { |
|
| 593 | + // array used to figure what number to decrement from character order value |
|
| 594 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 595 | + $decrement[4] = 240; |
|
| 596 | + $decrement[3] = 224; |
|
| 597 | + $decrement[2] = 192; |
|
| 598 | + $decrement[1] = 0; |
|
| 599 | + // the number of bits to shift each charNum by |
|
| 600 | + $shift[1][0] = 0; |
|
| 601 | + $shift[2][0] = 6; |
|
| 602 | + $shift[2][1] = 0; |
|
| 603 | + $shift[3][0] = 12; |
|
| 604 | + $shift[3][1] = 6; |
|
| 605 | + $shift[3][2] = 0; |
|
| 606 | + $shift[4][0] = 18; |
|
| 607 | + $shift[4][1] = 12; |
|
| 608 | + $shift[4][2] = 6; |
|
| 609 | + $shift[4][3] = 0; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $pos = 0; |
|
| 613 | + $len = strlen($source); |
|
| 614 | + $encodedString = ''; |
|
| 615 | + while ($pos < $len) { |
|
| 616 | + $char = ''; |
|
| 617 | + $ischar = false; |
|
| 618 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 619 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 620 | + // 4 chars representing one unicode character |
|
| 621 | + $thisLetter = substr($source, $pos, 4); |
|
| 622 | + $pos += 4; |
|
| 623 | + } else { |
|
| 624 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 625 | + // 3 chars representing one unicode character |
|
| 626 | + $thisLetter = substr($source, $pos, 3); |
|
| 627 | + $pos += 3; |
|
| 628 | + } else { |
|
| 629 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 630 | + // 2 chars representing one unicode character |
|
| 631 | + $thisLetter = substr($source, $pos, 2); |
|
| 632 | + $pos += 2; |
|
| 633 | + } else { |
|
| 634 | + // 1 char (lower ascii) |
|
| 635 | + $thisLetter = substr($source, $pos, 1); |
|
| 636 | + $pos += 1; |
|
| 637 | + $char = $thisLetter; |
|
| 638 | + $ischar = true; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if ($ischar) { |
|
| 644 | + $encodedString .= $char; |
|
| 645 | + } else { // process the string representing the letter to a unicode entity |
|
| 646 | + $thisLen = strlen($thisLetter); |
|
| 647 | + $thisPos = 0; |
|
| 648 | + $decimalCode = 0; |
|
| 649 | + while ($thisPos < $thisLen) { |
|
| 650 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 651 | + if ($thisPos == 0) { |
|
| 652 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 653 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 654 | + } else { |
|
| 655 | + $charNum = intval($thisCharOrd - 128); |
|
| 656 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 657 | + } |
|
| 658 | + $thisPos++; |
|
| 659 | + } |
|
| 660 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 661 | + $encodedString .= $encodedLetter; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return $encodedString; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -681,32 +681,32 @@ discard block |
||
| 681 | 681 | **/ |
| 682 | 682 | function utf_32_to_unicode($source) { |
| 683 | 683 | |
| 684 | - // mb_string : methode rapide |
|
| 685 | - if (init_mb_string()) { |
|
| 686 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 687 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 688 | - |
|
| 689 | - return str_replace(chr(0), '', $source); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - // Sinon methode lente |
|
| 693 | - $texte = ''; |
|
| 694 | - while ($source) { |
|
| 695 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 696 | - $source = substr($source, 1024); |
|
| 697 | - foreach ($words as $word) { |
|
| 698 | - if ($word < 128) { |
|
| 699 | - $texte .= chr($word); |
|
| 700 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 701 | - else { |
|
| 702 | - if ($word != 65279) { |
|
| 703 | - $texte .= '&#' . $word . ';'; |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - return $texte; |
|
| 684 | + // mb_string : methode rapide |
|
| 685 | + if (init_mb_string()) { |
|
| 686 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 687 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 688 | + |
|
| 689 | + return str_replace(chr(0), '', $source); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + // Sinon methode lente |
|
| 693 | + $texte = ''; |
|
| 694 | + while ($source) { |
|
| 695 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 696 | + $source = substr($source, 1024); |
|
| 697 | + foreach ($words as $word) { |
|
| 698 | + if ($word < 128) { |
|
| 699 | + $texte .= chr($word); |
|
| 700 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 701 | + else { |
|
| 702 | + if ($word != 65279) { |
|
| 703 | + $texte .= '&#' . $word . ';'; |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + return $texte; |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | |
@@ -723,21 +723,21 @@ discard block |
||
| 723 | 723 | * Caractère utf8 si trouvé, '' sinon |
| 724 | 724 | **/ |
| 725 | 725 | function caractere_utf_8($num) { |
| 726 | - $num = intval($num); |
|
| 727 | - if ($num < 128) { |
|
| 728 | - return chr($num); |
|
| 729 | - } |
|
| 730 | - if ($num < 2048) { |
|
| 731 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 732 | - } |
|
| 733 | - if ($num < 65536) { |
|
| 734 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 735 | - } |
|
| 736 | - if ($num < 1_114_112) { |
|
| 737 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - return ''; |
|
| 726 | + $num = intval($num); |
|
| 727 | + if ($num < 128) { |
|
| 728 | + return chr($num); |
|
| 729 | + } |
|
| 730 | + if ($num < 2048) { |
|
| 731 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 732 | + } |
|
| 733 | + if ($num < 65536) { |
|
| 734 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 735 | + } |
|
| 736 | + if ($num < 1_114_112) { |
|
| 737 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + return ''; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -750,42 +750,42 @@ discard block |
||
| 750 | 750 | **/ |
| 751 | 751 | function unicode_to_utf_8($texte) { |
| 752 | 752 | |
| 753 | - // 1. Entites € et suivantes |
|
| 754 | - $vu = []; |
|
| 755 | - if ( |
|
| 756 | - preg_match_all( |
|
| 757 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 758 | - $texte, |
|
| 759 | - $regs, |
|
| 760 | - PREG_SET_ORDER |
|
| 761 | - ) |
|
| 762 | - ) { |
|
| 763 | - foreach ($regs as $reg) { |
|
| 764 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 765 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 770 | - |
|
| 771 | - // 2. Entites > ÿ |
|
| 772 | - //$vu = array(); |
|
| 773 | - if ( |
|
| 774 | - preg_match_all( |
|
| 775 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 776 | - $texte, |
|
| 777 | - $regs, |
|
| 778 | - PREG_SET_ORDER |
|
| 779 | - ) |
|
| 780 | - ) { |
|
| 781 | - foreach ($regs as $reg) { |
|
| 782 | - if (!isset($vu[$reg[0]])) { |
|
| 783 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 753 | + // 1. Entites € et suivantes |
|
| 754 | + $vu = []; |
|
| 755 | + if ( |
|
| 756 | + preg_match_all( |
|
| 757 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 758 | + $texte, |
|
| 759 | + $regs, |
|
| 760 | + PREG_SET_ORDER |
|
| 761 | + ) |
|
| 762 | + ) { |
|
| 763 | + foreach ($regs as $reg) { |
|
| 764 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 765 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 770 | + |
|
| 771 | + // 2. Entites > ÿ |
|
| 772 | + //$vu = array(); |
|
| 773 | + if ( |
|
| 774 | + preg_match_all( |
|
| 775 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 776 | + $texte, |
|
| 777 | + $regs, |
|
| 778 | + PREG_SET_ORDER |
|
| 779 | + ) |
|
| 780 | + ) { |
|
| 781 | + foreach ($regs as $reg) { |
|
| 782 | + if (!isset($vu[$reg[0]])) { |
|
| 783 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -797,15 +797,15 @@ discard block |
||
| 797 | 797 | * Texte converti |
| 798 | 798 | **/ |
| 799 | 799 | function unicode_to_javascript($texte) { |
| 800 | - $vu = []; |
|
| 801 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 802 | - $num = $regs[1]; |
|
| 803 | - $vu[$num] = true; |
|
| 804 | - $s = '\u' . sprintf('%04x', $num); |
|
| 805 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - return $texte; |
|
| 800 | + $vu = []; |
|
| 801 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 802 | + $num = $regs[1]; |
|
| 803 | + $vu[$num] = true; |
|
| 804 | + $s = '\u' . sprintf('%04x', $num); |
|
| 805 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + return $texte; |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /** |
@@ -817,11 +817,11 @@ discard block |
||
| 817 | 817 | * Texte converti |
| 818 | 818 | **/ |
| 819 | 819 | function javascript_to_unicode($texte) { |
| 820 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 821 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 822 | - } |
|
| 820 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 821 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | - return $texte; |
|
| 824 | + return $texte; |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /** |
@@ -833,11 +833,11 @@ discard block |
||
| 833 | 833 | * Texte converti |
| 834 | 834 | **/ |
| 835 | 835 | function javascript_to_binary($texte) { |
| 836 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 837 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 838 | - } |
|
| 836 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 837 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - return $texte; |
|
| 840 | + return $texte; |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | |
@@ -855,26 +855,26 @@ discard block |
||
| 855 | 855 | * @return string |
| 856 | 856 | */ |
| 857 | 857 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') { |
| 858 | - static $trans = []; |
|
| 859 | - if ($charset == 'AUTO') { |
|
| 860 | - $charset = $GLOBALS['meta']['charset']; |
|
| 861 | - } |
|
| 862 | - if (!strlen($texte)) { |
|
| 863 | - return $texte; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - $table_translit = 'translit' . $complexe; |
|
| 867 | - |
|
| 868 | - // 2. Translitterer grace a la table predefinie |
|
| 869 | - if (!isset($trans[$complexe])) { |
|
| 870 | - $trans[$complexe] = []; |
|
| 871 | - load_charset($table_translit); |
|
| 872 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 873 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 874 | - } |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 858 | + static $trans = []; |
|
| 859 | + if ($charset == 'AUTO') { |
|
| 860 | + $charset = $GLOBALS['meta']['charset']; |
|
| 861 | + } |
|
| 862 | + if (!strlen($texte)) { |
|
| 863 | + return $texte; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + $table_translit = 'translit' . $complexe; |
|
| 867 | + |
|
| 868 | + // 2. Translitterer grace a la table predefinie |
|
| 869 | + if (!isset($trans[$complexe])) { |
|
| 870 | + $trans[$complexe] = []; |
|
| 871 | + load_charset($table_translit); |
|
| 872 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 873 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -897,14 +897,14 @@ discard block |
||
| 897 | 897 | * @return string |
| 898 | 898 | */ |
| 899 | 899 | function translitteration($texte, $charset = 'AUTO', $complexe = '') { |
| 900 | - // 0. Supprimer les caracteres illegaux |
|
| 901 | - include_spip('inc/filtres'); |
|
| 902 | - $texte = corriger_caracteres($texte); |
|
| 900 | + // 0. Supprimer les caracteres illegaux |
|
| 901 | + include_spip('inc/filtres'); |
|
| 902 | + $texte = corriger_caracteres($texte); |
|
| 903 | 903 | |
| 904 | - // 1. Passer le charset et les é en utf-8 |
|
| 905 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 904 | + // 1. Passer le charset et les é en utf-8 |
|
| 905 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 906 | 906 | |
| 907 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 907 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -919,17 +919,17 @@ discard block |
||
| 919 | 919 | * @return string |
| 920 | 920 | */ |
| 921 | 921 | function translitteration_complexe($texte, $chiffres = false) { |
| 922 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 922 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | 923 | |
| 924 | - if ($chiffres) { |
|
| 925 | - $texte = preg_replace_callback( |
|
| 926 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 927 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 928 | - $texte |
|
| 929 | - ); |
|
| 930 | - } |
|
| 924 | + if ($chiffres) { |
|
| 925 | + $texte = preg_replace_callback( |
|
| 926 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 927 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 928 | + $texte |
|
| 929 | + ); |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | - return $texte; |
|
| 932 | + return $texte; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
@@ -941,7 +941,7 @@ discard block |
||
| 941 | 941 | * @return string |
| 942 | 942 | */ |
| 943 | 943 | function translitteration_chiffree($car) { |
| 944 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 944 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | * true s'il a un BOM |
| 955 | 955 | **/ |
| 956 | 956 | function bom_utf8($texte) { |
| 957 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 957 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -971,21 +971,21 @@ discard block |
||
| 971 | 971 | * true si c'est le cas |
| 972 | 972 | **/ |
| 973 | 973 | function is_utf8($string) { |
| 974 | - return !strlen( |
|
| 975 | - preg_replace( |
|
| 976 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 977 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 978 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 979 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 980 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 981 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 982 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 983 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 984 | - . ',sS', |
|
| 985 | - '', |
|
| 986 | - $string |
|
| 987 | - ) |
|
| 988 | - ); |
|
| 974 | + return !strlen( |
|
| 975 | + preg_replace( |
|
| 976 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 977 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 978 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 979 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 980 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 981 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 982 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 983 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 984 | + . ',sS', |
|
| 985 | + '', |
|
| 986 | + $string |
|
| 987 | + ) |
|
| 988 | + ); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
@@ -997,13 +997,13 @@ discard block |
||
| 997 | 997 | * true si c'est le cas |
| 998 | 998 | **/ |
| 999 | 999 | function is_ascii($string) { |
| 1000 | - return !strlen( |
|
| 1001 | - preg_replace( |
|
| 1002 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1003 | - '', |
|
| 1004 | - $string |
|
| 1005 | - ) |
|
| 1006 | - ); |
|
| 1000 | + return !strlen( |
|
| 1001 | + preg_replace( |
|
| 1002 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1003 | + '', |
|
| 1004 | + $string |
|
| 1005 | + ) |
|
| 1006 | + ); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1022,53 +1022,53 @@ discard block |
||
| 1022 | 1022 | **/ |
| 1023 | 1023 | function transcoder_page($texte, $headers = '') { |
| 1024 | 1024 | |
| 1025 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1026 | - if (is_ascii($texte)) { |
|
| 1027 | - #spip_log('charset: ascii'); |
|
| 1028 | - return $texte; |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - if (bom_utf8($texte)) { |
|
| 1032 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1033 | - $charset = 'utf-8'; |
|
| 1034 | - $texte = substr($texte, 3); |
|
| 1035 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1036 | - // charset precise par le contenu (xml) |
|
| 1037 | - $charset = trim(strtolower($regs[1])); |
|
| 1038 | - } elseif ( |
|
| 1039 | - // charset precise par le contenu (html) |
|
| 1040 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1041 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1042 | - and false === strpos($regs[2], '#') |
|
| 1043 | - and $tmp = trim(strtolower($regs[2])) |
|
| 1044 | - ) { |
|
| 1045 | - $charset = $tmp; |
|
| 1046 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1047 | - // charset de la reponse http |
|
| 1048 | - $charset = trim(strtolower($regs[1])); |
|
| 1049 | - } else { |
|
| 1050 | - $charset = ''; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - // normaliser les noms du shif-jis japonais |
|
| 1055 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1056 | - $charset = 'shift-jis'; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - if ($charset) { |
|
| 1060 | - spip_log("charset: $charset"); |
|
| 1061 | - } else { |
|
| 1062 | - // valeur par defaut |
|
| 1063 | - if (is_utf8($texte)) { |
|
| 1064 | - $charset = 'utf-8'; |
|
| 1065 | - } else { |
|
| 1066 | - $charset = 'iso-8859-1'; |
|
| 1067 | - } |
|
| 1068 | - spip_log("charset probable: $charset"); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - return importer_charset($texte, $charset); |
|
| 1025 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1026 | + if (is_ascii($texte)) { |
|
| 1027 | + #spip_log('charset: ascii'); |
|
| 1028 | + return $texte; |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + if (bom_utf8($texte)) { |
|
| 1032 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1033 | + $charset = 'utf-8'; |
|
| 1034 | + $texte = substr($texte, 3); |
|
| 1035 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1036 | + // charset precise par le contenu (xml) |
|
| 1037 | + $charset = trim(strtolower($regs[1])); |
|
| 1038 | + } elseif ( |
|
| 1039 | + // charset precise par le contenu (html) |
|
| 1040 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1041 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1042 | + and false === strpos($regs[2], '#') |
|
| 1043 | + and $tmp = trim(strtolower($regs[2])) |
|
| 1044 | + ) { |
|
| 1045 | + $charset = $tmp; |
|
| 1046 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1047 | + // charset de la reponse http |
|
| 1048 | + $charset = trim(strtolower($regs[1])); |
|
| 1049 | + } else { |
|
| 1050 | + $charset = ''; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + // normaliser les noms du shif-jis japonais |
|
| 1055 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1056 | + $charset = 'shift-jis'; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + if ($charset) { |
|
| 1060 | + spip_log("charset: $charset"); |
|
| 1061 | + } else { |
|
| 1062 | + // valeur par defaut |
|
| 1063 | + if (is_utf8($texte)) { |
|
| 1064 | + $charset = 'utf-8'; |
|
| 1065 | + } else { |
|
| 1066 | + $charset = 'iso-8859-1'; |
|
| 1067 | + } |
|
| 1068 | + spip_log("charset probable: $charset"); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + return importer_charset($texte, $charset); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | |
@@ -1092,26 +1092,26 @@ discard block |
||
| 1092 | 1092 | * Le texte coupé |
| 1093 | 1093 | **/ |
| 1094 | 1094 | function spip_substr($c, $start = 0, $length = null) { |
| 1095 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1096 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1097 | - if ($length) { |
|
| 1098 | - return substr($c, $start, $length); |
|
| 1099 | - } else { |
|
| 1100 | - return substr($c, $start); |
|
| 1101 | - } |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1105 | - if (init_mb_string()) { |
|
| 1106 | - if ($length) { |
|
| 1107 | - return mb_substr($c, $start, $length); |
|
| 1108 | - } else { |
|
| 1109 | - return mb_substr($c, $start); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // Version manuelle (cf. ci-dessous) |
|
| 1114 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1095 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1096 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1097 | + if ($length) { |
|
| 1098 | + return substr($c, $start, $length); |
|
| 1099 | + } else { |
|
| 1100 | + return substr($c, $start); |
|
| 1101 | + } |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1105 | + if (init_mb_string()) { |
|
| 1106 | + if ($length) { |
|
| 1107 | + return mb_substr($c, $start, $length); |
|
| 1108 | + } else { |
|
| 1109 | + return mb_substr($c, $start); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // Version manuelle (cf. ci-dessous) |
|
| 1114 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1130,40 +1130,40 @@ discard block |
||
| 1130 | 1130 | **/ |
| 1131 | 1131 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1132 | 1132 | |
| 1133 | - // Cas pathologique |
|
| 1134 | - if ($length === 0) { |
|
| 1135 | - return ''; |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - // S'il y a un demarrage, on se positionne |
|
| 1139 | - if ($start > 0) { |
|
| 1140 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1141 | - } elseif ($start < 0) { |
|
| 1142 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - if (!$length) { |
|
| 1146 | - return $c; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - if ($length > 0) { |
|
| 1150 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1151 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1152 | - $n = 0; |
|
| 1153 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1154 | - ; |
|
| 1155 | - } |
|
| 1156 | - $c = substr($c, 0, $n * $length); |
|
| 1157 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1158 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1159 | - $c = substr($c, 0, $length - $l); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - return $c; |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - // $length < 0 |
|
| 1166 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1133 | + // Cas pathologique |
|
| 1134 | + if ($length === 0) { |
|
| 1135 | + return ''; |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + // S'il y a un demarrage, on se positionne |
|
| 1139 | + if ($start > 0) { |
|
| 1140 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1141 | + } elseif ($start < 0) { |
|
| 1142 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + if (!$length) { |
|
| 1146 | + return $c; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + if ($length > 0) { |
|
| 1150 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1151 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1152 | + $n = 0; |
|
| 1153 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1154 | + ; |
|
| 1155 | + } |
|
| 1156 | + $c = substr($c, 0, $n * $length); |
|
| 1157 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1158 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1159 | + $c = substr($c, 0, $length - $l); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + return $c; |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + // $length < 0 |
|
| 1166 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | /** |
@@ -1177,14 +1177,14 @@ discard block |
||
| 1177 | 1177 | * La chaîne avec une majuscule sur le premier mot |
| 1178 | 1178 | */ |
| 1179 | 1179 | function spip_ucfirst($c) { |
| 1180 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1181 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1182 | - return ucfirst($c); |
|
| 1183 | - } |
|
| 1180 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1181 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1182 | + return ucfirst($c); |
|
| 1183 | + } |
|
| 1184 | 1184 | |
| 1185 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1185 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1186 | 1186 | |
| 1187 | - return $lettre1 . spip_substr($c, 1); |
|
| 1187 | + return $lettre1 . spip_substr($c, 1); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1198,12 +1198,12 @@ discard block |
||
| 1198 | 1198 | * La chaîne en minuscules |
| 1199 | 1199 | */ |
| 1200 | 1200 | function spip_strtolower($c) { |
| 1201 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1202 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1203 | - return strtolower($c); |
|
| 1204 | - } |
|
| 1201 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1202 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1203 | + return strtolower($c); |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | - return mb_strtolower($c); |
|
| 1206 | + return mb_strtolower($c); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | /** |
@@ -1217,23 +1217,23 @@ discard block |
||
| 1217 | 1217 | * Longueur de la chaîne |
| 1218 | 1218 | */ |
| 1219 | 1219 | function spip_strlen($c) { |
| 1220 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1221 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1222 | - |
|
| 1223 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1224 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1225 | - return strlen($c); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1229 | - if (init_mb_string()) { |
|
| 1230 | - return mb_strlen($c); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1234 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1235 | - // de caracteres utf-8 (11......) |
|
| 1236 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1220 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1221 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1222 | + |
|
| 1223 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1224 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1225 | + return strlen($c); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1229 | + if (init_mb_string()) { |
|
| 1230 | + return mb_strlen($c); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1234 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1235 | + // de caracteres utf-8 (11......) |
|
| 1236 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | // Initialisation |
@@ -1243,16 +1243,16 @@ discard block |
||
| 1243 | 1243 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1244 | 1244 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1245 | 1245 | if ( |
| 1246 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 1247 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1246 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 1247 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1248 | 1248 | ) { |
| 1249 | - include_spip('inc/meta'); |
|
| 1250 | - ecrire_meta( |
|
| 1251 | - 'pcre_u', |
|
| 1252 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1253 | - and test_pcre_unicode()) |
|
| 1254 | - ? 'u' : '' |
|
| 1255 | - ); |
|
| 1249 | + include_spip('inc/meta'); |
|
| 1250 | + ecrire_meta( |
|
| 1251 | + 'pcre_u', |
|
| 1252 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1253 | + and test_pcre_unicode()) |
|
| 1254 | + ? 'u' : '' |
|
| 1255 | + ); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | |
@@ -1268,17 +1268,17 @@ discard block |
||
| 1268 | 1268 | * en unicode : 💩 |
| 1269 | 1269 | */ |
| 1270 | 1270 | function utf8_noplanes($x) { |
| 1271 | - $regexp_utf8_4bytes = '/( |
|
| 1271 | + $regexp_utf8_4bytes = '/( |
|
| 1272 | 1272 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1273 | 1273 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1274 | 1274 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1275 | 1275 | )/xS'; |
| 1276 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1277 | - foreach ($z[0] as $k) { |
|
| 1278 | - $ku = utf_8_to_unicode($k); |
|
| 1279 | - $x = str_replace($k, $ku, $x); |
|
| 1280 | - } |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - return $x; |
|
| 1276 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1277 | + foreach ($z[0] as $k) { |
|
| 1278 | + $ku = utf_8_to_unicode($k); |
|
| 1279 | + $x = str_replace($k, $ku, $x); |
|
| 1280 | + } |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + return $x; |
|
| 1284 | 1284 | } |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | $res = sql_select( |
| 36 | 36 | 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
| 37 | 37 | 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
| 38 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 39 | - AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
|
| 40 | - AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
|
| 38 | + 'rub1.id_parent = '.sql_quote($id_rubrique).' |
|
| 39 | + AND rub1.id_rubrique!=' . sql_quote($exclu).' |
|
| 40 | + AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu).')', |
|
| 41 | 41 | '', |
| 42 | 42 | '0+rub1.titre,rub1.titre' |
| 43 | 43 | ); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if ($row['langue_choisie'] != 'oui') { |
| 51 | 51 | $t .= ' <small title="' |
| 52 | 52 | . traduire_nom_langue($row['lang']) |
| 53 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | + . '">['.$row['lang'].']</small>'; |
|
| 54 | 54 | } |
| 55 | 55 | $ordre[$row['id_rubrique']] = $t; |
| 56 | 56 | } |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | $next = $list[$col] ?? 0; |
| 60 | 60 | if ($ordre) { |
| 61 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=".($col + 1)); |
|
| 62 | 62 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
| 63 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 63 | + $args = "'$idom',this,$col,'".$GLOBALS['spip_lang_left']."','$info',event"; |
|
| 64 | 64 | |
| 65 | 65 | foreach ($ordre as $id => $titrebrut) { |
| 66 | 66 | $titre = supprimer_numero($titrebrut); |
| 67 | 67 | |
| 68 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | + $classe1 = 'petit-item '.($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | 69 | if (isset($rub[$id]['enfants'])) { |
| 70 | 70 | $classe2 = " class='rub-ouverte'"; |
| 71 | 71 | $url = "\nhref='$rec&id=$id'"; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $url = "\nhref='javascript:void(0)'"; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $js_func = $do . '_selection_titre'; |
|
| 77 | + $js_func = $do.'_selection_titre'; |
|
| 78 | 78 | $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
| 79 | 79 | . (!is_array($list) ? ' false' |
| 80 | 80 | : "aff_selection_provisoire($id,$args)") |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | + $idom2 = $idom.'_col_'.($col + 1); |
|
| 105 | 105 | $left = ($col * 250); |
| 106 | 106 | |
| 107 | 107 | return http_img_pack( |
| 108 | 108 | 'loader.svg', |
| 109 | 109 | '', |
| 110 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | + "class='loader' style='visibility: hidden; position: absolute; ".$GLOBALS['spip_lang_left'].': ' |
|
| 111 | 111 | . ($left - 30) |
| 112 | 112 | . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
| 113 | 113 | ) |
| 114 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; ".$GLOBALS['spip_lang_left'].': ' |
|
| 115 | 115 | . ($left - 250) |
| 116 | 116 | . "px;'>" |
| 117 | 117 | . $ret |
@@ -11,112 +11,112 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/texte'); |
| 18 | 18 | |
| 19 | 19 | function inc_plonger_dist($id_rubrique, $idom = '', $list = [], $col = 1, $exclu = 0, $do = 'aff') { |
| 20 | 20 | |
| 21 | - if ($list) { |
|
| 22 | - $id_rubrique = $list[$col - 1]; |
|
| 23 | - } |
|
| 21 | + if ($list) { |
|
| 22 | + $id_rubrique = $list[$col - 1]; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - $ret = ''; |
|
| 25 | + $ret = ''; |
|
| 26 | 26 | |
| 27 | - # recherche les filles et petites-filles de la rubrique donnee |
|
| 28 | - # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 29 | - # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 30 | - # racine... sauf vers elle-meme ou sa propre branche) |
|
| 31 | - $ordre = []; |
|
| 32 | - $rub = []; |
|
| 27 | + # recherche les filles et petites-filles de la rubrique donnee |
|
| 28 | + # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 29 | + # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 30 | + # racine... sauf vers elle-meme ou sa propre branche) |
|
| 31 | + $ordre = []; |
|
| 32 | + $rub = []; |
|
| 33 | 33 | |
| 34 | - $res = sql_select( |
|
| 35 | - 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 36 | - 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 37 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 34 | + $res = sql_select( |
|
| 35 | + 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 36 | + 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 37 | + 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 38 | 38 | AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
| 39 | 39 | AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
| 40 | - '', |
|
| 41 | - '0+rub1.titre,rub1.titre' |
|
| 42 | - ); |
|
| 40 | + '', |
|
| 41 | + '0+rub1.titre,rub1.titre' |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - while ($row = sql_fetch($res)) { |
|
| 45 | - if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 46 | - $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 47 | - if ($row['id_parent'] == $id_rubrique) { |
|
| 48 | - $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 49 | - if ($row['langue_choisie'] != 'oui') { |
|
| 50 | - $t .= ' <small title="' |
|
| 51 | - . traduire_nom_langue($row['lang']) |
|
| 52 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | - } |
|
| 54 | - $ordre[$row['id_rubrique']] = $t; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - $next = $list[$col] ?? 0; |
|
| 59 | - if ($ordre) { |
|
| 60 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 62 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 44 | + while ($row = sql_fetch($res)) { |
|
| 45 | + if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 46 | + $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 47 | + if ($row['id_parent'] == $id_rubrique) { |
|
| 48 | + $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 49 | + if ($row['langue_choisie'] != 'oui') { |
|
| 50 | + $t .= ' <small title="' |
|
| 51 | + . traduire_nom_langue($row['lang']) |
|
| 52 | + . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | + } |
|
| 54 | + $ordre[$row['id_rubrique']] = $t; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + $next = $list[$col] ?? 0; |
|
| 59 | + if ($ordre) { |
|
| 60 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 62 | + $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 63 | 63 | |
| 64 | - foreach ($ordre as $id => $titrebrut) { |
|
| 65 | - $titre = supprimer_numero($titrebrut); |
|
| 64 | + foreach ($ordre as $id => $titrebrut) { |
|
| 65 | + $titre = supprimer_numero($titrebrut); |
|
| 66 | 66 | |
| 67 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | - if (isset($rub[$id]['enfants'])) { |
|
| 69 | - $classe2 = " class='rub-ouverte'"; |
|
| 70 | - $url = "\nhref='$rec&id=$id'"; |
|
| 71 | - } else { |
|
| 72 | - $classe2 = $url = ''; |
|
| 73 | - $url = "\nhref='javascript:void(0)'"; |
|
| 74 | - } |
|
| 67 | + $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | + if (isset($rub[$id]['enfants'])) { |
|
| 69 | + $classe2 = " class='rub-ouverte'"; |
|
| 70 | + $url = "\nhref='$rec&id=$id'"; |
|
| 71 | + } else { |
|
| 72 | + $classe2 = $url = ''; |
|
| 73 | + $url = "\nhref='javascript:void(0)'"; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $js_func = $do . '_selection_titre'; |
|
| 77 | - $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 78 | - . (!is_array($list) ? ' false' |
|
| 79 | - : "aff_selection_provisoire($id,$args)") |
|
| 76 | + $js_func = $do . '_selection_titre'; |
|
| 77 | + $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 78 | + . (!is_array($list) ? ' false' |
|
| 79 | + : "aff_selection_provisoire($id,$args)") |
|
| 80 | 80 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 81 | 81 | # et l'affichage de son titre dans le bandeau |
| 82 | - . "\"\nondblclick=\"" |
|
| 83 | - . "$js_func(this." |
|
| 84 | - . 'firstChild.nodeValue,' |
|
| 85 | - . $id |
|
| 86 | - . ",'selection_rubrique','id_parent');" |
|
| 87 | - . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 88 | - . '"'; |
|
| 82 | + . "\"\nondblclick=\"" |
|
| 83 | + . "$js_func(this." |
|
| 84 | + . 'firstChild.nodeValue,' |
|
| 85 | + . $id |
|
| 86 | + . ",'selection_rubrique','id_parent');" |
|
| 87 | + . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 88 | + . '"'; |
|
| 89 | 89 | |
| 90 | - $ret .= "<div class='" |
|
| 91 | - . (($id == $next) ? 'item on' : 'item') |
|
| 92 | - . "'><div class='" |
|
| 93 | - . $classe1 |
|
| 94 | - . "'><div$classe2><a" |
|
| 95 | - . $url |
|
| 96 | - . $click |
|
| 97 | - . '>' |
|
| 98 | - . $titre |
|
| 99 | - . '</a></div></div></div>'; |
|
| 100 | - } |
|
| 101 | - } |
|
| 90 | + $ret .= "<div class='" |
|
| 91 | + . (($id == $next) ? 'item on' : 'item') |
|
| 92 | + . "'><div class='" |
|
| 93 | + . $classe1 |
|
| 94 | + . "'><div$classe2><a" |
|
| 95 | + . $url |
|
| 96 | + . $click |
|
| 97 | + . '>' |
|
| 98 | + . $titre |
|
| 99 | + . '</a></div></div></div>'; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | - $left = ($col * 250); |
|
| 103 | + $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | + $left = ($col * 250); |
|
| 105 | 105 | |
| 106 | - return http_img_pack( |
|
| 107 | - 'loader.svg', |
|
| 108 | - '', |
|
| 109 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | - . ($left - 30) |
|
| 111 | - . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 112 | - ) |
|
| 113 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | - . ($left - 250) |
|
| 115 | - . "px;'>" |
|
| 116 | - . $ret |
|
| 117 | - . "\n</div>\n<div id='$idom2'>" |
|
| 118 | - . ($next |
|
| 119 | - ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 120 | - : '') |
|
| 121 | - . "\n</div>"; |
|
| 106 | + return http_img_pack( |
|
| 107 | + 'loader.svg', |
|
| 108 | + '', |
|
| 109 | + "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | + . ($left - 30) |
|
| 111 | + . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 112 | + ) |
|
| 113 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | + . ($left - 250) |
|
| 115 | + . "px;'>" |
|
| 116 | + . $ret |
|
| 117 | + . "\n</div>\n<div id='$idom2'>" |
|
| 118 | + . ($next |
|
| 119 | + ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 120 | + : '') |
|
| 121 | + . "\n</div>"; |
|
| 122 | 122 | } |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | foreach (['script', 'iframe'] as $tag) { |
| 106 | 106 | if ( |
| 107 | 107 | stripos($t, (string) "<$tag") !== false |
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | 109 | ) { |
| 110 | 110 | foreach ($r as $regs) { |
| 111 | 111 | $t = str_replace( |
| 112 | 112 | $regs[0], |
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 113 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 114 | 114 | $t |
| 115 | 115 | ); |
| 116 | 116 | } |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // echapper les tags asp/php |
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 166 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le php |
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 169 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 170 | 170 | |
| 171 | 171 | // echapper le < script language=php > |
| 172 | 172 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | // Reinserer les echappements des modeles |
| 190 | 190 | if (defined('_PROTEGE_JS_MODELES')) { |
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 191 | + $t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 194 | + $t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 290 | 290 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 291 | 291 | |
| 292 | -define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS'); |
|
| 292 | +define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS'); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Corrige la typographie |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return ['', '']; |
|
| 37 | + return ['', '']; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * Texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter à part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter à part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string Texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,40 +415,40 @@ discard block |
||
| 415 | 415 | * Texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - $env['espace_prive'] = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$t) { |
|
| 432 | - return strval($t); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | - // avant echappement des balises <html> |
|
| 437 | - // https://core.spip.net/issues/3371 |
|
| 438 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | - // https://core.spip.net/issues/4166 |
|
| 440 | - if ( |
|
| 441 | - $interdire_script |
|
| 442 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | - or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | - ) { |
|
| 446 | - $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | - } |
|
| 448 | - $t = echappe_html($t); |
|
| 449 | - $t = expanser_liens($t, $connect, $env); |
|
| 450 | - $t = traiter_raccourcis($t); |
|
| 451 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | - |
|
| 453 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + $env['espace_prive'] = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$t) { |
|
| 432 | + return strval($t); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | + // avant echappement des balises <html> |
|
| 437 | + // https://core.spip.net/issues/3371 |
|
| 438 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | + // https://core.spip.net/issues/4166 |
|
| 440 | + if ( |
|
| 441 | + $interdire_script |
|
| 442 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | + or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | + ) { |
|
| 446 | + $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | + } |
|
| 448 | + $t = echappe_html($t); |
|
| 449 | + $t = expanser_liens($t, $connect, $env); |
|
| 450 | + $t = traiter_raccourcis($t); |
|
| 451 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | + |
|
| 453 | + return $t; |
|
| 454 | 454 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | $_texte = ($_texte ?: "''"); |
| 52 | 52 | $_titre = ($_titre ? ", $_titre" : ', null'); |
| 53 | 53 | $_class = ($_class ? ", $_class" : ', null'); |
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | 57 | $f = chercher_filtre('message_alerte'); |
| 58 | 58 | $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | $_class = interprete_argument_balise(2, $p); |
| 91 | 91 | $_role = interprete_argument_balise(3, $p); |
| 92 | 92 | $_id = interprete_argument_balise(4, $p); |
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | 94 | $_class = ($_class ? ", $_class" : ', null'); |
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | 98 | $f = chercher_filtre('message_alerte_ouvrir'); |
| 99 | 99 | $p->code = "$f($_titre$_class$_role$_id)"; |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
| 164 | 164 | $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
| 165 | 165 | $message = |
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id). |
|
| 167 | + $texte. |
|
| 168 | 168 | $message_alerte_fermer(); |
| 169 | 169 | |
| 170 | 170 | return $message; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | ]; |
| 214 | 214 | $type = array_intersect(explode(' ', $class), $types); |
| 215 | 215 | $type = reset($type); |
| 216 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 216 | + $class = trim(str_replace($types, '', $class)." $type"); |
|
| 217 | 217 | |
| 218 | 218 | // Classes |
| 219 | 219 | $class_racine = 'msg-alert'; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | // Attributs |
| 240 | 240 | $attr_role = ($role ? "role=\"$role\"" : ''); |
| 241 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 241 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | 242 | $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
| 243 | 243 | |
| 244 | 244 | $message = |
@@ -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 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ?: "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ?: "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,56 +198,56 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $titre = trim($titre ?? ''); |
|
| 205 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 206 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $titre = trim($titre ?? ''); |
|
| 205 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 206 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 207 | 207 | |
| 208 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 209 | - $types = [ |
|
| 210 | - 'notice', |
|
| 211 | - 'error', |
|
| 212 | - 'success', |
|
| 213 | - 'info', |
|
| 214 | - ]; |
|
| 215 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 216 | - $type = reset($type); |
|
| 217 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 208 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 209 | + $types = [ |
|
| 210 | + 'notice', |
|
| 211 | + 'error', |
|
| 212 | + 'success', |
|
| 213 | + 'info', |
|
| 214 | + ]; |
|
| 215 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 216 | + $type = reset($type); |
|
| 217 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 218 | 218 | |
| 219 | - // Classes |
|
| 220 | - $class_racine = 'msg-alert'; |
|
| 221 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 222 | - $class_alerte = "$class_racine $class"; |
|
| 223 | - $class_texte = "{$class_racine}__text $clearfix"; |
|
| 224 | - $class_titre = "{$class_racine}__heading"; |
|
| 219 | + // Classes |
|
| 220 | + $class_racine = 'msg-alert'; |
|
| 221 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 222 | + $class_alerte = "$class_racine $class"; |
|
| 223 | + $class_texte = "{$class_racine}__text $clearfix"; |
|
| 224 | + $class_titre = "{$class_racine}__heading"; |
|
| 225 | 225 | |
| 226 | - // Titre : markup |
|
| 227 | - $titre = trim($titre); |
|
| 228 | - if (strlen($titre)) { |
|
| 229 | - include_spip('inc/filtres'); |
|
| 230 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 231 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 232 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 233 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 234 | - $titre = wrap($titre, $wrap_tag); |
|
| 235 | - } |
|
| 236 | - // puis on ajoute la classe |
|
| 237 | - $titre = ajouter_class($titre, $class_titre); |
|
| 238 | - } |
|
| 226 | + // Titre : markup |
|
| 227 | + $titre = trim($titre); |
|
| 228 | + if (strlen($titre)) { |
|
| 229 | + include_spip('inc/filtres'); |
|
| 230 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 231 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 232 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 233 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 234 | + $titre = wrap($titre, $wrap_tag); |
|
| 235 | + } |
|
| 236 | + // puis on ajoute la classe |
|
| 237 | + $titre = ajouter_class($titre, $class_titre); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Attributs |
|
| 241 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 242 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 243 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 240 | + // Attributs |
|
| 241 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 242 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 243 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 244 | 244 | |
| 245 | - $message = |
|
| 246 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 247 | - . $titre |
|
| 248 | - . "<div class=\"$class_texte\">"; |
|
| 245 | + $message = |
|
| 246 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 247 | + . $titre |
|
| 248 | + . "<div class=\"$class_texte\">"; |
|
| 249 | 249 | |
| 250 | - return $message; |
|
| 250 | + return $message; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -261,5 +261,5 @@ discard block |
||
| 261 | 261 | * HTML de fin de l'alerte |
| 262 | 262 | */ |
| 263 | 263 | function message_alerte_fermer(): string { |
| 264 | - return '</div></div>'; |
|
| 264 | + return '</div></div>'; |
|
| 265 | 265 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | ) { |
| 39 | 39 | // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
| 40 | 40 | include_spip('inc/autoriser'); |
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 41 | + if (!autoriser('configurer', '_'.substr($form, 11))) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
| 73 | 73 | ) { |
| 74 | 74 | $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return $flux; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $prefixe = $valeurs['_meta_prefixe']; |
| 147 | 147 | } |
| 148 | 148 | if (isset($valeurs['_meta_stockage'])) { |
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | + $stockage = $valeurs['_meta_stockage'].'::'; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // si on indique juste une table, il faut vider les autres proprietes |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // sinon cas analyse du squelette |
| 173 | 173 | if ( |
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 174 | + $f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | 175 | and lire_fichier($f, $contenu) |
| 176 | 176 | ) { |
| 177 | 177 | for ($i = 0; $i < 2; $i++) { |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | lire_metas($table); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 231 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 232 | 232 | $table = ($table) ? "/$table/" : ''; |
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/').'/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | 235 | foreach ($store as $k => $v) { |
| 236 | 236 | ecrire_config("$stockage$table$prefixe$casier$k", $v); |
| 237 | 237 | if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 238 | + $trace .= "<br />table $table : ".$prefixe.$k." = $v;"; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
| 253 | 253 | |
| 254 | 254 | $table = ($table) ? "/$table/" : ''; |
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 255 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 256 | 256 | if ($casier) { |
| 257 | 257 | $meta = lire_config("$stockage$table$prefixe$casier"); |
| 258 | 258 | $prefixe = ''; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | foreach ($valeurs as $k => $v) { |
| 265 | 265 | if (substr($k, 0, 1) !== '_') { |
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe.$k] ?? null); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | include_spip('inc/config'); |
@@ -32,31 +32,31 @@ discard block |
||
| 32 | 32 | * @return array|false |
| 33 | 33 | */ |
| 34 | 34 | function cvtconf_formulaire_charger($flux) { |
| 35 | - if ( |
|
| 36 | - $form = $flux['args']['form'] |
|
| 37 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | - ) { |
|
| 39 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | - include_spip('inc/autoriser'); |
|
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 35 | + if ( |
|
| 36 | + $form = $flux['args']['form'] |
|
| 37 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | + ) { |
|
| 39 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | + include_spip('inc/autoriser'); |
|
| 41 | + if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | - $flux['data']['editable'] = true; |
|
| 49 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | - if (!_AJAX) { |
|
| 51 | - var_dump($flux['data']); |
|
| 52 | - } |
|
| 53 | - // reinjecter pour la trace au traitement |
|
| 54 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 45 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | + $flux['data']['editable'] = true; |
|
| 49 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | + if (!_AJAX) { |
|
| 51 | + var_dump($flux['data']); |
|
| 52 | + } |
|
| 53 | + // reinjecter pour la trace au traitement |
|
| 54 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $flux; |
|
| 59 | + return $flux; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | 68 | function cvtconf_formulaire_traiter($flux) { |
| 69 | - if ( |
|
| 70 | - $form = $flux['args']['form'] |
|
| 71 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | - and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | - ) { |
|
| 74 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | - } |
|
| 69 | + if ( |
|
| 70 | + $form = $flux['args']['form'] |
|
| 71 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | + and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | + ) { |
|
| 74 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - return $flux; |
|
| 78 | + return $flux; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | 93 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 94 | - $valeurs = []; |
|
| 95 | - // charger les valeurs |
|
| 96 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | - // qui prend alors la main sur l'auto detection |
|
| 98 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | - $valeurs = $charger_valeurs(...$args); |
|
| 100 | - } |
|
| 101 | - $valeurs = pipeline( |
|
| 102 | - 'formulaire_charger', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | - 'data' => $valeurs |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - // ne pas stocker editable ! |
|
| 109 | - unset($valeurs['editable']); |
|
| 94 | + $valeurs = []; |
|
| 95 | + // charger les valeurs |
|
| 96 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | + // qui prend alors la main sur l'auto detection |
|
| 98 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | + $valeurs = $charger_valeurs(...$args); |
|
| 100 | + } |
|
| 101 | + $valeurs = pipeline( |
|
| 102 | + 'formulaire_charger', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | + 'data' => $valeurs |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + // ne pas stocker editable ! |
|
| 109 | + unset($valeurs['editable']); |
|
| 110 | 110 | |
| 111 | - // recuperer les valeurs postees |
|
| 112 | - $store = []; |
|
| 113 | - foreach ($valeurs as $k => $v) { |
|
| 114 | - if (substr($k, 0, 1) !== '_') { |
|
| 115 | - $store[$k] = _request($k); |
|
| 116 | - } |
|
| 117 | - } |
|
| 111 | + // recuperer les valeurs postees |
|
| 112 | + $store = []; |
|
| 113 | + foreach ($valeurs as $k => $v) { |
|
| 114 | + if (substr($k, 0, 1) !== '_') { |
|
| 115 | + $store[$k] = _request($k); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -132,31 +132,31 @@ discard block |
||
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | 134 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 135 | - // stocker en base |
|
| 136 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | - $casier = substr($form, 11); |
|
| 138 | - $table = 'meta'; |
|
| 139 | - $prefixe = ''; |
|
| 140 | - $stockage = ''; |
|
| 135 | + // stocker en base |
|
| 136 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | + $casier = substr($form, 11); |
|
| 138 | + $table = 'meta'; |
|
| 139 | + $prefixe = ''; |
|
| 140 | + $stockage = ''; |
|
| 141 | 141 | |
| 142 | - if (isset($valeurs['_meta_casier'])) { |
|
| 143 | - $casier = $valeurs['_meta_casier']; |
|
| 144 | - } |
|
| 145 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | - } |
|
| 148 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | - } |
|
| 142 | + if (isset($valeurs['_meta_casier'])) { |
|
| 143 | + $casier = $valeurs['_meta_casier']; |
|
| 144 | + } |
|
| 145 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | + } |
|
| 148 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | - if (isset($valeurs['_meta_table'])) { |
|
| 155 | - $table = $valeurs['_meta_table']; |
|
| 156 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | - } |
|
| 152 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | + if (isset($valeurs['_meta_table'])) { |
|
| 155 | + $table = $valeurs['_meta_table']; |
|
| 156 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -167,48 +167,48 @@ discard block |
||
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | 169 | function cvtconf_formulaires_configurer_recense($form) { |
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | - and lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | + and lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - $n = extraire_attribut($b, 'name') |
|
| 193 | - and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | - and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + $n = extraire_attribut($b, 'name') |
|
| 193 | + and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | + and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach ($valeurs as $k => $v) { |
|
| 265 | - if (substr($k, 0, 1) !== '_') { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach ($valeurs as $k => $v) { |
|
| 265 | + if (substr($k, 0, 1) !== '_') { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | $hsl = _couleur_hex_to_hsl($couleur); |
| 205 | 205 | $hsl = [ |
| 206 | 206 | 'h' => round($hsl['h'] * 360), |
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 207 | + 's' => round($hsl['s'] * 100).'%', |
|
| 208 | + 'l' => round($hsl['l'] * 100).'%' |
|
| 209 | 209 | ]; |
| 210 | 210 | if ($format === null) { |
| 211 | 211 | return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | $process = 'AUTO' |
| 385 | 385 | ) { |
| 386 | 386 | // PHP 7+ type hint |
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 387 | + $img = (string) $img; |
|
| 388 | + $taille_x = (int) $taille_x; |
|
| 389 | + $taille_y = (int) $taille_y; |
|
| 390 | + $force = (bool) $force; |
|
| 391 | + $process = (string) $process; |
|
| 392 | 392 | |
| 393 | 393 | if (!$img) { |
| 394 | 394 | return ''; |
@@ -465,11 +465,11 @@ discard block |
||
| 465 | 465 | $process = 'AUTO' |
| 466 | 466 | ) { |
| 467 | 467 | // PHP 7+ type hint |
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 468 | + $img = (string) $img; |
|
| 469 | + $taille = (int) $taille; |
|
| 470 | + $taille_y = (int) $taille_y; |
|
| 471 | + $force = (bool) $force; |
|
| 472 | + $process = (string) $process; |
|
| 473 | 473 | |
| 474 | 474 | // Determiner la taille x,y maxi |
| 475 | 475 | // prendre le reglage de previsu par defaut |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $background_color = 'white' |
| 513 | 513 | ) { |
| 514 | 514 | if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 515 | + return image_reduire(image_recadre($im, $width.':'.$height, '-', $position, $background_color), $width, $height); |
|
| 516 | 516 | } else { return image_passe_partout($im, $width, $height); |
| 517 | 517 | } |
| 518 | 518 | } |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | 535 | // PHP 7+ type hint |
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 536 | + $img = (string) $img; |
|
| 537 | + $val = (int) $val; |
|
| 538 | + $force = (bool) $force; |
|
| 539 | 539 | |
| 540 | 540 | [$hauteur, $largeur] = taille_image($img); |
| 541 | 541 | |
@@ -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 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 24 | 24 | |
@@ -31,161 +31,161 @@ discard block |
||
| 31 | 31 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 32 | 32 | */ |
| 33 | 33 | function couleur_html_to_hex($couleur) { |
| 34 | - $couleurs_html = [ |
|
| 35 | - 'aliceblue' => 'F0F8FF', |
|
| 36 | - 'antiquewhite' => 'FAEBD7', |
|
| 37 | - 'aqua' => '00FFFF', |
|
| 38 | - 'aquamarine' => '7FFFD4', |
|
| 39 | - 'azure' => 'F0FFFF', |
|
| 40 | - 'beige' => 'F5F5DC', |
|
| 41 | - 'bisque' => 'FFE4C4', |
|
| 42 | - 'black' => '000000', |
|
| 43 | - 'blanchedalmond' => 'FFEBCD', |
|
| 44 | - 'blue' => '0000FF', |
|
| 45 | - 'blueviolet' => '8A2BE2', |
|
| 46 | - 'brown' => 'A52A2A', |
|
| 47 | - 'burlywood' => 'DEB887', |
|
| 48 | - 'cadetblue' => '5F9EA0', |
|
| 49 | - 'chartreuse' => '7FFF00', |
|
| 50 | - 'chocolate' => 'D2691E', |
|
| 51 | - 'coral' => 'FF7F50', |
|
| 52 | - 'cornflowerblue' => '6495ED', |
|
| 53 | - 'cornsilk' => 'FFF8DC', |
|
| 54 | - 'crimson' => 'DC143C', |
|
| 55 | - 'cyan' => '00FFFF', |
|
| 56 | - 'darkblue' => '00008B', |
|
| 57 | - 'darkcyan' => '008B8B', |
|
| 58 | - 'darkgoldenrod' => 'B8860B', |
|
| 59 | - 'darkgray' => 'A9A9A9', |
|
| 60 | - 'darkgreen' => '006400', |
|
| 61 | - 'darkgrey' => 'A9A9A9', |
|
| 62 | - 'darkkhaki' => 'BDB76B', |
|
| 63 | - 'darkmagenta' => '8B008B', |
|
| 64 | - 'darkolivegreen' => '556B2F', |
|
| 65 | - 'darkorange' => 'FF8C00', |
|
| 66 | - 'darkorchid' => '9932CC', |
|
| 67 | - 'darkred' => '8B0000', |
|
| 68 | - 'darksalmon' => 'E9967A', |
|
| 69 | - 'darkseagreen' => '8FBC8F', |
|
| 70 | - 'darkslateblue' => '483D8B', |
|
| 71 | - 'darkslategray' => '2F4F4F', |
|
| 72 | - 'darkslategrey' => '2F4F4F', |
|
| 73 | - 'darkturquoise' => '00CED1', |
|
| 74 | - 'darkviolet' => '9400D3', |
|
| 75 | - 'deeppink' => 'FF1493', |
|
| 76 | - 'deepskyblue' => '00BFFF', |
|
| 77 | - 'dimgray' => '696969', |
|
| 78 | - 'dimgrey' => '696969', |
|
| 79 | - 'dodgerblue' => '1E90FF', |
|
| 80 | - 'firebrick' => 'B22222', |
|
| 81 | - 'floralwhite' => 'FFFAF0', |
|
| 82 | - 'forestgreen' => '228B22', |
|
| 83 | - 'fuchsia' => 'FF00FF', |
|
| 84 | - 'gainsboro' => 'DCDCDC', |
|
| 85 | - 'ghostwhite' => 'F8F8FF', |
|
| 86 | - 'gold' => 'FFD700', |
|
| 87 | - 'goldenrod' => 'DAA520', |
|
| 88 | - 'gray' => '808080', |
|
| 89 | - 'green' => '008000', |
|
| 90 | - 'greenyellow' => 'ADFF2F', |
|
| 91 | - 'grey' => '808080', |
|
| 92 | - 'honeydew' => 'F0FFF0', |
|
| 93 | - 'hotpink' => 'FF69B4', |
|
| 94 | - 'indianred' => 'CD5C5C', |
|
| 95 | - 'indigo' => '4B0082', |
|
| 96 | - 'ivory' => 'FFFFF0', |
|
| 97 | - 'khaki' => 'F0E68C', |
|
| 98 | - 'lavender' => 'E6E6FA', |
|
| 99 | - 'lavenderblush' => 'FFF0F5', |
|
| 100 | - 'lawngreen' => '7CFC00', |
|
| 101 | - 'lemonchiffon' => 'FFFACD', |
|
| 102 | - 'lightblue' => 'ADD8E6', |
|
| 103 | - 'lightcoral' => 'F08080', |
|
| 104 | - 'lightcyan' => 'E0FFFF', |
|
| 105 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | - 'lightgray' => 'D3D3D3', |
|
| 107 | - 'lightgreen' => '90EE90', |
|
| 108 | - 'lightgrey' => 'D3D3D3', |
|
| 109 | - 'lightpink' => 'FFB6C1', |
|
| 110 | - 'lightsalmon' => 'FFA07A', |
|
| 111 | - 'lightseagreen' => '20B2AA', |
|
| 112 | - 'lightskyblue' => '87CEFA', |
|
| 113 | - 'lightslategray' => '778899', |
|
| 114 | - 'lightslategrey' => '778899', |
|
| 115 | - 'lightsteelblue' => 'B0C4DE', |
|
| 116 | - 'lightyellow' => 'FFFFE0', |
|
| 117 | - 'lime' => '00FF00', |
|
| 118 | - 'limegreen' => '32CD32', |
|
| 119 | - 'linen' => 'FAF0E6', |
|
| 120 | - 'magenta' => 'FF00FF', |
|
| 121 | - 'maroon' => '800000', |
|
| 122 | - 'mediumaquamarine' => '66CDAA', |
|
| 123 | - 'mediumblue' => '0000CD', |
|
| 124 | - 'mediumorchid' => 'BA55D3', |
|
| 125 | - 'mediumpurple' => '9370DB', |
|
| 126 | - 'mediumseagreen' => '3CB371', |
|
| 127 | - 'mediumslateblue' => '7B68EE', |
|
| 128 | - 'mediumspringgreen' => '00FA9A', |
|
| 129 | - 'mediumturquoise' => '48D1CC', |
|
| 130 | - 'mediumvioletred' => 'C71585', |
|
| 131 | - 'midnightblue' => '191970', |
|
| 132 | - 'mintcream' => 'F5FFFA', |
|
| 133 | - 'mistyrose' => 'FFE4E1', |
|
| 134 | - 'moccasin' => 'FFE4B5', |
|
| 135 | - 'navajowhite' => 'FFDEAD', |
|
| 136 | - 'navy' => '000080', |
|
| 137 | - 'oldlace' => 'FDF5E6', |
|
| 138 | - 'olive' => '808000', |
|
| 139 | - 'olivedrab' => '6B8E23', |
|
| 140 | - 'orange' => 'FFA500', |
|
| 141 | - 'orangered' => 'FF4500', |
|
| 142 | - 'orchid' => 'DA70D6', |
|
| 143 | - 'palegoldenrod' => 'EEE8AA', |
|
| 144 | - 'palegreen' => '98FB98', |
|
| 145 | - 'paleturquoise' => 'AFEEEE', |
|
| 146 | - 'palevioletred' => 'DB7093', |
|
| 147 | - 'papayawhip' => 'FFEFD5', |
|
| 148 | - 'peachpuff' => 'FFDAB9', |
|
| 149 | - 'peru' => 'CD853F', |
|
| 150 | - 'pink' => 'FFC0CB', |
|
| 151 | - 'plum' => 'DDA0DD', |
|
| 152 | - 'powderblue' => 'B0E0E6', |
|
| 153 | - 'purple' => '800080', |
|
| 154 | - 'rebeccapurple' => '663399', |
|
| 155 | - 'red' => 'FF0000', |
|
| 156 | - 'rosybrown' => 'BC8F8F', |
|
| 157 | - 'royalblue' => '4169E1', |
|
| 158 | - 'saddlebrown' => '8B4513', |
|
| 159 | - 'salmon' => 'FA8072', |
|
| 160 | - 'sandybrown' => 'F4A460', |
|
| 161 | - 'seagreen' => '2E8B57', |
|
| 162 | - 'seashell' => 'FFF5EE', |
|
| 163 | - 'sienna' => 'A0522D', |
|
| 164 | - 'silver' => 'C0C0C0', |
|
| 165 | - 'skyblue' => '87CEEB', |
|
| 166 | - 'slateblue' => '6A5ACD', |
|
| 167 | - 'slategray' => '708090', |
|
| 168 | - 'slategrey' => '708090', |
|
| 169 | - 'snow' => 'FFFAFA', |
|
| 170 | - 'springgreen' => '00FF7F', |
|
| 171 | - 'steelblue' => '4682B4', |
|
| 172 | - 'tan' => 'D2B48C', |
|
| 173 | - 'teal' => '008080', |
|
| 174 | - 'thistle' => 'D8BFD8', |
|
| 175 | - 'tomato' => 'FF6347', |
|
| 176 | - 'turquoise' => '40E0D0', |
|
| 177 | - 'violet' => 'EE82EE', |
|
| 178 | - 'wheat' => 'F5DEB3', |
|
| 179 | - 'white' => 'FFFFFF', |
|
| 180 | - 'whitesmoke' => 'F5F5F5', |
|
| 181 | - 'yellow' => 'FFFF00', |
|
| 182 | - 'yellowgreen' => '9ACD32', |
|
| 183 | - ]; |
|
| 184 | - if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 185 | - return $couleurs_html[$lc]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $couleur; |
|
| 34 | + $couleurs_html = [ |
|
| 35 | + 'aliceblue' => 'F0F8FF', |
|
| 36 | + 'antiquewhite' => 'FAEBD7', |
|
| 37 | + 'aqua' => '00FFFF', |
|
| 38 | + 'aquamarine' => '7FFFD4', |
|
| 39 | + 'azure' => 'F0FFFF', |
|
| 40 | + 'beige' => 'F5F5DC', |
|
| 41 | + 'bisque' => 'FFE4C4', |
|
| 42 | + 'black' => '000000', |
|
| 43 | + 'blanchedalmond' => 'FFEBCD', |
|
| 44 | + 'blue' => '0000FF', |
|
| 45 | + 'blueviolet' => '8A2BE2', |
|
| 46 | + 'brown' => 'A52A2A', |
|
| 47 | + 'burlywood' => 'DEB887', |
|
| 48 | + 'cadetblue' => '5F9EA0', |
|
| 49 | + 'chartreuse' => '7FFF00', |
|
| 50 | + 'chocolate' => 'D2691E', |
|
| 51 | + 'coral' => 'FF7F50', |
|
| 52 | + 'cornflowerblue' => '6495ED', |
|
| 53 | + 'cornsilk' => 'FFF8DC', |
|
| 54 | + 'crimson' => 'DC143C', |
|
| 55 | + 'cyan' => '00FFFF', |
|
| 56 | + 'darkblue' => '00008B', |
|
| 57 | + 'darkcyan' => '008B8B', |
|
| 58 | + 'darkgoldenrod' => 'B8860B', |
|
| 59 | + 'darkgray' => 'A9A9A9', |
|
| 60 | + 'darkgreen' => '006400', |
|
| 61 | + 'darkgrey' => 'A9A9A9', |
|
| 62 | + 'darkkhaki' => 'BDB76B', |
|
| 63 | + 'darkmagenta' => '8B008B', |
|
| 64 | + 'darkolivegreen' => '556B2F', |
|
| 65 | + 'darkorange' => 'FF8C00', |
|
| 66 | + 'darkorchid' => '9932CC', |
|
| 67 | + 'darkred' => '8B0000', |
|
| 68 | + 'darksalmon' => 'E9967A', |
|
| 69 | + 'darkseagreen' => '8FBC8F', |
|
| 70 | + 'darkslateblue' => '483D8B', |
|
| 71 | + 'darkslategray' => '2F4F4F', |
|
| 72 | + 'darkslategrey' => '2F4F4F', |
|
| 73 | + 'darkturquoise' => '00CED1', |
|
| 74 | + 'darkviolet' => '9400D3', |
|
| 75 | + 'deeppink' => 'FF1493', |
|
| 76 | + 'deepskyblue' => '00BFFF', |
|
| 77 | + 'dimgray' => '696969', |
|
| 78 | + 'dimgrey' => '696969', |
|
| 79 | + 'dodgerblue' => '1E90FF', |
|
| 80 | + 'firebrick' => 'B22222', |
|
| 81 | + 'floralwhite' => 'FFFAF0', |
|
| 82 | + 'forestgreen' => '228B22', |
|
| 83 | + 'fuchsia' => 'FF00FF', |
|
| 84 | + 'gainsboro' => 'DCDCDC', |
|
| 85 | + 'ghostwhite' => 'F8F8FF', |
|
| 86 | + 'gold' => 'FFD700', |
|
| 87 | + 'goldenrod' => 'DAA520', |
|
| 88 | + 'gray' => '808080', |
|
| 89 | + 'green' => '008000', |
|
| 90 | + 'greenyellow' => 'ADFF2F', |
|
| 91 | + 'grey' => '808080', |
|
| 92 | + 'honeydew' => 'F0FFF0', |
|
| 93 | + 'hotpink' => 'FF69B4', |
|
| 94 | + 'indianred' => 'CD5C5C', |
|
| 95 | + 'indigo' => '4B0082', |
|
| 96 | + 'ivory' => 'FFFFF0', |
|
| 97 | + 'khaki' => 'F0E68C', |
|
| 98 | + 'lavender' => 'E6E6FA', |
|
| 99 | + 'lavenderblush' => 'FFF0F5', |
|
| 100 | + 'lawngreen' => '7CFC00', |
|
| 101 | + 'lemonchiffon' => 'FFFACD', |
|
| 102 | + 'lightblue' => 'ADD8E6', |
|
| 103 | + 'lightcoral' => 'F08080', |
|
| 104 | + 'lightcyan' => 'E0FFFF', |
|
| 105 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | + 'lightgray' => 'D3D3D3', |
|
| 107 | + 'lightgreen' => '90EE90', |
|
| 108 | + 'lightgrey' => 'D3D3D3', |
|
| 109 | + 'lightpink' => 'FFB6C1', |
|
| 110 | + 'lightsalmon' => 'FFA07A', |
|
| 111 | + 'lightseagreen' => '20B2AA', |
|
| 112 | + 'lightskyblue' => '87CEFA', |
|
| 113 | + 'lightslategray' => '778899', |
|
| 114 | + 'lightslategrey' => '778899', |
|
| 115 | + 'lightsteelblue' => 'B0C4DE', |
|
| 116 | + 'lightyellow' => 'FFFFE0', |
|
| 117 | + 'lime' => '00FF00', |
|
| 118 | + 'limegreen' => '32CD32', |
|
| 119 | + 'linen' => 'FAF0E6', |
|
| 120 | + 'magenta' => 'FF00FF', |
|
| 121 | + 'maroon' => '800000', |
|
| 122 | + 'mediumaquamarine' => '66CDAA', |
|
| 123 | + 'mediumblue' => '0000CD', |
|
| 124 | + 'mediumorchid' => 'BA55D3', |
|
| 125 | + 'mediumpurple' => '9370DB', |
|
| 126 | + 'mediumseagreen' => '3CB371', |
|
| 127 | + 'mediumslateblue' => '7B68EE', |
|
| 128 | + 'mediumspringgreen' => '00FA9A', |
|
| 129 | + 'mediumturquoise' => '48D1CC', |
|
| 130 | + 'mediumvioletred' => 'C71585', |
|
| 131 | + 'midnightblue' => '191970', |
|
| 132 | + 'mintcream' => 'F5FFFA', |
|
| 133 | + 'mistyrose' => 'FFE4E1', |
|
| 134 | + 'moccasin' => 'FFE4B5', |
|
| 135 | + 'navajowhite' => 'FFDEAD', |
|
| 136 | + 'navy' => '000080', |
|
| 137 | + 'oldlace' => 'FDF5E6', |
|
| 138 | + 'olive' => '808000', |
|
| 139 | + 'olivedrab' => '6B8E23', |
|
| 140 | + 'orange' => 'FFA500', |
|
| 141 | + 'orangered' => 'FF4500', |
|
| 142 | + 'orchid' => 'DA70D6', |
|
| 143 | + 'palegoldenrod' => 'EEE8AA', |
|
| 144 | + 'palegreen' => '98FB98', |
|
| 145 | + 'paleturquoise' => 'AFEEEE', |
|
| 146 | + 'palevioletred' => 'DB7093', |
|
| 147 | + 'papayawhip' => 'FFEFD5', |
|
| 148 | + 'peachpuff' => 'FFDAB9', |
|
| 149 | + 'peru' => 'CD853F', |
|
| 150 | + 'pink' => 'FFC0CB', |
|
| 151 | + 'plum' => 'DDA0DD', |
|
| 152 | + 'powderblue' => 'B0E0E6', |
|
| 153 | + 'purple' => '800080', |
|
| 154 | + 'rebeccapurple' => '663399', |
|
| 155 | + 'red' => 'FF0000', |
|
| 156 | + 'rosybrown' => 'BC8F8F', |
|
| 157 | + 'royalblue' => '4169E1', |
|
| 158 | + 'saddlebrown' => '8B4513', |
|
| 159 | + 'salmon' => 'FA8072', |
|
| 160 | + 'sandybrown' => 'F4A460', |
|
| 161 | + 'seagreen' => '2E8B57', |
|
| 162 | + 'seashell' => 'FFF5EE', |
|
| 163 | + 'sienna' => 'A0522D', |
|
| 164 | + 'silver' => 'C0C0C0', |
|
| 165 | + 'skyblue' => '87CEEB', |
|
| 166 | + 'slateblue' => '6A5ACD', |
|
| 167 | + 'slategray' => '708090', |
|
| 168 | + 'slategrey' => '708090', |
|
| 169 | + 'snow' => 'FFFAFA', |
|
| 170 | + 'springgreen' => '00FF7F', |
|
| 171 | + 'steelblue' => '4682B4', |
|
| 172 | + 'tan' => 'D2B48C', |
|
| 173 | + 'teal' => '008080', |
|
| 174 | + 'thistle' => 'D8BFD8', |
|
| 175 | + 'tomato' => 'FF6347', |
|
| 176 | + 'turquoise' => '40E0D0', |
|
| 177 | + 'violet' => 'EE82EE', |
|
| 178 | + 'wheat' => 'F5DEB3', |
|
| 179 | + 'white' => 'FFFFFF', |
|
| 180 | + 'whitesmoke' => 'F5F5F5', |
|
| 181 | + 'yellow' => 'FFFF00', |
|
| 182 | + 'yellowgreen' => '9ACD32', |
|
| 183 | + ]; |
|
| 184 | + if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 185 | + return $couleurs_html[$lc]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $couleur; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -201,16 +201,16 @@ discard block |
||
| 201 | 201 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 202 | 202 | */ |
| 203 | 203 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 204 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | - $hsl = [ |
|
| 206 | - 'h' => round($hsl['h'] * 360), |
|
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | - ]; |
|
| 210 | - if ($format === null) { |
|
| 211 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | - } |
|
| 213 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 204 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | + $hsl = [ |
|
| 206 | + 'h' => round($hsl['h'] * 360), |
|
| 207 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | + ]; |
|
| 210 | + if ($format === null) { |
|
| 211 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | + } |
|
| 213 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 228 | 228 | */ |
| 229 | 229 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 230 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | - $rgb = [ |
|
| 232 | - 'r' => $rgb['red'], |
|
| 233 | - 'g' => $rgb['green'], |
|
| 234 | - 'b' => $rgb['blue'], |
|
| 235 | - ]; |
|
| 236 | - if ($format === null) { |
|
| 237 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | - } |
|
| 239 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 230 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | + $rgb = [ |
|
| 232 | + 'r' => $rgb['red'], |
|
| 233 | + 'g' => $rgb['green'], |
|
| 234 | + 'b' => $rgb['blue'], |
|
| 235 | + ]; |
|
| 236 | + if ($format === null) { |
|
| 237 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | + } |
|
| 239 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | * Code hexadécimal de la couleur plus foncée |
| 253 | 253 | */ |
| 254 | 254 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 255 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 256 | 256 | |
| 257 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 257 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 260 | 260 | |
| 261 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 262 | 262 | |
| 263 | - return $couleur; |
|
| 263 | + return $couleur; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | * Code hexadécimal de la couleur éclaircie |
| 277 | 277 | */ |
| 278 | 278 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 279 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 279 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 280 | 280 | |
| 281 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 284 | 284 | |
| 285 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 285 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 286 | 286 | |
| 287 | - return $couleur; |
|
| 287 | + return $couleur; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -307,28 +307,28 @@ discard block |
||
| 307 | 307 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 308 | 308 | */ |
| 309 | 309 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 310 | - if (!$img) { |
|
| 311 | - return $img; |
|
| 312 | - } |
|
| 313 | - [$h, $l] = taille_image($img); |
|
| 314 | - $select = true; |
|
| 315 | - if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | - $select = false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $class = extraire_attribut($img, 'class'); |
|
| 320 | - $p = strpos($class, 'filtre_inactif'); |
|
| 321 | - if (($select == false) and ($p === false)) { |
|
| 322 | - $class .= ' filtre_inactif'; |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - if (($select == true) and ($p !== false)) { |
|
| 326 | - // no_image_filtrer : historique, a virer |
|
| 327 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | - $img = inserer_attribut($img, 'class', $class); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - return $img; |
|
| 310 | + if (!$img) { |
|
| 311 | + return $img; |
|
| 312 | + } |
|
| 313 | + [$h, $l] = taille_image($img); |
|
| 314 | + $select = true; |
|
| 315 | + if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | + $select = false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $class = extraire_attribut($img, 'class'); |
|
| 320 | + $p = strpos($class, 'filtre_inactif'); |
|
| 321 | + if (($select == false) and ($p === false)) { |
|
| 322 | + $class .= ' filtre_inactif'; |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + if (($select == true) and ($p !== false)) { |
|
| 326 | + // no_image_filtrer : historique, a virer |
|
| 327 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | + $img = inserer_attribut($img, 'class', $class); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + return $img; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -376,45 +376,45 @@ discard block |
||
| 376 | 376 | * Code HTML de l'image ou du texte. |
| 377 | 377 | **/ |
| 378 | 378 | function image_passe_partout( |
| 379 | - $img, |
|
| 380 | - $taille_x = -1, |
|
| 381 | - $taille_y = -1, |
|
| 382 | - $force = false, |
|
| 383 | - $cherche_image = false, |
|
| 384 | - $process = 'AUTO' |
|
| 379 | + $img, |
|
| 380 | + $taille_x = -1, |
|
| 381 | + $taille_y = -1, |
|
| 382 | + $force = false, |
|
| 383 | + $cherche_image = false, |
|
| 384 | + $process = 'AUTO' |
|
| 385 | 385 | ) { |
| 386 | - // PHP 7+ type hint |
|
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 392 | - |
|
| 393 | - if (!$img) { |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - [$hauteur, $largeur] = taille_image($img); |
|
| 397 | - if ($taille_x === -1) { |
|
| 398 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | - } |
|
| 400 | - if ($taille_y === -1) { |
|
| 401 | - $taille_y = $taille_x; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | - $taille_x = 1; |
|
| 406 | - } # {0,300} -> c'est 300 qui compte |
|
| 407 | - elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | - $taille_y = 1; |
|
| 409 | - } # {300,0} -> c'est 300 qui compte |
|
| 410 | - elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | - return ''; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | - |
|
| 417 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 386 | + // PHP 7+ type hint |
|
| 387 | + $img = (string)$img; |
|
| 388 | + $taille_x = (int)$taille_x; |
|
| 389 | + $taille_y = (int)$taille_y; |
|
| 390 | + $force = (bool)$force; |
|
| 391 | + $process = (string)$process; |
|
| 392 | + |
|
| 393 | + if (!$img) { |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + [$hauteur, $largeur] = taille_image($img); |
|
| 397 | + if ($taille_x === -1) { |
|
| 398 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | + } |
|
| 400 | + if ($taille_y === -1) { |
|
| 401 | + $taille_y = $taille_x; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | + $taille_x = 1; |
|
| 406 | + } # {0,300} -> c'est 300 qui compte |
|
| 407 | + elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | + $taille_y = 1; |
|
| 409 | + } # {300,0} -> c'est 300 qui compte |
|
| 410 | + elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | + return ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | + |
|
| 417 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -457,44 +457,44 @@ discard block |
||
| 457 | 457 | * Code HTML de l'image ou du texte. |
| 458 | 458 | **/ |
| 459 | 459 | function image_reduire( |
| 460 | - $img, |
|
| 461 | - $taille = -1, |
|
| 462 | - $taille_y = -1, |
|
| 463 | - $force = false, |
|
| 464 | - $cherche_image = false, |
|
| 465 | - $process = 'AUTO' |
|
| 460 | + $img, |
|
| 461 | + $taille = -1, |
|
| 462 | + $taille_y = -1, |
|
| 463 | + $force = false, |
|
| 464 | + $cherche_image = false, |
|
| 465 | + $process = 'AUTO' |
|
| 466 | 466 | ) { |
| 467 | - // PHP 7+ type hint |
|
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 473 | - |
|
| 474 | - // Determiner la taille x,y maxi |
|
| 475 | - // prendre le reglage de previsu par defaut |
|
| 476 | - if ($taille === -1) { |
|
| 477 | - $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | - ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | - : 150; |
|
| 480 | - } |
|
| 481 | - if ($taille_y === -1) { |
|
| 482 | - $taille_y = $taille; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if ($taille === 0 and $taille_y > 0) { |
|
| 486 | - $taille = 10000; |
|
| 487 | - } # {0,300} -> c'est 300 qui compte |
|
| 488 | - elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | - $taille_y = 10000; |
|
| 490 | - } # {300,0} -> c'est 300 qui compte |
|
| 491 | - elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | - |
|
| 497 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 467 | + // PHP 7+ type hint |
|
| 468 | + $img = (string)$img; |
|
| 469 | + $taille = (int)$taille; |
|
| 470 | + $taille_y = (int)$taille_y; |
|
| 471 | + $force = (bool)$force; |
|
| 472 | + $process = (string)$process; |
|
| 473 | + |
|
| 474 | + // Determiner la taille x,y maxi |
|
| 475 | + // prendre le reglage de previsu par defaut |
|
| 476 | + if ($taille === -1) { |
|
| 477 | + $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | + ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | + : 150; |
|
| 480 | + } |
|
| 481 | + if ($taille_y === -1) { |
|
| 482 | + $taille_y = $taille; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if ($taille === 0 and $taille_y > 0) { |
|
| 486 | + $taille = 10000; |
|
| 487 | + } # {0,300} -> c'est 300 qui compte |
|
| 488 | + elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | + $taille_y = 10000; |
|
| 490 | + } # {300,0} -> c'est 300 qui compte |
|
| 491 | + elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | + |
|
| 497 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,16 +505,16 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | **/ |
| 507 | 507 | function image_recadre_avec_fallback( |
| 508 | - $im, |
|
| 509 | - $width, |
|
| 510 | - $height = '-', |
|
| 511 | - $position = 'focus', |
|
| 512 | - $background_color = 'white' |
|
| 508 | + $im, |
|
| 509 | + $width, |
|
| 510 | + $height = '-', |
|
| 511 | + $position = 'focus', |
|
| 512 | + $background_color = 'white' |
|
| 513 | 513 | ) { |
| 514 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | - } else { return image_passe_partout($im, $width, $height); |
|
| 517 | - } |
|
| 514 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | + } else { return image_passe_partout($im, $width, $height); |
|
| 517 | + } |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,25 +532,25 @@ discard block |
||
| 532 | 532 | * Code HTML de l'image ou du texte. |
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | - // PHP 7+ type hint |
|
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 535 | + // PHP 7+ type hint |
|
| 536 | + $img = (string)$img; |
|
| 537 | + $val = (int)$val; |
|
| 538 | + $force = (bool)$force; |
|
| 539 | 539 | |
| 540 | - [$hauteur, $largeur] = taille_image($img); |
|
| 540 | + [$hauteur, $largeur] = taille_image($img); |
|
| 541 | 541 | |
| 542 | - $l = round($largeur / $val); |
|
| 543 | - $h = round($hauteur / $val); |
|
| 542 | + $l = round($largeur / $val); |
|
| 543 | + $h = round($hauteur / $val); |
|
| 544 | 544 | |
| 545 | - if ($l > $h) { |
|
| 546 | - $h = 0; |
|
| 547 | - } else { |
|
| 548 | - $l = 0; |
|
| 549 | - } |
|
| 545 | + if ($l > $h) { |
|
| 546 | + $h = 0; |
|
| 547 | + } else { |
|
| 548 | + $l = 0; |
|
| 549 | + } |
|
| 550 | 550 | |
| 551 | - $img = image_reduire($img, $l, $h, $force); |
|
| 551 | + $img = image_reduire($img, $l, $h, $force); |
|
| 552 | 552 | |
| 553 | - return $img; |
|
| 553 | + return $img; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * Couleur en écriture hexadécimale. |
| 574 | 574 | **/ |
| 575 | 575 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 576 | - if (function_exists('couleur_saturation')) { |
|
| 577 | - return couleur_saturation($couleur, $val, $strict); |
|
| 578 | - } |
|
| 579 | - return $couleur; |
|
| 576 | + if (function_exists('couleur_saturation')) { |
|
| 577 | + return couleur_saturation($couleur, $val, $strict); |
|
| 578 | + } |
|
| 579 | + return $couleur; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -597,8 +597,8 @@ discard block |
||
| 597 | 597 | * Couleur en écriture hexadécimale. |
| 598 | 598 | **/ |
| 599 | 599 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 600 | - if (function_exists('couleur_luminance')) { |
|
| 601 | - return couleur_luminance($couleur, $val); |
|
| 602 | - } |
|
| 603 | - return $couleur; |
|
| 600 | + if (function_exists('couleur_luminance')) { |
|
| 601 | + return couleur_luminance($couleur, $val); |
|
| 602 | + } |
|
| 603 | + return $couleur; |
|
| 604 | 604 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
| 136 | 136 | if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 137 | + $from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')'; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // nettoyer les é ’, &emdash; etc... |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | if (!_TEST_EMAIL_DEST) { |
| 172 | 172 | return false; |
| 173 | 173 | } else { |
| 174 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 174 | + $texte = "Dest : $destinataire\r\n".$texte; |
|
| 175 | 175 | $destinataire = _TEST_EMAIL_DEST; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | // Ajouter le Content-Type et consort s'il n'y est pas deja |
| 196 | 196 | if (strpos($headers, 'Content-Type: ') === false) { |
| 197 | 197 | $type = |
| 198 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 198 | + "Content-Type: text/plain;charset=\"$charset\";\n". |
|
| 199 | 199 | "Content-Transfer-Encoding: 8bit\n"; |
| 200 | 200 | } else { |
| 201 | 201 | $type = ''; |
@@ -207,17 +207,17 @@ discard block |
||
| 207 | 207 | $domain = $domain[0]; |
| 208 | 208 | } |
| 209 | 209 | else { |
| 210 | - $domain = '@unknown-' . md5($from) . '.org'; |
|
| 210 | + $domain = '@unknown-'.md5($from).'.org'; |
|
| 211 | 211 | } |
| 212 | - $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 212 | + $uniq = random_int(0, mt_getrandmax()).'_'.md5($to.$texte).$domain; |
|
| 213 | 213 | |
| 214 | 214 | // Si multi-part, s'en servir comme borne ... |
| 215 | 215 | if ($parts) { |
| 216 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 216 | + $texte = "--$uniq\n$type\n".$texte."\n"; |
|
| 217 | 217 | foreach ($parts as $part) { |
| 218 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 218 | + $n = strlen($part[1]).($part[0] ? "\n" : ''); |
|
| 219 | 219 | $e = join("\n", $part[0]); |
| 220 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 220 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1]; |
|
| 221 | 221 | } |
| 222 | 222 | $texte .= "\n\n--$uniq--\n"; |
| 223 | 223 | // Si boundary n'est pas entre guillemets, |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | // .. et s'en servir pour plaire a SpamAssassin |
| 229 | 229 | |
| 230 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 230 | + $mid = 'Message-Id: <'.$uniq.'>'; |
|
| 231 | 231 | |
| 232 | 232 | // indispensable pour les sites qui collent d'office From: serveur-http |
| 233 | 233 | // sauf si deja mis par l'envoyeur |
@@ -205,8 +205,7 @@ |
||
| 205 | 205 | // Marie Toto <[email protected]> => @toto.com |
| 206 | 206 | if (preg_match('/@[^\s>]+/', $from, $domain)) { |
| 207 | 207 | $domain = $domain[0]; |
| 208 | - } |
|
| 209 | - else { |
|
| 208 | + } else { |
|
| 210 | 209 | $domain = '@unknown-' . md5($from) . '.org'; |
| 211 | 210 | } |
| 212 | 211 | $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Mail |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function nettoyer_titre_email($titre) { |
| 35 | - return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre)))); |
|
| 35 | + return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre)))); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -48,23 +48,23 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function nettoyer_caracteres_mail($t) { |
| 50 | 50 | |
| 51 | - $t = filtrer_entites($t); |
|
| 51 | + $t = filtrer_entites($t); |
|
| 52 | 52 | |
| 53 | - if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | - $t = str_replace( |
|
| 55 | - ['’', '“', '”'], |
|
| 56 | - ["'", '"', '"'], |
|
| 57 | - $t |
|
| 58 | - ); |
|
| 59 | - } |
|
| 53 | + if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | + $t = str_replace( |
|
| 55 | + ['’', '“', '”'], |
|
| 56 | + ["'", '"', '"'], |
|
| 57 | + $t |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $t = str_replace( |
|
| 62 | - ['—', '&endash;'], |
|
| 63 | - ['--', '-'], |
|
| 64 | - $t |
|
| 65 | - ); |
|
| 61 | + $t = str_replace( |
|
| 62 | + ['—', '&endash;'], |
|
| 63 | + ['--', '-'], |
|
| 64 | + $t |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - return $t; |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -97,87 +97,87 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') { |
| 99 | 99 | |
| 100 | - if (!email_valide($destinataire)) { |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | - return false; |
|
| 105 | - } // tres fort |
|
| 106 | - |
|
| 107 | - // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | - // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | - |
|
| 110 | - $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | - if (!email_valide($email_envoi)) { |
|
| 112 | - spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | - $email_envoi = $destinataire; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $parts = ''; |
|
| 117 | - if (is_array($corps)) { |
|
| 118 | - $texte = $corps['texte']; |
|
| 119 | - $from = ($corps['from'] ?? $from); |
|
| 120 | - $headers = ($corps['headers'] ?? $headers); |
|
| 121 | - if (is_array($headers)) { |
|
| 122 | - $headers = implode("\n", $headers); |
|
| 123 | - } |
|
| 124 | - if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | - $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | - } |
|
| 127 | - } else { |
|
| 128 | - $texte = $corps; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if (!$from) { |
|
| 132 | - $from = $email_envoi; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | - if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // nettoyer les é ’, &emdash; etc... |
|
| 141 | - // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | - // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | - $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | - $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | - |
|
| 146 | - // encoder le sujet si possible selon la RFC |
|
| 147 | - if (init_mb_string()) { |
|
| 148 | - # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | - # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | - $charset = $GLOBALS['meta']['charset']; |
|
| 151 | - mb_internal_encoding($charset); |
|
| 152 | - $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | - mb_internal_encoding('utf-8'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $headers = $headers ?? ''; |
|
| 157 | - if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 158 | - $texte = wordwrap($texte); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 162 | - |
|
| 163 | - if (_OS_SERVEUR == 'windows') { |
|
| 164 | - $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 165 | - $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 166 | - $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 170 | - // mode TEST : forcer l'email |
|
| 171 | - if (defined('_TEST_EMAIL_DEST')) { |
|
| 172 | - if (!_TEST_EMAIL_DEST) { |
|
| 173 | - return false; |
|
| 174 | - } else { |
|
| 175 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 176 | - $destinataire = _TEST_EMAIL_DEST; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return @mail($destinataire, $sujet, $texte, $headers); |
|
| 100 | + if (!email_valide($destinataire)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | + return false; |
|
| 105 | + } // tres fort |
|
| 106 | + |
|
| 107 | + // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | + // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | + |
|
| 110 | + $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | + if (!email_valide($email_envoi)) { |
|
| 112 | + spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | + $email_envoi = $destinataire; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $parts = ''; |
|
| 117 | + if (is_array($corps)) { |
|
| 118 | + $texte = $corps['texte']; |
|
| 119 | + $from = ($corps['from'] ?? $from); |
|
| 120 | + $headers = ($corps['headers'] ?? $headers); |
|
| 121 | + if (is_array($headers)) { |
|
| 122 | + $headers = implode("\n", $headers); |
|
| 123 | + } |
|
| 124 | + if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | + $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | + } |
|
| 127 | + } else { |
|
| 128 | + $texte = $corps; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if (!$from) { |
|
| 132 | + $from = $email_envoi; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | + if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | + $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // nettoyer les é ’, &emdash; etc... |
|
| 141 | + // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | + // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | + $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | + $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | + |
|
| 146 | + // encoder le sujet si possible selon la RFC |
|
| 147 | + if (init_mb_string()) { |
|
| 148 | + # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | + # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | + $charset = $GLOBALS['meta']['charset']; |
|
| 151 | + mb_internal_encoding($charset); |
|
| 152 | + $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | + mb_internal_encoding('utf-8'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $headers = $headers ?? ''; |
|
| 157 | + if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 158 | + $texte = wordwrap($texte); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 162 | + |
|
| 163 | + if (_OS_SERVEUR == 'windows') { |
|
| 164 | + $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 165 | + $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 166 | + $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 170 | + // mode TEST : forcer l'email |
|
| 171 | + if (defined('_TEST_EMAIL_DEST')) { |
|
| 172 | + if (!_TEST_EMAIL_DEST) { |
|
| 173 | + return false; |
|
| 174 | + } else { |
|
| 175 | + $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 176 | + $destinataire = _TEST_EMAIL_DEST; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return @mail($destinataire, $sujet, $texte, $headers); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -191,58 +191,58 @@ discard block |
||
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | 193 | function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') { |
| 194 | - $charset = $GLOBALS['meta']['charset']; |
|
| 195 | - |
|
| 196 | - // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 197 | - if (strpos($headers, 'Content-Type: ') === false) { |
|
| 198 | - $type = |
|
| 199 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 200 | - "Content-Transfer-Encoding: 8bit\n"; |
|
| 201 | - } else { |
|
| 202 | - $type = ''; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // calculer un identifiant unique |
|
| 206 | - // Marie Toto <[email protected]> => @toto.com |
|
| 207 | - if (preg_match('/@[^\s>]+/', $from, $domain)) { |
|
| 208 | - $domain = $domain[0]; |
|
| 209 | - } |
|
| 210 | - else { |
|
| 211 | - $domain = '@unknown-' . md5($from) . '.org'; |
|
| 212 | - } |
|
| 213 | - $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 214 | - |
|
| 215 | - // Si multi-part, s'en servir comme borne ... |
|
| 216 | - if ($parts) { |
|
| 217 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 218 | - foreach ($parts as $part) { |
|
| 219 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 220 | - $e = join("\n", $part[0]); |
|
| 221 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 222 | - } |
|
| 223 | - $texte .= "\n\n--$uniq--\n"; |
|
| 224 | - // Si boundary n'est pas entre guillemets, |
|
| 225 | - // elle est comprise mais le charset est ignoree ! |
|
| 226 | - $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // .. et s'en servir pour plaire a SpamAssassin |
|
| 230 | - |
|
| 231 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 232 | - |
|
| 233 | - // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 234 | - // sauf si deja mis par l'envoyeur |
|
| 235 | - $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 236 | - |
|
| 237 | - // Nettoyer les en-tetes envoyees |
|
| 238 | - // Ajouter le \n final |
|
| 239 | - if (strlen($headers = trim($headers))) { |
|
| 240 | - $headers .= "\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Et mentionner l'indeboulonable nomenclature ratee |
|
| 244 | - |
|
| 245 | - $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 246 | - |
|
| 247 | - return [$headers, $texte]; |
|
| 194 | + $charset = $GLOBALS['meta']['charset']; |
|
| 195 | + |
|
| 196 | + // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 197 | + if (strpos($headers, 'Content-Type: ') === false) { |
|
| 198 | + $type = |
|
| 199 | + "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 200 | + "Content-Transfer-Encoding: 8bit\n"; |
|
| 201 | + } else { |
|
| 202 | + $type = ''; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // calculer un identifiant unique |
|
| 206 | + // Marie Toto <[email protected]> => @toto.com |
|
| 207 | + if (preg_match('/@[^\s>]+/', $from, $domain)) { |
|
| 208 | + $domain = $domain[0]; |
|
| 209 | + } |
|
| 210 | + else { |
|
| 211 | + $domain = '@unknown-' . md5($from) . '.org'; |
|
| 212 | + } |
|
| 213 | + $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 214 | + |
|
| 215 | + // Si multi-part, s'en servir comme borne ... |
|
| 216 | + if ($parts) { |
|
| 217 | + $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 218 | + foreach ($parts as $part) { |
|
| 219 | + $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 220 | + $e = join("\n", $part[0]); |
|
| 221 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 222 | + } |
|
| 223 | + $texte .= "\n\n--$uniq--\n"; |
|
| 224 | + // Si boundary n'est pas entre guillemets, |
|
| 225 | + // elle est comprise mais le charset est ignoree ! |
|
| 226 | + $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // .. et s'en servir pour plaire a SpamAssassin |
|
| 230 | + |
|
| 231 | + $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 232 | + |
|
| 233 | + // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 234 | + // sauf si deja mis par l'envoyeur |
|
| 235 | + $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 236 | + |
|
| 237 | + // Nettoyer les en-tetes envoyees |
|
| 238 | + // Ajouter le \n final |
|
| 239 | + if (strlen($headers = trim($headers))) { |
|
| 240 | + $headers .= "\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Et mentionner l'indeboulonable nomenclature ratee |
|
| 244 | + |
|
| 245 | + $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 246 | + |
|
| 247 | + return [$headers, $texte]; |
|
| 248 | 248 | } |
@@ -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'); |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | 44 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 45 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | - static $charset_source = 'iso-8859-1'; |
|
| 47 | - if ($definir_charset_source) { |
|
| 48 | - if ($definir_charset_source === true) { |
|
| 49 | - $charset_source = 'iso-8859-1'; |
|
| 50 | - } else { |
|
| 51 | - $charset_source = $definir_charset_source; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | - if (is_utf8($texte)) { |
|
| 56 | - $charset = 'utf-8'; |
|
| 57 | - } else { |
|
| 58 | - $charset = $charset_source; |
|
| 59 | - } |
|
| 60 | - return importer_charset($texte, $charset); |
|
| 45 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | + static $charset_source = 'iso-8859-1'; |
|
| 47 | + if ($definir_charset_source) { |
|
| 48 | + if ($definir_charset_source === true) { |
|
| 49 | + $charset_source = 'iso-8859-1'; |
|
| 50 | + } else { |
|
| 51 | + $charset_source = $definir_charset_source; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | + if (is_utf8($texte)) { |
|
| 56 | + $charset = 'utf-8'; |
|
| 57 | + } else { |
|
| 58 | + $charset = $charset_source; |
|
| 59 | + } |
|
| 60 | + return importer_charset($texte, $charset); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | 70 | function importer_csv_nettoie_key($key) { |
| 71 | - return translitteration($key); |
|
| 71 | + return translitteration($key); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -87,77 +87,77 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function inc_importer_csv_dist($file, $options = []) { |
| 89 | 89 | |
| 90 | - // support ancienne syntaxe |
|
| 91 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | - if (!is_array($options)) { |
|
| 93 | - $args = func_get_args(); |
|
| 94 | - $options = []; |
|
| 95 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | - if (!empty($args[$k])) { |
|
| 97 | - $options[$option] = $args[$k]; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 90 | + // support ancienne syntaxe |
|
| 91 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | + if (!is_array($options)) { |
|
| 93 | + $args = func_get_args(); |
|
| 94 | + $options = []; |
|
| 95 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | + if (!empty($args[$k])) { |
|
| 97 | + $options[$option] = $args[$k]; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $default_options = [ |
|
| 103 | - 'head' => false, |
|
| 104 | - 'delim' => ',', |
|
| 105 | - 'enclos' => '"', |
|
| 106 | - 'len' => 10000, |
|
| 107 | - 'charset_source' => '', |
|
| 108 | - ]; |
|
| 109 | - $options = array_merge($default_options, $options); |
|
| 102 | + $default_options = [ |
|
| 103 | + 'head' => false, |
|
| 104 | + 'delim' => ',', |
|
| 105 | + 'enclos' => '"', |
|
| 106 | + 'len' => 10000, |
|
| 107 | + 'charset_source' => '', |
|
| 108 | + ]; |
|
| 109 | + $options = array_merge($default_options, $options); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - $return = false; |
|
| 113 | - if ( |
|
| 114 | - @file_exists($file) |
|
| 115 | - and $handle = fopen($file, 'r') |
|
| 116 | - ) { |
|
| 117 | - if ($options['charset_source']) { |
|
| 118 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | - } |
|
| 120 | - if ($options['head']) { |
|
| 121 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | - if ($header) { |
|
| 123 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | - $header_type = []; |
|
| 126 | - foreach ($header as $heading) { |
|
| 127 | - if (!isset($header_type[$heading])) { |
|
| 128 | - $header_type[$heading] = 'scalar'; |
|
| 129 | - } else { |
|
| 130 | - $header_type[$heading] = 'array'; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 112 | + $return = false; |
|
| 113 | + if ( |
|
| 114 | + @file_exists($file) |
|
| 115 | + and $handle = fopen($file, 'r') |
|
| 116 | + ) { |
|
| 117 | + if ($options['charset_source']) { |
|
| 118 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | + } |
|
| 120 | + if ($options['head']) { |
|
| 121 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | + if ($header) { |
|
| 123 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | + $header_type = []; |
|
| 126 | + foreach ($header as $heading) { |
|
| 127 | + if (!isset($header_type[$heading])) { |
|
| 128 | + $header_type[$heading] = 'scalar'; |
|
| 129 | + } else { |
|
| 130 | + $header_type[$heading] = 'array'; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | - if ($options['head'] and isset($header)) { |
|
| 139 | - $row = []; |
|
| 140 | - foreach ($header as $key => $heading) { |
|
| 141 | - if ($header_type[$heading] == 'array') { |
|
| 142 | - if (!isset($row[$heading])) { |
|
| 143 | - $row[$heading] = []; |
|
| 144 | - } |
|
| 145 | - if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | - $row[$heading][] = $data[$key]; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $row[$heading] = $data[$key] ?? ''; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $return[] = $row; |
|
| 153 | - } else { |
|
| 154 | - $return[] = $data; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - if ($options['charset_source']) { |
|
| 158 | - importer_csv_importcharset('', true); |
|
| 159 | - } |
|
| 160 | - } |
|
| 136 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | + if ($options['head'] and isset($header)) { |
|
| 139 | + $row = []; |
|
| 140 | + foreach ($header as $key => $heading) { |
|
| 141 | + if ($header_type[$heading] == 'array') { |
|
| 142 | + if (!isset($row[$heading])) { |
|
| 143 | + $row[$heading] = []; |
|
| 144 | + } |
|
| 145 | + if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | + $row[$heading][] = $data[$key]; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $row[$heading] = $data[$key] ?? ''; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $return[] = $row; |
|
| 153 | + } else { |
|
| 154 | + $return[] = $data; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + if ($options['charset_source']) { |
|
| 158 | + importer_csv_importcharset('', true); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $return; |
|
| 162 | + return $return; |
|
| 163 | 163 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | * @return bool|null|void |
| 41 | 41 | */ |
| 42 | 42 | function inc_session_dist($auteur = false) { |
| 43 | - if (is_numeric($auteur)) { |
|
| 44 | - return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | - } else { |
|
| 46 | - if (is_array($auteur)) { |
|
| 47 | - return ajouter_session($auteur); |
|
| 48 | - } else { |
|
| 49 | - return verifier_session($auteur); |
|
| 50 | - } |
|
| 51 | - } |
|
| 43 | + if (is_numeric($auteur)) { |
|
| 44 | + return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | + } else { |
|
| 46 | + if (is_array($auteur)) { |
|
| 47 | + return ajouter_session($auteur); |
|
| 48 | + } else { |
|
| 49 | + return verifier_session($auteur); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,36 +77,36 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function supprimer_sessions($id_auteur, $toutes = true, $actives = true) { |
| 79 | 79 | |
| 80 | - $nb_files = 0; |
|
| 81 | - $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | - spip_log("supprimer sessions auteur $id_auteur", 'session'); |
|
| 83 | - if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | - $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | - while (($f = readdir($dir)) !== false) { |
|
| 89 | - $nb_files++; |
|
| 90 | - if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
|
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 92 | - if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | - spip_unlink($f); |
|
| 94 | - } |
|
| 95 | - // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | - // cf http://core.spip.org/issues/3276 |
|
| 97 | - elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | - spip_unlink($f); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - verifier_session(); |
|
| 105 | - spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // forcer le recalcul de la session courante |
|
| 109 | - spip_session(true); |
|
| 80 | + $nb_files = 0; |
|
| 81 | + $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | + spip_log("supprimer sessions auteur $id_auteur", 'session'); |
|
| 83 | + if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | + $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | + while (($f = readdir($dir)) !== false) { |
|
| 89 | + $nb_files++; |
|
| 90 | + if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
|
| 91 | + $f = _DIR_SESSIONS . $f; |
|
| 92 | + if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | + spip_unlink($f); |
|
| 94 | + } |
|
| 95 | + // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | + // cf http://core.spip.org/issues/3276 |
|
| 97 | + elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | + spip_unlink($f); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + verifier_session(); |
|
| 105 | + spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // forcer le recalcul de la session courante |
|
| 109 | + spip_session(true); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -124,125 +124,125 @@ discard block |
||
| 124 | 124 | * @return bool|string |
| 125 | 125 | */ |
| 126 | 126 | function ajouter_session($auteur) { |
| 127 | - // Si le client a deja une session valide pour son id_auteur |
|
| 128 | - // on conserve le meme fichier |
|
| 129 | - |
|
| 130 | - // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | - // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | - |
|
| 134 | - // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | - // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | - if (!$id_auteur) { |
|
| 137 | - // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | - $auteur_verif = $auteur; |
|
| 139 | - if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | - unset($auteur_verif['id_auteur']); |
|
| 141 | - } |
|
| 142 | - if (isset($auteur_verif['hash_env'])) { |
|
| 143 | - unset($auteur_verif['hash_env']); |
|
| 144 | - } |
|
| 145 | - if (isset($auteur_verif['ip_change'])) { |
|
| 146 | - unset($auteur_verif['ip_change']); |
|
| 147 | - } |
|
| 148 | - if (isset($auteur_verif['date_session'])) { |
|
| 149 | - unset($auteur_verif['date_session']); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | - foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | - if ($valeur === null) { |
|
| 155 | - unset($auteur_verif[$variable]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | - if (!$auteur_verif) { |
|
| 161 | - if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | - unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | - } |
|
| 164 | - if (isset($_COOKIE['spip_session'])) { |
|
| 165 | - unset($_COOKIE['spip_session']); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ( |
|
| 173 | - !isset($_COOKIE['spip_session']) |
|
| 174 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 175 | - ) { |
|
| 176 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Maintenant on sait qu'on a des choses à écrire |
|
| 180 | - // On s'assure d'avoir au moins ces valeurs |
|
| 181 | - $auteur['id_auteur'] = $id_auteur; |
|
| 182 | - if (!isset($auteur['hash_env'])) { |
|
| 183 | - $auteur['hash_env'] = hash_env(); |
|
| 184 | - } |
|
| 185 | - if (!isset($auteur['ip_change'])) { |
|
| 186 | - $auteur['ip_change'] = false; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!isset($auteur['date_session'])) { |
|
| 190 | - $auteur['date_session'] = time(); |
|
| 191 | - } |
|
| 192 | - if ( |
|
| 193 | - isset($auteur['prefs']) |
|
| 194 | - and is_string($auteur['prefs']) |
|
| 195 | - and $prefs = @unserialize($auteur['prefs']) |
|
| 196 | - ) { |
|
| 197 | - $auteur['prefs'] = $prefs; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $fichier_session = ''; |
|
| 201 | - |
|
| 202 | - // les sessions anonymes sont stockees dans $_SESSION |
|
| 203 | - if (!$id_auteur) { |
|
| 204 | - spip_php_session_start(); |
|
| 205 | - $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 206 | - } else { |
|
| 207 | - $fichier_session = fichier_session('alea_ephemere'); |
|
| 208 | - if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 209 | - spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 210 | - include_spip('inc/minipres'); |
|
| 211 | - echo minipres(); |
|
| 212 | - exit; |
|
| 213 | - } |
|
| 214 | - // verifier et limiter le nombre maxi de sessions |
|
| 215 | - // https://core.spip.net/issues/3807 |
|
| 216 | - lister_sessions_auteur($id_auteur); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // poser le cookie de session SPIP |
|
| 220 | - include_spip('inc/cookie'); |
|
| 221 | - $duree = definir_duree_cookie_session($auteur); |
|
| 222 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 223 | - 'expires' => time() + $duree |
|
| 224 | - ]); |
|
| 225 | - spip_log("ajoute session $fichier_session cookie $duree", 'session'); |
|
| 226 | - |
|
| 227 | - // Si on est admin, poser le cookie de correspondance |
|
| 228 | - if (!function_exists('autoriser')) { |
|
| 229 | - include_spip('inc/autoriser'); |
|
| 230 | - } |
|
| 231 | - if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 232 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 234 | - ]); |
|
| 235 | - } // sinon le supprimer ... |
|
| 236 | - else { |
|
| 237 | - spip_setcookie('spip_admin', '', [ |
|
| 238 | - 'expires' => 1 |
|
| 239 | - ]); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 243 | - # supprimer_sessions(0, true, false); |
|
| 244 | - |
|
| 245 | - return $_COOKIE['spip_session']; |
|
| 127 | + // Si le client a deja une session valide pour son id_auteur |
|
| 128 | + // on conserve le meme fichier |
|
| 129 | + |
|
| 130 | + // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | + // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | + |
|
| 134 | + // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | + // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | + if (!$id_auteur) { |
|
| 137 | + // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | + $auteur_verif = $auteur; |
|
| 139 | + if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | + unset($auteur_verif['id_auteur']); |
|
| 141 | + } |
|
| 142 | + if (isset($auteur_verif['hash_env'])) { |
|
| 143 | + unset($auteur_verif['hash_env']); |
|
| 144 | + } |
|
| 145 | + if (isset($auteur_verif['ip_change'])) { |
|
| 146 | + unset($auteur_verif['ip_change']); |
|
| 147 | + } |
|
| 148 | + if (isset($auteur_verif['date_session'])) { |
|
| 149 | + unset($auteur_verif['date_session']); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | + foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | + if ($valeur === null) { |
|
| 155 | + unset($auteur_verif[$variable]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | + if (!$auteur_verif) { |
|
| 161 | + if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | + unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | + } |
|
| 164 | + if (isset($_COOKIE['spip_session'])) { |
|
| 165 | + unset($_COOKIE['spip_session']); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ( |
|
| 173 | + !isset($_COOKIE['spip_session']) |
|
| 174 | + or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 175 | + ) { |
|
| 176 | + $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Maintenant on sait qu'on a des choses à écrire |
|
| 180 | + // On s'assure d'avoir au moins ces valeurs |
|
| 181 | + $auteur['id_auteur'] = $id_auteur; |
|
| 182 | + if (!isset($auteur['hash_env'])) { |
|
| 183 | + $auteur['hash_env'] = hash_env(); |
|
| 184 | + } |
|
| 185 | + if (!isset($auteur['ip_change'])) { |
|
| 186 | + $auteur['ip_change'] = false; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!isset($auteur['date_session'])) { |
|
| 190 | + $auteur['date_session'] = time(); |
|
| 191 | + } |
|
| 192 | + if ( |
|
| 193 | + isset($auteur['prefs']) |
|
| 194 | + and is_string($auteur['prefs']) |
|
| 195 | + and $prefs = @unserialize($auteur['prefs']) |
|
| 196 | + ) { |
|
| 197 | + $auteur['prefs'] = $prefs; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $fichier_session = ''; |
|
| 201 | + |
|
| 202 | + // les sessions anonymes sont stockees dans $_SESSION |
|
| 203 | + if (!$id_auteur) { |
|
| 204 | + spip_php_session_start(); |
|
| 205 | + $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 206 | + } else { |
|
| 207 | + $fichier_session = fichier_session('alea_ephemere'); |
|
| 208 | + if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 209 | + spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 210 | + include_spip('inc/minipres'); |
|
| 211 | + echo minipres(); |
|
| 212 | + exit; |
|
| 213 | + } |
|
| 214 | + // verifier et limiter le nombre maxi de sessions |
|
| 215 | + // https://core.spip.net/issues/3807 |
|
| 216 | + lister_sessions_auteur($id_auteur); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // poser le cookie de session SPIP |
|
| 220 | + include_spip('inc/cookie'); |
|
| 221 | + $duree = definir_duree_cookie_session($auteur); |
|
| 222 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 223 | + 'expires' => time() + $duree |
|
| 224 | + ]); |
|
| 225 | + spip_log("ajoute session $fichier_session cookie $duree", 'session'); |
|
| 226 | + |
|
| 227 | + // Si on est admin, poser le cookie de correspondance |
|
| 228 | + if (!function_exists('autoriser')) { |
|
| 229 | + include_spip('inc/autoriser'); |
|
| 230 | + } |
|
| 231 | + if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 232 | + spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 234 | + ]); |
|
| 235 | + } // sinon le supprimer ... |
|
| 236 | + else { |
|
| 237 | + spip_setcookie('spip_admin', '', [ |
|
| 238 | + 'expires' => 1 |
|
| 239 | + ]); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 243 | + # supprimer_sessions(0, true, false); |
|
| 244 | + |
|
| 245 | + return $_COOKIE['spip_session']; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -262,15 +262,15 @@ discard block |
||
| 262 | 262 | * Durée en secondes |
| 263 | 263 | **/ |
| 264 | 264 | function definir_duree_cookie_session($auteur) { |
| 265 | - $coef = 2; |
|
| 266 | - if (isset($auteur['cookie'])) { |
|
| 267 | - if (is_numeric($auteur['cookie'])) { |
|
| 268 | - $coef = $auteur['cookie']; |
|
| 269 | - } else { |
|
| 270 | - $coef = 20; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 265 | + $coef = 2; |
|
| 266 | + if (isset($auteur['cookie'])) { |
|
| 267 | + if (is_numeric($auteur['cookie'])) { |
|
| 268 | + $coef = $auteur['cookie']; |
|
| 269 | + } else { |
|
| 270 | + $coef = 20; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -290,91 +290,91 @@ discard block |
||
| 290 | 290 | * @return bool|int|null |
| 291 | 291 | */ |
| 292 | 292 | function verifier_session($change = false) { |
| 293 | - // si pas de cookie, c'est fichu |
|
| 294 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 295 | - return false; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $fichier_session = ''; |
|
| 299 | - |
|
| 300 | - // est-ce une session anonyme ? |
|
| 301 | - if (!intval($_COOKIE['spip_session'])) { |
|
| 302 | - spip_php_session_start(); |
|
| 303 | - if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 307 | - } else { |
|
| 308 | - // Tester avec alea courant |
|
| 309 | - $fichier_session = fichier_session('alea_ephemere', true); |
|
| 310 | - if ($fichier_session and @file_exists($fichier_session)) { |
|
| 311 | - include($fichier_session); |
|
| 312 | - } else { |
|
| 313 | - // Sinon, tester avec alea precedent |
|
| 314 | - $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 315 | - if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Renouveler la session avec l'alea courant |
|
| 320 | - include($fichier_session); |
|
| 321 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | - spip_unlink($fichier_session); |
|
| 323 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 328 | - // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 329 | - // n'etre qu'identifie, sans aucune authentification). |
|
| 330 | - |
|
| 331 | - if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 332 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 337 | - // avec un URL de rappel demandant a changer le nom de la session. |
|
| 338 | - // Seul celui qui a l'IP d'origine est rejoue |
|
| 339 | - // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 340 | - // sa victime, mais se ferait deconnecter par elle. |
|
| 341 | - if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 342 | - if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 343 | - define('_SESSION_REJOUER', true); |
|
| 344 | - $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 345 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 346 | - } else { |
|
| 347 | - if ($change) { |
|
| 348 | - spip_log('session non rejouee, vol de cookie ?', 'session'); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } else { |
|
| 352 | - if ($change) { |
|
| 353 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 354 | - if ($fichier_session) { |
|
| 355 | - spip_unlink($fichier_session); |
|
| 356 | - } |
|
| 357 | - $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 358 | - unset($_COOKIE['spip_session']); |
|
| 359 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 364 | - if ( |
|
| 365 | - isset($GLOBALS['visiteur_session']) |
|
| 366 | - and defined('_AGE_SESSION_MAX') |
|
| 367 | - and _AGE_SESSION_MAX > 0 |
|
| 368 | - and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 369 | - ) { |
|
| 370 | - unset($GLOBALS['visiteur_session']); |
|
| 371 | - |
|
| 372 | - return false; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 376 | - ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 377 | - : null; |
|
| 293 | + // si pas de cookie, c'est fichu |
|
| 294 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $fichier_session = ''; |
|
| 299 | + |
|
| 300 | + // est-ce une session anonyme ? |
|
| 301 | + if (!intval($_COOKIE['spip_session'])) { |
|
| 302 | + spip_php_session_start(); |
|
| 303 | + if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 307 | + } else { |
|
| 308 | + // Tester avec alea courant |
|
| 309 | + $fichier_session = fichier_session('alea_ephemere', true); |
|
| 310 | + if ($fichier_session and @file_exists($fichier_session)) { |
|
| 311 | + include($fichier_session); |
|
| 312 | + } else { |
|
| 313 | + // Sinon, tester avec alea precedent |
|
| 314 | + $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 315 | + if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Renouveler la session avec l'alea courant |
|
| 320 | + include($fichier_session); |
|
| 321 | + spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | + spip_unlink($fichier_session); |
|
| 323 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 328 | + // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 329 | + // n'etre qu'identifie, sans aucune authentification). |
|
| 330 | + |
|
| 331 | + if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 332 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 337 | + // avec un URL de rappel demandant a changer le nom de la session. |
|
| 338 | + // Seul celui qui a l'IP d'origine est rejoue |
|
| 339 | + // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 340 | + // sa victime, mais se ferait deconnecter par elle. |
|
| 341 | + if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 342 | + if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 343 | + define('_SESSION_REJOUER', true); |
|
| 344 | + $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 345 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 346 | + } else { |
|
| 347 | + if ($change) { |
|
| 348 | + spip_log('session non rejouee, vol de cookie ?', 'session'); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } else { |
|
| 352 | + if ($change) { |
|
| 353 | + spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 354 | + if ($fichier_session) { |
|
| 355 | + spip_unlink($fichier_session); |
|
| 356 | + } |
|
| 357 | + $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 358 | + unset($_COOKIE['spip_session']); |
|
| 359 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 364 | + if ( |
|
| 365 | + isset($GLOBALS['visiteur_session']) |
|
| 366 | + and defined('_AGE_SESSION_MAX') |
|
| 367 | + and _AGE_SESSION_MAX > 0 |
|
| 368 | + and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 369 | + ) { |
|
| 370 | + unset($GLOBALS['visiteur_session']); |
|
| 371 | + |
|
| 372 | + return false; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 376 | + ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 377 | + : null; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * Valeur, si trouvée, `null` sinon. |
| 390 | 390 | */ |
| 391 | 391 | function session_get($nom) { |
| 392 | - return $GLOBALS['visiteur_session'][$nom] ?? null; |
|
| 392 | + return $GLOBALS['visiteur_session'][$nom] ?? null; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -405,32 +405,32 @@ discard block |
||
| 405 | 405 | * @return void|array |
| 406 | 406 | */ |
| 407 | 407 | function session_set($nom, $val = null) { |
| 408 | - static $remove = []; |
|
| 409 | - static $actualiser_sessions = false; |
|
| 410 | - if ($nom === false) { |
|
| 411 | - return $remove; |
|
| 412 | - } |
|
| 413 | - if (is_null($val)) { |
|
| 414 | - // rien a faire |
|
| 415 | - if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 416 | - return; |
|
| 417 | - } |
|
| 418 | - unset($GLOBALS['visiteur_session'][$nom]); |
|
| 419 | - $remove[] = $nom; |
|
| 420 | - } else { |
|
| 421 | - // On ajoute la valeur dans la globale |
|
| 422 | - $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 423 | - if ($remove) { |
|
| 424 | - $remove = array_diff($remove, [$nom]); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - if (!$actualiser_sessions) { |
|
| 428 | - // il faut creer la session si on en a pas, la premiere fois |
|
| 429 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 430 | - // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 431 | - register_shutdown_function('terminer_actualiser_sessions'); |
|
| 432 | - $actualiser_sessions = true; |
|
| 433 | - } |
|
| 408 | + static $remove = []; |
|
| 409 | + static $actualiser_sessions = false; |
|
| 410 | + if ($nom === false) { |
|
| 411 | + return $remove; |
|
| 412 | + } |
|
| 413 | + if (is_null($val)) { |
|
| 414 | + // rien a faire |
|
| 415 | + if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 416 | + return; |
|
| 417 | + } |
|
| 418 | + unset($GLOBALS['visiteur_session'][$nom]); |
|
| 419 | + $remove[] = $nom; |
|
| 420 | + } else { |
|
| 421 | + // On ajoute la valeur dans la globale |
|
| 422 | + $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 423 | + if ($remove) { |
|
| 424 | + $remove = array_diff($remove, [$nom]); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + if (!$actualiser_sessions) { |
|
| 428 | + // il faut creer la session si on en a pas, la premiere fois |
|
| 429 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 430 | + // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 431 | + register_shutdown_function('terminer_actualiser_sessions'); |
|
| 432 | + $actualiser_sessions = true; |
|
| 433 | + } |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | * @uses actualiser_sessions() |
| 440 | 440 | */ |
| 441 | 441 | function terminer_actualiser_sessions() { |
| 442 | - // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 443 | - chdir(_ROOT_CWD); |
|
| 444 | - // recuperer les variables a effacer |
|
| 445 | - $remove = session_set(false); |
|
| 446 | - // mettre a jour toutes les sessions |
|
| 447 | - actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 442 | + // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 443 | + chdir(_ROOT_CWD); |
|
| 444 | + // recuperer les variables a effacer |
|
| 445 | + $remove = session_set(false); |
|
| 446 | + // mettre a jour toutes les sessions |
|
| 447 | + actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
@@ -469,83 +469,83 @@ discard block |
||
| 469 | 469 | */ |
| 470 | 470 | function actualiser_sessions($auteur, $supprimer_cles = []) { |
| 471 | 471 | |
| 472 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 473 | - $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 474 | - |
|
| 475 | - // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 476 | - $fichier_session_courante = ''; |
|
| 477 | - if ($id_auteur == $id_auteur_courant) { |
|
| 478 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 479 | - ajouter_session($auteur); |
|
| 480 | - if ($id_auteur) { |
|
| 481 | - $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 486 | - if (!$id_auteur) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - // les préférences sont désérialisées, toujours. |
|
| 491 | - // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 492 | - if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 493 | - $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 494 | - if (!is_array($auteur['prefs'])) { |
|
| 495 | - $auteur['prefs'] = []; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 500 | - $sauve = $GLOBALS['visiteur_session']; |
|
| 501 | - |
|
| 502 | - // .. mettre a jour les sessions de l'auteur cible |
|
| 503 | - // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 504 | - // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 505 | - $sessions = lister_sessions_auteur($id_auteur); |
|
| 506 | - |
|
| 507 | - // 1ere passe : lire et fusionner les sessions |
|
| 508 | - foreach ($sessions as $session) { |
|
| 509 | - $GLOBALS['visiteur_session'] = []; |
|
| 510 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 511 | - if ( |
|
| 512 | - $session !== $fichier_session_courante |
|
| 513 | - and @file_exists($session) |
|
| 514 | - ) { |
|
| 515 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 516 | - |
|
| 517 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // supprimer les eventuelles cles dont on ne veut plus |
|
| 522 | - foreach ($supprimer_cles as $cle) { |
|
| 523 | - unset($auteur[$cle]); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $auteur_session = preparer_ecriture_session($auteur); |
|
| 527 | - |
|
| 528 | - // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 529 | - foreach ($sessions as $session) { |
|
| 530 | - $GLOBALS['visiteur_session'] = []; |
|
| 531 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 532 | - if (@file_exists($session)) { |
|
| 533 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 534 | - |
|
| 535 | - // est-ce que cette session est a mettre a jour ? |
|
| 536 | - if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 537 | - ecrire_fichier_session($session, $auteur); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - if ($id_auteur == $id_auteur_courant) { |
|
| 543 | - $GLOBALS['visiteur_session'] = $auteur; |
|
| 544 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 545 | - } else { |
|
| 546 | - // restaurer l'auteur courant |
|
| 547 | - $GLOBALS['visiteur_session'] = $sauve; |
|
| 548 | - } |
|
| 472 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 473 | + $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 474 | + |
|
| 475 | + // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 476 | + $fichier_session_courante = ''; |
|
| 477 | + if ($id_auteur == $id_auteur_courant) { |
|
| 478 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 479 | + ajouter_session($auteur); |
|
| 480 | + if ($id_auteur) { |
|
| 481 | + $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 486 | + if (!$id_auteur) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + // les préférences sont désérialisées, toujours. |
|
| 491 | + // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 492 | + if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 493 | + $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 494 | + if (!is_array($auteur['prefs'])) { |
|
| 495 | + $auteur['prefs'] = []; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 500 | + $sauve = $GLOBALS['visiteur_session']; |
|
| 501 | + |
|
| 502 | + // .. mettre a jour les sessions de l'auteur cible |
|
| 503 | + // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 504 | + // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 505 | + $sessions = lister_sessions_auteur($id_auteur); |
|
| 506 | + |
|
| 507 | + // 1ere passe : lire et fusionner les sessions |
|
| 508 | + foreach ($sessions as $session) { |
|
| 509 | + $GLOBALS['visiteur_session'] = []; |
|
| 510 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 511 | + if ( |
|
| 512 | + $session !== $fichier_session_courante |
|
| 513 | + and @file_exists($session) |
|
| 514 | + ) { |
|
| 515 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 516 | + |
|
| 517 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // supprimer les eventuelles cles dont on ne veut plus |
|
| 522 | + foreach ($supprimer_cles as $cle) { |
|
| 523 | + unset($auteur[$cle]); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + $auteur_session = preparer_ecriture_session($auteur); |
|
| 527 | + |
|
| 528 | + // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 529 | + foreach ($sessions as $session) { |
|
| 530 | + $GLOBALS['visiteur_session'] = []; |
|
| 531 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 532 | + if (@file_exists($session)) { |
|
| 533 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 534 | + |
|
| 535 | + // est-ce que cette session est a mettre a jour ? |
|
| 536 | + if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 537 | + ecrire_fichier_session($session, $auteur); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + if ($id_auteur == $id_auteur_courant) { |
|
| 543 | + $GLOBALS['visiteur_session'] = $auteur; |
|
| 544 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 545 | + } else { |
|
| 546 | + // restaurer l'auteur courant |
|
| 547 | + $GLOBALS['visiteur_session'] = $sauve; |
|
| 548 | + } |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -559,48 +559,48 @@ discard block |
||
| 559 | 559 | */ |
| 560 | 560 | function lister_sessions_auteur($id_auteur, $nb_max = null) { |
| 561 | 561 | |
| 562 | - if (is_null($nb_max)) { |
|
| 563 | - if (!defined('_NB_SESSIONS_MAX')) { |
|
| 564 | - define('_NB_SESSIONS_MAX', 100); |
|
| 565 | - } |
|
| 566 | - $nb_max = _NB_SESSIONS_MAX; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - // liste des sessions |
|
| 570 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 571 | - |
|
| 572 | - // si on en a plus que la limite, supprimer les plus vieilles |
|
| 573 | - // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 574 | - if ( |
|
| 575 | - $id_auteur |
|
| 576 | - and count($sessions) > $nb_max |
|
| 577 | - ) { |
|
| 578 | - // limiter le nombre de sessions ouvertes par un auteur |
|
| 579 | - // filemtime sur les sessions |
|
| 580 | - $sessions = array_flip($sessions); |
|
| 581 | - |
|
| 582 | - // 1ere passe : lire les filemtime |
|
| 583 | - foreach ($sessions as $session => $z) { |
|
| 584 | - if ( |
|
| 585 | - $d = @filemtime($session) |
|
| 586 | - ) { |
|
| 587 | - $sessions[$session] = $d; |
|
| 588 | - } else { |
|
| 589 | - $sessions[$session] = 0; |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - // les plus anciennes en premier |
|
| 594 | - asort($sessions); |
|
| 595 | - |
|
| 596 | - $sessions = array_keys($sessions); |
|
| 597 | - while (count($sessions) > $nb_max) { |
|
| 598 | - $session = array_shift($sessions); |
|
| 599 | - @unlink($session); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - return $sessions; |
|
| 562 | + if (is_null($nb_max)) { |
|
| 563 | + if (!defined('_NB_SESSIONS_MAX')) { |
|
| 564 | + define('_NB_SESSIONS_MAX', 100); |
|
| 565 | + } |
|
| 566 | + $nb_max = _NB_SESSIONS_MAX; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + // liste des sessions |
|
| 570 | + $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 571 | + |
|
| 572 | + // si on en a plus que la limite, supprimer les plus vieilles |
|
| 573 | + // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 574 | + if ( |
|
| 575 | + $id_auteur |
|
| 576 | + and count($sessions) > $nb_max |
|
| 577 | + ) { |
|
| 578 | + // limiter le nombre de sessions ouvertes par un auteur |
|
| 579 | + // filemtime sur les sessions |
|
| 580 | + $sessions = array_flip($sessions); |
|
| 581 | + |
|
| 582 | + // 1ere passe : lire les filemtime |
|
| 583 | + foreach ($sessions as $session => $z) { |
|
| 584 | + if ( |
|
| 585 | + $d = @filemtime($session) |
|
| 586 | + ) { |
|
| 587 | + $sessions[$session] = $d; |
|
| 588 | + } else { |
|
| 589 | + $sessions[$session] = 0; |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + // les plus anciennes en premier |
|
| 594 | + asort($sessions); |
|
| 595 | + |
|
| 596 | + $sessions = array_keys($sessions); |
|
| 597 | + while (count($sessions) > $nb_max) { |
|
| 598 | + $session = array_shift($sessions); |
|
| 599 | + @unlink($session); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + return $sessions; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -614,26 +614,26 @@ discard block |
||
| 614 | 614 | * @return array |
| 615 | 615 | */ |
| 616 | 616 | function preparer_ecriture_session($auteur) { |
| 617 | - $row = $auteur; |
|
| 618 | - |
|
| 619 | - // ne pas enregistrer ces elements de securite |
|
| 620 | - // dans le fichier de session |
|
| 621 | - unset($auteur['pass']); |
|
| 622 | - unset($auteur['htpass']); |
|
| 623 | - unset($auteur['low_sec']); |
|
| 624 | - unset($auteur['alea_actuel']); |
|
| 625 | - unset($auteur['alea_futur']); |
|
| 626 | - |
|
| 627 | - $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]); |
|
| 628 | - |
|
| 629 | - // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 630 | - foreach ($auteur as $variable => $valeur) { |
|
| 631 | - if ($valeur === null) { |
|
| 632 | - unset($auteur[$variable]); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - return $auteur; |
|
| 617 | + $row = $auteur; |
|
| 618 | + |
|
| 619 | + // ne pas enregistrer ces elements de securite |
|
| 620 | + // dans le fichier de session |
|
| 621 | + unset($auteur['pass']); |
|
| 622 | + unset($auteur['htpass']); |
|
| 623 | + unset($auteur['low_sec']); |
|
| 624 | + unset($auteur['alea_actuel']); |
|
| 625 | + unset($auteur['alea_futur']); |
|
| 626 | + |
|
| 627 | + $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]); |
|
| 628 | + |
|
| 629 | + // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 630 | + foreach ($auteur as $variable => $valeur) { |
|
| 631 | + if ($valeur === null) { |
|
| 632 | + unset($auteur[$variable]); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + return $auteur; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -645,17 +645,17 @@ discard block |
||
| 645 | 645 | */ |
| 646 | 646 | function ecrire_fichier_session($fichier, $auteur) { |
| 647 | 647 | |
| 648 | - $auteur = preparer_ecriture_session($auteur); |
|
| 648 | + $auteur = preparer_ecriture_session($auteur); |
|
| 649 | 649 | |
| 650 | - // enregistrer les autres donnees du visiteur |
|
| 651 | - $texte = '<' . "?php\n"; |
|
| 652 | - foreach ($auteur as $var => $val) { |
|
| 653 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | - . var_export($val, true) . ";\n"; |
|
| 655 | - } |
|
| 656 | - $texte .= '?' . ">\n"; |
|
| 650 | + // enregistrer les autres donnees du visiteur |
|
| 651 | + $texte = '<' . "?php\n"; |
|
| 652 | + foreach ($auteur as $var => $val) { |
|
| 653 | + $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | + . var_export($val, true) . ";\n"; |
|
| 655 | + } |
|
| 656 | + $texte .= '?' . ">\n"; |
|
| 657 | 657 | |
| 658 | - return ecrire_fichier($fichier, $texte); |
|
| 658 | + return ecrire_fichier($fichier, $texte); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -668,23 +668,23 @@ discard block |
||
| 668 | 668 | */ |
| 669 | 669 | function fichier_session($alea, $tantpis = false) { |
| 670 | 670 | |
| 671 | - include_spip('inc/acces'); |
|
| 672 | - charger_aleas(); |
|
| 671 | + include_spip('inc/acces'); |
|
| 672 | + charger_aleas(); |
|
| 673 | 673 | |
| 674 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 675 | - if (!$tantpis) { |
|
| 676 | - spip_log("fichier session ($tantpis): $alea indisponible", 'session'); |
|
| 677 | - include_spip('inc/minipres'); |
|
| 678 | - echo minipres(); |
|
| 679 | - } |
|
| 674 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 675 | + if (!$tantpis) { |
|
| 676 | + spip_log("fichier session ($tantpis): $alea indisponible", 'session'); |
|
| 677 | + include_spip('inc/minipres'); |
|
| 678 | + echo minipres(); |
|
| 679 | + } |
|
| 680 | 680 | |
| 681 | - return ''; // echec mais $tanpis |
|
| 682 | - } else { |
|
| 683 | - $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 684 | - $c = $_COOKIE['spip_session']; |
|
| 681 | + return ''; // echec mais $tanpis |
|
| 682 | + } else { |
|
| 683 | + $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 684 | + $c = $_COOKIE['spip_session']; |
|
| 685 | 685 | |
| 686 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 687 | - } |
|
| 686 | + return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 687 | + } |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | * @return string |
| 702 | 702 | */ |
| 703 | 703 | function rejouer_session() { |
| 704 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 704 | + return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * @return string |
| 712 | 712 | */ |
| 713 | 713 | function hash_env() { |
| 714 | - static $res = ''; |
|
| 715 | - if ($res) { |
|
| 716 | - return $res; |
|
| 717 | - } |
|
| 714 | + static $res = ''; |
|
| 715 | + if ($res) { |
|
| 716 | + return $res; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 719 | + return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -728,11 +728,11 @@ discard block |
||
| 728 | 728 | * @return bool True si une session PHP est ouverte. |
| 729 | 729 | **/ |
| 730 | 730 | function spip_php_session_start() { |
| 731 | - if (!is_php_session_started()) { |
|
| 732 | - return session_start(); |
|
| 733 | - } |
|
| 731 | + if (!is_php_session_started()) { |
|
| 732 | + return session_start(); |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | - return true; |
|
| 735 | + return true; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -742,9 +742,9 @@ discard block |
||
| 742 | 742 | * @return bool true si une session PHP est active |
| 743 | 743 | **/ |
| 744 | 744 | function is_php_session_started() { |
| 745 | - if (php_sapi_name() !== 'cli') { |
|
| 746 | - return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 747 | - } |
|
| 745 | + if (php_sapi_name() !== 'cli') { |
|
| 746 | + return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - return false; |
|
| 749 | + return false; |
|
| 750 | 750 | } |
@@ -82,13 +82,13 @@ discard block |
||
| 82 | 82 | spip_log("supprimer sessions auteur $id_auteur", 'session'); |
| 83 | 83 | if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
| 84 | 84 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | 87 | $t = time() - (4 * _RENOUVELLE_ALEA); |
| 88 | 88 | while (($f = readdir($dir)) !== false) { |
| 89 | 89 | $nb_files++; |
| 90 | 90 | if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 91 | + $f = _DIR_SESSIONS.$f; |
|
| 92 | 92 | if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
| 93 | 93 | spip_unlink($f); |
| 94 | 94 | } |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | if ( |
| 173 | 173 | !isset($_COOKIE['spip_session']) |
| 174 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 174 | + or !preg_match(',^'.$id_auteur.'_,', $_COOKIE['spip_session']) |
|
| 175 | 175 | ) { |
| 176 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 176 | + $_COOKIE['spip_session'] = $id_auteur.'_'.md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Maintenant on sait qu'on a des choses à écrire |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | } else { |
| 207 | 207 | $fichier_session = fichier_session('alea_ephemere'); |
| 208 | 208 | if (!ecrire_fichier_session($fichier_session, $auteur)) { |
| 209 | - spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 209 | + spip_log('Echec ecriture fichier session '.$fichier_session, 'session'._LOG_HS); |
|
| 210 | 210 | include_spip('inc/minipres'); |
| 211 | 211 | echo minipres(); |
| 212 | 212 | exit; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | include_spip('inc/autoriser'); |
| 230 | 230 | } |
| 231 | 231 | if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
| 232 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 232 | + spip_setcookie('spip_admin', '@'.($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | 233 | 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
| 234 | 234 | ]); |
| 235 | 235 | } // sinon le supprimer ... |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $coef = 20; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 273 | + return (int) (_RENOUVELLE_ALEA * $coef); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | // Renouveler la session avec l'alea courant |
| 320 | 320 | include($fichier_session); |
| 321 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 321 | + spip_log('renouvelle session '.$GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | 322 | spip_unlink($fichier_session); |
| 323 | 323 | ajouter_session($GLOBALS['visiteur_session']); |
| 324 | 324 | } |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | } else { |
| 352 | 352 | if ($change) { |
| 353 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 353 | + spip_log("rejoue session $fichier_session ".$_COOKIE['spip_session'], 'session'); |
|
| 354 | 354 | if ($fichier_session) { |
| 355 | 355 | spip_unlink($fichier_session); |
| 356 | 356 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // liste des sessions |
| 570 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 570 | + $sessions = preg_files(_DIR_SESSIONS, '/'.$id_auteur.'_.*\.php$'); |
|
| 571 | 571 | |
| 572 | 572 | // si on en a plus que la limite, supprimer les plus vieilles |
| 573 | 573 | // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
@@ -648,12 +648,12 @@ discard block |
||
| 648 | 648 | $auteur = preparer_ecriture_session($auteur); |
| 649 | 649 | |
| 650 | 650 | // enregistrer les autres donnees du visiteur |
| 651 | - $texte = '<' . "?php\n"; |
|
| 651 | + $texte = '<'."?php\n"; |
|
| 652 | 652 | foreach ($auteur as $var => $val) { |
| 653 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | - . var_export($val, true) . ";\n"; |
|
| 653 | + $texte .= '$GLOBALS[\'visiteur_session\']['.var_export($var, true).'] = ' |
|
| 654 | + . var_export($val, true).";\n"; |
|
| 655 | 655 | } |
| 656 | - $texte .= '?' . ">\n"; |
|
| 656 | + $texte .= '?'.">\n"; |
|
| 657 | 657 | |
| 658 | 658 | return ecrire_fichier($fichier, $texte); |
| 659 | 659 | } |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
| 684 | 684 | $c = $_COOKIE['spip_session']; |
| 685 | 685 | |
| 686 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 686 | + return $repertoire.intval($c).'_'.md5($c.' '.$GLOBALS['meta'][$alea]).'.php'; |
|
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | * @return string |
| 702 | 702 | */ |
| 703 | 703 | function rejouer_session() { |
| 704 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 704 | + return '<img src="'.generer_url_action('cookie', 'change_session=oui', true).'" width="0" height="0" alt="" />'; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | return $res; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 719 | + return $res = md5($GLOBALS['ip'].($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |