@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
| 101 | 101 | // c'est une preg |
| 102 | 102 | $recherche_trans = translitteration($recherche); |
| 103 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | + $preg = $recherche_trans.$options['preg_flags']; |
|
| 104 | 104 | $is_preg = true; |
| 105 | 105 | } else { |
| 106 | 106 | // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | + if (preg_match(',\s+,'.$u, $recherche_mod)) { |
|
| 124 | 124 | $is_preg = true; |
| 125 | 125 | |
| 126 | 126 | $recherche_inter = '|'; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | foreach ($recherche_mots as $mot) { |
| 131 | 131 | if (strlen($mot) >= $min_long) { |
| 132 | 132 | // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
| 133 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | + $recherche_inter .= preg_quote($mot).' '; |
|
| 134 | 134 | $petits_mots = false; |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | // mais on cherche quand même l'expression complète, même si elle |
| 140 | 140 | // comporte des mots de moins de quatre lettres |
| 141 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | + $recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|'); |
|
| 142 | 142 | if (!$recherche or $petits_mots) { |
| 143 | 143 | $recherche = preg_quote($recherche_org); |
| 144 | 144 | } |
| 145 | 145 | $recherche_trans = translitteration($recherche); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | + $preg = '/'.str_replace('/', '\\/', $recherche_trans).'/'.$options['preg_flags']; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | $q = sql_quote( |
| 187 | 187 | '%' |
| 188 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | + . preg_replace(',\s+,'.$u, '%', $q) |
|
| 189 | 189 | . '%' |
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | + $preg = '/'.preg_replace(',\s+,'.$u, '.+', trim($recherche_mod)).'/'.$options['preg_flags']; |
|
| 193 | 193 | } else { |
| 194 | 194 | $methode = 'REGEXP'; |
| 195 | 195 | $q = sql_quote(trim($recherche, '/')); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | foreach ($tables as $table => $champs) { |
| 312 | 312 | # lock via memoization, si dispo |
| 313 | 313 | if (function_exists('cache_lock')) { |
| 314 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | + cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | spip_timer('rech'); |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | |
| 328 | 328 | spip_log( |
| 329 | - "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | + "recherche $table ($recherche) : ".(is_countable($results[$table]) ? count($results[$table]) : 0).' resultats '.spip_timer('rech'), |
|
| 330 | 330 | 'recherche' |
| 331 | 331 | ); |
| 332 | 332 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | $results = recherche_en_base($recherche, $tables, $options); |
| 363 | 363 | |
| 364 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 364 | + $preg = '/'.str_replace('/', '\\/', $recherche).'/'.$options['preg_flags']; |
|
| 365 | 365 | |
| 366 | 366 | foreach ($results as $table => $r) { |
| 367 | 367 | $_id_table = id_table_objet($table); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext'); |
@@ -35,198 +35,198 @@ discard block |
||
| 35 | 35 | * @return array Couples (type d'objet => Couples (champ => score)) |
| 36 | 36 | */ |
| 37 | 37 | function liste_des_champs() { |
| 38 | - static $liste = null; |
|
| 39 | - if (is_null($liste)) { |
|
| 40 | - $liste = []; |
|
| 41 | - // recuperer les tables_objets_sql declarees |
|
| 42 | - include_spip('base/objets'); |
|
| 43 | - $tables_objets = lister_tables_objets_sql(); |
|
| 44 | - foreach ($tables_objets as $t => $infos) { |
|
| 45 | - if ($infos['rechercher_champs']) { |
|
| 46 | - $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - // puis passer dans le pipeline |
|
| 50 | - $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $liste; |
|
| 38 | + static $liste = null; |
|
| 39 | + if (is_null($liste)) { |
|
| 40 | + $liste = []; |
|
| 41 | + // recuperer les tables_objets_sql declarees |
|
| 42 | + include_spip('base/objets'); |
|
| 43 | + $tables_objets = lister_tables_objets_sql(); |
|
| 44 | + foreach ($tables_objets as $t => $infos) { |
|
| 45 | + if ($infos['rechercher_champs']) { |
|
| 46 | + $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + // puis passer dans le pipeline |
|
| 50 | + $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $liste; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // Recherche des auteurs et mots-cles associes |
| 58 | 58 | // en ne regardant que le titre ou le nom |
| 59 | 59 | function liste_des_jointures() { |
| 60 | - static $liste = null; |
|
| 61 | - if (is_null($liste)) { |
|
| 62 | - $liste = []; |
|
| 63 | - // recuperer les tables_objets_sql declarees |
|
| 64 | - include_spip('base/objets'); |
|
| 65 | - $tables_objets = lister_tables_objets_sql(); |
|
| 66 | - foreach ($tables_objets as $t => $infos) { |
|
| 67 | - if ($infos['rechercher_jointures']) { |
|
| 68 | - $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - // puis passer dans le pipeline |
|
| 72 | - $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $liste; |
|
| 60 | + static $liste = null; |
|
| 61 | + if (is_null($liste)) { |
|
| 62 | + $liste = []; |
|
| 63 | + // recuperer les tables_objets_sql declarees |
|
| 64 | + include_spip('base/objets'); |
|
| 65 | + $tables_objets = lister_tables_objets_sql(); |
|
| 66 | + foreach ($tables_objets as $t => $infos) { |
|
| 67 | + if ($infos['rechercher_jointures']) { |
|
| 68 | + $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + // puis passer dans le pipeline |
|
| 72 | + $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $liste; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function expression_recherche($recherche, $options) { |
| 79 | - // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | - // (meme si utilisee dans plusieurs boucles) |
|
| 81 | - static $expression = []; |
|
| 82 | - $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | - if (isset($expression[$key])) { |
|
| 84 | - return $expression[$key]; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | - if ($u and strpos($options['preg_flags'], (string) $u) === false) { |
|
| 89 | - $options['preg_flags'] .= $u; |
|
| 90 | - } |
|
| 91 | - include_spip('inc/charsets'); |
|
| 92 | - $recherche = trim($recherche); |
|
| 93 | - |
|
| 94 | - // retirer les + de +truc et les * de truc* |
|
| 95 | - $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | - $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | - |
|
| 98 | - $is_preg = false; |
|
| 99 | - if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | - // c'est une preg |
|
| 101 | - $recherche_trans = translitteration($recherche); |
|
| 102 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | - $is_preg = true; |
|
| 104 | - } else { |
|
| 105 | - // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | - // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | - // 'une', 'des' ...) |
|
| 108 | - |
|
| 109 | - // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | - $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | - |
|
| 112 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | - // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | - foreach ($matches as $match) { |
|
| 116 | - $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | - $word = trim($word, '"'); |
|
| 118 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | - $is_preg = true; |
|
| 124 | - |
|
| 125 | - $recherche_inter = '|'; |
|
| 126 | - $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | - $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | - $petits_mots = true; |
|
| 129 | - foreach ($recherche_mots as $mot) { |
|
| 130 | - if (strlen($mot) >= $min_long) { |
|
| 131 | - // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | - $petits_mots = false; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | - |
|
| 138 | - // mais on cherche quand même l'expression complète, même si elle |
|
| 139 | - // comporte des mots de moins de quatre lettres |
|
| 140 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | - if (!$recherche or $petits_mots) { |
|
| 142 | - $recherche = preg_quote($recherche_org); |
|
| 143 | - } |
|
| 144 | - $recherche_trans = translitteration($recherche); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | - // ou si l'expression reguliere est invalide |
|
| 152 | - if ( |
|
| 153 | - !$is_preg |
|
| 154 | - or (@preg_match($preg, '') === false) |
|
| 155 | - ) { |
|
| 156 | - $methode = 'LIKE'; |
|
| 157 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | - |
|
| 159 | - // echapper les % et _ |
|
| 160 | - $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | - |
|
| 162 | - // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | - $recherche = preg_quote($recherche, '/'); |
|
| 164 | - $recherche_trans = translitteration($recherche); |
|
| 165 | - $recherche_mod = $recherche_trans; |
|
| 166 | - |
|
| 167 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | - // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | - // corriger le like dans le $q |
|
| 170 | - if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | - foreach ($matches as $match) { |
|
| 172 | - $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | - $word = trim($word, '"'); |
|
| 174 | - $q = str_replace($match, $word, $q); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - // corriger la regexp |
|
| 178 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | - foreach ($matches as $match) { |
|
| 180 | - $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | - $word = trim($word, '"'); |
|
| 182 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - $q = sql_quote( |
|
| 186 | - '%' |
|
| 187 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | - . '%' |
|
| 189 | - ); |
|
| 190 | - |
|
| 191 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | - } else { |
|
| 193 | - $methode = 'REGEXP'; |
|
| 194 | - $q = sql_quote(trim($recherche, '/')); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | - // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | - $q_t = $q; |
|
| 200 | - for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | - $char = spip_substr($q, $i, 1); |
|
| 202 | - if ( |
|
| 203 | - !is_ascii($char) |
|
| 204 | - and $char_t = translitteration($char) |
|
| 205 | - and $char_t !== $char |
|
| 206 | - ) { |
|
| 207 | - // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | - // mais c'est un pis aller cf #4354 |
|
| 209 | - $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $q = $q_t; |
|
| 214 | - |
|
| 215 | - // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | - // les plus frequents qui peuvent etre accentues |
|
| 217 | - // (oui c'est tres dicustable...) |
|
| 218 | - if ( |
|
| 219 | - isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | - and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | - ) { |
|
| 222 | - $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | - // si il reste au moins un char significatif... |
|
| 224 | - if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | - $q = $q_t; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $expression[$key] = [$methode, $q, $preg]; |
|
| 79 | + // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | + // (meme si utilisee dans plusieurs boucles) |
|
| 81 | + static $expression = []; |
|
| 82 | + $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | + if (isset($expression[$key])) { |
|
| 84 | + return $expression[$key]; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | + if ($u and strpos($options['preg_flags'], (string) $u) === false) { |
|
| 89 | + $options['preg_flags'] .= $u; |
|
| 90 | + } |
|
| 91 | + include_spip('inc/charsets'); |
|
| 92 | + $recherche = trim($recherche); |
|
| 93 | + |
|
| 94 | + // retirer les + de +truc et les * de truc* |
|
| 95 | + $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | + $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | + |
|
| 98 | + $is_preg = false; |
|
| 99 | + if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | + // c'est une preg |
|
| 101 | + $recherche_trans = translitteration($recherche); |
|
| 102 | + $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | + $is_preg = true; |
|
| 104 | + } else { |
|
| 105 | + // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | + // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | + // 'une', 'des' ...) |
|
| 108 | + |
|
| 109 | + // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | + $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | + |
|
| 112 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | + // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | + foreach ($matches as $match) { |
|
| 116 | + $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | + $word = trim($word, '"'); |
|
| 118 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | + $is_preg = true; |
|
| 124 | + |
|
| 125 | + $recherche_inter = '|'; |
|
| 126 | + $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | + $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | + $petits_mots = true; |
|
| 129 | + foreach ($recherche_mots as $mot) { |
|
| 130 | + if (strlen($mot) >= $min_long) { |
|
| 131 | + // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | + $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | + $petits_mots = false; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | + |
|
| 138 | + // mais on cherche quand même l'expression complète, même si elle |
|
| 139 | + // comporte des mots de moins de quatre lettres |
|
| 140 | + $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | + if (!$recherche or $petits_mots) { |
|
| 142 | + $recherche = preg_quote($recherche_org); |
|
| 143 | + } |
|
| 144 | + $recherche_trans = translitteration($recherche); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | + // ou si l'expression reguliere est invalide |
|
| 152 | + if ( |
|
| 153 | + !$is_preg |
|
| 154 | + or (@preg_match($preg, '') === false) |
|
| 155 | + ) { |
|
| 156 | + $methode = 'LIKE'; |
|
| 157 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | + |
|
| 159 | + // echapper les % et _ |
|
| 160 | + $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | + |
|
| 162 | + // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | + $recherche = preg_quote($recherche, '/'); |
|
| 164 | + $recherche_trans = translitteration($recherche); |
|
| 165 | + $recherche_mod = $recherche_trans; |
|
| 166 | + |
|
| 167 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | + // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | + // corriger le like dans le $q |
|
| 170 | + if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | + foreach ($matches as $match) { |
|
| 172 | + $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | + $word = trim($word, '"'); |
|
| 174 | + $q = str_replace($match, $word, $q); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + // corriger la regexp |
|
| 178 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | + foreach ($matches as $match) { |
|
| 180 | + $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | + $word = trim($word, '"'); |
|
| 182 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + $q = sql_quote( |
|
| 186 | + '%' |
|
| 187 | + . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | + . '%' |
|
| 189 | + ); |
|
| 190 | + |
|
| 191 | + $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | + } else { |
|
| 193 | + $methode = 'REGEXP'; |
|
| 194 | + $q = sql_quote(trim($recherche, '/')); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | + // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | + $q_t = $q; |
|
| 200 | + for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | + $char = spip_substr($q, $i, 1); |
|
| 202 | + if ( |
|
| 203 | + !is_ascii($char) |
|
| 204 | + and $char_t = translitteration($char) |
|
| 205 | + and $char_t !== $char |
|
| 206 | + ) { |
|
| 207 | + // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | + // mais c'est un pis aller cf #4354 |
|
| 209 | + $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $q = $q_t; |
|
| 214 | + |
|
| 215 | + // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | + // les plus frequents qui peuvent etre accentues |
|
| 217 | + // (oui c'est tres dicustable...) |
|
| 218 | + if ( |
|
| 219 | + isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | + and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | + ) { |
|
| 222 | + $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | + // si il reste au moins un char significatif... |
|
| 224 | + if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | + $q = $q_t; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $expression[$key] = [$methode, $q, $preg]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -253,142 +253,142 @@ discard block |
||
| 253 | 253 | * @return array |
| 254 | 254 | */ |
| 255 | 255 | function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') { |
| 256 | - include_spip('base/abstract_sql'); |
|
| 257 | - |
|
| 258 | - if (!is_array($tables)) { |
|
| 259 | - $liste = liste_des_champs(); |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - is_string($tables) |
|
| 263 | - and $tables != '' |
|
| 264 | - ) { |
|
| 265 | - $toutes = []; |
|
| 266 | - foreach (explode(',', $tables) as $t) { |
|
| 267 | - $t = trim($t); |
|
| 268 | - if (isset($liste[$t])) { |
|
| 269 | - $toutes[$t] = $liste[$t]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $tables = $toutes; |
|
| 273 | - unset($toutes); |
|
| 274 | - } else { |
|
| 275 | - $tables = $liste; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if (!strlen($recherche) or !count($tables)) { |
|
| 280 | - return []; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - include_spip('inc/autoriser'); |
|
| 284 | - |
|
| 285 | - // options par defaut |
|
| 286 | - $options = array_merge( |
|
| 287 | - [ |
|
| 288 | - 'preg_flags' => 'UimsS', |
|
| 289 | - 'toutvoir' => false, |
|
| 290 | - 'champs' => false, |
|
| 291 | - 'score' => false, |
|
| 292 | - 'matches' => false, |
|
| 293 | - 'jointures' => false, |
|
| 294 | - 'serveur' => $serveur |
|
| 295 | - ], |
|
| 296 | - $options |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - $results = []; |
|
| 300 | - |
|
| 301 | - // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | - // pour recuperer les couples (id_objet, score) |
|
| 303 | - // Le resultat est au format { |
|
| 304 | - // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | - // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | - // } |
|
| 307 | - |
|
| 308 | - include_spip('inc/recherche_to_array'); |
|
| 309 | - |
|
| 310 | - foreach ($tables as $table => $champs) { |
|
| 311 | - # lock via memoization, si dispo |
|
| 312 | - if (function_exists('cache_lock')) { |
|
| 313 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - spip_timer('rech'); |
|
| 317 | - |
|
| 318 | - # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | - $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | - $results[$table] = $to_array( |
|
| 321 | - $recherche, |
|
| 322 | - array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | - ); |
|
| 324 | - ##var_dump($results[$table]); |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - spip_log( |
|
| 328 | - "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | - 'recherche' |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - if (isset($lock)) { |
|
| 333 | - cache_unlock($lock); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return $results; |
|
| 256 | + include_spip('base/abstract_sql'); |
|
| 257 | + |
|
| 258 | + if (!is_array($tables)) { |
|
| 259 | + $liste = liste_des_champs(); |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + is_string($tables) |
|
| 263 | + and $tables != '' |
|
| 264 | + ) { |
|
| 265 | + $toutes = []; |
|
| 266 | + foreach (explode(',', $tables) as $t) { |
|
| 267 | + $t = trim($t); |
|
| 268 | + if (isset($liste[$t])) { |
|
| 269 | + $toutes[$t] = $liste[$t]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $tables = $toutes; |
|
| 273 | + unset($toutes); |
|
| 274 | + } else { |
|
| 275 | + $tables = $liste; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if (!strlen($recherche) or !count($tables)) { |
|
| 280 | + return []; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + include_spip('inc/autoriser'); |
|
| 284 | + |
|
| 285 | + // options par defaut |
|
| 286 | + $options = array_merge( |
|
| 287 | + [ |
|
| 288 | + 'preg_flags' => 'UimsS', |
|
| 289 | + 'toutvoir' => false, |
|
| 290 | + 'champs' => false, |
|
| 291 | + 'score' => false, |
|
| 292 | + 'matches' => false, |
|
| 293 | + 'jointures' => false, |
|
| 294 | + 'serveur' => $serveur |
|
| 295 | + ], |
|
| 296 | + $options |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + $results = []; |
|
| 300 | + |
|
| 301 | + // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | + // pour recuperer les couples (id_objet, score) |
|
| 303 | + // Le resultat est au format { |
|
| 304 | + // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | + // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | + // } |
|
| 307 | + |
|
| 308 | + include_spip('inc/recherche_to_array'); |
|
| 309 | + |
|
| 310 | + foreach ($tables as $table => $champs) { |
|
| 311 | + # lock via memoization, si dispo |
|
| 312 | + if (function_exists('cache_lock')) { |
|
| 313 | + cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + spip_timer('rech'); |
|
| 317 | + |
|
| 318 | + # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | + $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | + $results[$table] = $to_array( |
|
| 321 | + $recherche, |
|
| 322 | + array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | + ); |
|
| 324 | + ##var_dump($results[$table]); |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + spip_log( |
|
| 328 | + "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | + 'recherche' |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + if (isset($lock)) { |
|
| 333 | + cache_unlock($lock); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return $results; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
| 341 | 341 | // Effectue une recherche sur toutes les tables de la base de donnees |
| 342 | 342 | function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) { |
| 343 | - include_spip('inc/modifier'); |
|
| 344 | - |
|
| 345 | - // options par defaut |
|
| 346 | - $options = array_merge( |
|
| 347 | - [ |
|
| 348 | - 'preg_flags' => 'UimsS', |
|
| 349 | - 'toutmodifier' => false |
|
| 350 | - ], |
|
| 351 | - $options |
|
| 352 | - ); |
|
| 353 | - $options['champs'] = true; |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - if (!is_array($tables)) { |
|
| 357 | - $tables = liste_des_champs(); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | - |
|
| 362 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | - |
|
| 364 | - foreach ($results as $table => $r) { |
|
| 365 | - $_id_table = id_table_objet($table); |
|
| 366 | - foreach ($r as $id => $x) { |
|
| 367 | - if ( |
|
| 368 | - $options['toutmodifier'] |
|
| 369 | - or autoriser('modifier', $table, $id) |
|
| 370 | - ) { |
|
| 371 | - $modifs = []; |
|
| 372 | - foreach ($x['champs'] as $key => $val) { |
|
| 373 | - if ($key == $_id_table) { |
|
| 374 | - continue; |
|
| 375 | - } |
|
| 376 | - $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | - if ($repl <> $val) { |
|
| 378 | - $modifs[$key] = $repl; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - if ($modifs) { |
|
| 382 | - objet_modifier_champs( |
|
| 383 | - $table, |
|
| 384 | - $id, |
|
| 385 | - [ |
|
| 386 | - 'champs' => array_keys($modifs), |
|
| 387 | - ], |
|
| 388 | - $modifs |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 343 | + include_spip('inc/modifier'); |
|
| 344 | + |
|
| 345 | + // options par defaut |
|
| 346 | + $options = array_merge( |
|
| 347 | + [ |
|
| 348 | + 'preg_flags' => 'UimsS', |
|
| 349 | + 'toutmodifier' => false |
|
| 350 | + ], |
|
| 351 | + $options |
|
| 352 | + ); |
|
| 353 | + $options['champs'] = true; |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + if (!is_array($tables)) { |
|
| 357 | + $tables = liste_des_champs(); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | + |
|
| 362 | + $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | + |
|
| 364 | + foreach ($results as $table => $r) { |
|
| 365 | + $_id_table = id_table_objet($table); |
|
| 366 | + foreach ($r as $id => $x) { |
|
| 367 | + if ( |
|
| 368 | + $options['toutmodifier'] |
|
| 369 | + or autoriser('modifier', $table, $id) |
|
| 370 | + ) { |
|
| 371 | + $modifs = []; |
|
| 372 | + foreach ($x['champs'] as $key => $val) { |
|
| 373 | + if ($key == $_id_table) { |
|
| 374 | + continue; |
|
| 375 | + } |
|
| 376 | + $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | + if ($repl <> $val) { |
|
| 378 | + $modifs[$key] = $repl; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + if ($modifs) { |
|
| 382 | + objet_modifier_champs( |
|
| 383 | + $table, |
|
| 384 | + $id, |
|
| 385 | + [ |
|
| 386 | + 'champs' => array_keys($modifs), |
|
| 387 | + ], |
|
| 388 | + $modifs |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | $n = 0; |
| 46 | 46 | $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
| 47 | 47 | for ($i = 0; $i < 256; $i++) { |
| 48 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 48 | + $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 49 | 49 | if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
| 50 | 50 | while (($f = readdir($d)) !== false) { |
| 51 | 51 | if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | // stocker la date_modif_$objet (ne sert a rien pour le moment) |
| 104 | 104 | if (isset($objet)) { |
| 105 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 105 | + ecrire_meta('derniere_modif_'.$objet, time()); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // si $derniere_modif_invalide est un array('article', 'rubrique') |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
| 147 | 147 | // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
| 148 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 148 | + if (file_exists(rtrim($dir, '/').'/inhib_purger_repertoire.txt')) { |
|
| 149 | 149 | return 0; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | ) |
| 209 | 209 | ) { |
| 210 | 210 | // supprimer le fichier (de facon propre) |
| 211 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | + supprimer_fichier(_DIR_CACHE.$cache); |
|
| 212 | 212 | } else { |
| 213 | 213 | spip_log("Nom de fichier cache incorrect : $cache"); |
| 214 | 214 | } |
@@ -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('base/serial'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * en droit de l'éliminer |
| 28 | 28 | */ |
| 29 | 29 | if (!defined('_AGE_CACHE_ATIME')) { |
| 30 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 30 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | * @return int Taille approximative en octets |
| 41 | 41 | **/ |
| 42 | 42 | function taille_du_cache() { |
| 43 | - # check dirs until we reach > 500 files |
|
| 44 | - $t = 0; |
|
| 45 | - $n = 0; |
|
| 46 | - $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | - for ($i = 0; $i < 256; $i++) { |
|
| 48 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | - while (($f = readdir($d)) !== false) { |
|
| 51 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | - $n++; |
|
| 53 | - if ($a['mtime'] >= $time) { |
|
| 54 | - if ($a['blocks'] > 0) { |
|
| 55 | - $t += 512 * $a['blocks']; |
|
| 56 | - } else { |
|
| 57 | - $t += $a['size']; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - if ($n > 500) { |
|
| 64 | - return intval(256 * $t / (1 + $i)); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $t; |
|
| 43 | + # check dirs until we reach > 500 files |
|
| 44 | + $t = 0; |
|
| 45 | + $n = 0; |
|
| 46 | + $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | + for ($i = 0; $i < 256; $i++) { |
|
| 48 | + $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | + while (($f = readdir($d)) !== false) { |
|
| 51 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | + $n++; |
|
| 53 | + if ($a['mtime'] >= $time) { |
|
| 54 | + if ($a['blocks'] > 0) { |
|
| 55 | + $t += 512 * $a['blocks']; |
|
| 56 | + } else { |
|
| 57 | + $t += $a['size']; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + if ($n > 500) { |
|
| 64 | + return intval(256 * $t / (1 + $i)); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -91,30 +91,30 @@ discard block |
||
| 91 | 91 | * Inutilisé |
| 92 | 92 | **/ |
| 93 | 93 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 94 | - if (!$modif) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // determiner l'objet modifie : forum, article, etc |
|
| 99 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | - $objet = objet_type($r[1]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | - if (isset($objet)) { |
|
| 105 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | - ecrire_meta('derniere_modif', time()); |
|
| 113 | - } |
|
| 114 | - } // sinon, cas standard, toujours affecter la meta |
|
| 115 | - else { |
|
| 116 | - ecrire_meta('derniere_modif', time()); |
|
| 117 | - } |
|
| 94 | + if (!$modif) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // determiner l'objet modifie : forum, article, etc |
|
| 99 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | + $objet = objet_type($r[1]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | + if (isset($objet)) { |
|
| 105 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | + ecrire_meta('derniere_modif', time()); |
|
| 113 | + } |
|
| 114 | + } // sinon, cas standard, toujours affecter la meta |
|
| 115 | + else { |
|
| 116 | + ecrire_meta('derniere_modif', time()); |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -139,57 +139,57 @@ discard block |
||
| 139 | 139 | * Nombre de fichiers supprimés |
| 140 | 140 | **/ |
| 141 | 141 | function purger_repertoire($dir, $options = []) { |
| 142 | - if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | - return 0; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | - // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | - return 0; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $handle = opendir($dir); |
|
| 153 | - if (!$handle) { |
|
| 154 | - return 0; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $total = 0; |
|
| 158 | - |
|
| 159 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | - if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | - continue; |
|
| 163 | - } |
|
| 164 | - $chemin = "$dir/$fichier"; |
|
| 165 | - if (is_file($chemin)) { |
|
| 166 | - if ( |
|
| 167 | - (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | - and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | - ) { |
|
| 170 | - supprimer_fichier($chemin); |
|
| 171 | - $total++; |
|
| 172 | - } |
|
| 173 | - } else { |
|
| 174 | - if (is_dir($chemin)) { |
|
| 175 | - $opts = $options; |
|
| 176 | - if (isset($options['limit'])) { |
|
| 177 | - $opts['limit'] = $options['limit'] - $total; |
|
| 178 | - } |
|
| 179 | - $total += purger_repertoire($chemin, $opts); |
|
| 180 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | - spip_unlink($chemin); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - closedir($handle); |
|
| 191 | - |
|
| 192 | - return $total; |
|
| 142 | + if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | + return 0; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | + // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | + if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | + return 0; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $handle = opendir($dir); |
|
| 153 | + if (!$handle) { |
|
| 154 | + return 0; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $total = 0; |
|
| 158 | + |
|
| 159 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | + if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 164 | + $chemin = "$dir/$fichier"; |
|
| 165 | + if (is_file($chemin)) { |
|
| 166 | + if ( |
|
| 167 | + (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | + and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | + ) { |
|
| 170 | + supprimer_fichier($chemin); |
|
| 171 | + $total++; |
|
| 172 | + } |
|
| 173 | + } else { |
|
| 174 | + if (is_dir($chemin)) { |
|
| 175 | + $opts = $options; |
|
| 176 | + if (isset($options['limit'])) { |
|
| 177 | + $opts['limit'] = $options['limit'] - $total; |
|
| 178 | + } |
|
| 179 | + $total += purger_repertoire($chemin, $opts); |
|
| 180 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | + spip_unlink($chemin); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + closedir($handle); |
|
| 191 | + |
|
| 192 | + return $total; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -200,26 +200,26 @@ discard block |
||
| 200 | 200 | // Securite : est sur que c'est un cache |
| 201 | 201 | function retire_cache($cache) { |
| 202 | 202 | |
| 203 | - if ( |
|
| 204 | - preg_match( |
|
| 205 | - ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | - $cache |
|
| 207 | - ) |
|
| 208 | - ) { |
|
| 209 | - // supprimer le fichier (de facon propre) |
|
| 210 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | - } else { |
|
| 212 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | - } |
|
| 203 | + if ( |
|
| 204 | + preg_match( |
|
| 205 | + ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | + $cache |
|
| 207 | + ) |
|
| 208 | + ) { |
|
| 209 | + // supprimer le fichier (de facon propre) |
|
| 210 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | + } else { |
|
| 212 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Supprimer les caches marques "x" |
| 217 | 217 | // A priori dans cette version la fonction ne sera pas appelee, car |
| 218 | 218 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 219 | 219 | function inc_retire_caches_dist($chemin = '') { |
| 220 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | - effacer_meta('invalider_caches'); |
|
| 222 | - } # concurrence |
|
| 220 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | + effacer_meta('invalider_caches'); |
|
| 222 | + } # concurrence |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | ####################################################################### |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | ## |
| 231 | 231 | |
| 232 | 232 | function retire_caches($chemin = '') { |
| 233 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | - return $retire_caches($chemin); |
|
| 235 | - } |
|
| 233 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | + return $retire_caches($chemin); |
|
| 235 | + } |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | // (note: si absente, n'est pas appellee) |
| 241 | 241 | |
| 242 | 242 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 243 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | - } |
|
| 246 | - return $corps; |
|
| 243 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | + } |
|
| 246 | + return $corps; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -252,41 +252,41 @@ discard block |
||
| 252 | 252 | // invoquee quand on vide tout le cache en bloc (action/purger) |
| 253 | 253 | // |
| 254 | 254 | function supprime_invalideurs() { |
| 255 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | - return $supprime_invalideurs(); |
|
| 257 | - } |
|
| 255 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | + return $supprime_invalideurs(); |
|
| 257 | + } |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
| 261 | 261 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 262 | 262 | function maj_invalideurs($fichier, &$page) { |
| 263 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | - return $maj_invalideurs($fichier, $page); |
|
| 265 | - } |
|
| 263 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | + return $maj_invalideurs($fichier, $page); |
|
| 265 | + } |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | // les invalideurs sont de la forme "objet/id_objet" |
| 270 | 270 | function insere_invalideur($inval, $fichier) { |
| 271 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | - return $insere_invalideur($inval, $fichier); |
|
| 273 | - } |
|
| 271 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | + return $insere_invalideur($inval, $fichier); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // |
| 277 | 277 | // Marquer les fichiers caches invalides comme etant a supprimer |
| 278 | 278 | // |
| 279 | 279 | function applique_invalideur($depart) { |
| 280 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | - return $applique_invalideur($depart); |
|
| 282 | - } |
|
| 280 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | + return $applique_invalideur($depart); |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // |
| 286 | 286 | // Invalider les caches liés à telle condition |
| 287 | 287 | // |
| 288 | 288 | function suivre_invalideur($cond, $modif = true) { |
| 289 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | - return $suivre_invalideur($cond, $modif); |
|
| 291 | - } |
|
| 289 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | + return $suivre_invalideur($cond, $modif); |
|
| 291 | + } |
|
| 292 | 292 | } |
@@ -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 | } |