@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('base/abstract_sql'); |
@@ -36,42 +36,42 @@ discard block |
||
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | 38 | function inc_lien_dist( |
| 39 | - $lien, |
|
| 40 | - $texte = '', |
|
| 41 | - $class = '', |
|
| 42 | - $title = '', |
|
| 43 | - $hlang = '', |
|
| 44 | - $rel = '', |
|
| 45 | - string $connect = '', |
|
| 46 | - $env = [] |
|
| 39 | + $lien, |
|
| 40 | + $texte = '', |
|
| 41 | + $class = '', |
|
| 42 | + $title = '', |
|
| 43 | + $hlang = '', |
|
| 44 | + $rel = '', |
|
| 45 | + string $connect = '', |
|
| 46 | + $env = [] |
|
| 47 | 47 | ) { |
| 48 | - return $lien; |
|
| 48 | + return $lien; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | function expanser_liens($t, string $connect = '', $env = []) { |
| 52 | 52 | |
| 53 | - $t = pipeline('pre_liens', $t); |
|
| 53 | + $t = pipeline('pre_liens', $t); |
|
| 54 | 54 | |
| 55 | - // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 56 | - // de remettre le texte d'origine dans les parametres du modele |
|
| 57 | - $t = traiter_modeles($t, false, false, $connect); |
|
| 55 | + // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 56 | + // de remettre le texte d'origine dans les parametres du modele |
|
| 57 | + $t = traiter_modeles($t, false, false, $connect); |
|
| 58 | 58 | |
| 59 | - return $t; |
|
| 59 | + return $t; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Meme analyse mais pour eliminer les liens |
| 63 | 63 | // et ne laisser que leur titre, a expliciter si ce n'est fait |
| 64 | 64 | function nettoyer_raccourcis_typo($texte, string $connect = '') { |
| 65 | - return $texte; |
|
| 65 | + return $texte; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Repere dans la partie texte d'un raccourci [texte->...] |
| 69 | 69 | // la langue et la bulle eventuelles |
| 70 | 70 | function traiter_raccourci_lien_atts($texte) { |
| 71 | - $bulle = ''; |
|
| 72 | - $hlang = ''; |
|
| 71 | + $bulle = ''; |
|
| 72 | + $hlang = ''; |
|
| 73 | 73 | |
| 74 | - return [trim((string) $texte), $bulle, $hlang]; |
|
| 74 | + return [trim((string) $texte), $bulle, $hlang]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/'); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @return string |
| 88 | 88 | */ |
| 89 | 89 | function virtuel_redirige($virtuel, $url = false) { |
| 90 | - return $virtuel; |
|
| 90 | + return $virtuel; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Cherche un lien du type [->raccourci 123] |
@@ -100,56 +100,56 @@ discard block |
||
| 100 | 100 | // 'url': seulement U (i.e. generer_url_RACCOURCI) |
| 101 | 101 | |
| 102 | 102 | function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 103 | - $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 103 | + $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 104 | 104 | |
| 105 | - return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 105 | + return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
| 109 | 109 | |
| 110 | 110 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 111 | - if (preg_match(_EXTRAIRE_LIEN, (string) $ref)) { |
|
| 112 | - return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $lien = entites_html(trim((string) $ref)); |
|
| 116 | - |
|
| 117 | - // Liens explicites |
|
| 118 | - if (!$texte) { |
|
| 119 | - $texte = str_replace('"', '', (string) $lien); |
|
| 120 | - // evite l'affichage de trops longues urls. |
|
| 121 | - $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 122 | - $texte = $lien_court($texte); |
|
| 123 | - if ($echappe_typo) { |
|
| 124 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // petites corrections d'URL |
|
| 129 | - if (preg_match('/^www\.[^@]+$/S', (string) $lien)) { |
|
| 130 | - $lien = 'http://' . $lien; |
|
| 131 | - } else { |
|
| 132 | - if (strpos((string) $lien, '@') && email_valide($lien)) { |
|
| 133 | - if (!$texte) { |
|
| 134 | - $texte = $lien; |
|
| 135 | - } |
|
| 136 | - $lien = 'mailto:' . $lien; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if ($pour == 'url') { |
|
| 141 | - return $lien; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($pour == 'titre') { |
|
| 145 | - return $texte; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return ['url' => $lien, 'titre' => $texte]; |
|
| 111 | + if (preg_match(_EXTRAIRE_LIEN, (string) $ref)) { |
|
| 112 | + return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $lien = entites_html(trim((string) $ref)); |
|
| 116 | + |
|
| 117 | + // Liens explicites |
|
| 118 | + if (!$texte) { |
|
| 119 | + $texte = str_replace('"', '', (string) $lien); |
|
| 120 | + // evite l'affichage de trops longues urls. |
|
| 121 | + $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 122 | + $texte = $lien_court($texte); |
|
| 123 | + if ($echappe_typo) { |
|
| 124 | + $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // petites corrections d'URL |
|
| 129 | + if (preg_match('/^www\.[^@]+$/S', (string) $lien)) { |
|
| 130 | + $lien = 'http://' . $lien; |
|
| 131 | + } else { |
|
| 132 | + if (strpos((string) $lien, '@') && email_valide($lien)) { |
|
| 133 | + if (!$texte) { |
|
| 134 | + $texte = $lien; |
|
| 135 | + } |
|
| 136 | + $lien = 'mailto:' . $lien; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if ($pour == 'url') { |
|
| 141 | + return $lien; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($pour == 'titre') { |
|
| 145 | + return $texte; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return ['url' => $lien, 'titre' => $texte]; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 152 | - return function_exists($f = 'glossaire_' . $ancre) ? $f($texte, $id) : glossaire_std($texte); |
|
| 152 | + return function_exists($f = 'glossaire_' . $ancre) ? $f($texte, $id) : glossaire_std($texte); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -171,73 +171,73 @@ discard block |
||
| 171 | 171 | * @return array|bool|string |
| 172 | 172 | */ |
| 173 | 173 | function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '') { |
| 174 | - $cible = $GLOBALS['lien_implicite_cible_public'] ?? null; |
|
| 175 | - if (!($match = typer_raccourci($ref))) { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 180 | - |
|
| 181 | - # attention dans le cas des sites le lien doit pointer non pas sur |
|
| 182 | - # la page locale du site, mais directement sur le site lui-meme |
|
| 183 | - $url = ''; |
|
| 184 | - if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 185 | - $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if (!$url) { |
|
| 189 | - $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if (!$url) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (is_array($url)) { |
|
| 197 | - [$type, $id] = array_pad($url, 2, null); |
|
| 198 | - $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($pour === 'url') { |
|
| 202 | - return $url; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 206 | - if ($r) { |
|
| 207 | - $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if ($texte = trim($texte)) { |
|
| 211 | - $r['titre'] = $texte; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - if (!@$r['titre']) { |
|
| 215 | - $r['titre'] = _T($type) . " $id"; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($pour == 'titre') { |
|
| 219 | - return $r['titre']; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $r['url'] = $url; |
|
| 223 | - |
|
| 224 | - // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 225 | - if ( |
|
| 226 | - $type == 'document' && ($mime = sql_getfetsel( |
|
| 227 | - 'mime_type', |
|
| 228 | - 'spip_types_documents', |
|
| 229 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 230 | - '', |
|
| 231 | - '', |
|
| 232 | - '', |
|
| 233 | - '', |
|
| 234 | - $connect |
|
| 235 | - )) |
|
| 236 | - ) { |
|
| 237 | - $r['mime'] = $mime; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return $r; |
|
| 174 | + $cible = $GLOBALS['lien_implicite_cible_public'] ?? null; |
|
| 175 | + if (!($match = typer_raccourci($ref))) { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 180 | + |
|
| 181 | + # attention dans le cas des sites le lien doit pointer non pas sur |
|
| 182 | + # la page locale du site, mais directement sur le site lui-meme |
|
| 183 | + $url = ''; |
|
| 184 | + if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 185 | + $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if (!$url) { |
|
| 189 | + $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if (!$url) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (is_array($url)) { |
|
| 197 | + [$type, $id] = array_pad($url, 2, null); |
|
| 198 | + $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($pour === 'url') { |
|
| 202 | + return $url; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 206 | + if ($r) { |
|
| 207 | + $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if ($texte = trim($texte)) { |
|
| 211 | + $r['titre'] = $texte; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if (!@$r['titre']) { |
|
| 215 | + $r['titre'] = _T($type) . " $id"; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($pour == 'titre') { |
|
| 219 | + return $r['titre']; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $r['url'] = $url; |
|
| 223 | + |
|
| 224 | + // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 225 | + if ( |
|
| 226 | + $type == 'document' && ($mime = sql_getfetsel( |
|
| 227 | + 'mime_type', |
|
| 228 | + 'spip_types_documents', |
|
| 229 | + 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 230 | + '', |
|
| 231 | + '', |
|
| 232 | + '', |
|
| 233 | + '', |
|
| 234 | + $connect |
|
| 235 | + )) |
|
| 236 | + ) { |
|
| 237 | + $r['mime'] = $mime; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return $r; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes |
@@ -245,43 +245,43 @@ discard block |
||
| 245 | 245 | define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S'); |
| 246 | 246 | |
| 247 | 247 | function typer_raccourci($lien) { |
| 248 | - if (!preg_match(_RACCOURCI_URL, (string) $lien, $match)) { |
|
| 249 | - return []; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $f = $match[1]; |
|
| 253 | - // valeur par defaut et alias historiques |
|
| 254 | - if (!$f) { |
|
| 255 | - $f = 'article'; |
|
| 256 | - } else { |
|
| 257 | - if ($f == 'art') { |
|
| 258 | - $f = 'article'; |
|
| 259 | - } else { |
|
| 260 | - if ($f == 'br') { |
|
| 261 | - $f = 'breve'; |
|
| 262 | - } else { |
|
| 263 | - if ($f == 'rub') { |
|
| 264 | - $f = 'rubrique'; |
|
| 265 | - } else { |
|
| 266 | - if ($f == 'aut') { |
|
| 267 | - $f = 'auteur'; |
|
| 268 | - } else { |
|
| 269 | - if ($f == 'doc' || $f == 'im' || $f == 'img' || $f == 'image' || $f == 'emb') { |
|
| 270 | - $f = 'document'; |
|
| 271 | - } else { |
|
| 272 | - if (preg_match('/^br..?ve$/S', $f)) { |
|
| 273 | - $f = 'breve'; # accents :( |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - $match[0] = $f; |
|
| 283 | - |
|
| 284 | - return $match; |
|
| 248 | + if (!preg_match(_RACCOURCI_URL, (string) $lien, $match)) { |
|
| 249 | + return []; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $f = $match[1]; |
|
| 253 | + // valeur par defaut et alias historiques |
|
| 254 | + if (!$f) { |
|
| 255 | + $f = 'article'; |
|
| 256 | + } else { |
|
| 257 | + if ($f == 'art') { |
|
| 258 | + $f = 'article'; |
|
| 259 | + } else { |
|
| 260 | + if ($f == 'br') { |
|
| 261 | + $f = 'breve'; |
|
| 262 | + } else { |
|
| 263 | + if ($f == 'rub') { |
|
| 264 | + $f = 'rubrique'; |
|
| 265 | + } else { |
|
| 266 | + if ($f == 'aut') { |
|
| 267 | + $f = 'auteur'; |
|
| 268 | + } else { |
|
| 269 | + if ($f == 'doc' || $f == 'im' || $f == 'img' || $f == 'image' || $f == 'emb') { |
|
| 270 | + $f = 'document'; |
|
| 271 | + } else { |
|
| 272 | + if (preg_match('/^br..?ve$/S', $f)) { |
|
| 273 | + $f = 'breve'; # accents :( |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + $match[0] = $f; |
|
| 283 | + |
|
| 284 | + return $match; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -296,44 +296,44 @@ discard block |
||
| 296 | 296 | * } |
| 297 | 297 | **/ |
| 298 | 298 | function traiter_raccourci_titre($id, $type, $connect = null) { |
| 299 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 300 | - $desc = $trouver_table(table_objet($type)); |
|
| 299 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 300 | + $desc = $trouver_table(table_objet($type)); |
|
| 301 | 301 | |
| 302 | - if (!($desc && ($s = $desc['titre']))) { |
|
| 303 | - return []; |
|
| 304 | - } |
|
| 302 | + if (!($desc && ($s = $desc['titre']))) { |
|
| 303 | + return []; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - $_id = $desc['key']['PRIMARY KEY']; |
|
| 307 | - $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 306 | + $_id = $desc['key']['PRIMARY KEY']; |
|
| 307 | + $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 308 | 308 | |
| 309 | - if (!$r) { |
|
| 310 | - return []; |
|
| 311 | - } |
|
| 309 | + if (!$r) { |
|
| 310 | + return []; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - $r['titre'] = supprimer_numero($r['titre']); |
|
| 313 | + $r['titre'] = supprimer_numero($r['titre']); |
|
| 314 | 314 | |
| 315 | - if (!$r['titre'] && !empty($r['surnom'])) { |
|
| 316 | - $r['titre'] = $r['surnom']; |
|
| 317 | - } |
|
| 315 | + if (!$r['titre'] && !empty($r['surnom'])) { |
|
| 316 | + $r['titre'] = $r['surnom']; |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - if (!isset($r['lang'])) { |
|
| 320 | - $r['lang'] = ''; |
|
| 321 | - } |
|
| 319 | + if (!isset($r['lang'])) { |
|
| 320 | + $r['lang'] = ''; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - return $r; |
|
| 323 | + return $r; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | // |
| 327 | 327 | // Raccourcis ancre [#ancre<-] |
| 328 | 328 | // |
| 329 | 329 | function traiter_raccourci_ancre($letexte) { |
| 330 | - return $letexte; |
|
| 330 | + return $letexte; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | function traiter_raccourci_glossaire($texte) { |
| 334 | - return $texte; |
|
| 334 | + return $texte; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | function glossaire_std($terme) { |
| 338 | - return $terme; |
|
| 338 | + return $terme; |
|
| 339 | 339 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | -define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
|
| 108 | +define('_EXTRAIRE_LIEN', ',^\s*(?:'._PROTOCOLES_STD.'):?/?/?\s*$,iS'); |
|
| 109 | 109 | |
| 110 | 110 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 111 | 111 | if (preg_match(_EXTRAIRE_LIEN, (string) $ref)) { |
@@ -121,19 +121,19 @@ discard block |
||
| 121 | 121 | $lien_court = charger_fonction('lien_court', 'inc'); |
| 122 | 122 | $texte = $lien_court($texte); |
| 123 | 123 | if ($echappe_typo) { |
| 124 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 124 | + $texte = '<html>'.quote_amp($texte).'</html>'; |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // petites corrections d'URL |
| 129 | 129 | if (preg_match('/^www\.[^@]+$/S', (string) $lien)) { |
| 130 | - $lien = 'http://' . $lien; |
|
| 130 | + $lien = 'http://'.$lien; |
|
| 131 | 131 | } else { |
| 132 | 132 | if (strpos((string) $lien, '@') && email_valide($lien)) { |
| 133 | 133 | if (!$texte) { |
| 134 | 134 | $texte = $lien; |
| 135 | 135 | } |
| 136 | - $lien = 'mailto:' . $lien; |
|
| 136 | + $lien = 'mailto:'.$lien; |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 152 | - return function_exists($f = 'glossaire_' . $ancre) ? $f($texte, $id) : glossaire_std($texte); |
|
| 152 | + return function_exists($f = 'glossaire_'.$ancre) ? $f($texte, $id) : glossaire_std($texte); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 179 | + [$type,, $id,, $args,, $ancre] = array_pad($match, 7, null); |
|
| 180 | 180 | |
| 181 | 181 | # attention dans le cas des sites le lien doit pointer non pas sur |
| 182 | 182 | # la page locale du site, mais directement sur le site lui-meme |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | if (!@$r['titre']) { |
| 215 | - $r['titre'] = _T($type) . " $id"; |
|
| 215 | + $r['titre'] = _T($type)." $id"; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | if ($pour == 'titre') { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $type == 'document' && ($mime = sql_getfetsel( |
| 227 | 227 | 'mime_type', |
| 228 | 228 | 'spip_types_documents', |
| 229 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 229 | + 'extension IN ('.sql_get_select('extension', 'spip_documents', 'id_document='.sql_quote($id)).')', |
|
| 230 | 230 | '', |
| 231 | 231 | '', |
| 232 | 232 | '', |
@@ -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 | /** |
@@ -34,35 +34,35 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function definir_barre_onglets($script) { |
| 36 | 36 | |
| 37 | - $onglets = []; |
|
| 38 | - $liste_onglets = []; |
|
| 37 | + $onglets = []; |
|
| 38 | + $liste_onglets = []; |
|
| 39 | 39 | |
| 40 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 41 | - if (function_exists('onglets_plugins')) { |
|
| 42 | - $liste_onglets = onglets_plugins(); |
|
| 43 | - } |
|
| 40 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 41 | + if (function_exists('onglets_plugins')) { |
|
| 42 | + $liste_onglets = onglets_plugins(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - foreach ($liste_onglets as $id => $infos) { |
|
| 47 | - if ( |
|
| 48 | - ($parent = $infos['parent']) |
|
| 49 | - && $parent == $script |
|
| 50 | - && autoriser('onglet', "_$id") |
|
| 51 | - ) { |
|
| 52 | - $onglets[$id] = new Bouton( |
|
| 53 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 54 | - $infos['titre'], // titre |
|
| 55 | - (isset($infos['action']) && $infos['action']) |
|
| 56 | - ? generer_url_ecrire( |
|
| 57 | - $infos['action'], |
|
| 58 | - (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : '' |
|
| 59 | - ) |
|
| 60 | - : null |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - } |
|
| 46 | + foreach ($liste_onglets as $id => $infos) { |
|
| 47 | + if ( |
|
| 48 | + ($parent = $infos['parent']) |
|
| 49 | + && $parent == $script |
|
| 50 | + && autoriser('onglet', "_$id") |
|
| 51 | + ) { |
|
| 52 | + $onglets[$id] = new Bouton( |
|
| 53 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 54 | + $infos['titre'], // titre |
|
| 55 | + (isset($infos['action']) && $infos['action']) |
|
| 56 | + ? generer_url_ecrire( |
|
| 57 | + $infos['action'], |
|
| 58 | + (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : '' |
|
| 59 | + ) |
|
| 60 | + : null |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 65 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 83 | - include_spip('inc/presentation'); |
|
| 83 | + include_spip('inc/presentation'); |
|
| 84 | 84 | |
| 85 | - $res = ''; |
|
| 85 | + $res = ''; |
|
| 86 | 86 | |
| 87 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 88 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 89 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 90 | - } |
|
| 87 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 88 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 89 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return $res ? debut_onglet($class) . $res . fin_onglet() : (''); |
|
| 92 | + return $res ? debut_onglet($class) . $res . fin_onglet() : (''); |
|
| 93 | 93 | } |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | && autoriser('onglet', "_$id") |
| 51 | 51 | ) { |
| 52 | 52 | $onglets[$id] = new Bouton( |
| 53 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 54 | - $infos['titre'], // titre |
|
| 53 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 54 | + $infos['titre'], // titre |
|
| 55 | 55 | (isset($infos['action']) && $infos['action']) |
| 56 | 56 | ? generer_url_ecrire( |
| 57 | 57 | $infos['action'], |
@@ -89,5 +89,5 @@ discard block |
||
| 89 | 89 | $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - return $res ? debut_onglet($class) . $res . fin_onglet() : (''); |
|
| 92 | + return $res ? debut_onglet($class).$res.fin_onglet() : (''); |
|
| 93 | 93 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('base/serial'); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * en droit de l'éliminer |
| 27 | 27 | */ |
| 28 | 28 | if (!defined('_AGE_CACHE_ATIME')) { |
| 29 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 29 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | |
@@ -39,31 +39,31 @@ discard block |
||
| 39 | 39 | * @return int Taille approximative en octets |
| 40 | 40 | **/ |
| 41 | 41 | function taille_du_cache() { |
| 42 | - # check dirs until we reach > 500 files |
|
| 43 | - $t = 0; |
|
| 44 | - $n = 0; |
|
| 45 | - $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 46 | - for ($i = 0; $i < 256; $i++) { |
|
| 47 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 48 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 49 | - while (($f = readdir($d)) !== false) { |
|
| 50 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) { |
|
| 51 | - $n++; |
|
| 52 | - if ($a['mtime'] >= $time) { |
|
| 53 | - if ($a['blocks'] > 0) { |
|
| 54 | - $t += 512 * $a['blocks']; |
|
| 55 | - } else { |
|
| 56 | - $t += $a['size']; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - if ($n > 500) { |
|
| 63 | - return (int) (256 * $t / (1 + $i)); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $t; |
|
| 42 | + # check dirs until we reach > 500 files |
|
| 43 | + $t = 0; |
|
| 44 | + $n = 0; |
|
| 45 | + $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 46 | + for ($i = 0; $i < 256; $i++) { |
|
| 47 | + $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 48 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 49 | + while (($f = readdir($d)) !== false) { |
|
| 50 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) { |
|
| 51 | + $n++; |
|
| 52 | + if ($a['mtime'] >= $time) { |
|
| 53 | + if ($a['blocks'] > 0) { |
|
| 54 | + $t += 512 * $a['blocks']; |
|
| 55 | + } else { |
|
| 56 | + $t += $a['size']; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + if ($n > 500) { |
|
| 63 | + return (int) (256 * $t / (1 + $i)); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $t; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -90,30 +90,30 @@ discard block |
||
| 90 | 90 | * Inutilisé |
| 91 | 91 | **/ |
| 92 | 92 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 93 | - if (!$modif) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // determiner l'objet modifie : forum, article, etc |
|
| 98 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 99 | - $objet = objet_type($r[1]); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 103 | - if (isset($objet)) { |
|
| 104 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 108 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 109 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 110 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | - ecrire_meta('derniere_modif', time()); |
|
| 112 | - } |
|
| 113 | - } // sinon, cas standard, toujours affecter la meta |
|
| 114 | - else { |
|
| 115 | - ecrire_meta('derniere_modif', time()); |
|
| 116 | - } |
|
| 93 | + if (!$modif) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // determiner l'objet modifie : forum, article, etc |
|
| 98 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 99 | + $objet = objet_type($r[1]); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 103 | + if (isset($objet)) { |
|
| 104 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 108 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 109 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 110 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | + ecrire_meta('derniere_modif', time()); |
|
| 112 | + } |
|
| 113 | + } // sinon, cas standard, toujours affecter la meta |
|
| 114 | + else { |
|
| 115 | + ecrire_meta('derniere_modif', time()); |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -138,56 +138,56 @@ discard block |
||
| 138 | 138 | * Nombre de fichiers supprimés |
| 139 | 139 | **/ |
| 140 | 140 | function purger_repertoire($dir, $options = []) { |
| 141 | - if (!is_dir($dir) || !is_readable($dir)) { |
|
| 142 | - return 0; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 146 | - // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 147 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 148 | - return 0; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $handle = opendir($dir); |
|
| 152 | - if (!$handle) { |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $total = 0; |
|
| 157 | - |
|
| 158 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 159 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 160 | - if ($fichier[0] == '.' || $fichier == 'CACHEDIR.TAG') { |
|
| 161 | - continue; |
|
| 162 | - } |
|
| 163 | - $chemin = "$dir/$fichier"; |
|
| 164 | - if (is_file($chemin)) { |
|
| 165 | - if ( |
|
| 166 | - (!isset($options['atime']) || @fileatime($chemin) < $options['atime']) && (!isset($options['mtime']) || @filemtime($chemin) < $options['mtime']) |
|
| 167 | - ) { |
|
| 168 | - supprimer_fichier($chemin); |
|
| 169 | - $total++; |
|
| 170 | - } |
|
| 171 | - } else { |
|
| 172 | - if (is_dir($chemin)) { |
|
| 173 | - $opts = $options; |
|
| 174 | - if (isset($options['limit'])) { |
|
| 175 | - $opts['limit'] = $options['limit'] - $total; |
|
| 176 | - } |
|
| 177 | - $total += purger_repertoire($chemin, $opts); |
|
| 178 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 179 | - spip_unlink($chemin); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if (isset($options['limit']) && $total >= $options['limit']) { |
|
| 185 | - break; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - closedir($handle); |
|
| 189 | - |
|
| 190 | - return $total; |
|
| 141 | + if (!is_dir($dir) || !is_readable($dir)) { |
|
| 142 | + return 0; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 146 | + // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 147 | + if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 148 | + return 0; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $handle = opendir($dir); |
|
| 152 | + if (!$handle) { |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $total = 0; |
|
| 157 | + |
|
| 158 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 159 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 160 | + if ($fichier[0] == '.' || $fichier == 'CACHEDIR.TAG') { |
|
| 161 | + continue; |
|
| 162 | + } |
|
| 163 | + $chemin = "$dir/$fichier"; |
|
| 164 | + if (is_file($chemin)) { |
|
| 165 | + if ( |
|
| 166 | + (!isset($options['atime']) || @fileatime($chemin) < $options['atime']) && (!isset($options['mtime']) || @filemtime($chemin) < $options['mtime']) |
|
| 167 | + ) { |
|
| 168 | + supprimer_fichier($chemin); |
|
| 169 | + $total++; |
|
| 170 | + } |
|
| 171 | + } else { |
|
| 172 | + if (is_dir($chemin)) { |
|
| 173 | + $opts = $options; |
|
| 174 | + if (isset($options['limit'])) { |
|
| 175 | + $opts['limit'] = $options['limit'] - $total; |
|
| 176 | + } |
|
| 177 | + $total += purger_repertoire($chemin, $opts); |
|
| 178 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 179 | + spip_unlink($chemin); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if (isset($options['limit']) && $total >= $options['limit']) { |
|
| 185 | + break; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + closedir($handle); |
|
| 189 | + |
|
| 190 | + return $total; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -198,26 +198,26 @@ discard block |
||
| 198 | 198 | // Securite : est sur que c'est un cache |
| 199 | 199 | function retire_cache($cache) { |
| 200 | 200 | |
| 201 | - if ( |
|
| 202 | - preg_match( |
|
| 203 | - ',^([0-9a-f]/)?(\d+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 204 | - (string) $cache |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - // supprimer le fichier (de facon propre) |
|
| 208 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 209 | - } else { |
|
| 210 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 211 | - } |
|
| 201 | + if ( |
|
| 202 | + preg_match( |
|
| 203 | + ',^([0-9a-f]/)?(\d+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 204 | + (string) $cache |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + // supprimer le fichier (de facon propre) |
|
| 208 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 209 | + } else { |
|
| 210 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // Supprimer les caches marques "x" |
| 215 | 215 | // A priori dans cette version la fonction ne sera pas appelee, car |
| 216 | 216 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 217 | 217 | function inc_retire_caches_dist($chemin = '') { |
| 218 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 219 | - effacer_meta('invalider_caches'); |
|
| 220 | - } # concurrence |
|
| 218 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 219 | + effacer_meta('invalider_caches'); |
|
| 220 | + } # concurrence |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | ####################################################################### |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | ## |
| 229 | 229 | |
| 230 | 230 | function retire_caches($chemin = '') { |
| 231 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 232 | - return $retire_caches($chemin); |
|
| 233 | - } |
|
| 231 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 232 | + return $retire_caches($chemin); |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -238,10 +238,10 @@ discard block |
||
| 238 | 238 | // (note: si absente, n'est pas appellee) |
| 239 | 239 | |
| 240 | 240 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 241 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 242 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 243 | - } |
|
| 244 | - return $corps; |
|
| 241 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 242 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 243 | + } |
|
| 244 | + return $corps; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -250,41 +250,41 @@ discard block |
||
| 250 | 250 | // invoquee quand on vide tout le cache en bloc (action/purger) |
| 251 | 251 | // |
| 252 | 252 | function supprime_invalideurs() { |
| 253 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 254 | - return $supprime_invalideurs(); |
|
| 255 | - } |
|
| 253 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 254 | + return $supprime_invalideurs(); |
|
| 255 | + } |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
| 259 | 259 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 260 | 260 | function maj_invalideurs($fichier, &$page) { |
| 261 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 262 | - return $maj_invalideurs($fichier, $page); |
|
| 263 | - } |
|
| 261 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 262 | + return $maj_invalideurs($fichier, $page); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
| 267 | 267 | // les invalideurs sont de la forme "objet/id_objet" |
| 268 | 268 | function insere_invalideur($inval, $fichier) { |
| 269 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 270 | - return $insere_invalideur($inval, $fichier); |
|
| 271 | - } |
|
| 269 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 270 | + return $insere_invalideur($inval, $fichier); |
|
| 271 | + } |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
| 275 | 275 | // Marquer les fichiers caches invalides comme etant a supprimer |
| 276 | 276 | // |
| 277 | 277 | function applique_invalideur($depart) { |
| 278 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 279 | - return $applique_invalideur($depart); |
|
| 280 | - } |
|
| 278 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 279 | + return $applique_invalideur($depart); |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // |
| 284 | 284 | // Invalider les caches liés à telle condition |
| 285 | 285 | // |
| 286 | 286 | function suivre_invalideur($cond, $modif = true) { |
| 287 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 288 | - return $suivre_invalideur($cond, $modif); |
|
| 289 | - } |
|
| 287 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 288 | + return $suivre_invalideur($cond, $modif); |
|
| 289 | + } |
|
| 290 | 290 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $n = 0; |
| 45 | 45 | $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
| 46 | 46 | for ($i = 0; $i < 256; $i++) { |
| 47 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 47 | + $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 48 | 48 | if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
| 49 | 49 | while (($f = readdir($d)) !== false) { |
| 50 | 50 | if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) { |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // stocker la date_modif_$objet (ne sert a rien pour le moment) |
| 103 | 103 | if (isset($objet)) { |
| 104 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 104 | + ecrire_meta('derniere_modif_'.$objet, time()); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // si $derniere_modif_invalide est un array('article', 'rubrique') |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
| 146 | 146 | // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
| 147 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 147 | + if (file_exists(rtrim($dir, '/').'/inhib_purger_repertoire.txt')) { |
|
| 148 | 148 | return 0; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | ) |
| 206 | 206 | ) { |
| 207 | 207 | // supprimer le fichier (de facon propre) |
| 208 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 208 | + supprimer_fichier(_DIR_CACHE.$cache); |
|
| 209 | 209 | } else { |
| 210 | 210 | spip_log("Nom de fichier cache incorrect : $cache"); |
| 211 | 211 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // securité |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // se faciliter la lecture du charset |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * Initialisation |
| 32 | 32 | */ |
| 33 | 33 | function init_charset(): void { |
| 34 | - // Initialisation |
|
| 35 | - $GLOBALS['CHARSET'] = []; |
|
| 36 | - |
|
| 37 | - // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 38 | - // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 39 | - // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 40 | - if ( |
|
| 41 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 42 | - || isset($_GET['var_mode']) && !isset($_GET['var_profile']) |
|
| 43 | - ) { |
|
| 44 | - include_spip('inc/meta'); |
|
| 45 | - ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 46 | - } |
|
| 34 | + // Initialisation |
|
| 35 | + $GLOBALS['CHARSET'] = []; |
|
| 36 | + |
|
| 37 | + // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 38 | + // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 39 | + // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 40 | + if ( |
|
| 41 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 42 | + || isset($_GET['var_mode']) && !isset($_GET['var_profile']) |
|
| 43 | + ) { |
|
| 44 | + include_spip('inc/meta'); |
|
| 45 | + ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // TODO: code d’exécution en dehors du fichier. |
@@ -64,39 +64,39 @@ discard block |
||
| 64 | 64 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 65 | 65 | **/ |
| 66 | 66 | function load_charset($charset = 'AUTO') { |
| 67 | - if ($charset == 'AUTO') { |
|
| 68 | - $charset = $GLOBALS['meta']['charset']; |
|
| 69 | - } |
|
| 70 | - $charset = trim(strtolower((string) $charset)); |
|
| 71 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 72 | - return $charset; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ($charset == 'utf-8') { |
|
| 76 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 77 | - |
|
| 78 | - return $charset; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // Quelques synonymes |
|
| 82 | - if ($charset === '') { |
|
| 83 | - $charset = 'iso-8859-1'; |
|
| 84 | - } elseif ($charset === 'windows-1250') { |
|
| 85 | - $charset = 'cp1250'; |
|
| 86 | - } elseif ($charset === 'windows-1251') { |
|
| 87 | - $charset = 'cp1251'; |
|
| 88 | - } elseif ($charset === 'windows-1256') { |
|
| 89 | - $charset = 'cp1256'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | - return $charset; |
|
| 94 | - } else { |
|
| 95 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 96 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 97 | - |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 67 | + if ($charset == 'AUTO') { |
|
| 68 | + $charset = $GLOBALS['meta']['charset']; |
|
| 69 | + } |
|
| 70 | + $charset = trim(strtolower((string) $charset)); |
|
| 71 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 72 | + return $charset; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ($charset == 'utf-8') { |
|
| 76 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 77 | + |
|
| 78 | + return $charset; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // Quelques synonymes |
|
| 82 | + if ($charset === '') { |
|
| 83 | + $charset = 'iso-8859-1'; |
|
| 84 | + } elseif ($charset === 'windows-1250') { |
|
| 85 | + $charset = 'cp1250'; |
|
| 86 | + } elseif ($charset === 'windows-1251') { |
|
| 87 | + $charset = 'cp1251'; |
|
| 88 | + } elseif ($charset === 'windows-1256') { |
|
| 89 | + $charset = 'cp1256'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | + return $charset; |
|
| 94 | + } else { |
|
| 95 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 96 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 97 | + |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -109,19 +109,19 @@ discard block |
||
| 109 | 109 | * true si notre charset est utilisable par mb_strsing |
| 110 | 110 | **/ |
| 111 | 111 | function init_mb_string(): bool { |
| 112 | - static $mb; |
|
| 113 | - |
|
| 114 | - // verifier que le charset interne est connu de mb_string |
|
| 115 | - if (!$mb) { |
|
| 116 | - if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 117 | - mb_internal_encoding('utf-8'); |
|
| 118 | - $mb = 1; |
|
| 119 | - } else { |
|
| 120 | - $mb = -1; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return ($mb === 1); |
|
| 112 | + static $mb; |
|
| 113 | + |
|
| 114 | + // verifier que le charset interne est connu de mb_string |
|
| 115 | + if (!$mb) { |
|
| 116 | + if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 117 | + mb_internal_encoding('utf-8'); |
|
| 118 | + $mb = 1; |
|
| 119 | + } else { |
|
| 120 | + $mb = -1; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return ($mb === 1); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | * true si iconv fonctionne correctement |
| 137 | 137 | **/ |
| 138 | 138 | function test_iconv(): bool { |
| 139 | - static $iconv_ok; |
|
| 139 | + static $iconv_ok; |
|
| 140 | 140 | |
| 141 | - if (!$iconv_ok) { |
|
| 142 | - if (!function_exists('iconv')) { |
|
| 143 | - $iconv_ok = -1; |
|
| 144 | - } else { |
|
| 145 | - $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1; |
|
| 146 | - } |
|
| 147 | - } |
|
| 141 | + if (!$iconv_ok) { |
|
| 142 | + if (!function_exists('iconv')) { |
|
| 143 | + $iconv_ok = -1; |
|
| 144 | + } else { |
|
| 145 | + $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return ($iconv_ok === 1); |
|
| 149 | + return ($iconv_ok === 1); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -166,75 +166,75 @@ discard block |
||
| 166 | 166 | * texte corrigé |
| 167 | 167 | **/ |
| 168 | 168 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 169 | - static $trans; |
|
| 170 | - |
|
| 171 | - if (is_array($texte)) { |
|
| 172 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($charset == 'AUTO') { |
|
| 176 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 177 | - } |
|
| 178 | - if ($charset == 'utf-8') { |
|
| 179 | - $p = chr(194); |
|
| 180 | - if (!str_contains($texte, $p)) { |
|
| 181 | - return $texte; |
|
| 182 | - } |
|
| 183 | - } else { |
|
| 184 | - if ($charset == 'iso-8859-1') { |
|
| 185 | - $p = ''; |
|
| 186 | - } else { |
|
| 187 | - return $texte; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 192 | - $trans[$charset][$charset_cible] = [ |
|
| 193 | - $p . chr(128) => '€', |
|
| 194 | - $p . chr(129) => ' ', # pas affecte |
|
| 195 | - $p . chr(130) => '‚', |
|
| 196 | - $p . chr(131) => 'ƒ', |
|
| 197 | - $p . chr(132) => '„', |
|
| 198 | - $p . chr(133) => '…', |
|
| 199 | - $p . chr(134) => '†', |
|
| 200 | - $p . chr(135) => '‡', |
|
| 201 | - $p . chr(136) => 'ˆ', |
|
| 202 | - $p . chr(137) => '‰', |
|
| 203 | - $p . chr(138) => 'Š', |
|
| 204 | - $p . chr(139) => '‹', |
|
| 205 | - $p . chr(140) => 'Œ', |
|
| 206 | - $p . chr(141) => ' ', # pas affecte |
|
| 207 | - $p . chr(142) => 'Ž', |
|
| 208 | - $p . chr(143) => ' ', # pas affecte |
|
| 209 | - $p . chr(144) => ' ', # pas affecte |
|
| 210 | - $p . chr(145) => '‘', |
|
| 211 | - $p . chr(146) => '’', |
|
| 212 | - $p . chr(147) => '“', |
|
| 213 | - $p . chr(148) => '”', |
|
| 214 | - $p . chr(149) => '•', |
|
| 215 | - $p . chr(150) => '–', |
|
| 216 | - $p . chr(151) => '—', |
|
| 217 | - $p . chr(152) => '˜', |
|
| 218 | - $p . chr(153) => '™', |
|
| 219 | - $p . chr(154) => 'š', |
|
| 220 | - $p . chr(155) => '›', |
|
| 221 | - $p . chr(156) => 'œ', |
|
| 222 | - $p . chr(157) => ' ', # pas affecte |
|
| 223 | - $p . chr(158) => 'ž', |
|
| 224 | - $p . chr(159) => 'Ÿ', |
|
| 225 | - ]; |
|
| 226 | - if ($charset_cible != 'unicode') { |
|
| 227 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 228 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return @str_replace( |
|
| 234 | - array_keys($trans[$charset][$charset_cible]), |
|
| 235 | - array_values($trans[$charset][$charset_cible]), |
|
| 236 | - $texte |
|
| 237 | - ); |
|
| 169 | + static $trans; |
|
| 170 | + |
|
| 171 | + if (is_array($texte)) { |
|
| 172 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($charset == 'AUTO') { |
|
| 176 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 177 | + } |
|
| 178 | + if ($charset == 'utf-8') { |
|
| 179 | + $p = chr(194); |
|
| 180 | + if (!str_contains($texte, $p)) { |
|
| 181 | + return $texte; |
|
| 182 | + } |
|
| 183 | + } else { |
|
| 184 | + if ($charset == 'iso-8859-1') { |
|
| 185 | + $p = ''; |
|
| 186 | + } else { |
|
| 187 | + return $texte; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 192 | + $trans[$charset][$charset_cible] = [ |
|
| 193 | + $p . chr(128) => '€', |
|
| 194 | + $p . chr(129) => ' ', # pas affecte |
|
| 195 | + $p . chr(130) => '‚', |
|
| 196 | + $p . chr(131) => 'ƒ', |
|
| 197 | + $p . chr(132) => '„', |
|
| 198 | + $p . chr(133) => '…', |
|
| 199 | + $p . chr(134) => '†', |
|
| 200 | + $p . chr(135) => '‡', |
|
| 201 | + $p . chr(136) => 'ˆ', |
|
| 202 | + $p . chr(137) => '‰', |
|
| 203 | + $p . chr(138) => 'Š', |
|
| 204 | + $p . chr(139) => '‹', |
|
| 205 | + $p . chr(140) => 'Œ', |
|
| 206 | + $p . chr(141) => ' ', # pas affecte |
|
| 207 | + $p . chr(142) => 'Ž', |
|
| 208 | + $p . chr(143) => ' ', # pas affecte |
|
| 209 | + $p . chr(144) => ' ', # pas affecte |
|
| 210 | + $p . chr(145) => '‘', |
|
| 211 | + $p . chr(146) => '’', |
|
| 212 | + $p . chr(147) => '“', |
|
| 213 | + $p . chr(148) => '”', |
|
| 214 | + $p . chr(149) => '•', |
|
| 215 | + $p . chr(150) => '–', |
|
| 216 | + $p . chr(151) => '—', |
|
| 217 | + $p . chr(152) => '˜', |
|
| 218 | + $p . chr(153) => '™', |
|
| 219 | + $p . chr(154) => 'š', |
|
| 220 | + $p . chr(155) => '›', |
|
| 221 | + $p . chr(156) => 'œ', |
|
| 222 | + $p . chr(157) => ' ', # pas affecte |
|
| 223 | + $p . chr(158) => 'ž', |
|
| 224 | + $p . chr(159) => 'Ÿ', |
|
| 225 | + ]; |
|
| 226 | + if ($charset_cible != 'unicode') { |
|
| 227 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 228 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return @str_replace( |
|
| 234 | + array_keys($trans[$charset][$charset_cible]), |
|
| 235 | + array_values($trans[$charset][$charset_cible]), |
|
| 236 | + $texte |
|
| 237 | + ); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -251,26 +251,26 @@ discard block |
||
| 251 | 251 | * texte converti |
| 252 | 252 | **/ |
| 253 | 253 | function html2unicode($texte, $secure = false) { |
| 254 | - if (!str_contains($texte, '&')) { |
|
| 255 | - return $texte; |
|
| 256 | - } |
|
| 257 | - static $trans = []; |
|
| 258 | - if (!$trans) { |
|
| 259 | - load_charset('html'); |
|
| 260 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 261 | - $trans["&$key;"] = $val; |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if ($secure) { |
|
| 266 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 267 | - } else { |
|
| 268 | - return str_replace( |
|
| 269 | - ['&', '"', '<', '>'], |
|
| 270 | - ['&', '"', '<', '>'], |
|
| 271 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 254 | + if (!str_contains($texte, '&')) { |
|
| 255 | + return $texte; |
|
| 256 | + } |
|
| 257 | + static $trans = []; |
|
| 258 | + if (!$trans) { |
|
| 259 | + load_charset('html'); |
|
| 260 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 261 | + $trans["&$key;"] = $val; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if ($secure) { |
|
| 266 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 267 | + } else { |
|
| 268 | + return str_replace( |
|
| 269 | + ['&', '"', '<', '>'], |
|
| 270 | + ['&', '"', '<', '>'], |
|
| 271 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -285,16 +285,16 @@ discard block |
||
| 285 | 285 | * texte converti |
| 286 | 286 | **/ |
| 287 | 287 | function mathml2unicode($texte) { |
| 288 | - static $trans; |
|
| 289 | - if (!$trans) { |
|
| 290 | - load_charset('mathml'); |
|
| 288 | + static $trans; |
|
| 289 | + if (!$trans) { |
|
| 290 | + load_charset('mathml'); |
|
| 291 | 291 | |
| 292 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 293 | - $trans["&$key;"] = $val; |
|
| 294 | - } |
|
| 295 | - } |
|
| 292 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 293 | + $trans["&$key;"] = $val; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 297 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -316,70 +316,70 @@ discard block |
||
| 316 | 316 | * texte converti en unicode |
| 317 | 317 | **/ |
| 318 | 318 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 319 | - static $trans; |
|
| 320 | - |
|
| 321 | - if ($charset === 'AUTO') { |
|
| 322 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if ($charset === '') { |
|
| 326 | - $charset = 'iso-8859-1'; |
|
| 327 | - } |
|
| 328 | - $charset = strtolower((string) $charset); |
|
| 329 | - |
|
| 330 | - switch ($charset) { |
|
| 331 | - case 'utf-8': |
|
| 332 | - case 'utf8': |
|
| 333 | - return utf_8_to_unicode($texte); |
|
| 334 | - |
|
| 335 | - case 'iso-8859-1': |
|
| 336 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 337 | - // pas de break; ici, on suit sur default: |
|
| 338 | - |
|
| 339 | - default: |
|
| 340 | - // mbstring presente ? |
|
| 341 | - if (init_mb_string()) { |
|
| 342 | - $order = mb_detect_order(); |
|
| 343 | - try { |
|
| 344 | - # mb_string connait-il $charset? |
|
| 345 | - if ($order && mb_detect_order($charset)) { |
|
| 346 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 347 | - if ($s && $s != $texte) { |
|
| 348 | - return utf_8_to_unicode($s); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } catch (\Error) { |
|
| 352 | - // Le charset n'existe probablement pas |
|
| 353 | - } finally { |
|
| 354 | - mb_detect_order($order); # remettre comme precedemment |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 359 | - if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
|
| 360 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 361 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
|
| 365 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 369 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 370 | - // surtout en utf-8, gere ci-dessus) |
|
| 371 | - if (test_iconv()) { |
|
| 372 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 373 | - if ($s) { |
|
| 374 | - return utf_32_to_unicode($s); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Au pire ne rien faire |
|
| 379 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 380 | - |
|
| 381 | - return $texte; |
|
| 382 | - } |
|
| 319 | + static $trans; |
|
| 320 | + |
|
| 321 | + if ($charset === 'AUTO') { |
|
| 322 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if ($charset === '') { |
|
| 326 | + $charset = 'iso-8859-1'; |
|
| 327 | + } |
|
| 328 | + $charset = strtolower((string) $charset); |
|
| 329 | + |
|
| 330 | + switch ($charset) { |
|
| 331 | + case 'utf-8': |
|
| 332 | + case 'utf8': |
|
| 333 | + return utf_8_to_unicode($texte); |
|
| 334 | + |
|
| 335 | + case 'iso-8859-1': |
|
| 336 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 337 | + // pas de break; ici, on suit sur default: |
|
| 338 | + |
|
| 339 | + default: |
|
| 340 | + // mbstring presente ? |
|
| 341 | + if (init_mb_string()) { |
|
| 342 | + $order = mb_detect_order(); |
|
| 343 | + try { |
|
| 344 | + # mb_string connait-il $charset? |
|
| 345 | + if ($order && mb_detect_order($charset)) { |
|
| 346 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 347 | + if ($s && $s != $texte) { |
|
| 348 | + return utf_8_to_unicode($s); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } catch (\Error) { |
|
| 352 | + // Le charset n'existe probablement pas |
|
| 353 | + } finally { |
|
| 354 | + mb_detect_order($order); # remettre comme precedemment |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 359 | + if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
|
| 360 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 361 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
|
| 365 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 369 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 370 | + // surtout en utf-8, gere ci-dessus) |
|
| 371 | + if (test_iconv()) { |
|
| 372 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 373 | + if ($s) { |
|
| 374 | + return utf_32_to_unicode($s); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Au pire ne rien faire |
|
| 379 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 380 | + |
|
| 381 | + return $texte; |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -398,42 +398,42 @@ discard block |
||
| 398 | 398 | * texte transformé dans le charset souhaité |
| 399 | 399 | **/ |
| 400 | 400 | function unicode2charset($texte, $charset = 'AUTO') { |
| 401 | - static $CHARSET_REVERSE = []; |
|
| 402 | - static $trans = []; |
|
| 403 | - |
|
| 404 | - if ($charset == 'AUTO') { |
|
| 405 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - switch ($charset) { |
|
| 409 | - case 'utf-8': |
|
| 410 | - return unicode_to_utf_8($texte); |
|
| 411 | - |
|
| 412 | - default: |
|
| 413 | - $charset = load_charset($charset); |
|
| 414 | - |
|
| 415 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 416 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if (!isset($trans[$charset])) { |
|
| 420 | - $trans[$charset] = []; |
|
| 421 | - $t = &$trans[$charset]; |
|
| 422 | - for ($e = 128; $e < 255; $e++) { |
|
| 423 | - $h = dechex($e); |
|
| 424 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 425 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 426 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 427 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 428 | - } else { |
|
| 429 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 430 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 436 | - } |
|
| 401 | + static $CHARSET_REVERSE = []; |
|
| 402 | + static $trans = []; |
|
| 403 | + |
|
| 404 | + if ($charset == 'AUTO') { |
|
| 405 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + switch ($charset) { |
|
| 409 | + case 'utf-8': |
|
| 410 | + return unicode_to_utf_8($texte); |
|
| 411 | + |
|
| 412 | + default: |
|
| 413 | + $charset = load_charset($charset); |
|
| 414 | + |
|
| 415 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 416 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if (!isset($trans[$charset])) { |
|
| 420 | + $trans[$charset] = []; |
|
| 421 | + $t = &$trans[$charset]; |
|
| 422 | + for ($e = 128; $e < 255; $e++) { |
|
| 423 | + $h = dechex($e); |
|
| 424 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 425 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 426 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 427 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 428 | + } else { |
|
| 429 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 430 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 436 | + } |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -451,39 +451,39 @@ discard block |
||
| 451 | 451 | * texte transformé dans le charset site |
| 452 | 452 | **/ |
| 453 | 453 | function importer_charset($texte, $charset = 'AUTO') { |
| 454 | - $s = null; |
|
| 455 | - static $trans = []; |
|
| 456 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 457 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 458 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 459 | - if (init_mb_string()) { |
|
| 460 | - if ( |
|
| 461 | - ($order = mb_detect_order()) |
|
| 462 | - && mb_detect_order($charset) |
|
| 463 | - ) { |
|
| 464 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 465 | - } |
|
| 466 | - mb_detect_order($order); # remettre comme precedemment |
|
| 467 | - return $s; |
|
| 468 | - } |
|
| 469 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 470 | - if ( |
|
| 471 | - !isset($trans[$charset]) |
|
| 472 | - && (($cset = load_charset($charset)) |
|
| 473 | - && is_array($GLOBALS['CHARSET'][$cset])) |
|
| 474 | - ) { |
|
| 475 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 476 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 480 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - return $texte; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 454 | + $s = null; |
|
| 455 | + static $trans = []; |
|
| 456 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 457 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 458 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 459 | + if (init_mb_string()) { |
|
| 460 | + if ( |
|
| 461 | + ($order = mb_detect_order()) |
|
| 462 | + && mb_detect_order($charset) |
|
| 463 | + ) { |
|
| 464 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 465 | + } |
|
| 466 | + mb_detect_order($order); # remettre comme precedemment |
|
| 467 | + return $s; |
|
| 468 | + } |
|
| 469 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 470 | + if ( |
|
| 471 | + !isset($trans[$charset]) |
|
| 472 | + && (($cset = load_charset($charset)) |
|
| 473 | + && is_array($GLOBALS['CHARSET'][$cset])) |
|
| 474 | + ) { |
|
| 475 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 476 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 480 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return $texte; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -499,92 +499,92 @@ discard block |
||
| 499 | 499 | **/ |
| 500 | 500 | function utf_8_to_unicode($source) { |
| 501 | 501 | |
| 502 | - // mb_string : methode rapide |
|
| 503 | - if (init_mb_string()) { |
|
| 504 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 505 | - |
|
| 506 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - // Sinon methode pas a pas |
|
| 510 | - static $decrement; |
|
| 511 | - static $shift; |
|
| 512 | - |
|
| 513 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 514 | - if (!is_array($decrement)) { |
|
| 515 | - // array used to figure what number to decrement from character order value |
|
| 516 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 517 | - $decrement[4] = 240; |
|
| 518 | - $decrement[3] = 224; |
|
| 519 | - $decrement[2] = 192; |
|
| 520 | - $decrement[1] = 0; |
|
| 521 | - // the number of bits to shift each charNum by |
|
| 522 | - $shift[1][0] = 0; |
|
| 523 | - $shift[2][0] = 6; |
|
| 524 | - $shift[2][1] = 0; |
|
| 525 | - $shift[3][0] = 12; |
|
| 526 | - $shift[3][1] = 6; |
|
| 527 | - $shift[3][2] = 0; |
|
| 528 | - $shift[4][0] = 18; |
|
| 529 | - $shift[4][1] = 12; |
|
| 530 | - $shift[4][2] = 6; |
|
| 531 | - $shift[4][3] = 0; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $pos = 0; |
|
| 535 | - $len = strlen($source); |
|
| 536 | - $encodedString = ''; |
|
| 537 | - while ($pos < $len) { |
|
| 538 | - $char = ''; |
|
| 539 | - $ischar = false; |
|
| 540 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 541 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 542 | - // 4 chars representing one unicode character |
|
| 543 | - $thisLetter = substr($source, $pos, 4); |
|
| 544 | - $pos += 4; |
|
| 545 | - } else { |
|
| 546 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 547 | - // 3 chars representing one unicode character |
|
| 548 | - $thisLetter = substr($source, $pos, 3); |
|
| 549 | - $pos += 3; |
|
| 550 | - } else { |
|
| 551 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 552 | - // 2 chars representing one unicode character |
|
| 553 | - $thisLetter = substr($source, $pos, 2); |
|
| 554 | - $pos += 2; |
|
| 555 | - } else { |
|
| 556 | - // 1 char (lower ascii) |
|
| 557 | - $thisLetter = substr($source, $pos, 1); |
|
| 558 | - $pos += 1; |
|
| 559 | - $char = $thisLetter; |
|
| 560 | - $ischar = true; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - if ($ischar) { |
|
| 566 | - $encodedString .= $char; |
|
| 567 | - } else { // process the string representing the letter to a unicode entity |
|
| 568 | - $thisLen = strlen($thisLetter); |
|
| 569 | - $thisPos = 0; |
|
| 570 | - $decimalCode = 0; |
|
| 571 | - while ($thisPos < $thisLen) { |
|
| 572 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 573 | - if ($thisPos == 0) { |
|
| 574 | - $charNum = (int) ($thisCharOrd - $decrement[$thisLen]); |
|
| 575 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 576 | - } else { |
|
| 577 | - $charNum = (int) ($thisCharOrd - 128); |
|
| 578 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 579 | - } |
|
| 580 | - $thisPos++; |
|
| 581 | - } |
|
| 582 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 583 | - $encodedString .= $encodedLetter; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - return $encodedString; |
|
| 502 | + // mb_string : methode rapide |
|
| 503 | + if (init_mb_string()) { |
|
| 504 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 505 | + |
|
| 506 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + // Sinon methode pas a pas |
|
| 510 | + static $decrement; |
|
| 511 | + static $shift; |
|
| 512 | + |
|
| 513 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 514 | + if (!is_array($decrement)) { |
|
| 515 | + // array used to figure what number to decrement from character order value |
|
| 516 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 517 | + $decrement[4] = 240; |
|
| 518 | + $decrement[3] = 224; |
|
| 519 | + $decrement[2] = 192; |
|
| 520 | + $decrement[1] = 0; |
|
| 521 | + // the number of bits to shift each charNum by |
|
| 522 | + $shift[1][0] = 0; |
|
| 523 | + $shift[2][0] = 6; |
|
| 524 | + $shift[2][1] = 0; |
|
| 525 | + $shift[3][0] = 12; |
|
| 526 | + $shift[3][1] = 6; |
|
| 527 | + $shift[3][2] = 0; |
|
| 528 | + $shift[4][0] = 18; |
|
| 529 | + $shift[4][1] = 12; |
|
| 530 | + $shift[4][2] = 6; |
|
| 531 | + $shift[4][3] = 0; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $pos = 0; |
|
| 535 | + $len = strlen($source); |
|
| 536 | + $encodedString = ''; |
|
| 537 | + while ($pos < $len) { |
|
| 538 | + $char = ''; |
|
| 539 | + $ischar = false; |
|
| 540 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 541 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 542 | + // 4 chars representing one unicode character |
|
| 543 | + $thisLetter = substr($source, $pos, 4); |
|
| 544 | + $pos += 4; |
|
| 545 | + } else { |
|
| 546 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 547 | + // 3 chars representing one unicode character |
|
| 548 | + $thisLetter = substr($source, $pos, 3); |
|
| 549 | + $pos += 3; |
|
| 550 | + } else { |
|
| 551 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 552 | + // 2 chars representing one unicode character |
|
| 553 | + $thisLetter = substr($source, $pos, 2); |
|
| 554 | + $pos += 2; |
|
| 555 | + } else { |
|
| 556 | + // 1 char (lower ascii) |
|
| 557 | + $thisLetter = substr($source, $pos, 1); |
|
| 558 | + $pos += 1; |
|
| 559 | + $char = $thisLetter; |
|
| 560 | + $ischar = true; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + if ($ischar) { |
|
| 566 | + $encodedString .= $char; |
|
| 567 | + } else { // process the string representing the letter to a unicode entity |
|
| 568 | + $thisLen = strlen($thisLetter); |
|
| 569 | + $thisPos = 0; |
|
| 570 | + $decimalCode = 0; |
|
| 571 | + while ($thisPos < $thisLen) { |
|
| 572 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 573 | + if ($thisPos == 0) { |
|
| 574 | + $charNum = (int) ($thisCharOrd - $decrement[$thisLen]); |
|
| 575 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 576 | + } else { |
|
| 577 | + $charNum = (int) ($thisCharOrd - 128); |
|
| 578 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 579 | + } |
|
| 580 | + $thisPos++; |
|
| 581 | + } |
|
| 582 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 583 | + $encodedString .= $encodedLetter; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + return $encodedString; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -603,32 +603,32 @@ discard block |
||
| 603 | 603 | **/ |
| 604 | 604 | function utf_32_to_unicode($source) { |
| 605 | 605 | |
| 606 | - // mb_string : methode rapide |
|
| 607 | - if (init_mb_string()) { |
|
| 608 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 609 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 610 | - |
|
| 611 | - return str_replace(chr(0), '', $source); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // Sinon methode lente |
|
| 615 | - $texte = ''; |
|
| 616 | - while ($source) { |
|
| 617 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 618 | - $source = substr($source, 1024); |
|
| 619 | - foreach ($words as $word) { |
|
| 620 | - if ($word < 128) { |
|
| 621 | - $texte .= chr($word); |
|
| 622 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 623 | - else { |
|
| 624 | - if ($word != 65279) { |
|
| 625 | - $texte .= '&#' . $word . ';'; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - return $texte; |
|
| 606 | + // mb_string : methode rapide |
|
| 607 | + if (init_mb_string()) { |
|
| 608 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 609 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 610 | + |
|
| 611 | + return str_replace(chr(0), '', $source); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // Sinon methode lente |
|
| 615 | + $texte = ''; |
|
| 616 | + while ($source) { |
|
| 617 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 618 | + $source = substr($source, 1024); |
|
| 619 | + foreach ($words as $word) { |
|
| 620 | + if ($word < 128) { |
|
| 621 | + $texte .= chr($word); |
|
| 622 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 623 | + else { |
|
| 624 | + if ($word != 65279) { |
|
| 625 | + $texte .= '&#' . $word . ';'; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + return $texte; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | |
@@ -645,21 +645,21 @@ discard block |
||
| 645 | 645 | * Caractère utf8 si trouvé, '' sinon |
| 646 | 646 | **/ |
| 647 | 647 | function caractere_utf_8($num) { |
| 648 | - $num = (int) $num; |
|
| 649 | - if ($num < 128) { |
|
| 650 | - return chr($num); |
|
| 651 | - } |
|
| 652 | - if ($num < 2048) { |
|
| 653 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 654 | - } |
|
| 655 | - if ($num < 65536) { |
|
| 656 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 657 | - } |
|
| 658 | - if ($num < 1_114_112) { |
|
| 659 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - return ''; |
|
| 648 | + $num = (int) $num; |
|
| 649 | + if ($num < 128) { |
|
| 650 | + return chr($num); |
|
| 651 | + } |
|
| 652 | + if ($num < 2048) { |
|
| 653 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 654 | + } |
|
| 655 | + if ($num < 65536) { |
|
| 656 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 657 | + } |
|
| 658 | + if ($num < 1_114_112) { |
|
| 659 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + return ''; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | /** |
@@ -672,42 +672,42 @@ discard block |
||
| 672 | 672 | **/ |
| 673 | 673 | function unicode_to_utf_8($texte) { |
| 674 | 674 | |
| 675 | - // 1. Entites € et suivantes |
|
| 676 | - $vu = []; |
|
| 677 | - if ( |
|
| 678 | - preg_match_all( |
|
| 679 | - ',�*([1-9]\d\d+);,S', |
|
| 680 | - $texte, |
|
| 681 | - $regs, |
|
| 682 | - PREG_SET_ORDER |
|
| 683 | - ) |
|
| 684 | - ) { |
|
| 685 | - foreach ($regs as $reg) { |
|
| 686 | - if ($reg[1] > 127 && !isset($vu[$reg[0]])) { |
|
| 687 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 692 | - |
|
| 693 | - // 2. Entites > ÿ |
|
| 694 | - //$vu = array(); |
|
| 695 | - if ( |
|
| 696 | - preg_match_all( |
|
| 697 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 698 | - $texte, |
|
| 699 | - $regs, |
|
| 700 | - PREG_SET_ORDER |
|
| 701 | - ) |
|
| 702 | - ) { |
|
| 703 | - foreach ($regs as $reg) { |
|
| 704 | - if (!isset($vu[$reg[0]])) { |
|
| 705 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 675 | + // 1. Entites € et suivantes |
|
| 676 | + $vu = []; |
|
| 677 | + if ( |
|
| 678 | + preg_match_all( |
|
| 679 | + ',�*([1-9]\d\d+);,S', |
|
| 680 | + $texte, |
|
| 681 | + $regs, |
|
| 682 | + PREG_SET_ORDER |
|
| 683 | + ) |
|
| 684 | + ) { |
|
| 685 | + foreach ($regs as $reg) { |
|
| 686 | + if ($reg[1] > 127 && !isset($vu[$reg[0]])) { |
|
| 687 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 692 | + |
|
| 693 | + // 2. Entites > ÿ |
|
| 694 | + //$vu = array(); |
|
| 695 | + if ( |
|
| 696 | + preg_match_all( |
|
| 697 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 698 | + $texte, |
|
| 699 | + $regs, |
|
| 700 | + PREG_SET_ORDER |
|
| 701 | + ) |
|
| 702 | + ) { |
|
| 703 | + foreach ($regs as $reg) { |
|
| 704 | + if (!isset($vu[$reg[0]])) { |
|
| 705 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -719,15 +719,15 @@ discard block |
||
| 719 | 719 | * texte converti |
| 720 | 720 | **/ |
| 721 | 721 | function unicode_to_javascript($texte) { |
| 722 | - $vu = []; |
|
| 723 | - while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
|
| 724 | - $num = $regs[1]; |
|
| 725 | - $vu[$num] = true; |
|
| 726 | - $s = '\u' . sprintf('%04x', $num); |
|
| 727 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - return $texte; |
|
| 722 | + $vu = []; |
|
| 723 | + while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
|
| 724 | + $num = $regs[1]; |
|
| 725 | + $vu[$num] = true; |
|
| 726 | + $s = '\u' . sprintf('%04x', $num); |
|
| 727 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + return $texte; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -739,11 +739,11 @@ discard block |
||
| 739 | 739 | * texte converti |
| 740 | 740 | **/ |
| 741 | 741 | function javascript_to_unicode($texte) { |
| 742 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 743 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 744 | - } |
|
| 742 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 743 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 744 | + } |
|
| 745 | 745 | |
| 746 | - return $texte; |
|
| 746 | + return $texte; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -755,11 +755,11 @@ discard block |
||
| 755 | 755 | * texte converti |
| 756 | 756 | **/ |
| 757 | 757 | function javascript_to_binary($texte) { |
| 758 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 759 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 760 | - } |
|
| 758 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 759 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - return $texte; |
|
| 762 | + return $texte; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | |
@@ -777,26 +777,26 @@ discard block |
||
| 777 | 777 | * @return string |
| 778 | 778 | */ |
| 779 | 779 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string { |
| 780 | - static $trans = []; |
|
| 781 | - if ($charset == 'AUTO') { |
|
| 782 | - $charset = $GLOBALS['meta']['charset']; |
|
| 783 | - } |
|
| 784 | - if (!strlen($texte)) { |
|
| 785 | - return $texte; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - $table_translit = 'translit' . $complexe; |
|
| 789 | - |
|
| 790 | - // 2. Translitterer grace a la table predefinie |
|
| 791 | - if (!isset($trans[$complexe])) { |
|
| 792 | - $trans[$complexe] = []; |
|
| 793 | - load_charset($table_translit); |
|
| 794 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 795 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 780 | + static $trans = []; |
|
| 781 | + if ($charset == 'AUTO') { |
|
| 782 | + $charset = $GLOBALS['meta']['charset']; |
|
| 783 | + } |
|
| 784 | + if (!strlen($texte)) { |
|
| 785 | + return $texte; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + $table_translit = 'translit' . $complexe; |
|
| 789 | + |
|
| 790 | + // 2. Translitterer grace a la table predefinie |
|
| 791 | + if (!isset($trans[$complexe])) { |
|
| 792 | + $trans[$complexe] = []; |
|
| 793 | + load_charset($table_translit); |
|
| 794 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 795 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -819,14 +819,14 @@ discard block |
||
| 819 | 819 | * @return string |
| 820 | 820 | */ |
| 821 | 821 | function translitteration($texte, $charset = 'AUTO', $complexe = ''): string { |
| 822 | - // 0. Supprimer les caracteres illegaux |
|
| 823 | - include_spip('inc/filtres'); |
|
| 824 | - $texte = corriger_caracteres($texte); |
|
| 822 | + // 0. Supprimer les caracteres illegaux |
|
| 823 | + include_spip('inc/filtres'); |
|
| 824 | + $texte = corriger_caracteres($texte); |
|
| 825 | 825 | |
| 826 | - // 1. Passer le charset et les é en utf-8 |
|
| 827 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 826 | + // 1. Passer le charset et les é en utf-8 |
|
| 827 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 828 | 828 | |
| 829 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 829 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -841,17 +841,17 @@ discard block |
||
| 841 | 841 | * @return string |
| 842 | 842 | */ |
| 843 | 843 | function translitteration_complexe($texte, $chiffres = false): string { |
| 844 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 844 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 845 | 845 | |
| 846 | - if ($chiffres) { |
|
| 847 | - $texte = preg_replace_callback( |
|
| 848 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 849 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 850 | - $texte |
|
| 851 | - ); |
|
| 852 | - } |
|
| 846 | + if ($chiffres) { |
|
| 847 | + $texte = preg_replace_callback( |
|
| 848 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 849 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 850 | + $texte |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - return $texte; |
|
| 854 | + return $texte; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | * @return string |
| 864 | 864 | */ |
| 865 | 865 | function translitteration_chiffree($car): string { |
| 866 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 866 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * true s'il a un BOM |
| 877 | 877 | **/ |
| 878 | 878 | function bom_utf8($texte): bool { |
| 879 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 879 | + return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -893,21 +893,21 @@ discard block |
||
| 893 | 893 | * true si c'est le cas |
| 894 | 894 | **/ |
| 895 | 895 | function is_utf8($string): bool { |
| 896 | - return !strlen( |
|
| 897 | - preg_replace( |
|
| 898 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 899 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 900 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 901 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 902 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 903 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 904 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 905 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 906 | - . ',sS', |
|
| 907 | - '', |
|
| 908 | - $string |
|
| 909 | - ) |
|
| 910 | - ); |
|
| 896 | + return !strlen( |
|
| 897 | + preg_replace( |
|
| 898 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 899 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 900 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 901 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 902 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 903 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 904 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 905 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 906 | + . ',sS', |
|
| 907 | + '', |
|
| 908 | + $string |
|
| 909 | + ) |
|
| 910 | + ); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -919,13 +919,13 @@ discard block |
||
| 919 | 919 | * true si c'est le cas |
| 920 | 920 | **/ |
| 921 | 921 | function is_ascii($string): bool { |
| 922 | - return !strlen( |
|
| 923 | - preg_replace( |
|
| 924 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 925 | - '', |
|
| 926 | - $string |
|
| 927 | - ) |
|
| 928 | - ); |
|
| 922 | + return !strlen( |
|
| 923 | + preg_replace( |
|
| 924 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 925 | + '', |
|
| 926 | + $string |
|
| 927 | + ) |
|
| 928 | + ); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
@@ -944,50 +944,50 @@ discard block |
||
| 944 | 944 | **/ |
| 945 | 945 | function transcoder_page($texte, $headers = ''): string { |
| 946 | 946 | |
| 947 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 948 | - if (is_ascii($texte)) { |
|
| 949 | - #spip_log('charset: ascii'); |
|
| 950 | - return $texte; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - if (bom_utf8($texte)) { |
|
| 954 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 955 | - $charset = 'utf-8'; |
|
| 956 | - $texte = substr($texte, 3); |
|
| 957 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 958 | - // charset precise par le contenu (xml) |
|
| 959 | - $charset = trim(strtolower($regs[1])); |
|
| 960 | - } elseif ( |
|
| 961 | - // charset precise par le contenu (html) |
|
| 962 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 963 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 964 | - |
|
| 965 | - && !str_contains($regs[2], '#') |
|
| 966 | - && ($tmp = trim(strtolower($regs[2]))) |
|
| 967 | - ) { |
|
| 968 | - $charset = $tmp; |
|
| 969 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 970 | - // charset de la reponse http |
|
| 971 | - $charset = trim(strtolower($regs[1])); |
|
| 972 | - } else { |
|
| 973 | - $charset = ''; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - // normaliser les noms du shif-jis japonais |
|
| 978 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 979 | - $charset = 'shift-jis'; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - if ($charset) { |
|
| 983 | - spip_log("charset: $charset"); |
|
| 984 | - } else { |
|
| 985 | - // valeur par defaut |
|
| 986 | - $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1'; |
|
| 987 | - spip_log("charset probable: $charset"); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - return importer_charset($texte, $charset); |
|
| 947 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 948 | + if (is_ascii($texte)) { |
|
| 949 | + #spip_log('charset: ascii'); |
|
| 950 | + return $texte; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + if (bom_utf8($texte)) { |
|
| 954 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 955 | + $charset = 'utf-8'; |
|
| 956 | + $texte = substr($texte, 3); |
|
| 957 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 958 | + // charset precise par le contenu (xml) |
|
| 959 | + $charset = trim(strtolower($regs[1])); |
|
| 960 | + } elseif ( |
|
| 961 | + // charset precise par le contenu (html) |
|
| 962 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 963 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 964 | + |
|
| 965 | + && !str_contains($regs[2], '#') |
|
| 966 | + && ($tmp = trim(strtolower($regs[2]))) |
|
| 967 | + ) { |
|
| 968 | + $charset = $tmp; |
|
| 969 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 970 | + // charset de la reponse http |
|
| 971 | + $charset = trim(strtolower($regs[1])); |
|
| 972 | + } else { |
|
| 973 | + $charset = ''; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + // normaliser les noms du shif-jis japonais |
|
| 978 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 979 | + $charset = 'shift-jis'; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + if ($charset) { |
|
| 983 | + spip_log("charset: $charset"); |
|
| 984 | + } else { |
|
| 985 | + // valeur par defaut |
|
| 986 | + $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1'; |
|
| 987 | + spip_log("charset probable: $charset"); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + return importer_charset($texte, $charset); |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | |
@@ -1011,19 +1011,19 @@ discard block |
||
| 1011 | 1011 | * Le texte coupé |
| 1012 | 1012 | **/ |
| 1013 | 1013 | function spip_substr($c, $start = 0, $length = null) { |
| 1014 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1015 | - if ($length) { |
|
| 1016 | - return substr($c, $start, $length); |
|
| 1017 | - } else { |
|
| 1018 | - return substr($c, $start); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - if ($length) { |
|
| 1023 | - return mb_substr($c, $start, $length); |
|
| 1024 | - } else { |
|
| 1025 | - return mb_substr($c, $start); |
|
| 1026 | - } |
|
| 1014 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1015 | + if ($length) { |
|
| 1016 | + return substr($c, $start, $length); |
|
| 1017 | + } else { |
|
| 1018 | + return substr($c, $start); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + if ($length) { |
|
| 1023 | + return mb_substr($c, $start, $length); |
|
| 1024 | + } else { |
|
| 1025 | + return mb_substr($c, $start); |
|
| 1026 | + } |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | /** |
@@ -1037,13 +1037,13 @@ discard block |
||
| 1037 | 1037 | * La chaîne avec une majuscule sur le premier mot |
| 1038 | 1038 | */ |
| 1039 | 1039 | function spip_ucfirst($c) { |
| 1040 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1041 | - return ucfirst($c); |
|
| 1042 | - } |
|
| 1040 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1041 | + return ucfirst($c); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1044 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1045 | 1045 | |
| 1046 | - return $lettre1 . spip_substr($c, 1); |
|
| 1046 | + return $lettre1 . spip_substr($c, 1); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1057,11 +1057,11 @@ discard block |
||
| 1057 | 1057 | * La chaîne en minuscules |
| 1058 | 1058 | */ |
| 1059 | 1059 | function spip_strtolower($c) { |
| 1060 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1061 | - return strtolower($c); |
|
| 1062 | - } |
|
| 1060 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1061 | + return strtolower($c); |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - return mb_strtolower($c); |
|
| 1064 | + return mb_strtolower($c); |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | /** |
@@ -1075,15 +1075,15 @@ discard block |
||
| 1075 | 1075 | * Longueur de la chaîne |
| 1076 | 1076 | */ |
| 1077 | 1077 | function spip_strlen($c) { |
| 1078 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1079 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1078 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1079 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1080 | 1080 | |
| 1081 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1082 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1083 | - return strlen($c); |
|
| 1084 | - } |
|
| 1081 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1082 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1083 | + return strlen($c); |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - return mb_strlen($c); |
|
| 1086 | + return mb_strlen($c); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1098,17 +1098,17 @@ discard block |
||
| 1098 | 1098 | * en unicode : 💩 |
| 1099 | 1099 | */ |
| 1100 | 1100 | function utf8_noplanes($x): string { |
| 1101 | - $regexp_utf8_4bytes = '/( |
|
| 1101 | + $regexp_utf8_4bytes = '/( |
|
| 1102 | 1102 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1103 | 1103 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1104 | 1104 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1105 | 1105 | )/xS'; |
| 1106 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1107 | - foreach ($z[0] as $k) { |
|
| 1108 | - $ku = utf_8_to_unicode($k); |
|
| 1109 | - $x = str_replace($k, $ku, $x); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - return $x; |
|
| 1106 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1107 | + foreach ($z[0] as $k) { |
|
| 1108 | + $ku = utf_8_to_unicode($k); |
|
| 1109 | + $x = str_replace($k, $ku, $x); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + return $x; |
|
| 1114 | 1114 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $charset = 'cp1256'; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 92 | + if (find_in_path($charset.'.php', 'charsets/', true)) { |
|
| 93 | 93 | return $charset; |
| 94 | 94 | } else { |
| 95 | 95 | spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
@@ -190,38 +190,38 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | if (!isset($trans[$charset][$charset_cible])) { |
| 192 | 192 | $trans[$charset][$charset_cible] = [ |
| 193 | - $p . chr(128) => '€', |
|
| 194 | - $p . chr(129) => ' ', # pas affecte |
|
| 195 | - $p . chr(130) => '‚', |
|
| 196 | - $p . chr(131) => 'ƒ', |
|
| 197 | - $p . chr(132) => '„', |
|
| 198 | - $p . chr(133) => '…', |
|
| 199 | - $p . chr(134) => '†', |
|
| 200 | - $p . chr(135) => '‡', |
|
| 201 | - $p . chr(136) => 'ˆ', |
|
| 202 | - $p . chr(137) => '‰', |
|
| 203 | - $p . chr(138) => 'Š', |
|
| 204 | - $p . chr(139) => '‹', |
|
| 205 | - $p . chr(140) => 'Œ', |
|
| 206 | - $p . chr(141) => ' ', # pas affecte |
|
| 207 | - $p . chr(142) => 'Ž', |
|
| 208 | - $p . chr(143) => ' ', # pas affecte |
|
| 209 | - $p . chr(144) => ' ', # pas affecte |
|
| 210 | - $p . chr(145) => '‘', |
|
| 211 | - $p . chr(146) => '’', |
|
| 212 | - $p . chr(147) => '“', |
|
| 213 | - $p . chr(148) => '”', |
|
| 214 | - $p . chr(149) => '•', |
|
| 215 | - $p . chr(150) => '–', |
|
| 216 | - $p . chr(151) => '—', |
|
| 217 | - $p . chr(152) => '˜', |
|
| 218 | - $p . chr(153) => '™', |
|
| 219 | - $p . chr(154) => 'š', |
|
| 220 | - $p . chr(155) => '›', |
|
| 221 | - $p . chr(156) => 'œ', |
|
| 222 | - $p . chr(157) => ' ', # pas affecte |
|
| 223 | - $p . chr(158) => 'ž', |
|
| 224 | - $p . chr(159) => 'Ÿ', |
|
| 193 | + $p.chr(128) => '€', |
|
| 194 | + $p.chr(129) => ' ', # pas affecte |
|
| 195 | + $p.chr(130) => '‚', |
|
| 196 | + $p.chr(131) => 'ƒ', |
|
| 197 | + $p.chr(132) => '„', |
|
| 198 | + $p.chr(133) => '…', |
|
| 199 | + $p.chr(134) => '†', |
|
| 200 | + $p.chr(135) => '‡', |
|
| 201 | + $p.chr(136) => 'ˆ', |
|
| 202 | + $p.chr(137) => '‰', |
|
| 203 | + $p.chr(138) => 'Š', |
|
| 204 | + $p.chr(139) => '‹', |
|
| 205 | + $p.chr(140) => 'Œ', |
|
| 206 | + $p.chr(141) => ' ', # pas affecte |
|
| 207 | + $p.chr(142) => 'Ž', |
|
| 208 | + $p.chr(143) => ' ', # pas affecte |
|
| 209 | + $p.chr(144) => ' ', # pas affecte |
|
| 210 | + $p.chr(145) => '‘', |
|
| 211 | + $p.chr(146) => '’', |
|
| 212 | + $p.chr(147) => '“', |
|
| 213 | + $p.chr(148) => '”', |
|
| 214 | + $p.chr(149) => '•', |
|
| 215 | + $p.chr(150) => '–', |
|
| 216 | + $p.chr(151) => '—', |
|
| 217 | + $p.chr(152) => '˜', |
|
| 218 | + $p.chr(153) => '™', |
|
| 219 | + $p.chr(154) => 'š', |
|
| 220 | + $p.chr(155) => '›', |
|
| 221 | + $p.chr(156) => 'œ', |
|
| 222 | + $p.chr(157) => ' ', # pas affecte |
|
| 223 | + $p.chr(158) => 'ž', |
|
| 224 | + $p.chr(159) => 'Ÿ', |
|
| 225 | 225 | ]; |
| 226 | 226 | if ($charset_cible != 'unicode') { |
| 227 | 227 | foreach ($trans[$charset][$charset_cible] as $k => $c) { |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | // Sinon, peut-etre connaissons-nous ce charset ? |
| 359 | 359 | if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
| 360 | 360 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 361 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 361 | + $trans[$charset][chr($key)] = '&#'.$val.';'; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
@@ -423,11 +423,11 @@ discard block |
||
| 423 | 423 | $h = dechex($e); |
| 424 | 424 | if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
| 425 | 425 | $s = $CHARSET_REVERSE[$charset][$e]; |
| 426 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 427 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 426 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($s); |
|
| 427 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($s); |
|
| 428 | 428 | } else { |
| 429 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 430 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 429 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($e); |
|
| 430 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($e); |
|
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | && is_array($GLOBALS['CHARSET'][$cset])) |
| 474 | 474 | ) { |
| 475 | 475 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 476 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 476 | + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | $thisPos++; |
| 581 | 581 | } |
| 582 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 582 | + $encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';'; |
|
| 583 | 583 | $encodedString .= $encodedLetter; |
| 584 | 584 | } |
| 585 | 585 | } |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
| 623 | 623 | else { |
| 624 | 624 | if ($word != 65279) { |
| 625 | - $texte .= '&#' . $word . ';'; |
|
| 625 | + $texte .= '&#'.$word.';'; |
|
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | } |
@@ -650,13 +650,13 @@ discard block |
||
| 650 | 650 | return chr($num); |
| 651 | 651 | } |
| 652 | 652 | if ($num < 2048) { |
| 653 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 653 | + return chr(($num >> 6) + 192).chr(($num & 63) + 128); |
|
| 654 | 654 | } |
| 655 | 655 | if ($num < 65536) { |
| 656 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 656 | + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 657 | 657 | } |
| 658 | 658 | if ($num < 1_114_112) { |
| 659 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 659 | + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | return ''; |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
| 724 | 724 | $num = $regs[1]; |
| 725 | 725 | $vu[$num] = true; |
| 726 | - $s = '\u' . sprintf('%04x', $num); |
|
| 726 | + $s = '\u'.sprintf('%04x', $num); |
|
| 727 | 727 | $texte = str_replace($regs[0], $s, $texte); |
| 728 | 728 | } |
| 729 | 729 | |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | **/ |
| 741 | 741 | function javascript_to_unicode($texte) { |
| 742 | 742 | while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
| 743 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 743 | + $texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | return $texte; |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | return $texte; |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | - $table_translit = 'translit' . $complexe; |
|
| 788 | + $table_translit = 'translit'.$complexe; |
|
| 789 | 789 | |
| 790 | 790 | // 2. Translitterer grace a la table predefinie |
| 791 | 791 | if (!isset($trans[$complexe])) { |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * true s'il a un BOM |
| 877 | 877 | **/ |
| 878 | 878 | function bom_utf8($texte): bool { |
| 879 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 879 | + return (substr($texte, 0, 3) === chr(0xEF).chr(0xBB).chr(0xBF)); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | |
| 1044 | 1044 | $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
| 1045 | 1045 | |
| 1046 | - return $lettre1 . spip_substr($c, 1); |
|
| 1046 | + return $lettre1.spip_substr($c, 1); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -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 | |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_BOITE_OUVRIR_dist($p) { |
| 46 | - $_titre = interprete_argument_balise(1, $p); |
|
| 47 | - $_class = interprete_argument_balise(2, $p); |
|
| 48 | - $_head_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_titre = ($_titre ?: "''"); |
|
| 50 | - $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 51 | - $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 52 | - |
|
| 53 | - $f = chercher_filtre('boite_ouvrir'); |
|
| 54 | - $p->code = "$f($_titre$_class$_head_class)"; |
|
| 55 | - $p->interdire_scripts = false; |
|
| 56 | - |
|
| 57 | - return $p; |
|
| 46 | + $_titre = interprete_argument_balise(1, $p); |
|
| 47 | + $_class = interprete_argument_balise(2, $p); |
|
| 48 | + $_head_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_titre = ($_titre ?: "''"); |
|
| 50 | + $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 51 | + $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 52 | + |
|
| 53 | + $f = chercher_filtre('boite_ouvrir'); |
|
| 54 | + $p->code = "$f($_titre$_class$_head_class)"; |
|
| 55 | + $p->interdire_scripts = false; |
|
| 56 | + |
|
| 57 | + return $p; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * Pile complétée par le code à générer |
| 75 | 75 | */ |
| 76 | 76 | function balise_BOITE_PIED_dist($p) { |
| 77 | - $_class = interprete_argument_balise(1, $p); |
|
| 78 | - $_class = ($_class ? "$_class" : ''); |
|
| 77 | + $_class = interprete_argument_balise(1, $p); |
|
| 78 | + $_class = ($_class ? "$_class" : ''); |
|
| 79 | 79 | |
| 80 | - $f = chercher_filtre('boite_pied'); |
|
| 81 | - $p->code = "$f($_class)"; |
|
| 82 | - $p->interdire_scripts = false; |
|
| 80 | + $f = chercher_filtre('boite_pied'); |
|
| 81 | + $p->code = "$f($_class)"; |
|
| 82 | + $p->interdire_scripts = false; |
|
| 83 | 83 | |
| 84 | - return $p; |
|
| 84 | + return $p; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | * Pile complétée par le code à générer |
| 102 | 102 | */ |
| 103 | 103 | function balise_BOITE_FERMER_dist($p) { |
| 104 | - $f = chercher_filtre('boite_fermer'); |
|
| 105 | - $p->code = "$f()"; |
|
| 106 | - $p->interdire_scripts = false; |
|
| 104 | + $f = chercher_filtre('boite_fermer'); |
|
| 105 | + $p->code = "$f()"; |
|
| 106 | + $p->interdire_scripts = false; |
|
| 107 | 107 | |
| 108 | - return $p; |
|
| 108 | + return $p; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -127,16 +127,16 @@ discard block |
||
| 127 | 127 | * HTML du début de la boîte |
| 128 | 128 | */ |
| 129 | 129 | function boite_ouvrir($titre, $class = '', $head_class = '', $id = '') { |
| 130 | - $class = "box $class"; |
|
| 131 | - $head_class = "box__header $head_class clearfix"; |
|
| 132 | - // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 133 | - if (test_espace_prive() && strlen($titre) && !str_contains($titre, '<h')) { |
|
| 134 | - $titre = "<h3>$titre</h3>"; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 138 | - . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 139 | - . '<div class="box__body clearfix">'; |
|
| 130 | + $class = "box $class"; |
|
| 131 | + $head_class = "box__header $head_class clearfix"; |
|
| 132 | + // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 133 | + if (test_espace_prive() && strlen($titre) && !str_contains($titre, '<h')) { |
|
| 134 | + $titre = "<h3>$titre</h3>"; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 138 | + . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 139 | + . '<div class="box__body clearfix">'; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | * HTML de transition vers le pied de la boîte |
| 154 | 154 | */ |
| 155 | 155 | function boite_pied($class = 'act') { |
| 156 | - $class = "box__footer $class"; |
|
| 156 | + $class = "box__footer $class"; |
|
| 157 | 157 | |
| 158 | - return '</div>' |
|
| 159 | - . "<div class=\"$class clearfix\">"; |
|
| 158 | + return '</div>' |
|
| 159 | + . "<div class=\"$class clearfix\">"; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
@@ -171,5 +171,5 @@ discard block |
||
| 171 | 171 | * HTML de fin de la boîte |
| 172 | 172 | */ |
| 173 | 173 | function boite_fermer() { |
| 174 | - return '</div></div>'; |
|
| 174 | + return '</div></div>'; |
|
| 175 | 175 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_TEST_FILE_EXISTS')) { |
| 23 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 23 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 30 | 30 | |
| 31 | 31 | if (_SPIP_LOCK_MODE == 2) { |
| 32 | - include_spip('inc/nfslock'); |
|
| 32 | + include_spip('inc/nfslock'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['liste_verrous'] = []; |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | * Ressource sur le fichier ouvert, sinon false. |
| 53 | 53 | **/ |
| 54 | 54 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 55 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | - // verrou |
|
| 58 | - @flock($fl, $verrou); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $fl; |
|
| 62 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | - |
|
| 66 | - return $fl; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return @fopen($fichier, $mode); |
|
| 55 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | + // verrou |
|
| 58 | + @flock($fl, $verrou); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $fl; |
|
| 62 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | + |
|
| 66 | + return $fl; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return @fopen($fichier, $mode); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * true si succès, false sinon. |
| 85 | 85 | **/ |
| 86 | 86 | function spip_fclose_unlock($handle) { |
| 87 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | - @flock($handle, LOCK_UN); |
|
| 89 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return @fclose($handle); |
|
| 87 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | + @flock($handle, LOCK_UN); |
|
| 89 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return @fclose($handle); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -105,23 +105,23 @@ discard block |
||
| 105 | 105 | * Contenu du fichier |
| 106 | 106 | **/ |
| 107 | 107 | function spip_file_get_contents($fichier) { |
| 108 | - if (!str_ends_with($fichier, '.gz')) { |
|
| 109 | - if (function_exists('file_get_contents')) { |
|
| 110 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | - // sinon on fait un file() pour avoir le coeur net |
|
| 113 | - $contenu = @file_get_contents($fichier); |
|
| 114 | - if (!$contenu && _OS_SERVEUR == 'windows') { |
|
| 115 | - $contenu = @file($fichier); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $contenu = @file($fichier); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $contenu = @gzfile($fichier); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 108 | + if (!str_ends_with($fichier, '.gz')) { |
|
| 109 | + if (function_exists('file_get_contents')) { |
|
| 110 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | + // sinon on fait un file() pour avoir le coeur net |
|
| 113 | + $contenu = @file_get_contents($fichier); |
|
| 114 | + if (!$contenu && _OS_SERVEUR == 'windows') { |
|
| 115 | + $contenu = @file($fichier); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $contenu = @file($fichier); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $contenu = @gzfile($fichier); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -146,48 +146,48 @@ discard block |
||
| 146 | 146 | * true si l'opération a réussie, false sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 149 | - $contenu = ''; |
|
| 150 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | - if (_TEST_FILE_EXISTS && !@file_exists($fichier)) { |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - #spip_timer('lire_fichier'); |
|
| 157 | - |
|
| 158 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | - // lire le fichier avant tout |
|
| 161 | - $contenu = spip_file_get_contents($fichier); |
|
| 162 | - |
|
| 163 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | - // et eviter un acces disque |
|
| 167 | - if (!$contenu && !@file_exists($fichier)) { |
|
| 168 | - spip_fclose_unlock($fl); |
|
| 169 | - |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // liberer le verrou |
|
| 174 | - spip_fclose_unlock($fl); |
|
| 175 | - |
|
| 176 | - // Verifications |
|
| 177 | - $ok = true; |
|
| 178 | - if (isset($options['phpcheck']) && $options['phpcheck'] == 'oui') { |
|
| 179 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | - if (!$ok) { |
|
| 184 | - spip_log("echec lecture $fichier"); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $ok; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return false; |
|
| 149 | + $contenu = ''; |
|
| 150 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | + if (_TEST_FILE_EXISTS && !@file_exists($fichier)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + #spip_timer('lire_fichier'); |
|
| 157 | + |
|
| 158 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | + // lire le fichier avant tout |
|
| 161 | + $contenu = spip_file_get_contents($fichier); |
|
| 162 | + |
|
| 163 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | + // et eviter un acces disque |
|
| 167 | + if (!$contenu && !@file_exists($fichier)) { |
|
| 168 | + spip_fclose_unlock($fl); |
|
| 169 | + |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // liberer le verrou |
|
| 174 | + spip_fclose_unlock($fl); |
|
| 175 | + |
|
| 176 | + // Verifications |
|
| 177 | + $ok = true; |
|
| 178 | + if (isset($options['phpcheck']) && $options['phpcheck'] == 'oui') { |
|
| 179 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | + if (!$ok) { |
|
| 184 | + spip_log("echec lecture $fichier"); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $ok; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return false; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -215,92 +215,92 @@ discard block |
||
| 215 | 215 | **/ |
| 216 | 216 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 217 | 217 | |
| 218 | - #spip_timer('ecrire_fichier'); |
|
| 219 | - |
|
| 220 | - // verrouiller le fichier destination |
|
| 221 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | - // ecrire les donnees, compressees le cas echeant |
|
| 223 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | - if (str_ends_with($fichier, '.gz')) { |
|
| 226 | - $contenu = gzencode($contenu); |
|
| 227 | - } |
|
| 228 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | - // pour etre sur d'avoir une operation atomique |
|
| 230 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | - // sauf sous wintruc ou ca ne marche pas |
|
| 232 | - $ok = false; |
|
| 233 | - if ($truncate && _OS_SERVEUR != 'windows') { |
|
| 234 | - if (!function_exists('creer_uniqid')) { |
|
| 235 | - include_spip('inc/acces'); |
|
| 236 | - } |
|
| 237 | - $id = creer_uniqid(); |
|
| 238 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | - $s = @fwrite($fp2, $contenu, $a = strlen($contenu)); |
|
| 241 | - $ok = ($s == $a); |
|
| 242 | - spip_fclose_unlock($fp2); |
|
| 243 | - spip_fclose_unlock($fp); |
|
| 244 | - $fp = null; |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS || @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - $fp = null; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - // sinon ou si methode precedente a echoueee |
|
| 266 | - // on se rabat sur la methode ancienne |
|
| 267 | - if (!$ok && !is_null($fp)) { |
|
| 268 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | - if ($truncate) { |
|
| 270 | - @ftruncate($fp, 0); |
|
| 271 | - } |
|
| 272 | - $s = @fwrite($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | - |
|
| 274 | - $ok = ($s == $a); |
|
| 275 | - spip_fclose_unlock($fp); |
|
| 276 | - } |
|
| 277 | - // on tente une dernière fois file_put_contents |
|
| 278 | - if (!$ok) { |
|
| 279 | - $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | - $ok = ($l === strlen($contenu)); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // liberer le verrou et fermer le fichier |
|
| 284 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | - if ($ok) { |
|
| 286 | - if (str_contains($fichier, '.php')) { |
|
| 287 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return $ok; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!$ignorer_echec) { |
|
| 295 | - include_spip('inc/autoriser'); |
|
| 296 | - if (autoriser('chargerftp')) { |
|
| 297 | - raler_fichier($fichier); |
|
| 298 | - } |
|
| 299 | - spip_unlink($fichier); |
|
| 300 | - } |
|
| 301 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | - |
|
| 303 | - return false; |
|
| 218 | + #spip_timer('ecrire_fichier'); |
|
| 219 | + |
|
| 220 | + // verrouiller le fichier destination |
|
| 221 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | + // ecrire les donnees, compressees le cas echeant |
|
| 223 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | + if (str_ends_with($fichier, '.gz')) { |
|
| 226 | + $contenu = gzencode($contenu); |
|
| 227 | + } |
|
| 228 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | + // pour etre sur d'avoir une operation atomique |
|
| 230 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | + // sauf sous wintruc ou ca ne marche pas |
|
| 232 | + $ok = false; |
|
| 233 | + if ($truncate && _OS_SERVEUR != 'windows') { |
|
| 234 | + if (!function_exists('creer_uniqid')) { |
|
| 235 | + include_spip('inc/acces'); |
|
| 236 | + } |
|
| 237 | + $id = creer_uniqid(); |
|
| 238 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | + $s = @fwrite($fp2, $contenu, $a = strlen($contenu)); |
|
| 241 | + $ok = ($s == $a); |
|
| 242 | + spip_fclose_unlock($fp2); |
|
| 243 | + spip_fclose_unlock($fp); |
|
| 244 | + $fp = null; |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS || @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + $fp = null; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + // sinon ou si methode precedente a echoueee |
|
| 266 | + // on se rabat sur la methode ancienne |
|
| 267 | + if (!$ok && !is_null($fp)) { |
|
| 268 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | + if ($truncate) { |
|
| 270 | + @ftruncate($fp, 0); |
|
| 271 | + } |
|
| 272 | + $s = @fwrite($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | + |
|
| 274 | + $ok = ($s == $a); |
|
| 275 | + spip_fclose_unlock($fp); |
|
| 276 | + } |
|
| 277 | + // on tente une dernière fois file_put_contents |
|
| 278 | + if (!$ok) { |
|
| 279 | + $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | + $ok = ($l === strlen($contenu)); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // liberer le verrou et fermer le fichier |
|
| 284 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | + if ($ok) { |
|
| 286 | + if (str_contains($fichier, '.php')) { |
|
| 287 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return $ok; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!$ignorer_echec) { |
|
| 295 | + include_spip('inc/autoriser'); |
|
| 296 | + if (autoriser('chargerftp')) { |
|
| 297 | + raler_fichier($fichier); |
|
| 298 | + } |
|
| 299 | + spip_unlink($fichier); |
|
| 300 | + } |
|
| 301 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | + |
|
| 303 | + return false; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -320,12 +320,12 @@ discard block |
||
| 320 | 320 | * Écriture avec troncation ? |
| 321 | 321 | */ |
| 322 | 322 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 323 | - if (!str_ends_with($fichier, '.php')) { |
|
| 324 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | - } |
|
| 326 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 323 | + if (!str_ends_with($fichier, '.php')) { |
|
| 324 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | + } |
|
| 326 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 327 | 327 | |
| 328 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 328 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -336,25 +336,25 @@ discard block |
||
| 336 | 336 | * @return bool |
| 337 | 337 | */ |
| 338 | 338 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 339 | - $fichier_tmp = $fichier . '.last'; |
|
| 340 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - if ( |
|
| 344 | - $force |
|
| 345 | - || !file_exists($fichier) |
|
| 346 | - || md5_file($fichier) !== md5_file($fichier_tmp) |
|
| 347 | - ) { |
|
| 348 | - if ($use_copy) { |
|
| 349 | - @copy($fichier_tmp, $fichier); |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - @rename($fichier_tmp, $fichier); |
|
| 353 | - } |
|
| 354 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | - clearstatcache(true, $fichier); |
|
| 356 | - } |
|
| 357 | - return true; |
|
| 339 | + $fichier_tmp = $fichier . '.last'; |
|
| 340 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + if ( |
|
| 344 | + $force |
|
| 345 | + || !file_exists($fichier) |
|
| 346 | + || md5_file($fichier) !== md5_file($fichier_tmp) |
|
| 347 | + ) { |
|
| 348 | + if ($use_copy) { |
|
| 349 | + @copy($fichier_tmp, $fichier); |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + @rename($fichier_tmp, $fichier); |
|
| 353 | + } |
|
| 354 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | + clearstatcache(true, $fichier); |
|
| 356 | + } |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | * true si l'opération a réussie, false sinon. |
| 376 | 376 | */ |
| 377 | 377 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 378 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | - $contenu = substr((string) $contenu, strlen('<?php die (\'Acces interdit\'); ?> |
|
| 378 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | + $contenu = substr((string) $contenu, strlen('<?php die (\'Acces interdit\'); ?> |
|
| 380 | 380 | ')); |
| 381 | - } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - return $res; |
|
| 383 | + return $res; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -395,25 +395,25 @@ discard block |
||
| 395 | 395 | * Chemin du fichier |
| 396 | 396 | **/ |
| 397 | 397 | function raler_fichier($fichier) { |
| 398 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 399 | - spip_initialisation_suite(); |
|
| 400 | - } |
|
| 401 | - include_spip('inc/minipres'); |
|
| 402 | - $dir = dirname($fichier); |
|
| 403 | - http_response_code(401); |
|
| 404 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 405 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 406 | - . " <a href='" |
|
| 407 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 408 | - . "'>" |
|
| 409 | - . _T('texte_inc_meta_2') |
|
| 410 | - . '</a> ' |
|
| 411 | - . _T( |
|
| 412 | - 'texte_inc_meta_3', |
|
| 413 | - ['repertoire' => joli_repertoire($dir)] |
|
| 414 | - ) |
|
| 415 | - . "</h4>\n"); |
|
| 416 | - exit; |
|
| 398 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 399 | + spip_initialisation_suite(); |
|
| 400 | + } |
|
| 401 | + include_spip('inc/minipres'); |
|
| 402 | + $dir = dirname($fichier); |
|
| 403 | + http_response_code(401); |
|
| 404 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 405 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 406 | + . " <a href='" |
|
| 407 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 408 | + . "'>" |
|
| 409 | + . _T('texte_inc_meta_2') |
|
| 410 | + . '</a> ' |
|
| 411 | + . _T( |
|
| 412 | + 'texte_inc_meta_3', |
|
| 413 | + ['repertoire' => joli_repertoire($dir)] |
|
| 414 | + ) |
|
| 415 | + . "</h4>\n"); |
|
| 416 | + exit; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | |
@@ -428,14 +428,14 @@ discard block |
||
| 428 | 428 | * - true si récent, false sinon |
| 429 | 429 | */ |
| 430 | 430 | function jeune_fichier($fichier, $n) { |
| 431 | - if (!file_exists($fichier)) { |
|
| 432 | - return false; |
|
| 433 | - } |
|
| 434 | - if (!$c = @filemtime($fichier)) { |
|
| 435 | - return false; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return (time() - $n <= $c); |
|
| 431 | + if (!file_exists($fichier)) { |
|
| 432 | + return false; |
|
| 433 | + } |
|
| 434 | + if (!$c = @filemtime($fichier)) { |
|
| 435 | + return false; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return (time() - $n <= $c); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | /** |
@@ -450,22 +450,22 @@ discard block |
||
| 450 | 450 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 451 | 451 | */ |
| 452 | 452 | function supprimer_fichier($fichier, $lock = true) { |
| 453 | - if (!@file_exists($fichier)) { |
|
| 454 | - return true; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if ($lock) { |
|
| 458 | - // verrouiller le fichier destination |
|
| 459 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // liberer le verrou |
|
| 464 | - spip_fclose_unlock($fp); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - // supprimer |
|
| 468 | - return @unlink($fichier); |
|
| 453 | + if (!@file_exists($fichier)) { |
|
| 454 | + return true; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if ($lock) { |
|
| 458 | + // verrouiller le fichier destination |
|
| 459 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // liberer le verrou |
|
| 464 | + spip_fclose_unlock($fp); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + // supprimer |
|
| 468 | + return @unlink($fichier); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
@@ -475,12 +475,12 @@ discard block |
||
| 475 | 475 | * Chemin du fichier |
| 476 | 476 | */ |
| 477 | 477 | function spip_unlink($f) { |
| 478 | - if (!is_dir($f)) { |
|
| 479 | - supprimer_fichier($f, false); |
|
| 480 | - } else { |
|
| 481 | - @unlink("$f/.ok"); |
|
| 482 | - @rmdir($f); |
|
| 483 | - } |
|
| 478 | + if (!is_dir($f)) { |
|
| 479 | + supprimer_fichier($f, false); |
|
| 480 | + } else { |
|
| 481 | + @unlink("$f/.ok"); |
|
| 482 | + @rmdir($f); |
|
| 483 | + } |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -494,26 +494,26 @@ discard block |
||
| 494 | 494 | * The absolute path of the PHP file to invalidate. |
| 495 | 495 | */ |
| 496 | 496 | function spip_clear_opcode_cache($filepath) { |
| 497 | - clearstatcache(true, $filepath); |
|
| 498 | - |
|
| 499 | - // Zend OPcache |
|
| 500 | - if (function_exists('opcache_invalidate')) { |
|
| 501 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 502 | - // si l'invalidation a echoue lever un flag |
|
| 503 | - if (!$invalidate && !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 504 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 505 | - } |
|
| 506 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 507 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 508 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 509 | - } |
|
| 510 | - // APC. |
|
| 511 | - if (function_exists('apc_delete_file')) { |
|
| 512 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 513 | - // not compiled yet. |
|
| 514 | - // @see http://php.net/apc-delete-file |
|
| 515 | - @apc_delete_file($filepath); |
|
| 516 | - } |
|
| 497 | + clearstatcache(true, $filepath); |
|
| 498 | + |
|
| 499 | + // Zend OPcache |
|
| 500 | + if (function_exists('opcache_invalidate')) { |
|
| 501 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 502 | + // si l'invalidation a echoue lever un flag |
|
| 503 | + if (!$invalidate && !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 504 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 505 | + } |
|
| 506 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 507 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 508 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 509 | + } |
|
| 510 | + // APC. |
|
| 511 | + if (function_exists('apc_delete_file')) { |
|
| 512 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 513 | + // not compiled yet. |
|
| 514 | + // @see http://php.net/apc-delete-file |
|
| 515 | + @apc_delete_file($filepath); |
|
| 516 | + } |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -536,25 +536,25 @@ discard block |
||
| 536 | 536 | * |
| 537 | 537 | */ |
| 538 | 538 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 539 | - if ( |
|
| 540 | - function_exists('opcache_get_configuration') |
|
| 541 | - && @ini_get('opcache.enable') |
|
| 542 | - && @ini_get('opcache.validate_timestamps') |
|
| 543 | - && (($duree = (int) @ini_get('opcache.revalidate_freq')) || ($duree = 2)) |
|
| 544 | - && defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 545 | - ) { |
|
| 546 | - $wait = $duree + 1; |
|
| 547 | - if ($timestamp) { |
|
| 548 | - $wait -= (time() - $timestamp); |
|
| 549 | - if ($wait < 0) { |
|
| 550 | - $wait = 0; |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 554 | - if ($wait) { |
|
| 555 | - sleep($duree + 1); |
|
| 556 | - } |
|
| 557 | - } |
|
| 539 | + if ( |
|
| 540 | + function_exists('opcache_get_configuration') |
|
| 541 | + && @ini_get('opcache.enable') |
|
| 542 | + && @ini_get('opcache.validate_timestamps') |
|
| 543 | + && (($duree = (int) @ini_get('opcache.revalidate_freq')) || ($duree = 2)) |
|
| 544 | + && defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 545 | + ) { |
|
| 546 | + $wait = $duree + 1; |
|
| 547 | + if ($timestamp) { |
|
| 548 | + $wait -= (time() - $timestamp); |
|
| 549 | + if ($wait < 0) { |
|
| 550 | + $wait = 0; |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 554 | + if ($wait) { |
|
| 555 | + sleep($duree + 1); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | |
@@ -567,26 +567,26 @@ discard block |
||
| 567 | 567 | * @return bool Suppression reussie. |
| 568 | 568 | */ |
| 569 | 569 | function supprimer_repertoire($dir) { |
| 570 | - if (!file_exists($dir)) { |
|
| 571 | - return true; |
|
| 572 | - } |
|
| 573 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 574 | - return @unlink($dir); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - foreach (scandir($dir) as $item) { |
|
| 578 | - if ($item == '.' || $item == '..') { |
|
| 579 | - continue; |
|
| 580 | - } |
|
| 581 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 582 | - @chmod($dir . '/' . $item, 0777); |
|
| 583 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 584 | - return false; |
|
| 585 | - } |
|
| 586 | - }; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return @rmdir($dir); |
|
| 570 | + if (!file_exists($dir)) { |
|
| 571 | + return true; |
|
| 572 | + } |
|
| 573 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 574 | + return @unlink($dir); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + foreach (scandir($dir) as $item) { |
|
| 578 | + if ($item == '.' || $item == '..') { |
|
| 579 | + continue; |
|
| 580 | + } |
|
| 581 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 582 | + @chmod($dir . '/' . $item, 0777); |
|
| 583 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 584 | + return false; |
|
| 585 | + } |
|
| 586 | + }; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return @rmdir($dir); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
@@ -615,57 +615,57 @@ discard block |
||
| 615 | 615 | * Chemin du répertoire créé. |
| 616 | 616 | **/ |
| 617 | 617 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 618 | - static $dirs = []; |
|
| 619 | - |
|
| 620 | - $base = str_replace('//', '/', $base); |
|
| 621 | - |
|
| 622 | - # suppr le dernier caractere si c'est un / |
|
| 623 | - $base = rtrim($base, '/'); |
|
| 624 | - |
|
| 625 | - if (!strlen($subdir)) { |
|
| 626 | - $n = strrpos($base, '/'); |
|
| 627 | - if ($n === false) { |
|
| 628 | - return $nobase ? '' : ($base . '/'); |
|
| 629 | - } |
|
| 630 | - $subdir = substr($base, $n + 1); |
|
| 631 | - $base = substr($base, 0, $n + 1); |
|
| 632 | - } else { |
|
| 633 | - $base .= '/'; |
|
| 634 | - $subdir = str_replace('/', '', $subdir); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - $baseaff = $nobase ? '' : $base; |
|
| 638 | - if (isset($dirs[$base . $subdir])) { |
|
| 639 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 643 | - |
|
| 644 | - if (file_exists("$path/.ok")) { |
|
| 645 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - @mkdir($path, _SPIP_CHMOD); |
|
| 649 | - @chmod($path, _SPIP_CHMOD); |
|
| 650 | - |
|
| 651 | - if (is_dir($path) && is_writable($path)) { |
|
| 652 | - @touch("$path/.ok"); |
|
| 653 | - spip_log("creation $base$subdir/"); |
|
| 654 | - |
|
| 655 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 659 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 660 | - spip_log("echec creation $base{$subdir}"); |
|
| 661 | - if ($tantpis) { |
|
| 662 | - return ''; |
|
| 663 | - } |
|
| 664 | - if (!_DIR_RESTREINT) { |
|
| 665 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 666 | - } |
|
| 667 | - $base .= $subdir; |
|
| 668 | - raler_fichier($base . '/.ok'); |
|
| 618 | + static $dirs = []; |
|
| 619 | + |
|
| 620 | + $base = str_replace('//', '/', $base); |
|
| 621 | + |
|
| 622 | + # suppr le dernier caractere si c'est un / |
|
| 623 | + $base = rtrim($base, '/'); |
|
| 624 | + |
|
| 625 | + if (!strlen($subdir)) { |
|
| 626 | + $n = strrpos($base, '/'); |
|
| 627 | + if ($n === false) { |
|
| 628 | + return $nobase ? '' : ($base . '/'); |
|
| 629 | + } |
|
| 630 | + $subdir = substr($base, $n + 1); |
|
| 631 | + $base = substr($base, 0, $n + 1); |
|
| 632 | + } else { |
|
| 633 | + $base .= '/'; |
|
| 634 | + $subdir = str_replace('/', '', $subdir); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + $baseaff = $nobase ? '' : $base; |
|
| 638 | + if (isset($dirs[$base . $subdir])) { |
|
| 639 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 643 | + |
|
| 644 | + if (file_exists("$path/.ok")) { |
|
| 645 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + @mkdir($path, _SPIP_CHMOD); |
|
| 649 | + @chmod($path, _SPIP_CHMOD); |
|
| 650 | + |
|
| 651 | + if (is_dir($path) && is_writable($path)) { |
|
| 652 | + @touch("$path/.ok"); |
|
| 653 | + spip_log("creation $base$subdir/"); |
|
| 654 | + |
|
| 655 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 659 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 660 | + spip_log("echec creation $base{$subdir}"); |
|
| 661 | + if ($tantpis) { |
|
| 662 | + return ''; |
|
| 663 | + } |
|
| 664 | + if (!_DIR_RESTREINT) { |
|
| 665 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 666 | + } |
|
| 667 | + $base .= $subdir; |
|
| 668 | + raler_fichier($base . '/.ok'); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | |
@@ -698,56 +698,56 @@ discard block |
||
| 698 | 698 | * Chemins des fichiers trouvés. |
| 699 | 699 | **/ |
| 700 | 700 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 701 | - $nbfiles = 0; |
|
| 702 | - if ($pattern == -1) { |
|
| 703 | - $pattern = ''; |
|
| 704 | - } |
|
| 705 | - $fichiers = []; |
|
| 706 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 707 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 708 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 709 | - if ($dir == '') { |
|
| 710 | - $dir = '.'; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 714 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 715 | - if ( |
|
| 716 | - $f[0] != '.' |
|
| 717 | - && $f != 'CVS' |
|
| 718 | - && $f != 'remove.txt' |
|
| 719 | - && is_readable($f = "$dir/$f") |
|
| 720 | - ) { |
|
| 721 | - if (is_file($f)) { |
|
| 722 | - if (!$pattern || preg_match(";$pattern;iS", $f)) { |
|
| 723 | - $fichiers[] = $f; |
|
| 724 | - $nbfiles++; |
|
| 725 | - } |
|
| 726 | - } else { |
|
| 727 | - if (is_dir($f) && is_array($recurs)) { |
|
| 728 | - $rp = @realpath($f); |
|
| 729 | - if (!is_string($rp) || !strlen($rp)) { |
|
| 730 | - $rp = $f; |
|
| 731 | - } # realpath n'est peut etre pas autorise |
|
| 732 | - if (!isset($recurs[$rp])) { |
|
| 733 | - $recurs[$rp] = true; |
|
| 734 | - $beginning = $fichiers; |
|
| 735 | - $end = preg_files( |
|
| 736 | - "$f/", |
|
| 737 | - $pattern, |
|
| 738 | - $maxfiles - $nbfiles, |
|
| 739 | - $recurs |
|
| 740 | - ); |
|
| 741 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 742 | - $nbfiles = count($fichiers); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - closedir($d); |
|
| 749 | - } |
|
| 750 | - sort($fichiers); |
|
| 751 | - |
|
| 752 | - return $fichiers; |
|
| 701 | + $nbfiles = 0; |
|
| 702 | + if ($pattern == -1) { |
|
| 703 | + $pattern = ''; |
|
| 704 | + } |
|
| 705 | + $fichiers = []; |
|
| 706 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 707 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 708 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 709 | + if ($dir == '') { |
|
| 710 | + $dir = '.'; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 714 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 715 | + if ( |
|
| 716 | + $f[0] != '.' |
|
| 717 | + && $f != 'CVS' |
|
| 718 | + && $f != 'remove.txt' |
|
| 719 | + && is_readable($f = "$dir/$f") |
|
| 720 | + ) { |
|
| 721 | + if (is_file($f)) { |
|
| 722 | + if (!$pattern || preg_match(";$pattern;iS", $f)) { |
|
| 723 | + $fichiers[] = $f; |
|
| 724 | + $nbfiles++; |
|
| 725 | + } |
|
| 726 | + } else { |
|
| 727 | + if (is_dir($f) && is_array($recurs)) { |
|
| 728 | + $rp = @realpath($f); |
|
| 729 | + if (!is_string($rp) || !strlen($rp)) { |
|
| 730 | + $rp = $f; |
|
| 731 | + } # realpath n'est peut etre pas autorise |
|
| 732 | + if (!isset($recurs[$rp])) { |
|
| 733 | + $recurs[$rp] = true; |
|
| 734 | + $beginning = $fichiers; |
|
| 735 | + $end = preg_files( |
|
| 736 | + "$f/", |
|
| 737 | + $pattern, |
|
| 738 | + $maxfiles - $nbfiles, |
|
| 739 | + $recurs |
|
| 740 | + ); |
|
| 741 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 742 | + $nbfiles = count($fichiers); |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + closedir($d); |
|
| 749 | + } |
|
| 750 | + sort($fichiers); |
|
| 751 | + |
|
| 752 | + return $fichiers; |
|
| 753 | 753 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $contenu = @gzfile($fichier); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - return is_array($contenu) ? implode('', $contenu) : (string)$contenu; |
|
| 124 | + return is_array($contenu) ? implode('', $contenu) : (string) $contenu; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -321,9 +321,9 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 323 | 323 | if (!str_ends_with($fichier, '.php')) { |
| 324 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 324 | + spip_log('Erreur de programmation: '.$fichier.' doit finir par .php'); |
|
| 325 | 325 | } |
| 326 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 326 | + $contenu = '<'."?php die ('Acces interdit'); ?".">\n".$contenu; |
|
| 327 | 327 | |
| 328 | 328 | return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
| 329 | 329 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * @return bool |
| 337 | 337 | */ |
| 338 | 338 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 339 | - $fichier_tmp = $fichier . '.last'; |
|
| 339 | + $fichier_tmp = $fichier.'.last'; |
|
| 340 | 340 | if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
| 341 | 341 | return false; |
| 342 | 342 | } |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | $wait = 0; |
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 553 | + spip_log('Probleme de configuration opcache.revalidate_freq '.$duree.'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 554 | 554 | if ($wait) { |
| 555 | 555 | sleep($duree + 1); |
| 556 | 556 | } |
@@ -578,9 +578,9 @@ discard block |
||
| 578 | 578 | if ($item == '.' || $item == '..') { |
| 579 | 579 | continue; |
| 580 | 580 | } |
| 581 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 582 | - @chmod($dir . '/' . $item, 0777); |
|
| 583 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | + if (!supprimer_repertoire($dir.'/'.$item)) { |
|
| 582 | + @chmod($dir.'/'.$item, 0777); |
|
| 583 | + if (!supprimer_repertoire($dir.'/'.$item)) { |
|
| 584 | 584 | return false; |
| 585 | 585 | } |
| 586 | 586 | }; |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | if (!strlen($subdir)) { |
| 626 | 626 | $n = strrpos($base, '/'); |
| 627 | 627 | if ($n === false) { |
| 628 | - return $nobase ? '' : ($base . '/'); |
|
| 628 | + return $nobase ? '' : ($base.'/'); |
|
| 629 | 629 | } |
| 630 | 630 | $subdir = substr($base, $n + 1); |
| 631 | 631 | $base = substr($base, 0, $n + 1); |
@@ -635,14 +635,14 @@ discard block |
||
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | $baseaff = $nobase ? '' : $base; |
| 638 | - if (isset($dirs[$base . $subdir])) { |
|
| 639 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 638 | + if (isset($dirs[$base.$subdir])) { |
|
| 639 | + return $baseaff.$dirs[$base.$subdir]; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 642 | + $path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 643 | 643 | |
| 644 | 644 | if (file_exists("$path/.ok")) { |
| 645 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 645 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | @mkdir($path, _SPIP_CHMOD); |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | @touch("$path/.ok"); |
| 653 | 653 | spip_log("creation $base$subdir/"); |
| 654 | 654 | |
| 655 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 655 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
@@ -662,10 +662,10 @@ discard block |
||
| 662 | 662 | return ''; |
| 663 | 663 | } |
| 664 | 664 | if (!_DIR_RESTREINT) { |
| 665 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 665 | + $base = preg_replace(',^'._DIR_RACINE.',', '', $base); |
|
| 666 | 666 | } |
| 667 | 667 | $base .= $subdir; |
| 668 | - raler_fichier($base . '/.ok'); |
|
| 668 | + raler_fichier($base.'/.ok'); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | $maxfiles - $nbfiles, |
| 739 | 739 | $recurs |
| 740 | 740 | ); |
| 741 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 741 | + $fichiers = array_merge((array) $beginning, (array) $end); |
|
| 742 | 742 | $nbfiles = count($fichiers); |
| 743 | 743 | } |
| 744 | 744 | } |
@@ -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 | /** |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * Pile complétée par le code à générer |
| 43 | 43 | */ |
| 44 | 44 | function balise_ALERTE_MESSAGE_dist($p) { |
| 45 | - $_texte = interprete_argument_balise(1, $p); |
|
| 46 | - $_titre = interprete_argument_balise(2, $p); |
|
| 47 | - $_class = interprete_argument_balise(3, $p); |
|
| 48 | - $_role = interprete_argument_balise(4, $p); |
|
| 49 | - $_id = interprete_argument_balise(5, $p); |
|
| 50 | - $_texte = ($_texte ?: "''"); |
|
| 51 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 52 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 53 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 45 | + $_texte = interprete_argument_balise(1, $p); |
|
| 46 | + $_titre = interprete_argument_balise(2, $p); |
|
| 47 | + $_class = interprete_argument_balise(3, $p); |
|
| 48 | + $_role = interprete_argument_balise(4, $p); |
|
| 49 | + $_id = interprete_argument_balise(5, $p); |
|
| 50 | + $_texte = ($_texte ?: "''"); |
|
| 51 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 52 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 53 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 55 | 55 | |
| 56 | - $f = chercher_filtre('message_alerte'); |
|
| 57 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 58 | - $p->interdire_scripts = false; |
|
| 56 | + $f = chercher_filtre('message_alerte'); |
|
| 57 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 58 | + $p->interdire_scripts = false; |
|
| 59 | 59 | |
| 60 | - return $p; |
|
| 60 | + return $p; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -85,20 +85,20 @@ discard block |
||
| 85 | 85 | * Pile complétée par le code à générer |
| 86 | 86 | */ |
| 87 | 87 | function balise_ALERTE_OUVRIR_dist($p) { |
| 88 | - $_titre = interprete_argument_balise(1, $p); |
|
| 89 | - $_class = interprete_argument_balise(2, $p); |
|
| 90 | - $_role = interprete_argument_balise(3, $p); |
|
| 91 | - $_id = interprete_argument_balise(4, $p); |
|
| 92 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 94 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 88 | + $_titre = interprete_argument_balise(1, $p); |
|
| 89 | + $_class = interprete_argument_balise(2, $p); |
|
| 90 | + $_role = interprete_argument_balise(3, $p); |
|
| 91 | + $_id = interprete_argument_balise(4, $p); |
|
| 92 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 94 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 96 | 96 | |
| 97 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 98 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 99 | - $p->interdire_scripts = false; |
|
| 97 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 98 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 99 | + $p->interdire_scripts = false; |
|
| 100 | 100 | |
| 101 | - return $p; |
|
| 101 | + return $p; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | * Pile complétée par le code à générer |
| 121 | 121 | */ |
| 122 | 122 | function balise_ALERTE_FERMER_dist($p) { |
| 123 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 124 | - $p->code = "$f()"; |
|
| 125 | - $p->interdire_scripts = false; |
|
| 123 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 124 | + $p->code = "$f()"; |
|
| 125 | + $p->interdire_scripts = false; |
|
| 126 | 126 | |
| 127 | - return $p; |
|
| 127 | + return $p; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -159,12 +159,12 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 161 | 161 | |
| 162 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 163 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 162 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 163 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 164 | 164 | |
| 165 | - return $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 166 | - $texte . |
|
| 167 | - $message_alerte_fermer(); |
|
| 165 | + return $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 166 | + $texte . |
|
| 167 | + $message_alerte_fermer(); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -195,53 +195,53 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 197 | 197 | |
| 198 | - $prive = test_espace_prive(); |
|
| 198 | + $prive = test_espace_prive(); |
|
| 199 | 199 | |
| 200 | - // Valeurs par défaut |
|
| 201 | - $titre = trim($titre ?? ''); |
|
| 202 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 203 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 200 | + // Valeurs par défaut |
|
| 201 | + $titre = trim($titre ?? ''); |
|
| 202 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 203 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 204 | 204 | |
| 205 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 206 | - $types = [ |
|
| 207 | - 'notice', |
|
| 208 | - 'error', |
|
| 209 | - 'success', |
|
| 210 | - 'info', |
|
| 211 | - ]; |
|
| 212 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 213 | - $type = reset($type); |
|
| 214 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 205 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 206 | + $types = [ |
|
| 207 | + 'notice', |
|
| 208 | + 'error', |
|
| 209 | + 'success', |
|
| 210 | + 'info', |
|
| 211 | + ]; |
|
| 212 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 213 | + $type = reset($type); |
|
| 214 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 215 | 215 | |
| 216 | - // Classes |
|
| 217 | - $class_racine = 'msg-alert'; |
|
| 218 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 219 | - $class_alerte = "$class_racine $class"; |
|
| 220 | - $class_texte = "{$class_racine}__text $clearfix"; |
|
| 221 | - $class_titre = "{$class_racine}__heading"; |
|
| 216 | + // Classes |
|
| 217 | + $class_racine = 'msg-alert'; |
|
| 218 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 219 | + $class_alerte = "$class_racine $class"; |
|
| 220 | + $class_texte = "{$class_racine}__text $clearfix"; |
|
| 221 | + $class_titre = "{$class_racine}__heading"; |
|
| 222 | 222 | |
| 223 | - // Titre : markup |
|
| 224 | - $titre = trim($titre); |
|
| 225 | - if (strlen($titre)) { |
|
| 226 | - include_spip('inc/filtres'); |
|
| 227 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 228 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 229 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 230 | - if (!str_starts_with($titre, $cherche_tag)) { |
|
| 231 | - $titre = wrap($titre, $wrap_tag); |
|
| 232 | - } |
|
| 233 | - // puis on ajoute la classe |
|
| 234 | - $titre = ajouter_class($titre, $class_titre); |
|
| 235 | - } |
|
| 223 | + // Titre : markup |
|
| 224 | + $titre = trim($titre); |
|
| 225 | + if (strlen($titre)) { |
|
| 226 | + include_spip('inc/filtres'); |
|
| 227 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 228 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 229 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 230 | + if (!str_starts_with($titre, $cherche_tag)) { |
|
| 231 | + $titre = wrap($titre, $wrap_tag); |
|
| 232 | + } |
|
| 233 | + // puis on ajoute la classe |
|
| 234 | + $titre = ajouter_class($titre, $class_titre); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - // Attributs |
|
| 238 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 239 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 240 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 237 | + // Attributs |
|
| 238 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 239 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 240 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 241 | 241 | |
| 242 | - return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 243 | - . $titre |
|
| 244 | - . "<div class=\"$class_texte\">"; |
|
| 242 | + return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 243 | + . $titre |
|
| 244 | + . "<div class=\"$class_texte\">"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -255,5 +255,5 @@ discard block |
||
| 255 | 255 | * HTML de fin de l'alerte |
| 256 | 256 | */ |
| 257 | 257 | function message_alerte_fermer(): string { |
| 258 | - return '</div></div>'; |
|
| 258 | + return '</div></div>'; |
|
| 259 | 259 | } |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | $_texte = ($_texte ?: "''"); |
| 51 | 51 | $_titre = ($_titre ? ", $_titre" : ', null'); |
| 52 | 52 | $_class = ($_class ? ", $_class" : ', null'); |
| 53 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 53 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 55 | 55 | |
| 56 | 56 | $f = chercher_filtre('message_alerte'); |
| 57 | 57 | $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | $_class = interprete_argument_balise(2, $p); |
| 90 | 90 | $_role = interprete_argument_balise(3, $p); |
| 91 | 91 | $_id = interprete_argument_balise(4, $p); |
| 92 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 92 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | 93 | $_class = ($_class ? ", $_class" : ', null'); |
| 94 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 94 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 96 | 96 | |
| 97 | 97 | $f = chercher_filtre('message_alerte_ouvrir'); |
| 98 | 98 | $p->code = "$f($_titre$_class$_role$_id)"; |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
| 163 | 163 | $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
| 164 | 164 | |
| 165 | - return $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 166 | - $texte . |
|
| 165 | + return $message_alerte_ouvrir($titre, $class, $role, $id). |
|
| 166 | + $texte. |
|
| 167 | 167 | $message_alerte_fermer(); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | ]; |
| 212 | 212 | $type = array_intersect(explode(' ', $class), $types); |
| 213 | 213 | $type = reset($type); |
| 214 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 214 | + $class = trim(str_replace($types, '', $class)." $type"); |
|
| 215 | 215 | |
| 216 | 216 | // Classes |
| 217 | 217 | $class_racine = 'msg-alert'; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // Attributs |
| 238 | 238 | $attr_role = ($role ? "role=\"$role\"" : ''); |
| 239 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 239 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 240 | 240 | $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
| 241 | 241 | |
| 242 | 242 | return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/config'); |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | * @return array|false |
| 32 | 32 | */ |
| 33 | 33 | function cvtconf_formulaire_charger($flux) { |
| 34 | - if ( |
|
| 35 | - ($form = $flux['args']['form']) |
|
| 36 | - && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 37 | - ) { |
|
| 38 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 39 | - include_spip('inc/autoriser'); |
|
| 40 | - if (!autoriser('configurer', '_' . substr((string) $form, 11))) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 34 | + if ( |
|
| 35 | + ($form = $flux['args']['form']) |
|
| 36 | + && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 37 | + ) { |
|
| 38 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 39 | + include_spip('inc/autoriser'); |
|
| 40 | + if (!autoriser('configurer', '_' . substr((string) $form, 11))) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 45 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 46 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 47 | - $flux['data']['editable'] = true; |
|
| 48 | - if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 49 | - if (!_AJAX) { |
|
| 50 | - var_dump($flux['data']); |
|
| 51 | - } |
|
| 52 | - // reinjecter pour la trace au traitement |
|
| 53 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 44 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 45 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 46 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 47 | + $flux['data']['editable'] = true; |
|
| 48 | + if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 49 | + if (!_AJAX) { |
|
| 50 | + var_dump($flux['data']); |
|
| 51 | + } |
|
| 52 | + // reinjecter pour la trace au traitement |
|
| 53 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $flux; |
|
| 58 | + return $flux; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | 67 | function cvtconf_formulaire_traiter($flux) { |
| 68 | - if ( |
|
| 69 | - ($form = $flux['args']['form']) |
|
| 70 | - && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 71 | - && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 72 | - ) { |
|
| 73 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 74 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | - } |
|
| 68 | + if ( |
|
| 69 | + ($form = $flux['args']['form']) |
|
| 70 | + && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 71 | + && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 72 | + ) { |
|
| 73 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 74 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return $flux; |
|
| 77 | + return $flux; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -90,32 +90,32 @@ discard block |
||
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | 92 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 93 | - $valeurs = []; |
|
| 94 | - // charger les valeurs |
|
| 95 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 96 | - // qui prend alors la main sur l'auto detection |
|
| 97 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 98 | - $valeurs = $charger_valeurs(...$args); |
|
| 99 | - } |
|
| 100 | - $valeurs = pipeline( |
|
| 101 | - 'formulaire_charger', |
|
| 102 | - [ |
|
| 103 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 104 | - 'data' => $valeurs |
|
| 105 | - ] |
|
| 106 | - ); |
|
| 107 | - // ne pas stocker editable ! |
|
| 108 | - unset($valeurs['editable']); |
|
| 93 | + $valeurs = []; |
|
| 94 | + // charger les valeurs |
|
| 95 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 96 | + // qui prend alors la main sur l'auto detection |
|
| 97 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 98 | + $valeurs = $charger_valeurs(...$args); |
|
| 99 | + } |
|
| 100 | + $valeurs = pipeline( |
|
| 101 | + 'formulaire_charger', |
|
| 102 | + [ |
|
| 103 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 104 | + 'data' => $valeurs |
|
| 105 | + ] |
|
| 106 | + ); |
|
| 107 | + // ne pas stocker editable ! |
|
| 108 | + unset($valeurs['editable']); |
|
| 109 | 109 | |
| 110 | - // recuperer les valeurs postees |
|
| 111 | - $store = []; |
|
| 112 | - foreach ($valeurs as $k => $v) { |
|
| 113 | - if (!str_starts_with((string) $k, '_')) { |
|
| 114 | - $store[$k] = _request($k); |
|
| 115 | - } |
|
| 116 | - } |
|
| 110 | + // recuperer les valeurs postees |
|
| 111 | + $store = []; |
|
| 112 | + foreach ($valeurs as $k => $v) { |
|
| 113 | + if (!str_starts_with((string) $k, '_')) { |
|
| 114 | + $store[$k] = _request($k); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 118 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,31 +131,31 @@ discard block |
||
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | 133 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 134 | - // stocker en base |
|
| 135 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 136 | - $casier = substr($form, 11); |
|
| 137 | - $table = 'meta'; |
|
| 138 | - $prefixe = ''; |
|
| 139 | - $stockage = ''; |
|
| 134 | + // stocker en base |
|
| 135 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 136 | + $casier = substr($form, 11); |
|
| 137 | + $table = 'meta'; |
|
| 138 | + $prefixe = ''; |
|
| 139 | + $stockage = ''; |
|
| 140 | 140 | |
| 141 | - if (isset($valeurs['_meta_casier'])) { |
|
| 142 | - $casier = $valeurs['_meta_casier']; |
|
| 143 | - } |
|
| 144 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 145 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 146 | - } |
|
| 147 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 148 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | - } |
|
| 141 | + if (isset($valeurs['_meta_casier'])) { |
|
| 142 | + $casier = $valeurs['_meta_casier']; |
|
| 143 | + } |
|
| 144 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 145 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 146 | + } |
|
| 147 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 148 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 152 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 153 | - if (isset($valeurs['_meta_table'])) { |
|
| 154 | - $table = $valeurs['_meta_table']; |
|
| 155 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 156 | - } |
|
| 151 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 152 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 153 | + if (isset($valeurs['_meta_table'])) { |
|
| 154 | + $table = $valeurs['_meta_table']; |
|
| 155 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 158 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -166,49 +166,49 @@ discard block |
||
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | 168 | function cvtconf_formulaires_configurer_recense($form) { |
| 169 | - $contenu = null; |
|
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 169 | + $contenu = null; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | - && 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 | + && 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 | - && preg_match(',^([\w\-]+)(\[\w*\])?$,', (string) $n, $r) |
|
| 194 | - && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - && 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 (str_starts_with($r[1], '_meta_')) { |
|
| 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 | + && preg_match(',^([\w\-]+)(\[\w*\])?$,', (string) $n, $r) |
|
| 194 | + && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + && 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 (str_starts_with($r[1], '_meta_')) { |
|
| 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((string) $casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim((string) $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' && 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' && 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 (array_keys($valeurs) as $k) { |
|
| 265 | - if (!str_starts_with($k, '_')) { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach (array_keys($valeurs) as $k) { |
|
| 265 | + if (!str_starts_with($k, '_')) { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ) { |
| 38 | 38 | // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
| 39 | 39 | include_spip('inc/autoriser'); |
| 40 | - if (!autoriser('configurer', '_' . substr((string) $form, 11))) { |
|
| 40 | + if (!autoriser('configurer', '_'.substr((string) $form, 11))) { |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
| 72 | 72 | ) { |
| 73 | 73 | $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
| 74 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 74 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | return $flux; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $prefixe = $valeurs['_meta_prefixe']; |
| 146 | 146 | } |
| 147 | 147 | if (isset($valeurs['_meta_stockage'])) { |
| 148 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 148 | + $stockage = $valeurs['_meta_stockage'].'::'; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // 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 | && 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((string) $casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 233 | + $casier = ($casier) ? rtrim((string) $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' && 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 (array_keys($valeurs) as $k) { |
| 265 | 265 | if (!str_starts_with($k, '_')) { |
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe.$k] ?? null); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Affichage |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @return string Code HTML |
| 25 | 25 | */ |
| 26 | 26 | function debut_grand_cadre() { |
| 27 | - return "\n<div class = 'table_page'>\n"; |
|
| 27 | + return "\n<div class = 'table_page'>\n"; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return string Code HTML |
| 34 | 34 | */ |
| 35 | 35 | function fin_grand_cadre() { |
| 36 | - return "\n</div>"; |
|
| 36 | + return "\n</div>"; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // Debut de la colonne de gauche |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return string Code HTML |
| 49 | 49 | */ |
| 50 | 50 | function debut_gauche() { |
| 51 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 51 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @return string Code HTML |
| 58 | 58 | */ |
| 59 | 59 | function fin_gauche() { |
| 60 | - return "</div></div><br class = 'nettoyeur' />"; |
|
| 60 | + return "</div></div><br class = 'nettoyeur' />"; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | * @return string Code HTML |
| 67 | 67 | */ |
| 68 | 68 | function creer_colonne_droite() { |
| 69 | - static $deja_colonne_droite; |
|
| 70 | - if ($deja_colonne_droite) { |
|
| 71 | - return ''; |
|
| 72 | - } |
|
| 73 | - $deja_colonne_droite = true; |
|
| 69 | + static $deja_colonne_droite; |
|
| 70 | + if ($deja_colonne_droite) { |
|
| 71 | + return ''; |
|
| 72 | + } |
|
| 73 | + $deja_colonne_droite = true; |
|
| 74 | 74 | |
| 75 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 75 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | * @return string Code HTML |
| 82 | 82 | */ |
| 83 | 83 | function debut_droite() { |
| 84 | - return liste_objets_bloques(_request('exec')) |
|
| 85 | - . creer_colonne_droite() |
|
| 86 | - . '</div>' |
|
| 87 | - . "\n<div id='contenu'>"; |
|
| 84 | + return liste_objets_bloques(_request('exec')) |
|
| 85 | + . creer_colonne_droite() |
|
| 86 | + . '</div>' |
|
| 87 | + . "\n<div id='contenu'>"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -106,32 +106,32 @@ discard block |
||
| 106 | 106 | * Code HTML |
| 107 | 107 | **/ |
| 108 | 108 | function liste_objets_bloques($exec, $contexte = [], $auteur = null): string { |
| 109 | - $res = ''; |
|
| 110 | - include_spip('inc/config'); |
|
| 111 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 112 | - include_spip('inc/drapeau_edition'); |
|
| 113 | - if (is_null($auteur)) { |
|
| 114 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | - } |
|
| 116 | - if ( |
|
| 117 | - ($en_cours = trouver_objet_exec($exec)) |
|
| 118 | - && $en_cours['edition'] |
|
| 119 | - && ($type = $en_cours['type']) |
|
| 120 | - && (isset($contexte[$en_cours['id_table_objet']]) |
|
| 121 | - && ($id = $contexte[$en_cours['id_table_objet']]) || ($id = _request($en_cours['id_table_objet']))) |
|
| 122 | - ) { |
|
| 123 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | - signale_edition($id, $auteur, $type); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | - if ($objets_ouverts !== []) { |
|
| 130 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $res; |
|
| 109 | + $res = ''; |
|
| 110 | + include_spip('inc/config'); |
|
| 111 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 112 | + include_spip('inc/drapeau_edition'); |
|
| 113 | + if (is_null($auteur)) { |
|
| 114 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | + } |
|
| 116 | + if ( |
|
| 117 | + ($en_cours = trouver_objet_exec($exec)) |
|
| 118 | + && $en_cours['edition'] |
|
| 119 | + && ($type = $en_cours['type']) |
|
| 120 | + && (isset($contexte[$en_cours['id_table_objet']]) |
|
| 121 | + && ($id = $contexte[$en_cours['id_table_objet']]) || ($id = _request($en_cours['id_table_objet']))) |
|
| 122 | + ) { |
|
| 123 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | + signale_edition($id, $auteur, $type); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | + if ($objets_ouverts !== []) { |
|
| 130 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $res; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -145,23 +145,23 @@ discard block |
||
| 145 | 145 | * @return string Code HTML |
| 146 | 146 | **/ |
| 147 | 147 | function fin_page() { |
| 148 | - include_spip('inc/pipelines'); |
|
| 149 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | - $debug = (_request('exec') !== 'valider_xml' |
|
| 151 | - && ( |
|
| 152 | - _request('var_mode') == 'debug' |
|
| 153 | - || isset($GLOBALS['tableau_des_temps']) && $GLOBALS['tableau_des_temps'] |
|
| 154 | - && isset($_COOKIE['spip_admin']) |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 158 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 159 | - . '</div>' |
|
| 160 | - . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 161 | - . ($debug ? erreur_squelette() : '') |
|
| 162 | - . "</body></html>\n"; |
|
| 163 | - |
|
| 164 | - return f_queue($t); |
|
| 148 | + include_spip('inc/pipelines'); |
|
| 149 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | + $debug = (_request('exec') !== 'valider_xml' |
|
| 151 | + && ( |
|
| 152 | + _request('var_mode') == 'debug' |
|
| 153 | + || isset($GLOBALS['tableau_des_temps']) && $GLOBALS['tableau_des_temps'] |
|
| 154 | + && isset($_COOKIE['spip_admin']) |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 158 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 159 | + . '</div>' |
|
| 160 | + . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 161 | + . ($debug ? erreur_squelette() : '') |
|
| 162 | + . "</body></html>\n"; |
|
| 163 | + |
|
| 164 | + return f_queue($t); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | * @return string Code HTML |
| 177 | 177 | **/ |
| 178 | 178 | function html_tests_js() { |
| 179 | - if (_SPIP_AJAX && !defined('_TESTER_NOSCRIPT')) { |
|
| 180 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 181 | - define( |
|
| 182 | - '_TESTER_NOSCRIPT', |
|
| 183 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 184 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 185 | - . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $rejouer = ''; |
|
| 190 | - if (defined('_SESSION_REJOUER')) { |
|
| 191 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 179 | + if (_SPIP_AJAX && !defined('_TESTER_NOSCRIPT')) { |
|
| 180 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 181 | + define( |
|
| 182 | + '_TESTER_NOSCRIPT', |
|
| 183 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 184 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 185 | + . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $rejouer = ''; |
|
| 190 | + if (defined('_SESSION_REJOUER')) { |
|
| 191 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -201,25 +201,25 @@ discard block |
||
| 201 | 201 | **/ |
| 202 | 202 | function info_maj_spip() { |
| 203 | 203 | |
| 204 | - $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 205 | - if (!$maj) { |
|
| 206 | - return ''; |
|
| 207 | - } |
|
| 204 | + $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 205 | + if (!$maj) { |
|
| 206 | + return ''; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - $maj = explode('|', (string) $maj); |
|
| 210 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 211 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 212 | - return ''; |
|
| 213 | - } |
|
| 209 | + $maj = explode('|', (string) $maj); |
|
| 210 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 211 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 212 | + return ''; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - if (!autoriser('webmestre')) { |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 215 | + if (!autoriser('webmestre')) { |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - array_shift($maj); |
|
| 220 | - $maj = implode('|', $maj); |
|
| 219 | + array_shift($maj); |
|
| 220 | + $maj = implode('|', $maj); |
|
| 221 | 221 | |
| 222 | - return "$maj<br />"; |
|
| 222 | + return "$maj<br />"; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
@@ -230,43 +230,43 @@ discard block |
||
| 230 | 230 | **/ |
| 231 | 231 | function info_copyright() { |
| 232 | 232 | |
| 233 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 234 | - |
|
| 235 | - // |
|
| 236 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 237 | - // |
|
| 238 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 239 | - if ($vcs['vcs'] === 'GIT') { |
|
| 240 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 241 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 242 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 243 | - } else { |
|
| 244 | - $url = ''; |
|
| 245 | - } |
|
| 246 | - // affichage "GIT [master: abcdef]" |
|
| 247 | - $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 248 | - if ($url) { |
|
| 249 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 250 | - } |
|
| 251 | - if ($vcs['branch']) { |
|
| 252 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 253 | - } |
|
| 254 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // et la version de l'ecran de securite |
|
| 258 | - $secu = defined('_ECRAN_SECURITE') |
|
| 259 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 260 | - : ''; |
|
| 261 | - |
|
| 262 | - return _T( |
|
| 263 | - 'info_copyright', |
|
| 264 | - [ |
|
| 265 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 266 | - 'lien_gpl' => '<a href="https://www.gnu.org/licenses/gpl-3.0.html">' . _T('info_copyright_gpl') . '</a>' |
|
| 267 | - ] |
|
| 268 | - ) |
|
| 269 | - . $secu; |
|
| 233 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 234 | + |
|
| 235 | + // |
|
| 236 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 237 | + // |
|
| 238 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 239 | + if ($vcs['vcs'] === 'GIT') { |
|
| 240 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 241 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 242 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 243 | + } else { |
|
| 244 | + $url = ''; |
|
| 245 | + } |
|
| 246 | + // affichage "GIT [master: abcdef]" |
|
| 247 | + $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 248 | + if ($url) { |
|
| 249 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 250 | + } |
|
| 251 | + if ($vcs['branch']) { |
|
| 252 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 253 | + } |
|
| 254 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // et la version de l'ecran de securite |
|
| 258 | + $secu = defined('_ECRAN_SECURITE') |
|
| 259 | + ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 260 | + : ''; |
|
| 261 | + |
|
| 262 | + return _T( |
|
| 263 | + 'info_copyright', |
|
| 264 | + [ |
|
| 265 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 266 | + 'lien_gpl' => '<a href="https://www.gnu.org/licenses/gpl-3.0.html">' . _T('info_copyright_gpl') . '</a>' |
|
| 267 | + ] |
|
| 268 | + ) |
|
| 269 | + . $secu; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -281,17 +281,17 @@ discard block |
||
| 281 | 281 | * @return string Code HTML |
| 282 | 282 | **/ |
| 283 | 283 | function formulaire_recherche($page, $complement = '') { |
| 284 | - $recherche = _request('recherche'); |
|
| 285 | - $recherche_aff = entites_html($recherche); |
|
| 286 | - if (!strlen((string) $recherche)) { |
|
| 287 | - $recherche_aff = _T('info_rechercher'); |
|
| 288 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 289 | - } else { |
|
| 290 | - $onfocus = ''; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 294 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 295 | - |
|
| 296 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 284 | + $recherche = _request('recherche'); |
|
| 285 | + $recherche_aff = entites_html($recherche); |
|
| 286 | + if (!strlen((string) $recherche)) { |
|
| 287 | + $recherche_aff = _T('info_rechercher'); |
|
| 288 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 289 | + } else { |
|
| 290 | + $onfocus = ''; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 294 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 295 | + |
|
| 296 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 297 | 297 | } |