@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -67,31 +67,31 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 69 | 69 | |
| 70 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 71 | - $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 72 | - if ($attributs) { |
|
| 73 | - $attributs = " " . trim($attributs); |
|
| 74 | - } |
|
| 75 | - if ($langage) { |
|
| 76 | - $class .= " language-$langage"; |
|
| 77 | - $attributs .= ' data-language="'. $langage .'"'; |
|
| 78 | - } |
|
| 79 | - if ($bloc) { |
|
| 80 | - $html = "<div class=\"precode\">" |
|
| 81 | - . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 82 | - . "<code>" |
|
| 83 | - . $echap |
|
| 84 | - . '</code>' |
|
| 85 | - . '</pre>' |
|
| 86 | - . '</div>'; |
|
| 87 | - } |
|
| 88 | - else { |
|
| 89 | - $echap = str_replace("\t", " ", $echap); |
|
| 90 | - $echap = str_replace(" ", " ", $echap); |
|
| 91 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $html; |
|
| 70 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 71 | + $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 72 | + if ($attributs) { |
|
| 73 | + $attributs = " " . trim($attributs); |
|
| 74 | + } |
|
| 75 | + if ($langage) { |
|
| 76 | + $class .= " language-$langage"; |
|
| 77 | + $attributs .= ' data-language="'. $langage .'"'; |
|
| 78 | + } |
|
| 79 | + if ($bloc) { |
|
| 80 | + $html = "<div class=\"precode\">" |
|
| 81 | + . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 82 | + . "<code>" |
|
| 83 | + . $echap |
|
| 84 | + . '</code>' |
|
| 85 | + . '</pre>' |
|
| 86 | + . '</div>'; |
|
| 87 | + } |
|
| 88 | + else { |
|
| 89 | + $echap = str_replace("\t", " ", $echap); |
|
| 90 | + $echap = str_replace(" ", " ", $echap); |
|
| 91 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $html; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 100 | 100 | |
| 101 | 101 | if (!defined('_BALISES_BLOCS')) { |
| 102 | - define( |
|
| 103 | - '_BALISES_BLOCS', |
|
| 104 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 105 | - ); |
|
| 102 | + define( |
|
| 103 | + '_BALISES_BLOCS', |
|
| 104 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 105 | + ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 109 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 109 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // |
@@ -117,100 +117,100 @@ discard block |
||
| 117 | 117 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 118 | 118 | // echappe est un div ou un span |
| 119 | 119 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 120 | - if (!strlen($rempl)) { |
|
| 121 | - return ''; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Tester si on echappe en span ou en div |
|
| 125 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 126 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 130 | - $taille = 30000; |
|
| 131 | - $return = ''; |
|
| 132 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 133 | - // Convertir en base64 et cacher dans un attribut |
|
| 134 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 135 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 136 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $return; |
|
| 120 | + if (!strlen($rempl)) { |
|
| 121 | + return ''; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Tester si on echappe en span ou en div |
|
| 125 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 126 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 130 | + $taille = 30000; |
|
| 131 | + $return = ''; |
|
| 132 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 133 | + // Convertir en base64 et cacher dans un attribut |
|
| 134 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 135 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 136 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $return; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | // Echapper les <html>...</ html> |
| 144 | 144 | function traiter_echap_html_dist($regs, $options = []) { |
| 145 | - return $regs[3]; |
|
| 145 | + return $regs[3]; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Echapper les <pre>...</ pre> |
| 149 | 149 | function traiter_echap_pre_dist($regs, $options = []) { |
| 150 | - // echapper les <code> dans <pre> |
|
| 151 | - $pre = $regs[3]; |
|
| 152 | - |
|
| 153 | - // echapper les < dans <code> |
|
| 154 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 155 | - if ( |
|
| 156 | - strpos($pre, '<') !== false |
|
| 157 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 158 | - ) { |
|
| 159 | - foreach ($matches as $m) { |
|
| 160 | - if ($m[1] === 'code') { |
|
| 161 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 162 | - $pre = str_replace($m[0], $code, $pre); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return "<pre>$pre</pre>"; |
|
| 150 | + // echapper les <code> dans <pre> |
|
| 151 | + $pre = $regs[3]; |
|
| 152 | + |
|
| 153 | + // echapper les < dans <code> |
|
| 154 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 155 | + if ( |
|
| 156 | + strpos($pre, '<') !== false |
|
| 157 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 158 | + ) { |
|
| 159 | + foreach ($matches as $m) { |
|
| 160 | + if ($m[1] === 'code') { |
|
| 161 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 162 | + $pre = str_replace($m[0], $code, $pre); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return "<pre>$pre</pre>"; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // Echapper les <code>...</ code> |
| 170 | 170 | function traiter_echap_code_dist($regs, $options = []) { |
| 171 | - [, , $att, $corps] = $regs; |
|
| 171 | + [, , $att, $corps] = $regs; |
|
| 172 | 172 | |
| 173 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 174 | - if (strpos($corps, "\n") !== false) { |
|
| 175 | - // supprimer les sauts de ligne debut/fin |
|
| 176 | - // (mais pas les espaces => ascii art). |
|
| 177 | - $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 173 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 174 | + if (strpos($corps, "\n") !== false) { |
|
| 175 | + // supprimer les sauts de ligne debut/fin |
|
| 176 | + // (mais pas les espaces => ascii art). |
|
| 177 | + $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 178 | 178 | |
| 179 | - $echap = spip_balisage_code($corps, true, $att); |
|
| 180 | - } else { |
|
| 181 | - $echap = spip_balisage_code($corps, false, $att); |
|
| 182 | - } |
|
| 179 | + $echap = spip_balisage_code($corps, true, $att); |
|
| 180 | + } else { |
|
| 181 | + $echap = spip_balisage_code($corps, false, $att); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return $echap; |
|
| 184 | + return $echap; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 188 | 188 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 189 | - $echap = trim(entites_html($regs[3])); |
|
| 190 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 191 | - $lignes = explode("\n", trim($echap)); |
|
| 192 | - $n = 0; |
|
| 193 | - foreach ($lignes as $l) { |
|
| 194 | - $n += floor(strlen($l) / 60) + 1; |
|
| 195 | - } |
|
| 196 | - $n = max($n, 2); |
|
| 197 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 198 | - |
|
| 199 | - return $echap; |
|
| 189 | + $echap = trim(entites_html($regs[3])); |
|
| 190 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 191 | + $lignes = explode("\n", trim($echap)); |
|
| 192 | + $n = 0; |
|
| 193 | + foreach ($lignes as $l) { |
|
| 194 | + $n += floor(strlen($l) / 60) + 1; |
|
| 195 | + } |
|
| 196 | + $n = max($n, 2); |
|
| 197 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 198 | + |
|
| 199 | + return $echap; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function traiter_echap_frame_dist($regs, $options = []) { |
| 203 | - return traiter_echap_cadre_dist($regs); |
|
| 203 | + return traiter_echap_cadre_dist($regs); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | function traiter_echap_script_dist($regs, $options = []) { |
| 207 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 208 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 209 | - return highlight_string($regs[0], true); |
|
| 210 | - } |
|
| 207 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 208 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 209 | + return highlight_string($regs[0], true); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - // Cas normal : le script passe tel quel |
|
| 213 | - return $regs[0]; |
|
| 212 | + // Cas normal : le script passe tel quel |
|
| 213 | + return $regs[0]; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -229,73 +229,73 @@ discard block |
||
| 229 | 229 | * @return string|string[] |
| 230 | 230 | */ |
| 231 | 231 | function echappe_html( |
| 232 | - $letexte, |
|
| 233 | - $source = '', |
|
| 234 | - $no_transform = false, |
|
| 235 | - $preg = '', |
|
| 236 | - $callback_prefix = '', |
|
| 237 | - $callback_options = [] |
|
| 232 | + $letexte, |
|
| 233 | + $source = '', |
|
| 234 | + $no_transform = false, |
|
| 235 | + $preg = '', |
|
| 236 | + $callback_prefix = '', |
|
| 237 | + $callback_options = [] |
|
| 238 | 238 | ) { |
| 239 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 240 | - return $letexte; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - if ( |
|
| 244 | - ($preg or str_contains($letexte, '<')) |
|
| 245 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 246 | - ) { |
|
| 247 | - foreach ($matches as $regs) { |
|
| 248 | - // echappements tels quels ? |
|
| 249 | - if ($no_transform) { |
|
| 250 | - $echap = $regs[0]; |
|
| 251 | - } // sinon les traiter selon le cas |
|
| 252 | - else { |
|
| 253 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | - if ( |
|
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 257 | - or ($callback_secure_prefix and ( |
|
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 260 | - )) |
|
| 261 | - ) { |
|
| 262 | - $echap = $f($regs, $callback_options); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if ($no_transform) { |
|
| 272 | - return $letexte; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | - // seulement si on a echappe les <script> |
|
| 277 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | - // dans une callback autonommee |
|
| 279 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | - if ( |
|
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | - ',<[?].*($|[?]>),UisS', |
|
| 283 | - $letexte, |
|
| 284 | - $matches, |
|
| 285 | - PREG_SET_ORDER |
|
| 286 | - ) |
|
| 287 | - ) { |
|
| 288 | - foreach ($matches as $regs) { |
|
| 289 | - $letexte = str_replace( |
|
| 290 | - $regs[0], |
|
| 291 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | - $letexte |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return $letexte; |
|
| 239 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 240 | + return $letexte; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + if ( |
|
| 244 | + ($preg or str_contains($letexte, '<')) |
|
| 245 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 246 | + ) { |
|
| 247 | + foreach ($matches as $regs) { |
|
| 248 | + // echappements tels quels ? |
|
| 249 | + if ($no_transform) { |
|
| 250 | + $echap = $regs[0]; |
|
| 251 | + } // sinon les traiter selon le cas |
|
| 252 | + else { |
|
| 253 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | + if ( |
|
| 255 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f . '_dist') |
|
| 257 | + or ($callback_secure_prefix and ( |
|
| 258 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f . '_dist') |
|
| 260 | + )) |
|
| 261 | + ) { |
|
| 262 | + $echap = $f($regs, $callback_options); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if ($no_transform) { |
|
| 272 | + return $letexte; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | + // seulement si on a echappe les <script> |
|
| 277 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | + // dans une callback autonommee |
|
| 279 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | + if ( |
|
| 281 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | + ',<[?].*($|[?]>),UisS', |
|
| 283 | + $letexte, |
|
| 284 | + $matches, |
|
| 285 | + PREG_SET_ORDER |
|
| 286 | + ) |
|
| 287 | + ) { |
|
| 288 | + foreach ($matches as $regs) { |
|
| 289 | + $letexte = str_replace( |
|
| 290 | + $regs[0], |
|
| 291 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | + $letexte |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return $letexte; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // |
@@ -303,57 +303,57 @@ discard block |
||
| 303 | 303 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 304 | 304 | // par propre() : exemple dans multi et dans typo() |
| 305 | 305 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 306 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | - $max_prof = 5; |
|
| 309 | - while ( |
|
| 310 | - strpos($letexte, '<') !== false |
|
| 311 | - and |
|
| 312 | - preg_match_all( |
|
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | - $letexte, |
|
| 315 | - $regs, |
|
| 316 | - PREG_SET_ORDER |
|
| 317 | - ) |
|
| 318 | - and $max_prof-- |
|
| 319 | - ) { |
|
| 320 | - foreach ($regs as $reg) { |
|
| 321 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | - // recherche d'attributs supplementaires |
|
| 323 | - $at = []; |
|
| 324 | - foreach (['lang', 'dir'] as $attr) { |
|
| 325 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | - $at[$attr] = $a; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if ($at) { |
|
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | - foreach ($at as $attr => $a) { |
|
| 332 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - if ($filtre) { |
|
| 336 | - $rempl = $filtre($rempl); |
|
| 337 | - } |
|
| 338 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $letexte; |
|
| 306 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | + $max_prof = 5; |
|
| 309 | + while ( |
|
| 310 | + strpos($letexte, '<') !== false |
|
| 311 | + and |
|
| 312 | + preg_match_all( |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | + $letexte, |
|
| 315 | + $regs, |
|
| 316 | + PREG_SET_ORDER |
|
| 317 | + ) |
|
| 318 | + and $max_prof-- |
|
| 319 | + ) { |
|
| 320 | + foreach ($regs as $reg) { |
|
| 321 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | + // recherche d'attributs supplementaires |
|
| 323 | + $at = []; |
|
| 324 | + foreach (['lang', 'dir'] as $attr) { |
|
| 325 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | + $at[$attr] = $a; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if ($at) { |
|
| 330 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | + foreach ($at as $attr => $a) { |
|
| 332 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + if ($filtre) { |
|
| 336 | + $rempl = $filtre($rempl); |
|
| 337 | + } |
|
| 338 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $letexte; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Reinserer le javascript de confiance (venant des modeles) |
| 347 | 347 | |
| 348 | 348 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 349 | - $letexte = echappe_retour($letexte); |
|
| 349 | + $letexte = echappe_retour($letexte); |
|
| 350 | 350 | |
| 351 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | - if ($interdire_scripts) { |
|
| 353 | - $letexte = interdire_scripts($letexte); |
|
| 354 | - } |
|
| 351 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | + if ($interdire_scripts) { |
|
| 353 | + $letexte = interdire_scripts($letexte); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return trim($letexte); |
|
| 356 | + return trim($letexte); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
@@ -381,128 +381,128 @@ discard block |
||
| 381 | 381 | * texte coupé |
| 382 | 382 | **/ |
| 383 | 383 | function couper($texte, $taille = 50, $suite = null) { |
| 384 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | - return ''; |
|
| 386 | - } |
|
| 387 | - $offset = 400 + 2 * $taille; |
|
| 388 | - while ( |
|
| 389 | - $offset < $length |
|
| 390 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | - ) { |
|
| 392 | - $offset = 2 * $offset; |
|
| 393 | - } |
|
| 394 | - if ( |
|
| 395 | - $offset < $length |
|
| 396 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | - ) { |
|
| 398 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | - $offset = $p_tag_fermant + 1; |
|
| 401 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | - } |
|
| 403 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | - |
|
| 405 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | - include_spip('inc/lien'); |
|
| 407 | - } |
|
| 408 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | - |
|
| 410 | - // balises de sauts de ligne et paragraphe |
|
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | - |
|
| 414 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | - $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 416 | - |
|
| 417 | - // supprimer les tags |
|
| 418 | - $texte = supprimer_tags($texte); |
|
| 419 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | - |
|
| 421 | - // tester s'il est nécessaire de couper le texte |
|
| 422 | - if (spip_strlen($texte) <= $taille) { |
|
| 423 | - $points = ''; |
|
| 424 | - } else { |
|
| 425 | - // points de suite |
|
| 426 | - if (is_null($suite)) { |
|
| 427 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 428 | - } |
|
| 429 | - $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 430 | - |
|
| 431 | - // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 432 | - // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 433 | - // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 434 | - // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 435 | - $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 436 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 437 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 438 | - $points = $suite; |
|
| 439 | - |
|
| 440 | - // trop court ? ne pas faire de (...) |
|
| 441 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 442 | - $points = ''; |
|
| 443 | - $long = spip_substr($texte, 0, $taille + 1); |
|
| 444 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 446 | - // encore trop court ? couper au caractere |
|
| 447 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | - $texte = spip_substr($long, 0, $taille); |
|
| 449 | - } |
|
| 450 | - } else { |
|
| 451 | - $texte = $court; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - // remettre les paragraphes |
|
| 456 | - $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 457 | - |
|
| 458 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 459 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 460 | - |
|
| 461 | - return quote_amp(trim($texte)) . $points; |
|
| 384 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | + return ''; |
|
| 386 | + } |
|
| 387 | + $offset = 400 + 2 * $taille; |
|
| 388 | + while ( |
|
| 389 | + $offset < $length |
|
| 390 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | + ) { |
|
| 392 | + $offset = 2 * $offset; |
|
| 393 | + } |
|
| 394 | + if ( |
|
| 395 | + $offset < $length |
|
| 396 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | + ) { |
|
| 398 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | + $offset = $p_tag_fermant + 1; |
|
| 401 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | + } |
|
| 403 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | + |
|
| 405 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | + include_spip('inc/lien'); |
|
| 407 | + } |
|
| 408 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | + |
|
| 410 | + // balises de sauts de ligne et paragraphe |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | + |
|
| 414 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | + $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 416 | + |
|
| 417 | + // supprimer les tags |
|
| 418 | + $texte = supprimer_tags($texte); |
|
| 419 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | + |
|
| 421 | + // tester s'il est nécessaire de couper le texte |
|
| 422 | + if (spip_strlen($texte) <= $taille) { |
|
| 423 | + $points = ''; |
|
| 424 | + } else { |
|
| 425 | + // points de suite |
|
| 426 | + if (is_null($suite)) { |
|
| 427 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 428 | + } |
|
| 429 | + $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 430 | + |
|
| 431 | + // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 432 | + // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 433 | + // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 434 | + // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 435 | + $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 436 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 437 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 438 | + $points = $suite; |
|
| 439 | + |
|
| 440 | + // trop court ? ne pas faire de (...) |
|
| 441 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 442 | + $points = ''; |
|
| 443 | + $long = spip_substr($texte, 0, $taille + 1); |
|
| 444 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 446 | + // encore trop court ? couper au caractere |
|
| 447 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | + $texte = spip_substr($long, 0, $taille); |
|
| 449 | + } |
|
| 450 | + } else { |
|
| 451 | + $texte = $court; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + // remettre les paragraphes |
|
| 456 | + $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 457 | + |
|
| 458 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 459 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 460 | + |
|
| 461 | + return quote_amp(trim($texte)) . $points; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
| 465 | 465 | function protege_js_modeles($t) { |
| 466 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 467 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 468 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 469 | - include_spip('inc/acces'); |
|
| 470 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 471 | - } |
|
| 472 | - foreach ($r as $regs) { |
|
| 473 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 478 | - include_spip('inc/acces'); |
|
| 479 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 480 | - } |
|
| 481 | - foreach ($r as $regs) { |
|
| 482 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $t; |
|
| 466 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 467 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 468 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 469 | + include_spip('inc/acces'); |
|
| 470 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 471 | + } |
|
| 472 | + foreach ($r as $regs) { |
|
| 473 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 478 | + include_spip('inc/acces'); |
|
| 479 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 480 | + } |
|
| 481 | + foreach ($r as $regs) { |
|
| 482 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $t; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
| 491 | 491 | function echapper_faux_tags($letexte) { |
| 492 | - if (strpos($letexte, '<') === false) { |
|
| 493 | - return $letexte; |
|
| 494 | - } |
|
| 495 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 496 | - |
|
| 497 | - $letexte = ''; |
|
| 498 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 499 | - // un texte a echapper |
|
| 500 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 501 | - // un tag html qui a servit a faite le split |
|
| 502 | - $letexte .= array_shift($textMatches); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - return $letexte; |
|
| 492 | + if (strpos($letexte, '<') === false) { |
|
| 493 | + return $letexte; |
|
| 494 | + } |
|
| 495 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 496 | + |
|
| 497 | + $letexte = ''; |
|
| 498 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 499 | + // un texte a echapper |
|
| 500 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 501 | + // un tag html qui a servit a faite le split |
|
| 502 | + $letexte .= array_shift($textMatches); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + return $letexte; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -522,115 +522,115 @@ discard block |
||
| 522 | 522 | * @return string |
| 523 | 523 | */ |
| 524 | 524 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 525 | - static $echapper_html_suspect; |
|
| 526 | - if (!$texte or !is_string($texte)) { |
|
| 527 | - return $texte; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if (!isset($echapper_html_suspect)) { |
|
| 531 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 532 | - } |
|
| 533 | - // si fonction personalisee, on delegue |
|
| 534 | - if ($echapper_html_suspect) { |
|
| 535 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 536 | - $args = [$texte, $options]; |
|
| 537 | - if ($connect or !empty($env)) { |
|
| 538 | - $args[] = $connect; |
|
| 539 | - } |
|
| 540 | - if (!empty($env)) { |
|
| 541 | - $args[] = $env; |
|
| 542 | - } |
|
| 543 | - return $echapper_html_suspect(...$args); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if (is_bool($options)) { |
|
| 547 | - $options = ['strict' => $options]; |
|
| 548 | - } |
|
| 549 | - $strict = $options['strict'] ?? true; |
|
| 550 | - |
|
| 551 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 552 | - if ( |
|
| 553 | - strpos($texte, '<') === false |
|
| 554 | - or !str_contains($texte, '=') |
|
| 555 | - ) { |
|
| 556 | - return $texte; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 560 | - if (!isset($env['espace_prive'])) { |
|
| 561 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 562 | - $env['espace_prive'] = test_espace_prive(); |
|
| 563 | - } |
|
| 564 | - if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 565 | - |
|
| 566 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 567 | - // car sinon on declenche sur les modeles ou ressources |
|
| 568 | - if ( |
|
| 569 | - !$strict and |
|
| 570 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 571 | - ) { |
|
| 572 | - return $texte; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 576 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 577 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 578 | - $texte = $collecteurModeles->echapper($texte); |
|
| 579 | - $texte = echappe_js($texte); |
|
| 580 | - |
|
| 581 | - $texte_to_check = $texte; |
|
| 582 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 583 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 584 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 585 | - if (!empty($options['expanser_liens'])) { |
|
| 586 | - $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 587 | - } |
|
| 588 | - if (!is_html_safe($texte_to_check)) { |
|
| 589 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 590 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 591 | - $texte = str_replace('<', '<', $texte); |
|
| 592 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 593 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 594 | - if (!function_exists('attribut_html')) { |
|
| 595 | - include_spip('inc/filtres'); |
|
| 596 | - } |
|
| 597 | - if (!empty($options['wrap_suspect'])) { |
|
| 598 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 599 | - } |
|
| 600 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - $texte = $collecteurModeles->retablir($texte); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - // si on est là dans le public c'est le mode parano |
|
| 607 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 608 | - else { |
|
| 609 | - $collecteurLiens = $collecteurModeles = null; |
|
| 610 | - if (!empty($options['expanser_liens'])) { |
|
| 611 | - $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 612 | - } |
|
| 613 | - else { |
|
| 614 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 615 | - include_spip("src/Texte/Collecteur/Liens"); |
|
| 616 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 617 | - |
|
| 618 | - $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 619 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 620 | - |
|
| 621 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 622 | - $texte = $collecteurModeles->echapper($texte); |
|
| 623 | - } |
|
| 624 | - $texte = safehtml($texte); |
|
| 625 | - if ($collecteurModeles) { |
|
| 626 | - $texte = $collecteurModeles->retablir($texte); |
|
| 627 | - } |
|
| 628 | - if ($collecteurLiens) { |
|
| 629 | - $texte = $collecteurLiens->retablir($texte); |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - return $texte; |
|
| 525 | + static $echapper_html_suspect; |
|
| 526 | + if (!$texte or !is_string($texte)) { |
|
| 527 | + return $texte; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + if (!isset($echapper_html_suspect)) { |
|
| 531 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 532 | + } |
|
| 533 | + // si fonction personalisee, on delegue |
|
| 534 | + if ($echapper_html_suspect) { |
|
| 535 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 536 | + $args = [$texte, $options]; |
|
| 537 | + if ($connect or !empty($env)) { |
|
| 538 | + $args[] = $connect; |
|
| 539 | + } |
|
| 540 | + if (!empty($env)) { |
|
| 541 | + $args[] = $env; |
|
| 542 | + } |
|
| 543 | + return $echapper_html_suspect(...$args); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if (is_bool($options)) { |
|
| 547 | + $options = ['strict' => $options]; |
|
| 548 | + } |
|
| 549 | + $strict = $options['strict'] ?? true; |
|
| 550 | + |
|
| 551 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 552 | + if ( |
|
| 553 | + strpos($texte, '<') === false |
|
| 554 | + or !str_contains($texte, '=') |
|
| 555 | + ) { |
|
| 556 | + return $texte; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 560 | + if (!isset($env['espace_prive'])) { |
|
| 561 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 562 | + $env['espace_prive'] = test_espace_prive(); |
|
| 563 | + } |
|
| 564 | + if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 565 | + |
|
| 566 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 567 | + // car sinon on declenche sur les modeles ou ressources |
|
| 568 | + if ( |
|
| 569 | + !$strict and |
|
| 570 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 571 | + ) { |
|
| 572 | + return $texte; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 576 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 577 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 578 | + $texte = $collecteurModeles->echapper($texte); |
|
| 579 | + $texte = echappe_js($texte); |
|
| 580 | + |
|
| 581 | + $texte_to_check = $texte; |
|
| 582 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 583 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 584 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 585 | + if (!empty($options['expanser_liens'])) { |
|
| 586 | + $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 587 | + } |
|
| 588 | + if (!is_html_safe($texte_to_check)) { |
|
| 589 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 590 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 591 | + $texte = str_replace('<', '<', $texte); |
|
| 592 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 593 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 594 | + if (!function_exists('attribut_html')) { |
|
| 595 | + include_spip('inc/filtres'); |
|
| 596 | + } |
|
| 597 | + if (!empty($options['wrap_suspect'])) { |
|
| 598 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 599 | + } |
|
| 600 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + $texte = $collecteurModeles->retablir($texte); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + // si on est là dans le public c'est le mode parano |
|
| 607 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 608 | + else { |
|
| 609 | + $collecteurLiens = $collecteurModeles = null; |
|
| 610 | + if (!empty($options['expanser_liens'])) { |
|
| 611 | + $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 612 | + } |
|
| 613 | + else { |
|
| 614 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 615 | + include_spip("src/Texte/Collecteur/Liens"); |
|
| 616 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 617 | + |
|
| 618 | + $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 619 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 620 | + |
|
| 621 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 622 | + $texte = $collecteurModeles->echapper($texte); |
|
| 623 | + } |
|
| 624 | + $texte = safehtml($texte); |
|
| 625 | + if ($collecteurModeles) { |
|
| 626 | + $texte = $collecteurModeles->retablir($texte); |
|
| 627 | + } |
|
| 628 | + if ($collecteurLiens) { |
|
| 629 | + $texte = $collecteurLiens->retablir($texte); |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + return $texte; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | |
@@ -651,52 +651,52 @@ discard block |
||
| 651 | 651 | * texte sécurisé |
| 652 | 652 | **/ |
| 653 | 653 | function safehtml($t) { |
| 654 | - static $safehtml; |
|
| 655 | - |
|
| 656 | - if (!$t or !is_string($t)) { |
|
| 657 | - return $t; |
|
| 658 | - } |
|
| 659 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 660 | - if (strpos($t, '<') === false) { |
|
| 661 | - return str_replace("\x00", '', $t); |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - $collecteurIdiomes = null; |
|
| 665 | - if (stripos($t, '<:') !== false) { |
|
| 666 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 667 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 668 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 669 | - $t = $collecteurIdiomes->echapper($t); |
|
| 670 | - } |
|
| 671 | - $collecteurMultis = null; |
|
| 672 | - if (stripos($t, '<multi') !== false) { |
|
| 673 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 674 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 675 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 676 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - if (!function_exists('interdire_scripts')) { |
|
| 680 | - include_spip('inc/texte'); |
|
| 681 | - } |
|
| 682 | - $t = interdire_scripts($t); // jolifier le php |
|
| 683 | - $t = echappe_js($t); |
|
| 684 | - |
|
| 685 | - if (!isset($safehtml)) { |
|
| 686 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 687 | - } |
|
| 688 | - if ($safehtml) { |
|
| 689 | - $t = $safehtml($t); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - if ($collecteurMultis) { |
|
| 693 | - $t = $collecteurMultis->retablir($t); |
|
| 694 | - } |
|
| 695 | - if ($collecteurIdiomes) { |
|
| 696 | - $t = $collecteurIdiomes->retablir($t); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 654 | + static $safehtml; |
|
| 655 | + |
|
| 656 | + if (!$t or !is_string($t)) { |
|
| 657 | + return $t; |
|
| 658 | + } |
|
| 659 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 660 | + if (strpos($t, '<') === false) { |
|
| 661 | + return str_replace("\x00", '', $t); |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + $collecteurIdiomes = null; |
|
| 665 | + if (stripos($t, '<:') !== false) { |
|
| 666 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 667 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 668 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 669 | + $t = $collecteurIdiomes->echapper($t); |
|
| 670 | + } |
|
| 671 | + $collecteurMultis = null; |
|
| 672 | + if (stripos($t, '<multi') !== false) { |
|
| 673 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 674 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 675 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 676 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + if (!function_exists('interdire_scripts')) { |
|
| 680 | + include_spip('inc/texte'); |
|
| 681 | + } |
|
| 682 | + $t = interdire_scripts($t); // jolifier le php |
|
| 683 | + $t = echappe_js($t); |
|
| 684 | + |
|
| 685 | + if (!isset($safehtml)) { |
|
| 686 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 687 | + } |
|
| 688 | + if ($safehtml) { |
|
| 689 | + $t = $safehtml($t); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + if ($collecteurMultis) { |
|
| 693 | + $t = $collecteurMultis->retablir($t); |
|
| 694 | + } |
|
| 695 | + if ($collecteurIdiomes) { |
|
| 696 | + $t = $collecteurIdiomes->retablir($t); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | |
@@ -704,25 +704,25 @@ discard block |
||
| 704 | 704 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 705 | 705 | */ |
| 706 | 706 | function is_html_safe(string $texte): bool { |
| 707 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 708 | - return $is_html_safe($texte); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 712 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 713 | - // safehtml reduit aussi potentiellement les |
|
| 714 | - $texte = str_replace(" ", " ", $texte); |
|
| 715 | - // safehtml remplace les entités numériques |
|
| 716 | - if (strpos($texte, '&#') !== false) { |
|
| 717 | - $texte = unicode2charset($texte); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - $texte_safe = safehtml($texte); |
|
| 721 | - |
|
| 722 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 723 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 724 | - // donc un test d'egalite est trop strict |
|
| 725 | - return strlen($texte_safe) === strlen($texte); |
|
| 707 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 708 | + return $is_html_safe($texte); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 712 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 713 | + // safehtml reduit aussi potentiellement les |
|
| 714 | + $texte = str_replace(" ", " ", $texte); |
|
| 715 | + // safehtml remplace les entités numériques |
|
| 716 | + if (strpos($texte, '&#') !== false) { |
|
| 717 | + $texte = unicode2charset($texte); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + $texte_safe = safehtml($texte); |
|
| 721 | + |
|
| 722 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 723 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 724 | + // donc un test d'egalite est trop strict |
|
| 725 | + return strlen($texte_safe) === strlen($texte); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -743,13 +743,13 @@ discard block |
||
| 743 | 743 | * texte sans les modèles d'image |
| 744 | 744 | **/ |
| 745 | 745 | function supprime_img($letexte, $message = null) { |
| 746 | - if ($message === null) { |
|
| 747 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - return preg_replace( |
|
| 751 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 752 | - $message, |
|
| 753 | - $letexte |
|
| 754 | - ); |
|
| 746 | + if ($message === null) { |
|
| 747 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + return preg_replace( |
|
| 751 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 752 | + $message, |
|
| 753 | + $letexte |
|
| 754 | + ); |
|
| 755 | 755 | } |
@@ -10,54 +10,54 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | class IndenteurXML { |
| 17 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 18 | - xml_debutElement($this, $name, $attrs); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function finElement($phraseur, $name) { |
|
| 22 | - xml_finElement($this, $name); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function textElement($phraseur, $data) { |
|
| 26 | - xml_textElement($this, $data); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function piElement($phraseur, $target, $data) { |
|
| 30 | - xml_PiElement($this, $target, $data); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function defaultElement($phraseur, $data) { |
|
| 34 | - xml_defaultElement($this, $data); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function phraserTout($phraseur, $data) { |
|
| 38 | - xml_parsestring($this, $data); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public $depth = ''; |
|
| 42 | - public $res = ''; |
|
| 43 | - public $err = []; |
|
| 44 | - public $contenu = []; |
|
| 45 | - public $ouvrant = []; |
|
| 46 | - public $reperes = []; |
|
| 47 | - public $entete = ''; |
|
| 48 | - public $page = ''; |
|
| 49 | - public $dtc = null; |
|
| 50 | - public $sax = null; |
|
| 17 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 18 | + xml_debutElement($this, $name, $attrs); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function finElement($phraseur, $name) { |
|
| 22 | + xml_finElement($this, $name); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function textElement($phraseur, $data) { |
|
| 26 | + xml_textElement($this, $data); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function piElement($phraseur, $target, $data) { |
|
| 30 | + xml_PiElement($this, $target, $data); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function defaultElement($phraseur, $data) { |
|
| 34 | + xml_defaultElement($this, $data); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function phraserTout($phraseur, $data) { |
|
| 38 | + xml_parsestring($this, $data); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public $depth = ''; |
|
| 42 | + public $res = ''; |
|
| 43 | + public $err = []; |
|
| 44 | + public $contenu = []; |
|
| 45 | + public $ouvrant = []; |
|
| 46 | + public $reperes = []; |
|
| 47 | + public $entete = ''; |
|
| 48 | + public $page = ''; |
|
| 49 | + public $dtc = null; |
|
| 50 | + public $sax = null; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function xml_indenter_dist($page, $apply = false) { |
| 54 | - $sax = charger_fonction('sax', 'xml'); |
|
| 55 | - $f = new IndenteurXML(); |
|
| 56 | - $sax($page, $apply, $f); |
|
| 57 | - if (!$f->err) { |
|
| 58 | - return $f->entete . $f->res; |
|
| 59 | - } |
|
| 60 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 61 | - |
|
| 62 | - return $f->entete . $f->page; |
|
| 54 | + $sax = charger_fonction('sax', 'xml'); |
|
| 55 | + $f = new IndenteurXML(); |
|
| 56 | + $sax($page, $apply, $f); |
|
| 57 | + if (!$f->err) { |
|
| 58 | + return $f->entete . $f->res; |
|
| 59 | + } |
|
| 60 | + spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 61 | + |
|
| 62 | + return $f->entete . $f->page; |
|
| 63 | 63 | } |
@@ -12,498 +12,498 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Data extends AbstractIterateur implements Iterator |
| 14 | 14 | { |
| 15 | - /** Tableau de données */ |
|
| 16 | - protected array $tableau = []; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Conditions de filtrage |
|
| 20 | - * ie criteres de selection |
|
| 21 | - */ |
|
| 22 | - protected array $filtre = []; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Cle courante |
|
| 26 | - * |
|
| 27 | - * @var scalar |
|
| 28 | - */ |
|
| 29 | - protected $cle = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Valeur courante |
|
| 33 | - * |
|
| 34 | - * @var mixed |
|
| 35 | - */ |
|
| 36 | - protected $valeur = null; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Constructeur |
|
| 40 | - * |
|
| 41 | - * @param $command |
|
| 42 | - * @param array $info |
|
| 43 | - */ |
|
| 44 | - public function __construct(array $command, array $info = []) { |
|
| 45 | - include_spip('iterateur/data'); |
|
| 46 | - $this->type = 'DATA'; |
|
| 47 | - $this->command = $command; |
|
| 48 | - $this->info = $info; |
|
| 49 | - $this->select($command); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Revenir au depart |
|
| 54 | - * |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function rewind(): void { |
|
| 58 | - reset($this->tableau); |
|
| 59 | - $this->cle = array_key_first($this->tableau); |
|
| 60 | - $this->valeur = current($this->tableau); |
|
| 61 | - next($this->tableau); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Déclarer les critères exceptions |
|
| 66 | - * |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function exception_des_criteres() { |
|
| 70 | - return ['tableau']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Récupérer depuis le cache si possible |
|
| 75 | - * |
|
| 76 | - * @param string $cle |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - protected function cache_get($cle) { |
|
| 80 | - if (!$cle) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - # utiliser memoization si dispo |
|
| 84 | - if (!function_exists('cache_get')) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return cache_get($cle); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Stocker en cache si possible |
|
| 93 | - * |
|
| 94 | - * @param string $cle |
|
| 95 | - * @param int $ttl |
|
| 96 | - * @param null|mixed $valeur |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 99 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 100 | - if (!$cle) { |
|
| 101 | - return; |
|
| 102 | - } |
|
| 103 | - if (is_null($valeur)) { |
|
| 104 | - $valeur = $this->tableau; |
|
| 105 | - } |
|
| 106 | - # utiliser memoization si dispo |
|
| 107 | - if (!function_exists('cache_set')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return cache_set( |
|
| 112 | - $cle, |
|
| 113 | - [ |
|
| 114 | - 'data' => $valeur, |
|
| 115 | - 'time' => time(), |
|
| 116 | - 'ttl' => $ttl |
|
| 117 | - ], |
|
| 118 | - 3600 + $ttl |
|
| 119 | - ); |
|
| 120 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 121 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Aller chercher les données de la boucle DATA |
|
| 126 | - * |
|
| 127 | - * @throws Exception |
|
| 128 | - * @param array $command |
|
| 129 | - * @return void |
|
| 130 | - */ |
|
| 131 | - protected function select($command) { |
|
| 132 | - |
|
| 133 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 134 | - // le type se retrouve dans la commande 'from' |
|
| 135 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 136 | - if (isset($this->command['from'][0])) { |
|
| 137 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 138 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 139 | - } |
|
| 140 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 144 | - // les commandes connues pour l'iterateur DATA |
|
| 145 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 146 | - |
|
| 147 | - // {source format, [URL], [arg2]...} |
|
| 148 | - if ( |
|
| 149 | - isset($this->command['source']) |
|
| 150 | - and isset($this->command['sourcemode']) |
|
| 151 | - ) { |
|
| 152 | - $this->select_source(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // Critere {liste X1, X2, X3} |
|
| 156 | - if (isset($this->command['liste'])) { |
|
| 157 | - $this->select_liste(); |
|
| 158 | - } |
|
| 159 | - if (isset($this->command['enum'])) { |
|
| 160 | - $this->select_enum(); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 164 | - if (!is_array($this->tableau)) { |
|
| 165 | - $this->err = true; |
|
| 166 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // {datapath query.results} |
|
| 170 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 171 | - if ( |
|
| 172 | - !$this->err |
|
| 173 | - and isset($this->command['datapath']) |
|
| 174 | - and is_array($this->command['datapath']) |
|
| 175 | - ) { |
|
| 176 | - $this->select_datapath(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // tri {par x} |
|
| 180 | - if ($this->command['orderby']) { |
|
| 181 | - $this->select_orderby(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 185 | - if ($this->command['groupby']) { |
|
| 186 | - $this->select_groupby(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $this->rewind(); |
|
| 190 | - #var_dump($this->tableau); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Aller chercher les donnees de la boucle DATA |
|
| 196 | - * depuis une source |
|
| 197 | - * {source format, [URL], [arg2]...} |
|
| 198 | - */ |
|
| 199 | - protected function select_source() { |
|
| 200 | - # un peu crado : avant de charger le cache il faut charger |
|
| 201 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 202 | - # l'objet en cache ; cf plugins/icalendar |
|
| 203 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 204 | - if ( |
|
| 205 | - isset($this->command['sourcemode']) |
|
| 206 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 207 | - ) { |
|
| 208 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - # le premier argument peut etre un array, une URL etc. |
|
| 212 | - $src = $this->command['source'][0]; |
|
| 213 | - |
|
| 214 | - # avons-nous un cache dispo ? |
|
| 215 | - $cle = null; |
|
| 216 | - if (is_string($src)) { |
|
| 217 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $cache = $this->cache_get($cle); |
|
| 221 | - if (isset($this->command['datacache'])) { |
|
| 222 | - $ttl = intval($this->command['datacache']); |
|
| 223 | - } |
|
| 224 | - if ( |
|
| 225 | - $cache |
|
| 226 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 227 | - > time()) |
|
| 228 | - and !(_request('var_mode') === 'recalcul' |
|
| 229 | - and include_spip('inc/autoriser') |
|
| 230 | - and autoriser('recalcul') |
|
| 231 | - ) |
|
| 232 | - ) { |
|
| 233 | - $this->tableau = $cache['data']; |
|
| 234 | - } else { |
|
| 235 | - try { |
|
| 236 | - if ( |
|
| 237 | - isset($this->command['sourcemode']) |
|
| 238 | - and in_array( |
|
| 239 | - $this->command['sourcemode'], |
|
| 240 | - ['table', 'array', 'tableau'] |
|
| 241 | - ) |
|
| 242 | - ) { |
|
| 243 | - if ( |
|
| 244 | - is_array($a = $src) |
|
| 245 | - or (is_string($a) |
|
| 246 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 247 | - and is_array($a = @unserialize($a))) |
|
| 248 | - ) { |
|
| 249 | - $this->tableau = $a; |
|
| 250 | - } |
|
| 251 | - } else { |
|
| 252 | - $data = $src; |
|
| 253 | - if (is_string($src)) { |
|
| 254 | - if (tester_url_absolue($src)) { |
|
| 255 | - include_spip('inc/distant'); |
|
| 256 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 257 | - $data = $data['page'] ?? ''; |
|
| 258 | - if (!$data) { |
|
| 259 | - throw new Exception('404'); |
|
| 260 | - } |
|
| 261 | - if (!isset($ttl)) { |
|
| 262 | - $ttl = 24 * 3600; |
|
| 263 | - } |
|
| 264 | - } elseif (@is_dir($src)) { |
|
| 265 | - $data = $src; |
|
| 266 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 267 | - $data = spip_file_get_contents($src); |
|
| 268 | - } |
|
| 269 | - if (!isset($ttl)) { |
|
| 270 | - $ttl = 10; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - if ( |
|
| 274 | - !$this->err |
|
| 275 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 276 | - ) { |
|
| 277 | - $args = $this->command['source']; |
|
| 278 | - $args[0] = $data; |
|
| 279 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 280 | - $this->tableau = $a; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if (!is_array($this->tableau)) { |
|
| 286 | - $this->err = true; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 290 | - $this->cache_set($cle, $ttl); |
|
| 291 | - } |
|
| 292 | - } catch (Exception $e) { |
|
| 293 | - $e = $e->getMessage(); |
|
| 294 | - $err = sprintf( |
|
| 295 | - "[%s, %s] $e", |
|
| 296 | - $src, |
|
| 297 | - $this->command['sourcemode'] |
|
| 298 | - ); |
|
| 299 | - erreur_squelette([$err, []]); |
|
| 300 | - $this->err = true; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 305 | - if ( |
|
| 306 | - $this->err |
|
| 307 | - and $cache |
|
| 308 | - ) { |
|
| 309 | - $this->tableau = $cache['data']; |
|
| 310 | - $this->err = false; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Retourne un tableau donne depuis un critère liste |
|
| 317 | - * |
|
| 318 | - * Critère `{liste X1, X2, X3}` |
|
| 319 | - * |
|
| 320 | - * @see critere_DATA_liste_dist() |
|
| 321 | - * |
|
| 322 | - **/ |
|
| 323 | - protected function select_liste() { |
|
| 324 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 325 | - if (!isset($this->command['liste'][1])) { |
|
| 326 | - if (!is_array($this->command['liste'][0])) { |
|
| 327 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 328 | - } else { |
|
| 329 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - $this->tableau = $this->command['liste']; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Retourne un tableau donne depuis un critere liste |
|
| 337 | - * Critere {enum Xmin, Xmax} |
|
| 338 | - * |
|
| 339 | - **/ |
|
| 340 | - protected function select_enum() { |
|
| 341 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 342 | - if (!isset($this->command['enum'][1])) { |
|
| 343 | - if (!is_array($this->command['enum'][0])) { |
|
| 344 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 345 | - } else { |
|
| 346 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 350 | - $enum = range( |
|
| 351 | - array_shift($this->command['enum']), |
|
| 352 | - array_shift($this->command['enum']), |
|
| 353 | - array_shift($this->command['enum']) |
|
| 354 | - ); |
|
| 355 | - } else { |
|
| 356 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 357 | - } |
|
| 358 | - $this->tableau = $enum; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 364 | - * {datapath query.results} |
|
| 365 | - * |
|
| 366 | - **/ |
|
| 367 | - protected function select_datapath() { |
|
| 368 | - $base = reset($this->command['datapath']); |
|
| 369 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 370 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 371 | - if (!is_array($this->tableau)) { |
|
| 372 | - $this->tableau = []; |
|
| 373 | - $this->err = true; |
|
| 374 | - spip_log("datapath '$base' absent"); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Ordonner les resultats |
|
| 381 | - * {par x} |
|
| 382 | - * |
|
| 383 | - **/ |
|
| 384 | - protected function select_orderby() { |
|
| 385 | - $sortfunc = ''; |
|
| 386 | - $aleas = 0; |
|
| 387 | - foreach ($this->command['orderby'] as $tri) { |
|
| 388 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 389 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 390 | - $r = array_pad($r, 3, null); |
|
| 391 | - |
|
| 392 | - // tri par cle |
|
| 393 | - if ($r[1] == 'cle') { |
|
| 394 | - if (isset($r[2]) and $r[2]) { |
|
| 395 | - krsort($this->tableau); |
|
| 396 | - } else { |
|
| 397 | - ksort($this->tableau); |
|
| 398 | - } |
|
| 399 | - } # {par hasard} |
|
| 400 | - else { |
|
| 401 | - if ($r[1] == 'hasard') { |
|
| 402 | - $k = array_keys($this->tableau); |
|
| 403 | - shuffle($k); |
|
| 404 | - $v = []; |
|
| 405 | - foreach ($k as $cle) { |
|
| 406 | - $v[$cle] = $this->tableau[$cle]; |
|
| 407 | - } |
|
| 408 | - $this->tableau = $v; |
|
| 409 | - } else { |
|
| 410 | - # {par valeur} |
|
| 411 | - if ($r[1] == 'valeur') { |
|
| 412 | - $tv = '%s'; |
|
| 413 | - } # {par valeur/xx/yy} ?? |
|
| 414 | - else { |
|
| 415 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 416 | - } |
|
| 417 | - $sortfunc .= ' |
|
| 15 | + /** Tableau de données */ |
|
| 16 | + protected array $tableau = []; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Conditions de filtrage |
|
| 20 | + * ie criteres de selection |
|
| 21 | + */ |
|
| 22 | + protected array $filtre = []; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Cle courante |
|
| 26 | + * |
|
| 27 | + * @var scalar |
|
| 28 | + */ |
|
| 29 | + protected $cle = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Valeur courante |
|
| 33 | + * |
|
| 34 | + * @var mixed |
|
| 35 | + */ |
|
| 36 | + protected $valeur = null; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructeur |
|
| 40 | + * |
|
| 41 | + * @param $command |
|
| 42 | + * @param array $info |
|
| 43 | + */ |
|
| 44 | + public function __construct(array $command, array $info = []) { |
|
| 45 | + include_spip('iterateur/data'); |
|
| 46 | + $this->type = 'DATA'; |
|
| 47 | + $this->command = $command; |
|
| 48 | + $this->info = $info; |
|
| 49 | + $this->select($command); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Revenir au depart |
|
| 54 | + * |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function rewind(): void { |
|
| 58 | + reset($this->tableau); |
|
| 59 | + $this->cle = array_key_first($this->tableau); |
|
| 60 | + $this->valeur = current($this->tableau); |
|
| 61 | + next($this->tableau); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Déclarer les critères exceptions |
|
| 66 | + * |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function exception_des_criteres() { |
|
| 70 | + return ['tableau']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Récupérer depuis le cache si possible |
|
| 75 | + * |
|
| 76 | + * @param string $cle |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + protected function cache_get($cle) { |
|
| 80 | + if (!$cle) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + # utiliser memoization si dispo |
|
| 84 | + if (!function_exists('cache_get')) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return cache_get($cle); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Stocker en cache si possible |
|
| 93 | + * |
|
| 94 | + * @param string $cle |
|
| 95 | + * @param int $ttl |
|
| 96 | + * @param null|mixed $valeur |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 100 | + if (!$cle) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | + if (is_null($valeur)) { |
|
| 104 | + $valeur = $this->tableau; |
|
| 105 | + } |
|
| 106 | + # utiliser memoization si dispo |
|
| 107 | + if (!function_exists('cache_set')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return cache_set( |
|
| 112 | + $cle, |
|
| 113 | + [ |
|
| 114 | + 'data' => $valeur, |
|
| 115 | + 'time' => time(), |
|
| 116 | + 'ttl' => $ttl |
|
| 117 | + ], |
|
| 118 | + 3600 + $ttl |
|
| 119 | + ); |
|
| 120 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 121 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Aller chercher les données de la boucle DATA |
|
| 126 | + * |
|
| 127 | + * @throws Exception |
|
| 128 | + * @param array $command |
|
| 129 | + * @return void |
|
| 130 | + */ |
|
| 131 | + protected function select($command) { |
|
| 132 | + |
|
| 133 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 134 | + // le type se retrouve dans la commande 'from' |
|
| 135 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 136 | + if (isset($this->command['from'][0])) { |
|
| 137 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 138 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 139 | + } |
|
| 140 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 144 | + // les commandes connues pour l'iterateur DATA |
|
| 145 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 146 | + |
|
| 147 | + // {source format, [URL], [arg2]...} |
|
| 148 | + if ( |
|
| 149 | + isset($this->command['source']) |
|
| 150 | + and isset($this->command['sourcemode']) |
|
| 151 | + ) { |
|
| 152 | + $this->select_source(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // Critere {liste X1, X2, X3} |
|
| 156 | + if (isset($this->command['liste'])) { |
|
| 157 | + $this->select_liste(); |
|
| 158 | + } |
|
| 159 | + if (isset($this->command['enum'])) { |
|
| 160 | + $this->select_enum(); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 164 | + if (!is_array($this->tableau)) { |
|
| 165 | + $this->err = true; |
|
| 166 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // {datapath query.results} |
|
| 170 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 171 | + if ( |
|
| 172 | + !$this->err |
|
| 173 | + and isset($this->command['datapath']) |
|
| 174 | + and is_array($this->command['datapath']) |
|
| 175 | + ) { |
|
| 176 | + $this->select_datapath(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // tri {par x} |
|
| 180 | + if ($this->command['orderby']) { |
|
| 181 | + $this->select_orderby(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 185 | + if ($this->command['groupby']) { |
|
| 186 | + $this->select_groupby(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $this->rewind(); |
|
| 190 | + #var_dump($this->tableau); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Aller chercher les donnees de la boucle DATA |
|
| 196 | + * depuis une source |
|
| 197 | + * {source format, [URL], [arg2]...} |
|
| 198 | + */ |
|
| 199 | + protected function select_source() { |
|
| 200 | + # un peu crado : avant de charger le cache il faut charger |
|
| 201 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 202 | + # l'objet en cache ; cf plugins/icalendar |
|
| 203 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 204 | + if ( |
|
| 205 | + isset($this->command['sourcemode']) |
|
| 206 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 207 | + ) { |
|
| 208 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + # le premier argument peut etre un array, une URL etc. |
|
| 212 | + $src = $this->command['source'][0]; |
|
| 213 | + |
|
| 214 | + # avons-nous un cache dispo ? |
|
| 215 | + $cle = null; |
|
| 216 | + if (is_string($src)) { |
|
| 217 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $cache = $this->cache_get($cle); |
|
| 221 | + if (isset($this->command['datacache'])) { |
|
| 222 | + $ttl = intval($this->command['datacache']); |
|
| 223 | + } |
|
| 224 | + if ( |
|
| 225 | + $cache |
|
| 226 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 227 | + > time()) |
|
| 228 | + and !(_request('var_mode') === 'recalcul' |
|
| 229 | + and include_spip('inc/autoriser') |
|
| 230 | + and autoriser('recalcul') |
|
| 231 | + ) |
|
| 232 | + ) { |
|
| 233 | + $this->tableau = $cache['data']; |
|
| 234 | + } else { |
|
| 235 | + try { |
|
| 236 | + if ( |
|
| 237 | + isset($this->command['sourcemode']) |
|
| 238 | + and in_array( |
|
| 239 | + $this->command['sourcemode'], |
|
| 240 | + ['table', 'array', 'tableau'] |
|
| 241 | + ) |
|
| 242 | + ) { |
|
| 243 | + if ( |
|
| 244 | + is_array($a = $src) |
|
| 245 | + or (is_string($a) |
|
| 246 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 247 | + and is_array($a = @unserialize($a))) |
|
| 248 | + ) { |
|
| 249 | + $this->tableau = $a; |
|
| 250 | + } |
|
| 251 | + } else { |
|
| 252 | + $data = $src; |
|
| 253 | + if (is_string($src)) { |
|
| 254 | + if (tester_url_absolue($src)) { |
|
| 255 | + include_spip('inc/distant'); |
|
| 256 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 257 | + $data = $data['page'] ?? ''; |
|
| 258 | + if (!$data) { |
|
| 259 | + throw new Exception('404'); |
|
| 260 | + } |
|
| 261 | + if (!isset($ttl)) { |
|
| 262 | + $ttl = 24 * 3600; |
|
| 263 | + } |
|
| 264 | + } elseif (@is_dir($src)) { |
|
| 265 | + $data = $src; |
|
| 266 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 267 | + $data = spip_file_get_contents($src); |
|
| 268 | + } |
|
| 269 | + if (!isset($ttl)) { |
|
| 270 | + $ttl = 10; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + if ( |
|
| 274 | + !$this->err |
|
| 275 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 276 | + ) { |
|
| 277 | + $args = $this->command['source']; |
|
| 278 | + $args[0] = $data; |
|
| 279 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 280 | + $this->tableau = $a; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if (!is_array($this->tableau)) { |
|
| 286 | + $this->err = true; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 290 | + $this->cache_set($cle, $ttl); |
|
| 291 | + } |
|
| 292 | + } catch (Exception $e) { |
|
| 293 | + $e = $e->getMessage(); |
|
| 294 | + $err = sprintf( |
|
| 295 | + "[%s, %s] $e", |
|
| 296 | + $src, |
|
| 297 | + $this->command['sourcemode'] |
|
| 298 | + ); |
|
| 299 | + erreur_squelette([$err, []]); |
|
| 300 | + $this->err = true; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 305 | + if ( |
|
| 306 | + $this->err |
|
| 307 | + and $cache |
|
| 308 | + ) { |
|
| 309 | + $this->tableau = $cache['data']; |
|
| 310 | + $this->err = false; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Retourne un tableau donne depuis un critère liste |
|
| 317 | + * |
|
| 318 | + * Critère `{liste X1, X2, X3}` |
|
| 319 | + * |
|
| 320 | + * @see critere_DATA_liste_dist() |
|
| 321 | + * |
|
| 322 | + **/ |
|
| 323 | + protected function select_liste() { |
|
| 324 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 325 | + if (!isset($this->command['liste'][1])) { |
|
| 326 | + if (!is_array($this->command['liste'][0])) { |
|
| 327 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 328 | + } else { |
|
| 329 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + $this->tableau = $this->command['liste']; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Retourne un tableau donne depuis un critere liste |
|
| 337 | + * Critere {enum Xmin, Xmax} |
|
| 338 | + * |
|
| 339 | + **/ |
|
| 340 | + protected function select_enum() { |
|
| 341 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 342 | + if (!isset($this->command['enum'][1])) { |
|
| 343 | + if (!is_array($this->command['enum'][0])) { |
|
| 344 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 345 | + } else { |
|
| 346 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 350 | + $enum = range( |
|
| 351 | + array_shift($this->command['enum']), |
|
| 352 | + array_shift($this->command['enum']), |
|
| 353 | + array_shift($this->command['enum']) |
|
| 354 | + ); |
|
| 355 | + } else { |
|
| 356 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 357 | + } |
|
| 358 | + $this->tableau = $enum; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 364 | + * {datapath query.results} |
|
| 365 | + * |
|
| 366 | + **/ |
|
| 367 | + protected function select_datapath() { |
|
| 368 | + $base = reset($this->command['datapath']); |
|
| 369 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 370 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 371 | + if (!is_array($this->tableau)) { |
|
| 372 | + $this->tableau = []; |
|
| 373 | + $this->err = true; |
|
| 374 | + spip_log("datapath '$base' absent"); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Ordonner les resultats |
|
| 381 | + * {par x} |
|
| 382 | + * |
|
| 383 | + **/ |
|
| 384 | + protected function select_orderby() { |
|
| 385 | + $sortfunc = ''; |
|
| 386 | + $aleas = 0; |
|
| 387 | + foreach ($this->command['orderby'] as $tri) { |
|
| 388 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 389 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 390 | + $r = array_pad($r, 3, null); |
|
| 391 | + |
|
| 392 | + // tri par cle |
|
| 393 | + if ($r[1] == 'cle') { |
|
| 394 | + if (isset($r[2]) and $r[2]) { |
|
| 395 | + krsort($this->tableau); |
|
| 396 | + } else { |
|
| 397 | + ksort($this->tableau); |
|
| 398 | + } |
|
| 399 | + } # {par hasard} |
|
| 400 | + else { |
|
| 401 | + if ($r[1] == 'hasard') { |
|
| 402 | + $k = array_keys($this->tableau); |
|
| 403 | + shuffle($k); |
|
| 404 | + $v = []; |
|
| 405 | + foreach ($k as $cle) { |
|
| 406 | + $v[$cle] = $this->tableau[$cle]; |
|
| 407 | + } |
|
| 408 | + $this->tableau = $v; |
|
| 409 | + } else { |
|
| 410 | + # {par valeur} |
|
| 411 | + if ($r[1] == 'valeur') { |
|
| 412 | + $tv = '%s'; |
|
| 413 | + } # {par valeur/xx/yy} ?? |
|
| 414 | + else { |
|
| 415 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 416 | + } |
|
| 417 | + $sortfunc .= ' |
|
| 418 | 418 | $a = ' . sprintf($tv, '$aa') . '; |
| 419 | 419 | $b = ' . sprintf($tv, '$bb') . '; |
| 420 | 420 | if ($a <> $b) |
| 421 | 421 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if ($sortfunc) { |
|
| 428 | - $sortfunc .= "\n return 0;"; |
|
| 429 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Grouper les resultats |
|
| 436 | - * {fusion /x/y/z} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_groupby() { |
|
| 440 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 441 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 442 | - $vu = []; |
|
| 443 | - foreach ($this->tableau as $k => $v) { |
|
| 444 | - $val = table_valeur($v, $fusion); |
|
| 445 | - if (isset($vu[$val])) { |
|
| 446 | - unset($this->tableau[$k]); |
|
| 447 | - } else { |
|
| 448 | - $vu[$val] = true; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * L'iterateur est-il encore valide ? |
|
| 457 | - * |
|
| 458 | - * @return bool |
|
| 459 | - */ |
|
| 460 | - public function valid(): bool { |
|
| 461 | - return !is_null($this->cle); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Retourner la valeur |
|
| 466 | - * |
|
| 467 | - * @return mixed |
|
| 468 | - */ |
|
| 469 | - #[\ReturnTypeWillChange] |
|
| 470 | - public function current() { |
|
| 471 | - return $this->valeur; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Retourner la cle |
|
| 476 | - * |
|
| 477 | - * @return mixed |
|
| 478 | - */ |
|
| 479 | - #[\ReturnTypeWillChange] |
|
| 480 | - public function key() { |
|
| 481 | - return $this->cle; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Passer a la valeur suivante |
|
| 486 | - * |
|
| 487 | - * @return void |
|
| 488 | - */ |
|
| 489 | - public function next(): void { |
|
| 490 | - if ($this->valid()) { |
|
| 491 | - $this->cle = key($this->tableau); |
|
| 492 | - $this->valeur = current($this->tableau); |
|
| 493 | - next($this->tableau); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Compter le nombre total de resultats |
|
| 499 | - * |
|
| 500 | - * @return int |
|
| 501 | - */ |
|
| 502 | - public function count() { |
|
| 503 | - if (is_null($this->total)) { |
|
| 504 | - $this->total = count($this->tableau); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - return $this->total; |
|
| 508 | - } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if ($sortfunc) { |
|
| 428 | + $sortfunc .= "\n return 0;"; |
|
| 429 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Grouper les resultats |
|
| 436 | + * {fusion /x/y/z} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_groupby() { |
|
| 440 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 441 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 442 | + $vu = []; |
|
| 443 | + foreach ($this->tableau as $k => $v) { |
|
| 444 | + $val = table_valeur($v, $fusion); |
|
| 445 | + if (isset($vu[$val])) { |
|
| 446 | + unset($this->tableau[$k]); |
|
| 447 | + } else { |
|
| 448 | + $vu[$val] = true; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * L'iterateur est-il encore valide ? |
|
| 457 | + * |
|
| 458 | + * @return bool |
|
| 459 | + */ |
|
| 460 | + public function valid(): bool { |
|
| 461 | + return !is_null($this->cle); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Retourner la valeur |
|
| 466 | + * |
|
| 467 | + * @return mixed |
|
| 468 | + */ |
|
| 469 | + #[\ReturnTypeWillChange] |
|
| 470 | + public function current() { |
|
| 471 | + return $this->valeur; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Retourner la cle |
|
| 476 | + * |
|
| 477 | + * @return mixed |
|
| 478 | + */ |
|
| 479 | + #[\ReturnTypeWillChange] |
|
| 480 | + public function key() { |
|
| 481 | + return $this->cle; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Passer a la valeur suivante |
|
| 486 | + * |
|
| 487 | + * @return void |
|
| 488 | + */ |
|
| 489 | + public function next(): void { |
|
| 490 | + if ($this->valid()) { |
|
| 491 | + $this->cle = key($this->tableau); |
|
| 492 | + $this->valeur = current($this->tableau); |
|
| 493 | + next($this->tableau); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Compter le nombre total de resultats |
|
| 499 | + * |
|
| 500 | + * @return int |
|
| 501 | + */ |
|
| 502 | + public function count() { |
|
| 503 | + if (is_null($this->total)) { |
|
| 504 | + $this->total = count($this->tableau); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + return $this->total; |
|
| 508 | + } |
|
| 509 | 509 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_TEST_FILE_EXISTS')) { |
| 23 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 23 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 30 | 30 | |
| 31 | 31 | if (_SPIP_LOCK_MODE == 2) { |
| 32 | - include_spip('inc/nfslock'); |
|
| 32 | + include_spip('inc/nfslock'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['liste_verrous'] = []; |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | * Ressource sur le fichier ouvert, sinon false. |
| 53 | 53 | **/ |
| 54 | 54 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 55 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | - // verrou |
|
| 58 | - @flock($fl, $verrou); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $fl; |
|
| 62 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | - |
|
| 66 | - return $fl; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return @fopen($fichier, $mode); |
|
| 55 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | + // verrou |
|
| 58 | + @flock($fl, $verrou); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $fl; |
|
| 62 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | + |
|
| 66 | + return $fl; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return @fopen($fichier, $mode); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * true si succès, false sinon. |
| 85 | 85 | **/ |
| 86 | 86 | function spip_fclose_unlock($handle) { |
| 87 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | - @flock($handle, LOCK_UN); |
|
| 89 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return @fclose($handle); |
|
| 87 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | + @flock($handle, LOCK_UN); |
|
| 89 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return @fclose($handle); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -105,23 +105,23 @@ discard block |
||
| 105 | 105 | * Contenu du fichier |
| 106 | 106 | **/ |
| 107 | 107 | function spip_file_get_contents($fichier) { |
| 108 | - if (substr($fichier, -3) != '.gz') { |
|
| 109 | - if (function_exists('file_get_contents')) { |
|
| 110 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | - // sinon on fait un file() pour avoir le coeur net |
|
| 113 | - $contenu = @file_get_contents($fichier); |
|
| 114 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 115 | - $contenu = @file($fichier); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $contenu = @file($fichier); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $contenu = @gzfile($fichier); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 108 | + if (substr($fichier, -3) != '.gz') { |
|
| 109 | + if (function_exists('file_get_contents')) { |
|
| 110 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | + // sinon on fait un file() pour avoir le coeur net |
|
| 113 | + $contenu = @file_get_contents($fichier); |
|
| 114 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 115 | + $contenu = @file($fichier); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $contenu = @file($fichier); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $contenu = @gzfile($fichier); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -146,48 +146,48 @@ discard block |
||
| 146 | 146 | * true si l'opération a réussie, false sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 149 | - $contenu = ''; |
|
| 150 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - #spip_timer('lire_fichier'); |
|
| 157 | - |
|
| 158 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | - // lire le fichier avant tout |
|
| 161 | - $contenu = spip_file_get_contents($fichier); |
|
| 162 | - |
|
| 163 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | - // et eviter un acces disque |
|
| 167 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 168 | - spip_fclose_unlock($fl); |
|
| 169 | - |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // liberer le verrou |
|
| 174 | - spip_fclose_unlock($fl); |
|
| 175 | - |
|
| 176 | - // Verifications |
|
| 177 | - $ok = true; |
|
| 178 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 179 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | - if (!$ok) { |
|
| 184 | - spip_log("echec lecture $fichier"); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $ok; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return false; |
|
| 149 | + $contenu = ''; |
|
| 150 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + #spip_timer('lire_fichier'); |
|
| 157 | + |
|
| 158 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | + // lire le fichier avant tout |
|
| 161 | + $contenu = spip_file_get_contents($fichier); |
|
| 162 | + |
|
| 163 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | + // et eviter un acces disque |
|
| 167 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 168 | + spip_fclose_unlock($fl); |
|
| 169 | + |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // liberer le verrou |
|
| 174 | + spip_fclose_unlock($fl); |
|
| 175 | + |
|
| 176 | + // Verifications |
|
| 177 | + $ok = true; |
|
| 178 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 179 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | + if (!$ok) { |
|
| 184 | + spip_log("echec lecture $fichier"); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $ok; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return false; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -215,92 +215,92 @@ discard block |
||
| 215 | 215 | **/ |
| 216 | 216 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 217 | 217 | |
| 218 | - #spip_timer('ecrire_fichier'); |
|
| 219 | - |
|
| 220 | - // verrouiller le fichier destination |
|
| 221 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | - // ecrire les donnees, compressees le cas echeant |
|
| 223 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | - if (substr($fichier, -3) == '.gz') { |
|
| 226 | - $contenu = gzencode($contenu); |
|
| 227 | - } |
|
| 228 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | - // pour etre sur d'avoir une operation atomique |
|
| 230 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | - // sauf sous wintruc ou ca ne marche pas |
|
| 232 | - $ok = false; |
|
| 233 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 234 | - if (!function_exists('creer_uniqid')) { |
|
| 235 | - include_spip('inc/acces'); |
|
| 236 | - } |
|
| 237 | - $id = creer_uniqid(); |
|
| 238 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 241 | - $ok = ($s == $a); |
|
| 242 | - spip_fclose_unlock($fp2); |
|
| 243 | - spip_fclose_unlock($fp); |
|
| 244 | - $fp = null; |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - $fp = null; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - // sinon ou si methode precedente a echoueee |
|
| 266 | - // on se rabat sur la methode ancienne |
|
| 267 | - if (!$ok and !is_null($fp)) { |
|
| 268 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | - if ($truncate) { |
|
| 270 | - @ftruncate($fp, 0); |
|
| 271 | - } |
|
| 272 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | - |
|
| 274 | - $ok = ($s == $a); |
|
| 275 | - spip_fclose_unlock($fp); |
|
| 276 | - } |
|
| 277 | - // on tente une dernière fois file_put_contents |
|
| 278 | - if (!$ok) { |
|
| 279 | - $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | - $ok = ($l === strlen($contenu)); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // liberer le verrou et fermer le fichier |
|
| 284 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | - if ($ok) { |
|
| 286 | - if (strpos($fichier, '.php') !== false) { |
|
| 287 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return $ok; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!$ignorer_echec) { |
|
| 295 | - include_spip('inc/autoriser'); |
|
| 296 | - if (autoriser('chargerftp')) { |
|
| 297 | - raler_fichier($fichier); |
|
| 298 | - } |
|
| 299 | - spip_unlink($fichier); |
|
| 300 | - } |
|
| 301 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | - |
|
| 303 | - return false; |
|
| 218 | + #spip_timer('ecrire_fichier'); |
|
| 219 | + |
|
| 220 | + // verrouiller le fichier destination |
|
| 221 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | + // ecrire les donnees, compressees le cas echeant |
|
| 223 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | + if (substr($fichier, -3) == '.gz') { |
|
| 226 | + $contenu = gzencode($contenu); |
|
| 227 | + } |
|
| 228 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | + // pour etre sur d'avoir une operation atomique |
|
| 230 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | + // sauf sous wintruc ou ca ne marche pas |
|
| 232 | + $ok = false; |
|
| 233 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 234 | + if (!function_exists('creer_uniqid')) { |
|
| 235 | + include_spip('inc/acces'); |
|
| 236 | + } |
|
| 237 | + $id = creer_uniqid(); |
|
| 238 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 241 | + $ok = ($s == $a); |
|
| 242 | + spip_fclose_unlock($fp2); |
|
| 243 | + spip_fclose_unlock($fp); |
|
| 244 | + $fp = null; |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + $fp = null; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + // sinon ou si methode precedente a echoueee |
|
| 266 | + // on se rabat sur la methode ancienne |
|
| 267 | + if (!$ok and !is_null($fp)) { |
|
| 268 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | + if ($truncate) { |
|
| 270 | + @ftruncate($fp, 0); |
|
| 271 | + } |
|
| 272 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | + |
|
| 274 | + $ok = ($s == $a); |
|
| 275 | + spip_fclose_unlock($fp); |
|
| 276 | + } |
|
| 277 | + // on tente une dernière fois file_put_contents |
|
| 278 | + if (!$ok) { |
|
| 279 | + $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | + $ok = ($l === strlen($contenu)); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // liberer le verrou et fermer le fichier |
|
| 284 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | + if ($ok) { |
|
| 286 | + if (strpos($fichier, '.php') !== false) { |
|
| 287 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return $ok; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!$ignorer_echec) { |
|
| 295 | + include_spip('inc/autoriser'); |
|
| 296 | + if (autoriser('chargerftp')) { |
|
| 297 | + raler_fichier($fichier); |
|
| 298 | + } |
|
| 299 | + spip_unlink($fichier); |
|
| 300 | + } |
|
| 301 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | + |
|
| 303 | + return false; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -320,12 +320,12 @@ discard block |
||
| 320 | 320 | * Écriture avec troncation ? |
| 321 | 321 | */ |
| 322 | 322 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 323 | - if (substr($fichier, -4) !== '.php') { |
|
| 324 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | - } |
|
| 326 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 323 | + if (substr($fichier, -4) !== '.php') { |
|
| 324 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | + } |
|
| 326 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 327 | 327 | |
| 328 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 328 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -336,25 +336,25 @@ discard block |
||
| 336 | 336 | * @return bool |
| 337 | 337 | */ |
| 338 | 338 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 339 | - $fichier_tmp = $fichier . '.last'; |
|
| 340 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - if ( |
|
| 344 | - $force |
|
| 345 | - or !file_exists($fichier) |
|
| 346 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 347 | - ) { |
|
| 348 | - if ($use_copy) { |
|
| 349 | - @copy($fichier_tmp, $fichier); |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - @rename($fichier_tmp, $fichier); |
|
| 353 | - } |
|
| 354 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | - clearstatcache(true, $fichier); |
|
| 356 | - } |
|
| 357 | - return true; |
|
| 339 | + $fichier_tmp = $fichier . '.last'; |
|
| 340 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + if ( |
|
| 344 | + $force |
|
| 345 | + or !file_exists($fichier) |
|
| 346 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 347 | + ) { |
|
| 348 | + if ($use_copy) { |
|
| 349 | + @copy($fichier_tmp, $fichier); |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + @rename($fichier_tmp, $fichier); |
|
| 353 | + } |
|
| 354 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | + clearstatcache(true, $fichier); |
|
| 356 | + } |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | |
@@ -375,11 +375,11 @@ discard block |
||
| 375 | 375 | * true si l'opération a réussie, false sinon. |
| 376 | 376 | */ |
| 377 | 377 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 378 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 380 | - } |
|
| 378 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - return $res; |
|
| 382 | + return $res; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -394,25 +394,25 @@ discard block |
||
| 394 | 394 | * Chemin du fichier |
| 395 | 395 | **/ |
| 396 | 396 | function raler_fichier($fichier) { |
| 397 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 398 | - spip_initialisation_suite(); |
|
| 399 | - } |
|
| 400 | - include_spip('inc/minipres'); |
|
| 401 | - $dir = dirname($fichier); |
|
| 402 | - http_response_code(401); |
|
| 403 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 404 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 405 | - . " <a href='" |
|
| 406 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 407 | - . "'>" |
|
| 408 | - . _T('texte_inc_meta_2') |
|
| 409 | - . '</a> ' |
|
| 410 | - . _T( |
|
| 411 | - 'texte_inc_meta_3', |
|
| 412 | - ['repertoire' => joli_repertoire($dir)] |
|
| 413 | - ) |
|
| 414 | - . "</h4>\n"); |
|
| 415 | - exit; |
|
| 397 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 398 | + spip_initialisation_suite(); |
|
| 399 | + } |
|
| 400 | + include_spip('inc/minipres'); |
|
| 401 | + $dir = dirname($fichier); |
|
| 402 | + http_response_code(401); |
|
| 403 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 404 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 405 | + . " <a href='" |
|
| 406 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 407 | + . "'>" |
|
| 408 | + . _T('texte_inc_meta_2') |
|
| 409 | + . '</a> ' |
|
| 410 | + . _T( |
|
| 411 | + 'texte_inc_meta_3', |
|
| 412 | + ['repertoire' => joli_repertoire($dir)] |
|
| 413 | + ) |
|
| 414 | + . "</h4>\n"); |
|
| 415 | + exit; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -427,14 +427,14 @@ discard block |
||
| 427 | 427 | * - true si récent, false sinon |
| 428 | 428 | */ |
| 429 | 429 | function jeune_fichier($fichier, $n) { |
| 430 | - if (!file_exists($fichier)) { |
|
| 431 | - return false; |
|
| 432 | - } |
|
| 433 | - if (!$c = @filemtime($fichier)) { |
|
| 434 | - return false; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - return (time() - $n <= $c); |
|
| 430 | + if (!file_exists($fichier)) { |
|
| 431 | + return false; |
|
| 432 | + } |
|
| 433 | + if (!$c = @filemtime($fichier)) { |
|
| 434 | + return false; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + return (time() - $n <= $c); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -449,22 +449,22 @@ discard block |
||
| 449 | 449 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 450 | 450 | */ |
| 451 | 451 | function supprimer_fichier($fichier, $lock = true) { |
| 452 | - if (!@file_exists($fichier)) { |
|
| 453 | - return true; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if ($lock) { |
|
| 457 | - // verrouiller le fichier destination |
|
| 458 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - // liberer le verrou |
|
| 463 | - spip_fclose_unlock($fp); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - // supprimer |
|
| 467 | - return @unlink($fichier); |
|
| 452 | + if (!@file_exists($fichier)) { |
|
| 453 | + return true; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if ($lock) { |
|
| 457 | + // verrouiller le fichier destination |
|
| 458 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + // liberer le verrou |
|
| 463 | + spip_fclose_unlock($fp); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + // supprimer |
|
| 467 | + return @unlink($fichier); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -474,12 +474,12 @@ discard block |
||
| 474 | 474 | * Chemin du fichier |
| 475 | 475 | */ |
| 476 | 476 | function spip_unlink($f) { |
| 477 | - if (!is_dir($f)) { |
|
| 478 | - supprimer_fichier($f, false); |
|
| 479 | - } else { |
|
| 480 | - @unlink("$f/.ok"); |
|
| 481 | - @rmdir($f); |
|
| 482 | - } |
|
| 477 | + if (!is_dir($f)) { |
|
| 478 | + supprimer_fichier($f, false); |
|
| 479 | + } else { |
|
| 480 | + @unlink("$f/.ok"); |
|
| 481 | + @rmdir($f); |
|
| 482 | + } |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -493,26 +493,26 @@ discard block |
||
| 493 | 493 | * The absolute path of the PHP file to invalidate. |
| 494 | 494 | */ |
| 495 | 495 | function spip_clear_opcode_cache($filepath) { |
| 496 | - clearstatcache(true, $filepath); |
|
| 497 | - |
|
| 498 | - // Zend OPcache |
|
| 499 | - if (function_exists('opcache_invalidate')) { |
|
| 500 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 501 | - // si l'invalidation a echoue lever un flag |
|
| 502 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 503 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 504 | - } |
|
| 505 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 506 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 507 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 508 | - } |
|
| 509 | - // APC. |
|
| 510 | - if (function_exists('apc_delete_file')) { |
|
| 511 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 512 | - // not compiled yet. |
|
| 513 | - // @see http://php.net/apc-delete-file |
|
| 514 | - @apc_delete_file($filepath); |
|
| 515 | - } |
|
| 496 | + clearstatcache(true, $filepath); |
|
| 497 | + |
|
| 498 | + // Zend OPcache |
|
| 499 | + if (function_exists('opcache_invalidate')) { |
|
| 500 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 501 | + // si l'invalidation a echoue lever un flag |
|
| 502 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 503 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 504 | + } |
|
| 505 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 506 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 507 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 508 | + } |
|
| 509 | + // APC. |
|
| 510 | + if (function_exists('apc_delete_file')) { |
|
| 511 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 512 | + // not compiled yet. |
|
| 513 | + // @see http://php.net/apc-delete-file |
|
| 514 | + @apc_delete_file($filepath); |
|
| 515 | + } |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,25 +535,25 @@ discard block |
||
| 535 | 535 | * |
| 536 | 536 | */ |
| 537 | 537 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 538 | - if ( |
|
| 539 | - function_exists('opcache_get_configuration') |
|
| 540 | - and @ini_get('opcache.enable') |
|
| 541 | - and @ini_get('opcache.validate_timestamps') |
|
| 542 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 543 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 544 | - ) { |
|
| 545 | - $wait = $duree + 1; |
|
| 546 | - if ($timestamp) { |
|
| 547 | - $wait -= (time() - $timestamp); |
|
| 548 | - if ($wait < 0) { |
|
| 549 | - $wait = 0; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 553 | - if ($wait) { |
|
| 554 | - sleep($duree + 1); |
|
| 555 | - } |
|
| 556 | - } |
|
| 538 | + if ( |
|
| 539 | + function_exists('opcache_get_configuration') |
|
| 540 | + and @ini_get('opcache.enable') |
|
| 541 | + and @ini_get('opcache.validate_timestamps') |
|
| 542 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 543 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 544 | + ) { |
|
| 545 | + $wait = $duree + 1; |
|
| 546 | + if ($timestamp) { |
|
| 547 | + $wait -= (time() - $timestamp); |
|
| 548 | + if ($wait < 0) { |
|
| 549 | + $wait = 0; |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 553 | + if ($wait) { |
|
| 554 | + sleep($duree + 1); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | |
@@ -566,26 +566,26 @@ discard block |
||
| 566 | 566 | * @return bool Suppression reussie. |
| 567 | 567 | */ |
| 568 | 568 | function supprimer_repertoire($dir) { |
| 569 | - if (!file_exists($dir)) { |
|
| 570 | - return true; |
|
| 571 | - } |
|
| 572 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 573 | - return @unlink($dir); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - foreach (scandir($dir) as $item) { |
|
| 577 | - if ($item == '.' || $item == '..') { |
|
| 578 | - continue; |
|
| 579 | - } |
|
| 580 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | - @chmod($dir . '/' . $item, 0777); |
|
| 582 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 583 | - return false; |
|
| 584 | - } |
|
| 585 | - }; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - return @rmdir($dir); |
|
| 569 | + if (!file_exists($dir)) { |
|
| 570 | + return true; |
|
| 571 | + } |
|
| 572 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 573 | + return @unlink($dir); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + foreach (scandir($dir) as $item) { |
|
| 577 | + if ($item == '.' || $item == '..') { |
|
| 578 | + continue; |
|
| 579 | + } |
|
| 580 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | + @chmod($dir . '/' . $item, 0777); |
|
| 582 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 585 | + }; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + return @rmdir($dir); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | |
@@ -614,57 +614,57 @@ discard block |
||
| 614 | 614 | * Chemin du répertoire créé. |
| 615 | 615 | **/ |
| 616 | 616 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 617 | - static $dirs = []; |
|
| 618 | - |
|
| 619 | - $base = str_replace('//', '/', $base); |
|
| 620 | - |
|
| 621 | - # suppr le dernier caractere si c'est un / |
|
| 622 | - $base = rtrim($base, '/'); |
|
| 623 | - |
|
| 624 | - if (!strlen($subdir)) { |
|
| 625 | - $n = strrpos($base, '/'); |
|
| 626 | - if ($n === false) { |
|
| 627 | - return $nobase ? '' : ($base . '/'); |
|
| 628 | - } |
|
| 629 | - $subdir = substr($base, $n + 1); |
|
| 630 | - $base = substr($base, 0, $n + 1); |
|
| 631 | - } else { |
|
| 632 | - $base .= '/'; |
|
| 633 | - $subdir = str_replace('/', '', $subdir); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - $baseaff = $nobase ? '' : $base; |
|
| 637 | - if (isset($dirs[$base . $subdir])) { |
|
| 638 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 642 | - |
|
| 643 | - if (file_exists("$path/.ok")) { |
|
| 644 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - @mkdir($path, _SPIP_CHMOD); |
|
| 648 | - @chmod($path, _SPIP_CHMOD); |
|
| 649 | - |
|
| 650 | - if (is_dir($path) && is_writable($path)) { |
|
| 651 | - @touch("$path/.ok"); |
|
| 652 | - spip_log("creation $base$subdir/"); |
|
| 653 | - |
|
| 654 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 658 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 659 | - spip_log("echec creation $base{$subdir}"); |
|
| 660 | - if ($tantpis) { |
|
| 661 | - return ''; |
|
| 662 | - } |
|
| 663 | - if (!_DIR_RESTREINT) { |
|
| 664 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 665 | - } |
|
| 666 | - $base .= $subdir; |
|
| 667 | - raler_fichier($base . '/.ok'); |
|
| 617 | + static $dirs = []; |
|
| 618 | + |
|
| 619 | + $base = str_replace('//', '/', $base); |
|
| 620 | + |
|
| 621 | + # suppr le dernier caractere si c'est un / |
|
| 622 | + $base = rtrim($base, '/'); |
|
| 623 | + |
|
| 624 | + if (!strlen($subdir)) { |
|
| 625 | + $n = strrpos($base, '/'); |
|
| 626 | + if ($n === false) { |
|
| 627 | + return $nobase ? '' : ($base . '/'); |
|
| 628 | + } |
|
| 629 | + $subdir = substr($base, $n + 1); |
|
| 630 | + $base = substr($base, 0, $n + 1); |
|
| 631 | + } else { |
|
| 632 | + $base .= '/'; |
|
| 633 | + $subdir = str_replace('/', '', $subdir); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + $baseaff = $nobase ? '' : $base; |
|
| 637 | + if (isset($dirs[$base . $subdir])) { |
|
| 638 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 642 | + |
|
| 643 | + if (file_exists("$path/.ok")) { |
|
| 644 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + @mkdir($path, _SPIP_CHMOD); |
|
| 648 | + @chmod($path, _SPIP_CHMOD); |
|
| 649 | + |
|
| 650 | + if (is_dir($path) && is_writable($path)) { |
|
| 651 | + @touch("$path/.ok"); |
|
| 652 | + spip_log("creation $base$subdir/"); |
|
| 653 | + |
|
| 654 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 658 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 659 | + spip_log("echec creation $base{$subdir}"); |
|
| 660 | + if ($tantpis) { |
|
| 661 | + return ''; |
|
| 662 | + } |
|
| 663 | + if (!_DIR_RESTREINT) { |
|
| 664 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 665 | + } |
|
| 666 | + $base .= $subdir; |
|
| 667 | + raler_fichier($base . '/.ok'); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | |
@@ -697,56 +697,56 @@ discard block |
||
| 697 | 697 | * Chemins des fichiers trouvés. |
| 698 | 698 | **/ |
| 699 | 699 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 700 | - $nbfiles = 0; |
|
| 701 | - if ($pattern == -1) { |
|
| 702 | - $pattern = ''; |
|
| 703 | - } |
|
| 704 | - $fichiers = []; |
|
| 705 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 706 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 707 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 708 | - if ($dir == '') { |
|
| 709 | - $dir = '.'; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 713 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 714 | - if ( |
|
| 715 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 716 | - and $f != 'CVS' |
|
| 717 | - and $f != 'remove.txt' |
|
| 718 | - and is_readable($f = "$dir/$f") |
|
| 719 | - ) { |
|
| 720 | - if (is_file($f)) { |
|
| 721 | - if (!$pattern or preg_match(";$pattern;iS", $f)) { |
|
| 722 | - $fichiers[] = $f; |
|
| 723 | - $nbfiles++; |
|
| 724 | - } |
|
| 725 | - } else { |
|
| 726 | - if (is_dir($f) and is_array($recurs)) { |
|
| 727 | - $rp = @realpath($f); |
|
| 728 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 729 | - $rp = $f; |
|
| 730 | - } # realpath n'est peut etre pas autorise |
|
| 731 | - if (!isset($recurs[$rp])) { |
|
| 732 | - $recurs[$rp] = true; |
|
| 733 | - $beginning = $fichiers; |
|
| 734 | - $end = preg_files( |
|
| 735 | - "$f/", |
|
| 736 | - $pattern, |
|
| 737 | - $maxfiles - $nbfiles, |
|
| 738 | - $recurs |
|
| 739 | - ); |
|
| 740 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 741 | - $nbfiles = count($fichiers); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - closedir($d); |
|
| 748 | - } |
|
| 749 | - sort($fichiers); |
|
| 750 | - |
|
| 751 | - return $fichiers; |
|
| 700 | + $nbfiles = 0; |
|
| 701 | + if ($pattern == -1) { |
|
| 702 | + $pattern = ''; |
|
| 703 | + } |
|
| 704 | + $fichiers = []; |
|
| 705 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 706 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 707 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 708 | + if ($dir == '') { |
|
| 709 | + $dir = '.'; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 713 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 714 | + if ( |
|
| 715 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 716 | + and $f != 'CVS' |
|
| 717 | + and $f != 'remove.txt' |
|
| 718 | + and is_readable($f = "$dir/$f") |
|
| 719 | + ) { |
|
| 720 | + if (is_file($f)) { |
|
| 721 | + if (!$pattern or preg_match(";$pattern;iS", $f)) { |
|
| 722 | + $fichiers[] = $f; |
|
| 723 | + $nbfiles++; |
|
| 724 | + } |
|
| 725 | + } else { |
|
| 726 | + if (is_dir($f) and is_array($recurs)) { |
|
| 727 | + $rp = @realpath($f); |
|
| 728 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 729 | + $rp = $f; |
|
| 730 | + } # realpath n'est peut etre pas autorise |
|
| 731 | + if (!isset($recurs[$rp])) { |
|
| 732 | + $recurs[$rp] = true; |
|
| 733 | + $beginning = $fichiers; |
|
| 734 | + $end = preg_files( |
|
| 735 | + "$f/", |
|
| 736 | + $pattern, |
|
| 737 | + $maxfiles - $nbfiles, |
|
| 738 | + $recurs |
|
| 739 | + ); |
|
| 740 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 741 | + $nbfiles = count($fichiers); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + closedir($d); |
|
| 748 | + } |
|
| 749 | + sort($fichiers); |
|
| 750 | + |
|
| 751 | + return $fichiers; |
|
| 752 | 752 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres'); // par precaution |
| 23 | 23 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -37,21 +37,21 @@ discard block |
||
| 37 | 37 | * Le code de la couleur en hexadécimal. |
| 38 | 38 | */ |
| 39 | 39 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 40 | - $red = dechex($red); |
|
| 41 | - $green = dechex($green); |
|
| 42 | - $blue = dechex($blue); |
|
| 43 | - |
|
| 44 | - if (strlen($red) == 1) { |
|
| 45 | - $red = '0' . $red; |
|
| 46 | - } |
|
| 47 | - if (strlen($green) == 1) { |
|
| 48 | - $green = '0' . $green; |
|
| 49 | - } |
|
| 50 | - if (strlen($blue) == 1) { |
|
| 51 | - $blue = '0' . $blue; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return "$red$green$blue"; |
|
| 40 | + $red = dechex($red); |
|
| 41 | + $green = dechex($green); |
|
| 42 | + $blue = dechex($blue); |
|
| 43 | + |
|
| 44 | + if (strlen($red) == 1) { |
|
| 45 | + $red = '0' . $red; |
|
| 46 | + } |
|
| 47 | + if (strlen($green) == 1) { |
|
| 48 | + $green = '0' . $green; |
|
| 49 | + } |
|
| 50 | + if (strlen($blue) == 1) { |
|
| 51 | + $blue = '0' . $blue; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return "$red$green$blue"; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -63,18 +63,18 @@ discard block |
||
| 63 | 63 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 64 | 64 | */ |
| 65 | 65 | function _couleur_hex_to_dec($couleur) { |
| 66 | - $couleur ??= ''; |
|
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 66 | + $couleur ??= ''; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,59 +120,59 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $H = null; |
|
| 124 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | - $var_G = ($G / 255); |
|
| 126 | - $var_B = ($B / 255); |
|
| 127 | - |
|
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | - |
|
| 132 | - $L = ($var_Max + $var_Min) / 2; |
|
| 133 | - |
|
| 134 | - if ($del_Max == 0) { |
|
| 135 | - //This is a gray, no chroma... |
|
| 136 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | - $S = 0; |
|
| 138 | - } else { |
|
| 139 | - // Chromatic data... |
|
| 140 | - if ($L < 0.5) { |
|
| 141 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | - } else { |
|
| 143 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - |
|
| 150 | - if ($var_R == $var_Max) { |
|
| 151 | - $H = $del_B - $del_G; |
|
| 152 | - } else { |
|
| 153 | - if ($var_G == $var_Max) { |
|
| 154 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | - } else { |
|
| 156 | - if ($var_B == $var_Max) { |
|
| 157 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if ($H < 0) { |
|
| 163 | - $H += 1; |
|
| 164 | - } |
|
| 165 | - if ($H > 1) { |
|
| 166 | - $H -= 1; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ret = []; |
|
| 171 | - $ret['h'] = $H; |
|
| 172 | - $ret['s'] = $S; |
|
| 173 | - $ret['l'] = $L; |
|
| 174 | - |
|
| 175 | - return $ret; |
|
| 123 | + $H = null; |
|
| 124 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | + $var_G = ($G / 255); |
|
| 126 | + $var_B = ($B / 255); |
|
| 127 | + |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | + |
|
| 132 | + $L = ($var_Max + $var_Min) / 2; |
|
| 133 | + |
|
| 134 | + if ($del_Max == 0) { |
|
| 135 | + //This is a gray, no chroma... |
|
| 136 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | + $S = 0; |
|
| 138 | + } else { |
|
| 139 | + // Chromatic data... |
|
| 140 | + if ($L < 0.5) { |
|
| 141 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | + } else { |
|
| 143 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + |
|
| 150 | + if ($var_R == $var_Max) { |
|
| 151 | + $H = $del_B - $del_G; |
|
| 152 | + } else { |
|
| 153 | + if ($var_G == $var_Max) { |
|
| 154 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | + } else { |
|
| 156 | + if ($var_B == $var_Max) { |
|
| 157 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if ($H < 0) { |
|
| 163 | + $H += 1; |
|
| 164 | + } |
|
| 165 | + if ($H > 1) { |
|
| 166 | + $H -= 1; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ret = []; |
|
| 171 | + $ret['h'] = $H; |
|
| 172 | + $ret['s'] = $S; |
|
| 173 | + $ret['l'] = $L; |
|
| 174 | + |
|
| 175 | + return $ret; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -188,52 +188,52 @@ discard block |
||
| 188 | 188 | * @return array |
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | - // helper |
|
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | - if ($vH < 0) { |
|
| 194 | - $vH += 1; |
|
| 195 | - } |
|
| 196 | - if ($vH > 1) { |
|
| 197 | - $vH -= 1; |
|
| 198 | - } |
|
| 199 | - if ((6 * $vH) < 1) { |
|
| 200 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | - } |
|
| 202 | - if ((2 * $vH) < 1) { |
|
| 203 | - return ($v2); |
|
| 204 | - } |
|
| 205 | - if ((3 * $vH) < 2) { |
|
| 206 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return ($v1); |
|
| 210 | - }; |
|
| 211 | - |
|
| 212 | - if ($S == 0) { |
|
| 213 | - // HSV values = 0 -> 1 |
|
| 214 | - $R = $L * 255; |
|
| 215 | - $G = $L * 255; |
|
| 216 | - $B = $L * 255; |
|
| 217 | - } else { |
|
| 218 | - if ($L < 0.5) { |
|
| 219 | - $var_2 = $L * (1 + $S); |
|
| 220 | - } else { |
|
| 221 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $var_1 = 2 * $L - $var_2; |
|
| 225 | - |
|
| 226 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $ret = []; |
|
| 232 | - $ret['r'] = floor($R); |
|
| 233 | - $ret['g'] = floor($G); |
|
| 234 | - $ret['b'] = floor($B); |
|
| 235 | - |
|
| 236 | - return $ret; |
|
| 191 | + // helper |
|
| 192 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | + if ($vH < 0) { |
|
| 194 | + $vH += 1; |
|
| 195 | + } |
|
| 196 | + if ($vH > 1) { |
|
| 197 | + $vH -= 1; |
|
| 198 | + } |
|
| 199 | + if ((6 * $vH) < 1) { |
|
| 200 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | + } |
|
| 202 | + if ((2 * $vH) < 1) { |
|
| 203 | + return ($v2); |
|
| 204 | + } |
|
| 205 | + if ((3 * $vH) < 2) { |
|
| 206 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return ($v1); |
|
| 210 | + }; |
|
| 211 | + |
|
| 212 | + if ($S == 0) { |
|
| 213 | + // HSV values = 0 -> 1 |
|
| 214 | + $R = $L * 255; |
|
| 215 | + $G = $L * 255; |
|
| 216 | + $B = $L * 255; |
|
| 217 | + } else { |
|
| 218 | + if ($L < 0.5) { |
|
| 219 | + $var_2 = $L * (1 + $S); |
|
| 220 | + } else { |
|
| 221 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $var_1 = 2 * $L - $var_2; |
|
| 225 | + |
|
| 226 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $ret = []; |
|
| 232 | + $ret['r'] = floor($R); |
|
| 233 | + $ret['g'] = floor($G); |
|
| 234 | + $ret['b'] = floor($B); |
|
| 235 | + |
|
| 236 | + return $ret; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 252 | 252 | */ |
| 253 | 253 | function statut_effacer_images_temporaires($stat) { |
| 254 | - static $statut = false; // par defaut on grave toute les images |
|
| 255 | - if ($stat === 'get') { |
|
| 256 | - return $statut; |
|
| 257 | - } |
|
| 258 | - $statut = $stat ? true : false; |
|
| 254 | + static $statut = false; // par defaut on grave toute les images |
|
| 255 | + if ($stat === 'get') { |
|
| 256 | + return $statut; |
|
| 257 | + } |
|
| 258 | + $statut = $stat ? true : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -308,247 +308,247 @@ discard block |
||
| 308 | 308 | * - array : tableau décrivant de l'image |
| 309 | 309 | */ |
| 310 | 310 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 311 | - $ret = []; |
|
| 312 | - $f = null; |
|
| 313 | - static $images_recalcul = []; |
|
| 314 | - if (strlen($img) == 0) { |
|
| 315 | - return false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | - if (strlen($source) < 1) { |
|
| 320 | - $source = $img; |
|
| 321 | - $img = "<img src='$source' />"; |
|
| 322 | - } elseif ( |
|
| 323 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | - ) { |
|
| 327 | - # gerer img src="data:....base64" |
|
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | - if (!file_exists($local)) { |
|
| 330 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | - } |
|
| 332 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | - $sanitizer($local); |
|
| 334 | - } |
|
| 335 | - $source = $local; |
|
| 336 | - $img = inserer_attribut($img, 'src', $source); |
|
| 337 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | - $img = inserer_attribut($img, 'width', ''); |
|
| 339 | - $img = inserer_attribut($img, 'height', ''); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // les protocoles web prennent au moins 3 lettres |
|
| 343 | - if (tester_url_absolue($source)) { |
|
| 344 | - include_spip('inc/distant'); |
|
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | - if (!$fichier) { |
|
| 347 | - return ''; |
|
| 348 | - } |
|
| 349 | - if ( |
|
| 350 | - $extension = _image_trouver_extension($fichier) |
|
| 351 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | - ) { |
|
| 353 | - $sanitizer($fichier); |
|
| 354 | - } |
|
| 355 | - } else { |
|
| 356 | - // enlever le timestamp eventuel |
|
| 357 | - if (strpos($source, '?') !== false) { |
|
| 358 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | - } |
|
| 360 | - if ( |
|
| 361 | - strpos($source, '?') !== false |
|
| 362 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | - ) { |
|
| 365 | - $source = $f; |
|
| 366 | - } |
|
| 367 | - $fichier = $source; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $terminaison_dest = ''; |
|
| 371 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ( |
|
| 376 | - $forcer_format !== false |
|
| 377 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | - ) { |
|
| 380 | - $terminaison_dest = $forcer_format; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - if (!$terminaison_dest) { |
|
| 384 | - return false; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | - $fichier_dest = $nom_fichier; |
|
| 389 | - if ( |
|
| 390 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | - or @file_exists($f = $fichier) |
|
| 392 | - ) { |
|
| 393 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | - // au lieu de faire un acces disque sur le fichier |
|
| 395 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | - $date_src = @filemtime($f); |
|
| 397 | - } elseif ( |
|
| 398 | - @file_exists($f = "$fichier.src") |
|
| 399 | - and lire_fichier($f, $valeurs) |
|
| 400 | - and $valeurs = unserialize($valeurs) |
|
| 401 | - and isset($valeurs['hauteur_dest']) |
|
| 402 | - and isset($valeurs['largeur_dest']) |
|
| 403 | - ) { |
|
| 404 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | - $date_src = $valeurs['date']; |
|
| 407 | - } // pas de fichier source par la |
|
| 408 | - else { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - // pas de taille mesurable ? |
|
| 413 | - if (!$ret['hauteur'] |
|
| 414 | - or !($ret['hauteur'] = intval(round($ret['hauteur']))) |
|
| 415 | - or !$ret['largeur'] |
|
| 416 | - or !($ret['largeur'] = intval(round($ret['largeur']))) |
|
| 417 | - ) { |
|
| 418 | - return false; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - // les images calculees dependent du chemin du fichier source |
|
| 422 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 423 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 424 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 425 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 426 | - // alors que ca concerne peu de site au final |
|
| 427 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 428 | - $identifiant = $fichier; |
|
| 429 | - |
|
| 430 | - // cas general : |
|
| 431 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 432 | - // cas particulier de reduire : |
|
| 433 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 434 | - $cache = 'cache-gd2'; |
|
| 435 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 436 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 437 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 438 | - $ret['largeur_dest'] = $destWidth; |
|
| 439 | - $ret['hauteur_dest'] = $destHeight; |
|
| 440 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 441 | - $cache = 'cache-vignettes'; |
|
| 442 | - $fichier_dest = basename($fichier_dest); |
|
| 443 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 444 | - // on garde la terminaison initiale car image simplement copiee |
|
| 445 | - // et on postfixe son nom avec un md5 du path |
|
| 446 | - $terminaison_dest = $terminaison; |
|
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 448 | - } else { |
|
| 449 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 450 | - } |
|
| 451 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | - $cache = sous_repertoire($cache, $effet); |
|
| 453 | - } else { |
|
| 454 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 455 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 456 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 457 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 461 | - |
|
| 462 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 463 | - |
|
| 464 | - $creer = true; |
|
| 465 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 466 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 467 | - $images_recalcul[$fichier_dest] = true; |
|
| 468 | - } else { |
|
| 469 | - if (@file_exists($f = $fichier_dest)) { |
|
| 470 | - if (filemtime($f) >= $date_src) { |
|
| 471 | - $creer = false; |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - if ( |
|
| 475 | - @file_exists($f = "$fichier_dest.src") |
|
| 476 | - and lire_fichier($f, $valeurs) |
|
| 477 | - and $valeurs = unserialize($valeurs) |
|
| 478 | - and $valeurs['date'] >= $date_src |
|
| 479 | - ) { |
|
| 480 | - $creer = false; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - if ($creer) { |
|
| 485 | - if (!@file_exists($fichier)) { |
|
| 486 | - if (!@file_exists("$fichier.src")) { |
|
| 487 | - spip_log("Image absente : $fichier"); |
|
| 488 | - |
|
| 489 | - return false; |
|
| 490 | - } |
|
| 491 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 492 | - reconstruire_image_intermediaire($fichier); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if ($creer) { |
|
| 497 | - spip_log( |
|
| 498 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 499 | - 'images' . _LOG_DEBUG |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 504 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 505 | - $ret['fichier'] = $fichier; |
|
| 506 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 507 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 508 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 509 | - $ret['format_dest'] = $terminaison_dest; |
|
| 510 | - $ret['date_src'] = $date_src; |
|
| 511 | - $ret['creer'] = $creer; |
|
| 512 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 513 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 514 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 515 | - $ret['tag'] = $img; |
|
| 516 | - if ($fonction_creation) { |
|
| 517 | - $ret['reconstruction'] = $fonction_creation; |
|
| 518 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 519 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 520 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 521 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 525 | - 'args' => [ |
|
| 526 | - 'img' => $img, |
|
| 527 | - 'effet' => $effet, |
|
| 528 | - 'forcer_format' => $forcer_format, |
|
| 529 | - 'fonction_creation' => $fonction_creation, |
|
| 530 | - 'find_in_path' => $find_in_path, |
|
| 531 | - ], |
|
| 532 | - 'data' => $ret |
|
| 533 | - ]); |
|
| 534 | - |
|
| 535 | - // une globale pour le debug en cas de crash memoire |
|
| 536 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 537 | - |
|
| 538 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 539 | - if ($term_fonction === 'svg') { |
|
| 540 | - if ($creer and !$support_svg) { |
|
| 541 | - process_image_svg_identite($ret); |
|
| 542 | - $ret['creer'] = false; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - else { |
|
| 546 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - return $ret; |
|
| 311 | + $ret = []; |
|
| 312 | + $f = null; |
|
| 313 | + static $images_recalcul = []; |
|
| 314 | + if (strlen($img) == 0) { |
|
| 315 | + return false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | + if (strlen($source) < 1) { |
|
| 320 | + $source = $img; |
|
| 321 | + $img = "<img src='$source' />"; |
|
| 322 | + } elseif ( |
|
| 323 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | + ) { |
|
| 327 | + # gerer img src="data:....base64" |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | + if (!file_exists($local)) { |
|
| 330 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | + } |
|
| 332 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | + $sanitizer($local); |
|
| 334 | + } |
|
| 335 | + $source = $local; |
|
| 336 | + $img = inserer_attribut($img, 'src', $source); |
|
| 337 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | + $img = inserer_attribut($img, 'width', ''); |
|
| 339 | + $img = inserer_attribut($img, 'height', ''); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // les protocoles web prennent au moins 3 lettres |
|
| 343 | + if (tester_url_absolue($source)) { |
|
| 344 | + include_spip('inc/distant'); |
|
| 345 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | + if (!$fichier) { |
|
| 347 | + return ''; |
|
| 348 | + } |
|
| 349 | + if ( |
|
| 350 | + $extension = _image_trouver_extension($fichier) |
|
| 351 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | + ) { |
|
| 353 | + $sanitizer($fichier); |
|
| 354 | + } |
|
| 355 | + } else { |
|
| 356 | + // enlever le timestamp eventuel |
|
| 357 | + if (strpos($source, '?') !== false) { |
|
| 358 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | + } |
|
| 360 | + if ( |
|
| 361 | + strpos($source, '?') !== false |
|
| 362 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | + ) { |
|
| 365 | + $source = $f; |
|
| 366 | + } |
|
| 367 | + $fichier = $source; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $terminaison_dest = ''; |
|
| 371 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ( |
|
| 376 | + $forcer_format !== false |
|
| 377 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | + ) { |
|
| 380 | + $terminaison_dest = $forcer_format; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + if (!$terminaison_dest) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | + $fichier_dest = $nom_fichier; |
|
| 389 | + if ( |
|
| 390 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | + or @file_exists($f = $fichier) |
|
| 392 | + ) { |
|
| 393 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | + // au lieu de faire un acces disque sur le fichier |
|
| 395 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | + $date_src = @filemtime($f); |
|
| 397 | + } elseif ( |
|
| 398 | + @file_exists($f = "$fichier.src") |
|
| 399 | + and lire_fichier($f, $valeurs) |
|
| 400 | + and $valeurs = unserialize($valeurs) |
|
| 401 | + and isset($valeurs['hauteur_dest']) |
|
| 402 | + and isset($valeurs['largeur_dest']) |
|
| 403 | + ) { |
|
| 404 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | + $date_src = $valeurs['date']; |
|
| 407 | + } // pas de fichier source par la |
|
| 408 | + else { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + // pas de taille mesurable ? |
|
| 413 | + if (!$ret['hauteur'] |
|
| 414 | + or !($ret['hauteur'] = intval(round($ret['hauteur']))) |
|
| 415 | + or !$ret['largeur'] |
|
| 416 | + or !($ret['largeur'] = intval(round($ret['largeur']))) |
|
| 417 | + ) { |
|
| 418 | + return false; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + // les images calculees dependent du chemin du fichier source |
|
| 422 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 423 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 424 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 425 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 426 | + // alors que ca concerne peu de site au final |
|
| 427 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 428 | + $identifiant = $fichier; |
|
| 429 | + |
|
| 430 | + // cas general : |
|
| 431 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 432 | + // cas particulier de reduire : |
|
| 433 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 434 | + $cache = 'cache-gd2'; |
|
| 435 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 436 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 437 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 438 | + $ret['largeur_dest'] = $destWidth; |
|
| 439 | + $ret['hauteur_dest'] = $destHeight; |
|
| 440 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 441 | + $cache = 'cache-vignettes'; |
|
| 442 | + $fichier_dest = basename($fichier_dest); |
|
| 443 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 444 | + // on garde la terminaison initiale car image simplement copiee |
|
| 445 | + // et on postfixe son nom avec un md5 du path |
|
| 446 | + $terminaison_dest = $terminaison; |
|
| 447 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 448 | + } else { |
|
| 449 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 450 | + } |
|
| 451 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | + $cache = sous_repertoire($cache, $effet); |
|
| 453 | + } else { |
|
| 454 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 455 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 456 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 457 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 461 | + |
|
| 462 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 463 | + |
|
| 464 | + $creer = true; |
|
| 465 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 466 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 467 | + $images_recalcul[$fichier_dest] = true; |
|
| 468 | + } else { |
|
| 469 | + if (@file_exists($f = $fichier_dest)) { |
|
| 470 | + if (filemtime($f) >= $date_src) { |
|
| 471 | + $creer = false; |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + if ( |
|
| 475 | + @file_exists($f = "$fichier_dest.src") |
|
| 476 | + and lire_fichier($f, $valeurs) |
|
| 477 | + and $valeurs = unserialize($valeurs) |
|
| 478 | + and $valeurs['date'] >= $date_src |
|
| 479 | + ) { |
|
| 480 | + $creer = false; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + if ($creer) { |
|
| 485 | + if (!@file_exists($fichier)) { |
|
| 486 | + if (!@file_exists("$fichier.src")) { |
|
| 487 | + spip_log("Image absente : $fichier"); |
|
| 488 | + |
|
| 489 | + return false; |
|
| 490 | + } |
|
| 491 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 492 | + reconstruire_image_intermediaire($fichier); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if ($creer) { |
|
| 497 | + spip_log( |
|
| 498 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 499 | + 'images' . _LOG_DEBUG |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 504 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 505 | + $ret['fichier'] = $fichier; |
|
| 506 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 507 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 508 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 509 | + $ret['format_dest'] = $terminaison_dest; |
|
| 510 | + $ret['date_src'] = $date_src; |
|
| 511 | + $ret['creer'] = $creer; |
|
| 512 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 513 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 514 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 515 | + $ret['tag'] = $img; |
|
| 516 | + if ($fonction_creation) { |
|
| 517 | + $ret['reconstruction'] = $fonction_creation; |
|
| 518 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 519 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 520 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 521 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 525 | + 'args' => [ |
|
| 526 | + 'img' => $img, |
|
| 527 | + 'effet' => $effet, |
|
| 528 | + 'forcer_format' => $forcer_format, |
|
| 529 | + 'fonction_creation' => $fonction_creation, |
|
| 530 | + 'find_in_path' => $find_in_path, |
|
| 531 | + ], |
|
| 532 | + 'data' => $ret |
|
| 533 | + ]); |
|
| 534 | + |
|
| 535 | + // une globale pour le debug en cas de crash memoire |
|
| 536 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 537 | + |
|
| 538 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 539 | + if ($term_fonction === 'svg') { |
|
| 540 | + if ($creer and !$support_svg) { |
|
| 541 | + process_image_svg_identite($ret); |
|
| 542 | + $ret['creer'] = false; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + else { |
|
| 546 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + return $ret; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -557,54 +557,54 @@ discard block |
||
| 557 | 557 | * @return array |
| 558 | 558 | */ |
| 559 | 559 | function _image_extensions_acceptees_en_entree() { |
| 560 | - static $extensions = null; |
|
| 561 | - if (empty($extensions)) { |
|
| 562 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 563 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 564 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 565 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 566 | - $extensions = array_map('trim', $extensions); |
|
| 567 | - $extensions = array_filter($extensions); |
|
| 568 | - if (in_array('jpg', $extensions)) { |
|
| 569 | - $extensions[] = 'jpeg'; |
|
| 570 | - } |
|
| 571 | - $extensions = array_unique($extensions); |
|
| 572 | - } |
|
| 573 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - return $extensions; |
|
| 560 | + static $extensions = null; |
|
| 561 | + if (empty($extensions)) { |
|
| 562 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 563 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 564 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 565 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 566 | + $extensions = array_map('trim', $extensions); |
|
| 567 | + $extensions = array_filter($extensions); |
|
| 568 | + if (in_array('jpg', $extensions)) { |
|
| 569 | + $extensions[] = 'jpeg'; |
|
| 570 | + } |
|
| 571 | + $extensions = array_unique($extensions); |
|
| 572 | + } |
|
| 573 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + return $extensions; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | 580 | * @return array|string[]|null |
| 581 | 581 | */ |
| 582 | 582 | function _image_extensions_acceptees_en_sortie() { |
| 583 | - static $extensions = null; |
|
| 584 | - if (empty($extensions)) { |
|
| 585 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 586 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 587 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 588 | - $extensions = array_diff($extensions, ['gif']); |
|
| 589 | - } |
|
| 590 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 591 | - $extensions = array_diff($extensions, ['webp']); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - return $extensions; |
|
| 583 | + static $extensions = null; |
|
| 584 | + if (empty($extensions)) { |
|
| 585 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 586 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 587 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 588 | + $extensions = array_diff($extensions, ['gif']); |
|
| 589 | + } |
|
| 590 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 591 | + $extensions = array_diff($extensions, ['webp']); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + return $extensions; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | function _image_extension_normalisee($extension) { |
| 599 | - $extension = strtolower($extension); |
|
| 600 | - if ($extension === 'jpeg') { |
|
| 601 | - $extension = 'jpg'; |
|
| 602 | - } |
|
| 603 | - return $extension; |
|
| 599 | + $extension = strtolower($extension); |
|
| 600 | + if ($extension === 'jpeg') { |
|
| 601 | + $extension = 'jpg'; |
|
| 602 | + } |
|
| 603 | + return $extension; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | function _image_extensions_conservent_transparence() { |
| 607 | - return ['png', 'webp']; |
|
| 607 | + return ['png', 'webp']; |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | |
@@ -614,12 +614,12 @@ discard block |
||
| 614 | 614 | * @return string |
| 615 | 615 | */ |
| 616 | 616 | function _image_trouver_extension($path) { |
| 617 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 618 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 619 | - $terminaison = strtolower($regs[1]); |
|
| 620 | - return $terminaison; |
|
| 621 | - } |
|
| 622 | - return ''; |
|
| 617 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 618 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 619 | + $terminaison = strtolower($regs[1]); |
|
| 620 | + return $terminaison; |
|
| 621 | + } |
|
| 622 | + return ''; |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
@@ -630,33 +630,33 @@ discard block |
||
| 630 | 630 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 631 | 631 | */ |
| 632 | 632 | function _image_trouver_extension_pertinente($path) { |
| 633 | - $path = supprimer_timestamp($path); |
|
| 634 | - $terminaison = _image_trouver_extension($path); |
|
| 635 | - if ($terminaison == 'jpg') { |
|
| 636 | - $terminaison = 'jpeg'; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - if (!file_exists($path)) { |
|
| 640 | - return $terminaison; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if (!$info = @spip_getimagesize($path)) { |
|
| 644 | - return $terminaison; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - if (isset($info['mime'])) { |
|
| 648 | - $mime = $info['mime']; |
|
| 649 | - } |
|
| 650 | - else { |
|
| 651 | - $mime = image_type_to_mime_type($info[2]); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 655 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 656 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 657 | - $terminaison = $_terminaison; |
|
| 658 | - } |
|
| 659 | - return $terminaison; |
|
| 633 | + $path = supprimer_timestamp($path); |
|
| 634 | + $terminaison = _image_trouver_extension($path); |
|
| 635 | + if ($terminaison == 'jpg') { |
|
| 636 | + $terminaison = 'jpeg'; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + if (!file_exists($path)) { |
|
| 640 | + return $terminaison; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if (!$info = @spip_getimagesize($path)) { |
|
| 644 | + return $terminaison; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + if (isset($info['mime'])) { |
|
| 648 | + $mime = $info['mime']; |
|
| 649 | + } |
|
| 650 | + else { |
|
| 651 | + $mime = image_type_to_mime_type($info[2]); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 655 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 656 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 657 | + $terminaison = $_terminaison; |
|
| 658 | + } |
|
| 659 | + return $terminaison; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
@@ -664,36 +664,36 @@ discard block |
||
| 664 | 664 | * @return string |
| 665 | 665 | */ |
| 666 | 666 | function _image_trouver_extension_depuis_mime($mime) { |
| 667 | - switch (strtolower($mime)) { |
|
| 668 | - case 'image/png': |
|
| 669 | - case 'image/x-png': |
|
| 670 | - $terminaison = 'png'; |
|
| 671 | - break; |
|
| 672 | - |
|
| 673 | - case 'image/jpg': |
|
| 674 | - case 'image/jpeg': |
|
| 675 | - case 'image/pjpeg': |
|
| 676 | - $terminaison = 'jpeg'; |
|
| 677 | - break; |
|
| 678 | - |
|
| 679 | - case 'image/gif': |
|
| 680 | - $terminaison = 'gif'; |
|
| 681 | - break; |
|
| 682 | - |
|
| 683 | - case 'image/webp': |
|
| 684 | - case 'image/x-webp': |
|
| 685 | - $terminaison = 'webp'; |
|
| 686 | - break; |
|
| 687 | - |
|
| 688 | - case 'image/svg+xml': |
|
| 689 | - $terminaison = 'svg'; |
|
| 690 | - break; |
|
| 691 | - |
|
| 692 | - default: |
|
| 693 | - $terminaison = ''; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $terminaison; |
|
| 667 | + switch (strtolower($mime)) { |
|
| 668 | + case 'image/png': |
|
| 669 | + case 'image/x-png': |
|
| 670 | + $terminaison = 'png'; |
|
| 671 | + break; |
|
| 672 | + |
|
| 673 | + case 'image/jpg': |
|
| 674 | + case 'image/jpeg': |
|
| 675 | + case 'image/pjpeg': |
|
| 676 | + $terminaison = 'jpeg'; |
|
| 677 | + break; |
|
| 678 | + |
|
| 679 | + case 'image/gif': |
|
| 680 | + $terminaison = 'gif'; |
|
| 681 | + break; |
|
| 682 | + |
|
| 683 | + case 'image/webp': |
|
| 684 | + case 'image/x-webp': |
|
| 685 | + $terminaison = 'webp'; |
|
| 686 | + break; |
|
| 687 | + |
|
| 688 | + case 'image/svg+xml': |
|
| 689 | + $terminaison = 'svg'; |
|
| 690 | + break; |
|
| 691 | + |
|
| 692 | + default: |
|
| 693 | + $terminaison = ''; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $terminaison; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -713,18 +713,18 @@ discard block |
||
| 713 | 713 | * Une ressource de type Image GD. |
| 714 | 714 | */ |
| 715 | 715 | function _imagecreatefrom_func(string $func, string $filename) { |
| 716 | - if (!function_exists($func)) { |
|
| 717 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 718 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 719 | - return null; |
|
| 720 | - } |
|
| 721 | - $img = @$func($filename); |
|
| 722 | - if (!$img) { |
|
| 723 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 724 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 725 | - $img = imagecreate(10, 10); |
|
| 726 | - } |
|
| 727 | - return $img; |
|
| 716 | + if (!function_exists($func)) { |
|
| 717 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 718 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 719 | + return null; |
|
| 720 | + } |
|
| 721 | + $img = @$func($filename); |
|
| 722 | + if (!$img) { |
|
| 723 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 724 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 725 | + $img = imagecreate(10, 10); |
|
| 726 | + } |
|
| 727 | + return $img; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | * Une ressource de type Image GD. |
| 741 | 741 | */ |
| 742 | 742 | function _imagecreatefromjpeg($filename) { |
| 743 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 743 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | * Une ressource de type Image GD. |
| 757 | 757 | */ |
| 758 | 758 | function _imagecreatefrompng($filename) { |
| 759 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 759 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | * Une ressource de type Image GD. |
| 773 | 773 | */ |
| 774 | 774 | function _imagecreatefromgif($filename) { |
| 775 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 775 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | * Une ressource de type Image GD. |
| 790 | 790 | */ |
| 791 | 791 | function _imagecreatefromwebp($filename) { |
| 792 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 792 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -807,24 +807,24 @@ discard block |
||
| 807 | 807 | * - true si une image est bien retournée. |
| 808 | 808 | */ |
| 809 | 809 | function _image_imagepng($img, $fichier) { |
| 810 | - if (!function_exists('imagepng')) { |
|
| 811 | - return false; |
|
| 812 | - } |
|
| 813 | - $tmp = $fichier . '.tmp'; |
|
| 814 | - $ret = imagepng($img, $tmp); |
|
| 815 | - if (file_exists($tmp)) { |
|
| 816 | - $taille_test = @getimagesize($tmp); |
|
| 817 | - if (empty($taille_test[0])) { |
|
| 818 | - return false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 822 | - @rename($tmp, $fichier); |
|
| 823 | - |
|
| 824 | - return $ret; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - return false; |
|
| 810 | + if (!function_exists('imagepng')) { |
|
| 811 | + return false; |
|
| 812 | + } |
|
| 813 | + $tmp = $fichier . '.tmp'; |
|
| 814 | + $ret = imagepng($img, $tmp); |
|
| 815 | + if (file_exists($tmp)) { |
|
| 816 | + $taille_test = @getimagesize($tmp); |
|
| 817 | + if (empty($taille_test[0])) { |
|
| 818 | + return false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 822 | + @rename($tmp, $fichier); |
|
| 823 | + |
|
| 824 | + return $ret; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + return false; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -842,24 +842,24 @@ discard block |
||
| 842 | 842 | * - true si une image est bien retournée. |
| 843 | 843 | */ |
| 844 | 844 | function _image_imagegif($img, $fichier) { |
| 845 | - if (!function_exists('imagegif')) { |
|
| 846 | - return false; |
|
| 847 | - } |
|
| 848 | - $tmp = $fichier . '.tmp'; |
|
| 849 | - $ret = imagegif($img, $tmp); |
|
| 850 | - if (file_exists($tmp)) { |
|
| 851 | - $taille_test = @getimagesize($tmp); |
|
| 852 | - if (empty($taille_test[0])) { |
|
| 853 | - return false; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 857 | - @rename($tmp, $fichier); |
|
| 858 | - |
|
| 859 | - return $ret; |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return false; |
|
| 845 | + if (!function_exists('imagegif')) { |
|
| 846 | + return false; |
|
| 847 | + } |
|
| 848 | + $tmp = $fichier . '.tmp'; |
|
| 849 | + $ret = imagegif($img, $tmp); |
|
| 850 | + if (file_exists($tmp)) { |
|
| 851 | + $taille_test = @getimagesize($tmp); |
|
| 852 | + if (empty($taille_test[0])) { |
|
| 853 | + return false; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 857 | + @rename($tmp, $fichier); |
|
| 858 | + |
|
| 859 | + return $ret; |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return false; |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | /** |
@@ -882,29 +882,29 @@ discard block |
||
| 882 | 882 | * - true si une image est bien retournée. |
| 883 | 883 | */ |
| 884 | 884 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 885 | - if (!function_exists('imagejpeg')) { |
|
| 886 | - return false; |
|
| 887 | - } |
|
| 888 | - $tmp = $fichier . '.tmp'; |
|
| 885 | + if (!function_exists('imagejpeg')) { |
|
| 886 | + return false; |
|
| 887 | + } |
|
| 888 | + $tmp = $fichier . '.tmp'; |
|
| 889 | 889 | |
| 890 | - // Enable interlancing |
|
| 891 | - imageinterlace($img, true); |
|
| 890 | + // Enable interlancing |
|
| 891 | + imageinterlace($img, true); |
|
| 892 | 892 | |
| 893 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 893 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 894 | 894 | |
| 895 | - if (file_exists($tmp)) { |
|
| 896 | - $taille_test = @getimagesize($tmp); |
|
| 897 | - if (empty($taille_test[0])) { |
|
| 898 | - return false; |
|
| 899 | - } |
|
| 895 | + if (file_exists($tmp)) { |
|
| 896 | + $taille_test = @getimagesize($tmp); |
|
| 897 | + if (empty($taille_test[0])) { |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 900 | 900 | |
| 901 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 902 | - @rename($tmp, $fichier); |
|
| 901 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 902 | + @rename($tmp, $fichier); |
|
| 903 | 903 | |
| 904 | - return $ret; |
|
| 905 | - } |
|
| 904 | + return $ret; |
|
| 905 | + } |
|
| 906 | 906 | |
| 907 | - return false; |
|
| 907 | + return false; |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -922,9 +922,9 @@ discard block |
||
| 922 | 922 | * true si le fichier a bien été créé ; false sinon. |
| 923 | 923 | */ |
| 924 | 924 | function _image_imageico($img, $fichier) { |
| 925 | - $gd_image_array = [$img]; |
|
| 925 | + $gd_image_array = [$img]; |
|
| 926 | 926 | |
| 927 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 927 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | |
@@ -943,24 +943,24 @@ discard block |
||
| 943 | 943 | * - true si une image est bien retournée. |
| 944 | 944 | */ |
| 945 | 945 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 946 | - if (!function_exists('imagewebp')) { |
|
| 947 | - return false; |
|
| 948 | - } |
|
| 949 | - $tmp = $fichier . '.tmp'; |
|
| 950 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 951 | - if (file_exists($tmp)) { |
|
| 952 | - $taille_test = @getimagesize($tmp); |
|
| 953 | - if (empty($taille_test[0])) { |
|
| 954 | - return false; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 958 | - @rename($tmp, $fichier); |
|
| 959 | - |
|
| 960 | - return $ret; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - return false; |
|
| 946 | + if (!function_exists('imagewebp')) { |
|
| 947 | + return false; |
|
| 948 | + } |
|
| 949 | + $tmp = $fichier . '.tmp'; |
|
| 950 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 951 | + if (file_exists($tmp)) { |
|
| 952 | + $taille_test = @getimagesize($tmp); |
|
| 953 | + if (empty($taille_test[0])) { |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 958 | + @rename($tmp, $fichier); |
|
| 959 | + |
|
| 960 | + return $ret; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + return false; |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
@@ -980,35 +980,35 @@ discard block |
||
| 980 | 980 | */ |
| 981 | 981 | function _image_imagesvg($img, $fichier) { |
| 982 | 982 | |
| 983 | - $tmp = $fichier . '.tmp'; |
|
| 984 | - if (strpos($img, '<') === false) { |
|
| 985 | - $img = supprimer_timestamp($img); |
|
| 986 | - if (!file_exists($img)) { |
|
| 987 | - return false; |
|
| 988 | - } |
|
| 989 | - @copy($img, $tmp); |
|
| 990 | - if (filesize($tmp) == filesize($img)) { |
|
| 991 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 992 | - @rename($tmp, $fichier); |
|
| 993 | - return true; |
|
| 994 | - } |
|
| 995 | - return false; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - file_put_contents($tmp, $img); |
|
| 999 | - if (file_exists($tmp)) { |
|
| 1000 | - $taille_test = spip_getimagesize($tmp); |
|
| 1001 | - if (empty($taille_test[0])) { |
|
| 1002 | - return false; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1006 | - @rename($tmp, $fichier); |
|
| 1007 | - |
|
| 1008 | - return true; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - return false; |
|
| 983 | + $tmp = $fichier . '.tmp'; |
|
| 984 | + if (strpos($img, '<') === false) { |
|
| 985 | + $img = supprimer_timestamp($img); |
|
| 986 | + if (!file_exists($img)) { |
|
| 987 | + return false; |
|
| 988 | + } |
|
| 989 | + @copy($img, $tmp); |
|
| 990 | + if (filesize($tmp) == filesize($img)) { |
|
| 991 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 992 | + @rename($tmp, $fichier); |
|
| 993 | + return true; |
|
| 994 | + } |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + file_put_contents($tmp, $img); |
|
| 999 | + if (file_exists($tmp)) { |
|
| 1000 | + $taille_test = spip_getimagesize($tmp); |
|
| 1001 | + if (empty($taille_test[0])) { |
|
| 1002 | + return false; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1006 | + @rename($tmp, $fichier); |
|
| 1007 | + |
|
| 1008 | + return true; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + return false; |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | |
@@ -1036,30 +1036,30 @@ discard block |
||
| 1036 | 1036 | * - false sinon. |
| 1037 | 1037 | */ |
| 1038 | 1038 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1039 | - if (is_null($fonction)) { |
|
| 1040 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1041 | - } |
|
| 1042 | - $ret = false; |
|
| 1043 | - #un flag pour reperer les images gravees |
|
| 1044 | - $lock = ( |
|
| 1045 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1046 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1047 | - ); |
|
| 1048 | - if ( |
|
| 1049 | - function_exists($fonction) |
|
| 1050 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1051 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1052 | - && !$lock |
|
| 1053 | - ) { |
|
| 1054 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1055 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1056 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1057 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1058 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - return $ret; |
|
| 1039 | + if (is_null($fonction)) { |
|
| 1040 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1041 | + } |
|
| 1042 | + $ret = false; |
|
| 1043 | + #un flag pour reperer les images gravees |
|
| 1044 | + $lock = ( |
|
| 1045 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1046 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1047 | + ); |
|
| 1048 | + if ( |
|
| 1049 | + function_exists($fonction) |
|
| 1050 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1051 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1052 | + && !$lock |
|
| 1053 | + ) { |
|
| 1054 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1055 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1056 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1057 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1058 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + return $ret; |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | /** |
@@ -1072,27 +1072,27 @@ discard block |
||
| 1072 | 1072 | * Chemin vers le fichier manquant |
| 1073 | 1073 | **/ |
| 1074 | 1074 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1075 | - $reconstruire = []; |
|
| 1076 | - $fichier = $fichier_manquant; |
|
| 1077 | - while ( |
|
| 1078 | - strpos($fichier, '://') === false |
|
| 1079 | - and !@file_exists($fichier) |
|
| 1080 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1081 | - and $valeurs = unserialize($source) |
|
| 1082 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1083 | - ) { |
|
| 1084 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1085 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1086 | - } |
|
| 1087 | - while (count($reconstruire)) { |
|
| 1088 | - $r = array_pop($reconstruire); |
|
| 1089 | - $fonction = $r[0]; |
|
| 1090 | - $args = $r[1]; |
|
| 1091 | - $fonction(...$args); |
|
| 1092 | - } |
|
| 1093 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1094 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1095 | - ramasse_miettes($fichier_manquant); |
|
| 1075 | + $reconstruire = []; |
|
| 1076 | + $fichier = $fichier_manquant; |
|
| 1077 | + while ( |
|
| 1078 | + strpos($fichier, '://') === false |
|
| 1079 | + and !@file_exists($fichier) |
|
| 1080 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1081 | + and $valeurs = unserialize($source) |
|
| 1082 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1083 | + ) { |
|
| 1084 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1085 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1086 | + } |
|
| 1087 | + while (count($reconstruire)) { |
|
| 1088 | + $r = array_pop($reconstruire); |
|
| 1089 | + $fonction = $r[0]; |
|
| 1090 | + $args = $r[1]; |
|
| 1091 | + $fonction(...$args); |
|
| 1092 | + } |
|
| 1093 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1094 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1095 | + ramasse_miettes($fichier_manquant); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | /** |
@@ -1112,28 +1112,28 @@ discard block |
||
| 1112 | 1112 | * Chemin du fichier d'image calculé |
| 1113 | 1113 | **/ |
| 1114 | 1114 | function ramasse_miettes($fichier) { |
| 1115 | - if ( |
|
| 1116 | - strpos($fichier, '://') !== false |
|
| 1117 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1118 | - or !$valeurs = unserialize($source) |
|
| 1119 | - ) { |
|
| 1120 | - return; |
|
| 1121 | - } |
|
| 1122 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1123 | - while ( |
|
| 1124 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1125 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1126 | - and (lire_fichier( |
|
| 1127 | - $src = "$fichier.src", |
|
| 1128 | - $source |
|
| 1129 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1130 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1131 | - ) { |
|
| 1132 | - # on efface le fichier |
|
| 1133 | - spip_unlink($fichier); |
|
| 1134 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1135 | - #spip_unlink($src); |
|
| 1136 | - } |
|
| 1115 | + if ( |
|
| 1116 | + strpos($fichier, '://') !== false |
|
| 1117 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1118 | + or !$valeurs = unserialize($source) |
|
| 1119 | + ) { |
|
| 1120 | + return; |
|
| 1121 | + } |
|
| 1122 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1123 | + while ( |
|
| 1124 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1125 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1126 | + and (lire_fichier( |
|
| 1127 | + $src = "$fichier.src", |
|
| 1128 | + $source |
|
| 1129 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1130 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1131 | + ) { |
|
| 1132 | + # on efface le fichier |
|
| 1133 | + spip_unlink($fichier); |
|
| 1134 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1135 | + #spip_unlink($src); |
|
| 1136 | + } |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
@@ -1158,31 +1158,31 @@ discard block |
||
| 1158 | 1158 | * Code HTML de l'image |
| 1159 | 1159 | **/ |
| 1160 | 1160 | function image_graver($img) { |
| 1161 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1162 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1163 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1164 | - |
|
| 1165 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1166 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1167 | - $fichier = substr($fichier, 0, $p); |
|
| 1168 | - } |
|
| 1169 | - if (strlen($fichier) < 1) { |
|
| 1170 | - $fichier = $img; |
|
| 1171 | - } |
|
| 1172 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1173 | - # et qu'il ne s'agit pas d'une URL |
|
| 1174 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1175 | - reconstruire_image_intermediaire($fichier); |
|
| 1176 | - } |
|
| 1177 | - ramasse_miettes($fichier); |
|
| 1178 | - |
|
| 1179 | - // ajouter le timestamp si besoin |
|
| 1180 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1181 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1182 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - return $img; |
|
| 1161 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1162 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1163 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1164 | + |
|
| 1165 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1166 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1167 | + $fichier = substr($fichier, 0, $p); |
|
| 1168 | + } |
|
| 1169 | + if (strlen($fichier) < 1) { |
|
| 1170 | + $fichier = $img; |
|
| 1171 | + } |
|
| 1172 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1173 | + # et qu'il ne s'agit pas d'une URL |
|
| 1174 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1175 | + reconstruire_image_intermediaire($fichier); |
|
| 1176 | + } |
|
| 1177 | + ramasse_miettes($fichier); |
|
| 1178 | + |
|
| 1179 | + // ajouter le timestamp si besoin |
|
| 1180 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1181 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1182 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + return $img; |
|
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | /** |
@@ -1209,34 +1209,34 @@ discard block |
||
| 1209 | 1209 | * Code html modifié de la balise. |
| 1210 | 1210 | **/ |
| 1211 | 1211 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1212 | - if ($style === false) { |
|
| 1213 | - $style = extraire_attribut($tag, 'style'); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // enlever le width et height du style |
|
| 1217 | - if ($style) { |
|
| 1218 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1219 | - } |
|
| 1220 | - if ($style and $style[0] === ';') { |
|
| 1221 | - $style = substr($style, 1); |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - // mettre des attributs de width et height sur les images, |
|
| 1225 | - // ca accelere le rendu du navigateur |
|
| 1226 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1227 | - // quand on a desactive l'affichage des images. |
|
| 1228 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1229 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1230 | - |
|
| 1231 | - // attributs deprecies. Transformer en CSS |
|
| 1232 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1233 | - $style = "margin:{$espace}px;" . $style; |
|
| 1234 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1238 | - |
|
| 1239 | - return $tag; |
|
| 1212 | + if ($style === false) { |
|
| 1213 | + $style = extraire_attribut($tag, 'style'); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // enlever le width et height du style |
|
| 1217 | + if ($style) { |
|
| 1218 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1219 | + } |
|
| 1220 | + if ($style and $style[0] === ';') { |
|
| 1221 | + $style = substr($style, 1); |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + // mettre des attributs de width et height sur les images, |
|
| 1225 | + // ca accelere le rendu du navigateur |
|
| 1226 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1227 | + // quand on a desactive l'affichage des images. |
|
| 1228 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1229 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1230 | + |
|
| 1231 | + // attributs deprecies. Transformer en CSS |
|
| 1232 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1233 | + $style = "margin:{$espace}px;" . $style; |
|
| 1234 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1238 | + |
|
| 1239 | + return $tag; |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | |
@@ -1262,72 +1262,72 @@ discard block |
||
| 1262 | 1262 | * Retourne le code HTML de l'image |
| 1263 | 1263 | **/ |
| 1264 | 1264 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1265 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1266 | - |
|
| 1267 | - // fermer les tags img pas bien fermes; |
|
| 1268 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1269 | - |
|
| 1270 | - // le style |
|
| 1271 | - $style = $valeurs['style']; |
|
| 1272 | - if (isset($surcharge['style'])) { |
|
| 1273 | - $style = $surcharge['style']; |
|
| 1274 | - unset($surcharge['style']); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - // traiter specifiquement la largeur et la hauteur |
|
| 1278 | - $width = $valeurs['largeur']; |
|
| 1279 | - if (isset($surcharge['width'])) { |
|
| 1280 | - $width = $surcharge['width']; |
|
| 1281 | - unset($surcharge['width']); |
|
| 1282 | - } |
|
| 1283 | - $height = $valeurs['hauteur']; |
|
| 1284 | - if (isset($surcharge['height'])) { |
|
| 1285 | - $height = $surcharge['height']; |
|
| 1286 | - unset($surcharge['height']); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1290 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1291 | - // on remplace toute les ref a src dans le tag |
|
| 1292 | - $src = extraire_attribut($tag, 'src'); |
|
| 1293 | - if (isset($surcharge['src'])) { |
|
| 1294 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1295 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1296 | - // pas garanti comme methode, mais mieux que rien |
|
| 1297 | - if (strpos($src, '&') !== false) { |
|
| 1298 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1299 | - } |
|
| 1300 | - $src = $surcharge['src']; |
|
| 1301 | - unset($surcharge['src']); |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - $class = $valeurs['class']; |
|
| 1305 | - if (isset($surcharge['class'])) { |
|
| 1306 | - $class = $surcharge['class']; |
|
| 1307 | - unset($surcharge['class']); |
|
| 1308 | - } |
|
| 1309 | - if (is_scalar($class) && strlen($class)) { |
|
| 1310 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - if (count($surcharge)) { |
|
| 1314 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1315 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - $tag = pipeline( |
|
| 1320 | - 'image_ecrire_tag_finir', |
|
| 1321 | - [ |
|
| 1322 | - 'args' => [ |
|
| 1323 | - 'valeurs' => $valeurs, |
|
| 1324 | - 'surcharge' => $surcharge, |
|
| 1325 | - ], |
|
| 1326 | - 'data' => $tag |
|
| 1327 | - ] |
|
| 1328 | - ); |
|
| 1329 | - |
|
| 1330 | - return $tag; |
|
| 1265 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1266 | + |
|
| 1267 | + // fermer les tags img pas bien fermes; |
|
| 1268 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1269 | + |
|
| 1270 | + // le style |
|
| 1271 | + $style = $valeurs['style']; |
|
| 1272 | + if (isset($surcharge['style'])) { |
|
| 1273 | + $style = $surcharge['style']; |
|
| 1274 | + unset($surcharge['style']); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + // traiter specifiquement la largeur et la hauteur |
|
| 1278 | + $width = $valeurs['largeur']; |
|
| 1279 | + if (isset($surcharge['width'])) { |
|
| 1280 | + $width = $surcharge['width']; |
|
| 1281 | + unset($surcharge['width']); |
|
| 1282 | + } |
|
| 1283 | + $height = $valeurs['hauteur']; |
|
| 1284 | + if (isset($surcharge['height'])) { |
|
| 1285 | + $height = $surcharge['height']; |
|
| 1286 | + unset($surcharge['height']); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1290 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1291 | + // on remplace toute les ref a src dans le tag |
|
| 1292 | + $src = extraire_attribut($tag, 'src'); |
|
| 1293 | + if (isset($surcharge['src'])) { |
|
| 1294 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1295 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1296 | + // pas garanti comme methode, mais mieux que rien |
|
| 1297 | + if (strpos($src, '&') !== false) { |
|
| 1298 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1299 | + } |
|
| 1300 | + $src = $surcharge['src']; |
|
| 1301 | + unset($surcharge['src']); |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + $class = $valeurs['class']; |
|
| 1305 | + if (isset($surcharge['class'])) { |
|
| 1306 | + $class = $surcharge['class']; |
|
| 1307 | + unset($surcharge['class']); |
|
| 1308 | + } |
|
| 1309 | + if (is_scalar($class) && strlen($class)) { |
|
| 1310 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + if (count($surcharge)) { |
|
| 1314 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1315 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + $tag = pipeline( |
|
| 1320 | + 'image_ecrire_tag_finir', |
|
| 1321 | + [ |
|
| 1322 | + 'args' => [ |
|
| 1323 | + 'valeurs' => $valeurs, |
|
| 1324 | + 'surcharge' => $surcharge, |
|
| 1325 | + ], |
|
| 1326 | + 'data' => $tag |
|
| 1327 | + ] |
|
| 1328 | + ); |
|
| 1329 | + |
|
| 1330 | + return $tag; |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | /** |
@@ -1350,268 +1350,268 @@ discard block |
||
| 1350 | 1350 | * Description de l'image, sinon null. |
| 1351 | 1351 | **/ |
| 1352 | 1352 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1353 | - $srcHeight = null; |
|
| 1354 | - $retour = []; |
|
| 1355 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1356 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1357 | - $image = $valeurs['fichier']; |
|
| 1358 | - $format = $valeurs['format_source']; |
|
| 1359 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1360 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1361 | - |
|
| 1362 | - $format_sortie = $valeurs['format_dest']; |
|
| 1363 | - |
|
| 1364 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1365 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1369 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1370 | - return; |
|
| 1371 | - } |
|
| 1372 | - $destination = "$destdir/$destfile"; |
|
| 1373 | - |
|
| 1374 | - // calculer la taille |
|
| 1375 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1376 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1377 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1378 | - } |
|
| 1379 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1380 | - $destWidth = $maxWidth; |
|
| 1381 | - $destHeight = $maxHeight; |
|
| 1382 | - } else { |
|
| 1383 | - spip_log("echec $process sur $image"); |
|
| 1384 | - |
|
| 1385 | - return; |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - $vignette = ''; |
|
| 1389 | - |
|
| 1390 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1391 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1392 | - $vignette = $destination . '.' . $format; |
|
| 1393 | - @copy($image, $vignette); |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1397 | - include_spip('inc/svg'); |
|
| 1398 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1399 | - $format_sortie = 'svg'; |
|
| 1400 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1401 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1402 | - _image_gd_output($svg, $valeurs); |
|
| 1403 | - } |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - // imagemagick en ligne de commande |
|
| 1407 | - elseif ($process == 'convert') { |
|
| 1408 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1409 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1410 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1411 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1412 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1413 | - } |
|
| 1414 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1415 | - $commande = str_replace( |
|
| 1416 | - ['%x', '%y', '%src', '%dest'], |
|
| 1417 | - [ |
|
| 1418 | - $destWidth, |
|
| 1419 | - $destHeight, |
|
| 1420 | - escapeshellcmd($image), |
|
| 1421 | - escapeshellcmd($vignette) |
|
| 1422 | - ], |
|
| 1423 | - _RESIZE_COMMAND |
|
| 1424 | - ); |
|
| 1425 | - spip_log($commande); |
|
| 1426 | - exec($commande); |
|
| 1427 | - if (!@file_exists($vignette)) { |
|
| 1428 | - spip_log("echec convert sur $vignette"); |
|
| 1429 | - |
|
| 1430 | - return; // echec commande |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - // php5 imagemagick |
|
| 1435 | - elseif ($process == 'imagick') { |
|
| 1436 | - if (!class_exists(\Imagick::class)) { |
|
| 1437 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1438 | - |
|
| 1439 | - return; |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - // chemin compatible Windows |
|
| 1443 | - $output = realpath(dirname($destination)); |
|
| 1444 | - if (!$output) { |
|
| 1445 | - return; |
|
| 1446 | - } |
|
| 1447 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1448 | - |
|
| 1449 | - $imagick = new Imagick(); |
|
| 1450 | - $imagick->readImage(realpath($image)); |
|
| 1451 | - $imagick->resizeImage( |
|
| 1452 | - $destWidth, |
|
| 1453 | - $destHeight, |
|
| 1454 | - Imagick::FILTER_LANCZOS, |
|
| 1455 | - 1 |
|
| 1456 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1457 | - $imagick->writeImage($vignette); |
|
| 1458 | - |
|
| 1459 | - if (!@file_exists($vignette)) { |
|
| 1460 | - spip_log("echec imagick sur $vignette"); |
|
| 1461 | - |
|
| 1462 | - return; |
|
| 1463 | - } |
|
| 1464 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1465 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - // netpbm |
|
| 1469 | - elseif ($process == 'netpbm') { |
|
| 1470 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1471 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1472 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1473 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1474 | - return; |
|
| 1475 | - } |
|
| 1476 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1477 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1478 | - if ($format == 'jpg') { |
|
| 1479 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1480 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1481 | - if (!($s = @filesize($vignette))) { |
|
| 1482 | - spip_unlink($vignette); |
|
| 1483 | - } |
|
| 1484 | - if (!@file_exists($vignette)) { |
|
| 1485 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1486 | - |
|
| 1487 | - return; |
|
| 1488 | - } |
|
| 1489 | - } else { |
|
| 1490 | - if ($format == 'gif') { |
|
| 1491 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1492 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1493 | - if (!($s = @filesize($vignette))) { |
|
| 1494 | - spip_unlink($vignette); |
|
| 1495 | - } |
|
| 1496 | - if (!@file_exists($vignette)) { |
|
| 1497 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1498 | - |
|
| 1499 | - return; |
|
| 1500 | - } |
|
| 1501 | - } else { |
|
| 1502 | - if ($format == 'png') { |
|
| 1503 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | - if (!($s = @filesize($vignette))) { |
|
| 1506 | - spip_unlink($vignette); |
|
| 1507 | - } |
|
| 1508 | - if (!@file_exists($vignette)) { |
|
| 1509 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1510 | - |
|
| 1511 | - return; |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - } |
|
| 1515 | - } |
|
| 1516 | - } |
|
| 1517 | - |
|
| 1518 | - // gd ou gd2 |
|
| 1519 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1520 | - if (!function_exists('gd_info')) { |
|
| 1521 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1522 | - |
|
| 1523 | - return; |
|
| 1524 | - } |
|
| 1525 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1526 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1527 | - |
|
| 1528 | - return; |
|
| 1529 | - } |
|
| 1530 | - $destFormat = $format_sortie; |
|
| 1531 | - if (!$destFormat) { |
|
| 1532 | - spip_log("pas de format pour $image"); |
|
| 1533 | - |
|
| 1534 | - return; |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1538 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1539 | - return; |
|
| 1540 | - } |
|
| 1541 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1542 | - if (!$srcImage) { |
|
| 1543 | - spip_log('echec gd1/gd2'); |
|
| 1544 | - |
|
| 1545 | - return; |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - // Initialisation de l'image destination |
|
| 1549 | - $destImage = null; |
|
| 1550 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1551 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1552 | - } |
|
| 1553 | - if (!$destImage) { |
|
| 1554 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1558 | - $ok = false; |
|
| 1559 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1560 | - if ($format == 'gif') { |
|
| 1561 | - // Si un GIF est transparent, |
|
| 1562 | - // fabriquer un PNG transparent |
|
| 1563 | - $transp = imagecolortransparent($srcImage); |
|
| 1564 | - if ($transp > 0) { |
|
| 1565 | - $destFormat = 'png'; |
|
| 1566 | - } |
|
| 1567 | - } |
|
| 1568 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1569 | - // Conserver la transparence |
|
| 1570 | - if (function_exists('imageAntiAlias')) { |
|
| 1571 | - imageAntiAlias($destImage, true); |
|
| 1572 | - } |
|
| 1573 | - @imagealphablending($destImage, false); |
|
| 1574 | - @imagesavealpha($destImage, true); |
|
| 1575 | - } |
|
| 1576 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1577 | - } |
|
| 1578 | - if (!$ok) { |
|
| 1579 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - // Sauvegarde de l'image destination |
|
| 1583 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1584 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1585 | - _image_gd_output($destImage, $valeurs); |
|
| 1586 | - |
|
| 1587 | - if ($srcImage) { |
|
| 1588 | - ImageDestroy($srcImage); |
|
| 1589 | - } |
|
| 1590 | - ImageDestroy($destImage); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1594 | - $size = [$destWidth, $destHeight]; |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1598 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1599 | - if ($size[0] < 1) { |
|
| 1600 | - $size[0] = $destWidth; |
|
| 1601 | - } |
|
| 1602 | - if ($size[1] < 1) { |
|
| 1603 | - $size[1] = $destHeight; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - $retour['width'] = $largeur = $size[0]; |
|
| 1607 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1608 | - |
|
| 1609 | - $retour['fichier'] = $vignette; |
|
| 1610 | - $retour['format'] = $format; |
|
| 1611 | - $retour['date'] = @filemtime($vignette); |
|
| 1612 | - |
|
| 1613 | - // renvoyer l'image |
|
| 1614 | - return $retour; |
|
| 1353 | + $srcHeight = null; |
|
| 1354 | + $retour = []; |
|
| 1355 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1356 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1357 | + $image = $valeurs['fichier']; |
|
| 1358 | + $format = $valeurs['format_source']; |
|
| 1359 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1360 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1361 | + |
|
| 1362 | + $format_sortie = $valeurs['format_dest']; |
|
| 1363 | + |
|
| 1364 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1365 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1369 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1370 | + return; |
|
| 1371 | + } |
|
| 1372 | + $destination = "$destdir/$destfile"; |
|
| 1373 | + |
|
| 1374 | + // calculer la taille |
|
| 1375 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1376 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1377 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1378 | + } |
|
| 1379 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1380 | + $destWidth = $maxWidth; |
|
| 1381 | + $destHeight = $maxHeight; |
|
| 1382 | + } else { |
|
| 1383 | + spip_log("echec $process sur $image"); |
|
| 1384 | + |
|
| 1385 | + return; |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + $vignette = ''; |
|
| 1389 | + |
|
| 1390 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1391 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1392 | + $vignette = $destination . '.' . $format; |
|
| 1393 | + @copy($image, $vignette); |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1397 | + include_spip('inc/svg'); |
|
| 1398 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1399 | + $format_sortie = 'svg'; |
|
| 1400 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1401 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1402 | + _image_gd_output($svg, $valeurs); |
|
| 1403 | + } |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + // imagemagick en ligne de commande |
|
| 1407 | + elseif ($process == 'convert') { |
|
| 1408 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1409 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1410 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1411 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1412 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1413 | + } |
|
| 1414 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1415 | + $commande = str_replace( |
|
| 1416 | + ['%x', '%y', '%src', '%dest'], |
|
| 1417 | + [ |
|
| 1418 | + $destWidth, |
|
| 1419 | + $destHeight, |
|
| 1420 | + escapeshellcmd($image), |
|
| 1421 | + escapeshellcmd($vignette) |
|
| 1422 | + ], |
|
| 1423 | + _RESIZE_COMMAND |
|
| 1424 | + ); |
|
| 1425 | + spip_log($commande); |
|
| 1426 | + exec($commande); |
|
| 1427 | + if (!@file_exists($vignette)) { |
|
| 1428 | + spip_log("echec convert sur $vignette"); |
|
| 1429 | + |
|
| 1430 | + return; // echec commande |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + // php5 imagemagick |
|
| 1435 | + elseif ($process == 'imagick') { |
|
| 1436 | + if (!class_exists(\Imagick::class)) { |
|
| 1437 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1438 | + |
|
| 1439 | + return; |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + // chemin compatible Windows |
|
| 1443 | + $output = realpath(dirname($destination)); |
|
| 1444 | + if (!$output) { |
|
| 1445 | + return; |
|
| 1446 | + } |
|
| 1447 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1448 | + |
|
| 1449 | + $imagick = new Imagick(); |
|
| 1450 | + $imagick->readImage(realpath($image)); |
|
| 1451 | + $imagick->resizeImage( |
|
| 1452 | + $destWidth, |
|
| 1453 | + $destHeight, |
|
| 1454 | + Imagick::FILTER_LANCZOS, |
|
| 1455 | + 1 |
|
| 1456 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1457 | + $imagick->writeImage($vignette); |
|
| 1458 | + |
|
| 1459 | + if (!@file_exists($vignette)) { |
|
| 1460 | + spip_log("echec imagick sur $vignette"); |
|
| 1461 | + |
|
| 1462 | + return; |
|
| 1463 | + } |
|
| 1464 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1465 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + // netpbm |
|
| 1469 | + elseif ($process == 'netpbm') { |
|
| 1470 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1471 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1472 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1473 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1474 | + return; |
|
| 1475 | + } |
|
| 1476 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1477 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1478 | + if ($format == 'jpg') { |
|
| 1479 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1480 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1481 | + if (!($s = @filesize($vignette))) { |
|
| 1482 | + spip_unlink($vignette); |
|
| 1483 | + } |
|
| 1484 | + if (!@file_exists($vignette)) { |
|
| 1485 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1486 | + |
|
| 1487 | + return; |
|
| 1488 | + } |
|
| 1489 | + } else { |
|
| 1490 | + if ($format == 'gif') { |
|
| 1491 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1492 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1493 | + if (!($s = @filesize($vignette))) { |
|
| 1494 | + spip_unlink($vignette); |
|
| 1495 | + } |
|
| 1496 | + if (!@file_exists($vignette)) { |
|
| 1497 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1498 | + |
|
| 1499 | + return; |
|
| 1500 | + } |
|
| 1501 | + } else { |
|
| 1502 | + if ($format == 'png') { |
|
| 1503 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | + if (!($s = @filesize($vignette))) { |
|
| 1506 | + spip_unlink($vignette); |
|
| 1507 | + } |
|
| 1508 | + if (!@file_exists($vignette)) { |
|
| 1509 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1510 | + |
|
| 1511 | + return; |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + } |
|
| 1516 | + } |
|
| 1517 | + |
|
| 1518 | + // gd ou gd2 |
|
| 1519 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1520 | + if (!function_exists('gd_info')) { |
|
| 1521 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1522 | + |
|
| 1523 | + return; |
|
| 1524 | + } |
|
| 1525 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1526 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1527 | + |
|
| 1528 | + return; |
|
| 1529 | + } |
|
| 1530 | + $destFormat = $format_sortie; |
|
| 1531 | + if (!$destFormat) { |
|
| 1532 | + spip_log("pas de format pour $image"); |
|
| 1533 | + |
|
| 1534 | + return; |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1538 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1539 | + return; |
|
| 1540 | + } |
|
| 1541 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1542 | + if (!$srcImage) { |
|
| 1543 | + spip_log('echec gd1/gd2'); |
|
| 1544 | + |
|
| 1545 | + return; |
|
| 1546 | + } |
|
| 1547 | + |
|
| 1548 | + // Initialisation de l'image destination |
|
| 1549 | + $destImage = null; |
|
| 1550 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1551 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1552 | + } |
|
| 1553 | + if (!$destImage) { |
|
| 1554 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1558 | + $ok = false; |
|
| 1559 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1560 | + if ($format == 'gif') { |
|
| 1561 | + // Si un GIF est transparent, |
|
| 1562 | + // fabriquer un PNG transparent |
|
| 1563 | + $transp = imagecolortransparent($srcImage); |
|
| 1564 | + if ($transp > 0) { |
|
| 1565 | + $destFormat = 'png'; |
|
| 1566 | + } |
|
| 1567 | + } |
|
| 1568 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1569 | + // Conserver la transparence |
|
| 1570 | + if (function_exists('imageAntiAlias')) { |
|
| 1571 | + imageAntiAlias($destImage, true); |
|
| 1572 | + } |
|
| 1573 | + @imagealphablending($destImage, false); |
|
| 1574 | + @imagesavealpha($destImage, true); |
|
| 1575 | + } |
|
| 1576 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1577 | + } |
|
| 1578 | + if (!$ok) { |
|
| 1579 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1580 | + } |
|
| 1581 | + |
|
| 1582 | + // Sauvegarde de l'image destination |
|
| 1583 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1584 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1585 | + _image_gd_output($destImage, $valeurs); |
|
| 1586 | + |
|
| 1587 | + if ($srcImage) { |
|
| 1588 | + ImageDestroy($srcImage); |
|
| 1589 | + } |
|
| 1590 | + ImageDestroy($destImage); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1594 | + $size = [$destWidth, $destHeight]; |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1598 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1599 | + if ($size[0] < 1) { |
|
| 1600 | + $size[0] = $destWidth; |
|
| 1601 | + } |
|
| 1602 | + if ($size[1] < 1) { |
|
| 1603 | + $size[1] = $destHeight; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + $retour['width'] = $largeur = $size[0]; |
|
| 1607 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1608 | + |
|
| 1609 | + $retour['fichier'] = $vignette; |
|
| 1610 | + $retour['format'] = $format; |
|
| 1611 | + $retour['date'] = @filemtime($vignette); |
|
| 1612 | + |
|
| 1613 | + // renvoyer l'image |
|
| 1614 | + return $retour; |
|
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | /** |
@@ -1631,25 +1631,25 @@ discard block |
||
| 1631 | 1631 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1632 | 1632 | **/ |
| 1633 | 1633 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1634 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1635 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1636 | - |
|
| 1637 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1638 | - $destWidth = $srcWidth; |
|
| 1639 | - $destHeight = $srcHeight; |
|
| 1640 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1641 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1642 | - $destHeight = $maxHeight; |
|
| 1643 | - } else { |
|
| 1644 | - $destWidth = $maxWidth; |
|
| 1645 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - return [ |
|
| 1649 | - intval(round($destWidth)), |
|
| 1650 | - intval(round($destHeight)), |
|
| 1651 | - max($ratioWidth, $ratioHeight) |
|
| 1652 | - ]; |
|
| 1634 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1635 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1636 | + |
|
| 1637 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1638 | + $destWidth = $srcWidth; |
|
| 1639 | + $destHeight = $srcHeight; |
|
| 1640 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1641 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1642 | + $destHeight = $maxHeight; |
|
| 1643 | + } else { |
|
| 1644 | + $destWidth = $maxWidth; |
|
| 1645 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + return [ |
|
| 1649 | + intval(round($destWidth)), |
|
| 1650 | + intval(round($destHeight)), |
|
| 1651 | + max($ratioWidth, $ratioHeight) |
|
| 1652 | + ]; |
|
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | 1655 | /** |
@@ -1669,25 +1669,25 @@ discard block |
||
| 1669 | 1669 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1670 | 1670 | **/ |
| 1671 | 1671 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1672 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1673 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1674 | - |
|
| 1675 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1676 | - $destWidth = $srcWidth; |
|
| 1677 | - $destHeight = $srcHeight; |
|
| 1678 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1679 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1680 | - $destHeight = $maxHeight; |
|
| 1681 | - } else { |
|
| 1682 | - $destWidth = $maxWidth; |
|
| 1683 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - return [ |
|
| 1687 | - intval(round($destWidth)), |
|
| 1688 | - intval(round($destHeight)), |
|
| 1689 | - min($ratioWidth, $ratioHeight) |
|
| 1690 | - ]; |
|
| 1672 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1673 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1674 | + |
|
| 1675 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1676 | + $destWidth = $srcWidth; |
|
| 1677 | + $destHeight = $srcHeight; |
|
| 1678 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1679 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1680 | + $destHeight = $maxHeight; |
|
| 1681 | + } else { |
|
| 1682 | + $destWidth = $maxWidth; |
|
| 1683 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + return [ |
|
| 1687 | + intval(round($destWidth)), |
|
| 1688 | + intval(round($destHeight)), |
|
| 1689 | + min($ratioWidth, $ratioHeight) |
|
| 1690 | + ]; |
|
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | |
@@ -1700,12 +1700,12 @@ discard block |
||
| 1700 | 1700 | * @return string |
| 1701 | 1701 | */ |
| 1702 | 1702 | function process_image_svg_identite($image) { |
| 1703 | - if ($image['creer']) { |
|
| 1704 | - $source = $image['fichier']; |
|
| 1705 | - _image_gd_output($source, $image); |
|
| 1706 | - } |
|
| 1703 | + if ($image['creer']) { |
|
| 1704 | + $source = $image['fichier']; |
|
| 1705 | + _image_gd_output($source, $image); |
|
| 1706 | + } |
|
| 1707 | 1707 | |
| 1708 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1708 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | |
@@ -1738,109 +1738,109 @@ discard block |
||
| 1738 | 1738 | * Code HTML de la balise img produite |
| 1739 | 1739 | **/ |
| 1740 | 1740 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1741 | - $image = false; |
|
| 1742 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1743 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1744 | - } |
|
| 1745 | - # determiner le format de sortie |
|
| 1746 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1747 | - if ($process == 'netpbm') { |
|
| 1748 | - $format_sortie = 'jpg'; |
|
| 1749 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1750 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1751 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1752 | - $gd_formats = formats_image_acceptables(true); |
|
| 1753 | - if ( |
|
| 1754 | - is_array($image) |
|
| 1755 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1756 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1757 | - ) |
|
| 1758 | - ) { |
|
| 1759 | - if ($image['format_source'] == 'jpg') { |
|
| 1760 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1761 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1762 | - { |
|
| 1763 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1764 | - } |
|
| 1765 | - // Choisir le format destination |
|
| 1766 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1767 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1768 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1769 | - # pas *ecrire* |
|
| 1770 | - $format_sortie = ''; |
|
| 1771 | - foreach ($formats_sortie as $fmt) { |
|
| 1772 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1773 | - $format_sortie = $fmt; |
|
| 1774 | - break; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - $image = false; |
|
| 1778 | - } |
|
| 1779 | - } |
|
| 1780 | - |
|
| 1781 | - if (!is_array($image)) { |
|
| 1782 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1786 | - spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1787 | - // on peut resizer en mode html si on dispose des elements |
|
| 1788 | - [$srcw, $srch] = taille_image($img); |
|
| 1789 | - if ($srcw and $srch) { |
|
| 1790 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1791 | - |
|
| 1792 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1793 | - } |
|
| 1794 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1795 | - // sous la forme style='max-width: NNpx;' |
|
| 1796 | - return inserer_attribut( |
|
| 1797 | - $img, |
|
| 1798 | - 'style', |
|
| 1799 | - "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1800 | - ); |
|
| 1801 | - } |
|
| 1802 | - |
|
| 1803 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1804 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1805 | - if ($image['creer']) { |
|
| 1806 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - if ($image['creer'] == false && !$force) { |
|
| 1813 | - return _image_ecrire_tag( |
|
| 1814 | - $image, |
|
| 1815 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1816 | - ); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1820 | - $destWidth = $image['largeur_dest']; |
|
| 1821 | - $destHeight = $image['hauteur_dest']; |
|
| 1822 | - $logo = $image['fichier']; |
|
| 1823 | - $date = $image['date_src']; |
|
| 1824 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1825 | - |
|
| 1826 | - if ($preview && $preview['fichier']) { |
|
| 1827 | - $logo = $preview['fichier']; |
|
| 1828 | - $destWidth = $preview['width']; |
|
| 1829 | - $destHeight = $preview['height']; |
|
| 1830 | - $date = $preview['date']; |
|
| 1831 | - } |
|
| 1832 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1833 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1834 | - // quand on fait supprimer/reuploader un logo |
|
| 1835 | - // (pas de filemtime si SAFE MODE) |
|
| 1836 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1837 | - |
|
| 1838 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1839 | - } |
|
| 1840 | - else { |
|
| 1841 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1842 | - return $img; |
|
| 1843 | - } |
|
| 1741 | + $image = false; |
|
| 1742 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1743 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1744 | + } |
|
| 1745 | + # determiner le format de sortie |
|
| 1746 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1747 | + if ($process == 'netpbm') { |
|
| 1748 | + $format_sortie = 'jpg'; |
|
| 1749 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1750 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1751 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1752 | + $gd_formats = formats_image_acceptables(true); |
|
| 1753 | + if ( |
|
| 1754 | + is_array($image) |
|
| 1755 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1756 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1757 | + ) |
|
| 1758 | + ) { |
|
| 1759 | + if ($image['format_source'] == 'jpg') { |
|
| 1760 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1761 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1762 | + { |
|
| 1763 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1764 | + } |
|
| 1765 | + // Choisir le format destination |
|
| 1766 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1767 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1768 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1769 | + # pas *ecrire* |
|
| 1770 | + $format_sortie = ''; |
|
| 1771 | + foreach ($formats_sortie as $fmt) { |
|
| 1772 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1773 | + $format_sortie = $fmt; |
|
| 1774 | + break; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + $image = false; |
|
| 1778 | + } |
|
| 1779 | + } |
|
| 1780 | + |
|
| 1781 | + if (!is_array($image)) { |
|
| 1782 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1786 | + spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1787 | + // on peut resizer en mode html si on dispose des elements |
|
| 1788 | + [$srcw, $srch] = taille_image($img); |
|
| 1789 | + if ($srcw and $srch) { |
|
| 1790 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1791 | + |
|
| 1792 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1793 | + } |
|
| 1794 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1795 | + // sous la forme style='max-width: NNpx;' |
|
| 1796 | + return inserer_attribut( |
|
| 1797 | + $img, |
|
| 1798 | + 'style', |
|
| 1799 | + "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1800 | + ); |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1804 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1805 | + if ($image['creer']) { |
|
| 1806 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + if ($image['creer'] == false && !$force) { |
|
| 1813 | + return _image_ecrire_tag( |
|
| 1814 | + $image, |
|
| 1815 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1816 | + ); |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1820 | + $destWidth = $image['largeur_dest']; |
|
| 1821 | + $destHeight = $image['hauteur_dest']; |
|
| 1822 | + $logo = $image['fichier']; |
|
| 1823 | + $date = $image['date_src']; |
|
| 1824 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1825 | + |
|
| 1826 | + if ($preview && $preview['fichier']) { |
|
| 1827 | + $logo = $preview['fichier']; |
|
| 1828 | + $destWidth = $preview['width']; |
|
| 1829 | + $destHeight = $preview['height']; |
|
| 1830 | + $date = $preview['date']; |
|
| 1831 | + } |
|
| 1832 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1833 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1834 | + // quand on fait supprimer/reuploader un logo |
|
| 1835 | + // (pas de filemtime si SAFE MODE) |
|
| 1836 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1837 | + |
|
| 1838 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1839 | + } |
|
| 1840 | + else { |
|
| 1841 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1842 | + return $img; |
|
| 1843 | + } |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | /** |
@@ -1854,145 +1854,145 @@ discard block |
||
| 1854 | 1854 | * Class phpthumb_functions |
| 1855 | 1855 | */ |
| 1856 | 1856 | class phpthumb_functions { |
| 1857 | - /** |
|
| 1858 | - * Retourne la couleur d'un pixel dans une image |
|
| 1859 | - * |
|
| 1860 | - * @param resource|GdImage $img |
|
| 1861 | - * @param int $x |
|
| 1862 | - * @param int $y |
|
| 1863 | - * @return array|bool |
|
| 1864 | - */ |
|
| 1865 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1866 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1867 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1868 | - } |
|
| 1869 | - return false; |
|
| 1870 | - } |
|
| 1871 | - |
|
| 1872 | - /** |
|
| 1873 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1874 | - * |
|
| 1875 | - * @param int $number |
|
| 1876 | - * @param int $minbytes |
|
| 1877 | - * @return string |
|
| 1878 | - */ |
|
| 1879 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1880 | - $intstring = ''; |
|
| 1881 | - while ($number > 0) { |
|
| 1882 | - $intstring = $intstring . chr($number & 255); |
|
| 1883 | - $number >>= 8; |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - /** |
|
| 1890 | - * Transforme une ressource GD en image au format ICO |
|
| 1891 | - * |
|
| 1892 | - * @param array $gd_image_array |
|
| 1893 | - * Tableau de ressources d'images GD |
|
| 1894 | - * @return string |
|
| 1895 | - * Image au format ICO |
|
| 1896 | - */ |
|
| 1897 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1898 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1899 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1900 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1901 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1902 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1903 | - |
|
| 1904 | - $icXOR[$key] = ''; |
|
| 1905 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1906 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1907 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1908 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1909 | - $r = $argb['red']; |
|
| 1910 | - $g = $argb['green']; |
|
| 1911 | - $b = $argb['blue']; |
|
| 1912 | - |
|
| 1913 | - if ($bpp[$key] == 32) { |
|
| 1914 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1915 | - } elseif ($bpp[$key] == 24) { |
|
| 1916 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1917 | - } |
|
| 1918 | - |
|
| 1919 | - if ($a < 128) { |
|
| 1920 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1921 | - } else { |
|
| 1922 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1923 | - } |
|
| 1924 | - } |
|
| 1925 | - // mask bits are 32-bit aligned per scanline |
|
| 1926 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1927 | - $icANDmask[$key][$y] .= '0'; |
|
| 1928 | - } |
|
| 1929 | - } |
|
| 1930 | - $icAND[$key] = ''; |
|
| 1931 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1932 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1933 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1939 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1940 | - |
|
| 1941 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1942 | - $BitmapInfoHeader[$key] = ''; |
|
| 1943 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1944 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1945 | - // The biHeight member specifies the combined |
|
| 1946 | - // height of the XOR and AND masks. |
|
| 1947 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1948 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1949 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1950 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1951 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1952 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1953 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1954 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1955 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - |
|
| 1959 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1960 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1961 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1962 | - |
|
| 1963 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1964 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1965 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1966 | - |
|
| 1967 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1968 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1969 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1970 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1971 | - |
|
| 1972 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1973 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1974 | - |
|
| 1975 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1976 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1977 | - $dwBytesInRes, |
|
| 1978 | - 4 |
|
| 1979 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1980 | - |
|
| 1981 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1982 | - $dwImageOffset, |
|
| 1983 | - 4 |
|
| 1984 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1985 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1986 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1987 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1988 | - } |
|
| 1989 | - |
|
| 1990 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1991 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1992 | - $icondata .= $icXOR[$key]; |
|
| 1993 | - $icondata .= $icAND[$key]; |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - return $icondata; |
|
| 1997 | - } |
|
| 1857 | + /** |
|
| 1858 | + * Retourne la couleur d'un pixel dans une image |
|
| 1859 | + * |
|
| 1860 | + * @param resource|GdImage $img |
|
| 1861 | + * @param int $x |
|
| 1862 | + * @param int $y |
|
| 1863 | + * @return array|bool |
|
| 1864 | + */ |
|
| 1865 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1866 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1867 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1868 | + } |
|
| 1869 | + return false; |
|
| 1870 | + } |
|
| 1871 | + |
|
| 1872 | + /** |
|
| 1873 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1874 | + * |
|
| 1875 | + * @param int $number |
|
| 1876 | + * @param int $minbytes |
|
| 1877 | + * @return string |
|
| 1878 | + */ |
|
| 1879 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1880 | + $intstring = ''; |
|
| 1881 | + while ($number > 0) { |
|
| 1882 | + $intstring = $intstring . chr($number & 255); |
|
| 1883 | + $number >>= 8; |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + /** |
|
| 1890 | + * Transforme une ressource GD en image au format ICO |
|
| 1891 | + * |
|
| 1892 | + * @param array $gd_image_array |
|
| 1893 | + * Tableau de ressources d'images GD |
|
| 1894 | + * @return string |
|
| 1895 | + * Image au format ICO |
|
| 1896 | + */ |
|
| 1897 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1898 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1899 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1900 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1901 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1902 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1903 | + |
|
| 1904 | + $icXOR[$key] = ''; |
|
| 1905 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1906 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1907 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1908 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1909 | + $r = $argb['red']; |
|
| 1910 | + $g = $argb['green']; |
|
| 1911 | + $b = $argb['blue']; |
|
| 1912 | + |
|
| 1913 | + if ($bpp[$key] == 32) { |
|
| 1914 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1915 | + } elseif ($bpp[$key] == 24) { |
|
| 1916 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1917 | + } |
|
| 1918 | + |
|
| 1919 | + if ($a < 128) { |
|
| 1920 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1921 | + } else { |
|
| 1922 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1923 | + } |
|
| 1924 | + } |
|
| 1925 | + // mask bits are 32-bit aligned per scanline |
|
| 1926 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1927 | + $icANDmask[$key][$y] .= '0'; |
|
| 1928 | + } |
|
| 1929 | + } |
|
| 1930 | + $icAND[$key] = ''; |
|
| 1931 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1932 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1933 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1939 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1940 | + |
|
| 1941 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1942 | + $BitmapInfoHeader[$key] = ''; |
|
| 1943 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1944 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1945 | + // The biHeight member specifies the combined |
|
| 1946 | + // height of the XOR and AND masks. |
|
| 1947 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1948 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1949 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1950 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1951 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1952 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1953 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1954 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1955 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + |
|
| 1959 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1960 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1961 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1962 | + |
|
| 1963 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1964 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1965 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1966 | + |
|
| 1967 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1968 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1969 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1970 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1971 | + |
|
| 1972 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1973 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1974 | + |
|
| 1975 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1976 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1977 | + $dwBytesInRes, |
|
| 1978 | + 4 |
|
| 1979 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1980 | + |
|
| 1981 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1982 | + $dwImageOffset, |
|
| 1983 | + 4 |
|
| 1984 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1985 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1986 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1987 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1988 | + } |
|
| 1989 | + |
|
| 1990 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1991 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1992 | + $icondata .= $icXOR[$key]; |
|
| 1993 | + $icondata .= $icAND[$key]; |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + return $icondata; |
|
| 1997 | + } |
|
| 1998 | 1998 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | define('_PHP_MAX', '8.2.99'); |
| 39 | 39 | |
| 40 | 40 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 41 | - /** le nom du repertoire ecrire/ */ |
|
| 42 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 41 | + /** le nom du repertoire ecrire/ */ |
|
| 42 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** Chemin relatif pour aller dans ecrire |
| 46 | 46 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 47 | 47 | define( |
| 48 | - '_DIR_RESTREINT', |
|
| 49 | - (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 48 | + '_DIR_RESTREINT', |
|
| 49 | + (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | /** Chemin relatif pour aller à la racine */ |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | // Icones |
| 63 | 63 | if (!defined('_NOM_IMG_PACK')) { |
| 64 | - /** Nom du dossier images */ |
|
| 65 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 64 | + /** Nom du dossier images */ |
|
| 65 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 66 | 66 | } |
| 67 | 67 | /** le chemin http (relatif) vers les images standard */ |
| 68 | 68 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 72 | 72 | |
| 73 | 73 | if (!defined('_JAVASCRIPT')) { |
| 74 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 75 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 74 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 75 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 76 | 76 | } // utilisable avec #CHEMIN et find_in_path |
| 77 | 77 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 78 | 78 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -82,47 +82,47 @@ discard block |
||
| 82 | 82 | # mais on peut les mettre ailleurs et changer completement les noms |
| 83 | 83 | |
| 84 | 84 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 85 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 86 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 85 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 86 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 87 | 87 | } |
| 88 | 88 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 89 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 90 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 89 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 90 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 91 | 91 | } |
| 92 | 92 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 93 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 94 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 93 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 94 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 95 | 95 | } |
| 96 | 96 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 97 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 98 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 97 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 98 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | /** Le nom du fichier de personnalisation */ |
| 103 | 103 | if (!defined('_NOM_CONFIG')) { |
| 104 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 104 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Son emplacement absolu si on le trouve |
| 108 | 108 | if ( |
| 109 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 110 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 109 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 110 | + or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 111 | 111 | ) { |
| 112 | - /** Emplacement absolu du fichier d'option */ |
|
| 113 | - define('_FILE_OPTIONS', $f); |
|
| 112 | + /** Emplacement absolu du fichier d'option */ |
|
| 113 | + define('_FILE_OPTIONS', $f); |
|
| 114 | 114 | } else { |
| 115 | - define('_FILE_OPTIONS', ''); |
|
| 115 | + define('_FILE_OPTIONS', ''); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (!defined('MODULES_IDIOMES')) { |
| 119 | - /** |
|
| 120 | - * Modules par défaut pour la traduction. |
|
| 121 | - * |
|
| 122 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 123 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 124 | - */ |
|
| 125 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 119 | + /** |
|
| 120 | + * Modules par défaut pour la traduction. |
|
| 121 | + * |
|
| 122 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 123 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 124 | + */ |
|
| 125 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // *** Fin des define *** // |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | // inclure l'ecran de securite |
| 132 | 132 | if ( |
| 133 | - !defined('_ECRAN_SECURITE') |
|
| 134 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 133 | + !defined('_ECRAN_SECURITE') |
|
| 134 | + and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 135 | 135 | ) { |
| 136 | - include $f; |
|
| 136 | + include $f; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | |
@@ -141,30 +141,30 @@ discard block |
||
| 141 | 141 | * Détecteur de robot d'indexation |
| 142 | 142 | */ |
| 143 | 143 | if (!defined('_IS_BOT')) { |
| 144 | - define( |
|
| 145 | - '_IS_BOT', |
|
| 146 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 147 | - and preg_match( |
|
| 148 | - // mots generiques |
|
| 149 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 150 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 151 | - . 'MSIE 6\.0|' |
|
| 152 | - // UA plus cibles |
|
| 153 | - . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 154 | - . ',i', |
|
| 155 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 156 | - ) |
|
| 157 | - ); |
|
| 144 | + define( |
|
| 145 | + '_IS_BOT', |
|
| 146 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 147 | + and preg_match( |
|
| 148 | + // mots generiques |
|
| 149 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 150 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 151 | + . 'MSIE 6\.0|' |
|
| 152 | + // UA plus cibles |
|
| 153 | + . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 154 | + . ',i', |
|
| 155 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 156 | + ) |
|
| 157 | + ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | if (!defined('_IS_CLI')) { |
| 161 | - define( |
|
| 162 | - '_IS_CLI', |
|
| 163 | - !isset($_SERVER['HTTP_HOST']) |
|
| 164 | - and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 165 | - and !empty($_SERVER['argv']) |
|
| 166 | - and empty($_SERVER['REQUEST_METHOD']) |
|
| 167 | - ); |
|
| 161 | + define( |
|
| 162 | + '_IS_CLI', |
|
| 163 | + !isset($_SERVER['HTTP_HOST']) |
|
| 164 | + and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 165 | + and !empty($_SERVER['argv']) |
|
| 166 | + and empty($_SERVER['REQUEST_METHOD']) |
|
| 167 | + ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // *** Parametrage par defaut de SPIP *** |
@@ -176,61 +176,61 @@ discard block |
||
| 176 | 176 | // Ne pas les rendre indefinies. |
| 177 | 177 | |
| 178 | 178 | global |
| 179 | - $nombre_de_logs, |
|
| 180 | - $taille_des_logs, |
|
| 181 | - $table_prefix, |
|
| 182 | - $cookie_prefix, |
|
| 183 | - $dossier_squelettes, |
|
| 184 | - $filtrer_javascript, |
|
| 185 | - $type_urls, |
|
| 186 | - $debut_date_publication, |
|
| 187 | - $ip, |
|
| 188 | - $mysql_rappel_connexion, |
|
| 189 | - $mysql_rappel_nom_base, |
|
| 190 | - $test_i18n, |
|
| 191 | - $ignore_auth_http, |
|
| 192 | - $ignore_remote_user, |
|
| 193 | - $derniere_modif_invalide, |
|
| 194 | - $home_server, |
|
| 195 | - $help_server, |
|
| 196 | - $url_glossaire_externe, |
|
| 197 | - $tex_server, |
|
| 198 | - $traiter_math, |
|
| 199 | - $xhtml, |
|
| 200 | - $xml_indent, |
|
| 201 | - $source_vignettes, |
|
| 202 | - $formats_logos, |
|
| 203 | - $controler_dates_rss, |
|
| 204 | - $spip_pipeline, |
|
| 205 | - $spip_matrice, |
|
| 206 | - $plugins, |
|
| 207 | - $surcharges, |
|
| 208 | - $exceptions_des_tables, |
|
| 209 | - $tables_principales, |
|
| 210 | - $table_des_tables, |
|
| 211 | - $tables_auxiliaires, |
|
| 212 | - $table_primary, |
|
| 213 | - $table_date, |
|
| 214 | - $table_titre, |
|
| 215 | - $tables_jointures, |
|
| 216 | - $liste_des_statuts, |
|
| 217 | - $liste_des_etats, |
|
| 218 | - $liste_des_authentifications, |
|
| 219 | - $spip_version_branche, |
|
| 220 | - $spip_version_code, |
|
| 221 | - $spip_version_base, |
|
| 222 | - $spip_sql_version, |
|
| 223 | - $spip_version_affichee, |
|
| 224 | - $visiteur_session, |
|
| 225 | - $auteur_session, |
|
| 226 | - $connect_statut, |
|
| 227 | - $connect_toutes_rubriques, |
|
| 228 | - $hash_recherche, |
|
| 229 | - $hash_recherche_strict, |
|
| 230 | - $ldap_present, |
|
| 231 | - $meta, |
|
| 232 | - $connect_id_rubrique, |
|
| 233 | - $puce; |
|
| 179 | + $nombre_de_logs, |
|
| 180 | + $taille_des_logs, |
|
| 181 | + $table_prefix, |
|
| 182 | + $cookie_prefix, |
|
| 183 | + $dossier_squelettes, |
|
| 184 | + $filtrer_javascript, |
|
| 185 | + $type_urls, |
|
| 186 | + $debut_date_publication, |
|
| 187 | + $ip, |
|
| 188 | + $mysql_rappel_connexion, |
|
| 189 | + $mysql_rappel_nom_base, |
|
| 190 | + $test_i18n, |
|
| 191 | + $ignore_auth_http, |
|
| 192 | + $ignore_remote_user, |
|
| 193 | + $derniere_modif_invalide, |
|
| 194 | + $home_server, |
|
| 195 | + $help_server, |
|
| 196 | + $url_glossaire_externe, |
|
| 197 | + $tex_server, |
|
| 198 | + $traiter_math, |
|
| 199 | + $xhtml, |
|
| 200 | + $xml_indent, |
|
| 201 | + $source_vignettes, |
|
| 202 | + $formats_logos, |
|
| 203 | + $controler_dates_rss, |
|
| 204 | + $spip_pipeline, |
|
| 205 | + $spip_matrice, |
|
| 206 | + $plugins, |
|
| 207 | + $surcharges, |
|
| 208 | + $exceptions_des_tables, |
|
| 209 | + $tables_principales, |
|
| 210 | + $table_des_tables, |
|
| 211 | + $tables_auxiliaires, |
|
| 212 | + $table_primary, |
|
| 213 | + $table_date, |
|
| 214 | + $table_titre, |
|
| 215 | + $tables_jointures, |
|
| 216 | + $liste_des_statuts, |
|
| 217 | + $liste_des_etats, |
|
| 218 | + $liste_des_authentifications, |
|
| 219 | + $spip_version_branche, |
|
| 220 | + $spip_version_code, |
|
| 221 | + $spip_version_base, |
|
| 222 | + $spip_sql_version, |
|
| 223 | + $spip_version_affichee, |
|
| 224 | + $visiteur_session, |
|
| 225 | + $auteur_session, |
|
| 226 | + $connect_statut, |
|
| 227 | + $connect_toutes_rubriques, |
|
| 228 | + $hash_recherche, |
|
| 229 | + $hash_recherche_strict, |
|
| 230 | + $ldap_present, |
|
| 231 | + $meta, |
|
| 232 | + $connect_id_rubrique, |
|
| 233 | + $puce; |
|
| 234 | 234 | |
| 235 | 235 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 236 | 236 | $nombre_de_logs = 4; |
@@ -285,48 +285,48 @@ discard block |
||
| 285 | 285 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 286 | 286 | // |
| 287 | 287 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 288 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 289 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 290 | - } |
|
| 291 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 292 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 293 | - } |
|
| 288 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 289 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 290 | + } |
|
| 291 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 292 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 293 | + } |
|
| 294 | 294 | } |
| 295 | 295 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 296 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 297 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 298 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 299 | - $_SERVER['HTTPS'] = 'on'; |
|
| 300 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 301 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 306 | - if (strpos($host, ',') !== false) { |
|
| 307 | - $h = explode(',', $host); |
|
| 308 | - $host = trim(reset($h)); |
|
| 309 | - } |
|
| 310 | - // securite sur le contenu de l'entete |
|
| 311 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 312 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 296 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 297 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 298 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 299 | + $_SERVER['HTTPS'] = 'on'; |
|
| 300 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 301 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 306 | + if (strpos($host, ',') !== false) { |
|
| 307 | + $h = explode(',', $host); |
|
| 308 | + $host = trim(reset($h)); |
|
| 309 | + } |
|
| 310 | + // securite sur le contenu de l'entete |
|
| 311 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 312 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 313 | 313 | } |
| 314 | 314 | // |
| 315 | 315 | // On note le numero IP du client dans la variable $ip |
| 316 | 316 | // |
| 317 | 317 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 318 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 319 | - if (strpos($ip, ',') !== false) { |
|
| 320 | - $ip = explode(',', $ip); |
|
| 321 | - $ip = reset($ip); |
|
| 322 | - } |
|
| 323 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 324 | - if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 325 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 326 | - } |
|
| 318 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 319 | + if (strpos($ip, ',') !== false) { |
|
| 320 | + $ip = explode(',', $ip); |
|
| 321 | + $ip = reset($ip); |
|
| 322 | + } |
|
| 323 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 324 | + if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 325 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 326 | + } |
|
| 327 | 327 | } |
| 328 | 328 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 329 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 329 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -411,24 +411,24 @@ discard block |
||
| 411 | 411 | |
| 412 | 412 | // Liste des statuts. |
| 413 | 413 | $liste_des_statuts = [ |
| 414 | - 'info_administrateurs' => '0minirezo', |
|
| 415 | - 'info_redacteurs' => '1comite', |
|
| 416 | - 'info_visiteurs' => '6forum', |
|
| 417 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 414 | + 'info_administrateurs' => '0minirezo', |
|
| 415 | + 'info_redacteurs' => '1comite', |
|
| 416 | + 'info_visiteurs' => '6forum', |
|
| 417 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 418 | 418 | ]; |
| 419 | 419 | |
| 420 | 420 | $liste_des_etats = [ |
| 421 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 422 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 423 | - 'texte_statut_publie' => 'publie', |
|
| 424 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 425 | - 'texte_statut_refuse' => 'refuse' |
|
| 421 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 422 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 423 | + 'texte_statut_publie' => 'publie', |
|
| 424 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 425 | + 'texte_statut_refuse' => 'refuse' |
|
| 426 | 426 | ]; |
| 427 | 427 | |
| 428 | 428 | // liste des methodes d'authentifications |
| 429 | 429 | $liste_des_authentifications = [ |
| 430 | - 'spip' => 'spip', |
|
| 431 | - 'ldap' => 'ldap' |
|
| 430 | + 'spip' => 'spip', |
|
| 431 | + 'ldap' => 'ldap' |
|
| 432 | 432 | ]; |
| 433 | 433 | |
| 434 | 434 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -478,12 +478,12 @@ discard block |
||
| 478 | 478 | // Definition personnelles eventuelles |
| 479 | 479 | |
| 480 | 480 | if (_FILE_OPTIONS) { |
| 481 | - include_once _FILE_OPTIONS; |
|
| 481 | + include_once _FILE_OPTIONS; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 485 | - /** Masquer les warning */ |
|
| 486 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 485 | + /** Masquer les warning */ |
|
| 486 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 487 | 487 | } |
| 488 | 488 | error_reporting(SPIP_ERREUR_REPORT); |
| 489 | 489 | |
@@ -496,10 +496,10 @@ discard block |
||
| 496 | 496 | // ===> on execute en neutralisant les messages d'erreur |
| 497 | 497 | |
| 498 | 498 | spip_initialisation_core( |
| 499 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 501 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 502 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 499 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 500 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 501 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 502 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 503 | 503 | ); |
| 504 | 504 | |
| 505 | 505 | |
@@ -509,71 +509,71 @@ discard block |
||
| 509 | 509 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 510 | 510 | |
| 511 | 511 | if (@is_readable(_CACHE_PLUGINS_OPT) and @is_readable(_CACHE_PLUGINS_PATH)) { |
| 512 | - // chargement optimise precompile |
|
| 513 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 512 | + // chargement optimise precompile |
|
| 513 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 514 | 514 | } else { |
| 515 | - spip_initialisation_suite(); |
|
| 516 | - include_spip('inc/plugin'); |
|
| 517 | - // generer les fichiers php precompiles |
|
| 518 | - // de chargement des plugins et des pipelines |
|
| 519 | - actualise_plugins_actifs(); |
|
| 515 | + spip_initialisation_suite(); |
|
| 516 | + include_spip('inc/plugin'); |
|
| 517 | + // generer les fichiers php precompiles |
|
| 518 | + // de chargement des plugins et des pipelines |
|
| 519 | + actualise_plugins_actifs(); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | // Initialisations non critiques surchargeables par les plugins |
| 523 | 523 | spip_initialisation_suite(); |
| 524 | 524 | |
| 525 | 525 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 526 | - /** niveau maxi d'enregistrement des logs */ |
|
| 527 | - define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 526 | + /** niveau maxi d'enregistrement des logs */ |
|
| 527 | + define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 531 | - /** Activer des outils pour développeurs ? */ |
|
| 532 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 531 | + /** Activer des outils pour développeurs ? */ |
|
| 532 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 536 | 536 | if (test_espace_prive()) { |
| 537 | - include_spip('inc/autoriser'); |
|
| 537 | + include_spip('inc/autoriser'); |
|
| 538 | 538 | } |
| 539 | 539 | // |
| 540 | 540 | // Installer Spip si pas installe... sauf si justement on est en train |
| 541 | 541 | // |
| 542 | 542 | if ( |
| 543 | - !(_FILE_CONNECT |
|
| 544 | - or autoriser_sans_cookie(_request('exec')) |
|
| 545 | - or _request('action') == 'cookie' |
|
| 546 | - or _request('action') == 'converser' |
|
| 547 | - or _request('action') == 'test_dirs') |
|
| 543 | + !(_FILE_CONNECT |
|
| 544 | + or autoriser_sans_cookie(_request('exec')) |
|
| 545 | + or _request('action') == 'cookie' |
|
| 546 | + or _request('action') == 'converser' |
|
| 547 | + or _request('action') == 'test_dirs') |
|
| 548 | 548 | ) { |
| 549 | - // Si on peut installer, on lance illico |
|
| 550 | - if (test_espace_prive()) { |
|
| 551 | - include_spip('inc/headers'); |
|
| 552 | - redirige_url_ecrire('install'); |
|
| 553 | - } else { |
|
| 554 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 555 | - include_spip('inc/lang'); |
|
| 556 | - utiliser_langue_visiteur(); |
|
| 557 | - include_spip('inc/minipres'); |
|
| 558 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 559 | - exit; |
|
| 560 | - } |
|
| 561 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 549 | + // Si on peut installer, on lance illico |
|
| 550 | + if (test_espace_prive()) { |
|
| 551 | + include_spip('inc/headers'); |
|
| 552 | + redirige_url_ecrire('install'); |
|
| 553 | + } else { |
|
| 554 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 555 | + include_spip('inc/lang'); |
|
| 556 | + utiliser_langue_visiteur(); |
|
| 557 | + include_spip('inc/minipres'); |
|
| 558 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 559 | + exit; |
|
| 560 | + } |
|
| 561 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | // memoriser un tri sessionne eventuel |
| 565 | 565 | if ( |
| 566 | - isset($_REQUEST['var_memotri']) |
|
| 567 | - and $t = $_REQUEST['var_memotri'] |
|
| 568 | - and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 566 | + isset($_REQUEST['var_memotri']) |
|
| 567 | + and $t = $_REQUEST['var_memotri'] |
|
| 568 | + and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 569 | 569 | ) { |
| 570 | - if (!function_exists('session_set')) { |
|
| 571 | - include_spip('inc/session'); |
|
| 572 | - } |
|
| 573 | - $t = preg_replace(',\W,', '_', $t); |
|
| 574 | - if ($v = _request($t)) { |
|
| 575 | - session_set($t, $v); |
|
| 576 | - } |
|
| 570 | + if (!function_exists('session_set')) { |
|
| 571 | + include_spip('inc/session'); |
|
| 572 | + } |
|
| 573 | + $t = preg_replace(',\W,', '_', $t); |
|
| 574 | + if ($v = _request($t)) { |
|
| 575 | + session_set($t, $v); |
|
| 576 | + } |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -583,22 +583,22 @@ discard block |
||
| 583 | 583 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 584 | 584 | */ |
| 585 | 585 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 586 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 586 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 587 | 587 | } |
| 588 | 588 | if (!headers_sent() and _HEADER_COMPOSED_BY) { |
| 589 | - if (!defined('_HEADER_VARY')) { |
|
| 590 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 591 | - } |
|
| 592 | - if (_HEADER_VARY) { |
|
| 593 | - header(_HEADER_VARY); |
|
| 594 | - } |
|
| 595 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 596 | - include_spip('inc/filtres_mini'); |
|
| 597 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 598 | - } else { |
|
| 599 | - // header minimal |
|
| 600 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 601 | - } |
|
| 589 | + if (!defined('_HEADER_VARY')) { |
|
| 590 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 591 | + } |
|
| 592 | + if (_HEADER_VARY) { |
|
| 593 | + header(_HEADER_VARY); |
|
| 594 | + } |
|
| 595 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 596 | + include_spip('inc/filtres_mini'); |
|
| 597 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 598 | + } else { |
|
| 599 | + // header minimal |
|
| 600 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 601 | + } |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |
@@ -10,169 +10,169 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/headers'); |
| 17 | 17 | |
| 18 | 18 | function install_etape_3b_dist() { |
| 19 | - $auth_spip = null; |
|
| 20 | - $session = null; |
|
| 21 | - $row = null; |
|
| 22 | - $login = _request('login'); |
|
| 23 | - $email = _request('email'); |
|
| 24 | - $nom = _request('nom'); |
|
| 25 | - $pass = _request('pass'); |
|
| 26 | - $pass_verif = _request('pass_verif'); |
|
| 27 | - |
|
| 28 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 29 | - ? _INSTALL_SERVER_DB |
|
| 30 | - : _request('server_db'); |
|
| 31 | - |
|
| 32 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 33 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 34 | - } |
|
| 35 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 36 | - define('_LOGIN_TROP_COURT', 4); |
|
| 37 | - } |
|
| 38 | - if ($login) { |
|
| 39 | - $echec = ($pass != $pass_verif) ? |
|
| 40 | - _T('info_passes_identiques') |
|
| 41 | - : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 42 | - _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]) |
|
| 43 | - : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 44 | - _T('info_login_trop_court') |
|
| 45 | - : '')); |
|
| 46 | - include_spip('inc/filtres'); |
|
| 47 | - if (!$echec and $email and !email_valide($email)) { |
|
| 48 | - $echec = _T('form_email_non_valide'); |
|
| 49 | - } |
|
| 50 | - if ($echec) { |
|
| 51 | - echouer_etape_3b($echec); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 56 | - include(_FILE_CHMOD_TMP); |
|
| 57 | - } else { |
|
| 58 | - redirige_url_ecrire('install'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 62 | - redirige_url_ecrire('install'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 66 | - # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 67 | - # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 68 | - |
|
| 69 | - lire_metas(); |
|
| 70 | - if ($login) { |
|
| 71 | - include_spip('inc/charsets'); |
|
| 72 | - |
|
| 73 | - $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 74 | - $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 75 | - $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 76 | - |
|
| 77 | - include_spip('auth/spip'); |
|
| 78 | - // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 79 | - // sur une vieille base |
|
| 80 | - $t = sql_showtable('spip_auteurs', true); |
|
| 81 | - if (!isset($t['field']['webmestre'])) { |
|
| 82 | - @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // il faut avoir une cle des auth valide pour creer un nouvel auteur webmestre |
|
| 86 | - $cles = \Spip\Chiffrer\SpipCles::instance(); |
|
| 87 | - $secret = $cles->getSecretAuth(); |
|
| 88 | - |
|
| 89 | - $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 90 | - if ($id_auteur !== null) { |
|
| 91 | - // c'est un auteur connu : si on a pas de secret il faut absolument qu'il se reconnecte avec le meme mot de passe |
|
| 92 | - // pour restaurer la copie des cles |
|
| 93 | - if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 94 | - $row = sql_fetsel('backup_cles, pass', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 95 | - if (empty($row['backup_cles']) or !$cles->restore($row['backup_cles'], $pass, $row['pass'], $id_auteur)) { |
|
| 96 | - $echec = _T('avis_connexion_erreur_fichier_cle_manquant_1'); |
|
| 97 | - echouer_etape_3b($echec); |
|
| 98 | - } |
|
| 99 | - spip_log("Les cles secretes ont ete restaurées avec le backup du webmestre #$id_auteur", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 100 | - $cles->save(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - sql_updateq('spip_auteurs', [ |
|
| 104 | - 'nom' => $nom, |
|
| 105 | - 'email' => $email, |
|
| 106 | - 'login' => $login, |
|
| 107 | - 'statut' => '0minirezo' |
|
| 108 | - ], 'id_auteur=' . intval($id_auteur)); |
|
| 109 | - // le passer webmestre separement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 110 | - @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 111 | - if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 112 | - $echec = _T('avis_erreur_creation_compte'); |
|
| 113 | - echouer_etape_3b($echec); |
|
| 114 | - } |
|
| 115 | - } else { |
|
| 116 | - // Si on a pas de cle et qu'on ne sait pas la creer, on ne peut pas creer de nouveau compte : |
|
| 117 | - // il faut qu'un webmestre avec un backup fasse l'install |
|
| 118 | - if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 119 | - $echec = _T('avis_connexion_erreur_fichier_cle_manquant_2'); |
|
| 120 | - echouer_etape_3b($echec); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $id_auteur = sql_insertq('spip_auteurs', [ |
|
| 124 | - 'nom' => $nom, |
|
| 125 | - 'email' => $email, |
|
| 126 | - 'login' => $login, |
|
| 127 | - 'statut' => '0minirezo' |
|
| 128 | - ]); |
|
| 129 | - // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 130 | - @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 131 | - if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 132 | - $echec = _T('avis_erreur_creation_compte'); |
|
| 133 | - echouer_etape_3b($echec); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // inserer email comme email webmaster principal |
|
| 138 | - // (sauf s'il est vide: cas de la re-installation) |
|
| 139 | - if ($email) { |
|
| 140 | - ecrire_meta('email_webmaster', $email); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // Connecter directement celui qui vient de (re)donner son login |
|
| 144 | - // mais sans cookie d'admin ni connexion longue |
|
| 145 | - include_spip('inc/auth'); |
|
| 146 | - if ( |
|
| 147 | - !$auteur = auth_identifier_login($login, $pass) |
|
| 148 | - or !auth_loger($auteur) |
|
| 149 | - ) { |
|
| 150 | - spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // installer les metas |
|
| 155 | - $config = charger_fonction('config', 'inc'); |
|
| 156 | - $config(); |
|
| 157 | - |
|
| 158 | - // activer les plugins |
|
| 159 | - // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 160 | - // poursuivre au hit suivant |
|
| 161 | - include_spip('inc/plugin'); |
|
| 162 | - actualise_plugins_actifs(); |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - include_spip('inc/distant'); |
|
| 166 | - redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 19 | + $auth_spip = null; |
|
| 20 | + $session = null; |
|
| 21 | + $row = null; |
|
| 22 | + $login = _request('login'); |
|
| 23 | + $email = _request('email'); |
|
| 24 | + $nom = _request('nom'); |
|
| 25 | + $pass = _request('pass'); |
|
| 26 | + $pass_verif = _request('pass_verif'); |
|
| 27 | + |
|
| 28 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 29 | + ? _INSTALL_SERVER_DB |
|
| 30 | + : _request('server_db'); |
|
| 31 | + |
|
| 32 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 33 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 34 | + } |
|
| 35 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 36 | + define('_LOGIN_TROP_COURT', 4); |
|
| 37 | + } |
|
| 38 | + if ($login) { |
|
| 39 | + $echec = ($pass != $pass_verif) ? |
|
| 40 | + _T('info_passes_identiques') |
|
| 41 | + : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 42 | + _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]) |
|
| 43 | + : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 44 | + _T('info_login_trop_court') |
|
| 45 | + : '')); |
|
| 46 | + include_spip('inc/filtres'); |
|
| 47 | + if (!$echec and $email and !email_valide($email)) { |
|
| 48 | + $echec = _T('form_email_non_valide'); |
|
| 49 | + } |
|
| 50 | + if ($echec) { |
|
| 51 | + echouer_etape_3b($echec); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 56 | + include(_FILE_CHMOD_TMP); |
|
| 57 | + } else { |
|
| 58 | + redirige_url_ecrire('install'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 62 | + redirige_url_ecrire('install'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 66 | + # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 67 | + # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 68 | + |
|
| 69 | + lire_metas(); |
|
| 70 | + if ($login) { |
|
| 71 | + include_spip('inc/charsets'); |
|
| 72 | + |
|
| 73 | + $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 74 | + $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 75 | + $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 76 | + |
|
| 77 | + include_spip('auth/spip'); |
|
| 78 | + // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 79 | + // sur une vieille base |
|
| 80 | + $t = sql_showtable('spip_auteurs', true); |
|
| 81 | + if (!isset($t['field']['webmestre'])) { |
|
| 82 | + @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // il faut avoir une cle des auth valide pour creer un nouvel auteur webmestre |
|
| 86 | + $cles = \Spip\Chiffrer\SpipCles::instance(); |
|
| 87 | + $secret = $cles->getSecretAuth(); |
|
| 88 | + |
|
| 89 | + $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 90 | + if ($id_auteur !== null) { |
|
| 91 | + // c'est un auteur connu : si on a pas de secret il faut absolument qu'il se reconnecte avec le meme mot de passe |
|
| 92 | + // pour restaurer la copie des cles |
|
| 93 | + if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 94 | + $row = sql_fetsel('backup_cles, pass', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 95 | + if (empty($row['backup_cles']) or !$cles->restore($row['backup_cles'], $pass, $row['pass'], $id_auteur)) { |
|
| 96 | + $echec = _T('avis_connexion_erreur_fichier_cle_manquant_1'); |
|
| 97 | + echouer_etape_3b($echec); |
|
| 98 | + } |
|
| 99 | + spip_log("Les cles secretes ont ete restaurées avec le backup du webmestre #$id_auteur", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 100 | + $cles->save(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + sql_updateq('spip_auteurs', [ |
|
| 104 | + 'nom' => $nom, |
|
| 105 | + 'email' => $email, |
|
| 106 | + 'login' => $login, |
|
| 107 | + 'statut' => '0minirezo' |
|
| 108 | + ], 'id_auteur=' . intval($id_auteur)); |
|
| 109 | + // le passer webmestre separement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 110 | + @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 111 | + if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 112 | + $echec = _T('avis_erreur_creation_compte'); |
|
| 113 | + echouer_etape_3b($echec); |
|
| 114 | + } |
|
| 115 | + } else { |
|
| 116 | + // Si on a pas de cle et qu'on ne sait pas la creer, on ne peut pas creer de nouveau compte : |
|
| 117 | + // il faut qu'un webmestre avec un backup fasse l'install |
|
| 118 | + if (!$secret and !auth_spip_initialiser_secret()) { |
|
| 119 | + $echec = _T('avis_connexion_erreur_fichier_cle_manquant_2'); |
|
| 120 | + echouer_etape_3b($echec); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $id_auteur = sql_insertq('spip_auteurs', [ |
|
| 124 | + 'nom' => $nom, |
|
| 125 | + 'email' => $email, |
|
| 126 | + 'login' => $login, |
|
| 127 | + 'statut' => '0minirezo' |
|
| 128 | + ]); |
|
| 129 | + // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 130 | + @sql_updateq('spip_auteurs', ['webmestre' => 'oui'], "id_auteur=$id_auteur"); |
|
| 131 | + if (!auth_spip_modifier_pass($login, $pass, $id_auteur)) { |
|
| 132 | + $echec = _T('avis_erreur_creation_compte'); |
|
| 133 | + echouer_etape_3b($echec); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // inserer email comme email webmaster principal |
|
| 138 | + // (sauf s'il est vide: cas de la re-installation) |
|
| 139 | + if ($email) { |
|
| 140 | + ecrire_meta('email_webmaster', $email); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // Connecter directement celui qui vient de (re)donner son login |
|
| 144 | + // mais sans cookie d'admin ni connexion longue |
|
| 145 | + include_spip('inc/auth'); |
|
| 146 | + if ( |
|
| 147 | + !$auteur = auth_identifier_login($login, $pass) |
|
| 148 | + or !auth_loger($auteur) |
|
| 149 | + ) { |
|
| 150 | + spip_log("login automatique impossible $auth_spip $session" . (is_countable($row) ? count($row) : 0)); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // installer les metas |
|
| 155 | + $config = charger_fonction('config', 'inc'); |
|
| 156 | + $config(); |
|
| 157 | + |
|
| 158 | + // activer les plugins |
|
| 159 | + // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 160 | + // poursuivre au hit suivant |
|
| 161 | + include_spip('inc/plugin'); |
|
| 162 | + actualise_plugins_actifs(); |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + include_spip('inc/distant'); |
|
| 166 | + redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | function echouer_etape_3b($echec) { |
| 170 | - echo minipres( |
|
| 171 | - 'AUTO', |
|
| 172 | - info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 173 | - "<div class='error'><h3>$echec</h3>\n" . |
|
| 174 | - '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 175 | - '</div>' |
|
| 176 | - ); |
|
| 177 | - exit; |
|
| 170 | + echo minipres( |
|
| 171 | + 'AUTO', |
|
| 172 | + info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 173 | + "<div class='error'><h3>$echec</h3>\n" . |
|
| 174 | + '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 175 | + '</div>' |
|
| 176 | + ); |
|
| 177 | + exit; |
|
| 178 | 178 | } |
@@ -16,17 +16,17 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_UPGRADE_TIME_OUT')) { |
| 23 | - /** |
|
| 24 | - * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 25 | - * avant que la durée d'exécution du script provoque un timeout |
|
| 26 | - * |
|
| 27 | - * @var int |
|
| 28 | - **/ |
|
| 29 | - define('_UPGRADE_TIME_OUT', 20); |
|
| 23 | + /** |
|
| 24 | + * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 25 | + * avant que la durée d'exécution du script provoque un timeout |
|
| 26 | + * |
|
| 27 | + * @var int |
|
| 28 | + **/ |
|
| 29 | + define('_UPGRADE_TIME_OUT', 20); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -49,40 +49,40 @@ discard block |
||
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | 51 | function base_upgrade_dist($titre = '', $reprise = '') { |
| 52 | - if (!$titre) { |
|
| 53 | - return; |
|
| 54 | - } // anti-testeur automatique |
|
| 55 | - if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 56 | - if (!is_numeric(_request('reinstall'))) { |
|
| 57 | - include_spip('base/create'); |
|
| 58 | - spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 59 | - creer_base(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 63 | - // lancement de l'upgrade SPIP |
|
| 64 | - $res = maj_base(); |
|
| 65 | - |
|
| 66 | - if ($res) { |
|
| 67 | - // on arrete tout ici ! |
|
| 68 | - exit; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 72 | - |
|
| 73 | - // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 74 | - @spip_unlink(_CACHE_RUBRIQUES); |
|
| 75 | - @spip_unlink(_CACHE_PIPELINES); |
|
| 76 | - @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 77 | - @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 78 | - @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 79 | - @spip_unlink(_CACHE_CHEMIN); |
|
| 80 | - @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 81 | - |
|
| 82 | - include_spip('inc/auth'); |
|
| 83 | - auth_synchroniser_distant(); |
|
| 84 | - $config = charger_fonction('config', 'inc'); |
|
| 85 | - $config(); |
|
| 52 | + if (!$titre) { |
|
| 53 | + return; |
|
| 54 | + } // anti-testeur automatique |
|
| 55 | + if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 56 | + if (!is_numeric(_request('reinstall'))) { |
|
| 57 | + include_spip('base/create'); |
|
| 58 | + spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 59 | + creer_base(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 63 | + // lancement de l'upgrade SPIP |
|
| 64 | + $res = maj_base(); |
|
| 65 | + |
|
| 66 | + if ($res) { |
|
| 67 | + // on arrete tout ici ! |
|
| 68 | + exit; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 72 | + |
|
| 73 | + // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 74 | + @spip_unlink(_CACHE_RUBRIQUES); |
|
| 75 | + @spip_unlink(_CACHE_PIPELINES); |
|
| 76 | + @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 77 | + @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 78 | + @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 79 | + @spip_unlink(_CACHE_CHEMIN); |
|
| 80 | + @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 81 | + |
|
| 82 | + include_spip('inc/auth'); |
|
| 83 | + auth_synchroniser_distant(); |
|
| 84 | + $config = charger_fonction('config', 'inc'); |
|
| 85 | + $config(); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -113,51 +113,51 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function maj_base($version_cible = 0, $redirect = '', $debut_page = true) { |
| 115 | 115 | |
| 116 | - $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 117 | - |
|
| 118 | - spip_log( |
|
| 119 | - "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 120 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 121 | - ); |
|
| 122 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 123 | - sql_replace( |
|
| 124 | - 'spip_meta', |
|
| 125 | - [ |
|
| 126 | - 'nom' => 'version_installee', |
|
| 127 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 128 | - 'impt' => 'non' |
|
| 129 | - ] |
|
| 130 | - ); |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - if (!upgrade_test()) { |
|
| 134 | - return true; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 138 | - |
|
| 139 | - if ($version_installee < 2021_01_01_00) { |
|
| 140 | - include_spip('maj/legacy/v21'); |
|
| 141 | - include_spip('maj/legacy/v30'); |
|
| 142 | - include_spip('maj/legacy/v31'); |
|
| 143 | - include_spip('maj/legacy/v32'); |
|
| 144 | - include_spip('maj/legacy/v40'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - include_spip('maj/2021'); |
|
| 148 | - |
|
| 149 | - ksort($GLOBALS['maj']); |
|
| 150 | - $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 151 | - if ($res) { |
|
| 152 | - if (!is_array($res)) { |
|
| 153 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 154 | - } else { |
|
| 155 | - echo _T('avis_operation_echec') . ' ' . join(' ', $res); |
|
| 156 | - echo install_fin_html(); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $res; |
|
| 116 | + $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 117 | + |
|
| 118 | + spip_log( |
|
| 119 | + "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 120 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 121 | + ); |
|
| 122 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 123 | + sql_replace( |
|
| 124 | + 'spip_meta', |
|
| 125 | + [ |
|
| 126 | + 'nom' => 'version_installee', |
|
| 127 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 128 | + 'impt' => 'non' |
|
| 129 | + ] |
|
| 130 | + ); |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + if (!upgrade_test()) { |
|
| 134 | + return true; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 138 | + |
|
| 139 | + if ($version_installee < 2021_01_01_00) { |
|
| 140 | + include_spip('maj/legacy/v21'); |
|
| 141 | + include_spip('maj/legacy/v30'); |
|
| 142 | + include_spip('maj/legacy/v31'); |
|
| 143 | + include_spip('maj/legacy/v32'); |
|
| 144 | + include_spip('maj/legacy/v40'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + include_spip('maj/2021'); |
|
| 148 | + |
|
| 149 | + ksort($GLOBALS['maj']); |
|
| 150 | + $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 151 | + if ($res) { |
|
| 152 | + if (!is_array($res)) { |
|
| 153 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 154 | + } else { |
|
| 155 | + echo _T('avis_operation_echec') . ' ' . join(' ', $res); |
|
| 156 | + echo install_fin_html(); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $res; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -199,53 +199,53 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | function maj_plugin($nom_meta_base_version, $version_cible, $maj, $table_meta = 'meta') { |
| 201 | 201 | |
| 202 | - if ($table_meta !== 'meta') { |
|
| 203 | - installer_table_meta($table_meta); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $current_version = null; |
|
| 207 | - |
|
| 208 | - if ( |
|
| 209 | - (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 210 | - || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 211 | - ) { |
|
| 212 | - // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 213 | - // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 214 | - if (isset($maj['create'])) { |
|
| 215 | - if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 216 | - // installation : on ne fait que l'operation create |
|
| 217 | - $maj = ['init' => $maj['create']]; |
|
| 218 | - // et on lui ajoute un appel a inc/config |
|
| 219 | - // pour creer les metas par defaut |
|
| 220 | - $config = charger_fonction('config', 'inc'); |
|
| 221 | - $maj[$version_cible] = [[$config]]; |
|
| 222 | - } |
|
| 223 | - // dans tous les cas enlever cet index du tableau |
|
| 224 | - unset($maj['create']); |
|
| 225 | - } |
|
| 226 | - // si init, deja dans le bon ordre |
|
| 227 | - if (!isset($maj['init'])) { |
|
| 228 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 229 | - uksort($maj, 'spip_version_compare'); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 233 | - // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 234 | - // ou define _REDIRECT_MAJ_PLUGIN |
|
| 235 | - $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 236 | - if (defined('_ECRIRE_INSTALL')) { |
|
| 237 | - $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 241 | - if ($res) { |
|
| 242 | - if (!is_array($res)) { |
|
| 243 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 244 | - } else { |
|
| 245 | - echo '<p>' . _T('avis_operation_echec') . ' ' . join(' ', $res) . '</p>'; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 202 | + if ($table_meta !== 'meta') { |
|
| 203 | + installer_table_meta($table_meta); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $current_version = null; |
|
| 207 | + |
|
| 208 | + if ( |
|
| 209 | + (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 210 | + || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 211 | + ) { |
|
| 212 | + // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 213 | + // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 214 | + if (isset($maj['create'])) { |
|
| 215 | + if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 216 | + // installation : on ne fait que l'operation create |
|
| 217 | + $maj = ['init' => $maj['create']]; |
|
| 218 | + // et on lui ajoute un appel a inc/config |
|
| 219 | + // pour creer les metas par defaut |
|
| 220 | + $config = charger_fonction('config', 'inc'); |
|
| 221 | + $maj[$version_cible] = [[$config]]; |
|
| 222 | + } |
|
| 223 | + // dans tous les cas enlever cet index du tableau |
|
| 224 | + unset($maj['create']); |
|
| 225 | + } |
|
| 226 | + // si init, deja dans le bon ordre |
|
| 227 | + if (!isset($maj['init'])) { |
|
| 228 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 229 | + uksort($maj, 'spip_version_compare'); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 233 | + // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 234 | + // ou define _REDIRECT_MAJ_PLUGIN |
|
| 235 | + $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 236 | + if (defined('_ECRIRE_INSTALL')) { |
|
| 237 | + $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 241 | + if ($res) { |
|
| 242 | + if (!is_array($res)) { |
|
| 243 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 244 | + } else { |
|
| 245 | + echo '<p>' . _T('avis_operation_echec') . ' ' . join(' ', $res) . '</p>'; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -262,17 +262,17 @@ discard block |
||
| 262 | 262 | * @return void |
| 263 | 263 | */ |
| 264 | 264 | function relance_maj($meta, $table, $redirect = '') { |
| 265 | - include_spip('inc/headers'); |
|
| 266 | - if (!$redirect) { |
|
| 267 | - // recuperer la valeur installee en cours |
|
| 268 | - // on la tronque numeriquement, elle ne sert pas reellement |
|
| 269 | - // sauf pour verifier que ce n'est pas oui ou non |
|
| 270 | - // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 271 | - $installee = intval($GLOBALS[$table][$meta]); |
|
| 272 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 273 | - } |
|
| 274 | - echo redirige_formulaire($redirect); |
|
| 275 | - exit(); |
|
| 265 | + include_spip('inc/headers'); |
|
| 266 | + if (!$redirect) { |
|
| 267 | + // recuperer la valeur installee en cours |
|
| 268 | + // on la tronque numeriquement, elle ne sert pas reellement |
|
| 269 | + // sauf pour verifier que ce n'est pas oui ou non |
|
| 270 | + // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 271 | + $installee = intval($GLOBALS[$table][$meta]); |
|
| 272 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 273 | + } |
|
| 274 | + echo redirige_formulaire($redirect); |
|
| 275 | + exit(); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -285,29 +285,29 @@ discard block |
||
| 285 | 285 | * @return void |
| 286 | 286 | */ |
| 287 | 287 | function maj_debut_page($installee, $meta, $table) { |
| 288 | - static $done = false; |
|
| 289 | - if ($done) { |
|
| 290 | - return; |
|
| 291 | - } |
|
| 292 | - include_spip('inc/minipres'); |
|
| 293 | - include_spip('inc/filtres'); |
|
| 294 | - if (function_exists('ini_set')) { |
|
| 295 | - @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 296 | - } |
|
| 297 | - $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 298 | - $titre = _T('titre_page_upgrade'); |
|
| 299 | - $balise_img = charger_filtre('balise_img'); |
|
| 300 | - $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 301 | - echo(install_debut_html($titre)); |
|
| 302 | - // script de rechargement auto sur timeout |
|
| 303 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 304 | - echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 305 | - echo "<div style='text-align: left'>\n"; |
|
| 306 | - if (ob_get_level()) { |
|
| 307 | - ob_flush(); |
|
| 308 | - } |
|
| 309 | - flush(); |
|
| 310 | - $done = true; |
|
| 288 | + static $done = false; |
|
| 289 | + if ($done) { |
|
| 290 | + return; |
|
| 291 | + } |
|
| 292 | + include_spip('inc/minipres'); |
|
| 293 | + include_spip('inc/filtres'); |
|
| 294 | + if (function_exists('ini_set')) { |
|
| 295 | + @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 296 | + } |
|
| 297 | + $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 298 | + $titre = _T('titre_page_upgrade'); |
|
| 299 | + $balise_img = charger_filtre('balise_img'); |
|
| 300 | + $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 301 | + echo(install_debut_html($titre)); |
|
| 302 | + // script de rechargement auto sur timeout |
|
| 303 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 304 | + echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 305 | + echo "<div style='text-align: left'>\n"; |
|
| 306 | + if (ob_get_level()) { |
|
| 307 | + ob_flush(); |
|
| 308 | + } |
|
| 309 | + flush(); |
|
| 310 | + $done = true; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -351,64 +351,64 @@ discard block |
||
| 351 | 351 | * - tableau vide sinon. |
| 352 | 352 | */ |
| 353 | 353 | function maj_while($installee, $cible, $maj, $meta = '', $table = 'meta', $redirect = '', $debut_page = false) { |
| 354 | - # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 355 | - include_spip('base/create'); |
|
| 356 | - include_spip('base/abstract_sql'); |
|
| 357 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 358 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 359 | - $n = 0; |
|
| 360 | - $time = time(); |
|
| 361 | - |
|
| 362 | - if (!defined('_TIME_OUT')) { |
|
| 363 | - /** |
|
| 364 | - * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 365 | - * de mises à jour qui durent trop longtemps |
|
| 366 | - * |
|
| 367 | - * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 368 | - * |
|
| 369 | - * @var int |
|
| 370 | - */ |
|
| 371 | - define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - foreach ($maj as $v => $operations) { |
|
| 375 | - // si une maj pour cette version |
|
| 376 | - if ( |
|
| 377 | - $v == 'init' or |
|
| 378 | - (spip_version_compare($v, $installee, '>') |
|
| 379 | - and spip_version_compare($v, $cible, '<=')) |
|
| 380 | - ) { |
|
| 381 | - if ($debut_page) { |
|
| 382 | - maj_debut_page($v, $meta, $table); |
|
| 383 | - } |
|
| 384 | - echo "MAJ $v"; |
|
| 385 | - $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 386 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 387 | - # echec sur une etape en cours ? |
|
| 388 | - # on sort |
|
| 389 | - if ($etape) { |
|
| 390 | - return [$v, $etape]; |
|
| 391 | - } |
|
| 392 | - $n = time() - $time; |
|
| 393 | - spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 394 | - if ($meta) { |
|
| 395 | - ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 396 | - } |
|
| 397 | - echo (_IS_CLI ? "\n" : '<br />'); |
|
| 398 | - } |
|
| 399 | - if (time() >= _TIME_OUT) { |
|
| 400 | - relance_maj($meta, $table, $redirect); |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 404 | - // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 405 | - // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 406 | - if ($meta) { |
|
| 407 | - ecrire_meta($meta, $cible, 'oui', $table); |
|
| 408 | - } |
|
| 409 | - spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 410 | - |
|
| 411 | - return []; |
|
| 354 | + # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 355 | + include_spip('base/create'); |
|
| 356 | + include_spip('base/abstract_sql'); |
|
| 357 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 358 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 359 | + $n = 0; |
|
| 360 | + $time = time(); |
|
| 361 | + |
|
| 362 | + if (!defined('_TIME_OUT')) { |
|
| 363 | + /** |
|
| 364 | + * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 365 | + * de mises à jour qui durent trop longtemps |
|
| 366 | + * |
|
| 367 | + * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 368 | + * |
|
| 369 | + * @var int |
|
| 370 | + */ |
|
| 371 | + define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + foreach ($maj as $v => $operations) { |
|
| 375 | + // si une maj pour cette version |
|
| 376 | + if ( |
|
| 377 | + $v == 'init' or |
|
| 378 | + (spip_version_compare($v, $installee, '>') |
|
| 379 | + and spip_version_compare($v, $cible, '<=')) |
|
| 380 | + ) { |
|
| 381 | + if ($debut_page) { |
|
| 382 | + maj_debut_page($v, $meta, $table); |
|
| 383 | + } |
|
| 384 | + echo "MAJ $v"; |
|
| 385 | + $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 386 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 387 | + # echec sur une etape en cours ? |
|
| 388 | + # on sort |
|
| 389 | + if ($etape) { |
|
| 390 | + return [$v, $etape]; |
|
| 391 | + } |
|
| 392 | + $n = time() - $time; |
|
| 393 | + spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 394 | + if ($meta) { |
|
| 395 | + ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 396 | + } |
|
| 397 | + echo (_IS_CLI ? "\n" : '<br />'); |
|
| 398 | + } |
|
| 399 | + if (time() >= _TIME_OUT) { |
|
| 400 | + relance_maj($meta, $table, $redirect); |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 404 | + // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 405 | + // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 406 | + if ($meta) { |
|
| 407 | + ecrire_meta($meta, $cible, 'oui', $table); |
|
| 408 | + } |
|
| 409 | + spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 410 | + |
|
| 411 | + return []; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -431,53 +431,53 @@ discard block |
||
| 431 | 431 | * @return int |
| 432 | 432 | */ |
| 433 | 433 | function serie_alter($serie, $q = [], $meta = '', $table = 'meta', $redirect = '') { |
| 434 | - $meta2 = $meta . '_maj_' . $serie; |
|
| 435 | - $etape = 0; |
|
| 436 | - if (isset($GLOBALS[$table][$meta2])) { |
|
| 437 | - $etape = intval($GLOBALS[$table][$meta2]); |
|
| 438 | - } |
|
| 439 | - foreach ($q as $i => $r) { |
|
| 440 | - if ($i >= $etape) { |
|
| 441 | - $msg = "maj $table $meta2 etape $i"; |
|
| 442 | - if ( |
|
| 443 | - is_array($r) |
|
| 444 | - and function_exists($f = array_shift($r)) |
|
| 445 | - ) { |
|
| 446 | - // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 447 | - spip_log("$msg: $f " . @join(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | - // pour les fonctions atomiques sql_xx |
|
| 449 | - // on enregistre le meta avant de lancer la fonction, |
|
| 450 | - // de maniere a eviter de boucler sur timeout |
|
| 451 | - // mais pour les fonctions complexes, |
|
| 452 | - // il faut les rejouer jusqu'a achevement. |
|
| 453 | - // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 454 | - if (strncmp($f, 'sql_', 4) == 0) { |
|
| 455 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 456 | - } |
|
| 457 | - echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 458 | - $f(...$r); |
|
| 459 | - // si temps imparti depasse, on relance sans ecrire en meta |
|
| 460 | - // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 461 | - if (time() >= _TIME_OUT) { |
|
| 462 | - relance_maj($meta, $table, $redirect); |
|
| 463 | - } |
|
| 464 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 465 | - spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 466 | - } else { |
|
| 467 | - if (!is_array($r)) { |
|
| 468 | - spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 469 | - } else { |
|
| 470 | - spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 471 | - } |
|
| 472 | - // en cas d'erreur serieuse, on s'arrete |
|
| 473 | - // mais on permet de passer par dessus en rechargeant la page. |
|
| 474 | - return $i + 1; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - effacer_meta($meta2, $table); |
|
| 479 | - |
|
| 480 | - return 0; |
|
| 434 | + $meta2 = $meta . '_maj_' . $serie; |
|
| 435 | + $etape = 0; |
|
| 436 | + if (isset($GLOBALS[$table][$meta2])) { |
|
| 437 | + $etape = intval($GLOBALS[$table][$meta2]); |
|
| 438 | + } |
|
| 439 | + foreach ($q as $i => $r) { |
|
| 440 | + if ($i >= $etape) { |
|
| 441 | + $msg = "maj $table $meta2 etape $i"; |
|
| 442 | + if ( |
|
| 443 | + is_array($r) |
|
| 444 | + and function_exists($f = array_shift($r)) |
|
| 445 | + ) { |
|
| 446 | + // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 447 | + spip_log("$msg: $f " . @join(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | + // pour les fonctions atomiques sql_xx |
|
| 449 | + // on enregistre le meta avant de lancer la fonction, |
|
| 450 | + // de maniere a eviter de boucler sur timeout |
|
| 451 | + // mais pour les fonctions complexes, |
|
| 452 | + // il faut les rejouer jusqu'a achevement. |
|
| 453 | + // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 454 | + if (strncmp($f, 'sql_', 4) == 0) { |
|
| 455 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 456 | + } |
|
| 457 | + echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 458 | + $f(...$r); |
|
| 459 | + // si temps imparti depasse, on relance sans ecrire en meta |
|
| 460 | + // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 461 | + if (time() >= _TIME_OUT) { |
|
| 462 | + relance_maj($meta, $table, $redirect); |
|
| 463 | + } |
|
| 464 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 465 | + spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 466 | + } else { |
|
| 467 | + if (!is_array($r)) { |
|
| 468 | + spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 469 | + } else { |
|
| 470 | + spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 471 | + } |
|
| 472 | + // en cas d'erreur serieuse, on s'arrete |
|
| 473 | + // mais on permet de passer par dessus en rechargeant la page. |
|
| 474 | + return $i + 1; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + effacer_meta($meta2, $table); |
|
| 479 | + |
|
| 480 | + return 0; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -486,16 +486,16 @@ discard block |
||
| 486 | 486 | * @return bool True si possible. |
| 487 | 487 | **/ |
| 488 | 488 | function upgrade_test() { |
| 489 | - sql_drop_table('spip_test', true); |
|
| 490 | - sql_create('spip_test', ['a' => 'int']); |
|
| 491 | - sql_alter('TABLE spip_test ADD b INT'); |
|
| 492 | - sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 493 | - $result = sql_select('b', 'spip_test'); |
|
| 494 | - // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 495 | - // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 496 | - // car cette table serait alors 'verouillee' |
|
| 497 | - $result = $result ? true : false; |
|
| 498 | - sql_alter('TABLE spip_test DROP b'); |
|
| 499 | - |
|
| 500 | - return $result; |
|
| 489 | + sql_drop_table('spip_test', true); |
|
| 490 | + sql_create('spip_test', ['a' => 'int']); |
|
| 491 | + sql_alter('TABLE spip_test ADD b INT'); |
|
| 492 | + sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 493 | + $result = sql_select('b', 'spip_test'); |
|
| 494 | + // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 495 | + // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 496 | + // car cette table serait alors 'verouillee' |
|
| 497 | + $result = $result ? true : false; |
|
| 498 | + sql_alter('TABLE spip_test DROP b'); |
|
| 499 | + |
|
| 500 | + return $result; |
|
| 501 | 501 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/charsets'); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * @return string Fonction PHP correspondante du filtre |
| 42 | 42 | */ |
| 43 | 43 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 44 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | - return chercher_filtre($fonc, $default); |
|
| 44 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 45 | + return chercher_filtre($fonc, $default); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string texte |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_identite_dist($texte) { |
| 55 | - return $texte; |
|
| 55 | + return $texte; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -76,33 +76,33 @@ discard block |
||
| 76 | 76 | * Fonction PHP correspondante du filtre demandé |
| 77 | 77 | */ |
| 78 | 78 | function chercher_filtre($fonc, $default = null) { |
| 79 | - if (!$fonc) { |
|
| 80 | - return $default; |
|
| 81 | - } |
|
| 82 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | - // Foo::Bar |
|
| 84 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | - $f = chercher_filtre($nom); |
|
| 88 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | - if (!$f and $nom !== $fonc) { |
|
| 91 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $f; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - include_fichiers_fonctions(); |
|
| 98 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | - if (is_callable($f)) { |
|
| 101 | - return $f; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $default; |
|
| 79 | + if (!$fonc) { |
|
| 80 | + return $default; |
|
| 81 | + } |
|
| 82 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 83 | + // Foo::Bar |
|
| 84 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 85 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 86 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 87 | + $f = chercher_filtre($nom); |
|
| 88 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 89 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 90 | + if (!$f and $nom !== $fonc) { |
|
| 91 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $f; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + include_fichiers_fonctions(); |
|
| 98 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 100 | + if (is_callable($f)) { |
|
| 101 | + return $f; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $default; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * Chaîne vide sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function appliquer_filtre($arg, $filtre) { |
| 149 | - $args = func_get_args(); |
|
| 150 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 149 | + $args = func_get_args(); |
|
| 150 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * texte d'origine sinon |
| 173 | 173 | **/ |
| 174 | 174 | function appliquer_si_filtre($arg, $filtre) { |
| 175 | - $args = func_get_args(); |
|
| 176 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 175 | + $args = func_get_args(); |
|
| 176 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | * Version de SPIP |
| 190 | 190 | **/ |
| 191 | 191 | function spip_version() { |
| 192 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | - $version .= " $vcs_version"; |
|
| 195 | - } |
|
| 192 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 193 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 194 | + $version .= " $vcs_version"; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $version; |
|
| 197 | + return $version; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | 208 | function header_silencieux($version): string { |
| 209 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | - $version = ''; |
|
| 211 | - } |
|
| 209 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 210 | + $version = ''; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - return (string) $version; |
|
| 213 | + return (string) $version; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | * - string|null si $raw = false |
| 224 | 224 | */ |
| 225 | 225 | function version_vcs_courante($dir, $raw = false) { |
| 226 | - $desc = decrire_version_git($dir); |
|
| 227 | - if ($desc === null or $raw) { |
|
| 228 | - return $desc; |
|
| 229 | - } |
|
| 230 | - // affichage "GIT [master: abcdef]" |
|
| 231 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | - if ($desc['branch']) { |
|
| 233 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | - } |
|
| 235 | - return "{$desc['vcs']} [$commit]"; |
|
| 226 | + $desc = decrire_version_git($dir); |
|
| 227 | + if ($desc === null or $raw) { |
|
| 228 | + return $desc; |
|
| 229 | + } |
|
| 230 | + // affichage "GIT [master: abcdef]" |
|
| 231 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 232 | + if ($desc['branch']) { |
|
| 233 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | + } |
|
| 235 | + return "{$desc['vcs']} [$commit]"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,24 +244,24 @@ discard block |
||
| 244 | 244 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 245 | 245 | **/ |
| 246 | 246 | function decrire_version_git($dir) { |
| 247 | - if (!$dir) { |
|
| 248 | - $dir = '.'; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // version installee par GIT |
|
| 252 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 253 | - $currentHead = trim(substr($c, 4)); |
|
| 254 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 255 | - return [ |
|
| 256 | - 'vcs' => 'GIT', |
|
| 257 | - 'branch' => basename($currentHead), |
|
| 258 | - 'commit' => trim($hash), |
|
| 259 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 260 | - ]; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return null; |
|
| 247 | + if (!$dir) { |
|
| 248 | + $dir = '.'; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // version installee par GIT |
|
| 252 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 253 | + $currentHead = trim(substr($c, 4)); |
|
| 254 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 255 | + return [ |
|
| 256 | + 'vcs' => 'GIT', |
|
| 257 | + 'branch' => basename($currentHead), |
|
| 258 | + 'commit' => trim($hash), |
|
| 259 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 260 | + ]; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return null; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -308,18 +308,18 @@ discard block |
||
| 308 | 308 | * Code HTML retourné par le filtre |
| 309 | 309 | **/ |
| 310 | 310 | function filtrer($filtre) { |
| 311 | - $tous = func_get_args(); |
|
| 312 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 313 | - return image_filtrer($tous); |
|
| 314 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 315 | - array_shift($tous); |
|
| 316 | - return $f(...$tous); |
|
| 317 | - } else { |
|
| 318 | - // le filtre n'existe pas, on provoque une erreur |
|
| 319 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 320 | - erreur_squelette($msg); |
|
| 321 | - return ''; |
|
| 322 | - } |
|
| 311 | + $tous = func_get_args(); |
|
| 312 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 313 | + return image_filtrer($tous); |
|
| 314 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 315 | + array_shift($tous); |
|
| 316 | + return $f(...$tous); |
|
| 317 | + } else { |
|
| 318 | + // le filtre n'existe pas, on provoque une erreur |
|
| 319 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 320 | + erreur_squelette($msg); |
|
| 321 | + return ''; |
|
| 322 | + } |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -336,11 +336,11 @@ discard block |
||
| 336 | 336 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 337 | 337 | */ |
| 338 | 338 | function trouver_filtre_matrice($filtre) { |
| 339 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 340 | - find_in_path($f, '', true); |
|
| 341 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 342 | - } |
|
| 343 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 339 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 340 | + find_in_path($f, '', true); |
|
| 341 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 342 | + } |
|
| 343 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -368,8 +368,8 @@ discard block |
||
| 368 | 368 | * @return mixed |
| 369 | 369 | */ |
| 370 | 370 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 371 | - $Pile['vars'][$key] = $val; |
|
| 372 | - return $continue ? $val : ''; |
|
| 371 | + $Pile['vars'][$key] = $val; |
|
| 372 | + return $continue ? $val : ''; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 396 | 396 | */ |
| 397 | 397 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 398 | - $Pile[0][$key] = $val; |
|
| 399 | - return $continue ? $val : ''; |
|
| 398 | + $Pile[0][$key] = $val; |
|
| 399 | + return $continue ? $val : ''; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -405,8 +405,8 @@ discard block |
||
| 405 | 405 | * @return string |
| 406 | 406 | */ |
| 407 | 407 | function filtre_sanitize_env(&$Pile, $keys) { |
| 408 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 409 | - return ''; |
|
| 408 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 409 | + return ''; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -429,18 +429,18 @@ discard block |
||
| 429 | 429 | * @return mixed Retourne la valeur (sans la modifier). |
| 430 | 430 | */ |
| 431 | 431 | function filtre_debug($val, $key = null) { |
| 432 | - $debug = ( |
|
| 433 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 434 | - ) . var_export($val, true); |
|
| 432 | + $debug = ( |
|
| 433 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 434 | + ) . var_export($val, true); |
|
| 435 | 435 | |
| 436 | - include_spip('inc/autoriser'); |
|
| 437 | - if (autoriser('webmestre')) { |
|
| 438 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 439 | - } |
|
| 436 | + include_spip('inc/autoriser'); |
|
| 437 | + if (autoriser('webmestre')) { |
|
| 438 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - spip_log($debug, 'debug'); |
|
| 441 | + spip_log($debug, 'debug'); |
|
| 442 | 442 | |
| 443 | - return $val; |
|
| 443 | + return $val; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -470,84 +470,84 @@ discard block |
||
| 470 | 470 | * texte qui a reçu les filtres |
| 471 | 471 | **/ |
| 472 | 472 | function image_filtrer($args) { |
| 473 | - $filtre = array_shift($args); # enlever $filtre |
|
| 474 | - $texte = array_shift($args); |
|
| 475 | - if ($texte === null || !strlen($texte)) { |
|
| 476 | - return ''; |
|
| 477 | - } |
|
| 478 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 479 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 480 | - // Cas du nom de fichier local |
|
| 481 | - $is_file = trim($texte); |
|
| 482 | - if ( |
|
| 483 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 484 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 485 | - or strpos($is_file, '/') === 0 |
|
| 486 | - ) { |
|
| 487 | - $is_file = false; |
|
| 488 | - } |
|
| 489 | - if ($is_file) { |
|
| 490 | - $is_local_file = function ($path) { |
|
| 491 | - if (strpos($path, '?') !== false) { |
|
| 492 | - $path = supprimer_timestamp($path); |
|
| 493 | - // remove ?24px added by find_in_theme on .svg files |
|
| 494 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 495 | - } |
|
| 496 | - return file_exists($path); |
|
| 497 | - }; |
|
| 498 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 499 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 500 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 501 | - return $res; |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 506 | - if ( |
|
| 507 | - preg_match_all( |
|
| 508 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 509 | - $texte, |
|
| 510 | - $tags, |
|
| 511 | - PREG_SET_ORDER |
|
| 512 | - ) |
|
| 513 | - ) { |
|
| 514 | - foreach ($tags as $tag) { |
|
| 515 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 516 | - if ( |
|
| 517 | - !$class or |
|
| 518 | - (strpos($class, 'filtre_inactif') === false |
|
| 519 | - // compat historique a virer en 3.2 |
|
| 520 | - and !str_contains($class, 'no_image_filtrer')) |
|
| 521 | - ) { |
|
| 522 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 523 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 524 | - if ($tag[1]) { |
|
| 525 | - $w = extraire_attribut($reduit, 'width'); |
|
| 526 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 527 | - $w = $regs[1]; |
|
| 528 | - } |
|
| 529 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 530 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 531 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 532 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - // traiter aussi un eventuel mouseover |
|
| 536 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 537 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 538 | - $srcover = $match[1]; |
|
| 539 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 541 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 550 | - return $texte; |
|
| 473 | + $filtre = array_shift($args); # enlever $filtre |
|
| 474 | + $texte = array_shift($args); |
|
| 475 | + if ($texte === null || !strlen($texte)) { |
|
| 476 | + return ''; |
|
| 477 | + } |
|
| 478 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 479 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 480 | + // Cas du nom de fichier local |
|
| 481 | + $is_file = trim($texte); |
|
| 482 | + if ( |
|
| 483 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 484 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 485 | + or strpos($is_file, '/') === 0 |
|
| 486 | + ) { |
|
| 487 | + $is_file = false; |
|
| 488 | + } |
|
| 489 | + if ($is_file) { |
|
| 490 | + $is_local_file = function ($path) { |
|
| 491 | + if (strpos($path, '?') !== false) { |
|
| 492 | + $path = supprimer_timestamp($path); |
|
| 493 | + // remove ?24px added by find_in_theme on .svg files |
|
| 494 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 495 | + } |
|
| 496 | + return file_exists($path); |
|
| 497 | + }; |
|
| 498 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 499 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 500 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 501 | + return $res; |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 506 | + if ( |
|
| 507 | + preg_match_all( |
|
| 508 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 509 | + $texte, |
|
| 510 | + $tags, |
|
| 511 | + PREG_SET_ORDER |
|
| 512 | + ) |
|
| 513 | + ) { |
|
| 514 | + foreach ($tags as $tag) { |
|
| 515 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 516 | + if ( |
|
| 517 | + !$class or |
|
| 518 | + (strpos($class, 'filtre_inactif') === false |
|
| 519 | + // compat historique a virer en 3.2 |
|
| 520 | + and !str_contains($class, 'no_image_filtrer')) |
|
| 521 | + ) { |
|
| 522 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 523 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 524 | + if ($tag[1]) { |
|
| 525 | + $w = extraire_attribut($reduit, 'width'); |
|
| 526 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 527 | + $w = $regs[1]; |
|
| 528 | + } |
|
| 529 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 530 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 531 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 532 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + // traiter aussi un eventuel mouseover |
|
| 536 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 537 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 538 | + $srcover = $match[1]; |
|
| 539 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 541 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 550 | + return $texte; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -564,94 +564,94 @@ discard block |
||
| 564 | 564 | **/ |
| 565 | 565 | function infos_image($img, $force_refresh = false) { |
| 566 | 566 | |
| 567 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 568 | - $srcWidth = 0; |
|
| 569 | - $srcHeight = 0; |
|
| 570 | - $srcSize = null; |
|
| 571 | - |
|
| 572 | - $src = extraire_attribut($img, 'src'); |
|
| 573 | - |
|
| 574 | - if (!$src) { |
|
| 575 | - $src = $img; |
|
| 576 | - } else { |
|
| 577 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | - if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) { |
|
| 580 | - $srcWidth = $srcHeight = 0; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | - if (tester_url_absolue($src)) { |
|
| 587 | - include_spip('inc/distant'); |
|
| 588 | - $fichier = copie_locale($src); |
|
| 589 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | - } |
|
| 591 | - if (($p = strpos($src, '?')) !== false) { |
|
| 592 | - $src = substr($src, 0, $p); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $imagesize = false; |
|
| 596 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 597 | - $srcWidth = $largeur_img[$src]; |
|
| 598 | - } |
|
| 599 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 600 | - $srcHeight = $hauteur_img[$src]; |
|
| 601 | - } |
|
| 602 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 603 | - $srcSize = $poids_img[$src]; |
|
| 604 | - } |
|
| 605 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 606 | - if ( |
|
| 607 | - file_exists($src) |
|
| 608 | - and $imagesize = spip_getimagesize($src) |
|
| 609 | - ) { |
|
| 610 | - if (!$srcWidth) { |
|
| 611 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 612 | - } |
|
| 613 | - if (!$srcHeight) { |
|
| 614 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 615 | - } |
|
| 616 | - if (!$srcSize) { |
|
| 617 | - $poids_img[$src] = filesize($src); |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - elseif (strpos($src, '<svg') !== false) { |
|
| 621 | - include_spip('inc/svg'); |
|
| 622 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 623 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 624 | - if (!$srcWidth) { |
|
| 625 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 626 | - } |
|
| 627 | - if (!$srcHeight) { |
|
| 628 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 629 | - } |
|
| 630 | - if (!$srcSize) { |
|
| 631 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 636 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 637 | - elseif ( |
|
| 638 | - @file_exists($f = "$src.src") |
|
| 639 | - and lire_fichier($f, $valeurs) |
|
| 640 | - and $valeurs = unserialize($valeurs) |
|
| 641 | - ) { |
|
| 642 | - if (!$srcWidth) { |
|
| 643 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 644 | - } |
|
| 645 | - if (!$srcHeight) { |
|
| 646 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 647 | - } |
|
| 648 | - if (!$srcSize) { |
|
| 649 | - $poids_img[$src] = $srcSize = 0; |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 567 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 568 | + $srcWidth = 0; |
|
| 569 | + $srcHeight = 0; |
|
| 570 | + $srcSize = null; |
|
| 571 | + |
|
| 572 | + $src = extraire_attribut($img, 'src'); |
|
| 573 | + |
|
| 574 | + if (!$src) { |
|
| 575 | + $src = $img; |
|
| 576 | + } else { |
|
| 577 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 578 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 579 | + if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) { |
|
| 580 | + $srcWidth = $srcHeight = 0; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 585 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 586 | + if (tester_url_absolue($src)) { |
|
| 587 | + include_spip('inc/distant'); |
|
| 588 | + $fichier = copie_locale($src); |
|
| 589 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 590 | + } |
|
| 591 | + if (($p = strpos($src, '?')) !== false) { |
|
| 592 | + $src = substr($src, 0, $p); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + $imagesize = false; |
|
| 596 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 597 | + $srcWidth = $largeur_img[$src]; |
|
| 598 | + } |
|
| 599 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 600 | + $srcHeight = $hauteur_img[$src]; |
|
| 601 | + } |
|
| 602 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 603 | + $srcSize = $poids_img[$src]; |
|
| 604 | + } |
|
| 605 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 606 | + if ( |
|
| 607 | + file_exists($src) |
|
| 608 | + and $imagesize = spip_getimagesize($src) |
|
| 609 | + ) { |
|
| 610 | + if (!$srcWidth) { |
|
| 611 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 612 | + } |
|
| 613 | + if (!$srcHeight) { |
|
| 614 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 615 | + } |
|
| 616 | + if (!$srcSize) { |
|
| 617 | + $poids_img[$src] = filesize($src); |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + elseif (strpos($src, '<svg') !== false) { |
|
| 621 | + include_spip('inc/svg'); |
|
| 622 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 623 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 624 | + if (!$srcWidth) { |
|
| 625 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 626 | + } |
|
| 627 | + if (!$srcHeight) { |
|
| 628 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 629 | + } |
|
| 630 | + if (!$srcSize) { |
|
| 631 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 636 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 637 | + elseif ( |
|
| 638 | + @file_exists($f = "$src.src") |
|
| 639 | + and lire_fichier($f, $valeurs) |
|
| 640 | + and $valeurs = unserialize($valeurs) |
|
| 641 | + ) { |
|
| 642 | + if (!$srcWidth) { |
|
| 643 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 644 | + } |
|
| 645 | + if (!$srcHeight) { |
|
| 646 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 647 | + } |
|
| 648 | + if (!$srcSize) { |
|
| 649 | + $poids_img[$src] = $srcSize = 0; |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | * poids |
| 668 | 668 | **/ |
| 669 | 669 | function poids_image($img, $force_refresh = false) { |
| 670 | - $infos = infos_image($img, $force_refresh); |
|
| 671 | - return $infos['poids']; |
|
| 670 | + $infos = infos_image($img, $force_refresh); |
|
| 671 | + return $infos['poids']; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function taille_image($img, $force_refresh = false) { |
| 675 | - $infos = infos_image($img, $force_refresh); |
|
| 676 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 675 | + $infos = infos_image($img, $force_refresh); |
|
| 676 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -690,12 +690,12 @@ discard block |
||
| 690 | 690 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 691 | 691 | **/ |
| 692 | 692 | function largeur($img) { |
| 693 | - if (!$img) { |
|
| 694 | - return; |
|
| 695 | - } |
|
| 696 | - [$h, $l] = taille_image($img); |
|
| 693 | + if (!$img) { |
|
| 694 | + return; |
|
| 695 | + } |
|
| 696 | + [$h, $l] = taille_image($img); |
|
| 697 | 697 | |
| 698 | - return $l; |
|
| 698 | + return $l; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | /** |
@@ -712,12 +712,12 @@ discard block |
||
| 712 | 712 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 713 | 713 | **/ |
| 714 | 714 | function hauteur($img) { |
| 715 | - if (!$img) { |
|
| 716 | - return; |
|
| 717 | - } |
|
| 718 | - [$h, $l] = taille_image($img); |
|
| 715 | + if (!$img) { |
|
| 716 | + return; |
|
| 717 | + } |
|
| 718 | + [$h, $l] = taille_image($img); |
|
| 719 | 719 | |
| 720 | - return $h; |
|
| 720 | + return $h; |
|
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | |
@@ -737,11 +737,11 @@ discard block |
||
| 737 | 737 | * @return string |
| 738 | 738 | **/ |
| 739 | 739 | function corriger_entites_html($texte) { |
| 740 | - if (strpos($texte, '&') === false) { |
|
| 741 | - return $texte; |
|
| 742 | - } |
|
| 740 | + if (strpos($texte, '&') === false) { |
|
| 741 | + return $texte; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 744 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -756,11 +756,11 @@ discard block |
||
| 756 | 756 | * @return string |
| 757 | 757 | **/ |
| 758 | 758 | function corriger_toutes_entites_html($texte) { |
| 759 | - if (strpos($texte, '&') === false) { |
|
| 760 | - return $texte; |
|
| 761 | - } |
|
| 759 | + if (strpos($texte, '&') === false) { |
|
| 760 | + return $texte; |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 763 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | /** |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | * @return string |
| 771 | 771 | **/ |
| 772 | 772 | function proteger_amp($texte) { |
| 773 | - return str_replace('&', '&', $texte); |
|
| 773 | + return str_replace('&', '&', $texte); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | |
@@ -801,21 +801,21 @@ discard block |
||
| 801 | 801 | * @return mixed|string |
| 802 | 802 | */ |
| 803 | 803 | function entites_html($texte, $tout = false, $quote = true) { |
| 804 | - if ( |
|
| 805 | - !is_string($texte) or !$texte |
|
| 806 | - or strpbrk($texte, "&\"'<>") == false |
|
| 807 | - ) { |
|
| 808 | - return $texte; |
|
| 809 | - } |
|
| 810 | - include_spip('inc/texte'); |
|
| 811 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 812 | - $flags |= ENT_HTML401; |
|
| 813 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 814 | - if ($tout) { |
|
| 815 | - return corriger_toutes_entites_html($texte); |
|
| 816 | - } else { |
|
| 817 | - return corriger_entites_html($texte); |
|
| 818 | - } |
|
| 804 | + if ( |
|
| 805 | + !is_string($texte) or !$texte |
|
| 806 | + or strpbrk($texte, "&\"'<>") == false |
|
| 807 | + ) { |
|
| 808 | + return $texte; |
|
| 809 | + } |
|
| 810 | + include_spip('inc/texte'); |
|
| 811 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 812 | + $flags |= ENT_HTML401; |
|
| 813 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 814 | + if ($tout) { |
|
| 815 | + return corriger_toutes_entites_html($texte); |
|
| 816 | + } else { |
|
| 817 | + return corriger_entites_html($texte); |
|
| 818 | + } |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | /** |
@@ -834,38 +834,38 @@ discard block |
||
| 834 | 834 | * texte converti |
| 835 | 835 | **/ |
| 836 | 836 | function filtrer_entites(?string $texte): string { |
| 837 | - $texte ??= ''; |
|
| 838 | - if (strpos($texte, '&') === false) { |
|
| 839 | - return $texte; |
|
| 840 | - } |
|
| 841 | - // filtrer |
|
| 842 | - $texte = html2unicode($texte); |
|
| 843 | - // remettre le tout dans le charset cible |
|
| 844 | - $texte = unicode2charset($texte); |
|
| 845 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 846 | - // (on le faisait deja avec un ") |
|
| 847 | - if (strpos($texte, '&#') !== false) { |
|
| 848 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 849 | - } |
|
| 837 | + $texte ??= ''; |
|
| 838 | + if (strpos($texte, '&') === false) { |
|
| 839 | + return $texte; |
|
| 840 | + } |
|
| 841 | + // filtrer |
|
| 842 | + $texte = html2unicode($texte); |
|
| 843 | + // remettre le tout dans le charset cible |
|
| 844 | + $texte = unicode2charset($texte); |
|
| 845 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 846 | + // (on le faisait deja avec un ") |
|
| 847 | + if (strpos($texte, '&#') !== false) { |
|
| 848 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 849 | + } |
|
| 850 | 850 | |
| 851 | - return $texte; |
|
| 851 | + return $texte; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | |
| 855 | 855 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 856 | - /** |
|
| 857 | - * Version sécurisée de filtrer_entites |
|
| 858 | - * |
|
| 859 | - * @uses interdire_scripts() |
|
| 860 | - * @uses filtrer_entites() |
|
| 861 | - * |
|
| 862 | - * @param string $t |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - function filtre_filtrer_entites_dist($t) { |
|
| 866 | - include_spip('inc/texte'); |
|
| 867 | - return interdire_scripts(filtrer_entites($t)); |
|
| 868 | - } |
|
| 856 | + /** |
|
| 857 | + * Version sécurisée de filtrer_entites |
|
| 858 | + * |
|
| 859 | + * @uses interdire_scripts() |
|
| 860 | + * @uses filtrer_entites() |
|
| 861 | + * |
|
| 862 | + * @param string $t |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + function filtre_filtrer_entites_dist($t) { |
|
| 866 | + include_spip('inc/texte'); |
|
| 867 | + return interdire_scripts(filtrer_entites($t)); |
|
| 868 | + } |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | |
@@ -880,18 +880,18 @@ discard block |
||
| 880 | 880 | * @return string|array |
| 881 | 881 | **/ |
| 882 | 882 | function supprimer_caracteres_illegaux($texte) { |
| 883 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 884 | - static $to = null; |
|
| 883 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 884 | + static $to = null; |
|
| 885 | 885 | |
| 886 | - if (is_array($texte)) { |
|
| 887 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 888 | - } |
|
| 886 | + if (is_array($texte)) { |
|
| 887 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - if (!$to) { |
|
| 891 | - $to = str_repeat('-', strlen($from)); |
|
| 892 | - } |
|
| 890 | + if (!$to) { |
|
| 891 | + $to = str_repeat('-', strlen($from)); |
|
| 892 | + } |
|
| 893 | 893 | |
| 894 | - return strtr($texte, $from, $to); |
|
| 894 | + return strtr($texte, $from, $to); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -903,10 +903,10 @@ discard block |
||
| 903 | 903 | * @return string|array |
| 904 | 904 | **/ |
| 905 | 905 | function corriger_caracteres($texte) { |
| 906 | - $texte = corriger_caracteres_windows($texte); |
|
| 907 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 906 | + $texte = corriger_caracteres_windows($texte); |
|
| 907 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 908 | 908 | |
| 909 | - return $texte; |
|
| 909 | + return $texte; |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
@@ -923,44 +923,44 @@ discard block |
||
| 923 | 923 | * texte encodé pour XML |
| 924 | 924 | */ |
| 925 | 925 | function texte_backend(string $texte): string { |
| 926 | - if ($texte === '') { |
|
| 927 | - return ''; |
|
| 928 | - } |
|
| 926 | + if ($texte === '') { |
|
| 927 | + return ''; |
|
| 928 | + } |
|
| 929 | 929 | |
| 930 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 930 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 931 | 931 | |
| 932 | - // si on a des liens ou des images, les passer en absolu |
|
| 933 | - $texte = liens_absolus($texte); |
|
| 932 | + // si on a des liens ou des images, les passer en absolu |
|
| 933 | + $texte = liens_absolus($texte); |
|
| 934 | 934 | |
| 935 | - // echapper les tags > < |
|
| 936 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 935 | + // echapper les tags > < |
|
| 936 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 937 | 937 | |
| 938 | - // importer les é |
|
| 939 | - $texte = filtrer_entites($texte); |
|
| 938 | + // importer les é |
|
| 939 | + $texte = filtrer_entites($texte); |
|
| 940 | 940 | |
| 941 | - // " -> " et tout ce genre de choses |
|
| 942 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 943 | - $texte = str_replace(' ', ' ', $texte); |
|
| 944 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 945 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 946 | - $texte = entites_html($texte, false, false); |
|
| 947 | - // mais bien echapper les double quotes ! |
|
| 948 | - $texte = str_replace('"', '"', $texte); |
|
| 941 | + // " -> " et tout ce genre de choses |
|
| 942 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 943 | + $texte = str_replace(' ', ' ', $texte); |
|
| 944 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 945 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 946 | + $texte = entites_html($texte, false, false); |
|
| 947 | + // mais bien echapper les double quotes ! |
|
| 948 | + $texte = str_replace('"', '"', $texte); |
|
| 949 | 949 | |
| 950 | - // verifier le charset |
|
| 951 | - $texte = charset2unicode($texte); |
|
| 950 | + // verifier le charset |
|
| 951 | + $texte = charset2unicode($texte); |
|
| 952 | 952 | |
| 953 | - // Caracteres problematiques en iso-latin 1 |
|
| 954 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 955 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 956 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 957 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 958 | - } |
|
| 953 | + // Caracteres problematiques en iso-latin 1 |
|
| 954 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 955 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 956 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 957 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 961 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 962 | - // ==> on les remplace par l'entite HTML |
|
| 963 | - return str_replace($apostrophe, "'", $texte); |
|
| 960 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 961 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 962 | + // ==> on les remplace par l'entite HTML |
|
| 963 | + return str_replace($apostrophe, "'", $texte); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * texte encodé et quote pour XML |
| 978 | 978 | */ |
| 979 | 979 | function texte_backendq(string $texte): string { |
| 980 | - return addslashes(texte_backend($texte)); |
|
| 980 | + return addslashes(texte_backend($texte)); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | |
@@ -999,14 +999,14 @@ discard block |
||
| 999 | 999 | * Texte sans son numéro éventuel |
| 1000 | 1000 | **/ |
| 1001 | 1001 | function supprimer_numero(?string $texte): string { |
| 1002 | - if ($texte === null) { |
|
| 1003 | - return ''; |
|
| 1004 | - } |
|
| 1005 | - return preg_replace( |
|
| 1006 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1007 | - '', |
|
| 1008 | - $texte |
|
| 1009 | - ); |
|
| 1002 | + if ($texte === null) { |
|
| 1003 | + return ''; |
|
| 1004 | + } |
|
| 1005 | + return preg_replace( |
|
| 1006 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1007 | + '', |
|
| 1008 | + $texte |
|
| 1009 | + ); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | /** |
@@ -1029,18 +1029,18 @@ discard block |
||
| 1029 | 1029 | * Numéro de titre, sinon chaîne vide |
| 1030 | 1030 | **/ |
| 1031 | 1031 | function recuperer_numero(?string $texte): string { |
| 1032 | - if ( |
|
| 1033 | - $texte and |
|
| 1034 | - preg_match( |
|
| 1035 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | - $texte, |
|
| 1037 | - $regs |
|
| 1038 | - ) |
|
| 1039 | - ) { |
|
| 1040 | - return strval($regs[1]); |
|
| 1041 | - } else { |
|
| 1042 | - return ''; |
|
| 1043 | - } |
|
| 1032 | + if ( |
|
| 1033 | + $texte and |
|
| 1034 | + preg_match( |
|
| 1035 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | + $texte, |
|
| 1037 | + $regs |
|
| 1038 | + ) |
|
| 1039 | + ) { |
|
| 1040 | + return strval($regs[1]); |
|
| 1041 | + } else { |
|
| 1042 | + return ''; |
|
| 1043 | + } |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1067,16 +1067,16 @@ discard block |
||
| 1067 | 1067 | * texte ou tableau de textes converti |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function supprimer_tags($texte, $rempl = '') { |
| 1070 | - if ($texte === null) { |
|
| 1071 | - return ''; |
|
| 1072 | - } |
|
| 1073 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1074 | - // ne pas oublier un < final non ferme car coupe |
|
| 1075 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1076 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1077 | - $texte = str_replace('<', '<', $texte); |
|
| 1070 | + if ($texte === null) { |
|
| 1071 | + return ''; |
|
| 1072 | + } |
|
| 1073 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1074 | + // ne pas oublier un < final non ferme car coupe |
|
| 1075 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1076 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1077 | + $texte = str_replace('<', '<', $texte); |
|
| 1078 | 1078 | |
| 1079 | - return $texte; |
|
| 1079 | + return $texte; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1099,9 +1099,9 @@ discard block |
||
| 1099 | 1099 | * texte converti |
| 1100 | 1100 | **/ |
| 1101 | 1101 | function echapper_tags($texte, $rempl = '') { |
| 1102 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1102 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1103 | 1103 | |
| 1104 | - return $texte; |
|
| 1104 | + return $texte; |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | /** |
@@ -1122,18 +1122,18 @@ discard block |
||
| 1122 | 1122 | * texte converti |
| 1123 | 1123 | **/ |
| 1124 | 1124 | function textebrut($texte) { |
| 1125 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1126 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1127 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1128 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1129 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1130 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1131 | - $texte = supprimer_tags($texte); |
|
| 1132 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1133 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1134 | - $texte = str_replace('’', "'", $texte); |
|
| 1125 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1126 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1127 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1128 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1129 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1130 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1131 | + $texte = supprimer_tags($texte); |
|
| 1132 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1133 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1134 | + $texte = str_replace('’', "'", $texte); |
|
| 1135 | 1135 | |
| 1136 | - return $texte; |
|
| 1136 | + return $texte; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
@@ -1149,23 +1149,23 @@ discard block |
||
| 1149 | 1149 | * texte avec liens ouvrants |
| 1150 | 1150 | **/ |
| 1151 | 1151 | function liens_ouvrants($texte) { |
| 1152 | - if ( |
|
| 1153 | - preg_match_all( |
|
| 1154 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1155 | - $texte, |
|
| 1156 | - $liens, |
|
| 1157 | - PREG_PATTERN_ORDER |
|
| 1158 | - ) |
|
| 1159 | - ) { |
|
| 1160 | - foreach ($liens[0] as $a) { |
|
| 1161 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1162 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1163 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1164 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - return $texte; |
|
| 1152 | + if ( |
|
| 1153 | + preg_match_all( |
|
| 1154 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1155 | + $texte, |
|
| 1156 | + $liens, |
|
| 1157 | + PREG_PATTERN_ORDER |
|
| 1158 | + ) |
|
| 1159 | + ) { |
|
| 1160 | + foreach ($liens[0] as $a) { |
|
| 1161 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1162 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1163 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1164 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + return $texte; |
|
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | /** |
@@ -1175,22 +1175,22 @@ discard block |
||
| 1175 | 1175 | * @return string |
| 1176 | 1176 | */ |
| 1177 | 1177 | function liens_nofollow($texte) { |
| 1178 | - if (stripos($texte, '<a') === false) { |
|
| 1179 | - return $texte; |
|
| 1180 | - } |
|
| 1178 | + if (stripos($texte, '<a') === false) { |
|
| 1179 | + return $texte; |
|
| 1180 | + } |
|
| 1181 | 1181 | |
| 1182 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1183 | - foreach ($regs[0] as $a) { |
|
| 1184 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1185 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1186 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1187 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1188 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1182 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1183 | + foreach ($regs[0] as $a) { |
|
| 1184 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1185 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1186 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1187 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1188 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | 1192 | |
| 1193 | - return $texte; |
|
| 1193 | + return $texte; |
|
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | 1196 | /** |
@@ -1209,12 +1209,12 @@ discard block |
||
| 1209 | 1209 | * texte sans paraghaphes |
| 1210 | 1210 | **/ |
| 1211 | 1211 | function PtoBR($texte) { |
| 1212 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1213 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1214 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1215 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1212 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1213 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1214 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1215 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1216 | 1216 | |
| 1217 | - return $texte; |
|
| 1217 | + return $texte; |
|
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | |
@@ -1239,19 +1239,19 @@ discard block |
||
| 1239 | 1239 | * @return string texte encadré du style CSS |
| 1240 | 1240 | */ |
| 1241 | 1241 | function lignes_longues($texte) { |
| 1242 | - trigger_error( |
|
| 1243 | - sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1244 | - \E_USER_DEPRECATED |
|
| 1245 | - ); |
|
| 1242 | + trigger_error( |
|
| 1243 | + sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1244 | + \E_USER_DEPRECATED |
|
| 1245 | + ); |
|
| 1246 | 1246 | |
| 1247 | - if (!strlen(trim($texte))) { |
|
| 1248 | - return $texte; |
|
| 1249 | - } |
|
| 1250 | - include_spip('inc/texte'); |
|
| 1251 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1252 | - 'div' : 'span'; |
|
| 1247 | + if (!strlen(trim($texte))) { |
|
| 1248 | + return $texte; |
|
| 1249 | + } |
|
| 1250 | + include_spip('inc/texte'); |
|
| 1251 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1252 | + 'div' : 'span'; |
|
| 1253 | 1253 | |
| 1254 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1254 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | /** |
@@ -1270,30 +1270,30 @@ discard block |
||
| 1270 | 1270 | * @return string texte en majuscule |
| 1271 | 1271 | */ |
| 1272 | 1272 | function majuscules($texte) { |
| 1273 | - if (!strlen($texte)) { |
|
| 1274 | - return ''; |
|
| 1275 | - } |
|
| 1273 | + if (!strlen($texte)) { |
|
| 1274 | + return ''; |
|
| 1275 | + } |
|
| 1276 | 1276 | |
| 1277 | - // Cas du turc |
|
| 1278 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1279 | - # remplacer hors des tags et des entites |
|
| 1280 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1281 | - foreach ($regs as $n => $match) { |
|
| 1282 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1277 | + // Cas du turc |
|
| 1278 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1279 | + # remplacer hors des tags et des entites |
|
| 1280 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1281 | + foreach ($regs as $n => $match) { |
|
| 1282 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | 1285 | |
| 1286 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1286 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1287 | 1287 | |
| 1288 | - if ($regs) { |
|
| 1289 | - foreach ($regs as $n => $match) { |
|
| 1290 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1291 | - } |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1288 | + if ($regs) { |
|
| 1289 | + foreach ($regs as $n => $match) { |
|
| 1290 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1291 | + } |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | 1294 | |
| 1295 | - // Cas general |
|
| 1296 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1295 | + // Cas general |
|
| 1296 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | /** |
@@ -1315,38 +1315,38 @@ discard block |
||
| 1315 | 1315 | */ |
| 1316 | 1316 | function taille_en_octets($octets, $systeme = 'BI') { |
| 1317 | 1317 | |
| 1318 | - // Texte à afficher pour la taille |
|
| 1319 | - $affichage = ''; |
|
| 1318 | + // Texte à afficher pour la taille |
|
| 1319 | + $affichage = ''; |
|
| 1320 | 1320 | |
| 1321 | - static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1322 | - static $precisions = [0, 1, 1, 2]; |
|
| 1321 | + static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1322 | + static $precisions = [0, 1, 1, 2]; |
|
| 1323 | 1323 | |
| 1324 | - if ($octets >= 1) { |
|
| 1325 | - // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1326 | - $systeme = strtolower($systeme); |
|
| 1327 | - if ($systeme === 'bi') { |
|
| 1328 | - $kilo = 1024; |
|
| 1329 | - $suffixe_item = "_$systeme"; |
|
| 1330 | - } elseif ($systeme === 'si') { |
|
| 1331 | - $kilo = 1000; |
|
| 1332 | - $suffixe_item = ''; |
|
| 1333 | - } else { |
|
| 1334 | - return $affichage; |
|
| 1335 | - } |
|
| 1324 | + if ($octets >= 1) { |
|
| 1325 | + // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1326 | + $systeme = strtolower($systeme); |
|
| 1327 | + if ($systeme === 'bi') { |
|
| 1328 | + $kilo = 1024; |
|
| 1329 | + $suffixe_item = "_$systeme"; |
|
| 1330 | + } elseif ($systeme === 'si') { |
|
| 1331 | + $kilo = 1000; |
|
| 1332 | + $suffixe_item = ''; |
|
| 1333 | + } else { |
|
| 1334 | + return $affichage; |
|
| 1335 | + } |
|
| 1336 | 1336 | |
| 1337 | - // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1338 | - $puissance = floor(log($octets, $kilo)); |
|
| 1337 | + // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1338 | + $puissance = floor(log($octets, $kilo)); |
|
| 1339 | 1339 | |
| 1340 | - // Calcul de la taille et choix de l'unité |
|
| 1341 | - $affichage = _T( |
|
| 1342 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1343 | - [ |
|
| 1344 | - 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
|
| 1345 | - ] |
|
| 1346 | - ); |
|
| 1347 | - } |
|
| 1340 | + // Calcul de la taille et choix de l'unité |
|
| 1341 | + $affichage = _T( |
|
| 1342 | + 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1343 | + [ |
|
| 1344 | + 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
|
| 1345 | + ] |
|
| 1346 | + ); |
|
| 1347 | + } |
|
| 1348 | 1348 | |
| 1349 | - return $affichage; |
|
| 1349 | + return $affichage; |
|
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | 1352 | |
@@ -1368,21 +1368,21 @@ discard block |
||
| 1368 | 1368 | * texte prêt pour être utilisé en attribut HTML |
| 1369 | 1369 | **/ |
| 1370 | 1370 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1371 | - if ($texte === null) { |
|
| 1372 | - return ''; |
|
| 1373 | - } |
|
| 1374 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1375 | - if ($textebrut) { |
|
| 1376 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1377 | - } |
|
| 1378 | - $texte = texte_backend($texte); |
|
| 1379 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1371 | + if ($texte === null) { |
|
| 1372 | + return ''; |
|
| 1373 | + } |
|
| 1374 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1375 | + if ($textebrut) { |
|
| 1376 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1377 | + } |
|
| 1378 | + $texte = texte_backend($texte); |
|
| 1379 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1380 | 1380 | |
| 1381 | - return preg_replace( |
|
| 1382 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1383 | - ['&', '&'], |
|
| 1384 | - $texte |
|
| 1385 | - ); |
|
| 1381 | + return preg_replace( |
|
| 1382 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1383 | + ['&', '&'], |
|
| 1384 | + $texte |
|
| 1385 | + ); |
|
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | |
@@ -1402,15 +1402,15 @@ discard block |
||
| 1402 | 1402 | * URL ou chaîne vide |
| 1403 | 1403 | **/ |
| 1404 | 1404 | function vider_url(?string $url, $entites = true): string { |
| 1405 | - if ($url === null) { |
|
| 1406 | - return ''; |
|
| 1407 | - } |
|
| 1408 | - # un message pour abs_url |
|
| 1409 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1410 | - $url = trim($url); |
|
| 1411 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1405 | + if ($url === null) { |
|
| 1406 | + return ''; |
|
| 1407 | + } |
|
| 1408 | + # un message pour abs_url |
|
| 1409 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1410 | + $url = trim($url); |
|
| 1411 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1412 | 1412 | |
| 1413 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1413 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | |
@@ -1425,10 +1425,10 @@ discard block |
||
| 1425 | 1425 | * @return string Adresse email maquillée |
| 1426 | 1426 | **/ |
| 1427 | 1427 | function antispam($texte) { |
| 1428 | - include_spip('inc/acces'); |
|
| 1429 | - $masque = creer_pass_aleatoire(3); |
|
| 1428 | + include_spip('inc/acces'); |
|
| 1429 | + $masque = creer_pass_aleatoire(3); |
|
| 1430 | 1430 | |
| 1431 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1431 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | /** |
@@ -1460,8 +1460,8 @@ discard block |
||
| 1460 | 1460 | * True si on a le droit d'accès, false sinon. |
| 1461 | 1461 | **/ |
| 1462 | 1462 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1463 | - include_spip('inc/acces'); |
|
| 1464 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1463 | + include_spip('inc/acces'); |
|
| 1464 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | /** |
@@ -1485,13 +1485,13 @@ discard block |
||
| 1485 | 1485 | * Retourne $texte, sinon $sinon. |
| 1486 | 1486 | **/ |
| 1487 | 1487 | function sinon($texte, $sinon = '') { |
| 1488 | - if ($texte) { |
|
| 1489 | - return $texte; |
|
| 1490 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1491 | - return $texte; |
|
| 1492 | - } else { |
|
| 1493 | - return $sinon; |
|
| 1494 | - } |
|
| 1488 | + if ($texte) { |
|
| 1489 | + return $texte; |
|
| 1490 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1491 | + return $texte; |
|
| 1492 | + } else { |
|
| 1493 | + return $sinon; |
|
| 1494 | + } |
|
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | 1497 | /** |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | * @return mixed |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function choixsivide($a, $vide, $pasvide) { |
| 1518 | - return $a ? $pasvide : $vide; |
|
| 1518 | + return $a ? $pasvide : $vide; |
|
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | /** |
@@ -1539,7 +1539,7 @@ discard block |
||
| 1539 | 1539 | * @return mixed |
| 1540 | 1540 | **/ |
| 1541 | 1541 | function choixsiegal($a1, $a2, $v, $f) { |
| 1542 | - return ($a1 == $a2) ? $v : $f; |
|
| 1542 | + return ($a1 == $a2) ? $v : $f; |
|
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | // |
@@ -1558,13 +1558,13 @@ discard block |
||
| 1558 | 1558 | * @return string |
| 1559 | 1559 | **/ |
| 1560 | 1560 | function filtrer_ical($texte) { |
| 1561 | - #include_spip('inc/charsets'); |
|
| 1562 | - $texte = html2unicode($texte); |
|
| 1563 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1564 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1565 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1561 | + #include_spip('inc/charsets'); |
|
| 1562 | + $texte = html2unicode($texte); |
|
| 1563 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1564 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1565 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1566 | 1566 | |
| 1567 | - return $texte; |
|
| 1567 | + return $texte; |
|
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | 1570 | |
@@ -1589,58 +1589,58 @@ discard block |
||
| 1589 | 1589 | * @return string |
| 1590 | 1590 | **/ |
| 1591 | 1591 | function post_autobr($texte, $delim = "\n_ ") { |
| 1592 | - if (!function_exists('echappe_html')) { |
|
| 1593 | - include_spip('inc/texte_mini'); |
|
| 1594 | - } |
|
| 1595 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1596 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1597 | - |
|
| 1598 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1599 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1600 | - } else { |
|
| 1601 | - $fin = ''; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - $texte = echappe_html($texte, '', true); |
|
| 1605 | - |
|
| 1606 | - // echapper les modeles |
|
| 1607 | - $collecteurModeles = null; |
|
| 1608 | - if (strpos($texte, '<') !== false) { |
|
| 1609 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1610 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1611 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1612 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - $debut = ''; |
|
| 1616 | - $suite = $texte; |
|
| 1617 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1618 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1619 | - $suite = substr($suite, $t); |
|
| 1620 | - $car = substr($suite, 0, 1); |
|
| 1621 | - if ( |
|
| 1622 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1623 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1624 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1625 | - ) { |
|
| 1626 | - $debut .= $delim; |
|
| 1627 | - } else { |
|
| 1628 | - $debut .= "\n"; |
|
| 1629 | - } |
|
| 1630 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1631 | - $debut .= $regs[0]; |
|
| 1632 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1633 | - } |
|
| 1634 | - } |
|
| 1635 | - $texte = $debut . $suite; |
|
| 1636 | - |
|
| 1637 | - if ($collecteurModeles) { |
|
| 1638 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - $texte = echappe_retour($texte); |
|
| 1642 | - |
|
| 1643 | - return $texte . $fin; |
|
| 1592 | + if (!function_exists('echappe_html')) { |
|
| 1593 | + include_spip('inc/texte_mini'); |
|
| 1594 | + } |
|
| 1595 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1596 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1597 | + |
|
| 1598 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1599 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1600 | + } else { |
|
| 1601 | + $fin = ''; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + $texte = echappe_html($texte, '', true); |
|
| 1605 | + |
|
| 1606 | + // echapper les modeles |
|
| 1607 | + $collecteurModeles = null; |
|
| 1608 | + if (strpos($texte, '<') !== false) { |
|
| 1609 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1610 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1611 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1612 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + $debut = ''; |
|
| 1616 | + $suite = $texte; |
|
| 1617 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1618 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1619 | + $suite = substr($suite, $t); |
|
| 1620 | + $car = substr($suite, 0, 1); |
|
| 1621 | + if ( |
|
| 1622 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1623 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1624 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1625 | + ) { |
|
| 1626 | + $debut .= $delim; |
|
| 1627 | + } else { |
|
| 1628 | + $debut .= "\n"; |
|
| 1629 | + } |
|
| 1630 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1631 | + $debut .= $regs[0]; |
|
| 1632 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1633 | + } |
|
| 1634 | + } |
|
| 1635 | + $texte = $debut . $suite; |
|
| 1636 | + |
|
| 1637 | + if ($collecteurModeles) { |
|
| 1638 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + $texte = echappe_retour($texte); |
|
| 1642 | + |
|
| 1643 | + return $texte . $fin; |
|
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | |
@@ -1675,30 +1675,30 @@ discard block |
||
| 1675 | 1675 | **/ |
| 1676 | 1676 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1677 | 1677 | |
| 1678 | - if ( |
|
| 1679 | - $letexte |
|
| 1680 | - and strpos($letexte, '<:') !== false |
|
| 1681 | - ) { |
|
| 1682 | - if (!$lang) { |
|
| 1683 | - $lang = $GLOBALS['spip_lang']; |
|
| 1684 | - } |
|
| 1685 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1686 | - if (is_bool($options)) { |
|
| 1687 | - $options = ['echappe_span' => $options]; |
|
| 1688 | - } |
|
| 1689 | - if (!isset($options['echappe_span'])) { |
|
| 1690 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1691 | - } |
|
| 1692 | - $options['lang'] = $lang; |
|
| 1678 | + if ( |
|
| 1679 | + $letexte |
|
| 1680 | + and strpos($letexte, '<:') !== false |
|
| 1681 | + ) { |
|
| 1682 | + if (!$lang) { |
|
| 1683 | + $lang = $GLOBALS['spip_lang']; |
|
| 1684 | + } |
|
| 1685 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1686 | + if (is_bool($options)) { |
|
| 1687 | + $options = ['echappe_span' => $options]; |
|
| 1688 | + } |
|
| 1689 | + if (!isset($options['echappe_span'])) { |
|
| 1690 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1691 | + } |
|
| 1692 | + $options['lang'] = $lang; |
|
| 1693 | 1693 | |
| 1694 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1695 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1696 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1694 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1695 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1696 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1697 | 1697 | |
| 1698 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1698 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1699 | 1699 | |
| 1700 | - } |
|
| 1701 | - return $letexte; |
|
| 1700 | + } |
|
| 1701 | + return $letexte; |
|
| 1702 | 1702 | } |
| 1703 | 1703 | |
| 1704 | 1704 | /** |
@@ -1736,34 +1736,34 @@ discard block |
||
| 1736 | 1736 | **/ |
| 1737 | 1737 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1738 | 1738 | |
| 1739 | - if ( |
|
| 1740 | - $letexte |
|
| 1741 | - and stripos($letexte, '<multi') !== false |
|
| 1742 | - ) { |
|
| 1743 | - if (!$lang) { |
|
| 1744 | - $lang = $GLOBALS['spip_lang']; |
|
| 1745 | - } |
|
| 1739 | + if ( |
|
| 1740 | + $letexte |
|
| 1741 | + and stripos($letexte, '<multi') !== false |
|
| 1742 | + ) { |
|
| 1743 | + if (!$lang) { |
|
| 1744 | + $lang = $GLOBALS['spip_lang']; |
|
| 1745 | + } |
|
| 1746 | 1746 | |
| 1747 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1748 | - if (is_bool($options)) { |
|
| 1749 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1750 | - } |
|
| 1751 | - if (!isset($options['echappe_span'])) { |
|
| 1752 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1753 | - } |
|
| 1754 | - if (!isset($options['lang_defaut'])) { |
|
| 1755 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1756 | - } |
|
| 1757 | - $options['lang'] = $lang; |
|
| 1747 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1748 | + if (is_bool($options)) { |
|
| 1749 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1750 | + } |
|
| 1751 | + if (!isset($options['echappe_span'])) { |
|
| 1752 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1753 | + } |
|
| 1754 | + if (!isset($options['lang_defaut'])) { |
|
| 1755 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1756 | + } |
|
| 1757 | + $options['lang'] = $lang; |
|
| 1758 | 1758 | |
| 1759 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1760 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 1761 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1759 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1760 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 1761 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1762 | 1762 | |
| 1763 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1764 | - } |
|
| 1763 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1764 | + } |
|
| 1765 | 1765 | |
| 1766 | - return $letexte; |
|
| 1766 | + return $letexte; |
|
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | 1769 | /** |
@@ -1773,7 +1773,7 @@ discard block |
||
| 1773 | 1773 | * @return string L'initiale en majuscule |
| 1774 | 1774 | */ |
| 1775 | 1775 | function filtre_initiale($nom) { |
| 1776 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1776 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1777 | 1777 | } |
| 1778 | 1778 | |
| 1779 | 1779 | |
@@ -1818,33 +1818,33 @@ discard block |
||
| 1818 | 1818 | * - null (interne) : si on empile |
| 1819 | 1819 | **/ |
| 1820 | 1820 | function unique($donnee, $famille = '', $cpt = false) { |
| 1821 | - static $mem = []; |
|
| 1822 | - // permettre de vider la pile et de la restaurer |
|
| 1823 | - // pour le calcul de introduction... |
|
| 1824 | - if ($famille == '_spip_raz_') { |
|
| 1825 | - $tmp = $mem; |
|
| 1826 | - $mem = []; |
|
| 1827 | - |
|
| 1828 | - return $tmp; |
|
| 1829 | - } elseif ($famille == '_spip_set_') { |
|
| 1830 | - $mem = $donnee; |
|
| 1831 | - |
|
| 1832 | - return; |
|
| 1833 | - } |
|
| 1834 | - // eviter une notice |
|
| 1835 | - if (!isset($mem[$famille])) { |
|
| 1836 | - $mem[$famille] = []; |
|
| 1837 | - } |
|
| 1838 | - if ($cpt) { |
|
| 1839 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1840 | - } |
|
| 1841 | - // eviter une notice |
|
| 1842 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1843 | - $mem[$famille][$donnee] = 0; |
|
| 1844 | - } |
|
| 1845 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1846 | - return $donnee; |
|
| 1847 | - } |
|
| 1821 | + static $mem = []; |
|
| 1822 | + // permettre de vider la pile et de la restaurer |
|
| 1823 | + // pour le calcul de introduction... |
|
| 1824 | + if ($famille == '_spip_raz_') { |
|
| 1825 | + $tmp = $mem; |
|
| 1826 | + $mem = []; |
|
| 1827 | + |
|
| 1828 | + return $tmp; |
|
| 1829 | + } elseif ($famille == '_spip_set_') { |
|
| 1830 | + $mem = $donnee; |
|
| 1831 | + |
|
| 1832 | + return; |
|
| 1833 | + } |
|
| 1834 | + // eviter une notice |
|
| 1835 | + if (!isset($mem[$famille])) { |
|
| 1836 | + $mem[$famille] = []; |
|
| 1837 | + } |
|
| 1838 | + if ($cpt) { |
|
| 1839 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1840 | + } |
|
| 1841 | + // eviter une notice |
|
| 1842 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1843 | + $mem[$famille][$donnee] = 0; |
|
| 1844 | + } |
|
| 1845 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1846 | + return $donnee; |
|
| 1847 | + } |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | |
@@ -1874,20 +1874,20 @@ discard block |
||
| 1874 | 1874 | * Une des valeurs en fonction du compteur. |
| 1875 | 1875 | **/ |
| 1876 | 1876 | function alterner($i, ...$args) { |
| 1877 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1878 | - $num = count($args); |
|
| 1877 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1878 | + $num = count($args); |
|
| 1879 | 1879 | |
| 1880 | - if ($num === 1 && is_array($args[0])) { |
|
| 1881 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1882 | - $args = array_values($args[0]); |
|
| 1883 | - $num = count($args); |
|
| 1884 | - } |
|
| 1880 | + if ($num === 1 && is_array($args[0])) { |
|
| 1881 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1882 | + $args = array_values($args[0]); |
|
| 1883 | + $num = count($args); |
|
| 1884 | + } |
|
| 1885 | 1885 | |
| 1886 | - // un index compris entre 0 et num exclus |
|
| 1887 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1888 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1889 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1890 | - return $args[$i]; |
|
| 1886 | + // un index compris entre 0 et num exclus |
|
| 1887 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1888 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1889 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1890 | + return $args[$i]; |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | 1893 | |
@@ -1913,52 +1913,52 @@ discard block |
||
| 1913 | 1913 | * - null lorsque l’attribut n’existe pas. |
| 1914 | 1914 | **/ |
| 1915 | 1915 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1916 | - if (is_array($balise)) { |
|
| 1917 | - array_walk( |
|
| 1918 | - $balise, |
|
| 1919 | - function (&$a, $key, $t) { |
|
| 1920 | - $a = extraire_attribut($a, $t); |
|
| 1921 | - }, |
|
| 1922 | - $attribut |
|
| 1923 | - ); |
|
| 1924 | - |
|
| 1925 | - return $balise; |
|
| 1926 | - } |
|
| 1927 | - if ( |
|
| 1928 | - $balise |
|
| 1929 | - && stripos($balise, $attribut) !== false |
|
| 1930 | - && preg_match( |
|
| 1931 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1932 | - . $attribut |
|
| 1933 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1934 | - $balise, |
|
| 1935 | - $r |
|
| 1936 | - ) |
|
| 1937 | - ) { |
|
| 1938 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1939 | - $r[4] = substr($r[3], 1, -1); |
|
| 1940 | - $r[3] = $r[3][0]; |
|
| 1941 | - } elseif ($r[3] !== '') { |
|
| 1942 | - $r[4] = $r[3]; |
|
| 1943 | - $r[3] = ''; |
|
| 1944 | - } else { |
|
| 1945 | - $r[4] = trim($r[2]); |
|
| 1946 | - } |
|
| 1947 | - $att = $r[4]; |
|
| 1948 | - if (strpos($att, '&#') !== false) { |
|
| 1949 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1950 | - } |
|
| 1951 | - $att = filtrer_entites($att); |
|
| 1952 | - } else { |
|
| 1953 | - $att = null; |
|
| 1954 | - $r = []; |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - if ($complet) { |
|
| 1958 | - return [$att, $r]; |
|
| 1959 | - } else { |
|
| 1960 | - return $att; |
|
| 1961 | - } |
|
| 1916 | + if (is_array($balise)) { |
|
| 1917 | + array_walk( |
|
| 1918 | + $balise, |
|
| 1919 | + function (&$a, $key, $t) { |
|
| 1920 | + $a = extraire_attribut($a, $t); |
|
| 1921 | + }, |
|
| 1922 | + $attribut |
|
| 1923 | + ); |
|
| 1924 | + |
|
| 1925 | + return $balise; |
|
| 1926 | + } |
|
| 1927 | + if ( |
|
| 1928 | + $balise |
|
| 1929 | + && stripos($balise, $attribut) !== false |
|
| 1930 | + && preg_match( |
|
| 1931 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1932 | + . $attribut |
|
| 1933 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1934 | + $balise, |
|
| 1935 | + $r |
|
| 1936 | + ) |
|
| 1937 | + ) { |
|
| 1938 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1939 | + $r[4] = substr($r[3], 1, -1); |
|
| 1940 | + $r[3] = $r[3][0]; |
|
| 1941 | + } elseif ($r[3] !== '') { |
|
| 1942 | + $r[4] = $r[3]; |
|
| 1943 | + $r[3] = ''; |
|
| 1944 | + } else { |
|
| 1945 | + $r[4] = trim($r[2]); |
|
| 1946 | + } |
|
| 1947 | + $att = $r[4]; |
|
| 1948 | + if (strpos($att, '&#') !== false) { |
|
| 1949 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1950 | + } |
|
| 1951 | + $att = filtrer_entites($att); |
|
| 1952 | + } else { |
|
| 1953 | + $att = null; |
|
| 1954 | + $r = []; |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + if ($complet) { |
|
| 1958 | + return [$att, $r]; |
|
| 1959 | + } else { |
|
| 1960 | + return $att; |
|
| 1961 | + } |
|
| 1962 | 1962 | } |
| 1963 | 1963 | |
| 1964 | 1964 | /** |
@@ -1991,41 +1991,41 @@ discard block |
||
| 1991 | 1991 | **/ |
| 1992 | 1992 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 1993 | 1993 | |
| 1994 | - if ($balise === null or $balise === '') { |
|
| 1995 | - return ''; |
|
| 1996 | - } |
|
| 1994 | + if ($balise === null or $balise === '') { |
|
| 1995 | + return ''; |
|
| 1996 | + } |
|
| 1997 | 1997 | |
| 1998 | - // preparer l'attribut |
|
| 1999 | - // supprimer les etc mais pas les balises html |
|
| 2000 | - // qui ont un sens dans un attribut value d'un input |
|
| 2001 | - if ($proteger) { |
|
| 2002 | - $val = attribut_html($val, false); |
|
| 2003 | - } |
|
| 1998 | + // preparer l'attribut |
|
| 1999 | + // supprimer les etc mais pas les balises html |
|
| 2000 | + // qui ont un sens dans un attribut value d'un input |
|
| 2001 | + if ($proteger) { |
|
| 2002 | + $val = attribut_html($val, false); |
|
| 2003 | + } |
|
| 2004 | 2004 | |
| 2005 | - // echapper les ' pour eviter tout bug |
|
| 2006 | - $val = str_replace("'", ''', $val); |
|
| 2007 | - if ($vider and strlen($val) === 0) { |
|
| 2008 | - $insert = ''; |
|
| 2009 | - } else { |
|
| 2010 | - $insert = " $attribut='$val'"; |
|
| 2011 | - } |
|
| 2005 | + // echapper les ' pour eviter tout bug |
|
| 2006 | + $val = str_replace("'", ''', $val); |
|
| 2007 | + if ($vider and strlen($val) === 0) { |
|
| 2008 | + $insert = ''; |
|
| 2009 | + } else { |
|
| 2010 | + $insert = " $attribut='$val'"; |
|
| 2011 | + } |
|
| 2012 | 2012 | |
| 2013 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2013 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2014 | 2014 | |
| 2015 | - if ($old !== null) { |
|
| 2016 | - // Remplacer l'ancien attribut du meme nom |
|
| 2017 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2018 | - } else { |
|
| 2019 | - // preferer une balise " />" (comme <img />) |
|
| 2020 | - if (preg_match(',/>,', $balise)) { |
|
| 2021 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2022 | - } // sinon une balise <a ...> ... </a> |
|
| 2023 | - else { |
|
| 2024 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2025 | - } |
|
| 2026 | - } |
|
| 2015 | + if ($old !== null) { |
|
| 2016 | + // Remplacer l'ancien attribut du meme nom |
|
| 2017 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2018 | + } else { |
|
| 2019 | + // preferer une balise " />" (comme <img />) |
|
| 2020 | + if (preg_match(',/>,', $balise)) { |
|
| 2021 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2022 | + } // sinon une balise <a ...> ... </a> |
|
| 2023 | + else { |
|
| 2024 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2025 | + } |
|
| 2026 | + } |
|
| 2027 | 2027 | |
| 2028 | - return $balise; |
|
| 2028 | + return $balise; |
|
| 2029 | 2029 | } |
| 2030 | 2030 | |
| 2031 | 2031 | /** |
@@ -2043,7 +2043,7 @@ discard block |
||
| 2043 | 2043 | * @return string Code HTML sans l'attribut |
| 2044 | 2044 | **/ |
| 2045 | 2045 | function vider_attribut(?string $balise, string $attribut): string { |
| 2046 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2046 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2047 | 2047 | } |
| 2048 | 2048 | |
| 2049 | 2049 | /** |
@@ -2055,50 +2055,50 @@ discard block |
||
| 2055 | 2055 | * @return string |
| 2056 | 2056 | */ |
| 2057 | 2057 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2058 | - if (is_string($class)) { |
|
| 2059 | - $class = explode(' ', trim($class)); |
|
| 2060 | - } |
|
| 2061 | - $class = array_filter($class); |
|
| 2062 | - $class = array_unique($class); |
|
| 2063 | - if (!$class) { |
|
| 2064 | - return $balise; |
|
| 2065 | - } |
|
| 2066 | - |
|
| 2067 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2068 | - $class_new = $class_courante; |
|
| 2069 | - foreach ($class as $c) { |
|
| 2070 | - $is_class_presente = false; |
|
| 2071 | - if ( |
|
| 2072 | - $class_courante |
|
| 2073 | - and str_contains($class_courante, (string) $c) |
|
| 2074 | - and in_array($c, preg_split(",\s+,", $class_courante)) |
|
| 2075 | - ) { |
|
| 2076 | - $is_class_presente = true; |
|
| 2077 | - } |
|
| 2078 | - if ( |
|
| 2079 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2080 | - and !$is_class_presente |
|
| 2081 | - ) { |
|
| 2082 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2083 | - } elseif ( |
|
| 2084 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2085 | - and $is_class_presente |
|
| 2086 | - ) { |
|
| 2087 | - $class_new = preg_split(",\s+,", $class_new); |
|
| 2088 | - $class_new = array_diff($class_new, [$c]); |
|
| 2089 | - $class_new = implode(' ', $class_new); |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - if ($class_new !== $class_courante) { |
|
| 2094 | - if (strlen($class_new)) { |
|
| 2095 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2096 | - } elseif ($class_courante) { |
|
| 2097 | - $balise = vider_attribut($balise, 'class'); |
|
| 2098 | - } |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - return $balise; |
|
| 2058 | + if (is_string($class)) { |
|
| 2059 | + $class = explode(' ', trim($class)); |
|
| 2060 | + } |
|
| 2061 | + $class = array_filter($class); |
|
| 2062 | + $class = array_unique($class); |
|
| 2063 | + if (!$class) { |
|
| 2064 | + return $balise; |
|
| 2065 | + } |
|
| 2066 | + |
|
| 2067 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2068 | + $class_new = $class_courante; |
|
| 2069 | + foreach ($class as $c) { |
|
| 2070 | + $is_class_presente = false; |
|
| 2071 | + if ( |
|
| 2072 | + $class_courante |
|
| 2073 | + and str_contains($class_courante, (string) $c) |
|
| 2074 | + and in_array($c, preg_split(",\s+,", $class_courante)) |
|
| 2075 | + ) { |
|
| 2076 | + $is_class_presente = true; |
|
| 2077 | + } |
|
| 2078 | + if ( |
|
| 2079 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2080 | + and !$is_class_presente |
|
| 2081 | + ) { |
|
| 2082 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2083 | + } elseif ( |
|
| 2084 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2085 | + and $is_class_presente |
|
| 2086 | + ) { |
|
| 2087 | + $class_new = preg_split(",\s+,", $class_new); |
|
| 2088 | + $class_new = array_diff($class_new, [$c]); |
|
| 2089 | + $class_new = implode(' ', $class_new); |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + if ($class_new !== $class_courante) { |
|
| 2094 | + if (strlen($class_new)) { |
|
| 2095 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2096 | + } elseif ($class_courante) { |
|
| 2097 | + $balise = vider_attribut($balise, 'class'); |
|
| 2098 | + } |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + return $balise; |
|
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | 2104 | /** |
@@ -2108,7 +2108,7 @@ discard block |
||
| 2108 | 2108 | * @return string |
| 2109 | 2109 | */ |
| 2110 | 2110 | function ajouter_class($balise, $class) { |
| 2111 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2111 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | 2114 | /** |
@@ -2118,7 +2118,7 @@ discard block |
||
| 2118 | 2118 | * @return string |
| 2119 | 2119 | */ |
| 2120 | 2120 | function supprimer_class($balise, $class) { |
| 2121 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2121 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | 2124 | /** |
@@ -2129,7 +2129,7 @@ discard block |
||
| 2129 | 2129 | * @return string |
| 2130 | 2130 | */ |
| 2131 | 2131 | function commuter_class($balise, $class) { |
| 2132 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2132 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | |
| 2135 | 2135 | /** |
@@ -2140,19 +2140,19 @@ discard block |
||
| 2140 | 2140 | * @return string |
| 2141 | 2141 | */ |
| 2142 | 2142 | function tester_config($id, $mode = '') { |
| 2143 | - include_spip('action/inscrire_auteur'); |
|
| 2143 | + include_spip('action/inscrire_auteur'); |
|
| 2144 | 2144 | |
| 2145 | - return tester_statut_inscription($mode, $id); |
|
| 2145 | + return tester_statut_inscription($mode, $id); |
|
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | // |
| 2149 | 2149 | // Quelques fonctions de calcul arithmetique |
| 2150 | 2150 | // |
| 2151 | 2151 | function floatstr($a) { |
| 2152 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2152 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2153 | 2153 | } |
| 2154 | 2154 | function strize($f, $a, $b) { |
| 2155 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2155 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | /** |
@@ -2171,11 +2171,11 @@ discard block |
||
| 2171 | 2171 | * @return int $a+$b |
| 2172 | 2172 | **/ |
| 2173 | 2173 | function plus($a, $b) { |
| 2174 | - return $a + $b; |
|
| 2174 | + return $a + $b; |
|
| 2175 | 2175 | } |
| 2176 | 2176 | |
| 2177 | 2177 | function strplus($a, $b) { |
| 2178 | - return strize('plus', $a, $b); |
|
| 2178 | + return strize('plus', $a, $b); |
|
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | 2181 | /** |
@@ -2194,11 +2194,11 @@ discard block |
||
| 2194 | 2194 | * @return int $a-$b |
| 2195 | 2195 | **/ |
| 2196 | 2196 | function moins($a, $b) { |
| 2197 | - return $a - $b; |
|
| 2197 | + return $a - $b; |
|
| 2198 | 2198 | } |
| 2199 | 2199 | |
| 2200 | 2200 | function strmoins($a, $b) { |
| 2201 | - return strize('moins', $a, $b); |
|
| 2201 | + return strize('moins', $a, $b); |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | /** |
@@ -2218,11 +2218,11 @@ discard block |
||
| 2218 | 2218 | * @return int $a*$b |
| 2219 | 2219 | **/ |
| 2220 | 2220 | function mult($a, $b) { |
| 2221 | - return $a * $b; |
|
| 2221 | + return $a * $b; |
|
| 2222 | 2222 | } |
| 2223 | 2223 | |
| 2224 | 2224 | function strmult($a, $b) { |
| 2225 | - return strize('mult', $a, $b); |
|
| 2225 | + return strize('mult', $a, $b); |
|
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | /** |
@@ -2242,11 +2242,11 @@ discard block |
||
| 2242 | 2242 | * @return int $a/$b (ou 0 si $b est nul) |
| 2243 | 2243 | **/ |
| 2244 | 2244 | function div($a, $b) { |
| 2245 | - return $b ? $a / $b : 0; |
|
| 2245 | + return $b ? $a / $b : 0; |
|
| 2246 | 2246 | } |
| 2247 | 2247 | |
| 2248 | 2248 | function strdiv($a, $b) { |
| 2249 | - return strize('div', $a, $b); |
|
| 2249 | + return strize('div', $a, $b); |
|
| 2250 | 2250 | } |
| 2251 | 2251 | |
| 2252 | 2252 | /** |
@@ -2267,7 +2267,7 @@ discard block |
||
| 2267 | 2267 | * @return int ($nb % $mod) + $add |
| 2268 | 2268 | **/ |
| 2269 | 2269 | function modulo($nb, $mod, $add = 0) { |
| 2270 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2270 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | |
@@ -2282,26 +2282,26 @@ discard block |
||
| 2282 | 2282 | * - true sinon |
| 2283 | 2283 | **/ |
| 2284 | 2284 | function nom_acceptable($nom) { |
| 2285 | - $remp2 = []; |
|
| 2286 | - $remp1 = []; |
|
| 2287 | - if (!is_string($nom)) { |
|
| 2288 | - return false; |
|
| 2289 | - } |
|
| 2290 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2291 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2292 | - } |
|
| 2293 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2294 | - foreach ($tags_acceptes as $tag) { |
|
| 2295 | - if (strlen($tag)) { |
|
| 2296 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2297 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2298 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2299 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2300 | - } |
|
| 2301 | - } |
|
| 2302 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2303 | - |
|
| 2304 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2285 | + $remp2 = []; |
|
| 2286 | + $remp1 = []; |
|
| 2287 | + if (!is_string($nom)) { |
|
| 2288 | + return false; |
|
| 2289 | + } |
|
| 2290 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2291 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2292 | + } |
|
| 2293 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2294 | + foreach ($tags_acceptes as $tag) { |
|
| 2295 | + if (strlen($tag)) { |
|
| 2296 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2297 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2298 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2299 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2300 | + } |
|
| 2301 | + } |
|
| 2302 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2303 | + |
|
| 2304 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | 2307 | |
@@ -2317,14 +2317,14 @@ discard block |
||
| 2317 | 2317 | * - renvoie un tableau si l'entree est un tableau |
| 2318 | 2318 | **/ |
| 2319 | 2319 | function email_valide($adresses) { |
| 2320 | - if (is_array($adresses)) { |
|
| 2321 | - $adresses = array_map('email_valide', $adresses); |
|
| 2322 | - $adresses = array_filter($adresses); |
|
| 2323 | - return $adresses; |
|
| 2324 | - } |
|
| 2320 | + if (is_array($adresses)) { |
|
| 2321 | + $adresses = array_map('email_valide', $adresses); |
|
| 2322 | + $adresses = array_filter($adresses); |
|
| 2323 | + return $adresses; |
|
| 2324 | + } |
|
| 2325 | 2325 | |
| 2326 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2327 | - return $email_valide($adresses); |
|
| 2326 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2327 | + return $email_valide($adresses); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | |
| 2330 | 2330 | /** |
@@ -2338,29 +2338,29 @@ discard block |
||
| 2338 | 2338 | * @return string texte |
| 2339 | 2339 | **/ |
| 2340 | 2340 | function afficher_enclosures($tags) { |
| 2341 | - $s = []; |
|
| 2342 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2343 | - if ( |
|
| 2344 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2345 | - and $t = extraire_attribut($tag, 'href') |
|
| 2346 | - ) { |
|
| 2347 | - $s[] = preg_replace( |
|
| 2348 | - ',>[^<]+</a>,S', |
|
| 2349 | - '>' |
|
| 2350 | - . http_img_pack( |
|
| 2351 | - 'attachment-16.png', |
|
| 2352 | - $t, |
|
| 2353 | - '', |
|
| 2354 | - $t, |
|
| 2355 | - ['utiliser_suffixe_size' => true] |
|
| 2356 | - ) |
|
| 2357 | - . '</a>', |
|
| 2358 | - $tag |
|
| 2359 | - ); |
|
| 2360 | - } |
|
| 2361 | - } |
|
| 2362 | - |
|
| 2363 | - return join(' ', $s); |
|
| 2341 | + $s = []; |
|
| 2342 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2343 | + if ( |
|
| 2344 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2345 | + and $t = extraire_attribut($tag, 'href') |
|
| 2346 | + ) { |
|
| 2347 | + $s[] = preg_replace( |
|
| 2348 | + ',>[^<]+</a>,S', |
|
| 2349 | + '>' |
|
| 2350 | + . http_img_pack( |
|
| 2351 | + 'attachment-16.png', |
|
| 2352 | + $t, |
|
| 2353 | + '', |
|
| 2354 | + $t, |
|
| 2355 | + ['utiliser_suffixe_size' => true] |
|
| 2356 | + ) |
|
| 2357 | + . '</a>', |
|
| 2358 | + $tag |
|
| 2359 | + ); |
|
| 2360 | + } |
|
| 2361 | + } |
|
| 2362 | + |
|
| 2363 | + return join(' ', $s); |
|
| 2364 | 2364 | } |
| 2365 | 2365 | |
| 2366 | 2366 | /** |
@@ -2375,15 +2375,15 @@ discard block |
||
| 2375 | 2375 | * @return string Liens trouvés |
| 2376 | 2376 | **/ |
| 2377 | 2377 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2378 | - $s = []; |
|
| 2379 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2380 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2381 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2382 | - $s[] = $tag; |
|
| 2383 | - } |
|
| 2384 | - } |
|
| 2378 | + $s = []; |
|
| 2379 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2380 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2381 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2382 | + $s[] = $tag; |
|
| 2383 | + } |
|
| 2384 | + } |
|
| 2385 | 2385 | |
| 2386 | - return join(', ', $s); |
|
| 2386 | + return join(', ', $s); |
|
| 2387 | 2387 | } |
| 2388 | 2388 | |
| 2389 | 2389 | |
@@ -2405,21 +2405,21 @@ discard block |
||
| 2405 | 2405 | * @return string Tag HTML `<a>` avec microformat. |
| 2406 | 2406 | **/ |
| 2407 | 2407 | function enclosure2microformat($e) { |
| 2408 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2409 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2410 | - } |
|
| 2411 | - $type = extraire_attribut($e, 'type'); |
|
| 2412 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2413 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2414 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2415 | - } |
|
| 2416 | - $fichier = basename($url); |
|
| 2408 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2409 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2410 | + } |
|
| 2411 | + $type = extraire_attribut($e, 'type'); |
|
| 2412 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2413 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2414 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2415 | + } |
|
| 2416 | + $fichier = basename($url); |
|
| 2417 | 2417 | |
| 2418 | - return '<a rel="enclosure"' |
|
| 2419 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2420 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2421 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2422 | - . '>' . $fichier . '</a>'; |
|
| 2418 | + return '<a rel="enclosure"' |
|
| 2419 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2420 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2421 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2422 | + . '>' . $fichier . '</a>'; |
|
| 2423 | 2423 | } |
| 2424 | 2424 | |
| 2425 | 2425 | /** |
@@ -2437,24 +2437,24 @@ discard block |
||
| 2437 | 2437 | * @return string Tags RSS `<enclosure>`. |
| 2438 | 2438 | **/ |
| 2439 | 2439 | function microformat2enclosure($tags) { |
| 2440 | - $enclosures = []; |
|
| 2441 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2442 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2443 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2444 | - $type = extraire_attribut($e, 'type'); |
|
| 2445 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2446 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2447 | - } # vieux data |
|
| 2448 | - $fichier = basename($url); |
|
| 2449 | - $enclosures[] = '<enclosure' |
|
| 2450 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2451 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2452 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2453 | - . ' />'; |
|
| 2454 | - } |
|
| 2455 | - } |
|
| 2440 | + $enclosures = []; |
|
| 2441 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2442 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2443 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2444 | + $type = extraire_attribut($e, 'type'); |
|
| 2445 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2446 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2447 | + } # vieux data |
|
| 2448 | + $fichier = basename($url); |
|
| 2449 | + $enclosures[] = '<enclosure' |
|
| 2450 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2451 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2452 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2453 | + . ' />'; |
|
| 2454 | + } |
|
| 2455 | + } |
|
| 2456 | 2456 | |
| 2457 | - return join("\n", $enclosures); |
|
| 2457 | + return join("\n", $enclosures); |
|
| 2458 | 2458 | } |
| 2459 | 2459 | |
| 2460 | 2460 | |
@@ -2470,16 +2470,16 @@ discard block |
||
| 2470 | 2470 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2471 | 2471 | **/ |
| 2472 | 2472 | function tags2dcsubject($tags) { |
| 2473 | - $subjects = ''; |
|
| 2474 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2475 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2476 | - $subjects .= '<dc:subject>' |
|
| 2477 | - . texte_backend(textebrut($e)) |
|
| 2478 | - . '</dc:subject>' . "\n"; |
|
| 2479 | - } |
|
| 2480 | - } |
|
| 2473 | + $subjects = ''; |
|
| 2474 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2475 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2476 | + $subjects .= '<dc:subject>' |
|
| 2477 | + . texte_backend(textebrut($e)) |
|
| 2478 | + . '</dc:subject>' . "\n"; |
|
| 2479 | + } |
|
| 2480 | + } |
|
| 2481 | 2481 | |
| 2482 | - return $subjects; |
|
| 2482 | + return $subjects; |
|
| 2483 | 2483 | } |
| 2484 | 2484 | |
| 2485 | 2485 | /** |
@@ -2508,27 +2508,27 @@ discard block |
||
| 2508 | 2508 | * - Tableau de résultats, si tableau en entrée. |
| 2509 | 2509 | **/ |
| 2510 | 2510 | function extraire_balise($texte, $tag = 'a') { |
| 2511 | - if (is_array($texte)) { |
|
| 2512 | - array_walk( |
|
| 2513 | - $texte, |
|
| 2514 | - function (&$a, $key, $t) { |
|
| 2515 | - $a = extraire_balise($a, $t); |
|
| 2516 | - }, |
|
| 2517 | - $tag |
|
| 2518 | - ); |
|
| 2519 | - |
|
| 2520 | - return $texte; |
|
| 2521 | - } |
|
| 2522 | - |
|
| 2523 | - if ( |
|
| 2524 | - preg_match( |
|
| 2525 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2526 | - $texte, |
|
| 2527 | - $regs |
|
| 2528 | - ) |
|
| 2529 | - ) { |
|
| 2530 | - return $regs[0]; |
|
| 2531 | - } |
|
| 2511 | + if (is_array($texte)) { |
|
| 2512 | + array_walk( |
|
| 2513 | + $texte, |
|
| 2514 | + function (&$a, $key, $t) { |
|
| 2515 | + $a = extraire_balise($a, $t); |
|
| 2516 | + }, |
|
| 2517 | + $tag |
|
| 2518 | + ); |
|
| 2519 | + |
|
| 2520 | + return $texte; |
|
| 2521 | + } |
|
| 2522 | + |
|
| 2523 | + if ( |
|
| 2524 | + preg_match( |
|
| 2525 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2526 | + $texte, |
|
| 2527 | + $regs |
|
| 2528 | + ) |
|
| 2529 | + ) { |
|
| 2530 | + return $regs[0]; |
|
| 2531 | + } |
|
| 2532 | 2532 | } |
| 2533 | 2533 | |
| 2534 | 2534 | /** |
@@ -2556,30 +2556,30 @@ discard block |
||
| 2556 | 2556 | * - Tableau de résultats, si tableau en entrée. |
| 2557 | 2557 | **/ |
| 2558 | 2558 | function extraire_balises($texte, $tag = 'a') { |
| 2559 | - if (is_array($texte)) { |
|
| 2560 | - array_walk( |
|
| 2561 | - $texte, |
|
| 2562 | - function (&$a, $key, $t) { |
|
| 2563 | - $a = extraire_balises($a, $t); |
|
| 2564 | - }, |
|
| 2565 | - $tag |
|
| 2566 | - ); |
|
| 2567 | - |
|
| 2568 | - return $texte; |
|
| 2569 | - } |
|
| 2570 | - |
|
| 2571 | - if ( |
|
| 2572 | - preg_match_all( |
|
| 2573 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2574 | - $texte, |
|
| 2575 | - $regs, |
|
| 2576 | - PREG_PATTERN_ORDER |
|
| 2577 | - ) |
|
| 2578 | - ) { |
|
| 2579 | - return $regs[0]; |
|
| 2580 | - } else { |
|
| 2581 | - return []; |
|
| 2582 | - } |
|
| 2559 | + if (is_array($texte)) { |
|
| 2560 | + array_walk( |
|
| 2561 | + $texte, |
|
| 2562 | + function (&$a, $key, $t) { |
|
| 2563 | + $a = extraire_balises($a, $t); |
|
| 2564 | + }, |
|
| 2565 | + $tag |
|
| 2566 | + ); |
|
| 2567 | + |
|
| 2568 | + return $texte; |
|
| 2569 | + } |
|
| 2570 | + |
|
| 2571 | + if ( |
|
| 2572 | + preg_match_all( |
|
| 2573 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2574 | + $texte, |
|
| 2575 | + $regs, |
|
| 2576 | + PREG_PATTERN_ORDER |
|
| 2577 | + ) |
|
| 2578 | + ) { |
|
| 2579 | + return $regs[0]; |
|
| 2580 | + } else { |
|
| 2581 | + return []; |
|
| 2582 | + } |
|
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | /** |
@@ -2608,11 +2608,11 @@ discard block |
||
| 2608 | 2608 | * - `$def` si on n'a pas transmis de tableau |
| 2609 | 2609 | **/ |
| 2610 | 2610 | function in_any($val, $vals, $def = '') { |
| 2611 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2612 | - $vals = $v; |
|
| 2613 | - } |
|
| 2611 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2612 | + $vals = $v; |
|
| 2613 | + } |
|
| 2614 | 2614 | |
| 2615 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2615 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2616 | 2616 | } |
| 2617 | 2617 | |
| 2618 | 2618 | |
@@ -2633,12 +2633,12 @@ discard block |
||
| 2633 | 2633 | * Résultat du calcul |
| 2634 | 2634 | **/ |
| 2635 | 2635 | function valeur_numerique($expr) { |
| 2636 | - $a = 0; |
|
| 2637 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2638 | - eval("\$a = $expr;"); |
|
| 2639 | - } |
|
| 2636 | + $a = 0; |
|
| 2637 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2638 | + eval("\$a = $expr;"); |
|
| 2639 | + } |
|
| 2640 | 2640 | |
| 2641 | - return intval($a); |
|
| 2641 | + return intval($a); |
|
| 2642 | 2642 | } |
| 2643 | 2643 | |
| 2644 | 2644 | /** |
@@ -2657,7 +2657,7 @@ discard block |
||
| 2657 | 2657 | * Retourne `$a*$b/$c` |
| 2658 | 2658 | **/ |
| 2659 | 2659 | function regledetrois($a, $b, $c) { |
| 2660 | - return round($a * $b / $c); |
|
| 2660 | + return round($a * $b / $c); |
|
| 2661 | 2661 | } |
| 2662 | 2662 | |
| 2663 | 2663 | |
@@ -2680,79 +2680,79 @@ discard block |
||
| 2680 | 2680 | * @return string Suite de champs input hidden |
| 2681 | 2681 | **/ |
| 2682 | 2682 | function form_hidden(?string $action = ''): string { |
| 2683 | - $action ??= ''; |
|
| 2684 | - |
|
| 2685 | - $contexte = []; |
|
| 2686 | - include_spip('inc/urls'); |
|
| 2687 | - if ( |
|
| 2688 | - $p = urls_decoder_url($action, '') |
|
| 2689 | - and reset($p) |
|
| 2690 | - ) { |
|
| 2691 | - $fond = array_shift($p); |
|
| 2692 | - if ($fond != '404') { |
|
| 2693 | - $contexte = array_shift($p); |
|
| 2694 | - $contexte['page'] = $fond; |
|
| 2695 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2696 | - } |
|
| 2697 | - } |
|
| 2698 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2699 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2700 | - unset($contexte['type']); |
|
| 2701 | - } |
|
| 2702 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2703 | - unset($contexte['type-page']); |
|
| 2704 | - } |
|
| 2705 | - |
|
| 2706 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2707 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2708 | - $values = []; |
|
| 2709 | - |
|
| 2710 | - // d'abord avec celles de l'url |
|
| 2711 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2712 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2713 | - $c = explode('=', $c, 2); |
|
| 2714 | - $var = array_shift($c); |
|
| 2715 | - $val = array_shift($c) ?? ''; |
|
| 2716 | - if ($var) { |
|
| 2717 | - $val = rawurldecode($val); |
|
| 2718 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2719 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2720 | - $values[] = [$var, $val]; |
|
| 2721 | - } else { |
|
| 2722 | - if (!isset($values[$var])) { |
|
| 2723 | - $values[$var] = [$var, $val]; |
|
| 2724 | - } |
|
| 2725 | - } |
|
| 2726 | - } |
|
| 2727 | - } |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2731 | - foreach ($contexte as $var => $val) { |
|
| 2732 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2733 | - $values[] = [$var, $val]; |
|
| 2734 | - } else { |
|
| 2735 | - if (!isset($values[$var])) { |
|
| 2736 | - $values[$var] = [$var, $val]; |
|
| 2737 | - } |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - |
|
| 2741 | - // puis on rassemble le tout |
|
| 2742 | - $hidden = []; |
|
| 2743 | - foreach ($values as $value) { |
|
| 2744 | - [$var, $val] = $value; |
|
| 2745 | - $hidden[] = '<input name="' |
|
| 2746 | - . entites_html($var) |
|
| 2747 | - . '"' |
|
| 2748 | - . (is_null($val) |
|
| 2749 | - ? '' |
|
| 2750 | - : ' value="' . entites_html($val) . '"' |
|
| 2751 | - ) |
|
| 2752 | - . ' type="hidden"' . "\n/>"; |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - return join('', $hidden); |
|
| 2683 | + $action ??= ''; |
|
| 2684 | + |
|
| 2685 | + $contexte = []; |
|
| 2686 | + include_spip('inc/urls'); |
|
| 2687 | + if ( |
|
| 2688 | + $p = urls_decoder_url($action, '') |
|
| 2689 | + and reset($p) |
|
| 2690 | + ) { |
|
| 2691 | + $fond = array_shift($p); |
|
| 2692 | + if ($fond != '404') { |
|
| 2693 | + $contexte = array_shift($p); |
|
| 2694 | + $contexte['page'] = $fond; |
|
| 2695 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2696 | + } |
|
| 2697 | + } |
|
| 2698 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2699 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2700 | + unset($contexte['type']); |
|
| 2701 | + } |
|
| 2702 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2703 | + unset($contexte['type-page']); |
|
| 2704 | + } |
|
| 2705 | + |
|
| 2706 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2707 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2708 | + $values = []; |
|
| 2709 | + |
|
| 2710 | + // d'abord avec celles de l'url |
|
| 2711 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2712 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2713 | + $c = explode('=', $c, 2); |
|
| 2714 | + $var = array_shift($c); |
|
| 2715 | + $val = array_shift($c) ?? ''; |
|
| 2716 | + if ($var) { |
|
| 2717 | + $val = rawurldecode($val); |
|
| 2718 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2719 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2720 | + $values[] = [$var, $val]; |
|
| 2721 | + } else { |
|
| 2722 | + if (!isset($values[$var])) { |
|
| 2723 | + $values[$var] = [$var, $val]; |
|
| 2724 | + } |
|
| 2725 | + } |
|
| 2726 | + } |
|
| 2727 | + } |
|
| 2728 | + } |
|
| 2729 | + |
|
| 2730 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2731 | + foreach ($contexte as $var => $val) { |
|
| 2732 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2733 | + $values[] = [$var, $val]; |
|
| 2734 | + } else { |
|
| 2735 | + if (!isset($values[$var])) { |
|
| 2736 | + $values[$var] = [$var, $val]; |
|
| 2737 | + } |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + |
|
| 2741 | + // puis on rassemble le tout |
|
| 2742 | + $hidden = []; |
|
| 2743 | + foreach ($values as $value) { |
|
| 2744 | + [$var, $val] = $value; |
|
| 2745 | + $hidden[] = '<input name="' |
|
| 2746 | + . entites_html($var) |
|
| 2747 | + . '"' |
|
| 2748 | + . (is_null($val) |
|
| 2749 | + ? '' |
|
| 2750 | + : ' value="' . entites_html($val) . '"' |
|
| 2751 | + ) |
|
| 2752 | + . ' type="hidden"' . "\n/>"; |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + return join('', $hidden); |
|
| 2756 | 2756 | } |
| 2757 | 2757 | |
| 2758 | 2758 | |
@@ -2774,7 +2774,7 @@ discard block |
||
| 2774 | 2774 | * - la première valeur du tableau sinon. |
| 2775 | 2775 | **/ |
| 2776 | 2776 | function filtre_reset($array) { |
| 2777 | - return !is_array($array) ? null : reset($array); |
|
| 2777 | + return !is_array($array) ? null : reset($array); |
|
| 2778 | 2778 | } |
| 2779 | 2779 | |
| 2780 | 2780 | /** |
@@ -2795,7 +2795,7 @@ discard block |
||
| 2795 | 2795 | * - la dernière valeur du tableau sinon. |
| 2796 | 2796 | **/ |
| 2797 | 2797 | function filtre_end($array) { |
| 2798 | - return !is_array($array) ? null : end($array); |
|
| 2798 | + return !is_array($array) ? null : end($array); |
|
| 2799 | 2799 | } |
| 2800 | 2800 | |
| 2801 | 2801 | /** |
@@ -2815,11 +2815,11 @@ discard block |
||
| 2815 | 2815 | * |
| 2816 | 2816 | **/ |
| 2817 | 2817 | function filtre_push($array, $val) { |
| 2818 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2819 | - return ''; |
|
| 2820 | - } |
|
| 2818 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2819 | + return ''; |
|
| 2820 | + } |
|
| 2821 | 2821 | |
| 2822 | - return $array; |
|
| 2822 | + return $array; |
|
| 2823 | 2823 | } |
| 2824 | 2824 | |
| 2825 | 2825 | /** |
@@ -2838,7 +2838,7 @@ discard block |
||
| 2838 | 2838 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2839 | 2839 | **/ |
| 2840 | 2840 | function filtre_find($array, $val) { |
| 2841 | - return (is_array($array) and in_array($val, $array)); |
|
| 2841 | + return (is_array($array) and in_array($val, $array)); |
|
| 2842 | 2842 | } |
| 2843 | 2843 | |
| 2844 | 2844 | |
@@ -2855,13 +2855,13 @@ discard block |
||
| 2855 | 2855 | * Contenu avec urls en absolus |
| 2856 | 2856 | **/ |
| 2857 | 2857 | function urls_absolues_css($contenu, $source) { |
| 2858 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2858 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2859 | 2859 | |
| 2860 | - return preg_replace_callback( |
|
| 2861 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2862 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2863 | - $contenu |
|
| 2864 | - ); |
|
| 2860 | + return preg_replace_callback( |
|
| 2861 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2862 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2863 | + $contenu |
|
| 2864 | + ); |
|
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | |
@@ -2890,119 +2890,119 @@ discard block |
||
| 2890 | 2890 | * Chemin du fichier CSS inversé |
| 2891 | 2891 | **/ |
| 2892 | 2892 | function direction_css($css, $voulue = '') { |
| 2893 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2894 | - return $css; |
|
| 2895 | - } |
|
| 2896 | - include_spip('inc/lang'); |
|
| 2897 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2898 | - if ($voulue = strtolower($voulue)) { |
|
| 2899 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2900 | - $voulue = lang_dir($voulue); |
|
| 2901 | - } |
|
| 2902 | - } else { |
|
| 2903 | - $voulue = lang_dir(); |
|
| 2904 | - } |
|
| 2905 | - |
|
| 2906 | - $r = count($r) > 1; |
|
| 2907 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2908 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2909 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2910 | - |
|
| 2911 | - if ($voulue == $dir) { |
|
| 2912 | - return $css; |
|
| 2913 | - } |
|
| 2914 | - |
|
| 2915 | - if ( |
|
| 2916 | - // url absolue |
|
| 2917 | - preg_match(',^https?:,i', $css) |
|
| 2918 | - // ou qui contient un ? |
|
| 2919 | - or (($p = strpos($css, '?')) !== false) |
|
| 2920 | - ) { |
|
| 2921 | - $distant = true; |
|
| 2922 | - $cssf = parse_url($css); |
|
| 2923 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2924 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2925 | - } else { |
|
| 2926 | - $distant = false; |
|
| 2927 | - $cssf = $css; |
|
| 2928 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2929 | - //propose (rien a faire dans ce cas) |
|
| 2930 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2931 | - if (@file_exists($f)) { |
|
| 2932 | - return $f; |
|
| 2933 | - } |
|
| 2934 | - } |
|
| 2935 | - |
|
| 2936 | - // 2. |
|
| 2937 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2938 | - $f = $dir_var |
|
| 2939 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2940 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2941 | - |
|
| 2942 | - // la css peut etre distante (url absolue !) |
|
| 2943 | - if ($distant) { |
|
| 2944 | - include_spip('inc/distant'); |
|
| 2945 | - $res = recuperer_url($css); |
|
| 2946 | - if (!$res or !$contenu = $res['page']) { |
|
| 2947 | - return $css; |
|
| 2948 | - } |
|
| 2949 | - } else { |
|
| 2950 | - if ( |
|
| 2951 | - (@filemtime($f) > @filemtime($css)) |
|
| 2952 | - and (_VAR_MODE != 'recalcul') |
|
| 2953 | - ) { |
|
| 2954 | - return $f; |
|
| 2955 | - } |
|
| 2956 | - if (!lire_fichier($css, $contenu)) { |
|
| 2957 | - return $css; |
|
| 2958 | - } |
|
| 2959 | - } |
|
| 2960 | - |
|
| 2961 | - |
|
| 2962 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2963 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2964 | - $parser = new csstidy(); |
|
| 2965 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2966 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2967 | - $parser->parse($contenu); |
|
| 2968 | - |
|
| 2969 | - $contenu = $parser->print->plain(); |
|
| 2970 | - |
|
| 2971 | - |
|
| 2972 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2973 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2974 | - $src = []; |
|
| 2975 | - $src_direction_css = []; |
|
| 2976 | - $src_faux_abs = []; |
|
| 2977 | - $d = dirname($css); |
|
| 2978 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2979 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2980 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2981 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2982 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2983 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2984 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2985 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2986 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2987 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2988 | - } |
|
| 2989 | - $src[] = $regs[0][$k]; |
|
| 2990 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2991 | - } |
|
| 2992 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2993 | - |
|
| 2994 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2995 | - |
|
| 2996 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2997 | - if (count($src_faux_abs)) { |
|
| 2998 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2999 | - } |
|
| 3000 | - |
|
| 3001 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3002 | - return $css; |
|
| 3003 | - } |
|
| 3004 | - |
|
| 3005 | - return $f; |
|
| 2893 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2894 | + return $css; |
|
| 2895 | + } |
|
| 2896 | + include_spip('inc/lang'); |
|
| 2897 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2898 | + if ($voulue = strtolower($voulue)) { |
|
| 2899 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2900 | + $voulue = lang_dir($voulue); |
|
| 2901 | + } |
|
| 2902 | + } else { |
|
| 2903 | + $voulue = lang_dir(); |
|
| 2904 | + } |
|
| 2905 | + |
|
| 2906 | + $r = count($r) > 1; |
|
| 2907 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2908 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2909 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2910 | + |
|
| 2911 | + if ($voulue == $dir) { |
|
| 2912 | + return $css; |
|
| 2913 | + } |
|
| 2914 | + |
|
| 2915 | + if ( |
|
| 2916 | + // url absolue |
|
| 2917 | + preg_match(',^https?:,i', $css) |
|
| 2918 | + // ou qui contient un ? |
|
| 2919 | + or (($p = strpos($css, '?')) !== false) |
|
| 2920 | + ) { |
|
| 2921 | + $distant = true; |
|
| 2922 | + $cssf = parse_url($css); |
|
| 2923 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2924 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2925 | + } else { |
|
| 2926 | + $distant = false; |
|
| 2927 | + $cssf = $css; |
|
| 2928 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2929 | + //propose (rien a faire dans ce cas) |
|
| 2930 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2931 | + if (@file_exists($f)) { |
|
| 2932 | + return $f; |
|
| 2933 | + } |
|
| 2934 | + } |
|
| 2935 | + |
|
| 2936 | + // 2. |
|
| 2937 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2938 | + $f = $dir_var |
|
| 2939 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2940 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2941 | + |
|
| 2942 | + // la css peut etre distante (url absolue !) |
|
| 2943 | + if ($distant) { |
|
| 2944 | + include_spip('inc/distant'); |
|
| 2945 | + $res = recuperer_url($css); |
|
| 2946 | + if (!$res or !$contenu = $res['page']) { |
|
| 2947 | + return $css; |
|
| 2948 | + } |
|
| 2949 | + } else { |
|
| 2950 | + if ( |
|
| 2951 | + (@filemtime($f) > @filemtime($css)) |
|
| 2952 | + and (_VAR_MODE != 'recalcul') |
|
| 2953 | + ) { |
|
| 2954 | + return $f; |
|
| 2955 | + } |
|
| 2956 | + if (!lire_fichier($css, $contenu)) { |
|
| 2957 | + return $css; |
|
| 2958 | + } |
|
| 2959 | + } |
|
| 2960 | + |
|
| 2961 | + |
|
| 2962 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2963 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2964 | + $parser = new csstidy(); |
|
| 2965 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2966 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2967 | + $parser->parse($contenu); |
|
| 2968 | + |
|
| 2969 | + $contenu = $parser->print->plain(); |
|
| 2970 | + |
|
| 2971 | + |
|
| 2972 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2973 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2974 | + $src = []; |
|
| 2975 | + $src_direction_css = []; |
|
| 2976 | + $src_faux_abs = []; |
|
| 2977 | + $d = dirname($css); |
|
| 2978 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2979 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2980 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2981 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2982 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2983 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2984 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2985 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2986 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2987 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2988 | + } |
|
| 2989 | + $src[] = $regs[0][$k]; |
|
| 2990 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2991 | + } |
|
| 2992 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2993 | + |
|
| 2994 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2995 | + |
|
| 2996 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2997 | + if (count($src_faux_abs)) { |
|
| 2998 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2999 | + } |
|
| 3000 | + |
|
| 3001 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3002 | + return $css; |
|
| 3003 | + } |
|
| 3004 | + |
|
| 3005 | + return $f; |
|
| 3006 | 3006 | } |
| 3007 | 3007 | |
| 3008 | 3008 | |
@@ -3025,46 +3025,46 @@ discard block |
||
| 3025 | 3025 | * - Chemin ou URL du fichier CSS source sinon. |
| 3026 | 3026 | **/ |
| 3027 | 3027 | function url_absolue_css($css) { |
| 3028 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3029 | - return $css; |
|
| 3030 | - } |
|
| 3028 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3029 | + return $css; |
|
| 3030 | + } |
|
| 3031 | 3031 | |
| 3032 | - $url_absolue_css = url_absolue($css); |
|
| 3032 | + $url_absolue_css = url_absolue($css); |
|
| 3033 | 3033 | |
| 3034 | - $f = basename($css, '.css'); |
|
| 3035 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3036 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3037 | - . '.css'; |
|
| 3034 | + $f = basename($css, '.css'); |
|
| 3035 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3036 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3037 | + . '.css'; |
|
| 3038 | 3038 | |
| 3039 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3040 | - return $f; |
|
| 3041 | - } |
|
| 3039 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3040 | + return $f; |
|
| 3041 | + } |
|
| 3042 | 3042 | |
| 3043 | - if ($url_absolue_css == $css) { |
|
| 3044 | - if ( |
|
| 3045 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3046 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3047 | - ) { |
|
| 3048 | - include_spip('inc/distant'); |
|
| 3049 | - $contenu = recuperer_url($css); |
|
| 3050 | - $contenu = $contenu['page'] ?? ''; |
|
| 3051 | - if (!$contenu) { |
|
| 3052 | - return $css; |
|
| 3053 | - } |
|
| 3054 | - } |
|
| 3055 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3056 | - return $css; |
|
| 3057 | - } |
|
| 3043 | + if ($url_absolue_css == $css) { |
|
| 3044 | + if ( |
|
| 3045 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3046 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3047 | + ) { |
|
| 3048 | + include_spip('inc/distant'); |
|
| 3049 | + $contenu = recuperer_url($css); |
|
| 3050 | + $contenu = $contenu['page'] ?? ''; |
|
| 3051 | + if (!$contenu) { |
|
| 3052 | + return $css; |
|
| 3053 | + } |
|
| 3054 | + } |
|
| 3055 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3056 | + return $css; |
|
| 3057 | + } |
|
| 3058 | 3058 | |
| 3059 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3060 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3059 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3060 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3061 | 3061 | |
| 3062 | - // ecrire la css |
|
| 3063 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3064 | - return $css; |
|
| 3065 | - } |
|
| 3062 | + // ecrire la css |
|
| 3063 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3064 | + return $css; |
|
| 3065 | + } |
|
| 3066 | 3066 | |
| 3067 | - return $f; |
|
| 3067 | + return $f; |
|
| 3068 | 3068 | } |
| 3069 | 3069 | |
| 3070 | 3070 | |
@@ -3098,24 +3098,24 @@ discard block |
||
| 3098 | 3098 | * Valeur trouvée ou valeur par défaut. |
| 3099 | 3099 | **/ |
| 3100 | 3100 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3101 | - foreach (explode('/', $cle) as $k) { |
|
| 3102 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3101 | + foreach (explode('/', $cle) as $k) { |
|
| 3102 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3103 | 3103 | |
| 3104 | - if (is_object($table)) { |
|
| 3105 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3106 | - } elseif (is_array($table)) { |
|
| 3107 | - if ($conserver_null) { |
|
| 3108 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3109 | - } else { |
|
| 3110 | - $table = ($table[$k] ?? $defaut); |
|
| 3111 | - } |
|
| 3112 | - } else { |
|
| 3113 | - $table = $defaut; |
|
| 3114 | - break; |
|
| 3115 | - } |
|
| 3116 | - } |
|
| 3104 | + if (is_object($table)) { |
|
| 3105 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3106 | + } elseif (is_array($table)) { |
|
| 3107 | + if ($conserver_null) { |
|
| 3108 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3109 | + } else { |
|
| 3110 | + $table = ($table[$k] ?? $defaut); |
|
| 3111 | + } |
|
| 3112 | + } else { |
|
| 3113 | + $table = $defaut; |
|
| 3114 | + break; |
|
| 3115 | + } |
|
| 3116 | + } |
|
| 3117 | 3117 | |
| 3118 | - return $table; |
|
| 3118 | + return $table; |
|
| 3119 | 3119 | } |
| 3120 | 3120 | |
| 3121 | 3121 | /** |
@@ -3148,22 +3148,22 @@ discard block |
||
| 3148 | 3148 | * - string : expression trouvée. |
| 3149 | 3149 | **/ |
| 3150 | 3150 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3151 | - if (intval($modif) and $capte == 0) { |
|
| 3152 | - $capte = $modif; |
|
| 3153 | - $modif = 'UuimsS'; |
|
| 3154 | - } |
|
| 3155 | - $expression = str_replace('\/', '/', $expression); |
|
| 3156 | - $expression = str_replace('/', '\/', $expression); |
|
| 3151 | + if (intval($modif) and $capte == 0) { |
|
| 3152 | + $capte = $modif; |
|
| 3153 | + $modif = 'UuimsS'; |
|
| 3154 | + } |
|
| 3155 | + $expression = str_replace('\/', '/', $expression); |
|
| 3156 | + $expression = str_replace('/', '\/', $expression); |
|
| 3157 | 3157 | |
| 3158 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3159 | - if (isset($r[$capte])) { |
|
| 3160 | - return $r[$capte]; |
|
| 3161 | - } else { |
|
| 3162 | - return true; |
|
| 3163 | - } |
|
| 3164 | - } |
|
| 3158 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3159 | + if (isset($r[$capte])) { |
|
| 3160 | + return $r[$capte]; |
|
| 3161 | + } else { |
|
| 3162 | + return true; |
|
| 3163 | + } |
|
| 3164 | + } |
|
| 3165 | 3165 | |
| 3166 | - return false; |
|
| 3166 | + return false; |
|
| 3167 | 3167 | } |
| 3168 | 3168 | |
| 3169 | 3169 | |
@@ -3190,14 +3190,14 @@ discard block |
||
| 3190 | 3190 | * Texte |
| 3191 | 3191 | **/ |
| 3192 | 3192 | function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string { |
| 3193 | - if (null === $texte) { |
|
| 3194 | - return ''; |
|
| 3195 | - } |
|
| 3193 | + if (null === $texte) { |
|
| 3194 | + return ''; |
|
| 3195 | + } |
|
| 3196 | 3196 | |
| 3197 | - $expression = str_replace('\/', '/', $expression); |
|
| 3198 | - $expression = str_replace('/', '\/', $expression); |
|
| 3197 | + $expression = str_replace('\/', '/', $expression); |
|
| 3198 | + $expression = str_replace('/', '\/', $expression); |
|
| 3199 | 3199 | |
| 3200 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3200 | + return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3201 | 3201 | } |
| 3202 | 3202 | |
| 3203 | 3203 | |
@@ -3215,25 +3215,25 @@ discard block |
||
| 3215 | 3215 | **/ |
| 3216 | 3216 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3217 | 3217 | |
| 3218 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3219 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3218 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3219 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3220 | 3220 | |
| 3221 | - if ( |
|
| 3222 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3223 | - and preg_match_all( |
|
| 3224 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3225 | - $t, |
|
| 3226 | - $matches, |
|
| 3227 | - PREG_PATTERN_ORDER |
|
| 3228 | - ) |
|
| 3229 | - ) { |
|
| 3230 | - if (!isset($doublons['documents'])) { |
|
| 3231 | - $doublons['documents'] = ''; |
|
| 3232 | - } |
|
| 3233 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3234 | - } |
|
| 3221 | + if ( |
|
| 3222 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3223 | + and preg_match_all( |
|
| 3224 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3225 | + $t, |
|
| 3226 | + $matches, |
|
| 3227 | + PREG_PATTERN_ORDER |
|
| 3228 | + ) |
|
| 3229 | + ) { |
|
| 3230 | + if (!isset($doublons['documents'])) { |
|
| 3231 | + $doublons['documents'] = ''; |
|
| 3232 | + } |
|
| 3233 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3234 | + } |
|
| 3235 | 3235 | |
| 3236 | - return $letexte; |
|
| 3236 | + return $letexte; |
|
| 3237 | 3237 | } |
| 3238 | 3238 | |
| 3239 | 3239 | /** |
@@ -3247,7 +3247,7 @@ discard block |
||
| 3247 | 3247 | * @return string Chaîne vide |
| 3248 | 3248 | **/ |
| 3249 | 3249 | function vide($texte) { |
| 3250 | - return ''; |
|
| 3250 | + return ''; |
|
| 3251 | 3251 | } |
| 3252 | 3252 | |
| 3253 | 3253 | // |
@@ -3276,23 +3276,23 @@ discard block |
||
| 3276 | 3276 | * Code HTML résultant |
| 3277 | 3277 | **/ |
| 3278 | 3278 | function env_to_params($env, $ignore_params = []) { |
| 3279 | - $ignore_params = array_merge( |
|
| 3280 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3281 | - $ignore_params |
|
| 3282 | - ); |
|
| 3283 | - if (!is_array($env)) { |
|
| 3284 | - $env = unserialize($env); |
|
| 3285 | - } |
|
| 3286 | - $texte = ''; |
|
| 3287 | - if ($env) { |
|
| 3288 | - foreach ($env as $i => $j) { |
|
| 3289 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3290 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3291 | - } |
|
| 3292 | - } |
|
| 3293 | - } |
|
| 3294 | - |
|
| 3295 | - return $texte; |
|
| 3279 | + $ignore_params = array_merge( |
|
| 3280 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3281 | + $ignore_params |
|
| 3282 | + ); |
|
| 3283 | + if (!is_array($env)) { |
|
| 3284 | + $env = unserialize($env); |
|
| 3285 | + } |
|
| 3286 | + $texte = ''; |
|
| 3287 | + if ($env) { |
|
| 3288 | + foreach ($env as $i => $j) { |
|
| 3289 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3290 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3291 | + } |
|
| 3292 | + } |
|
| 3293 | + } |
|
| 3294 | + |
|
| 3295 | + return $texte; |
|
| 3296 | 3296 | } |
| 3297 | 3297 | |
| 3298 | 3298 | /** |
@@ -3315,23 +3315,23 @@ discard block |
||
| 3315 | 3315 | * Code HTML résultant |
| 3316 | 3316 | **/ |
| 3317 | 3317 | function env_to_attributs($env, $ignore_params = []) { |
| 3318 | - $ignore_params = array_merge( |
|
| 3319 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3320 | - $ignore_params |
|
| 3321 | - ); |
|
| 3322 | - if (!is_array($env)) { |
|
| 3323 | - $env = unserialize($env); |
|
| 3324 | - } |
|
| 3325 | - $texte = ''; |
|
| 3326 | - if ($env) { |
|
| 3327 | - foreach ($env as $i => $j) { |
|
| 3328 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3329 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3330 | - } |
|
| 3331 | - } |
|
| 3332 | - } |
|
| 3318 | + $ignore_params = array_merge( |
|
| 3319 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3320 | + $ignore_params |
|
| 3321 | + ); |
|
| 3322 | + if (!is_array($env)) { |
|
| 3323 | + $env = unserialize($env); |
|
| 3324 | + } |
|
| 3325 | + $texte = ''; |
|
| 3326 | + if ($env) { |
|
| 3327 | + foreach ($env as $i => $j) { |
|
| 3328 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3329 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3330 | + } |
|
| 3331 | + } |
|
| 3332 | + } |
|
| 3333 | 3333 | |
| 3334 | - return $texte; |
|
| 3334 | + return $texte; |
|
| 3335 | 3335 | } |
| 3336 | 3336 | |
| 3337 | 3337 | |
@@ -3349,7 +3349,7 @@ discard block |
||
| 3349 | 3349 | * @return string Chaînes concaténés |
| 3350 | 3350 | **/ |
| 3351 | 3351 | function concat(...$args): string { |
| 3352 | - return join('', $args); |
|
| 3352 | + return join('', $args); |
|
| 3353 | 3353 | } |
| 3354 | 3354 | |
| 3355 | 3355 | |
@@ -3369,23 +3369,23 @@ discard block |
||
| 3369 | 3369 | * Contenu du ou des fichiers, concaténé |
| 3370 | 3370 | **/ |
| 3371 | 3371 | function charge_scripts($files, $script = true) { |
| 3372 | - $flux = ''; |
|
| 3373 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3374 | - if (!is_string($file)) { |
|
| 3375 | - continue; |
|
| 3376 | - } |
|
| 3377 | - if ($script) { |
|
| 3378 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3379 | - } |
|
| 3380 | - if ($file) { |
|
| 3381 | - $path = find_in_path($file); |
|
| 3382 | - if ($path) { |
|
| 3383 | - $flux .= spip_file_get_contents($path); |
|
| 3384 | - } |
|
| 3385 | - } |
|
| 3386 | - } |
|
| 3387 | - |
|
| 3388 | - return $flux; |
|
| 3372 | + $flux = ''; |
|
| 3373 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3374 | + if (!is_string($file)) { |
|
| 3375 | + continue; |
|
| 3376 | + } |
|
| 3377 | + if ($script) { |
|
| 3378 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3379 | + } |
|
| 3380 | + if ($file) { |
|
| 3381 | + $path = find_in_path($file); |
|
| 3382 | + if ($path) { |
|
| 3383 | + $flux .= spip_file_get_contents($path); |
|
| 3384 | + } |
|
| 3385 | + } |
|
| 3386 | + } |
|
| 3387 | + |
|
| 3388 | + return $flux; |
|
| 3389 | 3389 | } |
| 3390 | 3390 | |
| 3391 | 3391 | /** |
@@ -3396,22 +3396,22 @@ discard block |
||
| 3396 | 3396 | * @return string |
| 3397 | 3397 | */ |
| 3398 | 3398 | function http_img_variante_svg_si_possible($img_file) { |
| 3399 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3400 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3401 | - if ( |
|
| 3402 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3403 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3404 | - and file_exists($variante_svg_generique) |
|
| 3405 | - ) { |
|
| 3406 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3407 | - $img_file = $variante_svg_size; |
|
| 3408 | - } |
|
| 3409 | - else { |
|
| 3410 | - $img_file = $variante_svg_generique; |
|
| 3411 | - } |
|
| 3412 | - } |
|
| 3399 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3400 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3401 | + if ( |
|
| 3402 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3403 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3404 | + and file_exists($variante_svg_generique) |
|
| 3405 | + ) { |
|
| 3406 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3407 | + $img_file = $variante_svg_size; |
|
| 3408 | + } |
|
| 3409 | + else { |
|
| 3410 | + $img_file = $variante_svg_generique; |
|
| 3411 | + } |
|
| 3412 | + } |
|
| 3413 | 3413 | |
| 3414 | - return $img_file; |
|
| 3414 | + return $img_file; |
|
| 3415 | 3415 | } |
| 3416 | 3416 | |
| 3417 | 3417 | /** |
@@ -3432,54 +3432,54 @@ discard block |
||
| 3432 | 3432 | */ |
| 3433 | 3433 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3434 | 3434 | |
| 3435 | - $img_file = $img; |
|
| 3436 | - if ($p = strpos($img_file, '?')) { |
|
| 3437 | - $img_file = substr($img_file, 0, $p); |
|
| 3438 | - } |
|
| 3439 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3440 | - $img_file = chemin_image($img); |
|
| 3441 | - } |
|
| 3442 | - else { |
|
| 3443 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3444 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3445 | - } |
|
| 3446 | - } |
|
| 3447 | - if (stripos($atts, 'width') === false) { |
|
| 3448 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3449 | - if ( |
|
| 3450 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3451 | - or $options['utiliser_suffixe_size'] == true |
|
| 3452 | - or str_contains($img_file, '-xx.svg')) |
|
| 3453 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3454 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3455 | - ) { |
|
| 3456 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3457 | - } else { |
|
| 3458 | - $taille = taille_image($img_file); |
|
| 3459 | - [$hauteur, $largeur] = $taille; |
|
| 3460 | - if (!$hauteur or !$largeur) { |
|
| 3461 | - return ''; |
|
| 3462 | - } |
|
| 3463 | - } |
|
| 3464 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3465 | - } |
|
| 3466 | - |
|
| 3467 | - if (file_exists($img_file)) { |
|
| 3468 | - $img_file = timestamp($img_file); |
|
| 3469 | - } |
|
| 3470 | - if ($alt === false) { |
|
| 3471 | - $alt = ''; |
|
| 3472 | - } |
|
| 3473 | - elseif ($alt or $alt === '') { |
|
| 3474 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3475 | - } |
|
| 3476 | - else { |
|
| 3477 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3478 | - } |
|
| 3479 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3480 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3481 | - . ' ' . ltrim($atts) |
|
| 3482 | - . ' />'; |
|
| 3435 | + $img_file = $img; |
|
| 3436 | + if ($p = strpos($img_file, '?')) { |
|
| 3437 | + $img_file = substr($img_file, 0, $p); |
|
| 3438 | + } |
|
| 3439 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3440 | + $img_file = chemin_image($img); |
|
| 3441 | + } |
|
| 3442 | + else { |
|
| 3443 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3444 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3445 | + } |
|
| 3446 | + } |
|
| 3447 | + if (stripos($atts, 'width') === false) { |
|
| 3448 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3449 | + if ( |
|
| 3450 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3451 | + or $options['utiliser_suffixe_size'] == true |
|
| 3452 | + or str_contains($img_file, '-xx.svg')) |
|
| 3453 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3454 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3455 | + ) { |
|
| 3456 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3457 | + } else { |
|
| 3458 | + $taille = taille_image($img_file); |
|
| 3459 | + [$hauteur, $largeur] = $taille; |
|
| 3460 | + if (!$hauteur or !$largeur) { |
|
| 3461 | + return ''; |
|
| 3462 | + } |
|
| 3463 | + } |
|
| 3464 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3465 | + } |
|
| 3466 | + |
|
| 3467 | + if (file_exists($img_file)) { |
|
| 3468 | + $img_file = timestamp($img_file); |
|
| 3469 | + } |
|
| 3470 | + if ($alt === false) { |
|
| 3471 | + $alt = ''; |
|
| 3472 | + } |
|
| 3473 | + elseif ($alt or $alt === '') { |
|
| 3474 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3475 | + } |
|
| 3476 | + else { |
|
| 3477 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3478 | + } |
|
| 3479 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3480 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3481 | + . ' ' . ltrim($atts) |
|
| 3482 | + . ' />'; |
|
| 3483 | 3483 | } |
| 3484 | 3484 | |
| 3485 | 3485 | /** |
@@ -3491,70 +3491,70 @@ discard block |
||
| 3491 | 3491 | * @return string |
| 3492 | 3492 | */ |
| 3493 | 3493 | function http_style_background($img, $att = '', $size = null) { |
| 3494 | - if ($size and is_numeric($size)) { |
|
| 3495 | - $size = trim($size) . 'px'; |
|
| 3496 | - } |
|
| 3497 | - return " style='background" . |
|
| 3498 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3499 | - . ($size ? "background-size:{$size};" : '') |
|
| 3500 | - . "'"; |
|
| 3494 | + if ($size and is_numeric($size)) { |
|
| 3495 | + $size = trim($size) . 'px'; |
|
| 3496 | + } |
|
| 3497 | + return " style='background" . |
|
| 3498 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3499 | + . ($size ? "background-size:{$size};" : '') |
|
| 3500 | + . "'"; |
|
| 3501 | 3501 | } |
| 3502 | 3502 | |
| 3503 | 3503 | |
| 3504 | 3504 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3505 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3506 | - while (is_null(end($args)) and count($args)) { |
|
| 3507 | - array_pop($args); |
|
| 3508 | - } |
|
| 3509 | - if (!count($args)) { |
|
| 3510 | - return [null, null, null]; |
|
| 3511 | - } |
|
| 3512 | - if (count($args) < 3) { |
|
| 3513 | - $maybe_size = array_pop($args); |
|
| 3514 | - // @2x |
|
| 3515 | - // @1.5x |
|
| 3516 | - // 512 |
|
| 3517 | - // 512x* |
|
| 3518 | - // 512x300 |
|
| 3519 | - if ( |
|
| 3520 | - !strlen($maybe_size) |
|
| 3521 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3522 | - ) { |
|
| 3523 | - $args[] = $maybe_size; |
|
| 3524 | - $maybe_size = null; |
|
| 3525 | - } |
|
| 3526 | - while (count($args) < 2) { |
|
| 3527 | - $args[] = null; // default alt or class |
|
| 3528 | - } |
|
| 3529 | - $args[] = $maybe_size; |
|
| 3530 | - } |
|
| 3531 | - return $args; |
|
| 3505 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3506 | + while (is_null(end($args)) and count($args)) { |
|
| 3507 | + array_pop($args); |
|
| 3508 | + } |
|
| 3509 | + if (!count($args)) { |
|
| 3510 | + return [null, null, null]; |
|
| 3511 | + } |
|
| 3512 | + if (count($args) < 3) { |
|
| 3513 | + $maybe_size = array_pop($args); |
|
| 3514 | + // @2x |
|
| 3515 | + // @1.5x |
|
| 3516 | + // 512 |
|
| 3517 | + // 512x* |
|
| 3518 | + // 512x300 |
|
| 3519 | + if ( |
|
| 3520 | + !strlen($maybe_size) |
|
| 3521 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3522 | + ) { |
|
| 3523 | + $args[] = $maybe_size; |
|
| 3524 | + $maybe_size = null; |
|
| 3525 | + } |
|
| 3526 | + while (count($args) < 2) { |
|
| 3527 | + $args[] = null; // default alt or class |
|
| 3528 | + } |
|
| 3529 | + $args[] = $maybe_size; |
|
| 3530 | + } |
|
| 3531 | + return $args; |
|
| 3532 | 3532 | } |
| 3533 | 3533 | |
| 3534 | 3534 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3535 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3536 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3537 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3538 | - [$h, $w] = taille_image($img); |
|
| 3539 | - $height = intval(round($h / $coef)); |
|
| 3540 | - $width = intval(round($w / $coef)); |
|
| 3541 | - } |
|
| 3542 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3543 | - else { |
|
| 3544 | - $size = explode('x', $size, 2); |
|
| 3545 | - $size = array_map('trim', $size); |
|
| 3546 | - $height = $width = intval(array_shift($size)); |
|
| 3547 | - |
|
| 3548 | - if (count($size) and reset($size)) { |
|
| 3549 | - $height = array_shift($size); |
|
| 3550 | - if ($height === '*') { |
|
| 3551 | - [$h, $w] = taille_image($img); |
|
| 3552 | - $height = intval(round($h * $width / $w)); |
|
| 3553 | - } |
|
| 3554 | - } |
|
| 3555 | - } |
|
| 3556 | - |
|
| 3557 | - return [$width, $height]; |
|
| 3535 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3536 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3537 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3538 | + [$h, $w] = taille_image($img); |
|
| 3539 | + $height = intval(round($h / $coef)); |
|
| 3540 | + $width = intval(round($w / $coef)); |
|
| 3541 | + } |
|
| 3542 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3543 | + else { |
|
| 3544 | + $size = explode('x', $size, 2); |
|
| 3545 | + $size = array_map('trim', $size); |
|
| 3546 | + $height = $width = intval(array_shift($size)); |
|
| 3547 | + |
|
| 3548 | + if (count($size) and reset($size)) { |
|
| 3549 | + $height = array_shift($size); |
|
| 3550 | + if ($height === '*') { |
|
| 3551 | + [$h, $w] = taille_image($img); |
|
| 3552 | + $height = intval(round($h * $width / $w)); |
|
| 3553 | + } |
|
| 3554 | + } |
|
| 3555 | + } |
|
| 3556 | + |
|
| 3557 | + return [$width, $height]; |
|
| 3558 | 3558 | } |
| 3559 | 3559 | |
| 3560 | 3560 | /** |
@@ -3590,43 +3590,43 @@ discard block |
||
| 3590 | 3590 | */ |
| 3591 | 3591 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3592 | 3592 | |
| 3593 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3594 | - |
|
| 3595 | - $img = trim((string) $img); |
|
| 3596 | - if (strpos($img, '<img') === 0) { |
|
| 3597 | - if (!is_null($alt)) { |
|
| 3598 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3599 | - } |
|
| 3600 | - if (!is_null($class)) { |
|
| 3601 | - if (strlen($class)) { |
|
| 3602 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3603 | - } |
|
| 3604 | - else { |
|
| 3605 | - $img = vider_attribut($img, 'class'); |
|
| 3606 | - } |
|
| 3607 | - } |
|
| 3608 | - } |
|
| 3609 | - else { |
|
| 3610 | - $img = http_img_pack( |
|
| 3611 | - $img, |
|
| 3612 | - $alt, |
|
| 3613 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3614 | - '', |
|
| 3615 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3616 | - ); |
|
| 3617 | - if (is_null($alt)) { |
|
| 3618 | - $img = vider_attribut($img, 'alt'); |
|
| 3619 | - } |
|
| 3620 | - } |
|
| 3621 | - |
|
| 3622 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3623 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3624 | - |
|
| 3625 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3626 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3627 | - } |
|
| 3628 | - |
|
| 3629 | - return $img; |
|
| 3593 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3594 | + |
|
| 3595 | + $img = trim((string) $img); |
|
| 3596 | + if (strpos($img, '<img') === 0) { |
|
| 3597 | + if (!is_null($alt)) { |
|
| 3598 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3599 | + } |
|
| 3600 | + if (!is_null($class)) { |
|
| 3601 | + if (strlen($class)) { |
|
| 3602 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3603 | + } |
|
| 3604 | + else { |
|
| 3605 | + $img = vider_attribut($img, 'class'); |
|
| 3606 | + } |
|
| 3607 | + } |
|
| 3608 | + } |
|
| 3609 | + else { |
|
| 3610 | + $img = http_img_pack( |
|
| 3611 | + $img, |
|
| 3612 | + $alt, |
|
| 3613 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3614 | + '', |
|
| 3615 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3616 | + ); |
|
| 3617 | + if (is_null($alt)) { |
|
| 3618 | + $img = vider_attribut($img, 'alt'); |
|
| 3619 | + } |
|
| 3620 | + } |
|
| 3621 | + |
|
| 3622 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3623 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3624 | + |
|
| 3625 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3626 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3627 | + } |
|
| 3628 | + |
|
| 3629 | + return $img; |
|
| 3630 | 3630 | } |
| 3631 | 3631 | |
| 3632 | 3632 | |
@@ -3660,80 +3660,80 @@ discard block |
||
| 3660 | 3660 | */ |
| 3661 | 3661 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3662 | 3662 | |
| 3663 | - $svg = null; |
|
| 3664 | - $img = trim($img); |
|
| 3665 | - $img_file = $img; |
|
| 3666 | - if (strpos($img, '<svg') === false) { |
|
| 3667 | - if ($p = strpos($img_file, '?')) { |
|
| 3668 | - $img_file = substr($img_file, 0, $p); |
|
| 3669 | - } |
|
| 3670 | - |
|
| 3671 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3672 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3673 | - if (tester_url_absolue($img_file)) { |
|
| 3674 | - include_spip('inc/distant'); |
|
| 3675 | - $fichier = copie_locale($img_file); |
|
| 3676 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3677 | - } |
|
| 3678 | - |
|
| 3679 | - if ( |
|
| 3680 | - !$img_file |
|
| 3681 | - or !file_exists($img_file) |
|
| 3682 | - or !$svg = file_get_contents($img_file) |
|
| 3683 | - ) { |
|
| 3684 | - return ''; |
|
| 3685 | - } |
|
| 3686 | - } |
|
| 3687 | - |
|
| 3688 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3689 | - return ''; |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3693 | - |
|
| 3694 | - $balise_svg = $match[0]; |
|
| 3695 | - $balise_svg_source = $balise_svg; |
|
| 3696 | - |
|
| 3697 | - // entete XML à supprimer |
|
| 3698 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3699 | - |
|
| 3700 | - // IE est toujours mon ami |
|
| 3701 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3702 | - |
|
| 3703 | - // regler la classe |
|
| 3704 | - if (!is_null($class)) { |
|
| 3705 | - if (strlen($class)) { |
|
| 3706 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3707 | - } |
|
| 3708 | - else { |
|
| 3709 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3710 | - } |
|
| 3711 | - } |
|
| 3712 | - |
|
| 3713 | - // regler le alt |
|
| 3714 | - if ($alt) { |
|
| 3715 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3716 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3717 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3718 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3719 | - $balise_svg .= $title; |
|
| 3720 | - } |
|
| 3721 | - else { |
|
| 3722 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3723 | - } |
|
| 3724 | - |
|
| 3725 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3726 | - |
|
| 3727 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3728 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3729 | - |
|
| 3730 | - if (!function_exists('svg_redimensionner')) { |
|
| 3731 | - include_spip('inc/svg'); |
|
| 3732 | - } |
|
| 3733 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3734 | - } |
|
| 3735 | - |
|
| 3736 | - return $svg; |
|
| 3663 | + $svg = null; |
|
| 3664 | + $img = trim($img); |
|
| 3665 | + $img_file = $img; |
|
| 3666 | + if (strpos($img, '<svg') === false) { |
|
| 3667 | + if ($p = strpos($img_file, '?')) { |
|
| 3668 | + $img_file = substr($img_file, 0, $p); |
|
| 3669 | + } |
|
| 3670 | + |
|
| 3671 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3672 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3673 | + if (tester_url_absolue($img_file)) { |
|
| 3674 | + include_spip('inc/distant'); |
|
| 3675 | + $fichier = copie_locale($img_file); |
|
| 3676 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3677 | + } |
|
| 3678 | + |
|
| 3679 | + if ( |
|
| 3680 | + !$img_file |
|
| 3681 | + or !file_exists($img_file) |
|
| 3682 | + or !$svg = file_get_contents($img_file) |
|
| 3683 | + ) { |
|
| 3684 | + return ''; |
|
| 3685 | + } |
|
| 3686 | + } |
|
| 3687 | + |
|
| 3688 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3689 | + return ''; |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3693 | + |
|
| 3694 | + $balise_svg = $match[0]; |
|
| 3695 | + $balise_svg_source = $balise_svg; |
|
| 3696 | + |
|
| 3697 | + // entete XML à supprimer |
|
| 3698 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3699 | + |
|
| 3700 | + // IE est toujours mon ami |
|
| 3701 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3702 | + |
|
| 3703 | + // regler la classe |
|
| 3704 | + if (!is_null($class)) { |
|
| 3705 | + if (strlen($class)) { |
|
| 3706 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3707 | + } |
|
| 3708 | + else { |
|
| 3709 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3710 | + } |
|
| 3711 | + } |
|
| 3712 | + |
|
| 3713 | + // regler le alt |
|
| 3714 | + if ($alt) { |
|
| 3715 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3716 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3717 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3718 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3719 | + $balise_svg .= $title; |
|
| 3720 | + } |
|
| 3721 | + else { |
|
| 3722 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3723 | + } |
|
| 3724 | + |
|
| 3725 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3726 | + |
|
| 3727 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3728 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3729 | + |
|
| 3730 | + if (!function_exists('svg_redimensionner')) { |
|
| 3731 | + include_spip('inc/svg'); |
|
| 3732 | + } |
|
| 3733 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3734 | + } |
|
| 3735 | + |
|
| 3736 | + return $svg; |
|
| 3737 | 3737 | } |
| 3738 | 3738 | |
| 3739 | 3739 | |
@@ -3759,18 +3759,18 @@ discard block |
||
| 3759 | 3759 | * Code HTML résultant |
| 3760 | 3760 | **/ |
| 3761 | 3761 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3762 | - $texte = ''; |
|
| 3763 | - if (is_array($tableau)) { |
|
| 3764 | - foreach ($tableau as $k => $v) { |
|
| 3765 | - $res = recuperer_fond( |
|
| 3766 | - 'modeles/' . $modele, |
|
| 3767 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3768 | - ); |
|
| 3769 | - $texte .= $res; |
|
| 3770 | - } |
|
| 3771 | - } |
|
| 3762 | + $texte = ''; |
|
| 3763 | + if (is_array($tableau)) { |
|
| 3764 | + foreach ($tableau as $k => $v) { |
|
| 3765 | + $res = recuperer_fond( |
|
| 3766 | + 'modeles/' . $modele, |
|
| 3767 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3768 | + ); |
|
| 3769 | + $texte .= $res; |
|
| 3770 | + } |
|
| 3771 | + } |
|
| 3772 | 3772 | |
| 3773 | - return $texte; |
|
| 3773 | + return $texte; |
|
| 3774 | 3774 | } |
| 3775 | 3775 | |
| 3776 | 3776 | |
@@ -3795,37 +3795,37 @@ discard block |
||
| 3795 | 3795 | * - tout : retourne toutes les informations du plugin actif |
| 3796 | 3796 | **/ |
| 3797 | 3797 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3798 | - include_spip('inc/plugin'); |
|
| 3799 | - $plugin = strtoupper($plugin); |
|
| 3800 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3801 | - |
|
| 3802 | - if (!$plugin) { |
|
| 3803 | - return serialize(array_keys($plugins_actifs)); |
|
| 3804 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3805 | - return ''; |
|
| 3806 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3807 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3808 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3809 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3810 | - } else { |
|
| 3811 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3812 | - // On prend en compte les extensions |
|
| 3813 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3814 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3815 | - } else { |
|
| 3816 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3817 | - } |
|
| 3818 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3819 | - return ''; |
|
| 3820 | - } |
|
| 3821 | - if ($type_info == 'tout') { |
|
| 3822 | - return $infos; |
|
| 3823 | - } elseif ($type_info == 'est_actif') { |
|
| 3824 | - return $infos ? 1 : 0; |
|
| 3825 | - } else { |
|
| 3826 | - return strval($infos[$type_info]); |
|
| 3827 | - } |
|
| 3828 | - } |
|
| 3798 | + include_spip('inc/plugin'); |
|
| 3799 | + $plugin = strtoupper($plugin); |
|
| 3800 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3801 | + |
|
| 3802 | + if (!$plugin) { |
|
| 3803 | + return serialize(array_keys($plugins_actifs)); |
|
| 3804 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3805 | + return ''; |
|
| 3806 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3807 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3808 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3809 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3810 | + } else { |
|
| 3811 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3812 | + // On prend en compte les extensions |
|
| 3813 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3814 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3815 | + } else { |
|
| 3816 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3817 | + } |
|
| 3818 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3819 | + return ''; |
|
| 3820 | + } |
|
| 3821 | + if ($type_info == 'tout') { |
|
| 3822 | + return $infos; |
|
| 3823 | + } elseif ($type_info == 'est_actif') { |
|
| 3824 | + return $infos ? 1 : 0; |
|
| 3825 | + } else { |
|
| 3826 | + return strval($infos[$type_info]); |
|
| 3827 | + } |
|
| 3828 | + } |
|
| 3829 | 3829 | } |
| 3830 | 3830 | |
| 3831 | 3831 | |
@@ -3852,9 +3852,9 @@ discard block |
||
| 3852 | 3852 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3853 | 3853 | */ |
| 3854 | 3854 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3855 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3855 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3856 | 3856 | |
| 3857 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3857 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3858 | 3858 | } |
| 3859 | 3859 | |
| 3860 | 3860 | |
@@ -3884,19 +3884,19 @@ discard block |
||
| 3884 | 3884 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3885 | 3885 | */ |
| 3886 | 3886 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3887 | - static $puce_statut = null; |
|
| 3888 | - if (!$puce_statut) { |
|
| 3889 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3890 | - } |
|
| 3887 | + static $puce_statut = null; |
|
| 3888 | + if (!$puce_statut) { |
|
| 3889 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3890 | + } |
|
| 3891 | 3891 | |
| 3892 | - return $puce_statut( |
|
| 3893 | - $id_objet, |
|
| 3894 | - $statut, |
|
| 3895 | - $id_parent, |
|
| 3896 | - $objet, |
|
| 3897 | - false, |
|
| 3898 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3899 | - ); |
|
| 3892 | + return $puce_statut( |
|
| 3893 | + $id_objet, |
|
| 3894 | + $statut, |
|
| 3895 | + $id_parent, |
|
| 3896 | + $objet, |
|
| 3897 | + false, |
|
| 3898 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3899 | + ); |
|
| 3900 | 3900 | } |
| 3901 | 3901 | |
| 3902 | 3902 | |
@@ -3923,98 +3923,98 @@ discard block |
||
| 3923 | 3923 | * hash du contexte |
| 3924 | 3924 | */ |
| 3925 | 3925 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3926 | - $env = null; |
|
| 3927 | - if ( |
|
| 3928 | - is_string($c) |
|
| 3929 | - and @unserialize($c) !== false |
|
| 3930 | - ) { |
|
| 3931 | - $c = unserialize($c); |
|
| 3932 | - } |
|
| 3933 | - |
|
| 3934 | - // supprimer les parametres debut_x |
|
| 3935 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3936 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3937 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3938 | - if (is_array($c)) { |
|
| 3939 | - foreach ($c as $k => $v) { |
|
| 3940 | - if (strpos($k, 'debut_') === 0) { |
|
| 3941 | - unset($c[$k]); |
|
| 3942 | - } |
|
| 3943 | - } |
|
| 3944 | - } |
|
| 3945 | - |
|
| 3946 | - if (!function_exists('calculer_cle_action')) { |
|
| 3947 | - include_spip('inc/securiser_action'); |
|
| 3948 | - } |
|
| 3949 | - |
|
| 3950 | - $c = serialize($c); |
|
| 3951 | - $cle = calculer_cle_action($form . $c); |
|
| 3952 | - $c = "$cle:$c"; |
|
| 3953 | - |
|
| 3954 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3955 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3956 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3957 | - // que ce qui est toléré. |
|
| 3958 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3959 | - if (!$cache_contextes_ajax) { |
|
| 3960 | - $env = $c; |
|
| 3961 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3962 | - $env = gzdeflate($env); |
|
| 3963 | - } |
|
| 3964 | - $env = _xor($env); |
|
| 3965 | - $env = base64_encode($env); |
|
| 3966 | - $len = strlen($env); |
|
| 3967 | - // Si l’url est trop longue pour le navigateur |
|
| 3968 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3969 | - if ($len > $max_len) { |
|
| 3970 | - $cache_contextes_ajax = true; |
|
| 3971 | - spip_log( |
|
| 3972 | - 'Contextes AJAX forces en fichiers !' |
|
| 3973 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3974 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3975 | - _LOG_AVERTISSEMENT |
|
| 3976 | - ); |
|
| 3977 | - } |
|
| 3978 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3979 | - elseif ( |
|
| 3980 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3981 | - and $max_len < $len |
|
| 3982 | - ) { |
|
| 3983 | - $cache_contextes_ajax = true; |
|
| 3984 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3985 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3986 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3987 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3988 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3989 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3990 | - } |
|
| 3991 | - } |
|
| 3992 | - |
|
| 3993 | - if ($cache_contextes_ajax) { |
|
| 3994 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3995 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3996 | - $md5 = md5($c); |
|
| 3997 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3998 | - $env = $md5; |
|
| 3999 | - } |
|
| 4000 | - |
|
| 4001 | - if ($emboite === null) { |
|
| 4002 | - return $env; |
|
| 4003 | - } |
|
| 4004 | - if (!trim($emboite)) { |
|
| 4005 | - return ''; |
|
| 4006 | - } |
|
| 4007 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4008 | - $r = self(); |
|
| 4009 | - $r = ' data-origin="' . $r . '"'; |
|
| 4010 | - $class = 'ajaxbloc'; |
|
| 4011 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4012 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4013 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4014 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4015 | - } |
|
| 4016 | - |
|
| 4017 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3926 | + $env = null; |
|
| 3927 | + if ( |
|
| 3928 | + is_string($c) |
|
| 3929 | + and @unserialize($c) !== false |
|
| 3930 | + ) { |
|
| 3931 | + $c = unserialize($c); |
|
| 3932 | + } |
|
| 3933 | + |
|
| 3934 | + // supprimer les parametres debut_x |
|
| 3935 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3936 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3937 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3938 | + if (is_array($c)) { |
|
| 3939 | + foreach ($c as $k => $v) { |
|
| 3940 | + if (strpos($k, 'debut_') === 0) { |
|
| 3941 | + unset($c[$k]); |
|
| 3942 | + } |
|
| 3943 | + } |
|
| 3944 | + } |
|
| 3945 | + |
|
| 3946 | + if (!function_exists('calculer_cle_action')) { |
|
| 3947 | + include_spip('inc/securiser_action'); |
|
| 3948 | + } |
|
| 3949 | + |
|
| 3950 | + $c = serialize($c); |
|
| 3951 | + $cle = calculer_cle_action($form . $c); |
|
| 3952 | + $c = "$cle:$c"; |
|
| 3953 | + |
|
| 3954 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3955 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3956 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3957 | + // que ce qui est toléré. |
|
| 3958 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3959 | + if (!$cache_contextes_ajax) { |
|
| 3960 | + $env = $c; |
|
| 3961 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3962 | + $env = gzdeflate($env); |
|
| 3963 | + } |
|
| 3964 | + $env = _xor($env); |
|
| 3965 | + $env = base64_encode($env); |
|
| 3966 | + $len = strlen($env); |
|
| 3967 | + // Si l’url est trop longue pour le navigateur |
|
| 3968 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3969 | + if ($len > $max_len) { |
|
| 3970 | + $cache_contextes_ajax = true; |
|
| 3971 | + spip_log( |
|
| 3972 | + 'Contextes AJAX forces en fichiers !' |
|
| 3973 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3974 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3975 | + _LOG_AVERTISSEMENT |
|
| 3976 | + ); |
|
| 3977 | + } |
|
| 3978 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3979 | + elseif ( |
|
| 3980 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3981 | + and $max_len < $len |
|
| 3982 | + ) { |
|
| 3983 | + $cache_contextes_ajax = true; |
|
| 3984 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3985 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3986 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3987 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3988 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3989 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3990 | + } |
|
| 3991 | + } |
|
| 3992 | + |
|
| 3993 | + if ($cache_contextes_ajax) { |
|
| 3994 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3995 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3996 | + $md5 = md5($c); |
|
| 3997 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3998 | + $env = $md5; |
|
| 3999 | + } |
|
| 4000 | + |
|
| 4001 | + if ($emboite === null) { |
|
| 4002 | + return $env; |
|
| 4003 | + } |
|
| 4004 | + if (!trim($emboite)) { |
|
| 4005 | + return ''; |
|
| 4006 | + } |
|
| 4007 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4008 | + $r = self(); |
|
| 4009 | + $r = ' data-origin="' . $r . '"'; |
|
| 4010 | + $class = 'ajaxbloc'; |
|
| 4011 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4012 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4013 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4014 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4015 | + } |
|
| 4016 | + |
|
| 4017 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4018 | 4018 | } |
| 4019 | 4019 | |
| 4020 | 4020 | /** |
@@ -4034,37 +4034,37 @@ discard block |
||
| 4034 | 4034 | * - false : erreur de décodage |
| 4035 | 4035 | */ |
| 4036 | 4036 | function decoder_contexte_ajax($c, $form = '') { |
| 4037 | - if (!function_exists('calculer_cle_action')) { |
|
| 4038 | - include_spip('inc/securiser_action'); |
|
| 4039 | - } |
|
| 4040 | - if ( |
|
| 4041 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4042 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4043 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4044 | - ) { |
|
| 4045 | - $c = $contexte; |
|
| 4046 | - } else { |
|
| 4047 | - $c = @base64_decode($c); |
|
| 4048 | - $c = _xor($c); |
|
| 4049 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4050 | - $c = @gzinflate($c); |
|
| 4051 | - } |
|
| 4052 | - } |
|
| 4053 | - |
|
| 4054 | - // extraire la signature en debut de contexte |
|
| 4055 | - // et la verifier avant de deserializer |
|
| 4056 | - // format : signature:donneesserializees |
|
| 4057 | - if ($p = strpos($c, ':')) { |
|
| 4058 | - $cle = substr($c, 0, $p); |
|
| 4059 | - $c = substr($c, $p + 1); |
|
| 4060 | - |
|
| 4061 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4062 | - $env = @unserialize($c); |
|
| 4063 | - return $env; |
|
| 4064 | - } |
|
| 4065 | - } |
|
| 4066 | - |
|
| 4067 | - return false; |
|
| 4037 | + if (!function_exists('calculer_cle_action')) { |
|
| 4038 | + include_spip('inc/securiser_action'); |
|
| 4039 | + } |
|
| 4040 | + if ( |
|
| 4041 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4042 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4043 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4044 | + ) { |
|
| 4045 | + $c = $contexte; |
|
| 4046 | + } else { |
|
| 4047 | + $c = @base64_decode($c); |
|
| 4048 | + $c = _xor($c); |
|
| 4049 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4050 | + $c = @gzinflate($c); |
|
| 4051 | + } |
|
| 4052 | + } |
|
| 4053 | + |
|
| 4054 | + // extraire la signature en debut de contexte |
|
| 4055 | + // et la verifier avant de deserializer |
|
| 4056 | + // format : signature:donneesserializees |
|
| 4057 | + if ($p = strpos($c, ':')) { |
|
| 4058 | + $cle = substr($c, 0, $p); |
|
| 4059 | + $c = substr($c, $p + 1); |
|
| 4060 | + |
|
| 4061 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4062 | + $env = @unserialize($c); |
|
| 4063 | + return $env; |
|
| 4064 | + } |
|
| 4065 | + } |
|
| 4066 | + |
|
| 4067 | + return false; |
|
| 4068 | 4068 | } |
| 4069 | 4069 | |
| 4070 | 4070 | |
@@ -4082,20 +4082,20 @@ discard block |
||
| 4082 | 4082 | * Message décrypté ou encrypté |
| 4083 | 4083 | **/ |
| 4084 | 4084 | function _xor($message, $key = null) { |
| 4085 | - if (is_null($key)) { |
|
| 4086 | - if (!function_exists('calculer_cle_action')) { |
|
| 4087 | - include_spip('inc/securiser_action'); |
|
| 4088 | - } |
|
| 4089 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4090 | - } |
|
| 4085 | + if (is_null($key)) { |
|
| 4086 | + if (!function_exists('calculer_cle_action')) { |
|
| 4087 | + include_spip('inc/securiser_action'); |
|
| 4088 | + } |
|
| 4089 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4090 | + } |
|
| 4091 | 4091 | |
| 4092 | - $keylen = strlen($key); |
|
| 4093 | - $messagelen = strlen($message); |
|
| 4094 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4095 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4096 | - } |
|
| 4092 | + $keylen = strlen($key); |
|
| 4093 | + $messagelen = strlen($message); |
|
| 4094 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4095 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4096 | + } |
|
| 4097 | 4097 | |
| 4098 | - return $message; |
|
| 4098 | + return $message; |
|
| 4099 | 4099 | } |
| 4100 | 4100 | |
| 4101 | 4101 | /** |
@@ -4109,7 +4109,7 @@ discard block |
||
| 4109 | 4109 | * @return string |
| 4110 | 4110 | */ |
| 4111 | 4111 | function url_reponse_forum($texte) { |
| 4112 | - return $texte; |
|
| 4112 | + return $texte; |
|
| 4113 | 4113 | } |
| 4114 | 4114 | |
| 4115 | 4115 | /** |
@@ -4123,7 +4123,7 @@ discard block |
||
| 4123 | 4123 | * @return string |
| 4124 | 4124 | */ |
| 4125 | 4125 | function url_rss_forum($texte) { |
| 4126 | - return $texte; |
|
| 4126 | + return $texte; |
|
| 4127 | 4127 | } |
| 4128 | 4128 | |
| 4129 | 4129 | |
@@ -4162,37 +4162,37 @@ discard block |
||
| 4162 | 4162 | * Code HTML |
| 4163 | 4163 | */ |
| 4164 | 4164 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4165 | - if ($on) { |
|
| 4166 | - $bal = 'strong'; |
|
| 4167 | - $class = ''; |
|
| 4168 | - $att = ''; |
|
| 4169 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4170 | - // a.active span.selected.active etc.... |
|
| 4171 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4172 | - $on = explode('.', $on); |
|
| 4173 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4174 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4175 | - $bal = array_shift($on); |
|
| 4176 | - $class = implode(' ', $on); |
|
| 4177 | - if ($bal == 'a') { |
|
| 4178 | - $att = 'href="#" '; |
|
| 4179 | - } |
|
| 4180 | - } |
|
| 4181 | - } |
|
| 4182 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4183 | - } else { |
|
| 4184 | - $bal = 'a'; |
|
| 4185 | - $att = "href='$url'" |
|
| 4186 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4187 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4188 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4189 | - . $evt; |
|
| 4190 | - } |
|
| 4191 | - if ($libelle === null) { |
|
| 4192 | - $libelle = $url; |
|
| 4193 | - } |
|
| 4194 | - |
|
| 4195 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4165 | + if ($on) { |
|
| 4166 | + $bal = 'strong'; |
|
| 4167 | + $class = ''; |
|
| 4168 | + $att = ''; |
|
| 4169 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4170 | + // a.active span.selected.active etc.... |
|
| 4171 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4172 | + $on = explode('.', $on); |
|
| 4173 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4174 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4175 | + $bal = array_shift($on); |
|
| 4176 | + $class = implode(' ', $on); |
|
| 4177 | + if ($bal == 'a') { |
|
| 4178 | + $att = 'href="#" '; |
|
| 4179 | + } |
|
| 4180 | + } |
|
| 4181 | + } |
|
| 4182 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4183 | + } else { |
|
| 4184 | + $bal = 'a'; |
|
| 4185 | + $att = "href='$url'" |
|
| 4186 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4187 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4188 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4189 | + . $evt; |
|
| 4190 | + } |
|
| 4191 | + if ($libelle === null) { |
|
| 4192 | + $libelle = $url; |
|
| 4193 | + } |
|
| 4194 | + |
|
| 4195 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4196 | 4196 | } |
| 4197 | 4197 | |
| 4198 | 4198 | |
@@ -4209,39 +4209,39 @@ discard block |
||
| 4209 | 4209 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4210 | 4210 | */ |
| 4211 | 4211 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4212 | - static $local_singulier_ou_pluriel = []; |
|
| 4213 | - |
|
| 4214 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4215 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4216 | - return ''; |
|
| 4217 | - } |
|
| 4218 | - if (!is_array($vars)) { |
|
| 4219 | - return ''; |
|
| 4220 | - } |
|
| 4221 | - |
|
| 4222 | - $langue = $GLOBALS['spip_lang']; |
|
| 4223 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4224 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4225 | - if ( |
|
| 4226 | - $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4227 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4228 | - ) { |
|
| 4229 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4230 | - } |
|
| 4231 | - } |
|
| 4232 | - |
|
| 4233 | - // si on a une surcharge on l'utilise |
|
| 4234 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4235 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4236 | - } |
|
| 4237 | - |
|
| 4238 | - // sinon traitement par defaut |
|
| 4239 | - $vars[$var] = $nb; |
|
| 4240 | - if ($nb >= 2) { |
|
| 4241 | - return _T($chaine_plusieurs, $vars); |
|
| 4242 | - } else { |
|
| 4243 | - return _T($chaine_un, $vars); |
|
| 4244 | - } |
|
| 4212 | + static $local_singulier_ou_pluriel = []; |
|
| 4213 | + |
|
| 4214 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4215 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4216 | + return ''; |
|
| 4217 | + } |
|
| 4218 | + if (!is_array($vars)) { |
|
| 4219 | + return ''; |
|
| 4220 | + } |
|
| 4221 | + |
|
| 4222 | + $langue = $GLOBALS['spip_lang']; |
|
| 4223 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4224 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4225 | + if ( |
|
| 4226 | + $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4227 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4228 | + ) { |
|
| 4229 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4230 | + } |
|
| 4231 | + } |
|
| 4232 | + |
|
| 4233 | + // si on a une surcharge on l'utilise |
|
| 4234 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4235 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4236 | + } |
|
| 4237 | + |
|
| 4238 | + // sinon traitement par defaut |
|
| 4239 | + $vars[$var] = $nb; |
|
| 4240 | + if ($nb >= 2) { |
|
| 4241 | + return _T($chaine_plusieurs, $vars); |
|
| 4242 | + } else { |
|
| 4243 | + return _T($chaine_un, $vars); |
|
| 4244 | + } |
|
| 4245 | 4245 | } |
| 4246 | 4246 | |
| 4247 | 4247 | |
@@ -4269,73 +4269,73 @@ discard block |
||
| 4269 | 4269 | */ |
| 4270 | 4270 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4271 | 4271 | |
| 4272 | - $class_lien = $class_bouton = $class; |
|
| 4273 | - |
|
| 4274 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4275 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4276 | - $class_lien .= ' danger'; |
|
| 4277 | - $class_bouton .= ' btn_danger'; |
|
| 4278 | - } elseif ($fonction == 'rien.gif') { |
|
| 4279 | - $fonction = ''; |
|
| 4280 | - } elseif ($fonction == 'delsafe') { |
|
| 4281 | - $fonction = 'del'; |
|
| 4282 | - } |
|
| 4283 | - |
|
| 4284 | - $fond_origine = $fond; |
|
| 4285 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4286 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4287 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4288 | - } |
|
| 4289 | - |
|
| 4290 | - // Ajouter le type d'objet dans la classe |
|
| 4291 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4292 | - $class_lien .= " $objet_type"; |
|
| 4293 | - $class_bouton .= " $objet_type"; |
|
| 4294 | - |
|
| 4295 | - // texte |
|
| 4296 | - $alt = attribut_html($texte); |
|
| 4297 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4298 | - |
|
| 4299 | - // Liens : préparer les classes ajax |
|
| 4300 | - $ajax = ''; |
|
| 4301 | - if ($type === 'lien') { |
|
| 4302 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4303 | - $ajax = 'ajax'; |
|
| 4304 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4305 | - $ajax .= ' preload'; |
|
| 4306 | - } |
|
| 4307 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4308 | - $ajax .= ' nocache'; |
|
| 4309 | - } |
|
| 4310 | - $ajax = " class='$ajax'"; |
|
| 4311 | - } |
|
| 4312 | - } |
|
| 4313 | - |
|
| 4314 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4315 | - $size = 24; |
|
| 4316 | - if ( |
|
| 4317 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4318 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4319 | - ) { |
|
| 4320 | - $size = $match[1]; |
|
| 4321 | - } |
|
| 4322 | - $class_lien .= " s$size"; |
|
| 4323 | - $class_bouton .= " s$size"; |
|
| 4324 | - |
|
| 4325 | - // Icône |
|
| 4326 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4327 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4328 | - |
|
| 4329 | - // Markup final |
|
| 4330 | - if ($type == 'lien') { |
|
| 4331 | - return "<span class='icone $class_lien'>" |
|
| 4332 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4333 | - . $icone |
|
| 4334 | - . "<b>$texte</b>" |
|
| 4335 | - . "</a></span>\n"; |
|
| 4336 | - } else { |
|
| 4337 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4338 | - } |
|
| 4272 | + $class_lien = $class_bouton = $class; |
|
| 4273 | + |
|
| 4274 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4275 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4276 | + $class_lien .= ' danger'; |
|
| 4277 | + $class_bouton .= ' btn_danger'; |
|
| 4278 | + } elseif ($fonction == 'rien.gif') { |
|
| 4279 | + $fonction = ''; |
|
| 4280 | + } elseif ($fonction == 'delsafe') { |
|
| 4281 | + $fonction = 'del'; |
|
| 4282 | + } |
|
| 4283 | + |
|
| 4284 | + $fond_origine = $fond; |
|
| 4285 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4286 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4287 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4288 | + } |
|
| 4289 | + |
|
| 4290 | + // Ajouter le type d'objet dans la classe |
|
| 4291 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4292 | + $class_lien .= " $objet_type"; |
|
| 4293 | + $class_bouton .= " $objet_type"; |
|
| 4294 | + |
|
| 4295 | + // texte |
|
| 4296 | + $alt = attribut_html($texte); |
|
| 4297 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4298 | + |
|
| 4299 | + // Liens : préparer les classes ajax |
|
| 4300 | + $ajax = ''; |
|
| 4301 | + if ($type === 'lien') { |
|
| 4302 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4303 | + $ajax = 'ajax'; |
|
| 4304 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4305 | + $ajax .= ' preload'; |
|
| 4306 | + } |
|
| 4307 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4308 | + $ajax .= ' nocache'; |
|
| 4309 | + } |
|
| 4310 | + $ajax = " class='$ajax'"; |
|
| 4311 | + } |
|
| 4312 | + } |
|
| 4313 | + |
|
| 4314 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4315 | + $size = 24; |
|
| 4316 | + if ( |
|
| 4317 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4318 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4319 | + ) { |
|
| 4320 | + $size = $match[1]; |
|
| 4321 | + } |
|
| 4322 | + $class_lien .= " s$size"; |
|
| 4323 | + $class_bouton .= " s$size"; |
|
| 4324 | + |
|
| 4325 | + // Icône |
|
| 4326 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4327 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4328 | + |
|
| 4329 | + // Markup final |
|
| 4330 | + if ($type == 'lien') { |
|
| 4331 | + return "<span class='icone $class_lien'>" |
|
| 4332 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4333 | + . $icone |
|
| 4334 | + . "<b>$texte</b>" |
|
| 4335 | + . "</a></span>\n"; |
|
| 4336 | + } else { |
|
| 4337 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4338 | + } |
|
| 4339 | 4339 | } |
| 4340 | 4340 | |
| 4341 | 4341 | /** |
@@ -4359,7 +4359,7 @@ discard block |
||
| 4359 | 4359 | * Code HTML du lien |
| 4360 | 4360 | **/ |
| 4361 | 4361 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4362 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4362 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4363 | 4363 | } |
| 4364 | 4364 | |
| 4365 | 4365 | /** |
@@ -4394,7 +4394,7 @@ discard block |
||
| 4394 | 4394 | * Code HTML du lien |
| 4395 | 4395 | **/ |
| 4396 | 4396 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4397 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4397 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4398 | 4398 | } |
| 4399 | 4399 | |
| 4400 | 4400 | /** |
@@ -4439,7 +4439,7 @@ discard block |
||
| 4439 | 4439 | * Code HTML du lien |
| 4440 | 4440 | **/ |
| 4441 | 4441 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4442 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4442 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4443 | 4443 | } |
| 4444 | 4444 | |
| 4445 | 4445 | /** |
@@ -4470,7 +4470,7 @@ discard block |
||
| 4470 | 4470 | * Code HTML du lien |
| 4471 | 4471 | **/ |
| 4472 | 4472 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4473 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4473 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4474 | 4474 | } |
| 4475 | 4475 | |
| 4476 | 4476 | /** |
@@ -4501,7 +4501,7 @@ discard block |
||
| 4501 | 4501 | * Code HTML du lien |
| 4502 | 4502 | */ |
| 4503 | 4503 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4504 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4504 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4505 | 4505 | } |
| 4506 | 4506 | |
| 4507 | 4507 | |
@@ -4523,7 +4523,7 @@ discard block |
||
| 4523 | 4523 | * @return array Liste des éléments |
| 4524 | 4524 | */ |
| 4525 | 4525 | function filtre_explode_dist($a, $b) { |
| 4526 | - return explode($b, (string) $a); |
|
| 4526 | + return explode($b, (string) $a); |
|
| 4527 | 4527 | } |
| 4528 | 4528 | |
| 4529 | 4529 | /** |
@@ -4544,7 +4544,7 @@ discard block |
||
| 4544 | 4544 | * @return string texte |
| 4545 | 4545 | */ |
| 4546 | 4546 | function filtre_implode_dist($a, $b) { |
| 4547 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4547 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4548 | 4548 | } |
| 4549 | 4549 | |
| 4550 | 4550 | /** |
@@ -4553,22 +4553,22 @@ discard block |
||
| 4553 | 4553 | * @return string Code CSS |
| 4554 | 4554 | */ |
| 4555 | 4555 | function bando_images_background() { |
| 4556 | - include_spip('inc/bandeau'); |
|
| 4557 | - // recuperer tous les boutons et leurs images |
|
| 4558 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4556 | + include_spip('inc/bandeau'); |
|
| 4557 | + // recuperer tous les boutons et leurs images |
|
| 4558 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4559 | 4559 | |
| 4560 | - $res = ''; |
|
| 4561 | - foreach ($boutons as $page => $detail) { |
|
| 4562 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4563 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4564 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4565 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4566 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4567 | - } |
|
| 4568 | - } |
|
| 4569 | - } |
|
| 4560 | + $res = ''; |
|
| 4561 | + foreach ($boutons as $page => $detail) { |
|
| 4562 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4563 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4564 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4565 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4566 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4567 | + } |
|
| 4568 | + } |
|
| 4569 | + } |
|
| 4570 | 4570 | |
| 4571 | - return $res; |
|
| 4571 | + return $res; |
|
| 4572 | 4572 | } |
| 4573 | 4573 | |
| 4574 | 4574 | /** |
@@ -4593,27 +4593,27 @@ discard block |
||
| 4593 | 4593 | */ |
| 4594 | 4594 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4595 | 4595 | |
| 4596 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4597 | - $class_form = ''; |
|
| 4598 | - if (strpos($class, 'ajax') !== false) { |
|
| 4599 | - $class_form = 'ajax'; |
|
| 4600 | - $class = str_replace('ajax', '', $class); |
|
| 4601 | - } |
|
| 4602 | - $class_btn = 'submit ' . trim($class); |
|
| 4596 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4597 | + $class_form = ''; |
|
| 4598 | + if (strpos($class, 'ajax') !== false) { |
|
| 4599 | + $class_form = 'ajax'; |
|
| 4600 | + $class = str_replace('ajax', '', $class); |
|
| 4601 | + } |
|
| 4602 | + $class_btn = 'submit ' . trim($class); |
|
| 4603 | 4603 | |
| 4604 | - if ($confirm) { |
|
| 4605 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4606 | - if ($callback) { |
|
| 4607 | - $callback = "$confirm?($callback):false"; |
|
| 4608 | - } else { |
|
| 4609 | - $callback = $confirm; |
|
| 4610 | - } |
|
| 4611 | - } |
|
| 4612 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4613 | - $title = $title ? " title='$title'" : ''; |
|
| 4604 | + if ($confirm) { |
|
| 4605 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4606 | + if ($callback) { |
|
| 4607 | + $callback = "$confirm?($callback):false"; |
|
| 4608 | + } else { |
|
| 4609 | + $callback = $confirm; |
|
| 4610 | + } |
|
| 4611 | + } |
|
| 4612 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4613 | + $title = $title ? " title='$title'" : ''; |
|
| 4614 | 4614 | |
| 4615 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4616 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4615 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4616 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4617 | 4617 | } |
| 4618 | 4618 | |
| 4619 | 4619 | /** |
@@ -4636,101 +4636,101 @@ discard block |
||
| 4636 | 4636 | * @return string |
| 4637 | 4637 | */ |
| 4638 | 4638 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4639 | - static $trouver_table = null; |
|
| 4640 | - static $objets; |
|
| 4641 | - |
|
| 4642 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4643 | - $id_objet = intval($id_objet); |
|
| 4644 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4645 | - return ''; |
|
| 4646 | - } |
|
| 4647 | - |
|
| 4648 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4649 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4650 | - return ''; |
|
| 4651 | - } |
|
| 4652 | - |
|
| 4653 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4654 | - if ($info == 'url') { |
|
| 4655 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4656 | - } |
|
| 4657 | - |
|
| 4658 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4659 | - $demande_titre = ($info === 'titre'); |
|
| 4660 | - $demande_introduction = ($info === 'introduction'); |
|
| 4661 | - |
|
| 4662 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4663 | - if ( |
|
| 4664 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4665 | - or |
|
| 4666 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4667 | - ) { |
|
| 4668 | - if (!$trouver_table) { |
|
| 4669 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4670 | - } |
|
| 4671 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4672 | - if (!$desc) { |
|
| 4673 | - return $objets[$type_objet] = false; |
|
| 4674 | - } |
|
| 4675 | - |
|
| 4676 | - // Si on demande le titre, on le gere en interne |
|
| 4677 | - $champ_titre = ''; |
|
| 4678 | - if ($demande_titre) { |
|
| 4679 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4680 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4681 | - } |
|
| 4682 | - include_spip('base/abstract_sql'); |
|
| 4683 | - include_spip('base/connect_sql'); |
|
| 4684 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4685 | - '*' . $champ_titre, |
|
| 4686 | - $desc['table_sql'], |
|
| 4687 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4688 | - ); |
|
| 4689 | - |
|
| 4690 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4691 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4692 | - } |
|
| 4693 | - |
|
| 4694 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4695 | - // ajouter la longueur au début des params supplémentaires |
|
| 4696 | - if ($demande_introduction) { |
|
| 4697 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4698 | - array_unshift($params, $introduction_longueur); |
|
| 4699 | - } |
|
| 4700 | - |
|
| 4701 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4702 | - if ( |
|
| 4703 | - $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4704 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4705 | - or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4706 | - ) { |
|
| 4707 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4708 | - } |
|
| 4709 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4710 | - elseif ( |
|
| 4711 | - $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4712 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4713 | - or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4714 | - ) { |
|
| 4715 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4716 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4717 | - else { |
|
| 4718 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4719 | - } |
|
| 4720 | - |
|
| 4721 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4722 | - if (!$etoile) { |
|
| 4723 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4724 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4725 | - $info_generee = appliquer_traitement_champ( |
|
| 4726 | - $info_generee, |
|
| 4727 | - $info, |
|
| 4728 | - table_objet($type_objet), |
|
| 4729 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4730 | - ); |
|
| 4731 | - } |
|
| 4732 | - |
|
| 4733 | - return $info_generee; |
|
| 4639 | + static $trouver_table = null; |
|
| 4640 | + static $objets; |
|
| 4641 | + |
|
| 4642 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4643 | + $id_objet = intval($id_objet); |
|
| 4644 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4645 | + return ''; |
|
| 4646 | + } |
|
| 4647 | + |
|
| 4648 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4649 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4650 | + return ''; |
|
| 4651 | + } |
|
| 4652 | + |
|
| 4653 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4654 | + if ($info == 'url') { |
|
| 4655 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4656 | + } |
|
| 4657 | + |
|
| 4658 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4659 | + $demande_titre = ($info === 'titre'); |
|
| 4660 | + $demande_introduction = ($info === 'introduction'); |
|
| 4661 | + |
|
| 4662 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4663 | + if ( |
|
| 4664 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4665 | + or |
|
| 4666 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4667 | + ) { |
|
| 4668 | + if (!$trouver_table) { |
|
| 4669 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4670 | + } |
|
| 4671 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4672 | + if (!$desc) { |
|
| 4673 | + return $objets[$type_objet] = false; |
|
| 4674 | + } |
|
| 4675 | + |
|
| 4676 | + // Si on demande le titre, on le gere en interne |
|
| 4677 | + $champ_titre = ''; |
|
| 4678 | + if ($demande_titre) { |
|
| 4679 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4680 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4681 | + } |
|
| 4682 | + include_spip('base/abstract_sql'); |
|
| 4683 | + include_spip('base/connect_sql'); |
|
| 4684 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4685 | + '*' . $champ_titre, |
|
| 4686 | + $desc['table_sql'], |
|
| 4687 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4688 | + ); |
|
| 4689 | + |
|
| 4690 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4691 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4692 | + } |
|
| 4693 | + |
|
| 4694 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4695 | + // ajouter la longueur au début des params supplémentaires |
|
| 4696 | + if ($demande_introduction) { |
|
| 4697 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4698 | + array_unshift($params, $introduction_longueur); |
|
| 4699 | + } |
|
| 4700 | + |
|
| 4701 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4702 | + if ( |
|
| 4703 | + $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4704 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4705 | + or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4706 | + ) { |
|
| 4707 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4708 | + } |
|
| 4709 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4710 | + elseif ( |
|
| 4711 | + $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4712 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4713 | + or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4714 | + ) { |
|
| 4715 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4716 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4717 | + else { |
|
| 4718 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4719 | + } |
|
| 4720 | + |
|
| 4721 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4722 | + if (!$etoile) { |
|
| 4723 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4724 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4725 | + $info_generee = appliquer_traitement_champ( |
|
| 4726 | + $info_generee, |
|
| 4727 | + $info, |
|
| 4728 | + table_objet($type_objet), |
|
| 4729 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4730 | + ); |
|
| 4731 | + } |
|
| 4732 | + |
|
| 4733 | + return $info_generee; |
|
| 4734 | 4734 | } |
| 4735 | 4735 | |
| 4736 | 4736 | /** |
@@ -4738,7 +4738,7 @@ discard block |
||
| 4738 | 4738 | * @see generer_objet_info |
| 4739 | 4739 | */ |
| 4740 | 4740 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4741 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4741 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4742 | 4742 | } |
| 4743 | 4743 | |
| 4744 | 4744 | /** |
@@ -4771,36 +4771,36 @@ discard block |
||
| 4771 | 4771 | */ |
| 4772 | 4772 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4773 | 4773 | |
| 4774 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4775 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4776 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4777 | - if (isset($ligne_sql['chapo'])) { |
|
| 4778 | - $chapo = $ligne_sql['chapo']; |
|
| 4779 | - $texte = strlen($descriptif) ? |
|
| 4780 | - '' : |
|
| 4781 | - "$chapo \n\n $texte"; |
|
| 4782 | - } |
|
| 4774 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4775 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4776 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4777 | + if (isset($ligne_sql['chapo'])) { |
|
| 4778 | + $chapo = $ligne_sql['chapo']; |
|
| 4779 | + $texte = strlen($descriptif) ? |
|
| 4780 | + '' : |
|
| 4781 | + "$chapo \n\n $texte"; |
|
| 4782 | + } |
|
| 4783 | 4783 | |
| 4784 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4785 | - if (!intval($longueur_ou_suite)) { |
|
| 4786 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4787 | - } else { |
|
| 4788 | - $longueur = intval($longueur_ou_suite); |
|
| 4789 | - } |
|
| 4784 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4785 | + if (!intval($longueur_ou_suite)) { |
|
| 4786 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4787 | + } else { |
|
| 4788 | + $longueur = intval($longueur_ou_suite); |
|
| 4789 | + } |
|
| 4790 | 4790 | |
| 4791 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4792 | - // Ex : #INTRODUCTION{...} |
|
| 4793 | - if ( |
|
| 4794 | - is_null($suite) |
|
| 4795 | - and !intval($longueur_ou_suite) |
|
| 4796 | - ) { |
|
| 4797 | - $suite = $longueur_ou_suite; |
|
| 4798 | - } |
|
| 4791 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4792 | + // Ex : #INTRODUCTION{...} |
|
| 4793 | + if ( |
|
| 4794 | + is_null($suite) |
|
| 4795 | + and !intval($longueur_ou_suite) |
|
| 4796 | + ) { |
|
| 4797 | + $suite = $longueur_ou_suite; |
|
| 4798 | + } |
|
| 4799 | 4799 | |
| 4800 | - $f = chercher_filtre('introduction'); |
|
| 4801 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4800 | + $f = chercher_filtre('introduction'); |
|
| 4801 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4802 | 4802 | |
| 4803 | - return $introduction; |
|
| 4803 | + return $introduction; |
|
| 4804 | 4804 | } |
| 4805 | 4805 | |
| 4806 | 4806 | /** |
@@ -4808,7 +4808,7 @@ discard block |
||
| 4808 | 4808 | * @see generer_objet_introduction |
| 4809 | 4809 | */ |
| 4810 | 4810 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4811 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4811 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4812 | 4812 | } |
| 4813 | 4813 | |
| 4814 | 4814 | /** |
@@ -4822,49 +4822,49 @@ discard block |
||
| 4822 | 4822 | * @return string |
| 4823 | 4823 | */ |
| 4824 | 4824 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4825 | - if (!$champ) { |
|
| 4826 | - return $texte; |
|
| 4827 | - } |
|
| 4825 | + if (!$champ) { |
|
| 4826 | + return $texte; |
|
| 4827 | + } |
|
| 4828 | 4828 | |
| 4829 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4830 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4831 | - include_fichiers_fonctions(); |
|
| 4829 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4830 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4831 | + include_fichiers_fonctions(); |
|
| 4832 | 4832 | |
| 4833 | - $champ = strtoupper($champ); |
|
| 4834 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4835 | - if (!$traitements or !is_array($traitements)) { |
|
| 4836 | - return $texte; |
|
| 4837 | - } |
|
| 4833 | + $champ = strtoupper($champ); |
|
| 4834 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4835 | + if (!$traitements or !is_array($traitements)) { |
|
| 4836 | + return $texte; |
|
| 4837 | + } |
|
| 4838 | 4838 | |
| 4839 | - $traitement = ''; |
|
| 4840 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4841 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4842 | - $table_objet = table_objet($table_objet); |
|
| 4843 | - if (isset($traitements[$table_objet])) { |
|
| 4844 | - $traitement = $traitements[$table_objet]; |
|
| 4845 | - } |
|
| 4846 | - } |
|
| 4847 | - if (!$traitement and isset($traitements[0])) { |
|
| 4848 | - $traitement = $traitements[0]; |
|
| 4849 | - } |
|
| 4850 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4839 | + $traitement = ''; |
|
| 4840 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4841 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4842 | + $table_objet = table_objet($table_objet); |
|
| 4843 | + if (isset($traitements[$table_objet])) { |
|
| 4844 | + $traitement = $traitements[$table_objet]; |
|
| 4845 | + } |
|
| 4846 | + } |
|
| 4847 | + if (!$traitement and isset($traitements[0])) { |
|
| 4848 | + $traitement = $traitements[0]; |
|
| 4849 | + } |
|
| 4850 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4851 | 4851 | |
| 4852 | - if (!$traitement) { |
|
| 4853 | - return $texte; |
|
| 4854 | - } |
|
| 4852 | + if (!$traitement) { |
|
| 4853 | + return $texte; |
|
| 4854 | + } |
|
| 4855 | 4855 | |
| 4856 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4856 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4857 | 4857 | |
| 4858 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4859 | - if (test_espace_prive()) { |
|
| 4860 | - $env['espace_prive'] = 1; |
|
| 4861 | - } |
|
| 4858 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4859 | + if (test_espace_prive()) { |
|
| 4860 | + $env['espace_prive'] = 1; |
|
| 4861 | + } |
|
| 4862 | 4862 | |
| 4863 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4864 | - $Pile = [0 => $env]; |
|
| 4865 | - eval("\$texte = $traitement;"); |
|
| 4863 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4864 | + $Pile = [0 => $env]; |
|
| 4865 | + eval("\$texte = $traitement;"); |
|
| 4866 | 4866 | |
| 4867 | - return $texte; |
|
| 4867 | + return $texte; |
|
| 4868 | 4868 | } |
| 4869 | 4869 | |
| 4870 | 4870 | |
@@ -4878,21 +4878,21 @@ discard block |
||
| 4878 | 4878 | * @return string |
| 4879 | 4879 | */ |
| 4880 | 4880 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4881 | - include_spip('inc/liens'); |
|
| 4882 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4883 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4884 | - // le raccourcis n'est plus valide |
|
| 4885 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4886 | - // on essaye avec generer_info_entite ? |
|
| 4887 | - if (!strlen($titre) and !$connect) { |
|
| 4888 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4889 | - } |
|
| 4890 | - if (!strlen($titre)) { |
|
| 4891 | - $titre = _T('info_sans_titre'); |
|
| 4892 | - } |
|
| 4893 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4881 | + include_spip('inc/liens'); |
|
| 4882 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4883 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4884 | + // le raccourcis n'est plus valide |
|
| 4885 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4886 | + // on essaye avec generer_info_entite ? |
|
| 4887 | + if (!strlen($titre) and !$connect) { |
|
| 4888 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4889 | + } |
|
| 4890 | + if (!strlen($titre)) { |
|
| 4891 | + $titre = _T('info_sans_titre'); |
|
| 4892 | + } |
|
| 4893 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4894 | 4894 | |
| 4895 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4895 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4896 | 4896 | } |
| 4897 | 4897 | |
| 4898 | 4898 | /** |
@@ -4900,7 +4900,7 @@ discard block |
||
| 4900 | 4900 | * @see generer_objet_lien |
| 4901 | 4901 | */ |
| 4902 | 4902 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4903 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4903 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4904 | 4904 | } |
| 4905 | 4905 | |
| 4906 | 4906 | /** |
@@ -4916,15 +4916,15 @@ discard block |
||
| 4916 | 4916 | * @return string |
| 4917 | 4917 | */ |
| 4918 | 4918 | function wrap($texte, $wrap) { |
| 4919 | - $balises = extraire_balises($wrap); |
|
| 4920 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | - $texte = $wrap . $texte; |
|
| 4922 | - $regs = array_reverse($regs[1]); |
|
| 4923 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | - $texte = $texte . $wrap; |
|
| 4925 | - } |
|
| 4919 | + $balises = extraire_balises($wrap); |
|
| 4920 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | + $texte = $wrap . $texte; |
|
| 4922 | + $regs = array_reverse($regs[1]); |
|
| 4923 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | + $texte = $texte . $wrap; |
|
| 4925 | + } |
|
| 4926 | 4926 | |
| 4927 | - return $texte; |
|
| 4927 | + return $texte; |
|
| 4928 | 4928 | } |
| 4929 | 4929 | |
| 4930 | 4930 | |
@@ -4944,44 +4944,44 @@ discard block |
||
| 4944 | 4944 | * @return array|mixed|string |
| 4945 | 4945 | */ |
| 4946 | 4946 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4947 | - if (is_string($u)) { |
|
| 4948 | - $u = typo($u); |
|
| 4947 | + if (is_string($u)) { |
|
| 4948 | + $u = typo($u); |
|
| 4949 | 4949 | |
| 4950 | - return $u; |
|
| 4951 | - } |
|
| 4950 | + return $u; |
|
| 4951 | + } |
|
| 4952 | 4952 | |
| 4953 | - // caster $u en array si besoin |
|
| 4954 | - if (is_object($u)) { |
|
| 4955 | - $u = (array)$u; |
|
| 4956 | - } |
|
| 4953 | + // caster $u en array si besoin |
|
| 4954 | + if (is_object($u)) { |
|
| 4955 | + $u = (array)$u; |
|
| 4956 | + } |
|
| 4957 | 4957 | |
| 4958 | - if (is_array($u)) { |
|
| 4959 | - $out = ''; |
|
| 4960 | - // toutes les cles sont numeriques ? |
|
| 4961 | - // et aucun enfant n'est un tableau |
|
| 4962 | - // liste simple separee par des virgules |
|
| 4963 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | - $array_values = array_map('is_array', $u); |
|
| 4965 | - $object_values = array_map('is_object', $u); |
|
| 4966 | - if ( |
|
| 4967 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | - and !array_sum($array_values) |
|
| 4969 | - and !array_sum($object_values) |
|
| 4970 | - ) { |
|
| 4971 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | - } |
|
| 4958 | + if (is_array($u)) { |
|
| 4959 | + $out = ''; |
|
| 4960 | + // toutes les cles sont numeriques ? |
|
| 4961 | + // et aucun enfant n'est un tableau |
|
| 4962 | + // liste simple separee par des virgules |
|
| 4963 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | + $array_values = array_map('is_array', $u); |
|
| 4965 | + $object_values = array_map('is_object', $u); |
|
| 4966 | + if ( |
|
| 4967 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | + and !array_sum($array_values) |
|
| 4969 | + and !array_sum($object_values) |
|
| 4970 | + ) { |
|
| 4971 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | + } |
|
| 4973 | 4973 | |
| 4974 | - // sinon on passe a la ligne et on indente |
|
| 4975 | - $i_str = str_pad('', $indent, ' '); |
|
| 4976 | - foreach ($u as $k => $v) { |
|
| 4977 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | - } |
|
| 4974 | + // sinon on passe a la ligne et on indente |
|
| 4975 | + $i_str = str_pad('', $indent, ' '); |
|
| 4976 | + foreach ($u as $k => $v) { |
|
| 4977 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | + } |
|
| 4979 | 4979 | |
| 4980 | - return $out; |
|
| 4981 | - } |
|
| 4980 | + return $out; |
|
| 4981 | + } |
|
| 4982 | 4982 | |
| 4983 | - // on sait pas quoi faire... |
|
| 4984 | - return $u; |
|
| 4983 | + // on sait pas quoi faire... |
|
| 4984 | + return $u; |
|
| 4985 | 4985 | } |
| 4986 | 4986 | |
| 4987 | 4987 | |
@@ -4994,10 +4994,10 @@ discard block |
||
| 4994 | 4994 | * @return string|array |
| 4995 | 4995 | */ |
| 4996 | 4996 | function objet_info($objet, $info) { |
| 4997 | - $table = table_objet_sql($objet); |
|
| 4998 | - $infos = lister_tables_objets_sql($table); |
|
| 4997 | + $table = table_objet_sql($objet); |
|
| 4998 | + $infos = lister_tables_objets_sql($table); |
|
| 4999 | 4999 | |
| 5000 | - return ($infos[$info] ?? ''); |
|
| 5000 | + return ($infos[$info] ?? ''); |
|
| 5001 | 5001 | } |
| 5002 | 5002 | |
| 5003 | 5003 | /** |
@@ -5012,11 +5012,11 @@ discard block |
||
| 5012 | 5012 | * texte traduit du comptage, tel que '3 articles' |
| 5013 | 5013 | */ |
| 5014 | 5014 | function objet_afficher_nb($nb, $objet) { |
| 5015 | - if (!$nb) { |
|
| 5016 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | - } else { |
|
| 5018 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | - } |
|
| 5015 | + if (!$nb) { |
|
| 5016 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | + } else { |
|
| 5018 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | + } |
|
| 5020 | 5020 | } |
| 5021 | 5021 | |
| 5022 | 5022 | /** |
@@ -5028,11 +5028,11 @@ discard block |
||
| 5028 | 5028 | * @return string |
| 5029 | 5029 | */ |
| 5030 | 5030 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5031 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | - $icone = chemin_image($icone); |
|
| 5033 | - $balise_img = charger_filtre('balise_img'); |
|
| 5031 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | + $icone = chemin_image($icone); |
|
| 5033 | + $balise_img = charger_filtre('balise_img'); |
|
| 5034 | 5034 | |
| 5035 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5035 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5036 | 5036 | } |
| 5037 | 5037 | |
| 5038 | 5038 | /** |
@@ -5053,12 +5053,12 @@ discard block |
||
| 5053 | 5053 | * @return string |
| 5054 | 5054 | */ |
| 5055 | 5055 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5056 | - $chaine = explode(':', $chaine); |
|
| 5057 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | - return $t; |
|
| 5059 | - } |
|
| 5060 | - $chaine = implode(':', $chaine); |
|
| 5061 | - return _T($chaine, $args, $options); |
|
| 5056 | + $chaine = explode(':', $chaine); |
|
| 5057 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | + return $t; |
|
| 5059 | + } |
|
| 5060 | + $chaine = implode(':', $chaine); |
|
| 5061 | + return _T($chaine, $args, $options); |
|
| 5062 | 5062 | } |
| 5063 | 5063 | |
| 5064 | 5064 | /** |
@@ -5072,18 +5072,18 @@ discard block |
||
| 5072 | 5072 | * @return string Code HTML |
| 5073 | 5073 | */ |
| 5074 | 5074 | function insert_head_css_conditionnel($flux) { |
| 5075 | - if ( |
|
| 5076 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | - ) { |
|
| 5079 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | - $p = $p1; |
|
| 5082 | - } |
|
| 5083 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | - } |
|
| 5075 | + if ( |
|
| 5076 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | + ) { |
|
| 5079 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | + $p = $p1; |
|
| 5082 | + } |
|
| 5083 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | + } |
|
| 5085 | 5085 | |
| 5086 | - return $flux; |
|
| 5086 | + return $flux; |
|
| 5087 | 5087 | } |
| 5088 | 5088 | |
| 5089 | 5089 | /** |
@@ -5106,75 +5106,75 @@ discard block |
||
| 5106 | 5106 | * @return string |
| 5107 | 5107 | */ |
| 5108 | 5108 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5109 | - if (isset($contexte['format'])) { |
|
| 5110 | - $extension = $contexte['format']; |
|
| 5111 | - unset($contexte['format']); |
|
| 5112 | - } else { |
|
| 5113 | - $extension = 'html'; |
|
| 5114 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | - $extension = $m[1]; |
|
| 5116 | - } |
|
| 5117 | - } |
|
| 5118 | - // recuperer le contenu produit par le squelette |
|
| 5119 | - $options['raw'] = true; |
|
| 5120 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | - |
|
| 5122 | - // calculer le nom de la css |
|
| 5123 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | - |
|
| 5127 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | - } |
|
| 5133 | - else { |
|
| 5134 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | - ksort($contexte); |
|
| 5136 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5137 | - } |
|
| 5138 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | - |
|
| 5140 | - // mettre a jour le fichier si il n'existe pas |
|
| 5141 | - // ou trop ancien |
|
| 5142 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | - if ( |
|
| 5145 | - !file_exists($filename) |
|
| 5146 | - or !file_exists($filename . '.last') |
|
| 5147 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | - ) { |
|
| 5150 | - $contenu = $cache['texte']; |
|
| 5151 | - // passer les urls en absolu si c'est une css |
|
| 5152 | - if ($extension == 'css') { |
|
| 5153 | - $contenu = urls_absolues_css( |
|
| 5154 | - $contenu, |
|
| 5155 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | - ); |
|
| 5157 | - } |
|
| 5158 | - |
|
| 5159 | - $comment = ''; |
|
| 5160 | - // ne pas insérer de commentaire sur certains formats |
|
| 5161 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | - foreach ($contexte as $k => $v) { |
|
| 5164 | - if (is_array($v)) { |
|
| 5165 | - $v = var_export($v, true); |
|
| 5166 | - } |
|
| 5167 | - $comment .= ",$k=$v"; |
|
| 5168 | - } |
|
| 5169 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5170 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5171 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5172 | - } |
|
| 5173 | - // et ecrire le fichier si il change |
|
| 5174 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5175 | - } |
|
| 5176 | - |
|
| 5177 | - return timestamp($filename); |
|
| 5109 | + if (isset($contexte['format'])) { |
|
| 5110 | + $extension = $contexte['format']; |
|
| 5111 | + unset($contexte['format']); |
|
| 5112 | + } else { |
|
| 5113 | + $extension = 'html'; |
|
| 5114 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | + $extension = $m[1]; |
|
| 5116 | + } |
|
| 5117 | + } |
|
| 5118 | + // recuperer le contenu produit par le squelette |
|
| 5119 | + $options['raw'] = true; |
|
| 5120 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | + |
|
| 5122 | + // calculer le nom de la css |
|
| 5123 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | + |
|
| 5127 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | + } |
|
| 5133 | + else { |
|
| 5134 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | + ksort($contexte); |
|
| 5136 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5137 | + } |
|
| 5138 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | + |
|
| 5140 | + // mettre a jour le fichier si il n'existe pas |
|
| 5141 | + // ou trop ancien |
|
| 5142 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | + if ( |
|
| 5145 | + !file_exists($filename) |
|
| 5146 | + or !file_exists($filename . '.last') |
|
| 5147 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | + ) { |
|
| 5150 | + $contenu = $cache['texte']; |
|
| 5151 | + // passer les urls en absolu si c'est une css |
|
| 5152 | + if ($extension == 'css') { |
|
| 5153 | + $contenu = urls_absolues_css( |
|
| 5154 | + $contenu, |
|
| 5155 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | + ); |
|
| 5157 | + } |
|
| 5158 | + |
|
| 5159 | + $comment = ''; |
|
| 5160 | + // ne pas insérer de commentaire sur certains formats |
|
| 5161 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | + foreach ($contexte as $k => $v) { |
|
| 5164 | + if (is_array($v)) { |
|
| 5165 | + $v = var_export($v, true); |
|
| 5166 | + } |
|
| 5167 | + $comment .= ",$k=$v"; |
|
| 5168 | + } |
|
| 5169 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5170 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5171 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5172 | + } |
|
| 5173 | + // et ecrire le fichier si il change |
|
| 5174 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5175 | + } |
|
| 5176 | + |
|
| 5177 | + return timestamp($filename); |
|
| 5178 | 5178 | } |
| 5179 | 5179 | |
| 5180 | 5180 | /** |
@@ -5187,15 +5187,15 @@ discard block |
||
| 5187 | 5187 | * $fichier auquel on a ajouté le timestamp |
| 5188 | 5188 | */ |
| 5189 | 5189 | function timestamp($fichier) { |
| 5190 | - if ( |
|
| 5191 | - !$fichier |
|
| 5192 | - or !file_exists($fichier) |
|
| 5193 | - or !$m = filemtime($fichier) |
|
| 5194 | - ) { |
|
| 5195 | - return $fichier; |
|
| 5196 | - } |
|
| 5190 | + if ( |
|
| 5191 | + !$fichier |
|
| 5192 | + or !file_exists($fichier) |
|
| 5193 | + or !$m = filemtime($fichier) |
|
| 5194 | + ) { |
|
| 5195 | + return $fichier; |
|
| 5196 | + } |
|
| 5197 | 5197 | |
| 5198 | - return "$fichier?$m"; |
|
| 5198 | + return "$fichier?$m"; |
|
| 5199 | 5199 | } |
| 5200 | 5200 | |
| 5201 | 5201 | /** |
@@ -5205,11 +5205,11 @@ discard block |
||
| 5205 | 5205 | * @return string |
| 5206 | 5206 | */ |
| 5207 | 5207 | function supprimer_timestamp($url) { |
| 5208 | - if (strpos($url, '?') === false) { |
|
| 5209 | - return $url; |
|
| 5210 | - } |
|
| 5208 | + if (strpos($url, '?') === false) { |
|
| 5209 | + return $url; |
|
| 5210 | + } |
|
| 5211 | 5211 | |
| 5212 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5212 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5213 | 5213 | } |
| 5214 | 5214 | |
| 5215 | 5215 | /** |
@@ -5224,15 +5224,15 @@ discard block |
||
| 5224 | 5224 | * @return string |
| 5225 | 5225 | */ |
| 5226 | 5226 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5227 | - include_spip('inc/envoyer_mail'); |
|
| 5227 | + include_spip('inc/envoyer_mail'); |
|
| 5228 | 5228 | |
| 5229 | - $titre = nettoyer_titre_email($titre); |
|
| 5230 | - // on est dans un squelette : securiser le retour |
|
| 5231 | - if (strpos($titre, '<') !== false) { |
|
| 5232 | - $titre = interdire_scripts($titre); |
|
| 5233 | - } |
|
| 5229 | + $titre = nettoyer_titre_email($titre); |
|
| 5230 | + // on est dans un squelette : securiser le retour |
|
| 5231 | + if (strpos($titre, '<') !== false) { |
|
| 5232 | + $titre = interdire_scripts($titre); |
|
| 5233 | + } |
|
| 5234 | 5234 | |
| 5235 | - return $titre; |
|
| 5235 | + return $titre; |
|
| 5236 | 5236 | } |
| 5237 | 5237 | |
| 5238 | 5238 | /** |
@@ -5254,27 +5254,27 @@ discard block |
||
| 5254 | 5254 | * @return string |
| 5255 | 5255 | */ |
| 5256 | 5256 | function filtre_chercher_rubrique_dist( |
| 5257 | - $titre, |
|
| 5258 | - $id_objet, |
|
| 5259 | - $id_parent, |
|
| 5260 | - $objet, |
|
| 5261 | - $id_secteur, |
|
| 5262 | - $restreint, |
|
| 5263 | - $actionable = false, |
|
| 5264 | - $retour_sans_cadre = false |
|
| 5257 | + $titre, |
|
| 5258 | + $id_objet, |
|
| 5259 | + $id_parent, |
|
| 5260 | + $objet, |
|
| 5261 | + $id_secteur, |
|
| 5262 | + $restreint, |
|
| 5263 | + $actionable = false, |
|
| 5264 | + $retour_sans_cadre = false |
|
| 5265 | 5265 | ) { |
| 5266 | - include_spip('inc/filtres_ecrire'); |
|
| 5266 | + include_spip('inc/filtres_ecrire'); |
|
| 5267 | 5267 | |
| 5268 | - return chercher_rubrique( |
|
| 5269 | - $titre, |
|
| 5270 | - $id_objet, |
|
| 5271 | - $id_parent, |
|
| 5272 | - $objet, |
|
| 5273 | - $id_secteur, |
|
| 5274 | - $restreint, |
|
| 5275 | - $actionable, |
|
| 5276 | - $retour_sans_cadre |
|
| 5277 | - ); |
|
| 5268 | + return chercher_rubrique( |
|
| 5269 | + $titre, |
|
| 5270 | + $id_objet, |
|
| 5271 | + $id_parent, |
|
| 5272 | + $objet, |
|
| 5273 | + $id_secteur, |
|
| 5274 | + $restreint, |
|
| 5275 | + $actionable, |
|
| 5276 | + $retour_sans_cadre |
|
| 5277 | + ); |
|
| 5278 | 5278 | } |
| 5279 | 5279 | |
| 5280 | 5280 | /** |
@@ -5303,56 +5303,56 @@ discard block |
||
| 5303 | 5303 | * Chaîne vide si l'accès est autorisé |
| 5304 | 5304 | */ |
| 5305 | 5305 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5306 | - if ($ok) { |
|
| 5307 | - return ''; |
|
| 5308 | - } |
|
| 5309 | - |
|
| 5310 | - // Vider tous les tampons |
|
| 5311 | - $level = @ob_get_level(); |
|
| 5312 | - while ($level--) { |
|
| 5313 | - @ob_end_clean(); |
|
| 5314 | - } |
|
| 5315 | - |
|
| 5316 | - include_spip('inc/headers'); |
|
| 5317 | - |
|
| 5318 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5319 | - if ($url) { |
|
| 5320 | - redirige_par_entete($url, '', $statut); |
|
| 5321 | - } |
|
| 5322 | - |
|
| 5323 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5324 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5325 | - $message = $statut; |
|
| 5326 | - $statut = 0; |
|
| 5327 | - } |
|
| 5328 | - if (!$message) { |
|
| 5329 | - $message = ''; |
|
| 5330 | - } |
|
| 5331 | - $statut = intval($statut); |
|
| 5332 | - |
|
| 5333 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5334 | - if (test_espace_prive()) { |
|
| 5335 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5336 | - $statut = 403; |
|
| 5337 | - } |
|
| 5338 | - http_response_code(403); |
|
| 5339 | - $echec = charger_fonction('403', 'exec'); |
|
| 5340 | - $echec($message); |
|
| 5341 | - } else { |
|
| 5342 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5343 | - if (!$statut) { |
|
| 5344 | - $statut = 404; |
|
| 5345 | - } |
|
| 5346 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5347 | - http_response_code($statut); |
|
| 5348 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5349 | - if ($statut >= 400) { |
|
| 5350 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5351 | - } |
|
| 5352 | - } |
|
| 5353 | - |
|
| 5354 | - |
|
| 5355 | - exit; |
|
| 5306 | + if ($ok) { |
|
| 5307 | + return ''; |
|
| 5308 | + } |
|
| 5309 | + |
|
| 5310 | + // Vider tous les tampons |
|
| 5311 | + $level = @ob_get_level(); |
|
| 5312 | + while ($level--) { |
|
| 5313 | + @ob_end_clean(); |
|
| 5314 | + } |
|
| 5315 | + |
|
| 5316 | + include_spip('inc/headers'); |
|
| 5317 | + |
|
| 5318 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5319 | + if ($url) { |
|
| 5320 | + redirige_par_entete($url, '', $statut); |
|
| 5321 | + } |
|
| 5322 | + |
|
| 5323 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5324 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5325 | + $message = $statut; |
|
| 5326 | + $statut = 0; |
|
| 5327 | + } |
|
| 5328 | + if (!$message) { |
|
| 5329 | + $message = ''; |
|
| 5330 | + } |
|
| 5331 | + $statut = intval($statut); |
|
| 5332 | + |
|
| 5333 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5334 | + if (test_espace_prive()) { |
|
| 5335 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5336 | + $statut = 403; |
|
| 5337 | + } |
|
| 5338 | + http_response_code(403); |
|
| 5339 | + $echec = charger_fonction('403', 'exec'); |
|
| 5340 | + $echec($message); |
|
| 5341 | + } else { |
|
| 5342 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5343 | + if (!$statut) { |
|
| 5344 | + $statut = 404; |
|
| 5345 | + } |
|
| 5346 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5347 | + http_response_code($statut); |
|
| 5348 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5349 | + if ($statut >= 400) { |
|
| 5350 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5351 | + } |
|
| 5352 | + } |
|
| 5353 | + |
|
| 5354 | + |
|
| 5355 | + exit; |
|
| 5356 | 5356 | } |
| 5357 | 5357 | |
| 5358 | 5358 | /** |
@@ -5363,11 +5363,11 @@ discard block |
||
| 5363 | 5363 | * @return string |
| 5364 | 5364 | */ |
| 5365 | 5365 | function filtre_compacte_dist($source, $format = null) { |
| 5366 | - if (function_exists('minifier')) { |
|
| 5367 | - return minifier($source, $format); |
|
| 5368 | - } |
|
| 5366 | + if (function_exists('minifier')) { |
|
| 5367 | + return minifier($source, $format); |
|
| 5368 | + } |
|
| 5369 | 5369 | |
| 5370 | - return $source; |
|
| 5370 | + return $source; |
|
| 5371 | 5371 | } |
| 5372 | 5372 | |
| 5373 | 5373 | |
@@ -5379,32 +5379,32 @@ discard block |
||
| 5379 | 5379 | * @return string |
| 5380 | 5380 | */ |
| 5381 | 5381 | function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5382 | - $passe ??= ''; |
|
| 5383 | - $l = strlen($passe); |
|
| 5384 | - |
|
| 5385 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5386 | - if (!$l) { |
|
| 5387 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5388 | - } |
|
| 5389 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5390 | - } |
|
| 5391 | - |
|
| 5392 | - if (is_null($portion_pourcent)) { |
|
| 5393 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5394 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5395 | - } |
|
| 5396 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5397 | - } |
|
| 5398 | - if ($portion_pourcent >= 100) { |
|
| 5399 | - return $passe; |
|
| 5400 | - } |
|
| 5401 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5402 | - $e = max($e, 0); |
|
| 5403 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5404 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5405 | - $mid = '***...***'; |
|
| 5406 | - } |
|
| 5407 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5382 | + $passe ??= ''; |
|
| 5383 | + $l = strlen($passe); |
|
| 5384 | + |
|
| 5385 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5386 | + if (!$l) { |
|
| 5387 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5388 | + } |
|
| 5389 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5390 | + } |
|
| 5391 | + |
|
| 5392 | + if (is_null($portion_pourcent)) { |
|
| 5393 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5394 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5395 | + } |
|
| 5396 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5397 | + } |
|
| 5398 | + if ($portion_pourcent >= 100) { |
|
| 5399 | + return $passe; |
|
| 5400 | + } |
|
| 5401 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5402 | + $e = max($e, 0); |
|
| 5403 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5404 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5405 | + $mid = '***...***'; |
|
| 5406 | + } |
|
| 5407 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5408 | 5408 | } |
| 5409 | 5409 | |
| 5410 | 5410 | |
@@ -5425,64 +5425,64 @@ discard block |
||
| 5425 | 5425 | */ |
| 5426 | 5426 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5427 | 5427 | |
| 5428 | - $original = $texte; |
|
| 5429 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5430 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5431 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5428 | + $original = $texte; |
|
| 5429 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5430 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5431 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5432 | 5432 | |
| 5433 | - if (!function_exists('translitteration')) { |
|
| 5434 | - include_spip('inc/charsets'); |
|
| 5435 | - } |
|
| 5433 | + if (!function_exists('translitteration')) { |
|
| 5434 | + include_spip('inc/charsets'); |
|
| 5435 | + } |
|
| 5436 | 5436 | |
| 5437 | - // pas de balise html |
|
| 5438 | - if (strpos($texte, '<') !== false) { |
|
| 5439 | - $texte = strip_tags($texte); |
|
| 5440 | - } |
|
| 5441 | - if (strpos($texte, '&') !== false) { |
|
| 5442 | - $texte = unicode2charset($texte); |
|
| 5443 | - } |
|
| 5444 | - // On enlève les espaces indésirables |
|
| 5445 | - $texte = trim($texte); |
|
| 5437 | + // pas de balise html |
|
| 5438 | + if (strpos($texte, '<') !== false) { |
|
| 5439 | + $texte = strip_tags($texte); |
|
| 5440 | + } |
|
| 5441 | + if (strpos($texte, '&') !== false) { |
|
| 5442 | + $texte = unicode2charset($texte); |
|
| 5443 | + } |
|
| 5444 | + // On enlève les espaces indésirables |
|
| 5445 | + $texte = trim($texte); |
|
| 5446 | 5446 | |
| 5447 | - // On enlève les accents et cie |
|
| 5448 | - $texte = translitteration($texte); |
|
| 5447 | + // On enlève les accents et cie |
|
| 5448 | + $texte = translitteration($texte); |
|
| 5449 | 5449 | |
| 5450 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5451 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5450 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5451 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5452 | 5452 | |
| 5453 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5454 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5455 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5456 | - } |
|
| 5453 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5454 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5455 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5456 | + } |
|
| 5457 | 5457 | |
| 5458 | - // pas de separateur au debut ni a la fin |
|
| 5459 | - $texte = trim($texte, $separateur); |
|
| 5458 | + // pas de separateur au debut ni a la fin |
|
| 5459 | + $texte = trim($texte, $separateur); |
|
| 5460 | 5460 | |
| 5461 | - // en minuscules |
|
| 5462 | - $texte = strtolower($texte); |
|
| 5461 | + // en minuscules |
|
| 5462 | + $texte = strtolower($texte); |
|
| 5463 | 5463 | |
| 5464 | - switch ($type) { |
|
| 5465 | - case 'class': |
|
| 5466 | - case 'id': |
|
| 5467 | - case 'anchor': |
|
| 5468 | - if (preg_match(',^\d,', $texte)) { |
|
| 5469 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5470 | - } |
|
| 5471 | - } |
|
| 5464 | + switch ($type) { |
|
| 5465 | + case 'class': |
|
| 5466 | + case 'id': |
|
| 5467 | + case 'anchor': |
|
| 5468 | + if (preg_match(',^\d,', $texte)) { |
|
| 5469 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5470 | + } |
|
| 5471 | + } |
|
| 5472 | 5472 | |
| 5473 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5474 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5475 | - } |
|
| 5473 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5474 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5475 | + } |
|
| 5476 | 5476 | |
| 5477 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5478 | - if (preg_match(',^\d,', $texte)) { |
|
| 5479 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5480 | - } |
|
| 5481 | - $texte .= $separateur . md5($original); |
|
| 5482 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5483 | - } |
|
| 5477 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5478 | + if (preg_match(',^\d,', $texte)) { |
|
| 5479 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5480 | + } |
|
| 5481 | + $texte .= $separateur . md5($original); |
|
| 5482 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5483 | + } |
|
| 5484 | 5484 | |
| 5485 | - return $texte; |
|
| 5485 | + return $texte; |
|
| 5486 | 5486 | } |
| 5487 | 5487 | |
| 5488 | 5488 | |
@@ -5503,11 +5503,11 @@ discard block |
||
| 5503 | 5503 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5504 | 5504 | */ |
| 5505 | 5505 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5506 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5507 | - if ($ucfirst) { |
|
| 5508 | - $label = spip_ucfirst($label); |
|
| 5509 | - } |
|
| 5510 | - return $label; |
|
| 5506 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5507 | + if ($ucfirst) { |
|
| 5508 | + $label = spip_ucfirst($label); |
|
| 5509 | + } |
|
| 5510 | + return $label; |
|
| 5511 | 5511 | } |
| 5512 | 5512 | |
| 5513 | 5513 | /** |
@@ -5520,8 +5520,8 @@ discard block |
||
| 5520 | 5520 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5521 | 5521 | */ |
| 5522 | 5522 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5523 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5524 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5523 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5524 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5525 | 5525 | } |
| 5526 | 5526 | |
| 5527 | 5527 | |
@@ -5534,19 +5534,19 @@ discard block |
||
| 5534 | 5534 | * @return array |
| 5535 | 5535 | */ |
| 5536 | 5536 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5537 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5538 | - return []; |
|
| 5539 | - } |
|
| 5537 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5538 | + return []; |
|
| 5539 | + } |
|
| 5540 | 5540 | |
| 5541 | - // compatibilite signature inversee |
|
| 5542 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5543 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5544 | - } |
|
| 5541 | + // compatibilite signature inversee |
|
| 5542 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5543 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5544 | + } |
|
| 5545 | 5545 | |
| 5546 | - if (!function_exists($fonction)) { |
|
| 5547 | - include_spip('base/objets'); |
|
| 5548 | - } |
|
| 5549 | - return $fonction($objet, $id_objet); |
|
| 5546 | + if (!function_exists($fonction)) { |
|
| 5547 | + include_spip('base/objets'); |
|
| 5548 | + } |
|
| 5549 | + return $fonction($objet, $id_objet); |
|
| 5550 | 5550 | } |
| 5551 | 5551 | |
| 5552 | 5552 | |
@@ -5561,7 +5561,7 @@ discard block |
||
| 5561 | 5561 | * @return array |
| 5562 | 5562 | */ |
| 5563 | 5563 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5564 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5564 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5565 | 5565 | } |
| 5566 | 5566 | |
| 5567 | 5567 | /** |
@@ -5575,7 +5575,7 @@ discard block |
||
| 5575 | 5575 | * @return array |
| 5576 | 5576 | */ |
| 5577 | 5577 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5578 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5578 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5579 | 5579 | } |
| 5580 | 5580 | |
| 5581 | 5581 | /** |
@@ -5589,7 +5589,7 @@ discard block |
||
| 5589 | 5589 | * @return array |
| 5590 | 5590 | */ |
| 5591 | 5591 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5592 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5592 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5593 | 5593 | } |
| 5594 | 5594 | |
| 5595 | 5595 | /** |
@@ -5603,5 +5603,5 @@ discard block |
||
| 5603 | 5603 | * @return array |
| 5604 | 5604 | */ |
| 5605 | 5605 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5606 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5606 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5607 | 5607 | } |