@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - // fonction ou name\space\fonction |
|
| 102 | - if (is_callable($f)) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | - elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | - return $f; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + // fonction ou name\space\fonction |
|
| 102 | + if (is_callable($f)) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | + elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | + return $f; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $default; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Chaîne vide sinon. |
| 153 | 153 | **/ |
| 154 | 154 | function appliquer_filtre($arg, $filtre) { |
| 155 | - $args = func_get_args(); |
|
| 156 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 155 | + $args = func_get_args(); |
|
| 156 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * Texte d'origine sinon |
| 179 | 179 | **/ |
| 180 | 180 | function appliquer_si_filtre($arg, $filtre) { |
| 181 | - $args = func_get_args(); |
|
| 182 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 181 | + $args = func_get_args(); |
|
| 182 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * Version de SPIP |
| 196 | 196 | **/ |
| 197 | 197 | function spip_version() { |
| 198 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | - $version .= " $vcs_version"; |
|
| 201 | - } |
|
| 198 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | + $version .= " $vcs_version"; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $version; |
|
| 203 | + return $version; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | 214 | function header_silencieux($version) { |
| 215 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | - $version = ''; |
|
| 217 | - } |
|
| 215 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | + $version = ''; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $version; |
|
| 219 | + return $version; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | * - string|null si $raw = false |
| 230 | 230 | */ |
| 231 | 231 | function version_vcs_courante($dir, $raw = false) { |
| 232 | - $desc = decrire_version_git($dir); |
|
| 233 | - if ($desc === null) { |
|
| 234 | - $desc = decrire_version_svn($dir); |
|
| 235 | - } |
|
| 236 | - if ($desc === null or $raw) { |
|
| 237 | - return $desc; |
|
| 238 | - } |
|
| 239 | - // affichage "GIT [master: abcdef]" |
|
| 240 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | - if ($desc['branch']) { |
|
| 242 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | - } |
|
| 244 | - return "{$desc['vcs']} [$commit]"; |
|
| 232 | + $desc = decrire_version_git($dir); |
|
| 233 | + if ($desc === null) { |
|
| 234 | + $desc = decrire_version_svn($dir); |
|
| 235 | + } |
|
| 236 | + if ($desc === null or $raw) { |
|
| 237 | + return $desc; |
|
| 238 | + } |
|
| 239 | + // affichage "GIT [master: abcdef]" |
|
| 240 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | + if ($desc['branch']) { |
|
| 242 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | + } |
|
| 244 | + return "{$desc['vcs']} [$commit]"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -253,24 +253,24 @@ discard block |
||
| 253 | 253 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 254 | 254 | **/ |
| 255 | 255 | function decrire_version_git($dir) { |
| 256 | - if (!$dir) { |
|
| 257 | - $dir = '.'; |
|
| 258 | - } |
|
| 256 | + if (!$dir) { |
|
| 257 | + $dir = '.'; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // version installee par GIT |
|
| 261 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | - $currentHead = trim(substr($c, 4)); |
|
| 263 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | - return [ |
|
| 265 | - 'vcs' => 'GIT', |
|
| 266 | - 'branch' => basename($currentHead), |
|
| 267 | - 'commit' => trim($hash), |
|
| 268 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | - ]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 260 | + // version installee par GIT |
|
| 261 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | + $currentHead = trim(substr($c, 4)); |
|
| 263 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | + return [ |
|
| 265 | + 'vcs' => 'GIT', |
|
| 266 | + 'branch' => basename($currentHead), |
|
| 267 | + 'commit' => trim($hash), |
|
| 268 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | + ]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - return null; |
|
| 273 | + return null; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -283,25 +283,25 @@ discard block |
||
| 283 | 283 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 284 | 284 | **/ |
| 285 | 285 | function decrire_version_svn($dir) { |
| 286 | - if (!$dir) { |
|
| 287 | - $dir = '.'; |
|
| 288 | - } |
|
| 289 | - // version installee par SVN |
|
| 290 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | - if ($result) { |
|
| 294 | - $row = $result->fetchArray(); |
|
| 295 | - if ($row['changed_revision'] != '') { |
|
| 296 | - return [ |
|
| 297 | - 'vcs' => 'SVN', |
|
| 298 | - 'branch' => '', |
|
| 299 | - 'commit' => $row['changed_revision'], |
|
| 300 | - ]; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return null; |
|
| 286 | + if (!$dir) { |
|
| 287 | + $dir = '.'; |
|
| 288 | + } |
|
| 289 | + // version installee par SVN |
|
| 290 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | + if ($result) { |
|
| 294 | + $row = $result->fetchArray(); |
|
| 295 | + if ($row['changed_revision'] != '') { |
|
| 296 | + return [ |
|
| 297 | + 'vcs' => 'SVN', |
|
| 298 | + 'branch' => '', |
|
| 299 | + 'commit' => $row['changed_revision'], |
|
| 300 | + ]; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return null; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | * Code HTML retourné par le filtre |
| 349 | 349 | **/ |
| 350 | 350 | function filtrer($filtre) { |
| 351 | - $tous = func_get_args(); |
|
| 352 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | - return image_filtrer($tous); |
|
| 354 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | - array_shift($tous); |
|
| 356 | - return call_user_func_array($f, $tous); |
|
| 357 | - } else { |
|
| 358 | - // le filtre n'existe pas, on provoque une erreur |
|
| 359 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | - erreur_squelette($msg); |
|
| 361 | - return ''; |
|
| 362 | - } |
|
| 351 | + $tous = func_get_args(); |
|
| 352 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | + return image_filtrer($tous); |
|
| 354 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | + array_shift($tous); |
|
| 356 | + return call_user_func_array($f, $tous); |
|
| 357 | + } else { |
|
| 358 | + // le filtre n'existe pas, on provoque une erreur |
|
| 359 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | + erreur_squelette($msg); |
|
| 361 | + return ''; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 377 | 377 | */ |
| 378 | 378 | function trouver_filtre_matrice($filtre) { |
| 379 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | - find_in_path($f, '', true); |
|
| 381 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | - } |
|
| 383 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | + find_in_path($f, '', true); |
|
| 381 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | + } |
|
| 383 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @return mixed |
| 409 | 409 | */ |
| 410 | 410 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 411 | - $Pile['vars'][$key] = $val; |
|
| 412 | - return $continue ? $val : ''; |
|
| 411 | + $Pile['vars'][$key] = $val; |
|
| 412 | + return $continue ? $val : ''; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 436 | 436 | */ |
| 437 | 437 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 438 | - $Pile[0][$key] = $val; |
|
| 439 | - return $continue ? $val : ''; |
|
| 438 | + $Pile[0][$key] = $val; |
|
| 439 | + return $continue ? $val : ''; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | 447 | function filtre_sanitize_env(&$Pile, $keys) { |
| 448 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | - return ''; |
|
| 448 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -469,18 +469,18 @@ discard block |
||
| 469 | 469 | * @return mixed Retourne la valeur (sans la modifier). |
| 470 | 470 | */ |
| 471 | 471 | function filtre_debug($val, $key = null) { |
| 472 | - $debug = ( |
|
| 473 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | - ) . var_export($val, true); |
|
| 472 | + $debug = ( |
|
| 473 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | + ) . var_export($val, true); |
|
| 475 | 475 | |
| 476 | - include_spip('inc/autoriser'); |
|
| 477 | - if (autoriser('webmestre')) { |
|
| 478 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | - } |
|
| 476 | + include_spip('inc/autoriser'); |
|
| 477 | + if (autoriser('webmestre')) { |
|
| 478 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - spip_log($debug, 'debug'); |
|
| 481 | + spip_log($debug, 'debug'); |
|
| 482 | 482 | |
| 483 | - return $val; |
|
| 483 | + return $val; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -508,89 +508,89 @@ discard block |
||
| 508 | 508 | * Texte qui a reçu les filtres |
| 509 | 509 | **/ |
| 510 | 510 | function image_filtrer($args) { |
| 511 | - $filtre = array_shift($args); # enlever $filtre |
|
| 512 | - $texte = array_shift($args); |
|
| 513 | - if ($texte === null || !strlen($texte)) { |
|
| 514 | - return; |
|
| 515 | - } |
|
| 516 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 517 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 518 | - // Cas du nom de fichier local |
|
| 519 | - $is_file = trim($texte); |
|
| 520 | - if ( |
|
| 521 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 522 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 523 | - or strpos($is_file, '/') === 0 |
|
| 524 | - ) { |
|
| 525 | - $is_file = false; |
|
| 526 | - } |
|
| 527 | - if ($is_file) { |
|
| 528 | - $is_local_file = function ($path) { |
|
| 529 | - if (strpos($path, '?') !== false) { |
|
| 530 | - $path = supprimer_timestamp($path); |
|
| 531 | - // remove ?24px added by find_in_theme on .svg files |
|
| 532 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 533 | - } |
|
| 534 | - return file_exists($path); |
|
| 535 | - }; |
|
| 536 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 537 | - array_unshift($args, "<img src='$is_file' />"); |
|
| 538 | - $res = call_user_func_array($filtre, $args); |
|
| 539 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 540 | - return $res; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 545 | - if ( |
|
| 546 | - preg_match_all( |
|
| 547 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 548 | - $texte, |
|
| 549 | - $tags, |
|
| 550 | - PREG_SET_ORDER |
|
| 551 | - ) |
|
| 552 | - ) { |
|
| 553 | - foreach ($tags as $tag) { |
|
| 554 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 555 | - if ( |
|
| 556 | - !$class or |
|
| 557 | - (strpos($class, 'filtre_inactif') === false |
|
| 558 | - // compat historique a virer en 3.2 |
|
| 559 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 560 | - ) { |
|
| 561 | - array_unshift($args, $tag[3]); |
|
| 562 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 563 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | - if ($tag[1]) { |
|
| 565 | - $w = extraire_attribut($reduit, 'width'); |
|
| 566 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | - $w = $regs[1]; |
|
| 568 | - } |
|
| 569 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | - $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - // traiter aussi un eventuel mouseover |
|
| 576 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | - $srcover = $match[1]; |
|
| 579 | - array_shift($args); |
|
| 580 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 581 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 582 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 583 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 587 | - } |
|
| 588 | - array_shift($args); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 593 | - return $texte; |
|
| 511 | + $filtre = array_shift($args); # enlever $filtre |
|
| 512 | + $texte = array_shift($args); |
|
| 513 | + if ($texte === null || !strlen($texte)) { |
|
| 514 | + return; |
|
| 515 | + } |
|
| 516 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 517 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 518 | + // Cas du nom de fichier local |
|
| 519 | + $is_file = trim($texte); |
|
| 520 | + if ( |
|
| 521 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 522 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 523 | + or strpos($is_file, '/') === 0 |
|
| 524 | + ) { |
|
| 525 | + $is_file = false; |
|
| 526 | + } |
|
| 527 | + if ($is_file) { |
|
| 528 | + $is_local_file = function ($path) { |
|
| 529 | + if (strpos($path, '?') !== false) { |
|
| 530 | + $path = supprimer_timestamp($path); |
|
| 531 | + // remove ?24px added by find_in_theme on .svg files |
|
| 532 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 533 | + } |
|
| 534 | + return file_exists($path); |
|
| 535 | + }; |
|
| 536 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 537 | + array_unshift($args, "<img src='$is_file' />"); |
|
| 538 | + $res = call_user_func_array($filtre, $args); |
|
| 539 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 540 | + return $res; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 545 | + if ( |
|
| 546 | + preg_match_all( |
|
| 547 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 548 | + $texte, |
|
| 549 | + $tags, |
|
| 550 | + PREG_SET_ORDER |
|
| 551 | + ) |
|
| 552 | + ) { |
|
| 553 | + foreach ($tags as $tag) { |
|
| 554 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 555 | + if ( |
|
| 556 | + !$class or |
|
| 557 | + (strpos($class, 'filtre_inactif') === false |
|
| 558 | + // compat historique a virer en 3.2 |
|
| 559 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 560 | + ) { |
|
| 561 | + array_unshift($args, $tag[3]); |
|
| 562 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 563 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | + if ($tag[1]) { |
|
| 565 | + $w = extraire_attribut($reduit, 'width'); |
|
| 566 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | + $w = $regs[1]; |
|
| 568 | + } |
|
| 569 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | + $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + // traiter aussi un eventuel mouseover |
|
| 576 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | + $srcover = $match[1]; |
|
| 579 | + array_shift($args); |
|
| 580 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 581 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 582 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 583 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 587 | + } |
|
| 588 | + array_shift($args); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 593 | + return $texte; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -607,91 +607,91 @@ discard block |
||
| 607 | 607 | **/ |
| 608 | 608 | function infos_image($img, $force_refresh = false) { |
| 609 | 609 | |
| 610 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 611 | - $srcWidth = 0; |
|
| 612 | - $srcHeight = 0; |
|
| 613 | - $srcSize = null; |
|
| 614 | - |
|
| 615 | - $src = extraire_attribut($img, 'src'); |
|
| 616 | - |
|
| 617 | - if (!$src) { |
|
| 618 | - $src = $img; |
|
| 619 | - } else { |
|
| 620 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 621 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 625 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 626 | - if (tester_url_absolue($src)) { |
|
| 627 | - include_spip('inc/distant'); |
|
| 628 | - $fichier = copie_locale($src); |
|
| 629 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 630 | - } |
|
| 631 | - if (($p = strpos($src, '?')) !== false) { |
|
| 632 | - $src = substr($src, 0, $p); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $imagesize = false; |
|
| 636 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 637 | - $srcWidth = $largeur_img[$src]; |
|
| 638 | - } |
|
| 639 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 640 | - $srcHeight = $hauteur_img[$src]; |
|
| 641 | - } |
|
| 642 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 643 | - $srcSize = $poids_img[$src]; |
|
| 644 | - } |
|
| 645 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 646 | - if ( |
|
| 647 | - file_exists($src) |
|
| 648 | - and $imagesize = spip_getimagesize($src) |
|
| 649 | - ) { |
|
| 650 | - if (!$srcWidth) { |
|
| 651 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 652 | - } |
|
| 653 | - if (!$srcHeight) { |
|
| 654 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 655 | - } |
|
| 656 | - if (!$srcSize){ |
|
| 657 | - $poids_img[$src] = filesize($src); |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - elseif (strpos($src, '<svg') !== false) { |
|
| 661 | - include_spip('inc/svg'); |
|
| 662 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 663 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 664 | - if (!$srcWidth) { |
|
| 665 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 666 | - } |
|
| 667 | - if (!$srcHeight) { |
|
| 668 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 669 | - } |
|
| 670 | - if (!$srcSize){ |
|
| 671 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 676 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 677 | - elseif ( |
|
| 678 | - @file_exists($f = "$src.src") |
|
| 679 | - and lire_fichier($f, $valeurs) |
|
| 680 | - and $valeurs = unserialize($valeurs) |
|
| 681 | - ) { |
|
| 682 | - if (!$srcWidth) { |
|
| 683 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 684 | - } |
|
| 685 | - if (!$srcHeight) { |
|
| 686 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 687 | - } |
|
| 688 | - if (!$srcSize){ |
|
| 689 | - $poids_img[$src] = $srcSize = 0; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 610 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 611 | + $srcWidth = 0; |
|
| 612 | + $srcHeight = 0; |
|
| 613 | + $srcSize = null; |
|
| 614 | + |
|
| 615 | + $src = extraire_attribut($img, 'src'); |
|
| 616 | + |
|
| 617 | + if (!$src) { |
|
| 618 | + $src = $img; |
|
| 619 | + } else { |
|
| 620 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 621 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 625 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 626 | + if (tester_url_absolue($src)) { |
|
| 627 | + include_spip('inc/distant'); |
|
| 628 | + $fichier = copie_locale($src); |
|
| 629 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 630 | + } |
|
| 631 | + if (($p = strpos($src, '?')) !== false) { |
|
| 632 | + $src = substr($src, 0, $p); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $imagesize = false; |
|
| 636 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 637 | + $srcWidth = $largeur_img[$src]; |
|
| 638 | + } |
|
| 639 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 640 | + $srcHeight = $hauteur_img[$src]; |
|
| 641 | + } |
|
| 642 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 643 | + $srcSize = $poids_img[$src]; |
|
| 644 | + } |
|
| 645 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 646 | + if ( |
|
| 647 | + file_exists($src) |
|
| 648 | + and $imagesize = spip_getimagesize($src) |
|
| 649 | + ) { |
|
| 650 | + if (!$srcWidth) { |
|
| 651 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 652 | + } |
|
| 653 | + if (!$srcHeight) { |
|
| 654 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 655 | + } |
|
| 656 | + if (!$srcSize){ |
|
| 657 | + $poids_img[$src] = filesize($src); |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + elseif (strpos($src, '<svg') !== false) { |
|
| 661 | + include_spip('inc/svg'); |
|
| 662 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 663 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 664 | + if (!$srcWidth) { |
|
| 665 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 666 | + } |
|
| 667 | + if (!$srcHeight) { |
|
| 668 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 669 | + } |
|
| 670 | + if (!$srcSize){ |
|
| 671 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 676 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 677 | + elseif ( |
|
| 678 | + @file_exists($f = "$src.src") |
|
| 679 | + and lire_fichier($f, $valeurs) |
|
| 680 | + and $valeurs = unserialize($valeurs) |
|
| 681 | + ) { |
|
| 682 | + if (!$srcWidth) { |
|
| 683 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 684 | + } |
|
| 685 | + if (!$srcHeight) { |
|
| 686 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 687 | + } |
|
| 688 | + if (!$srcSize){ |
|
| 689 | + $poids_img[$src] = $srcSize = 0; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -707,13 +707,13 @@ discard block |
||
| 707 | 707 | * poids |
| 708 | 708 | **/ |
| 709 | 709 | function poids_image($img, $force_refresh = false) { |
| 710 | - $infos = infos_image($img, $force_refresh); |
|
| 711 | - return $infos['poids']; |
|
| 710 | + $infos = infos_image($img, $force_refresh); |
|
| 711 | + return $infos['poids']; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | function taille_image($img, $force_refresh = false){ |
| 715 | - $infos = infos_image($img, $force_refresh); |
|
| 716 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 715 | + $infos = infos_image($img, $force_refresh); |
|
| 716 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -730,12 +730,12 @@ discard block |
||
| 730 | 730 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 731 | 731 | **/ |
| 732 | 732 | function largeur($img) { |
| 733 | - if (!$img) { |
|
| 734 | - return; |
|
| 735 | - } |
|
| 736 | - [$h, $l] = taille_image($img); |
|
| 733 | + if (!$img) { |
|
| 734 | + return; |
|
| 735 | + } |
|
| 736 | + [$h, $l] = taille_image($img); |
|
| 737 | 737 | |
| 738 | - return $l; |
|
| 738 | + return $l; |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -752,12 +752,12 @@ discard block |
||
| 752 | 752 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 753 | 753 | **/ |
| 754 | 754 | function hauteur($img) { |
| 755 | - if (!$img) { |
|
| 756 | - return; |
|
| 757 | - } |
|
| 758 | - [$h, $l] = taille_image($img); |
|
| 755 | + if (!$img) { |
|
| 756 | + return; |
|
| 757 | + } |
|
| 758 | + [$h, $l] = taille_image($img); |
|
| 759 | 759 | |
| 760 | - return $h; |
|
| 760 | + return $h; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | |
@@ -777,11 +777,11 @@ discard block |
||
| 777 | 777 | * @return string |
| 778 | 778 | **/ |
| 779 | 779 | function corriger_entites_html($texte) { |
| 780 | - if (strpos($texte, '&') === false) { |
|
| 781 | - return $texte; |
|
| 782 | - } |
|
| 780 | + if (strpos($texte, '&') === false) { |
|
| 781 | + return $texte; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 784 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /** |
@@ -796,11 +796,11 @@ discard block |
||
| 796 | 796 | * @return string |
| 797 | 797 | **/ |
| 798 | 798 | function corriger_toutes_entites_html($texte) { |
| 799 | - if (strpos($texte, '&') === false) { |
|
| 800 | - return $texte; |
|
| 801 | - } |
|
| 799 | + if (strpos($texte, '&') === false) { |
|
| 800 | + return $texte; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 803 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * @return string |
| 811 | 811 | **/ |
| 812 | 812 | function proteger_amp($texte) { |
| 813 | - return str_replace('&', '&', $texte); |
|
| 813 | + return str_replace('&', '&', $texte); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -841,21 +841,21 @@ discard block |
||
| 841 | 841 | * @return mixed|string |
| 842 | 842 | */ |
| 843 | 843 | function entites_html($texte, $tout = false, $quote = true) { |
| 844 | - if ( |
|
| 845 | - !is_string($texte) or !$texte |
|
| 846 | - or strpbrk($texte, "&\"'<>") == false |
|
| 847 | - ) { |
|
| 848 | - return $texte; |
|
| 849 | - } |
|
| 850 | - include_spip('inc/texte'); |
|
| 851 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 852 | - $flags |= ENT_HTML401; |
|
| 853 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 854 | - if ($tout) { |
|
| 855 | - return corriger_toutes_entites_html($texte); |
|
| 856 | - } else { |
|
| 857 | - return corriger_entites_html($texte); |
|
| 858 | - } |
|
| 844 | + if ( |
|
| 845 | + !is_string($texte) or !$texte |
|
| 846 | + or strpbrk($texte, "&\"'<>") == false |
|
| 847 | + ) { |
|
| 848 | + return $texte; |
|
| 849 | + } |
|
| 850 | + include_spip('inc/texte'); |
|
| 851 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 852 | + $flags |= ENT_HTML401; |
|
| 853 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 854 | + if ($tout) { |
|
| 855 | + return corriger_toutes_entites_html($texte); |
|
| 856 | + } else { |
|
| 857 | + return corriger_entites_html($texte); |
|
| 858 | + } |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
@@ -874,37 +874,37 @@ discard block |
||
| 874 | 874 | * Texte converti |
| 875 | 875 | **/ |
| 876 | 876 | function filtrer_entites($texte) { |
| 877 | - if (strpos($texte, '&') === false) { |
|
| 878 | - return $texte; |
|
| 879 | - } |
|
| 880 | - // filtrer |
|
| 881 | - $texte = html2unicode($texte); |
|
| 882 | - // remettre le tout dans le charset cible |
|
| 883 | - $texte = unicode2charset($texte); |
|
| 884 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 885 | - // (on le faisait deja avec un ") |
|
| 886 | - if (strpos($texte, '&#') !== false) { |
|
| 887 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 888 | - } |
|
| 877 | + if (strpos($texte, '&') === false) { |
|
| 878 | + return $texte; |
|
| 879 | + } |
|
| 880 | + // filtrer |
|
| 881 | + $texte = html2unicode($texte); |
|
| 882 | + // remettre le tout dans le charset cible |
|
| 883 | + $texte = unicode2charset($texte); |
|
| 884 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 885 | + // (on le faisait deja avec un ") |
|
| 886 | + if (strpos($texte, '&#') !== false) { |
|
| 887 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - return $texte; |
|
| 890 | + return $texte; |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | |
| 894 | 894 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 895 | - /** |
|
| 896 | - * Version sécurisée de filtrer_entites |
|
| 897 | - * |
|
| 898 | - * @uses interdire_scripts() |
|
| 899 | - * @uses filtrer_entites() |
|
| 900 | - * |
|
| 901 | - * @param string $t |
|
| 902 | - * @return string |
|
| 903 | - */ |
|
| 904 | - function filtre_filtrer_entites_dist($t) { |
|
| 905 | - include_spip('inc/texte'); |
|
| 906 | - return interdire_scripts(filtrer_entites($t)); |
|
| 907 | - } |
|
| 895 | + /** |
|
| 896 | + * Version sécurisée de filtrer_entites |
|
| 897 | + * |
|
| 898 | + * @uses interdire_scripts() |
|
| 899 | + * @uses filtrer_entites() |
|
| 900 | + * |
|
| 901 | + * @param string $t |
|
| 902 | + * @return string |
|
| 903 | + */ |
|
| 904 | + function filtre_filtrer_entites_dist($t) { |
|
| 905 | + include_spip('inc/texte'); |
|
| 906 | + return interdire_scripts(filtrer_entites($t)); |
|
| 907 | + } |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
@@ -919,18 +919,18 @@ discard block |
||
| 919 | 919 | * @return string|array |
| 920 | 920 | **/ |
| 921 | 921 | function supprimer_caracteres_illegaux($texte) { |
| 922 | - 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"; |
|
| 923 | - static $to = null; |
|
| 922 | + 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"; |
|
| 923 | + static $to = null; |
|
| 924 | 924 | |
| 925 | - if (is_array($texte)) { |
|
| 926 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 927 | - } |
|
| 925 | + if (is_array($texte)) { |
|
| 926 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | - if (!$to) { |
|
| 930 | - $to = str_repeat('-', strlen($from)); |
|
| 931 | - } |
|
| 929 | + if (!$to) { |
|
| 930 | + $to = str_repeat('-', strlen($from)); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return strtr($texte, $from, $to); |
|
| 933 | + return strtr($texte, $from, $to); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -942,10 +942,10 @@ discard block |
||
| 942 | 942 | * @return string|array |
| 943 | 943 | **/ |
| 944 | 944 | function corriger_caracteres($texte) { |
| 945 | - $texte = corriger_caracteres_windows($texte); |
|
| 946 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 945 | + $texte = corriger_caracteres_windows($texte); |
|
| 946 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 947 | 947 | |
| 948 | - return $texte; |
|
| 948 | + return $texte; |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -962,44 +962,44 @@ discard block |
||
| 962 | 962 | * Texte encodé pour XML |
| 963 | 963 | */ |
| 964 | 964 | function texte_backend(string $texte): string { |
| 965 | - if ($texte === '') { |
|
| 966 | - return ''; |
|
| 967 | - } |
|
| 965 | + if ($texte === '') { |
|
| 966 | + return ''; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 969 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 970 | 970 | |
| 971 | - // si on a des liens ou des images, les passer en absolu |
|
| 972 | - $texte = liens_absolus($texte); |
|
| 971 | + // si on a des liens ou des images, les passer en absolu |
|
| 972 | + $texte = liens_absolus($texte); |
|
| 973 | 973 | |
| 974 | - // echapper les tags > < |
|
| 975 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 974 | + // echapper les tags > < |
|
| 975 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 976 | 976 | |
| 977 | - // importer les é |
|
| 978 | - $texte = filtrer_entites($texte); |
|
| 977 | + // importer les é |
|
| 978 | + $texte = filtrer_entites($texte); |
|
| 979 | 979 | |
| 980 | - // " -> " et tout ce genre de choses |
|
| 981 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 982 | - $texte = str_replace(' ', ' ', $texte); |
|
| 983 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 984 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 985 | - $texte = entites_html($texte, false, false); |
|
| 986 | - // mais bien echapper les double quotes ! |
|
| 987 | - $texte = str_replace('"', '"', $texte); |
|
| 980 | + // " -> " et tout ce genre de choses |
|
| 981 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 982 | + $texte = str_replace(' ', ' ', $texte); |
|
| 983 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 984 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 985 | + $texte = entites_html($texte, false, false); |
|
| 986 | + // mais bien echapper les double quotes ! |
|
| 987 | + $texte = str_replace('"', '"', $texte); |
|
| 988 | 988 | |
| 989 | - // verifier le charset |
|
| 990 | - $texte = charset2unicode($texte); |
|
| 989 | + // verifier le charset |
|
| 990 | + $texte = charset2unicode($texte); |
|
| 991 | 991 | |
| 992 | - // Caracteres problematiques en iso-latin 1 |
|
| 993 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 994 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 995 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 996 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 997 | - } |
|
| 992 | + // Caracteres problematiques en iso-latin 1 |
|
| 993 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 994 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 995 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 996 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 997 | + } |
|
| 998 | 998 | |
| 999 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 1000 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 1001 | - // ==> on les remplace par l'entite HTML |
|
| 1002 | - return str_replace($apostrophe, "'", $texte); |
|
| 999 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 1000 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 1001 | + // ==> on les remplace par l'entite HTML |
|
| 1002 | + return str_replace($apostrophe, "'", $texte); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | * Texte encodé et quote pour XML |
| 1017 | 1017 | */ |
| 1018 | 1018 | function texte_backendq(string $texte): string { |
| 1019 | - return addslashes(texte_backend($texte)); |
|
| 1019 | + return addslashes(texte_backend($texte)); |
|
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | |
@@ -1039,11 +1039,11 @@ discard block |
||
| 1039 | 1039 | * Numéro de titre, sinon chaîne vide |
| 1040 | 1040 | **/ |
| 1041 | 1041 | function supprimer_numero($texte) { |
| 1042 | - return preg_replace( |
|
| 1043 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1044 | - '', |
|
| 1045 | - $texte |
|
| 1046 | - ); |
|
| 1042 | + return preg_replace( |
|
| 1043 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1044 | + '', |
|
| 1045 | + $texte |
|
| 1046 | + ); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1066,17 +1066,17 @@ discard block |
||
| 1066 | 1066 | * Numéro de titre, sinon chaîne vide |
| 1067 | 1067 | **/ |
| 1068 | 1068 | function recuperer_numero($texte) { |
| 1069 | - if ( |
|
| 1070 | - preg_match( |
|
| 1071 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1072 | - $texte, |
|
| 1073 | - $regs |
|
| 1074 | - ) |
|
| 1075 | - ) { |
|
| 1076 | - return strval($regs[1]); |
|
| 1077 | - } else { |
|
| 1078 | - return ''; |
|
| 1079 | - } |
|
| 1069 | + if ( |
|
| 1070 | + preg_match( |
|
| 1071 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1072 | + $texte, |
|
| 1073 | + $regs |
|
| 1074 | + ) |
|
| 1075 | + ) { |
|
| 1076 | + return strval($regs[1]); |
|
| 1077 | + } else { |
|
| 1078 | + return ''; |
|
| 1079 | + } |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * Texte converti |
| 1104 | 1104 | **/ |
| 1105 | 1105 | function supprimer_tags(?string $texte, $rempl = ''): string { |
| 1106 | - if ($texte === null || !strlen($texte)) { |
|
| 1107 | - return ''; |
|
| 1108 | - } |
|
| 1109 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1110 | - // ne pas oublier un < final non ferme car coupe |
|
| 1111 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1112 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1113 | - $texte = str_replace('<', '<', $texte); |
|
| 1106 | + if ($texte === null || !strlen($texte)) { |
|
| 1107 | + return ''; |
|
| 1108 | + } |
|
| 1109 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1110 | + // ne pas oublier un < final non ferme car coupe |
|
| 1111 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1112 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1113 | + $texte = str_replace('<', '<', $texte); |
|
| 1114 | 1114 | |
| 1115 | - return $texte; |
|
| 1115 | + return $texte; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1135,9 +1135,9 @@ discard block |
||
| 1135 | 1135 | * Texte converti |
| 1136 | 1136 | **/ |
| 1137 | 1137 | function echapper_tags($texte, $rempl = '') { |
| 1138 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1138 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1139 | 1139 | |
| 1140 | - return $texte; |
|
| 1140 | + return $texte; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | /** |
@@ -1158,18 +1158,18 @@ discard block |
||
| 1158 | 1158 | * Texte converti |
| 1159 | 1159 | **/ |
| 1160 | 1160 | function textebrut($texte) { |
| 1161 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1162 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1164 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1165 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1166 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1167 | - $texte = supprimer_tags($texte); |
|
| 1168 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1169 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1170 | - $texte = str_replace('’', "'", $texte); |
|
| 1161 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1162 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1164 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1165 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1166 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1167 | + $texte = supprimer_tags($texte); |
|
| 1168 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1169 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1170 | + $texte = str_replace('’', "'", $texte); |
|
| 1171 | 1171 | |
| 1172 | - return $texte; |
|
| 1172 | + return $texte; |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | |
@@ -1185,23 +1185,23 @@ discard block |
||
| 1185 | 1185 | * Texte avec liens ouvrants |
| 1186 | 1186 | **/ |
| 1187 | 1187 | function liens_ouvrants($texte) { |
| 1188 | - if ( |
|
| 1189 | - preg_match_all( |
|
| 1190 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1191 | - $texte, |
|
| 1192 | - $liens, |
|
| 1193 | - PREG_PATTERN_ORDER |
|
| 1194 | - ) |
|
| 1195 | - ) { |
|
| 1196 | - foreach ($liens[0] as $a) { |
|
| 1197 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1198 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1199 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1200 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - return $texte; |
|
| 1188 | + if ( |
|
| 1189 | + preg_match_all( |
|
| 1190 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1191 | + $texte, |
|
| 1192 | + $liens, |
|
| 1193 | + PREG_PATTERN_ORDER |
|
| 1194 | + ) |
|
| 1195 | + ) { |
|
| 1196 | + foreach ($liens[0] as $a) { |
|
| 1197 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1198 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1199 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1200 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + return $texte; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | /** |
@@ -1211,22 +1211,22 @@ discard block |
||
| 1211 | 1211 | * @return string |
| 1212 | 1212 | */ |
| 1213 | 1213 | function liens_nofollow($texte) { |
| 1214 | - if (stripos($texte, '<a') === false) { |
|
| 1215 | - return $texte; |
|
| 1216 | - } |
|
| 1214 | + if (stripos($texte, '<a') === false) { |
|
| 1215 | + return $texte; |
|
| 1216 | + } |
|
| 1217 | 1217 | |
| 1218 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1219 | - foreach ($regs[0] as $a) { |
|
| 1220 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1221 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1222 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1223 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1224 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1225 | - } |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1218 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1219 | + foreach ($regs[0] as $a) { |
|
| 1220 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1221 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1222 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1223 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1224 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1225 | + } |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | 1228 | |
| 1229 | - return $texte; |
|
| 1229 | + return $texte; |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1245,12 +1245,12 @@ discard block |
||
| 1245 | 1245 | * Texte sans paraghaphes |
| 1246 | 1246 | **/ |
| 1247 | 1247 | function PtoBR($texte) { |
| 1248 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1249 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1250 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1251 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1248 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1249 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1250 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1251 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1252 | 1252 | |
| 1253 | - return $texte; |
|
| 1253 | + return $texte; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1275,14 +1275,14 @@ discard block |
||
| 1275 | 1275 | * @return string Texte encadré du style CSS |
| 1276 | 1276 | */ |
| 1277 | 1277 | function lignes_longues($texte) { |
| 1278 | - if (!strlen(trim($texte))) { |
|
| 1279 | - return $texte; |
|
| 1280 | - } |
|
| 1281 | - include_spip('inc/texte'); |
|
| 1282 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1283 | - 'div' : 'span'; |
|
| 1278 | + if (!strlen(trim($texte))) { |
|
| 1279 | + return $texte; |
|
| 1280 | + } |
|
| 1281 | + include_spip('inc/texte'); |
|
| 1282 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1283 | + 'div' : 'span'; |
|
| 1284 | 1284 | |
| 1285 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1285 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1301,30 +1301,30 @@ discard block |
||
| 1301 | 1301 | * @return string Texte en majuscule |
| 1302 | 1302 | */ |
| 1303 | 1303 | function majuscules($texte) { |
| 1304 | - if (!strlen($texte)) { |
|
| 1305 | - return ''; |
|
| 1306 | - } |
|
| 1304 | + if (!strlen($texte)) { |
|
| 1305 | + return ''; |
|
| 1306 | + } |
|
| 1307 | 1307 | |
| 1308 | - // Cas du turc |
|
| 1309 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1310 | - # remplacer hors des tags et des entites |
|
| 1311 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1312 | - foreach ($regs as $n => $match) { |
|
| 1313 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1308 | + // Cas du turc |
|
| 1309 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1310 | + # remplacer hors des tags et des entites |
|
| 1311 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1312 | + foreach ($regs as $n => $match) { |
|
| 1313 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | 1316 | |
| 1317 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1317 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1318 | 1318 | |
| 1319 | - if ($regs) { |
|
| 1320 | - foreach ($regs as $n => $match) { |
|
| 1321 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1319 | + if ($regs) { |
|
| 1320 | + foreach ($regs as $n => $match) { |
|
| 1321 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1322 | + } |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - // Cas general |
|
| 1327 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1326 | + // Cas general |
|
| 1327 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /** |
@@ -1342,29 +1342,29 @@ discard block |
||
| 1342 | 1342 | * @return string |
| 1343 | 1343 | **/ |
| 1344 | 1344 | function taille_en_octets($taille) { |
| 1345 | - if (!defined('_KILOBYTE')) { |
|
| 1346 | - /** |
|
| 1347 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1348 | - * |
|
| 1349 | - * @var int |
|
| 1350 | - **/ |
|
| 1351 | - define('_KILOBYTE', 1024); |
|
| 1352 | - } |
|
| 1345 | + if (!defined('_KILOBYTE')) { |
|
| 1346 | + /** |
|
| 1347 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1348 | + * |
|
| 1349 | + * @var int |
|
| 1350 | + **/ |
|
| 1351 | + define('_KILOBYTE', 1024); |
|
| 1352 | + } |
|
| 1353 | 1353 | |
| 1354 | - if ($taille < 1) { |
|
| 1355 | - return ''; |
|
| 1356 | - } |
|
| 1357 | - if ($taille < _KILOBYTE) { |
|
| 1358 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1359 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1360 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1361 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1362 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1363 | - } else { |
|
| 1364 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1365 | - } |
|
| 1354 | + if ($taille < 1) { |
|
| 1355 | + return ''; |
|
| 1356 | + } |
|
| 1357 | + if ($taille < _KILOBYTE) { |
|
| 1358 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1359 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1360 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1361 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1362 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1363 | + } else { |
|
| 1364 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1365 | + } |
|
| 1366 | 1366 | |
| 1367 | - return $taille; |
|
| 1367 | + return $taille; |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
@@ -1386,21 +1386,21 @@ discard block |
||
| 1386 | 1386 | * Texte prêt pour être utilisé en attribut HTML |
| 1387 | 1387 | **/ |
| 1388 | 1388 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1389 | - if ($texte === null) { |
|
| 1390 | - return ''; |
|
| 1391 | - } |
|
| 1392 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1393 | - if ($textebrut) { |
|
| 1394 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1395 | - } |
|
| 1396 | - $texte = texte_backend($texte); |
|
| 1397 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1389 | + if ($texte === null) { |
|
| 1390 | + return ''; |
|
| 1391 | + } |
|
| 1392 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1393 | + if ($textebrut) { |
|
| 1394 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1395 | + } |
|
| 1396 | + $texte = texte_backend($texte); |
|
| 1397 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1398 | 1398 | |
| 1399 | - return preg_replace( |
|
| 1400 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1401 | - ['&', '&'], |
|
| 1402 | - $texte |
|
| 1403 | - ); |
|
| 1399 | + return preg_replace( |
|
| 1400 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1401 | + ['&', '&'], |
|
| 1402 | + $texte |
|
| 1403 | + ); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | 1406 | |
@@ -1420,15 +1420,15 @@ discard block |
||
| 1420 | 1420 | * URL ou chaîne vide |
| 1421 | 1421 | **/ |
| 1422 | 1422 | function vider_url(?string $url, $entites = true): string { |
| 1423 | - if ($url === null) { |
|
| 1424 | - return ''; |
|
| 1425 | - } |
|
| 1426 | - # un message pour abs_url |
|
| 1427 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1428 | - $url = trim($url); |
|
| 1429 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1423 | + if ($url === null) { |
|
| 1424 | + return ''; |
|
| 1425 | + } |
|
| 1426 | + # un message pour abs_url |
|
| 1427 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1428 | + $url = trim($url); |
|
| 1429 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1430 | 1430 | |
| 1431 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1431 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | |
@@ -1443,10 +1443,10 @@ discard block |
||
| 1443 | 1443 | * @return string Adresse email maquillée |
| 1444 | 1444 | **/ |
| 1445 | 1445 | function antispam($texte) { |
| 1446 | - include_spip('inc/acces'); |
|
| 1447 | - $masque = creer_pass_aleatoire(3); |
|
| 1446 | + include_spip('inc/acces'); |
|
| 1447 | + $masque = creer_pass_aleatoire(3); |
|
| 1448 | 1448 | |
| 1449 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1449 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
@@ -1478,8 +1478,8 @@ discard block |
||
| 1478 | 1478 | * True si on a le droit d'accès, false sinon. |
| 1479 | 1479 | **/ |
| 1480 | 1480 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1481 | - include_spip('inc/acces'); |
|
| 1482 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1481 | + include_spip('inc/acces'); |
|
| 1482 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1504,13 +1504,13 @@ discard block |
||
| 1504 | 1504 | * Retourne $texte, sinon $sinon. |
| 1505 | 1505 | **/ |
| 1506 | 1506 | function sinon($texte, $sinon = '') { |
| 1507 | - if ($texte) { |
|
| 1508 | - return $texte; |
|
| 1509 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1510 | - return $texte; |
|
| 1511 | - } else { |
|
| 1512 | - return $sinon; |
|
| 1513 | - } |
|
| 1507 | + if ($texte) { |
|
| 1508 | + return $texte; |
|
| 1509 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1510 | + return $texte; |
|
| 1511 | + } else { |
|
| 1512 | + return $sinon; |
|
| 1513 | + } |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | /** |
@@ -1534,7 +1534,7 @@ discard block |
||
| 1534 | 1534 | * @return mixed |
| 1535 | 1535 | **/ |
| 1536 | 1536 | function choixsivide($a, $vide, $pasvide) { |
| 1537 | - return $a ? $pasvide : $vide; |
|
| 1537 | + return $a ? $pasvide : $vide; |
|
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | 1540 | /** |
@@ -1558,7 +1558,7 @@ discard block |
||
| 1558 | 1558 | * @return mixed |
| 1559 | 1559 | **/ |
| 1560 | 1560 | function choixsiegal($a1, $a2, $v, $f) { |
| 1561 | - return ($a1 == $a2) ? $v : $f; |
|
| 1561 | + return ($a1 == $a2) ? $v : $f; |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | // |
@@ -1577,13 +1577,13 @@ discard block |
||
| 1577 | 1577 | * @return string |
| 1578 | 1578 | **/ |
| 1579 | 1579 | function filtrer_ical($texte) { |
| 1580 | - #include_spip('inc/charsets'); |
|
| 1581 | - $texte = html2unicode($texte); |
|
| 1582 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1583 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1584 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1580 | + #include_spip('inc/charsets'); |
|
| 1581 | + $texte = html2unicode($texte); |
|
| 1582 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1583 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1584 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1585 | 1585 | |
| 1586 | - return $texte; |
|
| 1586 | + return $texte; |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | |
@@ -1608,54 +1608,54 @@ discard block |
||
| 1608 | 1608 | * @return string |
| 1609 | 1609 | **/ |
| 1610 | 1610 | function post_autobr($texte, $delim = "\n_ ") { |
| 1611 | - if (!function_exists('echappe_html')) { |
|
| 1612 | - include_spip('inc/texte_mini'); |
|
| 1613 | - } |
|
| 1614 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1615 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1616 | - |
|
| 1617 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1618 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1619 | - } else { |
|
| 1620 | - $fin = ''; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - $texte = echappe_html($texte, '', true); |
|
| 1624 | - |
|
| 1625 | - // echapper les modeles |
|
| 1626 | - if (strpos($texte, '<') !== false) { |
|
| 1627 | - include_spip('inc/lien'); |
|
| 1628 | - if (defined('_PREG_MODELE')) { |
|
| 1629 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1630 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1631 | - } |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - $debut = ''; |
|
| 1635 | - $suite = $texte; |
|
| 1636 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1637 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1638 | - $suite = substr($suite, $t); |
|
| 1639 | - $car = substr($suite, 0, 1); |
|
| 1640 | - if ( |
|
| 1641 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1642 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1643 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1644 | - ) { |
|
| 1645 | - $debut .= $delim; |
|
| 1646 | - } else { |
|
| 1647 | - $debut .= "\n"; |
|
| 1648 | - } |
|
| 1649 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1650 | - $debut .= $regs[0]; |
|
| 1651 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - $texte = $debut . $suite; |
|
| 1655 | - |
|
| 1656 | - $texte = echappe_retour($texte); |
|
| 1657 | - |
|
| 1658 | - return $texte . $fin; |
|
| 1611 | + if (!function_exists('echappe_html')) { |
|
| 1612 | + include_spip('inc/texte_mini'); |
|
| 1613 | + } |
|
| 1614 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1615 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1616 | + |
|
| 1617 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1618 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1619 | + } else { |
|
| 1620 | + $fin = ''; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + $texte = echappe_html($texte, '', true); |
|
| 1624 | + |
|
| 1625 | + // echapper les modeles |
|
| 1626 | + if (strpos($texte, '<') !== false) { |
|
| 1627 | + include_spip('inc/lien'); |
|
| 1628 | + if (defined('_PREG_MODELE')) { |
|
| 1629 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1630 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1631 | + } |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + $debut = ''; |
|
| 1635 | + $suite = $texte; |
|
| 1636 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1637 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1638 | + $suite = substr($suite, $t); |
|
| 1639 | + $car = substr($suite, 0, 1); |
|
| 1640 | + if ( |
|
| 1641 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1642 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1643 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1644 | + ) { |
|
| 1645 | + $debut .= $delim; |
|
| 1646 | + } else { |
|
| 1647 | + $debut .= "\n"; |
|
| 1648 | + } |
|
| 1649 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1650 | + $debut .= $regs[0]; |
|
| 1651 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + $texte = $debut . $suite; |
|
| 1655 | + |
|
| 1656 | + $texte = echappe_retour($texte); |
|
| 1657 | + |
|
| 1658 | + return $texte . $fin; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1696,47 +1696,47 @@ discard block |
||
| 1696 | 1696 | * @return string |
| 1697 | 1697 | **/ |
| 1698 | 1698 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1699 | - static $traduire = false; |
|
| 1700 | - if ( |
|
| 1701 | - $letexte |
|
| 1702 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1703 | - ) { |
|
| 1704 | - if (!$traduire) { |
|
| 1705 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1706 | - include_spip('inc/lang'); |
|
| 1707 | - } |
|
| 1708 | - if (!$lang) { |
|
| 1709 | - $lang = $GLOBALS['spip_lang']; |
|
| 1710 | - } |
|
| 1711 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1712 | - if (is_bool($options)) { |
|
| 1713 | - $options = ['echappe_span' => $options]; |
|
| 1714 | - } |
|
| 1715 | - if (!isset($options['echappe_span'])) { |
|
| 1716 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - foreach ($regs as $reg) { |
|
| 1720 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1721 | - $desc = $traduire($cle, $lang, true); |
|
| 1722 | - $l = $desc->langue; |
|
| 1723 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1724 | - if (strlen($desc->texte)) { |
|
| 1725 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1726 | - if ($l !== $lang) { |
|
| 1727 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1728 | - } |
|
| 1729 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1730 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1731 | - } |
|
| 1732 | - if (!$options['echappe_span']) { |
|
| 1733 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1734 | - } |
|
| 1735 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1736 | - } |
|
| 1737 | - } |
|
| 1738 | - } |
|
| 1739 | - return $letexte; |
|
| 1699 | + static $traduire = false; |
|
| 1700 | + if ( |
|
| 1701 | + $letexte |
|
| 1702 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1703 | + ) { |
|
| 1704 | + if (!$traduire) { |
|
| 1705 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1706 | + include_spip('inc/lang'); |
|
| 1707 | + } |
|
| 1708 | + if (!$lang) { |
|
| 1709 | + $lang = $GLOBALS['spip_lang']; |
|
| 1710 | + } |
|
| 1711 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1712 | + if (is_bool($options)) { |
|
| 1713 | + $options = ['echappe_span' => $options]; |
|
| 1714 | + } |
|
| 1715 | + if (!isset($options['echappe_span'])) { |
|
| 1716 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + foreach ($regs as $reg) { |
|
| 1720 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1721 | + $desc = $traduire($cle, $lang, true); |
|
| 1722 | + $l = $desc->langue; |
|
| 1723 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1724 | + if (strlen($desc->texte)) { |
|
| 1725 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1726 | + if ($l !== $lang) { |
|
| 1727 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1728 | + } |
|
| 1729 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1730 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1731 | + } |
|
| 1732 | + if (!$options['echappe_span']) { |
|
| 1733 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1734 | + } |
|
| 1735 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + return $letexte; |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | /** |
@@ -1788,68 +1788,68 @@ discard block |
||
| 1788 | 1788 | **/ |
| 1789 | 1789 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1790 | 1790 | |
| 1791 | - if ( |
|
| 1792 | - $letexte |
|
| 1793 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1794 | - ) { |
|
| 1795 | - if (!$lang) { |
|
| 1796 | - $lang = $GLOBALS['spip_lang']; |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1800 | - if (is_bool($options)) { |
|
| 1801 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1802 | - } |
|
| 1803 | - if (!isset($options['echappe_span'])) { |
|
| 1804 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1805 | - } |
|
| 1806 | - if (!isset($options['lang_defaut'])) { |
|
| 1807 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - include_spip('inc/lang'); |
|
| 1811 | - foreach ($regs as $reg) { |
|
| 1812 | - // chercher la version de la langue courante |
|
| 1813 | - $trads = extraire_trads($reg[1]); |
|
| 1814 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1815 | - $trad = $trads[$l]; |
|
| 1816 | - } else { |
|
| 1817 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1818 | - $trad = ''; |
|
| 1819 | - } else { |
|
| 1820 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1821 | - // ou la premiere dispo |
|
| 1822 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1823 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1824 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1825 | - $l = key($trads); |
|
| 1826 | - } |
|
| 1827 | - $trad = $trads[$l]; |
|
| 1828 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1829 | - $trad = $typographie($trad); |
|
| 1830 | - // Tester si on echappe en span ou en div |
|
| 1831 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1832 | - include_spip('inc/texte'); |
|
| 1833 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1834 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | - if ($mode === 'div') { |
|
| 1836 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1837 | - } |
|
| 1838 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1839 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1840 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1841 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1842 | - } |
|
| 1843 | - if (!$options['echappe_span']) { |
|
| 1844 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1845 | - } |
|
| 1846 | - } |
|
| 1847 | - } |
|
| 1848 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1849 | - } |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - return $letexte; |
|
| 1791 | + if ( |
|
| 1792 | + $letexte |
|
| 1793 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1794 | + ) { |
|
| 1795 | + if (!$lang) { |
|
| 1796 | + $lang = $GLOBALS['spip_lang']; |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1800 | + if (is_bool($options)) { |
|
| 1801 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1802 | + } |
|
| 1803 | + if (!isset($options['echappe_span'])) { |
|
| 1804 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1805 | + } |
|
| 1806 | + if (!isset($options['lang_defaut'])) { |
|
| 1807 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + include_spip('inc/lang'); |
|
| 1811 | + foreach ($regs as $reg) { |
|
| 1812 | + // chercher la version de la langue courante |
|
| 1813 | + $trads = extraire_trads($reg[1]); |
|
| 1814 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1815 | + $trad = $trads[$l]; |
|
| 1816 | + } else { |
|
| 1817 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1818 | + $trad = ''; |
|
| 1819 | + } else { |
|
| 1820 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1821 | + // ou la premiere dispo |
|
| 1822 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1823 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1824 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1825 | + $l = key($trads); |
|
| 1826 | + } |
|
| 1827 | + $trad = $trads[$l]; |
|
| 1828 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1829 | + $trad = $typographie($trad); |
|
| 1830 | + // Tester si on echappe en span ou en div |
|
| 1831 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1832 | + include_spip('inc/texte'); |
|
| 1833 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1834 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | + if ($mode === 'div') { |
|
| 1836 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1837 | + } |
|
| 1838 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1839 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1840 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1841 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1842 | + } |
|
| 1843 | + if (!$options['echappe_span']) { |
|
| 1844 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1845 | + } |
|
| 1846 | + } |
|
| 1847 | + } |
|
| 1848 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1849 | + } |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + return $letexte; |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | /** |
@@ -1865,21 +1865,21 @@ discard block |
||
| 1865 | 1865 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function extraire_trads($bloc) { |
| 1868 | - $trads = []; |
|
| 1869 | - $lang = ''; |
|
| 1868 | + $trads = []; |
|
| 1869 | + $lang = ''; |
|
| 1870 | 1870 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1871 | 1871 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1872 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1873 | - $texte = trim($regs[1]); |
|
| 1874 | - if ($texte or $lang) { |
|
| 1875 | - $trads[$lang] = $texte; |
|
| 1876 | - } |
|
| 1877 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1878 | - $lang = $regs[2]; |
|
| 1879 | - } |
|
| 1880 | - $trads[$lang] = $bloc; |
|
| 1872 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1873 | + $texte = trim($regs[1]); |
|
| 1874 | + if ($texte or $lang) { |
|
| 1875 | + $trads[$lang] = $texte; |
|
| 1876 | + } |
|
| 1877 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1878 | + $lang = $regs[2]; |
|
| 1879 | + } |
|
| 1880 | + $trads[$lang] = $bloc; |
|
| 1881 | 1881 | |
| 1882 | - return $trads; |
|
| 1882 | + return $trads; |
|
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | |
@@ -1890,7 +1890,7 @@ discard block |
||
| 1890 | 1890 | * @return string L'initiale en majuscule |
| 1891 | 1891 | */ |
| 1892 | 1892 | function filtre_initiale($nom) { |
| 1893 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1893 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | |
@@ -1935,33 +1935,33 @@ discard block |
||
| 1935 | 1935 | * - null (interne) : si on empile |
| 1936 | 1936 | **/ |
| 1937 | 1937 | function unique($donnee, $famille = '', $cpt = false) { |
| 1938 | - static $mem = []; |
|
| 1939 | - // permettre de vider la pile et de la restaurer |
|
| 1940 | - // pour le calcul de introduction... |
|
| 1941 | - if ($famille == '_spip_raz_') { |
|
| 1942 | - $tmp = $mem; |
|
| 1943 | - $mem = []; |
|
| 1944 | - |
|
| 1945 | - return $tmp; |
|
| 1946 | - } elseif ($famille == '_spip_set_') { |
|
| 1947 | - $mem = $donnee; |
|
| 1948 | - |
|
| 1949 | - return; |
|
| 1950 | - } |
|
| 1951 | - // eviter une notice |
|
| 1952 | - if (!isset($mem[$famille])) { |
|
| 1953 | - $mem[$famille] = []; |
|
| 1954 | - } |
|
| 1955 | - if ($cpt) { |
|
| 1956 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1957 | - } |
|
| 1958 | - // eviter une notice |
|
| 1959 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1960 | - $mem[$famille][$donnee] = 0; |
|
| 1961 | - } |
|
| 1962 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1963 | - return $donnee; |
|
| 1964 | - } |
|
| 1938 | + static $mem = []; |
|
| 1939 | + // permettre de vider la pile et de la restaurer |
|
| 1940 | + // pour le calcul de introduction... |
|
| 1941 | + if ($famille == '_spip_raz_') { |
|
| 1942 | + $tmp = $mem; |
|
| 1943 | + $mem = []; |
|
| 1944 | + |
|
| 1945 | + return $tmp; |
|
| 1946 | + } elseif ($famille == '_spip_set_') { |
|
| 1947 | + $mem = $donnee; |
|
| 1948 | + |
|
| 1949 | + return; |
|
| 1950 | + } |
|
| 1951 | + // eviter une notice |
|
| 1952 | + if (!isset($mem[$famille])) { |
|
| 1953 | + $mem[$famille] = []; |
|
| 1954 | + } |
|
| 1955 | + if ($cpt) { |
|
| 1956 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1957 | + } |
|
| 1958 | + // eviter une notice |
|
| 1959 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1960 | + $mem[$famille][$donnee] = 0; |
|
| 1961 | + } |
|
| 1962 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1963 | + return $donnee; |
|
| 1964 | + } |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | |
@@ -1991,20 +1991,20 @@ discard block |
||
| 1991 | 1991 | * Une des valeurs en fonction du compteur. |
| 1992 | 1992 | **/ |
| 1993 | 1993 | function alterner($i, ...$args) { |
| 1994 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1995 | - $num = count($args); |
|
| 1994 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1995 | + $num = count($args); |
|
| 1996 | 1996 | |
| 1997 | - if ($num === 1 && is_array($args[0])) { |
|
| 1998 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1999 | - $args = array_values($args[0]); |
|
| 2000 | - $num = count($args); |
|
| 2001 | - } |
|
| 1997 | + if ($num === 1 && is_array($args[0])) { |
|
| 1998 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1999 | + $args = array_values($args[0]); |
|
| 2000 | + $num = count($args); |
|
| 2001 | + } |
|
| 2002 | 2002 | |
| 2003 | - // un index compris entre 0 et num exclus |
|
| 2004 | - $i = ((intval($i) -1) % $num); // dans ]-$num;$num[ |
|
| 2005 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 2006 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2007 | - return $args[$i]; |
|
| 2003 | + // un index compris entre 0 et num exclus |
|
| 2004 | + $i = ((intval($i) -1) % $num); // dans ]-$num;$num[ |
|
| 2005 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 2006 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2007 | + return $args[$i]; |
|
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | 2010 | |
@@ -2030,51 +2030,51 @@ discard block |
||
| 2030 | 2030 | * - null lorsque l’attribut n’existe pas. |
| 2031 | 2031 | **/ |
| 2032 | 2032 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 2033 | - if (is_array($balise)) { |
|
| 2034 | - array_walk( |
|
| 2035 | - $balise, |
|
| 2036 | - function (&$a, $key, $t) { |
|
| 2037 | - $a = extraire_attribut($a, $t); |
|
| 2038 | - }, |
|
| 2039 | - $attribut |
|
| 2040 | - ); |
|
| 2041 | - |
|
| 2042 | - return $balise; |
|
| 2043 | - } |
|
| 2044 | - if ( |
|
| 2045 | - $balise |
|
| 2046 | - && preg_match( |
|
| 2047 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2048 | - . $attribut |
|
| 2049 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2050 | - $balise, |
|
| 2051 | - $r |
|
| 2052 | - ) |
|
| 2053 | - ) { |
|
| 2054 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2055 | - $r[4] = substr($r[3], 1, -1); |
|
| 2056 | - $r[3] = $r[3][0]; |
|
| 2057 | - } elseif ($r[3] !== '') { |
|
| 2058 | - $r[4] = $r[3]; |
|
| 2059 | - $r[3] = ''; |
|
| 2060 | - } else { |
|
| 2061 | - $r[4] = trim($r[2]); |
|
| 2062 | - } |
|
| 2063 | - $att = $r[4]; |
|
| 2064 | - if (strpos($att, '&#') !== false) { |
|
| 2065 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2066 | - } |
|
| 2067 | - $att = filtrer_entites($att); |
|
| 2068 | - } else { |
|
| 2069 | - $att = null; |
|
| 2070 | - $r = []; |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - if ($complet) { |
|
| 2074 | - return [$att, $r]; |
|
| 2075 | - } else { |
|
| 2076 | - return $att; |
|
| 2077 | - } |
|
| 2033 | + if (is_array($balise)) { |
|
| 2034 | + array_walk( |
|
| 2035 | + $balise, |
|
| 2036 | + function (&$a, $key, $t) { |
|
| 2037 | + $a = extraire_attribut($a, $t); |
|
| 2038 | + }, |
|
| 2039 | + $attribut |
|
| 2040 | + ); |
|
| 2041 | + |
|
| 2042 | + return $balise; |
|
| 2043 | + } |
|
| 2044 | + if ( |
|
| 2045 | + $balise |
|
| 2046 | + && preg_match( |
|
| 2047 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2048 | + . $attribut |
|
| 2049 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2050 | + $balise, |
|
| 2051 | + $r |
|
| 2052 | + ) |
|
| 2053 | + ) { |
|
| 2054 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2055 | + $r[4] = substr($r[3], 1, -1); |
|
| 2056 | + $r[3] = $r[3][0]; |
|
| 2057 | + } elseif ($r[3] !== '') { |
|
| 2058 | + $r[4] = $r[3]; |
|
| 2059 | + $r[3] = ''; |
|
| 2060 | + } else { |
|
| 2061 | + $r[4] = trim($r[2]); |
|
| 2062 | + } |
|
| 2063 | + $att = $r[4]; |
|
| 2064 | + if (strpos($att, '&#') !== false) { |
|
| 2065 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2066 | + } |
|
| 2067 | + $att = filtrer_entites($att); |
|
| 2068 | + } else { |
|
| 2069 | + $att = null; |
|
| 2070 | + $r = []; |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + if ($complet) { |
|
| 2074 | + return [$att, $r]; |
|
| 2075 | + } else { |
|
| 2076 | + return $att; |
|
| 2077 | + } |
|
| 2078 | 2078 | } |
| 2079 | 2079 | |
| 2080 | 2080 | /** |
@@ -2107,41 +2107,41 @@ discard block |
||
| 2107 | 2107 | **/ |
| 2108 | 2108 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2109 | 2109 | |
| 2110 | - if ($balise === null or $balise === '') { |
|
| 2111 | - return ''; |
|
| 2112 | - } |
|
| 2110 | + if ($balise === null or $balise === '') { |
|
| 2111 | + return ''; |
|
| 2112 | + } |
|
| 2113 | 2113 | |
| 2114 | - // preparer l'attribut |
|
| 2115 | - // supprimer les etc mais pas les balises html |
|
| 2116 | - // qui ont un sens dans un attribut value d'un input |
|
| 2117 | - if ($proteger) { |
|
| 2118 | - $val = attribut_html($val, false); |
|
| 2119 | - } |
|
| 2114 | + // preparer l'attribut |
|
| 2115 | + // supprimer les etc mais pas les balises html |
|
| 2116 | + // qui ont un sens dans un attribut value d'un input |
|
| 2117 | + if ($proteger) { |
|
| 2118 | + $val = attribut_html($val, false); |
|
| 2119 | + } |
|
| 2120 | 2120 | |
| 2121 | - // echapper les ' pour eviter tout bug |
|
| 2122 | - $val = str_replace("'", ''', $val); |
|
| 2123 | - if ($vider and strlen($val) === 0) { |
|
| 2124 | - $insert = ''; |
|
| 2125 | - } else { |
|
| 2126 | - $insert = " $attribut='$val'"; |
|
| 2127 | - } |
|
| 2121 | + // echapper les ' pour eviter tout bug |
|
| 2122 | + $val = str_replace("'", ''', $val); |
|
| 2123 | + if ($vider and strlen($val) === 0) { |
|
| 2124 | + $insert = ''; |
|
| 2125 | + } else { |
|
| 2126 | + $insert = " $attribut='$val'"; |
|
| 2127 | + } |
|
| 2128 | 2128 | |
| 2129 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2129 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2130 | 2130 | |
| 2131 | - if ($old !== null) { |
|
| 2132 | - // Remplacer l'ancien attribut du meme nom |
|
| 2133 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2134 | - } else { |
|
| 2135 | - // preferer une balise " />" (comme <img />) |
|
| 2136 | - if (preg_match(',/>,', $balise)) { |
|
| 2137 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2138 | - } // sinon une balise <a ...> ... </a> |
|
| 2139 | - else { |
|
| 2140 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2141 | - } |
|
| 2142 | - } |
|
| 2131 | + if ($old !== null) { |
|
| 2132 | + // Remplacer l'ancien attribut du meme nom |
|
| 2133 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2134 | + } else { |
|
| 2135 | + // preferer une balise " />" (comme <img />) |
|
| 2136 | + if (preg_match(',/>,', $balise)) { |
|
| 2137 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2138 | + } // sinon une balise <a ...> ... </a> |
|
| 2139 | + else { |
|
| 2140 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2141 | + } |
|
| 2142 | + } |
|
| 2143 | 2143 | |
| 2144 | - return $balise; |
|
| 2144 | + return $balise; |
|
| 2145 | 2145 | } |
| 2146 | 2146 | |
| 2147 | 2147 | /** |
@@ -2159,7 +2159,7 @@ discard block |
||
| 2159 | 2159 | * @return string Code HTML sans l'attribut |
| 2160 | 2160 | **/ |
| 2161 | 2161 | function vider_attribut(?string $balise, string $attribut): string { |
| 2162 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2162 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2163 | 2163 | } |
| 2164 | 2164 | |
| 2165 | 2165 | /** |
@@ -2171,53 +2171,53 @@ discard block |
||
| 2171 | 2171 | * @return string |
| 2172 | 2172 | */ |
| 2173 | 2173 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2174 | - if (is_string($class)) { |
|
| 2175 | - $class = explode(' ', trim($class)); |
|
| 2176 | - } |
|
| 2177 | - $class = array_filter($class); |
|
| 2178 | - $class = array_unique($class); |
|
| 2179 | - if (!$class) { |
|
| 2180 | - return $balise; |
|
| 2181 | - } |
|
| 2182 | - |
|
| 2183 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2184 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2185 | - return $balise; |
|
| 2186 | - } |
|
| 2187 | - |
|
| 2188 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2189 | - $class_new = $class_courante; |
|
| 2190 | - foreach ($class as $c) { |
|
| 2191 | - $is_class_presente = false; |
|
| 2192 | - if ( |
|
| 2193 | - $class_courante |
|
| 2194 | - and strpos($class_courante, (string) $c) !== false |
|
| 2195 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2196 | - ) { |
|
| 2197 | - $is_class_presente = true; |
|
| 2198 | - } |
|
| 2199 | - if ( |
|
| 2200 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2201 | - and !$is_class_presente |
|
| 2202 | - ) { |
|
| 2203 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2204 | - } elseif ( |
|
| 2205 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2206 | - and $is_class_presente |
|
| 2207 | - ) { |
|
| 2208 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2209 | - } |
|
| 2210 | - } |
|
| 2211 | - |
|
| 2212 | - if ($class_new !== $class_courante) { |
|
| 2213 | - if (strlen($class_new)) { |
|
| 2214 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2215 | - } elseif ($class_courante) { |
|
| 2216 | - $balise = vider_attribut($balise, 'class'); |
|
| 2217 | - } |
|
| 2218 | - } |
|
| 2219 | - |
|
| 2220 | - return $balise; |
|
| 2174 | + if (is_string($class)) { |
|
| 2175 | + $class = explode(' ', trim($class)); |
|
| 2176 | + } |
|
| 2177 | + $class = array_filter($class); |
|
| 2178 | + $class = array_unique($class); |
|
| 2179 | + if (!$class) { |
|
| 2180 | + return $balise; |
|
| 2181 | + } |
|
| 2182 | + |
|
| 2183 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2184 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2185 | + return $balise; |
|
| 2186 | + } |
|
| 2187 | + |
|
| 2188 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2189 | + $class_new = $class_courante; |
|
| 2190 | + foreach ($class as $c) { |
|
| 2191 | + $is_class_presente = false; |
|
| 2192 | + if ( |
|
| 2193 | + $class_courante |
|
| 2194 | + and strpos($class_courante, (string) $c) !== false |
|
| 2195 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2196 | + ) { |
|
| 2197 | + $is_class_presente = true; |
|
| 2198 | + } |
|
| 2199 | + if ( |
|
| 2200 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2201 | + and !$is_class_presente |
|
| 2202 | + ) { |
|
| 2203 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2204 | + } elseif ( |
|
| 2205 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2206 | + and $is_class_presente |
|
| 2207 | + ) { |
|
| 2208 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2209 | + } |
|
| 2210 | + } |
|
| 2211 | + |
|
| 2212 | + if ($class_new !== $class_courante) { |
|
| 2213 | + if (strlen($class_new)) { |
|
| 2214 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2215 | + } elseif ($class_courante) { |
|
| 2216 | + $balise = vider_attribut($balise, 'class'); |
|
| 2217 | + } |
|
| 2218 | + } |
|
| 2219 | + |
|
| 2220 | + return $balise; |
|
| 2221 | 2221 | } |
| 2222 | 2222 | |
| 2223 | 2223 | /** |
@@ -2227,7 +2227,7 @@ discard block |
||
| 2227 | 2227 | * @return string |
| 2228 | 2228 | */ |
| 2229 | 2229 | function ajouter_class($balise, $class) { |
| 2230 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2230 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | 2233 | /** |
@@ -2237,7 +2237,7 @@ discard block |
||
| 2237 | 2237 | * @return string |
| 2238 | 2238 | */ |
| 2239 | 2239 | function supprimer_class($balise, $class) { |
| 2240 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2240 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2241 | 2241 | } |
| 2242 | 2242 | |
| 2243 | 2243 | /** |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | * @return string |
| 2249 | 2249 | */ |
| 2250 | 2250 | function commuter_class($balise, $class) { |
| 2251 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2251 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 2254 | 2254 | /** |
@@ -2259,19 +2259,19 @@ discard block |
||
| 2259 | 2259 | * @return string |
| 2260 | 2260 | */ |
| 2261 | 2261 | function tester_config($id, $mode = '') { |
| 2262 | - include_spip('action/inscrire_auteur'); |
|
| 2262 | + include_spip('action/inscrire_auteur'); |
|
| 2263 | 2263 | |
| 2264 | - return tester_statut_inscription($mode, $id); |
|
| 2264 | + return tester_statut_inscription($mode, $id); |
|
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | 2267 | // |
| 2268 | 2268 | // Quelques fonctions de calcul arithmetique |
| 2269 | 2269 | // |
| 2270 | 2270 | function floatstr($a) { |
| 2271 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2271 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2272 | 2272 | } |
| 2273 | 2273 | function strize($f, $a, $b) { |
| 2274 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2274 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2275 | 2275 | } |
| 2276 | 2276 | |
| 2277 | 2277 | /** |
@@ -2290,7 +2290,7 @@ discard block |
||
| 2290 | 2290 | * @return int $a+$b |
| 2291 | 2291 | **/ |
| 2292 | 2292 | function plus($a, $b) { |
| 2293 | - return $a + $b; |
|
| 2293 | + return $a + $b; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | function strplus($a, $b) { |
| 2296 | 2296 | return strize('plus', $a, $b); |
@@ -2311,7 +2311,7 @@ discard block |
||
| 2311 | 2311 | * @return int $a-$b |
| 2312 | 2312 | **/ |
| 2313 | 2313 | function moins($a, $b) { |
| 2314 | - return $a - $b; |
|
| 2314 | + return $a - $b; |
|
| 2315 | 2315 | } |
| 2316 | 2316 | function strmoins($a, $b) { |
| 2317 | 2317 | return strize('moins', $a, $b); |
@@ -2334,7 +2334,7 @@ discard block |
||
| 2334 | 2334 | * @return int $a*$b |
| 2335 | 2335 | **/ |
| 2336 | 2336 | function mult($a, $b) { |
| 2337 | - return $a * $b; |
|
| 2337 | + return $a * $b; |
|
| 2338 | 2338 | } |
| 2339 | 2339 | function strmult($a, $b) { |
| 2340 | 2340 | return strize('mult', $a, $b); |
@@ -2357,7 +2357,7 @@ discard block |
||
| 2357 | 2357 | * @return int $a/$b (ou 0 si $b est nul) |
| 2358 | 2358 | **/ |
| 2359 | 2359 | function div($a, $b) { |
| 2360 | - return $b ? $a / $b : 0; |
|
| 2360 | + return $b ? $a / $b : 0; |
|
| 2361 | 2361 | } |
| 2362 | 2362 | function strdiv($a, $b) { |
| 2363 | 2363 | return strize('div', $a, $b); |
@@ -2381,7 +2381,7 @@ discard block |
||
| 2381 | 2381 | * @return int ($nb % $mod) + $add |
| 2382 | 2382 | **/ |
| 2383 | 2383 | function modulo($nb, $mod, $add = 0) { |
| 2384 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2384 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2385 | 2385 | } |
| 2386 | 2386 | |
| 2387 | 2387 | |
@@ -2396,26 +2396,26 @@ discard block |
||
| 2396 | 2396 | * - true sinon |
| 2397 | 2397 | **/ |
| 2398 | 2398 | function nom_acceptable($nom) { |
| 2399 | - $remp2 = []; |
|
| 2400 | - $remp1 = []; |
|
| 2401 | - if (!is_string($nom)) { |
|
| 2402 | - return false; |
|
| 2403 | - } |
|
| 2404 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2405 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2406 | - } |
|
| 2407 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2408 | - foreach ($tags_acceptes as $tag) { |
|
| 2409 | - if (strlen($tag)) { |
|
| 2410 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2411 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2412 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2413 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2414 | - } |
|
| 2415 | - } |
|
| 2416 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2417 | - |
|
| 2418 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2399 | + $remp2 = []; |
|
| 2400 | + $remp1 = []; |
|
| 2401 | + if (!is_string($nom)) { |
|
| 2402 | + return false; |
|
| 2403 | + } |
|
| 2404 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2405 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2406 | + } |
|
| 2407 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2408 | + foreach ($tags_acceptes as $tag) { |
|
| 2409 | + if (strlen($tag)) { |
|
| 2410 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2411 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2412 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2413 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2414 | + } |
|
| 2415 | + } |
|
| 2416 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2417 | + |
|
| 2418 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2419 | 2419 | } |
| 2420 | 2420 | |
| 2421 | 2421 | |
@@ -2431,14 +2431,14 @@ discard block |
||
| 2431 | 2431 | * - renvoie un tableau si l'entree est un tableau |
| 2432 | 2432 | **/ |
| 2433 | 2433 | function email_valide($adresses) { |
| 2434 | - if (is_array($adresses)) { |
|
| 2435 | - $adresses = array_map('email_valide', $adresses); |
|
| 2436 | - $adresses = array_filter($adresses); |
|
| 2437 | - return $adresses; |
|
| 2438 | - } |
|
| 2434 | + if (is_array($adresses)) { |
|
| 2435 | + $adresses = array_map('email_valide', $adresses); |
|
| 2436 | + $adresses = array_filter($adresses); |
|
| 2437 | + return $adresses; |
|
| 2438 | + } |
|
| 2439 | 2439 | |
| 2440 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2441 | - return $email_valide($adresses); |
|
| 2440 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2441 | + return $email_valide($adresses); |
|
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | /** |
@@ -2452,27 +2452,27 @@ discard block |
||
| 2452 | 2452 | * @return string Texte |
| 2453 | 2453 | **/ |
| 2454 | 2454 | function afficher_enclosures($tags) { |
| 2455 | - $s = []; |
|
| 2456 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2457 | - if ( |
|
| 2458 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2459 | - and $t = extraire_attribut($tag, 'href') |
|
| 2460 | - ) { |
|
| 2461 | - $s[] = preg_replace( |
|
| 2462 | - ',>[^<]+</a>,S', |
|
| 2463 | - '>' |
|
| 2464 | - . http_img_pack( |
|
| 2465 | - 'attachment-16.png', |
|
| 2466 | - $t, |
|
| 2467 | - 'title="' . attribut_html($t) . '"' |
|
| 2468 | - ) |
|
| 2469 | - . '</a>', |
|
| 2470 | - $tag |
|
| 2471 | - ); |
|
| 2472 | - } |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - return join(' ', $s); |
|
| 2455 | + $s = []; |
|
| 2456 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2457 | + if ( |
|
| 2458 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2459 | + and $t = extraire_attribut($tag, 'href') |
|
| 2460 | + ) { |
|
| 2461 | + $s[] = preg_replace( |
|
| 2462 | + ',>[^<]+</a>,S', |
|
| 2463 | + '>' |
|
| 2464 | + . http_img_pack( |
|
| 2465 | + 'attachment-16.png', |
|
| 2466 | + $t, |
|
| 2467 | + 'title="' . attribut_html($t) . '"' |
|
| 2468 | + ) |
|
| 2469 | + . '</a>', |
|
| 2470 | + $tag |
|
| 2471 | + ); |
|
| 2472 | + } |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + return join(' ', $s); |
|
| 2476 | 2476 | } |
| 2477 | 2477 | |
| 2478 | 2478 | /** |
@@ -2487,15 +2487,15 @@ discard block |
||
| 2487 | 2487 | * @return string Liens trouvés |
| 2488 | 2488 | **/ |
| 2489 | 2489 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2490 | - $s = []; |
|
| 2491 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2492 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2493 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2494 | - $s[] = $tag; |
|
| 2495 | - } |
|
| 2496 | - } |
|
| 2490 | + $s = []; |
|
| 2491 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2492 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2493 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2494 | + $s[] = $tag; |
|
| 2495 | + } |
|
| 2496 | + } |
|
| 2497 | 2497 | |
| 2498 | - return join(', ', $s); |
|
| 2498 | + return join(', ', $s); |
|
| 2499 | 2499 | } |
| 2500 | 2500 | |
| 2501 | 2501 | |
@@ -2517,21 +2517,21 @@ discard block |
||
| 2517 | 2517 | * @return string Tag HTML `<a>` avec microformat. |
| 2518 | 2518 | **/ |
| 2519 | 2519 | function enclosure2microformat($e) { |
| 2520 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2521 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2522 | - } |
|
| 2523 | - $type = extraire_attribut($e, 'type'); |
|
| 2524 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2525 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2526 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2527 | - } |
|
| 2528 | - $fichier = basename($url); |
|
| 2520 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2521 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2522 | + } |
|
| 2523 | + $type = extraire_attribut($e, 'type'); |
|
| 2524 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2525 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2526 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2527 | + } |
|
| 2528 | + $fichier = basename($url); |
|
| 2529 | 2529 | |
| 2530 | - return '<a rel="enclosure"' |
|
| 2531 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2532 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2533 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2534 | - . '>' . $fichier . '</a>'; |
|
| 2530 | + return '<a rel="enclosure"' |
|
| 2531 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2532 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2533 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2534 | + . '>' . $fichier . '</a>'; |
|
| 2535 | 2535 | } |
| 2536 | 2536 | |
| 2537 | 2537 | /** |
@@ -2549,24 +2549,24 @@ discard block |
||
| 2549 | 2549 | * @return string Tags RSS `<enclosure>`. |
| 2550 | 2550 | **/ |
| 2551 | 2551 | function microformat2enclosure($tags) { |
| 2552 | - $enclosures = []; |
|
| 2553 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2554 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2555 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2556 | - $type = extraire_attribut($e, 'type'); |
|
| 2557 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2558 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2559 | - } # vieux data |
|
| 2560 | - $fichier = basename($url); |
|
| 2561 | - $enclosures[] = '<enclosure' |
|
| 2562 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2563 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2564 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2565 | - . ' />'; |
|
| 2566 | - } |
|
| 2567 | - } |
|
| 2552 | + $enclosures = []; |
|
| 2553 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2554 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2555 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2556 | + $type = extraire_attribut($e, 'type'); |
|
| 2557 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2558 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2559 | + } # vieux data |
|
| 2560 | + $fichier = basename($url); |
|
| 2561 | + $enclosures[] = '<enclosure' |
|
| 2562 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2563 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2564 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2565 | + . ' />'; |
|
| 2566 | + } |
|
| 2567 | + } |
|
| 2568 | 2568 | |
| 2569 | - return join("\n", $enclosures); |
|
| 2569 | + return join("\n", $enclosures); |
|
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | |
@@ -2582,16 +2582,16 @@ discard block |
||
| 2582 | 2582 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2583 | 2583 | **/ |
| 2584 | 2584 | function tags2dcsubject($tags) { |
| 2585 | - $subjects = ''; |
|
| 2586 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2587 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2588 | - $subjects .= '<dc:subject>' |
|
| 2589 | - . texte_backend(textebrut($e)) |
|
| 2590 | - . '</dc:subject>' . "\n"; |
|
| 2591 | - } |
|
| 2592 | - } |
|
| 2585 | + $subjects = ''; |
|
| 2586 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2587 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2588 | + $subjects .= '<dc:subject>' |
|
| 2589 | + . texte_backend(textebrut($e)) |
|
| 2590 | + . '</dc:subject>' . "\n"; |
|
| 2591 | + } |
|
| 2592 | + } |
|
| 2593 | 2593 | |
| 2594 | - return $subjects; |
|
| 2594 | + return $subjects; |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | /** |
@@ -2620,27 +2620,27 @@ discard block |
||
| 2620 | 2620 | * - Tableau de résultats, si tableau en entrée. |
| 2621 | 2621 | **/ |
| 2622 | 2622 | function extraire_balise($texte, $tag = 'a') { |
| 2623 | - if (is_array($texte)) { |
|
| 2624 | - array_walk( |
|
| 2625 | - $texte, |
|
| 2626 | - function (&$a, $key, $t) { |
|
| 2627 | - $a = extraire_balise($a, $t); |
|
| 2628 | - }, |
|
| 2629 | - $tag |
|
| 2630 | - ); |
|
| 2631 | - |
|
| 2632 | - return $texte; |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - if ( |
|
| 2636 | - preg_match( |
|
| 2637 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2638 | - $texte, |
|
| 2639 | - $regs |
|
| 2640 | - ) |
|
| 2641 | - ) { |
|
| 2642 | - return $regs[0]; |
|
| 2643 | - } |
|
| 2623 | + if (is_array($texte)) { |
|
| 2624 | + array_walk( |
|
| 2625 | + $texte, |
|
| 2626 | + function (&$a, $key, $t) { |
|
| 2627 | + $a = extraire_balise($a, $t); |
|
| 2628 | + }, |
|
| 2629 | + $tag |
|
| 2630 | + ); |
|
| 2631 | + |
|
| 2632 | + return $texte; |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + if ( |
|
| 2636 | + preg_match( |
|
| 2637 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2638 | + $texte, |
|
| 2639 | + $regs |
|
| 2640 | + ) |
|
| 2641 | + ) { |
|
| 2642 | + return $regs[0]; |
|
| 2643 | + } |
|
| 2644 | 2644 | } |
| 2645 | 2645 | |
| 2646 | 2646 | /** |
@@ -2668,30 +2668,30 @@ discard block |
||
| 2668 | 2668 | * - Tableau de résultats, si tableau en entrée. |
| 2669 | 2669 | **/ |
| 2670 | 2670 | function extraire_balises($texte, $tag = 'a') { |
| 2671 | - if (is_array($texte)) { |
|
| 2672 | - array_walk( |
|
| 2673 | - $texte, |
|
| 2674 | - function (&$a, $key, $t) { |
|
| 2675 | - $a = extraire_balises($a, $t); |
|
| 2676 | - }, |
|
| 2677 | - $tag |
|
| 2678 | - ); |
|
| 2679 | - |
|
| 2680 | - return $texte; |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - if ( |
|
| 2684 | - preg_match_all( |
|
| 2685 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2686 | - $texte, |
|
| 2687 | - $regs, |
|
| 2688 | - PREG_PATTERN_ORDER |
|
| 2689 | - ) |
|
| 2690 | - ) { |
|
| 2691 | - return $regs[0]; |
|
| 2692 | - } else { |
|
| 2693 | - return []; |
|
| 2694 | - } |
|
| 2671 | + if (is_array($texte)) { |
|
| 2672 | + array_walk( |
|
| 2673 | + $texte, |
|
| 2674 | + function (&$a, $key, $t) { |
|
| 2675 | + $a = extraire_balises($a, $t); |
|
| 2676 | + }, |
|
| 2677 | + $tag |
|
| 2678 | + ); |
|
| 2679 | + |
|
| 2680 | + return $texte; |
|
| 2681 | + } |
|
| 2682 | + |
|
| 2683 | + if ( |
|
| 2684 | + preg_match_all( |
|
| 2685 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2686 | + $texte, |
|
| 2687 | + $regs, |
|
| 2688 | + PREG_PATTERN_ORDER |
|
| 2689 | + ) |
|
| 2690 | + ) { |
|
| 2691 | + return $regs[0]; |
|
| 2692 | + } else { |
|
| 2693 | + return []; |
|
| 2694 | + } |
|
| 2695 | 2695 | } |
| 2696 | 2696 | |
| 2697 | 2697 | /** |
@@ -2720,11 +2720,11 @@ discard block |
||
| 2720 | 2720 | * - `$def` si on n'a pas transmis de tableau |
| 2721 | 2721 | **/ |
| 2722 | 2722 | function in_any($val, $vals, $def = '') { |
| 2723 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2724 | - $vals = $v; |
|
| 2725 | - } |
|
| 2723 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2724 | + $vals = $v; |
|
| 2725 | + } |
|
| 2726 | 2726 | |
| 2727 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2727 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2728 | 2728 | } |
| 2729 | 2729 | |
| 2730 | 2730 | |
@@ -2745,12 +2745,12 @@ discard block |
||
| 2745 | 2745 | * Résultat du calcul |
| 2746 | 2746 | **/ |
| 2747 | 2747 | function valeur_numerique($expr) { |
| 2748 | - $a = 0; |
|
| 2749 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2750 | - eval("\$a = $expr;"); |
|
| 2751 | - } |
|
| 2748 | + $a = 0; |
|
| 2749 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2750 | + eval("\$a = $expr;"); |
|
| 2751 | + } |
|
| 2752 | 2752 | |
| 2753 | - return intval($a); |
|
| 2753 | + return intval($a); |
|
| 2754 | 2754 | } |
| 2755 | 2755 | |
| 2756 | 2756 | /** |
@@ -2769,7 +2769,7 @@ discard block |
||
| 2769 | 2769 | * Retourne `$a*$b/$c` |
| 2770 | 2770 | **/ |
| 2771 | 2771 | function regledetrois($a, $b, $c) { |
| 2772 | - return round($a * $b / $c); |
|
| 2772 | + return round($a * $b / $c); |
|
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | 2775 | |
@@ -2792,79 +2792,79 @@ discard block |
||
| 2792 | 2792 | * @return string Suite de champs input hidden |
| 2793 | 2793 | **/ |
| 2794 | 2794 | function form_hidden(?string $action = ''): string { |
| 2795 | - $action ??= ''; |
|
| 2796 | - |
|
| 2797 | - $contexte = []; |
|
| 2798 | - include_spip('inc/urls'); |
|
| 2799 | - if ( |
|
| 2800 | - $p = urls_decoder_url($action, '') |
|
| 2801 | - and reset($p) |
|
| 2802 | - ) { |
|
| 2803 | - $fond = array_shift($p); |
|
| 2804 | - if ($fond != '404') { |
|
| 2805 | - $contexte = array_shift($p); |
|
| 2806 | - $contexte['page'] = $fond; |
|
| 2807 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2808 | - } |
|
| 2809 | - } |
|
| 2810 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2811 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2812 | - unset($contexte['type']); |
|
| 2813 | - } |
|
| 2814 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2815 | - unset($contexte['type-page']); |
|
| 2816 | - } |
|
| 2817 | - |
|
| 2818 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2819 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2820 | - $values = []; |
|
| 2821 | - |
|
| 2822 | - // d'abord avec celles de l'url |
|
| 2823 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2824 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2825 | - $c = explode('=', $c, 2); |
|
| 2826 | - $var = array_shift($c); |
|
| 2827 | - $val = array_shift($c) ?? ''; |
|
| 2828 | - if ($var) { |
|
| 2829 | - $val = rawurldecode($val); |
|
| 2830 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2831 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2832 | - $values[] = [$var, $val]; |
|
| 2833 | - } else { |
|
| 2834 | - if (!isset($values[$var])) { |
|
| 2835 | - $values[$var] = [$var, $val]; |
|
| 2836 | - } |
|
| 2837 | - } |
|
| 2838 | - } |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - |
|
| 2842 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2843 | - foreach ($contexte as $var => $val) { |
|
| 2844 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2845 | - $values[] = [$var, $val]; |
|
| 2846 | - } else { |
|
| 2847 | - if (!isset($values[$var])) { |
|
| 2848 | - $values[$var] = [$var, $val]; |
|
| 2849 | - } |
|
| 2850 | - } |
|
| 2851 | - } |
|
| 2852 | - |
|
| 2853 | - // puis on rassemble le tout |
|
| 2854 | - $hidden = []; |
|
| 2855 | - foreach ($values as $value) { |
|
| 2856 | - [$var, $val] = $value; |
|
| 2857 | - $hidden[] = '<input name="' |
|
| 2858 | - . entites_html($var) |
|
| 2859 | - . '"' |
|
| 2860 | - . (is_null($val) |
|
| 2861 | - ? '' |
|
| 2862 | - : ' value="' . entites_html($val) . '"' |
|
| 2863 | - ) |
|
| 2864 | - . ' type="hidden"' . "\n/>"; |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - return join('', $hidden); |
|
| 2795 | + $action ??= ''; |
|
| 2796 | + |
|
| 2797 | + $contexte = []; |
|
| 2798 | + include_spip('inc/urls'); |
|
| 2799 | + if ( |
|
| 2800 | + $p = urls_decoder_url($action, '') |
|
| 2801 | + and reset($p) |
|
| 2802 | + ) { |
|
| 2803 | + $fond = array_shift($p); |
|
| 2804 | + if ($fond != '404') { |
|
| 2805 | + $contexte = array_shift($p); |
|
| 2806 | + $contexte['page'] = $fond; |
|
| 2807 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2808 | + } |
|
| 2809 | + } |
|
| 2810 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2811 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2812 | + unset($contexte['type']); |
|
| 2813 | + } |
|
| 2814 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2815 | + unset($contexte['type-page']); |
|
| 2816 | + } |
|
| 2817 | + |
|
| 2818 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2819 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2820 | + $values = []; |
|
| 2821 | + |
|
| 2822 | + // d'abord avec celles de l'url |
|
| 2823 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2824 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2825 | + $c = explode('=', $c, 2); |
|
| 2826 | + $var = array_shift($c); |
|
| 2827 | + $val = array_shift($c) ?? ''; |
|
| 2828 | + if ($var) { |
|
| 2829 | + $val = rawurldecode($val); |
|
| 2830 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2831 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2832 | + $values[] = [$var, $val]; |
|
| 2833 | + } else { |
|
| 2834 | + if (!isset($values[$var])) { |
|
| 2835 | + $values[$var] = [$var, $val]; |
|
| 2836 | + } |
|
| 2837 | + } |
|
| 2838 | + } |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + |
|
| 2842 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2843 | + foreach ($contexte as $var => $val) { |
|
| 2844 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2845 | + $values[] = [$var, $val]; |
|
| 2846 | + } else { |
|
| 2847 | + if (!isset($values[$var])) { |
|
| 2848 | + $values[$var] = [$var, $val]; |
|
| 2849 | + } |
|
| 2850 | + } |
|
| 2851 | + } |
|
| 2852 | + |
|
| 2853 | + // puis on rassemble le tout |
|
| 2854 | + $hidden = []; |
|
| 2855 | + foreach ($values as $value) { |
|
| 2856 | + [$var, $val] = $value; |
|
| 2857 | + $hidden[] = '<input name="' |
|
| 2858 | + . entites_html($var) |
|
| 2859 | + . '"' |
|
| 2860 | + . (is_null($val) |
|
| 2861 | + ? '' |
|
| 2862 | + : ' value="' . entites_html($val) . '"' |
|
| 2863 | + ) |
|
| 2864 | + . ' type="hidden"' . "\n/>"; |
|
| 2865 | + } |
|
| 2866 | + |
|
| 2867 | + return join('', $hidden); |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | |
@@ -2886,7 +2886,7 @@ discard block |
||
| 2886 | 2886 | * - la première valeur du tableau sinon. |
| 2887 | 2887 | **/ |
| 2888 | 2888 | function filtre_reset($array) { |
| 2889 | - return !is_array($array) ? null : reset($array); |
|
| 2889 | + return !is_array($array) ? null : reset($array); |
|
| 2890 | 2890 | } |
| 2891 | 2891 | |
| 2892 | 2892 | /** |
@@ -2907,7 +2907,7 @@ discard block |
||
| 2907 | 2907 | * - la dernière valeur du tableau sinon. |
| 2908 | 2908 | **/ |
| 2909 | 2909 | function filtre_end($array) { |
| 2910 | - return !is_array($array) ? null : end($array); |
|
| 2910 | + return !is_array($array) ? null : end($array); |
|
| 2911 | 2911 | } |
| 2912 | 2912 | |
| 2913 | 2913 | /** |
@@ -2927,11 +2927,11 @@ discard block |
||
| 2927 | 2927 | * |
| 2928 | 2928 | **/ |
| 2929 | 2929 | function filtre_push($array, $val) { |
| 2930 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2931 | - return ''; |
|
| 2932 | - } |
|
| 2930 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2931 | + return ''; |
|
| 2932 | + } |
|
| 2933 | 2933 | |
| 2934 | - return $array; |
|
| 2934 | + return $array; |
|
| 2935 | 2935 | } |
| 2936 | 2936 | |
| 2937 | 2937 | /** |
@@ -2950,7 +2950,7 @@ discard block |
||
| 2950 | 2950 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2951 | 2951 | **/ |
| 2952 | 2952 | function filtre_find($array, $val) { |
| 2953 | - return (is_array($array) and in_array($val, $array)); |
|
| 2953 | + return (is_array($array) and in_array($val, $array)); |
|
| 2954 | 2954 | } |
| 2955 | 2955 | |
| 2956 | 2956 | |
@@ -2967,13 +2967,13 @@ discard block |
||
| 2967 | 2967 | * Contenu avec urls en absolus |
| 2968 | 2968 | **/ |
| 2969 | 2969 | function urls_absolues_css($contenu, $source) { |
| 2970 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2970 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2971 | 2971 | |
| 2972 | - return preg_replace_callback( |
|
| 2973 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2974 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2975 | - $contenu |
|
| 2976 | - ); |
|
| 2972 | + return preg_replace_callback( |
|
| 2973 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2974 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2975 | + $contenu |
|
| 2976 | + ); |
|
| 2977 | 2977 | } |
| 2978 | 2978 | |
| 2979 | 2979 | |
@@ -3002,119 +3002,119 @@ discard block |
||
| 3002 | 3002 | * Chemin du fichier CSS inversé |
| 3003 | 3003 | **/ |
| 3004 | 3004 | function direction_css($css, $voulue = '') { |
| 3005 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3006 | - return $css; |
|
| 3007 | - } |
|
| 3008 | - include_spip('inc/lang'); |
|
| 3009 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3010 | - if ($voulue = strtolower($voulue)) { |
|
| 3011 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3012 | - $voulue = lang_dir($voulue); |
|
| 3013 | - } |
|
| 3014 | - } else { |
|
| 3015 | - $voulue = lang_dir(); |
|
| 3016 | - } |
|
| 3017 | - |
|
| 3018 | - $r = count($r) > 1; |
|
| 3019 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3020 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 3021 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3022 | - |
|
| 3023 | - if ($voulue == $dir) { |
|
| 3024 | - return $css; |
|
| 3025 | - } |
|
| 3026 | - |
|
| 3027 | - if ( |
|
| 3028 | - // url absolue |
|
| 3029 | - preg_match(',^https?:,i', $css) |
|
| 3030 | - // ou qui contient un ? |
|
| 3031 | - or (($p = strpos($css, '?')) !== false) |
|
| 3032 | - ) { |
|
| 3033 | - $distant = true; |
|
| 3034 | - $cssf = parse_url($css); |
|
| 3035 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3036 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3037 | - } else { |
|
| 3038 | - $distant = false; |
|
| 3039 | - $cssf = $css; |
|
| 3040 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3041 | - //propose (rien a faire dans ce cas) |
|
| 3042 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3043 | - if (@file_exists($f)) { |
|
| 3044 | - return $f; |
|
| 3045 | - } |
|
| 3046 | - } |
|
| 3047 | - |
|
| 3048 | - // 2. |
|
| 3049 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3050 | - $f = $dir_var |
|
| 3051 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3052 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3053 | - |
|
| 3054 | - // la css peut etre distante (url absolue !) |
|
| 3055 | - if ($distant) { |
|
| 3056 | - include_spip('inc/distant'); |
|
| 3057 | - $res = recuperer_url($css); |
|
| 3058 | - if (!$res or !$contenu = $res['page']) { |
|
| 3059 | - return $css; |
|
| 3060 | - } |
|
| 3061 | - } else { |
|
| 3062 | - if ( |
|
| 3063 | - (@filemtime($f) > @filemtime($css)) |
|
| 3064 | - and (_VAR_MODE != 'recalcul') |
|
| 3065 | - ) { |
|
| 3066 | - return $f; |
|
| 3067 | - } |
|
| 3068 | - if (!lire_fichier($css, $contenu)) { |
|
| 3069 | - return $css; |
|
| 3070 | - } |
|
| 3071 | - } |
|
| 3072 | - |
|
| 3073 | - |
|
| 3074 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3075 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3076 | - $parser = new csstidy(); |
|
| 3077 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3078 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3079 | - $parser->parse($contenu); |
|
| 3080 | - |
|
| 3081 | - $contenu = $parser->print->plain(); |
|
| 3082 | - |
|
| 3083 | - |
|
| 3084 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3085 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3086 | - $src = []; |
|
| 3087 | - $src_direction_css = []; |
|
| 3088 | - $src_faux_abs = []; |
|
| 3089 | - $d = dirname($css); |
|
| 3090 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3091 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3092 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3093 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3094 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3095 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3096 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3097 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3098 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3099 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3100 | - } |
|
| 3101 | - $src[] = $regs[0][$k]; |
|
| 3102 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3103 | - } |
|
| 3104 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3105 | - |
|
| 3106 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3107 | - |
|
| 3108 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3109 | - if (count($src_faux_abs)) { |
|
| 3110 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3111 | - } |
|
| 3112 | - |
|
| 3113 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3114 | - return $css; |
|
| 3115 | - } |
|
| 3116 | - |
|
| 3117 | - return $f; |
|
| 3005 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3006 | + return $css; |
|
| 3007 | + } |
|
| 3008 | + include_spip('inc/lang'); |
|
| 3009 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3010 | + if ($voulue = strtolower($voulue)) { |
|
| 3011 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3012 | + $voulue = lang_dir($voulue); |
|
| 3013 | + } |
|
| 3014 | + } else { |
|
| 3015 | + $voulue = lang_dir(); |
|
| 3016 | + } |
|
| 3017 | + |
|
| 3018 | + $r = count($r) > 1; |
|
| 3019 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3020 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 3021 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3022 | + |
|
| 3023 | + if ($voulue == $dir) { |
|
| 3024 | + return $css; |
|
| 3025 | + } |
|
| 3026 | + |
|
| 3027 | + if ( |
|
| 3028 | + // url absolue |
|
| 3029 | + preg_match(',^https?:,i', $css) |
|
| 3030 | + // ou qui contient un ? |
|
| 3031 | + or (($p = strpos($css, '?')) !== false) |
|
| 3032 | + ) { |
|
| 3033 | + $distant = true; |
|
| 3034 | + $cssf = parse_url($css); |
|
| 3035 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3036 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3037 | + } else { |
|
| 3038 | + $distant = false; |
|
| 3039 | + $cssf = $css; |
|
| 3040 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3041 | + //propose (rien a faire dans ce cas) |
|
| 3042 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3043 | + if (@file_exists($f)) { |
|
| 3044 | + return $f; |
|
| 3045 | + } |
|
| 3046 | + } |
|
| 3047 | + |
|
| 3048 | + // 2. |
|
| 3049 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3050 | + $f = $dir_var |
|
| 3051 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3052 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3053 | + |
|
| 3054 | + // la css peut etre distante (url absolue !) |
|
| 3055 | + if ($distant) { |
|
| 3056 | + include_spip('inc/distant'); |
|
| 3057 | + $res = recuperer_url($css); |
|
| 3058 | + if (!$res or !$contenu = $res['page']) { |
|
| 3059 | + return $css; |
|
| 3060 | + } |
|
| 3061 | + } else { |
|
| 3062 | + if ( |
|
| 3063 | + (@filemtime($f) > @filemtime($css)) |
|
| 3064 | + and (_VAR_MODE != 'recalcul') |
|
| 3065 | + ) { |
|
| 3066 | + return $f; |
|
| 3067 | + } |
|
| 3068 | + if (!lire_fichier($css, $contenu)) { |
|
| 3069 | + return $css; |
|
| 3070 | + } |
|
| 3071 | + } |
|
| 3072 | + |
|
| 3073 | + |
|
| 3074 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3075 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3076 | + $parser = new csstidy(); |
|
| 3077 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3078 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3079 | + $parser->parse($contenu); |
|
| 3080 | + |
|
| 3081 | + $contenu = $parser->print->plain(); |
|
| 3082 | + |
|
| 3083 | + |
|
| 3084 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3085 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3086 | + $src = []; |
|
| 3087 | + $src_direction_css = []; |
|
| 3088 | + $src_faux_abs = []; |
|
| 3089 | + $d = dirname($css); |
|
| 3090 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3091 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3092 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3093 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3094 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3095 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3096 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3097 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3098 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3099 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3100 | + } |
|
| 3101 | + $src[] = $regs[0][$k]; |
|
| 3102 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3103 | + } |
|
| 3104 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3105 | + |
|
| 3106 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3107 | + |
|
| 3108 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3109 | + if (count($src_faux_abs)) { |
|
| 3110 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3111 | + } |
|
| 3112 | + |
|
| 3113 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3114 | + return $css; |
|
| 3115 | + } |
|
| 3116 | + |
|
| 3117 | + return $f; |
|
| 3118 | 3118 | } |
| 3119 | 3119 | |
| 3120 | 3120 | |
@@ -3137,46 +3137,46 @@ discard block |
||
| 3137 | 3137 | * - Chemin ou URL du fichier CSS source sinon. |
| 3138 | 3138 | **/ |
| 3139 | 3139 | function url_absolue_css($css) { |
| 3140 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3141 | - return $css; |
|
| 3142 | - } |
|
| 3140 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3141 | + return $css; |
|
| 3142 | + } |
|
| 3143 | 3143 | |
| 3144 | - $url_absolue_css = url_absolue($css); |
|
| 3144 | + $url_absolue_css = url_absolue($css); |
|
| 3145 | 3145 | |
| 3146 | - $f = basename($css, '.css'); |
|
| 3147 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3148 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3149 | - . '.css'; |
|
| 3146 | + $f = basename($css, '.css'); |
|
| 3147 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3148 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3149 | + . '.css'; |
|
| 3150 | 3150 | |
| 3151 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3152 | - return $f; |
|
| 3153 | - } |
|
| 3151 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3152 | + return $f; |
|
| 3153 | + } |
|
| 3154 | 3154 | |
| 3155 | - if ($url_absolue_css == $css) { |
|
| 3156 | - if ( |
|
| 3157 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3158 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3159 | - ) { |
|
| 3160 | - include_spip('inc/distant'); |
|
| 3161 | - $contenu = recuperer_url($css); |
|
| 3162 | - $contenu = $contenu['page'] ?? ''; |
|
| 3163 | - if (!$contenu) { |
|
| 3164 | - return $css; |
|
| 3165 | - } |
|
| 3166 | - } |
|
| 3167 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3168 | - return $css; |
|
| 3169 | - } |
|
| 3155 | + if ($url_absolue_css == $css) { |
|
| 3156 | + if ( |
|
| 3157 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3158 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3159 | + ) { |
|
| 3160 | + include_spip('inc/distant'); |
|
| 3161 | + $contenu = recuperer_url($css); |
|
| 3162 | + $contenu = $contenu['page'] ?? ''; |
|
| 3163 | + if (!$contenu) { |
|
| 3164 | + return $css; |
|
| 3165 | + } |
|
| 3166 | + } |
|
| 3167 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3168 | + return $css; |
|
| 3169 | + } |
|
| 3170 | 3170 | |
| 3171 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3172 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3171 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3172 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3173 | 3173 | |
| 3174 | - // ecrire la css |
|
| 3175 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3176 | - return $css; |
|
| 3177 | - } |
|
| 3174 | + // ecrire la css |
|
| 3175 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3176 | + return $css; |
|
| 3177 | + } |
|
| 3178 | 3178 | |
| 3179 | - return $f; |
|
| 3179 | + return $f; |
|
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | 3182 | |
@@ -3210,24 +3210,24 @@ discard block |
||
| 3210 | 3210 | * Valeur trouvée ou valeur par défaut. |
| 3211 | 3211 | **/ |
| 3212 | 3212 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3213 | - foreach (explode('/', $cle) as $k) { |
|
| 3214 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3213 | + foreach (explode('/', $cle) as $k) { |
|
| 3214 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3215 | 3215 | |
| 3216 | - if (is_object($table)) { |
|
| 3217 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3218 | - } elseif (is_array($table)) { |
|
| 3219 | - if ($conserver_null) { |
|
| 3220 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3221 | - } else { |
|
| 3222 | - $table = ($table[$k] ?? $defaut); |
|
| 3223 | - } |
|
| 3224 | - } else { |
|
| 3225 | - $table = $defaut; |
|
| 3226 | - break; |
|
| 3227 | - } |
|
| 3228 | - } |
|
| 3216 | + if (is_object($table)) { |
|
| 3217 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3218 | + } elseif (is_array($table)) { |
|
| 3219 | + if ($conserver_null) { |
|
| 3220 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3221 | + } else { |
|
| 3222 | + $table = ($table[$k] ?? $defaut); |
|
| 3223 | + } |
|
| 3224 | + } else { |
|
| 3225 | + $table = $defaut; |
|
| 3226 | + break; |
|
| 3227 | + } |
|
| 3228 | + } |
|
| 3229 | 3229 | |
| 3230 | - return $table; |
|
| 3230 | + return $table; |
|
| 3231 | 3231 | } |
| 3232 | 3232 | |
| 3233 | 3233 | /** |
@@ -3260,22 +3260,22 @@ discard block |
||
| 3260 | 3260 | * - string : expression trouvée. |
| 3261 | 3261 | **/ |
| 3262 | 3262 | function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) { |
| 3263 | - if (intval($modif) and $capte == 0) { |
|
| 3264 | - $capte = $modif; |
|
| 3265 | - $modif = 'UimsS'; |
|
| 3266 | - } |
|
| 3267 | - $expression = str_replace('\/', '/', $expression); |
|
| 3268 | - $expression = str_replace('/', '\/', $expression); |
|
| 3263 | + if (intval($modif) and $capte == 0) { |
|
| 3264 | + $capte = $modif; |
|
| 3265 | + $modif = 'UimsS'; |
|
| 3266 | + } |
|
| 3267 | + $expression = str_replace('\/', '/', $expression); |
|
| 3268 | + $expression = str_replace('/', '\/', $expression); |
|
| 3269 | 3269 | |
| 3270 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3271 | - if (isset($r[$capte])) { |
|
| 3272 | - return $r[$capte]; |
|
| 3273 | - } else { |
|
| 3274 | - return true; |
|
| 3275 | - } |
|
| 3276 | - } |
|
| 3270 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3271 | + if (isset($r[$capte])) { |
|
| 3272 | + return $r[$capte]; |
|
| 3273 | + } else { |
|
| 3274 | + return true; |
|
| 3275 | + } |
|
| 3276 | + } |
|
| 3277 | 3277 | |
| 3278 | - return false; |
|
| 3278 | + return false; |
|
| 3279 | 3279 | } |
| 3280 | 3280 | |
| 3281 | 3281 | |
@@ -3302,10 +3302,10 @@ discard block |
||
| 3302 | 3302 | * Texte |
| 3303 | 3303 | **/ |
| 3304 | 3304 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3305 | - $expression = str_replace('\/', '/', $expression); |
|
| 3306 | - $expression = str_replace('/', '\/', $expression); |
|
| 3305 | + $expression = str_replace('\/', '/', $expression); |
|
| 3306 | + $expression = str_replace('/', '\/', $expression); |
|
| 3307 | 3307 | |
| 3308 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3308 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3309 | 3309 | } |
| 3310 | 3310 | |
| 3311 | 3311 | |
@@ -3323,25 +3323,25 @@ discard block |
||
| 3323 | 3323 | **/ |
| 3324 | 3324 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3325 | 3325 | |
| 3326 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3327 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3326 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3327 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3328 | 3328 | |
| 3329 | - if ( |
|
| 3330 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3331 | - and preg_match_all( |
|
| 3332 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3333 | - $t, |
|
| 3334 | - $matches, |
|
| 3335 | - PREG_PATTERN_ORDER |
|
| 3336 | - ) |
|
| 3337 | - ) { |
|
| 3338 | - if (!isset($doublons['documents'])) { |
|
| 3339 | - $doublons['documents'] = ''; |
|
| 3340 | - } |
|
| 3341 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3342 | - } |
|
| 3329 | + if ( |
|
| 3330 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3331 | + and preg_match_all( |
|
| 3332 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3333 | + $t, |
|
| 3334 | + $matches, |
|
| 3335 | + PREG_PATTERN_ORDER |
|
| 3336 | + ) |
|
| 3337 | + ) { |
|
| 3338 | + if (!isset($doublons['documents'])) { |
|
| 3339 | + $doublons['documents'] = ''; |
|
| 3340 | + } |
|
| 3341 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3342 | + } |
|
| 3343 | 3343 | |
| 3344 | - return $letexte; |
|
| 3344 | + return $letexte; |
|
| 3345 | 3345 | } |
| 3346 | 3346 | |
| 3347 | 3347 | /** |
@@ -3355,7 +3355,7 @@ discard block |
||
| 3355 | 3355 | * @return string Chaîne vide |
| 3356 | 3356 | **/ |
| 3357 | 3357 | function vide($texte) { |
| 3358 | - return ''; |
|
| 3358 | + return ''; |
|
| 3359 | 3359 | } |
| 3360 | 3360 | |
| 3361 | 3361 | // |
@@ -3384,23 +3384,23 @@ discard block |
||
| 3384 | 3384 | * Code HTML résultant |
| 3385 | 3385 | **/ |
| 3386 | 3386 | function env_to_params($env, $ignore_params = []) { |
| 3387 | - $ignore_params = array_merge( |
|
| 3388 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3389 | - $ignore_params |
|
| 3390 | - ); |
|
| 3391 | - if (!is_array($env)) { |
|
| 3392 | - $env = unserialize($env); |
|
| 3393 | - } |
|
| 3394 | - $texte = ''; |
|
| 3395 | - if ($env) { |
|
| 3396 | - foreach ($env as $i => $j) { |
|
| 3397 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3398 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3399 | - } |
|
| 3400 | - } |
|
| 3401 | - } |
|
| 3402 | - |
|
| 3403 | - return $texte; |
|
| 3387 | + $ignore_params = array_merge( |
|
| 3388 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3389 | + $ignore_params |
|
| 3390 | + ); |
|
| 3391 | + if (!is_array($env)) { |
|
| 3392 | + $env = unserialize($env); |
|
| 3393 | + } |
|
| 3394 | + $texte = ''; |
|
| 3395 | + if ($env) { |
|
| 3396 | + foreach ($env as $i => $j) { |
|
| 3397 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3398 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3399 | + } |
|
| 3400 | + } |
|
| 3401 | + } |
|
| 3402 | + |
|
| 3403 | + return $texte; |
|
| 3404 | 3404 | } |
| 3405 | 3405 | |
| 3406 | 3406 | /** |
@@ -3423,23 +3423,23 @@ discard block |
||
| 3423 | 3423 | * Code HTML résultant |
| 3424 | 3424 | **/ |
| 3425 | 3425 | function env_to_attributs($env, $ignore_params = []) { |
| 3426 | - $ignore_params = array_merge( |
|
| 3427 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3428 | - $ignore_params |
|
| 3429 | - ); |
|
| 3430 | - if (!is_array($env)) { |
|
| 3431 | - $env = unserialize($env); |
|
| 3432 | - } |
|
| 3433 | - $texte = ''; |
|
| 3434 | - if ($env) { |
|
| 3435 | - foreach ($env as $i => $j) { |
|
| 3436 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3437 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3438 | - } |
|
| 3439 | - } |
|
| 3440 | - } |
|
| 3426 | + $ignore_params = array_merge( |
|
| 3427 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3428 | + $ignore_params |
|
| 3429 | + ); |
|
| 3430 | + if (!is_array($env)) { |
|
| 3431 | + $env = unserialize($env); |
|
| 3432 | + } |
|
| 3433 | + $texte = ''; |
|
| 3434 | + if ($env) { |
|
| 3435 | + foreach ($env as $i => $j) { |
|
| 3436 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3437 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3438 | + } |
|
| 3439 | + } |
|
| 3440 | + } |
|
| 3441 | 3441 | |
| 3442 | - return $texte; |
|
| 3442 | + return $texte; |
|
| 3443 | 3443 | } |
| 3444 | 3444 | |
| 3445 | 3445 | |
@@ -3457,7 +3457,7 @@ discard block |
||
| 3457 | 3457 | * @return string Chaînes concaténés |
| 3458 | 3458 | **/ |
| 3459 | 3459 | function concat(...$args): string { |
| 3460 | - return join('', $args); |
|
| 3460 | + return join('', $args); |
|
| 3461 | 3461 | } |
| 3462 | 3462 | |
| 3463 | 3463 | |
@@ -3477,23 +3477,23 @@ discard block |
||
| 3477 | 3477 | * Contenu du ou des fichiers, concaténé |
| 3478 | 3478 | **/ |
| 3479 | 3479 | function charge_scripts($files, $script = true) { |
| 3480 | - $flux = ''; |
|
| 3481 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3482 | - if (!is_string($file)) { |
|
| 3483 | - continue; |
|
| 3484 | - } |
|
| 3485 | - if ($script) { |
|
| 3486 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3487 | - } |
|
| 3488 | - if ($file) { |
|
| 3489 | - $path = find_in_path($file); |
|
| 3490 | - if ($path) { |
|
| 3491 | - $flux .= spip_file_get_contents($path); |
|
| 3492 | - } |
|
| 3493 | - } |
|
| 3494 | - } |
|
| 3495 | - |
|
| 3496 | - return $flux; |
|
| 3480 | + $flux = ''; |
|
| 3481 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3482 | + if (!is_string($file)) { |
|
| 3483 | + continue; |
|
| 3484 | + } |
|
| 3485 | + if ($script) { |
|
| 3486 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3487 | + } |
|
| 3488 | + if ($file) { |
|
| 3489 | + $path = find_in_path($file); |
|
| 3490 | + if ($path) { |
|
| 3491 | + $flux .= spip_file_get_contents($path); |
|
| 3492 | + } |
|
| 3493 | + } |
|
| 3494 | + } |
|
| 3495 | + |
|
| 3496 | + return $flux; |
|
| 3497 | 3497 | } |
| 3498 | 3498 | |
| 3499 | 3499 | /** |
@@ -3504,22 +3504,22 @@ discard block |
||
| 3504 | 3504 | * @return string |
| 3505 | 3505 | */ |
| 3506 | 3506 | function http_img_variante_svg_si_possible($img_file) { |
| 3507 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3508 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3509 | - if ( |
|
| 3510 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3511 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3512 | - and file_exists($variante_svg_generique) |
|
| 3513 | - ) { |
|
| 3514 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3515 | - $img_file = $variante_svg_size; |
|
| 3516 | - } |
|
| 3517 | - else { |
|
| 3518 | - $img_file = $variante_svg_generique; |
|
| 3519 | - } |
|
| 3520 | - } |
|
| 3507 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3508 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3509 | + if ( |
|
| 3510 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3511 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3512 | + and file_exists($variante_svg_generique) |
|
| 3513 | + ) { |
|
| 3514 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3515 | + $img_file = $variante_svg_size; |
|
| 3516 | + } |
|
| 3517 | + else { |
|
| 3518 | + $img_file = $variante_svg_generique; |
|
| 3519 | + } |
|
| 3520 | + } |
|
| 3521 | 3521 | |
| 3522 | - return $img_file; |
|
| 3522 | + return $img_file; |
|
| 3523 | 3523 | } |
| 3524 | 3524 | |
| 3525 | 3525 | /** |
@@ -3540,54 +3540,54 @@ discard block |
||
| 3540 | 3540 | */ |
| 3541 | 3541 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3542 | 3542 | |
| 3543 | - $img_file = $img; |
|
| 3544 | - if ($p = strpos($img_file, '?')) { |
|
| 3545 | - $img_file = substr($img_file, 0, $p); |
|
| 3546 | - } |
|
| 3547 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3548 | - $img_file = chemin_image($img); |
|
| 3549 | - } |
|
| 3550 | - else { |
|
| 3551 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3552 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3553 | - } |
|
| 3554 | - } |
|
| 3555 | - if (stripos($atts, 'width') === false) { |
|
| 3556 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3557 | - if ( |
|
| 3558 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3559 | - or $options['utiliser_suffixe_size'] == true |
|
| 3560 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3561 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3562 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3563 | - ) { |
|
| 3564 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3565 | - } else { |
|
| 3566 | - $taille = taille_image($img_file); |
|
| 3567 | - [$hauteur, $largeur] = $taille; |
|
| 3568 | - if (!$hauteur or !$largeur) { |
|
| 3569 | - return ''; |
|
| 3570 | - } |
|
| 3571 | - } |
|
| 3572 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3573 | - } |
|
| 3574 | - |
|
| 3575 | - if (file_exists($img_file)) { |
|
| 3576 | - $img_file = timestamp($img_file); |
|
| 3577 | - } |
|
| 3578 | - if ($alt === false) { |
|
| 3579 | - $alt = ''; |
|
| 3580 | - } |
|
| 3581 | - elseif ($alt or $alt === '') { |
|
| 3582 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3583 | - } |
|
| 3584 | - else { |
|
| 3585 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3586 | - } |
|
| 3587 | - return "<img src='$img_file'$alt" |
|
| 3588 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3589 | - . ' ' . ltrim($atts) |
|
| 3590 | - . ' />'; |
|
| 3543 | + $img_file = $img; |
|
| 3544 | + if ($p = strpos($img_file, '?')) { |
|
| 3545 | + $img_file = substr($img_file, 0, $p); |
|
| 3546 | + } |
|
| 3547 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3548 | + $img_file = chemin_image($img); |
|
| 3549 | + } |
|
| 3550 | + else { |
|
| 3551 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3552 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3553 | + } |
|
| 3554 | + } |
|
| 3555 | + if (stripos($atts, 'width') === false) { |
|
| 3556 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3557 | + if ( |
|
| 3558 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3559 | + or $options['utiliser_suffixe_size'] == true |
|
| 3560 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3561 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3562 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3563 | + ) { |
|
| 3564 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3565 | + } else { |
|
| 3566 | + $taille = taille_image($img_file); |
|
| 3567 | + [$hauteur, $largeur] = $taille; |
|
| 3568 | + if (!$hauteur or !$largeur) { |
|
| 3569 | + return ''; |
|
| 3570 | + } |
|
| 3571 | + } |
|
| 3572 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3573 | + } |
|
| 3574 | + |
|
| 3575 | + if (file_exists($img_file)) { |
|
| 3576 | + $img_file = timestamp($img_file); |
|
| 3577 | + } |
|
| 3578 | + if ($alt === false) { |
|
| 3579 | + $alt = ''; |
|
| 3580 | + } |
|
| 3581 | + elseif ($alt or $alt === '') { |
|
| 3582 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3583 | + } |
|
| 3584 | + else { |
|
| 3585 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3586 | + } |
|
| 3587 | + return "<img src='$img_file'$alt" |
|
| 3588 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3589 | + . ' ' . ltrim($atts) |
|
| 3590 | + . ' />'; |
|
| 3591 | 3591 | } |
| 3592 | 3592 | |
| 3593 | 3593 | /** |
@@ -3599,70 +3599,70 @@ discard block |
||
| 3599 | 3599 | * @return string |
| 3600 | 3600 | */ |
| 3601 | 3601 | function http_style_background($img, $att = '', $size = null) { |
| 3602 | - if ($size and is_numeric($size)) { |
|
| 3603 | - $size = trim($size) . 'px'; |
|
| 3604 | - } |
|
| 3605 | - return " style='background" . |
|
| 3606 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3607 | - . ($size ? "background-size:{$size};" : '') |
|
| 3608 | - . "'"; |
|
| 3602 | + if ($size and is_numeric($size)) { |
|
| 3603 | + $size = trim($size) . 'px'; |
|
| 3604 | + } |
|
| 3605 | + return " style='background" . |
|
| 3606 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3607 | + . ($size ? "background-size:{$size};" : '') |
|
| 3608 | + . "'"; |
|
| 3609 | 3609 | } |
| 3610 | 3610 | |
| 3611 | 3611 | |
| 3612 | 3612 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3613 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3614 | - while (is_null(end($args)) and count($args)) { |
|
| 3615 | - array_pop($args); |
|
| 3616 | - } |
|
| 3617 | - if (!count($args)) { |
|
| 3618 | - return [null, null, null]; |
|
| 3619 | - } |
|
| 3620 | - if (count($args) < 3) { |
|
| 3621 | - $maybe_size = array_pop($args); |
|
| 3622 | - // @2x |
|
| 3623 | - // @1.5x |
|
| 3624 | - // 512 |
|
| 3625 | - // 512x* |
|
| 3626 | - // 512x300 |
|
| 3627 | - if ( |
|
| 3628 | - !strlen($maybe_size) |
|
| 3629 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3630 | - ) { |
|
| 3631 | - $args[] = $maybe_size; |
|
| 3632 | - $maybe_size = null; |
|
| 3633 | - } |
|
| 3634 | - while (count($args) < 2) { |
|
| 3635 | - $args[] = null; // default alt or class |
|
| 3636 | - } |
|
| 3637 | - $args[] = $maybe_size; |
|
| 3638 | - } |
|
| 3639 | - return $args; |
|
| 3613 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3614 | + while (is_null(end($args)) and count($args)) { |
|
| 3615 | + array_pop($args); |
|
| 3616 | + } |
|
| 3617 | + if (!count($args)) { |
|
| 3618 | + return [null, null, null]; |
|
| 3619 | + } |
|
| 3620 | + if (count($args) < 3) { |
|
| 3621 | + $maybe_size = array_pop($args); |
|
| 3622 | + // @2x |
|
| 3623 | + // @1.5x |
|
| 3624 | + // 512 |
|
| 3625 | + // 512x* |
|
| 3626 | + // 512x300 |
|
| 3627 | + if ( |
|
| 3628 | + !strlen($maybe_size) |
|
| 3629 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3630 | + ) { |
|
| 3631 | + $args[] = $maybe_size; |
|
| 3632 | + $maybe_size = null; |
|
| 3633 | + } |
|
| 3634 | + while (count($args) < 2) { |
|
| 3635 | + $args[] = null; // default alt or class |
|
| 3636 | + } |
|
| 3637 | + $args[] = $maybe_size; |
|
| 3638 | + } |
|
| 3639 | + return $args; |
|
| 3640 | 3640 | } |
| 3641 | 3641 | |
| 3642 | 3642 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3643 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3644 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3645 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3646 | - [$h, $w] = taille_image($img); |
|
| 3647 | - $height = intval(round($h / $coef)); |
|
| 3648 | - $width = intval(round($w / $coef)); |
|
| 3649 | - } |
|
| 3650 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3651 | - else { |
|
| 3652 | - $size = explode('x', $size, 2); |
|
| 3653 | - $size = array_map('trim', $size); |
|
| 3654 | - $height = $width = intval(array_shift($size)); |
|
| 3655 | - |
|
| 3656 | - if (count($size) and reset($size)) { |
|
| 3657 | - $height = array_shift($size); |
|
| 3658 | - if ($height === '*') { |
|
| 3659 | - [$h, $w] = taille_image($img); |
|
| 3660 | - $height = intval(round($h * $width / $w)); |
|
| 3661 | - } |
|
| 3662 | - } |
|
| 3663 | - } |
|
| 3664 | - |
|
| 3665 | - return [$width, $height]; |
|
| 3643 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3644 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3645 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3646 | + [$h, $w] = taille_image($img); |
|
| 3647 | + $height = intval(round($h / $coef)); |
|
| 3648 | + $width = intval(round($w / $coef)); |
|
| 3649 | + } |
|
| 3650 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3651 | + else { |
|
| 3652 | + $size = explode('x', $size, 2); |
|
| 3653 | + $size = array_map('trim', $size); |
|
| 3654 | + $height = $width = intval(array_shift($size)); |
|
| 3655 | + |
|
| 3656 | + if (count($size) and reset($size)) { |
|
| 3657 | + $height = array_shift($size); |
|
| 3658 | + if ($height === '*') { |
|
| 3659 | + [$h, $w] = taille_image($img); |
|
| 3660 | + $height = intval(round($h * $width / $w)); |
|
| 3661 | + } |
|
| 3662 | + } |
|
| 3663 | + } |
|
| 3664 | + |
|
| 3665 | + return [$width, $height]; |
|
| 3666 | 3666 | } |
| 3667 | 3667 | |
| 3668 | 3668 | /** |
@@ -3698,43 +3698,43 @@ discard block |
||
| 3698 | 3698 | */ |
| 3699 | 3699 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3700 | 3700 | |
| 3701 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3702 | - |
|
| 3703 | - $img = trim((string) $img); |
|
| 3704 | - if (strpos($img, '<img') === 0) { |
|
| 3705 | - if (!is_null($alt)) { |
|
| 3706 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3707 | - } |
|
| 3708 | - if (!is_null($class)) { |
|
| 3709 | - if (strlen($class)) { |
|
| 3710 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3711 | - } |
|
| 3712 | - else { |
|
| 3713 | - $img = vider_attribut($img, 'class'); |
|
| 3714 | - } |
|
| 3715 | - } |
|
| 3716 | - } |
|
| 3717 | - else { |
|
| 3718 | - $img = http_img_pack( |
|
| 3719 | - $img, |
|
| 3720 | - $alt, |
|
| 3721 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3722 | - '', |
|
| 3723 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3724 | - ); |
|
| 3725 | - if (is_null($alt)) { |
|
| 3726 | - $img = vider_attribut($img, 'alt'); |
|
| 3727 | - } |
|
| 3728 | - } |
|
| 3729 | - |
|
| 3730 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3731 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3732 | - |
|
| 3733 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3734 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3735 | - } |
|
| 3736 | - |
|
| 3737 | - return $img; |
|
| 3701 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3702 | + |
|
| 3703 | + $img = trim((string) $img); |
|
| 3704 | + if (strpos($img, '<img') === 0) { |
|
| 3705 | + if (!is_null($alt)) { |
|
| 3706 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3707 | + } |
|
| 3708 | + if (!is_null($class)) { |
|
| 3709 | + if (strlen($class)) { |
|
| 3710 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3711 | + } |
|
| 3712 | + else { |
|
| 3713 | + $img = vider_attribut($img, 'class'); |
|
| 3714 | + } |
|
| 3715 | + } |
|
| 3716 | + } |
|
| 3717 | + else { |
|
| 3718 | + $img = http_img_pack( |
|
| 3719 | + $img, |
|
| 3720 | + $alt, |
|
| 3721 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3722 | + '', |
|
| 3723 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3724 | + ); |
|
| 3725 | + if (is_null($alt)) { |
|
| 3726 | + $img = vider_attribut($img, 'alt'); |
|
| 3727 | + } |
|
| 3728 | + } |
|
| 3729 | + |
|
| 3730 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3731 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3732 | + |
|
| 3733 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3734 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3735 | + } |
|
| 3736 | + |
|
| 3737 | + return $img; |
|
| 3738 | 3738 | } |
| 3739 | 3739 | |
| 3740 | 3740 | |
@@ -3768,80 +3768,80 @@ discard block |
||
| 3768 | 3768 | */ |
| 3769 | 3769 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3770 | 3770 | |
| 3771 | - $svg = null; |
|
| 3772 | - $img = trim($img); |
|
| 3773 | - $img_file = $img; |
|
| 3774 | - if (strpos($img, '<svg') === false) { |
|
| 3775 | - if ($p = strpos($img_file, '?')) { |
|
| 3776 | - $img_file = substr($img_file, 0, $p); |
|
| 3777 | - } |
|
| 3778 | - |
|
| 3779 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3780 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3781 | - if (tester_url_absolue($img_file)) { |
|
| 3782 | - include_spip('inc/distant'); |
|
| 3783 | - $fichier = copie_locale($img_file); |
|
| 3784 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3785 | - } |
|
| 3786 | - |
|
| 3787 | - if ( |
|
| 3788 | - !$img_file |
|
| 3789 | - or !file_exists($img_file) |
|
| 3790 | - or !$svg = file_get_contents($img_file) |
|
| 3791 | - ) { |
|
| 3792 | - return ''; |
|
| 3793 | - } |
|
| 3794 | - } |
|
| 3795 | - |
|
| 3796 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3797 | - return ''; |
|
| 3798 | - } |
|
| 3799 | - |
|
| 3800 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3801 | - |
|
| 3802 | - $balise_svg = $match[0]; |
|
| 3803 | - $balise_svg_source = $balise_svg; |
|
| 3804 | - |
|
| 3805 | - // entete XML à supprimer |
|
| 3806 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3807 | - |
|
| 3808 | - // IE est toujours mon ami |
|
| 3809 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3810 | - |
|
| 3811 | - // regler la classe |
|
| 3812 | - if (!is_null($class)) { |
|
| 3813 | - if (strlen($class)) { |
|
| 3814 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3815 | - } |
|
| 3816 | - else { |
|
| 3817 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3818 | - } |
|
| 3819 | - } |
|
| 3820 | - |
|
| 3821 | - // regler le alt |
|
| 3822 | - if ($alt) { |
|
| 3823 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3824 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3825 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3826 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3827 | - $balise_svg .= $title; |
|
| 3828 | - } |
|
| 3829 | - else { |
|
| 3830 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3831 | - } |
|
| 3832 | - |
|
| 3833 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3834 | - |
|
| 3835 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3836 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3837 | - |
|
| 3838 | - if (!function_exists('svg_redimensionner')) { |
|
| 3839 | - include_spip('inc/svg'); |
|
| 3840 | - } |
|
| 3841 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3842 | - } |
|
| 3843 | - |
|
| 3844 | - return $svg; |
|
| 3771 | + $svg = null; |
|
| 3772 | + $img = trim($img); |
|
| 3773 | + $img_file = $img; |
|
| 3774 | + if (strpos($img, '<svg') === false) { |
|
| 3775 | + if ($p = strpos($img_file, '?')) { |
|
| 3776 | + $img_file = substr($img_file, 0, $p); |
|
| 3777 | + } |
|
| 3778 | + |
|
| 3779 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3780 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3781 | + if (tester_url_absolue($img_file)) { |
|
| 3782 | + include_spip('inc/distant'); |
|
| 3783 | + $fichier = copie_locale($img_file); |
|
| 3784 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3785 | + } |
|
| 3786 | + |
|
| 3787 | + if ( |
|
| 3788 | + !$img_file |
|
| 3789 | + or !file_exists($img_file) |
|
| 3790 | + or !$svg = file_get_contents($img_file) |
|
| 3791 | + ) { |
|
| 3792 | + return ''; |
|
| 3793 | + } |
|
| 3794 | + } |
|
| 3795 | + |
|
| 3796 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3797 | + return ''; |
|
| 3798 | + } |
|
| 3799 | + |
|
| 3800 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3801 | + |
|
| 3802 | + $balise_svg = $match[0]; |
|
| 3803 | + $balise_svg_source = $balise_svg; |
|
| 3804 | + |
|
| 3805 | + // entete XML à supprimer |
|
| 3806 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3807 | + |
|
| 3808 | + // IE est toujours mon ami |
|
| 3809 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3810 | + |
|
| 3811 | + // regler la classe |
|
| 3812 | + if (!is_null($class)) { |
|
| 3813 | + if (strlen($class)) { |
|
| 3814 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3815 | + } |
|
| 3816 | + else { |
|
| 3817 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3818 | + } |
|
| 3819 | + } |
|
| 3820 | + |
|
| 3821 | + // regler le alt |
|
| 3822 | + if ($alt) { |
|
| 3823 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3824 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3825 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3826 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3827 | + $balise_svg .= $title; |
|
| 3828 | + } |
|
| 3829 | + else { |
|
| 3830 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3831 | + } |
|
| 3832 | + |
|
| 3833 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3834 | + |
|
| 3835 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3836 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3837 | + |
|
| 3838 | + if (!function_exists('svg_redimensionner')) { |
|
| 3839 | + include_spip('inc/svg'); |
|
| 3840 | + } |
|
| 3841 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3842 | + } |
|
| 3843 | + |
|
| 3844 | + return $svg; |
|
| 3845 | 3845 | } |
| 3846 | 3846 | |
| 3847 | 3847 | |
@@ -3867,18 +3867,18 @@ discard block |
||
| 3867 | 3867 | * Code HTML résultant |
| 3868 | 3868 | **/ |
| 3869 | 3869 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3870 | - $texte = ''; |
|
| 3871 | - if (is_array($tableau)) { |
|
| 3872 | - foreach ($tableau as $k => $v) { |
|
| 3873 | - $res = recuperer_fond( |
|
| 3874 | - 'modeles/' . $modele, |
|
| 3875 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3876 | - ); |
|
| 3877 | - $texte .= $res; |
|
| 3878 | - } |
|
| 3879 | - } |
|
| 3870 | + $texte = ''; |
|
| 3871 | + if (is_array($tableau)) { |
|
| 3872 | + foreach ($tableau as $k => $v) { |
|
| 3873 | + $res = recuperer_fond( |
|
| 3874 | + 'modeles/' . $modele, |
|
| 3875 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3876 | + ); |
|
| 3877 | + $texte .= $res; |
|
| 3878 | + } |
|
| 3879 | + } |
|
| 3880 | 3880 | |
| 3881 | - return $texte; |
|
| 3881 | + return $texte; |
|
| 3882 | 3882 | } |
| 3883 | 3883 | |
| 3884 | 3884 | |
@@ -3903,37 +3903,37 @@ discard block |
||
| 3903 | 3903 | * - tout : retourne toutes les informations du plugin actif |
| 3904 | 3904 | **/ |
| 3905 | 3905 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3906 | - include_spip('inc/plugin'); |
|
| 3907 | - $plugin = strtoupper($plugin); |
|
| 3908 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3909 | - |
|
| 3910 | - if (!$plugin) { |
|
| 3911 | - return serialize(array_keys($plugins_actifs)); |
|
| 3912 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3913 | - return ''; |
|
| 3914 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3915 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3916 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3917 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3918 | - } else { |
|
| 3919 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3920 | - // On prend en compte les extensions |
|
| 3921 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3922 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3923 | - } else { |
|
| 3924 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3925 | - } |
|
| 3926 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3927 | - return ''; |
|
| 3928 | - } |
|
| 3929 | - if ($type_info == 'tout') { |
|
| 3930 | - return $infos; |
|
| 3931 | - } elseif ($type_info == 'est_actif') { |
|
| 3932 | - return $infos ? 1 : 0; |
|
| 3933 | - } else { |
|
| 3934 | - return strval($infos[$type_info]); |
|
| 3935 | - } |
|
| 3936 | - } |
|
| 3906 | + include_spip('inc/plugin'); |
|
| 3907 | + $plugin = strtoupper($plugin); |
|
| 3908 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3909 | + |
|
| 3910 | + if (!$plugin) { |
|
| 3911 | + return serialize(array_keys($plugins_actifs)); |
|
| 3912 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3913 | + return ''; |
|
| 3914 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3915 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3916 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3917 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3918 | + } else { |
|
| 3919 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3920 | + // On prend en compte les extensions |
|
| 3921 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3922 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3923 | + } else { |
|
| 3924 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3925 | + } |
|
| 3926 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3927 | + return ''; |
|
| 3928 | + } |
|
| 3929 | + if ($type_info == 'tout') { |
|
| 3930 | + return $infos; |
|
| 3931 | + } elseif ($type_info == 'est_actif') { |
|
| 3932 | + return $infos ? 1 : 0; |
|
| 3933 | + } else { |
|
| 3934 | + return strval($infos[$type_info]); |
|
| 3935 | + } |
|
| 3936 | + } |
|
| 3937 | 3937 | } |
| 3938 | 3938 | |
| 3939 | 3939 | |
@@ -3960,9 +3960,9 @@ discard block |
||
| 3960 | 3960 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3961 | 3961 | */ |
| 3962 | 3962 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3963 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3963 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3964 | 3964 | |
| 3965 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3965 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3966 | 3966 | } |
| 3967 | 3967 | |
| 3968 | 3968 | |
@@ -3992,19 +3992,19 @@ discard block |
||
| 3992 | 3992 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3993 | 3993 | */ |
| 3994 | 3994 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3995 | - static $puce_statut = null; |
|
| 3996 | - if (!$puce_statut) { |
|
| 3997 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3998 | - } |
|
| 3995 | + static $puce_statut = null; |
|
| 3996 | + if (!$puce_statut) { |
|
| 3997 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3998 | + } |
|
| 3999 | 3999 | |
| 4000 | - return $puce_statut( |
|
| 4001 | - $id_objet, |
|
| 4002 | - $statut, |
|
| 4003 | - $id_parent, |
|
| 4004 | - $objet, |
|
| 4005 | - false, |
|
| 4006 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4007 | - ); |
|
| 4000 | + return $puce_statut( |
|
| 4001 | + $id_objet, |
|
| 4002 | + $statut, |
|
| 4003 | + $id_parent, |
|
| 4004 | + $objet, |
|
| 4005 | + false, |
|
| 4006 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4007 | + ); |
|
| 4008 | 4008 | } |
| 4009 | 4009 | |
| 4010 | 4010 | |
@@ -4031,98 +4031,98 @@ discard block |
||
| 4031 | 4031 | * hash du contexte |
| 4032 | 4032 | */ |
| 4033 | 4033 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 4034 | - $env = null; |
|
| 4035 | - if ( |
|
| 4036 | - is_string($c) |
|
| 4037 | - and @unserialize($c) !== false |
|
| 4038 | - ) { |
|
| 4039 | - $c = unserialize($c); |
|
| 4040 | - } |
|
| 4041 | - |
|
| 4042 | - // supprimer les parametres debut_x |
|
| 4043 | - // pour que la pagination ajax ne soit pas plantee |
|
| 4044 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4045 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4046 | - if (is_array($c)) { |
|
| 4047 | - foreach ($c as $k => $v) { |
|
| 4048 | - if (strpos($k, 'debut_') === 0) { |
|
| 4049 | - unset($c[$k]); |
|
| 4050 | - } |
|
| 4051 | - } |
|
| 4052 | - } |
|
| 4053 | - |
|
| 4054 | - if (!function_exists('calculer_cle_action')) { |
|
| 4055 | - include_spip('inc/securiser_action'); |
|
| 4056 | - } |
|
| 4057 | - |
|
| 4058 | - $c = serialize($c); |
|
| 4059 | - $cle = calculer_cle_action($form . $c); |
|
| 4060 | - $c = "$cle:$c"; |
|
| 4061 | - |
|
| 4062 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4063 | - // par defaut, sauf si cette configuration a été forcée |
|
| 4064 | - // OU que la longueur de l’argument géneré est plus long |
|
| 4065 | - // que ce qui est toléré. |
|
| 4066 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4067 | - if (!$cache_contextes_ajax) { |
|
| 4068 | - $env = $c; |
|
| 4069 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4070 | - $env = gzdeflate($env); |
|
| 4071 | - } |
|
| 4072 | - $env = _xor($env); |
|
| 4073 | - $env = base64_encode($env); |
|
| 4074 | - $len = strlen($env); |
|
| 4075 | - // Si l’url est trop longue pour le navigateur |
|
| 4076 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4077 | - if ($len > $max_len) { |
|
| 4078 | - $cache_contextes_ajax = true; |
|
| 4079 | - spip_log( |
|
| 4080 | - 'Contextes AJAX forces en fichiers !' |
|
| 4081 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4082 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4083 | - _LOG_AVERTISSEMENT |
|
| 4084 | - ); |
|
| 4085 | - } |
|
| 4086 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4087 | - elseif ( |
|
| 4088 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4089 | - and $max_len < $len |
|
| 4090 | - ) { |
|
| 4091 | - $cache_contextes_ajax = true; |
|
| 4092 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4093 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4094 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4095 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4096 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4097 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4098 | - } |
|
| 4099 | - } |
|
| 4100 | - |
|
| 4101 | - if ($cache_contextes_ajax) { |
|
| 4102 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4103 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4104 | - $md5 = md5($c); |
|
| 4105 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4106 | - $env = $md5; |
|
| 4107 | - } |
|
| 4108 | - |
|
| 4109 | - if ($emboite === null) { |
|
| 4110 | - return $env; |
|
| 4111 | - } |
|
| 4112 | - if (!trim($emboite)) { |
|
| 4113 | - return ''; |
|
| 4114 | - } |
|
| 4115 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4116 | - $r = self(); |
|
| 4117 | - $r = ' data-origin="' . $r . '"'; |
|
| 4118 | - $class = 'ajaxbloc'; |
|
| 4119 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4120 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4121 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4122 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4123 | - } |
|
| 4124 | - |
|
| 4125 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4034 | + $env = null; |
|
| 4035 | + if ( |
|
| 4036 | + is_string($c) |
|
| 4037 | + and @unserialize($c) !== false |
|
| 4038 | + ) { |
|
| 4039 | + $c = unserialize($c); |
|
| 4040 | + } |
|
| 4041 | + |
|
| 4042 | + // supprimer les parametres debut_x |
|
| 4043 | + // pour que la pagination ajax ne soit pas plantee |
|
| 4044 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4045 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4046 | + if (is_array($c)) { |
|
| 4047 | + foreach ($c as $k => $v) { |
|
| 4048 | + if (strpos($k, 'debut_') === 0) { |
|
| 4049 | + unset($c[$k]); |
|
| 4050 | + } |
|
| 4051 | + } |
|
| 4052 | + } |
|
| 4053 | + |
|
| 4054 | + if (!function_exists('calculer_cle_action')) { |
|
| 4055 | + include_spip('inc/securiser_action'); |
|
| 4056 | + } |
|
| 4057 | + |
|
| 4058 | + $c = serialize($c); |
|
| 4059 | + $cle = calculer_cle_action($form . $c); |
|
| 4060 | + $c = "$cle:$c"; |
|
| 4061 | + |
|
| 4062 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4063 | + // par defaut, sauf si cette configuration a été forcée |
|
| 4064 | + // OU que la longueur de l’argument géneré est plus long |
|
| 4065 | + // que ce qui est toléré. |
|
| 4066 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4067 | + if (!$cache_contextes_ajax) { |
|
| 4068 | + $env = $c; |
|
| 4069 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4070 | + $env = gzdeflate($env); |
|
| 4071 | + } |
|
| 4072 | + $env = _xor($env); |
|
| 4073 | + $env = base64_encode($env); |
|
| 4074 | + $len = strlen($env); |
|
| 4075 | + // Si l’url est trop longue pour le navigateur |
|
| 4076 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4077 | + if ($len > $max_len) { |
|
| 4078 | + $cache_contextes_ajax = true; |
|
| 4079 | + spip_log( |
|
| 4080 | + 'Contextes AJAX forces en fichiers !' |
|
| 4081 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4082 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4083 | + _LOG_AVERTISSEMENT |
|
| 4084 | + ); |
|
| 4085 | + } |
|
| 4086 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4087 | + elseif ( |
|
| 4088 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4089 | + and $max_len < $len |
|
| 4090 | + ) { |
|
| 4091 | + $cache_contextes_ajax = true; |
|
| 4092 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4093 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4094 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4095 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4096 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4097 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4098 | + } |
|
| 4099 | + } |
|
| 4100 | + |
|
| 4101 | + if ($cache_contextes_ajax) { |
|
| 4102 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4103 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4104 | + $md5 = md5($c); |
|
| 4105 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4106 | + $env = $md5; |
|
| 4107 | + } |
|
| 4108 | + |
|
| 4109 | + if ($emboite === null) { |
|
| 4110 | + return $env; |
|
| 4111 | + } |
|
| 4112 | + if (!trim($emboite)) { |
|
| 4113 | + return ''; |
|
| 4114 | + } |
|
| 4115 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4116 | + $r = self(); |
|
| 4117 | + $r = ' data-origin="' . $r . '"'; |
|
| 4118 | + $class = 'ajaxbloc'; |
|
| 4119 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4120 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4121 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4122 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4123 | + } |
|
| 4124 | + |
|
| 4125 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4126 | 4126 | } |
| 4127 | 4127 | |
| 4128 | 4128 | /** |
@@ -4142,37 +4142,37 @@ discard block |
||
| 4142 | 4142 | * - false : erreur de décodage |
| 4143 | 4143 | */ |
| 4144 | 4144 | function decoder_contexte_ajax($c, $form = '') { |
| 4145 | - if (!function_exists('calculer_cle_action')) { |
|
| 4146 | - include_spip('inc/securiser_action'); |
|
| 4147 | - } |
|
| 4148 | - if ( |
|
| 4149 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4150 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4151 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4152 | - ) { |
|
| 4153 | - $c = $contexte; |
|
| 4154 | - } else { |
|
| 4155 | - $c = @base64_decode($c); |
|
| 4156 | - $c = _xor($c); |
|
| 4157 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4158 | - $c = @gzinflate($c); |
|
| 4159 | - } |
|
| 4160 | - } |
|
| 4161 | - |
|
| 4162 | - // extraire la signature en debut de contexte |
|
| 4163 | - // et la verifier avant de deserializer |
|
| 4164 | - // format : signature:donneesserializees |
|
| 4165 | - if ($p = strpos($c, ':')) { |
|
| 4166 | - $cle = substr($c, 0, $p); |
|
| 4167 | - $c = substr($c, $p + 1); |
|
| 4168 | - |
|
| 4169 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4170 | - $env = @unserialize($c); |
|
| 4171 | - return $env; |
|
| 4172 | - } |
|
| 4173 | - } |
|
| 4174 | - |
|
| 4175 | - return false; |
|
| 4145 | + if (!function_exists('calculer_cle_action')) { |
|
| 4146 | + include_spip('inc/securiser_action'); |
|
| 4147 | + } |
|
| 4148 | + if ( |
|
| 4149 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4150 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4151 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4152 | + ) { |
|
| 4153 | + $c = $contexte; |
|
| 4154 | + } else { |
|
| 4155 | + $c = @base64_decode($c); |
|
| 4156 | + $c = _xor($c); |
|
| 4157 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4158 | + $c = @gzinflate($c); |
|
| 4159 | + } |
|
| 4160 | + } |
|
| 4161 | + |
|
| 4162 | + // extraire la signature en debut de contexte |
|
| 4163 | + // et la verifier avant de deserializer |
|
| 4164 | + // format : signature:donneesserializees |
|
| 4165 | + if ($p = strpos($c, ':')) { |
|
| 4166 | + $cle = substr($c, 0, $p); |
|
| 4167 | + $c = substr($c, $p + 1); |
|
| 4168 | + |
|
| 4169 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4170 | + $env = @unserialize($c); |
|
| 4171 | + return $env; |
|
| 4172 | + } |
|
| 4173 | + } |
|
| 4174 | + |
|
| 4175 | + return false; |
|
| 4176 | 4176 | } |
| 4177 | 4177 | |
| 4178 | 4178 | |
@@ -4190,20 +4190,20 @@ discard block |
||
| 4190 | 4190 | * Message décrypté ou encrypté |
| 4191 | 4191 | **/ |
| 4192 | 4192 | function _xor($message, $key = null) { |
| 4193 | - if (is_null($key)) { |
|
| 4194 | - if (!function_exists('calculer_cle_action')) { |
|
| 4195 | - include_spip('inc/securiser_action'); |
|
| 4196 | - } |
|
| 4197 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4198 | - } |
|
| 4193 | + if (is_null($key)) { |
|
| 4194 | + if (!function_exists('calculer_cle_action')) { |
|
| 4195 | + include_spip('inc/securiser_action'); |
|
| 4196 | + } |
|
| 4197 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4198 | + } |
|
| 4199 | 4199 | |
| 4200 | - $keylen = strlen($key); |
|
| 4201 | - $messagelen = strlen($message); |
|
| 4202 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4203 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4204 | - } |
|
| 4200 | + $keylen = strlen($key); |
|
| 4201 | + $messagelen = strlen($message); |
|
| 4202 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4203 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4204 | + } |
|
| 4205 | 4205 | |
| 4206 | - return $message; |
|
| 4206 | + return $message; |
|
| 4207 | 4207 | } |
| 4208 | 4208 | |
| 4209 | 4209 | /** |
@@ -4217,7 +4217,7 @@ discard block |
||
| 4217 | 4217 | * @return string |
| 4218 | 4218 | */ |
| 4219 | 4219 | function url_reponse_forum($texte) { |
| 4220 | - return $texte; |
|
| 4220 | + return $texte; |
|
| 4221 | 4221 | } |
| 4222 | 4222 | |
| 4223 | 4223 | /** |
@@ -4231,7 +4231,7 @@ discard block |
||
| 4231 | 4231 | * @return string |
| 4232 | 4232 | */ |
| 4233 | 4233 | function url_rss_forum($texte) { |
| 4234 | - return $texte; |
|
| 4234 | + return $texte; |
|
| 4235 | 4235 | } |
| 4236 | 4236 | |
| 4237 | 4237 | |
@@ -4270,37 +4270,37 @@ discard block |
||
| 4270 | 4270 | * Code HTML |
| 4271 | 4271 | */ |
| 4272 | 4272 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4273 | - if ($on) { |
|
| 4274 | - $bal = 'strong'; |
|
| 4275 | - $class = ''; |
|
| 4276 | - $att = ''; |
|
| 4277 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4278 | - // a.active span.selected.active etc.... |
|
| 4279 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4280 | - $on = explode('.', $on); |
|
| 4281 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4282 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4283 | - $bal = array_shift($on); |
|
| 4284 | - $class = implode(' ', $on); |
|
| 4285 | - if ($bal == 'a') { |
|
| 4286 | - $att = 'href="#" '; |
|
| 4287 | - } |
|
| 4288 | - } |
|
| 4289 | - } |
|
| 4290 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4291 | - } else { |
|
| 4292 | - $bal = 'a'; |
|
| 4293 | - $att = "href='$url'" |
|
| 4294 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4295 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4296 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4297 | - . $evt; |
|
| 4298 | - } |
|
| 4299 | - if ($libelle === null) { |
|
| 4300 | - $libelle = $url; |
|
| 4301 | - } |
|
| 4302 | - |
|
| 4303 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4273 | + if ($on) { |
|
| 4274 | + $bal = 'strong'; |
|
| 4275 | + $class = ''; |
|
| 4276 | + $att = ''; |
|
| 4277 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4278 | + // a.active span.selected.active etc.... |
|
| 4279 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4280 | + $on = explode('.', $on); |
|
| 4281 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4282 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4283 | + $bal = array_shift($on); |
|
| 4284 | + $class = implode(' ', $on); |
|
| 4285 | + if ($bal == 'a') { |
|
| 4286 | + $att = 'href="#" '; |
|
| 4287 | + } |
|
| 4288 | + } |
|
| 4289 | + } |
|
| 4290 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4291 | + } else { |
|
| 4292 | + $bal = 'a'; |
|
| 4293 | + $att = "href='$url'" |
|
| 4294 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4295 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4296 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4297 | + . $evt; |
|
| 4298 | + } |
|
| 4299 | + if ($libelle === null) { |
|
| 4300 | + $libelle = $url; |
|
| 4301 | + } |
|
| 4302 | + |
|
| 4303 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4304 | 4304 | } |
| 4305 | 4305 | |
| 4306 | 4306 | |
@@ -4317,39 +4317,39 @@ discard block |
||
| 4317 | 4317 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4318 | 4318 | */ |
| 4319 | 4319 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4320 | - static $local_singulier_ou_pluriel = []; |
|
| 4321 | - |
|
| 4322 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4323 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4324 | - return ''; |
|
| 4325 | - } |
|
| 4326 | - if (!is_array($vars)) { |
|
| 4327 | - return ''; |
|
| 4328 | - } |
|
| 4329 | - |
|
| 4330 | - $langue = $GLOBALS['spip_lang']; |
|
| 4331 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4332 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4333 | - if ( |
|
| 4334 | - $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4335 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4336 | - ) { |
|
| 4337 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4338 | - } |
|
| 4339 | - } |
|
| 4340 | - |
|
| 4341 | - // si on a une surcharge on l'utilise |
|
| 4342 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4343 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4344 | - } |
|
| 4345 | - |
|
| 4346 | - // sinon traitement par defaut |
|
| 4347 | - $vars[$var] = $nb; |
|
| 4348 | - if ($nb >= 2) { |
|
| 4349 | - return _T($chaine_plusieurs, $vars); |
|
| 4350 | - } else { |
|
| 4351 | - return _T($chaine_un, $vars); |
|
| 4352 | - } |
|
| 4320 | + static $local_singulier_ou_pluriel = []; |
|
| 4321 | + |
|
| 4322 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4323 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4324 | + return ''; |
|
| 4325 | + } |
|
| 4326 | + if (!is_array($vars)) { |
|
| 4327 | + return ''; |
|
| 4328 | + } |
|
| 4329 | + |
|
| 4330 | + $langue = $GLOBALS['spip_lang']; |
|
| 4331 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4332 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4333 | + if ( |
|
| 4334 | + $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4335 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4336 | + ) { |
|
| 4337 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4338 | + } |
|
| 4339 | + } |
|
| 4340 | + |
|
| 4341 | + // si on a une surcharge on l'utilise |
|
| 4342 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4343 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4344 | + } |
|
| 4345 | + |
|
| 4346 | + // sinon traitement par defaut |
|
| 4347 | + $vars[$var] = $nb; |
|
| 4348 | + if ($nb >= 2) { |
|
| 4349 | + return _T($chaine_plusieurs, $vars); |
|
| 4350 | + } else { |
|
| 4351 | + return _T($chaine_un, $vars); |
|
| 4352 | + } |
|
| 4353 | 4353 | } |
| 4354 | 4354 | |
| 4355 | 4355 | |
@@ -4377,73 +4377,73 @@ discard block |
||
| 4377 | 4377 | */ |
| 4378 | 4378 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4379 | 4379 | |
| 4380 | - $class_lien = $class_bouton = $class; |
|
| 4381 | - |
|
| 4382 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4383 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4384 | - $class_lien .= ' danger'; |
|
| 4385 | - $class_bouton .= ' btn_danger'; |
|
| 4386 | - } elseif ($fonction == 'rien.gif') { |
|
| 4387 | - $fonction = ''; |
|
| 4388 | - } elseif ($fonction == 'delsafe') { |
|
| 4389 | - $fonction = 'del'; |
|
| 4390 | - } |
|
| 4391 | - |
|
| 4392 | - $fond_origine = $fond; |
|
| 4393 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4394 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4395 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4396 | - } |
|
| 4397 | - |
|
| 4398 | - // Ajouter le type d'objet dans la classe |
|
| 4399 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4400 | - $class_lien .= " $objet_type"; |
|
| 4401 | - $class_bouton .= " $objet_type"; |
|
| 4402 | - |
|
| 4403 | - // Texte |
|
| 4404 | - $alt = attribut_html($texte); |
|
| 4405 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4406 | - |
|
| 4407 | - // Liens : préparer les classes ajax |
|
| 4408 | - $ajax = ''; |
|
| 4409 | - if ($type === 'lien') { |
|
| 4410 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4411 | - $ajax = 'ajax'; |
|
| 4412 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4413 | - $ajax .= ' preload'; |
|
| 4414 | - } |
|
| 4415 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4416 | - $ajax .= ' nocache'; |
|
| 4417 | - } |
|
| 4418 | - $ajax = " class='$ajax'"; |
|
| 4419 | - } |
|
| 4420 | - } |
|
| 4421 | - |
|
| 4422 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4423 | - $size = 24; |
|
| 4424 | - if ( |
|
| 4425 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4426 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4427 | - ) { |
|
| 4428 | - $size = $match[1]; |
|
| 4429 | - } |
|
| 4430 | - $class_lien .= " s$size"; |
|
| 4431 | - $class_bouton .= " s$size"; |
|
| 4432 | - |
|
| 4433 | - // Icône |
|
| 4434 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4435 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4436 | - |
|
| 4437 | - // Markup final |
|
| 4438 | - if ($type == 'lien') { |
|
| 4439 | - return "<span class='icone $class_lien'>" |
|
| 4440 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4441 | - . $icone |
|
| 4442 | - . "<b>$texte</b>" |
|
| 4443 | - . "</a></span>\n"; |
|
| 4444 | - } else { |
|
| 4445 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4446 | - } |
|
| 4380 | + $class_lien = $class_bouton = $class; |
|
| 4381 | + |
|
| 4382 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4383 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4384 | + $class_lien .= ' danger'; |
|
| 4385 | + $class_bouton .= ' btn_danger'; |
|
| 4386 | + } elseif ($fonction == 'rien.gif') { |
|
| 4387 | + $fonction = ''; |
|
| 4388 | + } elseif ($fonction == 'delsafe') { |
|
| 4389 | + $fonction = 'del'; |
|
| 4390 | + } |
|
| 4391 | + |
|
| 4392 | + $fond_origine = $fond; |
|
| 4393 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4394 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4395 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4396 | + } |
|
| 4397 | + |
|
| 4398 | + // Ajouter le type d'objet dans la classe |
|
| 4399 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4400 | + $class_lien .= " $objet_type"; |
|
| 4401 | + $class_bouton .= " $objet_type"; |
|
| 4402 | + |
|
| 4403 | + // Texte |
|
| 4404 | + $alt = attribut_html($texte); |
|
| 4405 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4406 | + |
|
| 4407 | + // Liens : préparer les classes ajax |
|
| 4408 | + $ajax = ''; |
|
| 4409 | + if ($type === 'lien') { |
|
| 4410 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4411 | + $ajax = 'ajax'; |
|
| 4412 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4413 | + $ajax .= ' preload'; |
|
| 4414 | + } |
|
| 4415 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4416 | + $ajax .= ' nocache'; |
|
| 4417 | + } |
|
| 4418 | + $ajax = " class='$ajax'"; |
|
| 4419 | + } |
|
| 4420 | + } |
|
| 4421 | + |
|
| 4422 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4423 | + $size = 24; |
|
| 4424 | + if ( |
|
| 4425 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4426 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4427 | + ) { |
|
| 4428 | + $size = $match[1]; |
|
| 4429 | + } |
|
| 4430 | + $class_lien .= " s$size"; |
|
| 4431 | + $class_bouton .= " s$size"; |
|
| 4432 | + |
|
| 4433 | + // Icône |
|
| 4434 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4435 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4436 | + |
|
| 4437 | + // Markup final |
|
| 4438 | + if ($type == 'lien') { |
|
| 4439 | + return "<span class='icone $class_lien'>" |
|
| 4440 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4441 | + . $icone |
|
| 4442 | + . "<b>$texte</b>" |
|
| 4443 | + . "</a></span>\n"; |
|
| 4444 | + } else { |
|
| 4445 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4446 | + } |
|
| 4447 | 4447 | } |
| 4448 | 4448 | |
| 4449 | 4449 | /** |
@@ -4467,7 +4467,7 @@ discard block |
||
| 4467 | 4467 | * Code HTML du lien |
| 4468 | 4468 | **/ |
| 4469 | 4469 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4470 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4470 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4471 | 4471 | } |
| 4472 | 4472 | |
| 4473 | 4473 | /** |
@@ -4502,7 +4502,7 @@ discard block |
||
| 4502 | 4502 | * Code HTML du lien |
| 4503 | 4503 | **/ |
| 4504 | 4504 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4505 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4505 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4506 | 4506 | } |
| 4507 | 4507 | |
| 4508 | 4508 | /** |
@@ -4547,7 +4547,7 @@ discard block |
||
| 4547 | 4547 | * Code HTML du lien |
| 4548 | 4548 | **/ |
| 4549 | 4549 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4550 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4550 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4551 | 4551 | } |
| 4552 | 4552 | |
| 4553 | 4553 | /** |
@@ -4578,7 +4578,7 @@ discard block |
||
| 4578 | 4578 | * Code HTML du lien |
| 4579 | 4579 | **/ |
| 4580 | 4580 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4581 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4581 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4582 | 4582 | } |
| 4583 | 4583 | |
| 4584 | 4584 | /** |
@@ -4609,7 +4609,7 @@ discard block |
||
| 4609 | 4609 | * Code HTML du lien |
| 4610 | 4610 | */ |
| 4611 | 4611 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4612 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4612 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4613 | 4613 | } |
| 4614 | 4614 | |
| 4615 | 4615 | |
@@ -4631,7 +4631,7 @@ discard block |
||
| 4631 | 4631 | * @return array Liste des éléments |
| 4632 | 4632 | */ |
| 4633 | 4633 | function filtre_explode_dist($a, $b) { |
| 4634 | - return explode($b, (string) $a); |
|
| 4634 | + return explode($b, (string) $a); |
|
| 4635 | 4635 | } |
| 4636 | 4636 | |
| 4637 | 4637 | /** |
@@ -4652,7 +4652,7 @@ discard block |
||
| 4652 | 4652 | * @return string Texte |
| 4653 | 4653 | */ |
| 4654 | 4654 | function filtre_implode_dist($a, $b) { |
| 4655 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4655 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4656 | 4656 | } |
| 4657 | 4657 | |
| 4658 | 4658 | /** |
@@ -4661,24 +4661,24 @@ discard block |
||
| 4661 | 4661 | * @return string Code CSS |
| 4662 | 4662 | */ |
| 4663 | 4663 | function bando_images_background() { |
| 4664 | - include_spip('inc/bandeau'); |
|
| 4665 | - // recuperer tous les boutons et leurs images |
|
| 4666 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4664 | + include_spip('inc/bandeau'); |
|
| 4665 | + // recuperer tous les boutons et leurs images |
|
| 4666 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4667 | 4667 | |
| 4668 | - $res = ''; |
|
| 4669 | - foreach ($boutons as $page => $detail) { |
|
| 4670 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4671 | - if (is_array($detail->sousmenu)) { |
|
| 4672 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4673 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4674 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4675 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4676 | - } |
|
| 4677 | - } |
|
| 4678 | - } |
|
| 4679 | - } |
|
| 4668 | + $res = ''; |
|
| 4669 | + foreach ($boutons as $page => $detail) { |
|
| 4670 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4671 | + if (is_array($detail->sousmenu)) { |
|
| 4672 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4673 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4674 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4675 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4676 | + } |
|
| 4677 | + } |
|
| 4678 | + } |
|
| 4679 | + } |
|
| 4680 | 4680 | |
| 4681 | - return $res; |
|
| 4681 | + return $res; |
|
| 4682 | 4682 | } |
| 4683 | 4683 | |
| 4684 | 4684 | /** |
@@ -4703,27 +4703,27 @@ discard block |
||
| 4703 | 4703 | */ |
| 4704 | 4704 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4705 | 4705 | |
| 4706 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4707 | - $class_form = ''; |
|
| 4708 | - if (strpos($class, 'ajax') !== false) { |
|
| 4709 | - $class_form = 'ajax'; |
|
| 4710 | - $class = str_replace('ajax', '', $class); |
|
| 4711 | - } |
|
| 4712 | - $class_btn = 'submit ' . trim($class); |
|
| 4706 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4707 | + $class_form = ''; |
|
| 4708 | + if (strpos($class, 'ajax') !== false) { |
|
| 4709 | + $class_form = 'ajax'; |
|
| 4710 | + $class = str_replace('ajax', '', $class); |
|
| 4711 | + } |
|
| 4712 | + $class_btn = 'submit ' . trim($class); |
|
| 4713 | 4713 | |
| 4714 | - if ($confirm) { |
|
| 4715 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4716 | - if ($callback) { |
|
| 4717 | - $callback = "$confirm?($callback):false"; |
|
| 4718 | - } else { |
|
| 4719 | - $callback = $confirm; |
|
| 4720 | - } |
|
| 4721 | - } |
|
| 4722 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4723 | - $title = $title ? " title='$title'" : ''; |
|
| 4714 | + if ($confirm) { |
|
| 4715 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4716 | + if ($callback) { |
|
| 4717 | + $callback = "$confirm?($callback):false"; |
|
| 4718 | + } else { |
|
| 4719 | + $callback = $confirm; |
|
| 4720 | + } |
|
| 4721 | + } |
|
| 4722 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4723 | + $title = $title ? " title='$title'" : ''; |
|
| 4724 | 4724 | |
| 4725 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4726 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4725 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4726 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4727 | 4727 | } |
| 4728 | 4728 | |
| 4729 | 4729 | /** |
@@ -4746,101 +4746,101 @@ discard block |
||
| 4746 | 4746 | * @return string |
| 4747 | 4747 | */ |
| 4748 | 4748 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4749 | - static $trouver_table = null; |
|
| 4750 | - static $objets; |
|
| 4751 | - |
|
| 4752 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4753 | - $id_objet = intval($id_objet); |
|
| 4754 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4755 | - return ''; |
|
| 4756 | - } |
|
| 4757 | - |
|
| 4758 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4759 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4760 | - return ''; |
|
| 4761 | - } |
|
| 4762 | - |
|
| 4763 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4764 | - if ($info == 'url') { |
|
| 4765 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4766 | - } |
|
| 4767 | - |
|
| 4768 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4769 | - $demande_titre = ($info === 'titre'); |
|
| 4770 | - $demande_introduction = ($info === 'introduction'); |
|
| 4771 | - |
|
| 4772 | - // 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 |
|
| 4773 | - if ( |
|
| 4774 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4775 | - or |
|
| 4776 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4777 | - ) { |
|
| 4778 | - if (!$trouver_table) { |
|
| 4779 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4780 | - } |
|
| 4781 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4782 | - if (!$desc) { |
|
| 4783 | - return $objets[$type_objet] = false; |
|
| 4784 | - } |
|
| 4785 | - |
|
| 4786 | - // Si on demande le titre, on le gere en interne |
|
| 4787 | - $champ_titre = ''; |
|
| 4788 | - if ($demande_titre) { |
|
| 4789 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4790 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4791 | - } |
|
| 4792 | - include_spip('base/abstract_sql'); |
|
| 4793 | - include_spip('base/connect_sql'); |
|
| 4794 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4795 | - '*' . $champ_titre, |
|
| 4796 | - $desc['table_sql'], |
|
| 4797 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4798 | - ); |
|
| 4799 | - |
|
| 4800 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4801 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4802 | - } |
|
| 4803 | - |
|
| 4804 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4805 | - // ajouter la longueur au début des params supplémentaires |
|
| 4806 | - if ($demande_introduction) { |
|
| 4807 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4808 | - array_unshift($params, $introduction_longueur); |
|
| 4809 | - } |
|
| 4810 | - |
|
| 4811 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4812 | - if ( |
|
| 4813 | - $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4814 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4815 | - or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4816 | - ) { |
|
| 4817 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4818 | - } |
|
| 4819 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4820 | - elseif ( |
|
| 4821 | - $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4822 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4823 | - or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4824 | - ) { |
|
| 4825 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4826 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4827 | - else { |
|
| 4828 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4829 | - } |
|
| 4830 | - |
|
| 4831 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4832 | - if (!$etoile) { |
|
| 4833 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4834 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4835 | - $info_generee = appliquer_traitement_champ( |
|
| 4836 | - $info_generee, |
|
| 4837 | - $info, |
|
| 4838 | - table_objet($type_objet), |
|
| 4839 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4840 | - ); |
|
| 4841 | - } |
|
| 4842 | - |
|
| 4843 | - return $info_generee; |
|
| 4749 | + static $trouver_table = null; |
|
| 4750 | + static $objets; |
|
| 4751 | + |
|
| 4752 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4753 | + $id_objet = intval($id_objet); |
|
| 4754 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4755 | + return ''; |
|
| 4756 | + } |
|
| 4757 | + |
|
| 4758 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4759 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4760 | + return ''; |
|
| 4761 | + } |
|
| 4762 | + |
|
| 4763 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4764 | + if ($info == 'url') { |
|
| 4765 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4766 | + } |
|
| 4767 | + |
|
| 4768 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4769 | + $demande_titre = ($info === 'titre'); |
|
| 4770 | + $demande_introduction = ($info === 'introduction'); |
|
| 4771 | + |
|
| 4772 | + // 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 |
|
| 4773 | + if ( |
|
| 4774 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4775 | + or |
|
| 4776 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4777 | + ) { |
|
| 4778 | + if (!$trouver_table) { |
|
| 4779 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4780 | + } |
|
| 4781 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4782 | + if (!$desc) { |
|
| 4783 | + return $objets[$type_objet] = false; |
|
| 4784 | + } |
|
| 4785 | + |
|
| 4786 | + // Si on demande le titre, on le gere en interne |
|
| 4787 | + $champ_titre = ''; |
|
| 4788 | + if ($demande_titre) { |
|
| 4789 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4790 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4791 | + } |
|
| 4792 | + include_spip('base/abstract_sql'); |
|
| 4793 | + include_spip('base/connect_sql'); |
|
| 4794 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4795 | + '*' . $champ_titre, |
|
| 4796 | + $desc['table_sql'], |
|
| 4797 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4798 | + ); |
|
| 4799 | + |
|
| 4800 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4801 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4802 | + } |
|
| 4803 | + |
|
| 4804 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4805 | + // ajouter la longueur au début des params supplémentaires |
|
| 4806 | + if ($demande_introduction) { |
|
| 4807 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4808 | + array_unshift($params, $introduction_longueur); |
|
| 4809 | + } |
|
| 4810 | + |
|
| 4811 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4812 | + if ( |
|
| 4813 | + $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4814 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4815 | + or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4816 | + ) { |
|
| 4817 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4818 | + } |
|
| 4819 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4820 | + elseif ( |
|
| 4821 | + $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4822 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4823 | + or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4824 | + ) { |
|
| 4825 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4826 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4827 | + else { |
|
| 4828 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4829 | + } |
|
| 4830 | + |
|
| 4831 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4832 | + if (!$etoile) { |
|
| 4833 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4834 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4835 | + $info_generee = appliquer_traitement_champ( |
|
| 4836 | + $info_generee, |
|
| 4837 | + $info, |
|
| 4838 | + table_objet($type_objet), |
|
| 4839 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4840 | + ); |
|
| 4841 | + } |
|
| 4842 | + |
|
| 4843 | + return $info_generee; |
|
| 4844 | 4844 | } |
| 4845 | 4845 | |
| 4846 | 4846 | /** |
@@ -4848,7 +4848,7 @@ discard block |
||
| 4848 | 4848 | * @see generer_objet_info |
| 4849 | 4849 | */ |
| 4850 | 4850 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4851 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4851 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4852 | 4852 | } |
| 4853 | 4853 | |
| 4854 | 4854 | /** |
@@ -4881,36 +4881,36 @@ discard block |
||
| 4881 | 4881 | */ |
| 4882 | 4882 | 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 { |
| 4883 | 4883 | |
| 4884 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4885 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4886 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4887 | - if (isset($ligne_sql['chapo'])) { |
|
| 4888 | - $chapo = $ligne_sql['chapo']; |
|
| 4889 | - $texte = strlen($descriptif) ? |
|
| 4890 | - '' : |
|
| 4891 | - "$chapo \n\n $texte"; |
|
| 4892 | - } |
|
| 4884 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4885 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4886 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4887 | + if (isset($ligne_sql['chapo'])) { |
|
| 4888 | + $chapo = $ligne_sql['chapo']; |
|
| 4889 | + $texte = strlen($descriptif) ? |
|
| 4890 | + '' : |
|
| 4891 | + "$chapo \n\n $texte"; |
|
| 4892 | + } |
|
| 4893 | 4893 | |
| 4894 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4895 | - if (!intval($longueur_ou_suite)) { |
|
| 4896 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4897 | - } else { |
|
| 4898 | - $longueur = intval($longueur_ou_suite); |
|
| 4899 | - } |
|
| 4894 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4895 | + if (!intval($longueur_ou_suite)) { |
|
| 4896 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4897 | + } else { |
|
| 4898 | + $longueur = intval($longueur_ou_suite); |
|
| 4899 | + } |
|
| 4900 | 4900 | |
| 4901 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4902 | - // Ex : #INTRODUCTION{...} |
|
| 4903 | - if ( |
|
| 4904 | - is_null($suite) |
|
| 4905 | - and !intval($longueur_ou_suite) |
|
| 4906 | - ) { |
|
| 4907 | - $suite = $longueur_ou_suite; |
|
| 4908 | - } |
|
| 4901 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4902 | + // Ex : #INTRODUCTION{...} |
|
| 4903 | + if ( |
|
| 4904 | + is_null($suite) |
|
| 4905 | + and !intval($longueur_ou_suite) |
|
| 4906 | + ) { |
|
| 4907 | + $suite = $longueur_ou_suite; |
|
| 4908 | + } |
|
| 4909 | 4909 | |
| 4910 | - $f = chercher_filtre('introduction'); |
|
| 4911 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4910 | + $f = chercher_filtre('introduction'); |
|
| 4911 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4912 | 4912 | |
| 4913 | - return $introduction; |
|
| 4913 | + return $introduction; |
|
| 4914 | 4914 | } |
| 4915 | 4915 | |
| 4916 | 4916 | /** |
@@ -4918,7 +4918,7 @@ discard block |
||
| 4918 | 4918 | * @see generer_objet_introduction |
| 4919 | 4919 | */ |
| 4920 | 4920 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4921 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4921 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4922 | 4922 | } |
| 4923 | 4923 | |
| 4924 | 4924 | /** |
@@ -4932,44 +4932,44 @@ discard block |
||
| 4932 | 4932 | * @return string |
| 4933 | 4933 | */ |
| 4934 | 4934 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4935 | - if (!$champ) { |
|
| 4936 | - return $texte; |
|
| 4937 | - } |
|
| 4935 | + if (!$champ) { |
|
| 4936 | + return $texte; |
|
| 4937 | + } |
|
| 4938 | 4938 | |
| 4939 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4940 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4941 | - include_fichiers_fonctions(); |
|
| 4939 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4940 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4941 | + include_fichiers_fonctions(); |
|
| 4942 | 4942 | |
| 4943 | - $champ = strtoupper($champ); |
|
| 4944 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4945 | - if (!$traitements or !is_array($traitements)) { |
|
| 4946 | - return $texte; |
|
| 4947 | - } |
|
| 4943 | + $champ = strtoupper($champ); |
|
| 4944 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4945 | + if (!$traitements or !is_array($traitements)) { |
|
| 4946 | + return $texte; |
|
| 4947 | + } |
|
| 4948 | 4948 | |
| 4949 | - $traitement = ''; |
|
| 4950 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4951 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4952 | - $table_objet = table_objet($table_objet); |
|
| 4953 | - if (isset($traitements[$table_objet])) { |
|
| 4954 | - $traitement = $traitements[$table_objet]; |
|
| 4955 | - } |
|
| 4956 | - } |
|
| 4957 | - if (!$traitement and isset($traitements[0])) { |
|
| 4958 | - $traitement = $traitements[0]; |
|
| 4959 | - } |
|
| 4960 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4949 | + $traitement = ''; |
|
| 4950 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4951 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4952 | + $table_objet = table_objet($table_objet); |
|
| 4953 | + if (isset($traitements[$table_objet])) { |
|
| 4954 | + $traitement = $traitements[$table_objet]; |
|
| 4955 | + } |
|
| 4956 | + } |
|
| 4957 | + if (!$traitement and isset($traitements[0])) { |
|
| 4958 | + $traitement = $traitements[0]; |
|
| 4959 | + } |
|
| 4960 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4961 | 4961 | |
| 4962 | - if (!$traitement) { |
|
| 4963 | - return $texte; |
|
| 4964 | - } |
|
| 4962 | + if (!$traitement) { |
|
| 4963 | + return $texte; |
|
| 4964 | + } |
|
| 4965 | 4965 | |
| 4966 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4966 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4967 | 4967 | |
| 4968 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4969 | - $Pile = [0 => $env]; |
|
| 4970 | - eval("\$texte = $traitement;"); |
|
| 4968 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4969 | + $Pile = [0 => $env]; |
|
| 4970 | + eval("\$texte = $traitement;"); |
|
| 4971 | 4971 | |
| 4972 | - return $texte; |
|
| 4972 | + return $texte; |
|
| 4973 | 4973 | } |
| 4974 | 4974 | |
| 4975 | 4975 | |
@@ -4983,21 +4983,21 @@ discard block |
||
| 4983 | 4983 | * @return string |
| 4984 | 4984 | */ |
| 4985 | 4985 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4986 | - include_spip('inc/liens'); |
|
| 4987 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4988 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4989 | - // le raccourcis n'est plus valide |
|
| 4990 | - $titre = typo($titre['titre']) ?? ''; |
|
| 4991 | - // on essaye avec generer_info_entite ? |
|
| 4992 | - if (!strlen($titre) and !$connect) { |
|
| 4993 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4994 | - } |
|
| 4995 | - if (!strlen($titre)) { |
|
| 4996 | - $titre = _T('info_sans_titre'); |
|
| 4997 | - } |
|
| 4998 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4986 | + include_spip('inc/liens'); |
|
| 4987 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4988 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4989 | + // le raccourcis n'est plus valide |
|
| 4990 | + $titre = typo($titre['titre']) ?? ''; |
|
| 4991 | + // on essaye avec generer_info_entite ? |
|
| 4992 | + if (!strlen($titre) and !$connect) { |
|
| 4993 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4994 | + } |
|
| 4995 | + if (!strlen($titre)) { |
|
| 4996 | + $titre = _T('info_sans_titre'); |
|
| 4997 | + } |
|
| 4998 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4999 | 4999 | |
| 5000 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 5000 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 5001 | 5001 | } |
| 5002 | 5002 | |
| 5003 | 5003 | /** |
@@ -5005,7 +5005,7 @@ discard block |
||
| 5005 | 5005 | * @see generer_objet_lien |
| 5006 | 5006 | */ |
| 5007 | 5007 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 5008 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5008 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5009 | 5009 | } |
| 5010 | 5010 | |
| 5011 | 5011 | /** |
@@ -5021,15 +5021,15 @@ discard block |
||
| 5021 | 5021 | * @return string |
| 5022 | 5022 | */ |
| 5023 | 5023 | function wrap($texte, $wrap) { |
| 5024 | - $balises = extraire_balises($wrap); |
|
| 5025 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5026 | - $texte = $wrap . $texte; |
|
| 5027 | - $regs = array_reverse($regs[1]); |
|
| 5028 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5029 | - $texte = $texte . $wrap; |
|
| 5030 | - } |
|
| 5024 | + $balises = extraire_balises($wrap); |
|
| 5025 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5026 | + $texte = $wrap . $texte; |
|
| 5027 | + $regs = array_reverse($regs[1]); |
|
| 5028 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5029 | + $texte = $texte . $wrap; |
|
| 5030 | + } |
|
| 5031 | 5031 | |
| 5032 | - return $texte; |
|
| 5032 | + return $texte; |
|
| 5033 | 5033 | } |
| 5034 | 5034 | |
| 5035 | 5035 | |
@@ -5049,44 +5049,44 @@ discard block |
||
| 5049 | 5049 | * @return array|mixed|string |
| 5050 | 5050 | */ |
| 5051 | 5051 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 5052 | - if (is_string($u)) { |
|
| 5053 | - $u = typo($u); |
|
| 5052 | + if (is_string($u)) { |
|
| 5053 | + $u = typo($u); |
|
| 5054 | 5054 | |
| 5055 | - return $u; |
|
| 5056 | - } |
|
| 5055 | + return $u; |
|
| 5056 | + } |
|
| 5057 | 5057 | |
| 5058 | - // caster $u en array si besoin |
|
| 5059 | - if (is_object($u)) { |
|
| 5060 | - $u = (array)$u; |
|
| 5061 | - } |
|
| 5058 | + // caster $u en array si besoin |
|
| 5059 | + if (is_object($u)) { |
|
| 5060 | + $u = (array)$u; |
|
| 5061 | + } |
|
| 5062 | 5062 | |
| 5063 | - if (is_array($u)) { |
|
| 5064 | - $out = ''; |
|
| 5065 | - // toutes les cles sont numeriques ? |
|
| 5066 | - // et aucun enfant n'est un tableau |
|
| 5067 | - // liste simple separee par des virgules |
|
| 5068 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5069 | - $array_values = array_map('is_array', $u); |
|
| 5070 | - $object_values = array_map('is_object', $u); |
|
| 5071 | - if ( |
|
| 5072 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 5073 | - and !array_sum($array_values) |
|
| 5074 | - and !array_sum($object_values) |
|
| 5075 | - ) { |
|
| 5076 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5077 | - } |
|
| 5063 | + if (is_array($u)) { |
|
| 5064 | + $out = ''; |
|
| 5065 | + // toutes les cles sont numeriques ? |
|
| 5066 | + // et aucun enfant n'est un tableau |
|
| 5067 | + // liste simple separee par des virgules |
|
| 5068 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5069 | + $array_values = array_map('is_array', $u); |
|
| 5070 | + $object_values = array_map('is_object', $u); |
|
| 5071 | + if ( |
|
| 5072 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 5073 | + and !array_sum($array_values) |
|
| 5074 | + and !array_sum($object_values) |
|
| 5075 | + ) { |
|
| 5076 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5077 | + } |
|
| 5078 | 5078 | |
| 5079 | - // sinon on passe a la ligne et on indente |
|
| 5080 | - $i_str = str_pad('', $indent, ' '); |
|
| 5081 | - foreach ($u as $k => $v) { |
|
| 5082 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5083 | - } |
|
| 5079 | + // sinon on passe a la ligne et on indente |
|
| 5080 | + $i_str = str_pad('', $indent, ' '); |
|
| 5081 | + foreach ($u as $k => $v) { |
|
| 5082 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5083 | + } |
|
| 5084 | 5084 | |
| 5085 | - return $out; |
|
| 5086 | - } |
|
| 5085 | + return $out; |
|
| 5086 | + } |
|
| 5087 | 5087 | |
| 5088 | - // on sait pas quoi faire... |
|
| 5089 | - return $u; |
|
| 5088 | + // on sait pas quoi faire... |
|
| 5089 | + return $u; |
|
| 5090 | 5090 | } |
| 5091 | 5091 | |
| 5092 | 5092 | |
@@ -5099,10 +5099,10 @@ discard block |
||
| 5099 | 5099 | * @return string|array |
| 5100 | 5100 | */ |
| 5101 | 5101 | function objet_info($objet, $info) { |
| 5102 | - $table = table_objet_sql($objet); |
|
| 5103 | - $infos = lister_tables_objets_sql($table); |
|
| 5102 | + $table = table_objet_sql($objet); |
|
| 5103 | + $infos = lister_tables_objets_sql($table); |
|
| 5104 | 5104 | |
| 5105 | - return ($infos[$info] ?? ''); |
|
| 5105 | + return ($infos[$info] ?? ''); |
|
| 5106 | 5106 | } |
| 5107 | 5107 | |
| 5108 | 5108 | /** |
@@ -5117,11 +5117,11 @@ discard block |
||
| 5117 | 5117 | * Texte traduit du comptage, tel que '3 articles' |
| 5118 | 5118 | */ |
| 5119 | 5119 | function objet_afficher_nb($nb, $objet) { |
| 5120 | - if (!$nb) { |
|
| 5121 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5122 | - } else { |
|
| 5123 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5124 | - } |
|
| 5120 | + if (!$nb) { |
|
| 5121 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5122 | + } else { |
|
| 5123 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5124 | + } |
|
| 5125 | 5125 | } |
| 5126 | 5126 | |
| 5127 | 5127 | /** |
@@ -5133,11 +5133,11 @@ discard block |
||
| 5133 | 5133 | * @return string |
| 5134 | 5134 | */ |
| 5135 | 5135 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5136 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5137 | - $icone = chemin_image($icone); |
|
| 5138 | - $balise_img = charger_filtre('balise_img'); |
|
| 5136 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5137 | + $icone = chemin_image($icone); |
|
| 5138 | + $balise_img = charger_filtre('balise_img'); |
|
| 5139 | 5139 | |
| 5140 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5140 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5141 | 5141 | } |
| 5142 | 5142 | |
| 5143 | 5143 | /** |
@@ -5158,12 +5158,12 @@ discard block |
||
| 5158 | 5158 | * @return string |
| 5159 | 5159 | */ |
| 5160 | 5160 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5161 | - $chaine = explode(':', $chaine); |
|
| 5162 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5163 | - return $t; |
|
| 5164 | - } |
|
| 5165 | - $chaine = implode(':', $chaine); |
|
| 5166 | - return _T($chaine, $args, $options); |
|
| 5161 | + $chaine = explode(':', $chaine); |
|
| 5162 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5163 | + return $t; |
|
| 5164 | + } |
|
| 5165 | + $chaine = implode(':', $chaine); |
|
| 5166 | + return _T($chaine, $args, $options); |
|
| 5167 | 5167 | } |
| 5168 | 5168 | |
| 5169 | 5169 | /** |
@@ -5177,18 +5177,18 @@ discard block |
||
| 5177 | 5177 | * @return string Code HTML |
| 5178 | 5178 | */ |
| 5179 | 5179 | function insert_head_css_conditionnel($flux) { |
| 5180 | - if ( |
|
| 5181 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5182 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5183 | - ) { |
|
| 5184 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5185 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5186 | - $p = $p1; |
|
| 5187 | - } |
|
| 5188 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5189 | - } |
|
| 5180 | + if ( |
|
| 5181 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5182 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5183 | + ) { |
|
| 5184 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5185 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5186 | + $p = $p1; |
|
| 5187 | + } |
|
| 5188 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5189 | + } |
|
| 5190 | 5190 | |
| 5191 | - return $flux; |
|
| 5191 | + return $flux; |
|
| 5192 | 5192 | } |
| 5193 | 5193 | |
| 5194 | 5194 | /** |
@@ -5211,72 +5211,72 @@ discard block |
||
| 5211 | 5211 | * @return string |
| 5212 | 5212 | */ |
| 5213 | 5213 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5214 | - if (isset($contexte['format'])) { |
|
| 5215 | - $extension = $contexte['format']; |
|
| 5216 | - unset($contexte['format']); |
|
| 5217 | - } else { |
|
| 5218 | - $extension = 'html'; |
|
| 5219 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5220 | - $extension = $m[1]; |
|
| 5221 | - } |
|
| 5222 | - } |
|
| 5223 | - // recuperer le contenu produit par le squelette |
|
| 5224 | - $options['raw'] = true; |
|
| 5225 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5226 | - |
|
| 5227 | - // calculer le nom de la css |
|
| 5228 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5229 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5230 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5231 | - |
|
| 5232 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5233 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5234 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5235 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5236 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5237 | - } |
|
| 5238 | - else { |
|
| 5239 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5240 | - ksort($contexte); |
|
| 5241 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5242 | - } |
|
| 5243 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5244 | - |
|
| 5245 | - // mettre a jour le fichier si il n'existe pas |
|
| 5246 | - // ou trop ancien |
|
| 5247 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5248 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5249 | - if ( |
|
| 5250 | - !file_exists($filename) |
|
| 5251 | - or !file_exists($filename . '.last') |
|
| 5252 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5253 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5254 | - ) { |
|
| 5255 | - $contenu = $cache['texte']; |
|
| 5256 | - // passer les urls en absolu si c'est une css |
|
| 5257 | - if ($extension == 'css') { |
|
| 5258 | - $contenu = urls_absolues_css( |
|
| 5259 | - $contenu, |
|
| 5260 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5261 | - ); |
|
| 5262 | - } |
|
| 5263 | - |
|
| 5264 | - $comment = ''; |
|
| 5265 | - // ne pas insérer de commentaire sur certains formats |
|
| 5266 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5267 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5268 | - foreach ($contexte as $k => $v) { |
|
| 5269 | - $comment .= ",$k=$v"; |
|
| 5270 | - } |
|
| 5271 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5272 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5273 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5274 | - } |
|
| 5275 | - // et ecrire le fichier si il change |
|
| 5276 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5277 | - } |
|
| 5278 | - |
|
| 5279 | - return timestamp($filename); |
|
| 5214 | + if (isset($contexte['format'])) { |
|
| 5215 | + $extension = $contexte['format']; |
|
| 5216 | + unset($contexte['format']); |
|
| 5217 | + } else { |
|
| 5218 | + $extension = 'html'; |
|
| 5219 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5220 | + $extension = $m[1]; |
|
| 5221 | + } |
|
| 5222 | + } |
|
| 5223 | + // recuperer le contenu produit par le squelette |
|
| 5224 | + $options['raw'] = true; |
|
| 5225 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5226 | + |
|
| 5227 | + // calculer le nom de la css |
|
| 5228 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5229 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5230 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5231 | + |
|
| 5232 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5233 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5234 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5235 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5236 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5237 | + } |
|
| 5238 | + else { |
|
| 5239 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5240 | + ksort($contexte); |
|
| 5241 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5242 | + } |
|
| 5243 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5244 | + |
|
| 5245 | + // mettre a jour le fichier si il n'existe pas |
|
| 5246 | + // ou trop ancien |
|
| 5247 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5248 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5249 | + if ( |
|
| 5250 | + !file_exists($filename) |
|
| 5251 | + or !file_exists($filename . '.last') |
|
| 5252 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5253 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5254 | + ) { |
|
| 5255 | + $contenu = $cache['texte']; |
|
| 5256 | + // passer les urls en absolu si c'est une css |
|
| 5257 | + if ($extension == 'css') { |
|
| 5258 | + $contenu = urls_absolues_css( |
|
| 5259 | + $contenu, |
|
| 5260 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5261 | + ); |
|
| 5262 | + } |
|
| 5263 | + |
|
| 5264 | + $comment = ''; |
|
| 5265 | + // ne pas insérer de commentaire sur certains formats |
|
| 5266 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5267 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5268 | + foreach ($contexte as $k => $v) { |
|
| 5269 | + $comment .= ",$k=$v"; |
|
| 5270 | + } |
|
| 5271 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5272 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5273 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5274 | + } |
|
| 5275 | + // et ecrire le fichier si il change |
|
| 5276 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5277 | + } |
|
| 5278 | + |
|
| 5279 | + return timestamp($filename); |
|
| 5280 | 5280 | } |
| 5281 | 5281 | |
| 5282 | 5282 | /** |
@@ -5289,15 +5289,15 @@ discard block |
||
| 5289 | 5289 | * $fichier auquel on a ajouté le timestamp |
| 5290 | 5290 | */ |
| 5291 | 5291 | function timestamp($fichier) { |
| 5292 | - if ( |
|
| 5293 | - !$fichier |
|
| 5294 | - or !file_exists($fichier) |
|
| 5295 | - or !$m = filemtime($fichier) |
|
| 5296 | - ) { |
|
| 5297 | - return $fichier; |
|
| 5298 | - } |
|
| 5292 | + if ( |
|
| 5293 | + !$fichier |
|
| 5294 | + or !file_exists($fichier) |
|
| 5295 | + or !$m = filemtime($fichier) |
|
| 5296 | + ) { |
|
| 5297 | + return $fichier; |
|
| 5298 | + } |
|
| 5299 | 5299 | |
| 5300 | - return "$fichier?$m"; |
|
| 5300 | + return "$fichier?$m"; |
|
| 5301 | 5301 | } |
| 5302 | 5302 | |
| 5303 | 5303 | /** |
@@ -5307,11 +5307,11 @@ discard block |
||
| 5307 | 5307 | * @return string |
| 5308 | 5308 | */ |
| 5309 | 5309 | function supprimer_timestamp($url) { |
| 5310 | - if (strpos($url, '?') === false) { |
|
| 5311 | - return $url; |
|
| 5312 | - } |
|
| 5310 | + if (strpos($url, '?') === false) { |
|
| 5311 | + return $url; |
|
| 5312 | + } |
|
| 5313 | 5313 | |
| 5314 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5314 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5315 | 5315 | } |
| 5316 | 5316 | |
| 5317 | 5317 | /** |
@@ -5326,9 +5326,9 @@ discard block |
||
| 5326 | 5326 | * @return string |
| 5327 | 5327 | */ |
| 5328 | 5328 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5329 | - include_spip('inc/envoyer_mail'); |
|
| 5329 | + include_spip('inc/envoyer_mail'); |
|
| 5330 | 5330 | |
| 5331 | - return nettoyer_titre_email($titre); |
|
| 5331 | + return nettoyer_titre_email($titre); |
|
| 5332 | 5332 | } |
| 5333 | 5333 | |
| 5334 | 5334 | /** |
@@ -5350,27 +5350,27 @@ discard block |
||
| 5350 | 5350 | * @return string |
| 5351 | 5351 | */ |
| 5352 | 5352 | function filtre_chercher_rubrique_dist( |
| 5353 | - $titre, |
|
| 5354 | - $id_objet, |
|
| 5355 | - $id_parent, |
|
| 5356 | - $objet, |
|
| 5357 | - $id_secteur, |
|
| 5358 | - $restreint, |
|
| 5359 | - $actionable = false, |
|
| 5360 | - $retour_sans_cadre = false |
|
| 5353 | + $titre, |
|
| 5354 | + $id_objet, |
|
| 5355 | + $id_parent, |
|
| 5356 | + $objet, |
|
| 5357 | + $id_secteur, |
|
| 5358 | + $restreint, |
|
| 5359 | + $actionable = false, |
|
| 5360 | + $retour_sans_cadre = false |
|
| 5361 | 5361 | ) { |
| 5362 | - include_spip('inc/filtres_ecrire'); |
|
| 5362 | + include_spip('inc/filtres_ecrire'); |
|
| 5363 | 5363 | |
| 5364 | - return chercher_rubrique( |
|
| 5365 | - $titre, |
|
| 5366 | - $id_objet, |
|
| 5367 | - $id_parent, |
|
| 5368 | - $objet, |
|
| 5369 | - $id_secteur, |
|
| 5370 | - $restreint, |
|
| 5371 | - $actionable, |
|
| 5372 | - $retour_sans_cadre |
|
| 5373 | - ); |
|
| 5364 | + return chercher_rubrique( |
|
| 5365 | + $titre, |
|
| 5366 | + $id_objet, |
|
| 5367 | + $id_parent, |
|
| 5368 | + $objet, |
|
| 5369 | + $id_secteur, |
|
| 5370 | + $restreint, |
|
| 5371 | + $actionable, |
|
| 5372 | + $retour_sans_cadre |
|
| 5373 | + ); |
|
| 5374 | 5374 | } |
| 5375 | 5375 | |
| 5376 | 5376 | /** |
@@ -5399,56 +5399,56 @@ discard block |
||
| 5399 | 5399 | * Chaîne vide si l'accès est autorisé |
| 5400 | 5400 | */ |
| 5401 | 5401 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5402 | - if ($ok) { |
|
| 5403 | - return ''; |
|
| 5404 | - } |
|
| 5405 | - |
|
| 5406 | - // Vider tous les tampons |
|
| 5407 | - $level = @ob_get_level(); |
|
| 5408 | - while ($level--) { |
|
| 5409 | - @ob_end_clean(); |
|
| 5410 | - } |
|
| 5411 | - |
|
| 5412 | - include_spip('inc/headers'); |
|
| 5413 | - |
|
| 5414 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5415 | - if ($url) { |
|
| 5416 | - redirige_par_entete($url, '', $statut); |
|
| 5417 | - } |
|
| 5418 | - |
|
| 5419 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5420 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5421 | - $message = $statut; |
|
| 5422 | - $statut = 0; |
|
| 5423 | - } |
|
| 5424 | - if (!$message) { |
|
| 5425 | - $message = ''; |
|
| 5426 | - } |
|
| 5427 | - $statut = intval($statut); |
|
| 5428 | - |
|
| 5429 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5430 | - if (test_espace_prive()) { |
|
| 5431 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5432 | - $statut = 403; |
|
| 5433 | - } |
|
| 5434 | - http_response_code(403); |
|
| 5435 | - $echec = charger_fonction('403', 'exec'); |
|
| 5436 | - $echec($message); |
|
| 5437 | - } else { |
|
| 5438 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5439 | - if (!$statut) { |
|
| 5440 | - $statut = 404; |
|
| 5441 | - } |
|
| 5442 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5443 | - http_response_code($statut); |
|
| 5444 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5445 | - if ($statut >= 400) { |
|
| 5446 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5447 | - } |
|
| 5448 | - } |
|
| 5449 | - |
|
| 5450 | - |
|
| 5451 | - exit; |
|
| 5402 | + if ($ok) { |
|
| 5403 | + return ''; |
|
| 5404 | + } |
|
| 5405 | + |
|
| 5406 | + // Vider tous les tampons |
|
| 5407 | + $level = @ob_get_level(); |
|
| 5408 | + while ($level--) { |
|
| 5409 | + @ob_end_clean(); |
|
| 5410 | + } |
|
| 5411 | + |
|
| 5412 | + include_spip('inc/headers'); |
|
| 5413 | + |
|
| 5414 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5415 | + if ($url) { |
|
| 5416 | + redirige_par_entete($url, '', $statut); |
|
| 5417 | + } |
|
| 5418 | + |
|
| 5419 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5420 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5421 | + $message = $statut; |
|
| 5422 | + $statut = 0; |
|
| 5423 | + } |
|
| 5424 | + if (!$message) { |
|
| 5425 | + $message = ''; |
|
| 5426 | + } |
|
| 5427 | + $statut = intval($statut); |
|
| 5428 | + |
|
| 5429 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5430 | + if (test_espace_prive()) { |
|
| 5431 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5432 | + $statut = 403; |
|
| 5433 | + } |
|
| 5434 | + http_response_code(403); |
|
| 5435 | + $echec = charger_fonction('403', 'exec'); |
|
| 5436 | + $echec($message); |
|
| 5437 | + } else { |
|
| 5438 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5439 | + if (!$statut) { |
|
| 5440 | + $statut = 404; |
|
| 5441 | + } |
|
| 5442 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5443 | + http_response_code($statut); |
|
| 5444 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5445 | + if ($statut >= 400) { |
|
| 5446 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5447 | + } |
|
| 5448 | + } |
|
| 5449 | + |
|
| 5450 | + |
|
| 5451 | + exit; |
|
| 5452 | 5452 | } |
| 5453 | 5453 | |
| 5454 | 5454 | /** |
@@ -5459,11 +5459,11 @@ discard block |
||
| 5459 | 5459 | * @return string |
| 5460 | 5460 | */ |
| 5461 | 5461 | function filtre_compacte_dist($source, $format = null) { |
| 5462 | - if (function_exists('minifier')) { |
|
| 5463 | - return minifier($source, $format); |
|
| 5464 | - } |
|
| 5462 | + if (function_exists('minifier')) { |
|
| 5463 | + return minifier($source, $format); |
|
| 5464 | + } |
|
| 5465 | 5465 | |
| 5466 | - return $source; |
|
| 5466 | + return $source; |
|
| 5467 | 5467 | } |
| 5468 | 5468 | |
| 5469 | 5469 | |
@@ -5475,31 +5475,31 @@ discard block |
||
| 5475 | 5475 | * @return string |
| 5476 | 5476 | */ |
| 5477 | 5477 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 5478 | - $l = strlen($passe); |
|
| 5479 | - |
|
| 5480 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5481 | - if (!$l) { |
|
| 5482 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5483 | - } |
|
| 5484 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5485 | - } |
|
| 5486 | - |
|
| 5487 | - if (is_null($portion_pourcent)) { |
|
| 5488 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5489 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5490 | - } |
|
| 5491 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5492 | - } |
|
| 5493 | - if ($portion_pourcent >= 100) { |
|
| 5494 | - return $passe; |
|
| 5495 | - } |
|
| 5496 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5497 | - $e = max($e, 0); |
|
| 5498 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5499 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5500 | - $mid = '***...***'; |
|
| 5501 | - } |
|
| 5502 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5478 | + $l = strlen($passe); |
|
| 5479 | + |
|
| 5480 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5481 | + if (!$l) { |
|
| 5482 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5483 | + } |
|
| 5484 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5485 | + } |
|
| 5486 | + |
|
| 5487 | + if (is_null($portion_pourcent)) { |
|
| 5488 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5489 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5490 | + } |
|
| 5491 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5492 | + } |
|
| 5493 | + if ($portion_pourcent >= 100) { |
|
| 5494 | + return $passe; |
|
| 5495 | + } |
|
| 5496 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5497 | + $e = max($e, 0); |
|
| 5498 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5499 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5500 | + $mid = '***...***'; |
|
| 5501 | + } |
|
| 5502 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5503 | 5503 | } |
| 5504 | 5504 | |
| 5505 | 5505 | |
@@ -5520,64 +5520,64 @@ discard block |
||
| 5520 | 5520 | */ |
| 5521 | 5521 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5522 | 5522 | |
| 5523 | - $original = $texte; |
|
| 5524 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5525 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5526 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5523 | + $original = $texte; |
|
| 5524 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5525 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5526 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5527 | 5527 | |
| 5528 | - if (!function_exists('translitteration')) { |
|
| 5529 | - include_spip('inc/charsets'); |
|
| 5530 | - } |
|
| 5528 | + if (!function_exists('translitteration')) { |
|
| 5529 | + include_spip('inc/charsets'); |
|
| 5530 | + } |
|
| 5531 | 5531 | |
| 5532 | - // pas de balise html |
|
| 5533 | - if (strpos($texte, '<') !== false) { |
|
| 5534 | - $texte = strip_tags($texte); |
|
| 5535 | - } |
|
| 5536 | - if (strpos($texte, '&') !== false) { |
|
| 5537 | - $texte = unicode2charset($texte); |
|
| 5538 | - } |
|
| 5539 | - // On enlève les espaces indésirables |
|
| 5540 | - $texte = trim($texte); |
|
| 5532 | + // pas de balise html |
|
| 5533 | + if (strpos($texte, '<') !== false) { |
|
| 5534 | + $texte = strip_tags($texte); |
|
| 5535 | + } |
|
| 5536 | + if (strpos($texte, '&') !== false) { |
|
| 5537 | + $texte = unicode2charset($texte); |
|
| 5538 | + } |
|
| 5539 | + // On enlève les espaces indésirables |
|
| 5540 | + $texte = trim($texte); |
|
| 5541 | 5541 | |
| 5542 | - // On enlève les accents et cie |
|
| 5543 | - $texte = translitteration($texte); |
|
| 5542 | + // On enlève les accents et cie |
|
| 5543 | + $texte = translitteration($texte); |
|
| 5544 | 5544 | |
| 5545 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5546 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5545 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5546 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5547 | 5547 | |
| 5548 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5549 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5550 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5551 | - } |
|
| 5548 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5549 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5550 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5551 | + } |
|
| 5552 | 5552 | |
| 5553 | - // pas de separateur au debut ni a la fin |
|
| 5554 | - $texte = trim($texte, $separateur); |
|
| 5553 | + // pas de separateur au debut ni a la fin |
|
| 5554 | + $texte = trim($texte, $separateur); |
|
| 5555 | 5555 | |
| 5556 | - // en minuscules |
|
| 5557 | - $texte = strtolower($texte); |
|
| 5556 | + // en minuscules |
|
| 5557 | + $texte = strtolower($texte); |
|
| 5558 | 5558 | |
| 5559 | - switch ($type) { |
|
| 5560 | - case 'class': |
|
| 5561 | - case 'id': |
|
| 5562 | - case 'anchor': |
|
| 5563 | - if (preg_match(',^\d,', $texte)) { |
|
| 5564 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5565 | - } |
|
| 5566 | - } |
|
| 5559 | + switch ($type) { |
|
| 5560 | + case 'class': |
|
| 5561 | + case 'id': |
|
| 5562 | + case 'anchor': |
|
| 5563 | + if (preg_match(',^\d,', $texte)) { |
|
| 5564 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5565 | + } |
|
| 5566 | + } |
|
| 5567 | 5567 | |
| 5568 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5569 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5570 | - } |
|
| 5568 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5569 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5570 | + } |
|
| 5571 | 5571 | |
| 5572 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5573 | - if (preg_match(',^\d,', $texte)) { |
|
| 5574 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5575 | - } |
|
| 5576 | - $texte .= $separateur . md5($original); |
|
| 5577 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5578 | - } |
|
| 5572 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5573 | + if (preg_match(',^\d,', $texte)) { |
|
| 5574 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5575 | + } |
|
| 5576 | + $texte .= $separateur . md5($original); |
|
| 5577 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5578 | + } |
|
| 5579 | 5579 | |
| 5580 | - return $texte; |
|
| 5580 | + return $texte; |
|
| 5581 | 5581 | } |
| 5582 | 5582 | |
| 5583 | 5583 | |
@@ -5598,11 +5598,11 @@ discard block |
||
| 5598 | 5598 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5599 | 5599 | */ |
| 5600 | 5600 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5601 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5602 | - if ($ucfirst) { |
|
| 5603 | - $label = spip_ucfirst($label); |
|
| 5604 | - } |
|
| 5605 | - return $label; |
|
| 5601 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5602 | + if ($ucfirst) { |
|
| 5603 | + $label = spip_ucfirst($label); |
|
| 5604 | + } |
|
| 5605 | + return $label; |
|
| 5606 | 5606 | } |
| 5607 | 5607 | |
| 5608 | 5608 | /** |
@@ -5615,8 +5615,8 @@ discard block |
||
| 5615 | 5615 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5616 | 5616 | */ |
| 5617 | 5617 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5618 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5619 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5618 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5619 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5620 | 5620 | } |
| 5621 | 5621 | |
| 5622 | 5622 | |
@@ -5629,19 +5629,19 @@ discard block |
||
| 5629 | 5629 | * @return array |
| 5630 | 5630 | */ |
| 5631 | 5631 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5632 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5633 | - return []; |
|
| 5634 | - } |
|
| 5632 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5633 | + return []; |
|
| 5634 | + } |
|
| 5635 | 5635 | |
| 5636 | - // compatibilite signature inversee |
|
| 5637 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5638 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5639 | - } |
|
| 5636 | + // compatibilite signature inversee |
|
| 5637 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5638 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5639 | + } |
|
| 5640 | 5640 | |
| 5641 | - if (!function_exists($fonction)) { |
|
| 5642 | - include_spip('base/objets'); |
|
| 5643 | - } |
|
| 5644 | - return $fonction($objet, $id_objet); |
|
| 5641 | + if (!function_exists($fonction)) { |
|
| 5642 | + include_spip('base/objets'); |
|
| 5643 | + } |
|
| 5644 | + return $fonction($objet, $id_objet); |
|
| 5645 | 5645 | } |
| 5646 | 5646 | |
| 5647 | 5647 | |
@@ -5656,7 +5656,7 @@ discard block |
||
| 5656 | 5656 | * @return array |
| 5657 | 5657 | */ |
| 5658 | 5658 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5659 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5659 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5660 | 5660 | } |
| 5661 | 5661 | |
| 5662 | 5662 | /** |
@@ -5670,7 +5670,7 @@ discard block |
||
| 5670 | 5670 | * @return array |
| 5671 | 5671 | */ |
| 5672 | 5672 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5673 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5673 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5674 | 5674 | } |
| 5675 | 5675 | |
| 5676 | 5676 | /** |
@@ -5684,7 +5684,7 @@ discard block |
||
| 5684 | 5684 | * @return array |
| 5685 | 5685 | */ |
| 5686 | 5686 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5687 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5687 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5688 | 5688 | } |
| 5689 | 5689 | |
| 5690 | 5690 | /** |
@@ -5698,5 +5698,5 @@ discard block |
||
| 5698 | 5698 | * @return array |
| 5699 | 5699 | */ |
| 5700 | 5700 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5701 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5701 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5702 | 5702 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | include_fichiers_fonctions(); |
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) { |
|
| 100 | 100 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 101 | 101 | // fonction ou name\space\fonction |
| 102 | 102 | if (is_callable($f)) { |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | // affichage "GIT [master: abcdef]" |
| 240 | 240 | $commit = $desc['commit_short'] ?? $desc['commit']; |
| 241 | 241 | if ($desc['branch']) { |
| 242 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 242 | + $commit = $desc['branch'].': '.$commit; |
|
| 243 | 243 | } |
| 244 | 244 | return "{$desc['vcs']} [$commit]"; |
| 245 | 245 | } |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // version installee par GIT |
| 261 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 261 | + if (lire_fichier($dir.'/.git/HEAD', $c)) { |
|
| 262 | 262 | $currentHead = trim(substr($c, 4)); |
| 263 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 263 | + if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) { |
|
| 264 | 264 | return [ |
| 265 | 265 | 'vcs' => 'GIT', |
| 266 | 266 | 'branch' => basename($currentHead), |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | $dir = '.'; |
| 288 | 288 | } |
| 289 | 289 | // version installee par SVN |
| 290 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 290 | + if (file_exists($dir.'/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | + $db = new SQLite3($dir.'/.svn/wc.db'); |
|
| 292 | 292 | $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
| 293 | 293 | if ($result) { |
| 294 | 294 | $row = $result->fetchArray(); |
@@ -306,12 +306,12 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 308 | 308 | // et laisser passer les fonctions personnelles baptisees image_... |
| 309 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 310 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 311 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 312 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 313 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 314 | -$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php'; |
|
| 309 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 310 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 311 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 312 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 313 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 314 | +$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php'; |
|
| 315 | 315 | |
| 316 | 316 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 317 | 317 | $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php'; |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | */ |
| 471 | 471 | function filtre_debug($val, $key = null) { |
| 472 | 472 | $debug = ( |
| 473 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | - ) . var_export($val, true); |
|
| 473 | + is_null($key) ? '' : (var_export($key, true).' = ') |
|
| 474 | + ).var_export($val, true); |
|
| 475 | 475 | |
| 476 | 476 | include_spip('inc/autoriser'); |
| 477 | 477 | if (autoriser('webmestre')) { |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | $is_file = false; |
| 526 | 526 | } |
| 527 | 527 | if ($is_file) { |
| 528 | - $is_local_file = function ($path) { |
|
| 528 | + $is_local_file = function($path) { |
|
| 529 | 529 | if (strpos($path, '?') !== false) { |
| 530 | 530 | $path = supprimer_timestamp($path); |
| 531 | 531 | // remove ?24px added by find_in_theme on .svg files |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
| 578 | 578 | $srcover = $match[1]; |
| 579 | 579 | array_shift($args); |
| 580 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 580 | + array_unshift($args, "<img src='".$match[1]."' />"); |
|
| 581 | 581 | $srcover_filter = call_user_func_array($filtre, $args); |
| 582 | 582 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 583 | 583 | $reduit = str_replace($srcover, $srcover_filter, $reduit); |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | if (!$srcHeight) { |
| 654 | 654 | $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
| 655 | 655 | } |
| 656 | - if (!$srcSize){ |
|
| 656 | + if (!$srcSize) { |
|
| 657 | 657 | $poids_img[$src] = filesize($src); |
| 658 | 658 | } |
| 659 | 659 | } |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | if (!$srcHeight) { |
| 668 | 668 | $hauteur_img[$src] = $srcHeight = $height; |
| 669 | 669 | } |
| 670 | - if (!$srcSize){ |
|
| 670 | + if (!$srcSize) { |
|
| 671 | 671 | $poids_img[$src] = $srcSize = strlen($src); |
| 672 | 672 | } |
| 673 | 673 | } |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | if (!$srcHeight) { |
| 686 | 686 | $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
| 687 | 687 | } |
| 688 | - if (!$srcSize){ |
|
| 688 | + if (!$srcSize) { |
|
| 689 | 689 | $poids_img[$src] = $srcSize = 0; |
| 690 | 690 | } |
| 691 | 691 | } |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | return $infos['poids']; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | -function taille_image($img, $force_refresh = false){ |
|
| 714 | +function taille_image($img, $force_refresh = false) { |
|
| 715 | 715 | $infos = infos_image($img, $force_refresh); |
| 716 | 716 | return [$infos['hauteur'], $infos['largeur']]; |
| 717 | 717 | } |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | // " -> " et tout ce genre de choses |
| 981 | 981 | $u = $GLOBALS['meta']['pcre_u']; |
| 982 | 982 | $texte = str_replace(' ', ' ', $texte); |
| 983 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 983 | + $texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte); |
|
| 984 | 984 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 985 | 985 | $texte = entites_html($texte, false, false); |
| 986 | 986 | // mais bien echapper les double quotes ! |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | **/ |
| 1041 | 1041 | function supprimer_numero($texte) { |
| 1042 | 1042 | return preg_replace( |
| 1043 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1043 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1044 | 1044 | '', |
| 1045 | 1045 | $texte |
| 1046 | 1046 | ); |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | function recuperer_numero($texte) { |
| 1069 | 1069 | if ( |
| 1070 | 1070 | preg_match( |
| 1071 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1071 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1072 | 1072 | $texte, |
| 1073 | 1073 | $regs |
| 1074 | 1074 | ) |
@@ -1159,8 +1159,8 @@ discard block |
||
| 1159 | 1159 | **/ |
| 1160 | 1160 | function textebrut($texte) { |
| 1161 | 1161 | $u = $GLOBALS['meta']['pcre_u']; |
| 1162 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1163 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1162 | + $texte = preg_replace('/\s+/S'.$u, ' ', $texte); |
|
| 1163 | + $texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte); |
|
| 1164 | 1164 | $texte = preg_replace("/^\n+/", '', $texte); |
| 1165 | 1165 | $texte = preg_replace("/\n+$/", '', $texte); |
| 1166 | 1166 | $texte = preg_replace("/\n +/", "\n", $texte); |
@@ -1194,7 +1194,7 @@ discard block |
||
| 1194 | 1194 | ) |
| 1195 | 1195 | ) { |
| 1196 | 1196 | foreach ($liens[0] as $a) { |
| 1197 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1197 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1198 | 1198 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1199 | 1199 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1200 | 1200 | $texte = str_replace($a, $ablank, $texte); |
@@ -1219,7 +1219,7 @@ discard block |
||
| 1219 | 1219 | foreach ($regs[0] as $a) { |
| 1220 | 1220 | $rel = extraire_attribut($a, 'rel') ?? ''; |
| 1221 | 1221 | if (strpos($rel, 'nofollow') === false) { |
| 1222 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1222 | + $rel = 'nofollow'.($rel ? " $rel" : ''); |
|
| 1223 | 1223 | $anofollow = inserer_attribut($a, 'rel', $rel); |
| 1224 | 1224 | $texte = str_replace($a, $anofollow, $texte); |
| 1225 | 1225 | } |
@@ -1248,7 +1248,7 @@ discard block |
||
| 1248 | 1248 | $u = $GLOBALS['meta']['pcre_u']; |
| 1249 | 1249 | $texte = preg_replace('@</p>@iS', "\n", $texte); |
| 1250 | 1250 | $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
| 1251 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1251 | + $texte = preg_replace('@^\s*<br />@S'.$u, '', $texte); |
|
| 1252 | 1252 | |
| 1253 | 1253 | return $texte; |
| 1254 | 1254 | } |
@@ -1279,7 +1279,7 @@ discard block |
||
| 1279 | 1279 | return $texte; |
| 1280 | 1280 | } |
| 1281 | 1281 | include_spip('inc/texte'); |
| 1282 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1282 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1283 | 1283 | 'div' : 'span'; |
| 1284 | 1284 | |
| 1285 | 1285 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1391,7 +1391,7 @@ discard block |
||
| 1391 | 1391 | } |
| 1392 | 1392 | $u = $GLOBALS['meta']['pcre_u']; |
| 1393 | 1393 | if ($textebrut) { |
| 1394 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1394 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte)); |
|
| 1395 | 1395 | } |
| 1396 | 1396 | $texte = texte_backend($texte); |
| 1397 | 1397 | $texte = str_replace(["'", '"'], [''', '"'], $texte); |
@@ -1426,7 +1426,7 @@ discard block |
||
| 1426 | 1426 | # un message pour abs_url |
| 1427 | 1427 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1428 | 1428 | $url = trim($url); |
| 1429 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1429 | + $r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1430 | 1430 | |
| 1431 | 1431 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1432 | 1432 | } |
@@ -1626,14 +1626,14 @@ discard block |
||
| 1626 | 1626 | if (strpos($texte, '<') !== false) { |
| 1627 | 1627 | include_spip('inc/lien'); |
| 1628 | 1628 | if (defined('_PREG_MODELE')) { |
| 1629 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1629 | + $preg_modeles = '@'._PREG_MODELE.'@imsS'; |
|
| 1630 | 1630 | $texte = echappe_html($texte, '', true, $preg_modeles); |
| 1631 | 1631 | } |
| 1632 | 1632 | } |
| 1633 | 1633 | |
| 1634 | 1634 | $debut = ''; |
| 1635 | 1635 | $suite = $texte; |
| 1636 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1636 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1637 | 1637 | $debut .= substr($suite, 0, $t - 1); |
| 1638 | 1638 | $suite = substr($suite, $t); |
| 1639 | 1639 | $car = substr($suite, 0, 1); |
@@ -1651,11 +1651,11 @@ discard block |
||
| 1651 | 1651 | $suite = substr($suite, strlen($regs[0])); |
| 1652 | 1652 | } |
| 1653 | 1653 | } |
| 1654 | - $texte = $debut . $suite; |
|
| 1654 | + $texte = $debut.$suite; |
|
| 1655 | 1655 | |
| 1656 | 1656 | $texte = echappe_retour($texte); |
| 1657 | 1657 | |
| 1658 | - return $texte . $fin; |
|
| 1658 | + return $texte.$fin; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1717,7 +1717,7 @@ discard block |
||
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | foreach ($regs as $reg) { |
| 1720 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1720 | + $cle = ($reg[1] ? $reg[1].':' : '').$reg[2]; |
|
| 1721 | 1721 | $desc = $traduire($cle, $lang, true); |
| 1722 | 1722 | $l = $desc->langue; |
| 1723 | 1723 | // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
@@ -1831,9 +1831,9 @@ discard block |
||
| 1831 | 1831 | // il ne faut pas echapper en div si propre produit un seul paragraphe |
| 1832 | 1832 | include_spip('inc/texte'); |
| 1833 | 1833 | $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
| 1834 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1834 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1835 | 1835 | if ($mode === 'div') { |
| 1836 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1836 | + $trad = rtrim($trad)."\n\n"; |
|
| 1837 | 1837 | } |
| 1838 | 1838 | $trad = code_echappement($trad, 'multi', false, $mode); |
| 1839 | 1839 | $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
@@ -2001,7 +2001,7 @@ discard block |
||
| 2001 | 2001 | } |
| 2002 | 2002 | |
| 2003 | 2003 | // un index compris entre 0 et num exclus |
| 2004 | - $i = ((intval($i) -1) % $num); // dans ]-$num;$num[ |
|
| 2004 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 2005 | 2005 | $i = ($i + $num) % $num; // dans [0;$num[ |
| 2006 | 2006 | // renvoyer le i-ieme argument, modulo le nombre d'arguments |
| 2007 | 2007 | return $args[$i]; |
@@ -2033,7 +2033,7 @@ discard block |
||
| 2033 | 2033 | if (is_array($balise)) { |
| 2034 | 2034 | array_walk( |
| 2035 | 2035 | $balise, |
| 2036 | - function (&$a, $key, $t) { |
|
| 2036 | + function(&$a, $key, $t) { |
|
| 2037 | 2037 | $a = extraire_attribut($a, $t); |
| 2038 | 2038 | }, |
| 2039 | 2039 | $attribut |
@@ -2130,14 +2130,14 @@ discard block |
||
| 2130 | 2130 | |
| 2131 | 2131 | if ($old !== null) { |
| 2132 | 2132 | // Remplacer l'ancien attribut du meme nom |
| 2133 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2133 | + $balise = $r[1].$insert.$r[5]; |
|
| 2134 | 2134 | } else { |
| 2135 | 2135 | // preferer une balise " />" (comme <img />) |
| 2136 | 2136 | if (preg_match(',/>,', $balise)) { |
| 2137 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2137 | + $balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1); |
|
| 2138 | 2138 | } // sinon une balise <a ...> ... </a> |
| 2139 | 2139 | else { |
| 2140 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2140 | + $balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1); |
|
| 2141 | 2141 | } |
| 2142 | 2142 | } |
| 2143 | 2143 | |
@@ -2192,7 +2192,7 @@ discard block |
||
| 2192 | 2192 | if ( |
| 2193 | 2193 | $class_courante |
| 2194 | 2194 | and strpos($class_courante, (string) $c) !== false |
| 2195 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2195 | + and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante) |
|
| 2196 | 2196 | ) { |
| 2197 | 2197 | $is_class_presente = true; |
| 2198 | 2198 | } |
@@ -2200,12 +2200,12 @@ discard block |
||
| 2200 | 2200 | in_array($operation, ['ajouter', 'commuter']) |
| 2201 | 2201 | and !$is_class_presente |
| 2202 | 2202 | ) { |
| 2203 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2203 | + $class_new = ltrim(rtrim($class_new ?? '').' '.$c); |
|
| 2204 | 2204 | } elseif ( |
| 2205 | 2205 | in_array($operation, ['supprimer', 'commuter']) |
| 2206 | 2206 | and $is_class_presente |
| 2207 | 2207 | ) { |
| 2208 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2208 | + $class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new)); |
|
| 2209 | 2209 | } |
| 2210 | 2210 | } |
| 2211 | 2211 | |
@@ -2268,7 +2268,7 @@ discard block |
||
| 2268 | 2268 | // Quelques fonctions de calcul arithmetique |
| 2269 | 2269 | // |
| 2270 | 2270 | function floatstr($a) { |
| 2271 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2271 | + return str_replace(',', '.', (string) floatval($a)); |
|
| 2272 | 2272 | } |
| 2273 | 2273 | function strize($f, $a, $b) { |
| 2274 | 2274 | return floatstr($f(floatstr($a), floatstr($b))); |
@@ -2404,13 +2404,13 @@ discard block |
||
| 2404 | 2404 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2405 | 2405 | define('_TAGS_NOM_AUTEUR', ''); |
| 2406 | 2406 | } |
| 2407 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2407 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2408 | 2408 | foreach ($tags_acceptes as $tag) { |
| 2409 | 2409 | if (strlen($tag)) { |
| 2410 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2411 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2412 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2413 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2410 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2411 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2412 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2413 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2414 | 2414 | } |
| 2415 | 2415 | } |
| 2416 | 2416 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2464,7 +2464,7 @@ discard block |
||
| 2464 | 2464 | . http_img_pack( |
| 2465 | 2465 | 'attachment-16.png', |
| 2466 | 2466 | $t, |
| 2467 | - 'title="' . attribut_html($t) . '"' |
|
| 2467 | + 'title="'.attribut_html($t).'"' |
|
| 2468 | 2468 | ) |
| 2469 | 2469 | . '</a>', |
| 2470 | 2470 | $tag |
@@ -2528,10 +2528,10 @@ discard block |
||
| 2528 | 2528 | $fichier = basename($url); |
| 2529 | 2529 | |
| 2530 | 2530 | return '<a rel="enclosure"' |
| 2531 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2532 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2533 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2534 | - . '>' . $fichier . '</a>'; |
|
| 2531 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2532 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2533 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2534 | + . '>'.$fichier.'</a>'; |
|
| 2535 | 2535 | } |
| 2536 | 2536 | |
| 2537 | 2537 | /** |
@@ -2559,9 +2559,9 @@ discard block |
||
| 2559 | 2559 | } # vieux data |
| 2560 | 2560 | $fichier = basename($url); |
| 2561 | 2561 | $enclosures[] = '<enclosure' |
| 2562 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2563 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2564 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2562 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2563 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2564 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2565 | 2565 | . ' />'; |
| 2566 | 2566 | } |
| 2567 | 2567 | } |
@@ -2587,7 +2587,7 @@ discard block |
||
| 2587 | 2587 | if (extraire_attribut($e, 'rel') == 'tag') { |
| 2588 | 2588 | $subjects .= '<dc:subject>' |
| 2589 | 2589 | . texte_backend(textebrut($e)) |
| 2590 | - . '</dc:subject>' . "\n"; |
|
| 2590 | + . '</dc:subject>'."\n"; |
|
| 2591 | 2591 | } |
| 2592 | 2592 | } |
| 2593 | 2593 | |
@@ -2623,7 +2623,7 @@ discard block |
||
| 2623 | 2623 | if (is_array($texte)) { |
| 2624 | 2624 | array_walk( |
| 2625 | 2625 | $texte, |
| 2626 | - function (&$a, $key, $t) { |
|
| 2626 | + function(&$a, $key, $t) { |
|
| 2627 | 2627 | $a = extraire_balise($a, $t); |
| 2628 | 2628 | }, |
| 2629 | 2629 | $tag |
@@ -2671,7 +2671,7 @@ discard block |
||
| 2671 | 2671 | if (is_array($texte)) { |
| 2672 | 2672 | array_walk( |
| 2673 | 2673 | $texte, |
| 2674 | - function (&$a, $key, $t) { |
|
| 2674 | + function(&$a, $key, $t) { |
|
| 2675 | 2675 | $a = extraire_balises($a, $t); |
| 2676 | 2676 | }, |
| 2677 | 2677 | $tag |
@@ -2804,7 +2804,7 @@ discard block |
||
| 2804 | 2804 | if ($fond != '404') { |
| 2805 | 2805 | $contexte = array_shift($p); |
| 2806 | 2806 | $contexte['page'] = $fond; |
| 2807 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2807 | + $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2808 | 2808 | } |
| 2809 | 2809 | } |
| 2810 | 2810 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2859,9 +2859,9 @@ discard block |
||
| 2859 | 2859 | . '"' |
| 2860 | 2860 | . (is_null($val) |
| 2861 | 2861 | ? '' |
| 2862 | - : ' value="' . entites_html($val) . '"' |
|
| 2862 | + : ' value="'.entites_html($val).'"' |
|
| 2863 | 2863 | ) |
| 2864 | - . ' type="hidden"' . "\n/>"; |
|
| 2864 | + . ' type="hidden"'."\n/>"; |
|
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | return join('', $hidden); |
@@ -2971,7 +2971,7 @@ discard block |
||
| 2971 | 2971 | |
| 2972 | 2972 | return preg_replace_callback( |
| 2973 | 2973 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2974 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2974 | + fn($x) => "url('".suivre_lien($path, $x[1])."')", |
|
| 2975 | 2975 | $contenu |
| 2976 | 2976 | ); |
| 2977 | 2977 | } |
@@ -3032,14 +3032,14 @@ discard block |
||
| 3032 | 3032 | ) { |
| 3033 | 3033 | $distant = true; |
| 3034 | 3034 | $cssf = parse_url($css); |
| 3035 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3035 | + $cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : ''); |
|
| 3036 | 3036 | $cssf = preg_replace(',[?:&=],', '_', $cssf); |
| 3037 | 3037 | } else { |
| 3038 | 3038 | $distant = false; |
| 3039 | 3039 | $cssf = $css; |
| 3040 | 3040 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 3041 | 3041 | //propose (rien a faire dans ce cas) |
| 3042 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3042 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 3043 | 3043 | if (@file_exists($f)) { |
| 3044 | 3044 | return $f; |
| 3045 | 3045 | } |
@@ -3049,7 +3049,7 @@ discard block |
||
| 3049 | 3049 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 3050 | 3050 | $f = $dir_var |
| 3051 | 3051 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 3052 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3052 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 3053 | 3053 | |
| 3054 | 3054 | // la css peut etre distante (url absolue !) |
| 3055 | 3055 | if ($distant) { |
@@ -3095,8 +3095,8 @@ discard block |
||
| 3095 | 3095 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 3096 | 3096 | elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
| 3097 | 3097 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 3098 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3099 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3098 | + $src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction; |
|
| 3099 | + $css_direction = '/@@@@@@/'.$css_direction; |
|
| 3100 | 3100 | } |
| 3101 | 3101 | $src[] = $regs[0][$k]; |
| 3102 | 3102 | $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
@@ -3145,7 +3145,7 @@ discard block |
||
| 3145 | 3145 | |
| 3146 | 3146 | $f = basename($css, '.css'); |
| 3147 | 3147 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 3148 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3148 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 3149 | 3149 | . '.css'; |
| 3150 | 3150 | |
| 3151 | 3151 | if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
@@ -3155,7 +3155,7 @@ discard block |
||
| 3155 | 3155 | if ($url_absolue_css == $css) { |
| 3156 | 3156 | if ( |
| 3157 | 3157 | strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
| 3158 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3158 | + or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 3159 | 3159 | ) { |
| 3160 | 3160 | include_spip('inc/distant'); |
| 3161 | 3161 | $contenu = recuperer_url($css); |
@@ -3267,7 +3267,7 @@ discard block |
||
| 3267 | 3267 | $expression = str_replace('\/', '/', $expression); |
| 3268 | 3268 | $expression = str_replace('/', '\/', $expression); |
| 3269 | 3269 | |
| 3270 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3270 | + if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) { |
|
| 3271 | 3271 | if (isset($r[$capte])) { |
| 3272 | 3272 | return $r[$capte]; |
| 3273 | 3273 | } else { |
@@ -3305,7 +3305,7 @@ discard block |
||
| 3305 | 3305 | $expression = str_replace('\/', '/', $expression); |
| 3306 | 3306 | $expression = str_replace('/', '\/', $expression); |
| 3307 | 3307 | |
| 3308 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3308 | + return preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3309 | 3309 | } |
| 3310 | 3310 | |
| 3311 | 3311 | |
@@ -3324,7 +3324,7 @@ discard block |
||
| 3324 | 3324 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3325 | 3325 | |
| 3326 | 3326 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3327 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3327 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3328 | 3328 | |
| 3329 | 3329 | if ( |
| 3330 | 3330 | strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
@@ -3338,7 +3338,7 @@ discard block |
||
| 3338 | 3338 | if (!isset($doublons['documents'])) { |
| 3339 | 3339 | $doublons['documents'] = ''; |
| 3340 | 3340 | } |
| 3341 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3341 | + $doublons['documents'] .= ','.join(',', $matches[1]); |
|
| 3342 | 3342 | } |
| 3343 | 3343 | |
| 3344 | 3344 | return $letexte; |
@@ -3395,7 +3395,7 @@ discard block |
||
| 3395 | 3395 | if ($env) { |
| 3396 | 3396 | foreach ($env as $i => $j) { |
| 3397 | 3397 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3398 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3398 | + $texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />"; |
|
| 3399 | 3399 | } |
| 3400 | 3400 | } |
| 3401 | 3401 | } |
@@ -3434,7 +3434,7 @@ discard block |
||
| 3434 | 3434 | if ($env) { |
| 3435 | 3435 | foreach ($env as $i => $j) { |
| 3436 | 3436 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3437 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3437 | + $texte .= attribut_html($i)."='".attribut_html($j)."' "; |
|
| 3438 | 3438 | } |
| 3439 | 3439 | } |
| 3440 | 3440 | } |
@@ -3508,10 +3508,10 @@ discard block |
||
| 3508 | 3508 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 3509 | 3509 | if ( |
| 3510 | 3510 | preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
| 3511 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3511 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg' |
|
| 3512 | 3512 | and file_exists($variante_svg_generique) |
| 3513 | 3513 | ) { |
| 3514 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3514 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) { |
|
| 3515 | 3515 | $img_file = $variante_svg_size; |
| 3516 | 3516 | } |
| 3517 | 3517 | else { |
@@ -3569,7 +3569,7 @@ discard block |
||
| 3569 | 3569 | return ''; |
| 3570 | 3570 | } |
| 3571 | 3571 | } |
| 3572 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3572 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3573 | 3573 | } |
| 3574 | 3574 | |
| 3575 | 3575 | if (file_exists($img_file)) { |
@@ -3579,14 +3579,14 @@ discard block |
||
| 3579 | 3579 | $alt = ''; |
| 3580 | 3580 | } |
| 3581 | 3581 | elseif ($alt or $alt === '') { |
| 3582 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3582 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3583 | 3583 | } |
| 3584 | 3584 | else { |
| 3585 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3585 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3586 | 3586 | } |
| 3587 | 3587 | return "<img src='$img_file'$alt" |
| 3588 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3589 | - . ' ' . ltrim($atts) |
|
| 3588 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3589 | + . ' '.ltrim($atts) |
|
| 3590 | 3590 | . ' />'; |
| 3591 | 3591 | } |
| 3592 | 3592 | |
@@ -3600,10 +3600,10 @@ discard block |
||
| 3600 | 3600 | */ |
| 3601 | 3601 | function http_style_background($img, $att = '', $size = null) { |
| 3602 | 3602 | if ($size and is_numeric($size)) { |
| 3603 | - $size = trim($size) . 'px'; |
|
| 3603 | + $size = trim($size).'px'; |
|
| 3604 | 3604 | } |
| 3605 | - return " style='background" . |
|
| 3606 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3605 | + return " style='background". |
|
| 3606 | + ($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';' |
|
| 3607 | 3607 | . ($size ? "background-size:{$size};" : '') |
| 3608 | 3608 | . "'"; |
| 3609 | 3609 | } |
@@ -3718,7 +3718,7 @@ discard block |
||
| 3718 | 3718 | $img = http_img_pack( |
| 3719 | 3719 | $img, |
| 3720 | 3720 | $alt, |
| 3721 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3721 | + $class ? " class='".attribut_html($class)."'" : '', |
|
| 3722 | 3722 | '', |
| 3723 | 3723 | ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
| 3724 | 3724 | ); |
@@ -3803,7 +3803,7 @@ discard block |
||
| 3803 | 3803 | $balise_svg_source = $balise_svg; |
| 3804 | 3804 | |
| 3805 | 3805 | // entete XML à supprimer |
| 3806 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3806 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg); |
|
| 3807 | 3807 | |
| 3808 | 3808 | // IE est toujours mon ami |
| 3809 | 3809 | $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
@@ -3821,9 +3821,9 @@ discard block |
||
| 3821 | 3821 | // regler le alt |
| 3822 | 3822 | if ($alt) { |
| 3823 | 3823 | $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
| 3824 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3824 | + $id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3825 | 3825 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3826 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3826 | + $title = "<title id=\"$id\">".entites_html($alt)."</title>\n"; |
|
| 3827 | 3827 | $balise_svg .= $title; |
| 3828 | 3828 | } |
| 3829 | 3829 | else { |
@@ -3871,7 +3871,7 @@ discard block |
||
| 3871 | 3871 | if (is_array($tableau)) { |
| 3872 | 3872 | foreach ($tableau as $k => $v) { |
| 3873 | 3873 | $res = recuperer_fond( |
| 3874 | - 'modeles/' . $modele, |
|
| 3874 | + 'modeles/'.$modele, |
|
| 3875 | 3875 | array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
| 3876 | 3876 | ); |
| 3877 | 3877 | $texte .= $res; |
@@ -4056,7 +4056,7 @@ discard block |
||
| 4056 | 4056 | } |
| 4057 | 4057 | |
| 4058 | 4058 | $c = serialize($c); |
| 4059 | - $cle = calculer_cle_action($form . $c); |
|
| 4059 | + $cle = calculer_cle_action($form.$c); |
|
| 4060 | 4060 | $c = "$cle:$c"; |
| 4061 | 4061 | |
| 4062 | 4062 | // on ne stocke pas les contextes dans des fichiers en cache |
@@ -4114,15 +4114,15 @@ discard block |
||
| 4114 | 4114 | } |
| 4115 | 4115 | // toujours encoder l'url source dans le bloc ajax |
| 4116 | 4116 | $r = self(); |
| 4117 | - $r = ' data-origin="' . $r . '"'; |
|
| 4117 | + $r = ' data-origin="'.$r.'"'; |
|
| 4118 | 4118 | $class = 'ajaxbloc'; |
| 4119 | 4119 | if ($ajaxid and is_string($ajaxid)) { |
| 4120 | 4120 | // ajaxid est normalement conforme a un nom de classe css |
| 4121 | 4121 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 4122 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4122 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 4123 | 4123 | } |
| 4124 | 4124 | |
| 4125 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4125 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4126 | 4126 | } |
| 4127 | 4127 | |
| 4128 | 4128 | /** |
@@ -4166,7 +4166,7 @@ discard block |
||
| 4166 | 4166 | $cle = substr($c, 0, $p); |
| 4167 | 4167 | $c = substr($c, $p + 1); |
| 4168 | 4168 | |
| 4169 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4169 | + if ($cle == calculer_cle_action($form.$c)) { |
|
| 4170 | 4170 | $env = @unserialize($c); |
| 4171 | 4171 | return $env; |
| 4172 | 4172 | } |
@@ -4287,13 +4287,13 @@ discard block |
||
| 4287 | 4287 | } |
| 4288 | 4288 | } |
| 4289 | 4289 | } |
| 4290 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4290 | + $att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"'; |
|
| 4291 | 4291 | } else { |
| 4292 | 4292 | $bal = 'a'; |
| 4293 | 4293 | $att = "href='$url'" |
| 4294 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4295 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4296 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4294 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 4295 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 4296 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 4297 | 4297 | . $evt; |
| 4298 | 4298 | } |
| 4299 | 4299 | if ($libelle === null) { |
@@ -4432,7 +4432,7 @@ discard block |
||
| 4432 | 4432 | |
| 4433 | 4433 | // Icône |
| 4434 | 4434 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
| 4435 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4435 | + $icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>"; |
|
| 4436 | 4436 | |
| 4437 | 4437 | // Markup final |
| 4438 | 4438 | if ($type == 'lien') { |
@@ -4709,20 +4709,20 @@ discard block |
||
| 4709 | 4709 | $class_form = 'ajax'; |
| 4710 | 4710 | $class = str_replace('ajax', '', $class); |
| 4711 | 4711 | } |
| 4712 | - $class_btn = 'submit ' . trim($class); |
|
| 4712 | + $class_btn = 'submit '.trim($class); |
|
| 4713 | 4713 | |
| 4714 | 4714 | if ($confirm) { |
| 4715 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4715 | + $confirm = 'confirm("'.attribut_html($confirm).'")'; |
|
| 4716 | 4716 | if ($callback) { |
| 4717 | 4717 | $callback = "$confirm?($callback):false"; |
| 4718 | 4718 | } else { |
| 4719 | 4719 | $callback = $confirm; |
| 4720 | 4720 | } |
| 4721 | 4721 | } |
| 4722 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4722 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ''; |
|
| 4723 | 4723 | $title = $title ? " title='$title'" : ''; |
| 4724 | 4724 | |
| 4725 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4725 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url) |
|
| 4726 | 4726 | . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
| 4727 | 4727 | } |
| 4728 | 4728 | |
@@ -4787,14 +4787,14 @@ discard block |
||
| 4787 | 4787 | $champ_titre = ''; |
| 4788 | 4788 | if ($demande_titre) { |
| 4789 | 4789 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4790 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4790 | + $champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : ''; |
|
| 4791 | 4791 | } |
| 4792 | 4792 | include_spip('base/abstract_sql'); |
| 4793 | 4793 | include_spip('base/connect_sql'); |
| 4794 | 4794 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4795 | - '*' . $champ_titre, |
|
| 4795 | + '*'.$champ_titre, |
|
| 4796 | 4796 | $desc['table_sql'], |
| 4797 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4797 | + id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 4798 | 4798 | ); |
| 4799 | 4799 | |
| 4800 | 4800 | // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
@@ -4887,8 +4887,7 @@ discard block |
||
| 4887 | 4887 | if (isset($ligne_sql['chapo'])) { |
| 4888 | 4888 | $chapo = $ligne_sql['chapo']; |
| 4889 | 4889 | $texte = strlen($descriptif) ? |
| 4890 | - '' : |
|
| 4891 | - "$chapo \n\n $texte"; |
|
| 4890 | + '' : "$chapo \n\n $texte"; |
|
| 4892 | 4891 | } |
| 4893 | 4892 | |
| 4894 | 4893 | // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
@@ -4963,7 +4962,7 @@ discard block |
||
| 4963 | 4962 | return $texte; |
| 4964 | 4963 | } |
| 4965 | 4964 | |
| 4966 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4965 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement); |
|
| 4967 | 4966 | |
| 4968 | 4967 | // Fournir $connect et $Pile[0] au traitement si besoin |
| 4969 | 4968 | $Pile = [0 => $env]; |
@@ -4997,7 +4996,7 @@ discard block |
||
| 4997 | 4996 | } |
| 4998 | 4997 | $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
| 4999 | 4998 | |
| 5000 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4999 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>'; |
|
| 5001 | 5000 | } |
| 5002 | 5001 | |
| 5003 | 5002 | /** |
@@ -5023,10 +5022,10 @@ discard block |
||
| 5023 | 5022 | function wrap($texte, $wrap) { |
| 5024 | 5023 | $balises = extraire_balises($wrap); |
| 5025 | 5024 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 5026 | - $texte = $wrap . $texte; |
|
| 5025 | + $texte = $wrap.$texte; |
|
| 5027 | 5026 | $regs = array_reverse($regs[1]); |
| 5028 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5029 | - $texte = $texte . $wrap; |
|
| 5027 | + $wrap = '</'.implode('></', $regs).'>'; |
|
| 5028 | + $texte = $texte.$wrap; |
|
| 5030 | 5029 | } |
| 5031 | 5030 | |
| 5032 | 5031 | return $texte; |
@@ -5057,7 +5056,7 @@ discard block |
||
| 5057 | 5056 | |
| 5058 | 5057 | // caster $u en array si besoin |
| 5059 | 5058 | if (is_object($u)) { |
| 5060 | - $u = (array)$u; |
|
| 5059 | + $u = (array) $u; |
|
| 5061 | 5060 | } |
| 5062 | 5061 | |
| 5063 | 5062 | if (is_array($u)) { |
@@ -5079,7 +5078,7 @@ discard block |
||
| 5079 | 5078 | // sinon on passe a la ligne et on indente |
| 5080 | 5079 | $i_str = str_pad('', $indent, ' '); |
| 5081 | 5080 | foreach ($u as $k => $v) { |
| 5082 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5081 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 5083 | 5082 | } |
| 5084 | 5083 | |
| 5085 | 5084 | return $out; |
@@ -5133,7 +5132,7 @@ discard block |
||
| 5133 | 5132 | * @return string |
| 5134 | 5133 | */ |
| 5135 | 5134 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5136 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5135 | + $icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png'; |
|
| 5137 | 5136 | $icone = chemin_image($icone); |
| 5138 | 5137 | $balise_img = charger_filtre('balise_img'); |
| 5139 | 5138 | |
@@ -5159,7 +5158,7 @@ discard block |
||
| 5159 | 5158 | */ |
| 5160 | 5159 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5161 | 5160 | $chaine = explode(':', $chaine); |
| 5162 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5161 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5163 | 5162 | return $t; |
| 5164 | 5163 | } |
| 5165 | 5164 | $chaine = implode(':', $chaine); |
@@ -5225,7 +5224,7 @@ discard block |
||
| 5225 | 5224 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 5226 | 5225 | |
| 5227 | 5226 | // calculer le nom de la css |
| 5228 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5227 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 5229 | 5228 | $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
| 5230 | 5229 | $contexte_implicite = calculer_contexte_implicite(); |
| 5231 | 5230 | |
@@ -5233,14 +5232,14 @@ discard block |
||
| 5233 | 5232 | // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
| 5234 | 5233 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5235 | 5234 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5236 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5235 | + $hash = md5($contexte_implicite['host'].'::'.$cache); |
|
| 5237 | 5236 | } |
| 5238 | 5237 | else { |
| 5239 | 5238 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5240 | 5239 | ksort($contexte); |
| 5241 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5240 | + $hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect); |
|
| 5242 | 5241 | } |
| 5243 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5242 | + $filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension"; |
|
| 5244 | 5243 | |
| 5245 | 5244 | // mettre a jour le fichier si il n'existe pas |
| 5246 | 5245 | // ou trop ancien |
@@ -5248,8 +5247,8 @@ discard block |
||
| 5248 | 5247 | // et recopie sur le fichier cible uniquement si il change |
| 5249 | 5248 | if ( |
| 5250 | 5249 | !file_exists($filename) |
| 5251 | - or !file_exists($filename . '.last') |
|
| 5252 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5250 | + or !file_exists($filename.'.last') |
|
| 5251 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified']) |
|
| 5253 | 5252 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 5254 | 5253 | ) { |
| 5255 | 5254 | $contenu = $cache['texte']; |
@@ -5270,10 +5269,10 @@ discard block |
||
| 5270 | 5269 | } |
| 5271 | 5270 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 5272 | 5271 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 5273 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5272 | + $comment .= "}\n md5:".md5($contenu)." */\n"; |
|
| 5274 | 5273 | } |
| 5275 | 5274 | // et ecrire le fichier si il change |
| 5276 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5275 | + ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true); |
|
| 5277 | 5276 | } |
| 5278 | 5277 | |
| 5279 | 5278 | return timestamp($filename); |
@@ -5499,7 +5498,7 @@ discard block |
||
| 5499 | 5498 | if ($e > 0 and strlen($mid) > 8) { |
| 5500 | 5499 | $mid = '***...***'; |
| 5501 | 5500 | } |
| 5502 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5501 | + return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : ''); |
|
| 5503 | 5502 | } |
| 5504 | 5503 | |
| 5505 | 5504 | |
@@ -5561,7 +5560,7 @@ discard block |
||
| 5561 | 5560 | case 'id': |
| 5562 | 5561 | case 'anchor': |
| 5563 | 5562 | if (preg_match(',^\d,', $texte)) { |
| 5564 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5563 | + $texte = substr($type, 0, 1).$texte; |
|
| 5565 | 5564 | } |
| 5566 | 5565 | } |
| 5567 | 5566 | |
@@ -5571,9 +5570,9 @@ discard block |
||
| 5571 | 5570 | |
| 5572 | 5571 | if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
| 5573 | 5572 | if (preg_match(',^\d,', $texte)) { |
| 5574 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5573 | + $texte = ($type ? substr($type, 0, 1) : 's').$texte; |
|
| 5575 | 5574 | } |
| 5576 | - $texte .= $separateur . md5($original); |
|
| 5575 | + $texte .= $separateur.md5($original); |
|
| 5577 | 5576 | $texte = substr($texte, 0, $longueur_mini); |
| 5578 | 5577 | } |
| 5579 | 5578 | |