@@ -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 | |
@@ -47,71 +47,71 @@ discard block |
||
| 47 | 47 | * Nom de la fonction, ou false. |
| 48 | 48 | */ |
| 49 | 49 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 50 | - static $echecs = []; |
|
| 51 | - |
|
| 52 | - if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
|
| 53 | - $dossier .= '/'; |
|
| 54 | - } |
|
| 55 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 56 | - |
|
| 57 | - if (function_exists($f)) { |
|
| 58 | - return $f; |
|
| 59 | - } |
|
| 60 | - if (function_exists($g = $f . '_dist')) { |
|
| 61 | - return $g; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (isset($echecs[$f])) { |
|
| 65 | - return $echecs[$f]; |
|
| 66 | - } |
|
| 67 | - // Sinon charger le fichier de declaration si plausible |
|
| 68 | - |
|
| 69 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 70 | - if ($continue) { |
|
| 71 | - return false; |
|
| 72 | - } //appel interne, on passe |
|
| 73 | - include_spip('inc/minipres'); |
|
| 74 | - echo minipres(); |
|
| 75 | - exit; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // passer en minuscules (cf les balises de formulaires) |
|
| 79 | - // et inclure le fichier |
|
| 80 | - if ( |
|
| 81 | - !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 82 | - && strlen(dirname($dossier)) |
|
| 83 | - && dirname($dossier) != '.' |
|
| 84 | - ) { |
|
| 85 | - include_spip(substr($dossier, 0, -1)); |
|
| 86 | - } |
|
| 87 | - if (function_exists($f)) { |
|
| 88 | - return $f; |
|
| 89 | - } |
|
| 90 | - if (function_exists($g)) { |
|
| 91 | - return $g; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ($continue) { |
|
| 95 | - return $echecs[$f] = false; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Echec : message d'erreur |
|
| 99 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 100 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 101 | - |
|
| 102 | - include_spip('inc/minipres'); |
|
| 103 | - include_spip('inc/filtres_mini'); |
|
| 104 | - echo minipres( |
|
| 105 | - _T('forum_titre_erreur'), |
|
| 106 | - $inc ? |
|
| 107 | - _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 108 | - . '<br />' |
|
| 109 | - . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 110 | - : |
|
| 111 | - _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 112 | - ['all_inline' => true,'status' => 404] |
|
| 113 | - ); |
|
| 114 | - exit; |
|
| 50 | + static $echecs = []; |
|
| 51 | + |
|
| 52 | + if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
|
| 53 | + $dossier .= '/'; |
|
| 54 | + } |
|
| 55 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 56 | + |
|
| 57 | + if (function_exists($f)) { |
|
| 58 | + return $f; |
|
| 59 | + } |
|
| 60 | + if (function_exists($g = $f . '_dist')) { |
|
| 61 | + return $g; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (isset($echecs[$f])) { |
|
| 65 | + return $echecs[$f]; |
|
| 66 | + } |
|
| 67 | + // Sinon charger le fichier de declaration si plausible |
|
| 68 | + |
|
| 69 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 70 | + if ($continue) { |
|
| 71 | + return false; |
|
| 72 | + } //appel interne, on passe |
|
| 73 | + include_spip('inc/minipres'); |
|
| 74 | + echo minipres(); |
|
| 75 | + exit; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // passer en minuscules (cf les balises de formulaires) |
|
| 79 | + // et inclure le fichier |
|
| 80 | + if ( |
|
| 81 | + !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 82 | + && strlen(dirname($dossier)) |
|
| 83 | + && dirname($dossier) != '.' |
|
| 84 | + ) { |
|
| 85 | + include_spip(substr($dossier, 0, -1)); |
|
| 86 | + } |
|
| 87 | + if (function_exists($f)) { |
|
| 88 | + return $f; |
|
| 89 | + } |
|
| 90 | + if (function_exists($g)) { |
|
| 91 | + return $g; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ($continue) { |
|
| 95 | + return $echecs[$f] = false; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Echec : message d'erreur |
|
| 99 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 100 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 101 | + |
|
| 102 | + include_spip('inc/minipres'); |
|
| 103 | + include_spip('inc/filtres_mini'); |
|
| 104 | + echo minipres( |
|
| 105 | + _T('forum_titre_erreur'), |
|
| 106 | + $inc ? |
|
| 107 | + _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 108 | + . '<br />' |
|
| 109 | + . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 110 | + : |
|
| 111 | + _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 112 | + ['all_inline' => true,'status' => 404] |
|
| 113 | + ); |
|
| 114 | + exit; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -121,17 +121,17 @@ discard block |
||
| 121 | 121 | * @return bool |
| 122 | 122 | */ |
| 123 | 123 | function include_once_check($file) { |
| 124 | - if (file_exists($file)) { |
|
| 125 | - include_once $file; |
|
| 124 | + if (file_exists($file)) { |
|
| 125 | + include_once $file; |
|
| 126 | 126 | |
| 127 | - return true; |
|
| 128 | - } |
|
| 129 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 130 | - $crash = ($crash ?: []); |
|
| 131 | - $crash[$file] = true; |
|
| 132 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 127 | + return true; |
|
| 128 | + } |
|
| 129 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 130 | + $crash = ($crash ?: []); |
|
| 131 | + $crash[$file] = true; |
|
| 132 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 133 | 133 | |
| 134 | - return false; |
|
| 134 | + return false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * - string : chemin du fichier trouvé |
| 156 | 156 | **/ |
| 157 | 157 | function include_spip($f, $include = true) { |
| 158 | - return find_in_path($f . '.php', '', $include); |
|
| 158 | + return find_in_path($f . '.php', '', $include); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * - string : chemin du fichier trouvé |
| 176 | 176 | **/ |
| 177 | 177 | function require_spip($f) { |
| 178 | - return find_in_path($f . '.php', '', 'required'); |
|
| 178 | + return find_in_path($f . '.php', '', 'required'); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -184,27 +184,27 @@ discard block |
||
| 184 | 184 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 185 | 185 | */ |
| 186 | 186 | function include_fichiers_fonctions() { |
| 187 | - static $done = false; |
|
| 188 | - if (!$done) { |
|
| 189 | - include_spip('inc/lang'); |
|
| 190 | - |
|
| 191 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 192 | - // donc il faut l'inclure "en globals" |
|
| 193 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 194 | - global $dossier_squelettes; |
|
| 195 | - include_once(_ROOT_CWD . $f); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 199 | - // chargement optimise precompile |
|
| 200 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 201 | - } |
|
| 202 | - if (test_espace_prive()) { |
|
| 203 | - include_spip('inc/filtres_ecrire'); |
|
| 204 | - } |
|
| 205 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 206 | - $done = true; |
|
| 207 | - } |
|
| 187 | + static $done = false; |
|
| 188 | + if (!$done) { |
|
| 189 | + include_spip('inc/lang'); |
|
| 190 | + |
|
| 191 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 192 | + // donc il faut l'inclure "en globals" |
|
| 193 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 194 | + global $dossier_squelettes; |
|
| 195 | + include_once(_ROOT_CWD . $f); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 199 | + // chargement optimise precompile |
|
| 200 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 201 | + } |
|
| 202 | + if (test_espace_prive()) { |
|
| 203 | + include_spip('inc/filtres_ecrire'); |
|
| 204 | + } |
|
| 205 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 206 | + $done = true; |
|
| 207 | + } |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -230,23 +230,23 @@ discard block |
||
| 230 | 230 | * Les paramètres du pipeline modifiés |
| 231 | 231 | **/ |
| 232 | 232 | function minipipe($fonc, &$val) { |
| 233 | - // fonction |
|
| 234 | - if (function_exists($fonc)) { |
|
| 235 | - $val = $fonc($val); |
|
| 236 | - } // Class::Methode |
|
| 237 | - else { |
|
| 238 | - if ( |
|
| 239 | - preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 240 | - && ($methode = [$regs[1], $regs[2]]) |
|
| 241 | - && is_callable($methode) |
|
| 242 | - ) { |
|
| 243 | - $val = $methode($val); |
|
| 244 | - } else { |
|
| 245 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $val; |
|
| 233 | + // fonction |
|
| 234 | + if (function_exists($fonc)) { |
|
| 235 | + $val = $fonc($val); |
|
| 236 | + } // Class::Methode |
|
| 237 | + else { |
|
| 238 | + if ( |
|
| 239 | + preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 240 | + && ($methode = [$regs[1], $regs[2]]) |
|
| 241 | + && is_callable($methode) |
|
| 242 | + ) { |
|
| 243 | + $val = $methode($val); |
|
| 244 | + } else { |
|
| 245 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $val; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -277,46 +277,46 @@ discard block |
||
| 277 | 277 | * Résultat |
| 278 | 278 | */ |
| 279 | 279 | function pipeline($action, $val = null) { |
| 280 | - static $charger; |
|
| 281 | - |
|
| 282 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 283 | - if (!$charger) { |
|
| 284 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 285 | - include_spip('inc/plugin'); |
|
| 286 | - // generer les fichiers php precompiles |
|
| 287 | - // de chargement des plugins et des pipelines |
|
| 288 | - actualise_plugins_actifs(); |
|
| 289 | - if (!($ok = @is_readable($charger))) { |
|
| 290 | - spip_log("fichier $charger pas cree"); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if ($ok) { |
|
| 295 | - include_once $charger; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - // appliquer notre fonction si elle existe |
|
| 300 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 301 | - if (function_exists($fonc)) { |
|
| 302 | - $val = $fonc($val); |
|
| 303 | - } // plantage ? |
|
| 304 | - else { |
|
| 305 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // si le flux est une table avec 2 cle args&data |
|
| 309 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 310 | - // array_key_exists pour php 4.1.0 |
|
| 311 | - if ( |
|
| 312 | - is_array($val) |
|
| 313 | - && count($val) == 2 |
|
| 314 | - && array_key_exists('data', $val) |
|
| 315 | - ) { |
|
| 316 | - $val = $val['data']; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $val; |
|
| 280 | + static $charger; |
|
| 281 | + |
|
| 282 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 283 | + if (!$charger) { |
|
| 284 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 285 | + include_spip('inc/plugin'); |
|
| 286 | + // generer les fichiers php precompiles |
|
| 287 | + // de chargement des plugins et des pipelines |
|
| 288 | + actualise_plugins_actifs(); |
|
| 289 | + if (!($ok = @is_readable($charger))) { |
|
| 290 | + spip_log("fichier $charger pas cree"); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if ($ok) { |
|
| 295 | + include_once $charger; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // appliquer notre fonction si elle existe |
|
| 300 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 301 | + if (function_exists($fonc)) { |
|
| 302 | + $val = $fonc($val); |
|
| 303 | + } // plantage ? |
|
| 304 | + else { |
|
| 305 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // si le flux est une table avec 2 cle args&data |
|
| 309 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 310 | + // array_key_exists pour php 4.1.0 |
|
| 311 | + if ( |
|
| 312 | + is_array($val) |
|
| 313 | + && count($val) == 2 |
|
| 314 | + && array_key_exists('data', $val) |
|
| 315 | + ) { |
|
| 316 | + $val = $val['data']; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $val; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -360,38 +360,38 @@ discard block |
||
| 360 | 360 | * paramètre est planté pour cause de compatibilité ascendante. |
| 361 | 361 | */ |
| 362 | 362 | function spip_log($message = null, $name = null) { |
| 363 | - static $pre = []; |
|
| 364 | - static $log; |
|
| 365 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 366 | - if (!isset($regs[1]) || !$logname = $regs[1]) { |
|
| 367 | - $logname = null; |
|
| 368 | - } |
|
| 369 | - if (!isset($regs[2])) { |
|
| 370 | - $niveau = _LOG_INFO; |
|
| 371 | - } |
|
| 372 | - else { |
|
| 373 | - $niveau = intval($regs[2]); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 377 | - if (!$pre) { |
|
| 378 | - $pre = [ |
|
| 379 | - _LOG_HS => 'HS:', |
|
| 380 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 381 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 382 | - _LOG_ERREUR => 'ERREUR:', |
|
| 383 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 384 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 385 | - _LOG_INFO => 'info:', |
|
| 386 | - _LOG_DEBUG => 'debug:' |
|
| 387 | - ]; |
|
| 388 | - $log = charger_fonction('log', 'inc'); |
|
| 389 | - } |
|
| 390 | - if (!is_string($message)) { |
|
| 391 | - $message = print_r($message, true); |
|
| 392 | - } |
|
| 393 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 394 | - } |
|
| 363 | + static $pre = []; |
|
| 364 | + static $log; |
|
| 365 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 366 | + if (!isset($regs[1]) || !$logname = $regs[1]) { |
|
| 367 | + $logname = null; |
|
| 368 | + } |
|
| 369 | + if (!isset($regs[2])) { |
|
| 370 | + $niveau = _LOG_INFO; |
|
| 371 | + } |
|
| 372 | + else { |
|
| 373 | + $niveau = intval($regs[2]); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 377 | + if (!$pre) { |
|
| 378 | + $pre = [ |
|
| 379 | + _LOG_HS => 'HS:', |
|
| 380 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 381 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 382 | + _LOG_ERREUR => 'ERREUR:', |
|
| 383 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 384 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 385 | + _LOG_INFO => 'info:', |
|
| 386 | + _LOG_DEBUG => 'debug:' |
|
| 387 | + ]; |
|
| 388 | + $log = charger_fonction('log', 'inc'); |
|
| 389 | + } |
|
| 390 | + if (!is_string($message)) { |
|
| 391 | + $message = print_r($message, true); |
|
| 392 | + } |
|
| 393 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | * @param array $opt Tableau d'options |
| 404 | 404 | **/ |
| 405 | 405 | function journal($phrase, $opt = []) { |
| 406 | - $journal = charger_fonction('journal', 'inc'); |
|
| 407 | - $journal($phrase, $opt); |
|
| 406 | + $journal = charger_fonction('journal', 'inc'); |
|
| 407 | + $journal($phrase, $opt); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | |
@@ -423,37 +423,37 @@ discard block |
||
| 423 | 423 | **/ |
| 424 | 424 | function _request($var, $c = false) { |
| 425 | 425 | |
| 426 | - if (is_array($c)) { |
|
| 427 | - return $c[$var] ?? null; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if (isset($_GET[$var])) { |
|
| 431 | - $a = $_GET[$var]; |
|
| 432 | - } elseif (isset($_POST[$var])) { |
|
| 433 | - $a = $_POST[$var]; |
|
| 434 | - } else { |
|
| 435 | - return null; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - // Si on est en ajax et en POST tout a ete encode |
|
| 439 | - // via encodeURIComponent, il faut donc repasser |
|
| 440 | - // dans le charset local... |
|
| 441 | - if ( |
|
| 442 | - defined('_AJAX') |
|
| 443 | - && _AJAX |
|
| 444 | - && isset($GLOBALS['meta']['charset']) |
|
| 445 | - && $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 446 | - // check rapide mais pas fiable |
|
| 447 | - && is_string($a) |
|
| 448 | - && preg_match(',[\x80-\xFF],', $a) |
|
| 449 | - // check fiable |
|
| 450 | - && include_spip('inc/charsets') |
|
| 451 | - && is_utf8($a) |
|
| 452 | - ) { |
|
| 453 | - return importer_charset($a, 'utf-8'); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return $a; |
|
| 426 | + if (is_array($c)) { |
|
| 427 | + return $c[$var] ?? null; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if (isset($_GET[$var])) { |
|
| 431 | + $a = $_GET[$var]; |
|
| 432 | + } elseif (isset($_POST[$var])) { |
|
| 433 | + $a = $_POST[$var]; |
|
| 434 | + } else { |
|
| 435 | + return null; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + // Si on est en ajax et en POST tout a ete encode |
|
| 439 | + // via encodeURIComponent, il faut donc repasser |
|
| 440 | + // dans le charset local... |
|
| 441 | + if ( |
|
| 442 | + defined('_AJAX') |
|
| 443 | + && _AJAX |
|
| 444 | + && isset($GLOBALS['meta']['charset']) |
|
| 445 | + && $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 446 | + // check rapide mais pas fiable |
|
| 447 | + && is_string($a) |
|
| 448 | + && preg_match(',[\x80-\xFF],', $a) |
|
| 449 | + // check fiable |
|
| 450 | + && include_spip('inc/charsets') |
|
| 451 | + && is_utf8($a) |
|
| 452 | + ) { |
|
| 453 | + return importer_charset($a, 'utf-8'); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return $a; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | |
@@ -471,22 +471,22 @@ discard block |
||
| 471 | 471 | * - false sinon |
| 472 | 472 | **/ |
| 473 | 473 | function set_request($var, $val = null, $c = false) { |
| 474 | - if (is_array($c)) { |
|
| 475 | - unset($c[$var]); |
|
| 476 | - if ($val !== null) { |
|
| 477 | - $c[$var] = $val; |
|
| 478 | - } |
|
| 474 | + if (is_array($c)) { |
|
| 475 | + unset($c[$var]); |
|
| 476 | + if ($val !== null) { |
|
| 477 | + $c[$var] = $val; |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - return $c; |
|
| 481 | - } |
|
| 480 | + return $c; |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - unset($_GET[$var]); |
|
| 484 | - unset($_POST[$var]); |
|
| 485 | - if ($val !== null) { |
|
| 486 | - $_GET[$var] = $val; |
|
| 487 | - } |
|
| 483 | + unset($_GET[$var]); |
|
| 484 | + unset($_POST[$var]); |
|
| 485 | + if ($val !== null) { |
|
| 486 | + $_GET[$var] = $val; |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - return false; # n'affecte pas $c |
|
| 489 | + return false; # n'affecte pas $c |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -506,25 +506,25 @@ discard block |
||
| 506 | 506 | * @return array|mixed|string |
| 507 | 507 | */ |
| 508 | 508 | function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') { |
| 509 | - if (is_array($value)) { |
|
| 510 | - if ($key == '*') { |
|
| 511 | - $key = array_keys($value); |
|
| 512 | - } |
|
| 513 | - if (!is_array($key)) { |
|
| 514 | - $key = [$key]; |
|
| 515 | - } |
|
| 516 | - foreach ($key as $k) { |
|
| 517 | - if (!empty($value[$k])) { |
|
| 518 | - $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - return $value; |
|
| 522 | - } |
|
| 523 | - // si la valeur vient des GET ou POST on la sanitize |
|
| 524 | - if (!empty($value) && $value == _request($key)) { |
|
| 525 | - $value = $sanitize_function($value); |
|
| 526 | - } |
|
| 527 | - return $value; |
|
| 509 | + if (is_array($value)) { |
|
| 510 | + if ($key == '*') { |
|
| 511 | + $key = array_keys($value); |
|
| 512 | + } |
|
| 513 | + if (!is_array($key)) { |
|
| 514 | + $key = [$key]; |
|
| 515 | + } |
|
| 516 | + foreach ($key as $k) { |
|
| 517 | + if (!empty($value[$k])) { |
|
| 518 | + $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + return $value; |
|
| 522 | + } |
|
| 523 | + // si la valeur vient des GET ou POST on la sanitize |
|
| 524 | + if (!empty($value) && $value == _request($key)) { |
|
| 525 | + $value = $sanitize_function($value); |
|
| 526 | + } |
|
| 527 | + return $value; |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -532,23 +532,22 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * On est sur le web, on exclut certains protocoles, |
| 534 | 534 | * notamment 'file://', 'php://' et d'autres… |
| 535 | - |
|
| 536 | 535 | * @param string $url |
| 537 | 536 | * @return bool |
| 538 | 537 | */ |
| 539 | 538 | function tester_url_absolue($url) { |
| 540 | - $url = trim($url ?? ''); |
|
| 541 | - if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 542 | - if ( |
|
| 543 | - isset($m[1]) |
|
| 544 | - && ($p = strtolower(rtrim($m[1], ':'))) |
|
| 545 | - && in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 546 | - ) { |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - return true; |
|
| 550 | - } |
|
| 551 | - return false; |
|
| 539 | + $url = trim($url ?? ''); |
|
| 540 | + if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 541 | + if ( |
|
| 542 | + isset($m[1]) |
|
| 543 | + && ($p = strtolower(rtrim($m[1], ':'))) |
|
| 544 | + && in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 545 | + ) { |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 548 | + return true; |
|
| 549 | + } |
|
| 550 | + return false; |
|
| 552 | 551 | } |
| 553 | 552 | |
| 554 | 553 | /** |
@@ -570,100 +569,100 @@ discard block |
||
| 570 | 569 | * @return string URL |
| 571 | 570 | */ |
| 572 | 571 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 573 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 574 | - if (str_contains($c, '|') && is_null($v)) { |
|
| 575 | - return null; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - // lever l'#ancre |
|
| 579 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 580 | - $url = $r[1]; |
|
| 581 | - $ancre = $r[2]; |
|
| 582 | - } else { |
|
| 583 | - $ancre = ''; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // eclater |
|
| 587 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 588 | - |
|
| 589 | - // recuperer la base |
|
| 590 | - $a = array_shift($url); |
|
| 591 | - if (!$a) { |
|
| 592 | - $a = './'; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // preparer la regexp de maniere securisee |
|
| 596 | - $regexp = explode('|', $c); |
|
| 597 | - foreach ($regexp as $r => $e) { |
|
| 598 | - $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e)); |
|
| 599 | - } |
|
| 600 | - $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,'; |
|
| 601 | - $ajouts = array_flip(explode('|', $c)); |
|
| 602 | - $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 603 | - $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 604 | - $v_read = null; |
|
| 605 | - // lire les variables et agir |
|
| 606 | - foreach ($url as $n => $val) { |
|
| 607 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 608 | - $r = array_pad($r, 3, null); |
|
| 609 | - if ($v === null) { |
|
| 610 | - // c'est un tableau, on memorise les valeurs |
|
| 611 | - if (str_ends_with($r[1], '[]')) { |
|
| 612 | - if (!$v_read) { |
|
| 613 | - $v_read = []; |
|
| 614 | - } |
|
| 615 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 616 | - } // c'est un scalaire, on retourne direct |
|
| 617 | - else { |
|
| 618 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 619 | - } |
|
| 620 | - } // suppression |
|
| 621 | - elseif (!$testv) { |
|
| 622 | - unset($url[$n]); |
|
| 623 | - } |
|
| 624 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 625 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 626 | - elseif (!str_ends_with($r[1], '[]')) { |
|
| 627 | - $url[$n] = $r[1] . '=' . $u; |
|
| 628 | - unset($ajouts[$r[1]]); |
|
| 629 | - } |
|
| 630 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 631 | - // départ, on remplira à l'étape suivante |
|
| 632 | - else { |
|
| 633 | - unset($url[$n]); |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - // traiter les parametres pas encore trouves |
|
| 639 | - if ( |
|
| 640 | - $v === null |
|
| 641 | - && ($args = func_get_args()) |
|
| 642 | - && count($args) == 2 |
|
| 643 | - ) { |
|
| 644 | - return $v_read; // rien trouve ou un tableau |
|
| 645 | - } elseif ($testv) { |
|
| 646 | - foreach ($ajouts as $k => $n) { |
|
| 647 | - if (!is_array($v)) { |
|
| 648 | - $url[] = $k . '=' . $u; |
|
| 649 | - } else { |
|
| 650 | - $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]'); |
|
| 651 | - foreach ($v as $w) { |
|
| 652 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // eliminer les vides |
|
| 659 | - $url = array_filter($url); |
|
| 660 | - |
|
| 661 | - // recomposer l'adresse |
|
| 662 | - if ($url) { |
|
| 663 | - $a .= '?' . join($sep, $url); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $a . $ancre; |
|
| 572 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 573 | + if (str_contains($c, '|') && is_null($v)) { |
|
| 574 | + return null; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // lever l'#ancre |
|
| 578 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 579 | + $url = $r[1]; |
|
| 580 | + $ancre = $r[2]; |
|
| 581 | + } else { |
|
| 582 | + $ancre = ''; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + // eclater |
|
| 586 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 587 | + |
|
| 588 | + // recuperer la base |
|
| 589 | + $a = array_shift($url); |
|
| 590 | + if (!$a) { |
|
| 591 | + $a = './'; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + // preparer la regexp de maniere securisee |
|
| 595 | + $regexp = explode('|', $c); |
|
| 596 | + foreach ($regexp as $r => $e) { |
|
| 597 | + $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e)); |
|
| 598 | + } |
|
| 599 | + $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,'; |
|
| 600 | + $ajouts = array_flip(explode('|', $c)); |
|
| 601 | + $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 602 | + $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 603 | + $v_read = null; |
|
| 604 | + // lire les variables et agir |
|
| 605 | + foreach ($url as $n => $val) { |
|
| 606 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 607 | + $r = array_pad($r, 3, null); |
|
| 608 | + if ($v === null) { |
|
| 609 | + // c'est un tableau, on memorise les valeurs |
|
| 610 | + if (str_ends_with($r[1], '[]')) { |
|
| 611 | + if (!$v_read) { |
|
| 612 | + $v_read = []; |
|
| 613 | + } |
|
| 614 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 615 | + } // c'est un scalaire, on retourne direct |
|
| 616 | + else { |
|
| 617 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 618 | + } |
|
| 619 | + } // suppression |
|
| 620 | + elseif (!$testv) { |
|
| 621 | + unset($url[$n]); |
|
| 622 | + } |
|
| 623 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 624 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 625 | + elseif (!str_ends_with($r[1], '[]')) { |
|
| 626 | + $url[$n] = $r[1] . '=' . $u; |
|
| 627 | + unset($ajouts[$r[1]]); |
|
| 628 | + } |
|
| 629 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 630 | + // départ, on remplira à l'étape suivante |
|
| 631 | + else { |
|
| 632 | + unset($url[$n]); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + // traiter les parametres pas encore trouves |
|
| 638 | + if ( |
|
| 639 | + $v === null |
|
| 640 | + && ($args = func_get_args()) |
|
| 641 | + && count($args) == 2 |
|
| 642 | + ) { |
|
| 643 | + return $v_read; // rien trouve ou un tableau |
|
| 644 | + } elseif ($testv) { |
|
| 645 | + foreach ($ajouts as $k => $n) { |
|
| 646 | + if (!is_array($v)) { |
|
| 647 | + $url[] = $k . '=' . $u; |
|
| 648 | + } else { |
|
| 649 | + $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]'); |
|
| 650 | + foreach ($v as $w) { |
|
| 651 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // eliminer les vides |
|
| 658 | + $url = array_filter($url); |
|
| 659 | + |
|
| 660 | + // recomposer l'adresse |
|
| 661 | + if ($url) { |
|
| 662 | + $a .= '?' . join($sep, $url); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return $a . $ancre; |
|
| 667 | 666 | } |
| 668 | 667 | |
| 669 | 668 | /** |
@@ -678,22 +677,22 @@ discard block |
||
| 678 | 677 | * @uses translitteration() |
| 679 | 678 | */ |
| 680 | 679 | function ancre_url(string $url, ?string $ancre = ''): string { |
| 681 | - $ancre ??= ''; |
|
| 682 | - // lever l'#ancre |
|
| 683 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 684 | - $url = $r[1]; |
|
| 685 | - } |
|
| 686 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 687 | - if (!function_exists('translitteration')) { |
|
| 688 | - include_spip('inc/charsets'); |
|
| 689 | - } |
|
| 690 | - $ancre = preg_replace( |
|
| 691 | - ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 692 | - ['', '-'], |
|
| 693 | - translitteration($ancre) |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 680 | + $ancre ??= ''; |
|
| 681 | + // lever l'#ancre |
|
| 682 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 683 | + $url = $r[1]; |
|
| 684 | + } |
|
| 685 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 686 | + if (!function_exists('translitteration')) { |
|
| 687 | + include_spip('inc/charsets'); |
|
| 688 | + } |
|
| 689 | + $ancre = preg_replace( |
|
| 690 | + ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 691 | + ['', '-'], |
|
| 692 | + translitteration($ancre) |
|
| 693 | + ); |
|
| 694 | + } |
|
| 695 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 697 | 696 | } |
| 698 | 697 | |
| 699 | 698 | /** |
@@ -703,16 +702,16 @@ discard block |
||
| 703 | 702 | * @return string |
| 704 | 703 | */ |
| 705 | 704 | function nettoyer_uri($reset = null) { |
| 706 | - static $done = false; |
|
| 707 | - static $propre = ''; |
|
| 708 | - if (!is_null($reset)) { |
|
| 709 | - return $propre = $reset; |
|
| 710 | - } |
|
| 711 | - if ($done) { |
|
| 712 | - return $propre; |
|
| 713 | - } |
|
| 714 | - $done = true; |
|
| 715 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 705 | + static $done = false; |
|
| 706 | + static $propre = ''; |
|
| 707 | + if (!is_null($reset)) { |
|
| 708 | + return $propre = $reset; |
|
| 709 | + } |
|
| 710 | + if ($done) { |
|
| 711 | + return $propre; |
|
| 712 | + } |
|
| 713 | + $done = true; |
|
| 714 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 716 | 715 | } |
| 717 | 716 | |
| 718 | 717 | /** |
@@ -727,36 +726,36 @@ discard block |
||
| 727 | 726 | * @return string |
| 728 | 727 | */ |
| 729 | 728 | function nettoyer_uri_var($request_uri) { |
| 730 | - static $preg_nettoyer; |
|
| 731 | - if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
|
| 732 | - /** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */ |
|
| 733 | - define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']); |
|
| 734 | - } |
|
| 735 | - if (empty($preg_nettoyer)) { |
|
| 736 | - $preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES; |
|
| 737 | - foreach ($preg_nettoyer_vars as &$var) { |
|
| 738 | - if (str_starts_with($var, '^')) { |
|
| 739 | - $var = substr($var, 1); |
|
| 740 | - } else { |
|
| 741 | - $var = '[^=&]*' . $var; |
|
| 742 | - } |
|
| 743 | - if (str_ends_with($var, '$')) { |
|
| 744 | - $var = substr($var, 0, -1); |
|
| 745 | - } else { |
|
| 746 | - $var .= '[^=&]*'; |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i'; |
|
| 750 | - } |
|
| 751 | - if (empty($request_uri)) { |
|
| 752 | - return $request_uri; |
|
| 753 | - } |
|
| 754 | - $uri1 = $request_uri; |
|
| 755 | - do { |
|
| 756 | - $uri = $uri1; |
|
| 757 | - $uri1 = preg_replace($preg_nettoyer, '\1', $uri); |
|
| 758 | - } while ($uri <> $uri1); |
|
| 759 | - return rtrim($uri1, '?&'); |
|
| 729 | + static $preg_nettoyer; |
|
| 730 | + if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
|
| 731 | + /** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */ |
|
| 732 | + define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']); |
|
| 733 | + } |
|
| 734 | + if (empty($preg_nettoyer)) { |
|
| 735 | + $preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES; |
|
| 736 | + foreach ($preg_nettoyer_vars as &$var) { |
|
| 737 | + if (str_starts_with($var, '^')) { |
|
| 738 | + $var = substr($var, 1); |
|
| 739 | + } else { |
|
| 740 | + $var = '[^=&]*' . $var; |
|
| 741 | + } |
|
| 742 | + if (str_ends_with($var, '$')) { |
|
| 743 | + $var = substr($var, 0, -1); |
|
| 744 | + } else { |
|
| 745 | + $var .= '[^=&]*'; |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i'; |
|
| 749 | + } |
|
| 750 | + if (empty($request_uri)) { |
|
| 751 | + return $request_uri; |
|
| 752 | + } |
|
| 753 | + $uri1 = $request_uri; |
|
| 754 | + do { |
|
| 755 | + $uri = $uri1; |
|
| 756 | + $uri1 = preg_replace($preg_nettoyer, '\1', $uri); |
|
| 757 | + } while ($uri <> $uri1); |
|
| 758 | + return rtrim($uri1, '?&'); |
|
| 760 | 759 | } |
| 761 | 760 | |
| 762 | 761 | |
@@ -770,49 +769,49 @@ discard block |
||
| 770 | 769 | * URL vers soi-même |
| 771 | 770 | **/ |
| 772 | 771 | function self($amp = '&', $root = false) { |
| 773 | - $url = nettoyer_uri(); |
|
| 774 | - if ( |
|
| 775 | - !$root |
|
| 776 | - && ( |
|
| 777 | - // si pas de profondeur on peut tronquer |
|
| 778 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 779 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 780 | - || defined('_SET_HTML_BASE') && !_SET_HTML_BASE |
|
| 781 | - ) |
|
| 782 | - ) { |
|
| 783 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 784 | - } |
|
| 785 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 786 | - foreach ($_POST as $v => $c) { |
|
| 787 | - if (str_starts_with($v, 'id_')) { |
|
| 788 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - // supprimer les variables sans interet |
|
| 793 | - if (test_espace_prive()) { |
|
| 794 | - $url = preg_replace(',([?&])(' |
|
| 795 | - . 'lang|show_docs|' |
|
| 796 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 797 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 798 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // eviter les hacks |
|
| 802 | - include_spip('inc/filtres_mini'); |
|
| 803 | - $url = spip_htmlspecialchars($url); |
|
| 804 | - |
|
| 805 | - $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 806 | - |
|
| 807 | - // & ? |
|
| 808 | - if ($amp != '&') { |
|
| 809 | - $url = str_replace('&', $amp, $url); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - // Si ca demarre par ? ou vide, donner './' |
|
| 813 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 814 | - |
|
| 815 | - return $url; |
|
| 772 | + $url = nettoyer_uri(); |
|
| 773 | + if ( |
|
| 774 | + !$root |
|
| 775 | + && ( |
|
| 776 | + // si pas de profondeur on peut tronquer |
|
| 777 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 778 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 779 | + || defined('_SET_HTML_BASE') && !_SET_HTML_BASE |
|
| 780 | + ) |
|
| 781 | + ) { |
|
| 782 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 783 | + } |
|
| 784 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 785 | + foreach ($_POST as $v => $c) { |
|
| 786 | + if (str_starts_with($v, 'id_')) { |
|
| 787 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // supprimer les variables sans interet |
|
| 792 | + if (test_espace_prive()) { |
|
| 793 | + $url = preg_replace(',([?&])(' |
|
| 794 | + . 'lang|show_docs|' |
|
| 795 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 796 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 797 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + // eviter les hacks |
|
| 801 | + include_spip('inc/filtres_mini'); |
|
| 802 | + $url = spip_htmlspecialchars($url); |
|
| 803 | + |
|
| 804 | + $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 805 | + |
|
| 806 | + // & ? |
|
| 807 | + if ($amp != '&') { |
|
| 808 | + $url = str_replace('&', $amp, $url); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + // Si ca demarre par ? ou vide, donner './' |
|
| 812 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 813 | + |
|
| 814 | + return $url; |
|
| 816 | 815 | } |
| 817 | 816 | |
| 818 | 817 | |
@@ -823,7 +822,7 @@ discard block |
||
| 823 | 822 | * true si c'est le cas, false sinon. |
| 824 | 823 | */ |
| 825 | 824 | function test_espace_prive() { |
| 826 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 825 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 827 | 826 | } |
| 828 | 827 | |
| 829 | 828 | /** |
@@ -833,7 +832,7 @@ discard block |
||
| 833 | 832 | * @return bool |
| 834 | 833 | */ |
| 835 | 834 | function test_plugin_actif($plugin) { |
| 836 | - return ($plugin && defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 835 | + return ($plugin && defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 837 | 836 | } |
| 838 | 837 | |
| 839 | 838 | /** |
@@ -864,52 +863,52 @@ discard block |
||
| 864 | 863 | * texte |
| 865 | 864 | */ |
| 866 | 865 | function _T($texte, $args = [], $options = []) { |
| 867 | - static $traduire = false; |
|
| 868 | - $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 869 | - if ($options) { |
|
| 870 | - // support de l'ancien argument $class |
|
| 871 | - if (is_string($options)) { |
|
| 872 | - $options = ['class' => $options]; |
|
| 873 | - } |
|
| 874 | - $o = array_merge($o, $options); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - if (!$traduire) { |
|
| 878 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 879 | - include_spip('inc/lang'); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - // On peut passer explicitement la langue dans le tableau |
|
| 883 | - // On utilise le même nom de variable que la globale |
|
| 884 | - if (isset($args['spip_lang'])) { |
|
| 885 | - $lang = $args['spip_lang']; |
|
| 886 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 887 | - unset($args['spip_lang']); |
|
| 888 | - } // Sinon on prend la langue du contexte |
|
| 889 | - else { |
|
| 890 | - $lang = $GLOBALS['spip_lang']; |
|
| 891 | - } |
|
| 892 | - $text = $traduire($texte, $lang); |
|
| 893 | - |
|
| 894 | - if ($text === null || !strlen($text)) { |
|
| 895 | - if (!$o['force']) { |
|
| 896 | - return ''; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - $text = $texte; |
|
| 900 | - |
|
| 901 | - // pour les chaines non traduites, assurer un service minimum |
|
| 902 | - if (!$GLOBALS['test_i18n'] && _request('var_mode') != 'traduction') { |
|
| 903 | - $n = strpos($text, ':'); |
|
| 904 | - if ($n !== false) { |
|
| 905 | - $text = substr($text, $n + 1); |
|
| 906 | - } |
|
| 907 | - $text = str_replace('_', ' ', $text); |
|
| 908 | - } |
|
| 909 | - $o['class'] = null; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - return _L($text, $args, $o); |
|
| 866 | + static $traduire = false; |
|
| 867 | + $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 868 | + if ($options) { |
|
| 869 | + // support de l'ancien argument $class |
|
| 870 | + if (is_string($options)) { |
|
| 871 | + $options = ['class' => $options]; |
|
| 872 | + } |
|
| 873 | + $o = array_merge($o, $options); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + if (!$traduire) { |
|
| 877 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 878 | + include_spip('inc/lang'); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + // On peut passer explicitement la langue dans le tableau |
|
| 882 | + // On utilise le même nom de variable que la globale |
|
| 883 | + if (isset($args['spip_lang'])) { |
|
| 884 | + $lang = $args['spip_lang']; |
|
| 885 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 886 | + unset($args['spip_lang']); |
|
| 887 | + } // Sinon on prend la langue du contexte |
|
| 888 | + else { |
|
| 889 | + $lang = $GLOBALS['spip_lang']; |
|
| 890 | + } |
|
| 891 | + $text = $traduire($texte, $lang); |
|
| 892 | + |
|
| 893 | + if ($text === null || !strlen($text)) { |
|
| 894 | + if (!$o['force']) { |
|
| 895 | + return ''; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + $text = $texte; |
|
| 899 | + |
|
| 900 | + // pour les chaines non traduites, assurer un service minimum |
|
| 901 | + if (!$GLOBALS['test_i18n'] && _request('var_mode') != 'traduction') { |
|
| 902 | + $n = strpos($text, ':'); |
|
| 903 | + if ($n !== false) { |
|
| 904 | + $text = substr($text, $n + 1); |
|
| 905 | + } |
|
| 906 | + $text = str_replace('_', ' ', $text); |
|
| 907 | + } |
|
| 908 | + $o['class'] = null; |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + return _L($text, $args, $o); |
|
| 913 | 912 | } |
| 914 | 913 | |
| 915 | 914 | |
@@ -936,53 +935,53 @@ discard block |
||
| 936 | 935 | * texte |
| 937 | 936 | */ |
| 938 | 937 | function _L($text, $args = [], $options = []) { |
| 939 | - $f = $text; |
|
| 940 | - $defaut_options = [ |
|
| 941 | - 'class' => null, |
|
| 942 | - 'sanitize' => true, |
|
| 943 | - ]; |
|
| 944 | - // support de l'ancien argument $class |
|
| 945 | - if ($options && is_string($options)) { |
|
| 946 | - $options = ['class' => $options]; |
|
| 947 | - } |
|
| 948 | - if (is_array($options)) { |
|
| 949 | - $options += $defaut_options; |
|
| 950 | - } else { |
|
| 951 | - $options = $defaut_options; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - if (is_array($args) && count($args)) { |
|
| 955 | - if (!function_exists('interdire_scripts')) { |
|
| 956 | - include_spip('inc/texte'); |
|
| 957 | - } |
|
| 958 | - if (!function_exists('echapper_html_suspect')) { |
|
| 959 | - include_spip('inc/texte_mini'); |
|
| 960 | - } |
|
| 961 | - foreach ($args as $name => $value) { |
|
| 962 | - if (str_contains($text, (string) "@$name@")) { |
|
| 963 | - if ($options['sanitize']) { |
|
| 964 | - $value = echapper_html_suspect($value); |
|
| 965 | - $value = interdire_scripts($value, -1); |
|
| 966 | - } |
|
| 967 | - if (!empty($options['class'])) { |
|
| 968 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 969 | - } |
|
| 970 | - $text = str_replace("@$name@", (string) $value, (string) $text); |
|
| 971 | - unset($args[$name]); |
|
| 972 | - } |
|
| 973 | - } |
|
| 974 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 975 | - // (chaines de langues pas a jour) |
|
| 976 | - if ($args) { |
|
| 977 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - if (($GLOBALS['test_i18n'] || _request('var_mode') == 'traduction') && is_null($options['class'])) { |
|
| 982 | - return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 983 | - } else { |
|
| 984 | - return $text; |
|
| 985 | - } |
|
| 938 | + $f = $text; |
|
| 939 | + $defaut_options = [ |
|
| 940 | + 'class' => null, |
|
| 941 | + 'sanitize' => true, |
|
| 942 | + ]; |
|
| 943 | + // support de l'ancien argument $class |
|
| 944 | + if ($options && is_string($options)) { |
|
| 945 | + $options = ['class' => $options]; |
|
| 946 | + } |
|
| 947 | + if (is_array($options)) { |
|
| 948 | + $options += $defaut_options; |
|
| 949 | + } else { |
|
| 950 | + $options = $defaut_options; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + if (is_array($args) && count($args)) { |
|
| 954 | + if (!function_exists('interdire_scripts')) { |
|
| 955 | + include_spip('inc/texte'); |
|
| 956 | + } |
|
| 957 | + if (!function_exists('echapper_html_suspect')) { |
|
| 958 | + include_spip('inc/texte_mini'); |
|
| 959 | + } |
|
| 960 | + foreach ($args as $name => $value) { |
|
| 961 | + if (str_contains($text, (string) "@$name@")) { |
|
| 962 | + if ($options['sanitize']) { |
|
| 963 | + $value = echapper_html_suspect($value); |
|
| 964 | + $value = interdire_scripts($value, -1); |
|
| 965 | + } |
|
| 966 | + if (!empty($options['class'])) { |
|
| 967 | + $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 968 | + } |
|
| 969 | + $text = str_replace("@$name@", (string) $value, (string) $text); |
|
| 970 | + unset($args[$name]); |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 974 | + // (chaines de langues pas a jour) |
|
| 975 | + if ($args) { |
|
| 976 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + if (($GLOBALS['test_i18n'] || _request('var_mode') == 'traduction') && is_null($options['class'])) { |
|
| 981 | + return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 982 | + } else { |
|
| 983 | + return $text; |
|
| 984 | + } |
|
| 986 | 985 | } |
| 987 | 986 | |
| 988 | 987 | |
@@ -996,13 +995,13 @@ discard block |
||
| 996 | 995 | * @return string |
| 997 | 996 | */ |
| 998 | 997 | function joli_repertoire($rep) { |
| 999 | - $a = substr($rep, 0, 1); |
|
| 1000 | - if ($a <> '.' && $a <> '/') { |
|
| 1001 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 1002 | - } |
|
| 1003 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 998 | + $a = substr($rep, 0, 1); |
|
| 999 | + if ($a <> '.' && $a <> '/') { |
|
| 1000 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 1001 | + } |
|
| 1002 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 1004 | 1003 | |
| 1005 | - return $rep; |
|
| 1004 | + return $rep; |
|
| 1006 | 1005 | } |
| 1007 | 1006 | |
| 1008 | 1007 | |
@@ -1027,54 +1026,54 @@ discard block |
||
| 1027 | 1026 | * @return float|int|string|void |
| 1028 | 1027 | */ |
| 1029 | 1028 | function spip_timer($t = 'rien', $raw = false) { |
| 1030 | - static $time; |
|
| 1031 | - $a = time(); |
|
| 1032 | - $b = microtime(); |
|
| 1033 | - // microtime peut contenir les microsecondes et le temps |
|
| 1034 | - $b = explode(' ', $b); |
|
| 1035 | - if (count($b) == 2) { |
|
| 1036 | - $a = end($b); |
|
| 1037 | - } // plus precis ! |
|
| 1038 | - $b = reset($b); |
|
| 1039 | - if (!isset($time[$t])) { |
|
| 1040 | - $time[$t] = $a + $b; |
|
| 1041 | - } else { |
|
| 1042 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 1043 | - unset($time[$t]); |
|
| 1029 | + static $time; |
|
| 1030 | + $a = time(); |
|
| 1031 | + $b = microtime(); |
|
| 1032 | + // microtime peut contenir les microsecondes et le temps |
|
| 1033 | + $b = explode(' ', $b); |
|
| 1034 | + if (count($b) == 2) { |
|
| 1035 | + $a = end($b); |
|
| 1036 | + } // plus precis ! |
|
| 1037 | + $b = reset($b); |
|
| 1038 | + if (!isset($time[$t])) { |
|
| 1039 | + $time[$t] = $a + $b; |
|
| 1040 | + } else { |
|
| 1041 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 1042 | + unset($time[$t]); |
|
| 1044 | 1043 | # echo "'$p'";exit; |
| 1045 | - if ($raw) { |
|
| 1046 | - return $p; |
|
| 1047 | - } |
|
| 1048 | - if ($p < 1000) { |
|
| 1049 | - $s = ''; |
|
| 1050 | - } else { |
|
| 1051 | - $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1052 | - $p -= ($x * 1000); |
|
| 1053 | - } |
|
| 1044 | + if ($raw) { |
|
| 1045 | + return $p; |
|
| 1046 | + } |
|
| 1047 | + if ($p < 1000) { |
|
| 1048 | + $s = ''; |
|
| 1049 | + } else { |
|
| 1050 | + $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1051 | + $p -= ($x * 1000); |
|
| 1052 | + } |
|
| 1054 | 1053 | |
| 1055 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1056 | - } |
|
| 1054 | + return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1055 | + } |
|
| 1057 | 1056 | } |
| 1058 | 1057 | |
| 1059 | 1058 | |
| 1060 | 1059 | // Renvoie False si un fichier n'est pas plus vieux que $duree secondes, |
| 1061 | 1060 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 1062 | 1061 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 1063 | - if ($duree) { |
|
| 1064 | - clearstatcache(); |
|
| 1065 | - if (($f = @filemtime($fichier)) && $f >= time() - $duree) { |
|
| 1066 | - return false; |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - if ($touch !== false) { |
|
| 1070 | - if (!@touch($fichier)) { |
|
| 1071 | - spip_unlink($fichier); |
|
| 1072 | - @touch($fichier); |
|
| 1073 | - }; |
|
| 1074 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1075 | - } |
|
| 1062 | + if ($duree) { |
|
| 1063 | + clearstatcache(); |
|
| 1064 | + if (($f = @filemtime($fichier)) && $f >= time() - $duree) { |
|
| 1065 | + return false; |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + if ($touch !== false) { |
|
| 1069 | + if (!@touch($fichier)) { |
|
| 1070 | + spip_unlink($fichier); |
|
| 1071 | + @touch($fichier); |
|
| 1072 | + }; |
|
| 1073 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1074 | + } |
|
| 1076 | 1075 | |
| 1077 | - return true; |
|
| 1076 | + return true; |
|
| 1078 | 1077 | } |
| 1079 | 1078 | |
| 1080 | 1079 | |
@@ -1085,11 +1084,11 @@ discard block |
||
| 1085 | 1084 | * @uses cron() |
| 1086 | 1085 | **/ |
| 1087 | 1086 | function action_cron() { |
| 1088 | - include_spip('inc/headers'); |
|
| 1089 | - http_response_code(204); // No Content |
|
| 1090 | - header('Connection: close'); |
|
| 1091 | - define('_DIRECT_CRON_FORCE', true); |
|
| 1092 | - cron(); |
|
| 1087 | + include_spip('inc/headers'); |
|
| 1088 | + http_response_code(204); // No Content |
|
| 1089 | + header('Connection: close'); |
|
| 1090 | + define('_DIRECT_CRON_FORCE', true); |
|
| 1091 | + cron(); |
|
| 1093 | 1092 | } |
| 1094 | 1093 | |
| 1095 | 1094 | /** |
@@ -1105,26 +1104,26 @@ discard block |
||
| 1105 | 1104 | * True si la tache a pu être effectuée |
| 1106 | 1105 | */ |
| 1107 | 1106 | function cron($taches = [], $taches_old = []) { |
| 1108 | - // si pas en mode cron force, laisser tomber. |
|
| 1109 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1110 | - return false; |
|
| 1111 | - } |
|
| 1112 | - if (!is_array($taches)) { |
|
| 1113 | - $taches = $taches_old; |
|
| 1114 | - } // compat anciens appels |
|
| 1115 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1116 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1117 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1118 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1119 | - if ($taches && count($taches) && !spip_connect()) { |
|
| 1120 | - return false; |
|
| 1121 | - } |
|
| 1122 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1123 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1124 | - return $genie($taches); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - return false; |
|
| 1107 | + // si pas en mode cron force, laisser tomber. |
|
| 1108 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1109 | + return false; |
|
| 1110 | + } |
|
| 1111 | + if (!is_array($taches)) { |
|
| 1112 | + $taches = $taches_old; |
|
| 1113 | + } // compat anciens appels |
|
| 1114 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1115 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1116 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1117 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1118 | + if ($taches && count($taches) && !spip_connect()) { |
|
| 1119 | + return false; |
|
| 1120 | + } |
|
| 1121 | + spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1122 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1123 | + return $genie($taches); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + return false; |
|
| 1128 | 1127 | } |
| 1129 | 1128 | |
| 1130 | 1129 | /** |
@@ -1156,17 +1155,17 @@ discard block |
||
| 1156 | 1155 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1157 | 1156 | */ |
| 1158 | 1157 | function job_queue_add( |
| 1159 | - $function, |
|
| 1160 | - $description, |
|
| 1161 | - $arguments = [], |
|
| 1162 | - $file = '', |
|
| 1163 | - $no_duplicate = false, |
|
| 1164 | - $time = 0, |
|
| 1165 | - $priority = 0 |
|
| 1158 | + $function, |
|
| 1159 | + $description, |
|
| 1160 | + $arguments = [], |
|
| 1161 | + $file = '', |
|
| 1162 | + $no_duplicate = false, |
|
| 1163 | + $time = 0, |
|
| 1164 | + $priority = 0 |
|
| 1166 | 1165 | ) { |
| 1167 | - include_spip('inc/queue'); |
|
| 1166 | + include_spip('inc/queue'); |
|
| 1168 | 1167 | |
| 1169 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1168 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1170 | 1169 | } |
| 1171 | 1170 | |
| 1172 | 1171 | /** |
@@ -1177,9 +1176,9 @@ discard block |
||
| 1177 | 1176 | * @return bool |
| 1178 | 1177 | */ |
| 1179 | 1178 | function job_queue_remove($id_job) { |
| 1180 | - include_spip('inc/queue'); |
|
| 1179 | + include_spip('inc/queue'); |
|
| 1181 | 1180 | |
| 1182 | - return queue_remove_job($id_job); |
|
| 1181 | + return queue_remove_job($id_job); |
|
| 1183 | 1182 | } |
| 1184 | 1183 | |
| 1185 | 1184 | /** |
@@ -1192,9 +1191,9 @@ discard block |
||
| 1192 | 1191 | * or an array of simple array to link multiples objet in one time |
| 1193 | 1192 | */ |
| 1194 | 1193 | function job_queue_link($id_job, $objets) { |
| 1195 | - include_spip('inc/queue'); |
|
| 1194 | + include_spip('inc/queue'); |
|
| 1196 | 1195 | |
| 1197 | - return queue_link_job($id_job, $objets); |
|
| 1196 | + return queue_link_job($id_job, $objets); |
|
| 1198 | 1197 | } |
| 1199 | 1198 | |
| 1200 | 1199 | |
@@ -1213,37 +1212,37 @@ discard block |
||
| 1213 | 1212 | * - `null` si la queue n'est pas encore initialisée |
| 1214 | 1213 | */ |
| 1215 | 1214 | function queue_sleep_time_to_next_job($force = null) { |
| 1216 | - static $queue_next_job_time = -1; |
|
| 1217 | - if ($force === true) { |
|
| 1218 | - $queue_next_job_time = -1; |
|
| 1219 | - } elseif ($force) { |
|
| 1220 | - $queue_next_job_time = $force; |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - if ($queue_next_job_time == -1) { |
|
| 1224 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1225 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1226 | - } |
|
| 1227 | - // utiliser un cache memoire si dispo |
|
| 1228 | - if (function_exists('cache_get') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) { |
|
| 1229 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1230 | - } else { |
|
| 1231 | - $queue_next_job_time = null; |
|
| 1232 | - $contenu = null; |
|
| 1233 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1234 | - $queue_next_job_time = intval($contenu); |
|
| 1235 | - } |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - if (is_null($queue_next_job_time)) { |
|
| 1240 | - return null; |
|
| 1241 | - } |
|
| 1242 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1243 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1215 | + static $queue_next_job_time = -1; |
|
| 1216 | + if ($force === true) { |
|
| 1217 | + $queue_next_job_time = -1; |
|
| 1218 | + } elseif ($force) { |
|
| 1219 | + $queue_next_job_time = $force; |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + if ($queue_next_job_time == -1) { |
|
| 1223 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1224 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1225 | + } |
|
| 1226 | + // utiliser un cache memoire si dispo |
|
| 1227 | + if (function_exists('cache_get') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) { |
|
| 1228 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1229 | + } else { |
|
| 1230 | + $queue_next_job_time = null; |
|
| 1231 | + $contenu = null; |
|
| 1232 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1233 | + $queue_next_job_time = intval($contenu); |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + if (is_null($queue_next_job_time)) { |
|
| 1239 | + return null; |
|
| 1240 | + } |
|
| 1241 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1242 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1247 | 1246 | } |
| 1248 | 1247 | |
| 1249 | 1248 | |
@@ -1255,11 +1254,11 @@ discard block |
||
| 1255 | 1254 | * @return string |
| 1256 | 1255 | */ |
| 1257 | 1256 | function quote_amp($u) { |
| 1258 | - return preg_replace( |
|
| 1259 | - '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1260 | - '&', |
|
| 1261 | - $u |
|
| 1262 | - ); |
|
| 1257 | + return preg_replace( |
|
| 1258 | + '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1259 | + '&', |
|
| 1260 | + $u |
|
| 1261 | + ); |
|
| 1263 | 1262 | } |
| 1264 | 1263 | |
| 1265 | 1264 | |
@@ -1282,27 +1281,27 @@ discard block |
||
| 1282 | 1281 | * Balise HTML `<script>` et son contenu |
| 1283 | 1282 | **/ |
| 1284 | 1283 | function http_script($script, $src = '', $noscript = '') { |
| 1285 | - static $done = []; |
|
| 1284 | + static $done = []; |
|
| 1286 | 1285 | |
| 1287 | - if ($src && !isset($done[$src])) { |
|
| 1288 | - $done[$src] = true; |
|
| 1289 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1290 | - $src = " src='$src'"; |
|
| 1291 | - } else { |
|
| 1292 | - $src = ''; |
|
| 1293 | - } |
|
| 1294 | - if ($script) { |
|
| 1295 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1296 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1297 | - '/*]]>*/'); |
|
| 1298 | - } |
|
| 1299 | - if ($noscript) { |
|
| 1300 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1301 | - } |
|
| 1286 | + if ($src && !isset($done[$src])) { |
|
| 1287 | + $done[$src] = true; |
|
| 1288 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1289 | + $src = " src='$src'"; |
|
| 1290 | + } else { |
|
| 1291 | + $src = ''; |
|
| 1292 | + } |
|
| 1293 | + if ($script) { |
|
| 1294 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1295 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1296 | + '/*]]>*/'); |
|
| 1297 | + } |
|
| 1298 | + if ($noscript) { |
|
| 1299 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1300 | + } |
|
| 1302 | 1301 | |
| 1303 | - return ($src || $script || $noscript) |
|
| 1304 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1305 | - : ''; |
|
| 1302 | + return ($src || $script || $noscript) |
|
| 1303 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1304 | + : ''; |
|
| 1306 | 1305 | } |
| 1307 | 1306 | |
| 1308 | 1307 | |
@@ -1337,10 +1336,10 @@ discard block |
||
| 1337 | 1336 | * texte échappé |
| 1338 | 1337 | **/ |
| 1339 | 1338 | function texte_script(?string $texte): string { |
| 1340 | - if ($texte === null || $texte === '') { |
|
| 1341 | - return ''; |
|
| 1342 | - } |
|
| 1343 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1339 | + if ($texte === null || $texte === '') { |
|
| 1340 | + return ''; |
|
| 1341 | + } |
|
| 1342 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1344 | 1343 | } |
| 1345 | 1344 | |
| 1346 | 1345 | |
@@ -1377,68 +1376,68 @@ discard block |
||
| 1377 | 1376 | * Liste des chemins, par ordre de priorité. |
| 1378 | 1377 | **/ |
| 1379 | 1378 | function _chemin($dir_path = null) { |
| 1380 | - static $path_base = null; |
|
| 1381 | - static $path_full = null; |
|
| 1382 | - if ($path_base == null) { |
|
| 1383 | - // Chemin standard depuis l'espace public |
|
| 1384 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1385 | - _DIR_RACINE . ':' . |
|
| 1386 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1387 | - _DIR_RACINE . 'prive/:' . |
|
| 1388 | - _DIR_RESTREINT; |
|
| 1389 | - // Ajouter squelettes/ |
|
| 1390 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1391 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1392 | - } |
|
| 1393 | - foreach (explode(':', $path) as $dir) { |
|
| 1394 | - if (strlen($dir) && !str_ends_with($dir, '/')) { |
|
| 1395 | - $dir .= '/'; |
|
| 1396 | - } |
|
| 1397 | - $path_base[] = $dir; |
|
| 1398 | - } |
|
| 1399 | - $path_full = $path_base; |
|
| 1400 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1401 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1402 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1403 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1404 | - } |
|
| 1405 | - } |
|
| 1406 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1407 | - } |
|
| 1408 | - if ($dir_path === null) { |
|
| 1409 | - return $path_full; |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - if (is_array($dir_path) || strlen($dir_path)) { |
|
| 1413 | - $tete = ''; |
|
| 1414 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1415 | - $tete = array_shift($path_base); |
|
| 1416 | - } |
|
| 1417 | - $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1418 | - $dirs = array_reverse($dirs); |
|
| 1419 | - foreach ($dirs as $dir_path) { |
|
| 1420 | - if (!str_ends_with($dir_path, '/')) { |
|
| 1421 | - $dir_path .= '/'; |
|
| 1422 | - } |
|
| 1423 | - if (!in_array($dir_path, $path_base)) { |
|
| 1424 | - array_unshift($path_base, $dir_path); |
|
| 1425 | - } |
|
| 1426 | - } |
|
| 1427 | - if (strlen($tete)) { |
|
| 1428 | - array_unshift($path_base, $tete); |
|
| 1429 | - } |
|
| 1430 | - } |
|
| 1431 | - $path_full = $path_base; |
|
| 1432 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1433 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1434 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1435 | - array_unshift($path_full, ((isset($d[0]) && $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1436 | - } |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1440 | - |
|
| 1441 | - return $path_full; |
|
| 1379 | + static $path_base = null; |
|
| 1380 | + static $path_full = null; |
|
| 1381 | + if ($path_base == null) { |
|
| 1382 | + // Chemin standard depuis l'espace public |
|
| 1383 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1384 | + _DIR_RACINE . ':' . |
|
| 1385 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1386 | + _DIR_RACINE . 'prive/:' . |
|
| 1387 | + _DIR_RESTREINT; |
|
| 1388 | + // Ajouter squelettes/ |
|
| 1389 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1390 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1391 | + } |
|
| 1392 | + foreach (explode(':', $path) as $dir) { |
|
| 1393 | + if (strlen($dir) && !str_ends_with($dir, '/')) { |
|
| 1394 | + $dir .= '/'; |
|
| 1395 | + } |
|
| 1396 | + $path_base[] = $dir; |
|
| 1397 | + } |
|
| 1398 | + $path_full = $path_base; |
|
| 1399 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1400 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1401 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1402 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1403 | + } |
|
| 1404 | + } |
|
| 1405 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1406 | + } |
|
| 1407 | + if ($dir_path === null) { |
|
| 1408 | + return $path_full; |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + if (is_array($dir_path) || strlen($dir_path)) { |
|
| 1412 | + $tete = ''; |
|
| 1413 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1414 | + $tete = array_shift($path_base); |
|
| 1415 | + } |
|
| 1416 | + $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1417 | + $dirs = array_reverse($dirs); |
|
| 1418 | + foreach ($dirs as $dir_path) { |
|
| 1419 | + if (!str_ends_with($dir_path, '/')) { |
|
| 1420 | + $dir_path .= '/'; |
|
| 1421 | + } |
|
| 1422 | + if (!in_array($dir_path, $path_base)) { |
|
| 1423 | + array_unshift($path_base, $dir_path); |
|
| 1424 | + } |
|
| 1425 | + } |
|
| 1426 | + if (strlen($tete)) { |
|
| 1427 | + array_unshift($path_base, $tete); |
|
| 1428 | + } |
|
| 1429 | + } |
|
| 1430 | + $path_full = $path_base; |
|
| 1431 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1432 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1433 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1434 | + array_unshift($path_full, ((isset($d[0]) && $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1435 | + } |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1439 | + |
|
| 1440 | + return $path_full; |
|
| 1442 | 1441 | } |
| 1443 | 1442 | |
| 1444 | 1443 | /** |
@@ -1451,17 +1450,17 @@ discard block |
||
| 1451 | 1450 | * @return array Liste de chemins |
| 1452 | 1451 | **/ |
| 1453 | 1452 | function creer_chemin() { |
| 1454 | - $path_a = _chemin(); |
|
| 1455 | - static $c = ''; |
|
| 1453 | + $path_a = _chemin(); |
|
| 1454 | + static $c = ''; |
|
| 1456 | 1455 | |
| 1457 | - // on calcule le chemin si le dossier skel a change |
|
| 1458 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1459 | - // assurer le non plantage lors de la montee de version : |
|
| 1460 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1461 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1462 | - } |
|
| 1456 | + // on calcule le chemin si le dossier skel a change |
|
| 1457 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1458 | + // assurer le non plantage lors de la montee de version : |
|
| 1459 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1460 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1461 | + } |
|
| 1463 | 1462 | |
| 1464 | - return $path_a; |
|
| 1463 | + return $path_a; |
|
| 1465 | 1464 | } |
| 1466 | 1465 | |
| 1467 | 1466 | |
@@ -1473,61 +1472,61 @@ discard block |
||
| 1473 | 1472 | * @return string[] Nom des thèmes. |
| 1474 | 1473 | */ |
| 1475 | 1474 | function lister_themes_prives(): array { |
| 1476 | - static $themes = null; |
|
| 1477 | - if (is_null($themes)) { |
|
| 1478 | - // si pas encore definie |
|
| 1479 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1480 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1481 | - } |
|
| 1482 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 1483 | - // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé |
|
| 1484 | - // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp; |
|
| 1485 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 1486 | - if (is_string($prefs) && stripos($prefs, 'a:') === 0) { |
|
| 1487 | - $prefs = unserialize($prefs); |
|
| 1488 | - } else { |
|
| 1489 | - $prefs = []; |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null; |
|
| 1493 | - if ($theme && $theme !== _SPIP_THEME_PRIVE) { |
|
| 1494 | - // placer le theme choisi en tete |
|
| 1495 | - array_unshift($themes, $theme); |
|
| 1496 | - } |
|
| 1497 | - } |
|
| 1498 | - |
|
| 1499 | - return $themes; |
|
| 1475 | + static $themes = null; |
|
| 1476 | + if (is_null($themes)) { |
|
| 1477 | + // si pas encore definie |
|
| 1478 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1479 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1480 | + } |
|
| 1481 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 1482 | + // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé |
|
| 1483 | + // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp; |
|
| 1484 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 1485 | + if (is_string($prefs) && stripos($prefs, 'a:') === 0) { |
|
| 1486 | + $prefs = unserialize($prefs); |
|
| 1487 | + } else { |
|
| 1488 | + $prefs = []; |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null; |
|
| 1492 | + if ($theme && $theme !== _SPIP_THEME_PRIVE) { |
|
| 1493 | + // placer le theme choisi en tete |
|
| 1494 | + array_unshift($themes, $theme); |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + return $themes; |
|
| 1500 | 1499 | } |
| 1501 | 1500 | |
| 1502 | 1501 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1503 | - static $themefiles = []; |
|
| 1504 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1505 | - return $themefiles["$subdir$file"]; |
|
| 1506 | - } |
|
| 1507 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1508 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1509 | - if ( |
|
| 1510 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1511 | - && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 1512 | - && ($f = find_in_theme("$file_svg_generique")) |
|
| 1513 | - ) { |
|
| 1514 | - if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 1515 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1516 | - } |
|
| 1517 | - else { |
|
| 1518 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - $themes = lister_themes_prives(); |
|
| 1523 | - foreach ($themes as $theme) { |
|
| 1524 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1525 | - return $themefiles["$subdir$file"] = $f; |
|
| 1526 | - } |
|
| 1527 | - } |
|
| 1528 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1529 | - |
|
| 1530 | - return $themefiles["$subdir$file"] = ''; |
|
| 1502 | + static $themefiles = []; |
|
| 1503 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1504 | + return $themefiles["$subdir$file"]; |
|
| 1505 | + } |
|
| 1506 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1507 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1508 | + if ( |
|
| 1509 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1510 | + && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 1511 | + && ($f = find_in_theme("$file_svg_generique")) |
|
| 1512 | + ) { |
|
| 1513 | + if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 1514 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1515 | + } |
|
| 1516 | + else { |
|
| 1517 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + $themes = lister_themes_prives(); |
|
| 1522 | + foreach ($themes as $theme) { |
|
| 1523 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1524 | + return $themefiles["$subdir$file"] = $f; |
|
| 1525 | + } |
|
| 1526 | + } |
|
| 1527 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1528 | + |
|
| 1529 | + return $themefiles["$subdir$file"] = ''; |
|
| 1531 | 1530 | } |
| 1532 | 1531 | |
| 1533 | 1532 | |
@@ -1551,31 +1550,31 @@ discard block |
||
| 1551 | 1550 | * sinon chaîne vide. |
| 1552 | 1551 | **/ |
| 1553 | 1552 | function chemin_image($icone) { |
| 1554 | - static $icone_renommer; |
|
| 1555 | - if ($p = strpos($icone, '?')) { |
|
| 1556 | - $icone = substr($icone, 0, $p); |
|
| 1557 | - } |
|
| 1558 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1559 | - if (str_contains($icone, '/') && file_exists($icone)) { |
|
| 1560 | - return $icone; |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1564 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) { |
|
| 1565 | - return $f; |
|
| 1566 | - } |
|
| 1567 | - // sinon passer par le module de renommage |
|
| 1568 | - if (is_null($icone_renommer)) { |
|
| 1569 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1570 | - } |
|
| 1571 | - if ($icone_renommer) { |
|
| 1572 | - [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1573 | - if (file_exists($icone)) { |
|
| 1574 | - return $icone; |
|
| 1575 | - } |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1553 | + static $icone_renommer; |
|
| 1554 | + if ($p = strpos($icone, '?')) { |
|
| 1555 | + $icone = substr($icone, 0, $p); |
|
| 1556 | + } |
|
| 1557 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1558 | + if (str_contains($icone, '/') && file_exists($icone)) { |
|
| 1559 | + return $icone; |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1563 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) { |
|
| 1564 | + return $f; |
|
| 1565 | + } |
|
| 1566 | + // sinon passer par le module de renommage |
|
| 1567 | + if (is_null($icone_renommer)) { |
|
| 1568 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1569 | + } |
|
| 1570 | + if ($icone_renommer) { |
|
| 1571 | + [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1572 | + if (file_exists($icone)) { |
|
| 1573 | + return $icone; |
|
| 1574 | + } |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1579 | 1578 | } |
| 1580 | 1579 | |
| 1581 | 1580 | // |
@@ -1613,128 +1612,128 @@ discard block |
||
| 1613 | 1612 | * - false : fichier introuvable |
| 1614 | 1613 | **/ |
| 1615 | 1614 | function find_in_path($file, $dirname = '', $include = false) { |
| 1616 | - static $dirs = []; |
|
| 1617 | - static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1618 | - static $c = ''; |
|
| 1619 | - |
|
| 1620 | - if (!$file && !strlen($file)) { |
|
| 1621 | - return false; |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - // on calcule le chemin si le dossier skel a change |
|
| 1625 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1626 | - // assurer le non plantage lors de la montee de version : |
|
| 1627 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1628 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1632 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1633 | - return false; |
|
| 1634 | - } |
|
| 1635 | - if ($include && !isset($inc[$dirname][$file])) { |
|
| 1636 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1637 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - $a = strrpos($file, '/'); |
|
| 1644 | - if ($a !== false) { |
|
| 1645 | - $dirname .= substr($file, 0, ++$a); |
|
| 1646 | - $file = substr($file, $a); |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - foreach (creer_chemin() as $dir) { |
|
| 1650 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1651 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1652 | - } |
|
| 1653 | - if ($dirs[$a]) { |
|
| 1654 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1655 | - if ($include && !isset($inc[$dirname][$file])) { |
|
| 1656 | - include_once _ROOT_CWD . $a; |
|
| 1657 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1658 | - } |
|
| 1659 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1660 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1661 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1662 | - return $a; |
|
| 1663 | - } |
|
| 1664 | - define('_SAUVER_CHEMIN', true); |
|
| 1665 | - } |
|
| 1666 | - |
|
| 1667 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - if ($include) { |
|
| 1673 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1674 | - if ($include === 'required') { |
|
| 1675 | - echo '<pre>', |
|
| 1676 | - '<strong>Erreur Fatale</strong><br />'; |
|
| 1677 | - if (function_exists('debug_print_backtrace')) { |
|
| 1678 | - debug_print_backtrace(); |
|
| 1679 | - } |
|
| 1680 | - echo '</pre>'; |
|
| 1681 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1682 | - } |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1686 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1687 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1688 | - return false; |
|
| 1689 | - } |
|
| 1690 | - define('_SAUVER_CHEMIN', true); |
|
| 1691 | - } |
|
| 1692 | - |
|
| 1693 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1615 | + static $dirs = []; |
|
| 1616 | + static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1617 | + static $c = ''; |
|
| 1618 | + |
|
| 1619 | + if (!$file && !strlen($file)) { |
|
| 1620 | + return false; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + // on calcule le chemin si le dossier skel a change |
|
| 1624 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1625 | + // assurer le non plantage lors de la montee de version : |
|
| 1626 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1627 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1631 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1632 | + return false; |
|
| 1633 | + } |
|
| 1634 | + if ($include && !isset($inc[$dirname][$file])) { |
|
| 1635 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1636 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + $a = strrpos($file, '/'); |
|
| 1643 | + if ($a !== false) { |
|
| 1644 | + $dirname .= substr($file, 0, ++$a); |
|
| 1645 | + $file = substr($file, $a); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + foreach (creer_chemin() as $dir) { |
|
| 1649 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1650 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1651 | + } |
|
| 1652 | + if ($dirs[$a]) { |
|
| 1653 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1654 | + if ($include && !isset($inc[$dirname][$file])) { |
|
| 1655 | + include_once _ROOT_CWD . $a; |
|
| 1656 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1657 | + } |
|
| 1658 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1659 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1660 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1661 | + return $a; |
|
| 1662 | + } |
|
| 1663 | + define('_SAUVER_CHEMIN', true); |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1667 | + } |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + |
|
| 1671 | + if ($include) { |
|
| 1672 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1673 | + if ($include === 'required') { |
|
| 1674 | + echo '<pre>', |
|
| 1675 | + '<strong>Erreur Fatale</strong><br />'; |
|
| 1676 | + if (function_exists('debug_print_backtrace')) { |
|
| 1677 | + debug_print_backtrace(); |
|
| 1678 | + } |
|
| 1679 | + echo '</pre>'; |
|
| 1680 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1681 | + } |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1685 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1686 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1687 | + return false; |
|
| 1688 | + } |
|
| 1689 | + define('_SAUVER_CHEMIN', true); |
|
| 1690 | + } |
|
| 1691 | + |
|
| 1692 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1694 | 1693 | } |
| 1695 | 1694 | |
| 1696 | 1695 | function clear_path_cache() { |
| 1697 | - $GLOBALS['path_files'] = []; |
|
| 1698 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1696 | + $GLOBALS['path_files'] = []; |
|
| 1697 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1699 | 1698 | } |
| 1700 | 1699 | |
| 1701 | 1700 | function load_path_cache() { |
| 1702 | - // charger le path des plugins |
|
| 1703 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1704 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1705 | - } |
|
| 1706 | - $GLOBALS['path_files'] = []; |
|
| 1707 | - // si le visiteur est admin, |
|
| 1708 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1709 | - if ( |
|
| 1710 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1711 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1712 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1713 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1714 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1715 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1716 | - !_request('var_mode') |
|
| 1717 | - ) { |
|
| 1718 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1719 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1720 | - // mais si semble corrompu on relit avec un verrou |
|
| 1721 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1722 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1723 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1724 | - $GLOBALS['path_files'] = []; |
|
| 1725 | - } |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - } |
|
| 1701 | + // charger le path des plugins |
|
| 1702 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1703 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1704 | + } |
|
| 1705 | + $GLOBALS['path_files'] = []; |
|
| 1706 | + // si le visiteur est admin, |
|
| 1707 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1708 | + if ( |
|
| 1709 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1710 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1711 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1712 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1713 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1714 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1715 | + !_request('var_mode') |
|
| 1716 | + ) { |
|
| 1717 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1718 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1719 | + // mais si semble corrompu on relit avec un verrou |
|
| 1720 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1721 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1722 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1723 | + $GLOBALS['path_files'] = []; |
|
| 1724 | + } |
|
| 1725 | + } |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1729 | 1728 | } |
| 1730 | 1729 | |
| 1731 | 1730 | function save_path_cache() { |
| 1732 | - if ( |
|
| 1733 | - defined('_SAUVER_CHEMIN') |
|
| 1734 | - && _SAUVER_CHEMIN |
|
| 1735 | - ) { |
|
| 1736 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1737 | - } |
|
| 1731 | + if ( |
|
| 1732 | + defined('_SAUVER_CHEMIN') |
|
| 1733 | + && _SAUVER_CHEMIN |
|
| 1734 | + ) { |
|
| 1735 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1736 | + } |
|
| 1738 | 1737 | } |
| 1739 | 1738 | |
| 1740 | 1739 | |
@@ -1754,33 +1753,33 @@ discard block |
||
| 1754 | 1753 | * @return array |
| 1755 | 1754 | */ |
| 1756 | 1755 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1757 | - $liste_fichiers = []; |
|
| 1758 | - $maxfiles = 10000; |
|
| 1759 | - |
|
| 1760 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1761 | - // on a pas encore inclus flock.php |
|
| 1762 | - if (!function_exists('preg_files')) { |
|
| 1763 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - // Parcourir le chemin |
|
| 1767 | - foreach (creer_chemin() as $d) { |
|
| 1768 | - $f = $d . $dir; |
|
| 1769 | - if (@is_dir($f)) { |
|
| 1770 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1771 | - foreach ($liste as $chemin) { |
|
| 1772 | - $nom = basename($chemin); |
|
| 1773 | - // ne prendre que les fichiers pas deja trouves |
|
| 1774 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1775 | - // les autres sont donc masques |
|
| 1776 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1777 | - $liste_fichiers[$nom] = $chemin; |
|
| 1778 | - } |
|
| 1779 | - } |
|
| 1780 | - } |
|
| 1781 | - } |
|
| 1782 | - |
|
| 1783 | - return $liste_fichiers; |
|
| 1756 | + $liste_fichiers = []; |
|
| 1757 | + $maxfiles = 10000; |
|
| 1758 | + |
|
| 1759 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1760 | + // on a pas encore inclus flock.php |
|
| 1761 | + if (!function_exists('preg_files')) { |
|
| 1762 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + // Parcourir le chemin |
|
| 1766 | + foreach (creer_chemin() as $d) { |
|
| 1767 | + $f = $d . $dir; |
|
| 1768 | + if (@is_dir($f)) { |
|
| 1769 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1770 | + foreach ($liste as $chemin) { |
|
| 1771 | + $nom = basename($chemin); |
|
| 1772 | + // ne prendre que les fichiers pas deja trouves |
|
| 1773 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1774 | + // les autres sont donc masques |
|
| 1775 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1776 | + $liste_fichiers[$nom] = $chemin; |
|
| 1777 | + } |
|
| 1778 | + } |
|
| 1779 | + } |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + return $liste_fichiers; |
|
| 1784 | 1783 | } |
| 1785 | 1784 | |
| 1786 | 1785 | /** |
@@ -1792,17 +1791,17 @@ discard block |
||
| 1792 | 1791 | * @return bool |
| 1793 | 1792 | */ |
| 1794 | 1793 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1795 | - static $autsanscookie = ['install', 'base_repair']; |
|
| 1794 | + static $autsanscookie = ['install', 'base_repair']; |
|
| 1796 | 1795 | |
| 1797 | - if (in_array($nom, $autsanscookie)) { |
|
| 1798 | - if (test_espace_prive()) { |
|
| 1799 | - include_spip('base/connect_sql'); |
|
| 1800 | - if (!$strict || !spip_connect()) { |
|
| 1801 | - return true; |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - return false; |
|
| 1796 | + if (in_array($nom, $autsanscookie)) { |
|
| 1797 | + if (test_espace_prive()) { |
|
| 1798 | + include_spip('base/connect_sql'); |
|
| 1799 | + if (!$strict || !spip_connect()) { |
|
| 1800 | + return true; |
|
| 1801 | + } |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + return false; |
|
| 1806 | 1805 | } |
| 1807 | 1806 | |
| 1808 | 1807 | /** |
@@ -1814,59 +1813,59 @@ discard block |
||
| 1814 | 1813 | * @return string |
| 1815 | 1814 | */ |
| 1816 | 1815 | function charger_fonction_url(string $quoi, string $type = '') { |
| 1817 | - if ($type === 'defaut') { |
|
| 1818 | - $objet = objet_type($quoi); |
|
| 1819 | - if ( |
|
| 1820 | - ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 1821 | - || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 1822 | - ) { |
|
| 1823 | - return $f; |
|
| 1824 | - } |
|
| 1825 | - return ''; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - $url_type = $type; |
|
| 1829 | - if (!$url_type) { |
|
| 1830 | - $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1831 | - } |
|
| 1832 | - |
|
| 1833 | - // inclure le module d'url |
|
| 1834 | - include_spip('urls/' . $url_type); |
|
| 1835 | - |
|
| 1836 | - switch ($quoi) { |
|
| 1837 | - case 'page': |
|
| 1838 | - if ( |
|
| 1839 | - function_exists($f = "urls_{$url_type}_generer_url_page") |
|
| 1840 | - || function_exists($f .= '_dist') |
|
| 1841 | - // ou une fonction custom utilisateur independante du type d'url |
|
| 1842 | - || function_exists($f = 'generer_url_page') |
|
| 1843 | - || function_exists($f .= '_dist') |
|
| 1844 | - ) { |
|
| 1845 | - return $f; |
|
| 1846 | - } |
|
| 1847 | - // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 1848 | - return ''; |
|
| 1849 | - case 'objet': |
|
| 1850 | - case 'decoder': |
|
| 1851 | - default: |
|
| 1852 | - $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 1853 | - if ( |
|
| 1854 | - function_exists($f = "urls_{$url_type}_{$fquoi}") |
|
| 1855 | - || function_exists($f .= '_dist') |
|
| 1856 | - ) { |
|
| 1857 | - return $f; |
|
| 1858 | - } |
|
| 1859 | - // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 1860 | - // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 1861 | - if ($f = charger_fonction($url_type, 'urls', true)) { |
|
| 1862 | - return $f; |
|
| 1863 | - } |
|
| 1864 | - // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement |
|
| 1865 | - if (!$type && $url_type !== 'page') { |
|
| 1866 | - return charger_fonction_url($quoi, 'page'); |
|
| 1867 | - } |
|
| 1868 | - return ''; |
|
| 1869 | - } |
|
| 1816 | + if ($type === 'defaut') { |
|
| 1817 | + $objet = objet_type($quoi); |
|
| 1818 | + if ( |
|
| 1819 | + ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 1820 | + || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 1821 | + ) { |
|
| 1822 | + return $f; |
|
| 1823 | + } |
|
| 1824 | + return ''; |
|
| 1825 | + } |
|
| 1826 | + |
|
| 1827 | + $url_type = $type; |
|
| 1828 | + if (!$url_type) { |
|
| 1829 | + $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + // inclure le module d'url |
|
| 1833 | + include_spip('urls/' . $url_type); |
|
| 1834 | + |
|
| 1835 | + switch ($quoi) { |
|
| 1836 | + case 'page': |
|
| 1837 | + if ( |
|
| 1838 | + function_exists($f = "urls_{$url_type}_generer_url_page") |
|
| 1839 | + || function_exists($f .= '_dist') |
|
| 1840 | + // ou une fonction custom utilisateur independante du type d'url |
|
| 1841 | + || function_exists($f = 'generer_url_page') |
|
| 1842 | + || function_exists($f .= '_dist') |
|
| 1843 | + ) { |
|
| 1844 | + return $f; |
|
| 1845 | + } |
|
| 1846 | + // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 1847 | + return ''; |
|
| 1848 | + case 'objet': |
|
| 1849 | + case 'decoder': |
|
| 1850 | + default: |
|
| 1851 | + $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 1852 | + if ( |
|
| 1853 | + function_exists($f = "urls_{$url_type}_{$fquoi}") |
|
| 1854 | + || function_exists($f .= '_dist') |
|
| 1855 | + ) { |
|
| 1856 | + return $f; |
|
| 1857 | + } |
|
| 1858 | + // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 1859 | + // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 1860 | + if ($f = charger_fonction($url_type, 'urls', true)) { |
|
| 1861 | + return $f; |
|
| 1862 | + } |
|
| 1863 | + // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement |
|
| 1864 | + if (!$type && $url_type !== 'page') { |
|
| 1865 | + return charger_fonction_url($quoi, 'page'); |
|
| 1866 | + } |
|
| 1867 | + return ''; |
|
| 1868 | + } |
|
| 1870 | 1869 | } |
| 1871 | 1870 | |
| 1872 | 1871 | |
@@ -1892,48 +1891,48 @@ discard block |
||
| 1892 | 1891 | * url codee ou fonction de decodage |
| 1893 | 1892 | */ |
| 1894 | 1893 | function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 1895 | - if ($public === null) { |
|
| 1896 | - $public = !test_espace_prive(); |
|
| 1897 | - } |
|
| 1898 | - $id = intval($id); |
|
| 1899 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1900 | - |
|
| 1901 | - if (!$public) { |
|
| 1902 | - if (!$entite) { |
|
| 1903 | - return ''; |
|
| 1904 | - } |
|
| 1905 | - if (!function_exists('generer_objet_url_ecrire')) { |
|
| 1906 | - include_spip('inc/urls'); |
|
| 1907 | - } |
|
| 1908 | - $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 1909 | - } else { |
|
| 1910 | - $f = charger_fonction_url('objet', $type ?? ''); |
|
| 1911 | - |
|
| 1912 | - // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 1913 | - // @see charger_fonction_url |
|
| 1914 | - if (!$entite) { |
|
| 1915 | - return $f; |
|
| 1916 | - } |
|
| 1917 | - |
|
| 1918 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1919 | - // base distante |
|
| 1920 | - if ( |
|
| 1921 | - $connect |
|
| 1922 | - && ($g = charger_fonction('connect', 'urls', true)) |
|
| 1923 | - ) { |
|
| 1924 | - $f = $g; |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 1928 | - } |
|
| 1929 | - if ($res) { |
|
| 1930 | - return $res; |
|
| 1931 | - } |
|
| 1932 | - |
|
| 1933 | - // On a ete gentil mais la .... |
|
| 1934 | - spip_log("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1935 | - |
|
| 1936 | - return ''; |
|
| 1894 | + if ($public === null) { |
|
| 1895 | + $public = !test_espace_prive(); |
|
| 1896 | + } |
|
| 1897 | + $id = intval($id); |
|
| 1898 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1899 | + |
|
| 1900 | + if (!$public) { |
|
| 1901 | + if (!$entite) { |
|
| 1902 | + return ''; |
|
| 1903 | + } |
|
| 1904 | + if (!function_exists('generer_objet_url_ecrire')) { |
|
| 1905 | + include_spip('inc/urls'); |
|
| 1906 | + } |
|
| 1907 | + $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 1908 | + } else { |
|
| 1909 | + $f = charger_fonction_url('objet', $type ?? ''); |
|
| 1910 | + |
|
| 1911 | + // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 1912 | + // @see charger_fonction_url |
|
| 1913 | + if (!$entite) { |
|
| 1914 | + return $f; |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1918 | + // base distante |
|
| 1919 | + if ( |
|
| 1920 | + $connect |
|
| 1921 | + && ($g = charger_fonction('connect', 'urls', true)) |
|
| 1922 | + ) { |
|
| 1923 | + $f = $g; |
|
| 1924 | + } |
|
| 1925 | + |
|
| 1926 | + $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 1927 | + } |
|
| 1928 | + if ($res) { |
|
| 1929 | + return $res; |
|
| 1930 | + } |
|
| 1931 | + |
|
| 1932 | + // On a ete gentil mais la .... |
|
| 1933 | + spip_log("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1934 | + |
|
| 1935 | + return ''; |
|
| 1937 | 1936 | } |
| 1938 | 1937 | |
| 1939 | 1938 | /** |
@@ -1941,11 +1940,11 @@ discard block |
||
| 1941 | 1940 | * @see generer_objet_url |
| 1942 | 1941 | */ |
| 1943 | 1942 | function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 1944 | - trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url'); |
|
| 1945 | - if ($public && is_string($public)) { |
|
| 1946 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 1947 | - } |
|
| 1948 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 1943 | + trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url'); |
|
| 1944 | + if ($public && is_string($public)) { |
|
| 1945 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 1946 | + } |
|
| 1947 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 1949 | 1948 | } |
| 1950 | 1949 | |
| 1951 | 1950 | /** |
@@ -1953,19 +1952,19 @@ discard block |
||
| 1953 | 1952 | * @param int|string|null $id |
| 1954 | 1953 | */ |
| 1955 | 1954 | function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string { |
| 1956 | - $id = intval($id); |
|
| 1957 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1958 | - $url = generer_url_ecrire($exec, $args); |
|
| 1959 | - if (intval($id)) { |
|
| 1960 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1961 | - } else { |
|
| 1962 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1963 | - } |
|
| 1964 | - if ($ancre) { |
|
| 1965 | - $url = ancre_url($url, $ancre); |
|
| 1966 | - } |
|
| 1955 | + $id = intval($id); |
|
| 1956 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1957 | + $url = generer_url_ecrire($exec, $args); |
|
| 1958 | + if (intval($id)) { |
|
| 1959 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1960 | + } else { |
|
| 1961 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1962 | + } |
|
| 1963 | + if ($ancre) { |
|
| 1964 | + $url = ancre_url($url, $ancre); |
|
| 1965 | + } |
|
| 1967 | 1966 | |
| 1968 | - return $url; |
|
| 1967 | + return $url; |
|
| 1969 | 1968 | } |
| 1970 | 1969 | |
| 1971 | 1970 | /** |
@@ -1973,19 +1972,19 @@ discard block |
||
| 1973 | 1972 | * @see generer_objet_url_ecrire_edit |
| 1974 | 1973 | */ |
| 1975 | 1974 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 1976 | - trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit'); |
|
| 1977 | - return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 1975 | + trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit'); |
|
| 1976 | + return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 1978 | 1977 | } |
| 1979 | 1978 | |
| 1980 | 1979 | |
| 1981 | 1980 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1982 | - include_spip('base/connect_sql'); |
|
| 1983 | - $id_type = id_table_objet($entite, $public); |
|
| 1981 | + include_spip('base/connect_sql'); |
|
| 1982 | + $id_type = id_table_objet($entite, $public); |
|
| 1984 | 1983 | |
| 1985 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1986 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1987 | - . (!$args ? '' : "&$args") |
|
| 1988 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1984 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1985 | + . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1986 | + . (!$args ? '' : "&$args") |
|
| 1987 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1989 | 1988 | } |
| 1990 | 1989 | |
| 1991 | 1990 | |
@@ -1996,18 +1995,18 @@ discard block |
||
| 1996 | 1995 | * @return string |
| 1997 | 1996 | */ |
| 1998 | 1997 | function urlencode_1738($url) { |
| 1999 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 2000 | - $uri = ''; |
|
| 2001 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 2002 | - if (ord($a = $url[$i]) > 127) { |
|
| 2003 | - $a = rawurlencode($a); |
|
| 2004 | - } |
|
| 2005 | - $uri .= $a; |
|
| 2006 | - } |
|
| 2007 | - $url = $uri; |
|
| 2008 | - } |
|
| 1998 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1999 | + $uri = ''; |
|
| 2000 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 2001 | + if (ord($a = $url[$i]) > 127) { |
|
| 2002 | + $a = rawurlencode($a); |
|
| 2003 | + } |
|
| 2004 | + $uri .= $a; |
|
| 2005 | + } |
|
| 2006 | + $url = $uri; |
|
| 2007 | + } |
|
| 2009 | 2008 | |
| 2010 | - return quote_amp($url); |
|
| 2009 | + return quote_amp($url); |
|
| 2011 | 2010 | } |
| 2012 | 2011 | |
| 2013 | 2012 | /** |
@@ -2016,14 +2015,14 @@ discard block |
||
| 2016 | 2015 | * @param int|string|null $id |
| 2017 | 2016 | */ |
| 2018 | 2017 | function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 2019 | - $id = intval($id); |
|
| 2020 | - $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 2021 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 2022 | - include_spip('inc/filtres_mini'); |
|
| 2023 | - $h = url_absolue($h); |
|
| 2024 | - } |
|
| 2018 | + $id = intval($id); |
|
| 2019 | + $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 2020 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 2021 | + include_spip('inc/filtres_mini'); |
|
| 2022 | + $h = url_absolue($h); |
|
| 2023 | + } |
|
| 2025 | 2024 | |
| 2026 | - return $h; |
|
| 2025 | + return $h; |
|
| 2027 | 2026 | } |
| 2028 | 2027 | |
| 2029 | 2028 | /** |
@@ -2031,8 +2030,8 @@ discard block |
||
| 2031 | 2030 | * @see generer_objet_url_absolue |
| 2032 | 2031 | */ |
| 2033 | 2032 | function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) { |
| 2034 | - trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue'); |
|
| 2035 | - return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? ''); |
|
| 2033 | + trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue'); |
|
| 2034 | + return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? ''); |
|
| 2036 | 2035 | } |
| 2037 | 2036 | |
| 2038 | 2037 | |
@@ -2048,11 +2047,11 @@ discard block |
||
| 2048 | 2047 | * true si la valeur est considérée active ; false sinon. |
| 2049 | 2048 | **/ |
| 2050 | 2049 | function test_valeur_serveur($truc) { |
| 2051 | - if (!$truc) { |
|
| 2052 | - return false; |
|
| 2053 | - } |
|
| 2050 | + if (!$truc) { |
|
| 2051 | + return false; |
|
| 2052 | + } |
|
| 2054 | 2053 | |
| 2055 | - return (strtolower($truc) !== 'off'); |
|
| 2054 | + return (strtolower($truc) !== 'off'); |
|
| 2056 | 2055 | } |
| 2057 | 2056 | |
| 2058 | 2057 | // |
@@ -2080,89 +2079,89 @@ discard block |
||
| 2080 | 2079 | */ |
| 2081 | 2080 | function url_de_base($profondeur = null) { |
| 2082 | 2081 | |
| 2083 | - static $url = []; |
|
| 2084 | - if (is_array($profondeur)) { |
|
| 2085 | - return $url = $profondeur; |
|
| 2086 | - } |
|
| 2087 | - if ($profondeur === false) { |
|
| 2088 | - return $url; |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - if (is_null($profondeur)) { |
|
| 2092 | - $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 2093 | - } |
|
| 2094 | - |
|
| 2095 | - if (isset($url[$profondeur])) { |
|
| 2096 | - return $url[$profondeur]; |
|
| 2097 | - } |
|
| 2098 | - |
|
| 2099 | - $http = 'http'; |
|
| 2100 | - |
|
| 2101 | - if ( |
|
| 2102 | - isset($_SERVER['SCRIPT_URI']) |
|
| 2103 | - && str_starts_with($_SERVER['SCRIPT_URI'], 'https') |
|
| 2104 | - ) { |
|
| 2105 | - $http = 'https'; |
|
| 2106 | - } elseif ( |
|
| 2107 | - isset($_SERVER['HTTPS']) |
|
| 2108 | - && test_valeur_serveur($_SERVER['HTTPS']) |
|
| 2109 | - ) { |
|
| 2110 | - $http = 'https'; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 2114 | - if ($host = $_SERVER['HTTP_HOST'] ?? null) { |
|
| 2115 | - // Filtrer $host pour proteger d'attaques d'entete HTTP |
|
| 2116 | - $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null); |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2120 | - if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2121 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 2122 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2123 | - $http = $scheme; |
|
| 2124 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 2125 | - } |
|
| 2126 | - } |
|
| 2127 | - if ( |
|
| 2128 | - isset($_SERVER['SERVER_PORT']) |
|
| 2129 | - && ($port = $_SERVER['SERVER_PORT']) |
|
| 2130 | - && !str_contains($host, ':') |
|
| 2131 | - ) { |
|
| 2132 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2133 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 2134 | - } |
|
| 2135 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2136 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2137 | - } |
|
| 2138 | - if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2139 | - $host .= ":$port"; |
|
| 2140 | - } |
|
| 2141 | - if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2142 | - $host .= ":$port"; |
|
| 2143 | - } |
|
| 2144 | - } |
|
| 2145 | - |
|
| 2146 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 2147 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2148 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2149 | - } else { |
|
| 2150 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2151 | - if ( |
|
| 2152 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2153 | - && !str_contains($_SERVER['REQUEST_URI'], '?') |
|
| 2154 | - ) { |
|
| 2155 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2156 | - } |
|
| 2157 | - } |
|
| 2158 | - } |
|
| 2159 | - |
|
| 2160 | - // Et nettoyer l'url |
|
| 2161 | - $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: ''); |
|
| 2162 | - |
|
| 2163 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2164 | - |
|
| 2165 | - return $url[$profondeur]; |
|
| 2082 | + static $url = []; |
|
| 2083 | + if (is_array($profondeur)) { |
|
| 2084 | + return $url = $profondeur; |
|
| 2085 | + } |
|
| 2086 | + if ($profondeur === false) { |
|
| 2087 | + return $url; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + if (is_null($profondeur)) { |
|
| 2091 | + $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + if (isset($url[$profondeur])) { |
|
| 2095 | + return $url[$profondeur]; |
|
| 2096 | + } |
|
| 2097 | + |
|
| 2098 | + $http = 'http'; |
|
| 2099 | + |
|
| 2100 | + if ( |
|
| 2101 | + isset($_SERVER['SCRIPT_URI']) |
|
| 2102 | + && str_starts_with($_SERVER['SCRIPT_URI'], 'https') |
|
| 2103 | + ) { |
|
| 2104 | + $http = 'https'; |
|
| 2105 | + } elseif ( |
|
| 2106 | + isset($_SERVER['HTTPS']) |
|
| 2107 | + && test_valeur_serveur($_SERVER['HTTPS']) |
|
| 2108 | + ) { |
|
| 2109 | + $http = 'https'; |
|
| 2110 | + } |
|
| 2111 | + |
|
| 2112 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 2113 | + if ($host = $_SERVER['HTTP_HOST'] ?? null) { |
|
| 2114 | + // Filtrer $host pour proteger d'attaques d'entete HTTP |
|
| 2115 | + $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null); |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2119 | + if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2120 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 2121 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2122 | + $http = $scheme; |
|
| 2123 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 2124 | + } |
|
| 2125 | + } |
|
| 2126 | + if ( |
|
| 2127 | + isset($_SERVER['SERVER_PORT']) |
|
| 2128 | + && ($port = $_SERVER['SERVER_PORT']) |
|
| 2129 | + && !str_contains($host, ':') |
|
| 2130 | + ) { |
|
| 2131 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2132 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 2133 | + } |
|
| 2134 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2135 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2136 | + } |
|
| 2137 | + if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2138 | + $host .= ":$port"; |
|
| 2139 | + } |
|
| 2140 | + if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2141 | + $host .= ":$port"; |
|
| 2142 | + } |
|
| 2143 | + } |
|
| 2144 | + |
|
| 2145 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 2146 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2147 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2148 | + } else { |
|
| 2149 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2150 | + if ( |
|
| 2151 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2152 | + && !str_contains($_SERVER['REQUEST_URI'], '?') |
|
| 2153 | + ) { |
|
| 2154 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2155 | + } |
|
| 2156 | + } |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + // Et nettoyer l'url |
|
| 2160 | + $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: ''); |
|
| 2161 | + |
|
| 2162 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2163 | + |
|
| 2164 | + return $url[$profondeur]; |
|
| 2166 | 2165 | } |
| 2167 | 2166 | |
| 2168 | 2167 | /** |
@@ -2175,26 +2174,26 @@ discard block |
||
| 2175 | 2174 | * @return string |
| 2176 | 2175 | */ |
| 2177 | 2176 | function url_de_($http, $host, $request, $prof = 0) { |
| 2178 | - $prof = max($prof, 0); |
|
| 2177 | + $prof = max($prof, 0); |
|
| 2179 | 2178 | |
| 2180 | - $myself = ltrim($request, '/'); |
|
| 2181 | - # supprimer la chaine de GET |
|
| 2182 | - [$myself] = explode('?', $myself); |
|
| 2183 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2184 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2185 | - if (str_contains($myself, '://')) { |
|
| 2186 | - $myself = explode('://', $myself); |
|
| 2187 | - array_shift($myself); |
|
| 2188 | - $myself = implode('://', $myself); |
|
| 2189 | - $myself = explode('/', $myself); |
|
| 2190 | - array_shift($myself); |
|
| 2191 | - $myself = implode('/', $myself); |
|
| 2192 | - } |
|
| 2193 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2179 | + $myself = ltrim($request, '/'); |
|
| 2180 | + # supprimer la chaine de GET |
|
| 2181 | + [$myself] = explode('?', $myself); |
|
| 2182 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2183 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2184 | + if (str_contains($myself, '://')) { |
|
| 2185 | + $myself = explode('://', $myself); |
|
| 2186 | + array_shift($myself); |
|
| 2187 | + $myself = implode('://', $myself); |
|
| 2188 | + $myself = explode('/', $myself); |
|
| 2189 | + array_shift($myself); |
|
| 2190 | + $myself = implode('/', $myself); |
|
| 2191 | + } |
|
| 2192 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2194 | 2193 | |
| 2195 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2194 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2196 | 2195 | |
| 2197 | - return $url; |
|
| 2196 | + return $url; |
|
| 2198 | 2197 | } |
| 2199 | 2198 | |
| 2200 | 2199 | |
@@ -2229,26 +2228,26 @@ discard block |
||
| 2229 | 2228 | * @return string URL |
| 2230 | 2229 | **/ |
| 2231 | 2230 | function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) { |
| 2232 | - $script ??= ''; |
|
| 2233 | - if (!$rel) { |
|
| 2234 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2235 | - } else { |
|
| 2236 | - if (!is_string($rel)) { |
|
| 2237 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2238 | - } |
|
| 2239 | - } |
|
| 2240 | - |
|
| 2241 | - [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2242 | - if ($script && ($script <> 'accueil' || $rel)) { |
|
| 2243 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2244 | - } elseif ($args) { |
|
| 2245 | - $args = "?$args"; |
|
| 2246 | - } |
|
| 2247 | - if ($ancre) { |
|
| 2248 | - $args .= "#$ancre"; |
|
| 2249 | - } |
|
| 2250 | - |
|
| 2251 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2231 | + $script ??= ''; |
|
| 2232 | + if (!$rel) { |
|
| 2233 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2234 | + } else { |
|
| 2235 | + if (!is_string($rel)) { |
|
| 2236 | + $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2237 | + } |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2241 | + if ($script && ($script <> 'accueil' || $rel)) { |
|
| 2242 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2243 | + } elseif ($args) { |
|
| 2244 | + $args = "?$args"; |
|
| 2245 | + } |
|
| 2246 | + if ($ancre) { |
|
| 2247 | + $args .= "#$ancre"; |
|
| 2248 | + } |
|
| 2249 | + |
|
| 2250 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2252 | 2251 | } |
| 2253 | 2252 | |
| 2254 | 2253 | // |
@@ -2270,15 +2269,15 @@ discard block |
||
| 2270 | 2269 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2271 | 2270 | **/ |
| 2272 | 2271 | function get_spip_script($default = '') { |
| 2273 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2274 | - return 'spip.php'; |
|
| 2275 | - } |
|
| 2276 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2277 | - if (_SPIP_SCRIPT) { |
|
| 2278 | - return _SPIP_SCRIPT; |
|
| 2279 | - } else { |
|
| 2280 | - return $default; |
|
| 2281 | - } |
|
| 2272 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2273 | + return 'spip.php'; |
|
| 2274 | + } |
|
| 2275 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2276 | + if (_SPIP_SCRIPT) { |
|
| 2277 | + return _SPIP_SCRIPT; |
|
| 2278 | + } else { |
|
| 2279 | + return $default; |
|
| 2280 | + } |
|
| 2282 | 2281 | } |
| 2283 | 2282 | |
| 2284 | 2283 | /** |
@@ -2307,45 +2306,45 @@ discard block |
||
| 2307 | 2306 | * @return string URL |
| 2308 | 2307 | **/ |
| 2309 | 2308 | function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') { |
| 2310 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2311 | - // standardiser vers la nouvelle API |
|
| 2312 | - |
|
| 2313 | - if (is_array($args)) { |
|
| 2314 | - $args = http_build_query($args); |
|
| 2315 | - } |
|
| 2316 | - |
|
| 2317 | - $url = ''; |
|
| 2318 | - if ($f = charger_fonction_url('page')) { |
|
| 2319 | - $url = $f($script, $args); |
|
| 2320 | - if ($url && !$rel) { |
|
| 2321 | - include_spip('inc/filtres_mini'); |
|
| 2322 | - $url = url_absolue($url); |
|
| 2323 | - } |
|
| 2324 | - } |
|
| 2325 | - if (!$url) { |
|
| 2326 | - if (!$action) { |
|
| 2327 | - $action = get_spip_script(); |
|
| 2328 | - } |
|
| 2329 | - if ($script) { |
|
| 2330 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2331 | - } |
|
| 2332 | - if ($args) { |
|
| 2333 | - $action .= (str_contains($action, '?') ? '&' : '?') . $args; |
|
| 2334 | - } |
|
| 2335 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2336 | - $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2337 | - } |
|
| 2338 | - |
|
| 2339 | - if (!$no_entities) { |
|
| 2340 | - $url = quote_amp($url); |
|
| 2341 | - } |
|
| 2342 | - |
|
| 2343 | - return $url; |
|
| 2309 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2310 | + // standardiser vers la nouvelle API |
|
| 2311 | + |
|
| 2312 | + if (is_array($args)) { |
|
| 2313 | + $args = http_build_query($args); |
|
| 2314 | + } |
|
| 2315 | + |
|
| 2316 | + $url = ''; |
|
| 2317 | + if ($f = charger_fonction_url('page')) { |
|
| 2318 | + $url = $f($script, $args); |
|
| 2319 | + if ($url && !$rel) { |
|
| 2320 | + include_spip('inc/filtres_mini'); |
|
| 2321 | + $url = url_absolue($url); |
|
| 2322 | + } |
|
| 2323 | + } |
|
| 2324 | + if (!$url) { |
|
| 2325 | + if (!$action) { |
|
| 2326 | + $action = get_spip_script(); |
|
| 2327 | + } |
|
| 2328 | + if ($script) { |
|
| 2329 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2330 | + } |
|
| 2331 | + if ($args) { |
|
| 2332 | + $action .= (str_contains($action, '?') ? '&' : '?') . $args; |
|
| 2333 | + } |
|
| 2334 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2335 | + $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2336 | + } |
|
| 2337 | + |
|
| 2338 | + if (!$no_entities) { |
|
| 2339 | + $url = quote_amp($url); |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + return $url; |
|
| 2344 | 2343 | } |
| 2345 | 2344 | |
| 2346 | 2345 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2347 | 2346 | |
| 2348 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2347 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2349 | 2348 | } |
| 2350 | 2349 | |
| 2351 | 2350 | // Pour les formulaires en methode POST, |
@@ -2370,19 +2369,19 @@ discard block |
||
| 2370 | 2369 | **/ |
| 2371 | 2370 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2372 | 2371 | |
| 2373 | - $script1 = explode('&', $script); |
|
| 2374 | - $script1 = reset($script1); |
|
| 2372 | + $script1 = explode('&', $script); |
|
| 2373 | + $script1 = reset($script1); |
|
| 2375 | 2374 | |
| 2376 | - return "<form action='" |
|
| 2377 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2378 | - . "' " |
|
| 2379 | - . ($atts ?: " method='post'") |
|
| 2380 | - . "><div>\n" |
|
| 2381 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2382 | - . $corps |
|
| 2383 | - . (!$submit ? '' : |
|
| 2384 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2385 | - . "</div></form>\n"; |
|
| 2375 | + return "<form action='" |
|
| 2376 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2377 | + . "' " |
|
| 2378 | + . ($atts ?: " method='post'") |
|
| 2379 | + . "><div>\n" |
|
| 2380 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2381 | + . $corps |
|
| 2382 | + . (!$submit ? '' : |
|
| 2383 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2384 | + . "</div></form>\n"; |
|
| 2386 | 2385 | } |
| 2387 | 2386 | |
| 2388 | 2387 | /** |
@@ -2399,22 +2398,22 @@ discard block |
||
| 2399 | 2398 | * @return string |
| 2400 | 2399 | */ |
| 2401 | 2400 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2402 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2403 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2404 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2405 | - $h = (_DIR_RACINE && !$public) |
|
| 2406 | - ? generer_url_ecrire(_request('exec')) |
|
| 2407 | - : generer_url_public(); |
|
| 2401 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2402 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2403 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2404 | + $h = (_DIR_RACINE && !$public) |
|
| 2405 | + ? generer_url_ecrire(_request('exec')) |
|
| 2406 | + : generer_url_public(); |
|
| 2408 | 2407 | |
| 2409 | - return "\n<form action='" . |
|
| 2410 | - $h . |
|
| 2411 | - "'" . |
|
| 2412 | - $atts . |
|
| 2413 | - ">\n" . |
|
| 2414 | - '<div>' . |
|
| 2415 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2416 | - $corps . |
|
| 2417 | - '</div></form>'; |
|
| 2408 | + return "\n<form action='" . |
|
| 2409 | + $h . |
|
| 2410 | + "'" . |
|
| 2411 | + $atts . |
|
| 2412 | + ">\n" . |
|
| 2413 | + '<div>' . |
|
| 2414 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2415 | + $corps . |
|
| 2416 | + '</div></form>'; |
|
| 2418 | 2417 | } |
| 2419 | 2418 | |
| 2420 | 2419 | /** |
@@ -2433,22 +2432,22 @@ discard block |
||
| 2433 | 2432 | * URL |
| 2434 | 2433 | */ |
| 2435 | 2434 | function generer_url_action($script, $args = '', $no_entities = false, $public = false) { |
| 2436 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2437 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2438 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2439 | - $url = (_DIR_RACINE && !$public) |
|
| 2440 | - ? generer_url_ecrire(_request('exec')) |
|
| 2441 | - : generer_url_public('', '', false, false); |
|
| 2442 | - $url = parametre_url($url, 'action', $script); |
|
| 2443 | - if ($args) { |
|
| 2444 | - $url .= quote_amp('&' . $args); |
|
| 2445 | - } |
|
| 2435 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2436 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2437 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2438 | + $url = (_DIR_RACINE && !$public) |
|
| 2439 | + ? generer_url_ecrire(_request('exec')) |
|
| 2440 | + : generer_url_public('', '', false, false); |
|
| 2441 | + $url = parametre_url($url, 'action', $script); |
|
| 2442 | + if ($args) { |
|
| 2443 | + $url .= quote_amp('&' . $args); |
|
| 2444 | + } |
|
| 2446 | 2445 | |
| 2447 | - if ($no_entities) { |
|
| 2448 | - $url = str_replace('&', '&', $url); |
|
| 2449 | - } |
|
| 2446 | + if ($no_entities) { |
|
| 2447 | + $url = str_replace('&', '&', $url); |
|
| 2448 | + } |
|
| 2450 | 2449 | |
| 2451 | - return $url; |
|
| 2450 | + return $url; |
|
| 2452 | 2451 | } |
| 2453 | 2452 | |
| 2454 | 2453 | |
@@ -2467,23 +2466,23 @@ discard block |
||
| 2467 | 2466 | * URL |
| 2468 | 2467 | */ |
| 2469 | 2468 | function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 2470 | - if (is_null($public)) { |
|
| 2471 | - $public = (_DIR_RACINE ? false : true); |
|
| 2472 | - } |
|
| 2473 | - if (!str_ends_with($script, '.api')) { |
|
| 2474 | - $script .= '.api'; |
|
| 2475 | - } |
|
| 2476 | - $url = |
|
| 2477 | - (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 2478 | - . $script . '/' |
|
| 2479 | - . ($path ? trim($path, '/') : '') |
|
| 2480 | - . ($args ? '?' . quote_amp($args) : ''); |
|
| 2469 | + if (is_null($public)) { |
|
| 2470 | + $public = (_DIR_RACINE ? false : true); |
|
| 2471 | + } |
|
| 2472 | + if (!str_ends_with($script, '.api')) { |
|
| 2473 | + $script .= '.api'; |
|
| 2474 | + } |
|
| 2475 | + $url = |
|
| 2476 | + (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 2477 | + . $script . '/' |
|
| 2478 | + . ($path ? trim($path, '/') : '') |
|
| 2479 | + . ($args ? '?' . quote_amp($args) : ''); |
|
| 2481 | 2480 | |
| 2482 | - if ($no_entities) { |
|
| 2483 | - $url = str_replace('&', '&', $url); |
|
| 2484 | - } |
|
| 2481 | + if ($no_entities) { |
|
| 2482 | + $url = str_replace('&', '&', $url); |
|
| 2483 | + } |
|
| 2485 | 2484 | |
| 2486 | - return $url; |
|
| 2485 | + return $url; |
|
| 2487 | 2486 | } |
| 2488 | 2487 | |
| 2489 | 2488 | |
@@ -2496,8 +2495,8 @@ discard block |
||
| 2496 | 2495 | * @param string $ta Répertoire temporaire accessible |
| 2497 | 2496 | */ |
| 2498 | 2497 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2499 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2500 | - spip_initialisation_suite(); |
|
| 2498 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2499 | + spip_initialisation_suite(); |
|
| 2501 | 2500 | } |
| 2502 | 2501 | |
| 2503 | 2502 | /** |
@@ -2517,311 +2516,311 @@ discard block |
||
| 2517 | 2516 | * @param string $ta Répertoire temporaire accessible |
| 2518 | 2517 | */ |
| 2519 | 2518 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2520 | - static $too_late = 0; |
|
| 2521 | - if ($too_late++) { |
|
| 2522 | - return; |
|
| 2523 | - } |
|
| 2524 | - |
|
| 2525 | - // Declaration des repertoires |
|
| 2526 | - |
|
| 2527 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2528 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2529 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2533 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2534 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - // le nom du repertoire des librairies |
|
| 2538 | - if (!defined('_DIR_LIB')) { |
|
| 2539 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2540 | - } |
|
| 2541 | - |
|
| 2542 | - // répertoire des libs via Composer |
|
| 2543 | - if (!defined('_DIR_VENDOR')) { |
|
| 2544 | - define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 2545 | - } |
|
| 2546 | - |
|
| 2547 | - if (!defined('_DIR_IMG')) { |
|
| 2548 | - define('_DIR_IMG', $pa); |
|
| 2549 | - } |
|
| 2550 | - if (!defined('_DIR_LOGOS')) { |
|
| 2551 | - define('_DIR_LOGOS', $pa); |
|
| 2552 | - } |
|
| 2553 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2554 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2555 | - } |
|
| 2556 | - |
|
| 2557 | - if (!defined('_DIR_DUMP')) { |
|
| 2558 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2559 | - } |
|
| 2560 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2561 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2562 | - } |
|
| 2563 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2564 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2565 | - } |
|
| 2566 | - if (!defined('_DIR_CACHE')) { |
|
| 2567 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2568 | - } |
|
| 2569 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2570 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2571 | - } |
|
| 2572 | - if (!defined('_DIR_SKELS')) { |
|
| 2573 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2574 | - } |
|
| 2575 | - if (!defined('_DIR_AIDE')) { |
|
| 2576 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2577 | - } |
|
| 2578 | - if (!defined('_DIR_TMP')) { |
|
| 2579 | - define('_DIR_TMP', $ti); |
|
| 2580 | - } |
|
| 2581 | - |
|
| 2582 | - if (!defined('_DIR_VAR')) { |
|
| 2583 | - define('_DIR_VAR', $ta); |
|
| 2584 | - } |
|
| 2585 | - |
|
| 2586 | - if (!defined('_DIR_ETC')) { |
|
| 2587 | - define('_DIR_ETC', $pi); |
|
| 2588 | - } |
|
| 2589 | - if (!defined('_DIR_CONNECT')) { |
|
| 2590 | - define('_DIR_CONNECT', $pi); |
|
| 2591 | - } |
|
| 2592 | - if (!defined('_DIR_CHMOD')) { |
|
| 2593 | - define('_DIR_CHMOD', $pi); |
|
| 2594 | - } |
|
| 2595 | - |
|
| 2596 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 2597 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2598 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2599 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2600 | - } |
|
| 2601 | - |
|
| 2602 | - // Declaration des fichiers |
|
| 2603 | - |
|
| 2604 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2605 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2606 | - } |
|
| 2607 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2608 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2609 | - } |
|
| 2610 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2611 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2612 | - } |
|
| 2613 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2614 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2615 | - } |
|
| 2616 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2617 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2621 | - if (!defined('_FILE_META')) { |
|
| 2622 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2623 | - } |
|
| 2624 | - if (!defined('_DIR_LOG')) { |
|
| 2625 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2626 | - } |
|
| 2627 | - if (!defined('_FILE_LOG')) { |
|
| 2628 | - define('_FILE_LOG', 'spip'); |
|
| 2629 | - } |
|
| 2630 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2631 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2632 | - } |
|
| 2633 | - |
|
| 2634 | - // Le fichier de connexion a la base de donnees |
|
| 2635 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2636 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2637 | - } |
|
| 2638 | - if (!defined('_FILE_CONNECT')) { |
|
| 2639 | - define( |
|
| 2640 | - '_FILE_CONNECT', |
|
| 2641 | - @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 2642 | - ); |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - // Le fichier de reglages des droits |
|
| 2646 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2647 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2648 | - } |
|
| 2649 | - if (!defined('_FILE_CHMOD')) { |
|
| 2650 | - define( |
|
| 2651 | - '_FILE_CHMOD', |
|
| 2652 | - @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 2653 | - ); |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - if (!defined('_FILE_LDAP')) { |
|
| 2657 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2658 | - } |
|
| 2659 | - |
|
| 2660 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2661 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2662 | - } |
|
| 2663 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2664 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2665 | - } |
|
| 2666 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2667 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2668 | - } |
|
| 2669 | - |
|
| 2670 | - // Definition des droits d'acces en ecriture |
|
| 2671 | - if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) { |
|
| 2672 | - include_once _FILE_CHMOD; |
|
| 2673 | - } |
|
| 2674 | - |
|
| 2675 | - // Se mefier des fichiers mal remplis! |
|
| 2676 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2677 | - define('_SPIP_CHMOD', 0777); |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2681 | - /** Le charset par défaut lors de l'installation */ |
|
| 2682 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2683 | - } |
|
| 2684 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2685 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2686 | - } |
|
| 2687 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2688 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2689 | - } |
|
| 2690 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2691 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2692 | - } |
|
| 2693 | - |
|
| 2694 | - // La taille des Log |
|
| 2695 | - if (!defined('_MAX_LOG')) { |
|
| 2696 | - define('_MAX_LOG', 100); |
|
| 2697 | - } |
|
| 2698 | - |
|
| 2699 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2700 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2701 | - if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) { |
|
| 2702 | - if (!defined('_OS_SERVEUR')) { |
|
| 2703 | - define('_OS_SERVEUR', 'windows'); |
|
| 2704 | - } |
|
| 2705 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2706 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2707 | - } // utiliser le flock php |
|
| 2708 | - } else { |
|
| 2709 | - if (!defined('_OS_SERVEUR')) { |
|
| 2710 | - define('_OS_SERVEUR', ''); |
|
| 2711 | - } |
|
| 2712 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2713 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2714 | - } // utiliser le flock php |
|
| 2715 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2716 | - } |
|
| 2717 | - |
|
| 2718 | - // Langue par defaut |
|
| 2719 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2720 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2721 | - } |
|
| 2722 | - |
|
| 2723 | - // |
|
| 2724 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2725 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2726 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2727 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2728 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2729 | - |
|
| 2730 | - // charger tout de suite le path et son cache |
|
| 2731 | - load_path_cache(); |
|
| 2732 | - |
|
| 2733 | - // *********** traiter les variables ************ |
|
| 2734 | - |
|
| 2735 | - // |
|
| 2736 | - // Securite |
|
| 2737 | - // |
|
| 2738 | - |
|
| 2739 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2740 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2741 | - die(); |
|
| 2742 | - } |
|
| 2743 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2744 | - spip_desinfecte($_GET); |
|
| 2745 | - spip_desinfecte($_POST); |
|
| 2746 | - spip_desinfecte($_COOKIE); |
|
| 2747 | - spip_desinfecte($_REQUEST); |
|
| 2748 | - |
|
| 2749 | - // appliquer le cookie_prefix |
|
| 2750 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2751 | - include_spip('inc/cookie'); |
|
| 2752 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2756 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2757 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2758 | - } else { |
|
| 2759 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2760 | - if ( |
|
| 2761 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2762 | - && !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2763 | - ) { |
|
| 2764 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2765 | - } |
|
| 2766 | - } |
|
| 2767 | - |
|
| 2768 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2769 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2770 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2771 | - } |
|
| 2772 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2773 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2774 | - } |
|
| 2775 | - |
|
| 2776 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2777 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2778 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2779 | - $inc_meta(); |
|
| 2780 | - |
|
| 2781 | - // nombre de repertoires depuis la racine |
|
| 2782 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2783 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2784 | - // le calcul est faux) |
|
| 2785 | - if (!_DIR_RESTREINT) { |
|
| 2786 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2787 | - } else { |
|
| 2788 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2789 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2790 | - if ( |
|
| 2791 | - !$uri_ref |
|
| 2792 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2793 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2794 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2795 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2796 | - || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2797 | - ) { |
|
| 2798 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2799 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2800 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2801 | - } else { |
|
| 2802 | - $uri_ref = ''; |
|
| 2803 | - } |
|
| 2804 | - } |
|
| 2805 | - if (!$uri || !$uri_ref) { |
|
| 2806 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2807 | - } else { |
|
| 2808 | - $GLOBALS['profondeur_url'] = max( |
|
| 2809 | - 0, |
|
| 2810 | - substr_count($uri[0], '/') |
|
| 2811 | - - substr_count($uri_ref, '/') |
|
| 2812 | - ); |
|
| 2813 | - } |
|
| 2814 | - } |
|
| 2815 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2816 | - if (_FILE_CONNECT) { |
|
| 2817 | - if ( |
|
| 2818 | - verifier_visiteur() == '0minirezo' |
|
| 2819 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2820 | - && !isset($_COOKIE['spip_admin']) |
|
| 2821 | - ) { |
|
| 2822 | - clear_path_cache(); |
|
| 2823 | - } |
|
| 2824 | - } |
|
| 2519 | + static $too_late = 0; |
|
| 2520 | + if ($too_late++) { |
|
| 2521 | + return; |
|
| 2522 | + } |
|
| 2523 | + |
|
| 2524 | + // Declaration des repertoires |
|
| 2525 | + |
|
| 2526 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2527 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2528 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2529 | + } |
|
| 2530 | + |
|
| 2531 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2532 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2533 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + // le nom du repertoire des librairies |
|
| 2537 | + if (!defined('_DIR_LIB')) { |
|
| 2538 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + // répertoire des libs via Composer |
|
| 2542 | + if (!defined('_DIR_VENDOR')) { |
|
| 2543 | + define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + if (!defined('_DIR_IMG')) { |
|
| 2547 | + define('_DIR_IMG', $pa); |
|
| 2548 | + } |
|
| 2549 | + if (!defined('_DIR_LOGOS')) { |
|
| 2550 | + define('_DIR_LOGOS', $pa); |
|
| 2551 | + } |
|
| 2552 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2553 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + if (!defined('_DIR_DUMP')) { |
|
| 2557 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2558 | + } |
|
| 2559 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2560 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2561 | + } |
|
| 2562 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2563 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2564 | + } |
|
| 2565 | + if (!defined('_DIR_CACHE')) { |
|
| 2566 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2567 | + } |
|
| 2568 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2569 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2570 | + } |
|
| 2571 | + if (!defined('_DIR_SKELS')) { |
|
| 2572 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2573 | + } |
|
| 2574 | + if (!defined('_DIR_AIDE')) { |
|
| 2575 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2576 | + } |
|
| 2577 | + if (!defined('_DIR_TMP')) { |
|
| 2578 | + define('_DIR_TMP', $ti); |
|
| 2579 | + } |
|
| 2580 | + |
|
| 2581 | + if (!defined('_DIR_VAR')) { |
|
| 2582 | + define('_DIR_VAR', $ta); |
|
| 2583 | + } |
|
| 2584 | + |
|
| 2585 | + if (!defined('_DIR_ETC')) { |
|
| 2586 | + define('_DIR_ETC', $pi); |
|
| 2587 | + } |
|
| 2588 | + if (!defined('_DIR_CONNECT')) { |
|
| 2589 | + define('_DIR_CONNECT', $pi); |
|
| 2590 | + } |
|
| 2591 | + if (!defined('_DIR_CHMOD')) { |
|
| 2592 | + define('_DIR_CHMOD', $pi); |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 2596 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2597 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2598 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2599 | + } |
|
| 2600 | + |
|
| 2601 | + // Declaration des fichiers |
|
| 2602 | + |
|
| 2603 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2604 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2605 | + } |
|
| 2606 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2607 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2608 | + } |
|
| 2609 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2610 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2611 | + } |
|
| 2612 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2613 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2614 | + } |
|
| 2615 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2616 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2620 | + if (!defined('_FILE_META')) { |
|
| 2621 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2622 | + } |
|
| 2623 | + if (!defined('_DIR_LOG')) { |
|
| 2624 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2625 | + } |
|
| 2626 | + if (!defined('_FILE_LOG')) { |
|
| 2627 | + define('_FILE_LOG', 'spip'); |
|
| 2628 | + } |
|
| 2629 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2630 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + // Le fichier de connexion a la base de donnees |
|
| 2634 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2635 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2636 | + } |
|
| 2637 | + if (!defined('_FILE_CONNECT')) { |
|
| 2638 | + define( |
|
| 2639 | + '_FILE_CONNECT', |
|
| 2640 | + @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 2641 | + ); |
|
| 2642 | + } |
|
| 2643 | + |
|
| 2644 | + // Le fichier de reglages des droits |
|
| 2645 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2646 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2647 | + } |
|
| 2648 | + if (!defined('_FILE_CHMOD')) { |
|
| 2649 | + define( |
|
| 2650 | + '_FILE_CHMOD', |
|
| 2651 | + @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 2652 | + ); |
|
| 2653 | + } |
|
| 2654 | + |
|
| 2655 | + if (!defined('_FILE_LDAP')) { |
|
| 2656 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2660 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2661 | + } |
|
| 2662 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2663 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2664 | + } |
|
| 2665 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2666 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2667 | + } |
|
| 2668 | + |
|
| 2669 | + // Definition des droits d'acces en ecriture |
|
| 2670 | + if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) { |
|
| 2671 | + include_once _FILE_CHMOD; |
|
| 2672 | + } |
|
| 2673 | + |
|
| 2674 | + // Se mefier des fichiers mal remplis! |
|
| 2675 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2676 | + define('_SPIP_CHMOD', 0777); |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2680 | + /** Le charset par défaut lors de l'installation */ |
|
| 2681 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2682 | + } |
|
| 2683 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2684 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2685 | + } |
|
| 2686 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2687 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2688 | + } |
|
| 2689 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2690 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2691 | + } |
|
| 2692 | + |
|
| 2693 | + // La taille des Log |
|
| 2694 | + if (!defined('_MAX_LOG')) { |
|
| 2695 | + define('_MAX_LOG', 100); |
|
| 2696 | + } |
|
| 2697 | + |
|
| 2698 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2699 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2700 | + if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) { |
|
| 2701 | + if (!defined('_OS_SERVEUR')) { |
|
| 2702 | + define('_OS_SERVEUR', 'windows'); |
|
| 2703 | + } |
|
| 2704 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2705 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2706 | + } // utiliser le flock php |
|
| 2707 | + } else { |
|
| 2708 | + if (!defined('_OS_SERVEUR')) { |
|
| 2709 | + define('_OS_SERVEUR', ''); |
|
| 2710 | + } |
|
| 2711 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2712 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2713 | + } // utiliser le flock php |
|
| 2714 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2715 | + } |
|
| 2716 | + |
|
| 2717 | + // Langue par defaut |
|
| 2718 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2719 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2720 | + } |
|
| 2721 | + |
|
| 2722 | + // |
|
| 2723 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2724 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2725 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2726 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2727 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2728 | + |
|
| 2729 | + // charger tout de suite le path et son cache |
|
| 2730 | + load_path_cache(); |
|
| 2731 | + |
|
| 2732 | + // *********** traiter les variables ************ |
|
| 2733 | + |
|
| 2734 | + // |
|
| 2735 | + // Securite |
|
| 2736 | + // |
|
| 2737 | + |
|
| 2738 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2739 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2740 | + die(); |
|
| 2741 | + } |
|
| 2742 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2743 | + spip_desinfecte($_GET); |
|
| 2744 | + spip_desinfecte($_POST); |
|
| 2745 | + spip_desinfecte($_COOKIE); |
|
| 2746 | + spip_desinfecte($_REQUEST); |
|
| 2747 | + |
|
| 2748 | + // appliquer le cookie_prefix |
|
| 2749 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2750 | + include_spip('inc/cookie'); |
|
| 2751 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2752 | + } |
|
| 2753 | + |
|
| 2754 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2755 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2756 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2757 | + } else { |
|
| 2758 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2759 | + if ( |
|
| 2760 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2761 | + && !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2762 | + ) { |
|
| 2763 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2764 | + } |
|
| 2765 | + } |
|
| 2766 | + |
|
| 2767 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2768 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2769 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2770 | + } |
|
| 2771 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2772 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2773 | + } |
|
| 2774 | + |
|
| 2775 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2776 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2777 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2778 | + $inc_meta(); |
|
| 2779 | + |
|
| 2780 | + // nombre de repertoires depuis la racine |
|
| 2781 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2782 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2783 | + // le calcul est faux) |
|
| 2784 | + if (!_DIR_RESTREINT) { |
|
| 2785 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2786 | + } else { |
|
| 2787 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2788 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2789 | + if ( |
|
| 2790 | + !$uri_ref |
|
| 2791 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2792 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2793 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2794 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2795 | + || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2796 | + ) { |
|
| 2797 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2798 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2799 | + $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2800 | + } else { |
|
| 2801 | + $uri_ref = ''; |
|
| 2802 | + } |
|
| 2803 | + } |
|
| 2804 | + if (!$uri || !$uri_ref) { |
|
| 2805 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2806 | + } else { |
|
| 2807 | + $GLOBALS['profondeur_url'] = max( |
|
| 2808 | + 0, |
|
| 2809 | + substr_count($uri[0], '/') |
|
| 2810 | + - substr_count($uri_ref, '/') |
|
| 2811 | + ); |
|
| 2812 | + } |
|
| 2813 | + } |
|
| 2814 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2815 | + if (_FILE_CONNECT) { |
|
| 2816 | + if ( |
|
| 2817 | + verifier_visiteur() == '0minirezo' |
|
| 2818 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2819 | + && !isset($_COOKIE['spip_admin']) |
|
| 2820 | + ) { |
|
| 2821 | + clear_path_cache(); |
|
| 2822 | + } |
|
| 2823 | + } |
|
| 2825 | 2824 | } |
| 2826 | 2825 | |
| 2827 | 2826 | /** |
@@ -2830,158 +2829,158 @@ discard block |
||
| 2830 | 2829 | * |
| 2831 | 2830 | */ |
| 2832 | 2831 | function spip_initialisation_suite() { |
| 2833 | - static $too_late = 0; |
|
| 2834 | - if ($too_late++) { |
|
| 2835 | - return; |
|
| 2836 | - } |
|
| 2837 | - |
|
| 2838 | - // taille mini des login |
|
| 2839 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2840 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2841 | - } |
|
| 2842 | - |
|
| 2843 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2844 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2845 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2846 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2847 | - |
|
| 2848 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2849 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2850 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2851 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2852 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2853 | - |
|
| 2854 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2855 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2856 | - } |
|
| 2857 | - |
|
| 2858 | - // largeur maximale des images dans l'administration |
|
| 2859 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2860 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2861 | - } |
|
| 2862 | - |
|
| 2863 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2864 | - if (!defined('_IMG_QUALITE')) { |
|
| 2865 | - define('_IMG_QUALITE', 85); |
|
| 2866 | - } # valeur par defaut |
|
| 2867 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2868 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2869 | - } # surcharge pour la lib GD |
|
| 2870 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2871 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2872 | - } # surcharge pour imagick en ligne de commande |
|
| 2873 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2874 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2875 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2876 | - } # surcharge pour imagick en PHP |
|
| 2877 | - |
|
| 2878 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2879 | - define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2880 | - } // poids en octet |
|
| 2881 | - |
|
| 2882 | - // qq chaines standard |
|
| 2883 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2884 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2885 | - } |
|
| 2886 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2887 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2888 | - } |
|
| 2889 | - if (!defined('_SPIP_DUMP')) { |
|
| 2890 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2891 | - } |
|
| 2892 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2893 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2894 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2895 | - } |
|
| 2896 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2897 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2898 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2899 | - } |
|
| 2900 | - |
|
| 2901 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2902 | - /** |
|
| 2903 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2904 | - * @var int Nombre de caractères */ |
|
| 2905 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2906 | - } |
|
| 2907 | - |
|
| 2908 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2909 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2910 | - } |
|
| 2911 | - |
|
| 2912 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2913 | - /** Définit le doctype de l’espace privé */ |
|
| 2914 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2915 | - } |
|
| 2916 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2917 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2918 | - define( |
|
| 2919 | - '_DOCTYPE_AIDE', |
|
| 2920 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2921 | - ); |
|
| 2922 | - } |
|
| 2923 | - |
|
| 2924 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2925 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2926 | - * le script de l'espace public, alias index.php */ |
|
| 2927 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2928 | - } |
|
| 2929 | - if (!defined('_SPIP_PAGE')) { |
|
| 2930 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2931 | - define('_SPIP_PAGE', 'page'); |
|
| 2932 | - } |
|
| 2933 | - |
|
| 2934 | - // le script de l'espace prive |
|
| 2935 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2936 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2937 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2938 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2939 | - if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2940 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2941 | - } else { |
|
| 2942 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2943 | - } |
|
| 2944 | - } |
|
| 2945 | - |
|
| 2946 | - |
|
| 2947 | - if (!defined('_SPIP_AJAX')) { |
|
| 2948 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2949 | - ? 1 |
|
| 2950 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2951 | - } |
|
| 2952 | - |
|
| 2953 | - // La requete est-elle en ajax ? |
|
| 2954 | - if (!defined('_AJAX')) { |
|
| 2955 | - define( |
|
| 2956 | - '_AJAX', |
|
| 2957 | - ( |
|
| 2958 | - isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2959 | - || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer |
|
| 2960 | - || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2961 | - || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2962 | - ) |
|
| 2963 | - && empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2964 | - ); |
|
| 2965 | - } |
|
| 2966 | - |
|
| 2967 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2968 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2969 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2970 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2971 | - define( |
|
| 2972 | - '_IMG_GD_MAX_PIXELS', |
|
| 2973 | - (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2974 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2975 | - : 0 |
|
| 2976 | - ); |
|
| 2977 | - } |
|
| 2978 | - |
|
| 2979 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2980 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2981 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2982 | - } |
|
| 2983 | - |
|
| 2984 | - init_var_mode(); |
|
| 2832 | + static $too_late = 0; |
|
| 2833 | + if ($too_late++) { |
|
| 2834 | + return; |
|
| 2835 | + } |
|
| 2836 | + |
|
| 2837 | + // taille mini des login |
|
| 2838 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2839 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2840 | + } |
|
| 2841 | + |
|
| 2842 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2843 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2844 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2845 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2846 | + |
|
| 2847 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2848 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2849 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2850 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2851 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2852 | + |
|
| 2853 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2854 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2855 | + } |
|
| 2856 | + |
|
| 2857 | + // largeur maximale des images dans l'administration |
|
| 2858 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2859 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2860 | + } |
|
| 2861 | + |
|
| 2862 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2863 | + if (!defined('_IMG_QUALITE')) { |
|
| 2864 | + define('_IMG_QUALITE', 85); |
|
| 2865 | + } # valeur par defaut |
|
| 2866 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2867 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2868 | + } # surcharge pour la lib GD |
|
| 2869 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2870 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2871 | + } # surcharge pour imagick en ligne de commande |
|
| 2872 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2873 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2874 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2875 | + } # surcharge pour imagick en PHP |
|
| 2876 | + |
|
| 2877 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2878 | + define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2879 | + } // poids en octet |
|
| 2880 | + |
|
| 2881 | + // qq chaines standard |
|
| 2882 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2883 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2884 | + } |
|
| 2885 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2886 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2887 | + } |
|
| 2888 | + if (!defined('_SPIP_DUMP')) { |
|
| 2889 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2890 | + } |
|
| 2891 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2892 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2893 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2894 | + } |
|
| 2895 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2896 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2897 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2898 | + } |
|
| 2899 | + |
|
| 2900 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2901 | + /** |
|
| 2902 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2903 | + * @var int Nombre de caractères */ |
|
| 2904 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2905 | + } |
|
| 2906 | + |
|
| 2907 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2908 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2909 | + } |
|
| 2910 | + |
|
| 2911 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2912 | + /** Définit le doctype de l’espace privé */ |
|
| 2913 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2914 | + } |
|
| 2915 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2916 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2917 | + define( |
|
| 2918 | + '_DOCTYPE_AIDE', |
|
| 2919 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2920 | + ); |
|
| 2921 | + } |
|
| 2922 | + |
|
| 2923 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2924 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2925 | + * le script de l'espace public, alias index.php */ |
|
| 2926 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2927 | + } |
|
| 2928 | + if (!defined('_SPIP_PAGE')) { |
|
| 2929 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2930 | + define('_SPIP_PAGE', 'page'); |
|
| 2931 | + } |
|
| 2932 | + |
|
| 2933 | + // le script de l'espace prive |
|
| 2934 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2935 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2936 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2937 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2938 | + if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2939 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2940 | + } else { |
|
| 2941 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2942 | + } |
|
| 2943 | + } |
|
| 2944 | + |
|
| 2945 | + |
|
| 2946 | + if (!defined('_SPIP_AJAX')) { |
|
| 2947 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2948 | + ? 1 |
|
| 2949 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2950 | + } |
|
| 2951 | + |
|
| 2952 | + // La requete est-elle en ajax ? |
|
| 2953 | + if (!defined('_AJAX')) { |
|
| 2954 | + define( |
|
| 2955 | + '_AJAX', |
|
| 2956 | + ( |
|
| 2957 | + isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2958 | + || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer |
|
| 2959 | + || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2960 | + || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2961 | + ) |
|
| 2962 | + && empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2963 | + ); |
|
| 2964 | + } |
|
| 2965 | + |
|
| 2966 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2967 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2968 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2969 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2970 | + define( |
|
| 2971 | + '_IMG_GD_MAX_PIXELS', |
|
| 2972 | + (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2973 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2974 | + : 0 |
|
| 2975 | + ); |
|
| 2976 | + } |
|
| 2977 | + |
|
| 2978 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2979 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2980 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2981 | + } |
|
| 2982 | + |
|
| 2983 | + init_var_mode(); |
|
| 2985 | 2984 | } |
| 2986 | 2985 | |
| 2987 | 2986 | /** |
@@ -3015,136 +3014,136 @@ discard block |
||
| 3015 | 3014 | * ` var_mode` (calcul ou recalcul). |
| 3016 | 3015 | */ |
| 3017 | 3016 | function init_var_mode() { |
| 3018 | - static $done = false; |
|
| 3019 | - if (!$done) { |
|
| 3020 | - if (isset($_GET['var_mode'])) { |
|
| 3021 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 3022 | - // tout le monde peut calcul/recalcul |
|
| 3023 | - if (!defined('_VAR_MODE')) { |
|
| 3024 | - if (in_array('recalcul', $var_mode)) { |
|
| 3025 | - define('_VAR_MODE', 'recalcul'); |
|
| 3026 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 3027 | - define('_VAR_MODE', 'calcul'); |
|
| 3028 | - } |
|
| 3029 | - } |
|
| 3030 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 3031 | - if ($var_mode) { |
|
| 3032 | - include_spip('inc/autoriser'); |
|
| 3033 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 3034 | - if ( |
|
| 3035 | - autoriser( |
|
| 3036 | - ($_GET['var_mode'] == 'preview') |
|
| 3037 | - ? 'previsualiser' |
|
| 3038 | - : 'debug' |
|
| 3039 | - ) |
|
| 3040 | - ) { |
|
| 3041 | - if (in_array('traduction', $var_mode)) { |
|
| 3042 | - // forcer le calcul pour passer dans traduire |
|
| 3043 | - if (!defined('_VAR_MODE')) { |
|
| 3044 | - define('_VAR_MODE', 'calcul'); |
|
| 3045 | - } |
|
| 3046 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 3047 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3048 | - define('_VAR_NOCACHE', true); |
|
| 3049 | - } |
|
| 3050 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 3051 | - } |
|
| 3052 | - if (in_array('preview', $var_mode)) { |
|
| 3053 | - // basculer sur les criteres de preview dans les boucles |
|
| 3054 | - if (!defined('_VAR_PREVIEW')) { |
|
| 3055 | - define('_VAR_PREVIEW', true); |
|
| 3056 | - } |
|
| 3057 | - // forcer le calcul |
|
| 3058 | - if (!defined('_VAR_MODE')) { |
|
| 3059 | - define('_VAR_MODE', 'calcul'); |
|
| 3060 | - } |
|
| 3061 | - // et ne pas enregistrer de cache |
|
| 3062 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3063 | - define('_VAR_NOCACHE', true); |
|
| 3064 | - } |
|
| 3065 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 3066 | - } |
|
| 3067 | - if (in_array('inclure', $var_mode)) { |
|
| 3068 | - // forcer le compilo et ignorer les caches existants |
|
| 3069 | - if (!defined('_VAR_MODE')) { |
|
| 3070 | - define('_VAR_MODE', 'calcul'); |
|
| 3071 | - } |
|
| 3072 | - if (!defined('_VAR_INCLURE')) { |
|
| 3073 | - define('_VAR_INCLURE', true); |
|
| 3074 | - } |
|
| 3075 | - // et ne pas enregistrer de cache |
|
| 3076 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3077 | - define('_VAR_NOCACHE', true); |
|
| 3078 | - } |
|
| 3079 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 3080 | - } |
|
| 3081 | - if (in_array('urls', $var_mode)) { |
|
| 3082 | - // forcer le compilo et ignorer les caches existants |
|
| 3083 | - if (!defined('_VAR_MODE')) { |
|
| 3084 | - define('_VAR_MODE', 'calcul'); |
|
| 3085 | - } |
|
| 3086 | - if (!defined('_VAR_URLS')) { |
|
| 3087 | - define('_VAR_URLS', true); |
|
| 3088 | - } |
|
| 3089 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 3090 | - } |
|
| 3091 | - if (in_array('images', $var_mode)) { |
|
| 3092 | - // forcer le compilo et ignorer les caches existants |
|
| 3093 | - if (!defined('_VAR_MODE')) { |
|
| 3094 | - define('_VAR_MODE', 'calcul'); |
|
| 3095 | - } |
|
| 3096 | - // indiquer qu'on doit recalculer les images |
|
| 3097 | - if (!defined('_VAR_IMAGES')) { |
|
| 3098 | - define('_VAR_IMAGES', true); |
|
| 3099 | - } |
|
| 3100 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 3101 | - } |
|
| 3102 | - if (in_array('debug', $var_mode)) { |
|
| 3103 | - if (!defined('_VAR_MODE')) { |
|
| 3104 | - define('_VAR_MODE', 'debug'); |
|
| 3105 | - } |
|
| 3106 | - // et ne pas enregistrer de cache |
|
| 3107 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3108 | - define('_VAR_NOCACHE', true); |
|
| 3109 | - } |
|
| 3110 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 3111 | - } |
|
| 3112 | - if (count($var_mode) && !defined('_VAR_MODE')) { |
|
| 3113 | - define('_VAR_MODE', reset($var_mode)); |
|
| 3114 | - } |
|
| 3115 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 3116 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 3117 | - . ' ' . _VAR_MODE); |
|
| 3118 | - } |
|
| 3119 | - } // pas autorise ? |
|
| 3120 | - else { |
|
| 3121 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3122 | - if ( |
|
| 3123 | - !$GLOBALS['visiteur_session'] |
|
| 3124 | - && !empty($_SERVER['HTTP_HOST']) |
|
| 3125 | - && !empty($_SERVER['REQUEST_METHOD']) |
|
| 3126 | - && $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3127 | - ) { |
|
| 3128 | - $self = self('&', true); |
|
| 3129 | - if (!str_contains($self, 'page=login')) { |
|
| 3130 | - include_spip('inc/headers'); |
|
| 3131 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3132 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3133 | - } |
|
| 3134 | - } |
|
| 3135 | - // sinon tant pis |
|
| 3136 | - } |
|
| 3137 | - } |
|
| 3138 | - } |
|
| 3139 | - if (!defined('_VAR_MODE')) { |
|
| 3140 | - /** |
|
| 3141 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 3142 | - * @see init_var_mode() |
|
| 3143 | - */ |
|
| 3144 | - define('_VAR_MODE', false); |
|
| 3145 | - } |
|
| 3146 | - $done = true; |
|
| 3147 | - } |
|
| 3017 | + static $done = false; |
|
| 3018 | + if (!$done) { |
|
| 3019 | + if (isset($_GET['var_mode'])) { |
|
| 3020 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 3021 | + // tout le monde peut calcul/recalcul |
|
| 3022 | + if (!defined('_VAR_MODE')) { |
|
| 3023 | + if (in_array('recalcul', $var_mode)) { |
|
| 3024 | + define('_VAR_MODE', 'recalcul'); |
|
| 3025 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 3026 | + define('_VAR_MODE', 'calcul'); |
|
| 3027 | + } |
|
| 3028 | + } |
|
| 3029 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 3030 | + if ($var_mode) { |
|
| 3031 | + include_spip('inc/autoriser'); |
|
| 3032 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 3033 | + if ( |
|
| 3034 | + autoriser( |
|
| 3035 | + ($_GET['var_mode'] == 'preview') |
|
| 3036 | + ? 'previsualiser' |
|
| 3037 | + : 'debug' |
|
| 3038 | + ) |
|
| 3039 | + ) { |
|
| 3040 | + if (in_array('traduction', $var_mode)) { |
|
| 3041 | + // forcer le calcul pour passer dans traduire |
|
| 3042 | + if (!defined('_VAR_MODE')) { |
|
| 3043 | + define('_VAR_MODE', 'calcul'); |
|
| 3044 | + } |
|
| 3045 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 3046 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3047 | + define('_VAR_NOCACHE', true); |
|
| 3048 | + } |
|
| 3049 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 3050 | + } |
|
| 3051 | + if (in_array('preview', $var_mode)) { |
|
| 3052 | + // basculer sur les criteres de preview dans les boucles |
|
| 3053 | + if (!defined('_VAR_PREVIEW')) { |
|
| 3054 | + define('_VAR_PREVIEW', true); |
|
| 3055 | + } |
|
| 3056 | + // forcer le calcul |
|
| 3057 | + if (!defined('_VAR_MODE')) { |
|
| 3058 | + define('_VAR_MODE', 'calcul'); |
|
| 3059 | + } |
|
| 3060 | + // et ne pas enregistrer de cache |
|
| 3061 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3062 | + define('_VAR_NOCACHE', true); |
|
| 3063 | + } |
|
| 3064 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 3065 | + } |
|
| 3066 | + if (in_array('inclure', $var_mode)) { |
|
| 3067 | + // forcer le compilo et ignorer les caches existants |
|
| 3068 | + if (!defined('_VAR_MODE')) { |
|
| 3069 | + define('_VAR_MODE', 'calcul'); |
|
| 3070 | + } |
|
| 3071 | + if (!defined('_VAR_INCLURE')) { |
|
| 3072 | + define('_VAR_INCLURE', true); |
|
| 3073 | + } |
|
| 3074 | + // et ne pas enregistrer de cache |
|
| 3075 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3076 | + define('_VAR_NOCACHE', true); |
|
| 3077 | + } |
|
| 3078 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 3079 | + } |
|
| 3080 | + if (in_array('urls', $var_mode)) { |
|
| 3081 | + // forcer le compilo et ignorer les caches existants |
|
| 3082 | + if (!defined('_VAR_MODE')) { |
|
| 3083 | + define('_VAR_MODE', 'calcul'); |
|
| 3084 | + } |
|
| 3085 | + if (!defined('_VAR_URLS')) { |
|
| 3086 | + define('_VAR_URLS', true); |
|
| 3087 | + } |
|
| 3088 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 3089 | + } |
|
| 3090 | + if (in_array('images', $var_mode)) { |
|
| 3091 | + // forcer le compilo et ignorer les caches existants |
|
| 3092 | + if (!defined('_VAR_MODE')) { |
|
| 3093 | + define('_VAR_MODE', 'calcul'); |
|
| 3094 | + } |
|
| 3095 | + // indiquer qu'on doit recalculer les images |
|
| 3096 | + if (!defined('_VAR_IMAGES')) { |
|
| 3097 | + define('_VAR_IMAGES', true); |
|
| 3098 | + } |
|
| 3099 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 3100 | + } |
|
| 3101 | + if (in_array('debug', $var_mode)) { |
|
| 3102 | + if (!defined('_VAR_MODE')) { |
|
| 3103 | + define('_VAR_MODE', 'debug'); |
|
| 3104 | + } |
|
| 3105 | + // et ne pas enregistrer de cache |
|
| 3106 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3107 | + define('_VAR_NOCACHE', true); |
|
| 3108 | + } |
|
| 3109 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 3110 | + } |
|
| 3111 | + if (count($var_mode) && !defined('_VAR_MODE')) { |
|
| 3112 | + define('_VAR_MODE', reset($var_mode)); |
|
| 3113 | + } |
|
| 3114 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 3115 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 3116 | + . ' ' . _VAR_MODE); |
|
| 3117 | + } |
|
| 3118 | + } // pas autorise ? |
|
| 3119 | + else { |
|
| 3120 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3121 | + if ( |
|
| 3122 | + !$GLOBALS['visiteur_session'] |
|
| 3123 | + && !empty($_SERVER['HTTP_HOST']) |
|
| 3124 | + && !empty($_SERVER['REQUEST_METHOD']) |
|
| 3125 | + && $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3126 | + ) { |
|
| 3127 | + $self = self('&', true); |
|
| 3128 | + if (!str_contains($self, 'page=login')) { |
|
| 3129 | + include_spip('inc/headers'); |
|
| 3130 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3131 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3132 | + } |
|
| 3133 | + } |
|
| 3134 | + // sinon tant pis |
|
| 3135 | + } |
|
| 3136 | + } |
|
| 3137 | + } |
|
| 3138 | + if (!defined('_VAR_MODE')) { |
|
| 3139 | + /** |
|
| 3140 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 3141 | + * @see init_var_mode() |
|
| 3142 | + */ |
|
| 3143 | + define('_VAR_MODE', false); |
|
| 3144 | + } |
|
| 3145 | + $done = true; |
|
| 3146 | + } |
|
| 3148 | 3147 | } |
| 3149 | 3148 | |
| 3150 | 3149 | /** |
@@ -3156,16 +3155,16 @@ discard block |
||
| 3156 | 3155 | * @param bool $deep = true : appliquer récursivement |
| 3157 | 3156 | **/ |
| 3158 | 3157 | function spip_desinfecte(&$t, $deep = true) { |
| 3159 | - foreach ($t as $key => $val) { |
|
| 3160 | - if (is_string($t[$key])) { |
|
| 3161 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3162 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 3163 | - else { |
|
| 3164 | - if ($deep && is_array($t[$key]) && $key !== 'GLOBALS') { |
|
| 3165 | - spip_desinfecte($t[$key], $deep); |
|
| 3166 | - } |
|
| 3167 | - } |
|
| 3168 | - } |
|
| 3158 | + foreach ($t as $key => $val) { |
|
| 3159 | + if (is_string($t[$key])) { |
|
| 3160 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3161 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 3162 | + else { |
|
| 3163 | + if ($deep && is_array($t[$key]) && $key !== 'GLOBALS') { |
|
| 3164 | + spip_desinfecte($t[$key], $deep); |
|
| 3165 | + } |
|
| 3166 | + } |
|
| 3167 | + } |
|
| 3169 | 3168 | } |
| 3170 | 3169 | |
| 3171 | 3170 | /** |
@@ -3178,64 +3177,64 @@ discard block |
||
| 3178 | 3177 | * @return string|0|false |
| 3179 | 3178 | **/ |
| 3180 | 3179 | function verifier_visiteur() { |
| 3181 | - @spip_initialisation_core( |
|
| 3182 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3183 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3184 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3185 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3186 | - ); |
|
| 3187 | - |
|
| 3188 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3189 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3190 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 3191 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3192 | - $variables_session = ['session_nom', 'session_email']; |
|
| 3193 | - foreach ($variables_session as $var) { |
|
| 3194 | - if (_request($var) !== null) { |
|
| 3195 | - $init = true; |
|
| 3196 | - break; |
|
| 3197 | - } |
|
| 3198 | - } |
|
| 3199 | - if (isset($init)) { |
|
| 3200 | - #@spip_initialisation_suite(); |
|
| 3201 | - $session = charger_fonction('session', 'inc'); |
|
| 3202 | - $session(); |
|
| 3203 | - include_spip('inc/texte'); |
|
| 3204 | - foreach ($variables_session as $var) { |
|
| 3205 | - if (($a = _request($var)) !== null) { |
|
| 3206 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3207 | - } |
|
| 3208 | - } |
|
| 3209 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3210 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3211 | - } |
|
| 3212 | - $session($GLOBALS['visiteur_session']); |
|
| 3213 | - |
|
| 3214 | - return 0; |
|
| 3215 | - } |
|
| 3216 | - |
|
| 3217 | - $h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']); |
|
| 3218 | - if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3219 | - $session = charger_fonction('session', 'inc'); |
|
| 3220 | - if ($session()) { |
|
| 3221 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3222 | - } |
|
| 3223 | - if ($h && isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3224 | - include_spip('inc/auth'); |
|
| 3225 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3226 | - } |
|
| 3227 | - if ($h) { |
|
| 3228 | - $GLOBALS['visiteur_session'] = $h; |
|
| 3229 | - |
|
| 3230 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3231 | - } |
|
| 3232 | - } |
|
| 3233 | - |
|
| 3234 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3235 | - include_spip('inc/lang'); |
|
| 3236 | - utiliser_langue_visiteur(); |
|
| 3237 | - |
|
| 3238 | - return false; |
|
| 3180 | + @spip_initialisation_core( |
|
| 3181 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3182 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3183 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3184 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3185 | + ); |
|
| 3186 | + |
|
| 3187 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3188 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3189 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 3190 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3191 | + $variables_session = ['session_nom', 'session_email']; |
|
| 3192 | + foreach ($variables_session as $var) { |
|
| 3193 | + if (_request($var) !== null) { |
|
| 3194 | + $init = true; |
|
| 3195 | + break; |
|
| 3196 | + } |
|
| 3197 | + } |
|
| 3198 | + if (isset($init)) { |
|
| 3199 | + #@spip_initialisation_suite(); |
|
| 3200 | + $session = charger_fonction('session', 'inc'); |
|
| 3201 | + $session(); |
|
| 3202 | + include_spip('inc/texte'); |
|
| 3203 | + foreach ($variables_session as $var) { |
|
| 3204 | + if (($a = _request($var)) !== null) { |
|
| 3205 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3206 | + } |
|
| 3207 | + } |
|
| 3208 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3209 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3210 | + } |
|
| 3211 | + $session($GLOBALS['visiteur_session']); |
|
| 3212 | + |
|
| 3213 | + return 0; |
|
| 3214 | + } |
|
| 3215 | + |
|
| 3216 | + $h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']); |
|
| 3217 | + if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3218 | + $session = charger_fonction('session', 'inc'); |
|
| 3219 | + if ($session()) { |
|
| 3220 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3221 | + } |
|
| 3222 | + if ($h && isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3223 | + include_spip('inc/auth'); |
|
| 3224 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3225 | + } |
|
| 3226 | + if ($h) { |
|
| 3227 | + $GLOBALS['visiteur_session'] = $h; |
|
| 3228 | + |
|
| 3229 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3230 | + } |
|
| 3231 | + } |
|
| 3232 | + |
|
| 3233 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3234 | + include_spip('inc/lang'); |
|
| 3235 | + utiliser_langue_visiteur(); |
|
| 3236 | + |
|
| 3237 | + return false; |
|
| 3239 | 3238 | } |
| 3240 | 3239 | |
| 3241 | 3240 | |
@@ -3258,21 +3257,21 @@ discard block |
||
| 3258 | 3257 | * - string Langue utilisée. |
| 3259 | 3258 | **/ |
| 3260 | 3259 | function lang_select($lang = null) { |
| 3261 | - static $pile_langues = []; |
|
| 3262 | - if (!function_exists('changer_langue')) { |
|
| 3263 | - include_spip('inc/lang'); |
|
| 3264 | - } |
|
| 3265 | - if ($lang === null) { |
|
| 3266 | - $lang = array_pop($pile_langues); |
|
| 3267 | - } else { |
|
| 3268 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3269 | - } |
|
| 3270 | - if (isset($GLOBALS['spip_lang']) && $lang == $GLOBALS['spip_lang']) { |
|
| 3271 | - return $lang; |
|
| 3272 | - } |
|
| 3273 | - changer_langue($lang); |
|
| 3260 | + static $pile_langues = []; |
|
| 3261 | + if (!function_exists('changer_langue')) { |
|
| 3262 | + include_spip('inc/lang'); |
|
| 3263 | + } |
|
| 3264 | + if ($lang === null) { |
|
| 3265 | + $lang = array_pop($pile_langues); |
|
| 3266 | + } else { |
|
| 3267 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3268 | + } |
|
| 3269 | + if (isset($GLOBALS['spip_lang']) && $lang == $GLOBALS['spip_lang']) { |
|
| 3270 | + return $lang; |
|
| 3271 | + } |
|
| 3272 | + changer_langue($lang); |
|
| 3274 | 3273 | |
| 3275 | - return $lang; |
|
| 3274 | + return $lang; |
|
| 3276 | 3275 | } |
| 3277 | 3276 | |
| 3278 | 3277 | /** |
@@ -3289,20 +3288,20 @@ discard block |
||
| 3289 | 3288 | * Identifiant de la session |
| 3290 | 3289 | **/ |
| 3291 | 3290 | function spip_session($force = false) { |
| 3292 | - static $session; |
|
| 3293 | - if ($force || !isset($session)) { |
|
| 3294 | - $s = ''; |
|
| 3295 | - if (!empty($GLOBALS['visiteur_session'])) { |
|
| 3296 | - include_spip('inc/session'); |
|
| 3297 | - $cookie = lire_cookie_session(); |
|
| 3298 | - $s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: ''); |
|
| 3299 | - } |
|
| 3300 | - $s = pipeline('definir_session', $s); |
|
| 3301 | - $session = ($s ? substr(md5($s), 0, 8) : ''); |
|
| 3302 | - } |
|
| 3291 | + static $session; |
|
| 3292 | + if ($force || !isset($session)) { |
|
| 3293 | + $s = ''; |
|
| 3294 | + if (!empty($GLOBALS['visiteur_session'])) { |
|
| 3295 | + include_spip('inc/session'); |
|
| 3296 | + $cookie = lire_cookie_session(); |
|
| 3297 | + $s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: ''); |
|
| 3298 | + } |
|
| 3299 | + $s = pipeline('definir_session', $s); |
|
| 3300 | + $session = ($s ? substr(md5($s), 0, 8) : ''); |
|
| 3301 | + } |
|
| 3303 | 3302 | |
| 3304 | - #spip_log('session: '.$session); |
|
| 3305 | - return $session; |
|
| 3303 | + #spip_log('session: '.$session); |
|
| 3304 | + return $session; |
|
| 3306 | 3305 | } |
| 3307 | 3306 | |
| 3308 | 3307 | |
@@ -3321,9 +3320,9 @@ discard block |
||
| 3321 | 3320 | * Lien sur une icone d'aide |
| 3322 | 3321 | **/ |
| 3323 | 3322 | function aider($aide = '', $distante = false) { |
| 3324 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3323 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3325 | 3324 | |
| 3326 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3325 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3327 | 3326 | } |
| 3328 | 3327 | |
| 3329 | 3328 | /** |
@@ -3333,35 +3332,35 @@ discard block |
||
| 3333 | 3332 | */ |
| 3334 | 3333 | function exec_info_dist() { |
| 3335 | 3334 | |
| 3336 | - include_spip('inc/autoriser'); |
|
| 3337 | - if (autoriser('phpinfos')) { |
|
| 3338 | - $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3339 | - $cookies_backup = []; |
|
| 3340 | - $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []]; |
|
| 3341 | - $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []]; |
|
| 3342 | - $mask = '******************************'; |
|
| 3343 | - foreach ($cookies_masques as $k) { |
|
| 3344 | - if (!empty($_COOKIE[$k])) { |
|
| 3345 | - $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3346 | - $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []); |
|
| 3347 | - $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []); |
|
| 3348 | - $_COOKIE[$k] = $mask; |
|
| 3349 | - } |
|
| 3350 | - } |
|
| 3351 | - phpinfo(); |
|
| 3352 | - foreach ($cookies_backup as $k => $v) { |
|
| 3353 | - $_COOKIE[$k] = $v; |
|
| 3354 | - } |
|
| 3355 | - foreach ($server_backup as $k => $v) { |
|
| 3356 | - $_SERVER[$k] = $v; |
|
| 3357 | - } |
|
| 3358 | - foreach ($env_backup as $k => $v) { |
|
| 3359 | - $_ENV[$k] = $v; |
|
| 3360 | - } |
|
| 3361 | - } else { |
|
| 3362 | - include_spip('inc/filtres'); |
|
| 3363 | - sinon_interdire_acces(); |
|
| 3364 | - } |
|
| 3335 | + include_spip('inc/autoriser'); |
|
| 3336 | + if (autoriser('phpinfos')) { |
|
| 3337 | + $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3338 | + $cookies_backup = []; |
|
| 3339 | + $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []]; |
|
| 3340 | + $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []]; |
|
| 3341 | + $mask = '******************************'; |
|
| 3342 | + foreach ($cookies_masques as $k) { |
|
| 3343 | + if (!empty($_COOKIE[$k])) { |
|
| 3344 | + $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3345 | + $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []); |
|
| 3346 | + $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []); |
|
| 3347 | + $_COOKIE[$k] = $mask; |
|
| 3348 | + } |
|
| 3349 | + } |
|
| 3350 | + phpinfo(); |
|
| 3351 | + foreach ($cookies_backup as $k => $v) { |
|
| 3352 | + $_COOKIE[$k] = $v; |
|
| 3353 | + } |
|
| 3354 | + foreach ($server_backup as $k => $v) { |
|
| 3355 | + $_SERVER[$k] = $v; |
|
| 3356 | + } |
|
| 3357 | + foreach ($env_backup as $k => $v) { |
|
| 3358 | + $_ENV[$k] = $v; |
|
| 3359 | + } |
|
| 3360 | + } else { |
|
| 3361 | + include_spip('inc/filtres'); |
|
| 3362 | + sinon_interdire_acces(); |
|
| 3363 | + } |
|
| 3365 | 3364 | } |
| 3366 | 3365 | |
| 3367 | 3366 | /** |
@@ -3381,13 +3380,13 @@ discard block |
||
| 3381 | 3380 | * - string si $message à false. |
| 3382 | 3381 | **/ |
| 3383 | 3382 | function erreur_squelette($message = '', $lieu = '') { |
| 3384 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3385 | - if (is_array($lieu)) { |
|
| 3386 | - include_spip('public/compiler'); |
|
| 3387 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3388 | - } |
|
| 3383 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3384 | + if (is_array($lieu)) { |
|
| 3385 | + include_spip('public/compiler'); |
|
| 3386 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3387 | + } |
|
| 3389 | 3388 | |
| 3390 | - return $debusquer($message, $lieu); |
|
| 3389 | + return $debusquer($message, $lieu); |
|
| 3391 | 3390 | } |
| 3392 | 3391 | |
| 3393 | 3392 | /** |
@@ -3424,108 +3423,108 @@ discard block |
||
| 3424 | 3423 | * - ou tableau d'information sur le squelette. |
| 3425 | 3424 | */ |
| 3426 | 3425 | function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') { |
| 3427 | - if (!function_exists('evaluer_fond')) { |
|
| 3428 | - include_spip('public/assembler'); |
|
| 3429 | - } |
|
| 3430 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3431 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3432 | - if (!is_array($options)) { |
|
| 3433 | - $options = ['trim' => $options]; |
|
| 3434 | - } |
|
| 3435 | - if (!isset($options['trim'])) { |
|
| 3436 | - $options['trim'] = true; |
|
| 3437 | - } |
|
| 3438 | - |
|
| 3439 | - if (isset($contexte['connect'])) { |
|
| 3440 | - $connect = $contexte['connect']; |
|
| 3441 | - unset($contexte['connect']); |
|
| 3442 | - } |
|
| 3443 | - |
|
| 3444 | - $texte = ''; |
|
| 3445 | - $pages = []; |
|
| 3446 | - $lang_select = ''; |
|
| 3447 | - if (!isset($options['etoile']) || !$options['etoile']) { |
|
| 3448 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3449 | - if (!isset($contexte['lang'])) { |
|
| 3450 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3451 | - } |
|
| 3452 | - |
|
| 3453 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3454 | - $lang_select = lang_select($contexte['lang']); |
|
| 3455 | - } |
|
| 3456 | - } |
|
| 3457 | - |
|
| 3458 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3459 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3460 | - } |
|
| 3461 | - |
|
| 3462 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3463 | - |
|
| 3464 | - // fix #4235 |
|
| 3465 | - $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3466 | - |
|
| 3467 | - |
|
| 3468 | - foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3469 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3470 | - |
|
| 3471 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3472 | - if ($page === '') { |
|
| 3473 | - $c = $options['compil'] ?? ''; |
|
| 3474 | - $a = ['fichier' => $f]; |
|
| 3475 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3476 | - erreur_squelette($erreur, $c); |
|
| 3477 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3478 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3479 | - } |
|
| 3480 | - |
|
| 3481 | - $page = pipeline('recuperer_fond', [ |
|
| 3482 | - 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3483 | - 'data' => $page |
|
| 3484 | - ]); |
|
| 3485 | - if (isset($options['ajax']) && $options['ajax']) { |
|
| 3486 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3487 | - include_spip('inc/filtres'); |
|
| 3488 | - } |
|
| 3489 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3490 | - array_merge( |
|
| 3491 | - $contexte, |
|
| 3492 | - ['fond' => $f], |
|
| 3493 | - ($connect ? ['connect' => $connect] : []) |
|
| 3494 | - ), |
|
| 3495 | - '', |
|
| 3496 | - $page['texte'], |
|
| 3497 | - $options['ajax'] |
|
| 3498 | - ); |
|
| 3499 | - } |
|
| 3500 | - |
|
| 3501 | - if (isset($options['raw']) && $options['raw']) { |
|
| 3502 | - $pages[] = $page; |
|
| 3503 | - } else { |
|
| 3504 | - $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte']; |
|
| 3505 | - } |
|
| 3506 | - |
|
| 3507 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3508 | - if (isset($page['invalideurs']['session'])) { |
|
| 3509 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3510 | - } |
|
| 3511 | - } |
|
| 3512 | - |
|
| 3513 | - // restaurer le sessionnement du contexte appelant, |
|
| 3514 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3515 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3516 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3517 | - } |
|
| 3518 | - |
|
| 3519 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3520 | - |
|
| 3521 | - if ($lang_select) { |
|
| 3522 | - lang_select(); |
|
| 3523 | - } |
|
| 3524 | - if (isset($options['raw']) && $options['raw']) { |
|
| 3525 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3526 | - } else { |
|
| 3527 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3528 | - } |
|
| 3426 | + if (!function_exists('evaluer_fond')) { |
|
| 3427 | + include_spip('public/assembler'); |
|
| 3428 | + } |
|
| 3429 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3430 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3431 | + if (!is_array($options)) { |
|
| 3432 | + $options = ['trim' => $options]; |
|
| 3433 | + } |
|
| 3434 | + if (!isset($options['trim'])) { |
|
| 3435 | + $options['trim'] = true; |
|
| 3436 | + } |
|
| 3437 | + |
|
| 3438 | + if (isset($contexte['connect'])) { |
|
| 3439 | + $connect = $contexte['connect']; |
|
| 3440 | + unset($contexte['connect']); |
|
| 3441 | + } |
|
| 3442 | + |
|
| 3443 | + $texte = ''; |
|
| 3444 | + $pages = []; |
|
| 3445 | + $lang_select = ''; |
|
| 3446 | + if (!isset($options['etoile']) || !$options['etoile']) { |
|
| 3447 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3448 | + if (!isset($contexte['lang'])) { |
|
| 3449 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3450 | + } |
|
| 3451 | + |
|
| 3452 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3453 | + $lang_select = lang_select($contexte['lang']); |
|
| 3454 | + } |
|
| 3455 | + } |
|
| 3456 | + |
|
| 3457 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3458 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3459 | + } |
|
| 3460 | + |
|
| 3461 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3462 | + |
|
| 3463 | + // fix #4235 |
|
| 3464 | + $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3465 | + |
|
| 3466 | + |
|
| 3467 | + foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3468 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3469 | + |
|
| 3470 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3471 | + if ($page === '') { |
|
| 3472 | + $c = $options['compil'] ?? ''; |
|
| 3473 | + $a = ['fichier' => $f]; |
|
| 3474 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3475 | + erreur_squelette($erreur, $c); |
|
| 3476 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3477 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3478 | + } |
|
| 3479 | + |
|
| 3480 | + $page = pipeline('recuperer_fond', [ |
|
| 3481 | + 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3482 | + 'data' => $page |
|
| 3483 | + ]); |
|
| 3484 | + if (isset($options['ajax']) && $options['ajax']) { |
|
| 3485 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3486 | + include_spip('inc/filtres'); |
|
| 3487 | + } |
|
| 3488 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3489 | + array_merge( |
|
| 3490 | + $contexte, |
|
| 3491 | + ['fond' => $f], |
|
| 3492 | + ($connect ? ['connect' => $connect] : []) |
|
| 3493 | + ), |
|
| 3494 | + '', |
|
| 3495 | + $page['texte'], |
|
| 3496 | + $options['ajax'] |
|
| 3497 | + ); |
|
| 3498 | + } |
|
| 3499 | + |
|
| 3500 | + if (isset($options['raw']) && $options['raw']) { |
|
| 3501 | + $pages[] = $page; |
|
| 3502 | + } else { |
|
| 3503 | + $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte']; |
|
| 3504 | + } |
|
| 3505 | + |
|
| 3506 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3507 | + if (isset($page['invalideurs']['session'])) { |
|
| 3508 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3509 | + } |
|
| 3510 | + } |
|
| 3511 | + |
|
| 3512 | + // restaurer le sessionnement du contexte appelant, |
|
| 3513 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3514 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3515 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3516 | + } |
|
| 3517 | + |
|
| 3518 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3519 | + |
|
| 3520 | + if ($lang_select) { |
|
| 3521 | + lang_select(); |
|
| 3522 | + } |
|
| 3523 | + if (isset($options['raw']) && $options['raw']) { |
|
| 3524 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3525 | + } else { |
|
| 3526 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3527 | + } |
|
| 3529 | 3528 | } |
| 3530 | 3529 | |
| 3531 | 3530 | /** |
@@ -3535,7 +3534,7 @@ discard block |
||
| 3535 | 3534 | * @return string |
| 3536 | 3535 | */ |
| 3537 | 3536 | function trouve_modele($nom) { |
| 3538 | - return trouver_fond($nom, 'modeles/'); |
|
| 3537 | + return trouver_fond($nom, 'modeles/'); |
|
| 3539 | 3538 | } |
| 3540 | 3539 | |
| 3541 | 3540 | /** |
@@ -3551,21 +3550,21 @@ discard block |
||
| 3551 | 3550 | * @return array|string |
| 3552 | 3551 | */ |
| 3553 | 3552 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3554 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3555 | - if (!$pathinfo) { |
|
| 3556 | - return $f; |
|
| 3557 | - } |
|
| 3558 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3559 | - $p = pathinfo($f); |
|
| 3560 | - if (!isset($p['extension']) || !$p['extension']) { |
|
| 3561 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3562 | - } |
|
| 3563 | - if (!isset($p['extension']) || !$p['filename']) { |
|
| 3564 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3565 | - } |
|
| 3566 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3553 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3554 | + if (!$pathinfo) { |
|
| 3555 | + return $f; |
|
| 3556 | + } |
|
| 3557 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3558 | + $p = pathinfo($f); |
|
| 3559 | + if (!isset($p['extension']) || !$p['extension']) { |
|
| 3560 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3561 | + } |
|
| 3562 | + if (!isset($p['extension']) || !$p['filename']) { |
|
| 3563 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3564 | + } |
|
| 3565 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3567 | 3566 | |
| 3568 | - return $p; |
|
| 3567 | + return $p; |
|
| 3569 | 3568 | } |
| 3570 | 3569 | |
| 3571 | 3570 | /** |
@@ -3585,21 +3584,21 @@ discard block |
||
| 3585 | 3584 | * Nom de l'exec, sinon chaîne vide. |
| 3586 | 3585 | **/ |
| 3587 | 3586 | function tester_url_ecrire($nom) { |
| 3588 | - static $exec = []; |
|
| 3589 | - if (isset($exec[$nom])) { |
|
| 3590 | - return $exec[$nom]; |
|
| 3591 | - } |
|
| 3592 | - // tester si c'est une page en squelette |
|
| 3593 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3594 | - return $exec[$nom] = 'fond'; |
|
| 3595 | - } // echafaudage d'un fond ! |
|
| 3596 | - elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) { |
|
| 3597 | - return $exec[$nom] = 'fond'; |
|
| 3598 | - } |
|
| 3599 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3600 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3601 | - // et des define intrusifs potentiels |
|
| 3602 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3587 | + static $exec = []; |
|
| 3588 | + if (isset($exec[$nom])) { |
|
| 3589 | + return $exec[$nom]; |
|
| 3590 | + } |
|
| 3591 | + // tester si c'est une page en squelette |
|
| 3592 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3593 | + return $exec[$nom] = 'fond'; |
|
| 3594 | + } // echafaudage d'un fond ! |
|
| 3595 | + elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) { |
|
| 3596 | + return $exec[$nom] = 'fond'; |
|
| 3597 | + } |
|
| 3598 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3599 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3600 | + // et des define intrusifs potentiels |
|
| 3601 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3603 | 3602 | } |
| 3604 | 3603 | |
| 3605 | 3604 | /** |
@@ -3609,36 +3608,36 @@ discard block |
||
| 3609 | 3608 | * true si la constante _VERSION_HTML n'est pas définie ou égale à html5 |
| 3610 | 3609 | **/ |
| 3611 | 3610 | function html5_permis() { |
| 3612 | - return (!defined('_VERSION_HTML') || _VERSION_HTML !== 'html4'); |
|
| 3611 | + return (!defined('_VERSION_HTML') || _VERSION_HTML !== 'html4'); |
|
| 3613 | 3612 | } |
| 3614 | 3613 | |
| 3615 | 3614 | /** |
| 3616 | 3615 | * Lister les formats image acceptes par les lib et fonctions images |
| 3617 | 3616 | */ |
| 3618 | 3617 | function formats_image_acceptables(?bool $gd = null, bool $svg_allowed = true): array { |
| 3619 | - $formats = null; |
|
| 3620 | - if (!is_null($gd)) { |
|
| 3621 | - $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3622 | - if (isset($GLOBALS['meta'][$config])) { |
|
| 3623 | - $formats = $GLOBALS['meta'][$config]; |
|
| 3624 | - $formats = explode(',', $formats); |
|
| 3625 | - $formats = array_filter($formats); |
|
| 3626 | - $formats = array_map('trim', $formats); |
|
| 3627 | - } |
|
| 3628 | - } |
|
| 3629 | - if (is_null($formats)) { |
|
| 3630 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 3631 | - $formats = _image_extensions_acceptees_en_entree(); |
|
| 3632 | - } |
|
| 3633 | - |
|
| 3634 | - if ($svg_allowed) { |
|
| 3635 | - if (!in_array('svg', $formats)) { |
|
| 3636 | - $formats[] = 'svg'; |
|
| 3637 | - } |
|
| 3638 | - } else { |
|
| 3639 | - $formats = array_diff($formats, ['svg']); |
|
| 3640 | - } |
|
| 3641 | - return $formats; |
|
| 3618 | + $formats = null; |
|
| 3619 | + if (!is_null($gd)) { |
|
| 3620 | + $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3621 | + if (isset($GLOBALS['meta'][$config])) { |
|
| 3622 | + $formats = $GLOBALS['meta'][$config]; |
|
| 3623 | + $formats = explode(',', $formats); |
|
| 3624 | + $formats = array_filter($formats); |
|
| 3625 | + $formats = array_map('trim', $formats); |
|
| 3626 | + } |
|
| 3627 | + } |
|
| 3628 | + if (is_null($formats)) { |
|
| 3629 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 3630 | + $formats = _image_extensions_acceptees_en_entree(); |
|
| 3631 | + } |
|
| 3632 | + |
|
| 3633 | + if ($svg_allowed) { |
|
| 3634 | + if (!in_array('svg', $formats)) { |
|
| 3635 | + $formats[] = 'svg'; |
|
| 3636 | + } |
|
| 3637 | + } else { |
|
| 3638 | + $formats = array_diff($formats, ['svg']); |
|
| 3639 | + } |
|
| 3640 | + return $formats; |
|
| 3642 | 3641 | } |
| 3643 | 3642 | |
| 3644 | 3643 | /** |
@@ -3647,20 +3646,20 @@ discard block |
||
| 3647 | 3646 | * @return array|bool |
| 3648 | 3647 | */ |
| 3649 | 3648 | function spip_getimagesize($fichier) { |
| 3650 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3651 | - include_spip('inc/svg'); |
|
| 3652 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3653 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3654 | - $imagesize = [ |
|
| 3655 | - $width, |
|
| 3656 | - $height, |
|
| 3657 | - IMAGETYPE_SVG, |
|
| 3658 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3659 | - 'mime' => 'image/svg+xml' |
|
| 3660 | - ]; |
|
| 3661 | - } |
|
| 3662 | - } |
|
| 3663 | - return $imagesize; |
|
| 3649 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3650 | + include_spip('inc/svg'); |
|
| 3651 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3652 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3653 | + $imagesize = [ |
|
| 3654 | + $width, |
|
| 3655 | + $height, |
|
| 3656 | + IMAGETYPE_SVG, |
|
| 3657 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3658 | + 'mime' => 'image/svg+xml' |
|
| 3659 | + ]; |
|
| 3660 | + } |
|
| 3661 | + } |
|
| 3662 | + return $imagesize; |
|
| 3664 | 3663 | } |
| 3665 | 3664 | |
| 3666 | 3665 | /** |
@@ -3674,18 +3673,18 @@ discard block |
||
| 3674 | 3673 | * @param string $statut |
| 3675 | 3674 | */ |
| 3676 | 3675 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3677 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3678 | - if ( |
|
| 3679 | - !$alertes || !is_array($alertes = unserialize($alertes)) |
|
| 3680 | - ) { |
|
| 3681 | - $alertes = []; |
|
| 3682 | - } |
|
| 3676 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3677 | + if ( |
|
| 3678 | + !$alertes || !is_array($alertes = unserialize($alertes)) |
|
| 3679 | + ) { |
|
| 3680 | + $alertes = []; |
|
| 3681 | + } |
|
| 3683 | 3682 | |
| 3684 | - if (!isset($alertes[$statut])) { |
|
| 3685 | - $alertes[$statut] = []; |
|
| 3686 | - } |
|
| 3687 | - $alertes[$statut][$nom] = $message; |
|
| 3688 | - ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3683 | + if (!isset($alertes[$statut])) { |
|
| 3684 | + $alertes[$statut] = []; |
|
| 3685 | + } |
|
| 3686 | + $alertes[$statut][$nom] = $message; |
|
| 3687 | + ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3689 | 3688 | } |
| 3690 | 3689 | |
| 3691 | 3690 | /** |
@@ -3699,10 +3698,10 @@ discard block |
||
| 3699 | 3698 | * @return string|string[] |
| 3700 | 3699 | */ |
| 3701 | 3700 | function spip_sanitize_classname($classes) { |
| 3702 | - if (is_array($classes)) { |
|
| 3703 | - return array_map('spip_sanitize_classname', $classes); |
|
| 3704 | - } |
|
| 3705 | - return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3701 | + if (is_array($classes)) { |
|
| 3702 | + return array_map('spip_sanitize_classname', $classes); |
|
| 3703 | + } |
|
| 3704 | + return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3706 | 3705 | } |
| 3707 | 3706 | |
| 3708 | 3707 | |
@@ -3727,32 +3726,32 @@ discard block |
||
| 3727 | 3726 | * Avec operateur : bool. |
| 3728 | 3727 | **/ |
| 3729 | 3728 | function spip_version_compare($v1, $v2, $op = null) { |
| 3730 | - $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3731 | - $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3732 | - $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3733 | - $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3734 | - |
|
| 3735 | - $v1 = explode('.', $v1); |
|
| 3736 | - $v2 = explode('.', $v2); |
|
| 3737 | - // $v1 est toujours une version, donc sans etoile |
|
| 3738 | - while (count($v1) < count($v2)) { |
|
| 3739 | - $v1[] = '0'; |
|
| 3740 | - } |
|
| 3741 | - |
|
| 3742 | - // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3743 | - $etoile = false; |
|
| 3744 | - foreach ($v1 as $k => $v) { |
|
| 3745 | - if (!isset($v2[$k])) { |
|
| 3746 | - $v2[] = ($etoile && (is_numeric($v) || $v == 'pl' || $v == 'p')) ? $v : '0'; |
|
| 3747 | - } else { |
|
| 3748 | - if ($v2[$k] == '*') { |
|
| 3749 | - $etoile = true; |
|
| 3750 | - $v2[$k] = $v; |
|
| 3751 | - } |
|
| 3752 | - } |
|
| 3753 | - } |
|
| 3754 | - $v1 = implode('.', $v1); |
|
| 3755 | - $v2 = implode('.', $v2); |
|
| 3756 | - |
|
| 3757 | - return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3729 | + $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3730 | + $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3731 | + $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3732 | + $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3733 | + |
|
| 3734 | + $v1 = explode('.', $v1); |
|
| 3735 | + $v2 = explode('.', $v2); |
|
| 3736 | + // $v1 est toujours une version, donc sans etoile |
|
| 3737 | + while (count($v1) < count($v2)) { |
|
| 3738 | + $v1[] = '0'; |
|
| 3739 | + } |
|
| 3740 | + |
|
| 3741 | + // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3742 | + $etoile = false; |
|
| 3743 | + foreach ($v1 as $k => $v) { |
|
| 3744 | + if (!isset($v2[$k])) { |
|
| 3745 | + $v2[] = ($etoile && (is_numeric($v) || $v == 'pl' || $v == 'p')) ? $v : '0'; |
|
| 3746 | + } else { |
|
| 3747 | + if ($v2[$k] == '*') { |
|
| 3748 | + $etoile = true; |
|
| 3749 | + $v2[$k] = $v; |
|
| 3750 | + } |
|
| 3751 | + } |
|
| 3752 | + } |
|
| 3753 | + $v1 = implode('.', $v1); |
|
| 3754 | + $v2 = implode('.', $v2); |
|
| 3755 | + |
|
| 3756 | + return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3758 | 3757 | } |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
| 53 | 53 | $dossier .= '/'; |
| 54 | 54 | } |
| 55 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 55 | + $f = str_replace('/', '_', $dossier).$nom; |
|
| 56 | 56 | |
| 57 | 57 | if (function_exists($f)) { |
| 58 | 58 | return $f; |
| 59 | 59 | } |
| 60 | - if (function_exists($g = $f . '_dist')) { |
|
| 60 | + if (function_exists($g = $f.'_dist')) { |
|
| 61 | 61 | return $g; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | // passer en minuscules (cf les balises de formulaires) |
| 79 | 79 | // et inclure le fichier |
| 80 | 80 | if ( |
| 81 | - !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 81 | + !($inc = include_spip($dossier.($d = strtolower($nom)))) |
|
| 82 | 82 | && strlen(dirname($dossier)) |
| 83 | 83 | && dirname($dossier) != '.' |
| 84 | 84 | ) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Echec : message d'erreur |
| 99 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 99 | + spip_log("fonction $nom ($f ou $g) indisponible". |
|
| 100 | 100 | ($inc ? '' : " (fichier $d absent de $dossier)")); |
| 101 | 101 | |
| 102 | 102 | include_spip('inc/minipres'); |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | echo minipres( |
| 105 | 105 | _T('forum_titre_erreur'), |
| 106 | 106 | $inc ? |
| 107 | - _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 107 | + _T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($f).'</code>']) |
|
| 108 | 108 | . '<br />' |
| 109 | - . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 109 | + . _T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($g).'</code>']) |
|
| 110 | 110 | : |
| 111 | - _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 112 | - ['all_inline' => true,'status' => 404] |
|
| 111 | + _T('fichier_introuvable', ['fichier' => '<code>'.spip_htmlentities($d).'</code>']), |
|
| 112 | + ['all_inline' => true, 'status' => 404] |
|
| 113 | 113 | ); |
| 114 | 114 | exit; |
| 115 | 115 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * - string : chemin du fichier trouvé |
| 156 | 156 | **/ |
| 157 | 157 | function include_spip($f, $include = true) { |
| 158 | - return find_in_path($f . '.php', '', $include); |
|
| 158 | + return find_in_path($f.'.php', '', $include); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * - string : chemin du fichier trouvé |
| 176 | 176 | **/ |
| 177 | 177 | function require_spip($f) { |
| 178 | - return find_in_path($f . '.php', '', 'required'); |
|
| 178 | + return find_in_path($f.'.php', '', 'required'); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | // donc il faut l'inclure "en globals" |
| 193 | 193 | if ($f = find_in_path('mes_fonctions.php')) { |
| 194 | 194 | global $dossier_squelettes; |
| 195 | - include_once(_ROOT_CWD . $f); |
|
| 195 | + include_once(_ROOT_CWD.$f); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // appliquer notre fonction si elle existe |
| 300 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 300 | + $fonc = 'execute_pipeline_'.strtolower($action); |
|
| 301 | 301 | if (function_exists($fonc)) { |
| 302 | 302 | $val = $fonc($val); |
| 303 | 303 | } // plantage ? |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | function spip_log($message = null, $name = null) { |
| 363 | 363 | static $pre = []; |
| 364 | 364 | static $log; |
| 365 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 365 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs); |
|
| 366 | 366 | if (!isset($regs[1]) || !$logname = $regs[1]) { |
| 367 | 367 | $logname = null; |
| 368 | 368 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | if (!is_string($message)) { |
| 391 | 391 | $message = print_r($message, true); |
| 392 | 392 | } |
| 393 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 393 | + $log($pre[$niveau].' '.$message, $logname); |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | foreach ($regexp as $r => $e) { |
| 598 | 598 | $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e)); |
| 599 | 599 | } |
| 600 | - $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,'; |
|
| 600 | + $regexp = ',^('.implode('|', $regexp).'[[]?[]]?)(=.*)?$,'; |
|
| 601 | 601 | $ajouts = array_flip(explode('|', $c)); |
| 602 | 602 | $u = is_array($v) ? $v : rawurlencode((string) $v); |
| 603 | 603 | $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | // Ajout. Pour une variable, remplacer au meme endroit, |
| 625 | 625 | // pour un tableau ce sera fait dans la prochaine boucle |
| 626 | 626 | elseif (!str_ends_with($r[1], '[]')) { |
| 627 | - $url[$n] = $r[1] . '=' . $u; |
|
| 627 | + $url[$n] = $r[1].'='.$u; |
|
| 628 | 628 | unset($ajouts[$r[1]]); |
| 629 | 629 | } |
| 630 | 630 | // Pour les tableaux on laisse tomber les valeurs de |
@@ -645,11 +645,11 @@ discard block |
||
| 645 | 645 | } elseif ($testv) { |
| 646 | 646 | foreach ($ajouts as $k => $n) { |
| 647 | 647 | if (!is_array($v)) { |
| 648 | - $url[] = $k . '=' . $u; |
|
| 648 | + $url[] = $k.'='.$u; |
|
| 649 | 649 | } else { |
| 650 | - $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]'); |
|
| 650 | + $id = (str_ends_with($k, '[]')) ? $k : ($k.'[]'); |
|
| 651 | 651 | foreach ($v as $w) { |
| 652 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 652 | + $url[] = $id.'='.(is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 653 | 653 | } |
| 654 | 654 | } |
| 655 | 655 | } |
@@ -660,10 +660,10 @@ discard block |
||
| 660 | 660 | |
| 661 | 661 | // recomposer l'adresse |
| 662 | 662 | if ($url) { |
| 663 | - $a .= '?' . join($sep, $url); |
|
| 663 | + $a .= '?'.join($sep, $url); |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - return $a . $ancre; |
|
| 666 | + return $a.$ancre; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | translitteration($ancre) |
| 694 | 694 | ); |
| 695 | 695 | } |
| 696 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 696 | + return $url.(strlen($ancre) ? '#'.$ancre : ''); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /** |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | if (str_starts_with($var, '^')) { |
| 739 | 739 | $var = substr($var, 1); |
| 740 | 740 | } else { |
| 741 | - $var = '[^=&]*' . $var; |
|
| 741 | + $var = '[^=&]*'.$var; |
|
| 742 | 742 | } |
| 743 | 743 | if (str_ends_with($var, '$')) { |
| 744 | 744 | $var = substr($var, 0, -1); |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | $var .= '[^=&]*'; |
| 747 | 747 | } |
| 748 | 748 | } |
| 749 | - $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i'; |
|
| 749 | + $preg_nettoyer = ',([?&])('.implode('|', $preg_nettoyer_vars).')=[^&]*(&|$),i'; |
|
| 750 | 750 | } |
| 751 | 751 | if (empty($request_uri)) { |
| 752 | 752 | return $request_uri; |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | * @return bool |
| 834 | 834 | */ |
| 835 | 835 | function test_plugin_actif($plugin) { |
| 836 | - return ($plugin && defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 836 | + return ($plugin && defined('_DIR_PLUGIN_'.strtoupper($plugin))) ? true : false; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | $value = interdire_scripts($value, -1); |
| 966 | 966 | } |
| 967 | 967 | if (!empty($options['class'])) { |
| 968 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 968 | + $value = "<span class='".$options['class']."'>$value</span>"; |
|
| 969 | 969 | } |
| 970 | 970 | $text = str_replace("@$name@", (string) $value, (string) $text); |
| 971 | 971 | unset($args[$name]); |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | // Si des variables n'ont pas ete inserees, le signaler |
| 975 | 975 | // (chaines de langues pas a jour) |
| 976 | 976 | if ($args) { |
| 977 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 977 | + spip_log("$f: variables inutilisees ".join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | function joli_repertoire($rep) { |
| 999 | 999 | $a = substr($rep, 0, 1); |
| 1000 | 1000 | if ($a <> '.' && $a <> '/') { |
| 1001 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 1001 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS).$rep; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | $rep = preg_replace(',(^\.\.\/),', '', $rep); |
| 1004 | 1004 | |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | $p -= ($x * 1000); |
| 1053 | 1053 | } |
| 1054 | 1054 | |
| 1055 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1055 | + return $s.sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1056 | 1056 | } |
| 1057 | 1057 | } |
| 1058 | 1058 | |
@@ -1119,7 +1119,7 @@ discard block |
||
| 1119 | 1119 | if ($taches && count($taches) && !spip_connect()) { |
| 1120 | 1120 | return false; |
| 1121 | 1121 | } |
| 1122 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1122 | + spip_log('cron !', 'jq'._LOG_DEBUG); |
|
| 1123 | 1123 | if ($genie = charger_fonction('genie', 'inc', true)) { |
| 1124 | 1124 | return $genie($taches); |
| 1125 | 1125 | } |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | |
| 1223 | 1223 | if ($queue_next_job_time == -1) { |
| 1224 | 1224 | if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
| 1225 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1225 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP.'job_queue_next.txt'); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | // utiliser un cache memoire si dispo |
| 1228 | 1228 | if (function_exists('cache_get') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) { |
@@ -1292,8 +1292,8 @@ discard block |
||
| 1292 | 1292 | $src = ''; |
| 1293 | 1293 | } |
| 1294 | 1294 | if ($script) { |
| 1295 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1296 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1295 | + $script = ("/*<![CDATA[*/\n". |
|
| 1296 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script). |
|
| 1297 | 1297 | '/*]]>*/'); |
| 1298 | 1298 | } |
| 1299 | 1299 | if ($noscript) { |
@@ -1382,13 +1382,13 @@ discard block |
||
| 1382 | 1382 | if ($path_base == null) { |
| 1383 | 1383 | // Chemin standard depuis l'espace public |
| 1384 | 1384 | $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
| 1385 | - _DIR_RACINE . ':' . |
|
| 1386 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1387 | - _DIR_RACINE . 'prive/:' . |
|
| 1385 | + _DIR_RACINE.':'. |
|
| 1386 | + _DIR_RACINE.'squelettes-dist/:'. |
|
| 1387 | + _DIR_RACINE.'prive/:'. |
|
| 1388 | 1388 | _DIR_RESTREINT; |
| 1389 | 1389 | // Ajouter squelettes/ |
| 1390 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1391 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1390 | + if (@is_dir(_DIR_RACINE.'squelettes')) { |
|
| 1391 | + $path = _DIR_RACINE.'squelettes/:'.$path; |
|
| 1392 | 1392 | } |
| 1393 | 1393 | foreach (explode(':', $path) as $dir) { |
| 1394 | 1394 | if (strlen($dir) && !str_ends_with($dir, '/')) { |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | // Et le(s) dossier(s) des squelettes nommes |
| 1401 | 1401 | if (strlen($GLOBALS['dossier_squelettes'])) { |
| 1402 | 1402 | foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
| 1403 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1403 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/'); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | } |
| 1406 | 1406 | $GLOBALS['path_sig'] = md5(serialize($path_full)); |
@@ -1411,7 +1411,7 @@ discard block |
||
| 1411 | 1411 | |
| 1412 | 1412 | if (is_array($dir_path) || strlen($dir_path)) { |
| 1413 | 1413 | $tete = ''; |
| 1414 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1414 | + if (reset($path_base) == _DIR_RACINE.'squelettes/') { |
|
| 1415 | 1415 | $tete = array_shift($path_base); |
| 1416 | 1416 | } |
| 1417 | 1417 | $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
@@ -1432,7 +1432,7 @@ discard block |
||
| 1432 | 1432 | // Et le(s) dossier(s) des squelettes nommes |
| 1433 | 1433 | if (strlen($GLOBALS['dossier_squelettes'])) { |
| 1434 | 1434 | foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
| 1435 | - array_unshift($path_full, ((isset($d[0]) && $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1435 | + array_unshift($path_full, ((isset($d[0]) && $d[0] == '/') ? '' : _DIR_RACINE).$d.'/'); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | } |
| 1438 | 1438 | |
@@ -1508,14 +1508,14 @@ discard block |
||
| 1508 | 1508 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 1509 | 1509 | if ( |
| 1510 | 1510 | preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
| 1511 | - && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 1511 | + && ($file_svg_generique = substr($file, 0, -strlen($m[0])).'-xx.svg') |
|
| 1512 | 1512 | && ($f = find_in_theme("$file_svg_generique")) |
| 1513 | 1513 | ) { |
| 1514 | - if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 1514 | + if (($fsize = substr($f, 0, -6).$m[1].'.svg') && file_exists($fsize)) { |
|
| 1515 | 1515 | return $themefiles["$subdir$file"] = $fsize; |
| 1516 | 1516 | } |
| 1517 | 1517 | else { |
| 1518 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1518 | + return $themefiles["$subdir$file"] = "$f?".$m[1].'px'; |
|
| 1519 | 1519 | } |
| 1520 | 1520 | } |
| 1521 | 1521 | |
@@ -1525,7 +1525,7 @@ discard block |
||
| 1525 | 1525 | return $themefiles["$subdir$file"] = $f; |
| 1526 | 1526 | } |
| 1527 | 1527 | } |
| 1528 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1528 | + spip_log("$file introuvable dans le theme prive ".reset($themes), 'theme'); |
|
| 1529 | 1529 | |
| 1530 | 1530 | return $themefiles["$subdir$file"] = ''; |
| 1531 | 1531 | } |
@@ -1633,8 +1633,8 @@ discard block |
||
| 1633 | 1633 | return false; |
| 1634 | 1634 | } |
| 1635 | 1635 | if ($include && !isset($inc[$dirname][$file])) { |
| 1636 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1637 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1636 | + include_once _ROOT_CWD.$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1637 | + $inc[$dirname][$file] = $inc[''][$dirname.$file] = true; |
|
| 1638 | 1638 | } |
| 1639 | 1639 | |
| 1640 | 1640 | return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
@@ -1647,14 +1647,14 @@ discard block |
||
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | foreach (creer_chemin() as $dir) { |
| 1650 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1651 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1650 | + if (!isset($dirs[$a = $dir.$dirname])) { |
|
| 1651 | + $dirs[$a] = (is_dir(_ROOT_CWD.$a) || !$a); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | if ($dirs[$a]) { |
| 1654 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1654 | + if (file_exists(_ROOT_CWD.($a .= $file))) { |
|
| 1655 | 1655 | if ($include && !isset($inc[$dirname][$file])) { |
| 1656 | - include_once _ROOT_CWD . $a; |
|
| 1657 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1656 | + include_once _ROOT_CWD.$a; |
|
| 1657 | + $inc[$dirname][$file] = $inc[''][$dirname.$file] = true; |
|
| 1658 | 1658 | } |
| 1659 | 1659 | if (!defined('_SAUVER_CHEMIN')) { |
| 1660 | 1660 | // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
@@ -1664,7 +1664,7 @@ discard block |
||
| 1664 | 1664 | define('_SAUVER_CHEMIN', true); |
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1667 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = $a; |
|
| 1668 | 1668 | } |
| 1669 | 1669 | } |
| 1670 | 1670 | } |
@@ -1690,7 +1690,7 @@ discard block |
||
| 1690 | 1690 | define('_SAUVER_CHEMIN', true); |
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1693 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = false; |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | function clear_path_cache() { |
@@ -1760,12 +1760,12 @@ discard block |
||
| 1760 | 1760 | // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
| 1761 | 1761 | // on a pas encore inclus flock.php |
| 1762 | 1762 | if (!function_exists('preg_files')) { |
| 1763 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1763 | + include_once _ROOT_RESTREINT.'inc/flock.php'; |
|
| 1764 | 1764 | } |
| 1765 | 1765 | |
| 1766 | 1766 | // Parcourir le chemin |
| 1767 | 1767 | foreach (creer_chemin() as $d) { |
| 1768 | - $f = $d . $dir; |
|
| 1768 | + $f = $d.$dir; |
|
| 1769 | 1769 | if (@is_dir($f)) { |
| 1770 | 1770 | $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
| 1771 | 1771 | foreach ($liste as $chemin) { |
@@ -1817,8 +1817,8 @@ discard block |
||
| 1817 | 1817 | if ($type === 'defaut') { |
| 1818 | 1818 | $objet = objet_type($quoi); |
| 1819 | 1819 | if ( |
| 1820 | - ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 1821 | - || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 1820 | + ($f = charger_fonction('generer_'.$objet.'_url', 'urls', true)) |
|
| 1821 | + || ($f = charger_fonction('generer_url_'.$objet, 'urls', true)) // deprecated |
|
| 1822 | 1822 | ) { |
| 1823 | 1823 | return $f; |
| 1824 | 1824 | } |
@@ -1831,7 +1831,7 @@ discard block |
||
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | 1833 | // inclure le module d'url |
| 1834 | - include_spip('urls/' . $url_type); |
|
| 1834 | + include_spip('urls/'.$url_type); |
|
| 1835 | 1835 | |
| 1836 | 1836 | switch ($quoi) { |
| 1837 | 1837 | case 'page': |
@@ -1931,7 +1931,7 @@ discard block |
||
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | 1933 | // On a ete gentil mais la .... |
| 1934 | - spip_log("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1934 | + spip_log("generer_objet_url: entite $entite ".($public ? "($f)" : '')." inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1935 | 1935 | |
| 1936 | 1936 | return ''; |
| 1937 | 1937 | } |
@@ -1982,8 +1982,8 @@ discard block |
||
| 1982 | 1982 | include_spip('base/connect_sql'); |
| 1983 | 1983 | $id_type = id_table_objet($entite, $public); |
| 1984 | 1984 | |
| 1985 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1986 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1985 | + return _DIR_RACINE.get_spip_script('./') |
|
| 1986 | + . '?'._SPIP_PAGE."=$entite&$id_type=$i&connect=$public" |
|
| 1987 | 1987 | . (!$args ? '' : "&$args") |
| 1988 | 1988 | . (!$ancre ? '' : "#$ancre"); |
| 1989 | 1989 | } |
@@ -2152,7 +2152,7 @@ discard block |
||
| 2152 | 2152 | !empty($_SERVER['QUERY_STRING']) |
| 2153 | 2153 | && !str_contains($_SERVER['REQUEST_URI'], '?') |
| 2154 | 2154 | ) { |
| 2155 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2155 | + $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
| 2156 | 2156 | } |
| 2157 | 2157 | } |
| 2158 | 2158 | } |
@@ -2190,9 +2190,9 @@ discard block |
||
| 2190 | 2190 | array_shift($myself); |
| 2191 | 2191 | $myself = implode('/', $myself); |
| 2192 | 2192 | } |
| 2193 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2193 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/'; |
|
| 2194 | 2194 | |
| 2195 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2195 | + $url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/'); |
|
| 2196 | 2196 | |
| 2197 | 2197 | return $url; |
| 2198 | 2198 | } |
@@ -2231,16 +2231,16 @@ discard block |
||
| 2231 | 2231 | function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) { |
| 2232 | 2232 | $script ??= ''; |
| 2233 | 2233 | if (!$rel) { |
| 2234 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2234 | + $rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT; |
|
| 2235 | 2235 | } else { |
| 2236 | 2236 | if (!is_string($rel)) { |
| 2237 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2237 | + $rel = _DIR_RESTREINT ?: './'._SPIP_ECRIRE_SCRIPT; |
|
| 2238 | 2238 | } |
| 2239 | 2239 | } |
| 2240 | 2240 | |
| 2241 | 2241 | [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
| 2242 | 2242 | if ($script && ($script <> 'accueil' || $rel)) { |
| 2243 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2243 | + $args = "?exec=$script".(!$args ? '' : "&$args"); |
|
| 2244 | 2244 | } elseif ($args) { |
| 2245 | 2245 | $args = "?$args"; |
| 2246 | 2246 | } |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | $args .= "#$ancre"; |
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2251 | + return $rel.($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 2254 | 2254 | // |
@@ -2330,10 +2330,10 @@ discard block |
||
| 2330 | 2330 | $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
| 2331 | 2331 | } |
| 2332 | 2332 | if ($args) { |
| 2333 | - $action .= (str_contains($action, '?') ? '&' : '?') . $args; |
|
| 2333 | + $action .= (str_contains($action, '?') ? '&' : '?').$args; |
|
| 2334 | 2334 | } |
| 2335 | 2335 | // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
| 2336 | - $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2336 | + $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/').preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2337 | 2337 | } |
| 2338 | 2338 | |
| 2339 | 2339 | if (!$no_entities) { |
@@ -2345,7 +2345,7 @@ discard block |
||
| 2345 | 2345 | |
| 2346 | 2346 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2347 | 2347 | |
| 2348 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2348 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php'); |
|
| 2349 | 2349 | } |
| 2350 | 2350 | |
| 2351 | 2351 | // Pour les formulaires en methode POST, |
@@ -2380,8 +2380,7 @@ discard block |
||
| 2380 | 2380 | . "><div>\n" |
| 2381 | 2381 | . "<input type='hidden' name='exec' value='$script1' />" |
| 2382 | 2382 | . $corps |
| 2383 | - . (!$submit ? '' : |
|
| 2384 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2383 | + . (!$submit ? '' : ("<div style='text-align: ".$GLOBALS['spip_lang_right']."'><input class='fondo submit btn' type='submit' value=\"".entites_html($submit).'" /></div>')) |
|
| 2385 | 2384 | . "</div></form>\n"; |
| 2386 | 2385 | } |
| 2387 | 2386 | |
@@ -2406,14 +2405,14 @@ discard block |
||
| 2406 | 2405 | ? generer_url_ecrire(_request('exec')) |
| 2407 | 2406 | : generer_url_public(); |
| 2408 | 2407 | |
| 2409 | - return "\n<form action='" . |
|
| 2410 | - $h . |
|
| 2411 | - "'" . |
|
| 2412 | - $atts . |
|
| 2413 | - ">\n" . |
|
| 2414 | - '<div>' . |
|
| 2415 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2416 | - $corps . |
|
| 2408 | + return "\n<form action='". |
|
| 2409 | + $h. |
|
| 2410 | + "'". |
|
| 2411 | + $atts. |
|
| 2412 | + ">\n". |
|
| 2413 | + '<div>'. |
|
| 2414 | + "\n<input type='hidden' name='action' value='$script' />". |
|
| 2415 | + $corps. |
|
| 2417 | 2416 | '</div></form>'; |
| 2418 | 2417 | } |
| 2419 | 2418 | |
@@ -2441,7 +2440,7 @@ discard block |
||
| 2441 | 2440 | : generer_url_public('', '', false, false); |
| 2442 | 2441 | $url = parametre_url($url, 'action', $script); |
| 2443 | 2442 | if ($args) { |
| 2444 | - $url .= quote_amp('&' . $args); |
|
| 2443 | + $url .= quote_amp('&'.$args); |
|
| 2445 | 2444 | } |
| 2446 | 2445 | |
| 2447 | 2446 | if ($no_entities) { |
@@ -2475,9 +2474,9 @@ discard block |
||
| 2475 | 2474 | } |
| 2476 | 2475 | $url = |
| 2477 | 2476 | (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
| 2478 | - . $script . '/' |
|
| 2477 | + . $script.'/' |
|
| 2479 | 2478 | . ($path ? trim($path, '/') : '') |
| 2480 | - . ($args ? '?' . quote_amp($args) : ''); |
|
| 2479 | + . ($args ? '?'.quote_amp($args) : ''); |
|
| 2481 | 2480 | |
| 2482 | 2481 | if ($no_entities) { |
| 2483 | 2482 | $url = str_replace('&', '&', $url); |
@@ -2526,22 +2525,22 @@ discard block |
||
| 2526 | 2525 | |
| 2527 | 2526 | // le nom du repertoire plugins/ activables/desactivables |
| 2528 | 2527 | if (!defined('_DIR_PLUGINS')) { |
| 2529 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2528 | + define('_DIR_PLUGINS', _DIR_RACINE.'plugins/'); |
|
| 2530 | 2529 | } |
| 2531 | 2530 | |
| 2532 | 2531 | // le nom du repertoire des extensions/ permanentes du core, toujours actives |
| 2533 | 2532 | if (!defined('_DIR_PLUGINS_DIST')) { |
| 2534 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2533 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE.'plugins-dist/'); |
|
| 2535 | 2534 | } |
| 2536 | 2535 | |
| 2537 | 2536 | // le nom du repertoire des librairies |
| 2538 | 2537 | if (!defined('_DIR_LIB')) { |
| 2539 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2538 | + define('_DIR_LIB', _DIR_RACINE.'lib/'); |
|
| 2540 | 2539 | } |
| 2541 | 2540 | |
| 2542 | 2541 | // répertoire des libs via Composer |
| 2543 | 2542 | if (!defined('_DIR_VENDOR')) { |
| 2544 | - define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 2543 | + define('_DIR_VENDOR', _DIR_RACINE.'vendor/'); |
|
| 2545 | 2544 | } |
| 2546 | 2545 | |
| 2547 | 2546 | if (!defined('_DIR_IMG')) { |
@@ -2551,29 +2550,29 @@ discard block |
||
| 2551 | 2550 | define('_DIR_LOGOS', $pa); |
| 2552 | 2551 | } |
| 2553 | 2552 | if (!defined('_DIR_IMG_ICONES')) { |
| 2554 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2553 | + define('_DIR_IMG_ICONES', _DIR_LOGOS.'icones/'); |
|
| 2555 | 2554 | } |
| 2556 | 2555 | |
| 2557 | 2556 | if (!defined('_DIR_DUMP')) { |
| 2558 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2557 | + define('_DIR_DUMP', $ti.'dump/'); |
|
| 2559 | 2558 | } |
| 2560 | 2559 | if (!defined('_DIR_SESSIONS')) { |
| 2561 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2560 | + define('_DIR_SESSIONS', $ti.'sessions/'); |
|
| 2562 | 2561 | } |
| 2563 | 2562 | if (!defined('_DIR_TRANSFERT')) { |
| 2564 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2563 | + define('_DIR_TRANSFERT', $ti.'upload/'); |
|
| 2565 | 2564 | } |
| 2566 | 2565 | if (!defined('_DIR_CACHE')) { |
| 2567 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2566 | + define('_DIR_CACHE', $ti.'cache/'); |
|
| 2568 | 2567 | } |
| 2569 | 2568 | if (!defined('_DIR_CACHE_XML')) { |
| 2570 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2569 | + define('_DIR_CACHE_XML', _DIR_CACHE.'xml/'); |
|
| 2571 | 2570 | } |
| 2572 | 2571 | if (!defined('_DIR_SKELS')) { |
| 2573 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2572 | + define('_DIR_SKELS', _DIR_CACHE.'skel/'); |
|
| 2574 | 2573 | } |
| 2575 | 2574 | if (!defined('_DIR_AIDE')) { |
| 2576 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2575 | + define('_DIR_AIDE', _DIR_CACHE.'aide/'); |
|
| 2577 | 2576 | } |
| 2578 | 2577 | if (!defined('_DIR_TMP')) { |
| 2579 | 2578 | define('_DIR_TMP', $ti); |
@@ -2602,27 +2601,27 @@ discard block |
||
| 2602 | 2601 | // Declaration des fichiers |
| 2603 | 2602 | |
| 2604 | 2603 | if (!defined('_CACHE_PLUGINS_PATH')) { |
| 2605 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2604 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE.'charger_plugins_chemins.php'); |
|
| 2606 | 2605 | } |
| 2607 | 2606 | if (!defined('_CACHE_PLUGINS_OPT')) { |
| 2608 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2607 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE.'charger_plugins_options.php'); |
|
| 2609 | 2608 | } |
| 2610 | 2609 | if (!defined('_CACHE_PLUGINS_FCT')) { |
| 2611 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2610 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE.'charger_plugins_fonctions.php'); |
|
| 2612 | 2611 | } |
| 2613 | 2612 | if (!defined('_CACHE_PIPELINES')) { |
| 2614 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2613 | + define('_CACHE_PIPELINES', _DIR_CACHE.'charger_pipelines.php'); |
|
| 2615 | 2614 | } |
| 2616 | 2615 | if (!defined('_CACHE_CHEMIN')) { |
| 2617 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2616 | + define('_CACHE_CHEMIN', _DIR_CACHE.'chemin.txt'); |
|
| 2618 | 2617 | } |
| 2619 | 2618 | |
| 2620 | 2619 | # attention .php obligatoire pour ecrire_fichier_securise |
| 2621 | 2620 | if (!defined('_FILE_META')) { |
| 2622 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2621 | + define('_FILE_META', $ti.'meta_cache.php'); |
|
| 2623 | 2622 | } |
| 2624 | 2623 | if (!defined('_DIR_LOG')) { |
| 2625 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2624 | + define('_DIR_LOG', _DIR_TMP.'log/'); |
|
| 2626 | 2625 | } |
| 2627 | 2626 | if (!defined('_FILE_LOG')) { |
| 2628 | 2627 | define('_FILE_LOG', 'spip'); |
@@ -2638,7 +2637,7 @@ discard block |
||
| 2638 | 2637 | if (!defined('_FILE_CONNECT')) { |
| 2639 | 2638 | define( |
| 2640 | 2639 | '_FILE_CONNECT', |
| 2641 | - @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 2640 | + @is_readable($f = _DIR_CONNECT._FILE_CONNECT_INS.'.php') ? $f : false |
|
| 2642 | 2641 | ); |
| 2643 | 2642 | } |
| 2644 | 2643 | |
@@ -2649,7 +2648,7 @@ discard block |
||
| 2649 | 2648 | if (!defined('_FILE_CHMOD')) { |
| 2650 | 2649 | define( |
| 2651 | 2650 | '_FILE_CHMOD', |
| 2652 | - @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 2651 | + @is_readable($f = _DIR_CHMOD._FILE_CHMOD_INS.'.php') ? $f : false |
|
| 2653 | 2652 | ); |
| 2654 | 2653 | } |
| 2655 | 2654 | |
@@ -2661,10 +2660,10 @@ discard block |
||
| 2661 | 2660 | define('_FILE_TMP_SUFFIX', '.tmp.php'); |
| 2662 | 2661 | } |
| 2663 | 2662 | if (!defined('_FILE_CONNECT_TMP')) { |
| 2664 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2663 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT._FILE_CONNECT_INS._FILE_TMP_SUFFIX); |
|
| 2665 | 2664 | } |
| 2666 | 2665 | if (!defined('_FILE_CHMOD_TMP')) { |
| 2667 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2666 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD._FILE_CHMOD_INS._FILE_TMP_SUFFIX); |
|
| 2668 | 2667 | } |
| 2669 | 2668 | |
| 2670 | 2669 | // Definition des droits d'acces en ecriture |
@@ -2682,13 +2681,13 @@ discard block |
||
| 2682 | 2681 | define('_DEFAULT_CHARSET', 'utf-8'); |
| 2683 | 2682 | } |
| 2684 | 2683 | if (!defined('_ROOT_PLUGINS')) { |
| 2685 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2684 | + define('_ROOT_PLUGINS', _ROOT_RACINE.'plugins/'); |
|
| 2686 | 2685 | } |
| 2687 | 2686 | if (!defined('_ROOT_PLUGINS_DIST')) { |
| 2688 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2687 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE.'plugins-dist/'); |
|
| 2689 | 2688 | } |
| 2690 | 2689 | if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
| 2691 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2690 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE.str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2692 | 2691 | } |
| 2693 | 2692 | |
| 2694 | 2693 | // La taille des Log |
@@ -2725,7 +2724,7 @@ discard block |
||
| 2725 | 2724 | // (non surchargeable en l'etat ; attention si on utilise include_spip() |
| 2726 | 2725 | // pour le rendre surchargeable, on va provoquer un reecriture |
| 2727 | 2726 | // systematique du noyau ou une baisse de perfs => a etudier) |
| 2728 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2727 | + include_once _ROOT_RESTREINT.'inc/flock.php'; |
|
| 2729 | 2728 | |
| 2730 | 2729 | // charger tout de suite le path et son cache |
| 2731 | 2730 | load_path_cache(); |
@@ -2761,7 +2760,7 @@ discard block |
||
| 2761 | 2760 | !empty($_SERVER['QUERY_STRING']) |
| 2762 | 2761 | && !strpos($_SERVER['REQUEST_URI'], '?') |
| 2763 | 2762 | ) { |
| 2764 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2763 | + $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
| 2765 | 2764 | } |
| 2766 | 2765 | } |
| 2767 | 2766 | |
@@ -2797,7 +2796,7 @@ discard block |
||
| 2797 | 2796 | ) { |
| 2798 | 2797 | if (isset($GLOBALS['meta']['adresse_site'])) { |
| 2799 | 2798 | $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
| 2800 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2799 | + $uri_ref = ($uri_ref['path'] ?? '').'/'; |
|
| 2801 | 2800 | } else { |
| 2802 | 2801 | $uri_ref = ''; |
| 2803 | 2802 | } |
@@ -2891,7 +2890,7 @@ discard block |
||
| 2891 | 2890 | } |
| 2892 | 2891 | if (!defined('_CACHE_RUBRIQUES')) { |
| 2893 | 2892 | /** Fichier cache pour le navigateur de rubrique du bandeau */ |
| 2894 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2893 | + define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt'); |
|
| 2895 | 2894 | } |
| 2896 | 2895 | if (!defined('_CACHE_RUBRIQUES_MAX')) { |
| 2897 | 2896 | /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
@@ -3114,7 +3113,7 @@ discard block |
||
| 3114 | 3113 | } |
| 3115 | 3114 | if (isset($GLOBALS['visiteur_session']['nom'])) { |
| 3116 | 3115 | spip_log($GLOBALS['visiteur_session']['nom'] |
| 3117 | - . ' ' . _VAR_MODE); |
|
| 3116 | + . ' '._VAR_MODE); |
|
| 3118 | 3117 | } |
| 3119 | 3118 | } // pas autorise ? |
| 3120 | 3119 | else { |
@@ -3129,7 +3128,7 @@ discard block |
||
| 3129 | 3128 | if (!str_contains($self, 'page=login')) { |
| 3130 | 3129 | include_spip('inc/headers'); |
| 3131 | 3130 | $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
| 3132 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3131 | + redirige_par_entete(generer_url_public('login', 'url='.rawurlencode($redirect), true)); |
|
| 3133 | 3132 | } |
| 3134 | 3133 | } |
| 3135 | 3134 | // sinon tant pis |
@@ -3179,10 +3178,10 @@ discard block |
||
| 3179 | 3178 | **/ |
| 3180 | 3179 | function verifier_visiteur() { |
| 3181 | 3180 | @spip_initialisation_core( |
| 3182 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3183 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3184 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3185 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3181 | + (_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES), |
|
| 3182 | + (_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES), |
|
| 3183 | + (_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3184 | + (_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3186 | 3185 | ); |
| 3187 | 3186 | |
| 3188 | 3187 | // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
@@ -3215,7 +3214,7 @@ discard block |
||
| 3215 | 3214 | } |
| 3216 | 3215 | |
| 3217 | 3216 | $h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']); |
| 3218 | - if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3217 | + if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) { |
|
| 3219 | 3218 | $session = charger_fonction('session', 'inc'); |
| 3220 | 3219 | if ($session()) { |
| 3221 | 3220 | return $GLOBALS['visiteur_session']['statut']; |
@@ -3295,7 +3294,7 @@ discard block |
||
| 3295 | 3294 | if (!empty($GLOBALS['visiteur_session'])) { |
| 3296 | 3295 | include_spip('inc/session'); |
| 3297 | 3296 | $cookie = lire_cookie_session(); |
| 3298 | - $s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: ''); |
|
| 3297 | + $s = serialize($GLOBALS['visiteur_session']).'_'.($cookie ?: ''); |
|
| 3299 | 3298 | } |
| 3300 | 3299 | $s = pipeline('definir_session', $s); |
| 3301 | 3300 | $session = ($s ? substr(md5($s), 0, 8) : ''); |
@@ -3343,8 +3342,8 @@ discard block |
||
| 3343 | 3342 | foreach ($cookies_masques as $k) { |
| 3344 | 3343 | if (!empty($_COOKIE[$k])) { |
| 3345 | 3344 | $cookies_backup[$k] = $_COOKIE[$k]; |
| 3346 | - $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []); |
|
| 3347 | - $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []); |
|
| 3345 | + $_SERVER['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []); |
|
| 3346 | + $_ENV['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []); |
|
| 3348 | 3347 | $_COOKIE[$k] = $mask; |
| 3349 | 3348 | } |
| 3350 | 3349 | } |
@@ -3462,11 +3461,11 @@ discard block |
||
| 3462 | 3461 | $GLOBALS['_INC_PUBLIC']++; |
| 3463 | 3462 | |
| 3464 | 3463 | // fix #4235 |
| 3465 | - $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3464 | + $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3466 | 3465 | |
| 3467 | 3466 | |
| 3468 | 3467 | foreach (is_array($fond) ? $fond : [$fond] as $f) { |
| 3469 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3468 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3470 | 3469 | |
| 3471 | 3470 | $page = evaluer_fond($f, $contexte, $connect); |
| 3472 | 3471 | if ($page === '') { |
@@ -3551,7 +3550,7 @@ discard block |
||
| 3551 | 3550 | * @return array|string |
| 3552 | 3551 | */ |
| 3553 | 3552 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3554 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3553 | + $f = find_in_path($nom.'.'._EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/').'/' : ''); |
|
| 3555 | 3554 | if (!$pathinfo) { |
| 3556 | 3555 | return $f; |
| 3557 | 3556 | } |
@@ -19,170 +19,170 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | function assembler($fond, string $connect = '') { |
| 26 | 26 | |
| 27 | - $chemin_cache = null; |
|
| 28 | - $lastmodified = null; |
|
| 29 | - $res = null; |
|
| 30 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 31 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 32 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 33 | - |
|
| 34 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 35 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 36 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 37 | - ',\.[a-zA-Z0-9]*$,', |
|
| 38 | - '', |
|
| 39 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 40 | - ); |
|
| 41 | - // Cette fonction est utilisee deux fois |
|
| 42 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 43 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 44 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 45 | - if ($cacher) { |
|
| 46 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 47 | - } else { |
|
| 48 | - $GLOBALS['use_cache'] = -1; |
|
| 49 | - } |
|
| 50 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 51 | - if ($res) { |
|
| 52 | - return ['texte' => $res]; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if (!$chemin_cache || !$lastmodified) { |
|
| 56 | - $lastmodified = time(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 60 | - $calculer_page = true; |
|
| 61 | - |
|
| 62 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 63 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 64 | - // pages sont dynamiques) |
|
| 65 | - if ( |
|
| 66 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 67 | - && (!defined('_VAR_MODE') || !_VAR_MODE) |
|
| 68 | - && $chemin_cache && isset($page['entetes']) |
|
| 69 | - && isset($page['entetes']['Cache-Control']) |
|
| 70 | - && strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 71 | - && !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 72 | - ) { |
|
| 73 | - $since = preg_replace( |
|
| 74 | - '/;.*/', |
|
| 75 | - '', |
|
| 76 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 77 | - ); |
|
| 78 | - $since = str_replace('GMT', '', $since); |
|
| 79 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 80 | - $page['status'] = 304; |
|
| 81 | - $headers_only = true; |
|
| 82 | - $calculer_page = false; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 87 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 88 | - if (!$calculer_page) { |
|
| 89 | - $page['texte'] = ''; |
|
| 90 | - } else { |
|
| 91 | - // si la page est prise dans le cache |
|
| 92 | - if (!$GLOBALS['use_cache']) { |
|
| 93 | - // Informer les boutons d'admin du contexte |
|
| 94 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 95 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 96 | - |
|
| 97 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 98 | - // d'inversion url => objet |
|
| 99 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 100 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 101 | - #unset($_ENV['url_propre']); |
|
| 102 | - } else { |
|
| 103 | - // Compat ascendante : |
|
| 104 | - // 1. $contexte est global |
|
| 105 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 106 | - // et calculer la page |
|
| 107 | - if (!test_espace_prive()) { |
|
| 108 | - include_spip('inc/urls'); |
|
| 109 | - [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 110 | - nettoyer_uri(), |
|
| 111 | - $fond, |
|
| 112 | - $GLOBALS['contexte'], |
|
| 113 | - true |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - // squelette par defaut |
|
| 117 | - if (!strlen($fond ?? '')) { |
|
| 118 | - $fond = 'sommaire'; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // produire la page : peut mettre a jour $lastmodified |
|
| 122 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 123 | - $page = $produire_page( |
|
| 124 | - $fond, |
|
| 125 | - $GLOBALS['contexte'], |
|
| 126 | - $GLOBALS['use_cache'], |
|
| 127 | - $chemin_cache, |
|
| 128 | - null, |
|
| 129 | - $page, |
|
| 130 | - $lastmodified, |
|
| 131 | - $connect |
|
| 132 | - ); |
|
| 133 | - if ($page === '') { |
|
| 134 | - $erreur = _T( |
|
| 135 | - 'info_erreur_squelette2', |
|
| 136 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 137 | - ); |
|
| 138 | - erreur_squelette($erreur); |
|
| 139 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 140 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($page && $chemin_cache) { |
|
| 145 | - $page['cache'] = $chemin_cache; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - auto_content_type($page); |
|
| 149 | - |
|
| 150 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 151 | - |
|
| 152 | - // Definir les entetes si ce n'est fait |
|
| 153 | - if (!$GLOBALS['flag_preserver']) { |
|
| 154 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 155 | - if ( |
|
| 156 | - trim($page['texte']) === '' |
|
| 157 | - && _VAR_MODE !== 'debug' |
|
| 158 | - && !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 159 | - ) { |
|
| 160 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 161 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 162 | - } |
|
| 163 | - // pas de cache client en mode 'observation' |
|
| 164 | - if (defined('_VAR_MODE') && _VAR_MODE) { |
|
| 165 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 166 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Entete Last-Modified: |
|
| 172 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 173 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 174 | - if ( |
|
| 175 | - $lastmodified && !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !isset($page['entetes']['Last-Modified']) |
|
| 176 | - ) { |
|
| 177 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // fermer la connexion apres les headers si requete HEAD |
|
| 181 | - if ($headers_only) { |
|
| 182 | - $page['entetes']['Connection'] = 'close'; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return $page; |
|
| 27 | + $chemin_cache = null; |
|
| 28 | + $lastmodified = null; |
|
| 29 | + $res = null; |
|
| 30 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 31 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 32 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 33 | + |
|
| 34 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 35 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 36 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 37 | + ',\.[a-zA-Z0-9]*$,', |
|
| 38 | + '', |
|
| 39 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 40 | + ); |
|
| 41 | + // Cette fonction est utilisee deux fois |
|
| 42 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 43 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 44 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 45 | + if ($cacher) { |
|
| 46 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 47 | + } else { |
|
| 48 | + $GLOBALS['use_cache'] = -1; |
|
| 49 | + } |
|
| 50 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 51 | + if ($res) { |
|
| 52 | + return ['texte' => $res]; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if (!$chemin_cache || !$lastmodified) { |
|
| 56 | + $lastmodified = time(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 60 | + $calculer_page = true; |
|
| 61 | + |
|
| 62 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 63 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 64 | + // pages sont dynamiques) |
|
| 65 | + if ( |
|
| 66 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 67 | + && (!defined('_VAR_MODE') || !_VAR_MODE) |
|
| 68 | + && $chemin_cache && isset($page['entetes']) |
|
| 69 | + && isset($page['entetes']['Cache-Control']) |
|
| 70 | + && strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 71 | + && !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 72 | + ) { |
|
| 73 | + $since = preg_replace( |
|
| 74 | + '/;.*/', |
|
| 75 | + '', |
|
| 76 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 77 | + ); |
|
| 78 | + $since = str_replace('GMT', '', $since); |
|
| 79 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 80 | + $page['status'] = 304; |
|
| 81 | + $headers_only = true; |
|
| 82 | + $calculer_page = false; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 87 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 88 | + if (!$calculer_page) { |
|
| 89 | + $page['texte'] = ''; |
|
| 90 | + } else { |
|
| 91 | + // si la page est prise dans le cache |
|
| 92 | + if (!$GLOBALS['use_cache']) { |
|
| 93 | + // Informer les boutons d'admin du contexte |
|
| 94 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 95 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 96 | + |
|
| 97 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 98 | + // d'inversion url => objet |
|
| 99 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 100 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 101 | + #unset($_ENV['url_propre']); |
|
| 102 | + } else { |
|
| 103 | + // Compat ascendante : |
|
| 104 | + // 1. $contexte est global |
|
| 105 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 106 | + // et calculer la page |
|
| 107 | + if (!test_espace_prive()) { |
|
| 108 | + include_spip('inc/urls'); |
|
| 109 | + [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 110 | + nettoyer_uri(), |
|
| 111 | + $fond, |
|
| 112 | + $GLOBALS['contexte'], |
|
| 113 | + true |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + // squelette par defaut |
|
| 117 | + if (!strlen($fond ?? '')) { |
|
| 118 | + $fond = 'sommaire'; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // produire la page : peut mettre a jour $lastmodified |
|
| 122 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 123 | + $page = $produire_page( |
|
| 124 | + $fond, |
|
| 125 | + $GLOBALS['contexte'], |
|
| 126 | + $GLOBALS['use_cache'], |
|
| 127 | + $chemin_cache, |
|
| 128 | + null, |
|
| 129 | + $page, |
|
| 130 | + $lastmodified, |
|
| 131 | + $connect |
|
| 132 | + ); |
|
| 133 | + if ($page === '') { |
|
| 134 | + $erreur = _T( |
|
| 135 | + 'info_erreur_squelette2', |
|
| 136 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 137 | + ); |
|
| 138 | + erreur_squelette($erreur); |
|
| 139 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 140 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($page && $chemin_cache) { |
|
| 145 | + $page['cache'] = $chemin_cache; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + auto_content_type($page); |
|
| 149 | + |
|
| 150 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 151 | + |
|
| 152 | + // Definir les entetes si ce n'est fait |
|
| 153 | + if (!$GLOBALS['flag_preserver']) { |
|
| 154 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 155 | + if ( |
|
| 156 | + trim($page['texte']) === '' |
|
| 157 | + && _VAR_MODE !== 'debug' |
|
| 158 | + && !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 159 | + ) { |
|
| 160 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 161 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 162 | + } |
|
| 163 | + // pas de cache client en mode 'observation' |
|
| 164 | + if (defined('_VAR_MODE') && _VAR_MODE) { |
|
| 165 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 166 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Entete Last-Modified: |
|
| 172 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 173 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 174 | + if ( |
|
| 175 | + $lastmodified && !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !isset($page['entetes']['Last-Modified']) |
|
| 176 | + ) { |
|
| 177 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // fermer la connexion apres les headers si requete HEAD |
|
| 181 | + if ($headers_only) { |
|
| 182 | + $page['entetes']['Connection'] = 'close'; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return $page; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -201,27 +201,27 @@ discard block |
||
| 201 | 201 | * @return array Un tableau du contexte de la page |
| 202 | 202 | */ |
| 203 | 203 | function calculer_contexte() { |
| 204 | - static $preg_ignore_variables; |
|
| 205 | - if (empty($preg_ignore_variables)) { |
|
| 206 | - if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
|
| 207 | - nettoyer_uri_var(''); |
|
| 208 | - } |
|
| 209 | - $preg_ignore_variables = '/(' . implode('|',_CONTEXTE_IGNORE_LISTE_VARIABLES) . ')/'; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $contexte = []; |
|
| 213 | - foreach ($_GET as $var => $val) { |
|
| 214 | - if (!preg_match($preg_ignore_variables, $var)) { |
|
| 215 | - $contexte[$var] = $val; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - foreach ($_POST as $var => $val) { |
|
| 219 | - if (!preg_match($preg_ignore_variables, $var)) { |
|
| 220 | - $contexte[$var] = $val; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - return $contexte; |
|
| 204 | + static $preg_ignore_variables; |
|
| 205 | + if (empty($preg_ignore_variables)) { |
|
| 206 | + if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
|
| 207 | + nettoyer_uri_var(''); |
|
| 208 | + } |
|
| 209 | + $preg_ignore_variables = '/(' . implode('|',_CONTEXTE_IGNORE_LISTE_VARIABLES) . ')/'; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $contexte = []; |
|
| 213 | + foreach ($_GET as $var => $val) { |
|
| 214 | + if (!preg_match($preg_ignore_variables, $var)) { |
|
| 215 | + $contexte[$var] = $val; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + foreach ($_POST as $var => $val) { |
|
| 219 | + if (!preg_match($preg_ignore_variables, $var)) { |
|
| 220 | + $contexte[$var] = $val; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + return $contexte; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -232,25 +232,25 @@ discard block |
||
| 232 | 232 | * @return array |
| 233 | 233 | */ |
| 234 | 234 | function calculer_contexte_implicite() { |
| 235 | - static $notes = null; |
|
| 236 | - if (is_null($notes)) { |
|
| 237 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 238 | - } |
|
| 239 | - $contexte_implicite = [ |
|
| 240 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 241 | - 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 242 | - 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 243 | - 'espace' => test_espace_prive(), |
|
| 244 | - 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 245 | - 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 246 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 247 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 248 | - ]; |
|
| 249 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 250 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - return $contexte_implicite; |
|
| 235 | + static $notes = null; |
|
| 236 | + if (is_null($notes)) { |
|
| 237 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 238 | + } |
|
| 239 | + $contexte_implicite = [ |
|
| 240 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 241 | + 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 242 | + 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 243 | + 'espace' => test_espace_prive(), |
|
| 244 | + 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 245 | + 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 246 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 247 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 248 | + ]; |
|
| 249 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 250 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + return $contexte_implicite; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // |
@@ -259,56 +259,56 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | function auto_content_type($page) { |
| 261 | 261 | |
| 262 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 263 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 264 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 265 | - $page['texte'] |
|
| 266 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 267 | - } |
|
| 262 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 263 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 264 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 265 | + $page['texte'] |
|
| 266 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 267 | + } |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | function inclure_page($fond, $contexte, string $connect = '') { |
| 271 | - $use_cache = null; |
|
| 272 | - $chemin_cache = null; |
|
| 273 | - $lastinclude = null; |
|
| 274 | - $res = null; |
|
| 275 | - static $cacher, $produire_page; |
|
| 276 | - |
|
| 277 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 278 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 279 | - // (cette precaution n'est probablement plus utile) |
|
| 280 | - unset($contexte['fond']); |
|
| 281 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 282 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 283 | - if (is_null($cacher)) { |
|
| 284 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 285 | - } |
|
| 286 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 287 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 288 | - if ($cacher) { |
|
| 289 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 290 | - } else { |
|
| 291 | - $use_cache = -1; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // $res = message d'erreur : on sort de la |
|
| 295 | - if ($res) { |
|
| 296 | - return ['texte' => $res]; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 300 | - // produire la page : peut mettre a jour $lastinclude |
|
| 301 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 302 | - if ($use_cache) { |
|
| 303 | - if (is_null($produire_page)) { |
|
| 304 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 305 | - } |
|
| 306 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 307 | - } |
|
| 308 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 309 | - $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 310 | - |
|
| 311 | - return $page; |
|
| 271 | + $use_cache = null; |
|
| 272 | + $chemin_cache = null; |
|
| 273 | + $lastinclude = null; |
|
| 274 | + $res = null; |
|
| 275 | + static $cacher, $produire_page; |
|
| 276 | + |
|
| 277 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 278 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 279 | + // (cette precaution n'est probablement plus utile) |
|
| 280 | + unset($contexte['fond']); |
|
| 281 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 282 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 283 | + if (is_null($cacher)) { |
|
| 284 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 285 | + } |
|
| 286 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 287 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 288 | + if ($cacher) { |
|
| 289 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 290 | + } else { |
|
| 291 | + $use_cache = -1; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // $res = message d'erreur : on sort de la |
|
| 295 | + if ($res) { |
|
| 296 | + return ['texte' => $res]; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 300 | + // produire la page : peut mettre a jour $lastinclude |
|
| 301 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 302 | + if ($use_cache) { |
|
| 303 | + if (is_null($produire_page)) { |
|
| 304 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 305 | + } |
|
| 306 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 307 | + } |
|
| 308 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 309 | + $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 310 | + |
|
| 311 | + return $page; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -326,41 +326,41 @@ discard block |
||
| 326 | 326 | * @return array |
| 327 | 327 | */ |
| 328 | 328 | function public_produire_page_dist( |
| 329 | - $fond, |
|
| 330 | - $contexte, |
|
| 331 | - $use_cache, |
|
| 332 | - $chemin_cache, |
|
| 333 | - $contexte_cache, |
|
| 334 | - &$page, |
|
| 335 | - &$lastinclude, |
|
| 336 | - $connect = '' |
|
| 329 | + $fond, |
|
| 330 | + $contexte, |
|
| 331 | + $use_cache, |
|
| 332 | + $chemin_cache, |
|
| 333 | + $contexte_cache, |
|
| 334 | + &$page, |
|
| 335 | + &$lastinclude, |
|
| 336 | + $connect = '' |
|
| 337 | 337 | ) { |
| 338 | - static $parametrer, $cacher; |
|
| 339 | - if (!$parametrer) { |
|
| 340 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 341 | - } |
|
| 342 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 343 | - // et on l'enregistre sur le disque |
|
| 344 | - if ( |
|
| 345 | - $chemin_cache |
|
| 346 | - && $use_cache > -1 |
|
| 347 | - && is_array($page) |
|
| 348 | - && count($page) |
|
| 349 | - && isset($page['entetes']['X-Spip-Cache']) |
|
| 350 | - && $page['entetes']['X-Spip-Cache'] > 0 |
|
| 351 | - ) { |
|
| 352 | - if (is_null($cacher)) { |
|
| 353 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 354 | - } |
|
| 355 | - $lastinclude = time(); |
|
| 356 | - if ($cacher) { |
|
| 357 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 358 | - } else { |
|
| 359 | - $use_cache = -1; |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $page; |
|
| 338 | + static $parametrer, $cacher; |
|
| 339 | + if (!$parametrer) { |
|
| 340 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 341 | + } |
|
| 342 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 343 | + // et on l'enregistre sur le disque |
|
| 344 | + if ( |
|
| 345 | + $chemin_cache |
|
| 346 | + && $use_cache > -1 |
|
| 347 | + && is_array($page) |
|
| 348 | + && count($page) |
|
| 349 | + && isset($page['entetes']['X-Spip-Cache']) |
|
| 350 | + && $page['entetes']['X-Spip-Cache'] > 0 |
|
| 351 | + ) { |
|
| 352 | + if (is_null($cacher)) { |
|
| 353 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 354 | + } |
|
| 355 | + $lastinclude = time(); |
|
| 356 | + if ($cacher) { |
|
| 357 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 358 | + } else { |
|
| 359 | + $use_cache = -1; |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $page; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // Fonction inseree par le compilateur dans le code compile. |
@@ -374,14 +374,14 @@ discard block |
||
| 374 | 374 | // 4: langue |
| 375 | 375 | |
| 376 | 376 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 377 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 378 | - |
|
| 379 | - if (!is_array($contexte_exec)) { |
|
| 380 | - echo $contexte_exec; |
|
| 381 | - } // message d'erreur etc |
|
| 382 | - else { |
|
| 383 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 384 | - } |
|
| 377 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 378 | + |
|
| 379 | + if (!is_array($contexte_exec)) { |
|
| 380 | + echo $contexte_exec; |
|
| 381 | + } // message d'erreur etc |
|
| 382 | + else { |
|
| 383 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 384 | + } |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -394,101 +394,101 @@ discard block |
||
| 394 | 394 | * @return string|void |
| 395 | 395 | */ |
| 396 | 396 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 397 | - if (is_array($texte)) { |
|
| 398 | - [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 399 | - |
|
| 400 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | - $d = $GLOBALS['delais'] ?? null; |
|
| 402 | - $GLOBALS['delais'] = $delainc; |
|
| 403 | - |
|
| 404 | - $page = recuperer_fond( |
|
| 405 | - $fond, |
|
| 406 | - $contexte_inclus, |
|
| 407 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | - ); |
|
| 409 | - |
|
| 410 | - $texte = $page['texte']; |
|
| 411 | - |
|
| 412 | - $GLOBALS['delais'] = $d; |
|
| 413 | - // Faire remonter les entetes |
|
| 414 | - if ( |
|
| 415 | - isset($page['entetes']) |
|
| 416 | - && is_array($page['entetes']) |
|
| 417 | - ) { |
|
| 418 | - // mais pas toutes |
|
| 419 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 420 | - unset($page['entetes']['Content-Type']); |
|
| 421 | - if (isset($GLOBALS['page']) && is_array($GLOBALS['page'])) { |
|
| 422 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 423 | - $GLOBALS['page']['entetes'] = []; |
|
| 424 | - } |
|
| 425 | - $GLOBALS['page']['entetes'] = |
|
| 426 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 430 | - if ( |
|
| 431 | - isset($page['contexte']['_pipelines']) |
|
| 432 | - && is_array($page['contexte']['_pipelines']) |
|
| 433 | - && count($page['contexte']['_pipelines']) |
|
| 434 | - ) { |
|
| 435 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 436 | - $args['contexte'] = $page['contexte']; |
|
| 437 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 438 | - $texte = pipeline( |
|
| 439 | - $pipe, |
|
| 440 | - [ |
|
| 441 | - 'data' => $texte, |
|
| 442 | - 'args' => $args |
|
| 443 | - ] |
|
| 444 | - ); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 450 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 451 | - $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 452 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 453 | - } |
|
| 454 | - if ($echo) { |
|
| 455 | - echo $texte; |
|
| 456 | - } else { |
|
| 457 | - return $texte; |
|
| 458 | - } |
|
| 397 | + if (is_array($texte)) { |
|
| 398 | + [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 399 | + |
|
| 400 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | + $d = $GLOBALS['delais'] ?? null; |
|
| 402 | + $GLOBALS['delais'] = $delainc; |
|
| 403 | + |
|
| 404 | + $page = recuperer_fond( |
|
| 405 | + $fond, |
|
| 406 | + $contexte_inclus, |
|
| 407 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | + ); |
|
| 409 | + |
|
| 410 | + $texte = $page['texte']; |
|
| 411 | + |
|
| 412 | + $GLOBALS['delais'] = $d; |
|
| 413 | + // Faire remonter les entetes |
|
| 414 | + if ( |
|
| 415 | + isset($page['entetes']) |
|
| 416 | + && is_array($page['entetes']) |
|
| 417 | + ) { |
|
| 418 | + // mais pas toutes |
|
| 419 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 420 | + unset($page['entetes']['Content-Type']); |
|
| 421 | + if (isset($GLOBALS['page']) && is_array($GLOBALS['page'])) { |
|
| 422 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 423 | + $GLOBALS['page']['entetes'] = []; |
|
| 424 | + } |
|
| 425 | + $GLOBALS['page']['entetes'] = |
|
| 426 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 430 | + if ( |
|
| 431 | + isset($page['contexte']['_pipelines']) |
|
| 432 | + && is_array($page['contexte']['_pipelines']) |
|
| 433 | + && count($page['contexte']['_pipelines']) |
|
| 434 | + ) { |
|
| 435 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 436 | + $args['contexte'] = $page['contexte']; |
|
| 437 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 438 | + $texte = pipeline( |
|
| 439 | + $pipe, |
|
| 440 | + [ |
|
| 441 | + 'data' => $texte, |
|
| 442 | + 'args' => $args |
|
| 443 | + ] |
|
| 444 | + ); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 450 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 451 | + $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 452 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 453 | + } |
|
| 454 | + if ($echo) { |
|
| 455 | + echo $texte; |
|
| 456 | + } else { |
|
| 457 | + return $texte; |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | function message_page_indisponible($page, $contexte) { |
| 462 | - static $deja = false; |
|
| 463 | - if ($deja) { |
|
| 464 | - return 'erreur'; |
|
| 465 | - } |
|
| 466 | - $codes = [ |
|
| 467 | - '404' => '404 Not Found', |
|
| 468 | - '503' => '503 Service Unavailable', |
|
| 469 | - ]; |
|
| 470 | - |
|
| 471 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 472 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 473 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 474 | - if (!isset($contexte['lang'])) { |
|
| 475 | - include_spip('inc/lang'); |
|
| 476 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $deja = true; |
|
| 480 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 481 | - // ex restriction d'acces => 401 |
|
| 482 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 483 | - |
|
| 484 | - // produire la page d'erreur |
|
| 485 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 486 | - if (!$page) { |
|
| 487 | - $page = inclure_page('404', $contexte); |
|
| 488 | - } |
|
| 489 | - $page['status'] = $contexte['status']; |
|
| 490 | - |
|
| 491 | - return $page; |
|
| 462 | + static $deja = false; |
|
| 463 | + if ($deja) { |
|
| 464 | + return 'erreur'; |
|
| 465 | + } |
|
| 466 | + $codes = [ |
|
| 467 | + '404' => '404 Not Found', |
|
| 468 | + '503' => '503 Service Unavailable', |
|
| 469 | + ]; |
|
| 470 | + |
|
| 471 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 472 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 473 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 474 | + if (!isset($contexte['lang'])) { |
|
| 475 | + include_spip('inc/lang'); |
|
| 476 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $deja = true; |
|
| 480 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 481 | + // ex restriction d'acces => 401 |
|
| 482 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 483 | + |
|
| 484 | + // produire la page d'erreur |
|
| 485 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 486 | + if (!$page) { |
|
| 487 | + $page = inclure_page('404', $contexte); |
|
| 488 | + } |
|
| 489 | + $page['status'] = $contexte['status']; |
|
| 490 | + |
|
| 491 | + return $page; |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /** |
@@ -500,44 +500,44 @@ discard block |
||
| 500 | 500 | * @return mixed |
| 501 | 501 | */ |
| 502 | 502 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 503 | - static $balise_dyn_appellee_par_modele = null; |
|
| 504 | - switch ($operation) { |
|
| 505 | - case 'read': |
|
| 506 | - return $balise_dyn_appellee_par_modele; |
|
| 507 | - case 'reset': |
|
| 508 | - $balise_dyn_appellee_par_modele = null; |
|
| 509 | - return null; |
|
| 510 | - case 'set': |
|
| 511 | - default: |
|
| 512 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 513 | - return $arg; |
|
| 514 | - } |
|
| 503 | + static $balise_dyn_appellee_par_modele = null; |
|
| 504 | + switch ($operation) { |
|
| 505 | + case 'read': |
|
| 506 | + return $balise_dyn_appellee_par_modele; |
|
| 507 | + case 'reset': |
|
| 508 | + $balise_dyn_appellee_par_modele = null; |
|
| 509 | + return null; |
|
| 510 | + case 'set': |
|
| 511 | + default: |
|
| 512 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 513 | + return $arg; |
|
| 514 | + } |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | // temporairement ici : a mettre dans le futur inc/modeles |
| 518 | 518 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 519 | 519 | function creer_contexte_de_modele($args) { |
| 520 | - $contexte = []; |
|
| 521 | - foreach ($args as $var => $val) { |
|
| 522 | - if (is_int($var)) { // argument pas formate |
|
| 523 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | - $var = 'align'; |
|
| 525 | - $contexte[$var] = $val; |
|
| 526 | - } else { |
|
| 527 | - $args = explode('=', $val); |
|
| 528 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | - } else // notation abregee |
|
| 531 | - { |
|
| 532 | - $contexte[trim($val)] = trim($val); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } else { |
|
| 536 | - $contexte[$var] = $val; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $contexte; |
|
| 520 | + $contexte = []; |
|
| 521 | + foreach ($args as $var => $val) { |
|
| 522 | + if (is_int($var)) { // argument pas formate |
|
| 523 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | + $var = 'align'; |
|
| 525 | + $contexte[$var] = $val; |
|
| 526 | + } else { |
|
| 527 | + $args = explode('=', $val); |
|
| 528 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | + } else // notation abregee |
|
| 531 | + { |
|
| 532 | + $contexte[trim($val)] = trim($val); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } else { |
|
| 536 | + $contexte[$var] = $val; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $contexte; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -552,45 +552,45 @@ discard block |
||
| 552 | 552 | * @return string |
| 553 | 553 | */ |
| 554 | 554 | function styliser_modele($modele, $id, $contexte = null) { |
| 555 | - static $styliseurs = null; |
|
| 556 | - if (is_null($styliseurs)) { |
|
| 557 | - $tables_objet = lister_tables_objets_sql(); |
|
| 558 | - foreach ($tables_objet as $table => $desc) { |
|
| 559 | - if ( |
|
| 560 | - isset($desc['modeles']) |
|
| 561 | - && $desc['modeles'] |
|
| 562 | - && isset($desc['modeles_styliser']) |
|
| 563 | - && $desc['modeles_styliser'] |
|
| 564 | - && function_exists($desc['modeles_styliser']) |
|
| 565 | - ) { |
|
| 566 | - $primary = id_table_objet($table); |
|
| 567 | - foreach ($desc['modeles'] as $m) { |
|
| 568 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - if (isset($styliseurs[$modele])) { |
|
| 575 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 576 | - $primary = $styliseurs[$modele]['primary']; |
|
| 577 | - if (is_null($id) && $contexte) { |
|
| 578 | - if (isset($contexte['id'])) { |
|
| 579 | - $id = $contexte['id']; |
|
| 580 | - } elseif (isset($contexte[$primary])) { |
|
| 581 | - $id = $contexte[$primary]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - if (is_null($id)) { |
|
| 585 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 586 | - erreur_squelette($msg); |
|
| 587 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 588 | - $id = 0; |
|
| 589 | - } |
|
| 590 | - $modele = $styliseur($modele, $id); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return $modele; |
|
| 555 | + static $styliseurs = null; |
|
| 556 | + if (is_null($styliseurs)) { |
|
| 557 | + $tables_objet = lister_tables_objets_sql(); |
|
| 558 | + foreach ($tables_objet as $table => $desc) { |
|
| 559 | + if ( |
|
| 560 | + isset($desc['modeles']) |
|
| 561 | + && $desc['modeles'] |
|
| 562 | + && isset($desc['modeles_styliser']) |
|
| 563 | + && $desc['modeles_styliser'] |
|
| 564 | + && function_exists($desc['modeles_styliser']) |
|
| 565 | + ) { |
|
| 566 | + $primary = id_table_objet($table); |
|
| 567 | + foreach ($desc['modeles'] as $m) { |
|
| 568 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + if (isset($styliseurs[$modele])) { |
|
| 575 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 576 | + $primary = $styliseurs[$modele]['primary']; |
|
| 577 | + if (is_null($id) && $contexte) { |
|
| 578 | + if (isset($contexte['id'])) { |
|
| 579 | + $id = $contexte['id']; |
|
| 580 | + } elseif (isset($contexte[$primary])) { |
|
| 581 | + $id = $contexte[$primary]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + if (is_null($id)) { |
|
| 585 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 586 | + erreur_squelette($msg); |
|
| 587 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 588 | + $id = 0; |
|
| 589 | + } |
|
| 590 | + $modele = $styliseur($modele, $id); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return $modele; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -605,102 +605,102 @@ discard block |
||
| 605 | 605 | */ |
| 606 | 606 | function inclure_modele($type, $id, $params, $lien, string $connect = '', $env = []) { |
| 607 | 607 | |
| 608 | - static $compteur; |
|
| 609 | - if (++$compteur > 10) { |
|
| 610 | - return ''; |
|
| 611 | - } # ne pas boucler indefiniment |
|
| 612 | - |
|
| 613 | - $type = strtolower($type); |
|
| 614 | - $type = styliser_modele($type, $id); |
|
| 615 | - |
|
| 616 | - $fond = $class = ''; |
|
| 617 | - |
|
| 618 | - $params = array_filter(explode('|', $params)); |
|
| 619 | - if ($params) { |
|
| 620 | - $soustype = current($params); |
|
| 621 | - $soustype = strtolower(trim($soustype)); |
|
| 622 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 623 | - $soustype = next($params); |
|
| 624 | - $soustype = strtolower($soustype); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 628 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 629 | - $fond = ''; |
|
| 630 | - $class = $soustype; |
|
| 631 | - } |
|
| 632 | - // enlever le sous type des params |
|
| 633 | - $params = array_diff($params, [$soustype]); |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 638 | - if (!$fond && !trouve_modele($fond = $type)) { |
|
| 639 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 640 | - $compteur--; |
|
| 641 | - return false; |
|
| 642 | - } |
|
| 643 | - $fond = 'modeles/' . $fond; |
|
| 644 | - // Creer le contexte |
|
| 645 | - $contexte = $env; |
|
| 646 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 647 | - |
|
| 648 | - // Le numero du modele est mis dans l'environnement |
|
| 649 | - // d'une part sous l'identifiant "id" |
|
| 650 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 651 | - // par la fonction id_table_objet, |
|
| 652 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 653 | - $_id = id_table_objet($type); |
|
| 654 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 655 | - |
|
| 656 | - if (isset($class)) { |
|
| 657 | - $contexte['class'] = $class; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 661 | - if ($lien) { |
|
| 662 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 663 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 664 | - $contexte['lien_class'] = $lien['class']; |
|
| 665 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 666 | - $contexte['lien_title'] = $lien['title']; |
|
| 667 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - // Traiter les parametres |
|
| 671 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 672 | - $arg_list = creer_contexte_de_modele($params); |
|
| 673 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 674 | - $contexte = array_merge($contexte, $arg_list); |
|
| 675 | - |
|
| 676 | - // Appliquer le modele avec le contexte |
|
| 677 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 678 | - |
|
| 679 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 680 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 681 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 682 | - if ( |
|
| 683 | - strstr( |
|
| 684 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 685 | - 'spip_lien_ok' |
|
| 686 | - ) |
|
| 687 | - ) { |
|
| 688 | - $retour = inserer_attribut( |
|
| 689 | - $retour, |
|
| 690 | - 'class', |
|
| 691 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 692 | - ); |
|
| 693 | - } else { |
|
| 694 | - if ($lien) { |
|
| 695 | - $retour = '<a href="' . $lien['href'] . '" class="' . $lien['class'] . '">' . $retour . '</a>'; |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - $compteur--; |
|
| 700 | - |
|
| 701 | - return (isset($arg_list['ajax']) && $arg_list['ajax'] == 'ajax') |
|
| 702 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 703 | - : $retour; |
|
| 608 | + static $compteur; |
|
| 609 | + if (++$compteur > 10) { |
|
| 610 | + return ''; |
|
| 611 | + } # ne pas boucler indefiniment |
|
| 612 | + |
|
| 613 | + $type = strtolower($type); |
|
| 614 | + $type = styliser_modele($type, $id); |
|
| 615 | + |
|
| 616 | + $fond = $class = ''; |
|
| 617 | + |
|
| 618 | + $params = array_filter(explode('|', $params)); |
|
| 619 | + if ($params) { |
|
| 620 | + $soustype = current($params); |
|
| 621 | + $soustype = strtolower(trim($soustype)); |
|
| 622 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 623 | + $soustype = next($params); |
|
| 624 | + $soustype = strtolower($soustype); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 628 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 629 | + $fond = ''; |
|
| 630 | + $class = $soustype; |
|
| 631 | + } |
|
| 632 | + // enlever le sous type des params |
|
| 633 | + $params = array_diff($params, [$soustype]); |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 638 | + if (!$fond && !trouve_modele($fond = $type)) { |
|
| 639 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 640 | + $compteur--; |
|
| 641 | + return false; |
|
| 642 | + } |
|
| 643 | + $fond = 'modeles/' . $fond; |
|
| 644 | + // Creer le contexte |
|
| 645 | + $contexte = $env; |
|
| 646 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 647 | + |
|
| 648 | + // Le numero du modele est mis dans l'environnement |
|
| 649 | + // d'une part sous l'identifiant "id" |
|
| 650 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 651 | + // par la fonction id_table_objet, |
|
| 652 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 653 | + $_id = id_table_objet($type); |
|
| 654 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 655 | + |
|
| 656 | + if (isset($class)) { |
|
| 657 | + $contexte['class'] = $class; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 661 | + if ($lien) { |
|
| 662 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 663 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 664 | + $contexte['lien_class'] = $lien['class']; |
|
| 665 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 666 | + $contexte['lien_title'] = $lien['title']; |
|
| 667 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + // Traiter les parametres |
|
| 671 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 672 | + $arg_list = creer_contexte_de_modele($params); |
|
| 673 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 674 | + $contexte = array_merge($contexte, $arg_list); |
|
| 675 | + |
|
| 676 | + // Appliquer le modele avec le contexte |
|
| 677 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 678 | + |
|
| 679 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 680 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 681 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 682 | + if ( |
|
| 683 | + strstr( |
|
| 684 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 685 | + 'spip_lien_ok' |
|
| 686 | + ) |
|
| 687 | + ) { |
|
| 688 | + $retour = inserer_attribut( |
|
| 689 | + $retour, |
|
| 690 | + 'class', |
|
| 691 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 692 | + ); |
|
| 693 | + } else { |
|
| 694 | + if ($lien) { |
|
| 695 | + $retour = '<a href="' . $lien['href'] . '" class="' . $lien['class'] . '">' . $retour . '</a>'; |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + $compteur--; |
|
| 700 | + |
|
| 701 | + return (isset($arg_list['ajax']) && $arg_list['ajax'] == 'ajax') |
|
| 702 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 703 | + : $retour; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -709,99 +709,99 @@ discard block |
||
| 709 | 709 | // recuperer_fond($fond,$contexte,array('raw'=>true)) |
| 710 | 710 | function evaluer_fond($fond, $contexte = [], string $connect = '') { |
| 711 | 711 | |
| 712 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 713 | - |
|
| 714 | - if (!$page) { |
|
| 715 | - return $page; |
|
| 716 | - } |
|
| 717 | - // eval $page et affecte $res |
|
| 718 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 719 | - |
|
| 720 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 721 | - // a destination de public/parametrer |
|
| 722 | - // pour remonter vers les inclusions appelantes |
|
| 723 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 724 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 725 | - if ( |
|
| 726 | - isset($page['invalideurs']) |
|
| 727 | - && isset($page['invalideurs']['session']) |
|
| 728 | - ) { |
|
| 729 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - return $page; |
|
| 712 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 713 | + |
|
| 714 | + if (!$page) { |
|
| 715 | + return $page; |
|
| 716 | + } |
|
| 717 | + // eval $page et affecte $res |
|
| 718 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 719 | + |
|
| 720 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 721 | + // a destination de public/parametrer |
|
| 722 | + // pour remonter vers les inclusions appelantes |
|
| 723 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 724 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 725 | + if ( |
|
| 726 | + isset($page['invalideurs']) |
|
| 727 | + && isset($page['invalideurs']['session']) |
|
| 728 | + ) { |
|
| 729 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + return $page; |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | |
| 736 | 736 | function page_base_href(&$texte) { |
| 737 | - static $set_html_base = null; |
|
| 738 | - if (is_null($set_html_base)) { |
|
| 739 | - if (!defined('_SET_HTML_BASE')) { |
|
| 740 | - // si la profondeur est superieure a 1 |
|
| 741 | - // est que ce n'est pas une url page ni une url action |
|
| 742 | - // activer par defaut |
|
| 743 | - $set_html_base = |
|
| 744 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 745 | - && _request(_SPIP_PAGE) !== 'login' |
|
| 746 | - && !_request('action'); |
|
| 747 | - } else { |
|
| 748 | - $set_html_base = _SET_HTML_BASE; |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - if ( |
|
| 753 | - $set_html_base |
|
| 754 | - && isset($GLOBALS['html']) |
|
| 755 | - && $GLOBALS['html'] |
|
| 756 | - && $GLOBALS['profondeur_url'] > 0 |
|
| 757 | - && ($poshead = strpos($texte, '</head>')) !== false |
|
| 758 | - ) { |
|
| 759 | - $head = substr($texte, 0, $poshead); |
|
| 760 | - $insert = false; |
|
| 761 | - $href_base = false; |
|
| 762 | - if (!str_contains($head, '<base')) { |
|
| 763 | - $insert = true; |
|
| 764 | - } else { |
|
| 765 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 766 | - // sinon juste re-ecrire les ancres si besoin |
|
| 767 | - $insert = true; |
|
| 768 | - include_spip('inc/filtres'); |
|
| 769 | - $bases = extraire_balises($head, 'base'); |
|
| 770 | - foreach ($bases as $base) { |
|
| 771 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 772 | - $insert = false; |
|
| 773 | - break; |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - if ($insert) { |
|
| 779 | - include_spip('inc/filtres_mini'); |
|
| 780 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 781 | - $href_base = url_absolue('./'); |
|
| 782 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 783 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 784 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 785 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 786 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 787 | - } |
|
| 788 | - $texte = $head . substr($texte, $poshead); |
|
| 789 | - } |
|
| 790 | - if ($href_base) { |
|
| 791 | - // gerer les ancres |
|
| 792 | - $base = $_SERVER['REQUEST_URI']; |
|
| 793 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 794 | - if (str_contains($base, "'") || str_contains($base, '"') || str_contains($base, '<')) { |
|
| 795 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 796 | - } |
|
| 797 | - if (str_contains($texte, "href='#")) { |
|
| 798 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 799 | - } |
|
| 800 | - if (str_contains($texte, 'href="#')) { |
|
| 801 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - } |
|
| 737 | + static $set_html_base = null; |
|
| 738 | + if (is_null($set_html_base)) { |
|
| 739 | + if (!defined('_SET_HTML_BASE')) { |
|
| 740 | + // si la profondeur est superieure a 1 |
|
| 741 | + // est que ce n'est pas une url page ni une url action |
|
| 742 | + // activer par defaut |
|
| 743 | + $set_html_base = |
|
| 744 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 745 | + && _request(_SPIP_PAGE) !== 'login' |
|
| 746 | + && !_request('action'); |
|
| 747 | + } else { |
|
| 748 | + $set_html_base = _SET_HTML_BASE; |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + if ( |
|
| 753 | + $set_html_base |
|
| 754 | + && isset($GLOBALS['html']) |
|
| 755 | + && $GLOBALS['html'] |
|
| 756 | + && $GLOBALS['profondeur_url'] > 0 |
|
| 757 | + && ($poshead = strpos($texte, '</head>')) !== false |
|
| 758 | + ) { |
|
| 759 | + $head = substr($texte, 0, $poshead); |
|
| 760 | + $insert = false; |
|
| 761 | + $href_base = false; |
|
| 762 | + if (!str_contains($head, '<base')) { |
|
| 763 | + $insert = true; |
|
| 764 | + } else { |
|
| 765 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 766 | + // sinon juste re-ecrire les ancres si besoin |
|
| 767 | + $insert = true; |
|
| 768 | + include_spip('inc/filtres'); |
|
| 769 | + $bases = extraire_balises($head, 'base'); |
|
| 770 | + foreach ($bases as $base) { |
|
| 771 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 772 | + $insert = false; |
|
| 773 | + break; |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + if ($insert) { |
|
| 779 | + include_spip('inc/filtres_mini'); |
|
| 780 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 781 | + $href_base = url_absolue('./'); |
|
| 782 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 783 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 784 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 785 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 786 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 787 | + } |
|
| 788 | + $texte = $head . substr($texte, $poshead); |
|
| 789 | + } |
|
| 790 | + if ($href_base) { |
|
| 791 | + // gerer les ancres |
|
| 792 | + $base = $_SERVER['REQUEST_URI']; |
|
| 793 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 794 | + if (str_contains($base, "'") || str_contains($base, '"') || str_contains($base, '<')) { |
|
| 795 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 796 | + } |
|
| 797 | + if (str_contains($texte, "href='#")) { |
|
| 798 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 799 | + } |
|
| 800 | + if (str_contains($texte, 'href="#')) { |
|
| 801 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | * Ceux spécifiques à SPIP commencent par X-Spip |
| 812 | 812 | */ |
| 813 | 813 | function envoyer_entetes($entetes) { |
| 814 | - foreach ($entetes as $k => $v) { |
|
| 815 | - @header(strlen((string) $v) ? "$k: $v" : $k); |
|
| 816 | - } |
|
| 814 | + foreach ($entetes as $k => $v) { |
|
| 815 | + @header(strlen((string) $v) ? "$k: $v" : $k); |
|
| 816 | + } |
|
| 817 | 817 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | $GLOBALS['contexte'] = calculer_contexte(); |
| 35 | 35 | $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
| 36 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 36 | + $page['contexte_implicite']['cache'] = $fond.preg_replace( |
|
| 37 | 37 | ',\.[a-zA-Z0-9]*$,', |
| 38 | 38 | '', |
| 39 | 39 | preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | if ($page === '') { |
| 134 | 134 | $erreur = _T( |
| 135 | 135 | 'info_erreur_squelette2', |
| 136 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 136 | + ['fichier' => spip_htmlspecialchars($fond).'.'._EXTENSION_SQUELETTES] |
|
| 137 | 137 | ); |
| 138 | 138 | erreur_squelette($erreur); |
| 139 | 139 | // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | if ( |
| 175 | 175 | $lastmodified && !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !isset($page['entetes']['Last-Modified']) |
| 176 | 176 | ) { |
| 177 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 177 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified).' GMT'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // fermer la connexion apres les headers si requete HEAD |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) { |
| 207 | 207 | nettoyer_uri_var(''); |
| 208 | 208 | } |
| 209 | - $preg_ignore_variables = '/(' . implode('|',_CONTEXTE_IGNORE_LISTE_VARIABLES) . ')/'; |
|
| 209 | + $preg_ignore_variables = '/('.implode('|', _CONTEXTE_IGNORE_LISTE_VARIABLES).')/'; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $contexte = []; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | 'spip_version_code' => $GLOBALS['spip_version_code'], |
| 248 | 248 | ]; |
| 249 | 249 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 250 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | + $contexte_implicite['host'] .= '|'.$_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return $contexte_implicite; |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | } |
| 583 | 583 | } |
| 584 | 584 | if (is_null($id)) { |
| 585 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 585 | + $msg = "modeles/$modele : "._T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 586 | 586 | erreur_squelette($msg); |
| 587 | 587 | // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
| 588 | 588 | $id = 0; |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
| 628 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 628 | + if (!trouve_modele($fond = ($type.'_'.$soustype))) { |
|
| 629 | 629 | $fond = ''; |
| 630 | 630 | $class = $soustype; |
| 631 | 631 | } |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | $compteur--; |
| 641 | 641 | return false; |
| 642 | 642 | } |
| 643 | - $fond = 'modeles/' . $fond; |
|
| 643 | + $fond = 'modeles/'.$fond; |
|
| 644 | 644 | // Creer le contexte |
| 645 | 645 | $contexte = $env; |
| 646 | 646 | $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | // sinon, s'il y a un lien, on l'ajoute classiquement |
| 682 | 682 | if ( |
| 683 | 683 | strstr( |
| 684 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 684 | + ' '.($classes = extraire_attribut($retour, 'class')).' ', |
|
| 685 | 685 | 'spip_lien_ok' |
| 686 | 686 | ) |
| 687 | 687 | ) { |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | ); |
| 693 | 693 | } else { |
| 694 | 694 | if ($lien) { |
| 695 | - $retour = '<a href="' . $lien['href'] . '" class="' . $lien['class'] . '">' . $retour . '</a>'; |
|
| 695 | + $retour = '<a href="'.$lien['href'].'" class="'.$lien['class'].'">'.$retour.'</a>'; |
|
| 696 | 696 | } |
| 697 | 697 | } |
| 698 | 698 | |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | return $page; |
| 716 | 716 | } |
| 717 | 717 | // eval $page et affecte $res |
| 718 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 718 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 719 | 719 | |
| 720 | 720 | // Lever un drapeau (global) si le fond utilise #SESSION |
| 721 | 721 | // a destination de public/parametrer |
@@ -783,16 +783,16 @@ discard block |
||
| 783 | 783 | if (($pos = strpos($head, '<head>')) !== false) { |
| 784 | 784 | $head = substr_replace($head, $base, $pos + 6, 0); |
| 785 | 785 | } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
| 786 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 786 | + $head = str_replace($r[0], $r[0].$base, $head); |
|
| 787 | 787 | } |
| 788 | - $texte = $head . substr($texte, $poshead); |
|
| 788 | + $texte = $head.substr($texte, $poshead); |
|
| 789 | 789 | } |
| 790 | 790 | if ($href_base) { |
| 791 | 791 | // gerer les ancres |
| 792 | 792 | $base = $_SERVER['REQUEST_URI']; |
| 793 | 793 | // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
| 794 | 794 | if (str_contains($base, "'") || str_contains($base, '"') || str_contains($base, '<')) { |
| 795 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 795 | + $base = str_replace(["'", '"', '<'], ['%27', '%22', '%3C'], $base); |
|
| 796 | 796 | } |
| 797 | 797 | if (str_contains($texte, "href='#")) { |
| 798 | 798 | $texte = str_replace("href='#", "href='$base#", $texte); |