@@ -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 !str_contains($options['preg_flags'], (string) $u)) { |
|
| 89 | - $options['preg_flags'] .= $u; |
|
| 90 | - } |
|
| 91 | - include_spip('inc/charsets'); |
|
| 92 | - $recherche = trim($recherche); |
|
| 93 | - |
|
| 94 | - // retirer les + de +truc et les * de truc* |
|
| 95 | - $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | - $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | - |
|
| 98 | - $is_preg = false; |
|
| 99 | - if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | - // c'est une preg |
|
| 101 | - $recherche_trans = translitteration($recherche); |
|
| 102 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | - $is_preg = true; |
|
| 104 | - } else { |
|
| 105 | - // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | - // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | - // 'une', 'des' ...) |
|
| 108 | - |
|
| 109 | - // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | - $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | - |
|
| 112 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | - // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | - foreach ($matches as $match) { |
|
| 116 | - $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | - $word = trim($word, '"'); |
|
| 118 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | - $is_preg = true; |
|
| 124 | - |
|
| 125 | - $recherche_inter = '|'; |
|
| 126 | - $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | - $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | - $petits_mots = true; |
|
| 129 | - foreach ($recherche_mots as $mot) { |
|
| 130 | - if (strlen($mot) >= $min_long) { |
|
| 131 | - // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | - $petits_mots = false; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | - |
|
| 138 | - // mais on cherche quand mĂªme l'expression complète, mĂªme si elle |
|
| 139 | - // comporte des mots de moins de quatre lettres |
|
| 140 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | - if (!$recherche or $petits_mots) { |
|
| 142 | - $recherche = preg_quote($recherche_org); |
|
| 143 | - } |
|
| 144 | - $recherche_trans = translitteration($recherche); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | - // ou si l'expression reguliere est invalide |
|
| 152 | - if ( |
|
| 153 | - !$is_preg |
|
| 154 | - or (@preg_match($preg, '') === false) |
|
| 155 | - ) { |
|
| 156 | - $methode = 'LIKE'; |
|
| 157 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | - |
|
| 159 | - // echapper les % et _ |
|
| 160 | - $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | - |
|
| 162 | - // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | - $recherche = preg_quote($recherche, '/'); |
|
| 164 | - $recherche_trans = translitteration($recherche); |
|
| 165 | - $recherche_mod = $recherche_trans; |
|
| 166 | - |
|
| 167 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | - // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | - // corriger le like dans le $q |
|
| 170 | - if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | - foreach ($matches as $match) { |
|
| 172 | - $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | - $word = trim($word, '"'); |
|
| 174 | - $q = str_replace($match, $word, $q); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - // corriger la regexp |
|
| 178 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | - foreach ($matches as $match) { |
|
| 180 | - $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | - $word = trim($word, '"'); |
|
| 182 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - $q = sql_quote( |
|
| 186 | - '%' |
|
| 187 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | - . '%' |
|
| 189 | - ); |
|
| 190 | - |
|
| 191 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | - } else { |
|
| 193 | - $methode = 'REGEXP'; |
|
| 194 | - $q = sql_quote(trim($recherche, '/')); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | - // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | - $q_t = $q; |
|
| 200 | - for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | - $char = spip_substr($q, $i, 1); |
|
| 202 | - if ( |
|
| 203 | - !is_ascii($char) |
|
| 204 | - and $char_t = translitteration($char) |
|
| 205 | - and $char_t !== $char |
|
| 206 | - ) { |
|
| 207 | - // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | - // mais c'est un pis aller cf #4354 |
|
| 209 | - $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $q = $q_t; |
|
| 214 | - |
|
| 215 | - // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | - // les plus frequents qui peuvent etre accentues |
|
| 217 | - // (oui c'est tres dicustable...) |
|
| 218 | - if ( |
|
| 219 | - isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | - and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | - ) { |
|
| 222 | - $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | - // si il reste au moins un char significatif... |
|
| 224 | - if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | - $q = $q_t; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $expression[$key] = [$methode, $q, $preg]; |
|
| 79 | + // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | + // (meme si utilisee dans plusieurs boucles) |
|
| 81 | + static $expression = []; |
|
| 82 | + $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | + if (isset($expression[$key])) { |
|
| 84 | + return $expression[$key]; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | + if ($u and !str_contains($options['preg_flags'], (string) $u)) { |
|
| 89 | + $options['preg_flags'] .= $u; |
|
| 90 | + } |
|
| 91 | + include_spip('inc/charsets'); |
|
| 92 | + $recherche = trim($recherche); |
|
| 93 | + |
|
| 94 | + // retirer les + de +truc et les * de truc* |
|
| 95 | + $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | + $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | + |
|
| 98 | + $is_preg = false; |
|
| 99 | + if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | + // c'est une preg |
|
| 101 | + $recherche_trans = translitteration($recherche); |
|
| 102 | + $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | + $is_preg = true; |
|
| 104 | + } else { |
|
| 105 | + // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | + // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | + // 'une', 'des' ...) |
|
| 108 | + |
|
| 109 | + // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | + $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | + |
|
| 112 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | + // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | + foreach ($matches as $match) { |
|
| 116 | + $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | + $word = trim($word, '"'); |
|
| 118 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | + $is_preg = true; |
|
| 124 | + |
|
| 125 | + $recherche_inter = '|'; |
|
| 126 | + $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | + $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | + $petits_mots = true; |
|
| 129 | + foreach ($recherche_mots as $mot) { |
|
| 130 | + if (strlen($mot) >= $min_long) { |
|
| 131 | + // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | + $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | + $petits_mots = false; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | + |
|
| 138 | + // mais on cherche quand mĂªme l'expression complète, mĂªme si elle |
|
| 139 | + // comporte des mots de moins de quatre lettres |
|
| 140 | + $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | + if (!$recherche or $petits_mots) { |
|
| 142 | + $recherche = preg_quote($recherche_org); |
|
| 143 | + } |
|
| 144 | + $recherche_trans = translitteration($recherche); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | + // ou si l'expression reguliere est invalide |
|
| 152 | + if ( |
|
| 153 | + !$is_preg |
|
| 154 | + or (@preg_match($preg, '') === false) |
|
| 155 | + ) { |
|
| 156 | + $methode = 'LIKE'; |
|
| 157 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | + |
|
| 159 | + // echapper les % et _ |
|
| 160 | + $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | + |
|
| 162 | + // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | + $recherche = preg_quote($recherche, '/'); |
|
| 164 | + $recherche_trans = translitteration($recherche); |
|
| 165 | + $recherche_mod = $recherche_trans; |
|
| 166 | + |
|
| 167 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | + // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | + // corriger le like dans le $q |
|
| 170 | + if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | + foreach ($matches as $match) { |
|
| 172 | + $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | + $word = trim($word, '"'); |
|
| 174 | + $q = str_replace($match, $word, $q); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + // corriger la regexp |
|
| 178 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | + foreach ($matches as $match) { |
|
| 180 | + $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | + $word = trim($word, '"'); |
|
| 182 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + $q = sql_quote( |
|
| 186 | + '%' |
|
| 187 | + . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | + . '%' |
|
| 189 | + ); |
|
| 190 | + |
|
| 191 | + $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | + } else { |
|
| 193 | + $methode = 'REGEXP'; |
|
| 194 | + $q = sql_quote(trim($recherche, '/')); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | + // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | + $q_t = $q; |
|
| 200 | + for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | + $char = spip_substr($q, $i, 1); |
|
| 202 | + if ( |
|
| 203 | + !is_ascii($char) |
|
| 204 | + and $char_t = translitteration($char) |
|
| 205 | + and $char_t !== $char |
|
| 206 | + ) { |
|
| 207 | + // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | + // mais c'est un pis aller cf #4354 |
|
| 209 | + $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $q = $q_t; |
|
| 214 | + |
|
| 215 | + // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | + // les plus frequents qui peuvent etre accentues |
|
| 217 | + // (oui c'est tres dicustable...) |
|
| 218 | + if ( |
|
| 219 | + isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | + and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | + ) { |
|
| 222 | + $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | + // si il reste au moins un char significatif... |
|
| 224 | + if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | + $q = $q_t; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $expression[$key] = [$methode, $q, $preg]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -253,142 +253,142 @@ discard block |
||
| 253 | 253 | * @return array |
| 254 | 254 | */ |
| 255 | 255 | function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') { |
| 256 | - include_spip('base/abstract_sql'); |
|
| 257 | - |
|
| 258 | - if (!is_array($tables)) { |
|
| 259 | - $liste = liste_des_champs(); |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - is_string($tables) |
|
| 263 | - and $tables != '' |
|
| 264 | - ) { |
|
| 265 | - $toutes = []; |
|
| 266 | - foreach (explode(',', $tables) as $t) { |
|
| 267 | - $t = trim($t); |
|
| 268 | - if (isset($liste[$t])) { |
|
| 269 | - $toutes[$t] = $liste[$t]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $tables = $toutes; |
|
| 273 | - unset($toutes); |
|
| 274 | - } else { |
|
| 275 | - $tables = $liste; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if (!strlen($recherche) or !count($tables)) { |
|
| 280 | - return []; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - include_spip('inc/autoriser'); |
|
| 284 | - |
|
| 285 | - // options par defaut |
|
| 286 | - $options = array_merge( |
|
| 287 | - [ |
|
| 288 | - 'preg_flags' => 'UimsS', |
|
| 289 | - 'toutvoir' => false, |
|
| 290 | - 'champs' => false, |
|
| 291 | - 'score' => false, |
|
| 292 | - 'matches' => false, |
|
| 293 | - 'jointures' => false, |
|
| 294 | - 'serveur' => $serveur |
|
| 295 | - ], |
|
| 296 | - $options |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - $results = []; |
|
| 300 | - |
|
| 301 | - // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | - // pour recuperer les couples (id_objet, score) |
|
| 303 | - // Le resultat est au format { |
|
| 304 | - // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | - // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | - // } |
|
| 307 | - |
|
| 308 | - include_spip('inc/recherche_to_array'); |
|
| 309 | - |
|
| 310 | - foreach ($tables as $table => $champs) { |
|
| 311 | - # lock via memoization, si dispo |
|
| 312 | - if (function_exists('cache_lock')) { |
|
| 313 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - spip_timer('rech'); |
|
| 317 | - |
|
| 318 | - # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | - $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | - $results[$table] = $to_array( |
|
| 321 | - $recherche, |
|
| 322 | - array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | - ); |
|
| 324 | - ##var_dump($results[$table]); |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - spip_log( |
|
| 328 | - "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | - 'recherche' |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - if (isset($lock)) { |
|
| 333 | - cache_unlock($lock); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return $results; |
|
| 256 | + include_spip('base/abstract_sql'); |
|
| 257 | + |
|
| 258 | + if (!is_array($tables)) { |
|
| 259 | + $liste = liste_des_champs(); |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + is_string($tables) |
|
| 263 | + and $tables != '' |
|
| 264 | + ) { |
|
| 265 | + $toutes = []; |
|
| 266 | + foreach (explode(',', $tables) as $t) { |
|
| 267 | + $t = trim($t); |
|
| 268 | + if (isset($liste[$t])) { |
|
| 269 | + $toutes[$t] = $liste[$t]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $tables = $toutes; |
|
| 273 | + unset($toutes); |
|
| 274 | + } else { |
|
| 275 | + $tables = $liste; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if (!strlen($recherche) or !count($tables)) { |
|
| 280 | + return []; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + include_spip('inc/autoriser'); |
|
| 284 | + |
|
| 285 | + // options par defaut |
|
| 286 | + $options = array_merge( |
|
| 287 | + [ |
|
| 288 | + 'preg_flags' => 'UimsS', |
|
| 289 | + 'toutvoir' => false, |
|
| 290 | + 'champs' => false, |
|
| 291 | + 'score' => false, |
|
| 292 | + 'matches' => false, |
|
| 293 | + 'jointures' => false, |
|
| 294 | + 'serveur' => $serveur |
|
| 295 | + ], |
|
| 296 | + $options |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + $results = []; |
|
| 300 | + |
|
| 301 | + // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | + // pour recuperer les couples (id_objet, score) |
|
| 303 | + // Le resultat est au format { |
|
| 304 | + // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | + // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | + // } |
|
| 307 | + |
|
| 308 | + include_spip('inc/recherche_to_array'); |
|
| 309 | + |
|
| 310 | + foreach ($tables as $table => $champs) { |
|
| 311 | + # lock via memoization, si dispo |
|
| 312 | + if (function_exists('cache_lock')) { |
|
| 313 | + cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + spip_timer('rech'); |
|
| 317 | + |
|
| 318 | + # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | + $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | + $results[$table] = $to_array( |
|
| 321 | + $recherche, |
|
| 322 | + array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | + ); |
|
| 324 | + ##var_dump($results[$table]); |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + spip_log( |
|
| 328 | + "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | + 'recherche' |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + if (isset($lock)) { |
|
| 333 | + cache_unlock($lock); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return $results; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
| 341 | 341 | // Effectue une recherche sur toutes les tables de la base de donnees |
| 342 | 342 | function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) { |
| 343 | - include_spip('inc/modifier'); |
|
| 344 | - |
|
| 345 | - // options par defaut |
|
| 346 | - $options = array_merge( |
|
| 347 | - [ |
|
| 348 | - 'preg_flags' => 'UimsS', |
|
| 349 | - 'toutmodifier' => false |
|
| 350 | - ], |
|
| 351 | - $options |
|
| 352 | - ); |
|
| 353 | - $options['champs'] = true; |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - if (!is_array($tables)) { |
|
| 357 | - $tables = liste_des_champs(); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | - |
|
| 362 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | - |
|
| 364 | - foreach ($results as $table => $r) { |
|
| 365 | - $_id_table = id_table_objet($table); |
|
| 366 | - foreach ($r as $id => $x) { |
|
| 367 | - if ( |
|
| 368 | - $options['toutmodifier'] |
|
| 369 | - or autoriser('modifier', $table, $id) |
|
| 370 | - ) { |
|
| 371 | - $modifs = []; |
|
| 372 | - foreach ($x['champs'] as $key => $val) { |
|
| 373 | - if ($key == $_id_table) { |
|
| 374 | - continue; |
|
| 375 | - } |
|
| 376 | - $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | - if ($repl <> $val) { |
|
| 378 | - $modifs[$key] = $repl; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - if ($modifs) { |
|
| 382 | - objet_modifier_champs( |
|
| 383 | - $table, |
|
| 384 | - $id, |
|
| 385 | - [ |
|
| 386 | - 'champs' => array_keys($modifs), |
|
| 387 | - ], |
|
| 388 | - $modifs |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 343 | + include_spip('inc/modifier'); |
|
| 344 | + |
|
| 345 | + // options par defaut |
|
| 346 | + $options = array_merge( |
|
| 347 | + [ |
|
| 348 | + 'preg_flags' => 'UimsS', |
|
| 349 | + 'toutmodifier' => false |
|
| 350 | + ], |
|
| 351 | + $options |
|
| 352 | + ); |
|
| 353 | + $options['champs'] = true; |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + if (!is_array($tables)) { |
|
| 357 | + $tables = liste_des_champs(); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | + |
|
| 362 | + $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | + |
|
| 364 | + foreach ($results as $table => $r) { |
|
| 365 | + $_id_table = id_table_objet($table); |
|
| 366 | + foreach ($r as $id => $x) { |
|
| 367 | + if ( |
|
| 368 | + $options['toutmodifier'] |
|
| 369 | + or autoriser('modifier', $table, $id) |
|
| 370 | + ) { |
|
| 371 | + $modifs = []; |
|
| 372 | + foreach ($x['champs'] as $key => $val) { |
|
| 373 | + if ($key == $_id_table) { |
|
| 374 | + continue; |
|
| 375 | + } |
|
| 376 | + $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | + if ($repl <> $val) { |
|
| 378 | + $modifs[$key] = $repl; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + if ($modifs) { |
|
| 382 | + objet_modifier_champs( |
|
| 383 | + $table, |
|
| 384 | + $id, |
|
| 385 | + [ |
|
| 386 | + 'champs' => array_keys($modifs), |
|
| 387 | + ], |
|
| 388 | + $modifs |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -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 | } |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | $res = sql_select( |
| 36 | 36 | 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
| 37 | 37 | 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
| 38 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 39 | - AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
|
| 40 | - AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
|
| 38 | + 'rub1.id_parent = '.sql_quote($id_rubrique).' |
|
| 39 | + AND rub1.id_rubrique!=' . sql_quote($exclu).' |
|
| 40 | + AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu).')', |
|
| 41 | 41 | '', |
| 42 | 42 | '0+rub1.titre,rub1.titre' |
| 43 | 43 | ); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if ($row['langue_choisie'] != 'oui') { |
| 51 | 51 | $t .= ' <small title="' |
| 52 | 52 | . traduire_nom_langue($row['lang']) |
| 53 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | + . '">['.$row['lang'].']</small>'; |
|
| 54 | 54 | } |
| 55 | 55 | $ordre[$row['id_rubrique']] = $t; |
| 56 | 56 | } |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | $next = $list[$col] ?? 0; |
| 60 | 60 | if ($ordre) { |
| 61 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=".($col + 1)); |
|
| 62 | 62 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
| 63 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 63 | + $args = "'$idom',this,$col,'".$GLOBALS['spip_lang_left']."','$info',event"; |
|
| 64 | 64 | |
| 65 | 65 | foreach ($ordre as $id => $titrebrut) { |
| 66 | 66 | $titre = supprimer_numero($titrebrut); |
| 67 | 67 | |
| 68 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | + $classe1 = 'petit-item '.($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | 69 | if (isset($rub[$id]['enfants'])) { |
| 70 | 70 | $classe2 = " class='rub-ouverte'"; |
| 71 | 71 | $url = "\nhref='$rec&id=$id'"; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $url = "\nhref='javascript:void(0)'"; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $js_func = $do . '_selection_titre'; |
|
| 77 | + $js_func = $do.'_selection_titre'; |
|
| 78 | 78 | $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
| 79 | 79 | . (!is_array($list) ? ' false' |
| 80 | 80 | : "aff_selection_provisoire($id,$args)") |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | + $idom2 = $idom.'_col_'.($col + 1); |
|
| 105 | 105 | $left = ($col * 250); |
| 106 | 106 | |
| 107 | 107 | return http_img_pack( |
| 108 | 108 | 'loader.svg', |
| 109 | 109 | '', |
| 110 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | + "class='loader' style='visibility: hidden; position: absolute; ".$GLOBALS['spip_lang_left'].': ' |
|
| 111 | 111 | . ($left - 30) |
| 112 | 112 | . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
| 113 | 113 | ) |
| 114 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; ".$GLOBALS['spip_lang_left'].': ' |
|
| 115 | 115 | . ($left - 250) |
| 116 | 116 | . "px;'>" |
| 117 | 117 | . $ret |
@@ -11,112 +11,112 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/texte'); |
| 18 | 18 | |
| 19 | 19 | function inc_plonger_dist($id_rubrique, $idom = '', $list = [], $col = 1, $exclu = 0, $do = 'aff') { |
| 20 | 20 | |
| 21 | - if ($list) { |
|
| 22 | - $id_rubrique = $list[$col - 1]; |
|
| 23 | - } |
|
| 21 | + if ($list) { |
|
| 22 | + $id_rubrique = $list[$col - 1]; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - $ret = ''; |
|
| 25 | + $ret = ''; |
|
| 26 | 26 | |
| 27 | - # recherche les filles et petites-filles de la rubrique donnee |
|
| 28 | - # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 29 | - # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 30 | - # racine... sauf vers elle-meme ou sa propre branche) |
|
| 31 | - $ordre = []; |
|
| 32 | - $rub = []; |
|
| 27 | + # recherche les filles et petites-filles de la rubrique donnee |
|
| 28 | + # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 29 | + # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 30 | + # racine... sauf vers elle-meme ou sa propre branche) |
|
| 31 | + $ordre = []; |
|
| 32 | + $rub = []; |
|
| 33 | 33 | |
| 34 | - $res = sql_select( |
|
| 35 | - 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 36 | - 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 37 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 34 | + $res = sql_select( |
|
| 35 | + 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 36 | + 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 37 | + 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 38 | 38 | AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
| 39 | 39 | AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
| 40 | - '', |
|
| 41 | - '0+rub1.titre,rub1.titre' |
|
| 42 | - ); |
|
| 40 | + '', |
|
| 41 | + '0+rub1.titre,rub1.titre' |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - while ($row = sql_fetch($res)) { |
|
| 45 | - if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 46 | - $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 47 | - if ($row['id_parent'] == $id_rubrique) { |
|
| 48 | - $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 49 | - if ($row['langue_choisie'] != 'oui') { |
|
| 50 | - $t .= ' <small title="' |
|
| 51 | - . traduire_nom_langue($row['lang']) |
|
| 52 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | - } |
|
| 54 | - $ordre[$row['id_rubrique']] = $t; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - $next = $list[$col] ?? 0; |
|
| 59 | - if ($ordre) { |
|
| 60 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 62 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 44 | + while ($row = sql_fetch($res)) { |
|
| 45 | + if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 46 | + $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 47 | + if ($row['id_parent'] == $id_rubrique) { |
|
| 48 | + $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 49 | + if ($row['langue_choisie'] != 'oui') { |
|
| 50 | + $t .= ' <small title="' |
|
| 51 | + . traduire_nom_langue($row['lang']) |
|
| 52 | + . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | + } |
|
| 54 | + $ordre[$row['id_rubrique']] = $t; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + $next = $list[$col] ?? 0; |
|
| 59 | + if ($ordre) { |
|
| 60 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 62 | + $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 63 | 63 | |
| 64 | - foreach ($ordre as $id => $titrebrut) { |
|
| 65 | - $titre = supprimer_numero($titrebrut); |
|
| 64 | + foreach ($ordre as $id => $titrebrut) { |
|
| 65 | + $titre = supprimer_numero($titrebrut); |
|
| 66 | 66 | |
| 67 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | - if (isset($rub[$id]['enfants'])) { |
|
| 69 | - $classe2 = " class='rub-ouverte'"; |
|
| 70 | - $url = "\nhref='$rec&id=$id'"; |
|
| 71 | - } else { |
|
| 72 | - $classe2 = $url = ''; |
|
| 73 | - $url = "\nhref='javascript:void(0)'"; |
|
| 74 | - } |
|
| 67 | + $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | + if (isset($rub[$id]['enfants'])) { |
|
| 69 | + $classe2 = " class='rub-ouverte'"; |
|
| 70 | + $url = "\nhref='$rec&id=$id'"; |
|
| 71 | + } else { |
|
| 72 | + $classe2 = $url = ''; |
|
| 73 | + $url = "\nhref='javascript:void(0)'"; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $js_func = $do . '_selection_titre'; |
|
| 77 | - $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 78 | - . (!is_array($list) ? ' false' |
|
| 79 | - : "aff_selection_provisoire($id,$args)") |
|
| 76 | + $js_func = $do . '_selection_titre'; |
|
| 77 | + $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 78 | + . (!is_array($list) ? ' false' |
|
| 79 | + : "aff_selection_provisoire($id,$args)") |
|
| 80 | 80 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 81 | 81 | # et l'affichage de son titre dans le bandeau |
| 82 | - . "\"\nondblclick=\"" |
|
| 83 | - . "$js_func(this." |
|
| 84 | - . 'firstChild.nodeValue,' |
|
| 85 | - . $id |
|
| 86 | - . ",'selection_rubrique','id_parent');" |
|
| 87 | - . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 88 | - . '"'; |
|
| 82 | + . "\"\nondblclick=\"" |
|
| 83 | + . "$js_func(this." |
|
| 84 | + . 'firstChild.nodeValue,' |
|
| 85 | + . $id |
|
| 86 | + . ",'selection_rubrique','id_parent');" |
|
| 87 | + . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 88 | + . '"'; |
|
| 89 | 89 | |
| 90 | - $ret .= "<div class='" |
|
| 91 | - . (($id == $next) ? 'item on' : 'item') |
|
| 92 | - . "'><div class='" |
|
| 93 | - . $classe1 |
|
| 94 | - . "'><div$classe2><a" |
|
| 95 | - . $url |
|
| 96 | - . $click |
|
| 97 | - . '>' |
|
| 98 | - . $titre |
|
| 99 | - . '</a></div></div></div>'; |
|
| 100 | - } |
|
| 101 | - } |
|
| 90 | + $ret .= "<div class='" |
|
| 91 | + . (($id == $next) ? 'item on' : 'item') |
|
| 92 | + . "'><div class='" |
|
| 93 | + . $classe1 |
|
| 94 | + . "'><div$classe2><a" |
|
| 95 | + . $url |
|
| 96 | + . $click |
|
| 97 | + . '>' |
|
| 98 | + . $titre |
|
| 99 | + . '</a></div></div></div>'; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | - $left = ($col * 250); |
|
| 103 | + $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | + $left = ($col * 250); |
|
| 105 | 105 | |
| 106 | - return http_img_pack( |
|
| 107 | - 'loader.svg', |
|
| 108 | - '', |
|
| 109 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | - . ($left - 30) |
|
| 111 | - . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 112 | - ) |
|
| 113 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | - . ($left - 250) |
|
| 115 | - . "px;'>" |
|
| 116 | - . $ret |
|
| 117 | - . "\n</div>\n<div id='$idom2'>" |
|
| 118 | - . ($next |
|
| 119 | - ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 120 | - : '') |
|
| 121 | - . "\n</div>"; |
|
| 106 | + return http_img_pack( |
|
| 107 | + 'loader.svg', |
|
| 108 | + '', |
|
| 109 | + "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | + . ($left - 30) |
|
| 111 | + . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 112 | + ) |
|
| 113 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | + . ($left - 250) |
|
| 115 | + . "px;'>" |
|
| 116 | + . $ret |
|
| 117 | + . "\n</div>\n<div id='$idom2'>" |
|
| 118 | + . ($next |
|
| 119 | + ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 120 | + : '') |
|
| 121 | + . "\n</div>"; |
|
| 122 | 122 | } |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | foreach (['script', 'iframe'] as $tag) { |
| 106 | 106 | if ( |
| 107 | 107 | stripos($t, (string) "<$tag") !== false |
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | 109 | ) { |
| 110 | 110 | foreach ($r as $regs) { |
| 111 | 111 | $t = str_replace( |
| 112 | 112 | $regs[0], |
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 113 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 114 | 114 | $t |
| 115 | 115 | ); |
| 116 | 116 | } |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // echapper les tags asp/php |
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 166 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le php |
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 169 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 170 | 170 | |
| 171 | 171 | // echapper le < script language=php > |
| 172 | 172 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | // Reinserer les echappements des modeles |
| 190 | 190 | if (defined('_PROTEGE_JS_MODELES')) { |
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 191 | + $t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 194 | + $t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 290 | 290 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 291 | 291 | |
| 292 | -define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS'); |
|
| 292 | +define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS'); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Corrige la typographie |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return ['', '']; |
|
| 37 | + return ['', '']; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter Ă part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter Ă part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,40 +415,40 @@ discard block |
||
| 415 | 415 | * texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - $env['espace_prive'] = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$t) { |
|
| 432 | - return strval($t); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | - // avant echappement des balises <html> |
|
| 437 | - // https://core.spip.net/issues/3371 |
|
| 438 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | - // https://core.spip.net/issues/4166 |
|
| 440 | - if ( |
|
| 441 | - $interdire_script |
|
| 442 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | - or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | - ) { |
|
| 446 | - $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | - } |
|
| 448 | - $t = echappe_html($t); |
|
| 449 | - $t = expanser_liens($t, $connect, $env); |
|
| 450 | - $t = traiter_raccourcis($t); |
|
| 451 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | - |
|
| 453 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + $env['espace_prive'] = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$t) { |
|
| 432 | + return strval($t); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | + // avant echappement des balises <html> |
|
| 437 | + // https://core.spip.net/issues/3371 |
|
| 438 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | + // https://core.spip.net/issues/4166 |
|
| 440 | + if ( |
|
| 441 | + $interdire_script |
|
| 442 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | + or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | + ) { |
|
| 446 | + $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | + } |
|
| 448 | + $t = echappe_html($t); |
|
| 449 | + $t = expanser_liens($t, $connect, $env); |
|
| 450 | + $t = traiter_raccourcis($t); |
|
| 451 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | + |
|
| 453 | + return $t; |
|
| 454 | 454 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | $_texte = ($_texte ?: "''"); |
| 52 | 52 | $_titre = ($_titre ? ", $_titre" : ', null'); |
| 53 | 53 | $_class = ($_class ? ", $_class" : ', null'); |
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | 57 | $f = chercher_filtre('message_alerte'); |
| 58 | 58 | $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | $_class = interprete_argument_balise(2, $p); |
| 91 | 91 | $_role = interprete_argument_balise(3, $p); |
| 92 | 92 | $_id = interprete_argument_balise(4, $p); |
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | 94 | $_class = ($_class ? ", $_class" : ', null'); |
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | 98 | $f = chercher_filtre('message_alerte_ouvrir'); |
| 99 | 99 | $p->code = "$f($_titre$_class$_role$_id)"; |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
| 164 | 164 | $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
| 165 | 165 | $message = |
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id). |
|
| 167 | + $texte. |
|
| 168 | 168 | $message_alerte_fermer(); |
| 169 | 169 | |
| 170 | 170 | return $message; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | ]; |
| 214 | 214 | $type = array_intersect(explode(' ', $class), $types); |
| 215 | 215 | $type = reset($type); |
| 216 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 216 | + $class = trim(str_replace($types, '', $class)." $type"); |
|
| 217 | 217 | |
| 218 | 218 | // Classes |
| 219 | 219 | $class_racine = 'msg-alert'; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | // Attributs |
| 240 | 240 | $attr_role = ($role ? "role=\"$role\"" : ''); |
| 241 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 241 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | 242 | $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
| 243 | 243 | |
| 244 | 244 | $message = |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ?: "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ?: "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,56 +198,56 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $titre = trim($titre ?? ''); |
|
| 205 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 206 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $titre = trim($titre ?? ''); |
|
| 205 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 206 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 207 | 207 | |
| 208 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 209 | - $types = [ |
|
| 210 | - 'notice', |
|
| 211 | - 'error', |
|
| 212 | - 'success', |
|
| 213 | - 'info', |
|
| 214 | - ]; |
|
| 215 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 216 | - $type = reset($type); |
|
| 217 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 208 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 209 | + $types = [ |
|
| 210 | + 'notice', |
|
| 211 | + 'error', |
|
| 212 | + 'success', |
|
| 213 | + 'info', |
|
| 214 | + ]; |
|
| 215 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 216 | + $type = reset($type); |
|
| 217 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 218 | 218 | |
| 219 | - // Classes |
|
| 220 | - $class_racine = 'msg-alert'; |
|
| 221 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 222 | - $class_alerte = "$class_racine $class"; |
|
| 223 | - $class_texte = "{$class_racine}__text $clearfix"; |
|
| 224 | - $class_titre = "{$class_racine}__heading"; |
|
| 219 | + // Classes |
|
| 220 | + $class_racine = 'msg-alert'; |
|
| 221 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 222 | + $class_alerte = "$class_racine $class"; |
|
| 223 | + $class_texte = "{$class_racine}__text $clearfix"; |
|
| 224 | + $class_titre = "{$class_racine}__heading"; |
|
| 225 | 225 | |
| 226 | - // Titre : markup |
|
| 227 | - $titre = trim($titre); |
|
| 228 | - if (strlen($titre)) { |
|
| 229 | - include_spip('inc/filtres'); |
|
| 230 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 231 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 232 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 233 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 234 | - $titre = wrap($titre, $wrap_tag); |
|
| 235 | - } |
|
| 236 | - // puis on ajoute la classe |
|
| 237 | - $titre = ajouter_class($titre, $class_titre); |
|
| 238 | - } |
|
| 226 | + // Titre : markup |
|
| 227 | + $titre = trim($titre); |
|
| 228 | + if (strlen($titre)) { |
|
| 229 | + include_spip('inc/filtres'); |
|
| 230 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 231 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 232 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 233 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 234 | + $titre = wrap($titre, $wrap_tag); |
|
| 235 | + } |
|
| 236 | + // puis on ajoute la classe |
|
| 237 | + $titre = ajouter_class($titre, $class_titre); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Attributs |
|
| 241 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 242 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 243 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 240 | + // Attributs |
|
| 241 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 242 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 243 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 244 | 244 | |
| 245 | - $message = |
|
| 246 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 247 | - . $titre |
|
| 248 | - . "<div class=\"$class_texte\">"; |
|
| 245 | + $message = |
|
| 246 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 247 | + . $titre |
|
| 248 | + . "<div class=\"$class_texte\">"; |
|
| 249 | 249 | |
| 250 | - return $message; |
|
| 250 | + return $message; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -261,5 +261,5 @@ discard block |
||
| 261 | 261 | * HTML de fin de l'alerte |
| 262 | 262 | */ |
| 263 | 263 | function message_alerte_fermer(): string { |
| 264 | - return '</div></div>'; |
|
| 264 | + return '</div></div>'; |
|
| 265 | 265 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | ) { |
| 39 | 39 | // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
| 40 | 40 | include_spip('inc/autoriser'); |
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 41 | + if (!autoriser('configurer', '_'.substr($form, 11))) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
| 73 | 73 | ) { |
| 74 | 74 | $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return $flux; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $prefixe = $valeurs['_meta_prefixe']; |
| 147 | 147 | } |
| 148 | 148 | if (isset($valeurs['_meta_stockage'])) { |
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | + $stockage = $valeurs['_meta_stockage'].'::'; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // si on indique juste une table, il faut vider les autres proprietes |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // sinon cas analyse du squelette |
| 173 | 173 | if ( |
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 174 | + $f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | 175 | and lire_fichier($f, $contenu) |
| 176 | 176 | ) { |
| 177 | 177 | for ($i = 0; $i < 2; $i++) { |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | lire_metas($table); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 231 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 232 | 232 | $table = ($table) ? "/$table/" : ''; |
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/').'/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | 235 | foreach ($store as $k => $v) { |
| 236 | 236 | ecrire_config("$stockage$table$prefixe$casier$k", $v); |
| 237 | 237 | if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 238 | + $trace .= "<br />table $table : ".$prefixe.$k." = $v;"; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
| 253 | 253 | |
| 254 | 254 | $table = ($table) ? "/$table/" : ''; |
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 255 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 256 | 256 | if ($casier) { |
| 257 | 257 | $meta = lire_config("$stockage$table$prefixe$casier"); |
| 258 | 258 | $prefixe = ''; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | foreach ($valeurs as $k => $v) { |
| 265 | 265 | if (substr($k, 0, 1) !== '_') { |
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe.$k] ?? null); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | include_spip('inc/config'); |
@@ -32,31 +32,31 @@ discard block |
||
| 32 | 32 | * @return array|false |
| 33 | 33 | */ |
| 34 | 34 | function cvtconf_formulaire_charger($flux) { |
| 35 | - if ( |
|
| 36 | - $form = $flux['args']['form'] |
|
| 37 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | - ) { |
|
| 39 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | - include_spip('inc/autoriser'); |
|
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 35 | + if ( |
|
| 36 | + $form = $flux['args']['form'] |
|
| 37 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | + ) { |
|
| 39 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | + include_spip('inc/autoriser'); |
|
| 41 | + if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | - $flux['data']['editable'] = true; |
|
| 49 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | - if (!_AJAX) { |
|
| 51 | - var_dump($flux['data']); |
|
| 52 | - } |
|
| 53 | - // reinjecter pour la trace au traitement |
|
| 54 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 45 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | + $flux['data']['editable'] = true; |
|
| 49 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | + if (!_AJAX) { |
|
| 51 | + var_dump($flux['data']); |
|
| 52 | + } |
|
| 53 | + // reinjecter pour la trace au traitement |
|
| 54 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $flux; |
|
| 59 | + return $flux; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | 68 | function cvtconf_formulaire_traiter($flux) { |
| 69 | - if ( |
|
| 70 | - $form = $flux['args']['form'] |
|
| 71 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | - and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | - ) { |
|
| 74 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | - } |
|
| 69 | + if ( |
|
| 70 | + $form = $flux['args']['form'] |
|
| 71 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | + and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | + ) { |
|
| 74 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - return $flux; |
|
| 78 | + return $flux; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | 93 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 94 | - $valeurs = []; |
|
| 95 | - // charger les valeurs |
|
| 96 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | - // qui prend alors la main sur l'auto detection |
|
| 98 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | - $valeurs = $charger_valeurs(...$args); |
|
| 100 | - } |
|
| 101 | - $valeurs = pipeline( |
|
| 102 | - 'formulaire_charger', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | - 'data' => $valeurs |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - // ne pas stocker editable ! |
|
| 109 | - unset($valeurs['editable']); |
|
| 94 | + $valeurs = []; |
|
| 95 | + // charger les valeurs |
|
| 96 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | + // qui prend alors la main sur l'auto detection |
|
| 98 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | + $valeurs = $charger_valeurs(...$args); |
|
| 100 | + } |
|
| 101 | + $valeurs = pipeline( |
|
| 102 | + 'formulaire_charger', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | + 'data' => $valeurs |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + // ne pas stocker editable ! |
|
| 109 | + unset($valeurs['editable']); |
|
| 110 | 110 | |
| 111 | - // recuperer les valeurs postees |
|
| 112 | - $store = []; |
|
| 113 | - foreach ($valeurs as $k => $v) { |
|
| 114 | - if (substr($k, 0, 1) !== '_') { |
|
| 115 | - $store[$k] = _request($k); |
|
| 116 | - } |
|
| 117 | - } |
|
| 111 | + // recuperer les valeurs postees |
|
| 112 | + $store = []; |
|
| 113 | + foreach ($valeurs as $k => $v) { |
|
| 114 | + if (substr($k, 0, 1) !== '_') { |
|
| 115 | + $store[$k] = _request($k); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -132,31 +132,31 @@ discard block |
||
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | 134 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 135 | - // stocker en base |
|
| 136 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | - $casier = substr($form, 11); |
|
| 138 | - $table = 'meta'; |
|
| 139 | - $prefixe = ''; |
|
| 140 | - $stockage = ''; |
|
| 135 | + // stocker en base |
|
| 136 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | + $casier = substr($form, 11); |
|
| 138 | + $table = 'meta'; |
|
| 139 | + $prefixe = ''; |
|
| 140 | + $stockage = ''; |
|
| 141 | 141 | |
| 142 | - if (isset($valeurs['_meta_casier'])) { |
|
| 143 | - $casier = $valeurs['_meta_casier']; |
|
| 144 | - } |
|
| 145 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | - } |
|
| 148 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | - } |
|
| 142 | + if (isset($valeurs['_meta_casier'])) { |
|
| 143 | + $casier = $valeurs['_meta_casier']; |
|
| 144 | + } |
|
| 145 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | + } |
|
| 148 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | - if (isset($valeurs['_meta_table'])) { |
|
| 155 | - $table = $valeurs['_meta_table']; |
|
| 156 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | - } |
|
| 152 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | + if (isset($valeurs['_meta_table'])) { |
|
| 155 | + $table = $valeurs['_meta_table']; |
|
| 156 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -167,48 +167,48 @@ discard block |
||
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | 169 | function cvtconf_formulaires_configurer_recense($form) { |
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | - and lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | + and lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - $n = extraire_attribut($b, 'name') |
|
| 193 | - and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | - and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + $n = extraire_attribut($b, 'name') |
|
| 193 | + and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | + and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach ($valeurs as $k => $v) { |
|
| 265 | - if (substr($k, 0, 1) !== '_') { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach ($valeurs as $k => $v) { |
|
| 265 | + if (substr($k, 0, 1) !== '_') { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | $hsl = _couleur_hex_to_hsl($couleur); |
| 205 | 205 | $hsl = [ |
| 206 | 206 | 'h' => round($hsl['h'] * 360), |
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 207 | + 's' => round($hsl['s'] * 100).'%', |
|
| 208 | + 'l' => round($hsl['l'] * 100).'%' |
|
| 209 | 209 | ]; |
| 210 | 210 | if ($format === null) { |
| 211 | 211 | return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | $process = 'AUTO' |
| 385 | 385 | ) { |
| 386 | 386 | // PHP 7+ type hint |
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 387 | + $img = (string) $img; |
|
| 388 | + $taille_x = (int) $taille_x; |
|
| 389 | + $taille_y = (int) $taille_y; |
|
| 390 | + $force = (bool) $force; |
|
| 391 | + $process = (string) $process; |
|
| 392 | 392 | |
| 393 | 393 | if (!$img) { |
| 394 | 394 | return ''; |
@@ -465,11 +465,11 @@ discard block |
||
| 465 | 465 | $process = 'AUTO' |
| 466 | 466 | ) { |
| 467 | 467 | // PHP 7+ type hint |
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 468 | + $img = (string) $img; |
|
| 469 | + $taille = (int) $taille; |
|
| 470 | + $taille_y = (int) $taille_y; |
|
| 471 | + $force = (bool) $force; |
|
| 472 | + $process = (string) $process; |
|
| 473 | 473 | |
| 474 | 474 | // Determiner la taille x,y maxi |
| 475 | 475 | // prendre le reglage de previsu par defaut |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $background_color = 'white' |
| 513 | 513 | ) { |
| 514 | 514 | if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 515 | + return image_reduire(image_recadre($im, $width.':'.$height, '-', $position, $background_color), $width, $height); |
|
| 516 | 516 | } else { return image_passe_partout($im, $width, $height); |
| 517 | 517 | } |
| 518 | 518 | } |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | 535 | // PHP 7+ type hint |
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 536 | + $img = (string) $img; |
|
| 537 | + $val = (int) $val; |
|
| 538 | + $force = (bool) $force; |
|
| 539 | 539 | |
| 540 | 540 | [$hauteur, $largeur] = taille_image($img); |
| 541 | 541 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 24 | 24 | |
@@ -31,161 +31,161 @@ discard block |
||
| 31 | 31 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 32 | 32 | */ |
| 33 | 33 | function couleur_html_to_hex($couleur) { |
| 34 | - $couleurs_html = [ |
|
| 35 | - 'aliceblue' => 'F0F8FF', |
|
| 36 | - 'antiquewhite' => 'FAEBD7', |
|
| 37 | - 'aqua' => '00FFFF', |
|
| 38 | - 'aquamarine' => '7FFFD4', |
|
| 39 | - 'azure' => 'F0FFFF', |
|
| 40 | - 'beige' => 'F5F5DC', |
|
| 41 | - 'bisque' => 'FFE4C4', |
|
| 42 | - 'black' => '000000', |
|
| 43 | - 'blanchedalmond' => 'FFEBCD', |
|
| 44 | - 'blue' => '0000FF', |
|
| 45 | - 'blueviolet' => '8A2BE2', |
|
| 46 | - 'brown' => 'A52A2A', |
|
| 47 | - 'burlywood' => 'DEB887', |
|
| 48 | - 'cadetblue' => '5F9EA0', |
|
| 49 | - 'chartreuse' => '7FFF00', |
|
| 50 | - 'chocolate' => 'D2691E', |
|
| 51 | - 'coral' => 'FF7F50', |
|
| 52 | - 'cornflowerblue' => '6495ED', |
|
| 53 | - 'cornsilk' => 'FFF8DC', |
|
| 54 | - 'crimson' => 'DC143C', |
|
| 55 | - 'cyan' => '00FFFF', |
|
| 56 | - 'darkblue' => '00008B', |
|
| 57 | - 'darkcyan' => '008B8B', |
|
| 58 | - 'darkgoldenrod' => 'B8860B', |
|
| 59 | - 'darkgray' => 'A9A9A9', |
|
| 60 | - 'darkgreen' => '006400', |
|
| 61 | - 'darkgrey' => 'A9A9A9', |
|
| 62 | - 'darkkhaki' => 'BDB76B', |
|
| 63 | - 'darkmagenta' => '8B008B', |
|
| 64 | - 'darkolivegreen' => '556B2F', |
|
| 65 | - 'darkorange' => 'FF8C00', |
|
| 66 | - 'darkorchid' => '9932CC', |
|
| 67 | - 'darkred' => '8B0000', |
|
| 68 | - 'darksalmon' => 'E9967A', |
|
| 69 | - 'darkseagreen' => '8FBC8F', |
|
| 70 | - 'darkslateblue' => '483D8B', |
|
| 71 | - 'darkslategray' => '2F4F4F', |
|
| 72 | - 'darkslategrey' => '2F4F4F', |
|
| 73 | - 'darkturquoise' => '00CED1', |
|
| 74 | - 'darkviolet' => '9400D3', |
|
| 75 | - 'deeppink' => 'FF1493', |
|
| 76 | - 'deepskyblue' => '00BFFF', |
|
| 77 | - 'dimgray' => '696969', |
|
| 78 | - 'dimgrey' => '696969', |
|
| 79 | - 'dodgerblue' => '1E90FF', |
|
| 80 | - 'firebrick' => 'B22222', |
|
| 81 | - 'floralwhite' => 'FFFAF0', |
|
| 82 | - 'forestgreen' => '228B22', |
|
| 83 | - 'fuchsia' => 'FF00FF', |
|
| 84 | - 'gainsboro' => 'DCDCDC', |
|
| 85 | - 'ghostwhite' => 'F8F8FF', |
|
| 86 | - 'gold' => 'FFD700', |
|
| 87 | - 'goldenrod' => 'DAA520', |
|
| 88 | - 'gray' => '808080', |
|
| 89 | - 'green' => '008000', |
|
| 90 | - 'greenyellow' => 'ADFF2F', |
|
| 91 | - 'grey' => '808080', |
|
| 92 | - 'honeydew' => 'F0FFF0', |
|
| 93 | - 'hotpink' => 'FF69B4', |
|
| 94 | - 'indianred' => 'CD5C5C', |
|
| 95 | - 'indigo' => '4B0082', |
|
| 96 | - 'ivory' => 'FFFFF0', |
|
| 97 | - 'khaki' => 'F0E68C', |
|
| 98 | - 'lavender' => 'E6E6FA', |
|
| 99 | - 'lavenderblush' => 'FFF0F5', |
|
| 100 | - 'lawngreen' => '7CFC00', |
|
| 101 | - 'lemonchiffon' => 'FFFACD', |
|
| 102 | - 'lightblue' => 'ADD8E6', |
|
| 103 | - 'lightcoral' => 'F08080', |
|
| 104 | - 'lightcyan' => 'E0FFFF', |
|
| 105 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | - 'lightgray' => 'D3D3D3', |
|
| 107 | - 'lightgreen' => '90EE90', |
|
| 108 | - 'lightgrey' => 'D3D3D3', |
|
| 109 | - 'lightpink' => 'FFB6C1', |
|
| 110 | - 'lightsalmon' => 'FFA07A', |
|
| 111 | - 'lightseagreen' => '20B2AA', |
|
| 112 | - 'lightskyblue' => '87CEFA', |
|
| 113 | - 'lightslategray' => '778899', |
|
| 114 | - 'lightslategrey' => '778899', |
|
| 115 | - 'lightsteelblue' => 'B0C4DE', |
|
| 116 | - 'lightyellow' => 'FFFFE0', |
|
| 117 | - 'lime' => '00FF00', |
|
| 118 | - 'limegreen' => '32CD32', |
|
| 119 | - 'linen' => 'FAF0E6', |
|
| 120 | - 'magenta' => 'FF00FF', |
|
| 121 | - 'maroon' => '800000', |
|
| 122 | - 'mediumaquamarine' => '66CDAA', |
|
| 123 | - 'mediumblue' => '0000CD', |
|
| 124 | - 'mediumorchid' => 'BA55D3', |
|
| 125 | - 'mediumpurple' => '9370DB', |
|
| 126 | - 'mediumseagreen' => '3CB371', |
|
| 127 | - 'mediumslateblue' => '7B68EE', |
|
| 128 | - 'mediumspringgreen' => '00FA9A', |
|
| 129 | - 'mediumturquoise' => '48D1CC', |
|
| 130 | - 'mediumvioletred' => 'C71585', |
|
| 131 | - 'midnightblue' => '191970', |
|
| 132 | - 'mintcream' => 'F5FFFA', |
|
| 133 | - 'mistyrose' => 'FFE4E1', |
|
| 134 | - 'moccasin' => 'FFE4B5', |
|
| 135 | - 'navajowhite' => 'FFDEAD', |
|
| 136 | - 'navy' => '000080', |
|
| 137 | - 'oldlace' => 'FDF5E6', |
|
| 138 | - 'olive' => '808000', |
|
| 139 | - 'olivedrab' => '6B8E23', |
|
| 140 | - 'orange' => 'FFA500', |
|
| 141 | - 'orangered' => 'FF4500', |
|
| 142 | - 'orchid' => 'DA70D6', |
|
| 143 | - 'palegoldenrod' => 'EEE8AA', |
|
| 144 | - 'palegreen' => '98FB98', |
|
| 145 | - 'paleturquoise' => 'AFEEEE', |
|
| 146 | - 'palevioletred' => 'DB7093', |
|
| 147 | - 'papayawhip' => 'FFEFD5', |
|
| 148 | - 'peachpuff' => 'FFDAB9', |
|
| 149 | - 'peru' => 'CD853F', |
|
| 150 | - 'pink' => 'FFC0CB', |
|
| 151 | - 'plum' => 'DDA0DD', |
|
| 152 | - 'powderblue' => 'B0E0E6', |
|
| 153 | - 'purple' => '800080', |
|
| 154 | - 'rebeccapurple' => '663399', |
|
| 155 | - 'red' => 'FF0000', |
|
| 156 | - 'rosybrown' => 'BC8F8F', |
|
| 157 | - 'royalblue' => '4169E1', |
|
| 158 | - 'saddlebrown' => '8B4513', |
|
| 159 | - 'salmon' => 'FA8072', |
|
| 160 | - 'sandybrown' => 'F4A460', |
|
| 161 | - 'seagreen' => '2E8B57', |
|
| 162 | - 'seashell' => 'FFF5EE', |
|
| 163 | - 'sienna' => 'A0522D', |
|
| 164 | - 'silver' => 'C0C0C0', |
|
| 165 | - 'skyblue' => '87CEEB', |
|
| 166 | - 'slateblue' => '6A5ACD', |
|
| 167 | - 'slategray' => '708090', |
|
| 168 | - 'slategrey' => '708090', |
|
| 169 | - 'snow' => 'FFFAFA', |
|
| 170 | - 'springgreen' => '00FF7F', |
|
| 171 | - 'steelblue' => '4682B4', |
|
| 172 | - 'tan' => 'D2B48C', |
|
| 173 | - 'teal' => '008080', |
|
| 174 | - 'thistle' => 'D8BFD8', |
|
| 175 | - 'tomato' => 'FF6347', |
|
| 176 | - 'turquoise' => '40E0D0', |
|
| 177 | - 'violet' => 'EE82EE', |
|
| 178 | - 'wheat' => 'F5DEB3', |
|
| 179 | - 'white' => 'FFFFFF', |
|
| 180 | - 'whitesmoke' => 'F5F5F5', |
|
| 181 | - 'yellow' => 'FFFF00', |
|
| 182 | - 'yellowgreen' => '9ACD32', |
|
| 183 | - ]; |
|
| 184 | - if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 185 | - return $couleurs_html[$lc]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $couleur; |
|
| 34 | + $couleurs_html = [ |
|
| 35 | + 'aliceblue' => 'F0F8FF', |
|
| 36 | + 'antiquewhite' => 'FAEBD7', |
|
| 37 | + 'aqua' => '00FFFF', |
|
| 38 | + 'aquamarine' => '7FFFD4', |
|
| 39 | + 'azure' => 'F0FFFF', |
|
| 40 | + 'beige' => 'F5F5DC', |
|
| 41 | + 'bisque' => 'FFE4C4', |
|
| 42 | + 'black' => '000000', |
|
| 43 | + 'blanchedalmond' => 'FFEBCD', |
|
| 44 | + 'blue' => '0000FF', |
|
| 45 | + 'blueviolet' => '8A2BE2', |
|
| 46 | + 'brown' => 'A52A2A', |
|
| 47 | + 'burlywood' => 'DEB887', |
|
| 48 | + 'cadetblue' => '5F9EA0', |
|
| 49 | + 'chartreuse' => '7FFF00', |
|
| 50 | + 'chocolate' => 'D2691E', |
|
| 51 | + 'coral' => 'FF7F50', |
|
| 52 | + 'cornflowerblue' => '6495ED', |
|
| 53 | + 'cornsilk' => 'FFF8DC', |
|
| 54 | + 'crimson' => 'DC143C', |
|
| 55 | + 'cyan' => '00FFFF', |
|
| 56 | + 'darkblue' => '00008B', |
|
| 57 | + 'darkcyan' => '008B8B', |
|
| 58 | + 'darkgoldenrod' => 'B8860B', |
|
| 59 | + 'darkgray' => 'A9A9A9', |
|
| 60 | + 'darkgreen' => '006400', |
|
| 61 | + 'darkgrey' => 'A9A9A9', |
|
| 62 | + 'darkkhaki' => 'BDB76B', |
|
| 63 | + 'darkmagenta' => '8B008B', |
|
| 64 | + 'darkolivegreen' => '556B2F', |
|
| 65 | + 'darkorange' => 'FF8C00', |
|
| 66 | + 'darkorchid' => '9932CC', |
|
| 67 | + 'darkred' => '8B0000', |
|
| 68 | + 'darksalmon' => 'E9967A', |
|
| 69 | + 'darkseagreen' => '8FBC8F', |
|
| 70 | + 'darkslateblue' => '483D8B', |
|
| 71 | + 'darkslategray' => '2F4F4F', |
|
| 72 | + 'darkslategrey' => '2F4F4F', |
|
| 73 | + 'darkturquoise' => '00CED1', |
|
| 74 | + 'darkviolet' => '9400D3', |
|
| 75 | + 'deeppink' => 'FF1493', |
|
| 76 | + 'deepskyblue' => '00BFFF', |
|
| 77 | + 'dimgray' => '696969', |
|
| 78 | + 'dimgrey' => '696969', |
|
| 79 | + 'dodgerblue' => '1E90FF', |
|
| 80 | + 'firebrick' => 'B22222', |
|
| 81 | + 'floralwhite' => 'FFFAF0', |
|
| 82 | + 'forestgreen' => '228B22', |
|
| 83 | + 'fuchsia' => 'FF00FF', |
|
| 84 | + 'gainsboro' => 'DCDCDC', |
|
| 85 | + 'ghostwhite' => 'F8F8FF', |
|
| 86 | + 'gold' => 'FFD700', |
|
| 87 | + 'goldenrod' => 'DAA520', |
|
| 88 | + 'gray' => '808080', |
|
| 89 | + 'green' => '008000', |
|
| 90 | + 'greenyellow' => 'ADFF2F', |
|
| 91 | + 'grey' => '808080', |
|
| 92 | + 'honeydew' => 'F0FFF0', |
|
| 93 | + 'hotpink' => 'FF69B4', |
|
| 94 | + 'indianred' => 'CD5C5C', |
|
| 95 | + 'indigo' => '4B0082', |
|
| 96 | + 'ivory' => 'FFFFF0', |
|
| 97 | + 'khaki' => 'F0E68C', |
|
| 98 | + 'lavender' => 'E6E6FA', |
|
| 99 | + 'lavenderblush' => 'FFF0F5', |
|
| 100 | + 'lawngreen' => '7CFC00', |
|
| 101 | + 'lemonchiffon' => 'FFFACD', |
|
| 102 | + 'lightblue' => 'ADD8E6', |
|
| 103 | + 'lightcoral' => 'F08080', |
|
| 104 | + 'lightcyan' => 'E0FFFF', |
|
| 105 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | + 'lightgray' => 'D3D3D3', |
|
| 107 | + 'lightgreen' => '90EE90', |
|
| 108 | + 'lightgrey' => 'D3D3D3', |
|
| 109 | + 'lightpink' => 'FFB6C1', |
|
| 110 | + 'lightsalmon' => 'FFA07A', |
|
| 111 | + 'lightseagreen' => '20B2AA', |
|
| 112 | + 'lightskyblue' => '87CEFA', |
|
| 113 | + 'lightslategray' => '778899', |
|
| 114 | + 'lightslategrey' => '778899', |
|
| 115 | + 'lightsteelblue' => 'B0C4DE', |
|
| 116 | + 'lightyellow' => 'FFFFE0', |
|
| 117 | + 'lime' => '00FF00', |
|
| 118 | + 'limegreen' => '32CD32', |
|
| 119 | + 'linen' => 'FAF0E6', |
|
| 120 | + 'magenta' => 'FF00FF', |
|
| 121 | + 'maroon' => '800000', |
|
| 122 | + 'mediumaquamarine' => '66CDAA', |
|
| 123 | + 'mediumblue' => '0000CD', |
|
| 124 | + 'mediumorchid' => 'BA55D3', |
|
| 125 | + 'mediumpurple' => '9370DB', |
|
| 126 | + 'mediumseagreen' => '3CB371', |
|
| 127 | + 'mediumslateblue' => '7B68EE', |
|
| 128 | + 'mediumspringgreen' => '00FA9A', |
|
| 129 | + 'mediumturquoise' => '48D1CC', |
|
| 130 | + 'mediumvioletred' => 'C71585', |
|
| 131 | + 'midnightblue' => '191970', |
|
| 132 | + 'mintcream' => 'F5FFFA', |
|
| 133 | + 'mistyrose' => 'FFE4E1', |
|
| 134 | + 'moccasin' => 'FFE4B5', |
|
| 135 | + 'navajowhite' => 'FFDEAD', |
|
| 136 | + 'navy' => '000080', |
|
| 137 | + 'oldlace' => 'FDF5E6', |
|
| 138 | + 'olive' => '808000', |
|
| 139 | + 'olivedrab' => '6B8E23', |
|
| 140 | + 'orange' => 'FFA500', |
|
| 141 | + 'orangered' => 'FF4500', |
|
| 142 | + 'orchid' => 'DA70D6', |
|
| 143 | + 'palegoldenrod' => 'EEE8AA', |
|
| 144 | + 'palegreen' => '98FB98', |
|
| 145 | + 'paleturquoise' => 'AFEEEE', |
|
| 146 | + 'palevioletred' => 'DB7093', |
|
| 147 | + 'papayawhip' => 'FFEFD5', |
|
| 148 | + 'peachpuff' => 'FFDAB9', |
|
| 149 | + 'peru' => 'CD853F', |
|
| 150 | + 'pink' => 'FFC0CB', |
|
| 151 | + 'plum' => 'DDA0DD', |
|
| 152 | + 'powderblue' => 'B0E0E6', |
|
| 153 | + 'purple' => '800080', |
|
| 154 | + 'rebeccapurple' => '663399', |
|
| 155 | + 'red' => 'FF0000', |
|
| 156 | + 'rosybrown' => 'BC8F8F', |
|
| 157 | + 'royalblue' => '4169E1', |
|
| 158 | + 'saddlebrown' => '8B4513', |
|
| 159 | + 'salmon' => 'FA8072', |
|
| 160 | + 'sandybrown' => 'F4A460', |
|
| 161 | + 'seagreen' => '2E8B57', |
|
| 162 | + 'seashell' => 'FFF5EE', |
|
| 163 | + 'sienna' => 'A0522D', |
|
| 164 | + 'silver' => 'C0C0C0', |
|
| 165 | + 'skyblue' => '87CEEB', |
|
| 166 | + 'slateblue' => '6A5ACD', |
|
| 167 | + 'slategray' => '708090', |
|
| 168 | + 'slategrey' => '708090', |
|
| 169 | + 'snow' => 'FFFAFA', |
|
| 170 | + 'springgreen' => '00FF7F', |
|
| 171 | + 'steelblue' => '4682B4', |
|
| 172 | + 'tan' => 'D2B48C', |
|
| 173 | + 'teal' => '008080', |
|
| 174 | + 'thistle' => 'D8BFD8', |
|
| 175 | + 'tomato' => 'FF6347', |
|
| 176 | + 'turquoise' => '40E0D0', |
|
| 177 | + 'violet' => 'EE82EE', |
|
| 178 | + 'wheat' => 'F5DEB3', |
|
| 179 | + 'white' => 'FFFFFF', |
|
| 180 | + 'whitesmoke' => 'F5F5F5', |
|
| 181 | + 'yellow' => 'FFFF00', |
|
| 182 | + 'yellowgreen' => '9ACD32', |
|
| 183 | + ]; |
|
| 184 | + if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 185 | + return $couleurs_html[$lc]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $couleur; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -201,16 +201,16 @@ discard block |
||
| 201 | 201 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 202 | 202 | */ |
| 203 | 203 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 204 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | - $hsl = [ |
|
| 206 | - 'h' => round($hsl['h'] * 360), |
|
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | - ]; |
|
| 210 | - if ($format === null) { |
|
| 211 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | - } |
|
| 213 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 204 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | + $hsl = [ |
|
| 206 | + 'h' => round($hsl['h'] * 360), |
|
| 207 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | + ]; |
|
| 210 | + if ($format === null) { |
|
| 211 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | + } |
|
| 213 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 228 | 228 | */ |
| 229 | 229 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 230 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | - $rgb = [ |
|
| 232 | - 'r' => $rgb['red'], |
|
| 233 | - 'g' => $rgb['green'], |
|
| 234 | - 'b' => $rgb['blue'], |
|
| 235 | - ]; |
|
| 236 | - if ($format === null) { |
|
| 237 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | - } |
|
| 239 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 230 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | + $rgb = [ |
|
| 232 | + 'r' => $rgb['red'], |
|
| 233 | + 'g' => $rgb['green'], |
|
| 234 | + 'b' => $rgb['blue'], |
|
| 235 | + ]; |
|
| 236 | + if ($format === null) { |
|
| 237 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | + } |
|
| 239 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | * Code hexadécimal de la couleur plus foncée |
| 253 | 253 | */ |
| 254 | 254 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 255 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 256 | 256 | |
| 257 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 257 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 260 | 260 | |
| 261 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 262 | 262 | |
| 263 | - return $couleur; |
|
| 263 | + return $couleur; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | * Code hexadécimal de la couleur éclaircie |
| 277 | 277 | */ |
| 278 | 278 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 279 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 279 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 280 | 280 | |
| 281 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 284 | 284 | |
| 285 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 285 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 286 | 286 | |
| 287 | - return $couleur; |
|
| 287 | + return $couleur; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -307,28 +307,28 @@ discard block |
||
| 307 | 307 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 308 | 308 | */ |
| 309 | 309 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 310 | - if (!$img) { |
|
| 311 | - return $img; |
|
| 312 | - } |
|
| 313 | - [$h, $l] = taille_image($img); |
|
| 314 | - $select = true; |
|
| 315 | - if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | - $select = false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $class = extraire_attribut($img, 'class'); |
|
| 320 | - $p = strpos($class, 'filtre_inactif'); |
|
| 321 | - if (($select == false) and ($p === false)) { |
|
| 322 | - $class .= ' filtre_inactif'; |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - if (($select == true) and ($p !== false)) { |
|
| 326 | - // no_image_filtrer : historique, a virer |
|
| 327 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | - $img = inserer_attribut($img, 'class', $class); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - return $img; |
|
| 310 | + if (!$img) { |
|
| 311 | + return $img; |
|
| 312 | + } |
|
| 313 | + [$h, $l] = taille_image($img); |
|
| 314 | + $select = true; |
|
| 315 | + if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | + $select = false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $class = extraire_attribut($img, 'class'); |
|
| 320 | + $p = strpos($class, 'filtre_inactif'); |
|
| 321 | + if (($select == false) and ($p === false)) { |
|
| 322 | + $class .= ' filtre_inactif'; |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + if (($select == true) and ($p !== false)) { |
|
| 326 | + // no_image_filtrer : historique, a virer |
|
| 327 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | + $img = inserer_attribut($img, 'class', $class); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + return $img; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -376,45 +376,45 @@ discard block |
||
| 376 | 376 | * Code HTML de l'image ou du texte. |
| 377 | 377 | **/ |
| 378 | 378 | function image_passe_partout( |
| 379 | - $img, |
|
| 380 | - $taille_x = -1, |
|
| 381 | - $taille_y = -1, |
|
| 382 | - $force = false, |
|
| 383 | - $cherche_image = false, |
|
| 384 | - $process = 'AUTO' |
|
| 379 | + $img, |
|
| 380 | + $taille_x = -1, |
|
| 381 | + $taille_y = -1, |
|
| 382 | + $force = false, |
|
| 383 | + $cherche_image = false, |
|
| 384 | + $process = 'AUTO' |
|
| 385 | 385 | ) { |
| 386 | - // PHP 7+ type hint |
|
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 392 | - |
|
| 393 | - if (!$img) { |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - [$hauteur, $largeur] = taille_image($img); |
|
| 397 | - if ($taille_x === -1) { |
|
| 398 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | - } |
|
| 400 | - if ($taille_y === -1) { |
|
| 401 | - $taille_y = $taille_x; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | - $taille_x = 1; |
|
| 406 | - } # {0,300} -> c'est 300 qui compte |
|
| 407 | - elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | - $taille_y = 1; |
|
| 409 | - } # {300,0} -> c'est 300 qui compte |
|
| 410 | - elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | - return ''; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | - |
|
| 417 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 386 | + // PHP 7+ type hint |
|
| 387 | + $img = (string)$img; |
|
| 388 | + $taille_x = (int)$taille_x; |
|
| 389 | + $taille_y = (int)$taille_y; |
|
| 390 | + $force = (bool)$force; |
|
| 391 | + $process = (string)$process; |
|
| 392 | + |
|
| 393 | + if (!$img) { |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + [$hauteur, $largeur] = taille_image($img); |
|
| 397 | + if ($taille_x === -1) { |
|
| 398 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | + } |
|
| 400 | + if ($taille_y === -1) { |
|
| 401 | + $taille_y = $taille_x; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | + $taille_x = 1; |
|
| 406 | + } # {0,300} -> c'est 300 qui compte |
|
| 407 | + elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | + $taille_y = 1; |
|
| 409 | + } # {300,0} -> c'est 300 qui compte |
|
| 410 | + elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | + return ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | + |
|
| 417 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -457,44 +457,44 @@ discard block |
||
| 457 | 457 | * Code HTML de l'image ou du texte. |
| 458 | 458 | **/ |
| 459 | 459 | function image_reduire( |
| 460 | - $img, |
|
| 461 | - $taille = -1, |
|
| 462 | - $taille_y = -1, |
|
| 463 | - $force = false, |
|
| 464 | - $cherche_image = false, |
|
| 465 | - $process = 'AUTO' |
|
| 460 | + $img, |
|
| 461 | + $taille = -1, |
|
| 462 | + $taille_y = -1, |
|
| 463 | + $force = false, |
|
| 464 | + $cherche_image = false, |
|
| 465 | + $process = 'AUTO' |
|
| 466 | 466 | ) { |
| 467 | - // PHP 7+ type hint |
|
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 473 | - |
|
| 474 | - // Determiner la taille x,y maxi |
|
| 475 | - // prendre le reglage de previsu par defaut |
|
| 476 | - if ($taille === -1) { |
|
| 477 | - $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | - ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | - : 150; |
|
| 480 | - } |
|
| 481 | - if ($taille_y === -1) { |
|
| 482 | - $taille_y = $taille; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if ($taille === 0 and $taille_y > 0) { |
|
| 486 | - $taille = 10000; |
|
| 487 | - } # {0,300} -> c'est 300 qui compte |
|
| 488 | - elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | - $taille_y = 10000; |
|
| 490 | - } # {300,0} -> c'est 300 qui compte |
|
| 491 | - elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | - |
|
| 497 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 467 | + // PHP 7+ type hint |
|
| 468 | + $img = (string)$img; |
|
| 469 | + $taille = (int)$taille; |
|
| 470 | + $taille_y = (int)$taille_y; |
|
| 471 | + $force = (bool)$force; |
|
| 472 | + $process = (string)$process; |
|
| 473 | + |
|
| 474 | + // Determiner la taille x,y maxi |
|
| 475 | + // prendre le reglage de previsu par defaut |
|
| 476 | + if ($taille === -1) { |
|
| 477 | + $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | + ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | + : 150; |
|
| 480 | + } |
|
| 481 | + if ($taille_y === -1) { |
|
| 482 | + $taille_y = $taille; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if ($taille === 0 and $taille_y > 0) { |
|
| 486 | + $taille = 10000; |
|
| 487 | + } # {0,300} -> c'est 300 qui compte |
|
| 488 | + elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | + $taille_y = 10000; |
|
| 490 | + } # {300,0} -> c'est 300 qui compte |
|
| 491 | + elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | + |
|
| 497 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,16 +505,16 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | **/ |
| 507 | 507 | function image_recadre_avec_fallback( |
| 508 | - $im, |
|
| 509 | - $width, |
|
| 510 | - $height = '-', |
|
| 511 | - $position = 'focus', |
|
| 512 | - $background_color = 'white' |
|
| 508 | + $im, |
|
| 509 | + $width, |
|
| 510 | + $height = '-', |
|
| 511 | + $position = 'focus', |
|
| 512 | + $background_color = 'white' |
|
| 513 | 513 | ) { |
| 514 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | - } else { return image_passe_partout($im, $width, $height); |
|
| 517 | - } |
|
| 514 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | + } else { return image_passe_partout($im, $width, $height); |
|
| 517 | + } |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,25 +532,25 @@ discard block |
||
| 532 | 532 | * Code HTML de l'image ou du texte. |
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | - // PHP 7+ type hint |
|
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 535 | + // PHP 7+ type hint |
|
| 536 | + $img = (string)$img; |
|
| 537 | + $val = (int)$val; |
|
| 538 | + $force = (bool)$force; |
|
| 539 | 539 | |
| 540 | - [$hauteur, $largeur] = taille_image($img); |
|
| 540 | + [$hauteur, $largeur] = taille_image($img); |
|
| 541 | 541 | |
| 542 | - $l = round($largeur / $val); |
|
| 543 | - $h = round($hauteur / $val); |
|
| 542 | + $l = round($largeur / $val); |
|
| 543 | + $h = round($hauteur / $val); |
|
| 544 | 544 | |
| 545 | - if ($l > $h) { |
|
| 546 | - $h = 0; |
|
| 547 | - } else { |
|
| 548 | - $l = 0; |
|
| 549 | - } |
|
| 545 | + if ($l > $h) { |
|
| 546 | + $h = 0; |
|
| 547 | + } else { |
|
| 548 | + $l = 0; |
|
| 549 | + } |
|
| 550 | 550 | |
| 551 | - $img = image_reduire($img, $l, $h, $force); |
|
| 551 | + $img = image_reduire($img, $l, $h, $force); |
|
| 552 | 552 | |
| 553 | - return $img; |
|
| 553 | + return $img; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * Couleur en écriture hexadécimale. |
| 574 | 574 | **/ |
| 575 | 575 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 576 | - if (function_exists('couleur_saturation')) { |
|
| 577 | - return couleur_saturation($couleur, $val, $strict); |
|
| 578 | - } |
|
| 579 | - return $couleur; |
|
| 576 | + if (function_exists('couleur_saturation')) { |
|
| 577 | + return couleur_saturation($couleur, $val, $strict); |
|
| 578 | + } |
|
| 579 | + return $couleur; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -597,8 +597,8 @@ discard block |
||
| 597 | 597 | * Couleur en écriture hexadécimale. |
| 598 | 598 | **/ |
| 599 | 599 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 600 | - if (function_exists('couleur_luminance')) { |
|
| 601 | - return couleur_luminance($couleur, $val); |
|
| 602 | - } |
|
| 603 | - return $couleur; |
|
| 600 | + if (function_exists('couleur_luminance')) { |
|
| 601 | + return couleur_luminance($couleur, $val); |
|
| 602 | + } |
|
| 603 | + return $couleur; |
|
| 604 | 604 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
| 136 | 136 | if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 137 | + $from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')'; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // nettoyer les é ’, &emdash; etc... |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | if (!_TEST_EMAIL_DEST) { |
| 172 | 172 | return false; |
| 173 | 173 | } else { |
| 174 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 174 | + $texte = "Dest : $destinataire\r\n".$texte; |
|
| 175 | 175 | $destinataire = _TEST_EMAIL_DEST; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | // Ajouter le Content-Type et consort s'il n'y est pas deja |
| 196 | 196 | if (strpos($headers, 'Content-Type: ') === false) { |
| 197 | 197 | $type = |
| 198 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 198 | + "Content-Type: text/plain;charset=\"$charset\";\n". |
|
| 199 | 199 | "Content-Transfer-Encoding: 8bit\n"; |
| 200 | 200 | } else { |
| 201 | 201 | $type = ''; |
@@ -207,17 +207,17 @@ discard block |
||
| 207 | 207 | $domain = $domain[0]; |
| 208 | 208 | } |
| 209 | 209 | else { |
| 210 | - $domain = '@unknown-' . md5($from) . '.org'; |
|
| 210 | + $domain = '@unknown-'.md5($from).'.org'; |
|
| 211 | 211 | } |
| 212 | - $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 212 | + $uniq = random_int(0, mt_getrandmax()).'_'.md5($to.$texte).$domain; |
|
| 213 | 213 | |
| 214 | 214 | // Si multi-part, s'en servir comme borne ... |
| 215 | 215 | if ($parts) { |
| 216 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 216 | + $texte = "--$uniq\n$type\n".$texte."\n"; |
|
| 217 | 217 | foreach ($parts as $part) { |
| 218 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 218 | + $n = strlen($part[1]).($part[0] ? "\n" : ''); |
|
| 219 | 219 | $e = join("\n", $part[0]); |
| 220 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 220 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1]; |
|
| 221 | 221 | } |
| 222 | 222 | $texte .= "\n\n--$uniq--\n"; |
| 223 | 223 | // Si boundary n'est pas entre guillemets, |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | // .. et s'en servir pour plaire a SpamAssassin |
| 229 | 229 | |
| 230 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 230 | + $mid = 'Message-Id: <'.$uniq.'>'; |
|
| 231 | 231 | |
| 232 | 232 | // indispensable pour les sites qui collent d'office From: serveur-http |
| 233 | 233 | // sauf si deja mis par l'envoyeur |
@@ -205,8 +205,7 @@ |
||
| 205 | 205 | // Marie Toto <[email protected]> => @toto.com |
| 206 | 206 | if (preg_match('/@[^\s>]+/', $from, $domain)) { |
| 207 | 207 | $domain = $domain[0]; |
| 208 | - } |
|
| 209 | - else { |
|
| 208 | + } else { |
|
| 210 | 209 | $domain = '@unknown-' . md5($from) . '.org'; |
| 211 | 210 | } |
| 212 | 211 | $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Mail |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function nettoyer_titre_email($titre) { |
| 35 | - return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre)))); |
|
| 35 | + return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre)))); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -48,23 +48,23 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function nettoyer_caracteres_mail($t) { |
| 50 | 50 | |
| 51 | - $t = filtrer_entites($t); |
|
| 51 | + $t = filtrer_entites($t); |
|
| 52 | 52 | |
| 53 | - if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | - $t = str_replace( |
|
| 55 | - ['’', '“', '”'], |
|
| 56 | - ["'", '"', '"'], |
|
| 57 | - $t |
|
| 58 | - ); |
|
| 59 | - } |
|
| 53 | + if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | + $t = str_replace( |
|
| 55 | + ['’', '“', '”'], |
|
| 56 | + ["'", '"', '"'], |
|
| 57 | + $t |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $t = str_replace( |
|
| 62 | - ['—', '&endash;'], |
|
| 63 | - ['--', '-'], |
|
| 64 | - $t |
|
| 65 | - ); |
|
| 61 | + $t = str_replace( |
|
| 62 | + ['—', '&endash;'], |
|
| 63 | + ['--', '-'], |
|
| 64 | + $t |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - return $t; |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -97,87 +97,87 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') { |
| 99 | 99 | |
| 100 | - if (!email_valide($destinataire)) { |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | - return false; |
|
| 105 | - } // tres fort |
|
| 106 | - |
|
| 107 | - // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | - // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | - |
|
| 110 | - $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | - if (!email_valide($email_envoi)) { |
|
| 112 | - spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | - $email_envoi = $destinataire; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $parts = ''; |
|
| 117 | - if (is_array($corps)) { |
|
| 118 | - $texte = $corps['texte']; |
|
| 119 | - $from = ($corps['from'] ?? $from); |
|
| 120 | - $headers = ($corps['headers'] ?? $headers); |
|
| 121 | - if (is_array($headers)) { |
|
| 122 | - $headers = implode("\n", $headers); |
|
| 123 | - } |
|
| 124 | - if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | - $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | - } |
|
| 127 | - } else { |
|
| 128 | - $texte = $corps; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if (!$from) { |
|
| 132 | - $from = $email_envoi; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | - if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // nettoyer les é ’, &emdash; etc... |
|
| 141 | - // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | - // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | - $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | - $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | - |
|
| 146 | - // encoder le sujet si possible selon la RFC |
|
| 147 | - if (init_mb_string()) { |
|
| 148 | - # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | - # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | - $charset = $GLOBALS['meta']['charset']; |
|
| 151 | - mb_internal_encoding($charset); |
|
| 152 | - $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | - mb_internal_encoding('utf-8'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $headers = $headers ?? ''; |
|
| 157 | - if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 158 | - $texte = wordwrap($texte); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 162 | - |
|
| 163 | - if (_OS_SERVEUR == 'windows') { |
|
| 164 | - $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 165 | - $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 166 | - $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 170 | - // mode TEST : forcer l'email |
|
| 171 | - if (defined('_TEST_EMAIL_DEST')) { |
|
| 172 | - if (!_TEST_EMAIL_DEST) { |
|
| 173 | - return false; |
|
| 174 | - } else { |
|
| 175 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 176 | - $destinataire = _TEST_EMAIL_DEST; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return @mail($destinataire, $sujet, $texte, $headers); |
|
| 100 | + if (!email_valide($destinataire)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | + return false; |
|
| 105 | + } // tres fort |
|
| 106 | + |
|
| 107 | + // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | + // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | + |
|
| 110 | + $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | + if (!email_valide($email_envoi)) { |
|
| 112 | + spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | + $email_envoi = $destinataire; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $parts = ''; |
|
| 117 | + if (is_array($corps)) { |
|
| 118 | + $texte = $corps['texte']; |
|
| 119 | + $from = ($corps['from'] ?? $from); |
|
| 120 | + $headers = ($corps['headers'] ?? $headers); |
|
| 121 | + if (is_array($headers)) { |
|
| 122 | + $headers = implode("\n", $headers); |
|
| 123 | + } |
|
| 124 | + if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | + $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | + } |
|
| 127 | + } else { |
|
| 128 | + $texte = $corps; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if (!$from) { |
|
| 132 | + $from = $email_envoi; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | + if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | + $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // nettoyer les é ’, &emdash; etc... |
|
| 141 | + // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | + // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | + $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | + $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | + |
|
| 146 | + // encoder le sujet si possible selon la RFC |
|
| 147 | + if (init_mb_string()) { |
|
| 148 | + # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | + # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | + $charset = $GLOBALS['meta']['charset']; |
|
| 151 | + mb_internal_encoding($charset); |
|
| 152 | + $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | + mb_internal_encoding('utf-8'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $headers = $headers ?? ''; |
|
| 157 | + if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 158 | + $texte = wordwrap($texte); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 162 | + |
|
| 163 | + if (_OS_SERVEUR == 'windows') { |
|
| 164 | + $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 165 | + $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 166 | + $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 170 | + // mode TEST : forcer l'email |
|
| 171 | + if (defined('_TEST_EMAIL_DEST')) { |
|
| 172 | + if (!_TEST_EMAIL_DEST) { |
|
| 173 | + return false; |
|
| 174 | + } else { |
|
| 175 | + $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 176 | + $destinataire = _TEST_EMAIL_DEST; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return @mail($destinataire, $sujet, $texte, $headers); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -191,58 +191,58 @@ discard block |
||
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | 193 | function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') { |
| 194 | - $charset = $GLOBALS['meta']['charset']; |
|
| 195 | - |
|
| 196 | - // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 197 | - if (strpos($headers, 'Content-Type: ') === false) { |
|
| 198 | - $type = |
|
| 199 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 200 | - "Content-Transfer-Encoding: 8bit\n"; |
|
| 201 | - } else { |
|
| 202 | - $type = ''; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // calculer un identifiant unique |
|
| 206 | - // Marie Toto <[email protected]> => @toto.com |
|
| 207 | - if (preg_match('/@[^\s>]+/', $from, $domain)) { |
|
| 208 | - $domain = $domain[0]; |
|
| 209 | - } |
|
| 210 | - else { |
|
| 211 | - $domain = '@unknown-' . md5($from) . '.org'; |
|
| 212 | - } |
|
| 213 | - $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 214 | - |
|
| 215 | - // Si multi-part, s'en servir comme borne ... |
|
| 216 | - if ($parts) { |
|
| 217 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 218 | - foreach ($parts as $part) { |
|
| 219 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 220 | - $e = join("\n", $part[0]); |
|
| 221 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 222 | - } |
|
| 223 | - $texte .= "\n\n--$uniq--\n"; |
|
| 224 | - // Si boundary n'est pas entre guillemets, |
|
| 225 | - // elle est comprise mais le charset est ignoree ! |
|
| 226 | - $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // .. et s'en servir pour plaire a SpamAssassin |
|
| 230 | - |
|
| 231 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 232 | - |
|
| 233 | - // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 234 | - // sauf si deja mis par l'envoyeur |
|
| 235 | - $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 236 | - |
|
| 237 | - // Nettoyer les en-tetes envoyees |
|
| 238 | - // Ajouter le \n final |
|
| 239 | - if (strlen($headers = trim($headers))) { |
|
| 240 | - $headers .= "\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Et mentionner l'indeboulonable nomenclature ratee |
|
| 244 | - |
|
| 245 | - $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 246 | - |
|
| 247 | - return [$headers, $texte]; |
|
| 194 | + $charset = $GLOBALS['meta']['charset']; |
|
| 195 | + |
|
| 196 | + // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 197 | + if (strpos($headers, 'Content-Type: ') === false) { |
|
| 198 | + $type = |
|
| 199 | + "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 200 | + "Content-Transfer-Encoding: 8bit\n"; |
|
| 201 | + } else { |
|
| 202 | + $type = ''; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // calculer un identifiant unique |
|
| 206 | + // Marie Toto <[email protected]> => @toto.com |
|
| 207 | + if (preg_match('/@[^\s>]+/', $from, $domain)) { |
|
| 208 | + $domain = $domain[0]; |
|
| 209 | + } |
|
| 210 | + else { |
|
| 211 | + $domain = '@unknown-' . md5($from) . '.org'; |
|
| 212 | + } |
|
| 213 | + $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 214 | + |
|
| 215 | + // Si multi-part, s'en servir comme borne ... |
|
| 216 | + if ($parts) { |
|
| 217 | + $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 218 | + foreach ($parts as $part) { |
|
| 219 | + $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 220 | + $e = join("\n", $part[0]); |
|
| 221 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 222 | + } |
|
| 223 | + $texte .= "\n\n--$uniq--\n"; |
|
| 224 | + // Si boundary n'est pas entre guillemets, |
|
| 225 | + // elle est comprise mais le charset est ignoree ! |
|
| 226 | + $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // .. et s'en servir pour plaire a SpamAssassin |
|
| 230 | + |
|
| 231 | + $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 232 | + |
|
| 233 | + // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 234 | + // sauf si deja mis par l'envoyeur |
|
| 235 | + $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 236 | + |
|
| 237 | + // Nettoyer les en-tetes envoyees |
|
| 238 | + // Ajouter le \n final |
|
| 239 | + if (strlen($headers = trim($headers))) { |
|
| 240 | + $headers .= "\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Et mentionner l'indeboulonable nomenclature ratee |
|
| 244 | + |
|
| 245 | + $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 246 | + |
|
| 247 | + return [$headers, $texte]; |
|
| 248 | 248 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | 44 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 45 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | - static $charset_source = 'iso-8859-1'; |
|
| 47 | - if ($definir_charset_source) { |
|
| 48 | - if ($definir_charset_source === true) { |
|
| 49 | - $charset_source = 'iso-8859-1'; |
|
| 50 | - } else { |
|
| 51 | - $charset_source = $definir_charset_source; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | - if (is_utf8($texte)) { |
|
| 56 | - $charset = 'utf-8'; |
|
| 57 | - } else { |
|
| 58 | - $charset = $charset_source; |
|
| 59 | - } |
|
| 60 | - return importer_charset($texte, $charset); |
|
| 45 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | + static $charset_source = 'iso-8859-1'; |
|
| 47 | + if ($definir_charset_source) { |
|
| 48 | + if ($definir_charset_source === true) { |
|
| 49 | + $charset_source = 'iso-8859-1'; |
|
| 50 | + } else { |
|
| 51 | + $charset_source = $definir_charset_source; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | + if (is_utf8($texte)) { |
|
| 56 | + $charset = 'utf-8'; |
|
| 57 | + } else { |
|
| 58 | + $charset = $charset_source; |
|
| 59 | + } |
|
| 60 | + return importer_charset($texte, $charset); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | 70 | function importer_csv_nettoie_key($key) { |
| 71 | - return translitteration($key); |
|
| 71 | + return translitteration($key); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -87,77 +87,77 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function inc_importer_csv_dist($file, $options = []) { |
| 89 | 89 | |
| 90 | - // support ancienne syntaxe |
|
| 91 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | - if (!is_array($options)) { |
|
| 93 | - $args = func_get_args(); |
|
| 94 | - $options = []; |
|
| 95 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | - if (!empty($args[$k])) { |
|
| 97 | - $options[$option] = $args[$k]; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 90 | + // support ancienne syntaxe |
|
| 91 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | + if (!is_array($options)) { |
|
| 93 | + $args = func_get_args(); |
|
| 94 | + $options = []; |
|
| 95 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | + if (!empty($args[$k])) { |
|
| 97 | + $options[$option] = $args[$k]; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $default_options = [ |
|
| 103 | - 'head' => false, |
|
| 104 | - 'delim' => ',', |
|
| 105 | - 'enclos' => '"', |
|
| 106 | - 'len' => 10000, |
|
| 107 | - 'charset_source' => '', |
|
| 108 | - ]; |
|
| 109 | - $options = array_merge($default_options, $options); |
|
| 102 | + $default_options = [ |
|
| 103 | + 'head' => false, |
|
| 104 | + 'delim' => ',', |
|
| 105 | + 'enclos' => '"', |
|
| 106 | + 'len' => 10000, |
|
| 107 | + 'charset_source' => '', |
|
| 108 | + ]; |
|
| 109 | + $options = array_merge($default_options, $options); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - $return = false; |
|
| 113 | - if ( |
|
| 114 | - @file_exists($file) |
|
| 115 | - and $handle = fopen($file, 'r') |
|
| 116 | - ) { |
|
| 117 | - if ($options['charset_source']) { |
|
| 118 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | - } |
|
| 120 | - if ($options['head']) { |
|
| 121 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | - if ($header) { |
|
| 123 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | - $header_type = []; |
|
| 126 | - foreach ($header as $heading) { |
|
| 127 | - if (!isset($header_type[$heading])) { |
|
| 128 | - $header_type[$heading] = 'scalar'; |
|
| 129 | - } else { |
|
| 130 | - $header_type[$heading] = 'array'; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 112 | + $return = false; |
|
| 113 | + if ( |
|
| 114 | + @file_exists($file) |
|
| 115 | + and $handle = fopen($file, 'r') |
|
| 116 | + ) { |
|
| 117 | + if ($options['charset_source']) { |
|
| 118 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | + } |
|
| 120 | + if ($options['head']) { |
|
| 121 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | + if ($header) { |
|
| 123 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | + $header_type = []; |
|
| 126 | + foreach ($header as $heading) { |
|
| 127 | + if (!isset($header_type[$heading])) { |
|
| 128 | + $header_type[$heading] = 'scalar'; |
|
| 129 | + } else { |
|
| 130 | + $header_type[$heading] = 'array'; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | - if ($options['head'] and isset($header)) { |
|
| 139 | - $row = []; |
|
| 140 | - foreach ($header as $key => $heading) { |
|
| 141 | - if ($header_type[$heading] == 'array') { |
|
| 142 | - if (!isset($row[$heading])) { |
|
| 143 | - $row[$heading] = []; |
|
| 144 | - } |
|
| 145 | - if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | - $row[$heading][] = $data[$key]; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $row[$heading] = $data[$key] ?? ''; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $return[] = $row; |
|
| 153 | - } else { |
|
| 154 | - $return[] = $data; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - if ($options['charset_source']) { |
|
| 158 | - importer_csv_importcharset('', true); |
|
| 159 | - } |
|
| 160 | - } |
|
| 136 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | + if ($options['head'] and isset($header)) { |
|
| 139 | + $row = []; |
|
| 140 | + foreach ($header as $key => $heading) { |
|
| 141 | + if ($header_type[$heading] == 'array') { |
|
| 142 | + if (!isset($row[$heading])) { |
|
| 143 | + $row[$heading] = []; |
|
| 144 | + } |
|
| 145 | + if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | + $row[$heading][] = $data[$key]; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $row[$heading] = $data[$key] ?? ''; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $return[] = $row; |
|
| 153 | + } else { |
|
| 154 | + $return[] = $data; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + if ($options['charset_source']) { |
|
| 158 | + importer_csv_importcharset('', true); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $return; |
|
| 162 | + return $return; |
|
| 163 | 163 | } |