@@ -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_spip('public/parametrer'); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_spip('public/parametrer'); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -75,36 +75,36 @@ discard block |
||
| 75 | 75 | * Fonction PHP correspondante du filtre demandé |
| 76 | 76 | */ |
| 77 | 77 | function chercher_filtre($fonc, $default = null) { |
| 78 | - if (!$fonc) { |
|
| 79 | - return $default; |
|
| 80 | - } |
|
| 81 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 82 | - // Foo::Bar |
|
| 83 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 84 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 85 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 86 | - $f = chercher_filtre($nom); |
|
| 87 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 88 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 89 | - if (!$f and $nom !== $fonc) { |
|
| 90 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $f; |
|
| 94 | - } |
|
| 95 | - foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 96 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 97 | - // fonction ou name\space\fonction |
|
| 98 | - if (is_callable($f)) { |
|
| 99 | - return $f; |
|
| 100 | - } |
|
| 101 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 102 | - elseif (false === strpos($f, '::') and is_callable(array($f))) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $default; |
|
| 78 | + if (!$fonc) { |
|
| 79 | + return $default; |
|
| 80 | + } |
|
| 81 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 82 | + // Foo::Bar |
|
| 83 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 84 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 85 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 86 | + $f = chercher_filtre($nom); |
|
| 87 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 88 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 89 | + if (!$f and $nom !== $fonc) { |
|
| 90 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $f; |
|
| 94 | + } |
|
| 95 | + foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 96 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 97 | + // fonction ou name\space\fonction |
|
| 98 | + if (is_callable($f)) { |
|
| 99 | + return $f; |
|
| 100 | + } |
|
| 101 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 102 | + elseif (false === strpos($f, '::') and is_callable(array($f))) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $default; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -128,20 +128,20 @@ discard block |
||
| 128 | 128 | * Chaîne vide sinon (filtre introuvable). |
| 129 | 129 | **/ |
| 130 | 130 | function appliquer_filtre($arg, $filtre, $force = null) { |
| 131 | - $f = chercher_filtre($filtre); |
|
| 132 | - if (!$f) { |
|
| 133 | - if (!$force) { |
|
| 134 | - return ''; |
|
| 135 | - } else { |
|
| 136 | - return $arg; |
|
| 137 | - } |
|
| 138 | - } |
|
| 131 | + $f = chercher_filtre($filtre); |
|
| 132 | + if (!$f) { |
|
| 133 | + if (!$force) { |
|
| 134 | + return ''; |
|
| 135 | + } else { |
|
| 136 | + return $arg; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - $args = func_get_args(); |
|
| 141 | - array_shift($args); // enlever $arg |
|
| 142 | - array_shift($args); // enlever $filtre |
|
| 143 | - array_unshift($args, $arg); // remettre $arg |
|
| 144 | - return call_user_func_array($f, $args); |
|
| 140 | + $args = func_get_args(); |
|
| 141 | + array_shift($args); // enlever $arg |
|
| 142 | + array_shift($args); // enlever $filtre |
|
| 143 | + array_unshift($args, $arg); // remettre $arg |
|
| 144 | + return call_user_func_array($f, $args); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | * Version de SPIP |
| 158 | 158 | **/ |
| 159 | 159 | function spip_version() { |
| 160 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 161 | - if ($svn_revision = version_svn_courante(_DIR_RACINE)) { |
|
| 162 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 163 | - } |
|
| 160 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 161 | + if ($svn_revision = version_svn_courante(_DIR_RACINE)) { |
|
| 162 | + $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return $version; |
|
| 165 | + return $version; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -181,43 +181,43 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | **/ |
| 183 | 183 | function version_svn_courante($dir) { |
| 184 | - if (!$dir) { |
|
| 185 | - $dir = '.'; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // version installee par paquet ZIP |
|
| 189 | - if (lire_fichier($dir . '/svn.revision', $c) |
|
| 190 | - and preg_match(',Revision: (\d+),', $c, $d) |
|
| 191 | - ) { |
|
| 192 | - return intval($d[1]); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // version installee par SVN |
|
| 196 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 197 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 198 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 199 | - if ($result) { |
|
| 200 | - $row = $result->fetchArray(); |
|
| 201 | - if ($row['changed_revision'] != "") { |
|
| 202 | - return -$row['changed_revision']; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } else if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 206 | - and ( |
|
| 207 | - (preg_match_all( |
|
| 208 | - ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
|
| 209 | - and $v = max($r1[1]) |
|
| 210 | - ) |
|
| 211 | - or |
|
| 212 | - (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4 |
|
| 213 | - and $v = $r1[1] |
|
| 214 | - )) |
|
| 215 | - ) { |
|
| 216 | - return -$v; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // Bug ou paquet fait main |
|
| 220 | - return 0; |
|
| 184 | + if (!$dir) { |
|
| 185 | + $dir = '.'; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // version installee par paquet ZIP |
|
| 189 | + if (lire_fichier($dir . '/svn.revision', $c) |
|
| 190 | + and preg_match(',Revision: (\d+),', $c, $d) |
|
| 191 | + ) { |
|
| 192 | + return intval($d[1]); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // version installee par SVN |
|
| 196 | + if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 197 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 198 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 199 | + if ($result) { |
|
| 200 | + $row = $result->fetchArray(); |
|
| 201 | + if ($row['changed_revision'] != "") { |
|
| 202 | + return -$row['changed_revision']; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } else if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 206 | + and ( |
|
| 207 | + (preg_match_all( |
|
| 208 | + ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
|
| 209 | + and $v = max($r1[1]) |
|
| 210 | + ) |
|
| 211 | + or |
|
| 212 | + (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4 |
|
| 213 | + and $v = $r1[1] |
|
| 214 | + )) |
|
| 215 | + ) { |
|
| 216 | + return -$v; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // Bug ou paquet fait main |
|
| 220 | + return 0; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -261,18 +261,18 @@ discard block |
||
| 261 | 261 | * Code HTML retourné par le filtre |
| 262 | 262 | **/ |
| 263 | 263 | function filtrer($filtre) { |
| 264 | - $tous = func_get_args(); |
|
| 265 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 266 | - return image_filtrer($tous); |
|
| 267 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 268 | - array_shift($tous); |
|
| 269 | - return call_user_func_array($f, $tous); |
|
| 270 | - } else { |
|
| 271 | - // le filtre n'existe pas, on provoque une erreur |
|
| 272 | - $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre))); |
|
| 273 | - erreur_squelette($msg); |
|
| 274 | - return ''; |
|
| 275 | - } |
|
| 264 | + $tous = func_get_args(); |
|
| 265 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 266 | + return image_filtrer($tous); |
|
| 267 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 268 | + array_shift($tous); |
|
| 269 | + return call_user_func_array($f, $tous); |
|
| 270 | + } else { |
|
| 271 | + // le filtre n'existe pas, on provoque une erreur |
|
| 272 | + $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre))); |
|
| 273 | + erreur_squelette($msg); |
|
| 274 | + return ''; |
|
| 275 | + } |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 290 | 290 | */ |
| 291 | 291 | function trouver_filtre_matrice($filtre) { |
| 292 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 293 | - find_in_path($f, '', true); |
|
| 294 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 295 | - } |
|
| 296 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 292 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 293 | + find_in_path($f, '', true); |
|
| 294 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 295 | + } |
|
| 296 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | * @return mixed |
| 322 | 322 | */ |
| 323 | 323 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 324 | - $Pile['vars'][$key] = $val; |
|
| 325 | - return $continue ? $val : ''; |
|
| 324 | + $Pile['vars'][$key] = $val; |
|
| 325 | + return $continue ? $val : ''; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 349 | 349 | */ |
| 350 | 350 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 351 | - $Pile[0][$key] = $val; |
|
| 352 | - return $continue ? $val : ''; |
|
| 351 | + $Pile[0][$key] = $val; |
|
| 352 | + return $continue ? $val : ''; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -371,18 +371,18 @@ discard block |
||
| 371 | 371 | * @return mixed Retourne la valeur (sans la modifier). |
| 372 | 372 | */ |
| 373 | 373 | function filtre_debug($val, $key = null) { |
| 374 | - $debug = ( |
|
| 375 | - is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 376 | - ) . var_export($val, true); |
|
| 374 | + $debug = ( |
|
| 375 | + is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 376 | + ) . var_export($val, true); |
|
| 377 | 377 | |
| 378 | - include_spip('inc/autoriser'); |
|
| 379 | - if (autoriser('webmestre')) { |
|
| 380 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 381 | - } |
|
| 378 | + include_spip('inc/autoriser'); |
|
| 379 | + if (autoriser('webmestre')) { |
|
| 380 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - spip_log($debug, 'debug'); |
|
| 383 | + spip_log($debug, 'debug'); |
|
| 384 | 384 | |
| 385 | - return $val; |
|
| 385 | + return $val; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | |
@@ -410,71 +410,71 @@ discard block |
||
| 410 | 410 | * Texte qui a reçu les filtres |
| 411 | 411 | **/ |
| 412 | 412 | function image_filtrer($args) { |
| 413 | - $filtre = array_shift($args); # enlever $filtre |
|
| 414 | - $texte = array_shift($args); |
|
| 415 | - if (!strlen($texte)) { |
|
| 416 | - return; |
|
| 417 | - } |
|
| 418 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 419 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 420 | - // Cas du nom de fichier local |
|
| 421 | - if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false |
|
| 422 | - and !preg_match(',^/|[<>]|\s,S', $texte) |
|
| 423 | - and ( |
|
| 424 | - file_exists(preg_replace(',[?].*$,', '', $texte)) |
|
| 425 | - or tester_url_absolue($texte) |
|
| 426 | - ) |
|
| 427 | - ) { |
|
| 428 | - array_unshift($args, "<img src='$texte' />"); |
|
| 429 | - $res = call_user_func_array($filtre, $args); |
|
| 430 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 431 | - return $res; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 435 | - if (preg_match_all( |
|
| 436 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 437 | - $texte, $tags, PREG_SET_ORDER)) { |
|
| 438 | - foreach ($tags as $tag) { |
|
| 439 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 440 | - if (!$class or |
|
| 441 | - (strpos($class, 'filtre_inactif') === false |
|
| 442 | - // compat historique a virer en 3.2 |
|
| 443 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 444 | - ) { |
|
| 445 | - array_unshift($args, $tag[3]); |
|
| 446 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 447 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 448 | - if ($tag[1]) { |
|
| 449 | - $w = extraire_attribut($reduit, 'width'); |
|
| 450 | - if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) { |
|
| 451 | - $w = $regs[1]; |
|
| 452 | - } |
|
| 453 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 454 | - $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 455 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 456 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - // traiter aussi un eventuel mouseover |
|
| 460 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 461 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 462 | - $srcover = $match[1]; |
|
| 463 | - array_shift($args); |
|
| 464 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 465 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 466 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 467 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 471 | - } |
|
| 472 | - array_shift($args); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 477 | - return $texte; |
|
| 413 | + $filtre = array_shift($args); # enlever $filtre |
|
| 414 | + $texte = array_shift($args); |
|
| 415 | + if (!strlen($texte)) { |
|
| 416 | + return; |
|
| 417 | + } |
|
| 418 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 419 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 420 | + // Cas du nom de fichier local |
|
| 421 | + if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false |
|
| 422 | + and !preg_match(',^/|[<>]|\s,S', $texte) |
|
| 423 | + and ( |
|
| 424 | + file_exists(preg_replace(',[?].*$,', '', $texte)) |
|
| 425 | + or tester_url_absolue($texte) |
|
| 426 | + ) |
|
| 427 | + ) { |
|
| 428 | + array_unshift($args, "<img src='$texte' />"); |
|
| 429 | + $res = call_user_func_array($filtre, $args); |
|
| 430 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 431 | + return $res; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 435 | + if (preg_match_all( |
|
| 436 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 437 | + $texte, $tags, PREG_SET_ORDER)) { |
|
| 438 | + foreach ($tags as $tag) { |
|
| 439 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 440 | + if (!$class or |
|
| 441 | + (strpos($class, 'filtre_inactif') === false |
|
| 442 | + // compat historique a virer en 3.2 |
|
| 443 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 444 | + ) { |
|
| 445 | + array_unshift($args, $tag[3]); |
|
| 446 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 447 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 448 | + if ($tag[1]) { |
|
| 449 | + $w = extraire_attribut($reduit, 'width'); |
|
| 450 | + if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) { |
|
| 451 | + $w = $regs[1]; |
|
| 452 | + } |
|
| 453 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 454 | + $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 455 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 456 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + // traiter aussi un eventuel mouseover |
|
| 460 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 461 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 462 | + $srcover = $match[1]; |
|
| 463 | + array_shift($args); |
|
| 464 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 465 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 466 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 467 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 471 | + } |
|
| 472 | + array_shift($args); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 477 | + return $texte; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -489,65 +489,65 @@ discard block |
||
| 489 | 489 | **/ |
| 490 | 490 | function taille_image($img) { |
| 491 | 491 | |
| 492 | - static $largeur_img = array(), $hauteur_img = array(); |
|
| 493 | - $srcWidth = 0; |
|
| 494 | - $srcHeight = 0; |
|
| 495 | - |
|
| 496 | - $src = extraire_attribut($img, 'src'); |
|
| 497 | - |
|
| 498 | - if (!$src) { |
|
| 499 | - $src = $img; |
|
| 500 | - } else { |
|
| 501 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 502 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 506 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 507 | - if (tester_url_absolue($src)) { |
|
| 508 | - include_spip('inc/distant'); |
|
| 509 | - $fichier = copie_locale($src); |
|
| 510 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 511 | - } |
|
| 512 | - if (($p = strpos($src, '?')) !== false) { |
|
| 513 | - $src = substr($src, 0, $p); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - $srcsize = false; |
|
| 517 | - if (isset($largeur_img[$src])) { |
|
| 518 | - $srcWidth = $largeur_img[$src]; |
|
| 519 | - } |
|
| 520 | - if (isset($hauteur_img[$src])) { |
|
| 521 | - $srcHeight = $hauteur_img[$src]; |
|
| 522 | - } |
|
| 523 | - if (!$srcWidth or !$srcHeight) { |
|
| 524 | - |
|
| 525 | - if (file_exists($src) |
|
| 526 | - and $srcsize = spip_getimagesize($src) |
|
| 527 | - ) { |
|
| 528 | - if (!$srcWidth) { |
|
| 529 | - $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 530 | - } |
|
| 531 | - if (!$srcHeight) { |
|
| 532 | - $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 536 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 537 | - elseif (@file_exists($f = "$src.src") |
|
| 538 | - and lire_fichier($f, $valeurs) |
|
| 539 | - and $valeurs = unserialize($valeurs) |
|
| 540 | - ) { |
|
| 541 | - if (!$srcWidth) { |
|
| 542 | - $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 543 | - } |
|
| 544 | - if (!$srcHeight) { |
|
| 545 | - $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return array($srcHeight, $srcWidth); |
|
| 492 | + static $largeur_img = array(), $hauteur_img = array(); |
|
| 493 | + $srcWidth = 0; |
|
| 494 | + $srcHeight = 0; |
|
| 495 | + |
|
| 496 | + $src = extraire_attribut($img, 'src'); |
|
| 497 | + |
|
| 498 | + if (!$src) { |
|
| 499 | + $src = $img; |
|
| 500 | + } else { |
|
| 501 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 502 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 506 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 507 | + if (tester_url_absolue($src)) { |
|
| 508 | + include_spip('inc/distant'); |
|
| 509 | + $fichier = copie_locale($src); |
|
| 510 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 511 | + } |
|
| 512 | + if (($p = strpos($src, '?')) !== false) { |
|
| 513 | + $src = substr($src, 0, $p); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + $srcsize = false; |
|
| 517 | + if (isset($largeur_img[$src])) { |
|
| 518 | + $srcWidth = $largeur_img[$src]; |
|
| 519 | + } |
|
| 520 | + if (isset($hauteur_img[$src])) { |
|
| 521 | + $srcHeight = $hauteur_img[$src]; |
|
| 522 | + } |
|
| 523 | + if (!$srcWidth or !$srcHeight) { |
|
| 524 | + |
|
| 525 | + if (file_exists($src) |
|
| 526 | + and $srcsize = spip_getimagesize($src) |
|
| 527 | + ) { |
|
| 528 | + if (!$srcWidth) { |
|
| 529 | + $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 530 | + } |
|
| 531 | + if (!$srcHeight) { |
|
| 532 | + $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 536 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 537 | + elseif (@file_exists($f = "$src.src") |
|
| 538 | + and lire_fichier($f, $valeurs) |
|
| 539 | + and $valeurs = unserialize($valeurs) |
|
| 540 | + ) { |
|
| 541 | + if (!$srcWidth) { |
|
| 542 | + $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 543 | + } |
|
| 544 | + if (!$srcHeight) { |
|
| 545 | + $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return array($srcHeight, $srcWidth); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -565,12 +565,12 @@ discard block |
||
| 565 | 565 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 566 | 566 | **/ |
| 567 | 567 | function largeur($img) { |
| 568 | - if (!$img) { |
|
| 569 | - return; |
|
| 570 | - } |
|
| 571 | - list($h, $l) = taille_image($img); |
|
| 568 | + if (!$img) { |
|
| 569 | + return; |
|
| 570 | + } |
|
| 571 | + list($h, $l) = taille_image($img); |
|
| 572 | 572 | |
| 573 | - return $l; |
|
| 573 | + return $l; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -587,12 +587,12 @@ discard block |
||
| 587 | 587 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 588 | 588 | **/ |
| 589 | 589 | function hauteur($img) { |
| 590 | - if (!$img) { |
|
| 591 | - return; |
|
| 592 | - } |
|
| 593 | - list($h, $l) = taille_image($img); |
|
| 590 | + if (!$img) { |
|
| 591 | + return; |
|
| 592 | + } |
|
| 593 | + list($h, $l) = taille_image($img); |
|
| 594 | 594 | |
| 595 | - return $h; |
|
| 595 | + return $h; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | |
@@ -612,11 +612,11 @@ discard block |
||
| 612 | 612 | * @return string |
| 613 | 613 | **/ |
| 614 | 614 | function corriger_entites_html($texte) { |
| 615 | - if (strpos($texte, '&') === false) { |
|
| 616 | - return $texte; |
|
| 617 | - } |
|
| 615 | + if (strpos($texte, '&') === false) { |
|
| 616 | + return $texte; |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 619 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -631,11 +631,11 @@ discard block |
||
| 631 | 631 | * @return string |
| 632 | 632 | **/ |
| 633 | 633 | function corriger_toutes_entites_html($texte) { |
| 634 | - if (strpos($texte, '&') === false) { |
|
| 635 | - return $texte; |
|
| 636 | - } |
|
| 634 | + if (strpos($texte, '&') === false) { |
|
| 635 | + return $texte; |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 638 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | * @return string |
| 646 | 646 | **/ |
| 647 | 647 | function proteger_amp($texte) { |
| 648 | - return str_replace('&', '&', $texte); |
|
| 648 | + return str_replace('&', '&', $texte); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -676,20 +676,20 @@ discard block |
||
| 676 | 676 | * @return mixed|string |
| 677 | 677 | */ |
| 678 | 678 | function entites_html($texte, $tout = false, $quote = true) { |
| 679 | - if (!is_string($texte) or !$texte |
|
| 680 | - or strpbrk($texte, "&\"'<>") == false |
|
| 681 | - ) { |
|
| 682 | - return $texte; |
|
| 683 | - } |
|
| 684 | - include_spip('inc/texte'); |
|
| 685 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 686 | - $flags |= ENT_HTML401; |
|
| 687 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 688 | - if ($tout) { |
|
| 689 | - return corriger_toutes_entites_html($texte); |
|
| 690 | - } else { |
|
| 691 | - return corriger_entites_html($texte); |
|
| 692 | - } |
|
| 679 | + if (!is_string($texte) or !$texte |
|
| 680 | + or strpbrk($texte, "&\"'<>") == false |
|
| 681 | + ) { |
|
| 682 | + return $texte; |
|
| 683 | + } |
|
| 684 | + include_spip('inc/texte'); |
|
| 685 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 686 | + $flags |= ENT_HTML401; |
|
| 687 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 688 | + if ($tout) { |
|
| 689 | + return corriger_toutes_entites_html($texte); |
|
| 690 | + } else { |
|
| 691 | + return corriger_entites_html($texte); |
|
| 692 | + } |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -708,37 +708,37 @@ discard block |
||
| 708 | 708 | * Texte converti |
| 709 | 709 | **/ |
| 710 | 710 | function filtrer_entites($texte) { |
| 711 | - if (strpos($texte, '&') === false) { |
|
| 712 | - return $texte; |
|
| 713 | - } |
|
| 714 | - // filtrer |
|
| 715 | - $texte = html2unicode($texte); |
|
| 716 | - // remettre le tout dans le charset cible |
|
| 717 | - $texte = unicode2charset($texte); |
|
| 718 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 719 | - // (on le faisait deja avec un ") |
|
| 720 | - if (strpos($texte, "&#") !== false) { |
|
| 721 | - $texte = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $texte); |
|
| 722 | - } |
|
| 711 | + if (strpos($texte, '&') === false) { |
|
| 712 | + return $texte; |
|
| 713 | + } |
|
| 714 | + // filtrer |
|
| 715 | + $texte = html2unicode($texte); |
|
| 716 | + // remettre le tout dans le charset cible |
|
| 717 | + $texte = unicode2charset($texte); |
|
| 718 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 719 | + // (on le faisait deja avec un ") |
|
| 720 | + if (strpos($texte, "&#") !== false) { |
|
| 721 | + $texte = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $texte); |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - return $texte; |
|
| 724 | + return $texte; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
| 728 | 728 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 729 | - /** |
|
| 730 | - * Version sécurisée de filtrer_entites |
|
| 731 | - * |
|
| 732 | - * @uses interdire_scripts() |
|
| 733 | - * @uses filtrer_entites() |
|
| 734 | - * |
|
| 735 | - * @param string $t |
|
| 736 | - * @return string |
|
| 737 | - */ |
|
| 738 | - function filtre_filtrer_entites_dist($t) { |
|
| 739 | - include_spip('inc/texte'); |
|
| 740 | - return interdire_scripts(filtrer_entites($t)); |
|
| 741 | - } |
|
| 729 | + /** |
|
| 730 | + * Version sécurisée de filtrer_entites |
|
| 731 | + * |
|
| 732 | + * @uses interdire_scripts() |
|
| 733 | + * @uses filtrer_entites() |
|
| 734 | + * |
|
| 735 | + * @param string $t |
|
| 736 | + * @return string |
|
| 737 | + */ |
|
| 738 | + function filtre_filtrer_entites_dist($t) { |
|
| 739 | + include_spip('inc/texte'); |
|
| 740 | + return interdire_scripts(filtrer_entites($t)); |
|
| 741 | + } |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
@@ -753,18 +753,18 @@ discard block |
||
| 753 | 753 | * @return string|array |
| 754 | 754 | **/ |
| 755 | 755 | function supprimer_caracteres_illegaux($texte) { |
| 756 | - 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"; |
|
| 757 | - static $to = null; |
|
| 756 | + 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"; |
|
| 757 | + static $to = null; |
|
| 758 | 758 | |
| 759 | - if (is_array($texte)) { |
|
| 760 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 761 | - } |
|
| 759 | + if (is_array($texte)) { |
|
| 760 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - if (!$to) { |
|
| 764 | - $to = str_repeat('-', strlen($from)); |
|
| 765 | - } |
|
| 763 | + if (!$to) { |
|
| 764 | + $to = str_repeat('-', strlen($from)); |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - return strtr($texte, $from, $to); |
|
| 767 | + return strtr($texte, $from, $to); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -776,10 +776,10 @@ discard block |
||
| 776 | 776 | * @return string|array |
| 777 | 777 | **/ |
| 778 | 778 | function corriger_caracteres($texte) { |
| 779 | - $texte = corriger_caracteres_windows($texte); |
|
| 780 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 779 | + $texte = corriger_caracteres_windows($texte); |
|
| 780 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 781 | 781 | |
| 782 | - return $texte; |
|
| 782 | + return $texte; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /** |
@@ -797,40 +797,40 @@ discard block |
||
| 797 | 797 | */ |
| 798 | 798 | function texte_backend($texte) { |
| 799 | 799 | |
| 800 | - static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 800 | + static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 801 | 801 | |
| 802 | - // si on a des liens ou des images, les passer en absolu |
|
| 803 | - $texte = liens_absolus($texte); |
|
| 802 | + // si on a des liens ou des images, les passer en absolu |
|
| 803 | + $texte = liens_absolus($texte); |
|
| 804 | 804 | |
| 805 | - // echapper les tags > < |
|
| 806 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 805 | + // echapper les tags > < |
|
| 806 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 807 | 807 | |
| 808 | - // importer les é |
|
| 809 | - $texte = filtrer_entites($texte); |
|
| 808 | + // importer les é |
|
| 809 | + $texte = filtrer_entites($texte); |
|
| 810 | 810 | |
| 811 | - // " -> " et tout ce genre de choses |
|
| 812 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 813 | - $texte = str_replace(" ", " ", $texte); |
|
| 814 | - $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 815 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 816 | - $texte = entites_html($texte, false, false); |
|
| 817 | - // mais bien echapper les double quotes ! |
|
| 818 | - $texte = str_replace('"', '"', $texte); |
|
| 811 | + // " -> " et tout ce genre de choses |
|
| 812 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 813 | + $texte = str_replace(" ", " ", $texte); |
|
| 814 | + $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 815 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 816 | + $texte = entites_html($texte, false, false); |
|
| 817 | + // mais bien echapper les double quotes ! |
|
| 818 | + $texte = str_replace('"', '"', $texte); |
|
| 819 | 819 | |
| 820 | - // verifier le charset |
|
| 821 | - $texte = charset2unicode($texte); |
|
| 820 | + // verifier le charset |
|
| 821 | + $texte = charset2unicode($texte); |
|
| 822 | 822 | |
| 823 | - // Caracteres problematiques en iso-latin 1 |
|
| 824 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 825 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 826 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 827 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 828 | - } |
|
| 823 | + // Caracteres problematiques en iso-latin 1 |
|
| 824 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 825 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 826 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 827 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 828 | + } |
|
| 829 | 829 | |
| 830 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 831 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 832 | - // ==> on les remplace par l'entite HTML |
|
| 833 | - return str_replace($apostrophe, "'", $texte); |
|
| 830 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 831 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 832 | + // ==> on les remplace par l'entite HTML |
|
| 833 | + return str_replace($apostrophe, "'", $texte); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /** |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | * Texte encodé et quote pour XML |
| 848 | 848 | */ |
| 849 | 849 | function texte_backendq($texte) { |
| 850 | - return addslashes(texte_backend($texte)); |
|
| 850 | + return addslashes(texte_backend($texte)); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | |
@@ -870,9 +870,9 @@ discard block |
||
| 870 | 870 | * Numéro de titre, sinon chaîne vide |
| 871 | 871 | **/ |
| 872 | 872 | function supprimer_numero($texte) { |
| 873 | - return preg_replace( |
|
| 874 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 875 | - "", $texte); |
|
| 873 | + return preg_replace( |
|
| 874 | + ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 875 | + "", $texte); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -895,13 +895,13 @@ discard block |
||
| 895 | 895 | * Numéro de titre, sinon chaîne vide |
| 896 | 896 | **/ |
| 897 | 897 | function recuperer_numero($texte) { |
| 898 | - if (preg_match( |
|
| 899 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 900 | - $texte, $regs)) { |
|
| 901 | - return strval($regs[1]); |
|
| 902 | - } else { |
|
| 903 | - return ''; |
|
| 904 | - } |
|
| 898 | + if (preg_match( |
|
| 899 | + ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 900 | + $texte, $regs)) { |
|
| 901 | + return strval($regs[1]); |
|
| 902 | + } else { |
|
| 903 | + return ''; |
|
| 904 | + } |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -928,13 +928,13 @@ discard block |
||
| 928 | 928 | * Texte converti |
| 929 | 929 | **/ |
| 930 | 930 | function supprimer_tags($texte, $rempl = "") { |
| 931 | - $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte); |
|
| 932 | - // ne pas oublier un < final non ferme car coupe |
|
| 933 | - $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte); |
|
| 934 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 935 | - $texte = str_replace('<', '<', $texte); |
|
| 931 | + $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte); |
|
| 932 | + // ne pas oublier un < final non ferme car coupe |
|
| 933 | + $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte); |
|
| 934 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 935 | + $texte = str_replace('<', '<', $texte); |
|
| 936 | 936 | |
| 937 | - return $texte; |
|
| 937 | + return $texte; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -957,9 +957,9 @@ discard block |
||
| 957 | 957 | * Texte converti |
| 958 | 958 | **/ |
| 959 | 959 | function echapper_tags($texte, $rempl = "") { |
| 960 | - $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 960 | + $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 961 | 961 | |
| 962 | - return $texte; |
|
| 962 | + return $texte; |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -980,18 +980,18 @@ discard block |
||
| 980 | 980 | * Texte converti |
| 981 | 981 | **/ |
| 982 | 982 | function textebrut($texte) { |
| 983 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 984 | - $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 985 | - $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 986 | - $texte = preg_replace("/^\n+/", "", $texte); |
|
| 987 | - $texte = preg_replace("/\n+$/", "", $texte); |
|
| 988 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 989 | - $texte = supprimer_tags($texte); |
|
| 990 | - $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 991 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 992 | - $texte = str_replace("’", "'", $texte); |
|
| 983 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 984 | + $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 985 | + $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 986 | + $texte = preg_replace("/^\n+/", "", $texte); |
|
| 987 | + $texte = preg_replace("/\n+$/", "", $texte); |
|
| 988 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 989 | + $texte = supprimer_tags($texte); |
|
| 990 | + $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 991 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 992 | + $texte = str_replace("’", "'", $texte); |
|
| 993 | 993 | |
| 994 | - return $texte; |
|
| 994 | + return $texte; |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | |
@@ -1007,17 +1007,17 @@ discard block |
||
| 1007 | 1007 | * Texte avec liens ouvrants |
| 1008 | 1008 | **/ |
| 1009 | 1009 | function liens_ouvrants($texte) { |
| 1010 | - if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1011 | - $texte, $liens, PREG_PATTERN_ORDER)) { |
|
| 1012 | - foreach ($liens[0] as $a) { |
|
| 1013 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1014 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1015 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1016 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1010 | + if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1011 | + $texte, $liens, PREG_PATTERN_ORDER)) { |
|
| 1012 | + foreach ($liens[0] as $a) { |
|
| 1013 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1014 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1015 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1016 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | - return $texte; |
|
| 1020 | + return $texte; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | /** |
@@ -1027,22 +1027,22 @@ discard block |
||
| 1027 | 1027 | * @return string |
| 1028 | 1028 | */ |
| 1029 | 1029 | function liens_nofollow($texte) { |
| 1030 | - if (stripos($texte, "<a") === false) { |
|
| 1031 | - return $texte; |
|
| 1032 | - } |
|
| 1030 | + if (stripos($texte, "<a") === false) { |
|
| 1031 | + return $texte; |
|
| 1032 | + } |
|
| 1033 | 1033 | |
| 1034 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1035 | - foreach ($regs[0] as $a) { |
|
| 1036 | - $rel = extraire_attribut($a, "rel"); |
|
| 1037 | - if (strpos($rel, "nofollow") === false) { |
|
| 1038 | - $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1039 | - $anofollow = inserer_attribut($a, "rel", $rel); |
|
| 1040 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1034 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1035 | + foreach ($regs[0] as $a) { |
|
| 1036 | + $rel = extraire_attribut($a, "rel"); |
|
| 1037 | + if (strpos($rel, "nofollow") === false) { |
|
| 1038 | + $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1039 | + $anofollow = inserer_attribut($a, "rel", $rel); |
|
| 1040 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | 1044 | |
| 1045 | - return $texte; |
|
| 1045 | + return $texte; |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1061,12 +1061,12 @@ discard block |
||
| 1061 | 1061 | * Texte sans paraghaphes |
| 1062 | 1062 | **/ |
| 1063 | 1063 | function PtoBR($texte) { |
| 1064 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1065 | - $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 1066 | - $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 1067 | - $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1064 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1065 | + $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 1066 | + $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 1067 | + $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1068 | 1068 | |
| 1069 | - return $texte; |
|
| 1069 | + return $texte; |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | |
@@ -1090,14 +1090,14 @@ discard block |
||
| 1090 | 1090 | * @return string Texte encadré du style CSS |
| 1091 | 1091 | */ |
| 1092 | 1092 | function lignes_longues($texte) { |
| 1093 | - if (!strlen(trim($texte))) { |
|
| 1094 | - return $texte; |
|
| 1095 | - } |
|
| 1096 | - include_spip('inc/texte'); |
|
| 1097 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1098 | - 'div' : 'span'; |
|
| 1093 | + if (!strlen(trim($texte))) { |
|
| 1094 | + return $texte; |
|
| 1095 | + } |
|
| 1096 | + include_spip('inc/texte'); |
|
| 1097 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1098 | + 'div' : 'span'; |
|
| 1099 | 1099 | |
| 1100 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1100 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
@@ -1116,30 +1116,30 @@ discard block |
||
| 1116 | 1116 | * @return string Texte en majuscule |
| 1117 | 1117 | */ |
| 1118 | 1118 | function majuscules($texte) { |
| 1119 | - if (!strlen($texte)) { |
|
| 1120 | - return ''; |
|
| 1121 | - } |
|
| 1119 | + if (!strlen($texte)) { |
|
| 1120 | + return ''; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - // Cas du turc |
|
| 1124 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1125 | - # remplacer hors des tags et des entites |
|
| 1126 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1127 | - foreach ($regs as $n => $match) { |
|
| 1128 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1123 | + // Cas du turc |
|
| 1124 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1125 | + # remplacer hors des tags et des entites |
|
| 1126 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1127 | + foreach ($regs as $n => $match) { |
|
| 1128 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | 1131 | |
| 1132 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1132 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1133 | 1133 | |
| 1134 | - if ($regs) { |
|
| 1135 | - foreach ($regs as $n => $match) { |
|
| 1136 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1134 | + if ($regs) { |
|
| 1135 | + foreach ($regs as $n => $match) { |
|
| 1136 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | 1140 | |
| 1141 | - // Cas general |
|
| 1142 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1141 | + // Cas general |
|
| 1142 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1157,29 +1157,29 @@ discard block |
||
| 1157 | 1157 | * @return string |
| 1158 | 1158 | **/ |
| 1159 | 1159 | function taille_en_octets($taille) { |
| 1160 | - if (!defined('_KILOBYTE')) { |
|
| 1161 | - /** |
|
| 1162 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1163 | - * |
|
| 1164 | - * @var int |
|
| 1165 | - **/ |
|
| 1166 | - define('_KILOBYTE', 1024); |
|
| 1167 | - } |
|
| 1160 | + if (!defined('_KILOBYTE')) { |
|
| 1161 | + /** |
|
| 1162 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1163 | + * |
|
| 1164 | + * @var int |
|
| 1165 | + **/ |
|
| 1166 | + define('_KILOBYTE', 1024); |
|
| 1167 | + } |
|
| 1168 | 1168 | |
| 1169 | - if ($taille < 1) { |
|
| 1170 | - return ''; |
|
| 1171 | - } |
|
| 1172 | - if ($taille < _KILOBYTE) { |
|
| 1173 | - $taille = _T('taille_octets', array('taille' => $taille)); |
|
| 1174 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1175 | - $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1))); |
|
| 1176 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1177 | - $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1))); |
|
| 1178 | - } else { |
|
| 1179 | - $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2))); |
|
| 1180 | - } |
|
| 1169 | + if ($taille < 1) { |
|
| 1170 | + return ''; |
|
| 1171 | + } |
|
| 1172 | + if ($taille < _KILOBYTE) { |
|
| 1173 | + $taille = _T('taille_octets', array('taille' => $taille)); |
|
| 1174 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1175 | + $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1))); |
|
| 1176 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1177 | + $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1))); |
|
| 1178 | + } else { |
|
| 1179 | + $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2))); |
|
| 1180 | + } |
|
| 1181 | 1181 | |
| 1182 | - return $taille; |
|
| 1182 | + return $taille; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | |
@@ -1201,15 +1201,15 @@ discard block |
||
| 1201 | 1201 | * Texte prêt pour être utilisé en attribut HTML |
| 1202 | 1202 | **/ |
| 1203 | 1203 | function attribut_html($texte, $textebrut = true) { |
| 1204 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1205 | - if ($textebrut) { |
|
| 1206 | - $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1207 | - } |
|
| 1208 | - $texte = texte_backend($texte); |
|
| 1209 | - $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
|
| 1204 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1205 | + if ($textebrut) { |
|
| 1206 | + $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1207 | + } |
|
| 1208 | + $texte = texte_backend($texte); |
|
| 1209 | + $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
|
| 1210 | 1210 | |
| 1211 | - return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&"), |
|
| 1212 | - $texte); |
|
| 1211 | + return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&"), |
|
| 1212 | + $texte); |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | |
@@ -1229,12 +1229,12 @@ discard block |
||
| 1229 | 1229 | * URL ou chaîne vide |
| 1230 | 1230 | **/ |
| 1231 | 1231 | function vider_url($url, $entites = true) { |
| 1232 | - # un message pour abs_url |
|
| 1233 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1234 | - $url = trim($url); |
|
| 1235 | - $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1232 | + # un message pour abs_url |
|
| 1233 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1234 | + $url = trim($url); |
|
| 1235 | + $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1236 | 1236 | |
| 1237 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1237 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | |
@@ -1249,10 +1249,10 @@ discard block |
||
| 1249 | 1249 | * @return string Adresse email maquillée |
| 1250 | 1250 | **/ |
| 1251 | 1251 | function antispam($texte) { |
| 1252 | - include_spip('inc/acces'); |
|
| 1253 | - $masque = creer_pass_aleatoire(3); |
|
| 1252 | + include_spip('inc/acces'); |
|
| 1253 | + $masque = creer_pass_aleatoire(3); |
|
| 1254 | 1254 | |
| 1255 | - return preg_replace("/@/", " $masque ", $texte); |
|
| 1255 | + return preg_replace("/@/", " $masque ", $texte); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | /** |
@@ -1284,12 +1284,12 @@ discard block |
||
| 1284 | 1284 | * True si on a le droit d'accès, false sinon. |
| 1285 | 1285 | **/ |
| 1286 | 1286 | function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1287 | - include_spip('inc/acces'); |
|
| 1288 | - if ($op) { |
|
| 1289 | - $dir .= " $op $args"; |
|
| 1290 | - } |
|
| 1287 | + include_spip('inc/acces'); |
|
| 1288 | + if ($op) { |
|
| 1289 | + $dir .= " $op $args"; |
|
| 1290 | + } |
|
| 1291 | 1291 | |
| 1292 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1292 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | /** |
@@ -1314,11 +1314,11 @@ discard block |
||
| 1314 | 1314 | * Retourne $texte, sinon $sinon. |
| 1315 | 1315 | **/ |
| 1316 | 1316 | function sinon($texte, $sinon = '') { |
| 1317 | - if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1318 | - return $texte; |
|
| 1319 | - } else { |
|
| 1320 | - return $sinon; |
|
| 1321 | - } |
|
| 1317 | + if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1318 | + return $texte; |
|
| 1319 | + } else { |
|
| 1320 | + return $sinon; |
|
| 1321 | + } |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | /** |
@@ -1342,7 +1342,7 @@ discard block |
||
| 1342 | 1342 | * @return mixed |
| 1343 | 1343 | **/ |
| 1344 | 1344 | function choixsivide($a, $vide, $pasvide) { |
| 1345 | - return $a ? $pasvide : $vide; |
|
| 1345 | + return $a ? $pasvide : $vide; |
|
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | 1348 | /** |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | * @return mixed |
| 1367 | 1367 | **/ |
| 1368 | 1368 | function choixsiegal($a1, $a2, $v, $f) { |
| 1369 | - return ($a1 == $a2) ? $v : $f; |
|
| 1369 | + return ($a1 == $a2) ? $v : $f; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | // |
@@ -1385,13 +1385,13 @@ discard block |
||
| 1385 | 1385 | * @return string |
| 1386 | 1386 | **/ |
| 1387 | 1387 | function filtrer_ical($texte) { |
| 1388 | - #include_spip('inc/charsets'); |
|
| 1389 | - $texte = html2unicode($texte); |
|
| 1390 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1391 | - $texte = preg_replace("/\n/", " ", $texte); |
|
| 1392 | - $texte = preg_replace("/,/", "\,", $texte); |
|
| 1388 | + #include_spip('inc/charsets'); |
|
| 1389 | + $texte = html2unicode($texte); |
|
| 1390 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1391 | + $texte = preg_replace("/\n/", " ", $texte); |
|
| 1392 | + $texte = preg_replace("/,/", "\,", $texte); |
|
| 1393 | 1393 | |
| 1394 | - return $texte; |
|
| 1394 | + return $texte; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | |
@@ -1416,53 +1416,53 @@ discard block |
||
| 1416 | 1416 | * @return string |
| 1417 | 1417 | **/ |
| 1418 | 1418 | function post_autobr($texte, $delim = "\n_ ") { |
| 1419 | - if (!function_exists('echappe_html')) { |
|
| 1420 | - include_spip('inc/texte_mini'); |
|
| 1421 | - } |
|
| 1422 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1423 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1424 | - |
|
| 1425 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1426 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1427 | - } else { |
|
| 1428 | - $fin = ''; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - $texte = echappe_html($texte, '', true); |
|
| 1432 | - |
|
| 1433 | - // echapper les modeles |
|
| 1434 | - if (strpos($texte, "<") !== false) { |
|
| 1435 | - include_spip('inc/lien'); |
|
| 1436 | - if (defined('_PREG_MODELE')) { |
|
| 1437 | - $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1438 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - $debut = ''; |
|
| 1443 | - $suite = $texte; |
|
| 1444 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1445 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1446 | - $suite = substr($suite, $t); |
|
| 1447 | - $car = substr($suite, 0, 1); |
|
| 1448 | - if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}") |
|
| 1449 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1450 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1451 | - ) { |
|
| 1452 | - $debut .= $delim; |
|
| 1453 | - } else { |
|
| 1454 | - $debut .= "\n"; |
|
| 1455 | - } |
|
| 1456 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1457 | - $debut .= $regs[0]; |
|
| 1458 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1459 | - } |
|
| 1460 | - } |
|
| 1461 | - $texte = $debut . $suite; |
|
| 1462 | - |
|
| 1463 | - $texte = echappe_retour($texte); |
|
| 1464 | - |
|
| 1465 | - return $texte . $fin; |
|
| 1419 | + if (!function_exists('echappe_html')) { |
|
| 1420 | + include_spip('inc/texte_mini'); |
|
| 1421 | + } |
|
| 1422 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1423 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1424 | + |
|
| 1425 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1426 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1427 | + } else { |
|
| 1428 | + $fin = ''; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + $texte = echappe_html($texte, '', true); |
|
| 1432 | + |
|
| 1433 | + // echapper les modeles |
|
| 1434 | + if (strpos($texte, "<") !== false) { |
|
| 1435 | + include_spip('inc/lien'); |
|
| 1436 | + if (defined('_PREG_MODELE')) { |
|
| 1437 | + $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1438 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + $debut = ''; |
|
| 1443 | + $suite = $texte; |
|
| 1444 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1445 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1446 | + $suite = substr($suite, $t); |
|
| 1447 | + $car = substr($suite, 0, 1); |
|
| 1448 | + if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}") |
|
| 1449 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1450 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1451 | + ) { |
|
| 1452 | + $debut .= $delim; |
|
| 1453 | + } else { |
|
| 1454 | + $debut .= "\n"; |
|
| 1455 | + } |
|
| 1456 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1457 | + $debut .= $regs[0]; |
|
| 1458 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1459 | + } |
|
| 1460 | + } |
|
| 1461 | + $texte = $debut . $suite; |
|
| 1462 | + |
|
| 1463 | + $texte = echappe_retour($texte); |
|
| 1464 | + |
|
| 1465 | + return $texte . $fin; |
|
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | |
@@ -1503,46 +1503,46 @@ discard block |
||
| 1503 | 1503 | * @return string |
| 1504 | 1504 | **/ |
| 1505 | 1505 | function extraire_idiome($letexte, $lang = null, $options = array()) { |
| 1506 | - static $traduire = false; |
|
| 1507 | - if ($letexte |
|
| 1508 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1509 | - ) { |
|
| 1510 | - if (!$traduire) { |
|
| 1511 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1512 | - include_spip('inc/lang'); |
|
| 1513 | - } |
|
| 1514 | - if (!$lang) { |
|
| 1515 | - $lang = $GLOBALS['spip_lang']; |
|
| 1516 | - } |
|
| 1517 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1518 | - if (is_bool($options)) { |
|
| 1519 | - $options = array('echappe_span' => $options); |
|
| 1520 | - } |
|
| 1521 | - if (!isset($options['echappe_span'])) { |
|
| 1522 | - $options = array_merge($options, array('echappe_span' => false)); |
|
| 1523 | - } |
|
| 1524 | - |
|
| 1525 | - foreach ($regs as $reg) { |
|
| 1526 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1527 | - $desc = $traduire($cle, $lang, true); |
|
| 1528 | - $l = $desc->langue; |
|
| 1529 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1530 | - if (strlen($desc->texte)) { |
|
| 1531 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1532 | - if ($l !== $lang) { |
|
| 1533 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1534 | - } |
|
| 1535 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1536 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1537 | - } |
|
| 1538 | - if (!$options['echappe_span']) { |
|
| 1539 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1540 | - } |
|
| 1541 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - return $letexte; |
|
| 1506 | + static $traduire = false; |
|
| 1507 | + if ($letexte |
|
| 1508 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1509 | + ) { |
|
| 1510 | + if (!$traduire) { |
|
| 1511 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1512 | + include_spip('inc/lang'); |
|
| 1513 | + } |
|
| 1514 | + if (!$lang) { |
|
| 1515 | + $lang = $GLOBALS['spip_lang']; |
|
| 1516 | + } |
|
| 1517 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1518 | + if (is_bool($options)) { |
|
| 1519 | + $options = array('echappe_span' => $options); |
|
| 1520 | + } |
|
| 1521 | + if (!isset($options['echappe_span'])) { |
|
| 1522 | + $options = array_merge($options, array('echappe_span' => false)); |
|
| 1523 | + } |
|
| 1524 | + |
|
| 1525 | + foreach ($regs as $reg) { |
|
| 1526 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1527 | + $desc = $traduire($cle, $lang, true); |
|
| 1528 | + $l = $desc->langue; |
|
| 1529 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1530 | + if (strlen($desc->texte)) { |
|
| 1531 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1532 | + if ($l !== $lang) { |
|
| 1533 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1534 | + } |
|
| 1535 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1536 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1537 | + } |
|
| 1538 | + if (!$options['echappe_span']) { |
|
| 1539 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1540 | + } |
|
| 1541 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + return $letexte; |
|
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | 1548 | /** |
@@ -1594,64 +1594,64 @@ discard block |
||
| 1594 | 1594 | **/ |
| 1595 | 1595 | function extraire_multi($letexte, $lang = null, $options = array()) { |
| 1596 | 1596 | |
| 1597 | - if ($letexte |
|
| 1598 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1599 | - ) { |
|
| 1600 | - if (!$lang) { |
|
| 1601 | - $lang = $GLOBALS['spip_lang']; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1605 | - if (is_bool($options)) { |
|
| 1606 | - $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT); |
|
| 1607 | - } |
|
| 1608 | - if (!isset($options['echappe_span'])) { |
|
| 1609 | - $options = array_merge($options, array('echappe_span' => false)); |
|
| 1610 | - } |
|
| 1611 | - if (!isset($options['lang_defaut'])) { |
|
| 1612 | - $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT)); |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - include_spip('inc/lang'); |
|
| 1616 | - foreach ($regs as $reg) { |
|
| 1617 | - // chercher la version de la langue courante |
|
| 1618 | - $trads = extraire_trads($reg[1]); |
|
| 1619 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1620 | - $trad = $trads[$l]; |
|
| 1621 | - } else { |
|
| 1622 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1623 | - $trad = ''; |
|
| 1624 | - } else { |
|
| 1625 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1626 | - // ou la premiere dispo |
|
| 1627 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1628 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1629 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1630 | - $l = key($trads); |
|
| 1631 | - } |
|
| 1632 | - $trad = $trads[$l]; |
|
| 1633 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1634 | - $trad = $typographie($trad); |
|
| 1635 | - // Tester si on echappe en span ou en div |
|
| 1636 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1637 | - include_spip('inc/texte'); |
|
| 1638 | - $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
|
| 1639 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1640 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1641 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1642 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1643 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1644 | - } |
|
| 1645 | - if (!$options['echappe_span']) { |
|
| 1646 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1647 | - } |
|
| 1648 | - } |
|
| 1649 | - } |
|
| 1650 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1651 | - } |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - return $letexte; |
|
| 1597 | + if ($letexte |
|
| 1598 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1599 | + ) { |
|
| 1600 | + if (!$lang) { |
|
| 1601 | + $lang = $GLOBALS['spip_lang']; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1605 | + if (is_bool($options)) { |
|
| 1606 | + $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT); |
|
| 1607 | + } |
|
| 1608 | + if (!isset($options['echappe_span'])) { |
|
| 1609 | + $options = array_merge($options, array('echappe_span' => false)); |
|
| 1610 | + } |
|
| 1611 | + if (!isset($options['lang_defaut'])) { |
|
| 1612 | + $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT)); |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + include_spip('inc/lang'); |
|
| 1616 | + foreach ($regs as $reg) { |
|
| 1617 | + // chercher la version de la langue courante |
|
| 1618 | + $trads = extraire_trads($reg[1]); |
|
| 1619 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1620 | + $trad = $trads[$l]; |
|
| 1621 | + } else { |
|
| 1622 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1623 | + $trad = ''; |
|
| 1624 | + } else { |
|
| 1625 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1626 | + // ou la premiere dispo |
|
| 1627 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1628 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1629 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1630 | + $l = key($trads); |
|
| 1631 | + } |
|
| 1632 | + $trad = $trads[$l]; |
|
| 1633 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1634 | + $trad = $typographie($trad); |
|
| 1635 | + // Tester si on echappe en span ou en div |
|
| 1636 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1637 | + include_spip('inc/texte'); |
|
| 1638 | + $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
|
| 1639 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1640 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1641 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1642 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1643 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1644 | + } |
|
| 1645 | + if (!$options['echappe_span']) { |
|
| 1646 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1647 | + } |
|
| 1648 | + } |
|
| 1649 | + } |
|
| 1650 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1651 | + } |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + return $letexte; |
|
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | /** |
@@ -1667,20 +1667,20 @@ discard block |
||
| 1667 | 1667 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1668 | 1668 | **/ |
| 1669 | 1669 | function extraire_trads($bloc) { |
| 1670 | - $lang = ''; |
|
| 1670 | + $lang = ''; |
|
| 1671 | 1671 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1672 | 1672 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1673 | - while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1674 | - $texte = trim($regs[1]); |
|
| 1675 | - if ($texte or $lang) { |
|
| 1676 | - $trads[$lang] = $texte; |
|
| 1677 | - } |
|
| 1678 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1679 | - $lang = $regs[2]; |
|
| 1680 | - } |
|
| 1681 | - $trads[$lang] = $bloc; |
|
| 1673 | + while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1674 | + $texte = trim($regs[1]); |
|
| 1675 | + if ($texte or $lang) { |
|
| 1676 | + $trads[$lang] = $texte; |
|
| 1677 | + } |
|
| 1678 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1679 | + $lang = $regs[2]; |
|
| 1680 | + } |
|
| 1681 | + $trads[$lang] = $bloc; |
|
| 1682 | 1682 | |
| 1683 | - return $trads; |
|
| 1683 | + return $trads; |
|
| 1684 | 1684 | } |
| 1685 | 1685 | |
| 1686 | 1686 | |
@@ -1691,7 +1691,7 @@ discard block |
||
| 1691 | 1691 | * @return string L'initiale en majuscule |
| 1692 | 1692 | */ |
| 1693 | 1693 | function filtre_initiale($nom) { |
| 1694 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1694 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | 1697 | |
@@ -1736,33 +1736,33 @@ discard block |
||
| 1736 | 1736 | * - null (interne) : si on empile |
| 1737 | 1737 | **/ |
| 1738 | 1738 | function unique($donnee, $famille = '', $cpt = false) { |
| 1739 | - static $mem = array(); |
|
| 1740 | - // permettre de vider la pile et de la restaurer |
|
| 1741 | - // pour le calcul de introduction... |
|
| 1742 | - if ($famille == '_spip_raz_') { |
|
| 1743 | - $tmp = $mem; |
|
| 1744 | - $mem = array(); |
|
| 1745 | - |
|
| 1746 | - return $tmp; |
|
| 1747 | - } elseif ($famille == '_spip_set_') { |
|
| 1748 | - $mem = $donnee; |
|
| 1749 | - |
|
| 1750 | - return; |
|
| 1751 | - } |
|
| 1752 | - // eviter une notice |
|
| 1753 | - if (!isset($mem[$famille])) { |
|
| 1754 | - $mem[$famille] = array(); |
|
| 1755 | - } |
|
| 1756 | - if ($cpt) { |
|
| 1757 | - return count($mem[$famille]); |
|
| 1758 | - } |
|
| 1759 | - // eviter une notice |
|
| 1760 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1761 | - $mem[$famille][$donnee] = 0; |
|
| 1762 | - } |
|
| 1763 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1764 | - return $donnee; |
|
| 1765 | - } |
|
| 1739 | + static $mem = array(); |
|
| 1740 | + // permettre de vider la pile et de la restaurer |
|
| 1741 | + // pour le calcul de introduction... |
|
| 1742 | + if ($famille == '_spip_raz_') { |
|
| 1743 | + $tmp = $mem; |
|
| 1744 | + $mem = array(); |
|
| 1745 | + |
|
| 1746 | + return $tmp; |
|
| 1747 | + } elseif ($famille == '_spip_set_') { |
|
| 1748 | + $mem = $donnee; |
|
| 1749 | + |
|
| 1750 | + return; |
|
| 1751 | + } |
|
| 1752 | + // eviter une notice |
|
| 1753 | + if (!isset($mem[$famille])) { |
|
| 1754 | + $mem[$famille] = array(); |
|
| 1755 | + } |
|
| 1756 | + if ($cpt) { |
|
| 1757 | + return count($mem[$famille]); |
|
| 1758 | + } |
|
| 1759 | + // eviter une notice |
|
| 1760 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1761 | + $mem[$famille][$donnee] = 0; |
|
| 1762 | + } |
|
| 1763 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1764 | + return $donnee; |
|
| 1765 | + } |
|
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | |
@@ -1790,18 +1790,18 @@ discard block |
||
| 1790 | 1790 | * Une des valeurs en fonction du compteur. |
| 1791 | 1791 | **/ |
| 1792 | 1792 | function alterner($i) { |
| 1793 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1794 | - $num = func_num_args(); |
|
| 1795 | - $args = func_get_args(); |
|
| 1793 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1794 | + $num = func_num_args(); |
|
| 1795 | + $args = func_get_args(); |
|
| 1796 | 1796 | |
| 1797 | - if ($num == 2 && is_array($args[1])) { |
|
| 1798 | - $args = $args[1]; |
|
| 1799 | - array_unshift($args, ''); |
|
| 1800 | - $num = count($args); |
|
| 1801 | - } |
|
| 1797 | + if ($num == 2 && is_array($args[1])) { |
|
| 1798 | + $args = $args[1]; |
|
| 1799 | + array_unshift($args, ''); |
|
| 1800 | + $num = count($args); |
|
| 1801 | + } |
|
| 1802 | 1802 | |
| 1803 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1804 | - return $args[(intval($i) - 1) % ($num - 1) + 1]; |
|
| 1803 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1804 | + return $args[(intval($i) - 1) % ($num - 1) + 1]; |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | |
@@ -1826,46 +1826,46 @@ discard block |
||
| 1826 | 1826 | * - Tableau complet (si 2e argument) |
| 1827 | 1827 | **/ |
| 1828 | 1828 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1829 | - if (is_array($balise)) { |
|
| 1830 | - array_walk( |
|
| 1831 | - $balise, |
|
| 1832 | - function(&$a, $key, $t){ |
|
| 1833 | - $a = extraire_attribut($a, $t); |
|
| 1834 | - }, |
|
| 1835 | - $attribut |
|
| 1836 | - ); |
|
| 1837 | - |
|
| 1838 | - return $balise; |
|
| 1839 | - } |
|
| 1840 | - if (preg_match( |
|
| 1841 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1842 | - . $attribut |
|
| 1843 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1844 | - |
|
| 1845 | - $balise, $r)) { |
|
| 1846 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1847 | - $r[4] = substr($r[3], 1, -1); |
|
| 1848 | - $r[3] = $r[3][0]; |
|
| 1849 | - } elseif ($r[3] !== '') { |
|
| 1850 | - $r[4] = $r[3]; |
|
| 1851 | - $r[3] = ''; |
|
| 1852 | - } else { |
|
| 1853 | - $r[4] = trim($r[2]); |
|
| 1854 | - } |
|
| 1855 | - $att = $r[4]; |
|
| 1856 | - if (strpos($att, "&#") !== false) { |
|
| 1857 | - $att = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $att); |
|
| 1858 | - } |
|
| 1859 | - $att = filtrer_entites($att); |
|
| 1860 | - } else { |
|
| 1861 | - $att = null; |
|
| 1862 | - } |
|
| 1863 | - |
|
| 1864 | - if ($complet) { |
|
| 1865 | - return array($att, $r); |
|
| 1866 | - } else { |
|
| 1867 | - return $att; |
|
| 1868 | - } |
|
| 1829 | + if (is_array($balise)) { |
|
| 1830 | + array_walk( |
|
| 1831 | + $balise, |
|
| 1832 | + function(&$a, $key, $t){ |
|
| 1833 | + $a = extraire_attribut($a, $t); |
|
| 1834 | + }, |
|
| 1835 | + $attribut |
|
| 1836 | + ); |
|
| 1837 | + |
|
| 1838 | + return $balise; |
|
| 1839 | + } |
|
| 1840 | + if (preg_match( |
|
| 1841 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1842 | + . $attribut |
|
| 1843 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1844 | + |
|
| 1845 | + $balise, $r)) { |
|
| 1846 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1847 | + $r[4] = substr($r[3], 1, -1); |
|
| 1848 | + $r[3] = $r[3][0]; |
|
| 1849 | + } elseif ($r[3] !== '') { |
|
| 1850 | + $r[4] = $r[3]; |
|
| 1851 | + $r[3] = ''; |
|
| 1852 | + } else { |
|
| 1853 | + $r[4] = trim($r[2]); |
|
| 1854 | + } |
|
| 1855 | + $att = $r[4]; |
|
| 1856 | + if (strpos($att, "&#") !== false) { |
|
| 1857 | + $att = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $att); |
|
| 1858 | + } |
|
| 1859 | + $att = filtrer_entites($att); |
|
| 1860 | + } else { |
|
| 1861 | + $att = null; |
|
| 1862 | + } |
|
| 1863 | + |
|
| 1864 | + if ($complet) { |
|
| 1865 | + return array($att, $r); |
|
| 1866 | + } else { |
|
| 1867 | + return $att; |
|
| 1868 | + } |
|
| 1869 | 1869 | } |
| 1870 | 1870 | |
| 1871 | 1871 | /** |
@@ -1897,37 +1897,37 @@ discard block |
||
| 1897 | 1897 | * Code html modifié |
| 1898 | 1898 | **/ |
| 1899 | 1899 | function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) { |
| 1900 | - // preparer l'attribut |
|
| 1901 | - // supprimer les etc mais pas les balises html |
|
| 1902 | - // qui ont un sens dans un attribut value d'un input |
|
| 1903 | - if ($proteger) { |
|
| 1904 | - $val = attribut_html($val, false); |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - // echapper les ' pour eviter tout bug |
|
| 1908 | - $val = str_replace("'", "'", $val); |
|
| 1909 | - if ($vider and strlen($val) == 0) { |
|
| 1910 | - $insert = ''; |
|
| 1911 | - } else { |
|
| 1912 | - $insert = " $attribut='$val'"; |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1916 | - |
|
| 1917 | - if ($old !== null) { |
|
| 1918 | - // Remplacer l'ancien attribut du meme nom |
|
| 1919 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1920 | - } else { |
|
| 1921 | - // preferer une balise " />" (comme <img />) |
|
| 1922 | - if (preg_match(',/>,', $balise)) { |
|
| 1923 | - $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1924 | - } // sinon une balise <a ...> ... </a> |
|
| 1925 | - else { |
|
| 1926 | - $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1927 | - } |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - return $balise; |
|
| 1900 | + // preparer l'attribut |
|
| 1901 | + // supprimer les etc mais pas les balises html |
|
| 1902 | + // qui ont un sens dans un attribut value d'un input |
|
| 1903 | + if ($proteger) { |
|
| 1904 | + $val = attribut_html($val, false); |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + // echapper les ' pour eviter tout bug |
|
| 1908 | + $val = str_replace("'", "'", $val); |
|
| 1909 | + if ($vider and strlen($val) == 0) { |
|
| 1910 | + $insert = ''; |
|
| 1911 | + } else { |
|
| 1912 | + $insert = " $attribut='$val'"; |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1916 | + |
|
| 1917 | + if ($old !== null) { |
|
| 1918 | + // Remplacer l'ancien attribut du meme nom |
|
| 1919 | + $balise = $r[1] . $insert . $r[5]; |
|
| 1920 | + } else { |
|
| 1921 | + // preferer une balise " />" (comme <img />) |
|
| 1922 | + if (preg_match(',/>,', $balise)) { |
|
| 1923 | + $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1924 | + } // sinon une balise <a ...> ... </a> |
|
| 1925 | + else { |
|
| 1926 | + $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1927 | + } |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + return $balise; |
|
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | 1933 | /** |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | * @return string Code HTML sans l'attribut |
| 1946 | 1946 | **/ |
| 1947 | 1947 | function vider_attribut($balise, $attribut) { |
| 1948 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 1948 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | |
@@ -1957,9 +1957,9 @@ discard block |
||
| 1957 | 1957 | * @return string |
| 1958 | 1958 | */ |
| 1959 | 1959 | function tester_config($id, $mode = '') { |
| 1960 | - include_spip('action/inscrire_auteur'); |
|
| 1960 | + include_spip('action/inscrire_auteur'); |
|
| 1961 | 1961 | |
| 1962 | - return tester_statut_inscription($mode, $id); |
|
| 1962 | + return tester_statut_inscription($mode, $id); |
|
| 1963 | 1963 | } |
| 1964 | 1964 | |
| 1965 | 1965 | // |
@@ -1984,7 +1984,7 @@ discard block |
||
| 1984 | 1984 | * @return int $a+$b |
| 1985 | 1985 | **/ |
| 1986 | 1986 | function plus($a, $b) { |
| 1987 | - return $a + $b; |
|
| 1987 | + return $a + $b; |
|
| 1988 | 1988 | } |
| 1989 | 1989 | function strplus($a, $b) {return strize('plus', $a, $b);} |
| 1990 | 1990 | /** |
@@ -2003,7 +2003,7 @@ discard block |
||
| 2003 | 2003 | * @return int $a-$b |
| 2004 | 2004 | **/ |
| 2005 | 2005 | function moins($a, $b) { |
| 2006 | - return $a - $b; |
|
| 2006 | + return $a - $b; |
|
| 2007 | 2007 | } |
| 2008 | 2008 | function strmoins($a, $b) {return strize('moins', $a, $b);} |
| 2009 | 2009 | |
@@ -2024,7 +2024,7 @@ discard block |
||
| 2024 | 2024 | * @return int $a*$b |
| 2025 | 2025 | **/ |
| 2026 | 2026 | function mult($a, $b) { |
| 2027 | - return $a * $b; |
|
| 2027 | + return $a * $b; |
|
| 2028 | 2028 | } |
| 2029 | 2029 | function strmult($a, $b) {return strize('mult', $a, $b);} |
| 2030 | 2030 | |
@@ -2045,7 +2045,7 @@ discard block |
||
| 2045 | 2045 | * @return int $a/$b (ou 0 si $b est nul) |
| 2046 | 2046 | **/ |
| 2047 | 2047 | function div($a, $b) { |
| 2048 | - return $b ? $a / $b : 0; |
|
| 2048 | + return $b ? $a / $b : 0; |
|
| 2049 | 2049 | } |
| 2050 | 2050 | function strdiv($a, $b) {return strize('div', $a, $b);} |
| 2051 | 2051 | |
@@ -2067,7 +2067,7 @@ discard block |
||
| 2067 | 2067 | * @return int ($nb % $mod) + $add |
| 2068 | 2068 | **/ |
| 2069 | 2069 | function modulo($nb, $mod, $add = 0) { |
| 2070 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2070 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | |
@@ -2082,24 +2082,24 @@ discard block |
||
| 2082 | 2082 | * - true sinon |
| 2083 | 2083 | **/ |
| 2084 | 2084 | function nom_acceptable($nom) { |
| 2085 | - if (!is_string($nom)) { |
|
| 2086 | - return false; |
|
| 2087 | - } |
|
| 2088 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2089 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2090 | - } |
|
| 2091 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2092 | - foreach ($tags_acceptes as $tag) { |
|
| 2093 | - if (strlen($tag)) { |
|
| 2094 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2095 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2096 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2097 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2098 | - } |
|
| 2099 | - } |
|
| 2100 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2085 | + if (!is_string($nom)) { |
|
| 2086 | + return false; |
|
| 2087 | + } |
|
| 2088 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2089 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2090 | + } |
|
| 2091 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2092 | + foreach ($tags_acceptes as $tag) { |
|
| 2093 | + if (strlen($tag)) { |
|
| 2094 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2095 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2096 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2097 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2098 | + } |
|
| 2099 | + } |
|
| 2100 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2101 | 2101 | |
| 2102 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2102 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | |
@@ -2113,29 +2113,29 @@ discard block |
||
| 2113 | 2113 | * - la normalisation de la dernière adresse donnée sinon |
| 2114 | 2114 | **/ |
| 2115 | 2115 | function email_valide($adresses) { |
| 2116 | - // eviter d'injecter n'importe quoi dans preg_match |
|
| 2117 | - if (!is_string($adresses)) { |
|
| 2118 | - return false; |
|
| 2119 | - } |
|
| 2116 | + // eviter d'injecter n'importe quoi dans preg_match |
|
| 2117 | + if (!is_string($adresses)) { |
|
| 2118 | + return false; |
|
| 2119 | + } |
|
| 2120 | 2120 | |
| 2121 | - // Si c'est un spammeur autant arreter tout de suite |
|
| 2122 | - if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 2123 | - spip_log("Tentative d'injection de mail : $adresses"); |
|
| 2121 | + // Si c'est un spammeur autant arreter tout de suite |
|
| 2122 | + if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 2123 | + spip_log("Tentative d'injection de mail : $adresses"); |
|
| 2124 | 2124 | |
| 2125 | - return false; |
|
| 2126 | - } |
|
| 2125 | + return false; |
|
| 2126 | + } |
|
| 2127 | 2127 | |
| 2128 | - foreach (explode(',', $adresses) as $v) { |
|
| 2129 | - // nettoyer certains formats |
|
| 2130 | - // "Marie Toto <[email protected]>" |
|
| 2131 | - $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 2132 | - // RFC 822 |
|
| 2133 | - if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) { |
|
| 2134 | - return false; |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2128 | + foreach (explode(',', $adresses) as $v) { |
|
| 2129 | + // nettoyer certains formats |
|
| 2130 | + // "Marie Toto <[email protected]>" |
|
| 2131 | + $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 2132 | + // RFC 822 |
|
| 2133 | + if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) { |
|
| 2134 | + return false; |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | 2137 | |
| 2138 | - return $adresse; |
|
| 2138 | + return $adresse; |
|
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | /** |
@@ -2149,20 +2149,20 @@ discard block |
||
| 2149 | 2149 | * @return string Texte |
| 2150 | 2150 | **/ |
| 2151 | 2151 | function afficher_enclosures($tags) { |
| 2152 | - $s = array(); |
|
| 2153 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2154 | - if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2155 | - and $t = extraire_attribut($tag, 'href') |
|
| 2156 | - ) { |
|
| 2157 | - $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 2158 | - '>' |
|
| 2159 | - . http_img_pack('attachment-16.png', $t, |
|
| 2160 | - 'title="' . attribut_html($t) . '"') |
|
| 2161 | - . '</a>', $tag); |
|
| 2162 | - } |
|
| 2163 | - } |
|
| 2152 | + $s = array(); |
|
| 2153 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2154 | + if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2155 | + and $t = extraire_attribut($tag, 'href') |
|
| 2156 | + ) { |
|
| 2157 | + $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 2158 | + '>' |
|
| 2159 | + . http_img_pack('attachment-16.png', $t, |
|
| 2160 | + 'title="' . attribut_html($t) . '"') |
|
| 2161 | + . '</a>', $tag); |
|
| 2162 | + } |
|
| 2163 | + } |
|
| 2164 | 2164 | |
| 2165 | - return join(' ', $s); |
|
| 2165 | + return join(' ', $s); |
|
| 2166 | 2166 | } |
| 2167 | 2167 | |
| 2168 | 2168 | /** |
@@ -2177,15 +2177,15 @@ discard block |
||
| 2177 | 2177 | * @return string Liens trouvés |
| 2178 | 2178 | **/ |
| 2179 | 2179 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2180 | - $s = array(); |
|
| 2181 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2182 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2183 | - if (strstr(",$rels,", ",$rel,")) { |
|
| 2184 | - $s[] = $tag; |
|
| 2185 | - } |
|
| 2186 | - } |
|
| 2180 | + $s = array(); |
|
| 2181 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2182 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2183 | + if (strstr(",$rels,", ",$rel,")) { |
|
| 2184 | + $s[] = $tag; |
|
| 2185 | + } |
|
| 2186 | + } |
|
| 2187 | 2187 | |
| 2188 | - return join(', ', $s); |
|
| 2188 | + return join(', ', $s); |
|
| 2189 | 2189 | } |
| 2190 | 2190 | |
| 2191 | 2191 | |
@@ -2207,21 +2207,21 @@ discard block |
||
| 2207 | 2207 | * @return string Tag HTML `<a>` avec microformat. |
| 2208 | 2208 | **/ |
| 2209 | 2209 | function enclosure2microformat($e) { |
| 2210 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2211 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2212 | - } |
|
| 2213 | - $type = extraire_attribut($e, 'type'); |
|
| 2214 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2215 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2216 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2217 | - } |
|
| 2218 | - $fichier = basename($url); |
|
| 2210 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2211 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2212 | + } |
|
| 2213 | + $type = extraire_attribut($e, 'type'); |
|
| 2214 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2215 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2216 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2217 | + } |
|
| 2218 | + $fichier = basename($url); |
|
| 2219 | 2219 | |
| 2220 | - return '<a rel="enclosure"' |
|
| 2221 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2222 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2223 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2224 | - . '>' . $fichier . '</a>'; |
|
| 2220 | + return '<a rel="enclosure"' |
|
| 2221 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2222 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2223 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2224 | + . '>' . $fichier . '</a>'; |
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | 2227 | /** |
@@ -2239,24 +2239,24 @@ discard block |
||
| 2239 | 2239 | * @return string Tags RSS `<enclosure>`. |
| 2240 | 2240 | **/ |
| 2241 | 2241 | function microformat2enclosure($tags) { |
| 2242 | - $enclosures = array(); |
|
| 2243 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2244 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2245 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2246 | - $type = extraire_attribut($e, 'type'); |
|
| 2247 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2248 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2249 | - } # vieux data |
|
| 2250 | - $fichier = basename($url); |
|
| 2251 | - $enclosures[] = '<enclosure' |
|
| 2252 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2253 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2254 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2255 | - . ' />'; |
|
| 2256 | - } |
|
| 2257 | - } |
|
| 2242 | + $enclosures = array(); |
|
| 2243 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2244 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2245 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2246 | + $type = extraire_attribut($e, 'type'); |
|
| 2247 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2248 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2249 | + } # vieux data |
|
| 2250 | + $fichier = basename($url); |
|
| 2251 | + $enclosures[] = '<enclosure' |
|
| 2252 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2253 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2254 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2255 | + . ' />'; |
|
| 2256 | + } |
|
| 2257 | + } |
|
| 2258 | 2258 | |
| 2259 | - return join("\n", $enclosures); |
|
| 2259 | + return join("\n", $enclosures); |
|
| 2260 | 2260 | } |
| 2261 | 2261 | |
| 2262 | 2262 | |
@@ -2272,16 +2272,16 @@ discard block |
||
| 2272 | 2272 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2273 | 2273 | **/ |
| 2274 | 2274 | function tags2dcsubject($tags) { |
| 2275 | - $subjects = ''; |
|
| 2276 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2277 | - if (extraire_attribut($e, rel) == 'tag') { |
|
| 2278 | - $subjects .= '<dc:subject>' |
|
| 2279 | - . texte_backend(textebrut($e)) |
|
| 2280 | - . '</dc:subject>' . "\n"; |
|
| 2281 | - } |
|
| 2282 | - } |
|
| 2275 | + $subjects = ''; |
|
| 2276 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2277 | + if (extraire_attribut($e, rel) == 'tag') { |
|
| 2278 | + $subjects .= '<dc:subject>' |
|
| 2279 | + . texte_backend(textebrut($e)) |
|
| 2280 | + . '</dc:subject>' . "\n"; |
|
| 2281 | + } |
|
| 2282 | + } |
|
| 2283 | 2283 | |
| 2284 | - return $subjects; |
|
| 2284 | + return $subjects; |
|
| 2285 | 2285 | } |
| 2286 | 2286 | |
| 2287 | 2287 | /** |
@@ -2310,23 +2310,23 @@ discard block |
||
| 2310 | 2310 | * - Tableau de résultats, si tableau en entrée. |
| 2311 | 2311 | **/ |
| 2312 | 2312 | function extraire_balise($texte, $tag = 'a') { |
| 2313 | - if (is_array($texte)) { |
|
| 2314 | - array_walk( |
|
| 2315 | - $texte, |
|
| 2316 | - function(&$a, $key, $t){ |
|
| 2317 | - $a = extraire_balise($a, $t); |
|
| 2318 | - }, |
|
| 2319 | - $tag |
|
| 2320 | - ); |
|
| 2313 | + if (is_array($texte)) { |
|
| 2314 | + array_walk( |
|
| 2315 | + $texte, |
|
| 2316 | + function(&$a, $key, $t){ |
|
| 2317 | + $a = extraire_balise($a, $t); |
|
| 2318 | + }, |
|
| 2319 | + $tag |
|
| 2320 | + ); |
|
| 2321 | 2321 | |
| 2322 | - return $texte; |
|
| 2323 | - } |
|
| 2322 | + return $texte; |
|
| 2323 | + } |
|
| 2324 | 2324 | |
| 2325 | - if (preg_match( |
|
| 2326 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2327 | - $texte, $regs)) { |
|
| 2328 | - return $regs[0]; |
|
| 2329 | - } |
|
| 2325 | + if (preg_match( |
|
| 2326 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2327 | + $texte, $regs)) { |
|
| 2328 | + return $regs[0]; |
|
| 2329 | + } |
|
| 2330 | 2330 | } |
| 2331 | 2331 | |
| 2332 | 2332 | /** |
@@ -2354,25 +2354,25 @@ discard block |
||
| 2354 | 2354 | * - Tableau de résultats, si tableau en entrée. |
| 2355 | 2355 | **/ |
| 2356 | 2356 | function extraire_balises($texte, $tag = 'a') { |
| 2357 | - if (is_array($texte)) { |
|
| 2358 | - array_walk( |
|
| 2359 | - $texte, |
|
| 2360 | - function(&$a, $key, $t){ |
|
| 2361 | - $a = extraire_balises($a, $t); |
|
| 2362 | - }, |
|
| 2363 | - $tag |
|
| 2364 | - ); |
|
| 2357 | + if (is_array($texte)) { |
|
| 2358 | + array_walk( |
|
| 2359 | + $texte, |
|
| 2360 | + function(&$a, $key, $t){ |
|
| 2361 | + $a = extraire_balises($a, $t); |
|
| 2362 | + }, |
|
| 2363 | + $tag |
|
| 2364 | + ); |
|
| 2365 | 2365 | |
| 2366 | - return $texte; |
|
| 2367 | - } |
|
| 2366 | + return $texte; |
|
| 2367 | + } |
|
| 2368 | 2368 | |
| 2369 | - if (preg_match_all( |
|
| 2370 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2371 | - $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 2372 | - return $regs[0]; |
|
| 2373 | - } else { |
|
| 2374 | - return array(); |
|
| 2375 | - } |
|
| 2369 | + if (preg_match_all( |
|
| 2370 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2371 | + $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 2372 | + return $regs[0]; |
|
| 2373 | + } else { |
|
| 2374 | + return array(); |
|
| 2375 | + } |
|
| 2376 | 2376 | } |
| 2377 | 2377 | |
| 2378 | 2378 | /** |
@@ -2401,11 +2401,11 @@ discard block |
||
| 2401 | 2401 | * - `$def` si on n'a pas transmis de tableau |
| 2402 | 2402 | **/ |
| 2403 | 2403 | function in_any($val, $vals, $def = '') { |
| 2404 | - if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2405 | - $vals = $v; |
|
| 2406 | - } |
|
| 2404 | + if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2405 | + $vals = $v; |
|
| 2406 | + } |
|
| 2407 | 2407 | |
| 2408 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2408 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2409 | 2409 | } |
| 2410 | 2410 | |
| 2411 | 2411 | |
@@ -2426,12 +2426,12 @@ discard block |
||
| 2426 | 2426 | * Résultat du calcul |
| 2427 | 2427 | **/ |
| 2428 | 2428 | function valeur_numerique($expr) { |
| 2429 | - $a = 0; |
|
| 2430 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2431 | - eval("\$a = $expr;"); |
|
| 2432 | - } |
|
| 2429 | + $a = 0; |
|
| 2430 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2431 | + eval("\$a = $expr;"); |
|
| 2432 | + } |
|
| 2433 | 2433 | |
| 2434 | - return intval($a); |
|
| 2434 | + return intval($a); |
|
| 2435 | 2435 | } |
| 2436 | 2436 | |
| 2437 | 2437 | /** |
@@ -2450,7 +2450,7 @@ discard block |
||
| 2450 | 2450 | * Retourne `$a*$b/$c` |
| 2451 | 2451 | **/ |
| 2452 | 2452 | function regledetrois($a, $b, $c) { |
| 2453 | - return round($a * $b / $c); |
|
| 2453 | + return round($a * $b / $c); |
|
| 2454 | 2454 | } |
| 2455 | 2455 | |
| 2456 | 2456 | |
@@ -2474,76 +2474,76 @@ discard block |
||
| 2474 | 2474 | **/ |
| 2475 | 2475 | function form_hidden($action) { |
| 2476 | 2476 | |
| 2477 | - $contexte = array(); |
|
| 2478 | - include_spip('inc/urls'); |
|
| 2479 | - if ($p = urls_decoder_url($action, '') |
|
| 2480 | - and reset($p) |
|
| 2481 | - ) { |
|
| 2482 | - $fond = array_shift($p); |
|
| 2483 | - if ($fond != '404') { |
|
| 2484 | - $contexte = array_shift($p); |
|
| 2485 | - $contexte['page'] = $fond; |
|
| 2486 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2487 | - } |
|
| 2488 | - } |
|
| 2489 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2490 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2491 | - unset($contexte['type']); |
|
| 2492 | - } |
|
| 2493 | - if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2494 | - unset($contexte['type-page']); |
|
| 2495 | - } |
|
| 2496 | - |
|
| 2497 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2498 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2499 | - $values = array(); |
|
| 2500 | - |
|
| 2501 | - // d'abord avec celles de l'url |
|
| 2502 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2503 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2504 | - $c = explode('=', $c, 2); |
|
| 2505 | - $var = array_shift($c); |
|
| 2506 | - $val = array_shift($c); |
|
| 2507 | - if ($var) { |
|
| 2508 | - $val = rawurldecode($val); |
|
| 2509 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2510 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2511 | - $values[] = array($var, $val); |
|
| 2512 | - } else { |
|
| 2513 | - if (!isset($values[$var])) { |
|
| 2514 | - $values[$var] = array($var, $val); |
|
| 2515 | - } |
|
| 2516 | - } |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2522 | - foreach ($contexte as $var => $val) { |
|
| 2523 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2524 | - $values[] = array($var, $val); |
|
| 2525 | - } else { |
|
| 2526 | - if (!isset($values[$var])) { |
|
| 2527 | - $values[$var] = array($var, $val); |
|
| 2528 | - } |
|
| 2529 | - } |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - // puis on rassemble le tout |
|
| 2533 | - $hidden = array(); |
|
| 2534 | - foreach ($values as $value) { |
|
| 2535 | - list($var, $val) = $value; |
|
| 2536 | - $hidden[] = '<input name="' |
|
| 2537 | - . entites_html($var) |
|
| 2538 | - . '"' |
|
| 2539 | - . (is_null($val) |
|
| 2540 | - ? '' |
|
| 2541 | - : ' value="' . entites_html($val) . '"' |
|
| 2542 | - ) |
|
| 2543 | - . ' type="hidden"' . "\n/>"; |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - return join("", $hidden); |
|
| 2477 | + $contexte = array(); |
|
| 2478 | + include_spip('inc/urls'); |
|
| 2479 | + if ($p = urls_decoder_url($action, '') |
|
| 2480 | + and reset($p) |
|
| 2481 | + ) { |
|
| 2482 | + $fond = array_shift($p); |
|
| 2483 | + if ($fond != '404') { |
|
| 2484 | + $contexte = array_shift($p); |
|
| 2485 | + $contexte['page'] = $fond; |
|
| 2486 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2487 | + } |
|
| 2488 | + } |
|
| 2489 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2490 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2491 | + unset($contexte['type']); |
|
| 2492 | + } |
|
| 2493 | + if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2494 | + unset($contexte['type-page']); |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2498 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2499 | + $values = array(); |
|
| 2500 | + |
|
| 2501 | + // d'abord avec celles de l'url |
|
| 2502 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2503 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2504 | + $c = explode('=', $c, 2); |
|
| 2505 | + $var = array_shift($c); |
|
| 2506 | + $val = array_shift($c); |
|
| 2507 | + if ($var) { |
|
| 2508 | + $val = rawurldecode($val); |
|
| 2509 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2510 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2511 | + $values[] = array($var, $val); |
|
| 2512 | + } else { |
|
| 2513 | + if (!isset($values[$var])) { |
|
| 2514 | + $values[$var] = array($var, $val); |
|
| 2515 | + } |
|
| 2516 | + } |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2522 | + foreach ($contexte as $var => $val) { |
|
| 2523 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2524 | + $values[] = array($var, $val); |
|
| 2525 | + } else { |
|
| 2526 | + if (!isset($values[$var])) { |
|
| 2527 | + $values[$var] = array($var, $val); |
|
| 2528 | + } |
|
| 2529 | + } |
|
| 2530 | + } |
|
| 2531 | + |
|
| 2532 | + // puis on rassemble le tout |
|
| 2533 | + $hidden = array(); |
|
| 2534 | + foreach ($values as $value) { |
|
| 2535 | + list($var, $val) = $value; |
|
| 2536 | + $hidden[] = '<input name="' |
|
| 2537 | + . entites_html($var) |
|
| 2538 | + . '"' |
|
| 2539 | + . (is_null($val) |
|
| 2540 | + ? '' |
|
| 2541 | + : ' value="' . entites_html($val) . '"' |
|
| 2542 | + ) |
|
| 2543 | + . ' type="hidden"' . "\n/>"; |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + return join("", $hidden); |
|
| 2547 | 2547 | } |
| 2548 | 2548 | |
| 2549 | 2549 | /** |
@@ -2561,15 +2561,15 @@ discard block |
||
| 2561 | 2561 | * Liste (première page, dernière page). |
| 2562 | 2562 | **/ |
| 2563 | 2563 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 2564 | - if ($max <= 0 or $max >= $nombre) { |
|
| 2565 | - return array(1, $nombre); |
|
| 2566 | - } |
|
| 2564 | + if ($max <= 0 or $max >= $nombre) { |
|
| 2565 | + return array(1, $nombre); |
|
| 2566 | + } |
|
| 2567 | 2567 | |
| 2568 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 2569 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 2570 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 2568 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 2569 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 2570 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 2571 | 2571 | |
| 2572 | - return array($premiere, $derniere); |
|
| 2572 | + return array($premiere, $derniere); |
|
| 2573 | 2573 | } |
| 2574 | 2574 | |
| 2575 | 2575 | |
@@ -2591,7 +2591,7 @@ discard block |
||
| 2591 | 2591 | * - la première valeur du tableau sinon. |
| 2592 | 2592 | **/ |
| 2593 | 2593 | function filtre_reset($array) { |
| 2594 | - return !is_array($array) ? null : reset($array); |
|
| 2594 | + return !is_array($array) ? null : reset($array); |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | /** |
@@ -2612,7 +2612,7 @@ discard block |
||
| 2612 | 2612 | * - la dernière valeur du tableau sinon. |
| 2613 | 2613 | **/ |
| 2614 | 2614 | function filtre_end($array) { |
| 2615 | - return !is_array($array) ? null : end($array); |
|
| 2615 | + return !is_array($array) ? null : end($array); |
|
| 2616 | 2616 | } |
| 2617 | 2617 | |
| 2618 | 2618 | /** |
@@ -2632,11 +2632,11 @@ discard block |
||
| 2632 | 2632 | * |
| 2633 | 2633 | **/ |
| 2634 | 2634 | function filtre_push($array, $val) { |
| 2635 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2636 | - return ''; |
|
| 2637 | - } |
|
| 2635 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2636 | + return ''; |
|
| 2637 | + } |
|
| 2638 | 2638 | |
| 2639 | - return $array; |
|
| 2639 | + return $array; |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | /** |
@@ -2655,7 +2655,7 @@ discard block |
||
| 2655 | 2655 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2656 | 2656 | **/ |
| 2657 | 2657 | function filtre_find($array, $val) { |
| 2658 | - return (is_array($array) and in_array($val, $array)); |
|
| 2658 | + return (is_array($array) and in_array($val, $array)); |
|
| 2659 | 2659 | } |
| 2660 | 2660 | |
| 2661 | 2661 | |
@@ -2690,59 +2690,59 @@ discard block |
||
| 2690 | 2690 | * Code HTML de la pagination |
| 2691 | 2691 | **/ |
| 2692 | 2692 | function filtre_pagination_dist( |
| 2693 | - $total, |
|
| 2694 | - $nom, |
|
| 2695 | - $position, |
|
| 2696 | - $pas, |
|
| 2697 | - $liste = true, |
|
| 2698 | - $modele = '', |
|
| 2699 | - $connect = '', |
|
| 2700 | - $env = array() |
|
| 2693 | + $total, |
|
| 2694 | + $nom, |
|
| 2695 | + $position, |
|
| 2696 | + $pas, |
|
| 2697 | + $liste = true, |
|
| 2698 | + $modele = '', |
|
| 2699 | + $connect = '', |
|
| 2700 | + $env = array() |
|
| 2701 | 2701 | ) { |
| 2702 | - static $ancres = array(); |
|
| 2703 | - if ($pas < 1) { |
|
| 2704 | - return ''; |
|
| 2705 | - } |
|
| 2706 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 2707 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 2708 | - |
|
| 2709 | - // n'afficher l'ancre qu'une fois |
|
| 2710 | - if (!isset($ancres[$ancre])) { |
|
| 2711 | - $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>"; |
|
| 2712 | - } else { |
|
| 2713 | - $bloc_ancre = ''; |
|
| 2714 | - } |
|
| 2715 | - // liste = false : on ne veut que l'ancre |
|
| 2716 | - if (!$liste) { |
|
| 2717 | - return $ancres[$ancre]; |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 2721 | - $pagination = array( |
|
| 2722 | - 'debut' => $debut, |
|
| 2723 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 2724 | - 'total' => $total, |
|
| 2725 | - 'position' => intval($position), |
|
| 2726 | - 'pas' => $pas, |
|
| 2727 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 2728 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 2729 | - 'ancre' => $ancre, |
|
| 2730 | - 'bloc_ancre' => $bloc_ancre |
|
| 2731 | - ); |
|
| 2732 | - if (is_array($env)) { |
|
| 2733 | - $pagination = array_merge($env, $pagination); |
|
| 2734 | - } |
|
| 2735 | - |
|
| 2736 | - // Pas de pagination |
|
| 2737 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 2738 | - return ''; |
|
| 2739 | - } |
|
| 2740 | - |
|
| 2741 | - if ($modele) { |
|
| 2742 | - $modele = '_' . $modele; |
|
| 2743 | - } |
|
| 2744 | - |
|
| 2745 | - return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect); |
|
| 2702 | + static $ancres = array(); |
|
| 2703 | + if ($pas < 1) { |
|
| 2704 | + return ''; |
|
| 2705 | + } |
|
| 2706 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 2707 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 2708 | + |
|
| 2709 | + // n'afficher l'ancre qu'une fois |
|
| 2710 | + if (!isset($ancres[$ancre])) { |
|
| 2711 | + $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>"; |
|
| 2712 | + } else { |
|
| 2713 | + $bloc_ancre = ''; |
|
| 2714 | + } |
|
| 2715 | + // liste = false : on ne veut que l'ancre |
|
| 2716 | + if (!$liste) { |
|
| 2717 | + return $ancres[$ancre]; |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 2721 | + $pagination = array( |
|
| 2722 | + 'debut' => $debut, |
|
| 2723 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 2724 | + 'total' => $total, |
|
| 2725 | + 'position' => intval($position), |
|
| 2726 | + 'pas' => $pas, |
|
| 2727 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 2728 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 2729 | + 'ancre' => $ancre, |
|
| 2730 | + 'bloc_ancre' => $bloc_ancre |
|
| 2731 | + ); |
|
| 2732 | + if (is_array($env)) { |
|
| 2733 | + $pagination = array_merge($env, $pagination); |
|
| 2734 | + } |
|
| 2735 | + |
|
| 2736 | + // Pas de pagination |
|
| 2737 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 2738 | + return ''; |
|
| 2739 | + } |
|
| 2740 | + |
|
| 2741 | + if ($modele) { |
|
| 2742 | + $modele = '_' . $modele; |
|
| 2743 | + } |
|
| 2744 | + |
|
| 2745 | + return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect); |
|
| 2746 | 2746 | } |
| 2747 | 2747 | |
| 2748 | 2748 | |
@@ -2759,15 +2759,15 @@ discard block |
||
| 2759 | 2759 | * Contenu avec urls en absolus |
| 2760 | 2760 | **/ |
| 2761 | 2761 | function urls_absolues_css($contenu, $source) { |
| 2762 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2762 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2763 | 2763 | |
| 2764 | - return preg_replace_callback( |
|
| 2765 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2766 | - function($x) use ($path) { |
|
| 2767 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2768 | - }, |
|
| 2769 | - $contenu |
|
| 2770 | - ); |
|
| 2764 | + return preg_replace_callback( |
|
| 2765 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2766 | + function($x) use ($path) { |
|
| 2767 | + return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2768 | + }, |
|
| 2769 | + $contenu |
|
| 2770 | + ); |
|
| 2771 | 2771 | } |
| 2772 | 2772 | |
| 2773 | 2773 | |
@@ -2796,118 +2796,118 @@ discard block |
||
| 2796 | 2796 | * Chemin du fichier CSS inversé |
| 2797 | 2797 | **/ |
| 2798 | 2798 | function direction_css($css, $voulue = '') { |
| 2799 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2800 | - return $css; |
|
| 2801 | - } |
|
| 2802 | - |
|
| 2803 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2804 | - if ($voulue = strtolower($voulue)) { |
|
| 2805 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2806 | - $voulue = lang_dir($voulue); |
|
| 2807 | - } |
|
| 2808 | - } else { |
|
| 2809 | - $voulue = lang_dir(); |
|
| 2810 | - } |
|
| 2811 | - |
|
| 2812 | - $r = count($r) > 1; |
|
| 2813 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2814 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2815 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2816 | - |
|
| 2817 | - if ($voulue == $dir) { |
|
| 2818 | - return $css; |
|
| 2819 | - } |
|
| 2820 | - |
|
| 2821 | - if ( |
|
| 2822 | - // url absolue |
|
| 2823 | - preg_match(",^https?:,i", $css) |
|
| 2824 | - // ou qui contient un ? |
|
| 2825 | - or (($p = strpos($css, '?')) !== false) |
|
| 2826 | - ) { |
|
| 2827 | - $distant = true; |
|
| 2828 | - $cssf = parse_url($css); |
|
| 2829 | - $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2830 | - $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2831 | - } else { |
|
| 2832 | - $distant = false; |
|
| 2833 | - $cssf = $css; |
|
| 2834 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2835 | - //propose (rien a faire dans ce cas) |
|
| 2836 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2837 | - if (@file_exists($f)) { |
|
| 2838 | - return $f; |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - |
|
| 2842 | - // 2. |
|
| 2843 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2844 | - $f = $dir_var |
|
| 2845 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2846 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2847 | - |
|
| 2848 | - // la css peut etre distante (url absolue !) |
|
| 2849 | - if ($distant) { |
|
| 2850 | - include_spip('inc/distant'); |
|
| 2851 | - $res = recuperer_url($css); |
|
| 2852 | - if (!$res or !$contenu = $res['page']) { |
|
| 2853 | - return $css; |
|
| 2854 | - } |
|
| 2855 | - } else { |
|
| 2856 | - if ((@filemtime($f) > @filemtime($css)) |
|
| 2857 | - and (_VAR_MODE != 'recalcul') |
|
| 2858 | - ) { |
|
| 2859 | - return $f; |
|
| 2860 | - } |
|
| 2861 | - if (!lire_fichier($css, $contenu)) { |
|
| 2862 | - return $css; |
|
| 2863 | - } |
|
| 2864 | - } |
|
| 2865 | - |
|
| 2866 | - |
|
| 2867 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2868 | - include_spip("lib/csstidy/class.csstidy"); |
|
| 2869 | - $parser = new csstidy(); |
|
| 2870 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2871 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2872 | - $parser->parse($contenu); |
|
| 2873 | - |
|
| 2874 | - $contenu = $parser->print->plain(); |
|
| 2875 | - |
|
| 2876 | - |
|
| 2877 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2878 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2879 | - $src = array(); |
|
| 2880 | - $src_direction_css = array(); |
|
| 2881 | - $src_faux_abs = array(); |
|
| 2882 | - $d = dirname($css); |
|
| 2883 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2884 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2885 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2886 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2887 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2888 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2889 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2890 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2891 | - $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2892 | - $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2893 | - } |
|
| 2894 | - $src[] = $regs[0][$k]; |
|
| 2895 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2896 | - } |
|
| 2897 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2898 | - |
|
| 2899 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2900 | - |
|
| 2901 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2902 | - if (count($src_faux_abs)) { |
|
| 2903 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2904 | - } |
|
| 2905 | - |
|
| 2906 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2907 | - return $css; |
|
| 2908 | - } |
|
| 2909 | - |
|
| 2910 | - return $f; |
|
| 2799 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2800 | + return $css; |
|
| 2801 | + } |
|
| 2802 | + |
|
| 2803 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2804 | + if ($voulue = strtolower($voulue)) { |
|
| 2805 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2806 | + $voulue = lang_dir($voulue); |
|
| 2807 | + } |
|
| 2808 | + } else { |
|
| 2809 | + $voulue = lang_dir(); |
|
| 2810 | + } |
|
| 2811 | + |
|
| 2812 | + $r = count($r) > 1; |
|
| 2813 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2814 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2815 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2816 | + |
|
| 2817 | + if ($voulue == $dir) { |
|
| 2818 | + return $css; |
|
| 2819 | + } |
|
| 2820 | + |
|
| 2821 | + if ( |
|
| 2822 | + // url absolue |
|
| 2823 | + preg_match(",^https?:,i", $css) |
|
| 2824 | + // ou qui contient un ? |
|
| 2825 | + or (($p = strpos($css, '?')) !== false) |
|
| 2826 | + ) { |
|
| 2827 | + $distant = true; |
|
| 2828 | + $cssf = parse_url($css); |
|
| 2829 | + $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2830 | + $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2831 | + } else { |
|
| 2832 | + $distant = false; |
|
| 2833 | + $cssf = $css; |
|
| 2834 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2835 | + //propose (rien a faire dans ce cas) |
|
| 2836 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2837 | + if (@file_exists($f)) { |
|
| 2838 | + return $f; |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + |
|
| 2842 | + // 2. |
|
| 2843 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2844 | + $f = $dir_var |
|
| 2845 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2846 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2847 | + |
|
| 2848 | + // la css peut etre distante (url absolue !) |
|
| 2849 | + if ($distant) { |
|
| 2850 | + include_spip('inc/distant'); |
|
| 2851 | + $res = recuperer_url($css); |
|
| 2852 | + if (!$res or !$contenu = $res['page']) { |
|
| 2853 | + return $css; |
|
| 2854 | + } |
|
| 2855 | + } else { |
|
| 2856 | + if ((@filemtime($f) > @filemtime($css)) |
|
| 2857 | + and (_VAR_MODE != 'recalcul') |
|
| 2858 | + ) { |
|
| 2859 | + return $f; |
|
| 2860 | + } |
|
| 2861 | + if (!lire_fichier($css, $contenu)) { |
|
| 2862 | + return $css; |
|
| 2863 | + } |
|
| 2864 | + } |
|
| 2865 | + |
|
| 2866 | + |
|
| 2867 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2868 | + include_spip("lib/csstidy/class.csstidy"); |
|
| 2869 | + $parser = new csstidy(); |
|
| 2870 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2871 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2872 | + $parser->parse($contenu); |
|
| 2873 | + |
|
| 2874 | + $contenu = $parser->print->plain(); |
|
| 2875 | + |
|
| 2876 | + |
|
| 2877 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2878 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2879 | + $src = array(); |
|
| 2880 | + $src_direction_css = array(); |
|
| 2881 | + $src_faux_abs = array(); |
|
| 2882 | + $d = dirname($css); |
|
| 2883 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2884 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2885 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2886 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2887 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2888 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2889 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2890 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2891 | + $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2892 | + $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2893 | + } |
|
| 2894 | + $src[] = $regs[0][$k]; |
|
| 2895 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2896 | + } |
|
| 2897 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2898 | + |
|
| 2899 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2900 | + |
|
| 2901 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2902 | + if (count($src_faux_abs)) { |
|
| 2903 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2904 | + } |
|
| 2905 | + |
|
| 2906 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2907 | + return $css; |
|
| 2908 | + } |
|
| 2909 | + |
|
| 2910 | + return $f; |
|
| 2911 | 2911 | } |
| 2912 | 2912 | |
| 2913 | 2913 | |
@@ -2930,43 +2930,43 @@ discard block |
||
| 2930 | 2930 | * - Chemin ou URL du fichier CSS source sinon. |
| 2931 | 2931 | **/ |
| 2932 | 2932 | function url_absolue_css($css) { |
| 2933 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2934 | - return $css; |
|
| 2935 | - } |
|
| 2933 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2934 | + return $css; |
|
| 2935 | + } |
|
| 2936 | 2936 | |
| 2937 | - $url_absolue_css = url_absolue($css); |
|
| 2937 | + $url_absolue_css = url_absolue($css); |
|
| 2938 | 2938 | |
| 2939 | - $f = basename($css, '.css'); |
|
| 2940 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2941 | - . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2942 | - . '.css'; |
|
| 2939 | + $f = basename($css, '.css'); |
|
| 2940 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2941 | + . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2942 | + . '.css'; |
|
| 2943 | 2943 | |
| 2944 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 2945 | - return $f; |
|
| 2946 | - } |
|
| 2944 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 2945 | + return $f; |
|
| 2946 | + } |
|
| 2947 | 2947 | |
| 2948 | - if ($url_absolue_css == $css) { |
|
| 2949 | - if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2950 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2951 | - ) { |
|
| 2952 | - include_spip('inc/distant'); |
|
| 2953 | - if (!$contenu = recuperer_page($css)) { |
|
| 2954 | - return $css; |
|
| 2955 | - } |
|
| 2956 | - } |
|
| 2957 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 2958 | - return $css; |
|
| 2959 | - } |
|
| 2948 | + if ($url_absolue_css == $css) { |
|
| 2949 | + if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2950 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2951 | + ) { |
|
| 2952 | + include_spip('inc/distant'); |
|
| 2953 | + if (!$contenu = recuperer_page($css)) { |
|
| 2954 | + return $css; |
|
| 2955 | + } |
|
| 2956 | + } |
|
| 2957 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 2958 | + return $css; |
|
| 2959 | + } |
|
| 2960 | 2960 | |
| 2961 | - // passer les url relatives a la css d'origine en url absolues |
|
| 2962 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2961 | + // passer les url relatives a la css d'origine en url absolues |
|
| 2962 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2963 | 2963 | |
| 2964 | - // ecrire la css |
|
| 2965 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2966 | - return $css; |
|
| 2967 | - } |
|
| 2964 | + // ecrire la css |
|
| 2965 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2966 | + return $css; |
|
| 2967 | + } |
|
| 2968 | 2968 | |
| 2969 | - return $f; |
|
| 2969 | + return $f; |
|
| 2970 | 2970 | } |
| 2971 | 2971 | |
| 2972 | 2972 | |
@@ -3000,24 +3000,24 @@ discard block |
||
| 3000 | 3000 | * Valeur trouvée ou valeur par défaut. |
| 3001 | 3001 | **/ |
| 3002 | 3002 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3003 | - foreach (explode('/', $cle) as $k) { |
|
| 3003 | + foreach (explode('/', $cle) as $k) { |
|
| 3004 | 3004 | |
| 3005 | - $table = is_string($table) ? @unserialize($table) : $table; |
|
| 3005 | + $table = is_string($table) ? @unserialize($table) : $table; |
|
| 3006 | 3006 | |
| 3007 | - if (is_object($table)) { |
|
| 3008 | - $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3009 | - } elseif (is_array($table)) { |
|
| 3010 | - if ($conserver_null) { |
|
| 3011 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3012 | - } else { |
|
| 3013 | - $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 3014 | - } |
|
| 3015 | - } else { |
|
| 3016 | - $table = $defaut; |
|
| 3017 | - } |
|
| 3018 | - } |
|
| 3007 | + if (is_object($table)) { |
|
| 3008 | + $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3009 | + } elseif (is_array($table)) { |
|
| 3010 | + if ($conserver_null) { |
|
| 3011 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3012 | + } else { |
|
| 3013 | + $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 3014 | + } |
|
| 3015 | + } else { |
|
| 3016 | + $table = $defaut; |
|
| 3017 | + } |
|
| 3018 | + } |
|
| 3019 | 3019 | |
| 3020 | - return $table; |
|
| 3020 | + return $table; |
|
| 3021 | 3021 | } |
| 3022 | 3022 | |
| 3023 | 3023 | /** |
@@ -3050,22 +3050,22 @@ discard block |
||
| 3050 | 3050 | * - string : expression trouvée. |
| 3051 | 3051 | **/ |
| 3052 | 3052 | function match($texte, $expression, $modif = "UimsS", $capte = 0) { |
| 3053 | - if (intval($modif) and $capte == 0) { |
|
| 3054 | - $capte = $modif; |
|
| 3055 | - $modif = "UimsS"; |
|
| 3056 | - } |
|
| 3057 | - $expression = str_replace("\/", "/", $expression); |
|
| 3058 | - $expression = str_replace("/", "\/", $expression); |
|
| 3053 | + if (intval($modif) and $capte == 0) { |
|
| 3054 | + $capte = $modif; |
|
| 3055 | + $modif = "UimsS"; |
|
| 3056 | + } |
|
| 3057 | + $expression = str_replace("\/", "/", $expression); |
|
| 3058 | + $expression = str_replace("/", "\/", $expression); |
|
| 3059 | 3059 | |
| 3060 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3061 | - if (isset($r[$capte])) { |
|
| 3062 | - return $r[$capte]; |
|
| 3063 | - } else { |
|
| 3064 | - return true; |
|
| 3065 | - } |
|
| 3066 | - } |
|
| 3060 | + if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3061 | + if (isset($r[$capte])) { |
|
| 3062 | + return $r[$capte]; |
|
| 3063 | + } else { |
|
| 3064 | + return true; |
|
| 3065 | + } |
|
| 3066 | + } |
|
| 3067 | 3067 | |
| 3068 | - return false; |
|
| 3068 | + return false; |
|
| 3069 | 3069 | } |
| 3070 | 3070 | |
| 3071 | 3071 | |
@@ -3092,10 +3092,10 @@ discard block |
||
| 3092 | 3092 | * Texte |
| 3093 | 3093 | **/ |
| 3094 | 3094 | function replace($texte, $expression, $replace = '', $modif = "UimsS") { |
| 3095 | - $expression = str_replace("\/", "/", $expression); |
|
| 3096 | - $expression = str_replace("/", "\/", $expression); |
|
| 3095 | + $expression = str_replace("\/", "/", $expression); |
|
| 3096 | + $expression = str_replace("/", "\/", $expression); |
|
| 3097 | 3097 | |
| 3098 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3098 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3099 | 3099 | } |
| 3100 | 3100 | |
| 3101 | 3101 | |
@@ -3113,21 +3113,21 @@ discard block |
||
| 3113 | 3113 | **/ |
| 3114 | 3114 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3115 | 3115 | |
| 3116 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3117 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3116 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3117 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3118 | 3118 | |
| 3119 | - if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3120 | - and preg_match_all( |
|
| 3121 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3122 | - $t, $matches, PREG_PATTERN_ORDER) |
|
| 3123 | - ) { |
|
| 3124 | - if (!isset($doublons['documents'])) { |
|
| 3125 | - $doublons['documents'] = ""; |
|
| 3126 | - } |
|
| 3127 | - $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3128 | - } |
|
| 3119 | + if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3120 | + and preg_match_all( |
|
| 3121 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3122 | + $t, $matches, PREG_PATTERN_ORDER) |
|
| 3123 | + ) { |
|
| 3124 | + if (!isset($doublons['documents'])) { |
|
| 3125 | + $doublons['documents'] = ""; |
|
| 3126 | + } |
|
| 3127 | + $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3128 | + } |
|
| 3129 | 3129 | |
| 3130 | - return $letexte; |
|
| 3130 | + return $letexte; |
|
| 3131 | 3131 | } |
| 3132 | 3132 | |
| 3133 | 3133 | /** |
@@ -3141,7 +3141,7 @@ discard block |
||
| 3141 | 3141 | * @return string Chaîne vide |
| 3142 | 3142 | **/ |
| 3143 | 3143 | function vide($texte) { |
| 3144 | - return ""; |
|
| 3144 | + return ""; |
|
| 3145 | 3145 | } |
| 3146 | 3146 | |
| 3147 | 3147 | // |
@@ -3170,23 +3170,23 @@ discard block |
||
| 3170 | 3170 | * Code HTML résultant |
| 3171 | 3171 | **/ |
| 3172 | 3172 | function env_to_params($env, $ignore_params = array()) { |
| 3173 | - $ignore_params = array_merge( |
|
| 3174 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3175 | - $ignore_params |
|
| 3176 | - ); |
|
| 3177 | - if (!is_array($env)) { |
|
| 3178 | - $env = unserialize($env); |
|
| 3179 | - } |
|
| 3180 | - $texte = ""; |
|
| 3181 | - if ($env) { |
|
| 3182 | - foreach ($env as $i => $j) { |
|
| 3183 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3184 | - $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />"; |
|
| 3185 | - } |
|
| 3186 | - } |
|
| 3187 | - } |
|
| 3188 | - |
|
| 3189 | - return $texte; |
|
| 3173 | + $ignore_params = array_merge( |
|
| 3174 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3175 | + $ignore_params |
|
| 3176 | + ); |
|
| 3177 | + if (!is_array($env)) { |
|
| 3178 | + $env = unserialize($env); |
|
| 3179 | + } |
|
| 3180 | + $texte = ""; |
|
| 3181 | + if ($env) { |
|
| 3182 | + foreach ($env as $i => $j) { |
|
| 3183 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3184 | + $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />"; |
|
| 3185 | + } |
|
| 3186 | + } |
|
| 3187 | + } |
|
| 3188 | + |
|
| 3189 | + return $texte; |
|
| 3190 | 3190 | } |
| 3191 | 3191 | |
| 3192 | 3192 | /** |
@@ -3209,23 +3209,23 @@ discard block |
||
| 3209 | 3209 | * Code HTML résultant |
| 3210 | 3210 | **/ |
| 3211 | 3211 | function env_to_attributs($env, $ignore_params = array()) { |
| 3212 | - $ignore_params = array_merge( |
|
| 3213 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3214 | - $ignore_params |
|
| 3215 | - ); |
|
| 3216 | - if (!is_array($env)) { |
|
| 3217 | - $env = unserialize($env); |
|
| 3218 | - } |
|
| 3219 | - $texte = ""; |
|
| 3220 | - if ($env) { |
|
| 3221 | - foreach ($env as $i => $j) { |
|
| 3222 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3223 | - $texte .= $i . "='" . $j . "' "; |
|
| 3224 | - } |
|
| 3225 | - } |
|
| 3226 | - } |
|
| 3212 | + $ignore_params = array_merge( |
|
| 3213 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3214 | + $ignore_params |
|
| 3215 | + ); |
|
| 3216 | + if (!is_array($env)) { |
|
| 3217 | + $env = unserialize($env); |
|
| 3218 | + } |
|
| 3219 | + $texte = ""; |
|
| 3220 | + if ($env) { |
|
| 3221 | + foreach ($env as $i => $j) { |
|
| 3222 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3223 | + $texte .= $i . "='" . $j . "' "; |
|
| 3224 | + } |
|
| 3225 | + } |
|
| 3226 | + } |
|
| 3227 | 3227 | |
| 3228 | - return $texte; |
|
| 3228 | + return $texte; |
|
| 3229 | 3229 | } |
| 3230 | 3230 | |
| 3231 | 3231 | |
@@ -3242,9 +3242,9 @@ discard block |
||
| 3242 | 3242 | * @return string Chaînes concaténés |
| 3243 | 3243 | **/ |
| 3244 | 3244 | function concat() { |
| 3245 | - $args = func_get_args(); |
|
| 3245 | + $args = func_get_args(); |
|
| 3246 | 3246 | |
| 3247 | - return join('', $args); |
|
| 3247 | + return join('', $args); |
|
| 3248 | 3248 | } |
| 3249 | 3249 | |
| 3250 | 3250 | |
@@ -3264,23 +3264,23 @@ discard block |
||
| 3264 | 3264 | * Contenu du ou des fichiers, concaténé |
| 3265 | 3265 | **/ |
| 3266 | 3266 | function charge_scripts($files, $script = true) { |
| 3267 | - $flux = ""; |
|
| 3268 | - foreach (is_array($files) ? $files : explode("|", $files) as $file) { |
|
| 3269 | - if (!is_string($file)) { |
|
| 3270 | - continue; |
|
| 3271 | - } |
|
| 3272 | - if ($script) { |
|
| 3273 | - $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : ''; |
|
| 3274 | - } |
|
| 3275 | - if ($file) { |
|
| 3276 | - $path = find_in_path($file); |
|
| 3277 | - if ($path) { |
|
| 3278 | - $flux .= spip_file_get_contents($path); |
|
| 3279 | - } |
|
| 3280 | - } |
|
| 3281 | - } |
|
| 3267 | + $flux = ""; |
|
| 3268 | + foreach (is_array($files) ? $files : explode("|", $files) as $file) { |
|
| 3269 | + if (!is_string($file)) { |
|
| 3270 | + continue; |
|
| 3271 | + } |
|
| 3272 | + if ($script) { |
|
| 3273 | + $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : ''; |
|
| 3274 | + } |
|
| 3275 | + if ($file) { |
|
| 3276 | + $path = find_in_path($file); |
|
| 3277 | + if ($path) { |
|
| 3278 | + $flux .= spip_file_get_contents($path); |
|
| 3279 | + } |
|
| 3280 | + } |
|
| 3281 | + } |
|
| 3282 | 3282 | |
| 3283 | - return $flux; |
|
| 3283 | + return $flux; |
|
| 3284 | 3284 | } |
| 3285 | 3285 | |
| 3286 | 3286 | |
@@ -3302,55 +3302,55 @@ discard block |
||
| 3302 | 3302 | */ |
| 3303 | 3303 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) { |
| 3304 | 3304 | |
| 3305 | - $img_file = $img; |
|
| 3306 | - if ($p = strpos($img_file, '?')) { |
|
| 3307 | - $img_file = substr($img_file,0, $p); |
|
| 3308 | - } |
|
| 3309 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3310 | - $img_file = chemin_image($img); |
|
| 3311 | - } |
|
| 3312 | - else { |
|
| 3313 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){ |
|
| 3314 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3315 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3316 | - if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3317 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg" |
|
| 3318 | - and file_exists($variante_svg_generique)) { |
|
| 3319 | - if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) { |
|
| 3320 | - $img_file = $variante_svg_size; |
|
| 3321 | - } |
|
| 3322 | - else { |
|
| 3323 | - $img_file = $variante_svg_generique; |
|
| 3324 | - } |
|
| 3325 | - } |
|
| 3326 | - } |
|
| 3327 | - } |
|
| 3328 | - if (stripos($atts, 'width') === false) { |
|
| 3329 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3330 | - if ((!isset($options['utiliser_suffixe_size']) |
|
| 3331 | - or $options['utiliser_suffixe_size'] == true |
|
| 3332 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3333 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3334 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3335 | - ) { |
|
| 3336 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3337 | - } else { |
|
| 3338 | - $taille = taille_image($img_file); |
|
| 3339 | - list($hauteur, $largeur) = $taille; |
|
| 3340 | - if (!$hauteur or !$largeur) { |
|
| 3341 | - return ""; |
|
| 3342 | - } |
|
| 3343 | - } |
|
| 3344 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3345 | - } |
|
| 3346 | - |
|
| 3347 | - if (file_exists($img_file)) { |
|
| 3348 | - $img_file = timestamp($img_file); |
|
| 3349 | - } |
|
| 3350 | - return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 3351 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3352 | - . " " . ltrim($atts) |
|
| 3353 | - . " />"; |
|
| 3305 | + $img_file = $img; |
|
| 3306 | + if ($p = strpos($img_file, '?')) { |
|
| 3307 | + $img_file = substr($img_file,0, $p); |
|
| 3308 | + } |
|
| 3309 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3310 | + $img_file = chemin_image($img); |
|
| 3311 | + } |
|
| 3312 | + else { |
|
| 3313 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){ |
|
| 3314 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3315 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3316 | + if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3317 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg" |
|
| 3318 | + and file_exists($variante_svg_generique)) { |
|
| 3319 | + if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) { |
|
| 3320 | + $img_file = $variante_svg_size; |
|
| 3321 | + } |
|
| 3322 | + else { |
|
| 3323 | + $img_file = $variante_svg_generique; |
|
| 3324 | + } |
|
| 3325 | + } |
|
| 3326 | + } |
|
| 3327 | + } |
|
| 3328 | + if (stripos($atts, 'width') === false) { |
|
| 3329 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3330 | + if ((!isset($options['utiliser_suffixe_size']) |
|
| 3331 | + or $options['utiliser_suffixe_size'] == true |
|
| 3332 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3333 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3334 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3335 | + ) { |
|
| 3336 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3337 | + } else { |
|
| 3338 | + $taille = taille_image($img_file); |
|
| 3339 | + list($hauteur, $largeur) = $taille; |
|
| 3340 | + if (!$hauteur or !$largeur) { |
|
| 3341 | + return ""; |
|
| 3342 | + } |
|
| 3343 | + } |
|
| 3344 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3345 | + } |
|
| 3346 | + |
|
| 3347 | + if (file_exists($img_file)) { |
|
| 3348 | + $img_file = timestamp($img_file); |
|
| 3349 | + } |
|
| 3350 | + return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 3351 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3352 | + . " " . ltrim($atts) |
|
| 3353 | + . " />"; |
|
| 3354 | 3354 | } |
| 3355 | 3355 | |
| 3356 | 3356 | /** |
@@ -3362,13 +3362,13 @@ discard block |
||
| 3362 | 3362 | * @return string |
| 3363 | 3363 | */ |
| 3364 | 3364 | function http_style_background($img, $att = '', $size=null) { |
| 3365 | - if ($size and is_numeric($size)){ |
|
| 3366 | - $size = trim($size) . "px"; |
|
| 3367 | - } |
|
| 3368 | - return " style='background" . |
|
| 3369 | - ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";" |
|
| 3370 | - . ($size ? "background-size:{$size};" : '') |
|
| 3371 | - . "'"; |
|
| 3365 | + if ($size and is_numeric($size)){ |
|
| 3366 | + $size = trim($size) . "px"; |
|
| 3367 | + } |
|
| 3368 | + return " style='background" . |
|
| 3369 | + ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";" |
|
| 3370 | + . ($size ? "background-size:{$size};" : '') |
|
| 3371 | + . "'"; |
|
| 3372 | 3372 | } |
| 3373 | 3373 | |
| 3374 | 3374 | /** |
@@ -3384,17 +3384,17 @@ discard block |
||
| 3384 | 3384 | * Code HTML de la balise IMG |
| 3385 | 3385 | */ |
| 3386 | 3386 | function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) { |
| 3387 | - $atts = $class ? " class='" . attribut_html($class) . "'" : ''; |
|
| 3388 | - // ecriture courte : on donne le width en 2e arg |
|
| 3389 | - if (empty($width) and is_numeric($alt)) { |
|
| 3390 | - $width = $alt; |
|
| 3391 | - $alt = ''; |
|
| 3392 | - } |
|
| 3393 | - if ($width) { |
|
| 3394 | - $atts .= " width='{$width}'"; |
|
| 3395 | - } |
|
| 3396 | - return http_img_pack($img, $alt, $atts, '', |
|
| 3397 | - array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
|
| 3387 | + $atts = $class ? " class='" . attribut_html($class) . "'" : ''; |
|
| 3388 | + // ecriture courte : on donne le width en 2e arg |
|
| 3389 | + if (empty($width) and is_numeric($alt)) { |
|
| 3390 | + $width = $alt; |
|
| 3391 | + $alt = ''; |
|
| 3392 | + } |
|
| 3393 | + if ($width) { |
|
| 3394 | + $atts .= " width='{$width}'"; |
|
| 3395 | + } |
|
| 3396 | + return http_img_pack($img, $alt, $atts, '', |
|
| 3397 | + array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
|
| 3398 | 3398 | } |
| 3399 | 3399 | |
| 3400 | 3400 | |
@@ -3410,34 +3410,34 @@ discard block |
||
| 3410 | 3410 | * @return string |
| 3411 | 3411 | */ |
| 3412 | 3412 | function filtre_balise_svg_dist($img, $alt = "", $class = "") { |
| 3413 | - if (!$file = find_in_path($img) |
|
| 3414 | - or !$svg = file_get_contents($file)) { |
|
| 3415 | - return ''; |
|
| 3416 | - } |
|
| 3417 | - |
|
| 3418 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3419 | - return ''; |
|
| 3420 | - } |
|
| 3421 | - $balise_svg = $match[0]; |
|
| 3422 | - $balise_svg_source = $balise_svg; |
|
| 3423 | - // IE est toujours mon ami |
|
| 3424 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3425 | - if ($class) { |
|
| 3426 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3427 | - } |
|
| 3428 | - if ($alt){ |
|
| 3429 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3430 | - $id = "img-svg-title-" . substr(md5("$file:$svg:$alt"),0,4); |
|
| 3431 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3432 | - $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n"; |
|
| 3433 | - $balise_svg .= $title; |
|
| 3434 | - } |
|
| 3435 | - else { |
|
| 3436 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3437 | - } |
|
| 3438 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3439 | - |
|
| 3440 | - return $svg; |
|
| 3413 | + if (!$file = find_in_path($img) |
|
| 3414 | + or !$svg = file_get_contents($file)) { |
|
| 3415 | + return ''; |
|
| 3416 | + } |
|
| 3417 | + |
|
| 3418 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3419 | + return ''; |
|
| 3420 | + } |
|
| 3421 | + $balise_svg = $match[0]; |
|
| 3422 | + $balise_svg_source = $balise_svg; |
|
| 3423 | + // IE est toujours mon ami |
|
| 3424 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3425 | + if ($class) { |
|
| 3426 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3427 | + } |
|
| 3428 | + if ($alt){ |
|
| 3429 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3430 | + $id = "img-svg-title-" . substr(md5("$file:$svg:$alt"),0,4); |
|
| 3431 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3432 | + $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n"; |
|
| 3433 | + $balise_svg .= $title; |
|
| 3434 | + } |
|
| 3435 | + else { |
|
| 3436 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3437 | + } |
|
| 3438 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3439 | + |
|
| 3440 | + return $svg; |
|
| 3441 | 3441 | } |
| 3442 | 3442 | |
| 3443 | 3443 | |
@@ -3460,17 +3460,17 @@ discard block |
||
| 3460 | 3460 | * Code HTML résultant |
| 3461 | 3461 | **/ |
| 3462 | 3462 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3463 | - $texte = ''; |
|
| 3464 | - if (is_array($tableau)) { |
|
| 3465 | - foreach ($tableau as $k => $v) { |
|
| 3466 | - $res = recuperer_fond('modeles/' . $modele, |
|
| 3467 | - array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 3468 | - ); |
|
| 3469 | - $texte .= $res; |
|
| 3470 | - } |
|
| 3471 | - } |
|
| 3463 | + $texte = ''; |
|
| 3464 | + if (is_array($tableau)) { |
|
| 3465 | + foreach ($tableau as $k => $v) { |
|
| 3466 | + $res = recuperer_fond('modeles/' . $modele, |
|
| 3467 | + array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 3468 | + ); |
|
| 3469 | + $texte .= $res; |
|
| 3470 | + } |
|
| 3471 | + } |
|
| 3472 | 3472 | |
| 3473 | - return $texte; |
|
| 3473 | + return $texte; |
|
| 3474 | 3474 | } |
| 3475 | 3475 | |
| 3476 | 3476 | |
@@ -3495,37 +3495,37 @@ discard block |
||
| 3495 | 3495 | * - tout : retourne toutes les informations du plugin actif |
| 3496 | 3496 | **/ |
| 3497 | 3497 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3498 | - include_spip('inc/plugin'); |
|
| 3499 | - $plugin = strtoupper($plugin); |
|
| 3500 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3501 | - |
|
| 3502 | - if (!$plugin) { |
|
| 3503 | - return serialize(array_keys($plugins_actifs)); |
|
| 3504 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3505 | - return ''; |
|
| 3506 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3507 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3508 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3509 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3510 | - } else { |
|
| 3511 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3512 | - // On prend en compte les extensions |
|
| 3513 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3514 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3515 | - } else { |
|
| 3516 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3517 | - } |
|
| 3518 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3519 | - return ''; |
|
| 3520 | - } |
|
| 3521 | - if ($type_info == 'tout') { |
|
| 3522 | - return $infos; |
|
| 3523 | - } elseif ($type_info == 'est_actif') { |
|
| 3524 | - return $infos ? 1 : 0; |
|
| 3525 | - } else { |
|
| 3526 | - return strval($infos[$type_info]); |
|
| 3527 | - } |
|
| 3528 | - } |
|
| 3498 | + include_spip('inc/plugin'); |
|
| 3499 | + $plugin = strtoupper($plugin); |
|
| 3500 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3501 | + |
|
| 3502 | + if (!$plugin) { |
|
| 3503 | + return serialize(array_keys($plugins_actifs)); |
|
| 3504 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3505 | + return ''; |
|
| 3506 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3507 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3508 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3509 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3510 | + } else { |
|
| 3511 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3512 | + // On prend en compte les extensions |
|
| 3513 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3514 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3515 | + } else { |
|
| 3516 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3517 | + } |
|
| 3518 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3519 | + return ''; |
|
| 3520 | + } |
|
| 3521 | + if ($type_info == 'tout') { |
|
| 3522 | + return $infos; |
|
| 3523 | + } elseif ($type_info == 'est_actif') { |
|
| 3524 | + return $infos ? 1 : 0; |
|
| 3525 | + } else { |
|
| 3526 | + return strval($infos[$type_info]); |
|
| 3527 | + } |
|
| 3528 | + } |
|
| 3529 | 3529 | } |
| 3530 | 3530 | |
| 3531 | 3531 | |
@@ -3552,9 +3552,9 @@ discard block |
||
| 3552 | 3552 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3553 | 3553 | */ |
| 3554 | 3554 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3555 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3555 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3556 | 3556 | |
| 3557 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3557 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3558 | 3558 | } |
| 3559 | 3559 | |
| 3560 | 3560 | |
@@ -3584,13 +3584,13 @@ discard block |
||
| 3584 | 3584 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3585 | 3585 | */ |
| 3586 | 3586 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3587 | - static $puce_statut = null; |
|
| 3588 | - if (!$puce_statut) { |
|
| 3589 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3590 | - } |
|
| 3587 | + static $puce_statut = null; |
|
| 3588 | + if (!$puce_statut) { |
|
| 3589 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3590 | + } |
|
| 3591 | 3591 | |
| 3592 | - return $puce_statut($id_objet, $statut, $id_parent, $objet, false, |
|
| 3593 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false); |
|
| 3592 | + return $puce_statut($id_objet, $statut, $id_parent, $objet, false, |
|
| 3593 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false); |
|
| 3594 | 3594 | } |
| 3595 | 3595 | |
| 3596 | 3596 | |
@@ -3617,88 +3617,88 @@ discard block |
||
| 3617 | 3617 | * hash du contexte |
| 3618 | 3618 | */ |
| 3619 | 3619 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3620 | - if (is_string($c) |
|
| 3621 | - and @unserialize($c) !== false |
|
| 3622 | - ) { |
|
| 3623 | - $c = unserialize($c); |
|
| 3624 | - } |
|
| 3625 | - |
|
| 3626 | - // supprimer les parametres debut_x |
|
| 3627 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3628 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3629 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3630 | - if (is_array($c)) { |
|
| 3631 | - foreach ($c as $k => $v) { |
|
| 3632 | - if (strpos($k, 'debut_') === 0) { |
|
| 3633 | - unset($c[$k]); |
|
| 3634 | - } |
|
| 3635 | - } |
|
| 3636 | - } |
|
| 3637 | - |
|
| 3638 | - if (!function_exists('calculer_cle_action')) { |
|
| 3639 | - include_spip("inc/securiser_action"); |
|
| 3640 | - } |
|
| 3641 | - |
|
| 3642 | - $c = serialize($c); |
|
| 3643 | - $cle = calculer_cle_action($form . $c); |
|
| 3644 | - $c = "$cle:$c"; |
|
| 3645 | - |
|
| 3646 | - // on ne stocke pas les contextes dans des fichiers caches |
|
| 3647 | - // par defaut, sauf si cette configuration a ete forcee |
|
| 3648 | - // OU que la longueur de l''argument generee est plus long |
|
| 3649 | - // que ce que telere Suhosin. |
|
| 3650 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3651 | - if (!$cache_contextes_ajax) { |
|
| 3652 | - $env = $c; |
|
| 3653 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3654 | - $env = gzdeflate($env); |
|
| 3655 | - // http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 3656 | - if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) { |
|
| 3657 | - $cache_contextes_ajax = true; |
|
| 3658 | - spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 3659 | - } |
|
| 3660 | - } |
|
| 3661 | - $env = _xor($env); |
|
| 3662 | - $env = base64_encode($env); |
|
| 3663 | - // tester Suhosin et la valeur maximale des variables en GET... |
|
| 3664 | - if ($max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3665 | - and $max_len < ($len = strlen($env)) |
|
| 3666 | - ) { |
|
| 3667 | - $cache_contextes_ajax = true; |
|
| 3668 | - spip_log("Contextes AJAX forces en fichiers !" |
|
| 3669 | - . " Cela arrive lorsque la valeur du contexte" |
|
| 3670 | - . " depasse la longueur maximale autorisee par Suhosin" |
|
| 3671 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3672 | - . " Vous devriez modifier les parametres de Suhosin" |
|
| 3673 | - . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 3674 | - } |
|
| 3675 | - } |
|
| 3676 | - |
|
| 3677 | - if ($cache_contextes_ajax) { |
|
| 3678 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3679 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3680 | - $md5 = md5($c); |
|
| 3681 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3682 | - $env = $md5; |
|
| 3683 | - } |
|
| 3684 | - |
|
| 3685 | - if ($emboite === null) { |
|
| 3686 | - return $env; |
|
| 3687 | - } |
|
| 3688 | - if (!trim($emboite)) { |
|
| 3689 | - return ""; |
|
| 3690 | - } |
|
| 3691 | - // toujours encoder l'url source dans le bloc ajax |
|
| 3692 | - $r = self(); |
|
| 3693 | - $r = ' data-origin="' . $r . '"'; |
|
| 3694 | - $class = 'ajaxbloc'; |
|
| 3695 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 3696 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 3697 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3698 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3699 | - } |
|
| 3700 | - |
|
| 3701 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3620 | + if (is_string($c) |
|
| 3621 | + and @unserialize($c) !== false |
|
| 3622 | + ) { |
|
| 3623 | + $c = unserialize($c); |
|
| 3624 | + } |
|
| 3625 | + |
|
| 3626 | + // supprimer les parametres debut_x |
|
| 3627 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3628 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3629 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3630 | + if (is_array($c)) { |
|
| 3631 | + foreach ($c as $k => $v) { |
|
| 3632 | + if (strpos($k, 'debut_') === 0) { |
|
| 3633 | + unset($c[$k]); |
|
| 3634 | + } |
|
| 3635 | + } |
|
| 3636 | + } |
|
| 3637 | + |
|
| 3638 | + if (!function_exists('calculer_cle_action')) { |
|
| 3639 | + include_spip("inc/securiser_action"); |
|
| 3640 | + } |
|
| 3641 | + |
|
| 3642 | + $c = serialize($c); |
|
| 3643 | + $cle = calculer_cle_action($form . $c); |
|
| 3644 | + $c = "$cle:$c"; |
|
| 3645 | + |
|
| 3646 | + // on ne stocke pas les contextes dans des fichiers caches |
|
| 3647 | + // par defaut, sauf si cette configuration a ete forcee |
|
| 3648 | + // OU que la longueur de l''argument generee est plus long |
|
| 3649 | + // que ce que telere Suhosin. |
|
| 3650 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3651 | + if (!$cache_contextes_ajax) { |
|
| 3652 | + $env = $c; |
|
| 3653 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3654 | + $env = gzdeflate($env); |
|
| 3655 | + // http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 3656 | + if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) { |
|
| 3657 | + $cache_contextes_ajax = true; |
|
| 3658 | + spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 3659 | + } |
|
| 3660 | + } |
|
| 3661 | + $env = _xor($env); |
|
| 3662 | + $env = base64_encode($env); |
|
| 3663 | + // tester Suhosin et la valeur maximale des variables en GET... |
|
| 3664 | + if ($max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3665 | + and $max_len < ($len = strlen($env)) |
|
| 3666 | + ) { |
|
| 3667 | + $cache_contextes_ajax = true; |
|
| 3668 | + spip_log("Contextes AJAX forces en fichiers !" |
|
| 3669 | + . " Cela arrive lorsque la valeur du contexte" |
|
| 3670 | + . " depasse la longueur maximale autorisee par Suhosin" |
|
| 3671 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3672 | + . " Vous devriez modifier les parametres de Suhosin" |
|
| 3673 | + . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 3674 | + } |
|
| 3675 | + } |
|
| 3676 | + |
|
| 3677 | + if ($cache_contextes_ajax) { |
|
| 3678 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3679 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3680 | + $md5 = md5($c); |
|
| 3681 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3682 | + $env = $md5; |
|
| 3683 | + } |
|
| 3684 | + |
|
| 3685 | + if ($emboite === null) { |
|
| 3686 | + return $env; |
|
| 3687 | + } |
|
| 3688 | + if (!trim($emboite)) { |
|
| 3689 | + return ""; |
|
| 3690 | + } |
|
| 3691 | + // toujours encoder l'url source dans le bloc ajax |
|
| 3692 | + $r = self(); |
|
| 3693 | + $r = ' data-origin="' . $r . '"'; |
|
| 3694 | + $class = 'ajaxbloc'; |
|
| 3695 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 3696 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 3697 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3698 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3699 | + } |
|
| 3700 | + |
|
| 3701 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3702 | 3702 | } |
| 3703 | 3703 | |
| 3704 | 3704 | /** |
@@ -3718,36 +3718,36 @@ discard block |
||
| 3718 | 3718 | * - false : erreur de décodage |
| 3719 | 3719 | */ |
| 3720 | 3720 | function decoder_contexte_ajax($c, $form = '') { |
| 3721 | - if (!function_exists('calculer_cle_action')) { |
|
| 3722 | - include_spip("inc/securiser_action"); |
|
| 3723 | - } |
|
| 3724 | - if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 3725 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 3726 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 3727 | - ) { |
|
| 3728 | - $c = $contexte; |
|
| 3729 | - } else { |
|
| 3730 | - $c = @base64_decode($c); |
|
| 3731 | - $c = _xor($c); |
|
| 3732 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3733 | - $c = @gzinflate($c); |
|
| 3734 | - } |
|
| 3735 | - } |
|
| 3736 | - |
|
| 3737 | - // extraire la signature en debut de contexte |
|
| 3738 | - // et la verifier avant de deserializer |
|
| 3739 | - // format : signature:donneesserializees |
|
| 3740 | - if ($p = strpos($c,":")){ |
|
| 3741 | - $cle = substr($c,0,$p); |
|
| 3742 | - $c = substr($c,$p+1); |
|
| 3743 | - |
|
| 3744 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 3745 | - $env = @unserialize($c); |
|
| 3746 | - return $env; |
|
| 3747 | - } |
|
| 3748 | - } |
|
| 3749 | - |
|
| 3750 | - return false; |
|
| 3721 | + if (!function_exists('calculer_cle_action')) { |
|
| 3722 | + include_spip("inc/securiser_action"); |
|
| 3723 | + } |
|
| 3724 | + if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 3725 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 3726 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 3727 | + ) { |
|
| 3728 | + $c = $contexte; |
|
| 3729 | + } else { |
|
| 3730 | + $c = @base64_decode($c); |
|
| 3731 | + $c = _xor($c); |
|
| 3732 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3733 | + $c = @gzinflate($c); |
|
| 3734 | + } |
|
| 3735 | + } |
|
| 3736 | + |
|
| 3737 | + // extraire la signature en debut de contexte |
|
| 3738 | + // et la verifier avant de deserializer |
|
| 3739 | + // format : signature:donneesserializees |
|
| 3740 | + if ($p = strpos($c,":")){ |
|
| 3741 | + $cle = substr($c,0,$p); |
|
| 3742 | + $c = substr($c,$p+1); |
|
| 3743 | + |
|
| 3744 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 3745 | + $env = @unserialize($c); |
|
| 3746 | + return $env; |
|
| 3747 | + } |
|
| 3748 | + } |
|
| 3749 | + |
|
| 3750 | + return false; |
|
| 3751 | 3751 | } |
| 3752 | 3752 | |
| 3753 | 3753 | |
@@ -3765,20 +3765,20 @@ discard block |
||
| 3765 | 3765 | * Message décrypté ou encrypté |
| 3766 | 3766 | **/ |
| 3767 | 3767 | function _xor($message, $key = null) { |
| 3768 | - if (is_null($key)) { |
|
| 3769 | - if (!function_exists('calculer_cle_action')) { |
|
| 3770 | - include_spip("inc/securiser_action"); |
|
| 3771 | - } |
|
| 3772 | - $key = pack("H*", calculer_cle_action('_xor')); |
|
| 3773 | - } |
|
| 3768 | + if (is_null($key)) { |
|
| 3769 | + if (!function_exists('calculer_cle_action')) { |
|
| 3770 | + include_spip("inc/securiser_action"); |
|
| 3771 | + } |
|
| 3772 | + $key = pack("H*", calculer_cle_action('_xor')); |
|
| 3773 | + } |
|
| 3774 | 3774 | |
| 3775 | - $keylen = strlen($key); |
|
| 3776 | - $messagelen = strlen($message); |
|
| 3777 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 3778 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3779 | - } |
|
| 3775 | + $keylen = strlen($key); |
|
| 3776 | + $messagelen = strlen($message); |
|
| 3777 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 3778 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3779 | + } |
|
| 3780 | 3780 | |
| 3781 | - return $message; |
|
| 3781 | + return $message; |
|
| 3782 | 3782 | } |
| 3783 | 3783 | |
| 3784 | 3784 | /** |
@@ -3836,22 +3836,22 @@ discard block |
||
| 3836 | 3836 | * Code HTML |
| 3837 | 3837 | */ |
| 3838 | 3838 | function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') { |
| 3839 | - if ($on) { |
|
| 3840 | - $bal = "strong"; |
|
| 3841 | - $att = "class='on'"; |
|
| 3842 | - } else { |
|
| 3843 | - $bal = 'a'; |
|
| 3844 | - $att = "href='$url'" |
|
| 3845 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3846 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3847 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3848 | - . $evt; |
|
| 3849 | - } |
|
| 3850 | - if ($libelle === null) { |
|
| 3851 | - $libelle = $url; |
|
| 3852 | - } |
|
| 3839 | + if ($on) { |
|
| 3840 | + $bal = "strong"; |
|
| 3841 | + $att = "class='on'"; |
|
| 3842 | + } else { |
|
| 3843 | + $bal = 'a'; |
|
| 3844 | + $att = "href='$url'" |
|
| 3845 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3846 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3847 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3848 | + . $evt; |
|
| 3849 | + } |
|
| 3850 | + if ($libelle === null) { |
|
| 3851 | + $libelle = $url; |
|
| 3852 | + } |
|
| 3853 | 3853 | |
| 3854 | - return "<$bal $att>$libelle</$bal>"; |
|
| 3854 | + return "<$bal $att>$libelle</$bal>"; |
|
| 3855 | 3855 | } |
| 3856 | 3856 | |
| 3857 | 3857 | |
@@ -3868,18 +3868,18 @@ discard block |
||
| 3868 | 3868 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 3869 | 3869 | */ |
| 3870 | 3870 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) { |
| 3871 | - if (!$nb = intval($nb)) { |
|
| 3872 | - return ""; |
|
| 3873 | - } |
|
| 3874 | - if (!is_array($vars)) { |
|
| 3875 | - return ""; |
|
| 3876 | - } |
|
| 3877 | - $vars[$var] = $nb; |
|
| 3878 | - if ($nb > 1) { |
|
| 3879 | - return _T($chaine_plusieurs, $vars); |
|
| 3880 | - } else { |
|
| 3881 | - return _T($chaine_un, $vars); |
|
| 3882 | - } |
|
| 3871 | + if (!$nb = intval($nb)) { |
|
| 3872 | + return ""; |
|
| 3873 | + } |
|
| 3874 | + if (!is_array($vars)) { |
|
| 3875 | + return ""; |
|
| 3876 | + } |
|
| 3877 | + $vars[$var] = $nb; |
|
| 3878 | + if ($nb > 1) { |
|
| 3879 | + return _T($chaine_plusieurs, $vars); |
|
| 3880 | + } else { |
|
| 3881 | + return _T($chaine_un, $vars); |
|
| 3882 | + } |
|
| 3883 | 3883 | } |
| 3884 | 3884 | |
| 3885 | 3885 | |
@@ -3904,56 +3904,56 @@ discard block |
||
| 3904 | 3904 | * @return string |
| 3905 | 3905 | */ |
| 3906 | 3906 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3907 | - if (in_array($fonction, array("del", "supprimer.gif"))) { |
|
| 3908 | - $class .= ' danger'; |
|
| 3909 | - } elseif ($fonction == "rien.gif") { |
|
| 3910 | - $fonction = ""; |
|
| 3911 | - } elseif ($fonction == "delsafe") { |
|
| 3912 | - $fonction = "del"; |
|
| 3913 | - } |
|
| 3914 | - |
|
| 3915 | - $fond_origine = $fond; |
|
| 3916 | - // remappage des icone : article-24.png+new => article-new-24.png |
|
| 3917 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 3918 | - list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 3919 | - } |
|
| 3920 | - |
|
| 3921 | - // ajouter le type d'objet dans la class de l'icone |
|
| 3922 | - $class .= " " . substr(basename($fond), 0, -4); |
|
| 3923 | - |
|
| 3924 | - $alt = attribut_html($texte); |
|
| 3925 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 3926 | - |
|
| 3927 | - $ajax = ""; |
|
| 3928 | - if (strpos($class, "ajax") !== false) { |
|
| 3929 | - $ajax = "ajax"; |
|
| 3930 | - if (strpos($class, "preload") !== false) { |
|
| 3931 | - $ajax .= " preload"; |
|
| 3932 | - } |
|
| 3933 | - if (strpos($class, "nocache") !== false) { |
|
| 3934 | - $ajax .= " nocache"; |
|
| 3935 | - } |
|
| 3936 | - $ajax = " class='$ajax'"; |
|
| 3937 | - } |
|
| 3938 | - |
|
| 3939 | - $size = 24; |
|
| 3940 | - if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match) |
|
| 3941 | - or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) { |
|
| 3942 | - $size = $match[1]; |
|
| 3943 | - } |
|
| 3944 | - |
|
| 3945 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 3946 | - $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>"; |
|
| 3947 | - |
|
| 3948 | - if ($type == 'lien') { |
|
| 3949 | - return "<span class='icone s$size $class'>" |
|
| 3950 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 3951 | - . $icone |
|
| 3952 | - . "<b>$texte</b>" |
|
| 3953 | - . "</a></span>\n"; |
|
| 3954 | - } else { |
|
| 3955 | - return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt); |
|
| 3956 | - } |
|
| 3907 | + if (in_array($fonction, array("del", "supprimer.gif"))) { |
|
| 3908 | + $class .= ' danger'; |
|
| 3909 | + } elseif ($fonction == "rien.gif") { |
|
| 3910 | + $fonction = ""; |
|
| 3911 | + } elseif ($fonction == "delsafe") { |
|
| 3912 | + $fonction = "del"; |
|
| 3913 | + } |
|
| 3914 | + |
|
| 3915 | + $fond_origine = $fond; |
|
| 3916 | + // remappage des icone : article-24.png+new => article-new-24.png |
|
| 3917 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 3918 | + list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 3919 | + } |
|
| 3920 | + |
|
| 3921 | + // ajouter le type d'objet dans la class de l'icone |
|
| 3922 | + $class .= " " . substr(basename($fond), 0, -4); |
|
| 3923 | + |
|
| 3924 | + $alt = attribut_html($texte); |
|
| 3925 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 3926 | + |
|
| 3927 | + $ajax = ""; |
|
| 3928 | + if (strpos($class, "ajax") !== false) { |
|
| 3929 | + $ajax = "ajax"; |
|
| 3930 | + if (strpos($class, "preload") !== false) { |
|
| 3931 | + $ajax .= " preload"; |
|
| 3932 | + } |
|
| 3933 | + if (strpos($class, "nocache") !== false) { |
|
| 3934 | + $ajax .= " nocache"; |
|
| 3935 | + } |
|
| 3936 | + $ajax = " class='$ajax'"; |
|
| 3937 | + } |
|
| 3938 | + |
|
| 3939 | + $size = 24; |
|
| 3940 | + if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match) |
|
| 3941 | + or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) { |
|
| 3942 | + $size = $match[1]; |
|
| 3943 | + } |
|
| 3944 | + |
|
| 3945 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 3946 | + $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>"; |
|
| 3947 | + |
|
| 3948 | + if ($type == 'lien') { |
|
| 3949 | + return "<span class='icone s$size $class'>" |
|
| 3950 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 3951 | + . $icone |
|
| 3952 | + . "<b>$texte</b>" |
|
| 3953 | + . "</a></span>\n"; |
|
| 3954 | + } else { |
|
| 3955 | + return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt); |
|
| 3956 | + } |
|
| 3957 | 3957 | } |
| 3958 | 3958 | |
| 3959 | 3959 | /** |
@@ -3977,7 +3977,7 @@ discard block |
||
| 3977 | 3977 | * Code HTML du lien |
| 3978 | 3978 | **/ |
| 3979 | 3979 | function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3980 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 3980 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 3981 | 3981 | } |
| 3982 | 3982 | |
| 3983 | 3983 | /** |
@@ -4012,7 +4012,7 @@ discard block |
||
| 4012 | 4012 | * Code HTML du lien |
| 4013 | 4013 | **/ |
| 4014 | 4014 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 4015 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4015 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4016 | 4016 | } |
| 4017 | 4017 | |
| 4018 | 4018 | /** |
@@ -4057,7 +4057,7 @@ discard block |
||
| 4057 | 4057 | * Code HTML du lien |
| 4058 | 4058 | **/ |
| 4059 | 4059 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 4060 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4060 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4061 | 4061 | } |
| 4062 | 4062 | |
| 4063 | 4063 | /** |
@@ -4088,7 +4088,7 @@ discard block |
||
| 4088 | 4088 | * Code HTML du lien |
| 4089 | 4089 | **/ |
| 4090 | 4090 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") { |
| 4091 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 4091 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 4092 | 4092 | } |
| 4093 | 4093 | |
| 4094 | 4094 | /** |
@@ -4118,7 +4118,7 @@ discard block |
||
| 4118 | 4118 | * Code HTML du lien |
| 4119 | 4119 | */ |
| 4120 | 4120 | function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") { |
| 4121 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4121 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4122 | 4122 | } |
| 4123 | 4123 | |
| 4124 | 4124 | |
@@ -4166,26 +4166,26 @@ discard block |
||
| 4166 | 4166 | * @return string Code CSS |
| 4167 | 4167 | */ |
| 4168 | 4168 | function bando_images_background() { |
| 4169 | - include_spip('inc/bandeau'); |
|
| 4170 | - // recuperer tous les boutons et leurs images |
|
| 4171 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4169 | + include_spip('inc/bandeau'); |
|
| 4170 | + // recuperer tous les boutons et leurs images |
|
| 4171 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4172 | 4172 | |
| 4173 | - $res = ""; |
|
| 4174 | - foreach ($boutons as $page => $detail) { |
|
| 4175 | - if ($detail->icone and strlen(trim($detail->icone))) { |
|
| 4176 | - $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4177 | - } |
|
| 4178 | - $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
|
| 4179 | - if (is_array($detail->sousmenu)) { |
|
| 4180 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4181 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4182 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4183 | - } |
|
| 4184 | - } |
|
| 4185 | - } |
|
| 4186 | - } |
|
| 4173 | + $res = ""; |
|
| 4174 | + foreach ($boutons as $page => $detail) { |
|
| 4175 | + if ($detail->icone and strlen(trim($detail->icone))) { |
|
| 4176 | + $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4177 | + } |
|
| 4178 | + $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
|
| 4179 | + if (is_array($detail->sousmenu)) { |
|
| 4180 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4181 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4182 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4183 | + } |
|
| 4184 | + } |
|
| 4185 | + } |
|
| 4186 | + } |
|
| 4187 | 4187 | |
| 4188 | - return $res; |
|
| 4188 | + return $res; |
|
| 4189 | 4189 | } |
| 4190 | 4190 | |
| 4191 | 4191 | /** |
@@ -4204,19 +4204,19 @@ discard block |
||
| 4204 | 4204 | * @return string |
| 4205 | 4205 | */ |
| 4206 | 4206 | function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") { |
| 4207 | - if ($confirm) { |
|
| 4208 | - $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4209 | - if ($callback) { |
|
| 4210 | - $callback = "$confirm?($callback):false"; |
|
| 4211 | - } else { |
|
| 4212 | - $callback = $confirm; |
|
| 4213 | - } |
|
| 4214 | - } |
|
| 4215 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4216 | - $title = $title ? " title='$title'" : ""; |
|
| 4207 | + if ($confirm) { |
|
| 4208 | + $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4209 | + if ($callback) { |
|
| 4210 | + $callback = "$confirm?($callback):false"; |
|
| 4211 | + } else { |
|
| 4212 | + $callback = $confirm; |
|
| 4213 | + } |
|
| 4214 | + } |
|
| 4215 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4216 | + $title = $title ? " title='$title'" : ""; |
|
| 4217 | 4217 | |
| 4218 | - return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4219 | - . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 4218 | + return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4219 | + . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 4220 | 4220 | } |
| 4221 | 4221 | |
| 4222 | 4222 | |
@@ -4228,7 +4228,7 @@ discard block |
||
| 4228 | 4228 | * @return string |
| 4229 | 4229 | */ |
| 4230 | 4230 | function tri_protege_champ($t) { |
| 4231 | - return preg_replace(',[^\s\w.+],', '', $t); |
|
| 4231 | + return preg_replace(',[^\s\w.+],', '', $t); |
|
| 4232 | 4232 | } |
| 4233 | 4233 | |
| 4234 | 4234 | /** |
@@ -4241,34 +4241,34 @@ discard block |
||
| 4241 | 4241 | * @return string |
| 4242 | 4242 | */ |
| 4243 | 4243 | function tri_champ_order($t, $from = null) { |
| 4244 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4245 | - return "multi"; |
|
| 4246 | - } |
|
| 4247 | - |
|
| 4248 | - $champ = $t; |
|
| 4249 | - |
|
| 4250 | - if (strncmp($t, 'num ', 4) == 0) { |
|
| 4251 | - $champ = substr($t, 4); |
|
| 4252 | - } |
|
| 4253 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 4254 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 4255 | - |
|
| 4256 | - if (is_array($from)) { |
|
| 4257 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4258 | - foreach ($from as $idt => $table_sql) { |
|
| 4259 | - if ($desc = $trouver_table($table_sql) |
|
| 4260 | - and isset($desc['field'][$champ]) |
|
| 4261 | - ) { |
|
| 4262 | - $champ = "$idt.$champ"; |
|
| 4263 | - break; |
|
| 4264 | - } |
|
| 4265 | - } |
|
| 4266 | - } |
|
| 4267 | - if (strncmp($t, 'num ', 4) == 0) { |
|
| 4268 | - return "0+$champ"; |
|
| 4269 | - } else { |
|
| 4270 | - return $champ; |
|
| 4271 | - } |
|
| 4244 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4245 | + return "multi"; |
|
| 4246 | + } |
|
| 4247 | + |
|
| 4248 | + $champ = $t; |
|
| 4249 | + |
|
| 4250 | + if (strncmp($t, 'num ', 4) == 0) { |
|
| 4251 | + $champ = substr($t, 4); |
|
| 4252 | + } |
|
| 4253 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 4254 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 4255 | + |
|
| 4256 | + if (is_array($from)) { |
|
| 4257 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4258 | + foreach ($from as $idt => $table_sql) { |
|
| 4259 | + if ($desc = $trouver_table($table_sql) |
|
| 4260 | + and isset($desc['field'][$champ]) |
|
| 4261 | + ) { |
|
| 4262 | + $champ = "$idt.$champ"; |
|
| 4263 | + break; |
|
| 4264 | + } |
|
| 4265 | + } |
|
| 4266 | + } |
|
| 4267 | + if (strncmp($t, 'num ', 4) == 0) { |
|
| 4268 | + return "0+$champ"; |
|
| 4269 | + } else { |
|
| 4270 | + return $champ; |
|
| 4271 | + } |
|
| 4272 | 4272 | } |
| 4273 | 4273 | |
| 4274 | 4274 | /** |
@@ -4282,18 +4282,18 @@ discard block |
||
| 4282 | 4282 | * @return string |
| 4283 | 4283 | */ |
| 4284 | 4284 | function tri_champ_select($t) { |
| 4285 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4286 | - $t = substr($t, 6); |
|
| 4287 | - $t = preg_replace(',\s,', '', $t); |
|
| 4288 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 4285 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4286 | + $t = substr($t, 6); |
|
| 4287 | + $t = preg_replace(',\s,', '', $t); |
|
| 4288 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 4289 | 4289 | |
| 4290 | - return $t; |
|
| 4291 | - } |
|
| 4292 | - if (trim($t) == 'hasard') { |
|
| 4293 | - return 'rand() AS hasard'; |
|
| 4294 | - } |
|
| 4290 | + return $t; |
|
| 4291 | + } |
|
| 4292 | + if (trim($t) == 'hasard') { |
|
| 4293 | + return 'rand() AS hasard'; |
|
| 4294 | + } |
|
| 4295 | 4295 | |
| 4296 | - return "''"; |
|
| 4296 | + return "''"; |
|
| 4297 | 4297 | } |
| 4298 | 4298 | |
| 4299 | 4299 | |
@@ -4315,78 +4315,78 @@ discard block |
||
| 4315 | 4315 | * @return string |
| 4316 | 4316 | */ |
| 4317 | 4317 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") { |
| 4318 | - static $trouver_table = null; |
|
| 4319 | - static $objets; |
|
| 4320 | - |
|
| 4321 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4322 | - $id_objet = intval($id_objet); |
|
| 4323 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4324 | - return ''; |
|
| 4325 | - } |
|
| 4326 | - |
|
| 4327 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4328 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4329 | - return ''; |
|
| 4330 | - } |
|
| 4331 | - |
|
| 4332 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4333 | - if ($info == 'url') { |
|
| 4334 | - return generer_url_entite($id_objet, $type_objet); |
|
| 4335 | - } |
|
| 4336 | - |
|
| 4337 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4338 | - $demande_titre = ($info == 'titre'); |
|
| 4339 | - |
|
| 4340 | - // 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 |
|
| 4341 | - if (!isset($objets[$type_objet][$id_objet]) |
|
| 4342 | - or |
|
| 4343 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4344 | - ) { |
|
| 4345 | - if (!$trouver_table) { |
|
| 4346 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4347 | - } |
|
| 4348 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4349 | - if (!$desc) { |
|
| 4350 | - return $objets[$type_objet] = false; |
|
| 4351 | - } |
|
| 4352 | - |
|
| 4353 | - // Si on demande le titre, on le gere en interne |
|
| 4354 | - $champ_titre = ""; |
|
| 4355 | - if ($demande_titre) { |
|
| 4356 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4357 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4358 | - } |
|
| 4359 | - include_spip('base/abstract_sql'); |
|
| 4360 | - include_spip('base/connect_sql'); |
|
| 4361 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4362 | - '*' . $champ_titre, |
|
| 4363 | - $desc['table_sql'], |
|
| 4364 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4365 | - ); |
|
| 4366 | - } |
|
| 4367 | - |
|
| 4368 | - // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4369 | - if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4370 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 4371 | - } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4372 | - else { |
|
| 4373 | - if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4374 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 4375 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4376 | - else { |
|
| 4377 | - $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4378 | - } |
|
| 4379 | - } |
|
| 4380 | - |
|
| 4381 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4382 | - if (!$etoile) { |
|
| 4383 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4384 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4385 | - $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet), |
|
| 4386 | - array('id_objet' => $id_objet, 'objet' => $type_objet, '')); |
|
| 4387 | - } |
|
| 4388 | - |
|
| 4389 | - return $info_generee; |
|
| 4318 | + static $trouver_table = null; |
|
| 4319 | + static $objets; |
|
| 4320 | + |
|
| 4321 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4322 | + $id_objet = intval($id_objet); |
|
| 4323 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4324 | + return ''; |
|
| 4325 | + } |
|
| 4326 | + |
|
| 4327 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4328 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4329 | + return ''; |
|
| 4330 | + } |
|
| 4331 | + |
|
| 4332 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4333 | + if ($info == 'url') { |
|
| 4334 | + return generer_url_entite($id_objet, $type_objet); |
|
| 4335 | + } |
|
| 4336 | + |
|
| 4337 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4338 | + $demande_titre = ($info == 'titre'); |
|
| 4339 | + |
|
| 4340 | + // 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 |
|
| 4341 | + if (!isset($objets[$type_objet][$id_objet]) |
|
| 4342 | + or |
|
| 4343 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4344 | + ) { |
|
| 4345 | + if (!$trouver_table) { |
|
| 4346 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4347 | + } |
|
| 4348 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4349 | + if (!$desc) { |
|
| 4350 | + return $objets[$type_objet] = false; |
|
| 4351 | + } |
|
| 4352 | + |
|
| 4353 | + // Si on demande le titre, on le gere en interne |
|
| 4354 | + $champ_titre = ""; |
|
| 4355 | + if ($demande_titre) { |
|
| 4356 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4357 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4358 | + } |
|
| 4359 | + include_spip('base/abstract_sql'); |
|
| 4360 | + include_spip('base/connect_sql'); |
|
| 4361 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4362 | + '*' . $champ_titre, |
|
| 4363 | + $desc['table_sql'], |
|
| 4364 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4365 | + ); |
|
| 4366 | + } |
|
| 4367 | + |
|
| 4368 | + // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4369 | + if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4370 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 4371 | + } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4372 | + else { |
|
| 4373 | + if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4374 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 4375 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4376 | + else { |
|
| 4377 | + $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4378 | + } |
|
| 4379 | + } |
|
| 4380 | + |
|
| 4381 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4382 | + if (!$etoile) { |
|
| 4383 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4384 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4385 | + $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet), |
|
| 4386 | + array('id_objet' => $id_objet, 'objet' => $type_objet, '')); |
|
| 4387 | + } |
|
| 4388 | + |
|
| 4389 | + return $info_generee; |
|
| 4390 | 4390 | } |
| 4391 | 4391 | |
| 4392 | 4392 | /** |
@@ -4400,44 +4400,44 @@ discard block |
||
| 4400 | 4400 | * @return string |
| 4401 | 4401 | */ |
| 4402 | 4402 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') { |
| 4403 | - if (!$champ) { |
|
| 4404 | - return $texte; |
|
| 4405 | - } |
|
| 4403 | + if (!$champ) { |
|
| 4404 | + return $texte; |
|
| 4405 | + } |
|
| 4406 | 4406 | |
| 4407 | - // On charge toujours les filtres de texte car la majorité des traitements les utilisent |
|
| 4408 | - // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4409 | - include_spip('inc/texte'); |
|
| 4407 | + // On charge toujours les filtres de texte car la majorité des traitements les utilisent |
|
| 4408 | + // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4409 | + include_spip('inc/texte'); |
|
| 4410 | 4410 | |
| 4411 | - $champ = strtoupper($champ); |
|
| 4412 | - $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4413 | - if (!$traitements or !is_array($traitements)) { |
|
| 4414 | - return $texte; |
|
| 4415 | - } |
|
| 4411 | + $champ = strtoupper($champ); |
|
| 4412 | + $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4413 | + if (!$traitements or !is_array($traitements)) { |
|
| 4414 | + return $texte; |
|
| 4415 | + } |
|
| 4416 | 4416 | |
| 4417 | - $traitement = ''; |
|
| 4418 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4419 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4420 | - $table_objet = table_objet($table_objet); |
|
| 4421 | - if (isset($traitements[$table_objet])) { |
|
| 4422 | - $traitement = $traitements[$table_objet]; |
|
| 4423 | - } |
|
| 4424 | - } |
|
| 4425 | - if (!$traitement and isset($traitements[0])) { |
|
| 4426 | - $traitement = $traitements[0]; |
|
| 4427 | - } |
|
| 4428 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4417 | + $traitement = ''; |
|
| 4418 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4419 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4420 | + $table_objet = table_objet($table_objet); |
|
| 4421 | + if (isset($traitements[$table_objet])) { |
|
| 4422 | + $traitement = $traitements[$table_objet]; |
|
| 4423 | + } |
|
| 4424 | + } |
|
| 4425 | + if (!$traitement and isset($traitements[0])) { |
|
| 4426 | + $traitement = $traitements[0]; |
|
| 4427 | + } |
|
| 4428 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4429 | 4429 | |
| 4430 | - if (!$traitement) { |
|
| 4431 | - return $texte; |
|
| 4432 | - } |
|
| 4430 | + if (!$traitement) { |
|
| 4431 | + return $texte; |
|
| 4432 | + } |
|
| 4433 | 4433 | |
| 4434 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4434 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4435 | 4435 | |
| 4436 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4437 | - $Pile = array(0 => $env); |
|
| 4438 | - eval("\$texte = $traitement;"); |
|
| 4436 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4437 | + $Pile = array(0 => $env); |
|
| 4438 | + eval("\$texte = $traitement;"); |
|
| 4439 | 4439 | |
| 4440 | - return $texte; |
|
| 4440 | + return $texte; |
|
| 4441 | 4441 | } |
| 4442 | 4442 | |
| 4443 | 4443 | |
@@ -4451,21 +4451,21 @@ discard block |
||
| 4451 | 4451 | * @return string |
| 4452 | 4452 | */ |
| 4453 | 4453 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4454 | - include_spip('inc/liens'); |
|
| 4455 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4456 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4457 | - // le raccourcis n'est plus valide |
|
| 4458 | - $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4459 | - // on essaye avec generer_info_entite ? |
|
| 4460 | - if (!strlen($titre) and !$connect) { |
|
| 4461 | - $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4462 | - } |
|
| 4463 | - if (!strlen($titre)) { |
|
| 4464 | - $titre = _T('info_sans_titre'); |
|
| 4465 | - } |
|
| 4466 | - $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4454 | + include_spip('inc/liens'); |
|
| 4455 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4456 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4457 | + // le raccourcis n'est plus valide |
|
| 4458 | + $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4459 | + // on essaye avec generer_info_entite ? |
|
| 4460 | + if (!strlen($titre) and !$connect) { |
|
| 4461 | + $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4462 | + } |
|
| 4463 | + if (!strlen($titre)) { |
|
| 4464 | + $titre = _T('info_sans_titre'); |
|
| 4465 | + } |
|
| 4466 | + $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4467 | 4467 | |
| 4468 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4468 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4469 | 4469 | } |
| 4470 | 4470 | |
| 4471 | 4471 | |
@@ -4482,15 +4482,15 @@ discard block |
||
| 4482 | 4482 | * @return string |
| 4483 | 4483 | */ |
| 4484 | 4484 | function wrap($texte, $wrap) { |
| 4485 | - $balises = extraire_balises($wrap); |
|
| 4486 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4487 | - $texte = $wrap . $texte; |
|
| 4488 | - $regs = array_reverse($regs[1]); |
|
| 4489 | - $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4490 | - $texte = $texte . $wrap; |
|
| 4491 | - } |
|
| 4485 | + $balises = extraire_balises($wrap); |
|
| 4486 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4487 | + $texte = $wrap . $texte; |
|
| 4488 | + $regs = array_reverse($regs[1]); |
|
| 4489 | + $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4490 | + $texte = $texte . $wrap; |
|
| 4491 | + } |
|
| 4492 | 4492 | |
| 4493 | - return $texte; |
|
| 4493 | + return $texte; |
|
| 4494 | 4494 | } |
| 4495 | 4495 | |
| 4496 | 4496 | |
@@ -4510,43 +4510,43 @@ discard block |
||
| 4510 | 4510 | * @return array|mixed|string |
| 4511 | 4511 | */ |
| 4512 | 4512 | function filtre_print_dist($u, $join = "<br />", $indent = 0) { |
| 4513 | - if (is_string($u)) { |
|
| 4514 | - $u = typo($u); |
|
| 4513 | + if (is_string($u)) { |
|
| 4514 | + $u = typo($u); |
|
| 4515 | 4515 | |
| 4516 | - return $u; |
|
| 4517 | - } |
|
| 4516 | + return $u; |
|
| 4517 | + } |
|
| 4518 | 4518 | |
| 4519 | - // caster $u en array si besoin |
|
| 4520 | - if (is_object($u)) { |
|
| 4521 | - $u = (array)$u; |
|
| 4522 | - } |
|
| 4519 | + // caster $u en array si besoin |
|
| 4520 | + if (is_object($u)) { |
|
| 4521 | + $u = (array)$u; |
|
| 4522 | + } |
|
| 4523 | 4523 | |
| 4524 | - if (is_array($u)) { |
|
| 4525 | - $out = ""; |
|
| 4526 | - // toutes les cles sont numeriques ? |
|
| 4527 | - // et aucun enfant n'est un tableau |
|
| 4528 | - // liste simple separee par des virgules |
|
| 4529 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4530 | - $array_values = array_map('is_array', $u); |
|
| 4531 | - $object_values = array_map('is_object', $u); |
|
| 4532 | - if (array_sum($numeric_keys) == count($numeric_keys) |
|
| 4533 | - and !array_sum($array_values) |
|
| 4534 | - and !array_sum($object_values) |
|
| 4535 | - ) { |
|
| 4536 | - return join(", ", array_map('filtre_print_dist', $u)); |
|
| 4537 | - } |
|
| 4524 | + if (is_array($u)) { |
|
| 4525 | + $out = ""; |
|
| 4526 | + // toutes les cles sont numeriques ? |
|
| 4527 | + // et aucun enfant n'est un tableau |
|
| 4528 | + // liste simple separee par des virgules |
|
| 4529 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4530 | + $array_values = array_map('is_array', $u); |
|
| 4531 | + $object_values = array_map('is_object', $u); |
|
| 4532 | + if (array_sum($numeric_keys) == count($numeric_keys) |
|
| 4533 | + and !array_sum($array_values) |
|
| 4534 | + and !array_sum($object_values) |
|
| 4535 | + ) { |
|
| 4536 | + return join(", ", array_map('filtre_print_dist', $u)); |
|
| 4537 | + } |
|
| 4538 | 4538 | |
| 4539 | - // sinon on passe a la ligne et on indente |
|
| 4540 | - $i_str = str_pad("", $indent, " "); |
|
| 4541 | - foreach ($u as $k => $v) { |
|
| 4542 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4543 | - } |
|
| 4539 | + // sinon on passe a la ligne et on indente |
|
| 4540 | + $i_str = str_pad("", $indent, " "); |
|
| 4541 | + foreach ($u as $k => $v) { |
|
| 4542 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4543 | + } |
|
| 4544 | 4544 | |
| 4545 | - return $out; |
|
| 4546 | - } |
|
| 4545 | + return $out; |
|
| 4546 | + } |
|
| 4547 | 4547 | |
| 4548 | - // on sait pas quoi faire... |
|
| 4549 | - return $u; |
|
| 4548 | + // on sait pas quoi faire... |
|
| 4549 | + return $u; |
|
| 4550 | 4550 | } |
| 4551 | 4551 | |
| 4552 | 4552 | |
@@ -4559,10 +4559,10 @@ discard block |
||
| 4559 | 4559 | * @return string |
| 4560 | 4560 | */ |
| 4561 | 4561 | function objet_info($objet, $info) { |
| 4562 | - $table = table_objet_sql($objet); |
|
| 4563 | - $infos = lister_tables_objets_sql($table); |
|
| 4562 | + $table = table_objet_sql($objet); |
|
| 4563 | + $infos = lister_tables_objets_sql($table); |
|
| 4564 | 4564 | |
| 4565 | - return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 4565 | + return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 4566 | 4566 | } |
| 4567 | 4567 | |
| 4568 | 4568 | /** |
@@ -4577,11 +4577,11 @@ discard block |
||
| 4577 | 4577 | * Texte traduit du comptage, tel que '3 articles' |
| 4578 | 4578 | */ |
| 4579 | 4579 | function objet_afficher_nb($nb, $objet) { |
| 4580 | - if (!$nb) { |
|
| 4581 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4582 | - } else { |
|
| 4583 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb)); |
|
| 4584 | - } |
|
| 4580 | + if (!$nb) { |
|
| 4581 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4582 | + } else { |
|
| 4583 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb)); |
|
| 4584 | + } |
|
| 4585 | 4585 | } |
| 4586 | 4586 | |
| 4587 | 4587 | /** |
@@ -4593,11 +4593,11 @@ discard block |
||
| 4593 | 4593 | * @return string |
| 4594 | 4594 | */ |
| 4595 | 4595 | function objet_icone($objet, $taille = 24, $class='') { |
| 4596 | - $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4597 | - $icone = chemin_image($icone); |
|
| 4598 | - $balise_img = charger_filtre('balise_img'); |
|
| 4596 | + $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4597 | + $icone = chemin_image($icone); |
|
| 4598 | + $balise_img = charger_filtre('balise_img'); |
|
| 4599 | 4599 | |
| 4600 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4600 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4601 | 4601 | } |
| 4602 | 4602 | |
| 4603 | 4603 | /** |
@@ -4618,12 +4618,12 @@ discard block |
||
| 4618 | 4618 | * @return string |
| 4619 | 4619 | */ |
| 4620 | 4620 | function objet_T($objet, $chaine, $args = array(), $options = array()){ |
| 4621 | - $chaine = explode(':',$chaine); |
|
| 4622 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4623 | - return $t; |
|
| 4624 | - } |
|
| 4625 | - $chaine = implode(':',$chaine); |
|
| 4626 | - return _T($chaine, $args, $options); |
|
| 4621 | + $chaine = explode(':',$chaine); |
|
| 4622 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4623 | + return $t; |
|
| 4624 | + } |
|
| 4625 | + $chaine = implode(':',$chaine); |
|
| 4626 | + return _T($chaine, $args, $options); |
|
| 4627 | 4627 | } |
| 4628 | 4628 | |
| 4629 | 4629 | /** |
@@ -4637,17 +4637,17 @@ discard block |
||
| 4637 | 4637 | * @return string Code HTML |
| 4638 | 4638 | */ |
| 4639 | 4639 | function insert_head_css_conditionnel($flux) { |
| 4640 | - if (strpos($flux, '<!-- insert_head_css -->') === false |
|
| 4641 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 4642 | - ) { |
|
| 4643 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4644 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 4645 | - $p = $p1; |
|
| 4646 | - } |
|
| 4647 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4648 | - } |
|
| 4640 | + if (strpos($flux, '<!-- insert_head_css -->') === false |
|
| 4641 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 4642 | + ) { |
|
| 4643 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4644 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 4645 | + $p = $p1; |
|
| 4646 | + } |
|
| 4647 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4648 | + } |
|
| 4649 | 4649 | |
| 4650 | - return $flux; |
|
| 4650 | + return $flux; |
|
| 4651 | 4651 | } |
| 4652 | 4652 | |
| 4653 | 4653 | /** |
@@ -4668,66 +4668,66 @@ discard block |
||
| 4668 | 4668 | * @return string |
| 4669 | 4669 | */ |
| 4670 | 4670 | function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') { |
| 4671 | - if (isset($contexte['format'])) { |
|
| 4672 | - $extension = $contexte['format']; |
|
| 4673 | - unset($contexte['format']); |
|
| 4674 | - } else { |
|
| 4675 | - $extension = "html"; |
|
| 4676 | - if (preg_match(',[.](css|js|json)$,', $fond, $m)) { |
|
| 4677 | - $extension = $m[1]; |
|
| 4678 | - } |
|
| 4679 | - } |
|
| 4680 | - // recuperer le contenu produit par le squelette |
|
| 4681 | - $options['raw'] = true; |
|
| 4682 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4683 | - |
|
| 4684 | - // calculer le nom de la css |
|
| 4685 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4686 | - $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
|
| 4687 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 4688 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" |
|
| 4689 | - . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8) |
|
| 4690 | - . ".$extension"; |
|
| 4691 | - |
|
| 4692 | - // mettre a jour le fichier si il n'existe pas |
|
| 4693 | - // ou trop ancien |
|
| 4694 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 4695 | - // et recopie sur le fichier cible uniquement si il change |
|
| 4696 | - if (!file_exists($filename) |
|
| 4697 | - or !file_exists($filename . ".last") |
|
| 4698 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4699 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 4700 | - ) { |
|
| 4701 | - $contenu = $cache['texte']; |
|
| 4702 | - // passer les urls en absolu si c'est une css |
|
| 4703 | - if ($extension == "css") { |
|
| 4704 | - $contenu = urls_absolues_css($contenu, |
|
| 4705 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)); |
|
| 4706 | - } |
|
| 4707 | - |
|
| 4708 | - $comment = ''; |
|
| 4709 | - // ne pas insérer de commentaire si c'est du json |
|
| 4710 | - if ($extension != "json") { |
|
| 4711 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 4712 | - foreach ($contexte as $k => $v) { |
|
| 4713 | - $comment .= ",$k=$v"; |
|
| 4714 | - } |
|
| 4715 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 4716 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 4717 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4718 | - } |
|
| 4719 | - // et ecrire le fichier |
|
| 4720 | - ecrire_fichier($filename . ".last", $comment . $contenu); |
|
| 4721 | - // regarder si on recopie |
|
| 4722 | - if (!file_exists($filename) |
|
| 4723 | - or md5_file($filename) !== md5_file($filename . ".last") |
|
| 4724 | - ) { |
|
| 4725 | - @copy($filename . ".last", $filename); |
|
| 4726 | - clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp |
|
| 4727 | - } |
|
| 4728 | - } |
|
| 4729 | - |
|
| 4730 | - return timestamp($filename); |
|
| 4671 | + if (isset($contexte['format'])) { |
|
| 4672 | + $extension = $contexte['format']; |
|
| 4673 | + unset($contexte['format']); |
|
| 4674 | + } else { |
|
| 4675 | + $extension = "html"; |
|
| 4676 | + if (preg_match(',[.](css|js|json)$,', $fond, $m)) { |
|
| 4677 | + $extension = $m[1]; |
|
| 4678 | + } |
|
| 4679 | + } |
|
| 4680 | + // recuperer le contenu produit par le squelette |
|
| 4681 | + $options['raw'] = true; |
|
| 4682 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4683 | + |
|
| 4684 | + // calculer le nom de la css |
|
| 4685 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4686 | + $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
|
| 4687 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 4688 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" |
|
| 4689 | + . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8) |
|
| 4690 | + . ".$extension"; |
|
| 4691 | + |
|
| 4692 | + // mettre a jour le fichier si il n'existe pas |
|
| 4693 | + // ou trop ancien |
|
| 4694 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 4695 | + // et recopie sur le fichier cible uniquement si il change |
|
| 4696 | + if (!file_exists($filename) |
|
| 4697 | + or !file_exists($filename . ".last") |
|
| 4698 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4699 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 4700 | + ) { |
|
| 4701 | + $contenu = $cache['texte']; |
|
| 4702 | + // passer les urls en absolu si c'est une css |
|
| 4703 | + if ($extension == "css") { |
|
| 4704 | + $contenu = urls_absolues_css($contenu, |
|
| 4705 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)); |
|
| 4706 | + } |
|
| 4707 | + |
|
| 4708 | + $comment = ''; |
|
| 4709 | + // ne pas insérer de commentaire si c'est du json |
|
| 4710 | + if ($extension != "json") { |
|
| 4711 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 4712 | + foreach ($contexte as $k => $v) { |
|
| 4713 | + $comment .= ",$k=$v"; |
|
| 4714 | + } |
|
| 4715 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 4716 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 4717 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4718 | + } |
|
| 4719 | + // et ecrire le fichier |
|
| 4720 | + ecrire_fichier($filename . ".last", $comment . $contenu); |
|
| 4721 | + // regarder si on recopie |
|
| 4722 | + if (!file_exists($filename) |
|
| 4723 | + or md5_file($filename) !== md5_file($filename . ".last") |
|
| 4724 | + ) { |
|
| 4725 | + @copy($filename . ".last", $filename); |
|
| 4726 | + clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp |
|
| 4727 | + } |
|
| 4728 | + } |
|
| 4729 | + |
|
| 4730 | + return timestamp($filename); |
|
| 4731 | 4731 | } |
| 4732 | 4732 | |
| 4733 | 4733 | /** |
@@ -4740,14 +4740,14 @@ discard block |
||
| 4740 | 4740 | * $fichier auquel on a ajouté le timestamp |
| 4741 | 4741 | */ |
| 4742 | 4742 | function timestamp($fichier) { |
| 4743 | - if (!$fichier |
|
| 4744 | - or !file_exists($fichier) |
|
| 4745 | - or !$m = filemtime($fichier) |
|
| 4746 | - ) { |
|
| 4747 | - return $fichier; |
|
| 4748 | - } |
|
| 4743 | + if (!$fichier |
|
| 4744 | + or !file_exists($fichier) |
|
| 4745 | + or !$m = filemtime($fichier) |
|
| 4746 | + ) { |
|
| 4747 | + return $fichier; |
|
| 4748 | + } |
|
| 4749 | 4749 | |
| 4750 | - return "$fichier?$m"; |
|
| 4750 | + return "$fichier?$m"; |
|
| 4751 | 4751 | } |
| 4752 | 4752 | |
| 4753 | 4753 | /** |
@@ -4757,11 +4757,11 @@ discard block |
||
| 4757 | 4757 | * @return string |
| 4758 | 4758 | */ |
| 4759 | 4759 | function supprimer_timestamp($url) { |
| 4760 | - if (strpos($url, "?") === false) { |
|
| 4761 | - return $url; |
|
| 4762 | - } |
|
| 4760 | + if (strpos($url, "?") === false) { |
|
| 4761 | + return $url; |
|
| 4762 | + } |
|
| 4763 | 4763 | |
| 4764 | - return preg_replace(",\?[[:digit:]]+$,", "", $url); |
|
| 4764 | + return preg_replace(",\?[[:digit:]]+$,", "", $url); |
|
| 4765 | 4765 | } |
| 4766 | 4766 | |
| 4767 | 4767 | /** |
@@ -4776,9 +4776,9 @@ discard block |
||
| 4776 | 4776 | * @return string |
| 4777 | 4777 | */ |
| 4778 | 4778 | function filtre_nettoyer_titre_email_dist($titre) { |
| 4779 | - include_spip('inc/envoyer_mail'); |
|
| 4779 | + include_spip('inc/envoyer_mail'); |
|
| 4780 | 4780 | |
| 4781 | - return nettoyer_titre_email($titre); |
|
| 4781 | + return nettoyer_titre_email($titre); |
|
| 4782 | 4782 | } |
| 4783 | 4783 | |
| 4784 | 4784 | /** |
@@ -4800,19 +4800,19 @@ discard block |
||
| 4800 | 4800 | * @return string |
| 4801 | 4801 | */ |
| 4802 | 4802 | function filtre_chercher_rubrique_dist( |
| 4803 | - $titre, |
|
| 4804 | - $id_objet, |
|
| 4805 | - $id_parent, |
|
| 4806 | - $objet, |
|
| 4807 | - $id_secteur, |
|
| 4808 | - $restreint, |
|
| 4809 | - $actionable = false, |
|
| 4810 | - $retour_sans_cadre = false |
|
| 4803 | + $titre, |
|
| 4804 | + $id_objet, |
|
| 4805 | + $id_parent, |
|
| 4806 | + $objet, |
|
| 4807 | + $id_secteur, |
|
| 4808 | + $restreint, |
|
| 4809 | + $actionable = false, |
|
| 4810 | + $retour_sans_cadre = false |
|
| 4811 | 4811 | ) { |
| 4812 | - include_spip('inc/filtres_ecrire'); |
|
| 4812 | + include_spip('inc/filtres_ecrire'); |
|
| 4813 | 4813 | |
| 4814 | - return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, |
|
| 4815 | - $retour_sans_cadre); |
|
| 4814 | + return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, |
|
| 4815 | + $retour_sans_cadre); |
|
| 4816 | 4816 | } |
| 4817 | 4817 | |
| 4818 | 4818 | /** |
@@ -4841,56 +4841,56 @@ discard block |
||
| 4841 | 4841 | * Chaîne vide si l'accès est autorisé |
| 4842 | 4842 | */ |
| 4843 | 4843 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 4844 | - if ($ok) { |
|
| 4845 | - return ''; |
|
| 4846 | - } |
|
| 4847 | - |
|
| 4848 | - // Vider tous les tampons |
|
| 4849 | - $level = @ob_get_level(); |
|
| 4850 | - while ($level--) { |
|
| 4851 | - @ob_end_clean(); |
|
| 4852 | - } |
|
| 4853 | - |
|
| 4854 | - include_spip('inc/headers'); |
|
| 4855 | - |
|
| 4856 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 4857 | - if ($url) { |
|
| 4858 | - redirige_par_entete($url, '', $statut); |
|
| 4859 | - } |
|
| 4860 | - |
|
| 4861 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 4862 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 4863 | - $message = $statut; |
|
| 4864 | - $statut = 0; |
|
| 4865 | - } |
|
| 4866 | - if (!$message) { |
|
| 4867 | - $message = ''; |
|
| 4868 | - } |
|
| 4869 | - $statut = intval($statut); |
|
| 4870 | - |
|
| 4871 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 4872 | - if (test_espace_prive()) { |
|
| 4873 | - if (!$statut or !in_array($statut, array(404, 403))) { |
|
| 4874 | - $statut = 403; |
|
| 4875 | - } |
|
| 4876 | - http_status(403); |
|
| 4877 | - $echec = charger_fonction('403', 'exec'); |
|
| 4878 | - $echec($message); |
|
| 4879 | - } else { |
|
| 4880 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 4881 | - if (!$statut) { |
|
| 4882 | - $statut = 404; |
|
| 4883 | - } |
|
| 4884 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 4885 | - http_status($statut); |
|
| 4886 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 4887 | - if ($statut >= 400) { |
|
| 4888 | - echo recuperer_fond("$statut", array('erreur' => $message)); |
|
| 4889 | - } |
|
| 4890 | - } |
|
| 4891 | - |
|
| 4892 | - |
|
| 4893 | - exit; |
|
| 4844 | + if ($ok) { |
|
| 4845 | + return ''; |
|
| 4846 | + } |
|
| 4847 | + |
|
| 4848 | + // Vider tous les tampons |
|
| 4849 | + $level = @ob_get_level(); |
|
| 4850 | + while ($level--) { |
|
| 4851 | + @ob_end_clean(); |
|
| 4852 | + } |
|
| 4853 | + |
|
| 4854 | + include_spip('inc/headers'); |
|
| 4855 | + |
|
| 4856 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 4857 | + if ($url) { |
|
| 4858 | + redirige_par_entete($url, '', $statut); |
|
| 4859 | + } |
|
| 4860 | + |
|
| 4861 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 4862 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 4863 | + $message = $statut; |
|
| 4864 | + $statut = 0; |
|
| 4865 | + } |
|
| 4866 | + if (!$message) { |
|
| 4867 | + $message = ''; |
|
| 4868 | + } |
|
| 4869 | + $statut = intval($statut); |
|
| 4870 | + |
|
| 4871 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 4872 | + if (test_espace_prive()) { |
|
| 4873 | + if (!$statut or !in_array($statut, array(404, 403))) { |
|
| 4874 | + $statut = 403; |
|
| 4875 | + } |
|
| 4876 | + http_status(403); |
|
| 4877 | + $echec = charger_fonction('403', 'exec'); |
|
| 4878 | + $echec($message); |
|
| 4879 | + } else { |
|
| 4880 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 4881 | + if (!$statut) { |
|
| 4882 | + $statut = 404; |
|
| 4883 | + } |
|
| 4884 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 4885 | + http_status($statut); |
|
| 4886 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 4887 | + if ($statut >= 400) { |
|
| 4888 | + echo recuperer_fond("$statut", array('erreur' => $message)); |
|
| 4889 | + } |
|
| 4890 | + } |
|
| 4891 | + |
|
| 4892 | + |
|
| 4893 | + exit; |
|
| 4894 | 4894 | } |
| 4895 | 4895 | |
| 4896 | 4896 | /** |
@@ -4901,9 +4901,9 @@ discard block |
||
| 4901 | 4901 | * @return string |
| 4902 | 4902 | */ |
| 4903 | 4903 | function filtre_compacte_dist($source, $format = null) { |
| 4904 | - if (function_exists('compacte')) { |
|
| 4905 | - return compacte($source, $format); |
|
| 4906 | - } |
|
| 4904 | + if (function_exists('compacte')) { |
|
| 4905 | + return compacte($source, $format); |
|
| 4906 | + } |
|
| 4907 | 4907 | |
| 4908 | - return $source; |
|
| 4908 | + return $source; |
|
| 4909 | 4909 | } |