@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Actions |
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | - use Spip\Chiffrer\SpipCles; |
|
| 18 | + use Spip\Chiffrer\SpipCles; |
|
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -51,19 +51,19 @@ discard block |
||
| 51 | 51 | * @return array|string |
| 52 | 52 | */ |
| 53 | 53 | function inc_securiser_action_dist($action = '', $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 54 | - if ($action) { |
|
| 55 | - return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 56 | - } else { |
|
| 57 | - $arg = _request('arg'); |
|
| 58 | - $hash = _request('hash'); |
|
| 59 | - $action = _request('action') ?: _request('formulaire_action'); |
|
| 60 | - if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 61 | - return $arg; |
|
| 62 | - } |
|
| 63 | - include_spip('inc/minipres'); |
|
| 64 | - echo minipres(); |
|
| 65 | - exit; |
|
| 66 | - } |
|
| 54 | + if ($action) { |
|
| 55 | + return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 56 | + } else { |
|
| 57 | + $arg = _request('arg'); |
|
| 58 | + $hash = _request('hash'); |
|
| 59 | + $action = _request('action') ?: _request('formulaire_action'); |
|
| 60 | + if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 61 | + return $arg; |
|
| 62 | + } |
|
| 63 | + include_spip('inc/minipres'); |
|
| 64 | + echo minipres(); |
|
| 65 | + exit; |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,29 +82,29 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function demander_confirmation_avant_action($titre, $titre_bouton, $url_action = null) { |
| 84 | 84 | |
| 85 | - if (!$url_action) { |
|
| 86 | - $url_action = self(); |
|
| 87 | - $action = _request('action'); |
|
| 88 | - $url_action = parametre_url($url_action, 'action', $action, '&'); |
|
| 89 | - } |
|
| 90 | - else { |
|
| 91 | - $action = parametre_url($url_action, 'action'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $arg = parametre_url($url_action, 'arg'); |
|
| 95 | - $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 96 | - if (_request('confirm_action') === $confirm) { |
|
| 97 | - return true; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&'); |
|
| 101 | - include_spip('inc/filtres'); |
|
| 102 | - $bouton_action = bouton_action($titre_bouton, $url_confirm); |
|
| 103 | - $corps = "<div style='text-align:center;'>$bouton_action</div>"; |
|
| 104 | - |
|
| 105 | - include_spip('inc/minipres'); |
|
| 106 | - echo minipres($titre, $corps); |
|
| 107 | - exit; |
|
| 85 | + if (!$url_action) { |
|
| 86 | + $url_action = self(); |
|
| 87 | + $action = _request('action'); |
|
| 88 | + $url_action = parametre_url($url_action, 'action', $action, '&'); |
|
| 89 | + } |
|
| 90 | + else { |
|
| 91 | + $action = parametre_url($url_action, 'action'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $arg = parametre_url($url_action, 'arg'); |
|
| 95 | + $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 96 | + if (_request('confirm_action') === $confirm) { |
|
| 97 | + return true; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&'); |
|
| 101 | + include_spip('inc/filtres'); |
|
| 102 | + $bouton_action = bouton_action($titre_bouton, $url_confirm); |
|
| 103 | + $corps = "<div style='text-align:center;'>$bouton_action</div>"; |
|
| 104 | + |
|
| 105 | + include_spip('inc/minipres'); |
|
| 106 | + echo minipres($titre, $corps); |
|
| 107 | + exit; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -135,34 +135,34 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | function securiser_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) { |
| 137 | 137 | |
| 138 | - // mode URL ou array |
|
| 139 | - if (!is_string($mode)) { |
|
| 140 | - $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 141 | - |
|
| 142 | - $r = rawurlencode($redirect); |
|
| 143 | - if ($mode === -1) { |
|
| 144 | - return ['action' => $action, 'arg' => $arg, 'hash' => $hash]; |
|
| 145 | - } else { |
|
| 146 | - return generer_url_action( |
|
| 147 | - $action, |
|
| 148 | - 'arg=' . rawurlencode($arg) . "&hash=$hash" . ($r ? "&redirect=$r" : ''), |
|
| 149 | - $mode, |
|
| 150 | - $public |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // mode formulaire |
|
| 156 | - $hash = calculer_action_auteur("$action-$arg"); |
|
| 157 | - $att .= " style='margin: 0px; border: 0px'"; |
|
| 158 | - if ($redirect) { |
|
| 159 | - $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 160 | - } |
|
| 161 | - $mode .= $redirect . " |
|
| 138 | + // mode URL ou array |
|
| 139 | + if (!is_string($mode)) { |
|
| 140 | + $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 141 | + |
|
| 142 | + $r = rawurlencode($redirect); |
|
| 143 | + if ($mode === -1) { |
|
| 144 | + return ['action' => $action, 'arg' => $arg, 'hash' => $hash]; |
|
| 145 | + } else { |
|
| 146 | + return generer_url_action( |
|
| 147 | + $action, |
|
| 148 | + 'arg=' . rawurlencode($arg) . "&hash=$hash" . ($r ? "&redirect=$r" : ''), |
|
| 149 | + $mode, |
|
| 150 | + $public |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // mode formulaire |
|
| 156 | + $hash = calculer_action_auteur("$action-$arg"); |
|
| 157 | + $att .= " style='margin: 0px; border: 0px'"; |
|
| 158 | + if ($redirect) { |
|
| 159 | + $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 160 | + } |
|
| 161 | + $mode .= $redirect . " |
|
| 162 | 162 | <input name='hash' type='hidden' value='$hash' /> |
| 163 | 163 | <input name='arg' type='hidden' value='$arg' />"; |
| 164 | 164 | |
| 165 | - return generer_form_action($action, $mode, $att, $public); |
|
| 165 | + return generer_form_action($action, $mode, $att, $public); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,48 +172,48 @@ discard block |
||
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | 174 | function caracteriser_auteur($id_auteur = null) { |
| 175 | - static $caracterisation = []; |
|
| 176 | - |
|
| 177 | - if (is_null($id_auteur) && !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 178 | - // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 179 | - // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 180 | - // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 181 | - if ( |
|
| 182 | - isset($_COOKIE['spip_session']) |
|
| 183 | - && preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r) |
|
| 184 | - ) { |
|
| 185 | - return [$r[1], '']; |
|
| 186 | - // Necessaire aux forums anonymes. |
|
| 187 | - // Pour le reste, ca echouera. |
|
| 188 | - } else { |
|
| 189 | - return ['0', '']; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - // Eviter l'acces SQL si le pass est connu de PHP |
|
| 193 | - if (is_null($id_auteur)) { |
|
| 194 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 195 | - if (isset($GLOBALS['visiteur_session']['pass']) && $GLOBALS['visiteur_session']['pass']) { |
|
| 196 | - return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']]; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (isset($caracterisation[$id_auteur])) { |
|
| 201 | - return $caracterisation[$id_auteur]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ($id_auteur) { |
|
| 205 | - include_spip('base/abstract_sql'); |
|
| 206 | - $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 207 | - if ($t) { |
|
| 208 | - return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']]; |
|
| 209 | - } |
|
| 210 | - include_spip('inc/minipres'); |
|
| 211 | - echo minipres(); |
|
| 212 | - exit; |
|
| 213 | - } // Visiteur anonyme, pour ls forums par exemple |
|
| 214 | - else { |
|
| 215 | - return ['0', '']; |
|
| 216 | - } |
|
| 175 | + static $caracterisation = []; |
|
| 176 | + |
|
| 177 | + if (is_null($id_auteur) && !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 178 | + // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 179 | + // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 180 | + // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 181 | + if ( |
|
| 182 | + isset($_COOKIE['spip_session']) |
|
| 183 | + && preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r) |
|
| 184 | + ) { |
|
| 185 | + return [$r[1], '']; |
|
| 186 | + // Necessaire aux forums anonymes. |
|
| 187 | + // Pour le reste, ca echouera. |
|
| 188 | + } else { |
|
| 189 | + return ['0', '']; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + // Eviter l'acces SQL si le pass est connu de PHP |
|
| 193 | + if (is_null($id_auteur)) { |
|
| 194 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 195 | + if (isset($GLOBALS['visiteur_session']['pass']) && $GLOBALS['visiteur_session']['pass']) { |
|
| 196 | + return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']]; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (isset($caracterisation[$id_auteur])) { |
|
| 201 | + return $caracterisation[$id_auteur]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ($id_auteur) { |
|
| 205 | + include_spip('base/abstract_sql'); |
|
| 206 | + $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 207 | + if ($t) { |
|
| 208 | + return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']]; |
|
| 209 | + } |
|
| 210 | + include_spip('inc/minipres'); |
|
| 211 | + echo minipres(); |
|
| 212 | + exit; |
|
| 213 | + } // Visiteur anonyme, pour ls forums par exemple |
|
| 214 | + else { |
|
| 215 | + return ['0', '']; |
|
| 216 | + } |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -222,31 +222,31 @@ discard block |
||
| 222 | 222 | * et verifier la legitimite de l'appel a l'action |
| 223 | 223 | */ |
| 224 | 224 | function _action_auteur(string $action, int $id_auteur, #[\SensitiveParameter] ?string $pass, string $alea): string { |
| 225 | - static $sha = []; |
|
| 226 | - $pass ??= ''; |
|
| 227 | - $entry = "$action:$id_auteur:$pass:$alea"; |
|
| 228 | - if (!isset($sha[$entry])) { |
|
| 229 | - $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea)); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - return $sha[$entry]; |
|
| 225 | + static $sha = []; |
|
| 226 | + $pass ??= ''; |
|
| 227 | + $entry = "$action:$id_auteur:$pass:$alea"; |
|
| 228 | + if (!isset($sha[$entry])) { |
|
| 229 | + $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea)); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + return $sha[$entry]; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | function _action_get_alea(string $alea): string { |
| 236 | - if (!isset($GLOBALS['meta'][$alea])) { |
|
| 237 | - $exec = _request('exec'); |
|
| 238 | - if (!$exec || !autoriser_sans_cookie($exec)) { |
|
| 239 | - include_spip('inc/acces'); |
|
| 240 | - charger_aleas(); |
|
| 241 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 242 | - include_spip('inc/minipres'); |
|
| 243 | - echo minipres(); |
|
| 244 | - spip_log("$alea indisponible"); |
|
| 245 | - exit; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - return $GLOBALS['meta'][$alea] ?? ''; |
|
| 236 | + if (!isset($GLOBALS['meta'][$alea])) { |
|
| 237 | + $exec = _request('exec'); |
|
| 238 | + if (!$exec || !autoriser_sans_cookie($exec)) { |
|
| 239 | + include_spip('inc/acces'); |
|
| 240 | + charger_aleas(); |
|
| 241 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 242 | + include_spip('inc/minipres'); |
|
| 243 | + echo minipres(); |
|
| 244 | + spip_log("$alea indisponible"); |
|
| 245 | + exit; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + return $GLOBALS['meta'][$alea] ?? ''; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | 259 | function calculer_action_auteur($action, $id_auteur = null) { |
| 260 | - [$id_auteur, $pass] = caracteriser_auteur($id_auteur); |
|
| 260 | + [$id_auteur, $pass] = caracteriser_auteur($id_auteur); |
|
| 261 | 261 | |
| 262 | - return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 262 | + return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -272,9 +272,9 @@ discard block |
||
| 272 | 272 | * @return bool |
| 273 | 273 | */ |
| 274 | 274 | function verifier_action_auteur($action, $hash) { |
| 275 | - [$id_auteur, $pass] = caracteriser_auteur(); |
|
| 276 | - return hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) |
|
| 277 | - || hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')); |
|
| 275 | + [$id_auteur, $pass] = caracteriser_auteur(); |
|
| 276 | + return hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) |
|
| 277 | + || hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | 291 | function secret_du_site() { |
| 292 | - return SpipCles::secret_du_site(); |
|
| 292 | + return SpipCles::secret_du_site(); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | 301 | function calculer_cle_action($action) { |
| 302 | - return hash_hmac('sha256', $action, secret_du_site()); |
|
| 302 | + return hash_hmac('sha256', $action, secret_du_site()); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return bool |
| 311 | 311 | */ |
| 312 | 312 | function verifier_cle_action($action, #[\SensitiveParameter] $cle) { |
| 313 | - return hash_equals($cle, calculer_cle_action($action)); |
|
| 313 | + return hash_equals($cle, calculer_cle_action($action)); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
@@ -327,17 +327,17 @@ discard block |
||
| 327 | 327 | * @return string Token, de la forme "{id}*{hash}" |
| 328 | 328 | */ |
| 329 | 329 | function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') { |
| 330 | - if (is_null($id_auteur) && !empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 331 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 332 | - } |
|
| 333 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 334 | - return ''; |
|
| 335 | - } |
|
| 336 | - // On nettoie l’URL de tous les var_. |
|
| 337 | - $url = nettoyer_uri_var($url); |
|
| 338 | - |
|
| 339 | - $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea); |
|
| 340 | - return "$id_auteur-$token"; |
|
| 330 | + if (is_null($id_auteur) && !empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 331 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 332 | + } |
|
| 333 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 334 | + return ''; |
|
| 335 | + } |
|
| 336 | + // On nettoie l’URL de tous les var_. |
|
| 337 | + $url = nettoyer_uri_var($url); |
|
| 338 | + |
|
| 339 | + $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea); |
|
| 340 | + return "$id_auteur-$token"; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | |
@@ -355,31 +355,31 @@ discard block |
||
| 355 | 355 | * + Tableau (id auteur, type d’objet, id_objet) sinon. |
| 356 | 356 | */ |
| 357 | 357 | function verifier_token_previsu(#[\SensitiveParameter] $token) { |
| 358 | - // retrouver auteur / hash |
|
| 359 | - $e = explode('-', $token, 2); |
|
| 360 | - if (count($e) == 2 && is_numeric(reset($e))) { |
|
| 361 | - $id_auteur = (int) reset($e); |
|
| 362 | - } else { |
|
| 363 | - return false; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // calculer le type et id de l’url actuelle |
|
| 367 | - include_spip('inc/urls'); |
|
| 368 | - include_spip('inc/filtres_mini'); |
|
| 369 | - $url = url_absolue(self()); |
|
| 370 | - |
|
| 371 | - // verifier le token |
|
| 372 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 373 | - if (!$_token || !hash_equals($token, $_token)) { |
|
| 374 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 375 | - if (!$_token || !hash_equals($token, $_token)) { |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - return [ |
|
| 381 | - 'id_auteur' => $id_auteur, |
|
| 382 | - ]; |
|
| 358 | + // retrouver auteur / hash |
|
| 359 | + $e = explode('-', $token, 2); |
|
| 360 | + if (count($e) == 2 && is_numeric(reset($e))) { |
|
| 361 | + $id_auteur = (int) reset($e); |
|
| 362 | + } else { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // calculer le type et id de l’url actuelle |
|
| 367 | + include_spip('inc/urls'); |
|
| 368 | + include_spip('inc/filtres_mini'); |
|
| 369 | + $url = url_absolue(self()); |
|
| 370 | + |
|
| 371 | + // verifier le token |
|
| 372 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 373 | + if (!$_token || !hash_equals($token, $_token)) { |
|
| 374 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 375 | + if (!$_token || !hash_equals($token, $_token)) { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + return [ |
|
| 381 | + 'id_auteur' => $id_auteur, |
|
| 382 | + ]; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | * @return bool|array |
| 389 | 389 | */ |
| 390 | 390 | function decrire_token_previsu() { |
| 391 | - static $desc = null; |
|
| 392 | - if (is_null($desc)) { |
|
| 393 | - $desc = ($token = _request('var_previewtoken')) ? verifier_token_previsu($token) : false; |
|
| 394 | - } |
|
| 395 | - return $desc; |
|
| 391 | + static $desc = null; |
|
| 392 | + if (is_null($desc)) { |
|
| 393 | + $desc = ($token = _request('var_previewtoken')) ? verifier_token_previsu($token) : false; |
|
| 394 | + } |
|
| 395 | + return $desc; |
|
| 396 | 396 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $arg = parametre_url($url_action, 'arg'); |
| 95 | - $confirm = md5("$action:$arg:" . realpath(__FILE__)); |
|
| 95 | + $confirm = md5("$action:$arg:".realpath(__FILE__)); |
|
| 96 | 96 | if (_request('confirm_action') === $confirm) { |
| 97 | 97 | return true; |
| 98 | 98 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | } else { |
| 146 | 146 | return generer_url_action( |
| 147 | 147 | $action, |
| 148 | - 'arg=' . rawurlencode($arg) . "&hash=$hash" . ($r ? "&redirect=$r" : ''), |
|
| 148 | + 'arg='.rawurlencode($arg)."&hash=$hash".($r ? "&redirect=$r" : ''), |
|
| 149 | 149 | $mode, |
| 150 | 150 | $public |
| 151 | 151 | ); |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | $hash = calculer_action_auteur("$action-$arg"); |
| 157 | 157 | $att .= " style='margin: 0px; border: 0px'"; |
| 158 | 158 | if ($redirect) { |
| 159 | - $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 159 | + $redirect = "\n\t\t<input name='redirect' type='hidden' value='".str_replace("'", ''', $redirect)."' />"; |
|
| 160 | 160 | } |
| 161 | - $mode .= $redirect . " |
|
| 161 | + $mode .= $redirect." |
|
| 162 | 162 | <input name='hash' type='hidden' value='$hash' /> |
| 163 | 163 | <input name='arg' type='hidden' value='$arg' />"; |
| 164 | 164 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $pass ??= ''; |
| 227 | 227 | $entry = "$action:$id_auteur:$pass:$alea"; |
| 228 | 228 | if (!isset($sha[$entry])) { |
| 229 | - $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea)); |
|
| 229 | + $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::"._action_get_alea($alea)); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return $sha[$entry]; |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | // On nettoie l’URL de tous les var_. |
| 337 | 337 | $url = nettoyer_uri_var($url); |
| 338 | 338 | |
| 339 | - $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea); |
|
| 339 | + $token = _action_auteur('previsualiser-'.$url, $id_auteur, secret_du_site(), $alea); |
|
| 340 | 340 | return "$id_auteur-$token"; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | * @return string Code HTML |
| 43 | 43 | **/ |
| 44 | 44 | function inc_commencer_page_dist( |
| 45 | - $titre = '', |
|
| 46 | - $rubrique = 'accueil', |
|
| 47 | - $sous_rubrique = 'accueil', |
|
| 48 | - $id_rubrique = '', |
|
| 49 | - $menu = true, |
|
| 50 | - $minipres = false, |
|
| 51 | - $alertes = true |
|
| 45 | + $titre = '', |
|
| 46 | + $rubrique = 'accueil', |
|
| 47 | + $sous_rubrique = 'accueil', |
|
| 48 | + $id_rubrique = '', |
|
| 49 | + $menu = true, |
|
| 50 | + $minipres = false, |
|
| 51 | + $alertes = true |
|
| 52 | 52 | ) { |
| 53 | 53 | |
| 54 | - include_spip('inc/headers'); |
|
| 54 | + include_spip('inc/headers'); |
|
| 55 | 55 | |
| 56 | - http_no_cache(); |
|
| 56 | + http_no_cache(); |
|
| 57 | 57 | |
| 58 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 59 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 60 | - . "<div id='page'>" |
|
| 61 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 62 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 63 | - . '<div class="largeur">'; |
|
| 58 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 59 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 60 | + . "<div id='page'>" |
|
| 61 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 62 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 63 | + . '<div class="largeur">'; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -81,21 +81,21 @@ discard block |
||
| 81 | 81 | * Entête du fichier HTML avec le DOCTYPE |
| 82 | 82 | */ |
| 83 | 83 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 84 | - include_spip('inc/texte'); |
|
| 85 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 86 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $titre = '[' |
|
| 90 | - . $nom_site_spip |
|
| 91 | - . ']' |
|
| 92 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | - |
|
| 94 | - return _DOCTYPE_ECRIRE |
|
| 95 | - . html_lang_attributes() |
|
| 96 | - . "<head>\n" |
|
| 97 | - . init_head($titre, $dummy, $minipres) |
|
| 98 | - . "</head>\n"; |
|
| 84 | + include_spip('inc/texte'); |
|
| 85 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 86 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $titre = '[' |
|
| 90 | + . $nom_site_spip |
|
| 91 | + . ']' |
|
| 92 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + |
|
| 94 | + return _DOCTYPE_ECRIRE |
|
| 95 | + . html_lang_attributes() |
|
| 96 | + . "<head>\n" |
|
| 97 | + . init_head($titre, $dummy, $minipres) |
|
| 98 | + . "</head>\n"; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | 111 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 112 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 112 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 133 | 133 | |
| 134 | - $res = pipeline('body_prive', "<body class='" |
|
| 135 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 137 | - . '>'); |
|
| 134 | + $res = pipeline('body_prive', "<body class='" |
|
| 135 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 137 | + . '>'); |
|
| 138 | 138 | |
| 139 | - if (!$menu) { |
|
| 140 | - return $res; |
|
| 141 | - } |
|
| 139 | + if (!$menu) { |
|
| 140 | + return $res; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | |
| 144 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 144 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | 145 | |
| 146 | - return $res |
|
| 147 | - . $bandeau(); |
|
| 146 | + return $res |
|
| 147 | + . $bandeau(); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | * @return string Classes CSS (séparées par des espaces) |
| 157 | 157 | */ |
| 158 | 158 | function init_body_class() { |
| 159 | - $display_modes = [ |
|
| 160 | - 0 => 'icones_img_texte' // défaut. |
|
| 161 | - /*init*/, |
|
| 162 | - 1 => 'icones_texte', |
|
| 163 | - 2 => 'icones_img_texte', |
|
| 164 | - 3 => 'icones_img' |
|
| 165 | - ]; |
|
| 159 | + $display_modes = [ |
|
| 160 | + 0 => 'icones_img_texte' // défaut. |
|
| 161 | + /*init*/, |
|
| 162 | + 1 => 'icones_texte', |
|
| 163 | + 2 => 'icones_img_texte', |
|
| 164 | + 3 => 'icones_img' |
|
| 165 | + ]; |
|
| 166 | 166 | |
| 167 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 167 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 168 | 168 | |
| 169 | - $display_mode = $display_modes[(int) ($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 170 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 169 | + $display_mode = $display_modes[(int) ($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 170 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 171 | 171 | |
| 172 | - $couleur = (int) ($prefs['couleur'] ?? 2); |
|
| 172 | + $couleur = (int) ($prefs['couleur'] ?? 2); |
|
| 173 | 173 | |
| 174 | - $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 175 | - return spip_sanitize_classname($classes); |
|
| 174 | + $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 175 | + return spip_sanitize_classname($classes); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -183,5 +183,5 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | function auteurs_recemment_connectes($id_auteur) { |
| 186 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 186 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 187 | 187 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Fichier |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -35,28 +35,28 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream', $options = []) { |
| 37 | 37 | |
| 38 | - $defaut = [ |
|
| 39 | - 'attachment' => false, |
|
| 40 | - 'expires' => 3600, |
|
| 41 | - 'range' => null, |
|
| 42 | - ]; |
|
| 43 | - $options = array_merge($defaut, $options); |
|
| 44 | - if (is_numeric($options['expires']) && $options['expires'] > 0) { |
|
| 45 | - $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - if (is_null($options) && isset($_SERVER['HTTP_RANGE'])) { |
|
| 49 | - $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - spip_livrer_fichier_entetes($fichier, $content_type, ($options['attachment'] && !$options['range']) ? $options['attachment'] : false, $options['expires']); |
|
| 53 | - |
|
| 54 | - if (!is_null($options['range'])) { |
|
| 55 | - spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - spip_livrer_fichier_entier($fichier); |
|
| 59 | - } |
|
| 38 | + $defaut = [ |
|
| 39 | + 'attachment' => false, |
|
| 40 | + 'expires' => 3600, |
|
| 41 | + 'range' => null, |
|
| 42 | + ]; |
|
| 43 | + $options = array_merge($defaut, $options); |
|
| 44 | + if (is_numeric($options['expires']) && $options['expires'] > 0) { |
|
| 45 | + $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + if (is_null($options) && isset($_SERVER['HTTP_RANGE'])) { |
|
| 49 | + $options['range'] = $_SERVER['HTTP_RANGE']; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + spip_livrer_fichier_entetes($fichier, $content_type, ($options['attachment'] && !$options['range']) ? $options['attachment'] : false, $options['expires']); |
|
| 53 | + |
|
| 54 | + if (!is_null($options['range'])) { |
|
| 55 | + spip_livrer_fichier_partie($fichier, $options['range']); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + spip_livrer_fichier_entier($fichier); |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -69,33 +69,33 @@ discard block |
||
| 69 | 69 | * @param int|string $expires |
| 70 | 70 | */ |
| 71 | 71 | function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) { |
| 72 | - // toujours envoyer un content type, meme vide ! |
|
| 73 | - header('Accept-Ranges: bytes'); |
|
| 74 | - header('Content-Type: ' . $content_type); |
|
| 75 | - |
|
| 76 | - if (($fs = stat($fichier)) && !empty($fs['size']) && !empty($fs['mtime'])) { |
|
| 77 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fs['mtime']) . ' GMT'); |
|
| 78 | - header(sprintf('Etag: "%x-%x"', $fs['size'], str_pad($fs['mtime'], 16, '0'))); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if ($attachment) { |
|
| 82 | - $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 83 | - // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 84 | - header('Content-Type: application/octet-stream'); |
|
| 85 | - |
|
| 86 | - header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 87 | - header('Content-Transfer-Encoding: binary'); |
|
| 88 | - |
|
| 89 | - // fix for IE caching or PHP bug issue |
|
| 90 | - header('Expires: 0'); // set expiration time |
|
| 91 | - header('Pragma: public'); |
|
| 92 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 93 | - } |
|
| 94 | - else { |
|
| 95 | - $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 96 | - header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 97 | - header('Expires: ' . $expires); // set expiration time |
|
| 98 | - } |
|
| 72 | + // toujours envoyer un content type, meme vide ! |
|
| 73 | + header('Accept-Ranges: bytes'); |
|
| 74 | + header('Content-Type: ' . $content_type); |
|
| 75 | + |
|
| 76 | + if (($fs = stat($fichier)) && !empty($fs['size']) && !empty($fs['mtime'])) { |
|
| 77 | + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fs['mtime']) . ' GMT'); |
|
| 78 | + header(sprintf('Etag: "%x-%x"', $fs['size'], str_pad($fs['mtime'], 16, '0'))); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if ($attachment) { |
|
| 82 | + $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 83 | + // ce content-type est necessaire pour eviter des corruptions de zip dans ie6 |
|
| 84 | + header('Content-Type: application/octet-stream'); |
|
| 85 | + |
|
| 86 | + header("Content-Disposition: attachment; filename=\"$f\";"); |
|
| 87 | + header('Content-Transfer-Encoding: binary'); |
|
| 88 | + |
|
| 89 | + // fix for IE caching or PHP bug issue |
|
| 90 | + header('Expires: 0'); // set expiration time |
|
| 91 | + header('Pragma: public'); |
|
| 92 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 93 | + } |
|
| 94 | + else { |
|
| 95 | + $f = (is_string($attachment) ? $attachment : basename($fichier)); |
|
| 96 | + header("Content-Disposition: inline; filename=\"$f\";"); |
|
| 97 | + header('Expires: ' . $expires); // set expiration time |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,20 +103,20 @@ discard block |
||
| 103 | 103 | * @param string $fichier |
| 104 | 104 | */ |
| 105 | 105 | function spip_livrer_fichier_entier($fichier) { |
| 106 | - if (!file_exists($fichier)) { |
|
| 107 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 108 | - } |
|
| 106 | + if (!file_exists($fichier)) { |
|
| 107 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - if (!is_readable($fichier)) { |
|
| 111 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 112 | - } |
|
| 110 | + if (!is_readable($fichier)) { |
|
| 111 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if ($size = filesize($fichier)) { |
|
| 115 | - header(sprintf('Content-Length: %d', $size)); |
|
| 116 | - } |
|
| 114 | + if ($size = filesize($fichier)) { |
|
| 115 | + header(sprintf('Content-Length: %d', $size)); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - readfile($fichier); |
|
| 119 | - exit(); |
|
| 118 | + readfile($fichier); |
|
| 119 | + exit(); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -129,98 +129,98 @@ discard block |
||
| 129 | 129 | * @throws Exception |
| 130 | 130 | */ |
| 131 | 131 | function spip_livrer_fichier_partie($fichier, $range = null) { |
| 132 | - if (!file_exists($fichier)) { |
|
| 133 | - throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 134 | - } |
|
| 132 | + if (!file_exists($fichier)) { |
|
| 133 | + throw new \Exception(sprintf('File not found: %s', $fichier)); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if (!is_readable($fichier)) { |
|
| 137 | - throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 138 | - } |
|
| 136 | + if (!is_readable($fichier)) { |
|
| 137 | + throw new \Exception(sprintf('File not readable: %s', $fichier)); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | - // Par defaut on envoie tout |
|
| 142 | - $byteOffset = 0; |
|
| 143 | - $byteLength = $fileSize = filesize($fichier); |
|
| 141 | + // Par defaut on envoie tout |
|
| 142 | + $byteOffset = 0; |
|
| 143 | + $byteLength = $fileSize = filesize($fichier); |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 147 | - if ($range && preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 148 | - ### Offset signifies where we should begin to read the file |
|
| 149 | - $byteOffset = (int)$match[1]; |
|
| 146 | + // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
|
| 147 | + if ($range && preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
|
| 148 | + ### Offset signifies where we should begin to read the file |
|
| 149 | + $byteOffset = (int)$match[1]; |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | - ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 153 | - if (isset($match[2])) { |
|
| 154 | - $finishBytes = (int)$match[2]; |
|
| 155 | - $byteLength = $finishBytes + 1; |
|
| 156 | - } else { |
|
| 157 | - $finishBytes = $fileSize - 1; |
|
| 158 | - } |
|
| 152 | + ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
|
| 153 | + if (isset($match[2])) { |
|
| 154 | + $finishBytes = (int)$match[2]; |
|
| 155 | + $byteLength = $finishBytes + 1; |
|
| 156 | + } else { |
|
| 157 | + $finishBytes = $fileSize - 1; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 161 | - } |
|
| 162 | - else { |
|
| 163 | - // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 164 | - spip_livrer_fichier_entier($fichier); |
|
| 165 | - // redondant, mais facilite la comprehension du code |
|
| 166 | - exit(); |
|
| 167 | - } |
|
| 160 | + $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize); |
|
| 161 | + } |
|
| 162 | + else { |
|
| 163 | + // si pas de range valide, on delegue a la methode d'envoi complet |
|
| 164 | + spip_livrer_fichier_entier($fichier); |
|
| 165 | + // redondant, mais facilite la comprehension du code |
|
| 166 | + exit(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - // Remove headers that might unnecessarily clutter up the output |
|
| 170 | - header_remove('Cache-Control'); |
|
| 171 | - header_remove('Pragma'); |
|
| 169 | + // Remove headers that might unnecessarily clutter up the output |
|
| 170 | + header_remove('Cache-Control'); |
|
| 171 | + header_remove('Pragma'); |
|
| 172 | 172 | |
| 173 | - // partial content |
|
| 174 | - header('HTTP/1.1 206 Partial content'); |
|
| 175 | - header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 173 | + // partial content |
|
| 174 | + header('HTTP/1.1 206 Partial content'); |
|
| 175 | + header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | - $byteRange = $byteLength - $byteOffset; |
|
| 178 | + $byteRange = $byteLength - $byteOffset; |
|
| 179 | 179 | |
| 180 | - header(sprintf('Content-Length: %d', $byteRange)); |
|
| 180 | + header(sprintf('Content-Length: %d', $byteRange)); |
|
| 181 | 181 | |
| 182 | - // Variable containing the buffer |
|
| 183 | - $buffer = ''; |
|
| 184 | - // Just a reasonable buffer size |
|
| 185 | - $bufferSize = 512 * 16; |
|
| 186 | - // Contains how much is left to read of the byteRange |
|
| 187 | - $bytePool = $byteRange; |
|
| 182 | + // Variable containing the buffer |
|
| 183 | + $buffer = ''; |
|
| 184 | + // Just a reasonable buffer size |
|
| 185 | + $bufferSize = 512 * 16; |
|
| 186 | + // Contains how much is left to read of the byteRange |
|
| 187 | + $bytePool = $byteRange; |
|
| 188 | 188 | |
| 189 | - if (!$handle = fopen($fichier, 'r')) { |
|
| 190 | - throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 191 | - } |
|
| 189 | + if (!$handle = fopen($fichier, 'r')) { |
|
| 190 | + throw new \Exception(sprintf('Could not get handle for file %s', $fichier)); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 194 | - throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 195 | - } |
|
| 193 | + if (fseek($handle, $byteOffset, SEEK_SET) == -1) { |
|
| 194 | + throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset)); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | 197 | |
| 198 | - while ($bytePool > 0) { |
|
| 199 | - // How many bytes we request on this iteration |
|
| 200 | - $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 198 | + while ($bytePool > 0) { |
|
| 199 | + // How many bytes we request on this iteration |
|
| 200 | + $chunkSizeRequested = min($bufferSize, $bytePool); |
|
| 201 | 201 | |
| 202 | - // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 203 | - $buffer = fread($handle, $chunkSizeRequested); |
|
| 202 | + // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer |
|
| 203 | + $buffer = fread($handle, $chunkSizeRequested); |
|
| 204 | 204 | |
| 205 | - // Store how many bytes were actually read |
|
| 206 | - $chunkSizeActual = strlen($buffer); |
|
| 205 | + // Store how many bytes were actually read |
|
| 206 | + $chunkSizeActual = strlen($buffer); |
|
| 207 | 207 | |
| 208 | - // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 209 | - if ($chunkSizeActual == 0) { |
|
| 210 | - // For production servers this should go in your php error log, since it will break the output |
|
| 211 | - trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 212 | - break; |
|
| 213 | - } |
|
| 208 | + // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already |
|
| 209 | + if ($chunkSizeActual == 0) { |
|
| 210 | + // For production servers this should go in your php error log, since it will break the output |
|
| 211 | + trigger_error('Chunksize became 0', E_USER_WARNING); |
|
| 212 | + break; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 216 | - $bytePool -= $chunkSizeActual; |
|
| 215 | + // Decrease byte pool with amount of bytes that were read during this iteration |
|
| 216 | + $bytePool -= $chunkSizeActual; |
|
| 217 | 217 | |
| 218 | - // Write the buffer to output |
|
| 219 | - print $buffer; |
|
| 218 | + // Write the buffer to output |
|
| 219 | + print $buffer; |
|
| 220 | 220 | |
| 221 | - // Try to output the data to the client immediately |
|
| 222 | - flush(); |
|
| 223 | - } |
|
| 221 | + // Try to output the data to the client immediately |
|
| 222 | + flush(); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - exit(); |
|
| 225 | + exit(); |
|
| 226 | 226 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | ]; |
| 43 | 43 | $options = array_merge($defaut, $options); |
| 44 | 44 | if (is_numeric($options['expires']) && $options['expires'] > 0) { |
| 45 | - $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT'; |
|
| 45 | + $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']).' GMT'; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | if (is_null($options) && isset($_SERVER['HTTP_RANGE'])) { |
@@ -71,10 +71,10 @@ discard block |
||
| 71 | 71 | function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) { |
| 72 | 72 | // toujours envoyer un content type, meme vide ! |
| 73 | 73 | header('Accept-Ranges: bytes'); |
| 74 | - header('Content-Type: ' . $content_type); |
|
| 74 | + header('Content-Type: '.$content_type); |
|
| 75 | 75 | |
| 76 | 76 | if (($fs = stat($fichier)) && !empty($fs['size']) && !empty($fs['mtime'])) { |
| 77 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fs['mtime']) . ' GMT'); |
|
| 77 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fs['mtime']).' GMT'); |
|
| 78 | 78 | header(sprintf('Etag: "%x-%x"', $fs['size'], str_pad($fs['mtime'], 16, '0'))); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | else { |
| 95 | 95 | $f = (is_string($attachment) ? $attachment : basename($fichier)); |
| 96 | 96 | header("Content-Disposition: inline; filename=\"$f\";"); |
| 97 | - header('Expires: ' . $expires); // set expiration time |
|
| 97 | + header('Expires: '.$expires); // set expiration time |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451" |
| 147 | 147 | if ($range && preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) { |
| 148 | 148 | ### Offset signifies where we should begin to read the file |
| 149 | - $byteOffset = (int)$match[1]; |
|
| 149 | + $byteOffset = (int) $match[1]; |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | 152 | ### Length is for how long we should read the file according to the browser, and can never go beyond the file size |
| 153 | 153 | if (isset($match[2])) { |
| 154 | - $finishBytes = (int)$match[2]; |
|
| 154 | + $finishBytes = (int) $match[2]; |
|
| 155 | 155 | $byteLength = $finishBytes + 1; |
| 156 | 156 | } else { |
| 157 | 157 | $finishBytes = $fileSize - 1; |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | // partial content |
| 174 | 174 | header('HTTP/1.1 206 Partial content'); |
| 175 | - header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 175 | + header($cr_header); ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | 178 | $byteRange = $byteLength - $byteOffset; |
@@ -16,13 +16,13 @@ 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('IMG_SVG')) { |
| 23 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | - define('IMG_SVG', 128); |
|
| 25 | - define('IMAGETYPE_SVG', 19); |
|
| 23 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | + define('IMG_SVG', 128); |
|
| 25 | + define('IMAGETYPE_SVG', 19); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | * false si on a pas pu charger l'image |
| 39 | 39 | */ |
| 40 | 40 | function svg_charger($fichier, $maxlen = null) { |
| 41 | - if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | - $image = explode(';', $fichier, 2); |
|
| 43 | - $image = end($image); |
|
| 44 | - if (str_starts_with($image, 'base64,')) { |
|
| 45 | - $image = base64_decode(substr($image, 7)); |
|
| 46 | - } |
|
| 47 | - if (str_contains($image, '<svg')) { |
|
| 48 | - return $image; |
|
| 49 | - } |
|
| 50 | - // encodage inconnu ou autre format d'image ? |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - // c'est peut etre deja une image svg ? |
|
| 54 | - if (str_contains($fichier, '<svg')) { |
|
| 55 | - return $fichier; |
|
| 56 | - } |
|
| 57 | - if (!file_exists($fichier)) { |
|
| 58 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | - if (!file_exists($fichier)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 64 | - // est-ce bien une image svg ? |
|
| 65 | - if (str_contains($image, '<svg')) { |
|
| 66 | - return $image; |
|
| 67 | - } |
|
| 68 | - return false; |
|
| 41 | + if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | + $image = explode(';', $fichier, 2); |
|
| 43 | + $image = end($image); |
|
| 44 | + if (str_starts_with($image, 'base64,')) { |
|
| 45 | + $image = base64_decode(substr($image, 7)); |
|
| 46 | + } |
|
| 47 | + if (str_contains($image, '<svg')) { |
|
| 48 | + return $image; |
|
| 49 | + } |
|
| 50 | + // encodage inconnu ou autre format d'image ? |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + // c'est peut etre deja une image svg ? |
|
| 54 | + if (str_contains($fichier, '<svg')) { |
|
| 55 | + return $fichier; |
|
| 56 | + } |
|
| 57 | + if (!file_exists($fichier)) { |
|
| 58 | + $fichier = supprimer_timestamp($fichier); |
|
| 59 | + if (!file_exists($fichier)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 64 | + // est-ce bien une image svg ? |
|
| 65 | + if (str_contains($image, '<svg')) { |
|
| 66 | + return $image; |
|
| 67 | + } |
|
| 68 | + return false; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * @return array|bool |
| 75 | 75 | */ |
| 76 | 76 | function svg_lire_balise_svg($fichier) { |
| 77 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 82 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 83 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 84 | - |
|
| 85 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 86 | - if (!function_exists('extraire_attribut')) { |
|
| 87 | - include_spip('inc/filtres'); |
|
| 88 | - } |
|
| 89 | - $attributs = []; |
|
| 90 | - foreach ($matches[1] as $att) { |
|
| 91 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return [$balise_svg, $attributs]; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return false; |
|
| 77 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 82 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 83 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 84 | + |
|
| 85 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 86 | + if (!function_exists('extraire_attribut')) { |
|
| 87 | + include_spip('inc/filtres'); |
|
| 88 | + } |
|
| 89 | + $attributs = []; |
|
| 90 | + foreach ($matches[1] as $att) { |
|
| 91 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return [$balise_svg, $attributs]; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return false; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | function svg_lire_attributs($img) { |
| 107 | 107 | |
| 108 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 109 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 110 | - return $attributs; |
|
| 111 | - } |
|
| 108 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 109 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 110 | + return $attributs; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return false; |
|
| 113 | + return false; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | * @return bool|float|int |
| 121 | 121 | */ |
| 122 | 122 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 123 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 124 | - return match (strtolower($m[2])) { |
|
| 125 | - '%' => false, |
|
| 126 | - 'em' => round($m[1] * 16, $precision), |
|
| 127 | - 'ex' => round($m[1] * 16, $precision), |
|
| 128 | - 'pc' => round($m[1] * 16, $precision), |
|
| 129 | - 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 130 | - 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 131 | - 'in' => round($m[1] * 96, $precision), |
|
| 132 | - default => $m[1], |
|
| 133 | - }; |
|
| 134 | - } |
|
| 135 | - return false; |
|
| 123 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 124 | + return match (strtolower($m[2])) { |
|
| 125 | + '%' => false, |
|
| 126 | + 'em' => round($m[1] * 16, $precision), |
|
| 127 | + 'ex' => round($m[1] * 16, $precision), |
|
| 128 | + 'pc' => round($m[1] * 16, $precision), |
|
| 129 | + 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 130 | + 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 131 | + 'in' => round($m[1] * 96, $precision), |
|
| 132 | + default => $m[1], |
|
| 133 | + }; |
|
| 134 | + } |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 146 | - $new_balise_svg = '<svg'; |
|
| 147 | - foreach ($attributs as $k => $v) { |
|
| 148 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 149 | - } |
|
| 150 | - $new_balise_svg .= '>'; |
|
| 151 | - |
|
| 152 | - $p = strpos($svg, $old_balise_svg); |
|
| 153 | - return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 146 | + $new_balise_svg = '<svg'; |
|
| 147 | + foreach ($attributs as $k => $v) { |
|
| 148 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 149 | + } |
|
| 150 | + $new_balise_svg .= '>'; |
|
| 151 | + |
|
| 152 | + $p = strpos($svg, $old_balise_svg); |
|
| 153 | + return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 164 | 164 | |
| 165 | - if ($start === false || $start === 'end') { |
|
| 166 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 167 | - } |
|
| 168 | - else { |
|
| 169 | - $p = stripos($svg, '<svg'); |
|
| 170 | - $p = strpos($svg, '>', $p); |
|
| 171 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 172 | - } |
|
| 173 | - return $svg; |
|
| 165 | + if ($start === false || $start === 'end') { |
|
| 166 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 167 | + } |
|
| 168 | + else { |
|
| 169 | + $p = stripos($svg, '<svg'); |
|
| 170 | + $p = strpos($svg, '>', $p); |
|
| 171 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 172 | + } |
|
| 173 | + return $svg; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -183,12 +183,12 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 186 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 187 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 188 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 189 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 190 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 191 | - return svg_insert_shapes($svg, '</g>', false); |
|
| 186 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 187 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 188 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 189 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 190 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 191 | + return svg_insert_shapes($svg, '</g>', false); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,20 +199,20 @@ discard block |
||
| 199 | 199 | * @return bool|string |
| 200 | 200 | */ |
| 201 | 201 | function svg_redimensionner($img, $new_width, $new_height) { |
| 202 | - if ( |
|
| 203 | - ($svg = svg_charger($img)) |
|
| 204 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 205 | - ) { |
|
| 206 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 207 | - if (!isset($attributs['viewBox'])) { |
|
| 208 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 209 | - } |
|
| 210 | - $attributs['width'] = (string) $new_width; |
|
| 211 | - $attributs['height'] = (string) $new_height; |
|
| 212 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - return $img; |
|
| 202 | + if ( |
|
| 203 | + ($svg = svg_charger($img)) |
|
| 204 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 205 | + ) { |
|
| 206 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 207 | + if (!isset($attributs['viewBox'])) { |
|
| 208 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 209 | + } |
|
| 210 | + $attributs['width'] = (string) $new_width; |
|
| 211 | + $attributs['height'] = (string) $new_height; |
|
| 212 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return $img; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | * @return string |
| 222 | 222 | */ |
| 223 | 223 | function svg_couleur_to_hexa($couleur) { |
| 224 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 225 | - $c = explode(',', substr($couleur, 4)); |
|
| 226 | - $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 227 | - } |
|
| 228 | - else { |
|
| 229 | - $couleur = couleur_html_to_hex($couleur); |
|
| 230 | - } |
|
| 231 | - return '#' . ltrim($couleur, '#'); |
|
| 224 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 225 | + $c = explode(',', substr($couleur, 4)); |
|
| 226 | + $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 227 | + } |
|
| 228 | + else { |
|
| 229 | + $couleur = couleur_html_to_hex($couleur); |
|
| 230 | + } |
|
| 231 | + return '#' . ltrim($couleur, '#'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | * @return array |
| 238 | 238 | */ |
| 239 | 239 | function svg_couleur_to_rgb($couleur) { |
| 240 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 241 | - $c = explode(',', substr($couleur, 4)); |
|
| 242 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 243 | - } |
|
| 244 | - return _couleur_hex_to_dec($couleur); |
|
| 240 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 241 | + $c = explode(',', substr($couleur, 4)); |
|
| 242 | + return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 243 | + } |
|
| 244 | + return _couleur_hex_to_dec($couleur); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -251,80 +251,80 @@ discard block |
||
| 251 | 251 | * @return array |
| 252 | 252 | */ |
| 253 | 253 | function svg_getimagesize_from_attr($attributs) { |
| 254 | - $width = 350; // default width |
|
| 255 | - $height = 150; // default height |
|
| 256 | - |
|
| 257 | - $viewBox = "0 0 $width $height"; |
|
| 258 | - if (isset($attributs['viewBox'])) { |
|
| 259 | - $viewBox = $attributs['viewBox']; |
|
| 260 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 261 | - } |
|
| 262 | - // et on la convertit en px |
|
| 263 | - $viewBox = explode(' ', $viewBox); |
|
| 264 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 265 | - if (!$viewBox[2]) { |
|
| 266 | - $viewBox[2] = $width; |
|
| 267 | - } |
|
| 268 | - if (!$viewBox[3]) { |
|
| 269 | - $viewBox[3] = $height; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $coeff = 1; |
|
| 273 | - if ( |
|
| 274 | - isset($attributs['width']) |
|
| 275 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 276 | - ) { |
|
| 277 | - $width = $w; |
|
| 278 | - // si on avait pas de viewBox, la construire a partir de ce width |
|
| 279 | - if (empty($attributs['viewBox'])) { |
|
| 280 | - $viewBox[2] = $width; |
|
| 281 | - // si pas de height valide, on suppose l'image carree |
|
| 282 | - $viewBox[3] = $width; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - else { |
|
| 286 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 287 | - $width = $viewBox[2]; |
|
| 288 | - if ($width < 1) { |
|
| 289 | - $coeff = max($coeff, 1000); |
|
| 290 | - } |
|
| 291 | - elseif ($width < 10) { |
|
| 292 | - $coeff = max($coeff, 100); |
|
| 293 | - } |
|
| 294 | - elseif ($width < 100) { |
|
| 295 | - $coeff = max($coeff, 10); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if ( |
|
| 299 | - isset($attributs['height']) |
|
| 300 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 301 | - ) { |
|
| 302 | - $height = $h; |
|
| 303 | - // si on avait pas de viewBox, la construire a partir de ce height |
|
| 304 | - if (empty($attributs['viewBox'])) { |
|
| 305 | - $viewBox[3] = $height; |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - else { |
|
| 309 | - $height = $viewBox[3]; |
|
| 310 | - if ($height < 1) { |
|
| 311 | - $coeff = max($coeff, 1000); |
|
| 312 | - } |
|
| 313 | - elseif ($height < 10) { |
|
| 314 | - $coeff = max($coeff, 100); |
|
| 315 | - } |
|
| 316 | - elseif ($height < 100) { |
|
| 317 | - $coeff = max($coeff, 10); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - // arrondir le width et height en pixel in fine |
|
| 322 | - $width = round($coeff * $width); |
|
| 323 | - $height = round($coeff * $height); |
|
| 324 | - |
|
| 325 | - $viewBox = implode(' ', $viewBox); |
|
| 326 | - |
|
| 327 | - return [$width, $height, $viewBox]; |
|
| 254 | + $width = 350; // default width |
|
| 255 | + $height = 150; // default height |
|
| 256 | + |
|
| 257 | + $viewBox = "0 0 $width $height"; |
|
| 258 | + if (isset($attributs['viewBox'])) { |
|
| 259 | + $viewBox = $attributs['viewBox']; |
|
| 260 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 261 | + } |
|
| 262 | + // et on la convertit en px |
|
| 263 | + $viewBox = explode(' ', $viewBox); |
|
| 264 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 265 | + if (!$viewBox[2]) { |
|
| 266 | + $viewBox[2] = $width; |
|
| 267 | + } |
|
| 268 | + if (!$viewBox[3]) { |
|
| 269 | + $viewBox[3] = $height; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $coeff = 1; |
|
| 273 | + if ( |
|
| 274 | + isset($attributs['width']) |
|
| 275 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 276 | + ) { |
|
| 277 | + $width = $w; |
|
| 278 | + // si on avait pas de viewBox, la construire a partir de ce width |
|
| 279 | + if (empty($attributs['viewBox'])) { |
|
| 280 | + $viewBox[2] = $width; |
|
| 281 | + // si pas de height valide, on suppose l'image carree |
|
| 282 | + $viewBox[3] = $width; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + else { |
|
| 286 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 287 | + $width = $viewBox[2]; |
|
| 288 | + if ($width < 1) { |
|
| 289 | + $coeff = max($coeff, 1000); |
|
| 290 | + } |
|
| 291 | + elseif ($width < 10) { |
|
| 292 | + $coeff = max($coeff, 100); |
|
| 293 | + } |
|
| 294 | + elseif ($width < 100) { |
|
| 295 | + $coeff = max($coeff, 10); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if ( |
|
| 299 | + isset($attributs['height']) |
|
| 300 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 301 | + ) { |
|
| 302 | + $height = $h; |
|
| 303 | + // si on avait pas de viewBox, la construire a partir de ce height |
|
| 304 | + if (empty($attributs['viewBox'])) { |
|
| 305 | + $viewBox[3] = $height; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + else { |
|
| 309 | + $height = $viewBox[3]; |
|
| 310 | + if ($height < 1) { |
|
| 311 | + $coeff = max($coeff, 1000); |
|
| 312 | + } |
|
| 313 | + elseif ($height < 10) { |
|
| 314 | + $coeff = max($coeff, 100); |
|
| 315 | + } |
|
| 316 | + elseif ($height < 100) { |
|
| 317 | + $coeff = max($coeff, 10); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + // arrondir le width et height en pixel in fine |
|
| 322 | + $width = round($coeff * $width); |
|
| 323 | + $height = round($coeff * $height); |
|
| 324 | + |
|
| 325 | + $viewBox = implode(' ', $viewBox); |
|
| 326 | + |
|
| 327 | + return [$width, $height, $viewBox]; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -340,23 +340,23 @@ discard block |
||
| 340 | 340 | * @return string |
| 341 | 341 | */ |
| 342 | 342 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 343 | - if ( |
|
| 344 | - ($svg = svg_charger($img)) |
|
| 345 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 346 | - ) { |
|
| 347 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 348 | - |
|
| 349 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 350 | - |
|
| 351 | - if ($force_width_and_height) { |
|
| 352 | - $attributs['width'] = $width; |
|
| 353 | - $attributs['height'] = $height; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $attributs['viewBox'] = $viewBox; |
|
| 357 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 358 | - } |
|
| 359 | - return $img; |
|
| 343 | + if ( |
|
| 344 | + ($svg = svg_charger($img)) |
|
| 345 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 346 | + ) { |
|
| 347 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 348 | + |
|
| 349 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 350 | + |
|
| 351 | + if ($force_width_and_height) { |
|
| 352 | + $attributs['width'] = $width; |
|
| 353 | + $attributs['height'] = $height; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $attributs['viewBox'] = $viewBox; |
|
| 357 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 358 | + } |
|
| 359 | + return $img; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -365,13 +365,13 @@ discard block |
||
| 365 | 365 | * @return array|mixed |
| 366 | 366 | */ |
| 367 | 367 | function svg_extract_couleurs($img) { |
| 368 | - if ( |
|
| 369 | - ($svg = svg_charger($img)) |
|
| 370 | - && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 371 | - ) { |
|
| 372 | - return $matches[0]; |
|
| 373 | - } |
|
| 374 | - return []; |
|
| 368 | + if ( |
|
| 369 | + ($svg = svg_charger($img)) |
|
| 370 | + && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 371 | + ) { |
|
| 372 | + return $matches[0]; |
|
| 373 | + } |
|
| 374 | + return []; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -382,58 +382,58 @@ discard block |
||
| 382 | 382 | * @return bool|string |
| 383 | 383 | */ |
| 384 | 384 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 385 | - if ( |
|
| 386 | - ($svg = svg_force_viewBox_px($img)) |
|
| 387 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 388 | - ) { |
|
| 389 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 390 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 391 | - |
|
| 392 | - $viewport_w = $new_width; |
|
| 393 | - $viewport_h = $new_height; |
|
| 394 | - $viewport_ox = $offset_width; |
|
| 395 | - $viewport_oy = $offset_height; |
|
| 396 | - |
|
| 397 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 398 | - if ( |
|
| 399 | - isset($attributs['width']) |
|
| 400 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 401 | - && isset($attributs['height']) |
|
| 402 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 403 | - ) { |
|
| 404 | - $xscale = $viewBox[2] / $w; |
|
| 405 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 406 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 407 | - $yscale = $viewBox[3] / $h; |
|
| 408 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 409 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 413 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - // maintenant on redefinit la viewBox |
|
| 417 | - $viewBox[0] += $viewport_ox; |
|
| 418 | - $viewBox[1] += $viewport_oy; |
|
| 419 | - $viewBox[2] = $viewport_w; |
|
| 420 | - $viewBox[3] = $viewport_h; |
|
| 421 | - |
|
| 422 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 423 | - $attributs['width'] = (string) $new_width; |
|
| 424 | - $attributs['height'] = (string) $new_height; |
|
| 425 | - |
|
| 426 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 427 | - |
|
| 428 | - // ajouter un background |
|
| 429 | - if ($background_color && $background_color !== 'transparent') { |
|
| 430 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return $svg; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $img; |
|
| 385 | + if ( |
|
| 386 | + ($svg = svg_force_viewBox_px($img)) |
|
| 387 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 388 | + ) { |
|
| 389 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 390 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 391 | + |
|
| 392 | + $viewport_w = $new_width; |
|
| 393 | + $viewport_h = $new_height; |
|
| 394 | + $viewport_ox = $offset_width; |
|
| 395 | + $viewport_oy = $offset_height; |
|
| 396 | + |
|
| 397 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 398 | + if ( |
|
| 399 | + isset($attributs['width']) |
|
| 400 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 401 | + && isset($attributs['height']) |
|
| 402 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 403 | + ) { |
|
| 404 | + $xscale = $viewBox[2] / $w; |
|
| 405 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 406 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 407 | + $yscale = $viewBox[3] / $h; |
|
| 408 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 409 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 413 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + // maintenant on redefinit la viewBox |
|
| 417 | + $viewBox[0] += $viewport_ox; |
|
| 418 | + $viewBox[1] += $viewport_oy; |
|
| 419 | + $viewBox[2] = $viewport_w; |
|
| 420 | + $viewBox[3] = $viewport_h; |
|
| 421 | + |
|
| 422 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 423 | + $attributs['width'] = (string) $new_width; |
|
| 424 | + $attributs['height'] = (string) $new_height; |
|
| 425 | + |
|
| 426 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 427 | + |
|
| 428 | + // ajouter un background |
|
| 429 | + if ($background_color && $background_color !== 'transparent') { |
|
| 430 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return $svg; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $img; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -443,26 +443,26 @@ discard block |
||
| 443 | 443 | * @return bool|string |
| 444 | 444 | */ |
| 445 | 445 | function svg_ajouter_background($img, $background_color) { |
| 446 | - if ( |
|
| 447 | - ($svg = svg_charger($img)) |
|
| 448 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 449 | - ) { |
|
| 450 | - if ($background_color && $background_color !== 'transparent') { |
|
| 451 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 452 | - |
|
| 453 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 454 | - if (isset($attributs['viewBox'])) { |
|
| 455 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 456 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 457 | - } |
|
| 458 | - else { |
|
| 459 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 460 | - } |
|
| 461 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 462 | - } |
|
| 463 | - return $svg; |
|
| 464 | - } |
|
| 465 | - return $img; |
|
| 446 | + if ( |
|
| 447 | + ($svg = svg_charger($img)) |
|
| 448 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 449 | + ) { |
|
| 450 | + if ($background_color && $background_color !== 'transparent') { |
|
| 451 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 452 | + |
|
| 453 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 454 | + if (isset($attributs['viewBox'])) { |
|
| 455 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 456 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 457 | + } |
|
| 458 | + else { |
|
| 459 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 460 | + } |
|
| 461 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 462 | + } |
|
| 463 | + return $svg; |
|
| 464 | + } |
|
| 465 | + return $img; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -473,26 +473,26 @@ discard block |
||
| 473 | 473 | * @return bool|string |
| 474 | 474 | */ |
| 475 | 475 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 476 | - if ( |
|
| 477 | - ($svg = svg_charger($img)) |
|
| 478 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 479 | - ) { |
|
| 480 | - if ($background_color && $background_color !== 'transparent') { |
|
| 481 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 482 | - |
|
| 483 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 484 | - if (isset($attributs['viewBox'])) { |
|
| 485 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 486 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | - } |
|
| 488 | - else { |
|
| 489 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 490 | - } |
|
| 491 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 492 | - } |
|
| 493 | - return $svg; |
|
| 494 | - } |
|
| 495 | - return $img; |
|
| 476 | + if ( |
|
| 477 | + ($svg = svg_charger($img)) |
|
| 478 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 479 | + ) { |
|
| 480 | + if ($background_color && $background_color !== 'transparent') { |
|
| 481 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 482 | + |
|
| 483 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 484 | + if (isset($attributs['viewBox'])) { |
|
| 485 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 486 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | + } |
|
| 488 | + else { |
|
| 489 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 490 | + } |
|
| 491 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 492 | + } |
|
| 493 | + return $svg; |
|
| 494 | + } |
|
| 495 | + return $img; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -503,27 +503,27 @@ discard block |
||
| 503 | 503 | * @return bool|string |
| 504 | 504 | */ |
| 505 | 505 | function svg_transformer($img, $attributs) { |
| 506 | - if ( |
|
| 507 | - ($svg = svg_charger($img)) |
|
| 508 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 509 | - ) { |
|
| 510 | - if ($attributs) { |
|
| 511 | - [$balise_svg, ] = $svg_infos; |
|
| 512 | - $g = '<g'; |
|
| 513 | - foreach ($attributs as $k => $v) { |
|
| 514 | - if (strlen($v)) { |
|
| 515 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - if (strlen($g) > 2) { |
|
| 519 | - $g .= '>'; |
|
| 520 | - $svg = svg_insert_shapes($svg, $g); |
|
| 521 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - return $svg; |
|
| 525 | - } |
|
| 526 | - return $img; |
|
| 506 | + if ( |
|
| 507 | + ($svg = svg_charger($img)) |
|
| 508 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 509 | + ) { |
|
| 510 | + if ($attributs) { |
|
| 511 | + [$balise_svg, ] = $svg_infos; |
|
| 512 | + $g = '<g'; |
|
| 513 | + foreach ($attributs as $k => $v) { |
|
| 514 | + if (strlen($v)) { |
|
| 515 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + if (strlen($g) > 2) { |
|
| 519 | + $g .= '>'; |
|
| 520 | + $svg = svg_insert_shapes($svg, $g); |
|
| 521 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + return $svg; |
|
| 525 | + } |
|
| 526 | + return $img; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -534,21 +534,21 @@ discard block |
||
| 534 | 534 | * @return bool|string |
| 535 | 535 | */ |
| 536 | 536 | function svg_apply_filter($img, $filter_def) { |
| 537 | - if ( |
|
| 538 | - ($svg = svg_charger($img)) |
|
| 539 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 540 | - ) { |
|
| 541 | - if ($filter_def) { |
|
| 542 | - [$balise_svg, ] = $svg_infos; |
|
| 543 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 544 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 545 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 546 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 547 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 548 | - } |
|
| 549 | - return $svg; |
|
| 550 | - } |
|
| 551 | - return $img; |
|
| 537 | + if ( |
|
| 538 | + ($svg = svg_charger($img)) |
|
| 539 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 540 | + ) { |
|
| 541 | + if ($filter_def) { |
|
| 542 | + [$balise_svg, ] = $svg_infos; |
|
| 543 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 544 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 545 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 546 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 547 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 548 | + } |
|
| 549 | + return $svg; |
|
| 550 | + } |
|
| 551 | + return $img; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -558,8 +558,8 @@ discard block |
||
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | 560 | function svg_filter_blur($img, $blur_width) { |
| 561 | - $blur_width = (int) $blur_width; |
|
| 562 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 561 | + $blur_width = (int) $blur_width; |
|
| 562 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -569,10 +569,10 @@ discard block |
||
| 569 | 569 | * @return bool|string |
| 570 | 570 | */ |
| 571 | 571 | function svg_filter_grayscale($img, $intensity) { |
| 572 | - $value = round(1.0 - $intensity, 2); |
|
| 573 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 574 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 575 | - return svg_apply_filter($img, $filter); |
|
| 572 | + $value = round(1.0 - $intensity, 2); |
|
| 573 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 574 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 575 | + return svg_apply_filter($img, $filter); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -582,8 +582,8 @@ discard block |
||
| 582 | 582 | * @return bool|string |
| 583 | 583 | */ |
| 584 | 584 | function svg_filter_sepia($img, $intensity) { |
| 585 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 586 | - return svg_apply_filter($img, $filter); |
|
| 585 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 586 | + return svg_apply_filter($img, $filter); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -593,30 +593,30 @@ discard block |
||
| 593 | 593 | * @return bool|string |
| 594 | 594 | */ |
| 595 | 595 | function svg_flip($img, $HorV) { |
| 596 | - if ( |
|
| 597 | - ($svg = svg_force_viewBox_px($img)) |
|
| 598 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 599 | - ) { |
|
| 600 | - [$balise_svg, $atts] = $svg_infos; |
|
| 601 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 602 | - |
|
| 603 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 604 | - $transform = 'scale(-1,1)'; |
|
| 605 | - |
|
| 606 | - $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 607 | - $mx = -$x; |
|
| 608 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 609 | - } |
|
| 610 | - else { |
|
| 611 | - $transform = 'scale(1,-1)'; |
|
| 612 | - |
|
| 613 | - $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 614 | - $my = -$y; |
|
| 615 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 616 | - } |
|
| 617 | - return svg_transformer($svg, ['transform' => $transform]); |
|
| 618 | - } |
|
| 619 | - return $img; |
|
| 596 | + if ( |
|
| 597 | + ($svg = svg_force_viewBox_px($img)) |
|
| 598 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 599 | + ) { |
|
| 600 | + [$balise_svg, $atts] = $svg_infos; |
|
| 601 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 602 | + |
|
| 603 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 604 | + $transform = 'scale(-1,1)'; |
|
| 605 | + |
|
| 606 | + $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 607 | + $mx = -$x; |
|
| 608 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 609 | + } |
|
| 610 | + else { |
|
| 611 | + $transform = 'scale(1,-1)'; |
|
| 612 | + |
|
| 613 | + $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 614 | + $my = -$y; |
|
| 615 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 616 | + } |
|
| 617 | + return svg_transformer($svg, ['transform' => $transform]); |
|
| 618 | + } |
|
| 619 | + return $img; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -630,19 +630,19 @@ discard block |
||
| 630 | 630 | * @return bool|string |
| 631 | 631 | */ |
| 632 | 632 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 633 | - if ( |
|
| 634 | - ($svg = svg_force_viewBox_px($img)) |
|
| 635 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 636 | - ) { |
|
| 637 | - [$balise_svg, $atts] = $svg_infos; |
|
| 638 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 639 | - |
|
| 640 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 641 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 642 | - |
|
| 643 | - return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 644 | - } |
|
| 645 | - return $img; |
|
| 633 | + if ( |
|
| 634 | + ($svg = svg_force_viewBox_px($img)) |
|
| 635 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 636 | + ) { |
|
| 637 | + [$balise_svg, $atts] = $svg_infos; |
|
| 638 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 639 | + |
|
| 640 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 641 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 642 | + |
|
| 643 | + return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 644 | + } |
|
| 645 | + return $img; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
@@ -654,40 +654,40 @@ discard block |
||
| 654 | 654 | * @return bool|mixed|string |
| 655 | 655 | */ |
| 656 | 656 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 657 | - if ( |
|
| 658 | - ($svg = svg_force_viewBox_px($img)) |
|
| 659 | - && ($colors = svg_extract_couleurs($svg)) |
|
| 660 | - ) { |
|
| 661 | - $colors = array_unique($colors); |
|
| 662 | - |
|
| 663 | - $short = []; |
|
| 664 | - $long = []; |
|
| 665 | - while (count($colors)) { |
|
| 666 | - $c = array_shift($colors); |
|
| 667 | - if (strlen($c) == 4) { |
|
| 668 | - $short[] = $c; |
|
| 669 | - } |
|
| 670 | - else { |
|
| 671 | - $long[] = $c; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - $colors = [...$long, ...$short]; |
|
| 676 | - $new_colors = []; |
|
| 677 | - $colors = array_flip($colors); |
|
| 678 | - foreach ($colors as $c => $k) { |
|
| 679 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - foreach ($colors as $original => $replace) { |
|
| 684 | - $new = svg_couleur_to_hexa($original); |
|
| 685 | - $new_colors[$replace] = $callback_filter($new); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 689 | - |
|
| 690 | - return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 691 | - } |
|
| 692 | - return $img; |
|
| 657 | + if ( |
|
| 658 | + ($svg = svg_force_viewBox_px($img)) |
|
| 659 | + && ($colors = svg_extract_couleurs($svg)) |
|
| 660 | + ) { |
|
| 661 | + $colors = array_unique($colors); |
|
| 662 | + |
|
| 663 | + $short = []; |
|
| 664 | + $long = []; |
|
| 665 | + while (count($colors)) { |
|
| 666 | + $c = array_shift($colors); |
|
| 667 | + if (strlen($c) == 4) { |
|
| 668 | + $short[] = $c; |
|
| 669 | + } |
|
| 670 | + else { |
|
| 671 | + $long[] = $c; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + $colors = [...$long, ...$short]; |
|
| 676 | + $new_colors = []; |
|
| 677 | + $colors = array_flip($colors); |
|
| 678 | + foreach ($colors as $c => $k) { |
|
| 679 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + foreach ($colors as $original => $replace) { |
|
| 684 | + $new = svg_couleur_to_hexa($original); |
|
| 685 | + $new_colors[$replace] = $callback_filter($new); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 689 | + |
|
| 690 | + return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 691 | + } |
|
| 692 | + return $img; |
|
| 693 | 693 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | return $fichier; |
| 56 | 56 | } |
| 57 | 57 | if (!file_exists($fichier)) { |
| 58 | - $fichier = supprimer_timestamp($fichier); |
|
| 58 | + $fichier = supprimer_timestamp($fichier); |
|
| 59 | 59 | if (!file_exists($fichier)) { |
| 60 | 60 | return false; |
| 61 | 61 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 146 | 146 | $new_balise_svg = '<svg'; |
| 147 | 147 | foreach ($attributs as $k => $v) { |
| 148 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 148 | + $new_balise_svg .= " $k=\"".entites_html($v).'"'; |
|
| 149 | 149 | } |
| 150 | 150 | $new_balise_svg .= '>'; |
| 151 | 151 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 164 | 164 | |
| 165 | 165 | if ($start === false || $start === 'end') { |
| 166 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 166 | + $svg = str_replace('</svg>', $shapes.'</svg>', $svg); |
|
| 167 | 167 | } |
| 168 | 168 | else { |
| 169 | 169 | $p = stripos($svg, '<svg'); |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 186 | 186 | $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
| 187 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 187 | + $id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8); |
|
| 188 | 188 | $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
| 189 | 189 | $g = "<g clip-path=\"url(#$id)\">"; |
| 190 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 190 | + $svg = svg_insert_shapes($svg, $clippath.$g); |
|
| 191 | 191 | return svg_insert_shapes($svg, '</g>', false); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | ) { |
| 206 | 206 | [$balise_svg, $attributs] = $svg_infos; |
| 207 | 207 | if (!isset($attributs['viewBox'])) { |
| 208 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 208 | + $attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height']; |
|
| 209 | 209 | } |
| 210 | 210 | $attributs['width'] = (string) $new_width; |
| 211 | 211 | $attributs['height'] = (string) $new_height; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | else { |
| 229 | 229 | $couleur = couleur_html_to_hex($couleur); |
| 230 | 230 | } |
| 231 | - return '#' . ltrim($couleur, '#'); |
|
| 231 | + return '#'.ltrim($couleur, '#'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | function svg_couleur_to_rgb($couleur) { |
| 240 | 240 | if (str_starts_with($couleur, 'rgb(')) { |
| 241 | 241 | $c = explode(',', substr($couleur, 4)); |
| 242 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 242 | + return ['red' => (int) $c[0], 'green' => (int) $c[1], 'blue' => (int) $c[2]]; |
|
| 243 | 243 | } |
| 244 | 244 | return _couleur_hex_to_dec($couleur); |
| 245 | 245 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | $background_color = svg_couleur_to_hexa($background_color); |
| 454 | 454 | if (isset($attributs['viewBox'])) { |
| 455 | 455 | $viewBox = explode(' ', $attributs['viewBox']); |
| 456 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 456 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>"; |
|
| 457 | 457 | } |
| 458 | 458 | else { |
| 459 | 459 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | $background_color = svg_couleur_to_hexa($background_color); |
| 484 | 484 | if (isset($attributs['viewBox'])) { |
| 485 | 485 | $viewBox = explode(' ', $attributs['viewBox']); |
| 486 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 486 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | 487 | } |
| 488 | 488 | else { |
| 489 | 489 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $g = '<g'; |
| 513 | 513 | foreach ($attributs as $k => $v) { |
| 514 | 514 | if (strlen($v)) { |
| 515 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 515 | + $g .= " $k=\"".attribut_html($v).'"'; |
|
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | if (strlen($g) > 2) { |
@@ -540,10 +540,10 @@ discard block |
||
| 540 | 540 | ) { |
| 541 | 541 | if ($filter_def) { |
| 542 | 542 | [$balise_svg, ] = $svg_infos; |
| 543 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 543 | + $filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8); |
|
| 544 | 544 | $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
| 545 | 545 | $g = "<g filter=\"url(#$filter_id)\">"; |
| 546 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 546 | + $svg = svg_insert_shapes($svg, $filter.$g); |
|
| 547 | 547 | $svg = svg_insert_shapes($svg, '</g>', false); |
| 548 | 548 | } |
| 549 | 549 | return $svg; |
@@ -164,8 +164,7 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | if ($start === false || $start === 'end') { |
| 166 | 166 | $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
| 167 | - } |
|
| 168 | - else { |
|
| 167 | + } else { |
|
| 169 | 168 | $p = stripos($svg, '<svg'); |
| 170 | 169 | $p = strpos($svg, '>', $p); |
| 171 | 170 | $svg = substr_replace($svg, $shapes, $p + 1, 0); |
@@ -224,8 +223,7 @@ discard block |
||
| 224 | 223 | if (str_starts_with($couleur, 'rgb(')) { |
| 225 | 224 | $c = explode(',', substr($couleur, 4)); |
| 226 | 225 | $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
| 227 | - } |
|
| 228 | - else { |
|
| 226 | + } else { |
|
| 229 | 227 | $couleur = couleur_html_to_hex($couleur); |
| 230 | 228 | } |
| 231 | 229 | return '#' . ltrim($couleur, '#'); |
@@ -281,17 +279,14 @@ discard block |
||
| 281 | 279 | // si pas de height valide, on suppose l'image carree |
| 282 | 280 | $viewBox[3] = $width; |
| 283 | 281 | } |
| 284 | - } |
|
| 285 | - else { |
|
| 282 | + } else { |
|
| 286 | 283 | // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
| 287 | 284 | $width = $viewBox[2]; |
| 288 | 285 | if ($width < 1) { |
| 289 | 286 | $coeff = max($coeff, 1000); |
| 290 | - } |
|
| 291 | - elseif ($width < 10) { |
|
| 287 | + } elseif ($width < 10) { |
|
| 292 | 288 | $coeff = max($coeff, 100); |
| 293 | - } |
|
| 294 | - elseif ($width < 100) { |
|
| 289 | + } elseif ($width < 100) { |
|
| 295 | 290 | $coeff = max($coeff, 10); |
| 296 | 291 | } |
| 297 | 292 | } |
@@ -304,16 +299,13 @@ discard block |
||
| 304 | 299 | if (empty($attributs['viewBox'])) { |
| 305 | 300 | $viewBox[3] = $height; |
| 306 | 301 | } |
| 307 | - } |
|
| 308 | - else { |
|
| 302 | + } else { |
|
| 309 | 303 | $height = $viewBox[3]; |
| 310 | 304 | if ($height < 1) { |
| 311 | 305 | $coeff = max($coeff, 1000); |
| 312 | - } |
|
| 313 | - elseif ($height < 10) { |
|
| 306 | + } elseif ($height < 10) { |
|
| 314 | 307 | $coeff = max($coeff, 100); |
| 315 | - } |
|
| 316 | - elseif ($height < 100) { |
|
| 308 | + } elseif ($height < 100) { |
|
| 317 | 309 | $coeff = max($coeff, 10); |
| 318 | 310 | } |
| 319 | 311 | } |
@@ -454,8 +446,7 @@ discard block |
||
| 454 | 446 | if (isset($attributs['viewBox'])) { |
| 455 | 447 | $viewBox = explode(' ', $attributs['viewBox']); |
| 456 | 448 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
| 457 | - } |
|
| 458 | - else { |
|
| 449 | + } else { |
|
| 459 | 450 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 460 | 451 | } |
| 461 | 452 | $svg = svg_insert_shapes($svg, $rect); |
@@ -484,8 +475,7 @@ discard block |
||
| 484 | 475 | if (isset($attributs['viewBox'])) { |
| 485 | 476 | $viewBox = explode(' ', $attributs['viewBox']); |
| 486 | 477 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
| 487 | - } |
|
| 488 | - else { |
|
| 478 | + } else { |
|
| 489 | 479 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 490 | 480 | } |
| 491 | 481 | $svg = svg_insert_shapes($svg, $rect, false); |
@@ -606,8 +596,7 @@ discard block |
||
| 606 | 596 | $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
| 607 | 597 | $mx = -$x; |
| 608 | 598 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 609 | - } |
|
| 610 | - else { |
|
| 599 | + } else { |
|
| 611 | 600 | $transform = 'scale(1,-1)'; |
| 612 | 601 | |
| 613 | 602 | $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
@@ -666,8 +655,7 @@ discard block |
||
| 666 | 655 | $c = array_shift($colors); |
| 667 | 656 | if (strlen($c) == 4) { |
| 668 | 657 | $short[] = $c; |
| 669 | - } |
|
| 670 | - else { |
|
| 658 | + } else { |
|
| 671 | 659 | $long[] = $c; |
| 672 | 660 | } |
| 673 | 661 | } |
@@ -15,265 +15,265 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées |
| 16 | 16 | **/ |
| 17 | 17 | abstract class AbstractPage { |
| 18 | - public const TYPE = ''; |
|
| 18 | + public const TYPE = ''; |
|
| 19 | 19 | |
| 20 | - public function __construct() { |
|
| 21 | - include_fichiers_fonctions(); |
|
| 22 | - include_spip('inc/headers'); |
|
| 23 | - include_spip('inc/texte'); //inclue inc/lang et inc/filtres |
|
| 24 | - include_spip('inc/filtres_images_mini'); |
|
| 25 | - } |
|
| 20 | + public function __construct() { |
|
| 21 | + include_fichiers_fonctions(); |
|
| 22 | + include_spip('inc/headers'); |
|
| 23 | + include_spip('inc/texte'); //inclue inc/lang et inc/filtres |
|
| 24 | + include_spip('inc/filtres_images_mini'); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Retourne le début d'une page HTML minimale |
|
| 29 | - * |
|
| 30 | - * Le contenu de CSS minimales (reset.css, clear.css, minipage.css) est inséré |
|
| 31 | - * dans une balise script inline (compactée si possible) |
|
| 32 | - * |
|
| 33 | - * @param array $options |
|
| 34 | - * string $lang : forcer la langue utilisateur |
|
| 35 | - * string $page_title : titre éventuel de la page (nom du site par défaut) |
|
| 36 | - * string $couleur_fond : pour la couleur dominante de la page (par défaut on reprend le réglage de la page de login) |
|
| 37 | - * bool $all_inline : inliner les CSS pour envoyer toute la page en 1 hit |
|
| 38 | - * string $doctype |
|
| 39 | - * string $charset |
|
| 40 | - * string $onload |
|
| 41 | - * array $css_files : ajouter des fichiers css |
|
| 42 | - * string $css : ajouter du CSS inline |
|
| 43 | - * string $head : contenu à ajouter à la fin <head> (pour inclusion de JS ou JS inline...) |
|
| 44 | - * @return string |
|
| 45 | - * Code HTML |
|
| 46 | - * |
|
| 47 | - * @uses html_lang_attributes() |
|
| 48 | - * @uses minifier() si le plugin compresseur est présent |
|
| 49 | - * @uses url_absolue_css() |
|
| 50 | - * |
|
| 51 | - * @uses utiliser_langue_visiteur() |
|
| 52 | - * @uses http_no_cache() |
|
| 53 | - */ |
|
| 54 | - protected function ouvreBody($options = []) { |
|
| 55 | - $h = null; |
|
| 56 | - $s = null; |
|
| 57 | - $l = null; |
|
| 58 | - if (empty($options['lang'])) { |
|
| 59 | - // on se limite sur une langue de $GLOBALS['meta']['langues_multilingue'] car on est dans le public |
|
| 60 | - utiliser_langue_visiteur($GLOBALS['meta']['langues_multilingue'] ?? null); |
|
| 61 | - } else { |
|
| 62 | - changer_langue($options['lang']); |
|
| 63 | - } |
|
| 64 | - http_no_cache(); |
|
| 27 | + /** |
|
| 28 | + * Retourne le début d'une page HTML minimale |
|
| 29 | + * |
|
| 30 | + * Le contenu de CSS minimales (reset.css, clear.css, minipage.css) est inséré |
|
| 31 | + * dans une balise script inline (compactée si possible) |
|
| 32 | + * |
|
| 33 | + * @param array $options |
|
| 34 | + * string $lang : forcer la langue utilisateur |
|
| 35 | + * string $page_title : titre éventuel de la page (nom du site par défaut) |
|
| 36 | + * string $couleur_fond : pour la couleur dominante de la page (par défaut on reprend le réglage de la page de login) |
|
| 37 | + * bool $all_inline : inliner les CSS pour envoyer toute la page en 1 hit |
|
| 38 | + * string $doctype |
|
| 39 | + * string $charset |
|
| 40 | + * string $onload |
|
| 41 | + * array $css_files : ajouter des fichiers css |
|
| 42 | + * string $css : ajouter du CSS inline |
|
| 43 | + * string $head : contenu à ajouter à la fin <head> (pour inclusion de JS ou JS inline...) |
|
| 44 | + * @return string |
|
| 45 | + * Code HTML |
|
| 46 | + * |
|
| 47 | + * @uses html_lang_attributes() |
|
| 48 | + * @uses minifier() si le plugin compresseur est présent |
|
| 49 | + * @uses url_absolue_css() |
|
| 50 | + * |
|
| 51 | + * @uses utiliser_langue_visiteur() |
|
| 52 | + * @uses http_no_cache() |
|
| 53 | + */ |
|
| 54 | + protected function ouvreBody($options = []) { |
|
| 55 | + $h = null; |
|
| 56 | + $s = null; |
|
| 57 | + $l = null; |
|
| 58 | + if (empty($options['lang'])) { |
|
| 59 | + // on se limite sur une langue de $GLOBALS['meta']['langues_multilingue'] car on est dans le public |
|
| 60 | + utiliser_langue_visiteur($GLOBALS['meta']['langues_multilingue'] ?? null); |
|
| 61 | + } else { |
|
| 62 | + changer_langue($options['lang']); |
|
| 63 | + } |
|
| 64 | + http_no_cache(); |
|
| 65 | 65 | |
| 66 | - $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']); |
|
| 67 | - $doctype = ($options['doctype'] ?? '<!DOCTYPE html>'); |
|
| 68 | - $doctype = trim($doctype) . "\n"; |
|
| 69 | - $charset = ($options['charset'] ?? 'utf-8'); |
|
| 70 | - $all_inline = ($options['all_inline'] ?? true); |
|
| 71 | - $onLoad = ($options['onLoad'] ?? ''); |
|
| 72 | - if ($onLoad) { |
|
| 73 | - $onLoad = ' onload="' . attribut_html($onLoad) . '"'; |
|
| 74 | - } |
|
| 66 | + $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']); |
|
| 67 | + $doctype = ($options['doctype'] ?? '<!DOCTYPE html>'); |
|
| 68 | + $doctype = trim($doctype) . "\n"; |
|
| 69 | + $charset = ($options['charset'] ?? 'utf-8'); |
|
| 70 | + $all_inline = ($options['all_inline'] ?? true); |
|
| 71 | + $onLoad = ($options['onLoad'] ?? ''); |
|
| 72 | + if ($onLoad) { |
|
| 73 | + $onLoad = ' onload="' . attribut_html($onLoad) . '"'; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - # envoyer le charset |
|
| 77 | - if (!headers_sent()) { |
|
| 78 | - header('Content-Type: text/html; charset=' . $charset); |
|
| 79 | - } |
|
| 76 | + # envoyer le charset |
|
| 77 | + if (!headers_sent()) { |
|
| 78 | + header('Content-Type: text/html; charset=' . $charset); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $css = ''; |
|
| 81 | + $css = ''; |
|
| 82 | 82 | |
| 83 | - if (function_exists('couleur_hex_to_hsl')) { |
|
| 84 | - $couleur_fond = empty($options['couleur_fond']) |
|
| 85 | - ? lire_config('couleur_login', '#db1762') |
|
| 86 | - : $options['couleur_fond']; |
|
| 87 | - $h = couleur_hex_to_hsl($couleur_fond, 'h'); |
|
| 88 | - $s = couleur_hex_to_hsl($couleur_fond, 's'); |
|
| 89 | - $l = couleur_hex_to_hsl($couleur_fond, 'l'); |
|
| 90 | - } |
|
| 83 | + if (function_exists('couleur_hex_to_hsl')) { |
|
| 84 | + $couleur_fond = empty($options['couleur_fond']) |
|
| 85 | + ? lire_config('couleur_login', '#db1762') |
|
| 86 | + : $options['couleur_fond']; |
|
| 87 | + $h = couleur_hex_to_hsl($couleur_fond, 'h'); |
|
| 88 | + $s = couleur_hex_to_hsl($couleur_fond, 's'); |
|
| 89 | + $l = couleur_hex_to_hsl($couleur_fond, 'l'); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $inline = ':root {' |
|
| 93 | - . "--minipage-color-theme--h: $h;" |
|
| 94 | - . "--minipage-color-theme--s: $s;" |
|
| 95 | - . "--minipage-color-theme--l: $l;}"; |
|
| 96 | - $vars = file_get_contents(find_in_theme('minipage.vars.css')); |
|
| 97 | - $inline .= "\n" . trim($vars); |
|
| 98 | - if (function_exists('minifier')) { |
|
| 99 | - $inline = minifier($inline, 'css'); |
|
| 100 | - } |
|
| 101 | - $files = [ |
|
| 102 | - find_in_theme('reset.css'), |
|
| 103 | - find_in_theme('clear.css'), |
|
| 104 | - find_in_theme('minipage.css'), |
|
| 105 | - ]; |
|
| 106 | - if (!empty($options['css_files'])) { |
|
| 107 | - foreach ($options['css_files'] as $css_file) { |
|
| 108 | - $files[] = $css_file; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - if ($all_inline) { |
|
| 112 | - // inliner les CSS (optimisation de la page minipage qui passe en un seul hit a la demande) |
|
| 113 | - foreach ($files as $name) { |
|
| 114 | - $file = direction_css($name); |
|
| 115 | - if (function_exists('minifier')) { |
|
| 116 | - $file = minifier($file); |
|
| 117 | - } else { |
|
| 118 | - $file = url_absolue_css($file); // precaution |
|
| 119 | - } |
|
| 120 | - $css .= file_get_contents($file); |
|
| 121 | - } |
|
| 122 | - $css = "$inline\n$css"; |
|
| 123 | - if (!empty($options['css'])) { |
|
| 124 | - $css .= "\n" . $options['css']; |
|
| 125 | - } |
|
| 126 | - $css = "<style type='text/css'>$css</style>"; |
|
| 127 | - } else { |
|
| 128 | - $css = "<style type='text/css'>$inline</style>"; |
|
| 129 | - foreach ($files as $name) { |
|
| 130 | - $file = timestamp(direction_css($name)); |
|
| 131 | - $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n"; |
|
| 132 | - } |
|
| 133 | - if (!empty($options['css'])) { |
|
| 134 | - $css .= "<style type='text/css'>" . $options['css'] . '</style>'; |
|
| 135 | - } |
|
| 136 | - } |
|
| 92 | + $inline = ':root {' |
|
| 93 | + . "--minipage-color-theme--h: $h;" |
|
| 94 | + . "--minipage-color-theme--s: $s;" |
|
| 95 | + . "--minipage-color-theme--l: $l;}"; |
|
| 96 | + $vars = file_get_contents(find_in_theme('minipage.vars.css')); |
|
| 97 | + $inline .= "\n" . trim($vars); |
|
| 98 | + if (function_exists('minifier')) { |
|
| 99 | + $inline = minifier($inline, 'css'); |
|
| 100 | + } |
|
| 101 | + $files = [ |
|
| 102 | + find_in_theme('reset.css'), |
|
| 103 | + find_in_theme('clear.css'), |
|
| 104 | + find_in_theme('minipage.css'), |
|
| 105 | + ]; |
|
| 106 | + if (!empty($options['css_files'])) { |
|
| 107 | + foreach ($options['css_files'] as $css_file) { |
|
| 108 | + $files[] = $css_file; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + if ($all_inline) { |
|
| 112 | + // inliner les CSS (optimisation de la page minipage qui passe en un seul hit a la demande) |
|
| 113 | + foreach ($files as $name) { |
|
| 114 | + $file = direction_css($name); |
|
| 115 | + if (function_exists('minifier')) { |
|
| 116 | + $file = minifier($file); |
|
| 117 | + } else { |
|
| 118 | + $file = url_absolue_css($file); // precaution |
|
| 119 | + } |
|
| 120 | + $css .= file_get_contents($file); |
|
| 121 | + } |
|
| 122 | + $css = "$inline\n$css"; |
|
| 123 | + if (!empty($options['css'])) { |
|
| 124 | + $css .= "\n" . $options['css']; |
|
| 125 | + } |
|
| 126 | + $css = "<style type='text/css'>$css</style>"; |
|
| 127 | + } else { |
|
| 128 | + $css = "<style type='text/css'>$inline</style>"; |
|
| 129 | + foreach ($files as $name) { |
|
| 130 | + $file = timestamp(direction_css($name)); |
|
| 131 | + $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n"; |
|
| 132 | + } |
|
| 133 | + if (!empty($options['css'])) { |
|
| 134 | + $css .= "<style type='text/css'>" . $options['css'] . '</style>'; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - return $doctype . |
|
| 139 | - html_lang_attributes() . |
|
| 140 | - "<head>\n" . |
|
| 141 | - '<title>' . |
|
| 142 | - textebrut($page_title) . |
|
| 143 | - "</title>\n" . |
|
| 144 | - "<meta name=\"viewport\" content=\"width=device-width\" />\n" . |
|
| 145 | - $css . |
|
| 146 | - (empty($options['head']) ? '' : $options['head']) . |
|
| 147 | - "</head>\n" . |
|
| 148 | - "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" . |
|
| 149 | - "\t<div class=\"minipage-bloc\">\n"; |
|
| 150 | - } |
|
| 138 | + return $doctype . |
|
| 139 | + html_lang_attributes() . |
|
| 140 | + "<head>\n" . |
|
| 141 | + '<title>' . |
|
| 142 | + textebrut($page_title) . |
|
| 143 | + "</title>\n" . |
|
| 144 | + "<meta name=\"viewport\" content=\"width=device-width\" />\n" . |
|
| 145 | + $css . |
|
| 146 | + (empty($options['head']) ? '' : $options['head']) . |
|
| 147 | + "</head>\n" . |
|
| 148 | + "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" . |
|
| 149 | + "\t<div class=\"minipage-bloc\">\n"; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Ouvre le corps : affiche le header avec un éventuel titre + ouvre le div corps |
|
| 154 | - * @param $options |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - protected function ouvreCorps($options = []) { |
|
| 158 | - $url_site = url_de_base(); |
|
| 159 | - $header = "<header>\n" . |
|
| 160 | - '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n"; |
|
| 152 | + /** |
|
| 153 | + * Ouvre le corps : affiche le header avec un éventuel titre + ouvre le div corps |
|
| 154 | + * @param $options |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + protected function ouvreCorps($options = []) { |
|
| 158 | + $url_site = url_de_base(); |
|
| 159 | + $header = "<header>\n" . |
|
| 160 | + '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n"; |
|
| 161 | 161 | |
| 162 | - $titre = ($options['titre'] ?? ''); |
|
| 163 | - if ($titre) { |
|
| 164 | - $header .= '<h2>' . interdire_scripts($titre) . '</h2>'; |
|
| 165 | - } |
|
| 166 | - $header .= '</header>'; |
|
| 162 | + $titre = ($options['titre'] ?? ''); |
|
| 163 | + if ($titre) { |
|
| 164 | + $header .= '<h2>' . interdire_scripts($titre) . '</h2>'; |
|
| 165 | + } |
|
| 166 | + $header .= '</header>'; |
|
| 167 | 167 | |
| 168 | - return $header . "<div class='corps'>\n"; |
|
| 169 | - } |
|
| 168 | + return $header . "<div class='corps'>\n"; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Ferme le corps : affiche le footer par défaut ou custom et ferme le div corps |
|
| 173 | - * @param $options |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - protected function fermeCorps($options = []) { |
|
| 177 | - $url_site = url_de_base(); |
|
| 171 | + /** |
|
| 172 | + * Ferme le corps : affiche le footer par défaut ou custom et ferme le div corps |
|
| 173 | + * @param $options |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + protected function fermeCorps($options = []) { |
|
| 177 | + $url_site = url_de_base(); |
|
| 178 | 178 | |
| 179 | - if (isset($options['footer'])) { |
|
| 180 | - $footer = $options['footer']; |
|
| 181 | - } else { |
|
| 182 | - $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n"; |
|
| 183 | - } |
|
| 184 | - if (!empty($footer)) { |
|
| 185 | - $footer = "<footer>\n{$footer}</footer>"; |
|
| 186 | - } |
|
| 179 | + if (isset($options['footer'])) { |
|
| 180 | + $footer = $options['footer']; |
|
| 181 | + } else { |
|
| 182 | + $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n"; |
|
| 183 | + } |
|
| 184 | + if (!empty($footer)) { |
|
| 185 | + $footer = "<footer>\n{$footer}</footer>"; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - return "</div>\n" . $footer; |
|
| 189 | - } |
|
| 188 | + return "</div>\n" . $footer; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Retourne la fin d'une page HTML minimale |
|
| 194 | - * |
|
| 195 | - * @return string Code HTML |
|
| 196 | - */ |
|
| 197 | - protected function fermeBody() { |
|
| 198 | - return "\n\t</div>\n</body>\n</html>"; |
|
| 199 | - } |
|
| 192 | + /** |
|
| 193 | + * Retourne la fin d'une page HTML minimale |
|
| 194 | + * |
|
| 195 | + * @return string Code HTML |
|
| 196 | + */ |
|
| 197 | + protected function fermeBody() { |
|
| 198 | + return "\n\t</div>\n</body>\n</html>"; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 204 | - * le contenu transmis dans `$corps`. |
|
| 205 | - * |
|
| 206 | - * Appelée pour afficher un message ou une demande de confirmation simple et rapide |
|
| 207 | - * |
|
| 208 | - * @param string $corps |
|
| 209 | - * Corps de la page |
|
| 210 | - * @param array $options |
|
| 211 | - * @return string |
|
| 212 | - * HTML de la page |
|
| 213 | - * @see ouvreBody() |
|
| 214 | - * @see ouvreCorps() |
|
| 215 | - * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 216 | - * int $status : status de la page |
|
| 217 | - * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 218 | - * @uses ouvreBody() |
|
| 219 | - * @uses ouvreCorps() |
|
| 220 | - * @uses fermeCorps() |
|
| 221 | - * @uses fermeBody() |
|
| 222 | - * |
|
| 223 | - */ |
|
| 224 | - public function page($corps, $options = []) { |
|
| 202 | + /** |
|
| 203 | + * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 204 | + * le contenu transmis dans `$corps`. |
|
| 205 | + * |
|
| 206 | + * Appelée pour afficher un message ou une demande de confirmation simple et rapide |
|
| 207 | + * |
|
| 208 | + * @param string $corps |
|
| 209 | + * Corps de la page |
|
| 210 | + * @param array $options |
|
| 211 | + * @return string |
|
| 212 | + * HTML de la page |
|
| 213 | + * @see ouvreBody() |
|
| 214 | + * @see ouvreCorps() |
|
| 215 | + * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 216 | + * int $status : status de la page |
|
| 217 | + * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 218 | + * @uses ouvreBody() |
|
| 219 | + * @uses ouvreCorps() |
|
| 220 | + * @uses fermeCorps() |
|
| 221 | + * @uses fermeBody() |
|
| 222 | + * |
|
| 223 | + */ |
|
| 224 | + public function page($corps, $options = []) { |
|
| 225 | 225 | |
| 226 | - // par securite |
|
| 227 | - if (!defined('_AJAX')) { |
|
| 228 | - define('_AJAX', false); |
|
| 229 | - } |
|
| 226 | + // par securite |
|
| 227 | + if (!defined('_AJAX')) { |
|
| 228 | + define('_AJAX', false); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $status = ((int) ($options['status'] ?? 200)) ?: 200; |
|
| 231 | + $status = ((int) ($options['status'] ?? 200)) ?: 200; |
|
| 232 | 232 | |
| 233 | - http_response_code($status); |
|
| 233 | + http_response_code($status); |
|
| 234 | 234 | |
| 235 | - $html = $this->ouvreBody($options) |
|
| 236 | - . $this->ouvreCorps($options) |
|
| 237 | - . $corps |
|
| 238 | - . $this->fermeCorps($options) |
|
| 239 | - . $this->fermeBody(); |
|
| 235 | + $html = $this->ouvreBody($options) |
|
| 236 | + . $this->ouvreCorps($options) |
|
| 237 | + . $corps |
|
| 238 | + . $this->fermeCorps($options) |
|
| 239 | + . $this->fermeBody(); |
|
| 240 | 240 | |
| 241 | - if ( |
|
| 242 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 243 | - && empty($options['all_inline']) |
|
| 244 | - ) { |
|
| 245 | - define('_SET_HTML_BASE', true); |
|
| 246 | - include_spip('public/assembler'); |
|
| 247 | - $GLOBALS['html'] = true; |
|
| 248 | - page_base_href($html); |
|
| 249 | - } |
|
| 250 | - return $html; |
|
| 251 | - } |
|
| 241 | + if ( |
|
| 242 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 243 | + && empty($options['all_inline']) |
|
| 244 | + ) { |
|
| 245 | + define('_SET_HTML_BASE', true); |
|
| 246 | + include_spip('public/assembler'); |
|
| 247 | + $GLOBALS['html'] = true; |
|
| 248 | + page_base_href($html); |
|
| 249 | + } |
|
| 250 | + return $html; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Fonction helper pour les erreurs |
|
| 255 | - * @param ?string $message_erreur |
|
| 256 | - * @param array $options |
|
| 257 | - * @see page() |
|
| 258 | - * @return string |
|
| 259 | - * |
|
| 260 | - */ |
|
| 261 | - public function pageErreur($message_erreur = null, $options = []) { |
|
| 253 | + /** |
|
| 254 | + * Fonction helper pour les erreurs |
|
| 255 | + * @param ?string $message_erreur |
|
| 256 | + * @param array $options |
|
| 257 | + * @see page() |
|
| 258 | + * @return string |
|
| 259 | + * |
|
| 260 | + */ |
|
| 261 | + public function pageErreur($message_erreur = null, $options = []) { |
|
| 262 | 262 | |
| 263 | - if (empty($message_erreur)) { |
|
| 264 | - if (empty($options['lang'])) { |
|
| 265 | - utiliser_langue_visiteur(); |
|
| 266 | - } else { |
|
| 267 | - changer_langue($options['lang']); |
|
| 268 | - } |
|
| 269 | - $message_erreur = _T('info_acces_interdit'); |
|
| 270 | - } |
|
| 271 | - $corps = "<div class='msg-alert error'>" |
|
| 272 | - . $message_erreur |
|
| 273 | - . '</div>'; |
|
| 274 | - if (empty($options['status'])) { |
|
| 275 | - $options['status'] = 403; |
|
| 276 | - } |
|
| 277 | - return $this->page($corps, $options); |
|
| 278 | - } |
|
| 263 | + if (empty($message_erreur)) { |
|
| 264 | + if (empty($options['lang'])) { |
|
| 265 | + utiliser_langue_visiteur(); |
|
| 266 | + } else { |
|
| 267 | + changer_langue($options['lang']); |
|
| 268 | + } |
|
| 269 | + $message_erreur = _T('info_acces_interdit'); |
|
| 270 | + } |
|
| 271 | + $corps = "<div class='msg-alert error'>" |
|
| 272 | + . $message_erreur |
|
| 273 | + . '</div>'; |
|
| 274 | + if (empty($options['status'])) { |
|
| 275 | + $options['status'] = 403; |
|
| 276 | + } |
|
| 277 | + return $this->page($corps, $options); |
|
| 278 | + } |
|
| 279 | 279 | } |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']); |
| 67 | 67 | $doctype = ($options['doctype'] ?? '<!DOCTYPE html>'); |
| 68 | - $doctype = trim($doctype) . "\n"; |
|
| 68 | + $doctype = trim($doctype)."\n"; |
|
| 69 | 69 | $charset = ($options['charset'] ?? 'utf-8'); |
| 70 | 70 | $all_inline = ($options['all_inline'] ?? true); |
| 71 | 71 | $onLoad = ($options['onLoad'] ?? ''); |
| 72 | 72 | if ($onLoad) { |
| 73 | - $onLoad = ' onload="' . attribut_html($onLoad) . '"'; |
|
| 73 | + $onLoad = ' onload="'.attribut_html($onLoad).'"'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | # envoyer le charset |
| 77 | 77 | if (!headers_sent()) { |
| 78 | - header('Content-Type: text/html; charset=' . $charset); |
|
| 78 | + header('Content-Type: text/html; charset='.$charset); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $css = ''; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | . "--minipage-color-theme--s: $s;" |
| 95 | 95 | . "--minipage-color-theme--l: $l;}"; |
| 96 | 96 | $vars = file_get_contents(find_in_theme('minipage.vars.css')); |
| 97 | - $inline .= "\n" . trim($vars); |
|
| 97 | + $inline .= "\n".trim($vars); |
|
| 98 | 98 | if (function_exists('minifier')) { |
| 99 | 99 | $inline = minifier($inline, 'css'); |
| 100 | 100 | } |
@@ -121,31 +121,31 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | $css = "$inline\n$css"; |
| 123 | 123 | if (!empty($options['css'])) { |
| 124 | - $css .= "\n" . $options['css']; |
|
| 124 | + $css .= "\n".$options['css']; |
|
| 125 | 125 | } |
| 126 | 126 | $css = "<style type='text/css'>$css</style>"; |
| 127 | 127 | } else { |
| 128 | 128 | $css = "<style type='text/css'>$inline</style>"; |
| 129 | 129 | foreach ($files as $name) { |
| 130 | 130 | $file = timestamp(direction_css($name)); |
| 131 | - $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n"; |
|
| 131 | + $css .= "<link rel='stylesheet' href='".attribut_html($file)."' type='text/css' />\n"; |
|
| 132 | 132 | } |
| 133 | 133 | if (!empty($options['css'])) { |
| 134 | - $css .= "<style type='text/css'>" . $options['css'] . '</style>'; |
|
| 134 | + $css .= "<style type='text/css'>".$options['css'].'</style>'; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return $doctype . |
|
| 139 | - html_lang_attributes() . |
|
| 140 | - "<head>\n" . |
|
| 141 | - '<title>' . |
|
| 142 | - textebrut($page_title) . |
|
| 143 | - "</title>\n" . |
|
| 144 | - "<meta name=\"viewport\" content=\"width=device-width\" />\n" . |
|
| 145 | - $css . |
|
| 146 | - (empty($options['head']) ? '' : $options['head']) . |
|
| 147 | - "</head>\n" . |
|
| 148 | - "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" . |
|
| 138 | + return $doctype. |
|
| 139 | + html_lang_attributes(). |
|
| 140 | + "<head>\n". |
|
| 141 | + '<title>'. |
|
| 142 | + textebrut($page_title). |
|
| 143 | + "</title>\n". |
|
| 144 | + "<meta name=\"viewport\" content=\"width=device-width\" />\n". |
|
| 145 | + $css. |
|
| 146 | + (empty($options['head']) ? '' : $options['head']). |
|
| 147 | + "</head>\n". |
|
| 148 | + "<body{$onLoad} class=\"minipage".($this::TYPE ? ' minipage--'.$this::TYPE : '')."\">\n". |
|
| 149 | 149 | "\t<div class=\"minipage-bloc\">\n"; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function ouvreCorps($options = []) { |
| 158 | 158 | $url_site = url_de_base(); |
| 159 | - $header = "<header>\n" . |
|
| 160 | - '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n"; |
|
| 159 | + $header = "<header>\n". |
|
| 160 | + '<h1><a href="'.attribut_html($url_site).'">'.interdire_scripts($GLOBALS['meta']['nom_site'] ?? '')."</a></h1>\n"; |
|
| 161 | 161 | |
| 162 | 162 | $titre = ($options['titre'] ?? ''); |
| 163 | 163 | if ($titre) { |
| 164 | - $header .= '<h2>' . interdire_scripts($titre) . '</h2>'; |
|
| 164 | + $header .= '<h2>'.interdire_scripts($titre).'</h2>'; |
|
| 165 | 165 | } |
| 166 | 166 | $header .= '</header>'; |
| 167 | 167 | |
| 168 | - return $header . "<div class='corps'>\n"; |
|
| 168 | + return $header."<div class='corps'>\n"; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | if (isset($options['footer'])) { |
| 180 | 180 | $footer = $options['footer']; |
| 181 | 181 | } else { |
| 182 | - $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n"; |
|
| 182 | + $footer = '<a href="'.attribut_html($url_site).'">'._T('retour')."</a>\n"; |
|
| 183 | 183 | } |
| 184 | 184 | if (!empty($footer)) { |
| 185 | 185 | $footer = "<footer>\n{$footer}</footer>"; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - return "</div>\n" . $footer; |
|
| 188 | + return "</div>\n".$footer; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées pour installer SPIP |
| 16 | 16 | **/ |
| 17 | 17 | class Installation extends Admin { |
| 18 | - public const TYPE = 'installation'; |
|
| 18 | + public const TYPE = 'installation'; |
|
| 19 | 19 | |
| 20 | - protected function setOptions(array $options) { |
|
| 21 | - $options['titre'] ??= ''; |
|
| 22 | - if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | - $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | - } |
|
| 25 | - $options = parent::setOptions($options); |
|
| 26 | - $options['couleur_fond'] = '#a1124d'; |
|
| 27 | - $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | - $options['footer'] = ''; |
|
| 29 | - return $options; |
|
| 30 | - } |
|
| 20 | + protected function setOptions(array $options) { |
|
| 21 | + $options['titre'] ??= ''; |
|
| 22 | + if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | + $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | + } |
|
| 25 | + $options = parent::setOptions($options); |
|
| 26 | + $options['couleur_fond'] = '#a1124d'; |
|
| 27 | + $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | + $options['footer'] = ''; |
|
| 29 | + return $options; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function page($corps = '', $options = []) { |
|
| 33 | - $options['titre'] ??= 'AUTO'; |
|
| 34 | - return parent::page($corps, $options); |
|
| 35 | - } |
|
| 32 | + public function page($corps = '', $options = []) { |
|
| 33 | + $options['titre'] ??= 'AUTO'; |
|
| 34 | + return parent::page($corps, $options); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -15,146 +15,146 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées d’admin pour envoyer un message à un utilisateur |
| 16 | 16 | **/ |
| 17 | 17 | class Admin extends Page { |
| 18 | - public const TYPE = 'admin'; |
|
| 19 | - protected function setOptions(array $options) { |
|
| 20 | - $options['couleur_fond'] = '#999'; |
|
| 21 | - if (empty($options['css_files'])) { |
|
| 22 | - $options['css_files'] = []; |
|
| 23 | - } |
|
| 24 | - array_unshift($options['css_files'], find_in_theme('minipres.css')); |
|
| 25 | - |
|
| 26 | - $options['page_title'] = ($options['titre'] ?? ''); |
|
| 27 | - |
|
| 28 | - return $options; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Retourne le début d'une page HTML minimale (de type installation ou erreur) |
|
| 34 | - * |
|
| 35 | - * @param array $options |
|
| 36 | - * @return string |
|
| 37 | - * Code HTML |
|
| 38 | - */ |
|
| 39 | - public function installDebutPage($options = []) { |
|
| 40 | - |
|
| 41 | - $options = $this->setOptions($options); |
|
| 42 | - return parent::ouvreBody($options) |
|
| 43 | - . parent::ouvreCorps($options); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Retourne le fin d'une page HTML minimale (de type installation ou erreur) |
|
| 48 | - * |
|
| 49 | - * @param array $options |
|
| 50 | - * @return string |
|
| 51 | - * Code HTML |
|
| 52 | - */ |
|
| 53 | - public function installFinPage($options = []) { |
|
| 54 | - |
|
| 55 | - $options = $this->setOptions($options); |
|
| 56 | - return parent::fermeCorps($options) |
|
| 57 | - . parent::fermeBody(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 63 | - * le contenu transmis dans `$corps`. |
|
| 64 | - * |
|
| 65 | - * Appelée pour afficher un message d’erreur (l’utilisateur n’a pas |
|
| 66 | - * accès à cette page par exemple). |
|
| 67 | - * |
|
| 68 | - * Lorsqu’aucun argument n’est transmis, un header 403 est renvoyé, |
|
| 69 | - * ainsi qu’un message indiquant une interdiction d’accès. |
|
| 70 | - * |
|
| 71 | - * @param string $corps |
|
| 72 | - * Corps de la page |
|
| 73 | - * @param array $options |
|
| 74 | - * @return string |
|
| 75 | - * HTML de la page |
|
| 76 | - * @see ouvreBody() |
|
| 77 | - * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 78 | - * int $status : status de la page |
|
| 79 | - * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 80 | - * @uses ouvreBody() |
|
| 81 | - * @uses fermeBody() |
|
| 82 | - * |
|
| 83 | - */ |
|
| 84 | - public function page($corps = '', $options = []) { |
|
| 85 | - |
|
| 86 | - $footer = ''; |
|
| 87 | - |
|
| 88 | - $titre = $options['titre'] ?? ''; |
|
| 89 | - if (!$titre) { |
|
| 90 | - if (empty($corps) && !isset($options['status'])) { |
|
| 91 | - $options['status'] = 403; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ( |
|
| 95 | - !$titre = _request('action') |
|
| 96 | - && !$titre = _request('exec') |
|
| 97 | - && !$titre = _request('page') |
|
| 98 | - ) { |
|
| 99 | - $titre = '?'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $titre = spip_htmlspecialchars($titre); |
|
| 103 | - |
|
| 104 | - $titre = ($titre == 'install') |
|
| 105 | - ? _T('avis_espace_interdit') |
|
| 106 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 107 | - |
|
| 108 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 109 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 110 | - |
|
| 111 | - if ($statut != '0minirezo') { |
|
| 112 | - $titre = _T('info_acces_interdit'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ($statut && test_espace_prive()) { |
|
| 116 | - $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 117 | - } |
|
| 118 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | - $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 120 | - } |
|
| 121 | - else { |
|
| 122 | - $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI'], 'minipres'); |
|
| 126 | - |
|
| 127 | - $options['footer'] = $footer; |
|
| 128 | - if (empty($corps)) { |
|
| 129 | - $corps = "<div class='msg-alert error'>" |
|
| 130 | - . $titre |
|
| 131 | - . '</div>'; |
|
| 132 | - $options['titre'] = ''; |
|
| 133 | - } |
|
| 134 | - else { |
|
| 135 | - $options['titre'] = $titre; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - else { |
|
| 139 | - $options['titre'] = $titre; |
|
| 140 | - } |
|
| 141 | - $options['page_title'] = $titre; |
|
| 142 | - |
|
| 143 | - $options = $this->setOptions($options); |
|
| 144 | - |
|
| 145 | - $html = parent::page($corps, $options); |
|
| 146 | - |
|
| 147 | - if (!_AJAX) { |
|
| 148 | - return $html; |
|
| 149 | - } else { |
|
| 150 | - include_spip('inc/headers'); |
|
| 151 | - include_spip('inc/actions'); |
|
| 152 | - $url = self('&', true); |
|
| 153 | - foreach ($_POST as $v => $c) { |
|
| 154 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 155 | - } |
|
| 156 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 159 | - } |
|
| 18 | + public const TYPE = 'admin'; |
|
| 19 | + protected function setOptions(array $options) { |
|
| 20 | + $options['couleur_fond'] = '#999'; |
|
| 21 | + if (empty($options['css_files'])) { |
|
| 22 | + $options['css_files'] = []; |
|
| 23 | + } |
|
| 24 | + array_unshift($options['css_files'], find_in_theme('minipres.css')); |
|
| 25 | + |
|
| 26 | + $options['page_title'] = ($options['titre'] ?? ''); |
|
| 27 | + |
|
| 28 | + return $options; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Retourne le début d'une page HTML minimale (de type installation ou erreur) |
|
| 34 | + * |
|
| 35 | + * @param array $options |
|
| 36 | + * @return string |
|
| 37 | + * Code HTML |
|
| 38 | + */ |
|
| 39 | + public function installDebutPage($options = []) { |
|
| 40 | + |
|
| 41 | + $options = $this->setOptions($options); |
|
| 42 | + return parent::ouvreBody($options) |
|
| 43 | + . parent::ouvreCorps($options); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Retourne le fin d'une page HTML minimale (de type installation ou erreur) |
|
| 48 | + * |
|
| 49 | + * @param array $options |
|
| 50 | + * @return string |
|
| 51 | + * Code HTML |
|
| 52 | + */ |
|
| 53 | + public function installFinPage($options = []) { |
|
| 54 | + |
|
| 55 | + $options = $this->setOptions($options); |
|
| 56 | + return parent::fermeCorps($options) |
|
| 57 | + . parent::fermeBody(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 63 | + * le contenu transmis dans `$corps`. |
|
| 64 | + * |
|
| 65 | + * Appelée pour afficher un message d’erreur (l’utilisateur n’a pas |
|
| 66 | + * accès à cette page par exemple). |
|
| 67 | + * |
|
| 68 | + * Lorsqu’aucun argument n’est transmis, un header 403 est renvoyé, |
|
| 69 | + * ainsi qu’un message indiquant une interdiction d’accès. |
|
| 70 | + * |
|
| 71 | + * @param string $corps |
|
| 72 | + * Corps de la page |
|
| 73 | + * @param array $options |
|
| 74 | + * @return string |
|
| 75 | + * HTML de la page |
|
| 76 | + * @see ouvreBody() |
|
| 77 | + * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 78 | + * int $status : status de la page |
|
| 79 | + * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 80 | + * @uses ouvreBody() |
|
| 81 | + * @uses fermeBody() |
|
| 82 | + * |
|
| 83 | + */ |
|
| 84 | + public function page($corps = '', $options = []) { |
|
| 85 | + |
|
| 86 | + $footer = ''; |
|
| 87 | + |
|
| 88 | + $titre = $options['titre'] ?? ''; |
|
| 89 | + if (!$titre) { |
|
| 90 | + if (empty($corps) && !isset($options['status'])) { |
|
| 91 | + $options['status'] = 403; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ( |
|
| 95 | + !$titre = _request('action') |
|
| 96 | + && !$titre = _request('exec') |
|
| 97 | + && !$titre = _request('page') |
|
| 98 | + ) { |
|
| 99 | + $titre = '?'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $titre = spip_htmlspecialchars($titre); |
|
| 103 | + |
|
| 104 | + $titre = ($titre == 'install') |
|
| 105 | + ? _T('avis_espace_interdit') |
|
| 106 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 107 | + |
|
| 108 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 109 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 110 | + |
|
| 111 | + if ($statut != '0minirezo') { |
|
| 112 | + $titre = _T('info_acces_interdit'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ($statut && test_espace_prive()) { |
|
| 116 | + $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 117 | + } |
|
| 118 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | + $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 120 | + } |
|
| 121 | + else { |
|
| 122 | + $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + spip_log($nom . " $titre " . $_SERVER['REQUEST_URI'], 'minipres'); |
|
| 126 | + |
|
| 127 | + $options['footer'] = $footer; |
|
| 128 | + if (empty($corps)) { |
|
| 129 | + $corps = "<div class='msg-alert error'>" |
|
| 130 | + . $titre |
|
| 131 | + . '</div>'; |
|
| 132 | + $options['titre'] = ''; |
|
| 133 | + } |
|
| 134 | + else { |
|
| 135 | + $options['titre'] = $titre; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + else { |
|
| 139 | + $options['titre'] = $titre; |
|
| 140 | + } |
|
| 141 | + $options['page_title'] = $titre; |
|
| 142 | + |
|
| 143 | + $options = $this->setOptions($options); |
|
| 144 | + |
|
| 145 | + $html = parent::page($corps, $options); |
|
| 146 | + |
|
| 147 | + if (!_AJAX) { |
|
| 148 | + return $html; |
|
| 149 | + } else { |
|
| 150 | + include_spip('inc/headers'); |
|
| 151 | + include_spip('inc/actions'); |
|
| 152 | + $url = self('&', true); |
|
| 153 | + foreach ($_POST as $v => $c) { |
|
| 154 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 155 | + } |
|
| 156 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -114,11 +114,9 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | if ($statut && test_espace_prive()) { |
| 116 | 116 | $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
| 117 | - } |
|
| 118 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 117 | + } elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | 118 | $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
| 123 | 121 | } |
| 124 | 122 | |
@@ -130,12 +128,10 @@ discard block |
||
| 130 | 128 | . $titre |
| 131 | 129 | . '</div>'; |
| 132 | 130 | $options['titre'] = ''; |
| 133 | - } |
|
| 134 | - else { |
|
| 131 | + } else { |
|
| 135 | 132 | $options['titre'] = $titre; |
| 136 | 133 | } |
| 137 | - } |
|
| 138 | - else { |
|
| 134 | + } else { |
|
| 139 | 135 | $options['titre'] = $titre; |
| 140 | 136 | } |
| 141 | 137 | $options['page_title'] = $titre; |
@@ -27,206 +27,206 @@ |
||
| 27 | 27 | * Ne pas mettre de span@lang=fr si on est déjà en fr. |
| 28 | 28 | */ |
| 29 | 29 | class Multis extends AbstractCollecteur { |
| 30 | - protected static string $markPrefix = 'MULTI'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * La preg pour découper et collecter les modèles |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected string $preg_multi; |
|
| 37 | - |
|
| 38 | - public function __construct(?string $preg = null) { |
|
| 39 | - |
|
| 40 | - $this->preg_multi = ($preg ?: '@<multi>(.*?)</multi>@sS'); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Sanitizer une collection d'occurences de multi : on sanitize chaque texte de langue séparemment |
|
| 45 | - * |
|
| 46 | - * @param array $collection |
|
| 47 | - * @param string $sanitize_callback |
|
| 48 | - * @return array |
|
| 49 | - */ |
|
| 50 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 51 | - |
|
| 52 | - foreach ($collection as &$multi) { |
|
| 53 | - $changed = false; |
|
| 54 | - foreach ($multi['trads'] as $lang => $trad) { |
|
| 55 | - $t = $sanitize_callback($trad); |
|
| 56 | - if ($t !== $trad) { |
|
| 57 | - $changed = true; |
|
| 58 | - $multi['trads'][$lang] = $t; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - if ($changed) { |
|
| 62 | - $texte = $this->agglomerer_trads($multi['trads']); |
|
| 63 | - $multi['raw'] = str_replace($multi['texte'], $texte, $multi['raw']); |
|
| 64 | - $multi['texte'] = $texte; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $collection; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Convertit le contenu d'une balise `<multi>` en un tableau |
|
| 73 | - * |
|
| 74 | - * Exemple de blocs. |
|
| 75 | - * - `texte par défaut [fr] en français [en] en anglais` |
|
| 76 | - * - `[fr] en français [en] en anglais` |
|
| 77 | - * |
|
| 78 | - * @param string $bloc |
|
| 79 | - * Le contenu intérieur d'un bloc multi |
|
| 80 | - * @return array [code de langue => texte] |
|
| 81 | - * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
|
| 82 | - **/ |
|
| 83 | - protected function extraire_trads($bloc) { |
|
| 84 | - $trads = []; |
|
| 85 | - |
|
| 86 | - if (strlen($bloc)) { |
|
| 87 | - $langs = static::collecteur($bloc, ']', '[', '@[\[]([a-z]{2,3}(_[a-z]{2,3})?(_[a-z]{2,3})?)[\]]@siS'); |
|
| 88 | - $lang = ''; |
|
| 89 | - $pos_prev = 0; |
|
| 90 | - foreach ($langs as $l) { |
|
| 91 | - $pos = $l['pos']; |
|
| 92 | - if ($lang || $pos > $pos_prev) { |
|
| 93 | - $trads[$lang] = substr($bloc, $pos_prev, $pos - $pos_prev); |
|
| 94 | - } |
|
| 95 | - $lang = $l['match'][1]; |
|
| 96 | - $pos_prev = $pos + $l['length']; |
|
| 97 | - } |
|
| 98 | - $trads[$lang] = substr($bloc, $pos_prev); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $trads; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Recoller ensemble les trads pour reconstituer le texte dans la balise <multi>...</multi> |
|
| 106 | - * @param $trads |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - protected function agglomerer_trads($trads) { |
|
| 110 | - $texte = ''; |
|
| 111 | - foreach ($trads as $lang => $trad) { |
|
| 112 | - if ($texte || $lang) { |
|
| 113 | - $texte .= "[$lang]"; |
|
| 114 | - } |
|
| 115 | - $texte .= $trad; |
|
| 116 | - } |
|
| 117 | - return $texte; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param string $texte |
|
| 122 | - * @param array $options |
|
| 123 | - * bool $collecter_liens |
|
| 124 | - * @return array |
|
| 125 | - */ |
|
| 126 | - public function collecter(string $texte, array $options = []): array { |
|
| 127 | - if (!$texte) { |
|
| 128 | - return []; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // collecter les matchs de la preg |
|
| 132 | - $multis = static::collecteur($texte, '', '<multi', $this->preg_multi, empty($options['detecter_presence']) ? 0 : 1); |
|
| 133 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 134 | - if (empty($options['detecter_presence'])) { |
|
| 135 | - foreach ($multis as $k => &$multi) { |
|
| 136 | - $multi['texte'] = $multi['match'][1]; |
|
| 137 | - // extraire les trads du texte |
|
| 138 | - $multi['trads'] = $this->extraire_trads($multi['texte']); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $multis; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Traiter les multis d'un texte |
|
| 147 | - * |
|
| 148 | - * @uses approcher_langue() |
|
| 149 | - * @uses lang_typo() |
|
| 150 | - * @uses code_echappement() |
|
| 151 | - * @uses echappe_retour() |
|
| 152 | - * |
|
| 153 | - * @param string $texte |
|
| 154 | - * @param array $options |
|
| 155 | - * ?string $lang |
|
| 156 | - * ?string $lang_defaut |
|
| 157 | - * ?bool echappe_span |
|
| 158 | - * ?bool appliquer_typo |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function traiter(string $texte, array $options) { |
|
| 162 | - if ($texte) { |
|
| 163 | - $multis = $this->collecter($texte); |
|
| 164 | - if ($multis !== []) { |
|
| 165 | - $lang = $options['lang'] ?? $GLOBALS['spip_lang']; |
|
| 166 | - $lang_defaut = $options['lang_defaut'] ?? _LANGUE_PAR_DEFAUT; |
|
| 167 | - $echappe_span = $options['echappe_span'] ?? false; |
|
| 168 | - $appliquer_typo = $options['appliquer_typo'] ?? true; |
|
| 169 | - |
|
| 170 | - if (!function_exists('approcher_langue')) { |
|
| 171 | - include_spip('inc/lang'); |
|
| 172 | - } |
|
| 173 | - if (!function_exists('code_echappement')) { |
|
| 174 | - include_spip('inc/texte_mini'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $offset_pos = 0; |
|
| 178 | - foreach ($multis as $m) { |
|
| 179 | - // chercher la version de la langue courante |
|
| 180 | - $trads = $m['trads']; |
|
| 181 | - if (empty($trads)) { |
|
| 182 | - $trad = ''; |
|
| 183 | - } |
|
| 184 | - elseif ($l = approcher_langue($trads, $lang)) { |
|
| 185 | - $trad = $trads[$l]; |
|
| 186 | - } else { |
|
| 187 | - if ($lang_defaut == 'aucune') { |
|
| 188 | - $trad = ''; |
|
| 189 | - } else { |
|
| 190 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 191 | - // ou la premiere dispo |
|
| 192 | - if (!$l = approcher_langue($trads, $lang_defaut)) { |
|
| 193 | - $l = array_keys($trads); |
|
| 194 | - $l = reset($l); |
|
| 195 | - } |
|
| 196 | - $trad = $trads[$l]; |
|
| 197 | - |
|
| 198 | - // mais typographier le texte selon les regles de celle-ci |
|
| 199 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 200 | - if ($appliquer_typo) { |
|
| 201 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 202 | - $trad = $typographie($trad); |
|
| 203 | - |
|
| 204 | - // Tester si on echappe en span ou en div |
|
| 205 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 206 | - include_spip('inc/texte'); |
|
| 207 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 208 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 209 | - if ($mode === 'div') { |
|
| 210 | - $trad = rtrim($trad) . "\n\n"; |
|
| 211 | - } |
|
| 212 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 213 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 214 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 215 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 216 | - } |
|
| 217 | - if (!$echappe_span) { |
|
| 218 | - $trad = echappe_retour($trad, 'multi'); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $texte = substr_replace($texte, $trad, $m['pos'] + $offset_pos, $m['length']); |
|
| 225 | - $offset_pos += strlen($trad) - $m['length']; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $texte; |
|
| 231 | - } |
|
| 30 | + protected static string $markPrefix = 'MULTI'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * La preg pour découper et collecter les modèles |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected string $preg_multi; |
|
| 37 | + |
|
| 38 | + public function __construct(?string $preg = null) { |
|
| 39 | + |
|
| 40 | + $this->preg_multi = ($preg ?: '@<multi>(.*?)</multi>@sS'); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Sanitizer une collection d'occurences de multi : on sanitize chaque texte de langue séparemment |
|
| 45 | + * |
|
| 46 | + * @param array $collection |
|
| 47 | + * @param string $sanitize_callback |
|
| 48 | + * @return array |
|
| 49 | + */ |
|
| 50 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 51 | + |
|
| 52 | + foreach ($collection as &$multi) { |
|
| 53 | + $changed = false; |
|
| 54 | + foreach ($multi['trads'] as $lang => $trad) { |
|
| 55 | + $t = $sanitize_callback($trad); |
|
| 56 | + if ($t !== $trad) { |
|
| 57 | + $changed = true; |
|
| 58 | + $multi['trads'][$lang] = $t; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + if ($changed) { |
|
| 62 | + $texte = $this->agglomerer_trads($multi['trads']); |
|
| 63 | + $multi['raw'] = str_replace($multi['texte'], $texte, $multi['raw']); |
|
| 64 | + $multi['texte'] = $texte; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $collection; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Convertit le contenu d'une balise `<multi>` en un tableau |
|
| 73 | + * |
|
| 74 | + * Exemple de blocs. |
|
| 75 | + * - `texte par défaut [fr] en français [en] en anglais` |
|
| 76 | + * - `[fr] en français [en] en anglais` |
|
| 77 | + * |
|
| 78 | + * @param string $bloc |
|
| 79 | + * Le contenu intérieur d'un bloc multi |
|
| 80 | + * @return array [code de langue => texte] |
|
| 81 | + * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
|
| 82 | + **/ |
|
| 83 | + protected function extraire_trads($bloc) { |
|
| 84 | + $trads = []; |
|
| 85 | + |
|
| 86 | + if (strlen($bloc)) { |
|
| 87 | + $langs = static::collecteur($bloc, ']', '[', '@[\[]([a-z]{2,3}(_[a-z]{2,3})?(_[a-z]{2,3})?)[\]]@siS'); |
|
| 88 | + $lang = ''; |
|
| 89 | + $pos_prev = 0; |
|
| 90 | + foreach ($langs as $l) { |
|
| 91 | + $pos = $l['pos']; |
|
| 92 | + if ($lang || $pos > $pos_prev) { |
|
| 93 | + $trads[$lang] = substr($bloc, $pos_prev, $pos - $pos_prev); |
|
| 94 | + } |
|
| 95 | + $lang = $l['match'][1]; |
|
| 96 | + $pos_prev = $pos + $l['length']; |
|
| 97 | + } |
|
| 98 | + $trads[$lang] = substr($bloc, $pos_prev); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $trads; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Recoller ensemble les trads pour reconstituer le texte dans la balise <multi>...</multi> |
|
| 106 | + * @param $trads |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + protected function agglomerer_trads($trads) { |
|
| 110 | + $texte = ''; |
|
| 111 | + foreach ($trads as $lang => $trad) { |
|
| 112 | + if ($texte || $lang) { |
|
| 113 | + $texte .= "[$lang]"; |
|
| 114 | + } |
|
| 115 | + $texte .= $trad; |
|
| 116 | + } |
|
| 117 | + return $texte; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param string $texte |
|
| 122 | + * @param array $options |
|
| 123 | + * bool $collecter_liens |
|
| 124 | + * @return array |
|
| 125 | + */ |
|
| 126 | + public function collecter(string $texte, array $options = []): array { |
|
| 127 | + if (!$texte) { |
|
| 128 | + return []; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // collecter les matchs de la preg |
|
| 132 | + $multis = static::collecteur($texte, '', '<multi', $this->preg_multi, empty($options['detecter_presence']) ? 0 : 1); |
|
| 133 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 134 | + if (empty($options['detecter_presence'])) { |
|
| 135 | + foreach ($multis as $k => &$multi) { |
|
| 136 | + $multi['texte'] = $multi['match'][1]; |
|
| 137 | + // extraire les trads du texte |
|
| 138 | + $multi['trads'] = $this->extraire_trads($multi['texte']); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $multis; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Traiter les multis d'un texte |
|
| 147 | + * |
|
| 148 | + * @uses approcher_langue() |
|
| 149 | + * @uses lang_typo() |
|
| 150 | + * @uses code_echappement() |
|
| 151 | + * @uses echappe_retour() |
|
| 152 | + * |
|
| 153 | + * @param string $texte |
|
| 154 | + * @param array $options |
|
| 155 | + * ?string $lang |
|
| 156 | + * ?string $lang_defaut |
|
| 157 | + * ?bool echappe_span |
|
| 158 | + * ?bool appliquer_typo |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function traiter(string $texte, array $options) { |
|
| 162 | + if ($texte) { |
|
| 163 | + $multis = $this->collecter($texte); |
|
| 164 | + if ($multis !== []) { |
|
| 165 | + $lang = $options['lang'] ?? $GLOBALS['spip_lang']; |
|
| 166 | + $lang_defaut = $options['lang_defaut'] ?? _LANGUE_PAR_DEFAUT; |
|
| 167 | + $echappe_span = $options['echappe_span'] ?? false; |
|
| 168 | + $appliquer_typo = $options['appliquer_typo'] ?? true; |
|
| 169 | + |
|
| 170 | + if (!function_exists('approcher_langue')) { |
|
| 171 | + include_spip('inc/lang'); |
|
| 172 | + } |
|
| 173 | + if (!function_exists('code_echappement')) { |
|
| 174 | + include_spip('inc/texte_mini'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $offset_pos = 0; |
|
| 178 | + foreach ($multis as $m) { |
|
| 179 | + // chercher la version de la langue courante |
|
| 180 | + $trads = $m['trads']; |
|
| 181 | + if (empty($trads)) { |
|
| 182 | + $trad = ''; |
|
| 183 | + } |
|
| 184 | + elseif ($l = approcher_langue($trads, $lang)) { |
|
| 185 | + $trad = $trads[$l]; |
|
| 186 | + } else { |
|
| 187 | + if ($lang_defaut == 'aucune') { |
|
| 188 | + $trad = ''; |
|
| 189 | + } else { |
|
| 190 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 191 | + // ou la premiere dispo |
|
| 192 | + if (!$l = approcher_langue($trads, $lang_defaut)) { |
|
| 193 | + $l = array_keys($trads); |
|
| 194 | + $l = reset($l); |
|
| 195 | + } |
|
| 196 | + $trad = $trads[$l]; |
|
| 197 | + |
|
| 198 | + // mais typographier le texte selon les regles de celle-ci |
|
| 199 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 200 | + if ($appliquer_typo) { |
|
| 201 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 202 | + $trad = $typographie($trad); |
|
| 203 | + |
|
| 204 | + // Tester si on echappe en span ou en div |
|
| 205 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 206 | + include_spip('inc/texte'); |
|
| 207 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 208 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 209 | + if ($mode === 'div') { |
|
| 210 | + $trad = rtrim($trad) . "\n\n"; |
|
| 211 | + } |
|
| 212 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 213 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 214 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 215 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 216 | + } |
|
| 217 | + if (!$echappe_span) { |
|
| 218 | + $trad = echappe_retour($trad, 'multi'); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $texte = substr_replace($texte, $trad, $m['pos'] + $offset_pos, $m['length']); |
|
| 225 | + $offset_pos += strlen($trad) - $m['length']; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $texte; |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -20,203 +20,203 @@ |
||
| 20 | 20 | * mais on renvoie les params (pour l'indexation par le moteur de recherche) |
| 21 | 21 | */ |
| 22 | 22 | class Modeles extends AbstractCollecteur { |
| 23 | - protected static string $markPrefix = 'MODELE'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * La preg pour découper et collecter les modèles |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected string $preg_modele; |
|
| 30 | - |
|
| 31 | - public function __construct(?string $preg = null) { |
|
| 32 | - |
|
| 33 | - $this->preg_modele = ($preg ?: |
|
| 34 | - '@<([a-z_-]{3,})' # <modele |
|
| 35 | - . '\s*([0-9]*)\s*' # id |
|
| 36 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 37 | - . '\s*/?' . '>@isS' # fin du modele > |
|
| 38 | - ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Sanitizer une collection d'occurences de modèle : on ne fait rien |
|
| 43 | - * |
|
| 44 | - * @param array $collection |
|
| 45 | - * @param string $sanitize_callback |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 49 | - |
|
| 50 | - return $collection; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param string $texte |
|
| 55 | - * @param array $options |
|
| 56 | - * bool $collecter_liens |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function collecter(string $texte, array $options = []): array { |
|
| 60 | - if (!$texte) { |
|
| 61 | - return []; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // collecter les matchs de la preg |
|
| 65 | - $modeles = static::collecteur($texte, '', '<', $this->preg_modele); |
|
| 66 | - |
|
| 67 | - $pos_prev = 0; |
|
| 68 | - foreach ($modeles as $k => &$modele) { |
|
| 69 | - $pos = $modele['pos']; |
|
| 70 | - $modele['type'] = $modele['match'][1]; |
|
| 71 | - $modele['id'] = $modele['match'][2] ?? ''; |
|
| 72 | - $modele['params'] = $modele['match'][3] ?? ''; |
|
| 73 | - |
|
| 74 | - $longueur = $modele['length']; |
|
| 75 | - $end = $pos + $longueur; |
|
| 76 | - |
|
| 77 | - // il faut avoir un id ou des params commençant par un | sinon c'est une simple balise html |
|
| 78 | - if (empty($modele['id']) && empty($modele['params'])) { |
|
| 79 | - unset($modeles[$k]); |
|
| 80 | - continue; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 84 | - if (!empty($options['detecter_presence'])) { |
|
| 85 | - break; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $modele['lien'] = false; |
|
| 89 | - if ( |
|
| 90 | - !empty($options['collecter_liens']) |
|
| 91 | - && ($pos_fermeture_lien = stripos($texte, '</a>', $end)) |
|
| 92 | - && !strlen(trim(substr($texte, $end, $pos_fermeture_lien - $end))) |
|
| 93 | - ) { |
|
| 94 | - $pos_lien_ouvrant = stripos($texte, '<a', $pos_prev); |
|
| 95 | - if ( |
|
| 96 | - $pos_lien_ouvrant !== false |
|
| 97 | - && $pos_lien_ouvrant < $pos |
|
| 98 | - && preg_match('/<a\s[^<>]*>\s*$/i', substr($texte, $pos_prev, $pos - $pos_prev), $r) |
|
| 99 | - ) { |
|
| 100 | - $modele['lien'] = [ |
|
| 101 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 102 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 103 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 104 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 105 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 106 | - ]; |
|
| 107 | - $n = strlen($r[0]); |
|
| 108 | - $pos -= $n; |
|
| 109 | - $longueur = $pos_fermeture_lien - $pos + 4; |
|
| 110 | - $end = $pos + $longueur; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - $modele['pos'] = $pos; |
|
| 116 | - $modele['length'] = $longueur; |
|
| 117 | - $pos_prev = $end; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $modeles; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Traiter les modeles d'un texte |
|
| 125 | - * @param string $texte |
|
| 126 | - * @param array $options |
|
| 127 | - * bool|array $doublons |
|
| 128 | - * string $echap |
|
| 129 | - * ?Spip\Texte\CollecteurLiens $collecteurLiens |
|
| 130 | - * ?array $env |
|
| 131 | - * ?string $connect |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function traiter(string $texte, array $options) { |
|
| 135 | - if ($texte) { |
|
| 136 | - $doublons = $options['doublons'] ?? false; |
|
| 137 | - $echap = $options['echap'] ?? ''; |
|
| 138 | - $collecteurLiens = $options['collecteurLiens'] ?? null; |
|
| 139 | - $env = $options['env'] ?? []; |
|
| 140 | - $connect = $options['connect'] ?? ''; |
|
| 141 | - |
|
| 142 | - // preserver la compatibilite : true = recherche des documents |
|
| 143 | - if ($doublons === true) { |
|
| 144 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $modeles = $this->collecter($texte, ['collecter_liens' => true]); |
|
| 148 | - if ($modeles !== []) { |
|
| 149 | - include_spip('public/assembler'); |
|
| 150 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 151 | - |
|
| 152 | - $offset_pos = 0; |
|
| 153 | - foreach ($modeles as $m) { |
|
| 154 | - // calculer le modele |
|
| 155 | - # hack indexation |
|
| 156 | - if ($doublons) { |
|
| 157 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 158 | - } # version normale |
|
| 159 | - else { |
|
| 160 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 161 | - // dans les parametres, plutot que les liens echappes |
|
| 162 | - $params = $m['params']; |
|
| 163 | - if (!is_null($collecteurLiens)) { |
|
| 164 | - $params = $collecteurLiens->retablir($params); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 168 | - |
|
| 169 | - // en cas d'echec, |
|
| 170 | - // si l'objet demande a une url, |
|
| 171 | - // creer un petit encadre vers elle |
|
| 172 | - if ($modele === false) { |
|
| 173 | - $modele = $m['raw']; |
|
| 174 | - |
|
| 175 | - if (!is_null($collecteurLiens)) { |
|
| 176 | - $modele = $collecteurLiens->retablir($modele); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 180 | - |
|
| 181 | - if (!empty($m['lien'])) { |
|
| 182 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 183 | - $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 184 | - $contexte['lien_class'] = $m['lien']['class']; |
|
| 185 | - $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 186 | - $contexte['lien_title'] = $m['lien']['title']; |
|
| 187 | - $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // le remplacer dans le texte |
|
| 194 | - if ($modele !== false) { |
|
| 195 | - $modele = protege_js_modeles($modele); |
|
| 196 | - |
|
| 197 | - if ($wrap_embed_html) { |
|
| 198 | - $modele = $wrap_embed_html($m['raw'], $modele); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $rempl = code_echappement($modele, $echap); |
|
| 202 | - $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 203 | - $offset_pos += strlen($rempl) - $m['length']; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // hack pour tout l'espace prive |
|
| 208 | - if ((test_espace_prive() || $doublons) && !empty($m['id'])) { |
|
| 209 | - $type = strtolower($m['type']); |
|
| 210 | - foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 211 | - if (in_array($type, $type_modeles)) { |
|
| 212 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $texte; |
|
| 221 | - } |
|
| 23 | + protected static string $markPrefix = 'MODELE'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * La preg pour découper et collecter les modèles |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected string $preg_modele; |
|
| 30 | + |
|
| 31 | + public function __construct(?string $preg = null) { |
|
| 32 | + |
|
| 33 | + $this->preg_modele = ($preg ?: |
|
| 34 | + '@<([a-z_-]{3,})' # <modele |
|
| 35 | + . '\s*([0-9]*)\s*' # id |
|
| 36 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 37 | + . '\s*/?' . '>@isS' # fin du modele > |
|
| 38 | + ); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Sanitizer une collection d'occurences de modèle : on ne fait rien |
|
| 43 | + * |
|
| 44 | + * @param array $collection |
|
| 45 | + * @param string $sanitize_callback |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 49 | + |
|
| 50 | + return $collection; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param string $texte |
|
| 55 | + * @param array $options |
|
| 56 | + * bool $collecter_liens |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function collecter(string $texte, array $options = []): array { |
|
| 60 | + if (!$texte) { |
|
| 61 | + return []; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // collecter les matchs de la preg |
|
| 65 | + $modeles = static::collecteur($texte, '', '<', $this->preg_modele); |
|
| 66 | + |
|
| 67 | + $pos_prev = 0; |
|
| 68 | + foreach ($modeles as $k => &$modele) { |
|
| 69 | + $pos = $modele['pos']; |
|
| 70 | + $modele['type'] = $modele['match'][1]; |
|
| 71 | + $modele['id'] = $modele['match'][2] ?? ''; |
|
| 72 | + $modele['params'] = $modele['match'][3] ?? ''; |
|
| 73 | + |
|
| 74 | + $longueur = $modele['length']; |
|
| 75 | + $end = $pos + $longueur; |
|
| 76 | + |
|
| 77 | + // il faut avoir un id ou des params commençant par un | sinon c'est une simple balise html |
|
| 78 | + if (empty($modele['id']) && empty($modele['params'])) { |
|
| 79 | + unset($modeles[$k]); |
|
| 80 | + continue; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 84 | + if (!empty($options['detecter_presence'])) { |
|
| 85 | + break; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $modele['lien'] = false; |
|
| 89 | + if ( |
|
| 90 | + !empty($options['collecter_liens']) |
|
| 91 | + && ($pos_fermeture_lien = stripos($texte, '</a>', $end)) |
|
| 92 | + && !strlen(trim(substr($texte, $end, $pos_fermeture_lien - $end))) |
|
| 93 | + ) { |
|
| 94 | + $pos_lien_ouvrant = stripos($texte, '<a', $pos_prev); |
|
| 95 | + if ( |
|
| 96 | + $pos_lien_ouvrant !== false |
|
| 97 | + && $pos_lien_ouvrant < $pos |
|
| 98 | + && preg_match('/<a\s[^<>]*>\s*$/i', substr($texte, $pos_prev, $pos - $pos_prev), $r) |
|
| 99 | + ) { |
|
| 100 | + $modele['lien'] = [ |
|
| 101 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 102 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 103 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 104 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 105 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 106 | + ]; |
|
| 107 | + $n = strlen($r[0]); |
|
| 108 | + $pos -= $n; |
|
| 109 | + $longueur = $pos_fermeture_lien - $pos + 4; |
|
| 110 | + $end = $pos + $longueur; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + $modele['pos'] = $pos; |
|
| 116 | + $modele['length'] = $longueur; |
|
| 117 | + $pos_prev = $end; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $modeles; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Traiter les modeles d'un texte |
|
| 125 | + * @param string $texte |
|
| 126 | + * @param array $options |
|
| 127 | + * bool|array $doublons |
|
| 128 | + * string $echap |
|
| 129 | + * ?Spip\Texte\CollecteurLiens $collecteurLiens |
|
| 130 | + * ?array $env |
|
| 131 | + * ?string $connect |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function traiter(string $texte, array $options) { |
|
| 135 | + if ($texte) { |
|
| 136 | + $doublons = $options['doublons'] ?? false; |
|
| 137 | + $echap = $options['echap'] ?? ''; |
|
| 138 | + $collecteurLiens = $options['collecteurLiens'] ?? null; |
|
| 139 | + $env = $options['env'] ?? []; |
|
| 140 | + $connect = $options['connect'] ?? ''; |
|
| 141 | + |
|
| 142 | + // preserver la compatibilite : true = recherche des documents |
|
| 143 | + if ($doublons === true) { |
|
| 144 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $modeles = $this->collecter($texte, ['collecter_liens' => true]); |
|
| 148 | + if ($modeles !== []) { |
|
| 149 | + include_spip('public/assembler'); |
|
| 150 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 151 | + |
|
| 152 | + $offset_pos = 0; |
|
| 153 | + foreach ($modeles as $m) { |
|
| 154 | + // calculer le modele |
|
| 155 | + # hack indexation |
|
| 156 | + if ($doublons) { |
|
| 157 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 158 | + } # version normale |
|
| 159 | + else { |
|
| 160 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 161 | + // dans les parametres, plutot que les liens echappes |
|
| 162 | + $params = $m['params']; |
|
| 163 | + if (!is_null($collecteurLiens)) { |
|
| 164 | + $params = $collecteurLiens->retablir($params); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 168 | + |
|
| 169 | + // en cas d'echec, |
|
| 170 | + // si l'objet demande a une url, |
|
| 171 | + // creer un petit encadre vers elle |
|
| 172 | + if ($modele === false) { |
|
| 173 | + $modele = $m['raw']; |
|
| 174 | + |
|
| 175 | + if (!is_null($collecteurLiens)) { |
|
| 176 | + $modele = $collecteurLiens->retablir($modele); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 180 | + |
|
| 181 | + if (!empty($m['lien'])) { |
|
| 182 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 183 | + $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 184 | + $contexte['lien_class'] = $m['lien']['class']; |
|
| 185 | + $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 186 | + $contexte['lien_title'] = $m['lien']['title']; |
|
| 187 | + $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // le remplacer dans le texte |
|
| 194 | + if ($modele !== false) { |
|
| 195 | + $modele = protege_js_modeles($modele); |
|
| 196 | + |
|
| 197 | + if ($wrap_embed_html) { |
|
| 198 | + $modele = $wrap_embed_html($m['raw'], $modele); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $rempl = code_echappement($modele, $echap); |
|
| 202 | + $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 203 | + $offset_pos += strlen($rempl) - $m['length']; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // hack pour tout l'espace prive |
|
| 208 | + if ((test_espace_prive() || $doublons) && !empty($m['id'])) { |
|
| 209 | + $type = strtolower($m['type']); |
|
| 210 | + foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 211 | + if (in_array($type, $type_modeles)) { |
|
| 212 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $texte; |
|
| 221 | + } |
|
| 222 | 222 | } |