@@ -26,7 +26,7 @@ |
||
| 26 | 26 | * |
| 27 | 27 | * @param string $adresses |
| 28 | 28 | * Adresse ou liste d'adresse (separees pas des virgules) |
| 29 | - * @return bool|string |
|
| 29 | + * @return false|string |
|
| 30 | 30 | * - false si une des adresses n'est pas conforme, |
| 31 | 31 | * - la normalisation de la dernière adresse donnée sinon |
| 32 | 32 | **/ |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Mail |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -31,27 +31,27 @@ discard block |
||
| 31 | 31 | * - la normalisation de la dernière adresse donnée sinon |
| 32 | 32 | **/ |
| 33 | 33 | function inc_email_valide_dist($adresses) { |
| 34 | - // eviter d'injecter n'importe quoi dans preg_match |
|
| 35 | - if (!is_string($adresses)) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Si c'est un spammeur autant arreter tout de suite |
|
| 40 | - if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 41 | - spip_log("Tentative d'injection de mail : $adresses"); |
|
| 42 | - |
|
| 43 | - return false; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - foreach (explode(',', $adresses) as $v) { |
|
| 47 | - // nettoyer certains formats |
|
| 48 | - // "Marie Toto <[email protected]>" |
|
| 49 | - $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 50 | - // RFC 822 |
|
| 51 | - if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) { |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $adresse; |
|
| 34 | + // eviter d'injecter n'importe quoi dans preg_match |
|
| 35 | + if (!is_string($adresses)) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Si c'est un spammeur autant arreter tout de suite |
|
| 40 | + if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 41 | + spip_log("Tentative d'injection de mail : $adresses"); |
|
| 42 | + |
|
| 43 | + return false; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + foreach (explode(',', $adresses) as $v) { |
|
| 47 | + // nettoyer certains formats |
|
| 48 | + // "Marie Toto <[email protected]>" |
|
| 49 | + $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 50 | + // RFC 822 |
|
| 51 | + if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) { |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $adresse; |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @param string $fonc |
| 71 | 71 | * Nom du filtre |
| 72 | - * @param null $default |
|
| 72 | + * @param string $default |
|
| 73 | 73 | * Nom du filtre appliqué par défaut si celui demandé n'est pas trouvé |
| 74 | 74 | * @return string |
| 75 | 75 | * Fonction PHP correspondante du filtre demandé |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @see filtrer() Assez proche |
| 120 | 120 | * |
| 121 | - * @param mixed $arg |
|
| 121 | + * @param string $arg |
|
| 122 | 122 | * Texte (le plus souvent) sur lequel appliquer le filtre |
| 123 | 123 | * @param string $filtre |
| 124 | 124 | * Nom du filtre à appliquer |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | * corriger toutes les `&xx;` en `&xx;` |
| 744 | 744 | * @param bool $quote |
| 745 | 745 | * Échapper aussi les simples quotes en `'` |
| 746 | - * @return mixed|string |
|
| 746 | + * @return string |
|
| 747 | 747 | */ |
| 748 | 748 | function entites_html($texte, $tout = false, $quote = true) { |
| 749 | 749 | if (!is_string($texte) or !$texte |
@@ -1378,7 +1378,7 @@ discard block |
||
| 1378 | 1378 | * |
| 1379 | 1379 | * @param mixed $texte |
| 1380 | 1380 | * Contenu de reference a tester |
| 1381 | - * @param mixed $sinon |
|
| 1381 | + * @param string|null $sinon |
|
| 1382 | 1382 | * Contenu a retourner si le contenu de reference est vide |
| 1383 | 1383 | * @return mixed |
| 1384 | 1384 | * Retourne $texte, sinon $sinon. |
@@ -1560,7 +1560,7 @@ discard block |
||
| 1560 | 1560 | * @param string $letexte |
| 1561 | 1561 | * @param string $lang |
| 1562 | 1562 | * Langue à retrouver (si vide, utilise la langue en cours). |
| 1563 | - * @param array $options Options { |
|
| 1563 | + * @param boolean $options Options { |
|
| 1564 | 1564 | * @type bool $echappe_span |
| 1565 | 1565 | * True pour échapper les balises span (false par défaut) |
| 1566 | 1566 | * @type string $lang_defaut |
@@ -1650,7 +1650,7 @@ discard block |
||
| 1650 | 1650 | * @param string $letexte |
| 1651 | 1651 | * @param string $lang |
| 1652 | 1652 | * Langue à retrouver (si vide, utilise la langue en cours). |
| 1653 | - * @param array $options Options { |
|
| 1653 | + * @param boolean $options Options { |
|
| 1654 | 1654 | * @type bool $echappe_span |
| 1655 | 1655 | * True pour échapper les balises span (false par défaut) |
| 1656 | 1656 | * @type string $lang_defaut |
@@ -2036,6 +2036,9 @@ discard block |
||
| 2036 | 2036 | // Quelques fonctions de calcul arithmetique |
| 2037 | 2037 | // |
| 2038 | 2038 | function floatstr($a) { return str_replace(',','.',(string)floatval($a)); } |
| 2039 | +/** |
|
| 2040 | + * @param string $f |
|
| 2041 | + */ |
|
| 2039 | 2042 | function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); } |
| 2040 | 2043 | |
| 2041 | 2044 | /** |
@@ -2179,7 +2182,7 @@ discard block |
||
| 2179 | 2182 | * @param string|array $adresses |
| 2180 | 2183 | * Adresse ou liste d'adresse |
| 2181 | 2184 | * si on fournit un tableau, il est filtre et la fonction renvoie avec uniquement les adresses email valides (donc possiblement vide) |
| 2182 | - * @return bool|string|array |
|
| 2185 | + * @return string|null |
|
| 2183 | 2186 | * - false si une des adresses n'est pas conforme, |
| 2184 | 2187 | * - la normalisation de la dernière adresse donnée sinon |
| 2185 | 2188 | * - renvoie un tableau si l'entree est un tableau |
@@ -2503,7 +2506,7 @@ discard block |
||
| 2503 | 2506 | * @param int $a |
| 2504 | 2507 | * @param int $b |
| 2505 | 2508 | * @param int $c |
| 2506 | - * @return int |
|
| 2509 | + * @return double |
|
| 2507 | 2510 | * Retourne `$a*$b/$c` |
| 2508 | 2511 | **/ |
| 2509 | 2512 | function regledetrois($a, $b, $c) { |
@@ -4494,7 +4497,7 @@ discard block |
||
| 4494 | 4497 | * Nombre d'éléments |
| 4495 | 4498 | * @param string $objet |
| 4496 | 4499 | * Objet |
| 4497 | - * @return mixed|string |
|
| 4500 | + * @return string |
|
| 4498 | 4501 | * Texte traduit du comptage, tel que '3 articles' |
| 4499 | 4502 | */ |
| 4500 | 4503 | function objet_afficher_nb($nb, $objet) { |
@@ -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,38 +75,38 @@ 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 | - |
|
| 96 | - include_fichiers_fonctions(); |
|
| 97 | - foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 98 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 99 | - // fonction ou name\space\fonction |
|
| 100 | - if (is_callable($f)) { |
|
| 101 | - return $f; |
|
| 102 | - } |
|
| 103 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 104 | - elseif (false === strpos($f, '::') and is_callable(array($f))) { |
|
| 105 | - return $f; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - 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 | + |
|
| 96 | + include_fichiers_fonctions(); |
|
| 97 | + foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 98 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 99 | + // fonction ou name\space\fonction |
|
| 100 | + if (is_callable($f)) { |
|
| 101 | + return $f; |
|
| 102 | + } |
|
| 103 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 104 | + elseif (false === strpos($f, '::') and is_callable(array($f))) { |
|
| 105 | + return $f; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $default; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -130,20 +130,20 @@ discard block |
||
| 130 | 130 | * Chaîne vide sinon (filtre introuvable). |
| 131 | 131 | **/ |
| 132 | 132 | function appliquer_filtre($arg, $filtre, $force = null) { |
| 133 | - $f = chercher_filtre($filtre); |
|
| 134 | - if (!$f) { |
|
| 135 | - if (!$force) { |
|
| 136 | - return ''; |
|
| 137 | - } else { |
|
| 138 | - return $arg; |
|
| 139 | - } |
|
| 140 | - } |
|
| 133 | + $f = chercher_filtre($filtre); |
|
| 134 | + if (!$f) { |
|
| 135 | + if (!$force) { |
|
| 136 | + return ''; |
|
| 137 | + } else { |
|
| 138 | + return $arg; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - $args = func_get_args(); |
|
| 143 | - array_shift($args); // enlever $arg |
|
| 144 | - array_shift($args); // enlever $filtre |
|
| 145 | - array_unshift($args, $arg); // remettre $arg |
|
| 146 | - return call_user_func_array($f, $args); |
|
| 142 | + $args = func_get_args(); |
|
| 143 | + array_shift($args); // enlever $arg |
|
| 144 | + array_shift($args); // enlever $filtre |
|
| 145 | + array_unshift($args, $arg); // remettre $arg |
|
| 146 | + return call_user_func_array($f, $args); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -159,12 +159,12 @@ discard block |
||
| 159 | 159 | * Version de SPIP |
| 160 | 160 | **/ |
| 161 | 161 | function spip_version() { |
| 162 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 163 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 164 | - $version .= " $vcs_version"; |
|
| 165 | - } |
|
| 162 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 163 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 164 | + $version .= " $vcs_version"; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - return $version; |
|
| 167 | + return $version; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -177,19 +177,19 @@ discard block |
||
| 177 | 177 | * - string|null si $raw = false |
| 178 | 178 | */ |
| 179 | 179 | function version_vcs_courante($dir, $raw = false) { |
| 180 | - $desc = decrire_version_git($dir); |
|
| 181 | - if ($desc === null) { |
|
| 182 | - $desc = decrire_version_svn($dir); |
|
| 183 | - } |
|
| 184 | - if ($desc === null or $raw) { |
|
| 185 | - return $desc; |
|
| 186 | - } |
|
| 187 | - // affichage "GIT [master: abcdef]" |
|
| 188 | - $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
|
| 189 | - if ($desc['branch']) { |
|
| 190 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 191 | - } |
|
| 192 | - return "{$desc['vcs']} [$commit]"; |
|
| 180 | + $desc = decrire_version_git($dir); |
|
| 181 | + if ($desc === null) { |
|
| 182 | + $desc = decrire_version_svn($dir); |
|
| 183 | + } |
|
| 184 | + if ($desc === null or $raw) { |
|
| 185 | + return $desc; |
|
| 186 | + } |
|
| 187 | + // affichage "GIT [master: abcdef]" |
|
| 188 | + $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
|
| 189 | + if ($desc['branch']) { |
|
| 190 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 191 | + } |
|
| 192 | + return "{$desc['vcs']} [$commit]"; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -201,24 +201,24 @@ discard block |
||
| 201 | 201 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 202 | 202 | **/ |
| 203 | 203 | function decrire_version_git($dir) { |
| 204 | - if (!$dir) { |
|
| 205 | - $dir = '.'; |
|
| 206 | - } |
|
| 204 | + if (!$dir) { |
|
| 205 | + $dir = '.'; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - // version installee par GIT |
|
| 209 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 210 | - $currentHead = trim(substr($c, 4)); |
|
| 211 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 212 | - return [ |
|
| 213 | - 'vcs' => 'GIT', |
|
| 214 | - 'branch' => basename($currentHead), |
|
| 215 | - 'commit' => trim($hash), |
|
| 216 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 217 | - ]; |
|
| 218 | - } |
|
| 219 | - } |
|
| 208 | + // version installee par GIT |
|
| 209 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 210 | + $currentHead = trim(substr($c, 4)); |
|
| 211 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 212 | + return [ |
|
| 213 | + 'vcs' => 'GIT', |
|
| 214 | + 'branch' => basename($currentHead), |
|
| 215 | + 'commit' => trim($hash), |
|
| 216 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 217 | + ]; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - return null; |
|
| 221 | + return null; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
@@ -231,25 +231,25 @@ discard block |
||
| 231 | 231 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 232 | 232 | **/ |
| 233 | 233 | function decrire_version_svn($dir) { |
| 234 | - if (!$dir) { |
|
| 235 | - $dir = '.'; |
|
| 236 | - } |
|
| 237 | - // version installee par SVN |
|
| 238 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 239 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 240 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 241 | - if ($result) { |
|
| 242 | - $row = $result->fetchArray(); |
|
| 243 | - if ($row['changed_revision'] != "") { |
|
| 244 | - return [ |
|
| 245 | - 'vcs' => 'SVN', |
|
| 246 | - 'branch' => '', |
|
| 247 | - 'commit' => $row['changed_revision'], |
|
| 248 | - ]; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - return null; |
|
| 234 | + if (!$dir) { |
|
| 235 | + $dir = '.'; |
|
| 236 | + } |
|
| 237 | + // version installee par SVN |
|
| 238 | + if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 239 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 240 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 241 | + if ($result) { |
|
| 242 | + $row = $result->fetchArray(); |
|
| 243 | + if ($row['changed_revision'] != "") { |
|
| 244 | + return [ |
|
| 245 | + 'vcs' => 'SVN', |
|
| 246 | + 'branch' => '', |
|
| 247 | + 'commit' => $row['changed_revision'], |
|
| 248 | + ]; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + return null; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -267,10 +267,10 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | **/ |
| 269 | 269 | function version_svn_courante($dir) { |
| 270 | - if ($desc = decrire_version_svn($dir)) { |
|
| 271 | - return -$desc['commit']; |
|
| 272 | - } |
|
| 273 | - return 0; |
|
| 270 | + if ($desc = decrire_version_svn($dir)) { |
|
| 271 | + return -$desc['commit']; |
|
| 272 | + } |
|
| 273 | + return 0; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -314,18 +314,18 @@ discard block |
||
| 314 | 314 | * Code HTML retourné par le filtre |
| 315 | 315 | **/ |
| 316 | 316 | function filtrer($filtre) { |
| 317 | - $tous = func_get_args(); |
|
| 318 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 319 | - return image_filtrer($tous); |
|
| 320 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 321 | - array_shift($tous); |
|
| 322 | - return call_user_func_array($f, $tous); |
|
| 323 | - } else { |
|
| 324 | - // le filtre n'existe pas, on provoque une erreur |
|
| 325 | - $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre))); |
|
| 326 | - erreur_squelette($msg); |
|
| 327 | - return ''; |
|
| 328 | - } |
|
| 317 | + $tous = func_get_args(); |
|
| 318 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 319 | + return image_filtrer($tous); |
|
| 320 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 321 | + array_shift($tous); |
|
| 322 | + return call_user_func_array($f, $tous); |
|
| 323 | + } else { |
|
| 324 | + // le filtre n'existe pas, on provoque une erreur |
|
| 325 | + $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre))); |
|
| 326 | + erreur_squelette($msg); |
|
| 327 | + return ''; |
|
| 328 | + } |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 343 | 343 | */ |
| 344 | 344 | function trouver_filtre_matrice($filtre) { |
| 345 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 346 | - find_in_path($f, '', true); |
|
| 347 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 348 | - } |
|
| 349 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 345 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 346 | + find_in_path($f, '', true); |
|
| 347 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 348 | + } |
|
| 349 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | * @return mixed |
| 375 | 375 | */ |
| 376 | 376 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 377 | - $Pile['vars'][$key] = $val; |
|
| 378 | - return $continue ? $val : ''; |
|
| 377 | + $Pile['vars'][$key] = $val; |
|
| 378 | + return $continue ? $val : ''; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 402 | 402 | */ |
| 403 | 403 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 404 | - $Pile[0][$key] = $val; |
|
| 405 | - return $continue ? $val : ''; |
|
| 404 | + $Pile[0][$key] = $val; |
|
| 405 | + return $continue ? $val : ''; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | * @return string |
| 412 | 412 | */ |
| 413 | 413 | function filtre_sanitize_env(&$Pile, $keys) { |
| 414 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 415 | - return ''; |
|
| 414 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 415 | + return ''; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -435,18 +435,18 @@ discard block |
||
| 435 | 435 | * @return mixed Retourne la valeur (sans la modifier). |
| 436 | 436 | */ |
| 437 | 437 | function filtre_debug($val, $key = null) { |
| 438 | - $debug = ( |
|
| 439 | - is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 440 | - ) . var_export($val, true); |
|
| 438 | + $debug = ( |
|
| 439 | + is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 440 | + ) . var_export($val, true); |
|
| 441 | 441 | |
| 442 | - include_spip('inc/autoriser'); |
|
| 443 | - if (autoriser('webmestre')) { |
|
| 444 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 445 | - } |
|
| 442 | + include_spip('inc/autoriser'); |
|
| 443 | + if (autoriser('webmestre')) { |
|
| 444 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - spip_log($debug, 'debug'); |
|
| 447 | + spip_log($debug, 'debug'); |
|
| 448 | 448 | |
| 449 | - return $val; |
|
| 449 | + return $val; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -474,77 +474,77 @@ discard block |
||
| 474 | 474 | * Texte qui a reçu les filtres |
| 475 | 475 | **/ |
| 476 | 476 | function image_filtrer($args) { |
| 477 | - $filtre = array_shift($args); # enlever $filtre |
|
| 478 | - $texte = array_shift($args); |
|
| 479 | - if (!strlen($texte)) { |
|
| 480 | - return; |
|
| 481 | - } |
|
| 482 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 483 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 484 | - // Cas du nom de fichier local |
|
| 485 | - $is_file = trim($texte); |
|
| 486 | - if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 487 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 488 | - or strpos($is_file, '/') === 0 |
|
| 489 | - ) { |
|
| 490 | - $is_file = false; |
|
| 491 | - } |
|
| 492 | - if ($is_file |
|
| 493 | - and ( |
|
| 494 | - file_exists(supprimer_timestamp($is_file)) |
|
| 495 | - or tester_url_absolue($is_file) |
|
| 496 | - ) |
|
| 497 | - ) { |
|
| 498 | - array_unshift($args, "<img src='$is_file' />"); |
|
| 499 | - $res = call_user_func_array($filtre, $args); |
|
| 500 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 501 | - return $res; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 505 | - if (preg_match_all( |
|
| 506 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 507 | - $texte, $tags, PREG_SET_ORDER)) { |
|
| 508 | - foreach ($tags as $tag) { |
|
| 509 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 510 | - if (!$class or |
|
| 511 | - (strpos($class, 'filtre_inactif') === false |
|
| 512 | - // compat historique a virer en 3.2 |
|
| 513 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 514 | - ) { |
|
| 515 | - array_unshift($args, $tag[3]); |
|
| 516 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 517 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 518 | - if ($tag[1]) { |
|
| 519 | - $w = extraire_attribut($reduit, 'width'); |
|
| 520 | - if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) { |
|
| 521 | - $w = $regs[1]; |
|
| 522 | - } |
|
| 523 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 524 | - $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 525 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 526 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - // traiter aussi un eventuel mouseover |
|
| 530 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 531 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 532 | - $srcover = $match[1]; |
|
| 533 | - array_shift($args); |
|
| 534 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 535 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 536 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 537 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 541 | - } |
|
| 542 | - array_shift($args); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 547 | - return $texte; |
|
| 477 | + $filtre = array_shift($args); # enlever $filtre |
|
| 478 | + $texte = array_shift($args); |
|
| 479 | + if (!strlen($texte)) { |
|
| 480 | + return; |
|
| 481 | + } |
|
| 482 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 483 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 484 | + // Cas du nom de fichier local |
|
| 485 | + $is_file = trim($texte); |
|
| 486 | + if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 487 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 488 | + or strpos($is_file, '/') === 0 |
|
| 489 | + ) { |
|
| 490 | + $is_file = false; |
|
| 491 | + } |
|
| 492 | + if ($is_file |
|
| 493 | + and ( |
|
| 494 | + file_exists(supprimer_timestamp($is_file)) |
|
| 495 | + or tester_url_absolue($is_file) |
|
| 496 | + ) |
|
| 497 | + ) { |
|
| 498 | + array_unshift($args, "<img src='$is_file' />"); |
|
| 499 | + $res = call_user_func_array($filtre, $args); |
|
| 500 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 501 | + return $res; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 505 | + if (preg_match_all( |
|
| 506 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 507 | + $texte, $tags, PREG_SET_ORDER)) { |
|
| 508 | + foreach ($tags as $tag) { |
|
| 509 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 510 | + if (!$class or |
|
| 511 | + (strpos($class, 'filtre_inactif') === false |
|
| 512 | + // compat historique a virer en 3.2 |
|
| 513 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 514 | + ) { |
|
| 515 | + array_unshift($args, $tag[3]); |
|
| 516 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 517 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 518 | + if ($tag[1]) { |
|
| 519 | + $w = extraire_attribut($reduit, 'width'); |
|
| 520 | + if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) { |
|
| 521 | + $w = $regs[1]; |
|
| 522 | + } |
|
| 523 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 524 | + $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 525 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 526 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + // traiter aussi un eventuel mouseover |
|
| 530 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 531 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 532 | + $srcover = $match[1]; |
|
| 533 | + array_shift($args); |
|
| 534 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 535 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 536 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 537 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 541 | + } |
|
| 542 | + array_shift($args); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 547 | + return $texte; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -559,65 +559,65 @@ discard block |
||
| 559 | 559 | **/ |
| 560 | 560 | function taille_image($img, $force_refresh = false) { |
| 561 | 561 | |
| 562 | - static $largeur_img = array(), $hauteur_img = array(); |
|
| 563 | - $srcWidth = 0; |
|
| 564 | - $srcHeight = 0; |
|
| 565 | - |
|
| 566 | - $src = extraire_attribut($img, 'src'); |
|
| 567 | - |
|
| 568 | - if (!$src) { |
|
| 569 | - $src = $img; |
|
| 570 | - } else { |
|
| 571 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 572 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 576 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 577 | - if (tester_url_absolue($src)) { |
|
| 578 | - include_spip('inc/distant'); |
|
| 579 | - $fichier = copie_locale($src); |
|
| 580 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 581 | - } |
|
| 582 | - if (($p = strpos($src, '?')) !== false) { |
|
| 583 | - $src = substr($src, 0, $p); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - $srcsize = false; |
|
| 587 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 588 | - $srcWidth = $largeur_img[$src]; |
|
| 589 | - } |
|
| 590 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 591 | - $srcHeight = $hauteur_img[$src]; |
|
| 592 | - } |
|
| 593 | - if (!$srcWidth or !$srcHeight) { |
|
| 594 | - |
|
| 595 | - if (file_exists($src) |
|
| 596 | - and $srcsize = spip_getimagesize($src) |
|
| 597 | - ) { |
|
| 598 | - if (!$srcWidth) { |
|
| 599 | - $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 600 | - } |
|
| 601 | - if (!$srcHeight) { |
|
| 602 | - $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 606 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 607 | - elseif (@file_exists($f = "$src.src") |
|
| 608 | - and lire_fichier($f, $valeurs) |
|
| 609 | - and $valeurs = unserialize($valeurs) |
|
| 610 | - ) { |
|
| 611 | - if (!$srcWidth) { |
|
| 612 | - $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 613 | - } |
|
| 614 | - if (!$srcHeight) { |
|
| 615 | - $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return array($srcHeight, $srcWidth); |
|
| 562 | + static $largeur_img = array(), $hauteur_img = array(); |
|
| 563 | + $srcWidth = 0; |
|
| 564 | + $srcHeight = 0; |
|
| 565 | + |
|
| 566 | + $src = extraire_attribut($img, 'src'); |
|
| 567 | + |
|
| 568 | + if (!$src) { |
|
| 569 | + $src = $img; |
|
| 570 | + } else { |
|
| 571 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 572 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 576 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 577 | + if (tester_url_absolue($src)) { |
|
| 578 | + include_spip('inc/distant'); |
|
| 579 | + $fichier = copie_locale($src); |
|
| 580 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 581 | + } |
|
| 582 | + if (($p = strpos($src, '?')) !== false) { |
|
| 583 | + $src = substr($src, 0, $p); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + $srcsize = false; |
|
| 587 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 588 | + $srcWidth = $largeur_img[$src]; |
|
| 589 | + } |
|
| 590 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 591 | + $srcHeight = $hauteur_img[$src]; |
|
| 592 | + } |
|
| 593 | + if (!$srcWidth or !$srcHeight) { |
|
| 594 | + |
|
| 595 | + if (file_exists($src) |
|
| 596 | + and $srcsize = spip_getimagesize($src) |
|
| 597 | + ) { |
|
| 598 | + if (!$srcWidth) { |
|
| 599 | + $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 600 | + } |
|
| 601 | + if (!$srcHeight) { |
|
| 602 | + $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 606 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 607 | + elseif (@file_exists($f = "$src.src") |
|
| 608 | + and lire_fichier($f, $valeurs) |
|
| 609 | + and $valeurs = unserialize($valeurs) |
|
| 610 | + ) { |
|
| 611 | + if (!$srcWidth) { |
|
| 612 | + $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 613 | + } |
|
| 614 | + if (!$srcHeight) { |
|
| 615 | + $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return array($srcHeight, $srcWidth); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | |
@@ -635,12 +635,12 @@ discard block |
||
| 635 | 635 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 636 | 636 | **/ |
| 637 | 637 | function largeur($img) { |
| 638 | - if (!$img) { |
|
| 639 | - return; |
|
| 640 | - } |
|
| 641 | - list($h, $l) = taille_image($img); |
|
| 638 | + if (!$img) { |
|
| 639 | + return; |
|
| 640 | + } |
|
| 641 | + list($h, $l) = taille_image($img); |
|
| 642 | 642 | |
| 643 | - return $l; |
|
| 643 | + return $l; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 658 | 658 | **/ |
| 659 | 659 | function hauteur($img) { |
| 660 | - if (!$img) { |
|
| 661 | - return; |
|
| 662 | - } |
|
| 663 | - list($h, $l) = taille_image($img); |
|
| 660 | + if (!$img) { |
|
| 661 | + return; |
|
| 662 | + } |
|
| 663 | + list($h, $l) = taille_image($img); |
|
| 664 | 664 | |
| 665 | - return $h; |
|
| 665 | + return $h; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -682,11 +682,11 @@ discard block |
||
| 682 | 682 | * @return string |
| 683 | 683 | **/ |
| 684 | 684 | function corriger_entites_html($texte) { |
| 685 | - if (strpos($texte, '&') === false) { |
|
| 686 | - return $texte; |
|
| 687 | - } |
|
| 685 | + if (strpos($texte, '&') === false) { |
|
| 686 | + return $texte; |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 689 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -701,11 +701,11 @@ discard block |
||
| 701 | 701 | * @return string |
| 702 | 702 | **/ |
| 703 | 703 | function corriger_toutes_entites_html($texte) { |
| 704 | - if (strpos($texte, '&') === false) { |
|
| 705 | - return $texte; |
|
| 706 | - } |
|
| 704 | + if (strpos($texte, '&') === false) { |
|
| 705 | + return $texte; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 708 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @return string |
| 716 | 716 | **/ |
| 717 | 717 | function proteger_amp($texte) { |
| 718 | - return str_replace('&', '&', $texte); |
|
| 718 | + return str_replace('&', '&', $texte); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | |
@@ -746,20 +746,20 @@ discard block |
||
| 746 | 746 | * @return mixed|string |
| 747 | 747 | */ |
| 748 | 748 | function entites_html($texte, $tout = false, $quote = true) { |
| 749 | - if (!is_string($texte) or !$texte |
|
| 750 | - or strpbrk($texte, "&\"'<>") == false |
|
| 751 | - ) { |
|
| 752 | - return $texte; |
|
| 753 | - } |
|
| 754 | - include_spip('inc/texte'); |
|
| 755 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 756 | - $flags |= ENT_HTML401; |
|
| 757 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 758 | - if ($tout) { |
|
| 759 | - return corriger_toutes_entites_html($texte); |
|
| 760 | - } else { |
|
| 761 | - return corriger_entites_html($texte); |
|
| 762 | - } |
|
| 749 | + if (!is_string($texte) or !$texte |
|
| 750 | + or strpbrk($texte, "&\"'<>") == false |
|
| 751 | + ) { |
|
| 752 | + return $texte; |
|
| 753 | + } |
|
| 754 | + include_spip('inc/texte'); |
|
| 755 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 756 | + $flags |= ENT_HTML401; |
|
| 757 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 758 | + if ($tout) { |
|
| 759 | + return corriger_toutes_entites_html($texte); |
|
| 760 | + } else { |
|
| 761 | + return corriger_entites_html($texte); |
|
| 762 | + } |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -778,37 +778,37 @@ discard block |
||
| 778 | 778 | * Texte converti |
| 779 | 779 | **/ |
| 780 | 780 | function filtrer_entites($texte) { |
| 781 | - if (strpos($texte, '&') === false) { |
|
| 782 | - return $texte; |
|
| 783 | - } |
|
| 784 | - // filtrer |
|
| 785 | - $texte = html2unicode($texte); |
|
| 786 | - // remettre le tout dans le charset cible |
|
| 787 | - $texte = unicode2charset($texte); |
|
| 788 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 789 | - // (on le faisait deja avec un ") |
|
| 790 | - if (strpos($texte, "&#") !== false) { |
|
| 791 | - $texte = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $texte); |
|
| 792 | - } |
|
| 781 | + if (strpos($texte, '&') === false) { |
|
| 782 | + return $texte; |
|
| 783 | + } |
|
| 784 | + // filtrer |
|
| 785 | + $texte = html2unicode($texte); |
|
| 786 | + // remettre le tout dans le charset cible |
|
| 787 | + $texte = unicode2charset($texte); |
|
| 788 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 789 | + // (on le faisait deja avec un ") |
|
| 790 | + if (strpos($texte, "&#") !== false) { |
|
| 791 | + $texte = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $texte); |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - return $texte; |
|
| 794 | + return $texte; |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | |
| 798 | 798 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 799 | - /** |
|
| 800 | - * Version sécurisée de filtrer_entites |
|
| 801 | - * |
|
| 802 | - * @uses interdire_scripts() |
|
| 803 | - * @uses filtrer_entites() |
|
| 804 | - * |
|
| 805 | - * @param string $t |
|
| 806 | - * @return string |
|
| 807 | - */ |
|
| 808 | - function filtre_filtrer_entites_dist($t) { |
|
| 809 | - include_spip('inc/texte'); |
|
| 810 | - return interdire_scripts(filtrer_entites($t)); |
|
| 811 | - } |
|
| 799 | + /** |
|
| 800 | + * Version sécurisée de filtrer_entites |
|
| 801 | + * |
|
| 802 | + * @uses interdire_scripts() |
|
| 803 | + * @uses filtrer_entites() |
|
| 804 | + * |
|
| 805 | + * @param string $t |
|
| 806 | + * @return string |
|
| 807 | + */ |
|
| 808 | + function filtre_filtrer_entites_dist($t) { |
|
| 809 | + include_spip('inc/texte'); |
|
| 810 | + return interdire_scripts(filtrer_entites($t)); |
|
| 811 | + } |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | |
@@ -823,18 +823,18 @@ discard block |
||
| 823 | 823 | * @return string|array |
| 824 | 824 | **/ |
| 825 | 825 | function supprimer_caracteres_illegaux($texte) { |
| 826 | - 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"; |
|
| 827 | - static $to = null; |
|
| 826 | + 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"; |
|
| 827 | + static $to = null; |
|
| 828 | 828 | |
| 829 | - if (is_array($texte)) { |
|
| 830 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 831 | - } |
|
| 829 | + if (is_array($texte)) { |
|
| 830 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 831 | + } |
|
| 832 | 832 | |
| 833 | - if (!$to) { |
|
| 834 | - $to = str_repeat('-', strlen($from)); |
|
| 835 | - } |
|
| 833 | + if (!$to) { |
|
| 834 | + $to = str_repeat('-', strlen($from)); |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | - return strtr($texte, $from, $to); |
|
| 837 | + return strtr($texte, $from, $to); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
@@ -846,10 +846,10 @@ discard block |
||
| 846 | 846 | * @return string|array |
| 847 | 847 | **/ |
| 848 | 848 | function corriger_caracteres($texte) { |
| 849 | - $texte = corriger_caracteres_windows($texte); |
|
| 850 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 849 | + $texte = corriger_caracteres_windows($texte); |
|
| 850 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 851 | 851 | |
| 852 | - return $texte; |
|
| 852 | + return $texte; |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
@@ -867,40 +867,40 @@ discard block |
||
| 867 | 867 | */ |
| 868 | 868 | function texte_backend($texte) { |
| 869 | 869 | |
| 870 | - static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 870 | + static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 871 | 871 | |
| 872 | - // si on a des liens ou des images, les passer en absolu |
|
| 873 | - $texte = liens_absolus($texte); |
|
| 872 | + // si on a des liens ou des images, les passer en absolu |
|
| 873 | + $texte = liens_absolus($texte); |
|
| 874 | 874 | |
| 875 | - // echapper les tags > < |
|
| 876 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 875 | + // echapper les tags > < |
|
| 876 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 877 | 877 | |
| 878 | - // importer les é |
|
| 879 | - $texte = filtrer_entites($texte); |
|
| 878 | + // importer les é |
|
| 879 | + $texte = filtrer_entites($texte); |
|
| 880 | 880 | |
| 881 | - // " -> " et tout ce genre de choses |
|
| 882 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 883 | - $texte = str_replace(" ", " ", $texte); |
|
| 884 | - $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 885 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 886 | - $texte = entites_html($texte, false, false); |
|
| 887 | - // mais bien echapper les double quotes ! |
|
| 888 | - $texte = str_replace('"', '"', $texte); |
|
| 881 | + // " -> " et tout ce genre de choses |
|
| 882 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 883 | + $texte = str_replace(" ", " ", $texte); |
|
| 884 | + $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 885 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 886 | + $texte = entites_html($texte, false, false); |
|
| 887 | + // mais bien echapper les double quotes ! |
|
| 888 | + $texte = str_replace('"', '"', $texte); |
|
| 889 | 889 | |
| 890 | - // verifier le charset |
|
| 891 | - $texte = charset2unicode($texte); |
|
| 890 | + // verifier le charset |
|
| 891 | + $texte = charset2unicode($texte); |
|
| 892 | 892 | |
| 893 | - // Caracteres problematiques en iso-latin 1 |
|
| 894 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 895 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 896 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 897 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 898 | - } |
|
| 893 | + // Caracteres problematiques en iso-latin 1 |
|
| 894 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 895 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 896 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 897 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 901 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 902 | - // ==> on les remplace par l'entite HTML |
|
| 903 | - return str_replace($apostrophe, "'", $texte); |
|
| 900 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 901 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 902 | + // ==> on les remplace par l'entite HTML |
|
| 903 | + return str_replace($apostrophe, "'", $texte); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | * Texte encodé et quote pour XML |
| 918 | 918 | */ |
| 919 | 919 | function texte_backendq($texte) { |
| 920 | - return addslashes(texte_backend($texte)); |
|
| 920 | + return addslashes(texte_backend($texte)); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | |
@@ -940,9 +940,9 @@ discard block |
||
| 940 | 940 | * Numéro de titre, sinon chaîne vide |
| 941 | 941 | **/ |
| 942 | 942 | function supprimer_numero($texte) { |
| 943 | - return preg_replace( |
|
| 944 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 945 | - "", $texte); |
|
| 943 | + return preg_replace( |
|
| 944 | + ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 945 | + "", $texte); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | /** |
@@ -965,13 +965,13 @@ discard block |
||
| 965 | 965 | * Numéro de titre, sinon chaîne vide |
| 966 | 966 | **/ |
| 967 | 967 | function recuperer_numero($texte) { |
| 968 | - if (preg_match( |
|
| 969 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 970 | - $texte, $regs)) { |
|
| 971 | - return strval($regs[1]); |
|
| 972 | - } else { |
|
| 973 | - return ''; |
|
| 974 | - } |
|
| 968 | + if (preg_match( |
|
| 969 | + ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 970 | + $texte, $regs)) { |
|
| 971 | + return strval($regs[1]); |
|
| 972 | + } else { |
|
| 973 | + return ''; |
|
| 974 | + } |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | /** |
@@ -998,13 +998,13 @@ discard block |
||
| 998 | 998 | * Texte converti |
| 999 | 999 | **/ |
| 1000 | 1000 | function supprimer_tags($texte, $rempl = "") { |
| 1001 | - $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte); |
|
| 1002 | - // ne pas oublier un < final non ferme car coupe |
|
| 1003 | - $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte); |
|
| 1004 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1005 | - $texte = str_replace('<', '<', $texte); |
|
| 1001 | + $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte); |
|
| 1002 | + // ne pas oublier un < final non ferme car coupe |
|
| 1003 | + $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte); |
|
| 1004 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1005 | + $texte = str_replace('<', '<', $texte); |
|
| 1006 | 1006 | |
| 1007 | - return $texte; |
|
| 1007 | + return $texte; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1027,9 +1027,9 @@ discard block |
||
| 1027 | 1027 | * Texte converti |
| 1028 | 1028 | **/ |
| 1029 | 1029 | function echapper_tags($texte, $rempl = "") { |
| 1030 | - $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 1030 | + $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 1031 | 1031 | |
| 1032 | - return $texte; |
|
| 1032 | + return $texte; |
|
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | /** |
@@ -1050,18 +1050,18 @@ discard block |
||
| 1050 | 1050 | * Texte converti |
| 1051 | 1051 | **/ |
| 1052 | 1052 | function textebrut($texte) { |
| 1053 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1054 | - $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 1055 | - $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 1056 | - $texte = preg_replace("/^\n+/", "", $texte); |
|
| 1057 | - $texte = preg_replace("/\n+$/", "", $texte); |
|
| 1058 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1059 | - $texte = supprimer_tags($texte); |
|
| 1060 | - $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 1061 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1062 | - $texte = str_replace("’", "'", $texte); |
|
| 1053 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1054 | + $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 1055 | + $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 1056 | + $texte = preg_replace("/^\n+/", "", $texte); |
|
| 1057 | + $texte = preg_replace("/\n+$/", "", $texte); |
|
| 1058 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1059 | + $texte = supprimer_tags($texte); |
|
| 1060 | + $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 1061 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1062 | + $texte = str_replace("’", "'", $texte); |
|
| 1063 | 1063 | |
| 1064 | - return $texte; |
|
| 1064 | + return $texte; |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | |
@@ -1077,17 +1077,17 @@ discard block |
||
| 1077 | 1077 | * Texte avec liens ouvrants |
| 1078 | 1078 | **/ |
| 1079 | 1079 | function liens_ouvrants($texte) { |
| 1080 | - if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1081 | - $texte, $liens, PREG_PATTERN_ORDER)) { |
|
| 1082 | - foreach ($liens[0] as $a) { |
|
| 1083 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1084 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1085 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1086 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1080 | + if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1081 | + $texte, $liens, PREG_PATTERN_ORDER)) { |
|
| 1082 | + foreach ($liens[0] as $a) { |
|
| 1083 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1084 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1085 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1086 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | 1089 | |
| 1090 | - return $texte; |
|
| 1090 | + return $texte; |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | /** |
@@ -1097,22 +1097,22 @@ discard block |
||
| 1097 | 1097 | * @return string |
| 1098 | 1098 | */ |
| 1099 | 1099 | function liens_nofollow($texte) { |
| 1100 | - if (stripos($texte, "<a") === false) { |
|
| 1101 | - return $texte; |
|
| 1102 | - } |
|
| 1100 | + if (stripos($texte, "<a") === false) { |
|
| 1101 | + return $texte; |
|
| 1102 | + } |
|
| 1103 | 1103 | |
| 1104 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1105 | - foreach ($regs[0] as $a) { |
|
| 1106 | - $rel = extraire_attribut($a, "rel"); |
|
| 1107 | - if (strpos($rel, "nofollow") === false) { |
|
| 1108 | - $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1109 | - $anofollow = inserer_attribut($a, "rel", $rel); |
|
| 1110 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1104 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1105 | + foreach ($regs[0] as $a) { |
|
| 1106 | + $rel = extraire_attribut($a, "rel"); |
|
| 1107 | + if (strpos($rel, "nofollow") === false) { |
|
| 1108 | + $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1109 | + $anofollow = inserer_attribut($a, "rel", $rel); |
|
| 1110 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | 1114 | |
| 1115 | - return $texte; |
|
| 1115 | + return $texte; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1131,12 +1131,12 @@ discard block |
||
| 1131 | 1131 | * Texte sans paraghaphes |
| 1132 | 1132 | **/ |
| 1133 | 1133 | function PtoBR($texte) { |
| 1134 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1135 | - $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 1136 | - $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 1137 | - $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1134 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1135 | + $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 1136 | + $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 1137 | + $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1138 | 1138 | |
| 1139 | - return $texte; |
|
| 1139 | + return $texte; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | |
@@ -1160,14 +1160,14 @@ discard block |
||
| 1160 | 1160 | * @return string Texte encadré du style CSS |
| 1161 | 1161 | */ |
| 1162 | 1162 | function lignes_longues($texte) { |
| 1163 | - if (!strlen(trim($texte))) { |
|
| 1164 | - return $texte; |
|
| 1165 | - } |
|
| 1166 | - include_spip('inc/texte'); |
|
| 1167 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1168 | - 'div' : 'span'; |
|
| 1163 | + if (!strlen(trim($texte))) { |
|
| 1164 | + return $texte; |
|
| 1165 | + } |
|
| 1166 | + include_spip('inc/texte'); |
|
| 1167 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1168 | + 'div' : 'span'; |
|
| 1169 | 1169 | |
| 1170 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1170 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | /** |
@@ -1186,30 +1186,30 @@ discard block |
||
| 1186 | 1186 | * @return string Texte en majuscule |
| 1187 | 1187 | */ |
| 1188 | 1188 | function majuscules($texte) { |
| 1189 | - if (!strlen($texte)) { |
|
| 1190 | - return ''; |
|
| 1191 | - } |
|
| 1189 | + if (!strlen($texte)) { |
|
| 1190 | + return ''; |
|
| 1191 | + } |
|
| 1192 | 1192 | |
| 1193 | - // Cas du turc |
|
| 1194 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1195 | - # remplacer hors des tags et des entites |
|
| 1196 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1197 | - foreach ($regs as $n => $match) { |
|
| 1198 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1193 | + // Cas du turc |
|
| 1194 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1195 | + # remplacer hors des tags et des entites |
|
| 1196 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1197 | + foreach ($regs as $n => $match) { |
|
| 1198 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | 1201 | |
| 1202 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1202 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1203 | 1203 | |
| 1204 | - if ($regs) { |
|
| 1205 | - foreach ($regs as $n => $match) { |
|
| 1206 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1204 | + if ($regs) { |
|
| 1205 | + foreach ($regs as $n => $match) { |
|
| 1206 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + } |
|
| 1210 | 1210 | |
| 1211 | - // Cas general |
|
| 1212 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1211 | + // Cas general |
|
| 1212 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | /** |
@@ -1227,29 +1227,29 @@ discard block |
||
| 1227 | 1227 | * @return string |
| 1228 | 1228 | **/ |
| 1229 | 1229 | function taille_en_octets($taille) { |
| 1230 | - if (!defined('_KILOBYTE')) { |
|
| 1231 | - /** |
|
| 1232 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1233 | - * |
|
| 1234 | - * @var int |
|
| 1235 | - **/ |
|
| 1236 | - define('_KILOBYTE', 1024); |
|
| 1237 | - } |
|
| 1230 | + if (!defined('_KILOBYTE')) { |
|
| 1231 | + /** |
|
| 1232 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1233 | + * |
|
| 1234 | + * @var int |
|
| 1235 | + **/ |
|
| 1236 | + define('_KILOBYTE', 1024); |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | - if ($taille < 1) { |
|
| 1240 | - return ''; |
|
| 1241 | - } |
|
| 1242 | - if ($taille < _KILOBYTE) { |
|
| 1243 | - $taille = _T('taille_octets', array('taille' => $taille)); |
|
| 1244 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1245 | - $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1))); |
|
| 1246 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1247 | - $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1))); |
|
| 1248 | - } else { |
|
| 1249 | - $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2))); |
|
| 1250 | - } |
|
| 1239 | + if ($taille < 1) { |
|
| 1240 | + return ''; |
|
| 1241 | + } |
|
| 1242 | + if ($taille < _KILOBYTE) { |
|
| 1243 | + $taille = _T('taille_octets', array('taille' => $taille)); |
|
| 1244 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1245 | + $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1))); |
|
| 1246 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1247 | + $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1))); |
|
| 1248 | + } else { |
|
| 1249 | + $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2))); |
|
| 1250 | + } |
|
| 1251 | 1251 | |
| 1252 | - return $taille; |
|
| 1252 | + return $taille; |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | |
@@ -1271,15 +1271,15 @@ discard block |
||
| 1271 | 1271 | * Texte prêt pour être utilisé en attribut HTML |
| 1272 | 1272 | **/ |
| 1273 | 1273 | function attribut_html($texte, $textebrut = true) { |
| 1274 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1275 | - if ($textebrut) { |
|
| 1276 | - $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1277 | - } |
|
| 1278 | - $texte = texte_backend($texte); |
|
| 1279 | - $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
|
| 1274 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1275 | + if ($textebrut) { |
|
| 1276 | + $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1277 | + } |
|
| 1278 | + $texte = texte_backend($texte); |
|
| 1279 | + $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
|
| 1280 | 1280 | |
| 1281 | - return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&"), |
|
| 1282 | - $texte); |
|
| 1281 | + return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&"), |
|
| 1282 | + $texte); |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | |
@@ -1299,12 +1299,12 @@ discard block |
||
| 1299 | 1299 | * URL ou chaîne vide |
| 1300 | 1300 | **/ |
| 1301 | 1301 | function vider_url($url, $entites = true) { |
| 1302 | - # un message pour abs_url |
|
| 1303 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1304 | - $url = trim($url); |
|
| 1305 | - $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1302 | + # un message pour abs_url |
|
| 1303 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1304 | + $url = trim($url); |
|
| 1305 | + $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1306 | 1306 | |
| 1307 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1307 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | |
@@ -1319,10 +1319,10 @@ discard block |
||
| 1319 | 1319 | * @return string Adresse email maquillée |
| 1320 | 1320 | **/ |
| 1321 | 1321 | function antispam($texte) { |
| 1322 | - include_spip('inc/acces'); |
|
| 1323 | - $masque = creer_pass_aleatoire(3); |
|
| 1322 | + include_spip('inc/acces'); |
|
| 1323 | + $masque = creer_pass_aleatoire(3); |
|
| 1324 | 1324 | |
| 1325 | - return preg_replace("/@/", " $masque ", $texte); |
|
| 1325 | + return preg_replace("/@/", " $masque ", $texte); |
|
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | 1328 | /** |
@@ -1354,12 +1354,12 @@ discard block |
||
| 1354 | 1354 | * True si on a le droit d'accès, false sinon. |
| 1355 | 1355 | **/ |
| 1356 | 1356 | function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1357 | - include_spip('inc/acces'); |
|
| 1358 | - if ($op) { |
|
| 1359 | - $dir .= " $op $args"; |
|
| 1360 | - } |
|
| 1357 | + include_spip('inc/acces'); |
|
| 1358 | + if ($op) { |
|
| 1359 | + $dir .= " $op $args"; |
|
| 1360 | + } |
|
| 1361 | 1361 | |
| 1362 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1362 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | /** |
@@ -1384,11 +1384,11 @@ discard block |
||
| 1384 | 1384 | * Retourne $texte, sinon $sinon. |
| 1385 | 1385 | **/ |
| 1386 | 1386 | function sinon($texte, $sinon = '') { |
| 1387 | - if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1388 | - return $texte; |
|
| 1389 | - } else { |
|
| 1390 | - return $sinon; |
|
| 1391 | - } |
|
| 1387 | + if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1388 | + return $texte; |
|
| 1389 | + } else { |
|
| 1390 | + return $sinon; |
|
| 1391 | + } |
|
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | /** |
@@ -1412,7 +1412,7 @@ discard block |
||
| 1412 | 1412 | * @return mixed |
| 1413 | 1413 | **/ |
| 1414 | 1414 | function choixsivide($a, $vide, $pasvide) { |
| 1415 | - return $a ? $pasvide : $vide; |
|
| 1415 | + return $a ? $pasvide : $vide; |
|
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | 1418 | /** |
@@ -1436,7 +1436,7 @@ discard block |
||
| 1436 | 1436 | * @return mixed |
| 1437 | 1437 | **/ |
| 1438 | 1438 | function choixsiegal($a1, $a2, $v, $f) { |
| 1439 | - return ($a1 == $a2) ? $v : $f; |
|
| 1439 | + return ($a1 == $a2) ? $v : $f; |
|
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | // |
@@ -1455,13 +1455,13 @@ discard block |
||
| 1455 | 1455 | * @return string |
| 1456 | 1456 | **/ |
| 1457 | 1457 | function filtrer_ical($texte) { |
| 1458 | - #include_spip('inc/charsets'); |
|
| 1459 | - $texte = html2unicode($texte); |
|
| 1460 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1461 | - $texte = preg_replace("/\n/", " ", $texte); |
|
| 1462 | - $texte = preg_replace("/,/", "\,", $texte); |
|
| 1458 | + #include_spip('inc/charsets'); |
|
| 1459 | + $texte = html2unicode($texte); |
|
| 1460 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1461 | + $texte = preg_replace("/\n/", " ", $texte); |
|
| 1462 | + $texte = preg_replace("/,/", "\,", $texte); |
|
| 1463 | 1463 | |
| 1464 | - return $texte; |
|
| 1464 | + return $texte; |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | |
@@ -1486,53 +1486,53 @@ discard block |
||
| 1486 | 1486 | * @return string |
| 1487 | 1487 | **/ |
| 1488 | 1488 | function post_autobr($texte, $delim = "\n_ ") { |
| 1489 | - if (!function_exists('echappe_html')) { |
|
| 1490 | - include_spip('inc/texte_mini'); |
|
| 1491 | - } |
|
| 1492 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1493 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1494 | - |
|
| 1495 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1496 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1497 | - } else { |
|
| 1498 | - $fin = ''; |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - $texte = echappe_html($texte, '', true); |
|
| 1502 | - |
|
| 1503 | - // echapper les modeles |
|
| 1504 | - if (strpos($texte, "<") !== false) { |
|
| 1505 | - include_spip('inc/lien'); |
|
| 1506 | - if (defined('_PREG_MODELE')) { |
|
| 1507 | - $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1508 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - $debut = ''; |
|
| 1513 | - $suite = $texte; |
|
| 1514 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1515 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1516 | - $suite = substr($suite, $t); |
|
| 1517 | - $car = substr($suite, 0, 1); |
|
| 1518 | - if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}") |
|
| 1519 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1520 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1521 | - ) { |
|
| 1522 | - $debut .= $delim; |
|
| 1523 | - } else { |
|
| 1524 | - $debut .= "\n"; |
|
| 1525 | - } |
|
| 1526 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1527 | - $debut .= $regs[0]; |
|
| 1528 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - $texte = $debut . $suite; |
|
| 1532 | - |
|
| 1533 | - $texte = echappe_retour($texte); |
|
| 1534 | - |
|
| 1535 | - return $texte . $fin; |
|
| 1489 | + if (!function_exists('echappe_html')) { |
|
| 1490 | + include_spip('inc/texte_mini'); |
|
| 1491 | + } |
|
| 1492 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1493 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1494 | + |
|
| 1495 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1496 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1497 | + } else { |
|
| 1498 | + $fin = ''; |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + $texte = echappe_html($texte, '', true); |
|
| 1502 | + |
|
| 1503 | + // echapper les modeles |
|
| 1504 | + if (strpos($texte, "<") !== false) { |
|
| 1505 | + include_spip('inc/lien'); |
|
| 1506 | + if (defined('_PREG_MODELE')) { |
|
| 1507 | + $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1508 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + $debut = ''; |
|
| 1513 | + $suite = $texte; |
|
| 1514 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1515 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1516 | + $suite = substr($suite, $t); |
|
| 1517 | + $car = substr($suite, 0, 1); |
|
| 1518 | + if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}") |
|
| 1519 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1520 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1521 | + ) { |
|
| 1522 | + $debut .= $delim; |
|
| 1523 | + } else { |
|
| 1524 | + $debut .= "\n"; |
|
| 1525 | + } |
|
| 1526 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1527 | + $debut .= $regs[0]; |
|
| 1528 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + $texte = $debut . $suite; |
|
| 1532 | + |
|
| 1533 | + $texte = echappe_retour($texte); |
|
| 1534 | + |
|
| 1535 | + return $texte . $fin; |
|
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | 1538 | |
@@ -1573,46 +1573,46 @@ discard block |
||
| 1573 | 1573 | * @return string |
| 1574 | 1574 | **/ |
| 1575 | 1575 | function extraire_idiome($letexte, $lang = null, $options = array()) { |
| 1576 | - static $traduire = false; |
|
| 1577 | - if ($letexte |
|
| 1578 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1579 | - ) { |
|
| 1580 | - if (!$traduire) { |
|
| 1581 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1582 | - include_spip('inc/lang'); |
|
| 1583 | - } |
|
| 1584 | - if (!$lang) { |
|
| 1585 | - $lang = $GLOBALS['spip_lang']; |
|
| 1586 | - } |
|
| 1587 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1588 | - if (is_bool($options)) { |
|
| 1589 | - $options = array('echappe_span' => $options); |
|
| 1590 | - } |
|
| 1591 | - if (!isset($options['echappe_span'])) { |
|
| 1592 | - $options = array_merge($options, array('echappe_span' => false)); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - foreach ($regs as $reg) { |
|
| 1596 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1597 | - $desc = $traduire($cle, $lang, true); |
|
| 1598 | - $l = $desc->langue; |
|
| 1599 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1600 | - if (strlen($desc->texte)) { |
|
| 1601 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1602 | - if ($l !== $lang) { |
|
| 1603 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1604 | - } |
|
| 1605 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1606 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1607 | - } |
|
| 1608 | - if (!$options['echappe_span']) { |
|
| 1609 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1610 | - } |
|
| 1611 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1614 | - } |
|
| 1615 | - return $letexte; |
|
| 1576 | + static $traduire = false; |
|
| 1577 | + if ($letexte |
|
| 1578 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1579 | + ) { |
|
| 1580 | + if (!$traduire) { |
|
| 1581 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1582 | + include_spip('inc/lang'); |
|
| 1583 | + } |
|
| 1584 | + if (!$lang) { |
|
| 1585 | + $lang = $GLOBALS['spip_lang']; |
|
| 1586 | + } |
|
| 1587 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1588 | + if (is_bool($options)) { |
|
| 1589 | + $options = array('echappe_span' => $options); |
|
| 1590 | + } |
|
| 1591 | + if (!isset($options['echappe_span'])) { |
|
| 1592 | + $options = array_merge($options, array('echappe_span' => false)); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + foreach ($regs as $reg) { |
|
| 1596 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1597 | + $desc = $traduire($cle, $lang, true); |
|
| 1598 | + $l = $desc->langue; |
|
| 1599 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1600 | + if (strlen($desc->texte)) { |
|
| 1601 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1602 | + if ($l !== $lang) { |
|
| 1603 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1604 | + } |
|
| 1605 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1606 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1607 | + } |
|
| 1608 | + if (!$options['echappe_span']) { |
|
| 1609 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1610 | + } |
|
| 1611 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | + } |
|
| 1615 | + return $letexte; |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | 1618 | /** |
@@ -1664,64 +1664,64 @@ discard block |
||
| 1664 | 1664 | **/ |
| 1665 | 1665 | function extraire_multi($letexte, $lang = null, $options = array()) { |
| 1666 | 1666 | |
| 1667 | - if ($letexte |
|
| 1668 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1669 | - ) { |
|
| 1670 | - if (!$lang) { |
|
| 1671 | - $lang = $GLOBALS['spip_lang']; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1675 | - if (is_bool($options)) { |
|
| 1676 | - $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT); |
|
| 1677 | - } |
|
| 1678 | - if (!isset($options['echappe_span'])) { |
|
| 1679 | - $options = array_merge($options, array('echappe_span' => false)); |
|
| 1680 | - } |
|
| 1681 | - if (!isset($options['lang_defaut'])) { |
|
| 1682 | - $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT)); |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - include_spip('inc/lang'); |
|
| 1686 | - foreach ($regs as $reg) { |
|
| 1687 | - // chercher la version de la langue courante |
|
| 1688 | - $trads = extraire_trads($reg[1]); |
|
| 1689 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1690 | - $trad = $trads[$l]; |
|
| 1691 | - } else { |
|
| 1692 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1693 | - $trad = ''; |
|
| 1694 | - } else { |
|
| 1695 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1696 | - // ou la premiere dispo |
|
| 1697 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1698 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1699 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1700 | - $l = key($trads); |
|
| 1701 | - } |
|
| 1702 | - $trad = $trads[$l]; |
|
| 1703 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1704 | - $trad = $typographie($trad); |
|
| 1705 | - // Tester si on echappe en span ou en div |
|
| 1706 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1707 | - include_spip('inc/texte'); |
|
| 1708 | - $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
|
| 1709 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1710 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1711 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1712 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1713 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1714 | - } |
|
| 1715 | - if (!$options['echappe_span']) { |
|
| 1716 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1717 | - } |
|
| 1718 | - } |
|
| 1719 | - } |
|
| 1720 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1721 | - } |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - return $letexte; |
|
| 1667 | + if ($letexte |
|
| 1668 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1669 | + ) { |
|
| 1670 | + if (!$lang) { |
|
| 1671 | + $lang = $GLOBALS['spip_lang']; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1675 | + if (is_bool($options)) { |
|
| 1676 | + $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT); |
|
| 1677 | + } |
|
| 1678 | + if (!isset($options['echappe_span'])) { |
|
| 1679 | + $options = array_merge($options, array('echappe_span' => false)); |
|
| 1680 | + } |
|
| 1681 | + if (!isset($options['lang_defaut'])) { |
|
| 1682 | + $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT)); |
|
| 1683 | + } |
|
| 1684 | + |
|
| 1685 | + include_spip('inc/lang'); |
|
| 1686 | + foreach ($regs as $reg) { |
|
| 1687 | + // chercher la version de la langue courante |
|
| 1688 | + $trads = extraire_trads($reg[1]); |
|
| 1689 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1690 | + $trad = $trads[$l]; |
|
| 1691 | + } else { |
|
| 1692 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1693 | + $trad = ''; |
|
| 1694 | + } else { |
|
| 1695 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1696 | + // ou la premiere dispo |
|
| 1697 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1698 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1699 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1700 | + $l = key($trads); |
|
| 1701 | + } |
|
| 1702 | + $trad = $trads[$l]; |
|
| 1703 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1704 | + $trad = $typographie($trad); |
|
| 1705 | + // Tester si on echappe en span ou en div |
|
| 1706 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1707 | + include_spip('inc/texte'); |
|
| 1708 | + $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
|
| 1709 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1710 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1711 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1712 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1713 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1714 | + } |
|
| 1715 | + if (!$options['echappe_span']) { |
|
| 1716 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1717 | + } |
|
| 1718 | + } |
|
| 1719 | + } |
|
| 1720 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1721 | + } |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + return $letexte; |
|
| 1725 | 1725 | } |
| 1726 | 1726 | |
| 1727 | 1727 | /** |
@@ -1737,20 +1737,20 @@ discard block |
||
| 1737 | 1737 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1738 | 1738 | **/ |
| 1739 | 1739 | function extraire_trads($bloc) { |
| 1740 | - $lang = ''; |
|
| 1740 | + $lang = ''; |
|
| 1741 | 1741 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1742 | 1742 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1743 | - while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1744 | - $texte = trim($regs[1]); |
|
| 1745 | - if ($texte or $lang) { |
|
| 1746 | - $trads[$lang] = $texte; |
|
| 1747 | - } |
|
| 1748 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1749 | - $lang = $regs[2]; |
|
| 1750 | - } |
|
| 1751 | - $trads[$lang] = $bloc; |
|
| 1743 | + while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1744 | + $texte = trim($regs[1]); |
|
| 1745 | + if ($texte or $lang) { |
|
| 1746 | + $trads[$lang] = $texte; |
|
| 1747 | + } |
|
| 1748 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1749 | + $lang = $regs[2]; |
|
| 1750 | + } |
|
| 1751 | + $trads[$lang] = $bloc; |
|
| 1752 | 1752 | |
| 1753 | - return $trads; |
|
| 1753 | + return $trads; |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | 1756 | |
@@ -1761,7 +1761,7 @@ discard block |
||
| 1761 | 1761 | * @return string L'initiale en majuscule |
| 1762 | 1762 | */ |
| 1763 | 1763 | function filtre_initiale($nom) { |
| 1764 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1764 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1765 | 1765 | } |
| 1766 | 1766 | |
| 1767 | 1767 | |
@@ -1806,33 +1806,33 @@ discard block |
||
| 1806 | 1806 | * - null (interne) : si on empile |
| 1807 | 1807 | **/ |
| 1808 | 1808 | function unique($donnee, $famille = '', $cpt = false) { |
| 1809 | - static $mem = array(); |
|
| 1810 | - // permettre de vider la pile et de la restaurer |
|
| 1811 | - // pour le calcul de introduction... |
|
| 1812 | - if ($famille == '_spip_raz_') { |
|
| 1813 | - $tmp = $mem; |
|
| 1814 | - $mem = array(); |
|
| 1815 | - |
|
| 1816 | - return $tmp; |
|
| 1817 | - } elseif ($famille == '_spip_set_') { |
|
| 1818 | - $mem = $donnee; |
|
| 1819 | - |
|
| 1820 | - return; |
|
| 1821 | - } |
|
| 1822 | - // eviter une notice |
|
| 1823 | - if (!isset($mem[$famille])) { |
|
| 1824 | - $mem[$famille] = array(); |
|
| 1825 | - } |
|
| 1826 | - if ($cpt) { |
|
| 1827 | - return count($mem[$famille]); |
|
| 1828 | - } |
|
| 1829 | - // eviter une notice |
|
| 1830 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1831 | - $mem[$famille][$donnee] = 0; |
|
| 1832 | - } |
|
| 1833 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1834 | - return $donnee; |
|
| 1835 | - } |
|
| 1809 | + static $mem = array(); |
|
| 1810 | + // permettre de vider la pile et de la restaurer |
|
| 1811 | + // pour le calcul de introduction... |
|
| 1812 | + if ($famille == '_spip_raz_') { |
|
| 1813 | + $tmp = $mem; |
|
| 1814 | + $mem = array(); |
|
| 1815 | + |
|
| 1816 | + return $tmp; |
|
| 1817 | + } elseif ($famille == '_spip_set_') { |
|
| 1818 | + $mem = $donnee; |
|
| 1819 | + |
|
| 1820 | + return; |
|
| 1821 | + } |
|
| 1822 | + // eviter une notice |
|
| 1823 | + if (!isset($mem[$famille])) { |
|
| 1824 | + $mem[$famille] = array(); |
|
| 1825 | + } |
|
| 1826 | + if ($cpt) { |
|
| 1827 | + return count($mem[$famille]); |
|
| 1828 | + } |
|
| 1829 | + // eviter une notice |
|
| 1830 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1831 | + $mem[$famille][$donnee] = 0; |
|
| 1832 | + } |
|
| 1833 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1834 | + return $donnee; |
|
| 1835 | + } |
|
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | 1838 | |
@@ -1860,18 +1860,18 @@ discard block |
||
| 1860 | 1860 | * Une des valeurs en fonction du compteur. |
| 1861 | 1861 | **/ |
| 1862 | 1862 | function alterner($i) { |
| 1863 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1864 | - $num = func_num_args(); |
|
| 1865 | - $args = func_get_args(); |
|
| 1863 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1864 | + $num = func_num_args(); |
|
| 1865 | + $args = func_get_args(); |
|
| 1866 | 1866 | |
| 1867 | - if ($num == 2 && is_array($args[1])) { |
|
| 1868 | - $args = $args[1]; |
|
| 1869 | - array_unshift($args, ''); |
|
| 1870 | - $num = count($args); |
|
| 1871 | - } |
|
| 1867 | + if ($num == 2 && is_array($args[1])) { |
|
| 1868 | + $args = $args[1]; |
|
| 1869 | + array_unshift($args, ''); |
|
| 1870 | + $num = count($args); |
|
| 1871 | + } |
|
| 1872 | 1872 | |
| 1873 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1874 | - return $args[(intval($i) - 1) % ($num - 1) + 1]; |
|
| 1873 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1874 | + return $args[(intval($i) - 1) % ($num - 1) + 1]; |
|
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | 1877 | |
@@ -1896,46 +1896,46 @@ discard block |
||
| 1896 | 1896 | * - Tableau complet (si 2e argument) |
| 1897 | 1897 | **/ |
| 1898 | 1898 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1899 | - if (is_array($balise)) { |
|
| 1900 | - array_walk( |
|
| 1901 | - $balise, |
|
| 1902 | - function(&$a, $key, $t){ |
|
| 1903 | - $a = extraire_attribut($a, $t); |
|
| 1904 | - }, |
|
| 1905 | - $attribut |
|
| 1906 | - ); |
|
| 1907 | - |
|
| 1908 | - return $balise; |
|
| 1909 | - } |
|
| 1910 | - if (preg_match( |
|
| 1911 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1912 | - . $attribut |
|
| 1913 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1914 | - |
|
| 1915 | - $balise, $r)) { |
|
| 1916 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1917 | - $r[4] = substr($r[3], 1, -1); |
|
| 1918 | - $r[3] = $r[3][0]; |
|
| 1919 | - } elseif ($r[3] !== '') { |
|
| 1920 | - $r[4] = $r[3]; |
|
| 1921 | - $r[3] = ''; |
|
| 1922 | - } else { |
|
| 1923 | - $r[4] = trim($r[2]); |
|
| 1924 | - } |
|
| 1925 | - $att = $r[4]; |
|
| 1926 | - if (strpos($att, "&#") !== false) { |
|
| 1927 | - $att = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $att); |
|
| 1928 | - } |
|
| 1929 | - $att = filtrer_entites($att); |
|
| 1930 | - } else { |
|
| 1931 | - $att = null; |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - if ($complet) { |
|
| 1935 | - return array($att, $r); |
|
| 1936 | - } else { |
|
| 1937 | - return $att; |
|
| 1938 | - } |
|
| 1899 | + if (is_array($balise)) { |
|
| 1900 | + array_walk( |
|
| 1901 | + $balise, |
|
| 1902 | + function(&$a, $key, $t){ |
|
| 1903 | + $a = extraire_attribut($a, $t); |
|
| 1904 | + }, |
|
| 1905 | + $attribut |
|
| 1906 | + ); |
|
| 1907 | + |
|
| 1908 | + return $balise; |
|
| 1909 | + } |
|
| 1910 | + if (preg_match( |
|
| 1911 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1912 | + . $attribut |
|
| 1913 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1914 | + |
|
| 1915 | + $balise, $r)) { |
|
| 1916 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1917 | + $r[4] = substr($r[3], 1, -1); |
|
| 1918 | + $r[3] = $r[3][0]; |
|
| 1919 | + } elseif ($r[3] !== '') { |
|
| 1920 | + $r[4] = $r[3]; |
|
| 1921 | + $r[3] = ''; |
|
| 1922 | + } else { |
|
| 1923 | + $r[4] = trim($r[2]); |
|
| 1924 | + } |
|
| 1925 | + $att = $r[4]; |
|
| 1926 | + if (strpos($att, "&#") !== false) { |
|
| 1927 | + $att = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $att); |
|
| 1928 | + } |
|
| 1929 | + $att = filtrer_entites($att); |
|
| 1930 | + } else { |
|
| 1931 | + $att = null; |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + if ($complet) { |
|
| 1935 | + return array($att, $r); |
|
| 1936 | + } else { |
|
| 1937 | + return $att; |
|
| 1938 | + } |
|
| 1939 | 1939 | } |
| 1940 | 1940 | |
| 1941 | 1941 | /** |
@@ -1967,37 +1967,37 @@ discard block |
||
| 1967 | 1967 | * Code html modifié |
| 1968 | 1968 | **/ |
| 1969 | 1969 | function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) { |
| 1970 | - // preparer l'attribut |
|
| 1971 | - // supprimer les etc mais pas les balises html |
|
| 1972 | - // qui ont un sens dans un attribut value d'un input |
|
| 1973 | - if ($proteger) { |
|
| 1974 | - $val = attribut_html($val, false); |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - // echapper les ' pour eviter tout bug |
|
| 1978 | - $val = str_replace("'", "'", $val); |
|
| 1979 | - if ($vider and strlen($val) == 0) { |
|
| 1980 | - $insert = ''; |
|
| 1981 | - } else { |
|
| 1982 | - $insert = " $attribut='$val'"; |
|
| 1983 | - } |
|
| 1984 | - |
|
| 1985 | - list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1986 | - |
|
| 1987 | - if ($old !== null) { |
|
| 1988 | - // Remplacer l'ancien attribut du meme nom |
|
| 1989 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1990 | - } else { |
|
| 1991 | - // preferer une balise " />" (comme <img />) |
|
| 1992 | - if (preg_match(',/>,', $balise)) { |
|
| 1993 | - $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1994 | - } // sinon une balise <a ...> ... </a> |
|
| 1995 | - else { |
|
| 1996 | - $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1997 | - } |
|
| 1998 | - } |
|
| 1999 | - |
|
| 2000 | - return $balise; |
|
| 1970 | + // preparer l'attribut |
|
| 1971 | + // supprimer les etc mais pas les balises html |
|
| 1972 | + // qui ont un sens dans un attribut value d'un input |
|
| 1973 | + if ($proteger) { |
|
| 1974 | + $val = attribut_html($val, false); |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + // echapper les ' pour eviter tout bug |
|
| 1978 | + $val = str_replace("'", "'", $val); |
|
| 1979 | + if ($vider and strlen($val) == 0) { |
|
| 1980 | + $insert = ''; |
|
| 1981 | + } else { |
|
| 1982 | + $insert = " $attribut='$val'"; |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1986 | + |
|
| 1987 | + if ($old !== null) { |
|
| 1988 | + // Remplacer l'ancien attribut du meme nom |
|
| 1989 | + $balise = $r[1] . $insert . $r[5]; |
|
| 1990 | + } else { |
|
| 1991 | + // preferer une balise " />" (comme <img />) |
|
| 1992 | + if (preg_match(',/>,', $balise)) { |
|
| 1993 | + $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1994 | + } // sinon une balise <a ...> ... </a> |
|
| 1995 | + else { |
|
| 1996 | + $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1997 | + } |
|
| 1998 | + } |
|
| 1999 | + |
|
| 2000 | + return $balise; |
|
| 2001 | 2001 | } |
| 2002 | 2002 | |
| 2003 | 2003 | /** |
@@ -2015,7 +2015,7 @@ discard block |
||
| 2015 | 2015 | * @return string Code HTML sans l'attribut |
| 2016 | 2016 | **/ |
| 2017 | 2017 | function vider_attribut($balise, $attribut) { |
| 2018 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2018 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2019 | 2019 | } |
| 2020 | 2020 | |
| 2021 | 2021 | |
@@ -2027,9 +2027,9 @@ discard block |
||
| 2027 | 2027 | * @return string |
| 2028 | 2028 | */ |
| 2029 | 2029 | function tester_config($id, $mode = '') { |
| 2030 | - include_spip('action/inscrire_auteur'); |
|
| 2030 | + include_spip('action/inscrire_auteur'); |
|
| 2031 | 2031 | |
| 2032 | - return tester_statut_inscription($mode, $id); |
|
| 2032 | + return tester_statut_inscription($mode, $id); |
|
| 2033 | 2033 | } |
| 2034 | 2034 | |
| 2035 | 2035 | // |
@@ -2054,7 +2054,7 @@ discard block |
||
| 2054 | 2054 | * @return int $a+$b |
| 2055 | 2055 | **/ |
| 2056 | 2056 | function plus($a, $b) { |
| 2057 | - return $a + $b; |
|
| 2057 | + return $a + $b; |
|
| 2058 | 2058 | } |
| 2059 | 2059 | function strplus($a, $b) {return strize('plus', $a, $b);} |
| 2060 | 2060 | /** |
@@ -2073,7 +2073,7 @@ discard block |
||
| 2073 | 2073 | * @return int $a-$b |
| 2074 | 2074 | **/ |
| 2075 | 2075 | function moins($a, $b) { |
| 2076 | - return $a - $b; |
|
| 2076 | + return $a - $b; |
|
| 2077 | 2077 | } |
| 2078 | 2078 | function strmoins($a, $b) {return strize('moins', $a, $b);} |
| 2079 | 2079 | |
@@ -2094,7 +2094,7 @@ discard block |
||
| 2094 | 2094 | * @return int $a*$b |
| 2095 | 2095 | **/ |
| 2096 | 2096 | function mult($a, $b) { |
| 2097 | - return $a * $b; |
|
| 2097 | + return $a * $b; |
|
| 2098 | 2098 | } |
| 2099 | 2099 | function strmult($a, $b) {return strize('mult', $a, $b);} |
| 2100 | 2100 | |
@@ -2115,7 +2115,7 @@ discard block |
||
| 2115 | 2115 | * @return int $a/$b (ou 0 si $b est nul) |
| 2116 | 2116 | **/ |
| 2117 | 2117 | function div($a, $b) { |
| 2118 | - return $b ? $a / $b : 0; |
|
| 2118 | + return $b ? $a / $b : 0; |
|
| 2119 | 2119 | } |
| 2120 | 2120 | function strdiv($a, $b) {return strize('div', $a, $b);} |
| 2121 | 2121 | |
@@ -2137,7 +2137,7 @@ discard block |
||
| 2137 | 2137 | * @return int ($nb % $mod) + $add |
| 2138 | 2138 | **/ |
| 2139 | 2139 | function modulo($nb, $mod, $add = 0) { |
| 2140 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2140 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | |
@@ -2152,24 +2152,24 @@ discard block |
||
| 2152 | 2152 | * - true sinon |
| 2153 | 2153 | **/ |
| 2154 | 2154 | function nom_acceptable($nom) { |
| 2155 | - if (!is_string($nom)) { |
|
| 2156 | - return false; |
|
| 2157 | - } |
|
| 2158 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2159 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2160 | - } |
|
| 2161 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2162 | - foreach ($tags_acceptes as $tag) { |
|
| 2163 | - if (strlen($tag)) { |
|
| 2164 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2165 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2166 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2167 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2168 | - } |
|
| 2169 | - } |
|
| 2170 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2155 | + if (!is_string($nom)) { |
|
| 2156 | + return false; |
|
| 2157 | + } |
|
| 2158 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2159 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2160 | + } |
|
| 2161 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2162 | + foreach ($tags_acceptes as $tag) { |
|
| 2163 | + if (strlen($tag)) { |
|
| 2164 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2165 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2166 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2167 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2168 | + } |
|
| 2169 | + } |
|
| 2170 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2171 | 2171 | |
| 2172 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2172 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2173 | 2173 | } |
| 2174 | 2174 | |
| 2175 | 2175 | |
@@ -2185,14 +2185,14 @@ discard block |
||
| 2185 | 2185 | * - renvoie un tableau si l'entree est un tableau |
| 2186 | 2186 | **/ |
| 2187 | 2187 | function email_valide($adresses) { |
| 2188 | - if (is_array($adresses)) { |
|
| 2189 | - $adresses = array_map('email_valide', $adresses); |
|
| 2190 | - $adresses = array_filter($adresses); |
|
| 2191 | - return $adresses; |
|
| 2192 | - } |
|
| 2188 | + if (is_array($adresses)) { |
|
| 2189 | + $adresses = array_map('email_valide', $adresses); |
|
| 2190 | + $adresses = array_filter($adresses); |
|
| 2191 | + return $adresses; |
|
| 2192 | + } |
|
| 2193 | 2193 | |
| 2194 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2195 | - return $email_valide($adresses); |
|
| 2194 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2195 | + return $email_valide($adresses); |
|
| 2196 | 2196 | } |
| 2197 | 2197 | |
| 2198 | 2198 | /** |
@@ -2206,20 +2206,20 @@ discard block |
||
| 2206 | 2206 | * @return string Texte |
| 2207 | 2207 | **/ |
| 2208 | 2208 | function afficher_enclosures($tags) { |
| 2209 | - $s = array(); |
|
| 2210 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2211 | - if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2212 | - and $t = extraire_attribut($tag, 'href') |
|
| 2213 | - ) { |
|
| 2214 | - $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 2215 | - '>' |
|
| 2216 | - . http_img_pack('attachment-16.png', $t, |
|
| 2217 | - 'title="' . attribut_html($t) . '"') |
|
| 2218 | - . '</a>', $tag); |
|
| 2219 | - } |
|
| 2220 | - } |
|
| 2209 | + $s = array(); |
|
| 2210 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2211 | + if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2212 | + and $t = extraire_attribut($tag, 'href') |
|
| 2213 | + ) { |
|
| 2214 | + $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 2215 | + '>' |
|
| 2216 | + . http_img_pack('attachment-16.png', $t, |
|
| 2217 | + 'title="' . attribut_html($t) . '"') |
|
| 2218 | + . '</a>', $tag); |
|
| 2219 | + } |
|
| 2220 | + } |
|
| 2221 | 2221 | |
| 2222 | - return join(' ', $s); |
|
| 2222 | + return join(' ', $s); |
|
| 2223 | 2223 | } |
| 2224 | 2224 | |
| 2225 | 2225 | /** |
@@ -2234,15 +2234,15 @@ discard block |
||
| 2234 | 2234 | * @return string Liens trouvés |
| 2235 | 2235 | **/ |
| 2236 | 2236 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2237 | - $s = array(); |
|
| 2238 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2239 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2240 | - if (strstr(",$rels,", ",$rel,")) { |
|
| 2241 | - $s[] = $tag; |
|
| 2242 | - } |
|
| 2243 | - } |
|
| 2237 | + $s = array(); |
|
| 2238 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2239 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2240 | + if (strstr(",$rels,", ",$rel,")) { |
|
| 2241 | + $s[] = $tag; |
|
| 2242 | + } |
|
| 2243 | + } |
|
| 2244 | 2244 | |
| 2245 | - return join(', ', $s); |
|
| 2245 | + return join(', ', $s); |
|
| 2246 | 2246 | } |
| 2247 | 2247 | |
| 2248 | 2248 | |
@@ -2264,21 +2264,21 @@ discard block |
||
| 2264 | 2264 | * @return string Tag HTML `<a>` avec microformat. |
| 2265 | 2265 | **/ |
| 2266 | 2266 | function enclosure2microformat($e) { |
| 2267 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2268 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2269 | - } |
|
| 2270 | - $type = extraire_attribut($e, 'type'); |
|
| 2271 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2272 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2273 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2274 | - } |
|
| 2275 | - $fichier = basename($url); |
|
| 2267 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2268 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2269 | + } |
|
| 2270 | + $type = extraire_attribut($e, 'type'); |
|
| 2271 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2272 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2273 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2274 | + } |
|
| 2275 | + $fichier = basename($url); |
|
| 2276 | 2276 | |
| 2277 | - return '<a rel="enclosure"' |
|
| 2278 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2279 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2280 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2281 | - . '>' . $fichier . '</a>'; |
|
| 2277 | + return '<a rel="enclosure"' |
|
| 2278 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2279 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2280 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2281 | + . '>' . $fichier . '</a>'; |
|
| 2282 | 2282 | } |
| 2283 | 2283 | |
| 2284 | 2284 | /** |
@@ -2296,24 +2296,24 @@ discard block |
||
| 2296 | 2296 | * @return string Tags RSS `<enclosure>`. |
| 2297 | 2297 | **/ |
| 2298 | 2298 | function microformat2enclosure($tags) { |
| 2299 | - $enclosures = array(); |
|
| 2300 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2301 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2302 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2303 | - $type = extraire_attribut($e, 'type'); |
|
| 2304 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2305 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2306 | - } # vieux data |
|
| 2307 | - $fichier = basename($url); |
|
| 2308 | - $enclosures[] = '<enclosure' |
|
| 2309 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2310 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2311 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2312 | - . ' />'; |
|
| 2313 | - } |
|
| 2314 | - } |
|
| 2299 | + $enclosures = array(); |
|
| 2300 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2301 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2302 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2303 | + $type = extraire_attribut($e, 'type'); |
|
| 2304 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2305 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2306 | + } # vieux data |
|
| 2307 | + $fichier = basename($url); |
|
| 2308 | + $enclosures[] = '<enclosure' |
|
| 2309 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2310 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2311 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2312 | + . ' />'; |
|
| 2313 | + } |
|
| 2314 | + } |
|
| 2315 | 2315 | |
| 2316 | - return join("\n", $enclosures); |
|
| 2316 | + return join("\n", $enclosures); |
|
| 2317 | 2317 | } |
| 2318 | 2318 | |
| 2319 | 2319 | |
@@ -2329,16 +2329,16 @@ discard block |
||
| 2329 | 2329 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2330 | 2330 | **/ |
| 2331 | 2331 | function tags2dcsubject($tags) { |
| 2332 | - $subjects = ''; |
|
| 2333 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2334 | - if (extraire_attribut($e, rel) == 'tag') { |
|
| 2335 | - $subjects .= '<dc:subject>' |
|
| 2336 | - . texte_backend(textebrut($e)) |
|
| 2337 | - . '</dc:subject>' . "\n"; |
|
| 2338 | - } |
|
| 2339 | - } |
|
| 2332 | + $subjects = ''; |
|
| 2333 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2334 | + if (extraire_attribut($e, rel) == 'tag') { |
|
| 2335 | + $subjects .= '<dc:subject>' |
|
| 2336 | + . texte_backend(textebrut($e)) |
|
| 2337 | + . '</dc:subject>' . "\n"; |
|
| 2338 | + } |
|
| 2339 | + } |
|
| 2340 | 2340 | |
| 2341 | - return $subjects; |
|
| 2341 | + return $subjects; |
|
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | 2344 | /** |
@@ -2367,23 +2367,23 @@ discard block |
||
| 2367 | 2367 | * - Tableau de résultats, si tableau en entrée. |
| 2368 | 2368 | **/ |
| 2369 | 2369 | function extraire_balise($texte, $tag = 'a') { |
| 2370 | - if (is_array($texte)) { |
|
| 2371 | - array_walk( |
|
| 2372 | - $texte, |
|
| 2373 | - function(&$a, $key, $t){ |
|
| 2374 | - $a = extraire_balise($a, $t); |
|
| 2375 | - }, |
|
| 2376 | - $tag |
|
| 2377 | - ); |
|
| 2370 | + if (is_array($texte)) { |
|
| 2371 | + array_walk( |
|
| 2372 | + $texte, |
|
| 2373 | + function(&$a, $key, $t){ |
|
| 2374 | + $a = extraire_balise($a, $t); |
|
| 2375 | + }, |
|
| 2376 | + $tag |
|
| 2377 | + ); |
|
| 2378 | 2378 | |
| 2379 | - return $texte; |
|
| 2380 | - } |
|
| 2379 | + return $texte; |
|
| 2380 | + } |
|
| 2381 | 2381 | |
| 2382 | - if (preg_match( |
|
| 2383 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2384 | - $texte, $regs)) { |
|
| 2385 | - return $regs[0]; |
|
| 2386 | - } |
|
| 2382 | + if (preg_match( |
|
| 2383 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2384 | + $texte, $regs)) { |
|
| 2385 | + return $regs[0]; |
|
| 2386 | + } |
|
| 2387 | 2387 | } |
| 2388 | 2388 | |
| 2389 | 2389 | /** |
@@ -2411,25 +2411,25 @@ discard block |
||
| 2411 | 2411 | * - Tableau de résultats, si tableau en entrée. |
| 2412 | 2412 | **/ |
| 2413 | 2413 | function extraire_balises($texte, $tag = 'a') { |
| 2414 | - if (is_array($texte)) { |
|
| 2415 | - array_walk( |
|
| 2416 | - $texte, |
|
| 2417 | - function(&$a, $key, $t){ |
|
| 2418 | - $a = extraire_balises($a, $t); |
|
| 2419 | - }, |
|
| 2420 | - $tag |
|
| 2421 | - ); |
|
| 2414 | + if (is_array($texte)) { |
|
| 2415 | + array_walk( |
|
| 2416 | + $texte, |
|
| 2417 | + function(&$a, $key, $t){ |
|
| 2418 | + $a = extraire_balises($a, $t); |
|
| 2419 | + }, |
|
| 2420 | + $tag |
|
| 2421 | + ); |
|
| 2422 | 2422 | |
| 2423 | - return $texte; |
|
| 2424 | - } |
|
| 2423 | + return $texte; |
|
| 2424 | + } |
|
| 2425 | 2425 | |
| 2426 | - if (preg_match_all( |
|
| 2427 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2428 | - $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 2429 | - return $regs[0]; |
|
| 2430 | - } else { |
|
| 2431 | - return array(); |
|
| 2432 | - } |
|
| 2426 | + if (preg_match_all( |
|
| 2427 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2428 | + $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 2429 | + return $regs[0]; |
|
| 2430 | + } else { |
|
| 2431 | + return array(); |
|
| 2432 | + } |
|
| 2433 | 2433 | } |
| 2434 | 2434 | |
| 2435 | 2435 | /** |
@@ -2458,11 +2458,11 @@ discard block |
||
| 2458 | 2458 | * - `$def` si on n'a pas transmis de tableau |
| 2459 | 2459 | **/ |
| 2460 | 2460 | function in_any($val, $vals, $def = '') { |
| 2461 | - if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2462 | - $vals = $v; |
|
| 2463 | - } |
|
| 2461 | + if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2462 | + $vals = $v; |
|
| 2463 | + } |
|
| 2464 | 2464 | |
| 2465 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2465 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2466 | 2466 | } |
| 2467 | 2467 | |
| 2468 | 2468 | |
@@ -2483,12 +2483,12 @@ discard block |
||
| 2483 | 2483 | * Résultat du calcul |
| 2484 | 2484 | **/ |
| 2485 | 2485 | function valeur_numerique($expr) { |
| 2486 | - $a = 0; |
|
| 2487 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2488 | - eval("\$a = $expr;"); |
|
| 2489 | - } |
|
| 2486 | + $a = 0; |
|
| 2487 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2488 | + eval("\$a = $expr;"); |
|
| 2489 | + } |
|
| 2490 | 2490 | |
| 2491 | - return intval($a); |
|
| 2491 | + return intval($a); |
|
| 2492 | 2492 | } |
| 2493 | 2493 | |
| 2494 | 2494 | /** |
@@ -2507,7 +2507,7 @@ discard block |
||
| 2507 | 2507 | * Retourne `$a*$b/$c` |
| 2508 | 2508 | **/ |
| 2509 | 2509 | function regledetrois($a, $b, $c) { |
| 2510 | - return round($a * $b / $c); |
|
| 2510 | + return round($a * $b / $c); |
|
| 2511 | 2511 | } |
| 2512 | 2512 | |
| 2513 | 2513 | |
@@ -2531,76 +2531,76 @@ discard block |
||
| 2531 | 2531 | **/ |
| 2532 | 2532 | function form_hidden($action) { |
| 2533 | 2533 | |
| 2534 | - $contexte = array(); |
|
| 2535 | - include_spip('inc/urls'); |
|
| 2536 | - if ($p = urls_decoder_url($action, '') |
|
| 2537 | - and reset($p) |
|
| 2538 | - ) { |
|
| 2539 | - $fond = array_shift($p); |
|
| 2540 | - if ($fond != '404') { |
|
| 2541 | - $contexte = array_shift($p); |
|
| 2542 | - $contexte['page'] = $fond; |
|
| 2543 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2544 | - } |
|
| 2545 | - } |
|
| 2546 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2547 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2548 | - unset($contexte['type']); |
|
| 2549 | - } |
|
| 2550 | - if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2551 | - unset($contexte['type-page']); |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2555 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2556 | - $values = array(); |
|
| 2557 | - |
|
| 2558 | - // d'abord avec celles de l'url |
|
| 2559 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2560 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2561 | - $c = explode('=', $c, 2); |
|
| 2562 | - $var = array_shift($c); |
|
| 2563 | - $val = array_shift($c); |
|
| 2564 | - if ($var) { |
|
| 2565 | - $val = rawurldecode($val); |
|
| 2566 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2567 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2568 | - $values[] = array($var, $val); |
|
| 2569 | - } else { |
|
| 2570 | - if (!isset($values[$var])) { |
|
| 2571 | - $values[$var] = array($var, $val); |
|
| 2572 | - } |
|
| 2573 | - } |
|
| 2574 | - } |
|
| 2575 | - } |
|
| 2576 | - } |
|
| 2577 | - |
|
| 2578 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2579 | - foreach ($contexte as $var => $val) { |
|
| 2580 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2581 | - $values[] = array($var, $val); |
|
| 2582 | - } else { |
|
| 2583 | - if (!isset($values[$var])) { |
|
| 2584 | - $values[$var] = array($var, $val); |
|
| 2585 | - } |
|
| 2586 | - } |
|
| 2587 | - } |
|
| 2588 | - |
|
| 2589 | - // puis on rassemble le tout |
|
| 2590 | - $hidden = array(); |
|
| 2591 | - foreach ($values as $value) { |
|
| 2592 | - list($var, $val) = $value; |
|
| 2593 | - $hidden[] = '<input name="' |
|
| 2594 | - . entites_html($var) |
|
| 2595 | - . '"' |
|
| 2596 | - . (is_null($val) |
|
| 2597 | - ? '' |
|
| 2598 | - : ' value="' . entites_html($val) . '"' |
|
| 2599 | - ) |
|
| 2600 | - . ' type="hidden"' . "\n/>"; |
|
| 2601 | - } |
|
| 2602 | - |
|
| 2603 | - return join("", $hidden); |
|
| 2534 | + $contexte = array(); |
|
| 2535 | + include_spip('inc/urls'); |
|
| 2536 | + if ($p = urls_decoder_url($action, '') |
|
| 2537 | + and reset($p) |
|
| 2538 | + ) { |
|
| 2539 | + $fond = array_shift($p); |
|
| 2540 | + if ($fond != '404') { |
|
| 2541 | + $contexte = array_shift($p); |
|
| 2542 | + $contexte['page'] = $fond; |
|
| 2543 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2544 | + } |
|
| 2545 | + } |
|
| 2546 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2547 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2548 | + unset($contexte['type']); |
|
| 2549 | + } |
|
| 2550 | + if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2551 | + unset($contexte['type-page']); |
|
| 2552 | + } |
|
| 2553 | + |
|
| 2554 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2555 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2556 | + $values = array(); |
|
| 2557 | + |
|
| 2558 | + // d'abord avec celles de l'url |
|
| 2559 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2560 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2561 | + $c = explode('=', $c, 2); |
|
| 2562 | + $var = array_shift($c); |
|
| 2563 | + $val = array_shift($c); |
|
| 2564 | + if ($var) { |
|
| 2565 | + $val = rawurldecode($val); |
|
| 2566 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2567 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2568 | + $values[] = array($var, $val); |
|
| 2569 | + } else { |
|
| 2570 | + if (!isset($values[$var])) { |
|
| 2571 | + $values[$var] = array($var, $val); |
|
| 2572 | + } |
|
| 2573 | + } |
|
| 2574 | + } |
|
| 2575 | + } |
|
| 2576 | + } |
|
| 2577 | + |
|
| 2578 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2579 | + foreach ($contexte as $var => $val) { |
|
| 2580 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2581 | + $values[] = array($var, $val); |
|
| 2582 | + } else { |
|
| 2583 | + if (!isset($values[$var])) { |
|
| 2584 | + $values[$var] = array($var, $val); |
|
| 2585 | + } |
|
| 2586 | + } |
|
| 2587 | + } |
|
| 2588 | + |
|
| 2589 | + // puis on rassemble le tout |
|
| 2590 | + $hidden = array(); |
|
| 2591 | + foreach ($values as $value) { |
|
| 2592 | + list($var, $val) = $value; |
|
| 2593 | + $hidden[] = '<input name="' |
|
| 2594 | + . entites_html($var) |
|
| 2595 | + . '"' |
|
| 2596 | + . (is_null($val) |
|
| 2597 | + ? '' |
|
| 2598 | + : ' value="' . entites_html($val) . '"' |
|
| 2599 | + ) |
|
| 2600 | + . ' type="hidden"' . "\n/>"; |
|
| 2601 | + } |
|
| 2602 | + |
|
| 2603 | + return join("", $hidden); |
|
| 2604 | 2604 | } |
| 2605 | 2605 | |
| 2606 | 2606 | /** |
@@ -2618,15 +2618,15 @@ discard block |
||
| 2618 | 2618 | * Liste (première page, dernière page). |
| 2619 | 2619 | **/ |
| 2620 | 2620 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 2621 | - if ($max <= 0 or $max >= $nombre) { |
|
| 2622 | - return array(1, $nombre); |
|
| 2623 | - } |
|
| 2621 | + if ($max <= 0 or $max >= $nombre) { |
|
| 2622 | + return array(1, $nombre); |
|
| 2623 | + } |
|
| 2624 | 2624 | |
| 2625 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 2626 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 2627 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 2625 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 2626 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 2627 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 2628 | 2628 | |
| 2629 | - return array($premiere, $derniere); |
|
| 2629 | + return array($premiere, $derniere); |
|
| 2630 | 2630 | } |
| 2631 | 2631 | |
| 2632 | 2632 | |
@@ -2648,7 +2648,7 @@ discard block |
||
| 2648 | 2648 | * - la première valeur du tableau sinon. |
| 2649 | 2649 | **/ |
| 2650 | 2650 | function filtre_reset($array) { |
| 2651 | - return !is_array($array) ? null : reset($array); |
|
| 2651 | + return !is_array($array) ? null : reset($array); |
|
| 2652 | 2652 | } |
| 2653 | 2653 | |
| 2654 | 2654 | /** |
@@ -2669,7 +2669,7 @@ discard block |
||
| 2669 | 2669 | * - la dernière valeur du tableau sinon. |
| 2670 | 2670 | **/ |
| 2671 | 2671 | function filtre_end($array) { |
| 2672 | - return !is_array($array) ? null : end($array); |
|
| 2672 | + return !is_array($array) ? null : end($array); |
|
| 2673 | 2673 | } |
| 2674 | 2674 | |
| 2675 | 2675 | /** |
@@ -2689,11 +2689,11 @@ discard block |
||
| 2689 | 2689 | * |
| 2690 | 2690 | **/ |
| 2691 | 2691 | function filtre_push($array, $val) { |
| 2692 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2693 | - return ''; |
|
| 2694 | - } |
|
| 2692 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2693 | + return ''; |
|
| 2694 | + } |
|
| 2695 | 2695 | |
| 2696 | - return $array; |
|
| 2696 | + return $array; |
|
| 2697 | 2697 | } |
| 2698 | 2698 | |
| 2699 | 2699 | /** |
@@ -2712,7 +2712,7 @@ discard block |
||
| 2712 | 2712 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2713 | 2713 | **/ |
| 2714 | 2714 | function filtre_find($array, $val) { |
| 2715 | - return (is_array($array) and in_array($val, $array)); |
|
| 2715 | + return (is_array($array) and in_array($val, $array)); |
|
| 2716 | 2716 | } |
| 2717 | 2717 | |
| 2718 | 2718 | |
@@ -2729,15 +2729,15 @@ discard block |
||
| 2729 | 2729 | * Contenu avec urls en absolus |
| 2730 | 2730 | **/ |
| 2731 | 2731 | function urls_absolues_css($contenu, $source) { |
| 2732 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2732 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2733 | 2733 | |
| 2734 | - return preg_replace_callback( |
|
| 2735 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2736 | - function($x) use ($path) { |
|
| 2737 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2738 | - }, |
|
| 2739 | - $contenu |
|
| 2740 | - ); |
|
| 2734 | + return preg_replace_callback( |
|
| 2735 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2736 | + function($x) use ($path) { |
|
| 2737 | + return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2738 | + }, |
|
| 2739 | + $contenu |
|
| 2740 | + ); |
|
| 2741 | 2741 | } |
| 2742 | 2742 | |
| 2743 | 2743 | |
@@ -2766,118 +2766,118 @@ discard block |
||
| 2766 | 2766 | * Chemin du fichier CSS inversé |
| 2767 | 2767 | **/ |
| 2768 | 2768 | function direction_css($css, $voulue = '') { |
| 2769 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2770 | - return $css; |
|
| 2771 | - } |
|
| 2772 | - |
|
| 2773 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2774 | - if ($voulue = strtolower($voulue)) { |
|
| 2775 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2776 | - $voulue = lang_dir($voulue); |
|
| 2777 | - } |
|
| 2778 | - } else { |
|
| 2779 | - $voulue = lang_dir(); |
|
| 2780 | - } |
|
| 2781 | - |
|
| 2782 | - $r = count($r) > 1; |
|
| 2783 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2784 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2785 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2786 | - |
|
| 2787 | - if ($voulue == $dir) { |
|
| 2788 | - return $css; |
|
| 2789 | - } |
|
| 2790 | - |
|
| 2791 | - if ( |
|
| 2792 | - // url absolue |
|
| 2793 | - preg_match(",^https?:,i", $css) |
|
| 2794 | - // ou qui contient un ? |
|
| 2795 | - or (($p = strpos($css, '?')) !== false) |
|
| 2796 | - ) { |
|
| 2797 | - $distant = true; |
|
| 2798 | - $cssf = parse_url($css); |
|
| 2799 | - $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2800 | - $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2801 | - } else { |
|
| 2802 | - $distant = false; |
|
| 2803 | - $cssf = $css; |
|
| 2804 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2805 | - //propose (rien a faire dans ce cas) |
|
| 2806 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2807 | - if (@file_exists($f)) { |
|
| 2808 | - return $f; |
|
| 2809 | - } |
|
| 2810 | - } |
|
| 2811 | - |
|
| 2812 | - // 2. |
|
| 2813 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2814 | - $f = $dir_var |
|
| 2815 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2816 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2817 | - |
|
| 2818 | - // la css peut etre distante (url absolue !) |
|
| 2819 | - if ($distant) { |
|
| 2820 | - include_spip('inc/distant'); |
|
| 2821 | - $res = recuperer_url($css); |
|
| 2822 | - if (!$res or !$contenu = $res['page']) { |
|
| 2823 | - return $css; |
|
| 2824 | - } |
|
| 2825 | - } else { |
|
| 2826 | - if ((@filemtime($f) > @filemtime($css)) |
|
| 2827 | - and (_VAR_MODE != 'recalcul') |
|
| 2828 | - ) { |
|
| 2829 | - return $f; |
|
| 2830 | - } |
|
| 2831 | - if (!lire_fichier($css, $contenu)) { |
|
| 2832 | - return $css; |
|
| 2833 | - } |
|
| 2834 | - } |
|
| 2835 | - |
|
| 2836 | - |
|
| 2837 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2838 | - include_spip("lib/csstidy/class.csstidy"); |
|
| 2839 | - $parser = new csstidy(); |
|
| 2840 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2841 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2842 | - $parser->parse($contenu); |
|
| 2843 | - |
|
| 2844 | - $contenu = $parser->print->plain(); |
|
| 2845 | - |
|
| 2846 | - |
|
| 2847 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2848 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2849 | - $src = array(); |
|
| 2850 | - $src_direction_css = array(); |
|
| 2851 | - $src_faux_abs = array(); |
|
| 2852 | - $d = dirname($css); |
|
| 2853 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2854 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2855 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2856 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2857 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2858 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2859 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2860 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2861 | - $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2862 | - $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2863 | - } |
|
| 2864 | - $src[] = $regs[0][$k]; |
|
| 2865 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2866 | - } |
|
| 2867 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2868 | - |
|
| 2869 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2870 | - |
|
| 2871 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2872 | - if (count($src_faux_abs)) { |
|
| 2873 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2874 | - } |
|
| 2875 | - |
|
| 2876 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2877 | - return $css; |
|
| 2878 | - } |
|
| 2879 | - |
|
| 2880 | - return $f; |
|
| 2769 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2770 | + return $css; |
|
| 2771 | + } |
|
| 2772 | + |
|
| 2773 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2774 | + if ($voulue = strtolower($voulue)) { |
|
| 2775 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2776 | + $voulue = lang_dir($voulue); |
|
| 2777 | + } |
|
| 2778 | + } else { |
|
| 2779 | + $voulue = lang_dir(); |
|
| 2780 | + } |
|
| 2781 | + |
|
| 2782 | + $r = count($r) > 1; |
|
| 2783 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2784 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2785 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2786 | + |
|
| 2787 | + if ($voulue == $dir) { |
|
| 2788 | + return $css; |
|
| 2789 | + } |
|
| 2790 | + |
|
| 2791 | + if ( |
|
| 2792 | + // url absolue |
|
| 2793 | + preg_match(",^https?:,i", $css) |
|
| 2794 | + // ou qui contient un ? |
|
| 2795 | + or (($p = strpos($css, '?')) !== false) |
|
| 2796 | + ) { |
|
| 2797 | + $distant = true; |
|
| 2798 | + $cssf = parse_url($css); |
|
| 2799 | + $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2800 | + $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2801 | + } else { |
|
| 2802 | + $distant = false; |
|
| 2803 | + $cssf = $css; |
|
| 2804 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2805 | + //propose (rien a faire dans ce cas) |
|
| 2806 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2807 | + if (@file_exists($f)) { |
|
| 2808 | + return $f; |
|
| 2809 | + } |
|
| 2810 | + } |
|
| 2811 | + |
|
| 2812 | + // 2. |
|
| 2813 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2814 | + $f = $dir_var |
|
| 2815 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2816 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2817 | + |
|
| 2818 | + // la css peut etre distante (url absolue !) |
|
| 2819 | + if ($distant) { |
|
| 2820 | + include_spip('inc/distant'); |
|
| 2821 | + $res = recuperer_url($css); |
|
| 2822 | + if (!$res or !$contenu = $res['page']) { |
|
| 2823 | + return $css; |
|
| 2824 | + } |
|
| 2825 | + } else { |
|
| 2826 | + if ((@filemtime($f) > @filemtime($css)) |
|
| 2827 | + and (_VAR_MODE != 'recalcul') |
|
| 2828 | + ) { |
|
| 2829 | + return $f; |
|
| 2830 | + } |
|
| 2831 | + if (!lire_fichier($css, $contenu)) { |
|
| 2832 | + return $css; |
|
| 2833 | + } |
|
| 2834 | + } |
|
| 2835 | + |
|
| 2836 | + |
|
| 2837 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2838 | + include_spip("lib/csstidy/class.csstidy"); |
|
| 2839 | + $parser = new csstidy(); |
|
| 2840 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2841 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2842 | + $parser->parse($contenu); |
|
| 2843 | + |
|
| 2844 | + $contenu = $parser->print->plain(); |
|
| 2845 | + |
|
| 2846 | + |
|
| 2847 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2848 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2849 | + $src = array(); |
|
| 2850 | + $src_direction_css = array(); |
|
| 2851 | + $src_faux_abs = array(); |
|
| 2852 | + $d = dirname($css); |
|
| 2853 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2854 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2855 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2856 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2857 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2858 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2859 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2860 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2861 | + $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2862 | + $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2863 | + } |
|
| 2864 | + $src[] = $regs[0][$k]; |
|
| 2865 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2866 | + } |
|
| 2867 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2868 | + |
|
| 2869 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2870 | + |
|
| 2871 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2872 | + if (count($src_faux_abs)) { |
|
| 2873 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2874 | + } |
|
| 2875 | + |
|
| 2876 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2877 | + return $css; |
|
| 2878 | + } |
|
| 2879 | + |
|
| 2880 | + return $f; |
|
| 2881 | 2881 | } |
| 2882 | 2882 | |
| 2883 | 2883 | |
@@ -2900,43 +2900,43 @@ discard block |
||
| 2900 | 2900 | * - Chemin ou URL du fichier CSS source sinon. |
| 2901 | 2901 | **/ |
| 2902 | 2902 | function url_absolue_css($css) { |
| 2903 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2904 | - return $css; |
|
| 2905 | - } |
|
| 2903 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2904 | + return $css; |
|
| 2905 | + } |
|
| 2906 | 2906 | |
| 2907 | - $url_absolue_css = url_absolue($css); |
|
| 2907 | + $url_absolue_css = url_absolue($css); |
|
| 2908 | 2908 | |
| 2909 | - $f = basename($css, '.css'); |
|
| 2910 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2911 | - . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2912 | - . '.css'; |
|
| 2909 | + $f = basename($css, '.css'); |
|
| 2910 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2911 | + . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2912 | + . '.css'; |
|
| 2913 | 2913 | |
| 2914 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 2915 | - return $f; |
|
| 2916 | - } |
|
| 2914 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 2915 | + return $f; |
|
| 2916 | + } |
|
| 2917 | 2917 | |
| 2918 | - if ($url_absolue_css == $css) { |
|
| 2919 | - if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2920 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2921 | - ) { |
|
| 2922 | - include_spip('inc/distant'); |
|
| 2923 | - if (!$contenu = recuperer_page($css)) { |
|
| 2924 | - return $css; |
|
| 2925 | - } |
|
| 2926 | - } |
|
| 2927 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 2928 | - return $css; |
|
| 2929 | - } |
|
| 2918 | + if ($url_absolue_css == $css) { |
|
| 2919 | + if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2920 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2921 | + ) { |
|
| 2922 | + include_spip('inc/distant'); |
|
| 2923 | + if (!$contenu = recuperer_page($css)) { |
|
| 2924 | + return $css; |
|
| 2925 | + } |
|
| 2926 | + } |
|
| 2927 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 2928 | + return $css; |
|
| 2929 | + } |
|
| 2930 | 2930 | |
| 2931 | - // passer les url relatives a la css d'origine en url absolues |
|
| 2932 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2931 | + // passer les url relatives a la css d'origine en url absolues |
|
| 2932 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2933 | 2933 | |
| 2934 | - // ecrire la css |
|
| 2935 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2936 | - return $css; |
|
| 2937 | - } |
|
| 2934 | + // ecrire la css |
|
| 2935 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2936 | + return $css; |
|
| 2937 | + } |
|
| 2938 | 2938 | |
| 2939 | - return $f; |
|
| 2939 | + return $f; |
|
| 2940 | 2940 | } |
| 2941 | 2941 | |
| 2942 | 2942 | |
@@ -2970,24 +2970,24 @@ discard block |
||
| 2970 | 2970 | * Valeur trouvée ou valeur par défaut. |
| 2971 | 2971 | **/ |
| 2972 | 2972 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 2973 | - foreach (explode('/', $cle) as $k) { |
|
| 2973 | + foreach (explode('/', $cle) as $k) { |
|
| 2974 | 2974 | |
| 2975 | - $table = is_string($table) ? @unserialize($table) : $table; |
|
| 2975 | + $table = is_string($table) ? @unserialize($table) : $table; |
|
| 2976 | 2976 | |
| 2977 | - if (is_object($table)) { |
|
| 2978 | - $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 2979 | - } elseif (is_array($table)) { |
|
| 2980 | - if ($conserver_null) { |
|
| 2981 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 2982 | - } else { |
|
| 2983 | - $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 2984 | - } |
|
| 2985 | - } else { |
|
| 2986 | - $table = $defaut; |
|
| 2987 | - } |
|
| 2988 | - } |
|
| 2977 | + if (is_object($table)) { |
|
| 2978 | + $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 2979 | + } elseif (is_array($table)) { |
|
| 2980 | + if ($conserver_null) { |
|
| 2981 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 2982 | + } else { |
|
| 2983 | + $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 2984 | + } |
|
| 2985 | + } else { |
|
| 2986 | + $table = $defaut; |
|
| 2987 | + } |
|
| 2988 | + } |
|
| 2989 | 2989 | |
| 2990 | - return $table; |
|
| 2990 | + return $table; |
|
| 2991 | 2991 | } |
| 2992 | 2992 | |
| 2993 | 2993 | /** |
@@ -3020,22 +3020,22 @@ discard block |
||
| 3020 | 3020 | * - string : expression trouvée. |
| 3021 | 3021 | **/ |
| 3022 | 3022 | function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) { |
| 3023 | - if (intval($modif) and $capte == 0) { |
|
| 3024 | - $capte = $modif; |
|
| 3025 | - $modif = "UimsS"; |
|
| 3026 | - } |
|
| 3027 | - $expression = str_replace("\/", "/", $expression); |
|
| 3028 | - $expression = str_replace("/", "\/", $expression); |
|
| 3023 | + if (intval($modif) and $capte == 0) { |
|
| 3024 | + $capte = $modif; |
|
| 3025 | + $modif = "UimsS"; |
|
| 3026 | + } |
|
| 3027 | + $expression = str_replace("\/", "/", $expression); |
|
| 3028 | + $expression = str_replace("/", "\/", $expression); |
|
| 3029 | 3029 | |
| 3030 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3031 | - if (isset($r[$capte])) { |
|
| 3032 | - return $r[$capte]; |
|
| 3033 | - } else { |
|
| 3034 | - return true; |
|
| 3035 | - } |
|
| 3036 | - } |
|
| 3030 | + if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3031 | + if (isset($r[$capte])) { |
|
| 3032 | + return $r[$capte]; |
|
| 3033 | + } else { |
|
| 3034 | + return true; |
|
| 3035 | + } |
|
| 3036 | + } |
|
| 3037 | 3037 | |
| 3038 | - return false; |
|
| 3038 | + return false; |
|
| 3039 | 3039 | } |
| 3040 | 3040 | |
| 3041 | 3041 | |
@@ -3062,10 +3062,10 @@ discard block |
||
| 3062 | 3062 | * Texte |
| 3063 | 3063 | **/ |
| 3064 | 3064 | function replace($texte, $expression, $replace = '', $modif = "UimsS") { |
| 3065 | - $expression = str_replace("\/", "/", $expression); |
|
| 3066 | - $expression = str_replace("/", "\/", $expression); |
|
| 3065 | + $expression = str_replace("\/", "/", $expression); |
|
| 3066 | + $expression = str_replace("/", "\/", $expression); |
|
| 3067 | 3067 | |
| 3068 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3068 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3069 | 3069 | } |
| 3070 | 3070 | |
| 3071 | 3071 | |
@@ -3083,21 +3083,21 @@ discard block |
||
| 3083 | 3083 | **/ |
| 3084 | 3084 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3085 | 3085 | |
| 3086 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3087 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3086 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3087 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3088 | 3088 | |
| 3089 | - if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3090 | - and preg_match_all( |
|
| 3091 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3092 | - $t, $matches, PREG_PATTERN_ORDER) |
|
| 3093 | - ) { |
|
| 3094 | - if (!isset($doublons['documents'])) { |
|
| 3095 | - $doublons['documents'] = ""; |
|
| 3096 | - } |
|
| 3097 | - $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3098 | - } |
|
| 3089 | + if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3090 | + and preg_match_all( |
|
| 3091 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3092 | + $t, $matches, PREG_PATTERN_ORDER) |
|
| 3093 | + ) { |
|
| 3094 | + if (!isset($doublons['documents'])) { |
|
| 3095 | + $doublons['documents'] = ""; |
|
| 3096 | + } |
|
| 3097 | + $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3098 | + } |
|
| 3099 | 3099 | |
| 3100 | - return $letexte; |
|
| 3100 | + return $letexte; |
|
| 3101 | 3101 | } |
| 3102 | 3102 | |
| 3103 | 3103 | /** |
@@ -3111,7 +3111,7 @@ discard block |
||
| 3111 | 3111 | * @return string Chaîne vide |
| 3112 | 3112 | **/ |
| 3113 | 3113 | function vide($texte) { |
| 3114 | - return ""; |
|
| 3114 | + return ""; |
|
| 3115 | 3115 | } |
| 3116 | 3116 | |
| 3117 | 3117 | // |
@@ -3140,23 +3140,23 @@ discard block |
||
| 3140 | 3140 | * Code HTML résultant |
| 3141 | 3141 | **/ |
| 3142 | 3142 | function env_to_params($env, $ignore_params = array()) { |
| 3143 | - $ignore_params = array_merge( |
|
| 3144 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3145 | - $ignore_params |
|
| 3146 | - ); |
|
| 3147 | - if (!is_array($env)) { |
|
| 3148 | - $env = unserialize($env); |
|
| 3149 | - } |
|
| 3150 | - $texte = ""; |
|
| 3151 | - if ($env) { |
|
| 3152 | - foreach ($env as $i => $j) { |
|
| 3153 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3154 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3155 | - } |
|
| 3156 | - } |
|
| 3157 | - } |
|
| 3158 | - |
|
| 3159 | - return $texte; |
|
| 3143 | + $ignore_params = array_merge( |
|
| 3144 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3145 | + $ignore_params |
|
| 3146 | + ); |
|
| 3147 | + if (!is_array($env)) { |
|
| 3148 | + $env = unserialize($env); |
|
| 3149 | + } |
|
| 3150 | + $texte = ""; |
|
| 3151 | + if ($env) { |
|
| 3152 | + foreach ($env as $i => $j) { |
|
| 3153 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3154 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3155 | + } |
|
| 3156 | + } |
|
| 3157 | + } |
|
| 3158 | + |
|
| 3159 | + return $texte; |
|
| 3160 | 3160 | } |
| 3161 | 3161 | |
| 3162 | 3162 | /** |
@@ -3179,23 +3179,23 @@ discard block |
||
| 3179 | 3179 | * Code HTML résultant |
| 3180 | 3180 | **/ |
| 3181 | 3181 | function env_to_attributs($env, $ignore_params = array()) { |
| 3182 | - $ignore_params = array_merge( |
|
| 3183 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3184 | - $ignore_params |
|
| 3185 | - ); |
|
| 3186 | - if (!is_array($env)) { |
|
| 3187 | - $env = unserialize($env); |
|
| 3188 | - } |
|
| 3189 | - $texte = ""; |
|
| 3190 | - if ($env) { |
|
| 3191 | - foreach ($env as $i => $j) { |
|
| 3192 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3193 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3194 | - } |
|
| 3195 | - } |
|
| 3196 | - } |
|
| 3182 | + $ignore_params = array_merge( |
|
| 3183 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3184 | + $ignore_params |
|
| 3185 | + ); |
|
| 3186 | + if (!is_array($env)) { |
|
| 3187 | + $env = unserialize($env); |
|
| 3188 | + } |
|
| 3189 | + $texte = ""; |
|
| 3190 | + if ($env) { |
|
| 3191 | + foreach ($env as $i => $j) { |
|
| 3192 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3193 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3194 | + } |
|
| 3195 | + } |
|
| 3196 | + } |
|
| 3197 | 3197 | |
| 3198 | - return $texte; |
|
| 3198 | + return $texte; |
|
| 3199 | 3199 | } |
| 3200 | 3200 | |
| 3201 | 3201 | |
@@ -3212,9 +3212,9 @@ discard block |
||
| 3212 | 3212 | * @return string Chaînes concaténés |
| 3213 | 3213 | **/ |
| 3214 | 3214 | function concat() { |
| 3215 | - $args = func_get_args(); |
|
| 3215 | + $args = func_get_args(); |
|
| 3216 | 3216 | |
| 3217 | - return join('', $args); |
|
| 3217 | + return join('', $args); |
|
| 3218 | 3218 | } |
| 3219 | 3219 | |
| 3220 | 3220 | |
@@ -3234,23 +3234,23 @@ discard block |
||
| 3234 | 3234 | * Contenu du ou des fichiers, concaténé |
| 3235 | 3235 | **/ |
| 3236 | 3236 | function charge_scripts($files, $script = true) { |
| 3237 | - $flux = ""; |
|
| 3238 | - foreach (is_array($files) ? $files : explode("|", $files) as $file) { |
|
| 3239 | - if (!is_string($file)) { |
|
| 3240 | - continue; |
|
| 3241 | - } |
|
| 3242 | - if ($script) { |
|
| 3243 | - $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : ''; |
|
| 3244 | - } |
|
| 3245 | - if ($file) { |
|
| 3246 | - $path = find_in_path($file); |
|
| 3247 | - if ($path) { |
|
| 3248 | - $flux .= spip_file_get_contents($path); |
|
| 3249 | - } |
|
| 3250 | - } |
|
| 3251 | - } |
|
| 3237 | + $flux = ""; |
|
| 3238 | + foreach (is_array($files) ? $files : explode("|", $files) as $file) { |
|
| 3239 | + if (!is_string($file)) { |
|
| 3240 | + continue; |
|
| 3241 | + } |
|
| 3242 | + if ($script) { |
|
| 3243 | + $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : ''; |
|
| 3244 | + } |
|
| 3245 | + if ($file) { |
|
| 3246 | + $path = find_in_path($file); |
|
| 3247 | + if ($path) { |
|
| 3248 | + $flux .= spip_file_get_contents($path); |
|
| 3249 | + } |
|
| 3250 | + } |
|
| 3251 | + } |
|
| 3252 | 3252 | |
| 3253 | - return $flux; |
|
| 3253 | + return $flux; |
|
| 3254 | 3254 | } |
| 3255 | 3255 | |
| 3256 | 3256 | |
@@ -3272,64 +3272,64 @@ discard block |
||
| 3272 | 3272 | */ |
| 3273 | 3273 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) { |
| 3274 | 3274 | |
| 3275 | - $img_file = $img; |
|
| 3276 | - if ($p = strpos($img_file, '?')) { |
|
| 3277 | - $img_file = substr($img_file,0, $p); |
|
| 3278 | - } |
|
| 3279 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3280 | - $img_file = chemin_image($img); |
|
| 3281 | - } |
|
| 3282 | - else { |
|
| 3283 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){ |
|
| 3284 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3285 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3286 | - if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3287 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg" |
|
| 3288 | - and file_exists($variante_svg_generique)) { |
|
| 3289 | - if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) { |
|
| 3290 | - $img_file = $variante_svg_size; |
|
| 3291 | - } |
|
| 3292 | - else { |
|
| 3293 | - $img_file = $variante_svg_generique; |
|
| 3294 | - } |
|
| 3295 | - } |
|
| 3296 | - } |
|
| 3297 | - } |
|
| 3298 | - if (stripos($atts, 'width') === false) { |
|
| 3299 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3300 | - if ((!isset($options['utiliser_suffixe_size']) |
|
| 3301 | - or $options['utiliser_suffixe_size'] == true |
|
| 3302 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3303 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3304 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3305 | - ) { |
|
| 3306 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3307 | - } else { |
|
| 3308 | - $taille = taille_image($img_file); |
|
| 3309 | - list($hauteur, $largeur) = $taille; |
|
| 3310 | - if (!$hauteur or !$largeur) { |
|
| 3311 | - return ""; |
|
| 3312 | - } |
|
| 3313 | - } |
|
| 3314 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3315 | - } |
|
| 3316 | - |
|
| 3317 | - if (file_exists($img_file)) { |
|
| 3318 | - $img_file = timestamp($img_file); |
|
| 3319 | - } |
|
| 3320 | - if ($alt === false) { |
|
| 3321 | - $alt = ''; |
|
| 3322 | - } |
|
| 3323 | - elseif($alt or $alt==='') { |
|
| 3324 | - $alt = " alt='".attribut_html($alt)."'"; |
|
| 3325 | - } |
|
| 3326 | - else { |
|
| 3327 | - $alt = " alt='".attribut_html($title)."'"; |
|
| 3328 | - } |
|
| 3329 | - return "<img src='$img_file'$alt" |
|
| 3330 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3331 | - . " " . ltrim($atts) |
|
| 3332 | - . " />"; |
|
| 3275 | + $img_file = $img; |
|
| 3276 | + if ($p = strpos($img_file, '?')) { |
|
| 3277 | + $img_file = substr($img_file,0, $p); |
|
| 3278 | + } |
|
| 3279 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3280 | + $img_file = chemin_image($img); |
|
| 3281 | + } |
|
| 3282 | + else { |
|
| 3283 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){ |
|
| 3284 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3285 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3286 | + if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3287 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg" |
|
| 3288 | + and file_exists($variante_svg_generique)) { |
|
| 3289 | + if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) { |
|
| 3290 | + $img_file = $variante_svg_size; |
|
| 3291 | + } |
|
| 3292 | + else { |
|
| 3293 | + $img_file = $variante_svg_generique; |
|
| 3294 | + } |
|
| 3295 | + } |
|
| 3296 | + } |
|
| 3297 | + } |
|
| 3298 | + if (stripos($atts, 'width') === false) { |
|
| 3299 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3300 | + if ((!isset($options['utiliser_suffixe_size']) |
|
| 3301 | + or $options['utiliser_suffixe_size'] == true |
|
| 3302 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3303 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3304 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3305 | + ) { |
|
| 3306 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3307 | + } else { |
|
| 3308 | + $taille = taille_image($img_file); |
|
| 3309 | + list($hauteur, $largeur) = $taille; |
|
| 3310 | + if (!$hauteur or !$largeur) { |
|
| 3311 | + return ""; |
|
| 3312 | + } |
|
| 3313 | + } |
|
| 3314 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3315 | + } |
|
| 3316 | + |
|
| 3317 | + if (file_exists($img_file)) { |
|
| 3318 | + $img_file = timestamp($img_file); |
|
| 3319 | + } |
|
| 3320 | + if ($alt === false) { |
|
| 3321 | + $alt = ''; |
|
| 3322 | + } |
|
| 3323 | + elseif($alt or $alt==='') { |
|
| 3324 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3325 | + } |
|
| 3326 | + else { |
|
| 3327 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3328 | + } |
|
| 3329 | + return "<img src='$img_file'$alt" |
|
| 3330 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3331 | + . " " . ltrim($atts) |
|
| 3332 | + . " />"; |
|
| 3333 | 3333 | } |
| 3334 | 3334 | |
| 3335 | 3335 | /** |
@@ -3341,13 +3341,13 @@ discard block |
||
| 3341 | 3341 | * @return string |
| 3342 | 3342 | */ |
| 3343 | 3343 | function http_style_background($img, $att = '', $size=null) { |
| 3344 | - if ($size and is_numeric($size)){ |
|
| 3345 | - $size = trim($size) . "px"; |
|
| 3346 | - } |
|
| 3347 | - return " style='background" . |
|
| 3348 | - ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";" |
|
| 3349 | - . ($size ? "background-size:{$size};" : '') |
|
| 3350 | - . "'"; |
|
| 3344 | + if ($size and is_numeric($size)){ |
|
| 3345 | + $size = trim($size) . "px"; |
|
| 3346 | + } |
|
| 3347 | + return " style='background" . |
|
| 3348 | + ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";" |
|
| 3349 | + . ($size ? "background-size:{$size};" : '') |
|
| 3350 | + . "'"; |
|
| 3351 | 3351 | } |
| 3352 | 3352 | |
| 3353 | 3353 | /** |
@@ -3363,17 +3363,17 @@ discard block |
||
| 3363 | 3363 | * Code HTML de la balise IMG |
| 3364 | 3364 | */ |
| 3365 | 3365 | function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) { |
| 3366 | - $atts = $class ? " class='" . attribut_html($class) . "'" : ''; |
|
| 3367 | - // ecriture courte : on donne le width en 2e arg |
|
| 3368 | - if (empty($width) and is_numeric($alt)) { |
|
| 3369 | - $width = $alt; |
|
| 3370 | - $alt = ''; |
|
| 3371 | - } |
|
| 3372 | - if ($width) { |
|
| 3373 | - $atts .= " width='{$width}'"; |
|
| 3374 | - } |
|
| 3375 | - return http_img_pack($img, $alt, $atts, '', |
|
| 3376 | - array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
|
| 3366 | + $atts = $class ? " class='" . attribut_html($class) . "'" : ''; |
|
| 3367 | + // ecriture courte : on donne le width en 2e arg |
|
| 3368 | + if (empty($width) and is_numeric($alt)) { |
|
| 3369 | + $width = $alt; |
|
| 3370 | + $alt = ''; |
|
| 3371 | + } |
|
| 3372 | + if ($width) { |
|
| 3373 | + $atts .= " width='{$width}'"; |
|
| 3374 | + } |
|
| 3375 | + return http_img_pack($img, $alt, $atts, '', |
|
| 3376 | + array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
|
| 3377 | 3377 | } |
| 3378 | 3378 | |
| 3379 | 3379 | |
@@ -3389,42 +3389,42 @@ discard block |
||
| 3389 | 3389 | * @return string |
| 3390 | 3390 | */ |
| 3391 | 3391 | function filtre_balise_svg_dist($img, $alt = "", $class = "") { |
| 3392 | - $img_file = $img; |
|
| 3393 | - if ($p = strpos($img_file, '?')) { |
|
| 3394 | - $img_file = substr($img_file,0, $p); |
|
| 3395 | - } |
|
| 3392 | + $img_file = $img; |
|
| 3393 | + if ($p = strpos($img_file, '?')) { |
|
| 3394 | + $img_file = substr($img_file,0, $p); |
|
| 3395 | + } |
|
| 3396 | 3396 | |
| 3397 | - if (!$img_file or !$svg = file_get_contents($img_file)) { |
|
| 3398 | - return ''; |
|
| 3399 | - } |
|
| 3397 | + if (!$img_file or !$svg = file_get_contents($img_file)) { |
|
| 3398 | + return ''; |
|
| 3399 | + } |
|
| 3400 | 3400 | |
| 3401 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3402 | - return ''; |
|
| 3403 | - } |
|
| 3404 | - $balise_svg = $match[0]; |
|
| 3405 | - $balise_svg_source = $balise_svg; |
|
| 3401 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3402 | + return ''; |
|
| 3403 | + } |
|
| 3404 | + $balise_svg = $match[0]; |
|
| 3405 | + $balise_svg_source = $balise_svg; |
|
| 3406 | 3406 | |
| 3407 | - // entete XML à supprimer |
|
| 3408 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3407 | + // entete XML à supprimer |
|
| 3408 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3409 | 3409 | |
| 3410 | - // IE est toujours mon ami |
|
| 3411 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3412 | - if ($class) { |
|
| 3413 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3414 | - } |
|
| 3415 | - if ($alt){ |
|
| 3416 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3417 | - $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4); |
|
| 3418 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3419 | - $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n"; |
|
| 3420 | - $balise_svg .= $title; |
|
| 3421 | - } |
|
| 3422 | - else { |
|
| 3423 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3424 | - } |
|
| 3425 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3410 | + // IE est toujours mon ami |
|
| 3411 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3412 | + if ($class) { |
|
| 3413 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3414 | + } |
|
| 3415 | + if ($alt){ |
|
| 3416 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3417 | + $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4); |
|
| 3418 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3419 | + $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n"; |
|
| 3420 | + $balise_svg .= $title; |
|
| 3421 | + } |
|
| 3422 | + else { |
|
| 3423 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3424 | + } |
|
| 3425 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3426 | 3426 | |
| 3427 | - return $svg; |
|
| 3427 | + return $svg; |
|
| 3428 | 3428 | } |
| 3429 | 3429 | |
| 3430 | 3430 | |
@@ -3447,17 +3447,17 @@ discard block |
||
| 3447 | 3447 | * Code HTML résultant |
| 3448 | 3448 | **/ |
| 3449 | 3449 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3450 | - $texte = ''; |
|
| 3451 | - if (is_array($tableau)) { |
|
| 3452 | - foreach ($tableau as $k => $v) { |
|
| 3453 | - $res = recuperer_fond('modeles/' . $modele, |
|
| 3454 | - array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 3455 | - ); |
|
| 3456 | - $texte .= $res; |
|
| 3457 | - } |
|
| 3458 | - } |
|
| 3450 | + $texte = ''; |
|
| 3451 | + if (is_array($tableau)) { |
|
| 3452 | + foreach ($tableau as $k => $v) { |
|
| 3453 | + $res = recuperer_fond('modeles/' . $modele, |
|
| 3454 | + array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 3455 | + ); |
|
| 3456 | + $texte .= $res; |
|
| 3457 | + } |
|
| 3458 | + } |
|
| 3459 | 3459 | |
| 3460 | - return $texte; |
|
| 3460 | + return $texte; |
|
| 3461 | 3461 | } |
| 3462 | 3462 | |
| 3463 | 3463 | |
@@ -3482,37 +3482,37 @@ discard block |
||
| 3482 | 3482 | * - tout : retourne toutes les informations du plugin actif |
| 3483 | 3483 | **/ |
| 3484 | 3484 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3485 | - include_spip('inc/plugin'); |
|
| 3486 | - $plugin = strtoupper($plugin); |
|
| 3487 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3488 | - |
|
| 3489 | - if (!$plugin) { |
|
| 3490 | - return serialize(array_keys($plugins_actifs)); |
|
| 3491 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3492 | - return ''; |
|
| 3493 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3494 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3495 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3496 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3497 | - } else { |
|
| 3498 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3499 | - // On prend en compte les extensions |
|
| 3500 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3501 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3502 | - } else { |
|
| 3503 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3504 | - } |
|
| 3505 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3506 | - return ''; |
|
| 3507 | - } |
|
| 3508 | - if ($type_info == 'tout') { |
|
| 3509 | - return $infos; |
|
| 3510 | - } elseif ($type_info == 'est_actif') { |
|
| 3511 | - return $infos ? 1 : 0; |
|
| 3512 | - } else { |
|
| 3513 | - return strval($infos[$type_info]); |
|
| 3514 | - } |
|
| 3515 | - } |
|
| 3485 | + include_spip('inc/plugin'); |
|
| 3486 | + $plugin = strtoupper($plugin); |
|
| 3487 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3488 | + |
|
| 3489 | + if (!$plugin) { |
|
| 3490 | + return serialize(array_keys($plugins_actifs)); |
|
| 3491 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3492 | + return ''; |
|
| 3493 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3494 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3495 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3496 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3497 | + } else { |
|
| 3498 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3499 | + // On prend en compte les extensions |
|
| 3500 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3501 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3502 | + } else { |
|
| 3503 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3504 | + } |
|
| 3505 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3506 | + return ''; |
|
| 3507 | + } |
|
| 3508 | + if ($type_info == 'tout') { |
|
| 3509 | + return $infos; |
|
| 3510 | + } elseif ($type_info == 'est_actif') { |
|
| 3511 | + return $infos ? 1 : 0; |
|
| 3512 | + } else { |
|
| 3513 | + return strval($infos[$type_info]); |
|
| 3514 | + } |
|
| 3515 | + } |
|
| 3516 | 3516 | } |
| 3517 | 3517 | |
| 3518 | 3518 | |
@@ -3539,9 +3539,9 @@ discard block |
||
| 3539 | 3539 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3540 | 3540 | */ |
| 3541 | 3541 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3542 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3542 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3543 | 3543 | |
| 3544 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3544 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3545 | 3545 | } |
| 3546 | 3546 | |
| 3547 | 3547 | |
@@ -3571,13 +3571,13 @@ discard block |
||
| 3571 | 3571 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3572 | 3572 | */ |
| 3573 | 3573 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3574 | - static $puce_statut = null; |
|
| 3575 | - if (!$puce_statut) { |
|
| 3576 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3577 | - } |
|
| 3574 | + static $puce_statut = null; |
|
| 3575 | + if (!$puce_statut) { |
|
| 3576 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3577 | + } |
|
| 3578 | 3578 | |
| 3579 | - return $puce_statut($id_objet, $statut, $id_parent, $objet, false, |
|
| 3580 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false); |
|
| 3579 | + return $puce_statut($id_objet, $statut, $id_parent, $objet, false, |
|
| 3580 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false); |
|
| 3581 | 3581 | } |
| 3582 | 3582 | |
| 3583 | 3583 | |
@@ -3604,100 +3604,100 @@ discard block |
||
| 3604 | 3604 | * hash du contexte |
| 3605 | 3605 | */ |
| 3606 | 3606 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3607 | - if (is_string($c) |
|
| 3608 | - and @unserialize($c) !== false |
|
| 3609 | - ) { |
|
| 3610 | - $c = unserialize($c); |
|
| 3611 | - } |
|
| 3612 | - |
|
| 3613 | - // supprimer les parametres debut_x |
|
| 3614 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3615 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3616 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3617 | - if (is_array($c)) { |
|
| 3618 | - foreach ($c as $k => $v) { |
|
| 3619 | - if (strpos($k, 'debut_') === 0) { |
|
| 3620 | - unset($c[$k]); |
|
| 3621 | - } |
|
| 3622 | - } |
|
| 3623 | - } |
|
| 3624 | - |
|
| 3625 | - if (!function_exists('calculer_cle_action')) { |
|
| 3626 | - include_spip("inc/securiser_action"); |
|
| 3627 | - } |
|
| 3628 | - |
|
| 3629 | - $c = serialize($c); |
|
| 3630 | - $cle = calculer_cle_action($form . $c); |
|
| 3631 | - $c = "$cle:$c"; |
|
| 3632 | - |
|
| 3633 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3634 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3635 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3636 | - // que ce qui est toléré. |
|
| 3637 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3638 | - if (!$cache_contextes_ajax) { |
|
| 3639 | - $env = $c; |
|
| 3640 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3641 | - $env = gzdeflate($env); |
|
| 3642 | - // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 3643 | - if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) { |
|
| 3644 | - $cache_contextes_ajax = true; |
|
| 3645 | - spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 3646 | - } |
|
| 3647 | - } |
|
| 3648 | - $env = _xor($env); |
|
| 3649 | - $env = base64_encode($env); |
|
| 3650 | - $len = strlen($env); |
|
| 3651 | - // Si l’url est trop longue pour le navigateur |
|
| 3652 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3653 | - if ($len > $max_len) { |
|
| 3654 | - $cache_contextes_ajax = true; |
|
| 3655 | - spip_log("Contextes AJAX forces en fichiers !" |
|
| 3656 | - . " Cela arrive lorsque la valeur du contexte" |
|
| 3657 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len." |
|
| 3658 | - , _LOG_AVERTISSEMENT); |
|
| 3659 | - } |
|
| 3660 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3661 | - elseif ( |
|
| 3662 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3663 | - and $max_len < $len |
|
| 3664 | - ) { |
|
| 3665 | - $cache_contextes_ajax = true; |
|
| 3666 | - spip_log("Contextes AJAX forces en fichiers !" |
|
| 3667 | - . " Cela arrive lorsque la valeur du contexte" |
|
| 3668 | - . " depasse la longueur maximale autorisee par Suhosin" |
|
| 3669 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3670 | - . " Vous devriez modifier les parametres de Suhosin" |
|
| 3671 | - . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 3672 | - } |
|
| 3673 | - |
|
| 3674 | - } |
|
| 3675 | - |
|
| 3676 | - if ($cache_contextes_ajax) { |
|
| 3677 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3678 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3679 | - $md5 = md5($c); |
|
| 3680 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3681 | - $env = $md5; |
|
| 3682 | - } |
|
| 3683 | - |
|
| 3684 | - if ($emboite === null) { |
|
| 3685 | - return $env; |
|
| 3686 | - } |
|
| 3687 | - if (!trim($emboite)) { |
|
| 3688 | - return ""; |
|
| 3689 | - } |
|
| 3690 | - // toujours encoder l'url source dans le bloc ajax |
|
| 3691 | - $r = self(); |
|
| 3692 | - $r = ' data-origin="' . $r . '"'; |
|
| 3693 | - $class = 'ajaxbloc'; |
|
| 3694 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 3695 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 3696 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3697 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3698 | - } |
|
| 3699 | - |
|
| 3700 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3607 | + if (is_string($c) |
|
| 3608 | + and @unserialize($c) !== false |
|
| 3609 | + ) { |
|
| 3610 | + $c = unserialize($c); |
|
| 3611 | + } |
|
| 3612 | + |
|
| 3613 | + // supprimer les parametres debut_x |
|
| 3614 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3615 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3616 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3617 | + if (is_array($c)) { |
|
| 3618 | + foreach ($c as $k => $v) { |
|
| 3619 | + if (strpos($k, 'debut_') === 0) { |
|
| 3620 | + unset($c[$k]); |
|
| 3621 | + } |
|
| 3622 | + } |
|
| 3623 | + } |
|
| 3624 | + |
|
| 3625 | + if (!function_exists('calculer_cle_action')) { |
|
| 3626 | + include_spip("inc/securiser_action"); |
|
| 3627 | + } |
|
| 3628 | + |
|
| 3629 | + $c = serialize($c); |
|
| 3630 | + $cle = calculer_cle_action($form . $c); |
|
| 3631 | + $c = "$cle:$c"; |
|
| 3632 | + |
|
| 3633 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3634 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3635 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3636 | + // que ce qui est toléré. |
|
| 3637 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3638 | + if (!$cache_contextes_ajax) { |
|
| 3639 | + $env = $c; |
|
| 3640 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3641 | + $env = gzdeflate($env); |
|
| 3642 | + // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 3643 | + if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) { |
|
| 3644 | + $cache_contextes_ajax = true; |
|
| 3645 | + spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 3646 | + } |
|
| 3647 | + } |
|
| 3648 | + $env = _xor($env); |
|
| 3649 | + $env = base64_encode($env); |
|
| 3650 | + $len = strlen($env); |
|
| 3651 | + // Si l’url est trop longue pour le navigateur |
|
| 3652 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3653 | + if ($len > $max_len) { |
|
| 3654 | + $cache_contextes_ajax = true; |
|
| 3655 | + spip_log("Contextes AJAX forces en fichiers !" |
|
| 3656 | + . " Cela arrive lorsque la valeur du contexte" |
|
| 3657 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len." |
|
| 3658 | + , _LOG_AVERTISSEMENT); |
|
| 3659 | + } |
|
| 3660 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3661 | + elseif ( |
|
| 3662 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3663 | + and $max_len < $len |
|
| 3664 | + ) { |
|
| 3665 | + $cache_contextes_ajax = true; |
|
| 3666 | + spip_log("Contextes AJAX forces en fichiers !" |
|
| 3667 | + . " Cela arrive lorsque la valeur du contexte" |
|
| 3668 | + . " depasse la longueur maximale autorisee par Suhosin" |
|
| 3669 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3670 | + . " Vous devriez modifier les parametres de Suhosin" |
|
| 3671 | + . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 3672 | + } |
|
| 3673 | + |
|
| 3674 | + } |
|
| 3675 | + |
|
| 3676 | + if ($cache_contextes_ajax) { |
|
| 3677 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3678 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3679 | + $md5 = md5($c); |
|
| 3680 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3681 | + $env = $md5; |
|
| 3682 | + } |
|
| 3683 | + |
|
| 3684 | + if ($emboite === null) { |
|
| 3685 | + return $env; |
|
| 3686 | + } |
|
| 3687 | + if (!trim($emboite)) { |
|
| 3688 | + return ""; |
|
| 3689 | + } |
|
| 3690 | + // toujours encoder l'url source dans le bloc ajax |
|
| 3691 | + $r = self(); |
|
| 3692 | + $r = ' data-origin="' . $r . '"'; |
|
| 3693 | + $class = 'ajaxbloc'; |
|
| 3694 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 3695 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 3696 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3697 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3698 | + } |
|
| 3699 | + |
|
| 3700 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3701 | 3701 | } |
| 3702 | 3702 | |
| 3703 | 3703 | /** |
@@ -3717,36 +3717,36 @@ discard block |
||
| 3717 | 3717 | * - false : erreur de décodage |
| 3718 | 3718 | */ |
| 3719 | 3719 | function decoder_contexte_ajax($c, $form = '') { |
| 3720 | - if (!function_exists('calculer_cle_action')) { |
|
| 3721 | - include_spip("inc/securiser_action"); |
|
| 3722 | - } |
|
| 3723 | - if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 3724 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 3725 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 3726 | - ) { |
|
| 3727 | - $c = $contexte; |
|
| 3728 | - } else { |
|
| 3729 | - $c = @base64_decode($c); |
|
| 3730 | - $c = _xor($c); |
|
| 3731 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3732 | - $c = @gzinflate($c); |
|
| 3733 | - } |
|
| 3734 | - } |
|
| 3735 | - |
|
| 3736 | - // extraire la signature en debut de contexte |
|
| 3737 | - // et la verifier avant de deserializer |
|
| 3738 | - // format : signature:donneesserializees |
|
| 3739 | - if ($p = strpos($c,":")){ |
|
| 3740 | - $cle = substr($c,0,$p); |
|
| 3741 | - $c = substr($c,$p+1); |
|
| 3742 | - |
|
| 3743 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 3744 | - $env = @unserialize($c); |
|
| 3745 | - return $env; |
|
| 3746 | - } |
|
| 3747 | - } |
|
| 3748 | - |
|
| 3749 | - return false; |
|
| 3720 | + if (!function_exists('calculer_cle_action')) { |
|
| 3721 | + include_spip("inc/securiser_action"); |
|
| 3722 | + } |
|
| 3723 | + if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 3724 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 3725 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 3726 | + ) { |
|
| 3727 | + $c = $contexte; |
|
| 3728 | + } else { |
|
| 3729 | + $c = @base64_decode($c); |
|
| 3730 | + $c = _xor($c); |
|
| 3731 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3732 | + $c = @gzinflate($c); |
|
| 3733 | + } |
|
| 3734 | + } |
|
| 3735 | + |
|
| 3736 | + // extraire la signature en debut de contexte |
|
| 3737 | + // et la verifier avant de deserializer |
|
| 3738 | + // format : signature:donneesserializees |
|
| 3739 | + if ($p = strpos($c,":")){ |
|
| 3740 | + $cle = substr($c,0,$p); |
|
| 3741 | + $c = substr($c,$p+1); |
|
| 3742 | + |
|
| 3743 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 3744 | + $env = @unserialize($c); |
|
| 3745 | + return $env; |
|
| 3746 | + } |
|
| 3747 | + } |
|
| 3748 | + |
|
| 3749 | + return false; |
|
| 3750 | 3750 | } |
| 3751 | 3751 | |
| 3752 | 3752 | |
@@ -3764,20 +3764,20 @@ discard block |
||
| 3764 | 3764 | * Message décrypté ou encrypté |
| 3765 | 3765 | **/ |
| 3766 | 3766 | function _xor($message, $key = null) { |
| 3767 | - if (is_null($key)) { |
|
| 3768 | - if (!function_exists('calculer_cle_action')) { |
|
| 3769 | - include_spip("inc/securiser_action"); |
|
| 3770 | - } |
|
| 3771 | - $key = pack("H*", calculer_cle_action('_xor')); |
|
| 3772 | - } |
|
| 3767 | + if (is_null($key)) { |
|
| 3768 | + if (!function_exists('calculer_cle_action')) { |
|
| 3769 | + include_spip("inc/securiser_action"); |
|
| 3770 | + } |
|
| 3771 | + $key = pack("H*", calculer_cle_action('_xor')); |
|
| 3772 | + } |
|
| 3773 | 3773 | |
| 3774 | - $keylen = strlen($key); |
|
| 3775 | - $messagelen = strlen($message); |
|
| 3776 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 3777 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3778 | - } |
|
| 3774 | + $keylen = strlen($key); |
|
| 3775 | + $messagelen = strlen($message); |
|
| 3776 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 3777 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3778 | + } |
|
| 3779 | 3779 | |
| 3780 | - return $message; |
|
| 3780 | + return $message; |
|
| 3781 | 3781 | } |
| 3782 | 3782 | |
| 3783 | 3783 | /** |
@@ -3835,22 +3835,22 @@ discard block |
||
| 3835 | 3835 | * Code HTML |
| 3836 | 3836 | */ |
| 3837 | 3837 | function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') { |
| 3838 | - if ($on) { |
|
| 3839 | - $bal = "strong"; |
|
| 3840 | - $att = "class='on'"; |
|
| 3841 | - } else { |
|
| 3842 | - $bal = 'a'; |
|
| 3843 | - $att = "href='$url'" |
|
| 3844 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3845 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3846 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3847 | - . $evt; |
|
| 3848 | - } |
|
| 3849 | - if ($libelle === null) { |
|
| 3850 | - $libelle = $url; |
|
| 3851 | - } |
|
| 3838 | + if ($on) { |
|
| 3839 | + $bal = "strong"; |
|
| 3840 | + $att = "class='on'"; |
|
| 3841 | + } else { |
|
| 3842 | + $bal = 'a'; |
|
| 3843 | + $att = "href='$url'" |
|
| 3844 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3845 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3846 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3847 | + . $evt; |
|
| 3848 | + } |
|
| 3849 | + if ($libelle === null) { |
|
| 3850 | + $libelle = $url; |
|
| 3851 | + } |
|
| 3852 | 3852 | |
| 3853 | - return "<$bal $att>$libelle</$bal>"; |
|
| 3853 | + return "<$bal $att>$libelle</$bal>"; |
|
| 3854 | 3854 | } |
| 3855 | 3855 | |
| 3856 | 3856 | |
@@ -3867,18 +3867,18 @@ discard block |
||
| 3867 | 3867 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 3868 | 3868 | */ |
| 3869 | 3869 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) { |
| 3870 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 3871 | - return ""; |
|
| 3872 | - } |
|
| 3873 | - if (!is_array($vars)) { |
|
| 3874 | - return ""; |
|
| 3875 | - } |
|
| 3876 | - $vars[$var] = $nb; |
|
| 3877 | - if ($nb >= 2) { |
|
| 3878 | - return _T($chaine_plusieurs, $vars); |
|
| 3879 | - } else { |
|
| 3880 | - return _T($chaine_un, $vars); |
|
| 3881 | - } |
|
| 3870 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 3871 | + return ""; |
|
| 3872 | + } |
|
| 3873 | + if (!is_array($vars)) { |
|
| 3874 | + return ""; |
|
| 3875 | + } |
|
| 3876 | + $vars[$var] = $nb; |
|
| 3877 | + if ($nb >= 2) { |
|
| 3878 | + return _T($chaine_plusieurs, $vars); |
|
| 3879 | + } else { |
|
| 3880 | + return _T($chaine_un, $vars); |
|
| 3881 | + } |
|
| 3882 | 3882 | } |
| 3883 | 3883 | |
| 3884 | 3884 | |
@@ -3903,56 +3903,56 @@ discard block |
||
| 3903 | 3903 | * @return string |
| 3904 | 3904 | */ |
| 3905 | 3905 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3906 | - if (in_array($fonction, array("del", "supprimer.gif"))) { |
|
| 3907 | - $class .= ' danger'; |
|
| 3908 | - } elseif ($fonction == "rien.gif") { |
|
| 3909 | - $fonction = ""; |
|
| 3910 | - } elseif ($fonction == "delsafe") { |
|
| 3911 | - $fonction = "del"; |
|
| 3912 | - } |
|
| 3913 | - |
|
| 3914 | - $fond_origine = $fond; |
|
| 3915 | - // remappage des icone : article-24.png+new => article-new-24.png |
|
| 3916 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 3917 | - list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 3918 | - } |
|
| 3919 | - |
|
| 3920 | - // ajouter le type d'objet dans la class de l'icone |
|
| 3921 | - $class .= " " . substr(basename($fond), 0, -4); |
|
| 3922 | - |
|
| 3923 | - $alt = attribut_html($texte); |
|
| 3924 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 3925 | - |
|
| 3926 | - $ajax = ""; |
|
| 3927 | - if (strpos($class, "ajax") !== false) { |
|
| 3928 | - $ajax = "ajax"; |
|
| 3929 | - if (strpos($class, "preload") !== false) { |
|
| 3930 | - $ajax .= " preload"; |
|
| 3931 | - } |
|
| 3932 | - if (strpos($class, "nocache") !== false) { |
|
| 3933 | - $ajax .= " nocache"; |
|
| 3934 | - } |
|
| 3935 | - $ajax = " class='$ajax'"; |
|
| 3936 | - } |
|
| 3937 | - |
|
| 3938 | - $size = 24; |
|
| 3939 | - if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match) |
|
| 3940 | - or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) { |
|
| 3941 | - $size = $match[1]; |
|
| 3942 | - } |
|
| 3943 | - |
|
| 3944 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 3945 | - $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>"; |
|
| 3946 | - |
|
| 3947 | - if ($type == 'lien') { |
|
| 3948 | - return "<span class='icone s$size $class'>" |
|
| 3949 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 3950 | - . $icone |
|
| 3951 | - . "<b>$texte</b>" |
|
| 3952 | - . "</a></span>\n"; |
|
| 3953 | - } else { |
|
| 3954 | - return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt); |
|
| 3955 | - } |
|
| 3906 | + if (in_array($fonction, array("del", "supprimer.gif"))) { |
|
| 3907 | + $class .= ' danger'; |
|
| 3908 | + } elseif ($fonction == "rien.gif") { |
|
| 3909 | + $fonction = ""; |
|
| 3910 | + } elseif ($fonction == "delsafe") { |
|
| 3911 | + $fonction = "del"; |
|
| 3912 | + } |
|
| 3913 | + |
|
| 3914 | + $fond_origine = $fond; |
|
| 3915 | + // remappage des icone : article-24.png+new => article-new-24.png |
|
| 3916 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 3917 | + list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 3918 | + } |
|
| 3919 | + |
|
| 3920 | + // ajouter le type d'objet dans la class de l'icone |
|
| 3921 | + $class .= " " . substr(basename($fond), 0, -4); |
|
| 3922 | + |
|
| 3923 | + $alt = attribut_html($texte); |
|
| 3924 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 3925 | + |
|
| 3926 | + $ajax = ""; |
|
| 3927 | + if (strpos($class, "ajax") !== false) { |
|
| 3928 | + $ajax = "ajax"; |
|
| 3929 | + if (strpos($class, "preload") !== false) { |
|
| 3930 | + $ajax .= " preload"; |
|
| 3931 | + } |
|
| 3932 | + if (strpos($class, "nocache") !== false) { |
|
| 3933 | + $ajax .= " nocache"; |
|
| 3934 | + } |
|
| 3935 | + $ajax = " class='$ajax'"; |
|
| 3936 | + } |
|
| 3937 | + |
|
| 3938 | + $size = 24; |
|
| 3939 | + if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match) |
|
| 3940 | + or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) { |
|
| 3941 | + $size = $match[1]; |
|
| 3942 | + } |
|
| 3943 | + |
|
| 3944 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 3945 | + $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>"; |
|
| 3946 | + |
|
| 3947 | + if ($type == 'lien') { |
|
| 3948 | + return "<span class='icone s$size $class'>" |
|
| 3949 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 3950 | + . $icone |
|
| 3951 | + . "<b>$texte</b>" |
|
| 3952 | + . "</a></span>\n"; |
|
| 3953 | + } else { |
|
| 3954 | + return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt); |
|
| 3955 | + } |
|
| 3956 | 3956 | } |
| 3957 | 3957 | |
| 3958 | 3958 | /** |
@@ -3976,7 +3976,7 @@ discard block |
||
| 3976 | 3976 | * Code HTML du lien |
| 3977 | 3977 | **/ |
| 3978 | 3978 | function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3979 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 3979 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 3980 | 3980 | } |
| 3981 | 3981 | |
| 3982 | 3982 | /** |
@@ -4011,7 +4011,7 @@ discard block |
||
| 4011 | 4011 | * Code HTML du lien |
| 4012 | 4012 | **/ |
| 4013 | 4013 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 4014 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4014 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4015 | 4015 | } |
| 4016 | 4016 | |
| 4017 | 4017 | /** |
@@ -4056,7 +4056,7 @@ discard block |
||
| 4056 | 4056 | * Code HTML du lien |
| 4057 | 4057 | **/ |
| 4058 | 4058 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 4059 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4059 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4060 | 4060 | } |
| 4061 | 4061 | |
| 4062 | 4062 | /** |
@@ -4087,7 +4087,7 @@ discard block |
||
| 4087 | 4087 | * Code HTML du lien |
| 4088 | 4088 | **/ |
| 4089 | 4089 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") { |
| 4090 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 4090 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 4091 | 4091 | } |
| 4092 | 4092 | |
| 4093 | 4093 | /** |
@@ -4117,7 +4117,7 @@ discard block |
||
| 4117 | 4117 | * Code HTML du lien |
| 4118 | 4118 | */ |
| 4119 | 4119 | function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") { |
| 4120 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4120 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4121 | 4121 | } |
| 4122 | 4122 | |
| 4123 | 4123 | |
@@ -4165,26 +4165,26 @@ discard block |
||
| 4165 | 4165 | * @return string Code CSS |
| 4166 | 4166 | */ |
| 4167 | 4167 | function bando_images_background() { |
| 4168 | - include_spip('inc/bandeau'); |
|
| 4169 | - // recuperer tous les boutons et leurs images |
|
| 4170 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4168 | + include_spip('inc/bandeau'); |
|
| 4169 | + // recuperer tous les boutons et leurs images |
|
| 4170 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4171 | 4171 | |
| 4172 | - $res = ""; |
|
| 4173 | - foreach ($boutons as $page => $detail) { |
|
| 4174 | - if ($detail->icone and strlen(trim($detail->icone))) { |
|
| 4175 | - $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4176 | - } |
|
| 4177 | - $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
|
| 4178 | - if (is_array($detail->sousmenu)) { |
|
| 4179 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4180 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4181 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4182 | - } |
|
| 4183 | - } |
|
| 4184 | - } |
|
| 4185 | - } |
|
| 4172 | + $res = ""; |
|
| 4173 | + foreach ($boutons as $page => $detail) { |
|
| 4174 | + if ($detail->icone and strlen(trim($detail->icone))) { |
|
| 4175 | + $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4176 | + } |
|
| 4177 | + $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
|
| 4178 | + if (is_array($detail->sousmenu)) { |
|
| 4179 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4180 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4181 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4182 | + } |
|
| 4183 | + } |
|
| 4184 | + } |
|
| 4185 | + } |
|
| 4186 | 4186 | |
| 4187 | - return $res; |
|
| 4187 | + return $res; |
|
| 4188 | 4188 | } |
| 4189 | 4189 | |
| 4190 | 4190 | /** |
@@ -4203,19 +4203,19 @@ discard block |
||
| 4203 | 4203 | * @return string |
| 4204 | 4204 | */ |
| 4205 | 4205 | function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") { |
| 4206 | - if ($confirm) { |
|
| 4207 | - $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4208 | - if ($callback) { |
|
| 4209 | - $callback = "$confirm?($callback):false"; |
|
| 4210 | - } else { |
|
| 4211 | - $callback = $confirm; |
|
| 4212 | - } |
|
| 4213 | - } |
|
| 4214 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4215 | - $title = $title ? " title='$title'" : ""; |
|
| 4206 | + if ($confirm) { |
|
| 4207 | + $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4208 | + if ($callback) { |
|
| 4209 | + $callback = "$confirm?($callback):false"; |
|
| 4210 | + } else { |
|
| 4211 | + $callback = $confirm; |
|
| 4212 | + } |
|
| 4213 | + } |
|
| 4214 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4215 | + $title = $title ? " title='$title'" : ""; |
|
| 4216 | 4216 | |
| 4217 | - return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4218 | - . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 4217 | + return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4218 | + . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 4219 | 4219 | } |
| 4220 | 4220 | |
| 4221 | 4221 | /** |
@@ -4236,78 +4236,78 @@ discard block |
||
| 4236 | 4236 | * @return string |
| 4237 | 4237 | */ |
| 4238 | 4238 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") { |
| 4239 | - static $trouver_table = null; |
|
| 4240 | - static $objets; |
|
| 4241 | - |
|
| 4242 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4243 | - $id_objet = intval($id_objet); |
|
| 4244 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4245 | - return ''; |
|
| 4246 | - } |
|
| 4247 | - |
|
| 4248 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4249 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4250 | - return ''; |
|
| 4251 | - } |
|
| 4252 | - |
|
| 4253 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4254 | - if ($info == 'url') { |
|
| 4255 | - return generer_url_entite($id_objet, $type_objet); |
|
| 4256 | - } |
|
| 4257 | - |
|
| 4258 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4259 | - $demande_titre = ($info == 'titre'); |
|
| 4260 | - |
|
| 4261 | - // 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 |
|
| 4262 | - if (!isset($objets[$type_objet][$id_objet]) |
|
| 4263 | - or |
|
| 4264 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4265 | - ) { |
|
| 4266 | - if (!$trouver_table) { |
|
| 4267 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4268 | - } |
|
| 4269 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4270 | - if (!$desc) { |
|
| 4271 | - return $objets[$type_objet] = false; |
|
| 4272 | - } |
|
| 4273 | - |
|
| 4274 | - // Si on demande le titre, on le gere en interne |
|
| 4275 | - $champ_titre = ""; |
|
| 4276 | - if ($demande_titre) { |
|
| 4277 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4278 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4279 | - } |
|
| 4280 | - include_spip('base/abstract_sql'); |
|
| 4281 | - include_spip('base/connect_sql'); |
|
| 4282 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4283 | - '*' . $champ_titre, |
|
| 4284 | - $desc['table_sql'], |
|
| 4285 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4286 | - ); |
|
| 4287 | - } |
|
| 4288 | - |
|
| 4289 | - // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4290 | - if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4291 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 4292 | - } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4293 | - else { |
|
| 4294 | - if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4295 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 4296 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4297 | - else { |
|
| 4298 | - $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4299 | - } |
|
| 4300 | - } |
|
| 4301 | - |
|
| 4302 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4303 | - if (!$etoile) { |
|
| 4304 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4305 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4306 | - $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet), |
|
| 4307 | - array('id_objet' => $id_objet, 'objet' => $type_objet, '')); |
|
| 4308 | - } |
|
| 4309 | - |
|
| 4310 | - return $info_generee; |
|
| 4239 | + static $trouver_table = null; |
|
| 4240 | + static $objets; |
|
| 4241 | + |
|
| 4242 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4243 | + $id_objet = intval($id_objet); |
|
| 4244 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4245 | + return ''; |
|
| 4246 | + } |
|
| 4247 | + |
|
| 4248 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4249 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4250 | + return ''; |
|
| 4251 | + } |
|
| 4252 | + |
|
| 4253 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4254 | + if ($info == 'url') { |
|
| 4255 | + return generer_url_entite($id_objet, $type_objet); |
|
| 4256 | + } |
|
| 4257 | + |
|
| 4258 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4259 | + $demande_titre = ($info == 'titre'); |
|
| 4260 | + |
|
| 4261 | + // 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 |
|
| 4262 | + if (!isset($objets[$type_objet][$id_objet]) |
|
| 4263 | + or |
|
| 4264 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4265 | + ) { |
|
| 4266 | + if (!$trouver_table) { |
|
| 4267 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4268 | + } |
|
| 4269 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4270 | + if (!$desc) { |
|
| 4271 | + return $objets[$type_objet] = false; |
|
| 4272 | + } |
|
| 4273 | + |
|
| 4274 | + // Si on demande le titre, on le gere en interne |
|
| 4275 | + $champ_titre = ""; |
|
| 4276 | + if ($demande_titre) { |
|
| 4277 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4278 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4279 | + } |
|
| 4280 | + include_spip('base/abstract_sql'); |
|
| 4281 | + include_spip('base/connect_sql'); |
|
| 4282 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4283 | + '*' . $champ_titre, |
|
| 4284 | + $desc['table_sql'], |
|
| 4285 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4286 | + ); |
|
| 4287 | + } |
|
| 4288 | + |
|
| 4289 | + // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4290 | + if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4291 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 4292 | + } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4293 | + else { |
|
| 4294 | + if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4295 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 4296 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4297 | + else { |
|
| 4298 | + $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4299 | + } |
|
| 4300 | + } |
|
| 4301 | + |
|
| 4302 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4303 | + if (!$etoile) { |
|
| 4304 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4305 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4306 | + $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet), |
|
| 4307 | + array('id_objet' => $id_objet, 'objet' => $type_objet, '')); |
|
| 4308 | + } |
|
| 4309 | + |
|
| 4310 | + return $info_generee; |
|
| 4311 | 4311 | } |
| 4312 | 4312 | |
| 4313 | 4313 | /** |
@@ -4321,44 +4321,44 @@ discard block |
||
| 4321 | 4321 | * @return string |
| 4322 | 4322 | */ |
| 4323 | 4323 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') { |
| 4324 | - if (!$champ) { |
|
| 4325 | - return $texte; |
|
| 4326 | - } |
|
| 4324 | + if (!$champ) { |
|
| 4325 | + return $texte; |
|
| 4326 | + } |
|
| 4327 | 4327 | |
| 4328 | - // On charge toujours les filtres de texte car la majorité des traitements les utilisent |
|
| 4329 | - // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4330 | - include_spip('inc/texte'); |
|
| 4328 | + // On charge toujours les filtres de texte car la majorité des traitements les utilisent |
|
| 4329 | + // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4330 | + include_spip('inc/texte'); |
|
| 4331 | 4331 | |
| 4332 | - $champ = strtoupper($champ); |
|
| 4333 | - $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4334 | - if (!$traitements or !is_array($traitements)) { |
|
| 4335 | - return $texte; |
|
| 4336 | - } |
|
| 4332 | + $champ = strtoupper($champ); |
|
| 4333 | + $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4334 | + if (!$traitements or !is_array($traitements)) { |
|
| 4335 | + return $texte; |
|
| 4336 | + } |
|
| 4337 | 4337 | |
| 4338 | - $traitement = ''; |
|
| 4339 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4340 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4341 | - $table_objet = table_objet($table_objet); |
|
| 4342 | - if (isset($traitements[$table_objet])) { |
|
| 4343 | - $traitement = $traitements[$table_objet]; |
|
| 4344 | - } |
|
| 4345 | - } |
|
| 4346 | - if (!$traitement and isset($traitements[0])) { |
|
| 4347 | - $traitement = $traitements[0]; |
|
| 4348 | - } |
|
| 4349 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4338 | + $traitement = ''; |
|
| 4339 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4340 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4341 | + $table_objet = table_objet($table_objet); |
|
| 4342 | + if (isset($traitements[$table_objet])) { |
|
| 4343 | + $traitement = $traitements[$table_objet]; |
|
| 4344 | + } |
|
| 4345 | + } |
|
| 4346 | + if (!$traitement and isset($traitements[0])) { |
|
| 4347 | + $traitement = $traitements[0]; |
|
| 4348 | + } |
|
| 4349 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4350 | 4350 | |
| 4351 | - if (!$traitement) { |
|
| 4352 | - return $texte; |
|
| 4353 | - } |
|
| 4351 | + if (!$traitement) { |
|
| 4352 | + return $texte; |
|
| 4353 | + } |
|
| 4354 | 4354 | |
| 4355 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4355 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4356 | 4356 | |
| 4357 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4358 | - $Pile = array(0 => $env); |
|
| 4359 | - eval("\$texte = $traitement;"); |
|
| 4357 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4358 | + $Pile = array(0 => $env); |
|
| 4359 | + eval("\$texte = $traitement;"); |
|
| 4360 | 4360 | |
| 4361 | - return $texte; |
|
| 4361 | + return $texte; |
|
| 4362 | 4362 | } |
| 4363 | 4363 | |
| 4364 | 4364 | |
@@ -4372,21 +4372,21 @@ discard block |
||
| 4372 | 4372 | * @return string |
| 4373 | 4373 | */ |
| 4374 | 4374 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4375 | - include_spip('inc/liens'); |
|
| 4376 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4377 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4378 | - // le raccourcis n'est plus valide |
|
| 4379 | - $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4380 | - // on essaye avec generer_info_entite ? |
|
| 4381 | - if (!strlen($titre) and !$connect) { |
|
| 4382 | - $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4383 | - } |
|
| 4384 | - if (!strlen($titre)) { |
|
| 4385 | - $titre = _T('info_sans_titre'); |
|
| 4386 | - } |
|
| 4387 | - $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4375 | + include_spip('inc/liens'); |
|
| 4376 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4377 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4378 | + // le raccourcis n'est plus valide |
|
| 4379 | + $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4380 | + // on essaye avec generer_info_entite ? |
|
| 4381 | + if (!strlen($titre) and !$connect) { |
|
| 4382 | + $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4383 | + } |
|
| 4384 | + if (!strlen($titre)) { |
|
| 4385 | + $titre = _T('info_sans_titre'); |
|
| 4386 | + } |
|
| 4387 | + $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4388 | 4388 | |
| 4389 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4389 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4390 | 4390 | } |
| 4391 | 4391 | |
| 4392 | 4392 | |
@@ -4403,15 +4403,15 @@ discard block |
||
| 4403 | 4403 | * @return string |
| 4404 | 4404 | */ |
| 4405 | 4405 | function wrap($texte, $wrap) { |
| 4406 | - $balises = extraire_balises($wrap); |
|
| 4407 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4408 | - $texte = $wrap . $texte; |
|
| 4409 | - $regs = array_reverse($regs[1]); |
|
| 4410 | - $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4411 | - $texte = $texte . $wrap; |
|
| 4412 | - } |
|
| 4406 | + $balises = extraire_balises($wrap); |
|
| 4407 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4408 | + $texte = $wrap . $texte; |
|
| 4409 | + $regs = array_reverse($regs[1]); |
|
| 4410 | + $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4411 | + $texte = $texte . $wrap; |
|
| 4412 | + } |
|
| 4413 | 4413 | |
| 4414 | - return $texte; |
|
| 4414 | + return $texte; |
|
| 4415 | 4415 | } |
| 4416 | 4416 | |
| 4417 | 4417 | |
@@ -4431,43 +4431,43 @@ discard block |
||
| 4431 | 4431 | * @return array|mixed|string |
| 4432 | 4432 | */ |
| 4433 | 4433 | function filtre_print_dist($u, $join = "<br />", $indent = 0) { |
| 4434 | - if (is_string($u)) { |
|
| 4435 | - $u = typo($u); |
|
| 4434 | + if (is_string($u)) { |
|
| 4435 | + $u = typo($u); |
|
| 4436 | 4436 | |
| 4437 | - return $u; |
|
| 4438 | - } |
|
| 4437 | + return $u; |
|
| 4438 | + } |
|
| 4439 | 4439 | |
| 4440 | - // caster $u en array si besoin |
|
| 4441 | - if (is_object($u)) { |
|
| 4442 | - $u = (array)$u; |
|
| 4443 | - } |
|
| 4440 | + // caster $u en array si besoin |
|
| 4441 | + if (is_object($u)) { |
|
| 4442 | + $u = (array)$u; |
|
| 4443 | + } |
|
| 4444 | 4444 | |
| 4445 | - if (is_array($u)) { |
|
| 4446 | - $out = ""; |
|
| 4447 | - // toutes les cles sont numeriques ? |
|
| 4448 | - // et aucun enfant n'est un tableau |
|
| 4449 | - // liste simple separee par des virgules |
|
| 4450 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4451 | - $array_values = array_map('is_array', $u); |
|
| 4452 | - $object_values = array_map('is_object', $u); |
|
| 4453 | - if (array_sum($numeric_keys) == count($numeric_keys) |
|
| 4454 | - and !array_sum($array_values) |
|
| 4455 | - and !array_sum($object_values) |
|
| 4456 | - ) { |
|
| 4457 | - return join(", ", array_map('filtre_print_dist', $u)); |
|
| 4458 | - } |
|
| 4445 | + if (is_array($u)) { |
|
| 4446 | + $out = ""; |
|
| 4447 | + // toutes les cles sont numeriques ? |
|
| 4448 | + // et aucun enfant n'est un tableau |
|
| 4449 | + // liste simple separee par des virgules |
|
| 4450 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4451 | + $array_values = array_map('is_array', $u); |
|
| 4452 | + $object_values = array_map('is_object', $u); |
|
| 4453 | + if (array_sum($numeric_keys) == count($numeric_keys) |
|
| 4454 | + and !array_sum($array_values) |
|
| 4455 | + and !array_sum($object_values) |
|
| 4456 | + ) { |
|
| 4457 | + return join(", ", array_map('filtre_print_dist', $u)); |
|
| 4458 | + } |
|
| 4459 | 4459 | |
| 4460 | - // sinon on passe a la ligne et on indente |
|
| 4461 | - $i_str = str_pad("", $indent, " "); |
|
| 4462 | - foreach ($u as $k => $v) { |
|
| 4463 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4464 | - } |
|
| 4460 | + // sinon on passe a la ligne et on indente |
|
| 4461 | + $i_str = str_pad("", $indent, " "); |
|
| 4462 | + foreach ($u as $k => $v) { |
|
| 4463 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4464 | + } |
|
| 4465 | 4465 | |
| 4466 | - return $out; |
|
| 4467 | - } |
|
| 4466 | + return $out; |
|
| 4467 | + } |
|
| 4468 | 4468 | |
| 4469 | - // on sait pas quoi faire... |
|
| 4470 | - return $u; |
|
| 4469 | + // on sait pas quoi faire... |
|
| 4470 | + return $u; |
|
| 4471 | 4471 | } |
| 4472 | 4472 | |
| 4473 | 4473 | |
@@ -4480,10 +4480,10 @@ discard block |
||
| 4480 | 4480 | * @return string|array |
| 4481 | 4481 | */ |
| 4482 | 4482 | function objet_info($objet, $info) { |
| 4483 | - $table = table_objet_sql($objet); |
|
| 4484 | - $infos = lister_tables_objets_sql($table); |
|
| 4483 | + $table = table_objet_sql($objet); |
|
| 4484 | + $infos = lister_tables_objets_sql($table); |
|
| 4485 | 4485 | |
| 4486 | - return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 4486 | + return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 4487 | 4487 | } |
| 4488 | 4488 | |
| 4489 | 4489 | /** |
@@ -4498,11 +4498,11 @@ discard block |
||
| 4498 | 4498 | * Texte traduit du comptage, tel que '3 articles' |
| 4499 | 4499 | */ |
| 4500 | 4500 | function objet_afficher_nb($nb, $objet) { |
| 4501 | - if (!$nb) { |
|
| 4502 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4503 | - } else { |
|
| 4504 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb)); |
|
| 4505 | - } |
|
| 4501 | + if (!$nb) { |
|
| 4502 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4503 | + } else { |
|
| 4504 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb)); |
|
| 4505 | + } |
|
| 4506 | 4506 | } |
| 4507 | 4507 | |
| 4508 | 4508 | /** |
@@ -4514,11 +4514,11 @@ discard block |
||
| 4514 | 4514 | * @return string |
| 4515 | 4515 | */ |
| 4516 | 4516 | function objet_icone($objet, $taille = 24, $class='') { |
| 4517 | - $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4518 | - $icone = chemin_image($icone); |
|
| 4519 | - $balise_img = charger_filtre('balise_img'); |
|
| 4517 | + $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4518 | + $icone = chemin_image($icone); |
|
| 4519 | + $balise_img = charger_filtre('balise_img'); |
|
| 4520 | 4520 | |
| 4521 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4521 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 4522 | 4522 | } |
| 4523 | 4523 | |
| 4524 | 4524 | /** |
@@ -4539,12 +4539,12 @@ discard block |
||
| 4539 | 4539 | * @return string |
| 4540 | 4540 | */ |
| 4541 | 4541 | function objet_T($objet, $chaine, $args = array(), $options = array()){ |
| 4542 | - $chaine = explode(':',$chaine); |
|
| 4543 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4544 | - return $t; |
|
| 4545 | - } |
|
| 4546 | - $chaine = implode(':',$chaine); |
|
| 4547 | - return _T($chaine, $args, $options); |
|
| 4542 | + $chaine = explode(':',$chaine); |
|
| 4543 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4544 | + return $t; |
|
| 4545 | + } |
|
| 4546 | + $chaine = implode(':',$chaine); |
|
| 4547 | + return _T($chaine, $args, $options); |
|
| 4548 | 4548 | } |
| 4549 | 4549 | |
| 4550 | 4550 | /** |
@@ -4558,17 +4558,17 @@ discard block |
||
| 4558 | 4558 | * @return string Code HTML |
| 4559 | 4559 | */ |
| 4560 | 4560 | function insert_head_css_conditionnel($flux) { |
| 4561 | - if (strpos($flux, '<!-- insert_head_css -->') === false |
|
| 4562 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 4563 | - ) { |
|
| 4564 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4565 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 4566 | - $p = $p1; |
|
| 4567 | - } |
|
| 4568 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4569 | - } |
|
| 4561 | + if (strpos($flux, '<!-- insert_head_css -->') === false |
|
| 4562 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 4563 | + ) { |
|
| 4564 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4565 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 4566 | + $p = $p1; |
|
| 4567 | + } |
|
| 4568 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4569 | + } |
|
| 4570 | 4570 | |
| 4571 | - return $flux; |
|
| 4571 | + return $flux; |
|
| 4572 | 4572 | } |
| 4573 | 4573 | |
| 4574 | 4574 | /** |
@@ -4589,69 +4589,69 @@ discard block |
||
| 4589 | 4589 | * @return string |
| 4590 | 4590 | */ |
| 4591 | 4591 | function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') { |
| 4592 | - if (isset($contexte['format'])) { |
|
| 4593 | - $extension = $contexte['format']; |
|
| 4594 | - unset($contexte['format']); |
|
| 4595 | - } else { |
|
| 4596 | - $extension = "html"; |
|
| 4597 | - if (preg_match(',[.](css|js|json)$,', $fond, $m)) { |
|
| 4598 | - $extension = $m[1]; |
|
| 4599 | - } |
|
| 4600 | - } |
|
| 4601 | - // recuperer le contenu produit par le squelette |
|
| 4602 | - $options['raw'] = true; |
|
| 4603 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4604 | - |
|
| 4605 | - // calculer le nom de la css |
|
| 4606 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4607 | - $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
|
| 4608 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 4609 | - |
|
| 4610 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 4611 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 4612 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 4613 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 4614 | - $hash = md5($contexte_implicite['host'] . '::'. $cache); |
|
| 4615 | - } |
|
| 4616 | - else { |
|
| 4617 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 4618 | - ksort($contexte); |
|
| 4619 | - $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 4620 | - } |
|
| 4621 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 4622 | - |
|
| 4623 | - // mettre a jour le fichier si il n'existe pas |
|
| 4624 | - // ou trop ancien |
|
| 4625 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 4626 | - // et recopie sur le fichier cible uniquement si il change |
|
| 4627 | - if (!file_exists($filename) |
|
| 4628 | - or !file_exists($filename . ".last") |
|
| 4629 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4630 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 4631 | - ) { |
|
| 4632 | - $contenu = $cache['texte']; |
|
| 4633 | - // passer les urls en absolu si c'est une css |
|
| 4634 | - if ($extension == "css") { |
|
| 4635 | - $contenu = urls_absolues_css($contenu, |
|
| 4636 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)); |
|
| 4637 | - } |
|
| 4638 | - |
|
| 4639 | - $comment = ''; |
|
| 4640 | - // ne pas insérer de commentaire si c'est du json |
|
| 4641 | - if ($extension != "json") { |
|
| 4642 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 4643 | - foreach ($contexte as $k => $v) { |
|
| 4644 | - $comment .= ",$k=$v"; |
|
| 4645 | - } |
|
| 4646 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 4647 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 4648 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4649 | - } |
|
| 4650 | - // et ecrire le fichier si il change |
|
| 4651 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 4652 | - } |
|
| 4653 | - |
|
| 4654 | - return timestamp($filename); |
|
| 4592 | + if (isset($contexte['format'])) { |
|
| 4593 | + $extension = $contexte['format']; |
|
| 4594 | + unset($contexte['format']); |
|
| 4595 | + } else { |
|
| 4596 | + $extension = "html"; |
|
| 4597 | + if (preg_match(',[.](css|js|json)$,', $fond, $m)) { |
|
| 4598 | + $extension = $m[1]; |
|
| 4599 | + } |
|
| 4600 | + } |
|
| 4601 | + // recuperer le contenu produit par le squelette |
|
| 4602 | + $options['raw'] = true; |
|
| 4603 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4604 | + |
|
| 4605 | + // calculer le nom de la css |
|
| 4606 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4607 | + $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
|
| 4608 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 4609 | + |
|
| 4610 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 4611 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 4612 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 4613 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 4614 | + $hash = md5($contexte_implicite['host'] . '::'. $cache); |
|
| 4615 | + } |
|
| 4616 | + else { |
|
| 4617 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 4618 | + ksort($contexte); |
|
| 4619 | + $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 4620 | + } |
|
| 4621 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 4622 | + |
|
| 4623 | + // mettre a jour le fichier si il n'existe pas |
|
| 4624 | + // ou trop ancien |
|
| 4625 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 4626 | + // et recopie sur le fichier cible uniquement si il change |
|
| 4627 | + if (!file_exists($filename) |
|
| 4628 | + or !file_exists($filename . ".last") |
|
| 4629 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4630 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 4631 | + ) { |
|
| 4632 | + $contenu = $cache['texte']; |
|
| 4633 | + // passer les urls en absolu si c'est une css |
|
| 4634 | + if ($extension == "css") { |
|
| 4635 | + $contenu = urls_absolues_css($contenu, |
|
| 4636 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)); |
|
| 4637 | + } |
|
| 4638 | + |
|
| 4639 | + $comment = ''; |
|
| 4640 | + // ne pas insérer de commentaire si c'est du json |
|
| 4641 | + if ($extension != "json") { |
|
| 4642 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 4643 | + foreach ($contexte as $k => $v) { |
|
| 4644 | + $comment .= ",$k=$v"; |
|
| 4645 | + } |
|
| 4646 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 4647 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 4648 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4649 | + } |
|
| 4650 | + // et ecrire le fichier si il change |
|
| 4651 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 4652 | + } |
|
| 4653 | + |
|
| 4654 | + return timestamp($filename); |
|
| 4655 | 4655 | } |
| 4656 | 4656 | |
| 4657 | 4657 | /** |
@@ -4664,14 +4664,14 @@ discard block |
||
| 4664 | 4664 | * $fichier auquel on a ajouté le timestamp |
| 4665 | 4665 | */ |
| 4666 | 4666 | function timestamp($fichier) { |
| 4667 | - if (!$fichier |
|
| 4668 | - or !file_exists($fichier) |
|
| 4669 | - or !$m = filemtime($fichier) |
|
| 4670 | - ) { |
|
| 4671 | - return $fichier; |
|
| 4672 | - } |
|
| 4667 | + if (!$fichier |
|
| 4668 | + or !file_exists($fichier) |
|
| 4669 | + or !$m = filemtime($fichier) |
|
| 4670 | + ) { |
|
| 4671 | + return $fichier; |
|
| 4672 | + } |
|
| 4673 | 4673 | |
| 4674 | - return "$fichier?$m"; |
|
| 4674 | + return "$fichier?$m"; |
|
| 4675 | 4675 | } |
| 4676 | 4676 | |
| 4677 | 4677 | /** |
@@ -4681,11 +4681,11 @@ discard block |
||
| 4681 | 4681 | * @return string |
| 4682 | 4682 | */ |
| 4683 | 4683 | function supprimer_timestamp($url) { |
| 4684 | - if (strpos($url, "?") === false) { |
|
| 4685 | - return $url; |
|
| 4686 | - } |
|
| 4684 | + if (strpos($url, "?") === false) { |
|
| 4685 | + return $url; |
|
| 4686 | + } |
|
| 4687 | 4687 | |
| 4688 | - return preg_replace(",\?[[:digit:]]+$,", "", $url); |
|
| 4688 | + return preg_replace(",\?[[:digit:]]+$,", "", $url); |
|
| 4689 | 4689 | } |
| 4690 | 4690 | |
| 4691 | 4691 | /** |
@@ -4700,9 +4700,9 @@ discard block |
||
| 4700 | 4700 | * @return string |
| 4701 | 4701 | */ |
| 4702 | 4702 | function filtre_nettoyer_titre_email_dist($titre) { |
| 4703 | - include_spip('inc/envoyer_mail'); |
|
| 4703 | + include_spip('inc/envoyer_mail'); |
|
| 4704 | 4704 | |
| 4705 | - return nettoyer_titre_email($titre); |
|
| 4705 | + return nettoyer_titre_email($titre); |
|
| 4706 | 4706 | } |
| 4707 | 4707 | |
| 4708 | 4708 | /** |
@@ -4724,19 +4724,19 @@ discard block |
||
| 4724 | 4724 | * @return string |
| 4725 | 4725 | */ |
| 4726 | 4726 | function filtre_chercher_rubrique_dist( |
| 4727 | - $titre, |
|
| 4728 | - $id_objet, |
|
| 4729 | - $id_parent, |
|
| 4730 | - $objet, |
|
| 4731 | - $id_secteur, |
|
| 4732 | - $restreint, |
|
| 4733 | - $actionable = false, |
|
| 4734 | - $retour_sans_cadre = false |
|
| 4727 | + $titre, |
|
| 4728 | + $id_objet, |
|
| 4729 | + $id_parent, |
|
| 4730 | + $objet, |
|
| 4731 | + $id_secteur, |
|
| 4732 | + $restreint, |
|
| 4733 | + $actionable = false, |
|
| 4734 | + $retour_sans_cadre = false |
|
| 4735 | 4735 | ) { |
| 4736 | - include_spip('inc/filtres_ecrire'); |
|
| 4736 | + include_spip('inc/filtres_ecrire'); |
|
| 4737 | 4737 | |
| 4738 | - return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, |
|
| 4739 | - $retour_sans_cadre); |
|
| 4738 | + return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, |
|
| 4739 | + $retour_sans_cadre); |
|
| 4740 | 4740 | } |
| 4741 | 4741 | |
| 4742 | 4742 | /** |
@@ -4765,56 +4765,56 @@ discard block |
||
| 4765 | 4765 | * Chaîne vide si l'accès est autorisé |
| 4766 | 4766 | */ |
| 4767 | 4767 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 4768 | - if ($ok) { |
|
| 4769 | - return ''; |
|
| 4770 | - } |
|
| 4771 | - |
|
| 4772 | - // Vider tous les tampons |
|
| 4773 | - $level = @ob_get_level(); |
|
| 4774 | - while ($level--) { |
|
| 4775 | - @ob_end_clean(); |
|
| 4776 | - } |
|
| 4777 | - |
|
| 4778 | - include_spip('inc/headers'); |
|
| 4779 | - |
|
| 4780 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 4781 | - if ($url) { |
|
| 4782 | - redirige_par_entete($url, '', $statut); |
|
| 4783 | - } |
|
| 4784 | - |
|
| 4785 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 4786 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 4787 | - $message = $statut; |
|
| 4788 | - $statut = 0; |
|
| 4789 | - } |
|
| 4790 | - if (!$message) { |
|
| 4791 | - $message = ''; |
|
| 4792 | - } |
|
| 4793 | - $statut = intval($statut); |
|
| 4794 | - |
|
| 4795 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 4796 | - if (test_espace_prive()) { |
|
| 4797 | - if (!$statut or !in_array($statut, array(404, 403))) { |
|
| 4798 | - $statut = 403; |
|
| 4799 | - } |
|
| 4800 | - http_status(403); |
|
| 4801 | - $echec = charger_fonction('403', 'exec'); |
|
| 4802 | - $echec($message); |
|
| 4803 | - } else { |
|
| 4804 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 4805 | - if (!$statut) { |
|
| 4806 | - $statut = 404; |
|
| 4807 | - } |
|
| 4808 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 4809 | - http_status($statut); |
|
| 4810 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 4811 | - if ($statut >= 400) { |
|
| 4812 | - echo recuperer_fond("$statut", array('erreur' => $message)); |
|
| 4813 | - } |
|
| 4814 | - } |
|
| 4815 | - |
|
| 4816 | - |
|
| 4817 | - exit; |
|
| 4768 | + if ($ok) { |
|
| 4769 | + return ''; |
|
| 4770 | + } |
|
| 4771 | + |
|
| 4772 | + // Vider tous les tampons |
|
| 4773 | + $level = @ob_get_level(); |
|
| 4774 | + while ($level--) { |
|
| 4775 | + @ob_end_clean(); |
|
| 4776 | + } |
|
| 4777 | + |
|
| 4778 | + include_spip('inc/headers'); |
|
| 4779 | + |
|
| 4780 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 4781 | + if ($url) { |
|
| 4782 | + redirige_par_entete($url, '', $statut); |
|
| 4783 | + } |
|
| 4784 | + |
|
| 4785 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 4786 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 4787 | + $message = $statut; |
|
| 4788 | + $statut = 0; |
|
| 4789 | + } |
|
| 4790 | + if (!$message) { |
|
| 4791 | + $message = ''; |
|
| 4792 | + } |
|
| 4793 | + $statut = intval($statut); |
|
| 4794 | + |
|
| 4795 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 4796 | + if (test_espace_prive()) { |
|
| 4797 | + if (!$statut or !in_array($statut, array(404, 403))) { |
|
| 4798 | + $statut = 403; |
|
| 4799 | + } |
|
| 4800 | + http_status(403); |
|
| 4801 | + $echec = charger_fonction('403', 'exec'); |
|
| 4802 | + $echec($message); |
|
| 4803 | + } else { |
|
| 4804 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 4805 | + if (!$statut) { |
|
| 4806 | + $statut = 404; |
|
| 4807 | + } |
|
| 4808 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 4809 | + http_status($statut); |
|
| 4810 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 4811 | + if ($statut >= 400) { |
|
| 4812 | + echo recuperer_fond("$statut", array('erreur' => $message)); |
|
| 4813 | + } |
|
| 4814 | + } |
|
| 4815 | + |
|
| 4816 | + |
|
| 4817 | + exit; |
|
| 4818 | 4818 | } |
| 4819 | 4819 | |
| 4820 | 4820 | /** |
@@ -4825,11 +4825,11 @@ discard block |
||
| 4825 | 4825 | * @return string |
| 4826 | 4826 | */ |
| 4827 | 4827 | function filtre_compacte_dist($source, $format = null) { |
| 4828 | - if (function_exists('compacte')) { |
|
| 4829 | - return compacte($source, $format); |
|
| 4830 | - } |
|
| 4828 | + if (function_exists('compacte')) { |
|
| 4829 | + return compacte($source, $format); |
|
| 4830 | + } |
|
| 4831 | 4831 | |
| 4832 | - return $source; |
|
| 4832 | + return $source; |
|
| 4833 | 4833 | } |
| 4834 | 4834 | |
| 4835 | 4835 | |
@@ -4841,29 +4841,29 @@ discard block |
||
| 4841 | 4841 | * @return string |
| 4842 | 4842 | */ |
| 4843 | 4843 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 4844 | - $l = strlen($passe); |
|
| 4845 | - |
|
| 4846 | - if ($l<=8 or !$afficher_partiellement){ |
|
| 4847 | - if (!$l) { |
|
| 4848 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 4849 | - } |
|
| 4850 | - return str_pad('',$afficher_partiellement ? $l : 16,'*'); |
|
| 4851 | - } |
|
| 4852 | - |
|
| 4853 | - if (is_null($portion_pourcent)) { |
|
| 4854 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 4855 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 4856 | - } |
|
| 4857 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 4858 | - } |
|
| 4859 | - if ($portion_pourcent >= 100) { |
|
| 4860 | - return $passe; |
|
| 4861 | - } |
|
| 4862 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 4863 | - $e = max($e, 0); |
|
| 4864 | - $mid = str_pad('',$l-2*$e,'*'); |
|
| 4865 | - if ($e>0 and strlen($mid)>8){ |
|
| 4866 | - $mid = '***...***'; |
|
| 4867 | - } |
|
| 4868 | - return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : ''); |
|
| 4844 | + $l = strlen($passe); |
|
| 4845 | + |
|
| 4846 | + if ($l<=8 or !$afficher_partiellement){ |
|
| 4847 | + if (!$l) { |
|
| 4848 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 4849 | + } |
|
| 4850 | + return str_pad('',$afficher_partiellement ? $l : 16,'*'); |
|
| 4851 | + } |
|
| 4852 | + |
|
| 4853 | + if (is_null($portion_pourcent)) { |
|
| 4854 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 4855 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 4856 | + } |
|
| 4857 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 4858 | + } |
|
| 4859 | + if ($portion_pourcent >= 100) { |
|
| 4860 | + return $passe; |
|
| 4861 | + } |
|
| 4862 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 4863 | + $e = max($e, 0); |
|
| 4864 | + $mid = str_pad('',$l-2*$e,'*'); |
|
| 4865 | + if ($e>0 and strlen($mid)>8){ |
|
| 4866 | + $mid = '***...***'; |
|
| 4867 | + } |
|
| 4868 | + return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : ''); |
|
| 4869 | 4869 | } |
| 4870 | 4870 | \ No newline at end of file |