@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/charsets'); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * @return string Fonction PHP correspondante du filtre |
| 42 | 42 | */ |
| 43 | 43 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 44 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | - return chercher_filtre($fonc, $default); |
|
| 44 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | + return chercher_filtre($fonc, $default); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string texte |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_identite_dist($texte) { |
| 55 | - return $texte; |
|
| 55 | + return $texte; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -76,33 +76,33 @@ discard block |
||
| 76 | 76 | * Fonction PHP correspondante du filtre demandé |
| 77 | 77 | */ |
| 78 | 78 | function chercher_filtre($fonc, $default = null) { |
| 79 | - if (!$fonc) { |
|
| 80 | - return $default; |
|
| 81 | - } |
|
| 82 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | - // Foo::Bar |
|
| 84 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | - $f = chercher_filtre($nom); |
|
| 88 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | - if (!$f and $nom !== $fonc) { |
|
| 91 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $f; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - include_fichiers_fonctions(); |
|
| 98 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | - if (is_callable($f)) { |
|
| 101 | - return $f; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $default; |
|
| 79 | + if (!$fonc) { |
|
| 80 | + return $default; |
|
| 81 | + } |
|
| 82 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | + // Foo::Bar |
|
| 84 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | + $f = chercher_filtre($nom); |
|
| 88 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | + if (!$f and $nom !== $fonc) { |
|
| 91 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $f; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + include_fichiers_fonctions(); |
|
| 98 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | + if (is_callable($f)) { |
|
| 101 | + return $f; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $default; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * Chaîne vide sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function appliquer_filtre($arg, $filtre) { |
| 149 | - $args = func_get_args(); |
|
| 150 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 149 | + $args = func_get_args(); |
|
| 150 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * texte d'origine sinon |
| 173 | 173 | **/ |
| 174 | 174 | function appliquer_si_filtre($arg, $filtre) { |
| 175 | - $args = func_get_args(); |
|
| 176 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 175 | + $args = func_get_args(); |
|
| 176 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | * Version de SPIP |
| 190 | 190 | **/ |
| 191 | 191 | function spip_version() { |
| 192 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | - $version .= " $vcs_version"; |
|
| 195 | - } |
|
| 192 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | + $version .= " $vcs_version"; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $version; |
|
| 197 | + return $version; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | 208 | function header_silencieux($version): string { |
| 209 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | - $version = ''; |
|
| 211 | - } |
|
| 209 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | + $version = ''; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - return (string) $version; |
|
| 213 | + return (string) $version; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | * - string|null si $raw = false |
| 224 | 224 | */ |
| 225 | 225 | function version_vcs_courante($dir, $raw = false) { |
| 226 | - $desc = decrire_version_git($dir); |
|
| 227 | - if ($desc === null or $raw) { |
|
| 228 | - return $desc; |
|
| 229 | - } |
|
| 230 | - // affichage "GIT [master: abcdef]" |
|
| 231 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | - if ($desc['branch']) { |
|
| 233 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | - } |
|
| 235 | - return "{$desc['vcs']} [$commit]"; |
|
| 226 | + $desc = decrire_version_git($dir); |
|
| 227 | + if ($desc === null or $raw) { |
|
| 228 | + return $desc; |
|
| 229 | + } |
|
| 230 | + // affichage "GIT [master: abcdef]" |
|
| 231 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | + if ($desc['branch']) { |
|
| 233 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | + } |
|
| 235 | + return "{$desc['vcs']} [$commit]"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,24 +244,24 @@ discard block |
||
| 244 | 244 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 245 | 245 | **/ |
| 246 | 246 | function decrire_version_git($dir) { |
| 247 | - if (!$dir) { |
|
| 248 | - $dir = '.'; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // version installee par GIT |
|
| 252 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 253 | - $currentHead = trim(substr($c, 4)); |
|
| 254 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 255 | - return [ |
|
| 256 | - 'vcs' => 'GIT', |
|
| 257 | - 'branch' => basename($currentHead), |
|
| 258 | - 'commit' => trim($hash), |
|
| 259 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 260 | - ]; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return null; |
|
| 247 | + if (!$dir) { |
|
| 248 | + $dir = '.'; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // version installee par GIT |
|
| 252 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 253 | + $currentHead = trim(substr($c, 4)); |
|
| 254 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 255 | + return [ |
|
| 256 | + 'vcs' => 'GIT', |
|
| 257 | + 'branch' => basename($currentHead), |
|
| 258 | + 'commit' => trim($hash), |
|
| 259 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 260 | + ]; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return null; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -308,18 +308,18 @@ discard block |
||
| 308 | 308 | * Code HTML retourné par le filtre |
| 309 | 309 | **/ |
| 310 | 310 | function filtrer($filtre) { |
| 311 | - $tous = func_get_args(); |
|
| 312 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 313 | - return image_filtrer($tous); |
|
| 314 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 315 | - array_shift($tous); |
|
| 316 | - return $f(...$tous); |
|
| 317 | - } else { |
|
| 318 | - // le filtre n'existe pas, on provoque une erreur |
|
| 319 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 320 | - erreur_squelette($msg); |
|
| 321 | - return ''; |
|
| 322 | - } |
|
| 311 | + $tous = func_get_args(); |
|
| 312 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 313 | + return image_filtrer($tous); |
|
| 314 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 315 | + array_shift($tous); |
|
| 316 | + return $f(...$tous); |
|
| 317 | + } else { |
|
| 318 | + // le filtre n'existe pas, on provoque une erreur |
|
| 319 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 320 | + erreur_squelette($msg); |
|
| 321 | + return ''; |
|
| 322 | + } |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -336,11 +336,11 @@ discard block |
||
| 336 | 336 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 337 | 337 | */ |
| 338 | 338 | function trouver_filtre_matrice($filtre) { |
| 339 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 340 | - find_in_path($f, '', true); |
|
| 341 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 342 | - } |
|
| 343 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 339 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 340 | + find_in_path($f, '', true); |
|
| 341 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 342 | + } |
|
| 343 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -368,8 +368,8 @@ discard block |
||
| 368 | 368 | * @return mixed |
| 369 | 369 | */ |
| 370 | 370 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 371 | - $Pile['vars'][$key] = $val; |
|
| 372 | - return $continue ? $val : ''; |
|
| 371 | + $Pile['vars'][$key] = $val; |
|
| 372 | + return $continue ? $val : ''; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 396 | 396 | */ |
| 397 | 397 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 398 | - $Pile[0][$key] = $val; |
|
| 399 | - return $continue ? $val : ''; |
|
| 398 | + $Pile[0][$key] = $val; |
|
| 399 | + return $continue ? $val : ''; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -405,8 +405,8 @@ discard block |
||
| 405 | 405 | * @return string |
| 406 | 406 | */ |
| 407 | 407 | function filtre_sanitize_env(&$Pile, $keys) { |
| 408 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 409 | - return ''; |
|
| 408 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 409 | + return ''; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -429,18 +429,18 @@ discard block |
||
| 429 | 429 | * @return mixed Retourne la valeur (sans la modifier). |
| 430 | 430 | */ |
| 431 | 431 | function filtre_debug($val, $key = null) { |
| 432 | - $debug = ( |
|
| 433 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 434 | - ) . var_export($val, true); |
|
| 432 | + $debug = ( |
|
| 433 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 434 | + ) . var_export($val, true); |
|
| 435 | 435 | |
| 436 | - include_spip('inc/autoriser'); |
|
| 437 | - if (autoriser('webmestre')) { |
|
| 438 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 439 | - } |
|
| 436 | + include_spip('inc/autoriser'); |
|
| 437 | + if (autoriser('webmestre')) { |
|
| 438 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - spip_log($debug, 'debug'); |
|
| 441 | + spip_log($debug, 'debug'); |
|
| 442 | 442 | |
| 443 | - return $val; |
|
| 443 | + return $val; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -470,84 +470,84 @@ discard block |
||
| 470 | 470 | * texte qui a reçu les filtres |
| 471 | 471 | **/ |
| 472 | 472 | function image_filtrer($args) { |
| 473 | - $filtre = array_shift($args); # enlever $filtre |
|
| 474 | - $texte = array_shift($args); |
|
| 475 | - if ($texte === null || !strlen($texte)) { |
|
| 476 | - return ''; |
|
| 477 | - } |
|
| 478 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 479 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 480 | - // Cas du nom de fichier local |
|
| 481 | - $is_file = trim($texte); |
|
| 482 | - if ( |
|
| 483 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 484 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 485 | - or strpos($is_file, '/') === 0 |
|
| 486 | - ) { |
|
| 487 | - $is_file = false; |
|
| 488 | - } |
|
| 489 | - if ($is_file) { |
|
| 490 | - $is_local_file = function ($path) { |
|
| 491 | - if (strpos($path, '?') !== false) { |
|
| 492 | - $path = supprimer_timestamp($path); |
|
| 493 | - // remove ?24px added by find_in_theme on .svg files |
|
| 494 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 495 | - } |
|
| 496 | - return file_exists($path); |
|
| 497 | - }; |
|
| 498 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 499 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 500 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 501 | - return $res; |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 506 | - if ( |
|
| 507 | - preg_match_all( |
|
| 508 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 509 | - $texte, |
|
| 510 | - $tags, |
|
| 511 | - PREG_SET_ORDER |
|
| 512 | - ) |
|
| 513 | - ) { |
|
| 514 | - foreach ($tags as $tag) { |
|
| 515 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 516 | - if ( |
|
| 517 | - !$class or |
|
| 518 | - (strpos($class, 'filtre_inactif') === false |
|
| 519 | - // compat historique a virer en 3.2 |
|
| 520 | - and !str_contains($class, 'no_image_filtrer')) |
|
| 521 | - ) { |
|
| 522 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 523 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 524 | - if ($tag[1]) { |
|
| 525 | - $w = extraire_attribut($reduit, 'width'); |
|
| 526 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 527 | - $w = $regs[1]; |
|
| 528 | - } |
|
| 529 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 530 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 531 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 532 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - // traiter aussi un eventuel mouseover |
|
| 536 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 537 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 538 | - $srcover = $match[1]; |
|
| 539 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 541 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 550 | - return $texte; |
|
| 473 | + $filtre = array_shift($args); # enlever $filtre |
|
| 474 | + $texte = array_shift($args); |
|
| 475 | + if ($texte === null || !strlen($texte)) { |
|
| 476 | + return ''; |
|
| 477 | + } |
|
| 478 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 479 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 480 | + // Cas du nom de fichier local |
|
| 481 | + $is_file = trim($texte); |
|
| 482 | + if ( |
|
| 483 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 484 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 485 | + or strpos($is_file, '/') === 0 |
|
| 486 | + ) { |
|
| 487 | + $is_file = false; |
|
| 488 | + } |
|
| 489 | + if ($is_file) { |
|
| 490 | + $is_local_file = function ($path) { |
|
| 491 | + if (strpos($path, '?') !== false) { |
|
| 492 | + $path = supprimer_timestamp($path); |
|
| 493 | + // remove ?24px added by find_in_theme on .svg files |
|
| 494 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 495 | + } |
|
| 496 | + return file_exists($path); |
|
| 497 | + }; |
|
| 498 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 499 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 500 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 501 | + return $res; |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 506 | + if ( |
|
| 507 | + preg_match_all( |
|
| 508 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 509 | + $texte, |
|
| 510 | + $tags, |
|
| 511 | + PREG_SET_ORDER |
|
| 512 | + ) |
|
| 513 | + ) { |
|
| 514 | + foreach ($tags as $tag) { |
|
| 515 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 516 | + if ( |
|
| 517 | + !$class or |
|
| 518 | + (strpos($class, 'filtre_inactif') === false |
|
| 519 | + // compat historique a virer en 3.2 |
|
| 520 | + and !str_contains($class, 'no_image_filtrer')) |
|
| 521 | + ) { |
|
| 522 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 523 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 524 | + if ($tag[1]) { |
|
| 525 | + $w = extraire_attribut($reduit, 'width'); |
|
| 526 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 527 | + $w = $regs[1]; |
|
| 528 | + } |
|
| 529 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 530 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 531 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 532 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + // traiter aussi un eventuel mouseover |
|
| 536 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 537 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 538 | + $srcover = $match[1]; |
|
| 539 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 541 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 550 | + return $texte; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -564,94 +564,94 @@ discard block |
||
| 564 | 564 | **/ |
| 565 | 565 | function infos_image($img, $force_refresh = false) { |
| 566 | 566 | |
| 567 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 568 | - $srcWidth = 0; |
|
| 569 | - $srcHeight = 0; |
|
| 570 | - $srcSize = null; |
|
| 571 | - |
|
| 572 | - $src = extraire_attribut($img, 'src'); |
|
| 573 | - |
|
| 574 | - if (!$src) { |
|
| 575 | - $src = $img; |
|
| 576 | - } else { |
|
| 577 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | - if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) { |
|
| 580 | - $srcWidth = $srcHeight = 0; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | - if (tester_url_absolue($src)) { |
|
| 587 | - include_spip('inc/distant'); |
|
| 588 | - $fichier = copie_locale($src); |
|
| 589 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | - } |
|
| 591 | - if (($p = strpos($src, '?')) !== false) { |
|
| 592 | - $src = substr($src, 0, $p); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $imagesize = false; |
|
| 596 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 597 | - $srcWidth = $largeur_img[$src]; |
|
| 598 | - } |
|
| 599 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 600 | - $srcHeight = $hauteur_img[$src]; |
|
| 601 | - } |
|
| 602 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 603 | - $srcSize = $poids_img[$src]; |
|
| 604 | - } |
|
| 605 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 606 | - if ( |
|
| 607 | - file_exists($src) |
|
| 608 | - and $imagesize = spip_getimagesize($src) |
|
| 609 | - ) { |
|
| 610 | - if (!$srcWidth) { |
|
| 611 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 612 | - } |
|
| 613 | - if (!$srcHeight) { |
|
| 614 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 615 | - } |
|
| 616 | - if (!$srcSize) { |
|
| 617 | - $poids_img[$src] = filesize($src); |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - elseif (strpos($src, '<svg') !== false) { |
|
| 621 | - include_spip('inc/svg'); |
|
| 622 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 623 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 624 | - if (!$srcWidth) { |
|
| 625 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 626 | - } |
|
| 627 | - if (!$srcHeight) { |
|
| 628 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 629 | - } |
|
| 630 | - if (!$srcSize) { |
|
| 631 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 636 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 637 | - elseif ( |
|
| 638 | - @file_exists($f = "$src.src") |
|
| 639 | - and lire_fichier($f, $valeurs) |
|
| 640 | - and $valeurs = unserialize($valeurs) |
|
| 641 | - ) { |
|
| 642 | - if (!$srcWidth) { |
|
| 643 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 644 | - } |
|
| 645 | - if (!$srcHeight) { |
|
| 646 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 647 | - } |
|
| 648 | - if (!$srcSize) { |
|
| 649 | - $poids_img[$src] = $srcSize = 0; |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 567 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 568 | + $srcWidth = 0; |
|
| 569 | + $srcHeight = 0; |
|
| 570 | + $srcSize = null; |
|
| 571 | + |
|
| 572 | + $src = extraire_attribut($img, 'src'); |
|
| 573 | + |
|
| 574 | + if (!$src) { |
|
| 575 | + $src = $img; |
|
| 576 | + } else { |
|
| 577 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | + if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) { |
|
| 580 | + $srcWidth = $srcHeight = 0; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | + if (tester_url_absolue($src)) { |
|
| 587 | + include_spip('inc/distant'); |
|
| 588 | + $fichier = copie_locale($src); |
|
| 589 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | + } |
|
| 591 | + if (($p = strpos($src, '?')) !== false) { |
|
| 592 | + $src = substr($src, 0, $p); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + $imagesize = false; |
|
| 596 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 597 | + $srcWidth = $largeur_img[$src]; |
|
| 598 | + } |
|
| 599 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 600 | + $srcHeight = $hauteur_img[$src]; |
|
| 601 | + } |
|
| 602 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 603 | + $srcSize = $poids_img[$src]; |
|
| 604 | + } |
|
| 605 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 606 | + if ( |
|
| 607 | + file_exists($src) |
|
| 608 | + and $imagesize = spip_getimagesize($src) |
|
| 609 | + ) { |
|
| 610 | + if (!$srcWidth) { |
|
| 611 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 612 | + } |
|
| 613 | + if (!$srcHeight) { |
|
| 614 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 615 | + } |
|
| 616 | + if (!$srcSize) { |
|
| 617 | + $poids_img[$src] = filesize($src); |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + elseif (strpos($src, '<svg') !== false) { |
|
| 621 | + include_spip('inc/svg'); |
|
| 622 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 623 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 624 | + if (!$srcWidth) { |
|
| 625 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 626 | + } |
|
| 627 | + if (!$srcHeight) { |
|
| 628 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 629 | + } |
|
| 630 | + if (!$srcSize) { |
|
| 631 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 636 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 637 | + elseif ( |
|
| 638 | + @file_exists($f = "$src.src") |
|
| 639 | + and lire_fichier($f, $valeurs) |
|
| 640 | + and $valeurs = unserialize($valeurs) |
|
| 641 | + ) { |
|
| 642 | + if (!$srcWidth) { |
|
| 643 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 644 | + } |
|
| 645 | + if (!$srcHeight) { |
|
| 646 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 647 | + } |
|
| 648 | + if (!$srcSize) { |
|
| 649 | + $poids_img[$src] = $srcSize = 0; |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | * poids |
| 668 | 668 | **/ |
| 669 | 669 | function poids_image($img, $force_refresh = false) { |
| 670 | - $infos = infos_image($img, $force_refresh); |
|
| 671 | - return $infos['poids']; |
|
| 670 | + $infos = infos_image($img, $force_refresh); |
|
| 671 | + return $infos['poids']; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function taille_image($img, $force_refresh = false) { |
| 675 | - $infos = infos_image($img, $force_refresh); |
|
| 676 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 675 | + $infos = infos_image($img, $force_refresh); |
|
| 676 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -690,12 +690,12 @@ discard block |
||
| 690 | 690 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 691 | 691 | **/ |
| 692 | 692 | function largeur($img) { |
| 693 | - if (!$img) { |
|
| 694 | - return; |
|
| 695 | - } |
|
| 696 | - [$h, $l] = taille_image($img); |
|
| 693 | + if (!$img) { |
|
| 694 | + return; |
|
| 695 | + } |
|
| 696 | + [$h, $l] = taille_image($img); |
|
| 697 | 697 | |
| 698 | - return $l; |
|
| 698 | + return $l; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | /** |
@@ -712,12 +712,12 @@ discard block |
||
| 712 | 712 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 713 | 713 | **/ |
| 714 | 714 | function hauteur($img) { |
| 715 | - if (!$img) { |
|
| 716 | - return; |
|
| 717 | - } |
|
| 718 | - [$h, $l] = taille_image($img); |
|
| 715 | + if (!$img) { |
|
| 716 | + return; |
|
| 717 | + } |
|
| 718 | + [$h, $l] = taille_image($img); |
|
| 719 | 719 | |
| 720 | - return $h; |
|
| 720 | + return $h; |
|
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | |
@@ -737,11 +737,11 @@ discard block |
||
| 737 | 737 | * @return string |
| 738 | 738 | **/ |
| 739 | 739 | function corriger_entites_html($texte) { |
| 740 | - if (strpos($texte, '&') === false) { |
|
| 741 | - return $texte; |
|
| 742 | - } |
|
| 740 | + if (strpos($texte, '&') === false) { |
|
| 741 | + return $texte; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 744 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -756,11 +756,11 @@ discard block |
||
| 756 | 756 | * @return string |
| 757 | 757 | **/ |
| 758 | 758 | function corriger_toutes_entites_html($texte) { |
| 759 | - if (strpos($texte, '&') === false) { |
|
| 760 | - return $texte; |
|
| 761 | - } |
|
| 759 | + if (strpos($texte, '&') === false) { |
|
| 760 | + return $texte; |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 763 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | /** |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | * @return string |
| 771 | 771 | **/ |
| 772 | 772 | function proteger_amp($texte) { |
| 773 | - return str_replace('&', '&', $texte); |
|
| 773 | + return str_replace('&', '&', $texte); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | |
@@ -801,21 +801,21 @@ discard block |
||
| 801 | 801 | * @return mixed|string |
| 802 | 802 | */ |
| 803 | 803 | function entites_html($texte, $tout = false, $quote = true) { |
| 804 | - if ( |
|
| 805 | - !is_string($texte) or !$texte |
|
| 806 | - or strpbrk($texte, "&\"'<>") == false |
|
| 807 | - ) { |
|
| 808 | - return $texte; |
|
| 809 | - } |
|
| 810 | - include_spip('inc/texte'); |
|
| 811 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 812 | - $flags |= ENT_HTML401; |
|
| 813 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 814 | - if ($tout) { |
|
| 815 | - return corriger_toutes_entites_html($texte); |
|
| 816 | - } else { |
|
| 817 | - return corriger_entites_html($texte); |
|
| 818 | - } |
|
| 804 | + if ( |
|
| 805 | + !is_string($texte) or !$texte |
|
| 806 | + or strpbrk($texte, "&\"'<>") == false |
|
| 807 | + ) { |
|
| 808 | + return $texte; |
|
| 809 | + } |
|
| 810 | + include_spip('inc/texte'); |
|
| 811 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 812 | + $flags |= ENT_HTML401; |
|
| 813 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 814 | + if ($tout) { |
|
| 815 | + return corriger_toutes_entites_html($texte); |
|
| 816 | + } else { |
|
| 817 | + return corriger_entites_html($texte); |
|
| 818 | + } |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | /** |
@@ -834,38 +834,38 @@ discard block |
||
| 834 | 834 | * texte converti |
| 835 | 835 | **/ |
| 836 | 836 | function filtrer_entites(?string $texte): string { |
| 837 | - $texte ??= ''; |
|
| 838 | - if (strpos($texte, '&') === false) { |
|
| 839 | - return $texte; |
|
| 840 | - } |
|
| 841 | - // filtrer |
|
| 842 | - $texte = html2unicode($texte); |
|
| 843 | - // remettre le tout dans le charset cible |
|
| 844 | - $texte = unicode2charset($texte); |
|
| 845 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 846 | - // (on le faisait deja avec un ") |
|
| 847 | - if (strpos($texte, '&#') !== false) { |
|
| 848 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 849 | - } |
|
| 837 | + $texte ??= ''; |
|
| 838 | + if (strpos($texte, '&') === false) { |
|
| 839 | + return $texte; |
|
| 840 | + } |
|
| 841 | + // filtrer |
|
| 842 | + $texte = html2unicode($texte); |
|
| 843 | + // remettre le tout dans le charset cible |
|
| 844 | + $texte = unicode2charset($texte); |
|
| 845 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 846 | + // (on le faisait deja avec un ") |
|
| 847 | + if (strpos($texte, '&#') !== false) { |
|
| 848 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 849 | + } |
|
| 850 | 850 | |
| 851 | - return $texte; |
|
| 851 | + return $texte; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | |
| 855 | 855 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 856 | - /** |
|
| 857 | - * Version sécurisée de filtrer_entites |
|
| 858 | - * |
|
| 859 | - * @uses interdire_scripts() |
|
| 860 | - * @uses filtrer_entites() |
|
| 861 | - * |
|
| 862 | - * @param string $t |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - function filtre_filtrer_entites_dist($t) { |
|
| 866 | - include_spip('inc/texte'); |
|
| 867 | - return interdire_scripts(filtrer_entites($t)); |
|
| 868 | - } |
|
| 856 | + /** |
|
| 857 | + * Version sécurisée de filtrer_entites |
|
| 858 | + * |
|
| 859 | + * @uses interdire_scripts() |
|
| 860 | + * @uses filtrer_entites() |
|
| 861 | + * |
|
| 862 | + * @param string $t |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + function filtre_filtrer_entites_dist($t) { |
|
| 866 | + include_spip('inc/texte'); |
|
| 867 | + return interdire_scripts(filtrer_entites($t)); |
|
| 868 | + } |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | |
@@ -880,18 +880,18 @@ discard block |
||
| 880 | 880 | * @return string|array |
| 881 | 881 | **/ |
| 882 | 882 | function supprimer_caracteres_illegaux($texte) { |
| 883 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 884 | - static $to = null; |
|
| 883 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 884 | + static $to = null; |
|
| 885 | 885 | |
| 886 | - if (is_array($texte)) { |
|
| 887 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 888 | - } |
|
| 886 | + if (is_array($texte)) { |
|
| 887 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - if (!$to) { |
|
| 891 | - $to = str_repeat('-', strlen($from)); |
|
| 892 | - } |
|
| 890 | + if (!$to) { |
|
| 891 | + $to = str_repeat('-', strlen($from)); |
|
| 892 | + } |
|
| 893 | 893 | |
| 894 | - return strtr($texte, $from, $to); |
|
| 894 | + return strtr($texte, $from, $to); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -903,10 +903,10 @@ discard block |
||
| 903 | 903 | * @return string|array |
| 904 | 904 | **/ |
| 905 | 905 | function corriger_caracteres($texte) { |
| 906 | - $texte = corriger_caracteres_windows($texte); |
|
| 907 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 906 | + $texte = corriger_caracteres_windows($texte); |
|
| 907 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 908 | 908 | |
| 909 | - return $texte; |
|
| 909 | + return $texte; |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
@@ -923,44 +923,44 @@ discard block |
||
| 923 | 923 | * texte encodé pour XML |
| 924 | 924 | */ |
| 925 | 925 | function texte_backend(string $texte): string { |
| 926 | - if ($texte === '') { |
|
| 927 | - return ''; |
|
| 928 | - } |
|
| 926 | + if ($texte === '') { |
|
| 927 | + return ''; |
|
| 928 | + } |
|
| 929 | 929 | |
| 930 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 930 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 931 | 931 | |
| 932 | - // si on a des liens ou des images, les passer en absolu |
|
| 933 | - $texte = liens_absolus($texte); |
|
| 932 | + // si on a des liens ou des images, les passer en absolu |
|
| 933 | + $texte = liens_absolus($texte); |
|
| 934 | 934 | |
| 935 | - // echapper les tags > < |
|
| 936 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 935 | + // echapper les tags > < |
|
| 936 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 937 | 937 | |
| 938 | - // importer les é |
|
| 939 | - $texte = filtrer_entites($texte); |
|
| 938 | + // importer les é |
|
| 939 | + $texte = filtrer_entites($texte); |
|
| 940 | 940 | |
| 941 | - // " -> " et tout ce genre de choses |
|
| 942 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 943 | - $texte = str_replace(' ', ' ', $texte); |
|
| 944 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 945 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 946 | - $texte = entites_html($texte, false, false); |
|
| 947 | - // mais bien echapper les double quotes ! |
|
| 948 | - $texte = str_replace('"', '"', $texte); |
|
| 941 | + // " -> " et tout ce genre de choses |
|
| 942 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 943 | + $texte = str_replace(' ', ' ', $texte); |
|
| 944 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 945 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 946 | + $texte = entites_html($texte, false, false); |
|
| 947 | + // mais bien echapper les double quotes ! |
|
| 948 | + $texte = str_replace('"', '"', $texte); |
|
| 949 | 949 | |
| 950 | - // verifier le charset |
|
| 951 | - $texte = charset2unicode($texte); |
|
| 950 | + // verifier le charset |
|
| 951 | + $texte = charset2unicode($texte); |
|
| 952 | 952 | |
| 953 | - // Caracteres problematiques en iso-latin 1 |
|
| 954 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 955 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 956 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 957 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 958 | - } |
|
| 953 | + // Caracteres problematiques en iso-latin 1 |
|
| 954 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 955 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 956 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 957 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 961 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 962 | - // ==> on les remplace par l'entite HTML |
|
| 963 | - return str_replace($apostrophe, "'", $texte); |
|
| 960 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 961 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 962 | + // ==> on les remplace par l'entite HTML |
|
| 963 | + return str_replace($apostrophe, "'", $texte); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * texte encodé et quote pour XML |
| 978 | 978 | */ |
| 979 | 979 | function texte_backendq(string $texte): string { |
| 980 | - return addslashes(texte_backend($texte)); |
|
| 980 | + return addslashes(texte_backend($texte)); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | |
@@ -999,14 +999,14 @@ discard block |
||
| 999 | 999 | * Texte sans son numéro éventuel |
| 1000 | 1000 | **/ |
| 1001 | 1001 | function supprimer_numero(?string $texte): string { |
| 1002 | - if ($texte === null) { |
|
| 1003 | - return ''; |
|
| 1004 | - } |
|
| 1005 | - return preg_replace( |
|
| 1006 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1007 | - '', |
|
| 1008 | - $texte |
|
| 1009 | - ); |
|
| 1002 | + if ($texte === null) { |
|
| 1003 | + return ''; |
|
| 1004 | + } |
|
| 1005 | + return preg_replace( |
|
| 1006 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1007 | + '', |
|
| 1008 | + $texte |
|
| 1009 | + ); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | /** |
@@ -1029,18 +1029,18 @@ discard block |
||
| 1029 | 1029 | * Numéro de titre, sinon chaîne vide |
| 1030 | 1030 | **/ |
| 1031 | 1031 | function recuperer_numero(?string $texte): string { |
| 1032 | - if ( |
|
| 1033 | - $texte and |
|
| 1034 | - preg_match( |
|
| 1035 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | - $texte, |
|
| 1037 | - $regs |
|
| 1038 | - ) |
|
| 1039 | - ) { |
|
| 1040 | - return strval($regs[1]); |
|
| 1041 | - } else { |
|
| 1042 | - return ''; |
|
| 1043 | - } |
|
| 1032 | + if ( |
|
| 1033 | + $texte and |
|
| 1034 | + preg_match( |
|
| 1035 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | + $texte, |
|
| 1037 | + $regs |
|
| 1038 | + ) |
|
| 1039 | + ) { |
|
| 1040 | + return strval($regs[1]); |
|
| 1041 | + } else { |
|
| 1042 | + return ''; |
|
| 1043 | + } |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1067,16 +1067,16 @@ discard block |
||
| 1067 | 1067 | * texte ou tableau de textes converti |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function supprimer_tags($texte, $rempl = '') { |
| 1070 | - if ($texte === null) { |
|
| 1071 | - return ''; |
|
| 1072 | - } |
|
| 1073 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1074 | - // ne pas oublier un < final non ferme car coupe |
|
| 1075 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1076 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1077 | - $texte = str_replace('<', '<', $texte); |
|
| 1070 | + if ($texte === null) { |
|
| 1071 | + return ''; |
|
| 1072 | + } |
|
| 1073 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1074 | + // ne pas oublier un < final non ferme car coupe |
|
| 1075 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1076 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1077 | + $texte = str_replace('<', '<', $texte); |
|
| 1078 | 1078 | |
| 1079 | - return $texte; |
|
| 1079 | + return $texte; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1099,9 +1099,9 @@ discard block |
||
| 1099 | 1099 | * texte converti |
| 1100 | 1100 | **/ |
| 1101 | 1101 | function echapper_tags($texte, $rempl = '') { |
| 1102 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1102 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1103 | 1103 | |
| 1104 | - return $texte; |
|
| 1104 | + return $texte; |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | /** |
@@ -1122,18 +1122,18 @@ discard block |
||
| 1122 | 1122 | * texte converti |
| 1123 | 1123 | **/ |
| 1124 | 1124 | function textebrut($texte) { |
| 1125 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1126 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1127 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1128 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1129 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1130 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1131 | - $texte = supprimer_tags($texte); |
|
| 1132 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1133 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1134 | - $texte = str_replace('’', "'", $texte); |
|
| 1125 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1126 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1127 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1128 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1129 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1130 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1131 | + $texte = supprimer_tags($texte); |
|
| 1132 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1133 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1134 | + $texte = str_replace('’', "'", $texte); |
|
| 1135 | 1135 | |
| 1136 | - return $texte; |
|
| 1136 | + return $texte; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
@@ -1149,23 +1149,23 @@ discard block |
||
| 1149 | 1149 | * texte avec liens ouvrants |
| 1150 | 1150 | **/ |
| 1151 | 1151 | function liens_ouvrants($texte) { |
| 1152 | - if ( |
|
| 1153 | - preg_match_all( |
|
| 1154 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1155 | - $texte, |
|
| 1156 | - $liens, |
|
| 1157 | - PREG_PATTERN_ORDER |
|
| 1158 | - ) |
|
| 1159 | - ) { |
|
| 1160 | - foreach ($liens[0] as $a) { |
|
| 1161 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1162 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1163 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1164 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - return $texte; |
|
| 1152 | + if ( |
|
| 1153 | + preg_match_all( |
|
| 1154 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1155 | + $texte, |
|
| 1156 | + $liens, |
|
| 1157 | + PREG_PATTERN_ORDER |
|
| 1158 | + ) |
|
| 1159 | + ) { |
|
| 1160 | + foreach ($liens[0] as $a) { |
|
| 1161 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1162 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1163 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1164 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + return $texte; |
|
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | /** |
@@ -1175,22 +1175,22 @@ discard block |
||
| 1175 | 1175 | * @return string |
| 1176 | 1176 | */ |
| 1177 | 1177 | function liens_nofollow($texte) { |
| 1178 | - if (stripos($texte, '<a') === false) { |
|
| 1179 | - return $texte; |
|
| 1180 | - } |
|
| 1178 | + if (stripos($texte, '<a') === false) { |
|
| 1179 | + return $texte; |
|
| 1180 | + } |
|
| 1181 | 1181 | |
| 1182 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1183 | - foreach ($regs[0] as $a) { |
|
| 1184 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1185 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1186 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1187 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1188 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1182 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1183 | + foreach ($regs[0] as $a) { |
|
| 1184 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1185 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1186 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1187 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1188 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | 1192 | |
| 1193 | - return $texte; |
|
| 1193 | + return $texte; |
|
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | 1196 | /** |
@@ -1209,12 +1209,12 @@ discard block |
||
| 1209 | 1209 | * texte sans paraghaphes |
| 1210 | 1210 | **/ |
| 1211 | 1211 | function PtoBR($texte) { |
| 1212 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1213 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1214 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1215 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1212 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1213 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1214 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1215 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1216 | 1216 | |
| 1217 | - return $texte; |
|
| 1217 | + return $texte; |
|
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | |
@@ -1239,19 +1239,19 @@ discard block |
||
| 1239 | 1239 | * @return string texte encadré du style CSS |
| 1240 | 1240 | */ |
| 1241 | 1241 | function lignes_longues($texte) { |
| 1242 | - trigger_error( |
|
| 1243 | - sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1244 | - \E_USER_DEPRECATED |
|
| 1245 | - ); |
|
| 1242 | + trigger_error( |
|
| 1243 | + sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1244 | + \E_USER_DEPRECATED |
|
| 1245 | + ); |
|
| 1246 | 1246 | |
| 1247 | - if (!strlen(trim($texte))) { |
|
| 1248 | - return $texte; |
|
| 1249 | - } |
|
| 1250 | - include_spip('inc/texte'); |
|
| 1251 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1252 | - 'div' : 'span'; |
|
| 1247 | + if (!strlen(trim($texte))) { |
|
| 1248 | + return $texte; |
|
| 1249 | + } |
|
| 1250 | + include_spip('inc/texte'); |
|
| 1251 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1252 | + 'div' : 'span'; |
|
| 1253 | 1253 | |
| 1254 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1254 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | /** |
@@ -1270,30 +1270,30 @@ discard block |
||
| 1270 | 1270 | * @return string texte en majuscule |
| 1271 | 1271 | */ |
| 1272 | 1272 | function majuscules($texte) { |
| 1273 | - if (!strlen($texte)) { |
|
| 1274 | - return ''; |
|
| 1275 | - } |
|
| 1273 | + if (!strlen($texte)) { |
|
| 1274 | + return ''; |
|
| 1275 | + } |
|
| 1276 | 1276 | |
| 1277 | - // Cas du turc |
|
| 1278 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1279 | - # remplacer hors des tags et des entites |
|
| 1280 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1281 | - foreach ($regs as $n => $match) { |
|
| 1282 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1277 | + // Cas du turc |
|
| 1278 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1279 | + # remplacer hors des tags et des entites |
|
| 1280 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1281 | + foreach ($regs as $n => $match) { |
|
| 1282 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | 1285 | |
| 1286 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1286 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1287 | 1287 | |
| 1288 | - if ($regs) { |
|
| 1289 | - foreach ($regs as $n => $match) { |
|
| 1290 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1291 | - } |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1288 | + if ($regs) { |
|
| 1289 | + foreach ($regs as $n => $match) { |
|
| 1290 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1291 | + } |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | 1294 | |
| 1295 | - // Cas general |
|
| 1296 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1295 | + // Cas general |
|
| 1296 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | /** |
@@ -1315,38 +1315,38 @@ discard block |
||
| 1315 | 1315 | */ |
| 1316 | 1316 | function taille_en_octets($octets, $systeme = 'BI') { |
| 1317 | 1317 | |
| 1318 | - // Texte à afficher pour la taille |
|
| 1319 | - $affichage = ''; |
|
| 1318 | + // Texte à afficher pour la taille |
|
| 1319 | + $affichage = ''; |
|
| 1320 | 1320 | |
| 1321 | - static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1322 | - static $precisions = [0, 1, 1, 2]; |
|
| 1321 | + static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1322 | + static $precisions = [0, 1, 1, 2]; |
|
| 1323 | 1323 | |
| 1324 | - if ($octets >= 1) { |
|
| 1325 | - // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1326 | - $systeme = strtolower($systeme); |
|
| 1327 | - if ($systeme === 'bi') { |
|
| 1328 | - $kilo = 1024; |
|
| 1329 | - $suffixe_item = "_$systeme"; |
|
| 1330 | - } elseif ($systeme === 'si') { |
|
| 1331 | - $kilo = 1000; |
|
| 1332 | - $suffixe_item = ''; |
|
| 1333 | - } else { |
|
| 1334 | - return $affichage; |
|
| 1335 | - } |
|
| 1324 | + if ($octets >= 1) { |
|
| 1325 | + // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1326 | + $systeme = strtolower($systeme); |
|
| 1327 | + if ($systeme === 'bi') { |
|
| 1328 | + $kilo = 1024; |
|
| 1329 | + $suffixe_item = "_$systeme"; |
|
| 1330 | + } elseif ($systeme === 'si') { |
|
| 1331 | + $kilo = 1000; |
|
| 1332 | + $suffixe_item = ''; |
|
| 1333 | + } else { |
|
| 1334 | + return $affichage; |
|
| 1335 | + } |
|
| 1336 | 1336 | |
| 1337 | - // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1338 | - $puissance = floor(log($octets, $kilo)); |
|
| 1337 | + // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1338 | + $puissance = floor(log($octets, $kilo)); |
|
| 1339 | 1339 | |
| 1340 | - // Calcul de la taille et choix de l'unité |
|
| 1341 | - $affichage = _T( |
|
| 1342 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1343 | - [ |
|
| 1344 | - 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
|
| 1345 | - ] |
|
| 1346 | - ); |
|
| 1347 | - } |
|
| 1340 | + // Calcul de la taille et choix de l'unité |
|
| 1341 | + $affichage = _T( |
|
| 1342 | + 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1343 | + [ |
|
| 1344 | + 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
|
| 1345 | + ] |
|
| 1346 | + ); |
|
| 1347 | + } |
|
| 1348 | 1348 | |
| 1349 | - return $affichage; |
|
| 1349 | + return $affichage; |
|
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | 1352 | |
@@ -1368,21 +1368,21 @@ discard block |
||
| 1368 | 1368 | * texte prêt pour être utilisé en attribut HTML |
| 1369 | 1369 | **/ |
| 1370 | 1370 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1371 | - if ($texte === null) { |
|
| 1372 | - return ''; |
|
| 1373 | - } |
|
| 1374 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1375 | - if ($textebrut) { |
|
| 1376 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1377 | - } |
|
| 1378 | - $texte = texte_backend($texte); |
|
| 1379 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1371 | + if ($texte === null) { |
|
| 1372 | + return ''; |
|
| 1373 | + } |
|
| 1374 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1375 | + if ($textebrut) { |
|
| 1376 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1377 | + } |
|
| 1378 | + $texte = texte_backend($texte); |
|
| 1379 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1380 | 1380 | |
| 1381 | - return preg_replace( |
|
| 1382 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1383 | - ['&', '&'], |
|
| 1384 | - $texte |
|
| 1385 | - ); |
|
| 1381 | + return preg_replace( |
|
| 1382 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1383 | + ['&', '&'], |
|
| 1384 | + $texte |
|
| 1385 | + ); |
|
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | |
@@ -1402,15 +1402,15 @@ discard block |
||
| 1402 | 1402 | * URL ou chaîne vide |
| 1403 | 1403 | **/ |
| 1404 | 1404 | function vider_url(?string $url, $entites = true): string { |
| 1405 | - if ($url === null) { |
|
| 1406 | - return ''; |
|
| 1407 | - } |
|
| 1408 | - # un message pour abs_url |
|
| 1409 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1410 | - $url = trim($url); |
|
| 1411 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1405 | + if ($url === null) { |
|
| 1406 | + return ''; |
|
| 1407 | + } |
|
| 1408 | + # un message pour abs_url |
|
| 1409 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1410 | + $url = trim($url); |
|
| 1411 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1412 | 1412 | |
| 1413 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1413 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | |
@@ -1425,10 +1425,10 @@ discard block |
||
| 1425 | 1425 | * @return string Adresse email maquillée |
| 1426 | 1426 | **/ |
| 1427 | 1427 | function antispam($texte) { |
| 1428 | - include_spip('inc/acces'); |
|
| 1429 | - $masque = creer_pass_aleatoire(3); |
|
| 1428 | + include_spip('inc/acces'); |
|
| 1429 | + $masque = creer_pass_aleatoire(3); |
|
| 1430 | 1430 | |
| 1431 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1431 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | /** |
@@ -1460,8 +1460,8 @@ discard block |
||
| 1460 | 1460 | * True si on a le droit d'accès, false sinon. |
| 1461 | 1461 | **/ |
| 1462 | 1462 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1463 | - include_spip('inc/acces'); |
|
| 1464 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1463 | + include_spip('inc/acces'); |
|
| 1464 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | /** |
@@ -1485,13 +1485,13 @@ discard block |
||
| 1485 | 1485 | * Retourne $texte, sinon $sinon. |
| 1486 | 1486 | **/ |
| 1487 | 1487 | function sinon($texte, $sinon = '') { |
| 1488 | - if ($texte) { |
|
| 1489 | - return $texte; |
|
| 1490 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1491 | - return $texte; |
|
| 1492 | - } else { |
|
| 1493 | - return $sinon; |
|
| 1494 | - } |
|
| 1488 | + if ($texte) { |
|
| 1489 | + return $texte; |
|
| 1490 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1491 | + return $texte; |
|
| 1492 | + } else { |
|
| 1493 | + return $sinon; |
|
| 1494 | + } |
|
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | 1497 | /** |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | * @return mixed |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function choixsivide($a, $vide, $pasvide) { |
| 1518 | - return $a ? $pasvide : $vide; |
|
| 1518 | + return $a ? $pasvide : $vide; |
|
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | /** |
@@ -1539,7 +1539,7 @@ discard block |
||
| 1539 | 1539 | * @return mixed |
| 1540 | 1540 | **/ |
| 1541 | 1541 | function choixsiegal($a1, $a2, $v, $f) { |
| 1542 | - return ($a1 == $a2) ? $v : $f; |
|
| 1542 | + return ($a1 == $a2) ? $v : $f; |
|
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | // |
@@ -1558,13 +1558,13 @@ discard block |
||
| 1558 | 1558 | * @return string |
| 1559 | 1559 | **/ |
| 1560 | 1560 | function filtrer_ical($texte) { |
| 1561 | - #include_spip('inc/charsets'); |
|
| 1562 | - $texte = html2unicode($texte); |
|
| 1563 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1564 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1565 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1561 | + #include_spip('inc/charsets'); |
|
| 1562 | + $texte = html2unicode($texte); |
|
| 1563 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1564 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1565 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1566 | 1566 | |
| 1567 | - return $texte; |
|
| 1567 | + return $texte; |
|
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | 1570 | |
@@ -1589,58 +1589,58 @@ discard block |
||
| 1589 | 1589 | * @return string |
| 1590 | 1590 | **/ |
| 1591 | 1591 | function post_autobr($texte, $delim = "\n_ ") { |
| 1592 | - if (!function_exists('echappe_html')) { |
|
| 1593 | - include_spip('inc/texte_mini'); |
|
| 1594 | - } |
|
| 1595 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1596 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1597 | - |
|
| 1598 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1599 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1600 | - } else { |
|
| 1601 | - $fin = ''; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - $texte = echappe_html($texte, '', true); |
|
| 1605 | - |
|
| 1606 | - // echapper les modeles |
|
| 1607 | - $collecteurModeles = null; |
|
| 1608 | - if (strpos($texte, '<') !== false) { |
|
| 1609 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1610 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1611 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1612 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - $debut = ''; |
|
| 1616 | - $suite = $texte; |
|
| 1617 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1618 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1619 | - $suite = substr($suite, $t); |
|
| 1620 | - $car = substr($suite, 0, 1); |
|
| 1621 | - if ( |
|
| 1622 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1623 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1624 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1625 | - ) { |
|
| 1626 | - $debut .= $delim; |
|
| 1627 | - } else { |
|
| 1628 | - $debut .= "\n"; |
|
| 1629 | - } |
|
| 1630 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1631 | - $debut .= $regs[0]; |
|
| 1632 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1633 | - } |
|
| 1634 | - } |
|
| 1635 | - $texte = $debut . $suite; |
|
| 1636 | - |
|
| 1637 | - if ($collecteurModeles) { |
|
| 1638 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - $texte = echappe_retour($texte); |
|
| 1642 | - |
|
| 1643 | - return $texte . $fin; |
|
| 1592 | + if (!function_exists('echappe_html')) { |
|
| 1593 | + include_spip('inc/texte_mini'); |
|
| 1594 | + } |
|
| 1595 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1596 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1597 | + |
|
| 1598 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1599 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1600 | + } else { |
|
| 1601 | + $fin = ''; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + $texte = echappe_html($texte, '', true); |
|
| 1605 | + |
|
| 1606 | + // echapper les modeles |
|
| 1607 | + $collecteurModeles = null; |
|
| 1608 | + if (strpos($texte, '<') !== false) { |
|
| 1609 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1610 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1611 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1612 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + $debut = ''; |
|
| 1616 | + $suite = $texte; |
|
| 1617 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1618 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1619 | + $suite = substr($suite, $t); |
|
| 1620 | + $car = substr($suite, 0, 1); |
|
| 1621 | + if ( |
|
| 1622 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1623 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1624 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1625 | + ) { |
|
| 1626 | + $debut .= $delim; |
|
| 1627 | + } else { |
|
| 1628 | + $debut .= "\n"; |
|
| 1629 | + } |
|
| 1630 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1631 | + $debut .= $regs[0]; |
|
| 1632 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1633 | + } |
|
| 1634 | + } |
|
| 1635 | + $texte = $debut . $suite; |
|
| 1636 | + |
|
| 1637 | + if ($collecteurModeles) { |
|
| 1638 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + $texte = echappe_retour($texte); |
|
| 1642 | + |
|
| 1643 | + return $texte . $fin; |
|
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | |
@@ -1675,30 +1675,30 @@ discard block |
||
| 1675 | 1675 | **/ |
| 1676 | 1676 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1677 | 1677 | |
| 1678 | - if ( |
|
| 1679 | - $letexte |
|
| 1680 | - and strpos($letexte, '<:') !== false |
|
| 1681 | - ) { |
|
| 1682 | - if (!$lang) { |
|
| 1683 | - $lang = $GLOBALS['spip_lang']; |
|
| 1684 | - } |
|
| 1685 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1686 | - if (is_bool($options)) { |
|
| 1687 | - $options = ['echappe_span' => $options]; |
|
| 1688 | - } |
|
| 1689 | - if (!isset($options['echappe_span'])) { |
|
| 1690 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1691 | - } |
|
| 1692 | - $options['lang'] = $lang; |
|
| 1678 | + if ( |
|
| 1679 | + $letexte |
|
| 1680 | + and strpos($letexte, '<:') !== false |
|
| 1681 | + ) { |
|
| 1682 | + if (!$lang) { |
|
| 1683 | + $lang = $GLOBALS['spip_lang']; |
|
| 1684 | + } |
|
| 1685 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1686 | + if (is_bool($options)) { |
|
| 1687 | + $options = ['echappe_span' => $options]; |
|
| 1688 | + } |
|
| 1689 | + if (!isset($options['echappe_span'])) { |
|
| 1690 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1691 | + } |
|
| 1692 | + $options['lang'] = $lang; |
|
| 1693 | 1693 | |
| 1694 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1695 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1696 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1694 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1695 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1696 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1697 | 1697 | |
| 1698 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1698 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1699 | 1699 | |
| 1700 | - } |
|
| 1701 | - return $letexte; |
|
| 1700 | + } |
|
| 1701 | + return $letexte; |
|
| 1702 | 1702 | } |
| 1703 | 1703 | |
| 1704 | 1704 | /** |
@@ -1736,34 +1736,34 @@ discard block |
||
| 1736 | 1736 | **/ |
| 1737 | 1737 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1738 | 1738 | |
| 1739 | - if ( |
|
| 1740 | - $letexte |
|
| 1741 | - and stripos($letexte, '<multi') !== false |
|
| 1742 | - ) { |
|
| 1743 | - if (!$lang) { |
|
| 1744 | - $lang = $GLOBALS['spip_lang']; |
|
| 1745 | - } |
|
| 1739 | + if ( |
|
| 1740 | + $letexte |
|
| 1741 | + and stripos($letexte, '<multi') !== false |
|
| 1742 | + ) { |
|
| 1743 | + if (!$lang) { |
|
| 1744 | + $lang = $GLOBALS['spip_lang']; |
|
| 1745 | + } |
|
| 1746 | 1746 | |
| 1747 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1748 | - if (is_bool($options)) { |
|
| 1749 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1750 | - } |
|
| 1751 | - if (!isset($options['echappe_span'])) { |
|
| 1752 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1753 | - } |
|
| 1754 | - if (!isset($options['lang_defaut'])) { |
|
| 1755 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1756 | - } |
|
| 1757 | - $options['lang'] = $lang; |
|
| 1747 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1748 | + if (is_bool($options)) { |
|
| 1749 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1750 | + } |
|
| 1751 | + if (!isset($options['echappe_span'])) { |
|
| 1752 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1753 | + } |
|
| 1754 | + if (!isset($options['lang_defaut'])) { |
|
| 1755 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1756 | + } |
|
| 1757 | + $options['lang'] = $lang; |
|
| 1758 | 1758 | |
| 1759 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1760 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 1761 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1759 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1760 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 1761 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1762 | 1762 | |
| 1763 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1764 | - } |
|
| 1763 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1764 | + } |
|
| 1765 | 1765 | |
| 1766 | - return $letexte; |
|
| 1766 | + return $letexte; |
|
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | 1769 | /** |
@@ -1773,7 +1773,7 @@ discard block |
||
| 1773 | 1773 | * @return string L'initiale en majuscule |
| 1774 | 1774 | */ |
| 1775 | 1775 | function filtre_initiale($nom) { |
| 1776 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1776 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1777 | 1777 | } |
| 1778 | 1778 | |
| 1779 | 1779 | |
@@ -1818,33 +1818,33 @@ discard block |
||
| 1818 | 1818 | * - null (interne) : si on empile |
| 1819 | 1819 | **/ |
| 1820 | 1820 | function unique($donnee, $famille = '', $cpt = false) { |
| 1821 | - static $mem = []; |
|
| 1822 | - // permettre de vider la pile et de la restaurer |
|
| 1823 | - // pour le calcul de introduction... |
|
| 1824 | - if ($famille == '_spip_raz_') { |
|
| 1825 | - $tmp = $mem; |
|
| 1826 | - $mem = []; |
|
| 1827 | - |
|
| 1828 | - return $tmp; |
|
| 1829 | - } elseif ($famille == '_spip_set_') { |
|
| 1830 | - $mem = $donnee; |
|
| 1831 | - |
|
| 1832 | - return; |
|
| 1833 | - } |
|
| 1834 | - // eviter une notice |
|
| 1835 | - if (!isset($mem[$famille])) { |
|
| 1836 | - $mem[$famille] = []; |
|
| 1837 | - } |
|
| 1838 | - if ($cpt) { |
|
| 1839 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1840 | - } |
|
| 1841 | - // eviter une notice |
|
| 1842 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1843 | - $mem[$famille][$donnee] = 0; |
|
| 1844 | - } |
|
| 1845 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1846 | - return $donnee; |
|
| 1847 | - } |
|
| 1821 | + static $mem = []; |
|
| 1822 | + // permettre de vider la pile et de la restaurer |
|
| 1823 | + // pour le calcul de introduction... |
|
| 1824 | + if ($famille == '_spip_raz_') { |
|
| 1825 | + $tmp = $mem; |
|
| 1826 | + $mem = []; |
|
| 1827 | + |
|
| 1828 | + return $tmp; |
|
| 1829 | + } elseif ($famille == '_spip_set_') { |
|
| 1830 | + $mem = $donnee; |
|
| 1831 | + |
|
| 1832 | + return; |
|
| 1833 | + } |
|
| 1834 | + // eviter une notice |
|
| 1835 | + if (!isset($mem[$famille])) { |
|
| 1836 | + $mem[$famille] = []; |
|
| 1837 | + } |
|
| 1838 | + if ($cpt) { |
|
| 1839 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1840 | + } |
|
| 1841 | + // eviter une notice |
|
| 1842 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1843 | + $mem[$famille][$donnee] = 0; |
|
| 1844 | + } |
|
| 1845 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1846 | + return $donnee; |
|
| 1847 | + } |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | |
@@ -1874,20 +1874,20 @@ discard block |
||
| 1874 | 1874 | * Une des valeurs en fonction du compteur. |
| 1875 | 1875 | **/ |
| 1876 | 1876 | function alterner($i, ...$args) { |
| 1877 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1878 | - $num = count($args); |
|
| 1877 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1878 | + $num = count($args); |
|
| 1879 | 1879 | |
| 1880 | - if ($num === 1 && is_array($args[0])) { |
|
| 1881 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1882 | - $args = array_values($args[0]); |
|
| 1883 | - $num = count($args); |
|
| 1884 | - } |
|
| 1880 | + if ($num === 1 && is_array($args[0])) { |
|
| 1881 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1882 | + $args = array_values($args[0]); |
|
| 1883 | + $num = count($args); |
|
| 1884 | + } |
|
| 1885 | 1885 | |
| 1886 | - // un index compris entre 0 et num exclus |
|
| 1887 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1888 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1889 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1890 | - return $args[$i]; |
|
| 1886 | + // un index compris entre 0 et num exclus |
|
| 1887 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1888 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1889 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1890 | + return $args[$i]; |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | 1893 | |
@@ -1913,52 +1913,52 @@ discard block |
||
| 1913 | 1913 | * - null lorsque l’attribut n’existe pas. |
| 1914 | 1914 | **/ |
| 1915 | 1915 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1916 | - if (is_array($balise)) { |
|
| 1917 | - array_walk( |
|
| 1918 | - $balise, |
|
| 1919 | - function (&$a, $key, $t) { |
|
| 1920 | - $a = extraire_attribut($a, $t); |
|
| 1921 | - }, |
|
| 1922 | - $attribut |
|
| 1923 | - ); |
|
| 1924 | - |
|
| 1925 | - return $balise; |
|
| 1926 | - } |
|
| 1927 | - if ( |
|
| 1928 | - $balise |
|
| 1929 | - && stripos($balise, $attribut) !== false |
|
| 1930 | - && preg_match( |
|
| 1931 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1932 | - . $attribut |
|
| 1933 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1934 | - $balise, |
|
| 1935 | - $r |
|
| 1936 | - ) |
|
| 1937 | - ) { |
|
| 1938 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1939 | - $r[4] = substr($r[3], 1, -1); |
|
| 1940 | - $r[3] = $r[3][0]; |
|
| 1941 | - } elseif ($r[3] !== '') { |
|
| 1942 | - $r[4] = $r[3]; |
|
| 1943 | - $r[3] = ''; |
|
| 1944 | - } else { |
|
| 1945 | - $r[4] = trim($r[2]); |
|
| 1946 | - } |
|
| 1947 | - $att = $r[4]; |
|
| 1948 | - if (strpos($att, '&#') !== false) { |
|
| 1949 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1950 | - } |
|
| 1951 | - $att = filtrer_entites($att); |
|
| 1952 | - } else { |
|
| 1953 | - $att = null; |
|
| 1954 | - $r = []; |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - if ($complet) { |
|
| 1958 | - return [$att, $r]; |
|
| 1959 | - } else { |
|
| 1960 | - return $att; |
|
| 1961 | - } |
|
| 1916 | + if (is_array($balise)) { |
|
| 1917 | + array_walk( |
|
| 1918 | + $balise, |
|
| 1919 | + function (&$a, $key, $t) { |
|
| 1920 | + $a = extraire_attribut($a, $t); |
|
| 1921 | + }, |
|
| 1922 | + $attribut |
|
| 1923 | + ); |
|
| 1924 | + |
|
| 1925 | + return $balise; |
|
| 1926 | + } |
|
| 1927 | + if ( |
|
| 1928 | + $balise |
|
| 1929 | + && stripos($balise, $attribut) !== false |
|
| 1930 | + && preg_match( |
|
| 1931 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1932 | + . $attribut |
|
| 1933 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1934 | + $balise, |
|
| 1935 | + $r |
|
| 1936 | + ) |
|
| 1937 | + ) { |
|
| 1938 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1939 | + $r[4] = substr($r[3], 1, -1); |
|
| 1940 | + $r[3] = $r[3][0]; |
|
| 1941 | + } elseif ($r[3] !== '') { |
|
| 1942 | + $r[4] = $r[3]; |
|
| 1943 | + $r[3] = ''; |
|
| 1944 | + } else { |
|
| 1945 | + $r[4] = trim($r[2]); |
|
| 1946 | + } |
|
| 1947 | + $att = $r[4]; |
|
| 1948 | + if (strpos($att, '&#') !== false) { |
|
| 1949 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1950 | + } |
|
| 1951 | + $att = filtrer_entites($att); |
|
| 1952 | + } else { |
|
| 1953 | + $att = null; |
|
| 1954 | + $r = []; |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + if ($complet) { |
|
| 1958 | + return [$att, $r]; |
|
| 1959 | + } else { |
|
| 1960 | + return $att; |
|
| 1961 | + } |
|
| 1962 | 1962 | } |
| 1963 | 1963 | |
| 1964 | 1964 | /** |
@@ -1991,41 +1991,41 @@ discard block |
||
| 1991 | 1991 | **/ |
| 1992 | 1992 | function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string { |
| 1993 | 1993 | |
| 1994 | - if ($balise === null or $balise === '') { |
|
| 1995 | - return ''; |
|
| 1996 | - } |
|
| 1994 | + if ($balise === null or $balise === '') { |
|
| 1995 | + return ''; |
|
| 1996 | + } |
|
| 1997 | 1997 | |
| 1998 | - // preparer l'attribut |
|
| 1999 | - // supprimer les etc mais pas les balises html |
|
| 2000 | - // qui ont un sens dans un attribut value d'un input |
|
| 2001 | - if ($proteger) { |
|
| 2002 | - $val = attribut_html($val, false); |
|
| 2003 | - } |
|
| 1998 | + // preparer l'attribut |
|
| 1999 | + // supprimer les etc mais pas les balises html |
|
| 2000 | + // qui ont un sens dans un attribut value d'un input |
|
| 2001 | + if ($proteger) { |
|
| 2002 | + $val = attribut_html($val, false); |
|
| 2003 | + } |
|
| 2004 | 2004 | |
| 2005 | - // echapper les ' pour eviter tout bug |
|
| 2006 | - $val = str_replace("'", ''', $val ?? ''); |
|
| 2007 | - if ($vider and strlen($val) === 0) { |
|
| 2008 | - $insert = ''; |
|
| 2009 | - } else { |
|
| 2010 | - $insert = " $attribut='$val'"; |
|
| 2011 | - } |
|
| 2005 | + // echapper les ' pour eviter tout bug |
|
| 2006 | + $val = str_replace("'", ''', $val ?? ''); |
|
| 2007 | + if ($vider and strlen($val) === 0) { |
|
| 2008 | + $insert = ''; |
|
| 2009 | + } else { |
|
| 2010 | + $insert = " $attribut='$val'"; |
|
| 2011 | + } |
|
| 2012 | 2012 | |
| 2013 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2013 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2014 | 2014 | |
| 2015 | - if ($old !== null) { |
|
| 2016 | - // Remplacer l'ancien attribut du meme nom |
|
| 2017 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2018 | - } else { |
|
| 2019 | - // preferer une balise " />" (comme <img />) |
|
| 2020 | - if (preg_match(',/>,', $balise)) { |
|
| 2021 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2022 | - } // sinon une balise <a ...> ... </a> |
|
| 2023 | - else { |
|
| 2024 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2025 | - } |
|
| 2026 | - } |
|
| 2015 | + if ($old !== null) { |
|
| 2016 | + // Remplacer l'ancien attribut du meme nom |
|
| 2017 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2018 | + } else { |
|
| 2019 | + // preferer une balise " />" (comme <img />) |
|
| 2020 | + if (preg_match(',/>,', $balise)) { |
|
| 2021 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2022 | + } // sinon une balise <a ...> ... </a> |
|
| 2023 | + else { |
|
| 2024 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2025 | + } |
|
| 2026 | + } |
|
| 2027 | 2027 | |
| 2028 | - return $balise; |
|
| 2028 | + return $balise; |
|
| 2029 | 2029 | } |
| 2030 | 2030 | |
| 2031 | 2031 | /** |
@@ -2043,7 +2043,7 @@ discard block |
||
| 2043 | 2043 | * @return string Code HTML sans l'attribut |
| 2044 | 2044 | **/ |
| 2045 | 2045 | function vider_attribut(?string $balise, string $attribut): string { |
| 2046 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2046 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2047 | 2047 | } |
| 2048 | 2048 | |
| 2049 | 2049 | /** |
@@ -2055,50 +2055,50 @@ discard block |
||
| 2055 | 2055 | * @return string |
| 2056 | 2056 | */ |
| 2057 | 2057 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2058 | - if (is_string($class)) { |
|
| 2059 | - $class = explode(' ', trim($class)); |
|
| 2060 | - } |
|
| 2061 | - $class = array_filter($class); |
|
| 2062 | - $class = array_unique($class); |
|
| 2063 | - if (!$class) { |
|
| 2064 | - return $balise; |
|
| 2065 | - } |
|
| 2066 | - |
|
| 2067 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2068 | - $class_new = $class_courante; |
|
| 2069 | - foreach ($class as $c) { |
|
| 2070 | - $is_class_presente = false; |
|
| 2071 | - if ( |
|
| 2072 | - $class_courante |
|
| 2073 | - and str_contains($class_courante, (string) $c) |
|
| 2074 | - and in_array($c, preg_split(",\s+,", $class_courante)) |
|
| 2075 | - ) { |
|
| 2076 | - $is_class_presente = true; |
|
| 2077 | - } |
|
| 2078 | - if ( |
|
| 2079 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2080 | - and !$is_class_presente |
|
| 2081 | - ) { |
|
| 2082 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2083 | - } elseif ( |
|
| 2084 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2085 | - and $is_class_presente |
|
| 2086 | - ) { |
|
| 2087 | - $class_new = preg_split(",\s+,", $class_new); |
|
| 2088 | - $class_new = array_diff($class_new, [$c]); |
|
| 2089 | - $class_new = implode(' ', $class_new); |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - if ($class_new !== $class_courante) { |
|
| 2094 | - if (strlen($class_new)) { |
|
| 2095 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2096 | - } elseif ($class_courante) { |
|
| 2097 | - $balise = vider_attribut($balise, 'class'); |
|
| 2098 | - } |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - return $balise; |
|
| 2058 | + if (is_string($class)) { |
|
| 2059 | + $class = explode(' ', trim($class)); |
|
| 2060 | + } |
|
| 2061 | + $class = array_filter($class); |
|
| 2062 | + $class = array_unique($class); |
|
| 2063 | + if (!$class) { |
|
| 2064 | + return $balise; |
|
| 2065 | + } |
|
| 2066 | + |
|
| 2067 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2068 | + $class_new = $class_courante; |
|
| 2069 | + foreach ($class as $c) { |
|
| 2070 | + $is_class_presente = false; |
|
| 2071 | + if ( |
|
| 2072 | + $class_courante |
|
| 2073 | + and str_contains($class_courante, (string) $c) |
|
| 2074 | + and in_array($c, preg_split(",\s+,", $class_courante)) |
|
| 2075 | + ) { |
|
| 2076 | + $is_class_presente = true; |
|
| 2077 | + } |
|
| 2078 | + if ( |
|
| 2079 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2080 | + and !$is_class_presente |
|
| 2081 | + ) { |
|
| 2082 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2083 | + } elseif ( |
|
| 2084 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2085 | + and $is_class_presente |
|
| 2086 | + ) { |
|
| 2087 | + $class_new = preg_split(",\s+,", $class_new); |
|
| 2088 | + $class_new = array_diff($class_new, [$c]); |
|
| 2089 | + $class_new = implode(' ', $class_new); |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + if ($class_new !== $class_courante) { |
|
| 2094 | + if (strlen($class_new)) { |
|
| 2095 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2096 | + } elseif ($class_courante) { |
|
| 2097 | + $balise = vider_attribut($balise, 'class'); |
|
| 2098 | + } |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + return $balise; |
|
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | 2104 | /** |
@@ -2108,7 +2108,7 @@ discard block |
||
| 2108 | 2108 | * @return string |
| 2109 | 2109 | */ |
| 2110 | 2110 | function ajouter_class($balise, $class) { |
| 2111 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2111 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | 2114 | /** |
@@ -2118,7 +2118,7 @@ discard block |
||
| 2118 | 2118 | * @return string |
| 2119 | 2119 | */ |
| 2120 | 2120 | function supprimer_class($balise, $class) { |
| 2121 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2121 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | 2124 | /** |
@@ -2129,7 +2129,7 @@ discard block |
||
| 2129 | 2129 | * @return string |
| 2130 | 2130 | */ |
| 2131 | 2131 | function commuter_class($balise, $class) { |
| 2132 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2132 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | |
| 2135 | 2135 | /** |
@@ -2140,19 +2140,19 @@ discard block |
||
| 2140 | 2140 | * @return string |
| 2141 | 2141 | */ |
| 2142 | 2142 | function tester_config($id, $mode = '') { |
| 2143 | - include_spip('action/inscrire_auteur'); |
|
| 2143 | + include_spip('action/inscrire_auteur'); |
|
| 2144 | 2144 | |
| 2145 | - return tester_statut_inscription($mode, $id); |
|
| 2145 | + return tester_statut_inscription($mode, $id); |
|
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | // |
| 2149 | 2149 | // Quelques fonctions de calcul arithmetique |
| 2150 | 2150 | // |
| 2151 | 2151 | function floatstr($a) { |
| 2152 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2152 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2153 | 2153 | } |
| 2154 | 2154 | function strize($f, $a, $b) { |
| 2155 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2155 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | /** |
@@ -2171,11 +2171,11 @@ discard block |
||
| 2171 | 2171 | * @return int $a+$b |
| 2172 | 2172 | **/ |
| 2173 | 2173 | function plus($a, $b) { |
| 2174 | - return $a + $b; |
|
| 2174 | + return $a + $b; |
|
| 2175 | 2175 | } |
| 2176 | 2176 | |
| 2177 | 2177 | function strplus($a, $b) { |
| 2178 | - return strize('plus', $a, $b); |
|
| 2178 | + return strize('plus', $a, $b); |
|
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | 2181 | /** |
@@ -2194,11 +2194,11 @@ discard block |
||
| 2194 | 2194 | * @return int $a-$b |
| 2195 | 2195 | **/ |
| 2196 | 2196 | function moins($a, $b) { |
| 2197 | - return $a - $b; |
|
| 2197 | + return $a - $b; |
|
| 2198 | 2198 | } |
| 2199 | 2199 | |
| 2200 | 2200 | function strmoins($a, $b) { |
| 2201 | - return strize('moins', $a, $b); |
|
| 2201 | + return strize('moins', $a, $b); |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | /** |
@@ -2218,11 +2218,11 @@ discard block |
||
| 2218 | 2218 | * @return int $a*$b |
| 2219 | 2219 | **/ |
| 2220 | 2220 | function mult($a, $b) { |
| 2221 | - return $a * $b; |
|
| 2221 | + return $a * $b; |
|
| 2222 | 2222 | } |
| 2223 | 2223 | |
| 2224 | 2224 | function strmult($a, $b) { |
| 2225 | - return strize('mult', $a, $b); |
|
| 2225 | + return strize('mult', $a, $b); |
|
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | /** |
@@ -2242,11 +2242,11 @@ discard block |
||
| 2242 | 2242 | * @return int $a/$b (ou 0 si $b est nul) |
| 2243 | 2243 | **/ |
| 2244 | 2244 | function div($a, $b) { |
| 2245 | - return $b ? $a / $b : 0; |
|
| 2245 | + return $b ? $a / $b : 0; |
|
| 2246 | 2246 | } |
| 2247 | 2247 | |
| 2248 | 2248 | function strdiv($a, $b) { |
| 2249 | - return strize('div', $a, $b); |
|
| 2249 | + return strize('div', $a, $b); |
|
| 2250 | 2250 | } |
| 2251 | 2251 | |
| 2252 | 2252 | /** |
@@ -2267,7 +2267,7 @@ discard block |
||
| 2267 | 2267 | * @return int ($nb % $mod) + $add |
| 2268 | 2268 | **/ |
| 2269 | 2269 | function modulo($nb, $mod, $add = 0) { |
| 2270 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2270 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | |
@@ -2282,26 +2282,26 @@ discard block |
||
| 2282 | 2282 | * - true sinon |
| 2283 | 2283 | **/ |
| 2284 | 2284 | function nom_acceptable($nom) { |
| 2285 | - $remp2 = []; |
|
| 2286 | - $remp1 = []; |
|
| 2287 | - if (!is_string($nom)) { |
|
| 2288 | - return false; |
|
| 2289 | - } |
|
| 2290 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2291 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2292 | - } |
|
| 2293 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2294 | - foreach ($tags_acceptes as $tag) { |
|
| 2295 | - if (strlen($tag)) { |
|
| 2296 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2297 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2298 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2299 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2300 | - } |
|
| 2301 | - } |
|
| 2302 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2303 | - |
|
| 2304 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2285 | + $remp2 = []; |
|
| 2286 | + $remp1 = []; |
|
| 2287 | + if (!is_string($nom)) { |
|
| 2288 | + return false; |
|
| 2289 | + } |
|
| 2290 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2291 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2292 | + } |
|
| 2293 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2294 | + foreach ($tags_acceptes as $tag) { |
|
| 2295 | + if (strlen($tag)) { |
|
| 2296 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2297 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2298 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2299 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2300 | + } |
|
| 2301 | + } |
|
| 2302 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2303 | + |
|
| 2304 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | 2307 | |
@@ -2317,14 +2317,14 @@ discard block |
||
| 2317 | 2317 | * - renvoie un tableau si l'entree est un tableau |
| 2318 | 2318 | **/ |
| 2319 | 2319 | function email_valide($adresses) { |
| 2320 | - if (is_array($adresses)) { |
|
| 2321 | - $adresses = array_map('email_valide', $adresses); |
|
| 2322 | - $adresses = array_filter($adresses); |
|
| 2323 | - return $adresses; |
|
| 2324 | - } |
|
| 2320 | + if (is_array($adresses)) { |
|
| 2321 | + $adresses = array_map('email_valide', $adresses); |
|
| 2322 | + $adresses = array_filter($adresses); |
|
| 2323 | + return $adresses; |
|
| 2324 | + } |
|
| 2325 | 2325 | |
| 2326 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2327 | - return $email_valide($adresses); |
|
| 2326 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2327 | + return $email_valide($adresses); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | |
| 2330 | 2330 | /** |
@@ -2338,29 +2338,29 @@ discard block |
||
| 2338 | 2338 | * @return string texte |
| 2339 | 2339 | **/ |
| 2340 | 2340 | function afficher_enclosures($tags) { |
| 2341 | - $s = []; |
|
| 2342 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2343 | - if ( |
|
| 2344 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2345 | - and $t = extraire_attribut($tag, 'href') |
|
| 2346 | - ) { |
|
| 2347 | - $s[] = preg_replace( |
|
| 2348 | - ',>[^<]+</a>,S', |
|
| 2349 | - '>' |
|
| 2350 | - . http_img_pack( |
|
| 2351 | - 'attachment-16.png', |
|
| 2352 | - $t, |
|
| 2353 | - '', |
|
| 2354 | - $t, |
|
| 2355 | - ['utiliser_suffixe_size' => true] |
|
| 2356 | - ) |
|
| 2357 | - . '</a>', |
|
| 2358 | - $tag |
|
| 2359 | - ); |
|
| 2360 | - } |
|
| 2361 | - } |
|
| 2362 | - |
|
| 2363 | - return join(' ', $s); |
|
| 2341 | + $s = []; |
|
| 2342 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2343 | + if ( |
|
| 2344 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2345 | + and $t = extraire_attribut($tag, 'href') |
|
| 2346 | + ) { |
|
| 2347 | + $s[] = preg_replace( |
|
| 2348 | + ',>[^<]+</a>,S', |
|
| 2349 | + '>' |
|
| 2350 | + . http_img_pack( |
|
| 2351 | + 'attachment-16.png', |
|
| 2352 | + $t, |
|
| 2353 | + '', |
|
| 2354 | + $t, |
|
| 2355 | + ['utiliser_suffixe_size' => true] |
|
| 2356 | + ) |
|
| 2357 | + . '</a>', |
|
| 2358 | + $tag |
|
| 2359 | + ); |
|
| 2360 | + } |
|
| 2361 | + } |
|
| 2362 | + |
|
| 2363 | + return join(' ', $s); |
|
| 2364 | 2364 | } |
| 2365 | 2365 | |
| 2366 | 2366 | /** |
@@ -2375,15 +2375,15 @@ discard block |
||
| 2375 | 2375 | * @return string Liens trouvés |
| 2376 | 2376 | **/ |
| 2377 | 2377 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2378 | - $s = []; |
|
| 2379 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2380 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2381 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2382 | - $s[] = $tag; |
|
| 2383 | - } |
|
| 2384 | - } |
|
| 2378 | + $s = []; |
|
| 2379 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2380 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2381 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2382 | + $s[] = $tag; |
|
| 2383 | + } |
|
| 2384 | + } |
|
| 2385 | 2385 | |
| 2386 | - return join(', ', $s); |
|
| 2386 | + return join(', ', $s); |
|
| 2387 | 2387 | } |
| 2388 | 2388 | |
| 2389 | 2389 | |
@@ -2405,21 +2405,21 @@ discard block |
||
| 2405 | 2405 | * @return string Tag HTML `<a>` avec microformat. |
| 2406 | 2406 | **/ |
| 2407 | 2407 | function enclosure2microformat($e) { |
| 2408 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2409 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2410 | - } |
|
| 2411 | - $type = extraire_attribut($e, 'type'); |
|
| 2412 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2413 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2414 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2415 | - } |
|
| 2416 | - $fichier = basename($url); |
|
| 2408 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2409 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2410 | + } |
|
| 2411 | + $type = extraire_attribut($e, 'type'); |
|
| 2412 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2413 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2414 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2415 | + } |
|
| 2416 | + $fichier = basename($url); |
|
| 2417 | 2417 | |
| 2418 | - return '<a rel="enclosure"' |
|
| 2419 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2420 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2421 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2422 | - . '>' . $fichier . '</a>'; |
|
| 2418 | + return '<a rel="enclosure"' |
|
| 2419 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2420 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2421 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2422 | + . '>' . $fichier . '</a>'; |
|
| 2423 | 2423 | } |
| 2424 | 2424 | |
| 2425 | 2425 | /** |
@@ -2437,24 +2437,24 @@ discard block |
||
| 2437 | 2437 | * @return string Tags RSS `<enclosure>`. |
| 2438 | 2438 | **/ |
| 2439 | 2439 | function microformat2enclosure($tags) { |
| 2440 | - $enclosures = []; |
|
| 2441 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2442 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2443 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2444 | - $type = extraire_attribut($e, 'type'); |
|
| 2445 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2446 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2447 | - } # vieux data |
|
| 2448 | - $fichier = basename($url); |
|
| 2449 | - $enclosures[] = '<enclosure' |
|
| 2450 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2451 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2452 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2453 | - . ' />'; |
|
| 2454 | - } |
|
| 2455 | - } |
|
| 2440 | + $enclosures = []; |
|
| 2441 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2442 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2443 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2444 | + $type = extraire_attribut($e, 'type'); |
|
| 2445 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2446 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2447 | + } # vieux data |
|
| 2448 | + $fichier = basename($url); |
|
| 2449 | + $enclosures[] = '<enclosure' |
|
| 2450 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2451 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2452 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2453 | + . ' />'; |
|
| 2454 | + } |
|
| 2455 | + } |
|
| 2456 | 2456 | |
| 2457 | - return join("\n", $enclosures); |
|
| 2457 | + return join("\n", $enclosures); |
|
| 2458 | 2458 | } |
| 2459 | 2459 | |
| 2460 | 2460 | |
@@ -2470,16 +2470,16 @@ discard block |
||
| 2470 | 2470 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2471 | 2471 | **/ |
| 2472 | 2472 | function tags2dcsubject($tags) { |
| 2473 | - $subjects = ''; |
|
| 2474 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2475 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2476 | - $subjects .= '<dc:subject>' |
|
| 2477 | - . texte_backend(textebrut($e)) |
|
| 2478 | - . '</dc:subject>' . "\n"; |
|
| 2479 | - } |
|
| 2480 | - } |
|
| 2473 | + $subjects = ''; |
|
| 2474 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2475 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2476 | + $subjects .= '<dc:subject>' |
|
| 2477 | + . texte_backend(textebrut($e)) |
|
| 2478 | + . '</dc:subject>' . "\n"; |
|
| 2479 | + } |
|
| 2480 | + } |
|
| 2481 | 2481 | |
| 2482 | - return $subjects; |
|
| 2482 | + return $subjects; |
|
| 2483 | 2483 | } |
| 2484 | 2484 | |
| 2485 | 2485 | /** |
@@ -2508,27 +2508,27 @@ discard block |
||
| 2508 | 2508 | * - Tableau de résultats, si tableau en entrée. |
| 2509 | 2509 | **/ |
| 2510 | 2510 | function extraire_balise($texte, $tag = 'a') { |
| 2511 | - if (is_array($texte)) { |
|
| 2512 | - array_walk( |
|
| 2513 | - $texte, |
|
| 2514 | - function (&$a, $key, $t) { |
|
| 2515 | - $a = extraire_balise($a, $t); |
|
| 2516 | - }, |
|
| 2517 | - $tag |
|
| 2518 | - ); |
|
| 2519 | - |
|
| 2520 | - return $texte; |
|
| 2521 | - } |
|
| 2522 | - |
|
| 2523 | - if ( |
|
| 2524 | - preg_match( |
|
| 2525 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2526 | - $texte, |
|
| 2527 | - $regs |
|
| 2528 | - ) |
|
| 2529 | - ) { |
|
| 2530 | - return $regs[0]; |
|
| 2531 | - } |
|
| 2511 | + if (is_array($texte)) { |
|
| 2512 | + array_walk( |
|
| 2513 | + $texte, |
|
| 2514 | + function (&$a, $key, $t) { |
|
| 2515 | + $a = extraire_balise($a, $t); |
|
| 2516 | + }, |
|
| 2517 | + $tag |
|
| 2518 | + ); |
|
| 2519 | + |
|
| 2520 | + return $texte; |
|
| 2521 | + } |
|
| 2522 | + |
|
| 2523 | + if ( |
|
| 2524 | + preg_match( |
|
| 2525 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2526 | + $texte, |
|
| 2527 | + $regs |
|
| 2528 | + ) |
|
| 2529 | + ) { |
|
| 2530 | + return $regs[0]; |
|
| 2531 | + } |
|
| 2532 | 2532 | } |
| 2533 | 2533 | |
| 2534 | 2534 | /** |
@@ -2556,30 +2556,30 @@ discard block |
||
| 2556 | 2556 | * - Tableau de résultats, si tableau en entrée. |
| 2557 | 2557 | **/ |
| 2558 | 2558 | function extraire_balises($texte, $tag = 'a') { |
| 2559 | - if (is_array($texte)) { |
|
| 2560 | - array_walk( |
|
| 2561 | - $texte, |
|
| 2562 | - function (&$a, $key, $t) { |
|
| 2563 | - $a = extraire_balises($a, $t); |
|
| 2564 | - }, |
|
| 2565 | - $tag |
|
| 2566 | - ); |
|
| 2567 | - |
|
| 2568 | - return $texte; |
|
| 2569 | - } |
|
| 2570 | - |
|
| 2571 | - if ( |
|
| 2572 | - preg_match_all( |
|
| 2573 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2574 | - $texte, |
|
| 2575 | - $regs, |
|
| 2576 | - PREG_PATTERN_ORDER |
|
| 2577 | - ) |
|
| 2578 | - ) { |
|
| 2579 | - return $regs[0]; |
|
| 2580 | - } else { |
|
| 2581 | - return []; |
|
| 2582 | - } |
|
| 2559 | + if (is_array($texte)) { |
|
| 2560 | + array_walk( |
|
| 2561 | + $texte, |
|
| 2562 | + function (&$a, $key, $t) { |
|
| 2563 | + $a = extraire_balises($a, $t); |
|
| 2564 | + }, |
|
| 2565 | + $tag |
|
| 2566 | + ); |
|
| 2567 | + |
|
| 2568 | + return $texte; |
|
| 2569 | + } |
|
| 2570 | + |
|
| 2571 | + if ( |
|
| 2572 | + preg_match_all( |
|
| 2573 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2574 | + $texte, |
|
| 2575 | + $regs, |
|
| 2576 | + PREG_PATTERN_ORDER |
|
| 2577 | + ) |
|
| 2578 | + ) { |
|
| 2579 | + return $regs[0]; |
|
| 2580 | + } else { |
|
| 2581 | + return []; |
|
| 2582 | + } |
|
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | /** |
@@ -2608,11 +2608,11 @@ discard block |
||
| 2608 | 2608 | * - `$def` si on n'a pas transmis de tableau |
| 2609 | 2609 | **/ |
| 2610 | 2610 | function in_any($val, $vals, $def = '') { |
| 2611 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2612 | - $vals = $v; |
|
| 2613 | - } |
|
| 2611 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2612 | + $vals = $v; |
|
| 2613 | + } |
|
| 2614 | 2614 | |
| 2615 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2615 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2616 | 2616 | } |
| 2617 | 2617 | |
| 2618 | 2618 | |
@@ -2633,12 +2633,12 @@ discard block |
||
| 2633 | 2633 | * Résultat du calcul |
| 2634 | 2634 | **/ |
| 2635 | 2635 | function valeur_numerique($expr) { |
| 2636 | - $a = 0; |
|
| 2637 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2638 | - eval("\$a = $expr;"); |
|
| 2639 | - } |
|
| 2636 | + $a = 0; |
|
| 2637 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2638 | + eval("\$a = $expr;"); |
|
| 2639 | + } |
|
| 2640 | 2640 | |
| 2641 | - return intval($a); |
|
| 2641 | + return intval($a); |
|
| 2642 | 2642 | } |
| 2643 | 2643 | |
| 2644 | 2644 | /** |
@@ -2657,7 +2657,7 @@ discard block |
||
| 2657 | 2657 | * Retourne `$a*$b/$c` |
| 2658 | 2658 | **/ |
| 2659 | 2659 | function regledetrois($a, $b, $c) { |
| 2660 | - return round($a * $b / $c); |
|
| 2660 | + return round($a * $b / $c); |
|
| 2661 | 2661 | } |
| 2662 | 2662 | |
| 2663 | 2663 | |
@@ -2680,79 +2680,79 @@ discard block |
||
| 2680 | 2680 | * @return string Suite de champs input hidden |
| 2681 | 2681 | **/ |
| 2682 | 2682 | function form_hidden(?string $action = ''): string { |
| 2683 | - $action ??= ''; |
|
| 2684 | - |
|
| 2685 | - $contexte = []; |
|
| 2686 | - include_spip('inc/urls'); |
|
| 2687 | - if ( |
|
| 2688 | - $p = urls_decoder_url($action, '') |
|
| 2689 | - and reset($p) |
|
| 2690 | - ) { |
|
| 2691 | - $fond = array_shift($p); |
|
| 2692 | - if ($fond != '404') { |
|
| 2693 | - $contexte = array_shift($p); |
|
| 2694 | - $contexte['page'] = $fond; |
|
| 2695 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2696 | - } |
|
| 2697 | - } |
|
| 2698 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2699 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2700 | - unset($contexte['type']); |
|
| 2701 | - } |
|
| 2702 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2703 | - unset($contexte['type-page']); |
|
| 2704 | - } |
|
| 2705 | - |
|
| 2706 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2707 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2708 | - $values = []; |
|
| 2709 | - |
|
| 2710 | - // d'abord avec celles de l'url |
|
| 2711 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2712 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2713 | - $c = explode('=', $c, 2); |
|
| 2714 | - $var = array_shift($c); |
|
| 2715 | - $val = array_shift($c) ?? ''; |
|
| 2716 | - if ($var) { |
|
| 2717 | - $val = rawurldecode($val); |
|
| 2718 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2719 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2720 | - $values[] = [$var, $val]; |
|
| 2721 | - } else { |
|
| 2722 | - if (!isset($values[$var])) { |
|
| 2723 | - $values[$var] = [$var, $val]; |
|
| 2724 | - } |
|
| 2725 | - } |
|
| 2726 | - } |
|
| 2727 | - } |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2731 | - foreach ($contexte as $var => $val) { |
|
| 2732 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2733 | - $values[] = [$var, $val]; |
|
| 2734 | - } else { |
|
| 2735 | - if (!isset($values[$var])) { |
|
| 2736 | - $values[$var] = [$var, $val]; |
|
| 2737 | - } |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - |
|
| 2741 | - // puis on rassemble le tout |
|
| 2742 | - $hidden = []; |
|
| 2743 | - foreach ($values as $value) { |
|
| 2744 | - [$var, $val] = $value; |
|
| 2745 | - $hidden[] = '<input name="' |
|
| 2746 | - . entites_html($var) |
|
| 2747 | - . '"' |
|
| 2748 | - . (is_null($val) |
|
| 2749 | - ? '' |
|
| 2750 | - : ' value="' . entites_html($val) . '"' |
|
| 2751 | - ) |
|
| 2752 | - . ' type="hidden"' . "\n/>"; |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - return join('', $hidden); |
|
| 2683 | + $action ??= ''; |
|
| 2684 | + |
|
| 2685 | + $contexte = []; |
|
| 2686 | + include_spip('inc/urls'); |
|
| 2687 | + if ( |
|
| 2688 | + $p = urls_decoder_url($action, '') |
|
| 2689 | + and reset($p) |
|
| 2690 | + ) { |
|
| 2691 | + $fond = array_shift($p); |
|
| 2692 | + if ($fond != '404') { |
|
| 2693 | + $contexte = array_shift($p); |
|
| 2694 | + $contexte['page'] = $fond; |
|
| 2695 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2696 | + } |
|
| 2697 | + } |
|
| 2698 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2699 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2700 | + unset($contexte['type']); |
|
| 2701 | + } |
|
| 2702 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2703 | + unset($contexte['type-page']); |
|
| 2704 | + } |
|
| 2705 | + |
|
| 2706 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2707 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2708 | + $values = []; |
|
| 2709 | + |
|
| 2710 | + // d'abord avec celles de l'url |
|
| 2711 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2712 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2713 | + $c = explode('=', $c, 2); |
|
| 2714 | + $var = array_shift($c); |
|
| 2715 | + $val = array_shift($c) ?? ''; |
|
| 2716 | + if ($var) { |
|
| 2717 | + $val = rawurldecode($val); |
|
| 2718 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2719 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2720 | + $values[] = [$var, $val]; |
|
| 2721 | + } else { |
|
| 2722 | + if (!isset($values[$var])) { |
|
| 2723 | + $values[$var] = [$var, $val]; |
|
| 2724 | + } |
|
| 2725 | + } |
|
| 2726 | + } |
|
| 2727 | + } |
|
| 2728 | + } |
|
| 2729 | + |
|
| 2730 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2731 | + foreach ($contexte as $var => $val) { |
|
| 2732 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2733 | + $values[] = [$var, $val]; |
|
| 2734 | + } else { |
|
| 2735 | + if (!isset($values[$var])) { |
|
| 2736 | + $values[$var] = [$var, $val]; |
|
| 2737 | + } |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + |
|
| 2741 | + // puis on rassemble le tout |
|
| 2742 | + $hidden = []; |
|
| 2743 | + foreach ($values as $value) { |
|
| 2744 | + [$var, $val] = $value; |
|
| 2745 | + $hidden[] = '<input name="' |
|
| 2746 | + . entites_html($var) |
|
| 2747 | + . '"' |
|
| 2748 | + . (is_null($val) |
|
| 2749 | + ? '' |
|
| 2750 | + : ' value="' . entites_html($val) . '"' |
|
| 2751 | + ) |
|
| 2752 | + . ' type="hidden"' . "\n/>"; |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + return join('', $hidden); |
|
| 2756 | 2756 | } |
| 2757 | 2757 | |
| 2758 | 2758 | |
@@ -2774,7 +2774,7 @@ discard block |
||
| 2774 | 2774 | * - la première valeur du tableau sinon. |
| 2775 | 2775 | **/ |
| 2776 | 2776 | function filtre_reset($array) { |
| 2777 | - return !is_array($array) ? null : reset($array); |
|
| 2777 | + return !is_array($array) ? null : reset($array); |
|
| 2778 | 2778 | } |
| 2779 | 2779 | |
| 2780 | 2780 | /** |
@@ -2795,7 +2795,7 @@ discard block |
||
| 2795 | 2795 | * - la dernière valeur du tableau sinon. |
| 2796 | 2796 | **/ |
| 2797 | 2797 | function filtre_end($array) { |
| 2798 | - return !is_array($array) ? null : end($array); |
|
| 2798 | + return !is_array($array) ? null : end($array); |
|
| 2799 | 2799 | } |
| 2800 | 2800 | |
| 2801 | 2801 | /** |
@@ -2815,11 +2815,11 @@ discard block |
||
| 2815 | 2815 | * |
| 2816 | 2816 | **/ |
| 2817 | 2817 | function filtre_push($array, $val) { |
| 2818 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2819 | - return ''; |
|
| 2820 | - } |
|
| 2818 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2819 | + return ''; |
|
| 2820 | + } |
|
| 2821 | 2821 | |
| 2822 | - return $array; |
|
| 2822 | + return $array; |
|
| 2823 | 2823 | } |
| 2824 | 2824 | |
| 2825 | 2825 | /** |
@@ -2838,7 +2838,7 @@ discard block |
||
| 2838 | 2838 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2839 | 2839 | **/ |
| 2840 | 2840 | function filtre_find($array, $val) { |
| 2841 | - return (is_array($array) and in_array($val, $array)); |
|
| 2841 | + return (is_array($array) and in_array($val, $array)); |
|
| 2842 | 2842 | } |
| 2843 | 2843 | |
| 2844 | 2844 | |
@@ -2855,13 +2855,13 @@ discard block |
||
| 2855 | 2855 | * Contenu avec urls en absolus |
| 2856 | 2856 | **/ |
| 2857 | 2857 | function urls_absolues_css($contenu, $source) { |
| 2858 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2858 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2859 | 2859 | |
| 2860 | - return preg_replace_callback( |
|
| 2861 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2862 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2863 | - $contenu |
|
| 2864 | - ); |
|
| 2860 | + return preg_replace_callback( |
|
| 2861 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2862 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2863 | + $contenu |
|
| 2864 | + ); |
|
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | |
@@ -2890,119 +2890,119 @@ discard block |
||
| 2890 | 2890 | * Chemin du fichier CSS inversé |
| 2891 | 2891 | **/ |
| 2892 | 2892 | function direction_css($css, $voulue = '') { |
| 2893 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2894 | - return $css; |
|
| 2895 | - } |
|
| 2896 | - include_spip('inc/lang'); |
|
| 2897 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2898 | - if ($voulue = strtolower($voulue)) { |
|
| 2899 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2900 | - $voulue = lang_dir($voulue); |
|
| 2901 | - } |
|
| 2902 | - } else { |
|
| 2903 | - $voulue = lang_dir(); |
|
| 2904 | - } |
|
| 2905 | - |
|
| 2906 | - $r = count($r) > 1; |
|
| 2907 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2908 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2909 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2910 | - |
|
| 2911 | - if ($voulue == $dir) { |
|
| 2912 | - return $css; |
|
| 2913 | - } |
|
| 2914 | - |
|
| 2915 | - if ( |
|
| 2916 | - // url absolue |
|
| 2917 | - preg_match(',^https?:,i', $css) |
|
| 2918 | - // ou qui contient un ? |
|
| 2919 | - or (($p = strpos($css, '?')) !== false) |
|
| 2920 | - ) { |
|
| 2921 | - $distant = true; |
|
| 2922 | - $cssf = parse_url($css); |
|
| 2923 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2924 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2925 | - } else { |
|
| 2926 | - $distant = false; |
|
| 2927 | - $cssf = $css; |
|
| 2928 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2929 | - //propose (rien a faire dans ce cas) |
|
| 2930 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2931 | - if (@file_exists($f)) { |
|
| 2932 | - return $f; |
|
| 2933 | - } |
|
| 2934 | - } |
|
| 2935 | - |
|
| 2936 | - // 2. |
|
| 2937 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2938 | - $f = $dir_var |
|
| 2939 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2940 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2941 | - |
|
| 2942 | - // la css peut etre distante (url absolue !) |
|
| 2943 | - if ($distant) { |
|
| 2944 | - include_spip('inc/distant'); |
|
| 2945 | - $res = recuperer_url($css); |
|
| 2946 | - if (!$res or !$contenu = $res['page']) { |
|
| 2947 | - return $css; |
|
| 2948 | - } |
|
| 2949 | - } else { |
|
| 2950 | - if ( |
|
| 2951 | - (@filemtime($f) > @filemtime($css)) |
|
| 2952 | - and (_VAR_MODE != 'recalcul') |
|
| 2953 | - ) { |
|
| 2954 | - return $f; |
|
| 2955 | - } |
|
| 2956 | - if (!lire_fichier($css, $contenu)) { |
|
| 2957 | - return $css; |
|
| 2958 | - } |
|
| 2959 | - } |
|
| 2960 | - |
|
| 2961 | - |
|
| 2962 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2963 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2964 | - $parser = new csstidy(); |
|
| 2965 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2966 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2967 | - $parser->parse($contenu); |
|
| 2968 | - |
|
| 2969 | - $contenu = $parser->print->plain(); |
|
| 2970 | - |
|
| 2971 | - |
|
| 2972 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2973 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2974 | - $src = []; |
|
| 2975 | - $src_direction_css = []; |
|
| 2976 | - $src_faux_abs = []; |
|
| 2977 | - $d = dirname($css); |
|
| 2978 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2979 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2980 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2981 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2982 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2983 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2984 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2985 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2986 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2987 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2988 | - } |
|
| 2989 | - $src[] = $regs[0][$k]; |
|
| 2990 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2991 | - } |
|
| 2992 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2993 | - |
|
| 2994 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2995 | - |
|
| 2996 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2997 | - if (count($src_faux_abs)) { |
|
| 2998 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2999 | - } |
|
| 3000 | - |
|
| 3001 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3002 | - return $css; |
|
| 3003 | - } |
|
| 3004 | - |
|
| 3005 | - return $f; |
|
| 2893 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2894 | + return $css; |
|
| 2895 | + } |
|
| 2896 | + include_spip('inc/lang'); |
|
| 2897 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2898 | + if ($voulue = strtolower($voulue)) { |
|
| 2899 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2900 | + $voulue = lang_dir($voulue); |
|
| 2901 | + } |
|
| 2902 | + } else { |
|
| 2903 | + $voulue = lang_dir(); |
|
| 2904 | + } |
|
| 2905 | + |
|
| 2906 | + $r = count($r) > 1; |
|
| 2907 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2908 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2909 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2910 | + |
|
| 2911 | + if ($voulue == $dir) { |
|
| 2912 | + return $css; |
|
| 2913 | + } |
|
| 2914 | + |
|
| 2915 | + if ( |
|
| 2916 | + // url absolue |
|
| 2917 | + preg_match(',^https?:,i', $css) |
|
| 2918 | + // ou qui contient un ? |
|
| 2919 | + or (($p = strpos($css, '?')) !== false) |
|
| 2920 | + ) { |
|
| 2921 | + $distant = true; |
|
| 2922 | + $cssf = parse_url($css); |
|
| 2923 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2924 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2925 | + } else { |
|
| 2926 | + $distant = false; |
|
| 2927 | + $cssf = $css; |
|
| 2928 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2929 | + //propose (rien a faire dans ce cas) |
|
| 2930 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2931 | + if (@file_exists($f)) { |
|
| 2932 | + return $f; |
|
| 2933 | + } |
|
| 2934 | + } |
|
| 2935 | + |
|
| 2936 | + // 2. |
|
| 2937 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2938 | + $f = $dir_var |
|
| 2939 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2940 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2941 | + |
|
| 2942 | + // la css peut etre distante (url absolue !) |
|
| 2943 | + if ($distant) { |
|
| 2944 | + include_spip('inc/distant'); |
|
| 2945 | + $res = recuperer_url($css); |
|
| 2946 | + if (!$res or !$contenu = $res['page']) { |
|
| 2947 | + return $css; |
|
| 2948 | + } |
|
| 2949 | + } else { |
|
| 2950 | + if ( |
|
| 2951 | + (@filemtime($f) > @filemtime($css)) |
|
| 2952 | + and (_VAR_MODE != 'recalcul') |
|
| 2953 | + ) { |
|
| 2954 | + return $f; |
|
| 2955 | + } |
|
| 2956 | + if (!lire_fichier($css, $contenu)) { |
|
| 2957 | + return $css; |
|
| 2958 | + } |
|
| 2959 | + } |
|
| 2960 | + |
|
| 2961 | + |
|
| 2962 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2963 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2964 | + $parser = new csstidy(); |
|
| 2965 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2966 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2967 | + $parser->parse($contenu); |
|
| 2968 | + |
|
| 2969 | + $contenu = $parser->print->plain(); |
|
| 2970 | + |
|
| 2971 | + |
|
| 2972 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2973 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2974 | + $src = []; |
|
| 2975 | + $src_direction_css = []; |
|
| 2976 | + $src_faux_abs = []; |
|
| 2977 | + $d = dirname($css); |
|
| 2978 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2979 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2980 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2981 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2982 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2983 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2984 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2985 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2986 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2987 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2988 | + } |
|
| 2989 | + $src[] = $regs[0][$k]; |
|
| 2990 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2991 | + } |
|
| 2992 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2993 | + |
|
| 2994 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2995 | + |
|
| 2996 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2997 | + if (count($src_faux_abs)) { |
|
| 2998 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2999 | + } |
|
| 3000 | + |
|
| 3001 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3002 | + return $css; |
|
| 3003 | + } |
|
| 3004 | + |
|
| 3005 | + return $f; |
|
| 3006 | 3006 | } |
| 3007 | 3007 | |
| 3008 | 3008 | |
@@ -3025,46 +3025,46 @@ discard block |
||
| 3025 | 3025 | * - Chemin ou URL du fichier CSS source sinon. |
| 3026 | 3026 | **/ |
| 3027 | 3027 | function url_absolue_css($css) { |
| 3028 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3029 | - return $css; |
|
| 3030 | - } |
|
| 3028 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3029 | + return $css; |
|
| 3030 | + } |
|
| 3031 | 3031 | |
| 3032 | - $url_absolue_css = url_absolue($css); |
|
| 3032 | + $url_absolue_css = url_absolue($css); |
|
| 3033 | 3033 | |
| 3034 | - $f = basename($css, '.css'); |
|
| 3035 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3036 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3037 | - . '.css'; |
|
| 3034 | + $f = basename($css, '.css'); |
|
| 3035 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3036 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3037 | + . '.css'; |
|
| 3038 | 3038 | |
| 3039 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3040 | - return $f; |
|
| 3041 | - } |
|
| 3039 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3040 | + return $f; |
|
| 3041 | + } |
|
| 3042 | 3042 | |
| 3043 | - if ($url_absolue_css == $css) { |
|
| 3044 | - if ( |
|
| 3045 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3046 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3047 | - ) { |
|
| 3048 | - include_spip('inc/distant'); |
|
| 3049 | - $contenu = recuperer_url($css); |
|
| 3050 | - $contenu = $contenu['page'] ?? ''; |
|
| 3051 | - if (!$contenu) { |
|
| 3052 | - return $css; |
|
| 3053 | - } |
|
| 3054 | - } |
|
| 3055 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3056 | - return $css; |
|
| 3057 | - } |
|
| 3043 | + if ($url_absolue_css == $css) { |
|
| 3044 | + if ( |
|
| 3045 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3046 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3047 | + ) { |
|
| 3048 | + include_spip('inc/distant'); |
|
| 3049 | + $contenu = recuperer_url($css); |
|
| 3050 | + $contenu = $contenu['page'] ?? ''; |
|
| 3051 | + if (!$contenu) { |
|
| 3052 | + return $css; |
|
| 3053 | + } |
|
| 3054 | + } |
|
| 3055 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3056 | + return $css; |
|
| 3057 | + } |
|
| 3058 | 3058 | |
| 3059 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3060 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3059 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3060 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3061 | 3061 | |
| 3062 | - // ecrire la css |
|
| 3063 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3064 | - return $css; |
|
| 3065 | - } |
|
| 3062 | + // ecrire la css |
|
| 3063 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3064 | + return $css; |
|
| 3065 | + } |
|
| 3066 | 3066 | |
| 3067 | - return $f; |
|
| 3067 | + return $f; |
|
| 3068 | 3068 | } |
| 3069 | 3069 | |
| 3070 | 3070 | |
@@ -3098,24 +3098,24 @@ discard block |
||
| 3098 | 3098 | * Valeur trouvée ou valeur par défaut. |
| 3099 | 3099 | **/ |
| 3100 | 3100 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3101 | - foreach (explode('/', $cle) as $k) { |
|
| 3102 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3101 | + foreach (explode('/', $cle) as $k) { |
|
| 3102 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3103 | 3103 | |
| 3104 | - if (is_object($table)) { |
|
| 3105 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3106 | - } elseif (is_array($table)) { |
|
| 3107 | - if ($conserver_null) { |
|
| 3108 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3109 | - } else { |
|
| 3110 | - $table = ($table[$k] ?? $defaut); |
|
| 3111 | - } |
|
| 3112 | - } else { |
|
| 3113 | - $table = $defaut; |
|
| 3114 | - break; |
|
| 3115 | - } |
|
| 3116 | - } |
|
| 3104 | + if (is_object($table)) { |
|
| 3105 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3106 | + } elseif (is_array($table)) { |
|
| 3107 | + if ($conserver_null) { |
|
| 3108 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3109 | + } else { |
|
| 3110 | + $table = ($table[$k] ?? $defaut); |
|
| 3111 | + } |
|
| 3112 | + } else { |
|
| 3113 | + $table = $defaut; |
|
| 3114 | + break; |
|
| 3115 | + } |
|
| 3116 | + } |
|
| 3117 | 3117 | |
| 3118 | - return $table; |
|
| 3118 | + return $table; |
|
| 3119 | 3119 | } |
| 3120 | 3120 | |
| 3121 | 3121 | /** |
@@ -3148,22 +3148,22 @@ discard block |
||
| 3148 | 3148 | * - string : expression trouvée. |
| 3149 | 3149 | **/ |
| 3150 | 3150 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3151 | - if (intval($modif) and $capte == 0) { |
|
| 3152 | - $capte = $modif; |
|
| 3153 | - $modif = 'UuimsS'; |
|
| 3154 | - } |
|
| 3155 | - $expression = str_replace('\/', '/', $expression); |
|
| 3156 | - $expression = str_replace('/', '\/', $expression); |
|
| 3151 | + if (intval($modif) and $capte == 0) { |
|
| 3152 | + $capte = $modif; |
|
| 3153 | + $modif = 'UuimsS'; |
|
| 3154 | + } |
|
| 3155 | + $expression = str_replace('\/', '/', $expression); |
|
| 3156 | + $expression = str_replace('/', '\/', $expression); |
|
| 3157 | 3157 | |
| 3158 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3159 | - if (isset($r[$capte])) { |
|
| 3160 | - return $r[$capte]; |
|
| 3161 | - } else { |
|
| 3162 | - return true; |
|
| 3163 | - } |
|
| 3164 | - } |
|
| 3158 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3159 | + if (isset($r[$capte])) { |
|
| 3160 | + return $r[$capte]; |
|
| 3161 | + } else { |
|
| 3162 | + return true; |
|
| 3163 | + } |
|
| 3164 | + } |
|
| 3165 | 3165 | |
| 3166 | - return false; |
|
| 3166 | + return false; |
|
| 3167 | 3167 | } |
| 3168 | 3168 | |
| 3169 | 3169 | |
@@ -3190,14 +3190,14 @@ discard block |
||
| 3190 | 3190 | * Texte |
| 3191 | 3191 | **/ |
| 3192 | 3192 | function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string { |
| 3193 | - if (null === $texte) { |
|
| 3194 | - return ''; |
|
| 3195 | - } |
|
| 3193 | + if (null === $texte) { |
|
| 3194 | + return ''; |
|
| 3195 | + } |
|
| 3196 | 3196 | |
| 3197 | - $expression = str_replace('\/', '/', $expression); |
|
| 3198 | - $expression = str_replace('/', '\/', $expression); |
|
| 3197 | + $expression = str_replace('\/', '/', $expression); |
|
| 3198 | + $expression = str_replace('/', '\/', $expression); |
|
| 3199 | 3199 | |
| 3200 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3200 | + return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3201 | 3201 | } |
| 3202 | 3202 | |
| 3203 | 3203 | |
@@ -3215,25 +3215,25 @@ discard block |
||
| 3215 | 3215 | **/ |
| 3216 | 3216 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3217 | 3217 | |
| 3218 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3219 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3218 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3219 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3220 | 3220 | |
| 3221 | - if ( |
|
| 3222 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3223 | - and preg_match_all( |
|
| 3224 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3225 | - $t, |
|
| 3226 | - $matches, |
|
| 3227 | - PREG_PATTERN_ORDER |
|
| 3228 | - ) |
|
| 3229 | - ) { |
|
| 3230 | - if (!isset($doublons['documents'])) { |
|
| 3231 | - $doublons['documents'] = ''; |
|
| 3232 | - } |
|
| 3233 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3234 | - } |
|
| 3221 | + if ( |
|
| 3222 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3223 | + and preg_match_all( |
|
| 3224 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3225 | + $t, |
|
| 3226 | + $matches, |
|
| 3227 | + PREG_PATTERN_ORDER |
|
| 3228 | + ) |
|
| 3229 | + ) { |
|
| 3230 | + if (!isset($doublons['documents'])) { |
|
| 3231 | + $doublons['documents'] = ''; |
|
| 3232 | + } |
|
| 3233 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3234 | + } |
|
| 3235 | 3235 | |
| 3236 | - return $letexte; |
|
| 3236 | + return $letexte; |
|
| 3237 | 3237 | } |
| 3238 | 3238 | |
| 3239 | 3239 | /** |
@@ -3247,7 +3247,7 @@ discard block |
||
| 3247 | 3247 | * @return string Chaîne vide |
| 3248 | 3248 | **/ |
| 3249 | 3249 | function vide($texte) { |
| 3250 | - return ''; |
|
| 3250 | + return ''; |
|
| 3251 | 3251 | } |
| 3252 | 3252 | |
| 3253 | 3253 | // |
@@ -3276,23 +3276,23 @@ discard block |
||
| 3276 | 3276 | * Code HTML résultant |
| 3277 | 3277 | **/ |
| 3278 | 3278 | function env_to_params($env, $ignore_params = []) { |
| 3279 | - $ignore_params = array_merge( |
|
| 3280 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3281 | - $ignore_params |
|
| 3282 | - ); |
|
| 3283 | - if (!is_array($env)) { |
|
| 3284 | - $env = unserialize($env); |
|
| 3285 | - } |
|
| 3286 | - $texte = ''; |
|
| 3287 | - if ($env) { |
|
| 3288 | - foreach ($env as $i => $j) { |
|
| 3289 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3290 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3291 | - } |
|
| 3292 | - } |
|
| 3293 | - } |
|
| 3294 | - |
|
| 3295 | - return $texte; |
|
| 3279 | + $ignore_params = array_merge( |
|
| 3280 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3281 | + $ignore_params |
|
| 3282 | + ); |
|
| 3283 | + if (!is_array($env)) { |
|
| 3284 | + $env = unserialize($env); |
|
| 3285 | + } |
|
| 3286 | + $texte = ''; |
|
| 3287 | + if ($env) { |
|
| 3288 | + foreach ($env as $i => $j) { |
|
| 3289 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3290 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3291 | + } |
|
| 3292 | + } |
|
| 3293 | + } |
|
| 3294 | + |
|
| 3295 | + return $texte; |
|
| 3296 | 3296 | } |
| 3297 | 3297 | |
| 3298 | 3298 | /** |
@@ -3315,23 +3315,23 @@ discard block |
||
| 3315 | 3315 | * Code HTML résultant |
| 3316 | 3316 | **/ |
| 3317 | 3317 | function env_to_attributs($env, $ignore_params = []) { |
| 3318 | - $ignore_params = array_merge( |
|
| 3319 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3320 | - $ignore_params |
|
| 3321 | - ); |
|
| 3322 | - if (!is_array($env)) { |
|
| 3323 | - $env = unserialize($env); |
|
| 3324 | - } |
|
| 3325 | - $texte = ''; |
|
| 3326 | - if ($env) { |
|
| 3327 | - foreach ($env as $i => $j) { |
|
| 3328 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3329 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3330 | - } |
|
| 3331 | - } |
|
| 3332 | - } |
|
| 3318 | + $ignore_params = array_merge( |
|
| 3319 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3320 | + $ignore_params |
|
| 3321 | + ); |
|
| 3322 | + if (!is_array($env)) { |
|
| 3323 | + $env = unserialize($env); |
|
| 3324 | + } |
|
| 3325 | + $texte = ''; |
|
| 3326 | + if ($env) { |
|
| 3327 | + foreach ($env as $i => $j) { |
|
| 3328 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3329 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3330 | + } |
|
| 3331 | + } |
|
| 3332 | + } |
|
| 3333 | 3333 | |
| 3334 | - return $texte; |
|
| 3334 | + return $texte; |
|
| 3335 | 3335 | } |
| 3336 | 3336 | |
| 3337 | 3337 | |
@@ -3349,7 +3349,7 @@ discard block |
||
| 3349 | 3349 | * @return string Chaînes concaténés |
| 3350 | 3350 | **/ |
| 3351 | 3351 | function concat(...$args): string { |
| 3352 | - return join('', $args); |
|
| 3352 | + return join('', $args); |
|
| 3353 | 3353 | } |
| 3354 | 3354 | |
| 3355 | 3355 | |
@@ -3369,23 +3369,23 @@ discard block |
||
| 3369 | 3369 | * Contenu du ou des fichiers, concaténé |
| 3370 | 3370 | **/ |
| 3371 | 3371 | function charge_scripts($files, $script = true) { |
| 3372 | - $flux = ''; |
|
| 3373 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3374 | - if (!is_string($file)) { |
|
| 3375 | - continue; |
|
| 3376 | - } |
|
| 3377 | - if ($script) { |
|
| 3378 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3379 | - } |
|
| 3380 | - if ($file) { |
|
| 3381 | - $path = find_in_path($file); |
|
| 3382 | - if ($path) { |
|
| 3383 | - $flux .= spip_file_get_contents($path); |
|
| 3384 | - } |
|
| 3385 | - } |
|
| 3386 | - } |
|
| 3387 | - |
|
| 3388 | - return $flux; |
|
| 3372 | + $flux = ''; |
|
| 3373 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3374 | + if (!is_string($file)) { |
|
| 3375 | + continue; |
|
| 3376 | + } |
|
| 3377 | + if ($script) { |
|
| 3378 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3379 | + } |
|
| 3380 | + if ($file) { |
|
| 3381 | + $path = find_in_path($file); |
|
| 3382 | + if ($path) { |
|
| 3383 | + $flux .= spip_file_get_contents($path); |
|
| 3384 | + } |
|
| 3385 | + } |
|
| 3386 | + } |
|
| 3387 | + |
|
| 3388 | + return $flux; |
|
| 3389 | 3389 | } |
| 3390 | 3390 | |
| 3391 | 3391 | /** |
@@ -3396,22 +3396,22 @@ discard block |
||
| 3396 | 3396 | * @return string |
| 3397 | 3397 | */ |
| 3398 | 3398 | function http_img_variante_svg_si_possible($img_file) { |
| 3399 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3400 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3401 | - if ( |
|
| 3402 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3403 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3404 | - and file_exists($variante_svg_generique) |
|
| 3405 | - ) { |
|
| 3406 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3407 | - $img_file = $variante_svg_size; |
|
| 3408 | - } |
|
| 3409 | - else { |
|
| 3410 | - $img_file = $variante_svg_generique; |
|
| 3411 | - } |
|
| 3412 | - } |
|
| 3399 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3400 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3401 | + if ( |
|
| 3402 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3403 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3404 | + and file_exists($variante_svg_generique) |
|
| 3405 | + ) { |
|
| 3406 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3407 | + $img_file = $variante_svg_size; |
|
| 3408 | + } |
|
| 3409 | + else { |
|
| 3410 | + $img_file = $variante_svg_generique; |
|
| 3411 | + } |
|
| 3412 | + } |
|
| 3413 | 3413 | |
| 3414 | - return $img_file; |
|
| 3414 | + return $img_file; |
|
| 3415 | 3415 | } |
| 3416 | 3416 | |
| 3417 | 3417 | /** |
@@ -3432,54 +3432,54 @@ discard block |
||
| 3432 | 3432 | */ |
| 3433 | 3433 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3434 | 3434 | |
| 3435 | - $img_file = $img; |
|
| 3436 | - if ($p = strpos($img_file, '?')) { |
|
| 3437 | - $img_file = substr($img_file, 0, $p); |
|
| 3438 | - } |
|
| 3439 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3440 | - $img_file = chemin_image($img); |
|
| 3441 | - } |
|
| 3442 | - else { |
|
| 3443 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3444 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3445 | - } |
|
| 3446 | - } |
|
| 3447 | - if (stripos($atts, 'width') === false) { |
|
| 3448 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3449 | - if ( |
|
| 3450 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3451 | - or $options['utiliser_suffixe_size'] == true |
|
| 3452 | - or str_contains($img_file, '-xx.svg')) |
|
| 3453 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3454 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3455 | - ) { |
|
| 3456 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3457 | - } else { |
|
| 3458 | - $taille = taille_image($img_file); |
|
| 3459 | - [$hauteur, $largeur] = $taille; |
|
| 3460 | - if (!$hauteur or !$largeur) { |
|
| 3461 | - return ''; |
|
| 3462 | - } |
|
| 3463 | - } |
|
| 3464 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3465 | - } |
|
| 3466 | - |
|
| 3467 | - if (file_exists($img_file)) { |
|
| 3468 | - $img_file = timestamp($img_file); |
|
| 3469 | - } |
|
| 3470 | - if ($alt === false) { |
|
| 3471 | - $alt = ''; |
|
| 3472 | - } |
|
| 3473 | - elseif ($alt or $alt === '') { |
|
| 3474 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3475 | - } |
|
| 3476 | - else { |
|
| 3477 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3478 | - } |
|
| 3479 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3480 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3481 | - . ' ' . ltrim($atts) |
|
| 3482 | - . ' />'; |
|
| 3435 | + $img_file = $img; |
|
| 3436 | + if ($p = strpos($img_file, '?')) { |
|
| 3437 | + $img_file = substr($img_file, 0, $p); |
|
| 3438 | + } |
|
| 3439 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3440 | + $img_file = chemin_image($img); |
|
| 3441 | + } |
|
| 3442 | + else { |
|
| 3443 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3444 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3445 | + } |
|
| 3446 | + } |
|
| 3447 | + if (stripos($atts, 'width') === false) { |
|
| 3448 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3449 | + if ( |
|
| 3450 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3451 | + or $options['utiliser_suffixe_size'] == true |
|
| 3452 | + or str_contains($img_file, '-xx.svg')) |
|
| 3453 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3454 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3455 | + ) { |
|
| 3456 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3457 | + } else { |
|
| 3458 | + $taille = taille_image($img_file); |
|
| 3459 | + [$hauteur, $largeur] = $taille; |
|
| 3460 | + if (!$hauteur or !$largeur) { |
|
| 3461 | + return ''; |
|
| 3462 | + } |
|
| 3463 | + } |
|
| 3464 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3465 | + } |
|
| 3466 | + |
|
| 3467 | + if (file_exists($img_file)) { |
|
| 3468 | + $img_file = timestamp($img_file); |
|
| 3469 | + } |
|
| 3470 | + if ($alt === false) { |
|
| 3471 | + $alt = ''; |
|
| 3472 | + } |
|
| 3473 | + elseif ($alt or $alt === '') { |
|
| 3474 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3475 | + } |
|
| 3476 | + else { |
|
| 3477 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3478 | + } |
|
| 3479 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3480 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3481 | + . ' ' . ltrim($atts) |
|
| 3482 | + . ' />'; |
|
| 3483 | 3483 | } |
| 3484 | 3484 | |
| 3485 | 3485 | /** |
@@ -3491,70 +3491,70 @@ discard block |
||
| 3491 | 3491 | * @return string |
| 3492 | 3492 | */ |
| 3493 | 3493 | function http_style_background($img, $att = '', $size = null) { |
| 3494 | - if ($size and is_numeric($size)) { |
|
| 3495 | - $size = trim($size) . 'px'; |
|
| 3496 | - } |
|
| 3497 | - return " style='background" . |
|
| 3498 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3499 | - . ($size ? "background-size:{$size};" : '') |
|
| 3500 | - . "'"; |
|
| 3494 | + if ($size and is_numeric($size)) { |
|
| 3495 | + $size = trim($size) . 'px'; |
|
| 3496 | + } |
|
| 3497 | + return " style='background" . |
|
| 3498 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3499 | + . ($size ? "background-size:{$size};" : '') |
|
| 3500 | + . "'"; |
|
| 3501 | 3501 | } |
| 3502 | 3502 | |
| 3503 | 3503 | |
| 3504 | 3504 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3505 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3506 | - while (is_null(end($args)) and count($args)) { |
|
| 3507 | - array_pop($args); |
|
| 3508 | - } |
|
| 3509 | - if (!count($args)) { |
|
| 3510 | - return [null, null, null]; |
|
| 3511 | - } |
|
| 3512 | - if (count($args) < 3) { |
|
| 3513 | - $maybe_size = array_pop($args); |
|
| 3514 | - // @2x |
|
| 3515 | - // @1.5x |
|
| 3516 | - // 512 |
|
| 3517 | - // 512x* |
|
| 3518 | - // 512x300 |
|
| 3519 | - if ( |
|
| 3520 | - !strlen($maybe_size) |
|
| 3521 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3522 | - ) { |
|
| 3523 | - $args[] = $maybe_size; |
|
| 3524 | - $maybe_size = null; |
|
| 3525 | - } |
|
| 3526 | - while (count($args) < 2) { |
|
| 3527 | - $args[] = null; // default alt or class |
|
| 3528 | - } |
|
| 3529 | - $args[] = $maybe_size; |
|
| 3530 | - } |
|
| 3531 | - return $args; |
|
| 3505 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3506 | + while (is_null(end($args)) and count($args)) { |
|
| 3507 | + array_pop($args); |
|
| 3508 | + } |
|
| 3509 | + if (!count($args)) { |
|
| 3510 | + return [null, null, null]; |
|
| 3511 | + } |
|
| 3512 | + if (count($args) < 3) { |
|
| 3513 | + $maybe_size = array_pop($args); |
|
| 3514 | + // @2x |
|
| 3515 | + // @1.5x |
|
| 3516 | + // 512 |
|
| 3517 | + // 512x* |
|
| 3518 | + // 512x300 |
|
| 3519 | + if ( |
|
| 3520 | + !strlen($maybe_size) |
|
| 3521 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3522 | + ) { |
|
| 3523 | + $args[] = $maybe_size; |
|
| 3524 | + $maybe_size = null; |
|
| 3525 | + } |
|
| 3526 | + while (count($args) < 2) { |
|
| 3527 | + $args[] = null; // default alt or class |
|
| 3528 | + } |
|
| 3529 | + $args[] = $maybe_size; |
|
| 3530 | + } |
|
| 3531 | + return $args; |
|
| 3532 | 3532 | } |
| 3533 | 3533 | |
| 3534 | 3534 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3535 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3536 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3537 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3538 | - [$h, $w] = taille_image($img); |
|
| 3539 | - $height = intval(round($h / $coef)); |
|
| 3540 | - $width = intval(round($w / $coef)); |
|
| 3541 | - } |
|
| 3542 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3543 | - else { |
|
| 3544 | - $size = explode('x', $size, 2); |
|
| 3545 | - $size = array_map('trim', $size); |
|
| 3546 | - $height = $width = intval(array_shift($size)); |
|
| 3547 | - |
|
| 3548 | - if (count($size) and reset($size)) { |
|
| 3549 | - $height = array_shift($size); |
|
| 3550 | - if ($height === '*') { |
|
| 3551 | - [$h, $w] = taille_image($img); |
|
| 3552 | - $height = intval(round($h * $width / $w)); |
|
| 3553 | - } |
|
| 3554 | - } |
|
| 3555 | - } |
|
| 3556 | - |
|
| 3557 | - return [$width, $height]; |
|
| 3535 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3536 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3537 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3538 | + [$h, $w] = taille_image($img); |
|
| 3539 | + $height = intval(round($h / $coef)); |
|
| 3540 | + $width = intval(round($w / $coef)); |
|
| 3541 | + } |
|
| 3542 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3543 | + else { |
|
| 3544 | + $size = explode('x', $size, 2); |
|
| 3545 | + $size = array_map('trim', $size); |
|
| 3546 | + $height = $width = intval(array_shift($size)); |
|
| 3547 | + |
|
| 3548 | + if (count($size) and reset($size)) { |
|
| 3549 | + $height = array_shift($size); |
|
| 3550 | + if ($height === '*') { |
|
| 3551 | + [$h, $w] = taille_image($img); |
|
| 3552 | + $height = intval(round($h * $width / $w)); |
|
| 3553 | + } |
|
| 3554 | + } |
|
| 3555 | + } |
|
| 3556 | + |
|
| 3557 | + return [$width, $height]; |
|
| 3558 | 3558 | } |
| 3559 | 3559 | |
| 3560 | 3560 | /** |
@@ -3590,43 +3590,43 @@ discard block |
||
| 3590 | 3590 | */ |
| 3591 | 3591 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3592 | 3592 | |
| 3593 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3594 | - |
|
| 3595 | - $img = trim((string) $img); |
|
| 3596 | - if (strpos($img, '<img') === 0) { |
|
| 3597 | - if (!is_null($alt)) { |
|
| 3598 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3599 | - } |
|
| 3600 | - if (!is_null($class)) { |
|
| 3601 | - if (strlen($class)) { |
|
| 3602 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3603 | - } |
|
| 3604 | - else { |
|
| 3605 | - $img = vider_attribut($img, 'class'); |
|
| 3606 | - } |
|
| 3607 | - } |
|
| 3608 | - } |
|
| 3609 | - else { |
|
| 3610 | - $img = http_img_pack( |
|
| 3611 | - $img, |
|
| 3612 | - $alt, |
|
| 3613 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3614 | - '', |
|
| 3615 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3616 | - ); |
|
| 3617 | - if (is_null($alt)) { |
|
| 3618 | - $img = vider_attribut($img, 'alt'); |
|
| 3619 | - } |
|
| 3620 | - } |
|
| 3621 | - |
|
| 3622 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3623 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3624 | - |
|
| 3625 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3626 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3627 | - } |
|
| 3628 | - |
|
| 3629 | - return $img; |
|
| 3593 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3594 | + |
|
| 3595 | + $img = trim((string) $img); |
|
| 3596 | + if (strpos($img, '<img') === 0) { |
|
| 3597 | + if (!is_null($alt)) { |
|
| 3598 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3599 | + } |
|
| 3600 | + if (!is_null($class)) { |
|
| 3601 | + if (strlen($class)) { |
|
| 3602 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3603 | + } |
|
| 3604 | + else { |
|
| 3605 | + $img = vider_attribut($img, 'class'); |
|
| 3606 | + } |
|
| 3607 | + } |
|
| 3608 | + } |
|
| 3609 | + else { |
|
| 3610 | + $img = http_img_pack( |
|
| 3611 | + $img, |
|
| 3612 | + $alt, |
|
| 3613 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3614 | + '', |
|
| 3615 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3616 | + ); |
|
| 3617 | + if (is_null($alt)) { |
|
| 3618 | + $img = vider_attribut($img, 'alt'); |
|
| 3619 | + } |
|
| 3620 | + } |
|
| 3621 | + |
|
| 3622 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3623 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3624 | + |
|
| 3625 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3626 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3627 | + } |
|
| 3628 | + |
|
| 3629 | + return $img; |
|
| 3630 | 3630 | } |
| 3631 | 3631 | |
| 3632 | 3632 | |
@@ -3660,80 +3660,80 @@ discard block |
||
| 3660 | 3660 | */ |
| 3661 | 3661 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3662 | 3662 | |
| 3663 | - $svg = null; |
|
| 3664 | - $img = trim($img); |
|
| 3665 | - $img_file = $img; |
|
| 3666 | - if (strpos($img, '<svg') === false) { |
|
| 3667 | - if ($p = strpos($img_file, '?')) { |
|
| 3668 | - $img_file = substr($img_file, 0, $p); |
|
| 3669 | - } |
|
| 3670 | - |
|
| 3671 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3672 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3673 | - if (tester_url_absolue($img_file)) { |
|
| 3674 | - include_spip('inc/distant'); |
|
| 3675 | - $fichier = copie_locale($img_file); |
|
| 3676 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3677 | - } |
|
| 3678 | - |
|
| 3679 | - if ( |
|
| 3680 | - !$img_file |
|
| 3681 | - or !file_exists($img_file) |
|
| 3682 | - or !$svg = file_get_contents($img_file) |
|
| 3683 | - ) { |
|
| 3684 | - return ''; |
|
| 3685 | - } |
|
| 3686 | - } |
|
| 3687 | - |
|
| 3688 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3689 | - return ''; |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3693 | - |
|
| 3694 | - $balise_svg = $match[0]; |
|
| 3695 | - $balise_svg_source = $balise_svg; |
|
| 3696 | - |
|
| 3697 | - // entete XML à supprimer |
|
| 3698 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3699 | - |
|
| 3700 | - // IE est toujours mon ami |
|
| 3701 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3702 | - |
|
| 3703 | - // regler la classe |
|
| 3704 | - if (!is_null($class)) { |
|
| 3705 | - if (strlen($class)) { |
|
| 3706 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3707 | - } |
|
| 3708 | - else { |
|
| 3709 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3710 | - } |
|
| 3711 | - } |
|
| 3712 | - |
|
| 3713 | - // regler le alt |
|
| 3714 | - if ($alt) { |
|
| 3715 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3716 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3717 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3718 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3719 | - $balise_svg .= $title; |
|
| 3720 | - } |
|
| 3721 | - else { |
|
| 3722 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3723 | - } |
|
| 3724 | - |
|
| 3725 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3726 | - |
|
| 3727 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3728 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3729 | - |
|
| 3730 | - if (!function_exists('svg_redimensionner')) { |
|
| 3731 | - include_spip('inc/svg'); |
|
| 3732 | - } |
|
| 3733 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3734 | - } |
|
| 3735 | - |
|
| 3736 | - return $svg; |
|
| 3663 | + $svg = null; |
|
| 3664 | + $img = trim($img); |
|
| 3665 | + $img_file = $img; |
|
| 3666 | + if (strpos($img, '<svg') === false) { |
|
| 3667 | + if ($p = strpos($img_file, '?')) { |
|
| 3668 | + $img_file = substr($img_file, 0, $p); |
|
| 3669 | + } |
|
| 3670 | + |
|
| 3671 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3672 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3673 | + if (tester_url_absolue($img_file)) { |
|
| 3674 | + include_spip('inc/distant'); |
|
| 3675 | + $fichier = copie_locale($img_file); |
|
| 3676 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3677 | + } |
|
| 3678 | + |
|
| 3679 | + if ( |
|
| 3680 | + !$img_file |
|
| 3681 | + or !file_exists($img_file) |
|
| 3682 | + or !$svg = file_get_contents($img_file) |
|
| 3683 | + ) { |
|
| 3684 | + return ''; |
|
| 3685 | + } |
|
| 3686 | + } |
|
| 3687 | + |
|
| 3688 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3689 | + return ''; |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3693 | + |
|
| 3694 | + $balise_svg = $match[0]; |
|
| 3695 | + $balise_svg_source = $balise_svg; |
|
| 3696 | + |
|
| 3697 | + // entete XML à supprimer |
|
| 3698 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3699 | + |
|
| 3700 | + // IE est toujours mon ami |
|
| 3701 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3702 | + |
|
| 3703 | + // regler la classe |
|
| 3704 | + if (!is_null($class)) { |
|
| 3705 | + if (strlen($class)) { |
|
| 3706 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3707 | + } |
|
| 3708 | + else { |
|
| 3709 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3710 | + } |
|
| 3711 | + } |
|
| 3712 | + |
|
| 3713 | + // regler le alt |
|
| 3714 | + if ($alt) { |
|
| 3715 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3716 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3717 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3718 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3719 | + $balise_svg .= $title; |
|
| 3720 | + } |
|
| 3721 | + else { |
|
| 3722 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3723 | + } |
|
| 3724 | + |
|
| 3725 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3726 | + |
|
| 3727 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3728 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3729 | + |
|
| 3730 | + if (!function_exists('svg_redimensionner')) { |
|
| 3731 | + include_spip('inc/svg'); |
|
| 3732 | + } |
|
| 3733 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3734 | + } |
|
| 3735 | + |
|
| 3736 | + return $svg; |
|
| 3737 | 3737 | } |
| 3738 | 3738 | |
| 3739 | 3739 | |
@@ -3759,18 +3759,18 @@ discard block |
||
| 3759 | 3759 | * Code HTML résultant |
| 3760 | 3760 | **/ |
| 3761 | 3761 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3762 | - $texte = ''; |
|
| 3763 | - if (is_array($tableau)) { |
|
| 3764 | - foreach ($tableau as $k => $v) { |
|
| 3765 | - $res = recuperer_fond( |
|
| 3766 | - 'modeles/' . $modele, |
|
| 3767 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3768 | - ); |
|
| 3769 | - $texte .= $res; |
|
| 3770 | - } |
|
| 3771 | - } |
|
| 3762 | + $texte = ''; |
|
| 3763 | + if (is_array($tableau)) { |
|
| 3764 | + foreach ($tableau as $k => $v) { |
|
| 3765 | + $res = recuperer_fond( |
|
| 3766 | + 'modeles/' . $modele, |
|
| 3767 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3768 | + ); |
|
| 3769 | + $texte .= $res; |
|
| 3770 | + } |
|
| 3771 | + } |
|
| 3772 | 3772 | |
| 3773 | - return $texte; |
|
| 3773 | + return $texte; |
|
| 3774 | 3774 | } |
| 3775 | 3775 | |
| 3776 | 3776 | |
@@ -3795,37 +3795,37 @@ discard block |
||
| 3795 | 3795 | * - tout : retourne toutes les informations du plugin actif |
| 3796 | 3796 | **/ |
| 3797 | 3797 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3798 | - include_spip('inc/plugin'); |
|
| 3799 | - $plugin = strtoupper($plugin); |
|
| 3800 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3801 | - |
|
| 3802 | - if (!$plugin) { |
|
| 3803 | - return serialize(array_keys($plugins_actifs)); |
|
| 3804 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3805 | - return ''; |
|
| 3806 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3807 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3808 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3809 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3810 | - } else { |
|
| 3811 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3812 | - // On prend en compte les extensions |
|
| 3813 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3814 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3815 | - } else { |
|
| 3816 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3817 | - } |
|
| 3818 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3819 | - return ''; |
|
| 3820 | - } |
|
| 3821 | - if ($type_info == 'tout') { |
|
| 3822 | - return $infos; |
|
| 3823 | - } elseif ($type_info == 'est_actif') { |
|
| 3824 | - return $infos ? 1 : 0; |
|
| 3825 | - } else { |
|
| 3826 | - return strval($infos[$type_info]); |
|
| 3827 | - } |
|
| 3828 | - } |
|
| 3798 | + include_spip('inc/plugin'); |
|
| 3799 | + $plugin = strtoupper($plugin); |
|
| 3800 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3801 | + |
|
| 3802 | + if (!$plugin) { |
|
| 3803 | + return serialize(array_keys($plugins_actifs)); |
|
| 3804 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3805 | + return ''; |
|
| 3806 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3807 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3808 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3809 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3810 | + } else { |
|
| 3811 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3812 | + // On prend en compte les extensions |
|
| 3813 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3814 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3815 | + } else { |
|
| 3816 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3817 | + } |
|
| 3818 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3819 | + return ''; |
|
| 3820 | + } |
|
| 3821 | + if ($type_info == 'tout') { |
|
| 3822 | + return $infos; |
|
| 3823 | + } elseif ($type_info == 'est_actif') { |
|
| 3824 | + return $infos ? 1 : 0; |
|
| 3825 | + } else { |
|
| 3826 | + return strval($infos[$type_info]); |
|
| 3827 | + } |
|
| 3828 | + } |
|
| 3829 | 3829 | } |
| 3830 | 3830 | |
| 3831 | 3831 | |
@@ -3852,9 +3852,9 @@ discard block |
||
| 3852 | 3852 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3853 | 3853 | */ |
| 3854 | 3854 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3855 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3855 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3856 | 3856 | |
| 3857 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3857 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3858 | 3858 | } |
| 3859 | 3859 | |
| 3860 | 3860 | |
@@ -3884,19 +3884,19 @@ discard block |
||
| 3884 | 3884 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3885 | 3885 | */ |
| 3886 | 3886 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3887 | - static $puce_statut = null; |
|
| 3888 | - if (!$puce_statut) { |
|
| 3889 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3890 | - } |
|
| 3887 | + static $puce_statut = null; |
|
| 3888 | + if (!$puce_statut) { |
|
| 3889 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3890 | + } |
|
| 3891 | 3891 | |
| 3892 | - return $puce_statut( |
|
| 3893 | - $id_objet, |
|
| 3894 | - $statut, |
|
| 3895 | - $id_parent, |
|
| 3896 | - $objet, |
|
| 3897 | - false, |
|
| 3898 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3899 | - ); |
|
| 3892 | + return $puce_statut( |
|
| 3893 | + $id_objet, |
|
| 3894 | + $statut, |
|
| 3895 | + $id_parent, |
|
| 3896 | + $objet, |
|
| 3897 | + false, |
|
| 3898 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3899 | + ); |
|
| 3900 | 3900 | } |
| 3901 | 3901 | |
| 3902 | 3902 | |
@@ -3923,98 +3923,98 @@ discard block |
||
| 3923 | 3923 | * hash du contexte |
| 3924 | 3924 | */ |
| 3925 | 3925 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3926 | - $env = null; |
|
| 3927 | - if ( |
|
| 3928 | - is_string($c) |
|
| 3929 | - and @unserialize($c) !== false |
|
| 3930 | - ) { |
|
| 3931 | - $c = unserialize($c); |
|
| 3932 | - } |
|
| 3933 | - |
|
| 3934 | - // supprimer les parametres debut_x |
|
| 3935 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3936 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3937 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3938 | - if (is_array($c)) { |
|
| 3939 | - foreach ($c as $k => $v) { |
|
| 3940 | - if (strpos($k, 'debut_') === 0) { |
|
| 3941 | - unset($c[$k]); |
|
| 3942 | - } |
|
| 3943 | - } |
|
| 3944 | - } |
|
| 3945 | - |
|
| 3946 | - if (!function_exists('calculer_cle_action')) { |
|
| 3947 | - include_spip('inc/securiser_action'); |
|
| 3948 | - } |
|
| 3949 | - |
|
| 3950 | - $c = serialize($c); |
|
| 3951 | - $cle = calculer_cle_action($form . $c); |
|
| 3952 | - $c = "$cle:$c"; |
|
| 3953 | - |
|
| 3954 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3955 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3956 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3957 | - // que ce qui est toléré. |
|
| 3958 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3959 | - if (!$cache_contextes_ajax) { |
|
| 3960 | - $env = $c; |
|
| 3961 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3962 | - $env = gzdeflate($env); |
|
| 3963 | - } |
|
| 3964 | - $env = _xor($env); |
|
| 3965 | - $env = base64_encode($env); |
|
| 3966 | - $len = strlen($env); |
|
| 3967 | - // Si l’url est trop longue pour le navigateur |
|
| 3968 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3969 | - if ($len > $max_len) { |
|
| 3970 | - $cache_contextes_ajax = true; |
|
| 3971 | - spip_log( |
|
| 3972 | - 'Contextes AJAX forces en fichiers !' |
|
| 3973 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3974 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3975 | - _LOG_AVERTISSEMENT |
|
| 3976 | - ); |
|
| 3977 | - } |
|
| 3978 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3979 | - elseif ( |
|
| 3980 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3981 | - and $max_len < $len |
|
| 3982 | - ) { |
|
| 3983 | - $cache_contextes_ajax = true; |
|
| 3984 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3985 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3986 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3987 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3988 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3989 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3990 | - } |
|
| 3991 | - } |
|
| 3992 | - |
|
| 3993 | - if ($cache_contextes_ajax) { |
|
| 3994 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3995 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3996 | - $md5 = md5($c); |
|
| 3997 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3998 | - $env = $md5; |
|
| 3999 | - } |
|
| 4000 | - |
|
| 4001 | - if ($emboite === null) { |
|
| 4002 | - return $env; |
|
| 4003 | - } |
|
| 4004 | - if (!trim($emboite)) { |
|
| 4005 | - return ''; |
|
| 4006 | - } |
|
| 4007 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4008 | - $r = self(); |
|
| 4009 | - $r = ' data-origin="' . $r . '"'; |
|
| 4010 | - $class = 'ajaxbloc'; |
|
| 4011 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4012 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4013 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4014 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4015 | - } |
|
| 4016 | - |
|
| 4017 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3926 | + $env = null; |
|
| 3927 | + if ( |
|
| 3928 | + is_string($c) |
|
| 3929 | + and @unserialize($c) !== false |
|
| 3930 | + ) { |
|
| 3931 | + $c = unserialize($c); |
|
| 3932 | + } |
|
| 3933 | + |
|
| 3934 | + // supprimer les parametres debut_x |
|
| 3935 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3936 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3937 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3938 | + if (is_array($c)) { |
|
| 3939 | + foreach ($c as $k => $v) { |
|
| 3940 | + if (strpos($k, 'debut_') === 0) { |
|
| 3941 | + unset($c[$k]); |
|
| 3942 | + } |
|
| 3943 | + } |
|
| 3944 | + } |
|
| 3945 | + |
|
| 3946 | + if (!function_exists('calculer_cle_action')) { |
|
| 3947 | + include_spip('inc/securiser_action'); |
|
| 3948 | + } |
|
| 3949 | + |
|
| 3950 | + $c = serialize($c); |
|
| 3951 | + $cle = calculer_cle_action($form . $c); |
|
| 3952 | + $c = "$cle:$c"; |
|
| 3953 | + |
|
| 3954 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3955 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3956 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3957 | + // que ce qui est toléré. |
|
| 3958 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3959 | + if (!$cache_contextes_ajax) { |
|
| 3960 | + $env = $c; |
|
| 3961 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3962 | + $env = gzdeflate($env); |
|
| 3963 | + } |
|
| 3964 | + $env = _xor($env); |
|
| 3965 | + $env = base64_encode($env); |
|
| 3966 | + $len = strlen($env); |
|
| 3967 | + // Si l’url est trop longue pour le navigateur |
|
| 3968 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3969 | + if ($len > $max_len) { |
|
| 3970 | + $cache_contextes_ajax = true; |
|
| 3971 | + spip_log( |
|
| 3972 | + 'Contextes AJAX forces en fichiers !' |
|
| 3973 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3974 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3975 | + _LOG_AVERTISSEMENT |
|
| 3976 | + ); |
|
| 3977 | + } |
|
| 3978 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3979 | + elseif ( |
|
| 3980 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3981 | + and $max_len < $len |
|
| 3982 | + ) { |
|
| 3983 | + $cache_contextes_ajax = true; |
|
| 3984 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3985 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3986 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3987 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3988 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3989 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3990 | + } |
|
| 3991 | + } |
|
| 3992 | + |
|
| 3993 | + if ($cache_contextes_ajax) { |
|
| 3994 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3995 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3996 | + $md5 = md5($c); |
|
| 3997 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3998 | + $env = $md5; |
|
| 3999 | + } |
|
| 4000 | + |
|
| 4001 | + if ($emboite === null) { |
|
| 4002 | + return $env; |
|
| 4003 | + } |
|
| 4004 | + if (!trim($emboite)) { |
|
| 4005 | + return ''; |
|
| 4006 | + } |
|
| 4007 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4008 | + $r = self(); |
|
| 4009 | + $r = ' data-origin="' . $r . '"'; |
|
| 4010 | + $class = 'ajaxbloc'; |
|
| 4011 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4012 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4013 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4014 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4015 | + } |
|
| 4016 | + |
|
| 4017 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4018 | 4018 | } |
| 4019 | 4019 | |
| 4020 | 4020 | /** |
@@ -4034,37 +4034,37 @@ discard block |
||
| 4034 | 4034 | * - false : erreur de décodage |
| 4035 | 4035 | */ |
| 4036 | 4036 | function decoder_contexte_ajax($c, $form = '') { |
| 4037 | - if (!function_exists('calculer_cle_action')) { |
|
| 4038 | - include_spip('inc/securiser_action'); |
|
| 4039 | - } |
|
| 4040 | - if ( |
|
| 4041 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4042 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4043 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4044 | - ) { |
|
| 4045 | - $c = $contexte; |
|
| 4046 | - } else { |
|
| 4047 | - $c = @base64_decode($c); |
|
| 4048 | - $c = _xor($c); |
|
| 4049 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4050 | - $c = @gzinflate($c); |
|
| 4051 | - } |
|
| 4052 | - } |
|
| 4053 | - |
|
| 4054 | - // extraire la signature en debut de contexte |
|
| 4055 | - // et la verifier avant de deserializer |
|
| 4056 | - // format : signature:donneesserializees |
|
| 4057 | - if ($p = strpos($c, ':')) { |
|
| 4058 | - $cle = substr($c, 0, $p); |
|
| 4059 | - $c = substr($c, $p + 1); |
|
| 4060 | - |
|
| 4061 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4062 | - $env = @unserialize($c); |
|
| 4063 | - return $env; |
|
| 4064 | - } |
|
| 4065 | - } |
|
| 4066 | - |
|
| 4067 | - return false; |
|
| 4037 | + if (!function_exists('calculer_cle_action')) { |
|
| 4038 | + include_spip('inc/securiser_action'); |
|
| 4039 | + } |
|
| 4040 | + if ( |
|
| 4041 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4042 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4043 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4044 | + ) { |
|
| 4045 | + $c = $contexte; |
|
| 4046 | + } else { |
|
| 4047 | + $c = @base64_decode($c); |
|
| 4048 | + $c = _xor($c); |
|
| 4049 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4050 | + $c = @gzinflate($c); |
|
| 4051 | + } |
|
| 4052 | + } |
|
| 4053 | + |
|
| 4054 | + // extraire la signature en debut de contexte |
|
| 4055 | + // et la verifier avant de deserializer |
|
| 4056 | + // format : signature:donneesserializees |
|
| 4057 | + if ($p = strpos($c, ':')) { |
|
| 4058 | + $cle = substr($c, 0, $p); |
|
| 4059 | + $c = substr($c, $p + 1); |
|
| 4060 | + |
|
| 4061 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4062 | + $env = @unserialize($c); |
|
| 4063 | + return $env; |
|
| 4064 | + } |
|
| 4065 | + } |
|
| 4066 | + |
|
| 4067 | + return false; |
|
| 4068 | 4068 | } |
| 4069 | 4069 | |
| 4070 | 4070 | |
@@ -4082,20 +4082,20 @@ discard block |
||
| 4082 | 4082 | * Message décrypté ou encrypté |
| 4083 | 4083 | **/ |
| 4084 | 4084 | function _xor($message, $key = null) { |
| 4085 | - if (is_null($key)) { |
|
| 4086 | - if (!function_exists('calculer_cle_action')) { |
|
| 4087 | - include_spip('inc/securiser_action'); |
|
| 4088 | - } |
|
| 4089 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4090 | - } |
|
| 4085 | + if (is_null($key)) { |
|
| 4086 | + if (!function_exists('calculer_cle_action')) { |
|
| 4087 | + include_spip('inc/securiser_action'); |
|
| 4088 | + } |
|
| 4089 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4090 | + } |
|
| 4091 | 4091 | |
| 4092 | - $keylen = strlen($key); |
|
| 4093 | - $messagelen = strlen($message); |
|
| 4094 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4095 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4096 | - } |
|
| 4092 | + $keylen = strlen($key); |
|
| 4093 | + $messagelen = strlen($message); |
|
| 4094 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4095 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4096 | + } |
|
| 4097 | 4097 | |
| 4098 | - return $message; |
|
| 4098 | + return $message; |
|
| 4099 | 4099 | } |
| 4100 | 4100 | |
| 4101 | 4101 | /** |
@@ -4109,7 +4109,7 @@ discard block |
||
| 4109 | 4109 | * @return string |
| 4110 | 4110 | */ |
| 4111 | 4111 | function url_reponse_forum($texte) { |
| 4112 | - return $texte; |
|
| 4112 | + return $texte; |
|
| 4113 | 4113 | } |
| 4114 | 4114 | |
| 4115 | 4115 | /** |
@@ -4123,7 +4123,7 @@ discard block |
||
| 4123 | 4123 | * @return string |
| 4124 | 4124 | */ |
| 4125 | 4125 | function url_rss_forum($texte) { |
| 4126 | - return $texte; |
|
| 4126 | + return $texte; |
|
| 4127 | 4127 | } |
| 4128 | 4128 | |
| 4129 | 4129 | |
@@ -4162,37 +4162,37 @@ discard block |
||
| 4162 | 4162 | * Code HTML |
| 4163 | 4163 | */ |
| 4164 | 4164 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4165 | - if ($on) { |
|
| 4166 | - $bal = 'strong'; |
|
| 4167 | - $class = ''; |
|
| 4168 | - $att = ''; |
|
| 4169 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4170 | - // a.active span.selected.active etc.... |
|
| 4171 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4172 | - $on = explode('.', $on); |
|
| 4173 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4174 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4175 | - $bal = array_shift($on); |
|
| 4176 | - $class = implode(' ', $on); |
|
| 4177 | - if ($bal == 'a') { |
|
| 4178 | - $att = 'href="#" '; |
|
| 4179 | - } |
|
| 4180 | - } |
|
| 4181 | - } |
|
| 4182 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4183 | - } else { |
|
| 4184 | - $bal = 'a'; |
|
| 4185 | - $att = "href='$url'" |
|
| 4186 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4187 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4188 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4189 | - . $evt; |
|
| 4190 | - } |
|
| 4191 | - if ($libelle === null) { |
|
| 4192 | - $libelle = $url; |
|
| 4193 | - } |
|
| 4194 | - |
|
| 4195 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4165 | + if ($on) { |
|
| 4166 | + $bal = 'strong'; |
|
| 4167 | + $class = ''; |
|
| 4168 | + $att = ''; |
|
| 4169 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4170 | + // a.active span.selected.active etc.... |
|
| 4171 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4172 | + $on = explode('.', $on); |
|
| 4173 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4174 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4175 | + $bal = array_shift($on); |
|
| 4176 | + $class = implode(' ', $on); |
|
| 4177 | + if ($bal == 'a') { |
|
| 4178 | + $att = 'href="#" '; |
|
| 4179 | + } |
|
| 4180 | + } |
|
| 4181 | + } |
|
| 4182 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4183 | + } else { |
|
| 4184 | + $bal = 'a'; |
|
| 4185 | + $att = "href='$url'" |
|
| 4186 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4187 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4188 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4189 | + . $evt; |
|
| 4190 | + } |
|
| 4191 | + if ($libelle === null) { |
|
| 4192 | + $libelle = $url; |
|
| 4193 | + } |
|
| 4194 | + |
|
| 4195 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4196 | 4196 | } |
| 4197 | 4197 | |
| 4198 | 4198 | |
@@ -4209,39 +4209,39 @@ discard block |
||
| 4209 | 4209 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4210 | 4210 | */ |
| 4211 | 4211 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4212 | - static $local_singulier_ou_pluriel = []; |
|
| 4213 | - |
|
| 4214 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4215 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4216 | - return ''; |
|
| 4217 | - } |
|
| 4218 | - if (!is_array($vars)) { |
|
| 4219 | - return ''; |
|
| 4220 | - } |
|
| 4221 | - |
|
| 4222 | - $langue = $GLOBALS['spip_lang']; |
|
| 4223 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4224 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4225 | - if ( |
|
| 4226 | - $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4227 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4228 | - ) { |
|
| 4229 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4230 | - } |
|
| 4231 | - } |
|
| 4232 | - |
|
| 4233 | - // si on a une surcharge on l'utilise |
|
| 4234 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4235 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4236 | - } |
|
| 4237 | - |
|
| 4238 | - // sinon traitement par defaut |
|
| 4239 | - $vars[$var] = $nb; |
|
| 4240 | - if ($nb >= 2) { |
|
| 4241 | - return _T($chaine_plusieurs, $vars); |
|
| 4242 | - } else { |
|
| 4243 | - return _T($chaine_un, $vars); |
|
| 4244 | - } |
|
| 4212 | + static $local_singulier_ou_pluriel = []; |
|
| 4213 | + |
|
| 4214 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4215 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4216 | + return ''; |
|
| 4217 | + } |
|
| 4218 | + if (!is_array($vars)) { |
|
| 4219 | + return ''; |
|
| 4220 | + } |
|
| 4221 | + |
|
| 4222 | + $langue = $GLOBALS['spip_lang']; |
|
| 4223 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4224 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4225 | + if ( |
|
| 4226 | + $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4227 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4228 | + ) { |
|
| 4229 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4230 | + } |
|
| 4231 | + } |
|
| 4232 | + |
|
| 4233 | + // si on a une surcharge on l'utilise |
|
| 4234 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4235 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4236 | + } |
|
| 4237 | + |
|
| 4238 | + // sinon traitement par defaut |
|
| 4239 | + $vars[$var] = $nb; |
|
| 4240 | + if ($nb >= 2) { |
|
| 4241 | + return _T($chaine_plusieurs, $vars); |
|
| 4242 | + } else { |
|
| 4243 | + return _T($chaine_un, $vars); |
|
| 4244 | + } |
|
| 4245 | 4245 | } |
| 4246 | 4246 | |
| 4247 | 4247 | |
@@ -4269,73 +4269,73 @@ discard block |
||
| 4269 | 4269 | */ |
| 4270 | 4270 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4271 | 4271 | |
| 4272 | - $class_lien = $class_bouton = $class; |
|
| 4273 | - |
|
| 4274 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4275 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4276 | - $class_lien .= ' danger'; |
|
| 4277 | - $class_bouton .= ' btn_danger'; |
|
| 4278 | - } elseif ($fonction == 'rien.gif') { |
|
| 4279 | - $fonction = ''; |
|
| 4280 | - } elseif ($fonction == 'delsafe') { |
|
| 4281 | - $fonction = 'del'; |
|
| 4282 | - } |
|
| 4283 | - |
|
| 4284 | - $fond_origine = $fond; |
|
| 4285 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4286 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4287 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4288 | - } |
|
| 4289 | - |
|
| 4290 | - // Ajouter le type d'objet dans la classe |
|
| 4291 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4292 | - $class_lien .= " $objet_type"; |
|
| 4293 | - $class_bouton .= " $objet_type"; |
|
| 4294 | - |
|
| 4295 | - // texte |
|
| 4296 | - $alt = attribut_html($texte); |
|
| 4297 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4298 | - |
|
| 4299 | - // Liens : préparer les classes ajax |
|
| 4300 | - $ajax = ''; |
|
| 4301 | - if ($type === 'lien') { |
|
| 4302 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4303 | - $ajax = 'ajax'; |
|
| 4304 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4305 | - $ajax .= ' preload'; |
|
| 4306 | - } |
|
| 4307 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4308 | - $ajax .= ' nocache'; |
|
| 4309 | - } |
|
| 4310 | - $ajax = " class='$ajax'"; |
|
| 4311 | - } |
|
| 4312 | - } |
|
| 4313 | - |
|
| 4314 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4315 | - $size = 24; |
|
| 4316 | - if ( |
|
| 4317 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4318 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4319 | - ) { |
|
| 4320 | - $size = $match[1]; |
|
| 4321 | - } |
|
| 4322 | - $class_lien .= " s$size"; |
|
| 4323 | - $class_bouton .= " s$size"; |
|
| 4324 | - |
|
| 4325 | - // Icône |
|
| 4326 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4327 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4328 | - |
|
| 4329 | - // Markup final |
|
| 4330 | - if ($type == 'lien') { |
|
| 4331 | - return "<span class='icone $class_lien'>" |
|
| 4332 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4333 | - . $icone |
|
| 4334 | - . "<b>$texte</b>" |
|
| 4335 | - . "</a></span>\n"; |
|
| 4336 | - } else { |
|
| 4337 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4338 | - } |
|
| 4272 | + $class_lien = $class_bouton = $class; |
|
| 4273 | + |
|
| 4274 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4275 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4276 | + $class_lien .= ' danger'; |
|
| 4277 | + $class_bouton .= ' btn_danger'; |
|
| 4278 | + } elseif ($fonction == 'rien.gif') { |
|
| 4279 | + $fonction = ''; |
|
| 4280 | + } elseif ($fonction == 'delsafe') { |
|
| 4281 | + $fonction = 'del'; |
|
| 4282 | + } |
|
| 4283 | + |
|
| 4284 | + $fond_origine = $fond; |
|
| 4285 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4286 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4287 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4288 | + } |
|
| 4289 | + |
|
| 4290 | + // Ajouter le type d'objet dans la classe |
|
| 4291 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4292 | + $class_lien .= " $objet_type"; |
|
| 4293 | + $class_bouton .= " $objet_type"; |
|
| 4294 | + |
|
| 4295 | + // texte |
|
| 4296 | + $alt = attribut_html($texte); |
|
| 4297 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4298 | + |
|
| 4299 | + // Liens : préparer les classes ajax |
|
| 4300 | + $ajax = ''; |
|
| 4301 | + if ($type === 'lien') { |
|
| 4302 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4303 | + $ajax = 'ajax'; |
|
| 4304 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4305 | + $ajax .= ' preload'; |
|
| 4306 | + } |
|
| 4307 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4308 | + $ajax .= ' nocache'; |
|
| 4309 | + } |
|
| 4310 | + $ajax = " class='$ajax'"; |
|
| 4311 | + } |
|
| 4312 | + } |
|
| 4313 | + |
|
| 4314 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4315 | + $size = 24; |
|
| 4316 | + if ( |
|
| 4317 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4318 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4319 | + ) { |
|
| 4320 | + $size = $match[1]; |
|
| 4321 | + } |
|
| 4322 | + $class_lien .= " s$size"; |
|
| 4323 | + $class_bouton .= " s$size"; |
|
| 4324 | + |
|
| 4325 | + // Icône |
|
| 4326 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4327 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4328 | + |
|
| 4329 | + // Markup final |
|
| 4330 | + if ($type == 'lien') { |
|
| 4331 | + return "<span class='icone $class_lien'>" |
|
| 4332 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4333 | + . $icone |
|
| 4334 | + . "<b>$texte</b>" |
|
| 4335 | + . "</a></span>\n"; |
|
| 4336 | + } else { |
|
| 4337 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4338 | + } |
|
| 4339 | 4339 | } |
| 4340 | 4340 | |
| 4341 | 4341 | /** |
@@ -4359,7 +4359,7 @@ discard block |
||
| 4359 | 4359 | * Code HTML du lien |
| 4360 | 4360 | **/ |
| 4361 | 4361 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4362 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4362 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4363 | 4363 | } |
| 4364 | 4364 | |
| 4365 | 4365 | /** |
@@ -4394,7 +4394,7 @@ discard block |
||
| 4394 | 4394 | * Code HTML du lien |
| 4395 | 4395 | **/ |
| 4396 | 4396 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4397 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4397 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4398 | 4398 | } |
| 4399 | 4399 | |
| 4400 | 4400 | /** |
@@ -4439,7 +4439,7 @@ discard block |
||
| 4439 | 4439 | * Code HTML du lien |
| 4440 | 4440 | **/ |
| 4441 | 4441 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4442 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4442 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4443 | 4443 | } |
| 4444 | 4444 | |
| 4445 | 4445 | /** |
@@ -4470,7 +4470,7 @@ discard block |
||
| 4470 | 4470 | * Code HTML du lien |
| 4471 | 4471 | **/ |
| 4472 | 4472 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4473 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4473 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4474 | 4474 | } |
| 4475 | 4475 | |
| 4476 | 4476 | /** |
@@ -4501,7 +4501,7 @@ discard block |
||
| 4501 | 4501 | * Code HTML du lien |
| 4502 | 4502 | */ |
| 4503 | 4503 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4504 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4504 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4505 | 4505 | } |
| 4506 | 4506 | |
| 4507 | 4507 | |
@@ -4523,7 +4523,7 @@ discard block |
||
| 4523 | 4523 | * @return array Liste des éléments |
| 4524 | 4524 | */ |
| 4525 | 4525 | function filtre_explode_dist($a, $b) { |
| 4526 | - return explode($b, (string) $a); |
|
| 4526 | + return explode($b, (string) $a); |
|
| 4527 | 4527 | } |
| 4528 | 4528 | |
| 4529 | 4529 | /** |
@@ -4544,7 +4544,7 @@ discard block |
||
| 4544 | 4544 | * @return string texte |
| 4545 | 4545 | */ |
| 4546 | 4546 | function filtre_implode_dist($a, $b) { |
| 4547 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4547 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4548 | 4548 | } |
| 4549 | 4549 | |
| 4550 | 4550 | /** |
@@ -4553,22 +4553,22 @@ discard block |
||
| 4553 | 4553 | * @return string Code CSS |
| 4554 | 4554 | */ |
| 4555 | 4555 | function bando_images_background() { |
| 4556 | - include_spip('inc/bandeau'); |
|
| 4557 | - // recuperer tous les boutons et leurs images |
|
| 4558 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4556 | + include_spip('inc/bandeau'); |
|
| 4557 | + // recuperer tous les boutons et leurs images |
|
| 4558 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4559 | 4559 | |
| 4560 | - $res = ''; |
|
| 4561 | - foreach ($boutons as $page => $detail) { |
|
| 4562 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4563 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4564 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4565 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4566 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4567 | - } |
|
| 4568 | - } |
|
| 4569 | - } |
|
| 4560 | + $res = ''; |
|
| 4561 | + foreach ($boutons as $page => $detail) { |
|
| 4562 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4563 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4564 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4565 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4566 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4567 | + } |
|
| 4568 | + } |
|
| 4569 | + } |
|
| 4570 | 4570 | |
| 4571 | - return $res; |
|
| 4571 | + return $res; |
|
| 4572 | 4572 | } |
| 4573 | 4573 | |
| 4574 | 4574 | /** |
@@ -4593,27 +4593,27 @@ discard block |
||
| 4593 | 4593 | */ |
| 4594 | 4594 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4595 | 4595 | |
| 4596 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4597 | - $class_form = ''; |
|
| 4598 | - if (strpos($class, 'ajax') !== false) { |
|
| 4599 | - $class_form = 'ajax'; |
|
| 4600 | - $class = str_replace('ajax', '', $class); |
|
| 4601 | - } |
|
| 4602 | - $class_btn = 'submit ' . trim($class); |
|
| 4596 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4597 | + $class_form = ''; |
|
| 4598 | + if (strpos($class, 'ajax') !== false) { |
|
| 4599 | + $class_form = 'ajax'; |
|
| 4600 | + $class = str_replace('ajax', '', $class); |
|
| 4601 | + } |
|
| 4602 | + $class_btn = 'submit ' . trim($class); |
|
| 4603 | 4603 | |
| 4604 | - if ($confirm) { |
|
| 4605 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4606 | - if ($callback) { |
|
| 4607 | - $callback = "$confirm?($callback):false"; |
|
| 4608 | - } else { |
|
| 4609 | - $callback = $confirm; |
|
| 4610 | - } |
|
| 4611 | - } |
|
| 4612 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4613 | - $title = $title ? " title='$title'" : ''; |
|
| 4604 | + if ($confirm) { |
|
| 4605 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4606 | + if ($callback) { |
|
| 4607 | + $callback = "$confirm?($callback):false"; |
|
| 4608 | + } else { |
|
| 4609 | + $callback = $confirm; |
|
| 4610 | + } |
|
| 4611 | + } |
|
| 4612 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4613 | + $title = $title ? " title='$title'" : ''; |
|
| 4614 | 4614 | |
| 4615 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4616 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4615 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4616 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4617 | 4617 | } |
| 4618 | 4618 | |
| 4619 | 4619 | /** |
@@ -4636,101 +4636,101 @@ discard block |
||
| 4636 | 4636 | * @return string |
| 4637 | 4637 | */ |
| 4638 | 4638 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4639 | - static $trouver_table = null; |
|
| 4640 | - static $objets; |
|
| 4641 | - |
|
| 4642 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4643 | - $id_objet = intval($id_objet); |
|
| 4644 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4645 | - return ''; |
|
| 4646 | - } |
|
| 4647 | - |
|
| 4648 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4649 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4650 | - return ''; |
|
| 4651 | - } |
|
| 4652 | - |
|
| 4653 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4654 | - if ($info == 'url') { |
|
| 4655 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4656 | - } |
|
| 4657 | - |
|
| 4658 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4659 | - $demande_titre = ($info === 'titre'); |
|
| 4660 | - $demande_introduction = ($info === 'introduction'); |
|
| 4661 | - |
|
| 4662 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4663 | - if ( |
|
| 4664 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4665 | - or |
|
| 4666 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4667 | - ) { |
|
| 4668 | - if (!$trouver_table) { |
|
| 4669 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4670 | - } |
|
| 4671 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4672 | - if (!$desc) { |
|
| 4673 | - return $objets[$type_objet] = false; |
|
| 4674 | - } |
|
| 4675 | - |
|
| 4676 | - // Si on demande le titre, on le gere en interne |
|
| 4677 | - $champ_titre = ''; |
|
| 4678 | - if ($demande_titre) { |
|
| 4679 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4680 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4681 | - } |
|
| 4682 | - include_spip('base/abstract_sql'); |
|
| 4683 | - include_spip('base/connect_sql'); |
|
| 4684 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4685 | - '*' . $champ_titre, |
|
| 4686 | - $desc['table_sql'], |
|
| 4687 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4688 | - ); |
|
| 4689 | - |
|
| 4690 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4691 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4692 | - } |
|
| 4693 | - |
|
| 4694 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4695 | - // ajouter la longueur au début des params supplémentaires |
|
| 4696 | - if ($demande_introduction) { |
|
| 4697 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4698 | - array_unshift($params, $introduction_longueur); |
|
| 4699 | - } |
|
| 4700 | - |
|
| 4701 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4702 | - if ( |
|
| 4703 | - $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4704 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4705 | - or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4706 | - ) { |
|
| 4707 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4708 | - } |
|
| 4709 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4710 | - elseif ( |
|
| 4711 | - $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4712 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4713 | - or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4714 | - ) { |
|
| 4715 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4716 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4717 | - else { |
|
| 4718 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4719 | - } |
|
| 4720 | - |
|
| 4721 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4722 | - if (!$etoile) { |
|
| 4723 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4724 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4725 | - $info_generee = appliquer_traitement_champ( |
|
| 4726 | - $info_generee, |
|
| 4727 | - $info, |
|
| 4728 | - table_objet($type_objet), |
|
| 4729 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4730 | - ); |
|
| 4731 | - } |
|
| 4732 | - |
|
| 4733 | - return $info_generee; |
|
| 4639 | + static $trouver_table = null; |
|
| 4640 | + static $objets; |
|
| 4641 | + |
|
| 4642 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4643 | + $id_objet = intval($id_objet); |
|
| 4644 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4645 | + return ''; |
|
| 4646 | + } |
|
| 4647 | + |
|
| 4648 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4649 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4650 | + return ''; |
|
| 4651 | + } |
|
| 4652 | + |
|
| 4653 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4654 | + if ($info == 'url') { |
|
| 4655 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4656 | + } |
|
| 4657 | + |
|
| 4658 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4659 | + $demande_titre = ($info === 'titre'); |
|
| 4660 | + $demande_introduction = ($info === 'introduction'); |
|
| 4661 | + |
|
| 4662 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4663 | + if ( |
|
| 4664 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4665 | + or |
|
| 4666 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4667 | + ) { |
|
| 4668 | + if (!$trouver_table) { |
|
| 4669 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4670 | + } |
|
| 4671 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4672 | + if (!$desc) { |
|
| 4673 | + return $objets[$type_objet] = false; |
|
| 4674 | + } |
|
| 4675 | + |
|
| 4676 | + // Si on demande le titre, on le gere en interne |
|
| 4677 | + $champ_titre = ''; |
|
| 4678 | + if ($demande_titre) { |
|
| 4679 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4680 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4681 | + } |
|
| 4682 | + include_spip('base/abstract_sql'); |
|
| 4683 | + include_spip('base/connect_sql'); |
|
| 4684 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4685 | + '*' . $champ_titre, |
|
| 4686 | + $desc['table_sql'], |
|
| 4687 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4688 | + ); |
|
| 4689 | + |
|
| 4690 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4691 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4692 | + } |
|
| 4693 | + |
|
| 4694 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4695 | + // ajouter la longueur au début des params supplémentaires |
|
| 4696 | + if ($demande_introduction) { |
|
| 4697 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4698 | + array_unshift($params, $introduction_longueur); |
|
| 4699 | + } |
|
| 4700 | + |
|
| 4701 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4702 | + if ( |
|
| 4703 | + $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4704 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4705 | + or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4706 | + ) { |
|
| 4707 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4708 | + } |
|
| 4709 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4710 | + elseif ( |
|
| 4711 | + $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4712 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4713 | + or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4714 | + ) { |
|
| 4715 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4716 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4717 | + else { |
|
| 4718 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4719 | + } |
|
| 4720 | + |
|
| 4721 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4722 | + if (!$etoile) { |
|
| 4723 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4724 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4725 | + $info_generee = appliquer_traitement_champ( |
|
| 4726 | + $info_generee, |
|
| 4727 | + $info, |
|
| 4728 | + table_objet($type_objet), |
|
| 4729 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4730 | + ); |
|
| 4731 | + } |
|
| 4732 | + |
|
| 4733 | + return $info_generee; |
|
| 4734 | 4734 | } |
| 4735 | 4735 | |
| 4736 | 4736 | /** |
@@ -4738,7 +4738,7 @@ discard block |
||
| 4738 | 4738 | * @see generer_objet_info |
| 4739 | 4739 | */ |
| 4740 | 4740 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4741 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4741 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4742 | 4742 | } |
| 4743 | 4743 | |
| 4744 | 4744 | /** |
@@ -4771,36 +4771,36 @@ discard block |
||
| 4771 | 4771 | */ |
| 4772 | 4772 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4773 | 4773 | |
| 4774 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4775 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4776 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4777 | - if (isset($ligne_sql['chapo'])) { |
|
| 4778 | - $chapo = $ligne_sql['chapo']; |
|
| 4779 | - $texte = strlen($descriptif) ? |
|
| 4780 | - '' : |
|
| 4781 | - "$chapo \n\n $texte"; |
|
| 4782 | - } |
|
| 4774 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4775 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4776 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4777 | + if (isset($ligne_sql['chapo'])) { |
|
| 4778 | + $chapo = $ligne_sql['chapo']; |
|
| 4779 | + $texte = strlen($descriptif) ? |
|
| 4780 | + '' : |
|
| 4781 | + "$chapo \n\n $texte"; |
|
| 4782 | + } |
|
| 4783 | 4783 | |
| 4784 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4785 | - if (!intval($longueur_ou_suite)) { |
|
| 4786 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4787 | - } else { |
|
| 4788 | - $longueur = intval($longueur_ou_suite); |
|
| 4789 | - } |
|
| 4784 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4785 | + if (!intval($longueur_ou_suite)) { |
|
| 4786 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4787 | + } else { |
|
| 4788 | + $longueur = intval($longueur_ou_suite); |
|
| 4789 | + } |
|
| 4790 | 4790 | |
| 4791 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4792 | - // Ex : #INTRODUCTION{...} |
|
| 4793 | - if ( |
|
| 4794 | - is_null($suite) |
|
| 4795 | - and !intval($longueur_ou_suite) |
|
| 4796 | - ) { |
|
| 4797 | - $suite = $longueur_ou_suite; |
|
| 4798 | - } |
|
| 4791 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4792 | + // Ex : #INTRODUCTION{...} |
|
| 4793 | + if ( |
|
| 4794 | + is_null($suite) |
|
| 4795 | + and !intval($longueur_ou_suite) |
|
| 4796 | + ) { |
|
| 4797 | + $suite = $longueur_ou_suite; |
|
| 4798 | + } |
|
| 4799 | 4799 | |
| 4800 | - $f = chercher_filtre('introduction'); |
|
| 4801 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4800 | + $f = chercher_filtre('introduction'); |
|
| 4801 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4802 | 4802 | |
| 4803 | - return $introduction; |
|
| 4803 | + return $introduction; |
|
| 4804 | 4804 | } |
| 4805 | 4805 | |
| 4806 | 4806 | /** |
@@ -4808,7 +4808,7 @@ discard block |
||
| 4808 | 4808 | * @see generer_objet_introduction |
| 4809 | 4809 | */ |
| 4810 | 4810 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4811 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4811 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4812 | 4812 | } |
| 4813 | 4813 | |
| 4814 | 4814 | /** |
@@ -4822,49 +4822,49 @@ discard block |
||
| 4822 | 4822 | * @return string |
| 4823 | 4823 | */ |
| 4824 | 4824 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4825 | - if (!$champ) { |
|
| 4826 | - return $texte; |
|
| 4827 | - } |
|
| 4825 | + if (!$champ) { |
|
| 4826 | + return $texte; |
|
| 4827 | + } |
|
| 4828 | 4828 | |
| 4829 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4830 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4831 | - include_fichiers_fonctions(); |
|
| 4829 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4830 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4831 | + include_fichiers_fonctions(); |
|
| 4832 | 4832 | |
| 4833 | - $champ = strtoupper($champ); |
|
| 4834 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4835 | - if (!$traitements or !is_array($traitements)) { |
|
| 4836 | - return $texte; |
|
| 4837 | - } |
|
| 4833 | + $champ = strtoupper($champ); |
|
| 4834 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4835 | + if (!$traitements or !is_array($traitements)) { |
|
| 4836 | + return $texte; |
|
| 4837 | + } |
|
| 4838 | 4838 | |
| 4839 | - $traitement = ''; |
|
| 4840 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4841 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4842 | - $table_objet = table_objet($table_objet); |
|
| 4843 | - if (isset($traitements[$table_objet])) { |
|
| 4844 | - $traitement = $traitements[$table_objet]; |
|
| 4845 | - } |
|
| 4846 | - } |
|
| 4847 | - if (!$traitement and isset($traitements[0])) { |
|
| 4848 | - $traitement = $traitements[0]; |
|
| 4849 | - } |
|
| 4850 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4839 | + $traitement = ''; |
|
| 4840 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4841 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4842 | + $table_objet = table_objet($table_objet); |
|
| 4843 | + if (isset($traitements[$table_objet])) { |
|
| 4844 | + $traitement = $traitements[$table_objet]; |
|
| 4845 | + } |
|
| 4846 | + } |
|
| 4847 | + if (!$traitement and isset($traitements[0])) { |
|
| 4848 | + $traitement = $traitements[0]; |
|
| 4849 | + } |
|
| 4850 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4851 | 4851 | |
| 4852 | - if (!$traitement) { |
|
| 4853 | - return $texte; |
|
| 4854 | - } |
|
| 4852 | + if (!$traitement) { |
|
| 4853 | + return $texte; |
|
| 4854 | + } |
|
| 4855 | 4855 | |
| 4856 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4856 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4857 | 4857 | |
| 4858 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4859 | - if (test_espace_prive()) { |
|
| 4860 | - $env['espace_prive'] = 1; |
|
| 4861 | - } |
|
| 4858 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4859 | + if (test_espace_prive()) { |
|
| 4860 | + $env['espace_prive'] = 1; |
|
| 4861 | + } |
|
| 4862 | 4862 | |
| 4863 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4864 | - $Pile = [0 => $env]; |
|
| 4865 | - eval("\$texte = $traitement;"); |
|
| 4863 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4864 | + $Pile = [0 => $env]; |
|
| 4865 | + eval("\$texte = $traitement;"); |
|
| 4866 | 4866 | |
| 4867 | - return $texte; |
|
| 4867 | + return $texte; |
|
| 4868 | 4868 | } |
| 4869 | 4869 | |
| 4870 | 4870 | |
@@ -4878,21 +4878,21 @@ discard block |
||
| 4878 | 4878 | * @return string |
| 4879 | 4879 | */ |
| 4880 | 4880 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4881 | - include_spip('inc/liens'); |
|
| 4882 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4883 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4884 | - // le raccourcis n'est plus valide |
|
| 4885 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4886 | - // on essaye avec generer_info_entite ? |
|
| 4887 | - if (!strlen($titre) and !$connect) { |
|
| 4888 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4889 | - } |
|
| 4890 | - if (!strlen($titre)) { |
|
| 4891 | - $titre = _T('info_sans_titre'); |
|
| 4892 | - } |
|
| 4893 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4881 | + include_spip('inc/liens'); |
|
| 4882 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4883 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4884 | + // le raccourcis n'est plus valide |
|
| 4885 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4886 | + // on essaye avec generer_info_entite ? |
|
| 4887 | + if (!strlen($titre) and !$connect) { |
|
| 4888 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4889 | + } |
|
| 4890 | + if (!strlen($titre)) { |
|
| 4891 | + $titre = _T('info_sans_titre'); |
|
| 4892 | + } |
|
| 4893 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4894 | 4894 | |
| 4895 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4895 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4896 | 4896 | } |
| 4897 | 4897 | |
| 4898 | 4898 | /** |
@@ -4900,7 +4900,7 @@ discard block |
||
| 4900 | 4900 | * @see generer_objet_lien |
| 4901 | 4901 | */ |
| 4902 | 4902 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4903 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4903 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4904 | 4904 | } |
| 4905 | 4905 | |
| 4906 | 4906 | /** |
@@ -4916,15 +4916,15 @@ discard block |
||
| 4916 | 4916 | * @return string |
| 4917 | 4917 | */ |
| 4918 | 4918 | function wrap($texte, $wrap) { |
| 4919 | - $balises = extraire_balises($wrap); |
|
| 4920 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | - $texte = $wrap . $texte; |
|
| 4922 | - $regs = array_reverse($regs[1]); |
|
| 4923 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | - $texte = $texte . $wrap; |
|
| 4925 | - } |
|
| 4919 | + $balises = extraire_balises($wrap); |
|
| 4920 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | + $texte = $wrap . $texte; |
|
| 4922 | + $regs = array_reverse($regs[1]); |
|
| 4923 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | + $texte = $texte . $wrap; |
|
| 4925 | + } |
|
| 4926 | 4926 | |
| 4927 | - return $texte; |
|
| 4927 | + return $texte; |
|
| 4928 | 4928 | } |
| 4929 | 4929 | |
| 4930 | 4930 | |
@@ -4944,44 +4944,44 @@ discard block |
||
| 4944 | 4944 | * @return array|mixed|string |
| 4945 | 4945 | */ |
| 4946 | 4946 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4947 | - if (is_string($u)) { |
|
| 4948 | - $u = typo($u); |
|
| 4947 | + if (is_string($u)) { |
|
| 4948 | + $u = typo($u); |
|
| 4949 | 4949 | |
| 4950 | - return $u; |
|
| 4951 | - } |
|
| 4950 | + return $u; |
|
| 4951 | + } |
|
| 4952 | 4952 | |
| 4953 | - // caster $u en array si besoin |
|
| 4954 | - if (is_object($u)) { |
|
| 4955 | - $u = (array)$u; |
|
| 4956 | - } |
|
| 4953 | + // caster $u en array si besoin |
|
| 4954 | + if (is_object($u)) { |
|
| 4955 | + $u = (array)$u; |
|
| 4956 | + } |
|
| 4957 | 4957 | |
| 4958 | - if (is_array($u)) { |
|
| 4959 | - $out = ''; |
|
| 4960 | - // toutes les cles sont numeriques ? |
|
| 4961 | - // et aucun enfant n'est un tableau |
|
| 4962 | - // liste simple separee par des virgules |
|
| 4963 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | - $array_values = array_map('is_array', $u); |
|
| 4965 | - $object_values = array_map('is_object', $u); |
|
| 4966 | - if ( |
|
| 4967 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | - and !array_sum($array_values) |
|
| 4969 | - and !array_sum($object_values) |
|
| 4970 | - ) { |
|
| 4971 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | - } |
|
| 4958 | + if (is_array($u)) { |
|
| 4959 | + $out = ''; |
|
| 4960 | + // toutes les cles sont numeriques ? |
|
| 4961 | + // et aucun enfant n'est un tableau |
|
| 4962 | + // liste simple separee par des virgules |
|
| 4963 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | + $array_values = array_map('is_array', $u); |
|
| 4965 | + $object_values = array_map('is_object', $u); |
|
| 4966 | + if ( |
|
| 4967 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | + and !array_sum($array_values) |
|
| 4969 | + and !array_sum($object_values) |
|
| 4970 | + ) { |
|
| 4971 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | + } |
|
| 4973 | 4973 | |
| 4974 | - // sinon on passe a la ligne et on indente |
|
| 4975 | - $i_str = str_pad('', $indent, ' '); |
|
| 4976 | - foreach ($u as $k => $v) { |
|
| 4977 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | - } |
|
| 4974 | + // sinon on passe a la ligne et on indente |
|
| 4975 | + $i_str = str_pad('', $indent, ' '); |
|
| 4976 | + foreach ($u as $k => $v) { |
|
| 4977 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | + } |
|
| 4979 | 4979 | |
| 4980 | - return $out; |
|
| 4981 | - } |
|
| 4980 | + return $out; |
|
| 4981 | + } |
|
| 4982 | 4982 | |
| 4983 | - // on sait pas quoi faire... |
|
| 4984 | - return $u; |
|
| 4983 | + // on sait pas quoi faire... |
|
| 4984 | + return $u; |
|
| 4985 | 4985 | } |
| 4986 | 4986 | |
| 4987 | 4987 | |
@@ -4994,10 +4994,10 @@ discard block |
||
| 4994 | 4994 | * @return string|array |
| 4995 | 4995 | */ |
| 4996 | 4996 | function objet_info($objet, $info) { |
| 4997 | - $table = table_objet_sql($objet); |
|
| 4998 | - $infos = lister_tables_objets_sql($table); |
|
| 4997 | + $table = table_objet_sql($objet); |
|
| 4998 | + $infos = lister_tables_objets_sql($table); |
|
| 4999 | 4999 | |
| 5000 | - return ($infos[$info] ?? ''); |
|
| 5000 | + return ($infos[$info] ?? ''); |
|
| 5001 | 5001 | } |
| 5002 | 5002 | |
| 5003 | 5003 | /** |
@@ -5012,11 +5012,11 @@ discard block |
||
| 5012 | 5012 | * texte traduit du comptage, tel que '3 articles' |
| 5013 | 5013 | */ |
| 5014 | 5014 | function objet_afficher_nb($nb, $objet) { |
| 5015 | - if (!$nb) { |
|
| 5016 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | - } else { |
|
| 5018 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | - } |
|
| 5015 | + if (!$nb) { |
|
| 5016 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | + } else { |
|
| 5018 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | + } |
|
| 5020 | 5020 | } |
| 5021 | 5021 | |
| 5022 | 5022 | /** |
@@ -5028,11 +5028,11 @@ discard block |
||
| 5028 | 5028 | * @return string |
| 5029 | 5029 | */ |
| 5030 | 5030 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5031 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | - $icone = chemin_image($icone); |
|
| 5033 | - $balise_img = charger_filtre('balise_img'); |
|
| 5031 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | + $icone = chemin_image($icone); |
|
| 5033 | + $balise_img = charger_filtre('balise_img'); |
|
| 5034 | 5034 | |
| 5035 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5035 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5036 | 5036 | } |
| 5037 | 5037 | |
| 5038 | 5038 | /** |
@@ -5053,12 +5053,12 @@ discard block |
||
| 5053 | 5053 | * @return string |
| 5054 | 5054 | */ |
| 5055 | 5055 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5056 | - $chaine = explode(':', $chaine); |
|
| 5057 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | - return $t; |
|
| 5059 | - } |
|
| 5060 | - $chaine = implode(':', $chaine); |
|
| 5061 | - return _T($chaine, $args, $options); |
|
| 5056 | + $chaine = explode(':', $chaine); |
|
| 5057 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | + return $t; |
|
| 5059 | + } |
|
| 5060 | + $chaine = implode(':', $chaine); |
|
| 5061 | + return _T($chaine, $args, $options); |
|
| 5062 | 5062 | } |
| 5063 | 5063 | |
| 5064 | 5064 | /** |
@@ -5072,18 +5072,18 @@ discard block |
||
| 5072 | 5072 | * @return string Code HTML |
| 5073 | 5073 | */ |
| 5074 | 5074 | function insert_head_css_conditionnel($flux) { |
| 5075 | - if ( |
|
| 5076 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | - ) { |
|
| 5079 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | - $p = $p1; |
|
| 5082 | - } |
|
| 5083 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | - } |
|
| 5075 | + if ( |
|
| 5076 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | + ) { |
|
| 5079 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | + $p = $p1; |
|
| 5082 | + } |
|
| 5083 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | + } |
|
| 5085 | 5085 | |
| 5086 | - return $flux; |
|
| 5086 | + return $flux; |
|
| 5087 | 5087 | } |
| 5088 | 5088 | |
| 5089 | 5089 | /** |
@@ -5106,75 +5106,75 @@ discard block |
||
| 5106 | 5106 | * @return string |
| 5107 | 5107 | */ |
| 5108 | 5108 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5109 | - if (isset($contexte['format'])) { |
|
| 5110 | - $extension = $contexte['format']; |
|
| 5111 | - unset($contexte['format']); |
|
| 5112 | - } else { |
|
| 5113 | - $extension = 'html'; |
|
| 5114 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | - $extension = $m[1]; |
|
| 5116 | - } |
|
| 5117 | - } |
|
| 5118 | - // recuperer le contenu produit par le squelette |
|
| 5119 | - $options['raw'] = true; |
|
| 5120 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | - |
|
| 5122 | - // calculer le nom de la css |
|
| 5123 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | - |
|
| 5127 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | - } |
|
| 5133 | - else { |
|
| 5134 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | - ksort($contexte); |
|
| 5136 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5137 | - } |
|
| 5138 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | - |
|
| 5140 | - // mettre a jour le fichier si il n'existe pas |
|
| 5141 | - // ou trop ancien |
|
| 5142 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | - if ( |
|
| 5145 | - !file_exists($filename) |
|
| 5146 | - or !file_exists($filename . '.last') |
|
| 5147 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | - ) { |
|
| 5150 | - $contenu = $cache['texte']; |
|
| 5151 | - // passer les urls en absolu si c'est une css |
|
| 5152 | - if ($extension == 'css') { |
|
| 5153 | - $contenu = urls_absolues_css( |
|
| 5154 | - $contenu, |
|
| 5155 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | - ); |
|
| 5157 | - } |
|
| 5158 | - |
|
| 5159 | - $comment = ''; |
|
| 5160 | - // ne pas insérer de commentaire sur certains formats |
|
| 5161 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | - foreach ($contexte as $k => $v) { |
|
| 5164 | - if (is_array($v)) { |
|
| 5165 | - $v = var_export($v, true); |
|
| 5166 | - } |
|
| 5167 | - $comment .= ",$k=$v"; |
|
| 5168 | - } |
|
| 5169 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5170 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5171 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5172 | - } |
|
| 5173 | - // et ecrire le fichier si il change |
|
| 5174 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5175 | - } |
|
| 5176 | - |
|
| 5177 | - return timestamp($filename); |
|
| 5109 | + if (isset($contexte['format'])) { |
|
| 5110 | + $extension = $contexte['format']; |
|
| 5111 | + unset($contexte['format']); |
|
| 5112 | + } else { |
|
| 5113 | + $extension = 'html'; |
|
| 5114 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | + $extension = $m[1]; |
|
| 5116 | + } |
|
| 5117 | + } |
|
| 5118 | + // recuperer le contenu produit par le squelette |
|
| 5119 | + $options['raw'] = true; |
|
| 5120 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | + |
|
| 5122 | + // calculer le nom de la css |
|
| 5123 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | + |
|
| 5127 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | + } |
|
| 5133 | + else { |
|
| 5134 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | + ksort($contexte); |
|
| 5136 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5137 | + } |
|
| 5138 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | + |
|
| 5140 | + // mettre a jour le fichier si il n'existe pas |
|
| 5141 | + // ou trop ancien |
|
| 5142 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | + if ( |
|
| 5145 | + !file_exists($filename) |
|
| 5146 | + or !file_exists($filename . '.last') |
|
| 5147 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | + ) { |
|
| 5150 | + $contenu = $cache['texte']; |
|
| 5151 | + // passer les urls en absolu si c'est une css |
|
| 5152 | + if ($extension == 'css') { |
|
| 5153 | + $contenu = urls_absolues_css( |
|
| 5154 | + $contenu, |
|
| 5155 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | + ); |
|
| 5157 | + } |
|
| 5158 | + |
|
| 5159 | + $comment = ''; |
|
| 5160 | + // ne pas insérer de commentaire sur certains formats |
|
| 5161 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | + foreach ($contexte as $k => $v) { |
|
| 5164 | + if (is_array($v)) { |
|
| 5165 | + $v = var_export($v, true); |
|
| 5166 | + } |
|
| 5167 | + $comment .= ",$k=$v"; |
|
| 5168 | + } |
|
| 5169 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5170 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5171 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5172 | + } |
|
| 5173 | + // et ecrire le fichier si il change |
|
| 5174 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5175 | + } |
|
| 5176 | + |
|
| 5177 | + return timestamp($filename); |
|
| 5178 | 5178 | } |
| 5179 | 5179 | |
| 5180 | 5180 | /** |
@@ -5187,15 +5187,15 @@ discard block |
||
| 5187 | 5187 | * $fichier auquel on a ajouté le timestamp |
| 5188 | 5188 | */ |
| 5189 | 5189 | function timestamp($fichier) { |
| 5190 | - if ( |
|
| 5191 | - !$fichier |
|
| 5192 | - or !file_exists($fichier) |
|
| 5193 | - or !$m = filemtime($fichier) |
|
| 5194 | - ) { |
|
| 5195 | - return $fichier; |
|
| 5196 | - } |
|
| 5190 | + if ( |
|
| 5191 | + !$fichier |
|
| 5192 | + or !file_exists($fichier) |
|
| 5193 | + or !$m = filemtime($fichier) |
|
| 5194 | + ) { |
|
| 5195 | + return $fichier; |
|
| 5196 | + } |
|
| 5197 | 5197 | |
| 5198 | - return "$fichier?$m"; |
|
| 5198 | + return "$fichier?$m"; |
|
| 5199 | 5199 | } |
| 5200 | 5200 | |
| 5201 | 5201 | /** |
@@ -5205,11 +5205,11 @@ discard block |
||
| 5205 | 5205 | * @return string |
| 5206 | 5206 | */ |
| 5207 | 5207 | function supprimer_timestamp($url) { |
| 5208 | - if (strpos($url, '?') === false) { |
|
| 5209 | - return $url; |
|
| 5210 | - } |
|
| 5208 | + if (strpos($url, '?') === false) { |
|
| 5209 | + return $url; |
|
| 5210 | + } |
|
| 5211 | 5211 | |
| 5212 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5212 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5213 | 5213 | } |
| 5214 | 5214 | |
| 5215 | 5215 | /** |
@@ -5224,15 +5224,15 @@ discard block |
||
| 5224 | 5224 | * @return string |
| 5225 | 5225 | */ |
| 5226 | 5226 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5227 | - include_spip('inc/envoyer_mail'); |
|
| 5227 | + include_spip('inc/envoyer_mail'); |
|
| 5228 | 5228 | |
| 5229 | - $titre = nettoyer_titre_email($titre); |
|
| 5230 | - // on est dans un squelette : securiser le retour |
|
| 5231 | - if (strpos($titre, '<') !== false) { |
|
| 5232 | - $titre = interdire_scripts($titre); |
|
| 5233 | - } |
|
| 5229 | + $titre = nettoyer_titre_email($titre); |
|
| 5230 | + // on est dans un squelette : securiser le retour |
|
| 5231 | + if (strpos($titre, '<') !== false) { |
|
| 5232 | + $titre = interdire_scripts($titre); |
|
| 5233 | + } |
|
| 5234 | 5234 | |
| 5235 | - return $titre; |
|
| 5235 | + return $titre; |
|
| 5236 | 5236 | } |
| 5237 | 5237 | |
| 5238 | 5238 | /** |
@@ -5254,27 +5254,27 @@ discard block |
||
| 5254 | 5254 | * @return string |
| 5255 | 5255 | */ |
| 5256 | 5256 | function filtre_chercher_rubrique_dist( |
| 5257 | - $titre, |
|
| 5258 | - $id_objet, |
|
| 5259 | - $id_parent, |
|
| 5260 | - $objet, |
|
| 5261 | - $id_secteur, |
|
| 5262 | - $restreint, |
|
| 5263 | - $actionable = false, |
|
| 5264 | - $retour_sans_cadre = false |
|
| 5257 | + $titre, |
|
| 5258 | + $id_objet, |
|
| 5259 | + $id_parent, |
|
| 5260 | + $objet, |
|
| 5261 | + $id_secteur, |
|
| 5262 | + $restreint, |
|
| 5263 | + $actionable = false, |
|
| 5264 | + $retour_sans_cadre = false |
|
| 5265 | 5265 | ) { |
| 5266 | - include_spip('inc/filtres_ecrire'); |
|
| 5266 | + include_spip('inc/filtres_ecrire'); |
|
| 5267 | 5267 | |
| 5268 | - return chercher_rubrique( |
|
| 5269 | - $titre, |
|
| 5270 | - $id_objet, |
|
| 5271 | - $id_parent, |
|
| 5272 | - $objet, |
|
| 5273 | - $id_secteur, |
|
| 5274 | - $restreint, |
|
| 5275 | - $actionable, |
|
| 5276 | - $retour_sans_cadre |
|
| 5277 | - ); |
|
| 5268 | + return chercher_rubrique( |
|
| 5269 | + $titre, |
|
| 5270 | + $id_objet, |
|
| 5271 | + $id_parent, |
|
| 5272 | + $objet, |
|
| 5273 | + $id_secteur, |
|
| 5274 | + $restreint, |
|
| 5275 | + $actionable, |
|
| 5276 | + $retour_sans_cadre |
|
| 5277 | + ); |
|
| 5278 | 5278 | } |
| 5279 | 5279 | |
| 5280 | 5280 | /** |
@@ -5303,56 +5303,56 @@ discard block |
||
| 5303 | 5303 | * Chaîne vide si l'accès est autorisé |
| 5304 | 5304 | */ |
| 5305 | 5305 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5306 | - if ($ok) { |
|
| 5307 | - return ''; |
|
| 5308 | - } |
|
| 5309 | - |
|
| 5310 | - // Vider tous les tampons |
|
| 5311 | - $level = @ob_get_level(); |
|
| 5312 | - while ($level--) { |
|
| 5313 | - @ob_end_clean(); |
|
| 5314 | - } |
|
| 5315 | - |
|
| 5316 | - include_spip('inc/headers'); |
|
| 5317 | - |
|
| 5318 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5319 | - if ($url) { |
|
| 5320 | - redirige_par_entete($url, '', $statut); |
|
| 5321 | - } |
|
| 5322 | - |
|
| 5323 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5324 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5325 | - $message = $statut; |
|
| 5326 | - $statut = 0; |
|
| 5327 | - } |
|
| 5328 | - if (!$message) { |
|
| 5329 | - $message = ''; |
|
| 5330 | - } |
|
| 5331 | - $statut = intval($statut); |
|
| 5332 | - |
|
| 5333 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5334 | - if (test_espace_prive()) { |
|
| 5335 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5336 | - $statut = 403; |
|
| 5337 | - } |
|
| 5338 | - http_response_code(403); |
|
| 5339 | - $echec = charger_fonction('403', 'exec'); |
|
| 5340 | - $echec($message); |
|
| 5341 | - } else { |
|
| 5342 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5343 | - if (!$statut) { |
|
| 5344 | - $statut = 404; |
|
| 5345 | - } |
|
| 5346 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5347 | - http_response_code($statut); |
|
| 5348 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5349 | - if ($statut >= 400) { |
|
| 5350 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5351 | - } |
|
| 5352 | - } |
|
| 5353 | - |
|
| 5354 | - |
|
| 5355 | - exit; |
|
| 5306 | + if ($ok) { |
|
| 5307 | + return ''; |
|
| 5308 | + } |
|
| 5309 | + |
|
| 5310 | + // Vider tous les tampons |
|
| 5311 | + $level = @ob_get_level(); |
|
| 5312 | + while ($level--) { |
|
| 5313 | + @ob_end_clean(); |
|
| 5314 | + } |
|
| 5315 | + |
|
| 5316 | + include_spip('inc/headers'); |
|
| 5317 | + |
|
| 5318 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5319 | + if ($url) { |
|
| 5320 | + redirige_par_entete($url, '', $statut); |
|
| 5321 | + } |
|
| 5322 | + |
|
| 5323 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5324 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5325 | + $message = $statut; |
|
| 5326 | + $statut = 0; |
|
| 5327 | + } |
|
| 5328 | + if (!$message) { |
|
| 5329 | + $message = ''; |
|
| 5330 | + } |
|
| 5331 | + $statut = intval($statut); |
|
| 5332 | + |
|
| 5333 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5334 | + if (test_espace_prive()) { |
|
| 5335 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5336 | + $statut = 403; |
|
| 5337 | + } |
|
| 5338 | + http_response_code(403); |
|
| 5339 | + $echec = charger_fonction('403', 'exec'); |
|
| 5340 | + $echec($message); |
|
| 5341 | + } else { |
|
| 5342 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5343 | + if (!$statut) { |
|
| 5344 | + $statut = 404; |
|
| 5345 | + } |
|
| 5346 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5347 | + http_response_code($statut); |
|
| 5348 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5349 | + if ($statut >= 400) { |
|
| 5350 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5351 | + } |
|
| 5352 | + } |
|
| 5353 | + |
|
| 5354 | + |
|
| 5355 | + exit; |
|
| 5356 | 5356 | } |
| 5357 | 5357 | |
| 5358 | 5358 | /** |
@@ -5363,11 +5363,11 @@ discard block |
||
| 5363 | 5363 | * @return string |
| 5364 | 5364 | */ |
| 5365 | 5365 | function filtre_compacte_dist($source, $format = null) { |
| 5366 | - if (function_exists('minifier')) { |
|
| 5367 | - return minifier($source, $format); |
|
| 5368 | - } |
|
| 5366 | + if (function_exists('minifier')) { |
|
| 5367 | + return minifier($source, $format); |
|
| 5368 | + } |
|
| 5369 | 5369 | |
| 5370 | - return $source; |
|
| 5370 | + return $source; |
|
| 5371 | 5371 | } |
| 5372 | 5372 | |
| 5373 | 5373 | |
@@ -5379,32 +5379,32 @@ discard block |
||
| 5379 | 5379 | * @return string |
| 5380 | 5380 | */ |
| 5381 | 5381 | function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5382 | - $passe ??= ''; |
|
| 5383 | - $l = strlen($passe); |
|
| 5384 | - |
|
| 5385 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5386 | - if (!$l) { |
|
| 5387 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5388 | - } |
|
| 5389 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5390 | - } |
|
| 5391 | - |
|
| 5392 | - if (is_null($portion_pourcent)) { |
|
| 5393 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5394 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5395 | - } |
|
| 5396 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5397 | - } |
|
| 5398 | - if ($portion_pourcent >= 100) { |
|
| 5399 | - return $passe; |
|
| 5400 | - } |
|
| 5401 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5402 | - $e = max($e, 0); |
|
| 5403 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5404 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5405 | - $mid = '***...***'; |
|
| 5406 | - } |
|
| 5407 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5382 | + $passe ??= ''; |
|
| 5383 | + $l = strlen($passe); |
|
| 5384 | + |
|
| 5385 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5386 | + if (!$l) { |
|
| 5387 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5388 | + } |
|
| 5389 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5390 | + } |
|
| 5391 | + |
|
| 5392 | + if (is_null($portion_pourcent)) { |
|
| 5393 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5394 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5395 | + } |
|
| 5396 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5397 | + } |
|
| 5398 | + if ($portion_pourcent >= 100) { |
|
| 5399 | + return $passe; |
|
| 5400 | + } |
|
| 5401 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5402 | + $e = max($e, 0); |
|
| 5403 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5404 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5405 | + $mid = '***...***'; |
|
| 5406 | + } |
|
| 5407 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5408 | 5408 | } |
| 5409 | 5409 | |
| 5410 | 5410 | |
@@ -5425,64 +5425,64 @@ discard block |
||
| 5425 | 5425 | */ |
| 5426 | 5426 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5427 | 5427 | |
| 5428 | - $original = $texte; |
|
| 5429 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5430 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5431 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5428 | + $original = $texte; |
|
| 5429 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5430 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5431 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5432 | 5432 | |
| 5433 | - if (!function_exists('translitteration')) { |
|
| 5434 | - include_spip('inc/charsets'); |
|
| 5435 | - } |
|
| 5433 | + if (!function_exists('translitteration')) { |
|
| 5434 | + include_spip('inc/charsets'); |
|
| 5435 | + } |
|
| 5436 | 5436 | |
| 5437 | - // pas de balise html |
|
| 5438 | - if (strpos($texte, '<') !== false) { |
|
| 5439 | - $texte = strip_tags($texte); |
|
| 5440 | - } |
|
| 5441 | - if (strpos($texte, '&') !== false) { |
|
| 5442 | - $texte = unicode2charset($texte); |
|
| 5443 | - } |
|
| 5444 | - // On enlève les espaces indésirables |
|
| 5445 | - $texte = trim($texte); |
|
| 5437 | + // pas de balise html |
|
| 5438 | + if (strpos($texte, '<') !== false) { |
|
| 5439 | + $texte = strip_tags($texte); |
|
| 5440 | + } |
|
| 5441 | + if (strpos($texte, '&') !== false) { |
|
| 5442 | + $texte = unicode2charset($texte); |
|
| 5443 | + } |
|
| 5444 | + // On enlève les espaces indésirables |
|
| 5445 | + $texte = trim($texte); |
|
| 5446 | 5446 | |
| 5447 | - // On enlève les accents et cie |
|
| 5448 | - $texte = translitteration($texte); |
|
| 5447 | + // On enlève les accents et cie |
|
| 5448 | + $texte = translitteration($texte); |
|
| 5449 | 5449 | |
| 5450 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5451 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5450 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5451 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5452 | 5452 | |
| 5453 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5454 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5455 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5456 | - } |
|
| 5453 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5454 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5455 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5456 | + } |
|
| 5457 | 5457 | |
| 5458 | - // pas de separateur au debut ni a la fin |
|
| 5459 | - $texte = trim($texte, $separateur); |
|
| 5458 | + // pas de separateur au debut ni a la fin |
|
| 5459 | + $texte = trim($texte, $separateur); |
|
| 5460 | 5460 | |
| 5461 | - // en minuscules |
|
| 5462 | - $texte = strtolower($texte); |
|
| 5461 | + // en minuscules |
|
| 5462 | + $texte = strtolower($texte); |
|
| 5463 | 5463 | |
| 5464 | - switch ($type) { |
|
| 5465 | - case 'class': |
|
| 5466 | - case 'id': |
|
| 5467 | - case 'anchor': |
|
| 5468 | - if (preg_match(',^\d,', $texte)) { |
|
| 5469 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5470 | - } |
|
| 5471 | - } |
|
| 5464 | + switch ($type) { |
|
| 5465 | + case 'class': |
|
| 5466 | + case 'id': |
|
| 5467 | + case 'anchor': |
|
| 5468 | + if (preg_match(',^\d,', $texte)) { |
|
| 5469 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5470 | + } |
|
| 5471 | + } |
|
| 5472 | 5472 | |
| 5473 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5474 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5475 | - } |
|
| 5473 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5474 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5475 | + } |
|
| 5476 | 5476 | |
| 5477 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5478 | - if (preg_match(',^\d,', $texte)) { |
|
| 5479 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5480 | - } |
|
| 5481 | - $texte .= $separateur . md5($original); |
|
| 5482 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5483 | - } |
|
| 5477 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5478 | + if (preg_match(',^\d,', $texte)) { |
|
| 5479 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5480 | + } |
|
| 5481 | + $texte .= $separateur . md5($original); |
|
| 5482 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5483 | + } |
|
| 5484 | 5484 | |
| 5485 | - return $texte; |
|
| 5485 | + return $texte; |
|
| 5486 | 5486 | } |
| 5487 | 5487 | |
| 5488 | 5488 | |
@@ -5503,11 +5503,11 @@ discard block |
||
| 5503 | 5503 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5504 | 5504 | */ |
| 5505 | 5505 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5506 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5507 | - if ($ucfirst) { |
|
| 5508 | - $label = spip_ucfirst($label); |
|
| 5509 | - } |
|
| 5510 | - return $label; |
|
| 5506 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5507 | + if ($ucfirst) { |
|
| 5508 | + $label = spip_ucfirst($label); |
|
| 5509 | + } |
|
| 5510 | + return $label; |
|
| 5511 | 5511 | } |
| 5512 | 5512 | |
| 5513 | 5513 | /** |
@@ -5520,8 +5520,8 @@ discard block |
||
| 5520 | 5520 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5521 | 5521 | */ |
| 5522 | 5522 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5523 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5524 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5523 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5524 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5525 | 5525 | } |
| 5526 | 5526 | |
| 5527 | 5527 | |
@@ -5534,19 +5534,19 @@ discard block |
||
| 5534 | 5534 | * @return array |
| 5535 | 5535 | */ |
| 5536 | 5536 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5537 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5538 | - return []; |
|
| 5539 | - } |
|
| 5537 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5538 | + return []; |
|
| 5539 | + } |
|
| 5540 | 5540 | |
| 5541 | - // compatibilite signature inversee |
|
| 5542 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5543 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5544 | - } |
|
| 5541 | + // compatibilite signature inversee |
|
| 5542 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5543 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5544 | + } |
|
| 5545 | 5545 | |
| 5546 | - if (!function_exists($fonction)) { |
|
| 5547 | - include_spip('base/objets'); |
|
| 5548 | - } |
|
| 5549 | - return $fonction($objet, $id_objet); |
|
| 5546 | + if (!function_exists($fonction)) { |
|
| 5547 | + include_spip('base/objets'); |
|
| 5548 | + } |
|
| 5549 | + return $fonction($objet, $id_objet); |
|
| 5550 | 5550 | } |
| 5551 | 5551 | |
| 5552 | 5552 | |
@@ -5561,7 +5561,7 @@ discard block |
||
| 5561 | 5561 | * @return array |
| 5562 | 5562 | */ |
| 5563 | 5563 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5564 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5564 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5565 | 5565 | } |
| 5566 | 5566 | |
| 5567 | 5567 | /** |
@@ -5575,7 +5575,7 @@ discard block |
||
| 5575 | 5575 | * @return array |
| 5576 | 5576 | */ |
| 5577 | 5577 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5578 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5578 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5579 | 5579 | } |
| 5580 | 5580 | |
| 5581 | 5581 | /** |
@@ -5589,7 +5589,7 @@ discard block |
||
| 5589 | 5589 | * @return array |
| 5590 | 5590 | */ |
| 5591 | 5591 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5592 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5592 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5593 | 5593 | } |
| 5594 | 5594 | |
| 5595 | 5595 | /** |
@@ -5603,5 +5603,5 @@ discard block |
||
| 5603 | 5603 | * @return array |
| 5604 | 5604 | */ |
| 5605 | 5605 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5606 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5606 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5607 | 5607 | } |