@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -48,63 +48,63 @@ discard block |
||
| 48 | 48 | * Nom de la fonction, ou false. |
| 49 | 49 | */ |
| 50 | 50 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 51 | - static $echecs = array(); |
|
| 52 | - |
|
| 53 | - if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | - $dossier .= '/'; |
|
| 55 | - } |
|
| 56 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | - |
|
| 58 | - if (function_exists($f)) { |
|
| 59 | - return $f; |
|
| 60 | - } |
|
| 61 | - if (function_exists($g = $f . '_dist')) { |
|
| 62 | - return $g; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (isset($echecs[$f])) { |
|
| 66 | - return $echecs[$f]; |
|
| 67 | - } |
|
| 68 | - // Sinon charger le fichier de declaration si plausible |
|
| 69 | - |
|
| 70 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | - if ($continue) { |
|
| 72 | - return false; |
|
| 73 | - } //appel interne, on passe |
|
| 74 | - include_spip('inc/minipres'); |
|
| 75 | - echo minipres(); |
|
| 76 | - exit; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // passer en minuscules (cf les balises de formulaires) |
|
| 80 | - // et inclure le fichier |
|
| 81 | - if (!$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 82 | - // si le fichier truc/machin/nom.php n'existe pas, |
|
| 83 | - // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 84 | - and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 85 | - ) { |
|
| 86 | - include_spip(substr($dossier, 0, -1)); |
|
| 87 | - } |
|
| 88 | - if (function_exists($f)) { |
|
| 89 | - return $f; |
|
| 90 | - } |
|
| 91 | - if (function_exists($g)) { |
|
| 92 | - return $g; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if ($continue) { |
|
| 96 | - return $echecs[$f] = false; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Echec : message d'erreur |
|
| 100 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 101 | - ($inc ? "" : " (fichier $d absent de $dossier)")); |
|
| 102 | - |
|
| 103 | - include_spip('inc/minipres'); |
|
| 104 | - echo minipres(_T('forum_titre_erreur'), |
|
| 105 | - _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')), |
|
| 106 | - array('all_inline'=>true,'status'=>404)); |
|
| 107 | - exit; |
|
| 51 | + static $echecs = array(); |
|
| 52 | + |
|
| 53 | + if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | + $dossier .= '/'; |
|
| 55 | + } |
|
| 56 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | + |
|
| 58 | + if (function_exists($f)) { |
|
| 59 | + return $f; |
|
| 60 | + } |
|
| 61 | + if (function_exists($g = $f . '_dist')) { |
|
| 62 | + return $g; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (isset($echecs[$f])) { |
|
| 66 | + return $echecs[$f]; |
|
| 67 | + } |
|
| 68 | + // Sinon charger le fichier de declaration si plausible |
|
| 69 | + |
|
| 70 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | + if ($continue) { |
|
| 72 | + return false; |
|
| 73 | + } //appel interne, on passe |
|
| 74 | + include_spip('inc/minipres'); |
|
| 75 | + echo minipres(); |
|
| 76 | + exit; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // passer en minuscules (cf les balises de formulaires) |
|
| 80 | + // et inclure le fichier |
|
| 81 | + if (!$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 82 | + // si le fichier truc/machin/nom.php n'existe pas, |
|
| 83 | + // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 84 | + and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 85 | + ) { |
|
| 86 | + include_spip(substr($dossier, 0, -1)); |
|
| 87 | + } |
|
| 88 | + if (function_exists($f)) { |
|
| 89 | + return $f; |
|
| 90 | + } |
|
| 91 | + if (function_exists($g)) { |
|
| 92 | + return $g; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if ($continue) { |
|
| 96 | + return $echecs[$f] = false; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Echec : message d'erreur |
|
| 100 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 101 | + ($inc ? "" : " (fichier $d absent de $dossier)")); |
|
| 102 | + |
|
| 103 | + include_spip('inc/minipres'); |
|
| 104 | + echo minipres(_T('forum_titre_erreur'), |
|
| 105 | + _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')), |
|
| 106 | + array('all_inline'=>true,'status'=>404)); |
|
| 107 | + exit; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | 116 | function include_once_check($file) { |
| 117 | - if (file_exists($file)) { |
|
| 118 | - include_once $file; |
|
| 117 | + if (file_exists($file)) { |
|
| 118 | + include_once $file; |
|
| 119 | 119 | |
| 120 | - return true; |
|
| 121 | - } |
|
| 122 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 123 | - $crash = ($crash ? $crash : array()); |
|
| 124 | - $crash[$file] = true; |
|
| 125 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 123 | + $crash = ($crash ? $crash : array()); |
|
| 124 | + $crash[$file] = true; |
|
| 125 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 126 | 126 | |
| 127 | - return false; |
|
| 127 | + return false; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * - string : chemin du fichier trouvé |
| 149 | 149 | **/ |
| 150 | 150 | function include_spip($f, $include = true) { |
| 151 | - return find_in_path($f . '.php', '', $include); |
|
| 151 | + return find_in_path($f . '.php', '', $include); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * - string : chemin du fichier trouvé |
| 169 | 169 | **/ |
| 170 | 170 | function require_spip($f) { |
| 171 | - return find_in_path($f . '.php', '', 'required'); |
|
| 171 | + return find_in_path($f . '.php', '', 'required'); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -194,22 +194,22 @@ discard block |
||
| 194 | 194 | * Les paramètres du pipeline modifiés |
| 195 | 195 | **/ |
| 196 | 196 | function minipipe($fonc, &$val) { |
| 197 | - // fonction |
|
| 198 | - if (function_exists($fonc)) { |
|
| 199 | - $val = call_user_func($fonc, $val); |
|
| 200 | - } // Class::Methode |
|
| 201 | - else { |
|
| 202 | - if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs) |
|
| 203 | - and $methode = array($regs[1], $regs[2]) |
|
| 204 | - and is_callable($methode) |
|
| 205 | - ) { |
|
| 206 | - $val = call_user_func($methode, $val); |
|
| 207 | - } else { |
|
| 208 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 209 | - } |
|
| 210 | - } |
|
| 197 | + // fonction |
|
| 198 | + if (function_exists($fonc)) { |
|
| 199 | + $val = call_user_func($fonc, $val); |
|
| 200 | + } // Class::Methode |
|
| 201 | + else { |
|
| 202 | + if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs) |
|
| 203 | + and $methode = array($regs[1], $regs[2]) |
|
| 204 | + and is_callable($methode) |
|
| 205 | + ) { |
|
| 206 | + $val = call_user_func($methode, $val); |
|
| 207 | + } else { |
|
| 208 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - return $val; |
|
| 212 | + return $val; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -240,45 +240,45 @@ discard block |
||
| 240 | 240 | * Résultat |
| 241 | 241 | */ |
| 242 | 242 | function pipeline($action, $val = null) { |
| 243 | - static $charger; |
|
| 244 | - |
|
| 245 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 246 | - if (!$charger) { |
|
| 247 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 248 | - include_spip('inc/plugin'); |
|
| 249 | - // generer les fichiers php precompiles |
|
| 250 | - // de chargement des plugins et des pipelines |
|
| 251 | - actualise_plugins_actifs(); |
|
| 252 | - if (!($ok = @is_readable($charger))) { |
|
| 253 | - spip_log("fichier $charger pas cree"); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($ok) { |
|
| 258 | - include_once $charger; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - // appliquer notre fonction si elle existe |
|
| 263 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 264 | - if (function_exists($fonc)) { |
|
| 265 | - $val = $fonc($val); |
|
| 266 | - } // plantage ? |
|
| 267 | - else { |
|
| 268 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // si le flux est une table avec 2 cle args&data |
|
| 272 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 273 | - // array_key_exists pour php 4.1.0 |
|
| 274 | - if (is_array($val) |
|
| 275 | - and count($val) == 2 |
|
| 276 | - and (array_key_exists('data', $val)) |
|
| 277 | - ) { |
|
| 278 | - $val = $val['data']; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return $val; |
|
| 243 | + static $charger; |
|
| 244 | + |
|
| 245 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 246 | + if (!$charger) { |
|
| 247 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 248 | + include_spip('inc/plugin'); |
|
| 249 | + // generer les fichiers php precompiles |
|
| 250 | + // de chargement des plugins et des pipelines |
|
| 251 | + actualise_plugins_actifs(); |
|
| 252 | + if (!($ok = @is_readable($charger))) { |
|
| 253 | + spip_log("fichier $charger pas cree"); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($ok) { |
|
| 258 | + include_once $charger; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + // appliquer notre fonction si elle existe |
|
| 263 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 264 | + if (function_exists($fonc)) { |
|
| 265 | + $val = $fonc($val); |
|
| 266 | + } // plantage ? |
|
| 267 | + else { |
|
| 268 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // si le flux est une table avec 2 cle args&data |
|
| 272 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 273 | + // array_key_exists pour php 4.1.0 |
|
| 274 | + if (is_array($val) |
|
| 275 | + and count($val) == 2 |
|
| 276 | + and (array_key_exists('data', $val)) |
|
| 277 | + ) { |
|
| 278 | + $val = $val['data']; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return $val; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -322,35 +322,35 @@ discard block |
||
| 322 | 322 | * paramètre est planté pour cause de compatibilité ascendante. |
| 323 | 323 | */ |
| 324 | 324 | function spip_log($message = null, $name = null) { |
| 325 | - static $pre = array(); |
|
| 326 | - static $log; |
|
| 327 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 328 | - if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 329 | - $logname = null; |
|
| 330 | - } |
|
| 331 | - if (!isset($regs[2]) or !$niveau = $regs[2]) { |
|
| 332 | - $niveau = _LOG_INFO; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 336 | - if (!$pre) { |
|
| 337 | - $pre = array( |
|
| 338 | - _LOG_HS => 'HS:', |
|
| 339 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 340 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 341 | - _LOG_ERREUR => 'ERREUR:', |
|
| 342 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 343 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 344 | - _LOG_INFO => 'info:', |
|
| 345 | - _LOG_DEBUG => 'debug:' |
|
| 346 | - ); |
|
| 347 | - $log = charger_fonction('log', 'inc'); |
|
| 348 | - } |
|
| 349 | - if (!is_string($message)) { |
|
| 350 | - $message = print_r($message, true); |
|
| 351 | - } |
|
| 352 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 353 | - } |
|
| 325 | + static $pre = array(); |
|
| 326 | + static $log; |
|
| 327 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 328 | + if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 329 | + $logname = null; |
|
| 330 | + } |
|
| 331 | + if (!isset($regs[2]) or !$niveau = $regs[2]) { |
|
| 332 | + $niveau = _LOG_INFO; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 336 | + if (!$pre) { |
|
| 337 | + $pre = array( |
|
| 338 | + _LOG_HS => 'HS:', |
|
| 339 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 340 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 341 | + _LOG_ERREUR => 'ERREUR:', |
|
| 342 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 343 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 344 | + _LOG_INFO => 'info:', |
|
| 345 | + _LOG_DEBUG => 'debug:' |
|
| 346 | + ); |
|
| 347 | + $log = charger_fonction('log', 'inc'); |
|
| 348 | + } |
|
| 349 | + if (!is_string($message)) { |
|
| 350 | + $message = print_r($message, true); |
|
| 351 | + } |
|
| 352 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 353 | + } |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | * @param array $opt Tableau d'options |
| 362 | 362 | **/ |
| 363 | 363 | function journal($phrase, $opt = array()) { |
| 364 | - $journal = charger_fonction('journal', 'inc'); |
|
| 365 | - $journal($phrase, $opt); |
|
| 364 | + $journal = charger_fonction('journal', 'inc'); |
|
| 365 | + $journal($phrase, $opt); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | |
@@ -381,36 +381,36 @@ discard block |
||
| 381 | 381 | **/ |
| 382 | 382 | function _request($var, $c = false) { |
| 383 | 383 | |
| 384 | - if (is_array($c)) { |
|
| 385 | - return isset($c[$var]) ? $c[$var] : null; |
|
| 386 | - } |
|
| 384 | + if (is_array($c)) { |
|
| 385 | + return isset($c[$var]) ? $c[$var] : null; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - if (isset($_GET[$var])) { |
|
| 389 | - $a = $_GET[$var]; |
|
| 390 | - } elseif (isset($_POST[$var])) { |
|
| 391 | - $a = $_POST[$var]; |
|
| 392 | - } else { |
|
| 393 | - return null; |
|
| 394 | - } |
|
| 388 | + if (isset($_GET[$var])) { |
|
| 389 | + $a = $_GET[$var]; |
|
| 390 | + } elseif (isset($_POST[$var])) { |
|
| 391 | + $a = $_POST[$var]; |
|
| 392 | + } else { |
|
| 393 | + return null; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - // Si on est en ajax et en POST tout a ete encode |
|
| 397 | - // via encodeURIComponent, il faut donc repasser |
|
| 398 | - // dans le charset local... |
|
| 399 | - if (defined('_AJAX') |
|
| 400 | - and _AJAX |
|
| 401 | - and isset($GLOBALS['meta']['charset']) |
|
| 402 | - and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 403 | - and is_string($a) |
|
| 404 | - // check rapide mais pas fiable |
|
| 405 | - and preg_match(',[\x80-\xFF],', $a) |
|
| 406 | - // check fiable |
|
| 407 | - and include_spip('inc/charsets') |
|
| 408 | - and is_utf8($a) |
|
| 409 | - ) { |
|
| 410 | - return importer_charset($a, 'utf-8'); |
|
| 411 | - } |
|
| 396 | + // Si on est en ajax et en POST tout a ete encode |
|
| 397 | + // via encodeURIComponent, il faut donc repasser |
|
| 398 | + // dans le charset local... |
|
| 399 | + if (defined('_AJAX') |
|
| 400 | + and _AJAX |
|
| 401 | + and isset($GLOBALS['meta']['charset']) |
|
| 402 | + and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 403 | + and is_string($a) |
|
| 404 | + // check rapide mais pas fiable |
|
| 405 | + and preg_match(',[\x80-\xFF],', $a) |
|
| 406 | + // check fiable |
|
| 407 | + and include_spip('inc/charsets') |
|
| 408 | + and is_utf8($a) |
|
| 409 | + ) { |
|
| 410 | + return importer_charset($a, 'utf-8'); |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - return $a; |
|
| 413 | + return $a; |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | |
@@ -428,22 +428,22 @@ discard block |
||
| 428 | 428 | * - false sinon |
| 429 | 429 | **/ |
| 430 | 430 | function set_request($var, $val = null, $c = false) { |
| 431 | - if (is_array($c)) { |
|
| 432 | - unset($c[$var]); |
|
| 433 | - if ($val !== null) { |
|
| 434 | - $c[$var] = $val; |
|
| 435 | - } |
|
| 431 | + if (is_array($c)) { |
|
| 432 | + unset($c[$var]); |
|
| 433 | + if ($val !== null) { |
|
| 434 | + $c[$var] = $val; |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - return $c; |
|
| 438 | - } |
|
| 437 | + return $c; |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - unset($_GET[$var]); |
|
| 441 | - unset($_POST[$var]); |
|
| 442 | - if ($val !== null) { |
|
| 443 | - $_GET[$var] = $val; |
|
| 444 | - } |
|
| 440 | + unset($_GET[$var]); |
|
| 441 | + unset($_POST[$var]); |
|
| 442 | + if ($val !== null) { |
|
| 443 | + $_GET[$var] = $val; |
|
| 444 | + } |
|
| 445 | 445 | |
| 446 | - return false; # n'affecte pas $c |
|
| 446 | + return false; # n'affecte pas $c |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | |
@@ -452,23 +452,22 @@ discard block |
||
| 452 | 452 | * |
| 453 | 453 | * On est sur le web, on exclut certains protocoles, |
| 454 | 454 | * notamment 'file://', 'php://' et d'autres… |
| 455 | - |
|
| 456 | 455 | * @param string $url |
| 457 | 456 | * @return bool |
| 458 | 457 | */ |
| 459 | 458 | function tester_url_absolue($url) { |
| 460 | - $url = trim($url); |
|
| 461 | - if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) { |
|
| 462 | - if ( |
|
| 463 | - isset($m[1]) |
|
| 464 | - and $p = strtolower(rtrim($m[1], ':')) |
|
| 465 | - and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip')) |
|
| 466 | - ) { |
|
| 467 | - return false; |
|
| 468 | - } |
|
| 469 | - return true; |
|
| 470 | - } |
|
| 471 | - return false; |
|
| 459 | + $url = trim($url); |
|
| 460 | + if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) { |
|
| 461 | + if ( |
|
| 462 | + isset($m[1]) |
|
| 463 | + and $p = strtolower(rtrim($m[1], ':')) |
|
| 464 | + and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip')) |
|
| 465 | + ) { |
|
| 466 | + return false; |
|
| 467 | + } |
|
| 468 | + return true; |
|
| 469 | + } |
|
| 470 | + return false; |
|
| 472 | 471 | } |
| 473 | 472 | |
| 474 | 473 | /** |
@@ -490,94 +489,94 @@ discard block |
||
| 490 | 489 | * @return string URL |
| 491 | 490 | */ |
| 492 | 491 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 493 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 494 | - if (strpos($c, "|") !== false and is_null($v)) { |
|
| 495 | - return null; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // lever l'#ancre |
|
| 499 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 500 | - $url = $r[1]; |
|
| 501 | - $ancre = $r[2]; |
|
| 502 | - } else { |
|
| 503 | - $ancre = ''; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - // eclater |
|
| 507 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 508 | - |
|
| 509 | - // recuperer la base |
|
| 510 | - $a = array_shift($url); |
|
| 511 | - if (!$a) { |
|
| 512 | - $a = './'; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 516 | - $ajouts = array_flip(explode('|', $c)); |
|
| 517 | - $u = is_array($v) ? $v : rawurlencode($v); |
|
| 518 | - $testv = (is_array($v) ? count($v) : strlen($v)); |
|
| 519 | - $v_read = null; |
|
| 520 | - // lire les variables et agir |
|
| 521 | - foreach ($url as $n => $val) { |
|
| 522 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 523 | - $r = array_pad($r, 3, null); |
|
| 524 | - if ($v === null) { |
|
| 525 | - // c'est un tableau, on memorise les valeurs |
|
| 526 | - if (substr($r[1], -2) == "[]") { |
|
| 527 | - if (!$v_read) { |
|
| 528 | - $v_read = array(); |
|
| 529 | - } |
|
| 530 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 531 | - } // c'est un scalaire, on retourne direct |
|
| 532 | - else { |
|
| 533 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 534 | - } |
|
| 535 | - } // suppression |
|
| 536 | - elseif (!$testv) { |
|
| 537 | - unset($url[$n]); |
|
| 538 | - } |
|
| 539 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 540 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 541 | - elseif (substr($r[1], -2) != '[]') { |
|
| 542 | - $url[$n] = $r[1] . '=' . $u; |
|
| 543 | - unset($ajouts[$r[1]]); |
|
| 544 | - } |
|
| 545 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 546 | - // départ, on remplira à l'étape suivante |
|
| 547 | - else { |
|
| 548 | - unset($url[$n]); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // traiter les parametres pas encore trouves |
|
| 554 | - if ($v === null |
|
| 555 | - and $args = func_get_args() |
|
| 556 | - and count($args) == 2 |
|
| 557 | - ) { |
|
| 558 | - return $v_read; // rien trouve ou un tableau |
|
| 559 | - } elseif ($testv) { |
|
| 560 | - foreach ($ajouts as $k => $n) { |
|
| 561 | - if (!is_array($v)) { |
|
| 562 | - $url[] = $k . '=' . $u; |
|
| 563 | - } else { |
|
| 564 | - $id = (substr($k, -2) == '[]') ? $k : ($k . "[]"); |
|
| 565 | - foreach ($v as $w) { |
|
| 566 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : $w); |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // eliminer les vides |
|
| 573 | - $url = array_filter($url); |
|
| 574 | - |
|
| 575 | - // recomposer l'adresse |
|
| 576 | - if ($url) { |
|
| 577 | - $a .= '?' . join($sep, $url); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - return $a . $ancre; |
|
| 492 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 493 | + if (strpos($c, "|") !== false and is_null($v)) { |
|
| 494 | + return null; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // lever l'#ancre |
|
| 498 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 499 | + $url = $r[1]; |
|
| 500 | + $ancre = $r[2]; |
|
| 501 | + } else { |
|
| 502 | + $ancre = ''; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // eclater |
|
| 506 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 507 | + |
|
| 508 | + // recuperer la base |
|
| 509 | + $a = array_shift($url); |
|
| 510 | + if (!$a) { |
|
| 511 | + $a = './'; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 515 | + $ajouts = array_flip(explode('|', $c)); |
|
| 516 | + $u = is_array($v) ? $v : rawurlencode($v); |
|
| 517 | + $testv = (is_array($v) ? count($v) : strlen($v)); |
|
| 518 | + $v_read = null; |
|
| 519 | + // lire les variables et agir |
|
| 520 | + foreach ($url as $n => $val) { |
|
| 521 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 522 | + $r = array_pad($r, 3, null); |
|
| 523 | + if ($v === null) { |
|
| 524 | + // c'est un tableau, on memorise les valeurs |
|
| 525 | + if (substr($r[1], -2) == "[]") { |
|
| 526 | + if (!$v_read) { |
|
| 527 | + $v_read = array(); |
|
| 528 | + } |
|
| 529 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 530 | + } // c'est un scalaire, on retourne direct |
|
| 531 | + else { |
|
| 532 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 533 | + } |
|
| 534 | + } // suppression |
|
| 535 | + elseif (!$testv) { |
|
| 536 | + unset($url[$n]); |
|
| 537 | + } |
|
| 538 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 539 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 540 | + elseif (substr($r[1], -2) != '[]') { |
|
| 541 | + $url[$n] = $r[1] . '=' . $u; |
|
| 542 | + unset($ajouts[$r[1]]); |
|
| 543 | + } |
|
| 544 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 545 | + // départ, on remplira à l'étape suivante |
|
| 546 | + else { |
|
| 547 | + unset($url[$n]); |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + // traiter les parametres pas encore trouves |
|
| 553 | + if ($v === null |
|
| 554 | + and $args = func_get_args() |
|
| 555 | + and count($args) == 2 |
|
| 556 | + ) { |
|
| 557 | + return $v_read; // rien trouve ou un tableau |
|
| 558 | + } elseif ($testv) { |
|
| 559 | + foreach ($ajouts as $k => $n) { |
|
| 560 | + if (!is_array($v)) { |
|
| 561 | + $url[] = $k . '=' . $u; |
|
| 562 | + } else { |
|
| 563 | + $id = (substr($k, -2) == '[]') ? $k : ($k . "[]"); |
|
| 564 | + foreach ($v as $w) { |
|
| 565 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : $w); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // eliminer les vides |
|
| 572 | + $url = array_filter($url); |
|
| 573 | + |
|
| 574 | + // recomposer l'adresse |
|
| 575 | + if ($url) { |
|
| 576 | + $a .= '?' . join($sep, $url); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $a . $ancre; |
|
| 581 | 580 | } |
| 582 | 581 | |
| 583 | 582 | /** |
@@ -595,21 +594,21 @@ discard block |
||
| 595 | 594 | * @return string |
| 596 | 595 | */ |
| 597 | 596 | function ancre_url($url, $ancre) { |
| 598 | - // lever l'#ancre |
|
| 599 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 600 | - $url = $r[1]; |
|
| 601 | - } |
|
| 602 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 603 | - if (!function_exists('translitteration')) { |
|
| 604 | - include_spip('inc/charsets'); |
|
| 605 | - } |
|
| 606 | - $ancre = preg_replace( |
|
| 607 | - array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), |
|
| 608 | - array('', '-'), |
|
| 609 | - translitteration($ancre) |
|
| 610 | - ); |
|
| 611 | - } |
|
| 612 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 597 | + // lever l'#ancre |
|
| 598 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 599 | + $url = $r[1]; |
|
| 600 | + } |
|
| 601 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 602 | + if (!function_exists('translitteration')) { |
|
| 603 | + include_spip('inc/charsets'); |
|
| 604 | + } |
|
| 605 | + $ancre = preg_replace( |
|
| 606 | + array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), |
|
| 607 | + array('', '-'), |
|
| 608 | + translitteration($ancre) |
|
| 609 | + ); |
|
| 610 | + } |
|
| 611 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 613 | 612 | } |
| 614 | 613 | |
| 615 | 614 | /** |
@@ -619,16 +618,16 @@ discard block |
||
| 619 | 618 | * @return string |
| 620 | 619 | */ |
| 621 | 620 | function nettoyer_uri($reset = null) { |
| 622 | - static $done = false; |
|
| 623 | - static $propre = ''; |
|
| 624 | - if (!is_null($reset)) { |
|
| 625 | - return $propre = $reset; |
|
| 626 | - } |
|
| 627 | - if ($done) { |
|
| 628 | - return $propre; |
|
| 629 | - } |
|
| 630 | - $done = true; |
|
| 631 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 621 | + static $done = false; |
|
| 622 | + static $propre = ''; |
|
| 623 | + if (!is_null($reset)) { |
|
| 624 | + return $propre = $reset; |
|
| 625 | + } |
|
| 626 | + if ($done) { |
|
| 627 | + return $propre; |
|
| 628 | + } |
|
| 629 | + $done = true; |
|
| 630 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 632 | 631 | } |
| 633 | 632 | |
| 634 | 633 | /** |
@@ -640,13 +639,13 @@ discard block |
||
| 640 | 639 | * @return string |
| 641 | 640 | */ |
| 642 | 641 | function nettoyer_uri_var($request_uri) { |
| 643 | - $uri1 = $request_uri; |
|
| 644 | - do { |
|
| 645 | - $uri = $uri1; |
|
| 646 | - $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 647 | - '\1', $uri); |
|
| 648 | - } while ($uri <> $uri1); |
|
| 649 | - return preg_replace(',[?&]$,', '', $uri1); |
|
| 642 | + $uri1 = $request_uri; |
|
| 643 | + do { |
|
| 644 | + $uri = $uri1; |
|
| 645 | + $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 646 | + '\1', $uri); |
|
| 647 | + } while ($uri <> $uri1); |
|
| 648 | + return preg_replace(',[?&]$,', '', $uri1); |
|
| 650 | 649 | } |
| 651 | 650 | |
| 652 | 651 | |
@@ -660,47 +659,47 @@ discard block |
||
| 660 | 659 | * URL vers soi-même |
| 661 | 660 | **/ |
| 662 | 661 | function self($amp = '&', $root = false) { |
| 663 | - $url = nettoyer_uri(); |
|
| 664 | - if (!$root |
|
| 665 | - and ( |
|
| 666 | - // si pas de profondeur on peut tronquer |
|
| 667 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 668 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 669 | - or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 670 | - ) { |
|
| 671 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 672 | - } |
|
| 673 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 674 | - foreach ($_POST as $v => $c) { |
|
| 675 | - if (substr($v, 0, 3) == 'id_') { |
|
| 676 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - // supprimer les variables sans interet |
|
| 681 | - if (test_espace_prive()) { |
|
| 682 | - $url = preg_replace(',([?&])(' |
|
| 683 | - . 'lang|show_docs|' |
|
| 684 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 685 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 686 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - // eviter les hacks |
|
| 690 | - include_spip('inc/filtres_mini'); |
|
| 691 | - $url = spip_htmlspecialchars($url); |
|
| 662 | + $url = nettoyer_uri(); |
|
| 663 | + if (!$root |
|
| 664 | + and ( |
|
| 665 | + // si pas de profondeur on peut tronquer |
|
| 666 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 667 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 668 | + or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 669 | + ) { |
|
| 670 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 671 | + } |
|
| 672 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 673 | + foreach ($_POST as $v => $c) { |
|
| 674 | + if (substr($v, 0, 3) == 'id_') { |
|
| 675 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + // supprimer les variables sans interet |
|
| 680 | + if (test_espace_prive()) { |
|
| 681 | + $url = preg_replace(',([?&])(' |
|
| 682 | + . 'lang|show_docs|' |
|
| 683 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 684 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 685 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + // eviter les hacks |
|
| 689 | + include_spip('inc/filtres_mini'); |
|
| 690 | + $url = spip_htmlspecialchars($url); |
|
| 692 | 691 | |
| 693 | - $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url); |
|
| 692 | + $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url); |
|
| 694 | 693 | |
| 695 | - // & ? |
|
| 696 | - if ($amp != '&') { |
|
| 697 | - $url = str_replace('&', $amp, $url); |
|
| 698 | - } |
|
| 694 | + // & ? |
|
| 695 | + if ($amp != '&') { |
|
| 696 | + $url = str_replace('&', $amp, $url); |
|
| 697 | + } |
|
| 699 | 698 | |
| 700 | - // Si ca demarre par ? ou vide, donner './' |
|
| 701 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 699 | + // Si ca demarre par ? ou vide, donner './' |
|
| 700 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 702 | 701 | |
| 703 | - return $url; |
|
| 702 | + return $url; |
|
| 704 | 703 | } |
| 705 | 704 | |
| 706 | 705 | |
@@ -711,7 +710,7 @@ discard block |
||
| 711 | 710 | * true si c'est le cas, false sinon. |
| 712 | 711 | */ |
| 713 | 712 | function test_espace_prive() { |
| 714 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 713 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 715 | 714 | } |
| 716 | 715 | |
| 717 | 716 | /** |
@@ -721,7 +720,7 @@ discard block |
||
| 721 | 720 | * @return bool |
| 722 | 721 | */ |
| 723 | 722 | function test_plugin_actif($plugin) { |
| 724 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 723 | + return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 725 | 724 | } |
| 726 | 725 | |
| 727 | 726 | /** |
@@ -752,51 +751,51 @@ discard block |
||
| 752 | 751 | * Texte |
| 753 | 752 | */ |
| 754 | 753 | function _T($texte, $args = array(), $options = array()) { |
| 755 | - static $traduire = false; |
|
| 756 | - $o = array('class' => '', 'force' => true, 'sanitize' => true); |
|
| 757 | - if ($options) { |
|
| 758 | - // support de l'ancien argument $class |
|
| 759 | - if (is_string($options)) { |
|
| 760 | - $options = array('class' => $options); |
|
| 761 | - } |
|
| 762 | - $o = array_merge($o, $options); |
|
| 763 | - } |
|
| 754 | + static $traduire = false; |
|
| 755 | + $o = array('class' => '', 'force' => true, 'sanitize' => true); |
|
| 756 | + if ($options) { |
|
| 757 | + // support de l'ancien argument $class |
|
| 758 | + if (is_string($options)) { |
|
| 759 | + $options = array('class' => $options); |
|
| 760 | + } |
|
| 761 | + $o = array_merge($o, $options); |
|
| 762 | + } |
|
| 764 | 763 | |
| 765 | - if (!$traduire) { |
|
| 766 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 767 | - include_spip('inc/lang'); |
|
| 768 | - } |
|
| 764 | + if (!$traduire) { |
|
| 765 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 766 | + include_spip('inc/lang'); |
|
| 767 | + } |
|
| 769 | 768 | |
| 770 | - // On peut passer explicitement la langue dans le tableau |
|
| 771 | - // On utilise le même nom de variable que la globale |
|
| 772 | - if (isset($args['spip_lang'])) { |
|
| 773 | - $lang = $args['spip_lang']; |
|
| 774 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 775 | - unset($args['spip_lang']); |
|
| 776 | - } // Sinon on prend la langue du contexte |
|
| 777 | - else { |
|
| 778 | - $lang = $GLOBALS['spip_lang']; |
|
| 779 | - } |
|
| 780 | - $text = $traduire($texte, $lang); |
|
| 769 | + // On peut passer explicitement la langue dans le tableau |
|
| 770 | + // On utilise le même nom de variable que la globale |
|
| 771 | + if (isset($args['spip_lang'])) { |
|
| 772 | + $lang = $args['spip_lang']; |
|
| 773 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 774 | + unset($args['spip_lang']); |
|
| 775 | + } // Sinon on prend la langue du contexte |
|
| 776 | + else { |
|
| 777 | + $lang = $GLOBALS['spip_lang']; |
|
| 778 | + } |
|
| 779 | + $text = $traduire($texte, $lang); |
|
| 781 | 780 | |
| 782 | - if (!strlen($text)) { |
|
| 783 | - if (!$o['force']) { |
|
| 784 | - return ''; |
|
| 785 | - } |
|
| 781 | + if (!strlen($text)) { |
|
| 782 | + if (!$o['force']) { |
|
| 783 | + return ''; |
|
| 784 | + } |
|
| 786 | 785 | |
| 787 | - $text = $texte; |
|
| 786 | + $text = $texte; |
|
| 788 | 787 | |
| 789 | - // pour les chaines non traduites, assurer un service minimum |
|
| 790 | - if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 791 | - $text = str_replace('_', ' ', |
|
| 792 | - (($n = strpos($text, ':')) === false ? $texte : |
|
| 793 | - substr($texte, $n + 1))); |
|
| 794 | - } |
|
| 795 | - $o['class'] = null; |
|
| 788 | + // pour les chaines non traduites, assurer un service minimum |
|
| 789 | + if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 790 | + $text = str_replace('_', ' ', |
|
| 791 | + (($n = strpos($text, ':')) === false ? $texte : |
|
| 792 | + substr($texte, $n + 1))); |
|
| 793 | + } |
|
| 794 | + $o['class'] = null; |
|
| 796 | 795 | |
| 797 | - } |
|
| 796 | + } |
|
| 798 | 797 | |
| 799 | - return _L($text, $args, $o); |
|
| 798 | + return _L($text, $args, $o); |
|
| 800 | 799 | |
| 801 | 800 | } |
| 802 | 801 | |
@@ -824,53 +823,53 @@ discard block |
||
| 824 | 823 | * Texte |
| 825 | 824 | */ |
| 826 | 825 | function _L($text, $args = array(), $options = array()) { |
| 827 | - $f = $text; |
|
| 828 | - $defaut_options = array( |
|
| 829 | - 'class' => null, |
|
| 830 | - 'sanitize' => true, |
|
| 831 | - ); |
|
| 832 | - // support de l'ancien argument $class |
|
| 833 | - if ($options and is_string($options)) { |
|
| 834 | - $options = array('class' => $options); |
|
| 835 | - } |
|
| 836 | - if (is_array($options)) { |
|
| 837 | - $options += $defaut_options; |
|
| 838 | - } else { |
|
| 839 | - $options = $defaut_options; |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - if (is_array($args) and count($args)) { |
|
| 843 | - if (!function_exists('interdire_scripts')) { |
|
| 844 | - include_spip('inc/texte'); |
|
| 845 | - } |
|
| 846 | - if (!function_exists('echapper_html_suspect')) { |
|
| 847 | - include_spip('inc/texte_mini'); |
|
| 848 | - } |
|
| 849 | - foreach ($args as $name => $value) { |
|
| 850 | - if (strpos($text, "@$name@") !== false) { |
|
| 851 | - if ($options['sanitize']) { |
|
| 852 | - $value = echapper_html_suspect($value); |
|
| 853 | - $value = interdire_scripts($value, -1); |
|
| 854 | - } |
|
| 855 | - if (!empty($options['class'])) { |
|
| 856 | - $value = "<span class='".$options['class']."'>$value</span>"; |
|
| 857 | - } |
|
| 858 | - $text = str_replace("@$name@", $value, $text); |
|
| 859 | - unset($args[$name]); |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 863 | - // (chaines de langues pas a jour) |
|
| 864 | - if ($args) { |
|
| 865 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 870 | - return "<span class=debug-traduction-erreur>$text</span>"; |
|
| 871 | - } else { |
|
| 872 | - return $text; |
|
| 873 | - } |
|
| 826 | + $f = $text; |
|
| 827 | + $defaut_options = array( |
|
| 828 | + 'class' => null, |
|
| 829 | + 'sanitize' => true, |
|
| 830 | + ); |
|
| 831 | + // support de l'ancien argument $class |
|
| 832 | + if ($options and is_string($options)) { |
|
| 833 | + $options = array('class' => $options); |
|
| 834 | + } |
|
| 835 | + if (is_array($options)) { |
|
| 836 | + $options += $defaut_options; |
|
| 837 | + } else { |
|
| 838 | + $options = $defaut_options; |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + if (is_array($args) and count($args)) { |
|
| 842 | + if (!function_exists('interdire_scripts')) { |
|
| 843 | + include_spip('inc/texte'); |
|
| 844 | + } |
|
| 845 | + if (!function_exists('echapper_html_suspect')) { |
|
| 846 | + include_spip('inc/texte_mini'); |
|
| 847 | + } |
|
| 848 | + foreach ($args as $name => $value) { |
|
| 849 | + if (strpos($text, "@$name@") !== false) { |
|
| 850 | + if ($options['sanitize']) { |
|
| 851 | + $value = echapper_html_suspect($value); |
|
| 852 | + $value = interdire_scripts($value, -1); |
|
| 853 | + } |
|
| 854 | + if (!empty($options['class'])) { |
|
| 855 | + $value = "<span class='".$options['class']."'>$value</span>"; |
|
| 856 | + } |
|
| 857 | + $text = str_replace("@$name@", $value, $text); |
|
| 858 | + unset($args[$name]); |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 862 | + // (chaines de langues pas a jour) |
|
| 863 | + if ($args) { |
|
| 864 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 869 | + return "<span class=debug-traduction-erreur>$text</span>"; |
|
| 870 | + } else { |
|
| 871 | + return $text; |
|
| 872 | + } |
|
| 874 | 873 | } |
| 875 | 874 | |
| 876 | 875 | |
@@ -884,13 +883,13 @@ discard block |
||
| 884 | 883 | * @return string |
| 885 | 884 | */ |
| 886 | 885 | function joli_repertoire($rep) { |
| 887 | - $a = substr($rep, 0, 1); |
|
| 888 | - if ($a <> '.' and $a <> '/') { |
|
| 889 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 890 | - } |
|
| 891 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 886 | + $a = substr($rep, 0, 1); |
|
| 887 | + if ($a <> '.' and $a <> '/') { |
|
| 888 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 889 | + } |
|
| 890 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 892 | 891 | |
| 893 | - return $rep; |
|
| 892 | + return $rep; |
|
| 894 | 893 | } |
| 895 | 894 | |
| 896 | 895 | |
@@ -915,33 +914,33 @@ discard block |
||
| 915 | 914 | * @return float|int|string|void |
| 916 | 915 | */ |
| 917 | 916 | function spip_timer($t = 'rien', $raw = false) { |
| 918 | - static $time; |
|
| 919 | - $a = time(); |
|
| 920 | - $b = microtime(); |
|
| 921 | - // microtime peut contenir les microsecondes et le temps |
|
| 922 | - $b = explode(' ', $b); |
|
| 923 | - if (count($b) == 2) { |
|
| 924 | - $a = end($b); |
|
| 925 | - } // plus precis ! |
|
| 926 | - $b = reset($b); |
|
| 927 | - if (!isset($time[$t])) { |
|
| 928 | - $time[$t] = $a + $b; |
|
| 929 | - } else { |
|
| 930 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 931 | - unset($time[$t]); |
|
| 917 | + static $time; |
|
| 918 | + $a = time(); |
|
| 919 | + $b = microtime(); |
|
| 920 | + // microtime peut contenir les microsecondes et le temps |
|
| 921 | + $b = explode(' ', $b); |
|
| 922 | + if (count($b) == 2) { |
|
| 923 | + $a = end($b); |
|
| 924 | + } // plus precis ! |
|
| 925 | + $b = reset($b); |
|
| 926 | + if (!isset($time[$t])) { |
|
| 927 | + $time[$t] = $a + $b; |
|
| 928 | + } else { |
|
| 929 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 930 | + unset($time[$t]); |
|
| 932 | 931 | # echo "'$p'";exit; |
| 933 | - if ($raw) { |
|
| 934 | - return $p; |
|
| 935 | - } |
|
| 936 | - if ($p < 1000) { |
|
| 937 | - $s = ''; |
|
| 938 | - } else { |
|
| 939 | - $s = sprintf("%d ", $x = floor($p / 1000)); |
|
| 940 | - $p -= ($x * 1000); |
|
| 941 | - } |
|
| 932 | + if ($raw) { |
|
| 933 | + return $p; |
|
| 934 | + } |
|
| 935 | + if ($p < 1000) { |
|
| 936 | + $s = ''; |
|
| 937 | + } else { |
|
| 938 | + $s = sprintf("%d ", $x = floor($p / 1000)); |
|
| 939 | + $p -= ($x * 1000); |
|
| 940 | + } |
|
| 942 | 941 | |
| 943 | - return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p); |
|
| 944 | - } |
|
| 942 | + return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p); |
|
| 943 | + } |
|
| 945 | 944 | } |
| 946 | 945 | |
| 947 | 946 | |
@@ -949,21 +948,21 @@ discard block |
||
| 949 | 948 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 950 | 949 | // http://code.spip.net/@spip_touch |
| 951 | 950 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 952 | - if ($duree) { |
|
| 953 | - clearstatcache(); |
|
| 954 | - if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 955 | - return false; |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - if ($touch !== false) { |
|
| 959 | - if (!@touch($fichier)) { |
|
| 960 | - spip_unlink($fichier); |
|
| 961 | - @touch($fichier); |
|
| 962 | - }; |
|
| 963 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 964 | - } |
|
| 951 | + if ($duree) { |
|
| 952 | + clearstatcache(); |
|
| 953 | + if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + if ($touch !== false) { |
|
| 958 | + if (!@touch($fichier)) { |
|
| 959 | + spip_unlink($fichier); |
|
| 960 | + @touch($fichier); |
|
| 961 | + }; |
|
| 962 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 963 | + } |
|
| 965 | 964 | |
| 966 | - return true; |
|
| 965 | + return true; |
|
| 967 | 966 | } |
| 968 | 967 | |
| 969 | 968 | |
@@ -975,11 +974,11 @@ discard block |
||
| 975 | 974 | * @uses cron() |
| 976 | 975 | **/ |
| 977 | 976 | function action_cron() { |
| 978 | - include_spip('inc/headers'); |
|
| 979 | - http_status(204); // No Content |
|
| 980 | - header("Connection: close"); |
|
| 981 | - define('_DIRECT_CRON_FORCE', true); |
|
| 982 | - cron(); |
|
| 977 | + include_spip('inc/headers'); |
|
| 978 | + http_status(204); // No Content |
|
| 979 | + header("Connection: close"); |
|
| 980 | + define('_DIRECT_CRON_FORCE', true); |
|
| 981 | + cron(); |
|
| 983 | 982 | } |
| 984 | 983 | |
| 985 | 984 | /** |
@@ -995,26 +994,26 @@ discard block |
||
| 995 | 994 | * True si la tache a pu être effectuée |
| 996 | 995 | */ |
| 997 | 996 | function cron($taches = array(), $taches_old = array()) { |
| 998 | - // si pas en mode cron force, laisser tomber. |
|
| 999 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1000 | - return false; |
|
| 1001 | - } |
|
| 1002 | - if (!is_array($taches)) { |
|
| 1003 | - $taches = $taches_old; |
|
| 1004 | - } // compat anciens appels |
|
| 1005 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1006 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1007 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1008 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1009 | - if ($taches and count($taches) and !spip_connect()) { |
|
| 1010 | - return false; |
|
| 1011 | - } |
|
| 1012 | - spip_log("cron !", 'jq' . _LOG_DEBUG); |
|
| 1013 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1014 | - return $genie($taches); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - return false; |
|
| 997 | + // si pas en mode cron force, laisser tomber. |
|
| 998 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 999 | + return false; |
|
| 1000 | + } |
|
| 1001 | + if (!is_array($taches)) { |
|
| 1002 | + $taches = $taches_old; |
|
| 1003 | + } // compat anciens appels |
|
| 1004 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1005 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1006 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1007 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1008 | + if ($taches and count($taches) and !spip_connect()) { |
|
| 1009 | + return false; |
|
| 1010 | + } |
|
| 1011 | + spip_log("cron !", 'jq' . _LOG_DEBUG); |
|
| 1012 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1013 | + return $genie($taches); |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + return false; |
|
| 1018 | 1017 | } |
| 1019 | 1018 | |
| 1020 | 1019 | /** |
@@ -1046,17 +1045,17 @@ discard block |
||
| 1046 | 1045 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1047 | 1046 | */ |
| 1048 | 1047 | function job_queue_add( |
| 1049 | - $function, |
|
| 1050 | - $description, |
|
| 1051 | - $arguments = array(), |
|
| 1052 | - $file = '', |
|
| 1053 | - $no_duplicate = false, |
|
| 1054 | - $time = 0, |
|
| 1055 | - $priority = 0 |
|
| 1048 | + $function, |
|
| 1049 | + $description, |
|
| 1050 | + $arguments = array(), |
|
| 1051 | + $file = '', |
|
| 1052 | + $no_duplicate = false, |
|
| 1053 | + $time = 0, |
|
| 1054 | + $priority = 0 |
|
| 1056 | 1055 | ) { |
| 1057 | - include_spip('inc/queue'); |
|
| 1056 | + include_spip('inc/queue'); |
|
| 1058 | 1057 | |
| 1059 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1058 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1060 | 1059 | } |
| 1061 | 1060 | |
| 1062 | 1061 | /** |
@@ -1067,9 +1066,9 @@ discard block |
||
| 1067 | 1066 | * @return bool |
| 1068 | 1067 | */ |
| 1069 | 1068 | function job_queue_remove($id_job) { |
| 1070 | - include_spip('inc/queue'); |
|
| 1069 | + include_spip('inc/queue'); |
|
| 1071 | 1070 | |
| 1072 | - return queue_remove_job($id_job); |
|
| 1071 | + return queue_remove_job($id_job); |
|
| 1073 | 1072 | } |
| 1074 | 1073 | |
| 1075 | 1074 | /** |
@@ -1082,9 +1081,9 @@ discard block |
||
| 1082 | 1081 | * or an array of simple array to link multiples objet in one time |
| 1083 | 1082 | */ |
| 1084 | 1083 | function job_queue_link($id_job, $objets) { |
| 1085 | - include_spip('inc/queue'); |
|
| 1084 | + include_spip('inc/queue'); |
|
| 1086 | 1085 | |
| 1087 | - return queue_link_job($id_job, $objets); |
|
| 1086 | + return queue_link_job($id_job, $objets); |
|
| 1088 | 1087 | } |
| 1089 | 1088 | |
| 1090 | 1089 | |
@@ -1104,36 +1103,36 @@ discard block |
||
| 1104 | 1103 | * - `null` si la queue n'est pas encore initialisée |
| 1105 | 1104 | */ |
| 1106 | 1105 | function queue_sleep_time_to_next_job($force = null) { |
| 1107 | - static $queue_next_job_time = -1; |
|
| 1108 | - if ($force === true) { |
|
| 1109 | - $queue_next_job_time = -1; |
|
| 1110 | - } elseif ($force) { |
|
| 1111 | - $queue_next_job_time = $force; |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - if ($queue_next_job_time == -1) { |
|
| 1115 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1116 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt"); |
|
| 1117 | - } |
|
| 1118 | - // utiliser un cache memoire si dispo |
|
| 1119 | - if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1120 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1121 | - } else { |
|
| 1122 | - $queue_next_job_time = null; |
|
| 1123 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1124 | - $queue_next_job_time = intval($contenu); |
|
| 1125 | - } |
|
| 1126 | - } |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - if (is_null($queue_next_job_time)) { |
|
| 1130 | - return null; |
|
| 1131 | - } |
|
| 1132 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1133 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1106 | + static $queue_next_job_time = -1; |
|
| 1107 | + if ($force === true) { |
|
| 1108 | + $queue_next_job_time = -1; |
|
| 1109 | + } elseif ($force) { |
|
| 1110 | + $queue_next_job_time = $force; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + if ($queue_next_job_time == -1) { |
|
| 1114 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1115 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt"); |
|
| 1116 | + } |
|
| 1117 | + // utiliser un cache memoire si dispo |
|
| 1118 | + if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1119 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1120 | + } else { |
|
| 1121 | + $queue_next_job_time = null; |
|
| 1122 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1123 | + $queue_next_job_time = intval($contenu); |
|
| 1124 | + } |
|
| 1125 | + } |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + if (is_null($queue_next_job_time)) { |
|
| 1129 | + return null; |
|
| 1130 | + } |
|
| 1131 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1132 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1137 | 1136 | } |
| 1138 | 1137 | |
| 1139 | 1138 | |
@@ -1145,9 +1144,9 @@ discard block |
||
| 1145 | 1144 | * @return string |
| 1146 | 1145 | */ |
| 1147 | 1146 | function quote_amp($u) { |
| 1148 | - return preg_replace( |
|
| 1149 | - "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i", |
|
| 1150 | - "&", $u); |
|
| 1147 | + return preg_replace( |
|
| 1148 | + "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i", |
|
| 1149 | + "&", $u); |
|
| 1151 | 1150 | } |
| 1152 | 1151 | |
| 1153 | 1152 | |
@@ -1170,27 +1169,27 @@ discard block |
||
| 1170 | 1169 | * Balise HTML `<script>` et son contenu |
| 1171 | 1170 | **/ |
| 1172 | 1171 | function http_script($script, $src = '', $noscript = '') { |
| 1173 | - static $done = array(); |
|
| 1172 | + static $done = array(); |
|
| 1174 | 1173 | |
| 1175 | - if ($src && !isset($done[$src])) { |
|
| 1176 | - $done[$src] = true; |
|
| 1177 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1178 | - $src = " src='$src'"; |
|
| 1179 | - } else { |
|
| 1180 | - $src = ''; |
|
| 1181 | - } |
|
| 1182 | - if ($script) { |
|
| 1183 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1184 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1185 | - "/*]]>*/"); |
|
| 1186 | - } |
|
| 1187 | - if ($noscript) { |
|
| 1188 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1189 | - } |
|
| 1174 | + if ($src && !isset($done[$src])) { |
|
| 1175 | + $done[$src] = true; |
|
| 1176 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1177 | + $src = " src='$src'"; |
|
| 1178 | + } else { |
|
| 1179 | + $src = ''; |
|
| 1180 | + } |
|
| 1181 | + if ($script) { |
|
| 1182 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1183 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1184 | + "/*]]>*/"); |
|
| 1185 | + } |
|
| 1186 | + if ($noscript) { |
|
| 1187 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1188 | + } |
|
| 1190 | 1189 | |
| 1191 | - return ($src or $script or $noscript) |
|
| 1192 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1193 | - : ''; |
|
| 1190 | + return ($src or $script or $noscript) |
|
| 1191 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1192 | + : ''; |
|
| 1194 | 1193 | } |
| 1195 | 1194 | |
| 1196 | 1195 | |
@@ -1225,7 +1224,7 @@ discard block |
||
| 1225 | 1224 | * Texte échappé |
| 1226 | 1225 | **/ |
| 1227 | 1226 | function texte_script($texte) { |
| 1228 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1227 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1229 | 1228 | } |
| 1230 | 1229 | |
| 1231 | 1230 | |
@@ -1262,69 +1261,69 @@ discard block |
||
| 1262 | 1261 | * Liste des chemins, par ordre de priorité. |
| 1263 | 1262 | **/ |
| 1264 | 1263 | function _chemin($dir_path = null) { |
| 1265 | - static $path_base = null; |
|
| 1266 | - static $path_full = null; |
|
| 1267 | - if ($path_base == null) { |
|
| 1268 | - // Chemin standard depuis l'espace public |
|
| 1269 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1270 | - _DIR_RACINE . ':' . |
|
| 1271 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1272 | - _DIR_RACINE . 'prive/:' . |
|
| 1273 | - _DIR_RESTREINT; |
|
| 1274 | - // Ajouter squelettes/ |
|
| 1275 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1276 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1277 | - } |
|
| 1278 | - foreach (explode(':', $path) as $dir) { |
|
| 1279 | - if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1280 | - $dir .= "/"; |
|
| 1281 | - } |
|
| 1282 | - $path_base[] = $dir; |
|
| 1283 | - } |
|
| 1284 | - $path_full = $path_base; |
|
| 1285 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1286 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1287 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1288 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1292 | - } |
|
| 1293 | - if ($dir_path === null) { |
|
| 1294 | - return $path_full; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - if (strlen($dir_path)) { |
|
| 1298 | - $tete = ""; |
|
| 1299 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1300 | - $tete = array_shift($path_base); |
|
| 1301 | - } |
|
| 1302 | - $dirs = array_reverse(explode(':', $dir_path)); |
|
| 1303 | - foreach ($dirs as $dir_path) { |
|
| 1304 | - #if ($dir_path{0}!='/') |
|
| 1305 | - # $dir_path = $dir_path; |
|
| 1306 | - if (substr($dir_path, -1) != '/') { |
|
| 1307 | - $dir_path .= "/"; |
|
| 1308 | - } |
|
| 1309 | - if (!in_array($dir_path, $path_base)) { |
|
| 1310 | - array_unshift($path_base, $dir_path); |
|
| 1311 | - } |
|
| 1312 | - } |
|
| 1313 | - if (strlen($tete)) { |
|
| 1314 | - array_unshift($path_base, $tete); |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - $path_full = $path_base; |
|
| 1318 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1319 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1320 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1321 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1326 | - |
|
| 1327 | - return $path_full; |
|
| 1264 | + static $path_base = null; |
|
| 1265 | + static $path_full = null; |
|
| 1266 | + if ($path_base == null) { |
|
| 1267 | + // Chemin standard depuis l'espace public |
|
| 1268 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1269 | + _DIR_RACINE . ':' . |
|
| 1270 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1271 | + _DIR_RACINE . 'prive/:' . |
|
| 1272 | + _DIR_RESTREINT; |
|
| 1273 | + // Ajouter squelettes/ |
|
| 1274 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1275 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1276 | + } |
|
| 1277 | + foreach (explode(':', $path) as $dir) { |
|
| 1278 | + if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1279 | + $dir .= "/"; |
|
| 1280 | + } |
|
| 1281 | + $path_base[] = $dir; |
|
| 1282 | + } |
|
| 1283 | + $path_full = $path_base; |
|
| 1284 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1285 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1286 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1287 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1288 | + } |
|
| 1289 | + } |
|
| 1290 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1291 | + } |
|
| 1292 | + if ($dir_path === null) { |
|
| 1293 | + return $path_full; |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + if (strlen($dir_path)) { |
|
| 1297 | + $tete = ""; |
|
| 1298 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1299 | + $tete = array_shift($path_base); |
|
| 1300 | + } |
|
| 1301 | + $dirs = array_reverse(explode(':', $dir_path)); |
|
| 1302 | + foreach ($dirs as $dir_path) { |
|
| 1303 | + #if ($dir_path{0}!='/') |
|
| 1304 | + # $dir_path = $dir_path; |
|
| 1305 | + if (substr($dir_path, -1) != '/') { |
|
| 1306 | + $dir_path .= "/"; |
|
| 1307 | + } |
|
| 1308 | + if (!in_array($dir_path, $path_base)) { |
|
| 1309 | + array_unshift($path_base, $dir_path); |
|
| 1310 | + } |
|
| 1311 | + } |
|
| 1312 | + if (strlen($tete)) { |
|
| 1313 | + array_unshift($path_base, $tete); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + $path_full = $path_base; |
|
| 1317 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1318 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1319 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1320 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1321 | + } |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1325 | + |
|
| 1326 | + return $path_full; |
|
| 1328 | 1327 | } |
| 1329 | 1328 | |
| 1330 | 1329 | /** |
@@ -1337,76 +1336,76 @@ discard block |
||
| 1337 | 1336 | * @return array Liste de chemins |
| 1338 | 1337 | **/ |
| 1339 | 1338 | function creer_chemin() { |
| 1340 | - $path_a = _chemin(); |
|
| 1341 | - static $c = ''; |
|
| 1339 | + $path_a = _chemin(); |
|
| 1340 | + static $c = ''; |
|
| 1342 | 1341 | |
| 1343 | - // on calcule le chemin si le dossier skel a change |
|
| 1344 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1345 | - // assurer le non plantage lors de la montee de version : |
|
| 1346 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1347 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1348 | - } |
|
| 1342 | + // on calcule le chemin si le dossier skel a change |
|
| 1343 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1344 | + // assurer le non plantage lors de la montee de version : |
|
| 1345 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1346 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1347 | + } |
|
| 1349 | 1348 | |
| 1350 | - return $path_a; |
|
| 1349 | + return $path_a; |
|
| 1351 | 1350 | } |
| 1352 | 1351 | |
| 1353 | 1352 | |
| 1354 | 1353 | function lister_themes_prives() { |
| 1355 | - static $themes = null; |
|
| 1356 | - if (is_null($themes)) { |
|
| 1357 | - // si pas encore definie |
|
| 1358 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1359 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1360 | - } |
|
| 1361 | - $themes = array(_SPIP_THEME_PRIVE); |
|
| 1362 | - // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1363 | - if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1364 | - $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1365 | - } else { |
|
| 1366 | - $prefs = array(); |
|
| 1367 | - } |
|
| 1368 | - if (is_string($prefs)) { |
|
| 1369 | - $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1370 | - } |
|
| 1371 | - if ( |
|
| 1372 | - ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1373 | - or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1374 | - and $theme != _SPIP_THEME_PRIVE |
|
| 1375 | - ) { |
|
| 1376 | - array_unshift($themes, $theme); |
|
| 1377 | - } // placer le theme choisi en tete |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - return $themes; |
|
| 1354 | + static $themes = null; |
|
| 1355 | + if (is_null($themes)) { |
|
| 1356 | + // si pas encore definie |
|
| 1357 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1358 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1359 | + } |
|
| 1360 | + $themes = array(_SPIP_THEME_PRIVE); |
|
| 1361 | + // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1362 | + if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1363 | + $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1364 | + } else { |
|
| 1365 | + $prefs = array(); |
|
| 1366 | + } |
|
| 1367 | + if (is_string($prefs)) { |
|
| 1368 | + $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1369 | + } |
|
| 1370 | + if ( |
|
| 1371 | + ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1372 | + or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1373 | + and $theme != _SPIP_THEME_PRIVE |
|
| 1374 | + ) { |
|
| 1375 | + array_unshift($themes, $theme); |
|
| 1376 | + } // placer le theme choisi en tete |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + return $themes; |
|
| 1381 | 1380 | } |
| 1382 | 1381 | |
| 1383 | 1382 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1384 | - static $themefiles = array(); |
|
| 1385 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1386 | - return $themefiles["$subdir$file"]; |
|
| 1387 | - } |
|
| 1388 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1389 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1390 | - if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1391 | - and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg" |
|
| 1392 | - and $f = find_in_theme("$file_svg_generique")) { |
|
| 1393 | - if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) { |
|
| 1394 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1395 | - } |
|
| 1396 | - else { |
|
| 1397 | - return $themefiles["$subdir$file"] = "$f?".$m[1]."px"; |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - $themes = lister_themes_prives(); |
|
| 1402 | - foreach ($themes as $theme) { |
|
| 1403 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1404 | - return $themefiles["$subdir$file"] = $f; |
|
| 1405 | - } |
|
| 1406 | - } |
|
| 1407 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1408 | - |
|
| 1409 | - return $themefiles["$subdir$file"] = ""; |
|
| 1383 | + static $themefiles = array(); |
|
| 1384 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1385 | + return $themefiles["$subdir$file"]; |
|
| 1386 | + } |
|
| 1387 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1388 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1389 | + if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1390 | + and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg" |
|
| 1391 | + and $f = find_in_theme("$file_svg_generique")) { |
|
| 1392 | + if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) { |
|
| 1393 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1394 | + } |
|
| 1395 | + else { |
|
| 1396 | + return $themefiles["$subdir$file"] = "$f?".$m[1]."px"; |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + $themes = lister_themes_prives(); |
|
| 1401 | + foreach ($themes as $theme) { |
|
| 1402 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1403 | + return $themefiles["$subdir$file"] = $f; |
|
| 1404 | + } |
|
| 1405 | + } |
|
| 1406 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1407 | + |
|
| 1408 | + return $themefiles["$subdir$file"] = ""; |
|
| 1410 | 1409 | } |
| 1411 | 1410 | |
| 1412 | 1411 | |
@@ -1430,31 +1429,31 @@ discard block |
||
| 1430 | 1429 | * sinon chaîne vide. |
| 1431 | 1430 | **/ |
| 1432 | 1431 | function chemin_image($icone) { |
| 1433 | - static $icone_renommer; |
|
| 1434 | - if ($p = strpos($icone, '?')) { |
|
| 1435 | - $icone = substr($icone,0, $p); |
|
| 1436 | - } |
|
| 1437 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1438 | - if (strpos($icone, "/") !== false and file_exists($icone)) { |
|
| 1439 | - return $icone; |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1443 | - if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1444 | - return $f; |
|
| 1445 | - } |
|
| 1446 | - // sinon passer par le module de renommage |
|
| 1447 | - if (is_null($icone_renommer)) { |
|
| 1448 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1449 | - } |
|
| 1450 | - if ($icone_renommer) { |
|
| 1451 | - list($icone, $fonction) = $icone_renommer($icone, ""); |
|
| 1452 | - if (file_exists($icone)) { |
|
| 1453 | - return $icone; |
|
| 1454 | - } |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1432 | + static $icone_renommer; |
|
| 1433 | + if ($p = strpos($icone, '?')) { |
|
| 1434 | + $icone = substr($icone,0, $p); |
|
| 1435 | + } |
|
| 1436 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1437 | + if (strpos($icone, "/") !== false and file_exists($icone)) { |
|
| 1438 | + return $icone; |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1442 | + if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1443 | + return $f; |
|
| 1444 | + } |
|
| 1445 | + // sinon passer par le module de renommage |
|
| 1446 | + if (is_null($icone_renommer)) { |
|
| 1447 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1448 | + } |
|
| 1449 | + if ($icone_renommer) { |
|
| 1450 | + list($icone, $fonction) = $icone_renommer($icone, ""); |
|
| 1451 | + if (file_exists($icone)) { |
|
| 1452 | + return $icone; |
|
| 1453 | + } |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1458 | 1457 | } |
| 1459 | 1458 | |
| 1460 | 1459 | // |
@@ -1492,123 +1491,123 @@ discard block |
||
| 1492 | 1491 | * - false : fichier introuvable |
| 1493 | 1492 | **/ |
| 1494 | 1493 | function find_in_path($file, $dirname = '', $include = false) { |
| 1495 | - static $dirs = array(); |
|
| 1496 | - static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743 |
|
| 1497 | - static $c = ''; |
|
| 1498 | - |
|
| 1499 | - // on calcule le chemin si le dossier skel a change |
|
| 1500 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1501 | - // assurer le non plantage lors de la montee de version : |
|
| 1502 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1503 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1504 | - } |
|
| 1505 | - |
|
| 1506 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1507 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1508 | - return false; |
|
| 1509 | - } |
|
| 1510 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1511 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1512 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1516 | - } |
|
| 1517 | - |
|
| 1518 | - $a = strrpos($file, '/'); |
|
| 1519 | - if ($a !== false) { |
|
| 1520 | - $dirname .= substr($file, 0, ++$a); |
|
| 1521 | - $file = substr($file, $a); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - foreach (creer_chemin() as $dir) { |
|
| 1525 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1526 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1527 | - } |
|
| 1528 | - if ($dirs[$a]) { |
|
| 1529 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1530 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1531 | - include_once _ROOT_CWD . $a; |
|
| 1532 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1533 | - } |
|
| 1534 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1535 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1536 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1537 | - return $a; |
|
| 1538 | - } |
|
| 1539 | - define('_SAUVER_CHEMIN', true); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - if ($include) { |
|
| 1548 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1549 | - if ($include === 'required') { |
|
| 1550 | - echo '<pre>', |
|
| 1551 | - "<strong>Erreur Fatale</strong><br />"; |
|
| 1552 | - if (function_exists('debug_print_backtrace')) { |
|
| 1553 | - echo debug_print_backtrace(); |
|
| 1554 | - } |
|
| 1555 | - echo '</pre>'; |
|
| 1556 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1557 | - } |
|
| 1558 | - } |
|
| 1559 | - |
|
| 1560 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1561 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1562 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1563 | - return false; |
|
| 1564 | - } |
|
| 1565 | - define('_SAUVER_CHEMIN', true); |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1494 | + static $dirs = array(); |
|
| 1495 | + static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743 |
|
| 1496 | + static $c = ''; |
|
| 1497 | + |
|
| 1498 | + // on calcule le chemin si le dossier skel a change |
|
| 1499 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1500 | + // assurer le non plantage lors de la montee de version : |
|
| 1501 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1502 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1506 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1507 | + return false; |
|
| 1508 | + } |
|
| 1509 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1510 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1511 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + $a = strrpos($file, '/'); |
|
| 1518 | + if ($a !== false) { |
|
| 1519 | + $dirname .= substr($file, 0, ++$a); |
|
| 1520 | + $file = substr($file, $a); |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + foreach (creer_chemin() as $dir) { |
|
| 1524 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1525 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1526 | + } |
|
| 1527 | + if ($dirs[$a]) { |
|
| 1528 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1529 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1530 | + include_once _ROOT_CWD . $a; |
|
| 1531 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1532 | + } |
|
| 1533 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1534 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1535 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1536 | + return $a; |
|
| 1537 | + } |
|
| 1538 | + define('_SAUVER_CHEMIN', true); |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + if ($include) { |
|
| 1547 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1548 | + if ($include === 'required') { |
|
| 1549 | + echo '<pre>', |
|
| 1550 | + "<strong>Erreur Fatale</strong><br />"; |
|
| 1551 | + if (function_exists('debug_print_backtrace')) { |
|
| 1552 | + echo debug_print_backtrace(); |
|
| 1553 | + } |
|
| 1554 | + echo '</pre>'; |
|
| 1555 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1556 | + } |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1560 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1561 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1562 | + return false; |
|
| 1563 | + } |
|
| 1564 | + define('_SAUVER_CHEMIN', true); |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1569 | 1568 | } |
| 1570 | 1569 | |
| 1571 | 1570 | function clear_path_cache() { |
| 1572 | - $GLOBALS['path_files'] = array(); |
|
| 1573 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1571 | + $GLOBALS['path_files'] = array(); |
|
| 1572 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1574 | 1573 | } |
| 1575 | 1574 | |
| 1576 | 1575 | function load_path_cache() { |
| 1577 | - // charger le path des plugins |
|
| 1578 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1579 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1580 | - } |
|
| 1581 | - $GLOBALS['path_files'] = array(); |
|
| 1582 | - // si le visiteur est admin, |
|
| 1583 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1584 | - if ( |
|
| 1585 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1586 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1587 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1588 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1589 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1590 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1591 | - !_request('var_mode') |
|
| 1592 | - ) { |
|
| 1593 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1594 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1595 | - // mais si semble corrompu on relit avec un verrou |
|
| 1596 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1597 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1598 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1599 | - $GLOBALS['path_files'] = array(); |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - } |
|
| 1603 | - } |
|
| 1576 | + // charger le path des plugins |
|
| 1577 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1578 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1579 | + } |
|
| 1580 | + $GLOBALS['path_files'] = array(); |
|
| 1581 | + // si le visiteur est admin, |
|
| 1582 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1583 | + if ( |
|
| 1584 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1585 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1586 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1587 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1588 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1589 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1590 | + !_request('var_mode') |
|
| 1591 | + ) { |
|
| 1592 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1593 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1594 | + // mais si semble corrompu on relit avec un verrou |
|
| 1595 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1596 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1597 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1598 | + $GLOBALS['path_files'] = array(); |
|
| 1599 | + } |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + } |
|
| 1604 | 1603 | } |
| 1605 | 1604 | |
| 1606 | 1605 | function save_path_cache() { |
| 1607 | - if (defined('_SAUVER_CHEMIN') |
|
| 1608 | - and _SAUVER_CHEMIN |
|
| 1609 | - ) { |
|
| 1610 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1611 | - } |
|
| 1606 | + if (defined('_SAUVER_CHEMIN') |
|
| 1607 | + and _SAUVER_CHEMIN |
|
| 1608 | + ) { |
|
| 1609 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1610 | + } |
|
| 1612 | 1611 | } |
| 1613 | 1612 | |
| 1614 | 1613 | |
@@ -1628,33 +1627,33 @@ discard block |
||
| 1628 | 1627 | * @return array |
| 1629 | 1628 | */ |
| 1630 | 1629 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1631 | - $liste_fichiers = array(); |
|
| 1632 | - $maxfiles = 10000; |
|
| 1633 | - |
|
| 1634 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1635 | - // on a pas encore inclus flock.php |
|
| 1636 | - if (!function_exists('preg_files')) { |
|
| 1637 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - // Parcourir le chemin |
|
| 1641 | - foreach (creer_chemin() as $d) { |
|
| 1642 | - $f = $d . $dir; |
|
| 1643 | - if (@is_dir($f)) { |
|
| 1644 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs); |
|
| 1645 | - foreach ($liste as $chemin) { |
|
| 1646 | - $nom = basename($chemin); |
|
| 1647 | - // ne prendre que les fichiers pas deja trouves |
|
| 1648 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1649 | - // les autres sont donc masques |
|
| 1650 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1651 | - $liste_fichiers[$nom] = $chemin; |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - } |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - return $liste_fichiers; |
|
| 1630 | + $liste_fichiers = array(); |
|
| 1631 | + $maxfiles = 10000; |
|
| 1632 | + |
|
| 1633 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1634 | + // on a pas encore inclus flock.php |
|
| 1635 | + if (!function_exists('preg_files')) { |
|
| 1636 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + // Parcourir le chemin |
|
| 1640 | + foreach (creer_chemin() as $d) { |
|
| 1641 | + $f = $d . $dir; |
|
| 1642 | + if (@is_dir($f)) { |
|
| 1643 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs); |
|
| 1644 | + foreach ($liste as $chemin) { |
|
| 1645 | + $nom = basename($chemin); |
|
| 1646 | + // ne prendre que les fichiers pas deja trouves |
|
| 1647 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1648 | + // les autres sont donc masques |
|
| 1649 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1650 | + $liste_fichiers[$nom] = $chemin; |
|
| 1651 | + } |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + return $liste_fichiers; |
|
| 1658 | 1657 | } |
| 1659 | 1658 | |
| 1660 | 1659 | /** |
@@ -1666,17 +1665,17 @@ discard block |
||
| 1666 | 1665 | * @return bool |
| 1667 | 1666 | */ |
| 1668 | 1667 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1669 | - static $autsanscookie = array('install', 'base_repair'); |
|
| 1668 | + static $autsanscookie = array('install', 'base_repair'); |
|
| 1670 | 1669 | |
| 1671 | - if (in_array($nom, $autsanscookie)) { |
|
| 1672 | - if (test_espace_prive()){ |
|
| 1673 | - include_spip('base/connect_sql'); |
|
| 1674 | - if (!$strict or !spip_connect()){ |
|
| 1675 | - return true; |
|
| 1676 | - } |
|
| 1677 | - } |
|
| 1678 | - } |
|
| 1679 | - return false; |
|
| 1670 | + if (in_array($nom, $autsanscookie)) { |
|
| 1671 | + if (test_espace_prive()){ |
|
| 1672 | + include_spip('base/connect_sql'); |
|
| 1673 | + if (!$strict or !spip_connect()){ |
|
| 1674 | + return true; |
|
| 1675 | + } |
|
| 1676 | + } |
|
| 1677 | + } |
|
| 1678 | + return false; |
|
| 1680 | 1679 | } |
| 1681 | 1680 | |
| 1682 | 1681 | /** |
@@ -1702,99 +1701,99 @@ discard block |
||
| 1702 | 1701 | * (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip) |
| 1703 | 1702 | */ |
| 1704 | 1703 | function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 1705 | - if ($public === null) { |
|
| 1706 | - $public = !test_espace_prive(); |
|
| 1707 | - } |
|
| 1708 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1709 | - |
|
| 1710 | - if (!$public) { |
|
| 1711 | - if (!$entite) { |
|
| 1712 | - return ''; |
|
| 1713 | - } |
|
| 1714 | - if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1715 | - include_spip('inc/urls'); |
|
| 1716 | - } |
|
| 1717 | - $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1718 | - } else { |
|
| 1719 | - if ($type === null) { |
|
| 1720 | - $type = (isset($GLOBALS['type_urls'])) |
|
| 1721 | - ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options |
|
| 1722 | - : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues |
|
| 1723 | - ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - $f = charger_fonction($type, 'urls', true); |
|
| 1727 | - // se rabattre sur les urls page si les urls perso non dispo |
|
| 1728 | - if (!$f) { |
|
| 1729 | - $f = charger_fonction('page', 'urls', true); |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1733 | - // sinon on veut effectuer le passage id ==> URL |
|
| 1734 | - if (!$entite) { |
|
| 1735 | - return $f; |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1739 | - // base distante |
|
| 1740 | - if (is_string($public) |
|
| 1741 | - and $g = charger_fonction('connect', 'urls', true) |
|
| 1742 | - ) { |
|
| 1743 | - $f = $g; |
|
| 1744 | - } |
|
| 1745 | - |
|
| 1746 | - $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1747 | - |
|
| 1748 | - } |
|
| 1749 | - if ($res) { |
|
| 1750 | - return $res; |
|
| 1751 | - } |
|
| 1752 | - // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1753 | - if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1754 | - if (!function_exists($f .= '_dist')) { |
|
| 1755 | - $f = ''; |
|
| 1756 | - } |
|
| 1757 | - } |
|
| 1758 | - if ($f) { |
|
| 1759 | - $url = $f($id, $args, $ancre); |
|
| 1760 | - if (strlen($args)) { |
|
| 1761 | - $url .= strstr($url, '?') |
|
| 1762 | - ? '&' . $args |
|
| 1763 | - : '?' . $args; |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - return $url; |
|
| 1767 | - } |
|
| 1768 | - // On a ete gentil mais la .... |
|
| 1769 | - spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1770 | - |
|
| 1771 | - return ''; |
|
| 1704 | + if ($public === null) { |
|
| 1705 | + $public = !test_espace_prive(); |
|
| 1706 | + } |
|
| 1707 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1708 | + |
|
| 1709 | + if (!$public) { |
|
| 1710 | + if (!$entite) { |
|
| 1711 | + return ''; |
|
| 1712 | + } |
|
| 1713 | + if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1714 | + include_spip('inc/urls'); |
|
| 1715 | + } |
|
| 1716 | + $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1717 | + } else { |
|
| 1718 | + if ($type === null) { |
|
| 1719 | + $type = (isset($GLOBALS['type_urls'])) |
|
| 1720 | + ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options |
|
| 1721 | + : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues |
|
| 1722 | + ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + $f = charger_fonction($type, 'urls', true); |
|
| 1726 | + // se rabattre sur les urls page si les urls perso non dispo |
|
| 1727 | + if (!$f) { |
|
| 1728 | + $f = charger_fonction('page', 'urls', true); |
|
| 1729 | + } |
|
| 1730 | + |
|
| 1731 | + // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1732 | + // sinon on veut effectuer le passage id ==> URL |
|
| 1733 | + if (!$entite) { |
|
| 1734 | + return $f; |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1738 | + // base distante |
|
| 1739 | + if (is_string($public) |
|
| 1740 | + and $g = charger_fonction('connect', 'urls', true) |
|
| 1741 | + ) { |
|
| 1742 | + $f = $g; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1746 | + |
|
| 1747 | + } |
|
| 1748 | + if ($res) { |
|
| 1749 | + return $res; |
|
| 1750 | + } |
|
| 1751 | + // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1752 | + if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1753 | + if (!function_exists($f .= '_dist')) { |
|
| 1754 | + $f = ''; |
|
| 1755 | + } |
|
| 1756 | + } |
|
| 1757 | + if ($f) { |
|
| 1758 | + $url = $f($id, $args, $ancre); |
|
| 1759 | + if (strlen($args)) { |
|
| 1760 | + $url .= strstr($url, '?') |
|
| 1761 | + ? '&' . $args |
|
| 1762 | + : '?' . $args; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + return $url; |
|
| 1766 | + } |
|
| 1767 | + // On a ete gentil mais la .... |
|
| 1768 | + spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1769 | + |
|
| 1770 | + return ''; |
|
| 1772 | 1771 | } |
| 1773 | 1772 | |
| 1774 | 1773 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 1775 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1776 | - $url = generer_url_ecrire($exec, $args); |
|
| 1777 | - if (intval($id)) { |
|
| 1778 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1779 | - } else { |
|
| 1780 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1781 | - } |
|
| 1782 | - if ($ancre) { |
|
| 1783 | - $url = ancre_url($url, $ancre); |
|
| 1784 | - } |
|
| 1774 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1775 | + $url = generer_url_ecrire($exec, $args); |
|
| 1776 | + if (intval($id)) { |
|
| 1777 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1778 | + } else { |
|
| 1779 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1780 | + } |
|
| 1781 | + if ($ancre) { |
|
| 1782 | + $url = ancre_url($url, $ancre); |
|
| 1783 | + } |
|
| 1785 | 1784 | |
| 1786 | - return $url; |
|
| 1785 | + return $url; |
|
| 1787 | 1786 | } |
| 1788 | 1787 | |
| 1789 | 1788 | // http://code.spip.net/@urls_connect_dist |
| 1790 | 1789 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1791 | - include_spip('base/connect_sql'); |
|
| 1792 | - $id_type = id_table_objet($entite, $public); |
|
| 1790 | + include_spip('base/connect_sql'); |
|
| 1791 | + $id_type = id_table_objet($entite, $public); |
|
| 1793 | 1792 | |
| 1794 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1795 | - . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1796 | - . (!$args ? '' : "&$args") |
|
| 1797 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1793 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1794 | + . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1795 | + . (!$args ? '' : "&$args") |
|
| 1796 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1798 | 1797 | } |
| 1799 | 1798 | |
| 1800 | 1799 | |
@@ -1805,32 +1804,32 @@ discard block |
||
| 1805 | 1804 | * @return string |
| 1806 | 1805 | */ |
| 1807 | 1806 | function urlencode_1738($url) { |
| 1808 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1809 | - $uri = ''; |
|
| 1810 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 1811 | - if (ord($a = $url[$i]) > 127) { |
|
| 1812 | - $a = rawurlencode($a); |
|
| 1813 | - } |
|
| 1814 | - $uri .= $a; |
|
| 1815 | - } |
|
| 1816 | - $url = $uri; |
|
| 1817 | - } |
|
| 1807 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1808 | + $uri = ''; |
|
| 1809 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 1810 | + if (ord($a = $url[$i]) > 127) { |
|
| 1811 | + $a = rawurlencode($a); |
|
| 1812 | + } |
|
| 1813 | + $uri .= $a; |
|
| 1814 | + } |
|
| 1815 | + $url = $uri; |
|
| 1816 | + } |
|
| 1818 | 1817 | |
| 1819 | - return quote_amp($url); |
|
| 1818 | + return quote_amp($url); |
|
| 1820 | 1819 | } |
| 1821 | 1820 | |
| 1822 | 1821 | // http://code.spip.net/@generer_url_entite_absolue |
| 1823 | 1822 | function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) { |
| 1824 | - if (!$connect) { |
|
| 1825 | - $connect = true; |
|
| 1826 | - } |
|
| 1827 | - $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1828 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 1829 | - include_spip('inc/filtres_mini'); |
|
| 1830 | - $h = url_absolue($h); |
|
| 1831 | - } |
|
| 1823 | + if (!$connect) { |
|
| 1824 | + $connect = true; |
|
| 1825 | + } |
|
| 1826 | + $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1827 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 1828 | + include_spip('inc/filtres_mini'); |
|
| 1829 | + $h = url_absolue($h); |
|
| 1830 | + } |
|
| 1832 | 1831 | |
| 1833 | - return $h; |
|
| 1832 | + return $h; |
|
| 1834 | 1833 | } |
| 1835 | 1834 | |
| 1836 | 1835 | |
@@ -1846,11 +1845,11 @@ discard block |
||
| 1846 | 1845 | * true si la valeur est considérée active ; false sinon. |
| 1847 | 1846 | **/ |
| 1848 | 1847 | function test_valeur_serveur($truc) { |
| 1849 | - if (!$truc) { |
|
| 1850 | - return false; |
|
| 1851 | - } |
|
| 1848 | + if (!$truc) { |
|
| 1849 | + return false; |
|
| 1850 | + } |
|
| 1852 | 1851 | |
| 1853 | - return (strtolower($truc) !== 'off'); |
|
| 1852 | + return (strtolower($truc) !== 'off'); |
|
| 1854 | 1853 | } |
| 1855 | 1854 | |
| 1856 | 1855 | // |
@@ -1878,80 +1877,80 @@ discard block |
||
| 1878 | 1877 | */ |
| 1879 | 1878 | function url_de_base($profondeur = null) { |
| 1880 | 1879 | |
| 1881 | - static $url = array(); |
|
| 1882 | - if (is_array($profondeur)) { |
|
| 1883 | - return $url = $profondeur; |
|
| 1884 | - } |
|
| 1885 | - if ($profondeur === false) { |
|
| 1886 | - return $url; |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - if (is_null($profondeur)) { |
|
| 1890 | - $profondeur = $GLOBALS['profondeur_url']; |
|
| 1891 | - } |
|
| 1892 | - |
|
| 1893 | - if (isset($url[$profondeur])) { |
|
| 1894 | - return $url[$profondeur]; |
|
| 1895 | - } |
|
| 1896 | - |
|
| 1897 | - $http = 'http'; |
|
| 1898 | - |
|
| 1899 | - if ( |
|
| 1900 | - isset($_SERVER["SCRIPT_URI"]) |
|
| 1901 | - and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' |
|
| 1902 | - ) { |
|
| 1903 | - $http = 'https'; |
|
| 1904 | - } elseif ( |
|
| 1905 | - isset($_SERVER['HTTPS']) |
|
| 1906 | - and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1907 | - ) { |
|
| 1908 | - $http = 'https'; |
|
| 1909 | - } |
|
| 1910 | - |
|
| 1911 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 1912 | - $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 1913 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 1914 | - if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 1915 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 1916 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 1917 | - $http = $scheme; |
|
| 1918 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 1919 | - } |
|
| 1920 | - } |
|
| 1921 | - if (isset($_SERVER['SERVER_PORT']) |
|
| 1922 | - and $port = $_SERVER['SERVER_PORT'] |
|
| 1923 | - and strpos($host, ":") == false |
|
| 1924 | - ) { |
|
| 1925 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 1926 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 1927 | - } |
|
| 1928 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 1929 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 1930 | - } |
|
| 1931 | - if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 1932 | - $host .= ":$port"; |
|
| 1933 | - } |
|
| 1934 | - if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 1935 | - $host .= ":$port"; |
|
| 1936 | - } |
|
| 1937 | - } |
|
| 1938 | - |
|
| 1939 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 1940 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 1941 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 1942 | - } else { |
|
| 1943 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 1944 | - if (!empty($_SERVER['QUERY_STRING']) |
|
| 1945 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 1946 | - ) { |
|
| 1947 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 1948 | - } |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 1953 | - |
|
| 1954 | - return $url[$profondeur]; |
|
| 1880 | + static $url = array(); |
|
| 1881 | + if (is_array($profondeur)) { |
|
| 1882 | + return $url = $profondeur; |
|
| 1883 | + } |
|
| 1884 | + if ($profondeur === false) { |
|
| 1885 | + return $url; |
|
| 1886 | + } |
|
| 1887 | + |
|
| 1888 | + if (is_null($profondeur)) { |
|
| 1889 | + $profondeur = $GLOBALS['profondeur_url']; |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + if (isset($url[$profondeur])) { |
|
| 1893 | + return $url[$profondeur]; |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + $http = 'http'; |
|
| 1897 | + |
|
| 1898 | + if ( |
|
| 1899 | + isset($_SERVER["SCRIPT_URI"]) |
|
| 1900 | + and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' |
|
| 1901 | + ) { |
|
| 1902 | + $http = 'https'; |
|
| 1903 | + } elseif ( |
|
| 1904 | + isset($_SERVER['HTTPS']) |
|
| 1905 | + and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1906 | + ) { |
|
| 1907 | + $http = 'https'; |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 1911 | + $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 1912 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 1913 | + if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 1914 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 1915 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 1916 | + $http = $scheme; |
|
| 1917 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 1918 | + } |
|
| 1919 | + } |
|
| 1920 | + if (isset($_SERVER['SERVER_PORT']) |
|
| 1921 | + and $port = $_SERVER['SERVER_PORT'] |
|
| 1922 | + and strpos($host, ":") == false |
|
| 1923 | + ) { |
|
| 1924 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 1925 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 1926 | + } |
|
| 1927 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 1928 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 1929 | + } |
|
| 1930 | + if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 1931 | + $host .= ":$port"; |
|
| 1932 | + } |
|
| 1933 | + if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 1934 | + $host .= ":$port"; |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 1939 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 1940 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 1941 | + } else { |
|
| 1942 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 1943 | + if (!empty($_SERVER['QUERY_STRING']) |
|
| 1944 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 1945 | + ) { |
|
| 1946 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 1947 | + } |
|
| 1948 | + } |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 1952 | + |
|
| 1953 | + return $url[$profondeur]; |
|
| 1955 | 1954 | } |
| 1956 | 1955 | |
| 1957 | 1956 | /** |
@@ -1964,26 +1963,26 @@ discard block |
||
| 1964 | 1963 | * @return string |
| 1965 | 1964 | */ |
| 1966 | 1965 | function url_de_($http, $host, $request, $prof = 0) { |
| 1967 | - $prof = max($prof, 0); |
|
| 1966 | + $prof = max($prof, 0); |
|
| 1968 | 1967 | |
| 1969 | - $myself = ltrim($request, '/'); |
|
| 1970 | - # supprimer la chaine de GET |
|
| 1971 | - list($myself) = explode('?', $myself); |
|
| 1972 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 1973 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 1974 | - if (strpos($myself,'://') !== false) { |
|
| 1975 | - $myself = explode('://',$myself); |
|
| 1976 | - array_shift($myself); |
|
| 1977 | - $myself = implode('://',$myself); |
|
| 1978 | - $myself = explode('/',$myself); |
|
| 1979 | - array_shift($myself); |
|
| 1980 | - $myself = implode('/',$myself); |
|
| 1981 | - } |
|
| 1982 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 1968 | + $myself = ltrim($request, '/'); |
|
| 1969 | + # supprimer la chaine de GET |
|
| 1970 | + list($myself) = explode('?', $myself); |
|
| 1971 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 1972 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 1973 | + if (strpos($myself,'://') !== false) { |
|
| 1974 | + $myself = explode('://',$myself); |
|
| 1975 | + array_shift($myself); |
|
| 1976 | + $myself = implode('://',$myself); |
|
| 1977 | + $myself = explode('/',$myself); |
|
| 1978 | + array_shift($myself); |
|
| 1979 | + $myself = implode('/',$myself); |
|
| 1980 | + } |
|
| 1981 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 1983 | 1982 | |
| 1984 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 1983 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 1985 | 1984 | |
| 1986 | - return $url; |
|
| 1985 | + return $url; |
|
| 1987 | 1986 | } |
| 1988 | 1987 | |
| 1989 | 1988 | |
@@ -2018,26 +2017,26 @@ discard block |
||
| 2018 | 2017 | * @return string URL |
| 2019 | 2018 | **/ |
| 2020 | 2019 | function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) { |
| 2021 | - if (!$rel) { |
|
| 2022 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2023 | - } else { |
|
| 2024 | - if (!is_string($rel)) { |
|
| 2025 | - $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
|
| 2026 | - ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2027 | - } |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
|
| 2031 | - if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2032 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2033 | - } elseif ($args) { |
|
| 2034 | - $args = "?$args"; |
|
| 2035 | - } |
|
| 2036 | - if ($ancre) { |
|
| 2037 | - $args .= "#$ancre"; |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2020 | + if (!$rel) { |
|
| 2021 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2022 | + } else { |
|
| 2023 | + if (!is_string($rel)) { |
|
| 2024 | + $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
|
| 2025 | + ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2026 | + } |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
|
| 2030 | + if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2031 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2032 | + } elseif ($args) { |
|
| 2033 | + $args = "?$args"; |
|
| 2034 | + } |
|
| 2035 | + if ($ancre) { |
|
| 2036 | + $args .= "#$ancre"; |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2041 | 2040 | } |
| 2042 | 2041 | |
| 2043 | 2042 | // |
@@ -2059,12 +2058,12 @@ discard block |
||
| 2059 | 2058 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2060 | 2059 | **/ |
| 2061 | 2060 | function get_spip_script($default = '') { |
| 2062 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2063 | - if (_SPIP_SCRIPT) { |
|
| 2064 | - return _SPIP_SCRIPT; |
|
| 2065 | - } else { |
|
| 2066 | - return $default; |
|
| 2067 | - } |
|
| 2061 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2062 | + if (_SPIP_SCRIPT) { |
|
| 2063 | + return _SPIP_SCRIPT; |
|
| 2064 | + } else { |
|
| 2065 | + return $default; |
|
| 2066 | + } |
|
| 2068 | 2067 | } |
| 2069 | 2068 | |
| 2070 | 2069 | /** |
@@ -2093,39 +2092,39 @@ discard block |
||
| 2093 | 2092 | * @return string URL |
| 2094 | 2093 | **/ |
| 2095 | 2094 | function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') { |
| 2096 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2097 | - // standardiser vers la nouvelle API |
|
| 2098 | - |
|
| 2099 | - if (!$action) { |
|
| 2100 | - $action = get_spip_script(); |
|
| 2101 | - } |
|
| 2102 | - if ($script) { |
|
| 2103 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - if ($args) { |
|
| 2107 | - if (is_array($args)) { |
|
| 2108 | - $r = ''; |
|
| 2109 | - foreach ($args as $k => $v) { |
|
| 2110 | - $r .= '&' . $k . '=' . $v; |
|
| 2111 | - } |
|
| 2112 | - $args = substr($r, 1); |
|
| 2113 | - } |
|
| 2114 | - $action .= |
|
| 2115 | - (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2116 | - } |
|
| 2117 | - if (!$no_entities) { |
|
| 2118 | - $action = quote_amp($action); |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2122 | - return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action")); |
|
| 2095 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2096 | + // standardiser vers la nouvelle API |
|
| 2097 | + |
|
| 2098 | + if (!$action) { |
|
| 2099 | + $action = get_spip_script(); |
|
| 2100 | + } |
|
| 2101 | + if ($script) { |
|
| 2102 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2103 | + } |
|
| 2104 | + |
|
| 2105 | + if ($args) { |
|
| 2106 | + if (is_array($args)) { |
|
| 2107 | + $r = ''; |
|
| 2108 | + foreach ($args as $k => $v) { |
|
| 2109 | + $r .= '&' . $k . '=' . $v; |
|
| 2110 | + } |
|
| 2111 | + $args = substr($r, 1); |
|
| 2112 | + } |
|
| 2113 | + $action .= |
|
| 2114 | + (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2115 | + } |
|
| 2116 | + if (!$no_entities) { |
|
| 2117 | + $action = quote_amp($action); |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2121 | + return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action")); |
|
| 2123 | 2122 | } |
| 2124 | 2123 | |
| 2125 | 2124 | // http://code.spip.net/@generer_url_prive |
| 2126 | 2125 | function generer_url_prive($script, $args = "", $no_entities = false) { |
| 2127 | 2126 | |
| 2128 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2127 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2129 | 2128 | } |
| 2130 | 2129 | |
| 2131 | 2130 | // Pour les formulaires en methode POST, |
@@ -2150,19 +2149,19 @@ discard block |
||
| 2150 | 2149 | **/ |
| 2151 | 2150 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2152 | 2151 | |
| 2153 | - $script1 = explode('&', $script); |
|
| 2154 | - $script1 = reset($script1); |
|
| 2152 | + $script1 = explode('&', $script); |
|
| 2153 | + $script1 = reset($script1); |
|
| 2155 | 2154 | |
| 2156 | - return "<form action='" |
|
| 2157 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2158 | - . "' " |
|
| 2159 | - . ($atts ? $atts : " method='post'") |
|
| 2160 | - . "><div>\n" |
|
| 2161 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2162 | - . $corps |
|
| 2163 | - . (!$submit ? '' : |
|
| 2164 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>")) |
|
| 2165 | - . "</div></form>\n"; |
|
| 2155 | + return "<form action='" |
|
| 2156 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2157 | + . "' " |
|
| 2158 | + . ($atts ? $atts : " method='post'") |
|
| 2159 | + . "><div>\n" |
|
| 2160 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2161 | + . $corps |
|
| 2162 | + . (!$submit ? '' : |
|
| 2163 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>")) |
|
| 2164 | + . "</div></form>\n"; |
|
| 2166 | 2165 | } |
| 2167 | 2166 | |
| 2168 | 2167 | /** |
@@ -2179,22 +2178,22 @@ discard block |
||
| 2179 | 2178 | * @return string |
| 2180 | 2179 | */ |
| 2181 | 2180 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2182 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2183 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2184 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2185 | - $h = (_DIR_RACINE and !$public) |
|
| 2186 | - ? generer_url_ecrire(_request('exec')) |
|
| 2187 | - : generer_url_public(); |
|
| 2181 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2182 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2183 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2184 | + $h = (_DIR_RACINE and !$public) |
|
| 2185 | + ? generer_url_ecrire(_request('exec')) |
|
| 2186 | + : generer_url_public(); |
|
| 2188 | 2187 | |
| 2189 | - return "\n<form action='" . |
|
| 2190 | - $h . |
|
| 2191 | - "'" . |
|
| 2192 | - $atts . |
|
| 2193 | - ">\n" . |
|
| 2194 | - "<div>" . |
|
| 2195 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2196 | - $corps . |
|
| 2197 | - "</div></form>"; |
|
| 2188 | + return "\n<form action='" . |
|
| 2189 | + $h . |
|
| 2190 | + "'" . |
|
| 2191 | + $atts . |
|
| 2192 | + ">\n" . |
|
| 2193 | + "<div>" . |
|
| 2194 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2195 | + $corps . |
|
| 2196 | + "</div></form>"; |
|
| 2198 | 2197 | } |
| 2199 | 2198 | |
| 2200 | 2199 | /** |
@@ -2213,22 +2212,22 @@ discard block |
||
| 2213 | 2212 | * URL |
| 2214 | 2213 | */ |
| 2215 | 2214 | function generer_url_action($script, $args = "", $no_entities = false, $public = false) { |
| 2216 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2217 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2218 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2219 | - $url = (_DIR_RACINE and !$public) |
|
| 2220 | - ? generer_url_ecrire(_request('exec')) |
|
| 2221 | - : generer_url_public('', '', false, false); |
|
| 2222 | - $url = parametre_url($url, 'action', $script); |
|
| 2223 | - if ($args) { |
|
| 2224 | - $url .= quote_amp('&' . $args); |
|
| 2225 | - } |
|
| 2215 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2216 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2217 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2218 | + $url = (_DIR_RACINE and !$public) |
|
| 2219 | + ? generer_url_ecrire(_request('exec')) |
|
| 2220 | + : generer_url_public('', '', false, false); |
|
| 2221 | + $url = parametre_url($url, 'action', $script); |
|
| 2222 | + if ($args) { |
|
| 2223 | + $url .= quote_amp('&' . $args); |
|
| 2224 | + } |
|
| 2226 | 2225 | |
| 2227 | - if ($no_entities) { |
|
| 2228 | - $url = str_replace('&', '&', $url); |
|
| 2229 | - } |
|
| 2226 | + if ($no_entities) { |
|
| 2227 | + $url = str_replace('&', '&', $url); |
|
| 2228 | + } |
|
| 2230 | 2229 | |
| 2231 | - return $url; |
|
| 2230 | + return $url; |
|
| 2232 | 2231 | } |
| 2233 | 2232 | |
| 2234 | 2233 | |
@@ -2241,8 +2240,8 @@ discard block |
||
| 2241 | 2240 | * @param string $ta Répertoire temporaire accessible |
| 2242 | 2241 | */ |
| 2243 | 2242 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2244 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2245 | - spip_initialisation_suite(); |
|
| 2243 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2244 | + spip_initialisation_suite(); |
|
| 2246 | 2245 | } |
| 2247 | 2246 | |
| 2248 | 2247 | /** |
@@ -2262,315 +2261,315 @@ discard block |
||
| 2262 | 2261 | * @param string $ta Répertoire temporaire accessible |
| 2263 | 2262 | */ |
| 2264 | 2263 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2265 | - static $too_late = 0; |
|
| 2266 | - if ($too_late++) { |
|
| 2267 | - return; |
|
| 2268 | - } |
|
| 2269 | - |
|
| 2270 | - // Declaration des repertoires |
|
| 2271 | - |
|
| 2272 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2273 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2274 | - define('_DIR_PLUGINS', _DIR_RACINE . "plugins/"); |
|
| 2275 | - } |
|
| 2276 | - |
|
| 2277 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2278 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2279 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/"); |
|
| 2280 | - } |
|
| 2281 | - |
|
| 2282 | - // le nom du repertoire des librairies |
|
| 2283 | - if (!defined('_DIR_LIB')) { |
|
| 2284 | - define('_DIR_LIB', _DIR_RACINE . "lib/"); |
|
| 2285 | - } |
|
| 2286 | - |
|
| 2287 | - if (!defined('_DIR_IMG')) { |
|
| 2288 | - define('_DIR_IMG', $pa); |
|
| 2289 | - } |
|
| 2290 | - if (!defined('_DIR_LOGOS')) { |
|
| 2291 | - define('_DIR_LOGOS', $pa); |
|
| 2292 | - } |
|
| 2293 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2294 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/"); |
|
| 2295 | - } |
|
| 2296 | - |
|
| 2297 | - if (!defined('_DIR_DUMP')) { |
|
| 2298 | - define('_DIR_DUMP', $ti . "dump/"); |
|
| 2299 | - } |
|
| 2300 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2301 | - define('_DIR_SESSIONS', $ti . "sessions/"); |
|
| 2302 | - } |
|
| 2303 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2304 | - define('_DIR_TRANSFERT', $ti . "upload/"); |
|
| 2305 | - } |
|
| 2306 | - if (!defined('_DIR_CACHE')) { |
|
| 2307 | - define('_DIR_CACHE', $ti . "cache/"); |
|
| 2308 | - } |
|
| 2309 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2310 | - define('_DIR_CACHE_XML', _DIR_CACHE . "xml/"); |
|
| 2311 | - } |
|
| 2312 | - if (!defined('_DIR_SKELS')) { |
|
| 2313 | - define('_DIR_SKELS', _DIR_CACHE . "skel/"); |
|
| 2314 | - } |
|
| 2315 | - if (!defined('_DIR_AIDE')) { |
|
| 2316 | - define('_DIR_AIDE', _DIR_CACHE . "aide/"); |
|
| 2317 | - } |
|
| 2318 | - if (!defined('_DIR_TMP')) { |
|
| 2319 | - define('_DIR_TMP', $ti); |
|
| 2320 | - } |
|
| 2321 | - |
|
| 2322 | - if (!defined('_DIR_VAR')) { |
|
| 2323 | - define('_DIR_VAR', $ta); |
|
| 2324 | - } |
|
| 2325 | - |
|
| 2326 | - if (!defined('_DIR_ETC')) { |
|
| 2327 | - define('_DIR_ETC', $pi); |
|
| 2328 | - } |
|
| 2329 | - if (!defined('_DIR_CONNECT')) { |
|
| 2330 | - define('_DIR_CONNECT', $pi); |
|
| 2331 | - } |
|
| 2332 | - if (!defined('_DIR_CHMOD')) { |
|
| 2333 | - define('_DIR_CHMOD', $pi); |
|
| 2334 | - } |
|
| 2335 | - |
|
| 2336 | - if (!isset($GLOBALS['test_dirs'])) |
|
| 2337 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2338 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2339 | - { |
|
| 2340 | - $GLOBALS['test_dirs'] = array($pa, $ti, $ta); |
|
| 2341 | - } |
|
| 2342 | - |
|
| 2343 | - // Declaration des fichiers |
|
| 2344 | - |
|
| 2345 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2346 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php"); |
|
| 2347 | - } |
|
| 2348 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2349 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php"); |
|
| 2350 | - } |
|
| 2351 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2352 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php"); |
|
| 2353 | - } |
|
| 2354 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2355 | - define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php"); |
|
| 2356 | - } |
|
| 2357 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2358 | - define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt"); |
|
| 2359 | - } |
|
| 2360 | - |
|
| 2361 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2362 | - if (!defined('_FILE_META')) { |
|
| 2363 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2364 | - } |
|
| 2365 | - if (!defined('_DIR_LOG')) { |
|
| 2366 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2367 | - } |
|
| 2368 | - if (!defined('_FILE_LOG')) { |
|
| 2369 | - define('_FILE_LOG', 'spip'); |
|
| 2370 | - } |
|
| 2371 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2372 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - // Le fichier de connexion a la base de donnees |
|
| 2376 | - // tient compte des anciennes versions (inc_connect...) |
|
| 2377 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2378 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2379 | - } |
|
| 2380 | - if (!defined('_FILE_CONNECT')) { |
|
| 2381 | - define('_FILE_CONNECT', |
|
| 2382 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2383 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2384 | - : false))); |
|
| 2385 | - } |
|
| 2386 | - |
|
| 2387 | - // Le fichier de reglages des droits |
|
| 2388 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2389 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2390 | - } |
|
| 2391 | - if (!defined('_FILE_CHMOD')) { |
|
| 2392 | - define('_FILE_CHMOD', |
|
| 2393 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2394 | - : false)); |
|
| 2395 | - } |
|
| 2396 | - |
|
| 2397 | - if (!defined('_FILE_LDAP')) { |
|
| 2398 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2402 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2403 | - } |
|
| 2404 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2405 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2406 | - } |
|
| 2407 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2408 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2409 | - } |
|
| 2410 | - |
|
| 2411 | - // Definition des droits d'acces en ecriture |
|
| 2412 | - if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2413 | - include_once _FILE_CHMOD; |
|
| 2414 | - } |
|
| 2415 | - |
|
| 2416 | - // Se mefier des fichiers mal remplis! |
|
| 2417 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2418 | - define('_SPIP_CHMOD', 0777); |
|
| 2419 | - } |
|
| 2420 | - |
|
| 2421 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2422 | - /** Le charset par défaut lors de l'installation */ |
|
| 2423 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2424 | - } |
|
| 2425 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2426 | - define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/"); |
|
| 2427 | - } |
|
| 2428 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2429 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/"); |
|
| 2430 | - } |
|
| 2431 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2432 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2433 | - } |
|
| 2434 | - |
|
| 2435 | - // La taille des Log |
|
| 2436 | - if (!defined('_MAX_LOG')) { |
|
| 2437 | - define('_MAX_LOG', 100); |
|
| 2438 | - } |
|
| 2439 | - |
|
| 2440 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2441 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2442 | - if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2443 | - if (!defined('_OS_SERVEUR')) { |
|
| 2444 | - define('_OS_SERVEUR', 'windows'); |
|
| 2445 | - } |
|
| 2446 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2447 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2448 | - } // utiliser le flock php |
|
| 2449 | - } else { |
|
| 2450 | - if (!defined('_OS_SERVEUR')) { |
|
| 2451 | - define('_OS_SERVEUR', ''); |
|
| 2452 | - } |
|
| 2453 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2454 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2455 | - } // utiliser le flock php |
|
| 2456 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2457 | - } |
|
| 2458 | - |
|
| 2459 | - // Langue par defaut |
|
| 2460 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2461 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2462 | - } |
|
| 2463 | - |
|
| 2464 | - // |
|
| 2465 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2466 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2467 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2468 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2469 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2470 | - |
|
| 2471 | - // charger tout de suite le path et son cache |
|
| 2472 | - load_path_cache(); |
|
| 2473 | - |
|
| 2474 | - // *********** traiter les variables ************ |
|
| 2475 | - |
|
| 2476 | - // |
|
| 2477 | - // Securite |
|
| 2478 | - // |
|
| 2479 | - |
|
| 2480 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2481 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2482 | - die(); |
|
| 2483 | - } |
|
| 2484 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2485 | - spip_desinfecte($_GET); |
|
| 2486 | - spip_desinfecte($_POST); |
|
| 2487 | - spip_desinfecte($_COOKIE); |
|
| 2488 | - spip_desinfecte($_REQUEST); |
|
| 2489 | - |
|
| 2490 | - // appliquer le cookie_prefix |
|
| 2491 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2492 | - include_spip('inc/cookie'); |
|
| 2493 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2494 | - } |
|
| 2495 | - |
|
| 2496 | - // |
|
| 2497 | - // Capacites php (en fonction de la version) |
|
| 2498 | - // |
|
| 2499 | - $GLOBALS['flag_ob'] = (function_exists("ob_start") |
|
| 2500 | - && function_exists("ini_get") |
|
| 2501 | - && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2502 | - $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name"); |
|
| 2503 | - $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ""); |
|
| 2504 | - $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2505 | - (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2506 | - |
|
| 2507 | - |
|
| 2508 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2509 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2510 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2511 | - } else { |
|
| 2512 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2513 | - if (!empty($_SERVER['QUERY_STRING']) |
|
| 2514 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2515 | - ) { |
|
| 2516 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2521 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2522 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2523 | - } |
|
| 2524 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2525 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2526 | - } |
|
| 2527 | - |
|
| 2528 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2529 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2530 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2531 | - $inc_meta(); |
|
| 2532 | - |
|
| 2533 | - // nombre de repertoires depuis la racine |
|
| 2534 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2535 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2536 | - // le calcul est faux) |
|
| 2537 | - if (!_DIR_RESTREINT) { |
|
| 2538 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2539 | - } else { |
|
| 2540 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2541 | - $uri_ref = $_SERVER["SCRIPT_NAME"]; |
|
| 2542 | - if (!$uri_ref |
|
| 2543 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2544 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2545 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2546 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2547 | - or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2548 | - ) { |
|
| 2549 | - |
|
| 2550 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2551 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2552 | - $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2553 | - } else { |
|
| 2554 | - $uri_ref = ""; |
|
| 2555 | - } |
|
| 2556 | - } |
|
| 2557 | - if (!$uri or !$uri_ref) { |
|
| 2558 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2559 | - } else { |
|
| 2560 | - $GLOBALS['profondeur_url'] = max(0, |
|
| 2561 | - substr_count($uri[0], '/') |
|
| 2562 | - - substr_count($uri_ref, '/')); |
|
| 2563 | - } |
|
| 2564 | - } |
|
| 2565 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2566 | - if (_FILE_CONNECT) { |
|
| 2567 | - if (verifier_visiteur() == '0minirezo' |
|
| 2568 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2569 | - and !isset($_COOKIE['spip_admin']) |
|
| 2570 | - ) { |
|
| 2571 | - clear_path_cache(); |
|
| 2572 | - } |
|
| 2573 | - } |
|
| 2264 | + static $too_late = 0; |
|
| 2265 | + if ($too_late++) { |
|
| 2266 | + return; |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + // Declaration des repertoires |
|
| 2270 | + |
|
| 2271 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2272 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2273 | + define('_DIR_PLUGINS', _DIR_RACINE . "plugins/"); |
|
| 2274 | + } |
|
| 2275 | + |
|
| 2276 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2277 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2278 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/"); |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + // le nom du repertoire des librairies |
|
| 2282 | + if (!defined('_DIR_LIB')) { |
|
| 2283 | + define('_DIR_LIB', _DIR_RACINE . "lib/"); |
|
| 2284 | + } |
|
| 2285 | + |
|
| 2286 | + if (!defined('_DIR_IMG')) { |
|
| 2287 | + define('_DIR_IMG', $pa); |
|
| 2288 | + } |
|
| 2289 | + if (!defined('_DIR_LOGOS')) { |
|
| 2290 | + define('_DIR_LOGOS', $pa); |
|
| 2291 | + } |
|
| 2292 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2293 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/"); |
|
| 2294 | + } |
|
| 2295 | + |
|
| 2296 | + if (!defined('_DIR_DUMP')) { |
|
| 2297 | + define('_DIR_DUMP', $ti . "dump/"); |
|
| 2298 | + } |
|
| 2299 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2300 | + define('_DIR_SESSIONS', $ti . "sessions/"); |
|
| 2301 | + } |
|
| 2302 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2303 | + define('_DIR_TRANSFERT', $ti . "upload/"); |
|
| 2304 | + } |
|
| 2305 | + if (!defined('_DIR_CACHE')) { |
|
| 2306 | + define('_DIR_CACHE', $ti . "cache/"); |
|
| 2307 | + } |
|
| 2308 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2309 | + define('_DIR_CACHE_XML', _DIR_CACHE . "xml/"); |
|
| 2310 | + } |
|
| 2311 | + if (!defined('_DIR_SKELS')) { |
|
| 2312 | + define('_DIR_SKELS', _DIR_CACHE . "skel/"); |
|
| 2313 | + } |
|
| 2314 | + if (!defined('_DIR_AIDE')) { |
|
| 2315 | + define('_DIR_AIDE', _DIR_CACHE . "aide/"); |
|
| 2316 | + } |
|
| 2317 | + if (!defined('_DIR_TMP')) { |
|
| 2318 | + define('_DIR_TMP', $ti); |
|
| 2319 | + } |
|
| 2320 | + |
|
| 2321 | + if (!defined('_DIR_VAR')) { |
|
| 2322 | + define('_DIR_VAR', $ta); |
|
| 2323 | + } |
|
| 2324 | + |
|
| 2325 | + if (!defined('_DIR_ETC')) { |
|
| 2326 | + define('_DIR_ETC', $pi); |
|
| 2327 | + } |
|
| 2328 | + if (!defined('_DIR_CONNECT')) { |
|
| 2329 | + define('_DIR_CONNECT', $pi); |
|
| 2330 | + } |
|
| 2331 | + if (!defined('_DIR_CHMOD')) { |
|
| 2332 | + define('_DIR_CHMOD', $pi); |
|
| 2333 | + } |
|
| 2334 | + |
|
| 2335 | + if (!isset($GLOBALS['test_dirs'])) |
|
| 2336 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2337 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2338 | + { |
|
| 2339 | + $GLOBALS['test_dirs'] = array($pa, $ti, $ta); |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + // Declaration des fichiers |
|
| 2343 | + |
|
| 2344 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2345 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php"); |
|
| 2346 | + } |
|
| 2347 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2348 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php"); |
|
| 2349 | + } |
|
| 2350 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2351 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php"); |
|
| 2352 | + } |
|
| 2353 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2354 | + define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php"); |
|
| 2355 | + } |
|
| 2356 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2357 | + define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt"); |
|
| 2358 | + } |
|
| 2359 | + |
|
| 2360 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2361 | + if (!defined('_FILE_META')) { |
|
| 2362 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2363 | + } |
|
| 2364 | + if (!defined('_DIR_LOG')) { |
|
| 2365 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2366 | + } |
|
| 2367 | + if (!defined('_FILE_LOG')) { |
|
| 2368 | + define('_FILE_LOG', 'spip'); |
|
| 2369 | + } |
|
| 2370 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2371 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2372 | + } |
|
| 2373 | + |
|
| 2374 | + // Le fichier de connexion a la base de donnees |
|
| 2375 | + // tient compte des anciennes versions (inc_connect...) |
|
| 2376 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2377 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2378 | + } |
|
| 2379 | + if (!defined('_FILE_CONNECT')) { |
|
| 2380 | + define('_FILE_CONNECT', |
|
| 2381 | + (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2382 | + : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2383 | + : false))); |
|
| 2384 | + } |
|
| 2385 | + |
|
| 2386 | + // Le fichier de reglages des droits |
|
| 2387 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2388 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2389 | + } |
|
| 2390 | + if (!defined('_FILE_CHMOD')) { |
|
| 2391 | + define('_FILE_CHMOD', |
|
| 2392 | + (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2393 | + : false)); |
|
| 2394 | + } |
|
| 2395 | + |
|
| 2396 | + if (!defined('_FILE_LDAP')) { |
|
| 2397 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2398 | + } |
|
| 2399 | + |
|
| 2400 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2401 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2402 | + } |
|
| 2403 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2404 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2405 | + } |
|
| 2406 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2407 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2408 | + } |
|
| 2409 | + |
|
| 2410 | + // Definition des droits d'acces en ecriture |
|
| 2411 | + if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2412 | + include_once _FILE_CHMOD; |
|
| 2413 | + } |
|
| 2414 | + |
|
| 2415 | + // Se mefier des fichiers mal remplis! |
|
| 2416 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2417 | + define('_SPIP_CHMOD', 0777); |
|
| 2418 | + } |
|
| 2419 | + |
|
| 2420 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2421 | + /** Le charset par défaut lors de l'installation */ |
|
| 2422 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2423 | + } |
|
| 2424 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2425 | + define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/"); |
|
| 2426 | + } |
|
| 2427 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2428 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/"); |
|
| 2429 | + } |
|
| 2430 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2431 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2432 | + } |
|
| 2433 | + |
|
| 2434 | + // La taille des Log |
|
| 2435 | + if (!defined('_MAX_LOG')) { |
|
| 2436 | + define('_MAX_LOG', 100); |
|
| 2437 | + } |
|
| 2438 | + |
|
| 2439 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2440 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2441 | + if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2442 | + if (!defined('_OS_SERVEUR')) { |
|
| 2443 | + define('_OS_SERVEUR', 'windows'); |
|
| 2444 | + } |
|
| 2445 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2446 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2447 | + } // utiliser le flock php |
|
| 2448 | + } else { |
|
| 2449 | + if (!defined('_OS_SERVEUR')) { |
|
| 2450 | + define('_OS_SERVEUR', ''); |
|
| 2451 | + } |
|
| 2452 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2453 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2454 | + } // utiliser le flock php |
|
| 2455 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2456 | + } |
|
| 2457 | + |
|
| 2458 | + // Langue par defaut |
|
| 2459 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2460 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + // |
|
| 2464 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2465 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2466 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2467 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2468 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2469 | + |
|
| 2470 | + // charger tout de suite le path et son cache |
|
| 2471 | + load_path_cache(); |
|
| 2472 | + |
|
| 2473 | + // *********** traiter les variables ************ |
|
| 2474 | + |
|
| 2475 | + // |
|
| 2476 | + // Securite |
|
| 2477 | + // |
|
| 2478 | + |
|
| 2479 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2480 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2481 | + die(); |
|
| 2482 | + } |
|
| 2483 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2484 | + spip_desinfecte($_GET); |
|
| 2485 | + spip_desinfecte($_POST); |
|
| 2486 | + spip_desinfecte($_COOKIE); |
|
| 2487 | + spip_desinfecte($_REQUEST); |
|
| 2488 | + |
|
| 2489 | + // appliquer le cookie_prefix |
|
| 2490 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2491 | + include_spip('inc/cookie'); |
|
| 2492 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + // |
|
| 2496 | + // Capacites php (en fonction de la version) |
|
| 2497 | + // |
|
| 2498 | + $GLOBALS['flag_ob'] = (function_exists("ob_start") |
|
| 2499 | + && function_exists("ini_get") |
|
| 2500 | + && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2501 | + $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name"); |
|
| 2502 | + $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ""); |
|
| 2503 | + $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2504 | + (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2505 | + |
|
| 2506 | + |
|
| 2507 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2508 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2509 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2510 | + } else { |
|
| 2511 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2512 | + if (!empty($_SERVER['QUERY_STRING']) |
|
| 2513 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2514 | + ) { |
|
| 2515 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2516 | + } |
|
| 2517 | + } |
|
| 2518 | + |
|
| 2519 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2520 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2521 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2522 | + } |
|
| 2523 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2524 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2525 | + } |
|
| 2526 | + |
|
| 2527 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2528 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2529 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2530 | + $inc_meta(); |
|
| 2531 | + |
|
| 2532 | + // nombre de repertoires depuis la racine |
|
| 2533 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2534 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2535 | + // le calcul est faux) |
|
| 2536 | + if (!_DIR_RESTREINT) { |
|
| 2537 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2538 | + } else { |
|
| 2539 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2540 | + $uri_ref = $_SERVER["SCRIPT_NAME"]; |
|
| 2541 | + if (!$uri_ref |
|
| 2542 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2543 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2544 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2545 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2546 | + or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2547 | + ) { |
|
| 2548 | + |
|
| 2549 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2550 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2551 | + $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2552 | + } else { |
|
| 2553 | + $uri_ref = ""; |
|
| 2554 | + } |
|
| 2555 | + } |
|
| 2556 | + if (!$uri or !$uri_ref) { |
|
| 2557 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2558 | + } else { |
|
| 2559 | + $GLOBALS['profondeur_url'] = max(0, |
|
| 2560 | + substr_count($uri[0], '/') |
|
| 2561 | + - substr_count($uri_ref, '/')); |
|
| 2562 | + } |
|
| 2563 | + } |
|
| 2564 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2565 | + if (_FILE_CONNECT) { |
|
| 2566 | + if (verifier_visiteur() == '0minirezo' |
|
| 2567 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2568 | + and !isset($_COOKIE['spip_admin']) |
|
| 2569 | + ) { |
|
| 2570 | + clear_path_cache(); |
|
| 2571 | + } |
|
| 2572 | + } |
|
| 2574 | 2573 | |
| 2575 | 2574 | } |
| 2576 | 2575 | |
@@ -2580,174 +2579,174 @@ discard block |
||
| 2580 | 2579 | * |
| 2581 | 2580 | */ |
| 2582 | 2581 | function spip_initialisation_suite() { |
| 2583 | - static $too_late = 0; |
|
| 2584 | - if ($too_late++) { |
|
| 2585 | - return; |
|
| 2586 | - } |
|
| 2587 | - |
|
| 2588 | - // taille mini des login |
|
| 2589 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2590 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2591 | - } |
|
| 2592 | - |
|
| 2593 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2594 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2595 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2596 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2597 | - |
|
| 2598 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2599 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2600 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2601 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2602 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2603 | - |
|
| 2604 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2605 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2606 | - } |
|
| 2607 | - |
|
| 2608 | - |
|
| 2609 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2610 | - if (!defined('_IMG_QUALITE')) { |
|
| 2611 | - define('_IMG_QUALITE', 85); |
|
| 2612 | - } # valeur par defaut |
|
| 2613 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2614 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2615 | - } # surcharge pour la lib GD |
|
| 2616 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2617 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2618 | - } # surcharge pour imagick en ligne de commande |
|
| 2619 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2620 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2621 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2622 | - } # surcharge pour imagick en PHP |
|
| 2623 | - |
|
| 2624 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2625 | - define('_COPIE_LOCALE_MAX_SIZE', 33554432); |
|
| 2626 | - } // poids en octet |
|
| 2627 | - |
|
| 2628 | - // qq chaines standard |
|
| 2629 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2630 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2631 | - } |
|
| 2632 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2633 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2634 | - } |
|
| 2635 | - if (!defined('_SPIP_DUMP')) { |
|
| 2636 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2637 | - } |
|
| 2638 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2639 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2640 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2641 | - } |
|
| 2642 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2643 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2644 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2645 | - } |
|
| 2646 | - |
|
| 2647 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2648 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2652 | - /** Définit le doctype de l’espace privé */ |
|
| 2653 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2654 | - } |
|
| 2655 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2656 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2657 | - define('_DOCTYPE_AIDE', |
|
| 2658 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"); |
|
| 2659 | - } |
|
| 2660 | - |
|
| 2661 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2662 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2663 | - * le script de l'espace public, alias index.php */ |
|
| 2664 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2665 | - } |
|
| 2666 | - if (!defined('_SPIP_PAGE')) { |
|
| 2667 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2668 | - define('_SPIP_PAGE', 'page'); |
|
| 2669 | - } |
|
| 2670 | - |
|
| 2671 | - // le script de l'espace prive |
|
| 2672 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2673 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2674 | - // meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html |
|
| 2675 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2676 | - if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2677 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2678 | - } else { |
|
| 2679 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2680 | - } |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - |
|
| 2684 | - if (!defined('_SPIP_AJAX')) { |
|
| 2685 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2686 | - ? 1 |
|
| 2687 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2688 | - } |
|
| 2689 | - |
|
| 2690 | - // La requete est-elle en ajax ? |
|
| 2691 | - if (!defined('_AJAX')) { |
|
| 2692 | - define('_AJAX', |
|
| 2693 | - (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2694 | - or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2695 | - or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2696 | - or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2697 | - ) |
|
| 2698 | - and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2699 | - ); |
|
| 2700 | - } |
|
| 2701 | - |
|
| 2702 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2703 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2704 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2705 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2706 | - define('_IMG_GD_MAX_PIXELS', |
|
| 2707 | - (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2708 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2709 | - : 0); |
|
| 2710 | - } |
|
| 2711 | - |
|
| 2712 | - if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2713 | - define('_MEMORY_LIMIT_MIN', 16); |
|
| 2714 | - } // en Mo |
|
| 2715 | - // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2716 | - // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2717 | - // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2718 | - if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2719 | - if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2720 | - $unit = strtolower(substr($memory, -1)); |
|
| 2721 | - $memory = substr($memory, 0, -1); |
|
| 2722 | - switch ($unit) { |
|
| 2723 | - // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2724 | - case 'g': |
|
| 2725 | - $memory *= 1024; |
|
| 2726 | - case 'm': |
|
| 2727 | - $memory *= 1024; |
|
| 2728 | - case 'k': |
|
| 2729 | - $memory *= 1024; |
|
| 2730 | - } |
|
| 2731 | - if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2732 | - @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2733 | - if (trim(ini_get('memory_limit')) != $m) { |
|
| 2734 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2735 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2736 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2737 | - } |
|
| 2738 | - } |
|
| 2739 | - } else { |
|
| 2740 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2741 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2742 | - } |
|
| 2743 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2744 | - } |
|
| 2745 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2746 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2747 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2748 | - } |
|
| 2749 | - |
|
| 2750 | - init_var_mode(); |
|
| 2582 | + static $too_late = 0; |
|
| 2583 | + if ($too_late++) { |
|
| 2584 | + return; |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + // taille mini des login |
|
| 2588 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2589 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2590 | + } |
|
| 2591 | + |
|
| 2592 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2593 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2594 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2595 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2596 | + |
|
| 2597 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2598 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2599 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2600 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2601 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2602 | + |
|
| 2603 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2604 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2605 | + } |
|
| 2606 | + |
|
| 2607 | + |
|
| 2608 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2609 | + if (!defined('_IMG_QUALITE')) { |
|
| 2610 | + define('_IMG_QUALITE', 85); |
|
| 2611 | + } # valeur par defaut |
|
| 2612 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2613 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2614 | + } # surcharge pour la lib GD |
|
| 2615 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2616 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2617 | + } # surcharge pour imagick en ligne de commande |
|
| 2618 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2619 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2620 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2621 | + } # surcharge pour imagick en PHP |
|
| 2622 | + |
|
| 2623 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2624 | + define('_COPIE_LOCALE_MAX_SIZE', 33554432); |
|
| 2625 | + } // poids en octet |
|
| 2626 | + |
|
| 2627 | + // qq chaines standard |
|
| 2628 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2629 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2630 | + } |
|
| 2631 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2632 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2633 | + } |
|
| 2634 | + if (!defined('_SPIP_DUMP')) { |
|
| 2635 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2636 | + } |
|
| 2637 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2638 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2639 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2640 | + } |
|
| 2641 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2642 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2643 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2644 | + } |
|
| 2645 | + |
|
| 2646 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2647 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2648 | + } |
|
| 2649 | + |
|
| 2650 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2651 | + /** Définit le doctype de l’espace privé */ |
|
| 2652 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2653 | + } |
|
| 2654 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2655 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2656 | + define('_DOCTYPE_AIDE', |
|
| 2657 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"); |
|
| 2658 | + } |
|
| 2659 | + |
|
| 2660 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2661 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2662 | + * le script de l'espace public, alias index.php */ |
|
| 2663 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2664 | + } |
|
| 2665 | + if (!defined('_SPIP_PAGE')) { |
|
| 2666 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2667 | + define('_SPIP_PAGE', 'page'); |
|
| 2668 | + } |
|
| 2669 | + |
|
| 2670 | + // le script de l'espace prive |
|
| 2671 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2672 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2673 | + // meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html |
|
| 2674 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2675 | + if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2676 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2677 | + } else { |
|
| 2678 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2679 | + } |
|
| 2680 | + } |
|
| 2681 | + |
|
| 2682 | + |
|
| 2683 | + if (!defined('_SPIP_AJAX')) { |
|
| 2684 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2685 | + ? 1 |
|
| 2686 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + // La requete est-elle en ajax ? |
|
| 2690 | + if (!defined('_AJAX')) { |
|
| 2691 | + define('_AJAX', |
|
| 2692 | + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2693 | + or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2694 | + or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2695 | + or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2696 | + ) |
|
| 2697 | + and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2698 | + ); |
|
| 2699 | + } |
|
| 2700 | + |
|
| 2701 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2702 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2703 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2704 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2705 | + define('_IMG_GD_MAX_PIXELS', |
|
| 2706 | + (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2707 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2708 | + : 0); |
|
| 2709 | + } |
|
| 2710 | + |
|
| 2711 | + if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2712 | + define('_MEMORY_LIMIT_MIN', 16); |
|
| 2713 | + } // en Mo |
|
| 2714 | + // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2715 | + // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2716 | + // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2717 | + if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2718 | + if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2719 | + $unit = strtolower(substr($memory, -1)); |
|
| 2720 | + $memory = substr($memory, 0, -1); |
|
| 2721 | + switch ($unit) { |
|
| 2722 | + // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2723 | + case 'g': |
|
| 2724 | + $memory *= 1024; |
|
| 2725 | + case 'm': |
|
| 2726 | + $memory *= 1024; |
|
| 2727 | + case 'k': |
|
| 2728 | + $memory *= 1024; |
|
| 2729 | + } |
|
| 2730 | + if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2731 | + @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2732 | + if (trim(ini_get('memory_limit')) != $m) { |
|
| 2733 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2734 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2735 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2736 | + } |
|
| 2737 | + } |
|
| 2738 | + } else { |
|
| 2739 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2740 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2741 | + } |
|
| 2742 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2743 | + } |
|
| 2744 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2745 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2746 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2747 | + } |
|
| 2748 | + |
|
| 2749 | + init_var_mode(); |
|
| 2751 | 2750 | } |
| 2752 | 2751 | |
| 2753 | 2752 | /** |
@@ -2781,129 +2780,129 @@ discard block |
||
| 2781 | 2780 | * ` var_mode` (calcul ou recalcul). |
| 2782 | 2781 | */ |
| 2783 | 2782 | function init_var_mode() { |
| 2784 | - static $done = false; |
|
| 2785 | - if (!$done) { |
|
| 2786 | - |
|
| 2787 | - if (isset($_GET['var_mode'])) { |
|
| 2788 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 2789 | - // tout le monde peut calcul/recalcul |
|
| 2790 | - if (!defined('_VAR_MODE')) { |
|
| 2791 | - if (in_array('recalcul', $var_mode)) { |
|
| 2792 | - define('_VAR_MODE', 'recalcul'); |
|
| 2793 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 2794 | - define('_VAR_MODE', 'calcul'); |
|
| 2795 | - } |
|
| 2796 | - } |
|
| 2797 | - $var_mode = array_diff($var_mode, array('calcul', 'recalcul')); |
|
| 2798 | - if ($var_mode) { |
|
| 2799 | - include_spip('inc/autoriser'); |
|
| 2800 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2801 | - if (autoriser( |
|
| 2802 | - ($_GET['var_mode'] == 'preview') |
|
| 2803 | - ? 'previsualiser' |
|
| 2804 | - : 'debug' |
|
| 2805 | - )) { |
|
| 2806 | - if (in_array('traduction', $var_mode)) { |
|
| 2807 | - // forcer le calcul pour passer dans traduire |
|
| 2808 | - if (!defined('_VAR_MODE')) { |
|
| 2809 | - define('_VAR_MODE', 'calcul'); |
|
| 2810 | - } |
|
| 2811 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2812 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2813 | - define('_VAR_NOCACHE', true); |
|
| 2814 | - } |
|
| 2815 | - $var_mode = array_diff($var_mode, array('traduction')); |
|
| 2816 | - } |
|
| 2817 | - if (in_array('preview', $var_mode)) { |
|
| 2818 | - // basculer sur les criteres de preview dans les boucles |
|
| 2819 | - if (!defined('_VAR_PREVIEW')) { |
|
| 2820 | - define('_VAR_PREVIEW', true); |
|
| 2821 | - } |
|
| 2822 | - // forcer le calcul |
|
| 2823 | - if (!defined('_VAR_MODE')) { |
|
| 2824 | - define('_VAR_MODE', 'calcul'); |
|
| 2825 | - } |
|
| 2826 | - // et ne pas enregistrer de cache |
|
| 2827 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2828 | - define('_VAR_NOCACHE', true); |
|
| 2829 | - } |
|
| 2830 | - $var_mode = array_diff($var_mode, array('preview')); |
|
| 2831 | - } |
|
| 2832 | - if (in_array('inclure', $var_mode)) { |
|
| 2833 | - // forcer le compilo et ignorer les caches existants |
|
| 2834 | - if (!defined('_VAR_MODE')) { |
|
| 2835 | - define('_VAR_MODE', 'calcul'); |
|
| 2836 | - } |
|
| 2837 | - if (!defined('_VAR_INCLURE')) { |
|
| 2838 | - define('_VAR_INCLURE', true); |
|
| 2839 | - } |
|
| 2840 | - // et ne pas enregistrer de cache |
|
| 2841 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2842 | - define('_VAR_NOCACHE', true); |
|
| 2843 | - } |
|
| 2844 | - $var_mode = array_diff($var_mode, array('inclure')); |
|
| 2845 | - } |
|
| 2846 | - if (in_array('urls', $var_mode)) { |
|
| 2847 | - // forcer le compilo et ignorer les caches existants |
|
| 2848 | - if (!defined('_VAR_MODE')) { |
|
| 2849 | - define('_VAR_MODE', 'calcul'); |
|
| 2850 | - } |
|
| 2851 | - if (!defined('_VAR_URLS')) { |
|
| 2852 | - define('_VAR_URLS', true); |
|
| 2853 | - } |
|
| 2854 | - $var_mode = array_diff($var_mode, array('urls')); |
|
| 2855 | - } |
|
| 2856 | - if (in_array('images', $var_mode)) { |
|
| 2857 | - // forcer le compilo et ignorer les caches existants |
|
| 2858 | - if (!defined('_VAR_MODE')) { |
|
| 2859 | - define('_VAR_MODE', 'calcul'); |
|
| 2860 | - } |
|
| 2861 | - // indiquer qu'on doit recalculer les images |
|
| 2862 | - if (!defined('_VAR_IMAGES')) { |
|
| 2863 | - define('_VAR_IMAGES', true); |
|
| 2864 | - } |
|
| 2865 | - $var_mode = array_diff($var_mode, array('images')); |
|
| 2866 | - } |
|
| 2867 | - if (in_array('debug', $var_mode)) { |
|
| 2868 | - if (!defined('_VAR_MODE')) { |
|
| 2869 | - define('_VAR_MODE', 'debug'); |
|
| 2870 | - } |
|
| 2871 | - // et ne pas enregistrer de cache |
|
| 2872 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2873 | - define('_VAR_NOCACHE', true); |
|
| 2874 | - } |
|
| 2875 | - $var_mode = array_diff($var_mode, array('debug')); |
|
| 2876 | - } |
|
| 2877 | - if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2878 | - define('_VAR_MODE', reset($var_mode)); |
|
| 2879 | - } |
|
| 2880 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2881 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2882 | - . " " . _VAR_MODE); |
|
| 2883 | - } |
|
| 2884 | - } // pas autorise ? |
|
| 2885 | - else { |
|
| 2886 | - // si on n'est pas connecte on se redirige |
|
| 2887 | - if (!$GLOBALS['visiteur_session']) { |
|
| 2888 | - include_spip('inc/headers'); |
|
| 2889 | - redirige_par_entete(generer_url_public('login', |
|
| 2890 | - 'url=' . rawurlencode( |
|
| 2891 | - parametre_url(self(), 'var_mode', $_GET['var_mode'], '&') |
|
| 2892 | - ), true)); |
|
| 2893 | - } |
|
| 2894 | - // sinon tant pis |
|
| 2895 | - } |
|
| 2896 | - } |
|
| 2897 | - } |
|
| 2898 | - if (!defined('_VAR_MODE')) { |
|
| 2899 | - /** |
|
| 2900 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 2901 | - * @see init_var_mode() |
|
| 2902 | - */ |
|
| 2903 | - define('_VAR_MODE', false); |
|
| 2904 | - } |
|
| 2905 | - $done = true; |
|
| 2906 | - } |
|
| 2783 | + static $done = false; |
|
| 2784 | + if (!$done) { |
|
| 2785 | + |
|
| 2786 | + if (isset($_GET['var_mode'])) { |
|
| 2787 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 2788 | + // tout le monde peut calcul/recalcul |
|
| 2789 | + if (!defined('_VAR_MODE')) { |
|
| 2790 | + if (in_array('recalcul', $var_mode)) { |
|
| 2791 | + define('_VAR_MODE', 'recalcul'); |
|
| 2792 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 2793 | + define('_VAR_MODE', 'calcul'); |
|
| 2794 | + } |
|
| 2795 | + } |
|
| 2796 | + $var_mode = array_diff($var_mode, array('calcul', 'recalcul')); |
|
| 2797 | + if ($var_mode) { |
|
| 2798 | + include_spip('inc/autoriser'); |
|
| 2799 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2800 | + if (autoriser( |
|
| 2801 | + ($_GET['var_mode'] == 'preview') |
|
| 2802 | + ? 'previsualiser' |
|
| 2803 | + : 'debug' |
|
| 2804 | + )) { |
|
| 2805 | + if (in_array('traduction', $var_mode)) { |
|
| 2806 | + // forcer le calcul pour passer dans traduire |
|
| 2807 | + if (!defined('_VAR_MODE')) { |
|
| 2808 | + define('_VAR_MODE', 'calcul'); |
|
| 2809 | + } |
|
| 2810 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2811 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2812 | + define('_VAR_NOCACHE', true); |
|
| 2813 | + } |
|
| 2814 | + $var_mode = array_diff($var_mode, array('traduction')); |
|
| 2815 | + } |
|
| 2816 | + if (in_array('preview', $var_mode)) { |
|
| 2817 | + // basculer sur les criteres de preview dans les boucles |
|
| 2818 | + if (!defined('_VAR_PREVIEW')) { |
|
| 2819 | + define('_VAR_PREVIEW', true); |
|
| 2820 | + } |
|
| 2821 | + // forcer le calcul |
|
| 2822 | + if (!defined('_VAR_MODE')) { |
|
| 2823 | + define('_VAR_MODE', 'calcul'); |
|
| 2824 | + } |
|
| 2825 | + // et ne pas enregistrer de cache |
|
| 2826 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2827 | + define('_VAR_NOCACHE', true); |
|
| 2828 | + } |
|
| 2829 | + $var_mode = array_diff($var_mode, array('preview')); |
|
| 2830 | + } |
|
| 2831 | + if (in_array('inclure', $var_mode)) { |
|
| 2832 | + // forcer le compilo et ignorer les caches existants |
|
| 2833 | + if (!defined('_VAR_MODE')) { |
|
| 2834 | + define('_VAR_MODE', 'calcul'); |
|
| 2835 | + } |
|
| 2836 | + if (!defined('_VAR_INCLURE')) { |
|
| 2837 | + define('_VAR_INCLURE', true); |
|
| 2838 | + } |
|
| 2839 | + // et ne pas enregistrer de cache |
|
| 2840 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2841 | + define('_VAR_NOCACHE', true); |
|
| 2842 | + } |
|
| 2843 | + $var_mode = array_diff($var_mode, array('inclure')); |
|
| 2844 | + } |
|
| 2845 | + if (in_array('urls', $var_mode)) { |
|
| 2846 | + // forcer le compilo et ignorer les caches existants |
|
| 2847 | + if (!defined('_VAR_MODE')) { |
|
| 2848 | + define('_VAR_MODE', 'calcul'); |
|
| 2849 | + } |
|
| 2850 | + if (!defined('_VAR_URLS')) { |
|
| 2851 | + define('_VAR_URLS', true); |
|
| 2852 | + } |
|
| 2853 | + $var_mode = array_diff($var_mode, array('urls')); |
|
| 2854 | + } |
|
| 2855 | + if (in_array('images', $var_mode)) { |
|
| 2856 | + // forcer le compilo et ignorer les caches existants |
|
| 2857 | + if (!defined('_VAR_MODE')) { |
|
| 2858 | + define('_VAR_MODE', 'calcul'); |
|
| 2859 | + } |
|
| 2860 | + // indiquer qu'on doit recalculer les images |
|
| 2861 | + if (!defined('_VAR_IMAGES')) { |
|
| 2862 | + define('_VAR_IMAGES', true); |
|
| 2863 | + } |
|
| 2864 | + $var_mode = array_diff($var_mode, array('images')); |
|
| 2865 | + } |
|
| 2866 | + if (in_array('debug', $var_mode)) { |
|
| 2867 | + if (!defined('_VAR_MODE')) { |
|
| 2868 | + define('_VAR_MODE', 'debug'); |
|
| 2869 | + } |
|
| 2870 | + // et ne pas enregistrer de cache |
|
| 2871 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2872 | + define('_VAR_NOCACHE', true); |
|
| 2873 | + } |
|
| 2874 | + $var_mode = array_diff($var_mode, array('debug')); |
|
| 2875 | + } |
|
| 2876 | + if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2877 | + define('_VAR_MODE', reset($var_mode)); |
|
| 2878 | + } |
|
| 2879 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2880 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2881 | + . " " . _VAR_MODE); |
|
| 2882 | + } |
|
| 2883 | + } // pas autorise ? |
|
| 2884 | + else { |
|
| 2885 | + // si on n'est pas connecte on se redirige |
|
| 2886 | + if (!$GLOBALS['visiteur_session']) { |
|
| 2887 | + include_spip('inc/headers'); |
|
| 2888 | + redirige_par_entete(generer_url_public('login', |
|
| 2889 | + 'url=' . rawurlencode( |
|
| 2890 | + parametre_url(self(), 'var_mode', $_GET['var_mode'], '&') |
|
| 2891 | + ), true)); |
|
| 2892 | + } |
|
| 2893 | + // sinon tant pis |
|
| 2894 | + } |
|
| 2895 | + } |
|
| 2896 | + } |
|
| 2897 | + if (!defined('_VAR_MODE')) { |
|
| 2898 | + /** |
|
| 2899 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 2900 | + * @see init_var_mode() |
|
| 2901 | + */ |
|
| 2902 | + define('_VAR_MODE', false); |
|
| 2903 | + } |
|
| 2904 | + $done = true; |
|
| 2905 | + } |
|
| 2907 | 2906 | } |
| 2908 | 2907 | |
| 2909 | 2908 | // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ; |
@@ -2911,93 +2910,93 @@ discard block |
||
| 2911 | 2910 | // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal') |
| 2912 | 2911 | // http://code.spip.net/@spip_desinfecte |
| 2913 | 2912 | function spip_desinfecte(&$t, $deep = true) { |
| 2914 | - static $magic_quotes; |
|
| 2915 | - if (!isset($magic_quotes)) { |
|
| 2916 | - $magic_quotes = @get_magic_quotes_gpc(); |
|
| 2917 | - } |
|
| 2918 | - |
|
| 2919 | - foreach ($t as $key => $val) { |
|
| 2920 | - if (is_string($t[$key])) { |
|
| 2921 | - if ($magic_quotes) { |
|
| 2922 | - $t[$key] = stripslashes($t[$key]); |
|
| 2923 | - } |
|
| 2924 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 2925 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 2926 | - else { |
|
| 2927 | - if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 2928 | - spip_desinfecte($t[$key], $deep); |
|
| 2929 | - } |
|
| 2930 | - } |
|
| 2931 | - } |
|
| 2913 | + static $magic_quotes; |
|
| 2914 | + if (!isset($magic_quotes)) { |
|
| 2915 | + $magic_quotes = @get_magic_quotes_gpc(); |
|
| 2916 | + } |
|
| 2917 | + |
|
| 2918 | + foreach ($t as $key => $val) { |
|
| 2919 | + if (is_string($t[$key])) { |
|
| 2920 | + if ($magic_quotes) { |
|
| 2921 | + $t[$key] = stripslashes($t[$key]); |
|
| 2922 | + } |
|
| 2923 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 2924 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 2925 | + else { |
|
| 2926 | + if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 2927 | + spip_desinfecte($t[$key], $deep); |
|
| 2928 | + } |
|
| 2929 | + } |
|
| 2930 | + } |
|
| 2932 | 2931 | } |
| 2933 | 2932 | |
| 2934 | 2933 | // retourne le statut du visiteur s'il s'annonce |
| 2935 | 2934 | |
| 2936 | 2935 | // http://code.spip.net/@verifier_visiteur |
| 2937 | 2936 | function verifier_visiteur() { |
| 2938 | - // Rq: pour que cette fonction marche depuis mes_options |
|
| 2939 | - // il faut forcer l'init si ce n'est fait |
|
| 2940 | - // mais on risque de perturber des plugins en initialisant trop tot |
|
| 2941 | - // certaines constantes |
|
| 2942 | - @spip_initialisation_core( |
|
| 2943 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 2944 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 2945 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 2946 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 2947 | - ); |
|
| 2948 | - |
|
| 2949 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 2950 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 2951 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 2952 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 2953 | - $variables_session = array('session_nom', 'session_email'); |
|
| 2954 | - foreach ($variables_session as $var) { |
|
| 2955 | - if (_request($var) !== null) { |
|
| 2956 | - $init = true; |
|
| 2957 | - break; |
|
| 2958 | - } |
|
| 2959 | - } |
|
| 2960 | - if (isset($init)) { |
|
| 2961 | - #@spip_initialisation_suite(); |
|
| 2962 | - $session = charger_fonction('session', 'inc'); |
|
| 2963 | - $session(); |
|
| 2964 | - include_spip('inc/texte'); |
|
| 2965 | - foreach ($variables_session as $var) { |
|
| 2966 | - if (($a = _request($var)) !== null) { |
|
| 2967 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 2968 | - } |
|
| 2969 | - } |
|
| 2970 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 2971 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 2972 | - } |
|
| 2973 | - $session($GLOBALS['visiteur_session']); |
|
| 2974 | - |
|
| 2975 | - return 0; |
|
| 2976 | - } |
|
| 2977 | - |
|
| 2978 | - $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 2979 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 2980 | - |
|
| 2981 | - $session = charger_fonction('session', 'inc'); |
|
| 2982 | - if ($session()) { |
|
| 2983 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 2984 | - } |
|
| 2985 | - if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 2986 | - include_spip('inc/auth'); |
|
| 2987 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 2988 | - } |
|
| 2989 | - if ($h) { |
|
| 2990 | - $GLOBALS['visiteur_session'] = $h; |
|
| 2991 | - |
|
| 2992 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 2993 | - } |
|
| 2994 | - } |
|
| 2995 | - |
|
| 2996 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 2997 | - include_spip('inc/lang'); |
|
| 2998 | - utiliser_langue_visiteur(); |
|
| 2999 | - |
|
| 3000 | - return false; |
|
| 2937 | + // Rq: pour que cette fonction marche depuis mes_options |
|
| 2938 | + // il faut forcer l'init si ce n'est fait |
|
| 2939 | + // mais on risque de perturber des plugins en initialisant trop tot |
|
| 2940 | + // certaines constantes |
|
| 2941 | + @spip_initialisation_core( |
|
| 2942 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 2943 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 2944 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 2945 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 2946 | + ); |
|
| 2947 | + |
|
| 2948 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 2949 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 2950 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 2951 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 2952 | + $variables_session = array('session_nom', 'session_email'); |
|
| 2953 | + foreach ($variables_session as $var) { |
|
| 2954 | + if (_request($var) !== null) { |
|
| 2955 | + $init = true; |
|
| 2956 | + break; |
|
| 2957 | + } |
|
| 2958 | + } |
|
| 2959 | + if (isset($init)) { |
|
| 2960 | + #@spip_initialisation_suite(); |
|
| 2961 | + $session = charger_fonction('session', 'inc'); |
|
| 2962 | + $session(); |
|
| 2963 | + include_spip('inc/texte'); |
|
| 2964 | + foreach ($variables_session as $var) { |
|
| 2965 | + if (($a = _request($var)) !== null) { |
|
| 2966 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 2967 | + } |
|
| 2968 | + } |
|
| 2969 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 2970 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 2971 | + } |
|
| 2972 | + $session($GLOBALS['visiteur_session']); |
|
| 2973 | + |
|
| 2974 | + return 0; |
|
| 2975 | + } |
|
| 2976 | + |
|
| 2977 | + $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 2978 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 2979 | + |
|
| 2980 | + $session = charger_fonction('session', 'inc'); |
|
| 2981 | + if ($session()) { |
|
| 2982 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 2983 | + } |
|
| 2984 | + if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 2985 | + include_spip('inc/auth'); |
|
| 2986 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 2987 | + } |
|
| 2988 | + if ($h) { |
|
| 2989 | + $GLOBALS['visiteur_session'] = $h; |
|
| 2990 | + |
|
| 2991 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 2992 | + } |
|
| 2993 | + } |
|
| 2994 | + |
|
| 2995 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 2996 | + include_spip('inc/lang'); |
|
| 2997 | + utiliser_langue_visiteur(); |
|
| 2998 | + |
|
| 2999 | + return false; |
|
| 3001 | 3000 | } |
| 3002 | 3001 | |
| 3003 | 3002 | |
@@ -3020,21 +3019,21 @@ discard block |
||
| 3020 | 3019 | * - string Langue utilisée. |
| 3021 | 3020 | **/ |
| 3022 | 3021 | function lang_select($lang = null) { |
| 3023 | - static $pile_langues = array(); |
|
| 3024 | - if (!function_exists('changer_langue')) { |
|
| 3025 | - include_spip('inc/lang'); |
|
| 3026 | - } |
|
| 3027 | - if ($lang === null) { |
|
| 3028 | - $lang = array_pop($pile_langues); |
|
| 3029 | - } else { |
|
| 3030 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3031 | - } |
|
| 3032 | - if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3033 | - return $lang; |
|
| 3034 | - } |
|
| 3035 | - changer_langue($lang); |
|
| 3022 | + static $pile_langues = array(); |
|
| 3023 | + if (!function_exists('changer_langue')) { |
|
| 3024 | + include_spip('inc/lang'); |
|
| 3025 | + } |
|
| 3026 | + if ($lang === null) { |
|
| 3027 | + $lang = array_pop($pile_langues); |
|
| 3028 | + } else { |
|
| 3029 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3030 | + } |
|
| 3031 | + if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3032 | + return $lang; |
|
| 3033 | + } |
|
| 3034 | + changer_langue($lang); |
|
| 3036 | 3035 | |
| 3037 | - return $lang; |
|
| 3036 | + return $lang; |
|
| 3038 | 3037 | } |
| 3039 | 3038 | |
| 3040 | 3039 | /** |
@@ -3051,19 +3050,19 @@ discard block |
||
| 3051 | 3050 | * Identifiant de la session |
| 3052 | 3051 | **/ |
| 3053 | 3052 | function spip_session($force = false) { |
| 3054 | - static $session; |
|
| 3055 | - if ($force or !isset($session)) { |
|
| 3056 | - $s = pipeline('definir_session', |
|
| 3057 | - $GLOBALS['visiteur_session'] |
|
| 3058 | - ? serialize($GLOBALS['visiteur_session']) |
|
| 3059 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3060 | - : '' |
|
| 3061 | - ); |
|
| 3062 | - $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3063 | - } |
|
| 3053 | + static $session; |
|
| 3054 | + if ($force or !isset($session)) { |
|
| 3055 | + $s = pipeline('definir_session', |
|
| 3056 | + $GLOBALS['visiteur_session'] |
|
| 3057 | + ? serialize($GLOBALS['visiteur_session']) |
|
| 3058 | + . '_' . @$_COOKIE['spip_session'] |
|
| 3059 | + : '' |
|
| 3060 | + ); |
|
| 3061 | + $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3062 | + } |
|
| 3064 | 3063 | |
| 3065 | - #spip_log('session: '.$session); |
|
| 3066 | - return $session; |
|
| 3064 | + #spip_log('session: '.$session); |
|
| 3065 | + return $session; |
|
| 3067 | 3066 | } |
| 3068 | 3067 | |
| 3069 | 3068 | |
@@ -3082,9 +3081,9 @@ discard block |
||
| 3082 | 3081 | * Lien sur une icone d'aide |
| 3083 | 3082 | **/ |
| 3084 | 3083 | function aider($aide = '', $distante = false) { |
| 3085 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3084 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3086 | 3085 | |
| 3087 | - return $aider ? $aider($aide, '', array(), $distante) : ''; |
|
| 3086 | + return $aider ? $aider($aide, '', array(), $distante) : ''; |
|
| 3088 | 3087 | } |
| 3089 | 3088 | |
| 3090 | 3089 | /** |
@@ -3094,13 +3093,13 @@ discard block |
||
| 3094 | 3093 | */ |
| 3095 | 3094 | function exec_info_dist() { |
| 3096 | 3095 | |
| 3097 | - include_spip('inc/autoriser'); |
|
| 3098 | - if (autoriser('webmestre')) { |
|
| 3099 | - phpinfo(); |
|
| 3100 | - } else { |
|
| 3101 | - include_spip('inc/filtres'); |
|
| 3102 | - sinon_interdire_acces(); |
|
| 3103 | - } |
|
| 3096 | + include_spip('inc/autoriser'); |
|
| 3097 | + if (autoriser('webmestre')) { |
|
| 3098 | + phpinfo(); |
|
| 3099 | + } else { |
|
| 3100 | + include_spip('inc/filtres'); |
|
| 3101 | + sinon_interdire_acces(); |
|
| 3102 | + } |
|
| 3104 | 3103 | } |
| 3105 | 3104 | |
| 3106 | 3105 | /** |
@@ -3120,13 +3119,13 @@ discard block |
||
| 3120 | 3119 | * - string si $message à false. |
| 3121 | 3120 | **/ |
| 3122 | 3121 | function erreur_squelette($message = '', $lieu = '') { |
| 3123 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3124 | - if (is_array($lieu)) { |
|
| 3125 | - include_spip('public/compiler'); |
|
| 3126 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3127 | - } |
|
| 3122 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3123 | + if (is_array($lieu)) { |
|
| 3124 | + include_spip('public/compiler'); |
|
| 3125 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3126 | + } |
|
| 3128 | 3127 | |
| 3129 | - return $debusquer($message, $lieu); |
|
| 3128 | + return $debusquer($message, $lieu); |
|
| 3130 | 3129 | } |
| 3131 | 3130 | |
| 3132 | 3131 | /** |
@@ -3163,109 +3162,109 @@ discard block |
||
| 3163 | 3162 | * - ou tableau d'information sur le squelette. |
| 3164 | 3163 | */ |
| 3165 | 3164 | function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') { |
| 3166 | - if (!function_exists('evaluer_fond')) { |
|
| 3167 | - include_spip('public/assembler'); |
|
| 3168 | - } |
|
| 3169 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3170 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3171 | - if (!is_array($options)) { |
|
| 3172 | - $options = array('trim' => $options); |
|
| 3173 | - } |
|
| 3174 | - if (!isset($options['trim'])) { |
|
| 3175 | - $options['trim'] = true; |
|
| 3176 | - } |
|
| 3177 | - |
|
| 3178 | - if (isset($contexte['connect'])) { |
|
| 3179 | - $connect = $contexte['connect']; |
|
| 3180 | - unset($contexte['connect']); |
|
| 3181 | - } |
|
| 3182 | - |
|
| 3183 | - $texte = ""; |
|
| 3184 | - $pages = array(); |
|
| 3185 | - $lang_select = ''; |
|
| 3186 | - if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3187 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3188 | - if (!isset($contexte['lang'])) { |
|
| 3189 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3190 | - } |
|
| 3191 | - |
|
| 3192 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3193 | - $lang_select = lang_select($contexte['lang']); |
|
| 3194 | - } |
|
| 3195 | - } |
|
| 3196 | - |
|
| 3197 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3198 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3199 | - } |
|
| 3200 | - |
|
| 3201 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3202 | - |
|
| 3203 | - // fix #4235 |
|
| 3204 | - $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3205 | - |
|
| 3206 | - |
|
| 3207 | - foreach (is_array($fond) ? $fond : array($fond) as $f) { |
|
| 3165 | + if (!function_exists('evaluer_fond')) { |
|
| 3166 | + include_spip('public/assembler'); |
|
| 3167 | + } |
|
| 3168 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3169 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3170 | + if (!is_array($options)) { |
|
| 3171 | + $options = array('trim' => $options); |
|
| 3172 | + } |
|
| 3173 | + if (!isset($options['trim'])) { |
|
| 3174 | + $options['trim'] = true; |
|
| 3175 | + } |
|
| 3176 | + |
|
| 3177 | + if (isset($contexte['connect'])) { |
|
| 3178 | + $connect = $contexte['connect']; |
|
| 3179 | + unset($contexte['connect']); |
|
| 3180 | + } |
|
| 3181 | + |
|
| 3182 | + $texte = ""; |
|
| 3183 | + $pages = array(); |
|
| 3184 | + $lang_select = ''; |
|
| 3185 | + if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3186 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3187 | + if (!isset($contexte['lang'])) { |
|
| 3188 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3189 | + } |
|
| 3190 | + |
|
| 3191 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3192 | + $lang_select = lang_select($contexte['lang']); |
|
| 3193 | + } |
|
| 3194 | + } |
|
| 3195 | + |
|
| 3196 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3197 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3198 | + } |
|
| 3199 | + |
|
| 3200 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3201 | + |
|
| 3202 | + // fix #4235 |
|
| 3203 | + $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3204 | + |
|
| 3205 | + |
|
| 3206 | + foreach (is_array($fond) ? $fond : array($fond) as $f) { |
|
| 3208 | 3207 | |
| 3209 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3210 | - |
|
| 3211 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3212 | - if ($page === '') { |
|
| 3213 | - $c = isset($options['compil']) ? $options['compil'] : ''; |
|
| 3214 | - $a = array('fichier' => $f); |
|
| 3215 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3216 | - erreur_squelette($erreur, $c); |
|
| 3217 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3218 | - $page = array('texte' => '', 'erreur' => $erreur); |
|
| 3219 | - } |
|
| 3220 | - |
|
| 3221 | - $page = pipeline('recuperer_fond', array( |
|
| 3222 | - 'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect), |
|
| 3223 | - 'data' => $page |
|
| 3224 | - )); |
|
| 3225 | - if (isset($options['ajax']) and $options['ajax']) { |
|
| 3226 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3227 | - include_spip('inc/filtres'); |
|
| 3228 | - } |
|
| 3229 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3230 | - array_merge( |
|
| 3231 | - $contexte, |
|
| 3232 | - array('fond' => $f), |
|
| 3233 | - ($connect ? array('connect' => $connect) : array()) |
|
| 3234 | - ), |
|
| 3235 | - '', |
|
| 3236 | - $page['texte'], |
|
| 3237 | - $options['ajax'] |
|
| 3238 | - ); |
|
| 3239 | - } |
|
| 3240 | - |
|
| 3241 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3242 | - $pages[] = $page; |
|
| 3243 | - } else { |
|
| 3244 | - $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3245 | - } |
|
| 3208 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3209 | + |
|
| 3210 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3211 | + if ($page === '') { |
|
| 3212 | + $c = isset($options['compil']) ? $options['compil'] : ''; |
|
| 3213 | + $a = array('fichier' => $f); |
|
| 3214 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3215 | + erreur_squelette($erreur, $c); |
|
| 3216 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3217 | + $page = array('texte' => '', 'erreur' => $erreur); |
|
| 3218 | + } |
|
| 3219 | + |
|
| 3220 | + $page = pipeline('recuperer_fond', array( |
|
| 3221 | + 'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect), |
|
| 3222 | + 'data' => $page |
|
| 3223 | + )); |
|
| 3224 | + if (isset($options['ajax']) and $options['ajax']) { |
|
| 3225 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3226 | + include_spip('inc/filtres'); |
|
| 3227 | + } |
|
| 3228 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3229 | + array_merge( |
|
| 3230 | + $contexte, |
|
| 3231 | + array('fond' => $f), |
|
| 3232 | + ($connect ? array('connect' => $connect) : array()) |
|
| 3233 | + ), |
|
| 3234 | + '', |
|
| 3235 | + $page['texte'], |
|
| 3236 | + $options['ajax'] |
|
| 3237 | + ); |
|
| 3238 | + } |
|
| 3239 | + |
|
| 3240 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3241 | + $pages[] = $page; |
|
| 3242 | + } else { |
|
| 3243 | + $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3244 | + } |
|
| 3246 | 3245 | |
| 3247 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3248 | - if (isset($page['invalideurs']['session'])){ |
|
| 3249 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3250 | - } |
|
| 3251 | - } |
|
| 3246 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3247 | + if (isset($page['invalideurs']['session'])){ |
|
| 3248 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3249 | + } |
|
| 3250 | + } |
|
| 3252 | 3251 | |
| 3253 | - // restaurer le sessionnement du contexte appelant, |
|
| 3254 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3255 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3256 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3257 | - } |
|
| 3252 | + // restaurer le sessionnement du contexte appelant, |
|
| 3253 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3254 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3255 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3256 | + } |
|
| 3258 | 3257 | |
| 3259 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3258 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3260 | 3259 | |
| 3261 | - if ($lang_select) { |
|
| 3262 | - lang_select(); |
|
| 3263 | - } |
|
| 3264 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3265 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3266 | - } else { |
|
| 3267 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3268 | - } |
|
| 3260 | + if ($lang_select) { |
|
| 3261 | + lang_select(); |
|
| 3262 | + } |
|
| 3263 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3264 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3265 | + } else { |
|
| 3266 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3267 | + } |
|
| 3269 | 3268 | } |
| 3270 | 3269 | |
| 3271 | 3270 | /** |
@@ -3275,7 +3274,7 @@ discard block |
||
| 3275 | 3274 | * @return string |
| 3276 | 3275 | */ |
| 3277 | 3276 | function trouve_modele($nom) { |
| 3278 | - return trouver_fond($nom, 'modeles/'); |
|
| 3277 | + return trouver_fond($nom, 'modeles/'); |
|
| 3279 | 3278 | } |
| 3280 | 3279 | |
| 3281 | 3280 | /** |
@@ -3291,21 +3290,21 @@ discard block |
||
| 3291 | 3290 | * @return array|string |
| 3292 | 3291 | */ |
| 3293 | 3292 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3294 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3295 | - if (!$pathinfo) { |
|
| 3296 | - return $f; |
|
| 3297 | - } |
|
| 3298 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3299 | - $p = pathinfo($f); |
|
| 3300 | - if (!isset($p['extension']) or !$p['extension']) { |
|
| 3301 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3302 | - } |
|
| 3303 | - if (!isset($p['extension']) or !$p['filename']) { |
|
| 3304 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3305 | - } |
|
| 3306 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3293 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3294 | + if (!$pathinfo) { |
|
| 3295 | + return $f; |
|
| 3296 | + } |
|
| 3297 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3298 | + $p = pathinfo($f); |
|
| 3299 | + if (!isset($p['extension']) or !$p['extension']) { |
|
| 3300 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3301 | + } |
|
| 3302 | + if (!isset($p['extension']) or !$p['filename']) { |
|
| 3303 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3304 | + } |
|
| 3305 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3307 | 3306 | |
| 3308 | - return $p; |
|
| 3307 | + return $p; |
|
| 3309 | 3308 | } |
| 3310 | 3309 | |
| 3311 | 3310 | /** |
@@ -3326,24 +3325,24 @@ discard block |
||
| 3326 | 3325 | * Nom de l'exec, sinon chaîne vide. |
| 3327 | 3326 | **/ |
| 3328 | 3327 | function tester_url_ecrire($nom) { |
| 3329 | - static $exec = array(); |
|
| 3330 | - if (isset($exec[$nom])) { |
|
| 3331 | - return $exec[$nom]; |
|
| 3332 | - } |
|
| 3333 | - // tester si c'est une page en squelette |
|
| 3334 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3335 | - return $exec[$nom] = 'fond'; |
|
| 3336 | - } // compat skels orthogonaux version precedente |
|
| 3337 | - elseif (trouver_fond($nom, 'prive/exec/')) { |
|
| 3338 | - return $exec[$nom] = 'fond_monobloc'; |
|
| 3339 | - } // echafaudage d'un fond ! |
|
| 3340 | - elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3341 | - return $exec[$nom] = 'fond'; |
|
| 3342 | - } |
|
| 3343 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3344 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3345 | - // et des define intrusifs potentiels |
|
| 3346 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3328 | + static $exec = array(); |
|
| 3329 | + if (isset($exec[$nom])) { |
|
| 3330 | + return $exec[$nom]; |
|
| 3331 | + } |
|
| 3332 | + // tester si c'est une page en squelette |
|
| 3333 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3334 | + return $exec[$nom] = 'fond'; |
|
| 3335 | + } // compat skels orthogonaux version precedente |
|
| 3336 | + elseif (trouver_fond($nom, 'prive/exec/')) { |
|
| 3337 | + return $exec[$nom] = 'fond_monobloc'; |
|
| 3338 | + } // echafaudage d'un fond ! |
|
| 3339 | + elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3340 | + return $exec[$nom] = 'fond'; |
|
| 3341 | + } |
|
| 3342 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3343 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3344 | + // et des define intrusifs potentiels |
|
| 3345 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3347 | 3346 | } |
| 3348 | 3347 | |
| 3349 | 3348 | |
@@ -3359,10 +3358,10 @@ discard block |
||
| 3359 | 3358 | * @return bool true si le module est chargé |
| 3360 | 3359 | **/ |
| 3361 | 3360 | function charger_php_extension($module) { |
| 3362 | - if (extension_loaded($module)) { |
|
| 3363 | - return true; |
|
| 3364 | - } |
|
| 3365 | - return false; |
|
| 3361 | + if (extension_loaded($module)) { |
|
| 3362 | + return true; |
|
| 3363 | + } |
|
| 3364 | + return false; |
|
| 3366 | 3365 | } |
| 3367 | 3366 | |
| 3368 | 3367 | |
@@ -3373,8 +3372,8 @@ discard block |
||
| 3373 | 3372 | * true si et seulement si la configuration autorise le code HTML5 sur le site public |
| 3374 | 3373 | **/ |
| 3375 | 3374 | function html5_permis() { |
| 3376 | - return (isset($GLOBALS['meta']['version_html_max']) |
|
| 3377 | - and ('html5' == $GLOBALS['meta']['version_html_max'])); |
|
| 3375 | + return (isset($GLOBALS['meta']['version_html_max']) |
|
| 3376 | + and ('html5' == $GLOBALS['meta']['version_html_max'])); |
|
| 3378 | 3377 | } |
| 3379 | 3378 | |
| 3380 | 3379 | /** |
@@ -3384,17 +3383,17 @@ discard block |
||
| 3384 | 3383 | * @return array |
| 3385 | 3384 | */ |
| 3386 | 3385 | function formats_image_acceptables($gd = false, $svg_allowed = true) { |
| 3387 | - $config = ($gd ? "gd_formats" : "formats_graphiques"); |
|
| 3388 | - $formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg'); |
|
| 3389 | - $formats = explode(',', $formats); |
|
| 3390 | - $formats = array_filter($formats); |
|
| 3391 | - $formats = array_map('trim', $formats); |
|
| 3386 | + $config = ($gd ? "gd_formats" : "formats_graphiques"); |
|
| 3387 | + $formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg'); |
|
| 3388 | + $formats = explode(',', $formats); |
|
| 3389 | + $formats = array_filter($formats); |
|
| 3390 | + $formats = array_map('trim', $formats); |
|
| 3392 | 3391 | |
| 3393 | - if ($svg_allowed) { |
|
| 3394 | - $formats[] = 'svg'; |
|
| 3395 | - } |
|
| 3392 | + if ($svg_allowed) { |
|
| 3393 | + $formats[] = 'svg'; |
|
| 3394 | + } |
|
| 3396 | 3395 | |
| 3397 | - return $formats; |
|
| 3396 | + return $formats; |
|
| 3398 | 3397 | } |
| 3399 | 3398 | |
| 3400 | 3399 | /** |
@@ -3403,21 +3402,21 @@ discard block |
||
| 3403 | 3402 | * @return array|bool |
| 3404 | 3403 | */ |
| 3405 | 3404 | function spip_getimagesize($fichier) { |
| 3406 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3405 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3407 | 3406 | |
| 3408 | - include_spip("inc/svg"); |
|
| 3409 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3410 | - list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 3411 | - $imagesize = [ |
|
| 3412 | - $width, |
|
| 3413 | - $height, |
|
| 3414 | - IMAGETYPE_SVG, |
|
| 3415 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3416 | - "mime" => "image/svg+xml" |
|
| 3417 | - ]; |
|
| 3418 | - } |
|
| 3419 | - } |
|
| 3420 | - return $imagesize; |
|
| 3407 | + include_spip("inc/svg"); |
|
| 3408 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3409 | + list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 3410 | + $imagesize = [ |
|
| 3411 | + $width, |
|
| 3412 | + $height, |
|
| 3413 | + IMAGETYPE_SVG, |
|
| 3414 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3415 | + "mime" => "image/svg+xml" |
|
| 3416 | + ]; |
|
| 3417 | + } |
|
| 3418 | + } |
|
| 3419 | + return $imagesize; |
|
| 3421 | 3420 | } |
| 3422 | 3421 | |
| 3423 | 3422 | |
@@ -3437,7 +3436,7 @@ discard block |
||
| 3437 | 3436 | * @return mixed Valeur de la meta. |
| 3438 | 3437 | **/ |
| 3439 | 3438 | function lire_meta($nom) { |
| 3440 | - return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null; |
|
| 3439 | + return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null; |
|
| 3441 | 3440 | } |
| 3442 | 3441 | |
| 3443 | 3442 | |
@@ -3459,128 +3458,128 @@ discard block |
||
| 3459 | 3458 | * @param string $statut |
| 3460 | 3459 | */ |
| 3461 | 3460 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3462 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3463 | - if (!$alertes |
|
| 3464 | - or !is_array($alertes = unserialize($alertes)) |
|
| 3465 | - ) { |
|
| 3466 | - $alertes = array(); |
|
| 3467 | - } |
|
| 3461 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3462 | + if (!$alertes |
|
| 3463 | + or !is_array($alertes = unserialize($alertes)) |
|
| 3464 | + ) { |
|
| 3465 | + $alertes = array(); |
|
| 3466 | + } |
|
| 3468 | 3467 | |
| 3469 | - if (!isset($alertes[$statut])) { |
|
| 3470 | - $alertes[$statut] = array(); |
|
| 3471 | - } |
|
| 3472 | - $alertes[$statut][$nom] = $message; |
|
| 3473 | - ecrire_meta("message_alertes_auteurs", serialize($alertes)); |
|
| 3468 | + if (!isset($alertes[$statut])) { |
|
| 3469 | + $alertes[$statut] = array(); |
|
| 3470 | + } |
|
| 3471 | + $alertes[$statut][$nom] = $message; |
|
| 3472 | + ecrire_meta("message_alertes_auteurs", serialize($alertes)); |
|
| 3474 | 3473 | } |
| 3475 | 3474 | |
| 3476 | 3475 | if (PHP_VERSION_ID < 50500) { |
| 3477 | - if (!function_exists('array_column')) { |
|
| 3478 | - /** |
|
| 3479 | - * Returns the values from a single column of the input array, identified by |
|
| 3480 | - * the $columnKey. |
|
| 3481 | - * |
|
| 3482 | - * Optionally, you may provide an $indexKey to index the values in the returned |
|
| 3483 | - * array by the values from the $indexKey column in the input array. |
|
| 3484 | - * |
|
| 3485 | - * @link http://php.net/manual/fr/function.array-column.php |
|
| 3486 | - * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php |
|
| 3487 | - * @copyright Copyright (c) Ben Ramsey (http://benramsey.com) |
|
| 3488 | - * @license http://opensource.org/licenses/MIT MIT |
|
| 3489 | - * |
|
| 3490 | - * @param array $input A multi-dimensional array (record set) from which to pull |
|
| 3491 | - * a column of values. |
|
| 3492 | - * @param mixed $columnKey The column of values to return. This value may be the |
|
| 3493 | - * integer key of the column you wish to retrieve, or it |
|
| 3494 | - * may be the string key name for an associative array. |
|
| 3495 | - * @param mixed $indexKey (Optional.) The column to use as the index/keys for |
|
| 3496 | - * the returned array. This value may be the integer key |
|
| 3497 | - * of the column, or it may be the string key name. |
|
| 3498 | - * @return array |
|
| 3499 | - */ |
|
| 3500 | - function array_column($input = null, $columnKey = null, $indexKey = null) |
|
| 3501 | - { |
|
| 3502 | - // Using func_get_args() in order to check for proper number of |
|
| 3503 | - // parameters and trigger errors exactly as the built-in array_column() |
|
| 3504 | - // does in PHP 5.5. |
|
| 3505 | - $argc = func_num_args(); |
|
| 3506 | - $params = func_get_args(); |
|
| 3507 | - |
|
| 3508 | - if ($argc < 2) { |
|
| 3509 | - trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING); |
|
| 3510 | - return null; |
|
| 3511 | - } |
|
| 3512 | - |
|
| 3513 | - if (!is_array($params[0])) { |
|
| 3514 | - trigger_error( |
|
| 3515 | - 'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', |
|
| 3516 | - E_USER_WARNING |
|
| 3517 | - ); |
|
| 3518 | - return null; |
|
| 3519 | - } |
|
| 3520 | - |
|
| 3521 | - if (!is_int($params[1]) |
|
| 3522 | - && !is_float($params[1]) |
|
| 3523 | - && !is_string($params[1]) |
|
| 3524 | - && $params[1] !== null |
|
| 3525 | - && !(is_object($params[1]) && method_exists($params[1], '__toString')) |
|
| 3526 | - ) { |
|
| 3527 | - trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); |
|
| 3528 | - return false; |
|
| 3529 | - } |
|
| 3530 | - |
|
| 3531 | - if (isset($params[2]) |
|
| 3532 | - && !is_int($params[2]) |
|
| 3533 | - && !is_float($params[2]) |
|
| 3534 | - && !is_string($params[2]) |
|
| 3535 | - && !(is_object($params[2]) && method_exists($params[2], '__toString')) |
|
| 3536 | - ) { |
|
| 3537 | - trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); |
|
| 3538 | - return false; |
|
| 3539 | - } |
|
| 3540 | - |
|
| 3541 | - $paramsInput = $params[0]; |
|
| 3542 | - $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null; |
|
| 3543 | - |
|
| 3544 | - $paramsIndexKey = null; |
|
| 3545 | - if (isset($params[2])) { |
|
| 3546 | - if (is_float($params[2]) || is_int($params[2])) { |
|
| 3547 | - $paramsIndexKey = (int) $params[2]; |
|
| 3548 | - } else { |
|
| 3549 | - $paramsIndexKey = (string) $params[2]; |
|
| 3550 | - } |
|
| 3551 | - } |
|
| 3552 | - |
|
| 3553 | - $resultArray = array(); |
|
| 3554 | - |
|
| 3555 | - foreach ($paramsInput as $row) { |
|
| 3556 | - $key = $value = null; |
|
| 3557 | - $keySet = $valueSet = false; |
|
| 3558 | - |
|
| 3559 | - if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) { |
|
| 3560 | - $keySet = true; |
|
| 3561 | - $key = (string) $row[$paramsIndexKey]; |
|
| 3562 | - } |
|
| 3563 | - |
|
| 3564 | - if ($paramsColumnKey === null) { |
|
| 3565 | - $valueSet = true; |
|
| 3566 | - $value = $row; |
|
| 3567 | - } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) { |
|
| 3568 | - $valueSet = true; |
|
| 3569 | - $value = $row[$paramsColumnKey]; |
|
| 3570 | - } |
|
| 3571 | - |
|
| 3572 | - if ($valueSet) { |
|
| 3573 | - if ($keySet) { |
|
| 3574 | - $resultArray[$key] = $value; |
|
| 3575 | - } else { |
|
| 3576 | - $resultArray[] = $value; |
|
| 3577 | - } |
|
| 3578 | - } |
|
| 3579 | - |
|
| 3580 | - } |
|
| 3581 | - |
|
| 3582 | - return $resultArray; |
|
| 3583 | - } |
|
| 3584 | - |
|
| 3585 | - } |
|
| 3476 | + if (!function_exists('array_column')) { |
|
| 3477 | + /** |
|
| 3478 | + * Returns the values from a single column of the input array, identified by |
|
| 3479 | + * the $columnKey. |
|
| 3480 | + * |
|
| 3481 | + * Optionally, you may provide an $indexKey to index the values in the returned |
|
| 3482 | + * array by the values from the $indexKey column in the input array. |
|
| 3483 | + * |
|
| 3484 | + * @link http://php.net/manual/fr/function.array-column.php |
|
| 3485 | + * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php |
|
| 3486 | + * @copyright Copyright (c) Ben Ramsey (http://benramsey.com) |
|
| 3487 | + * @license http://opensource.org/licenses/MIT MIT |
|
| 3488 | + * |
|
| 3489 | + * @param array $input A multi-dimensional array (record set) from which to pull |
|
| 3490 | + * a column of values. |
|
| 3491 | + * @param mixed $columnKey The column of values to return. This value may be the |
|
| 3492 | + * integer key of the column you wish to retrieve, or it |
|
| 3493 | + * may be the string key name for an associative array. |
|
| 3494 | + * @param mixed $indexKey (Optional.) The column to use as the index/keys for |
|
| 3495 | + * the returned array. This value may be the integer key |
|
| 3496 | + * of the column, or it may be the string key name. |
|
| 3497 | + * @return array |
|
| 3498 | + */ |
|
| 3499 | + function array_column($input = null, $columnKey = null, $indexKey = null) |
|
| 3500 | + { |
|
| 3501 | + // Using func_get_args() in order to check for proper number of |
|
| 3502 | + // parameters and trigger errors exactly as the built-in array_column() |
|
| 3503 | + // does in PHP 5.5. |
|
| 3504 | + $argc = func_num_args(); |
|
| 3505 | + $params = func_get_args(); |
|
| 3506 | + |
|
| 3507 | + if ($argc < 2) { |
|
| 3508 | + trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING); |
|
| 3509 | + return null; |
|
| 3510 | + } |
|
| 3511 | + |
|
| 3512 | + if (!is_array($params[0])) { |
|
| 3513 | + trigger_error( |
|
| 3514 | + 'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', |
|
| 3515 | + E_USER_WARNING |
|
| 3516 | + ); |
|
| 3517 | + return null; |
|
| 3518 | + } |
|
| 3519 | + |
|
| 3520 | + if (!is_int($params[1]) |
|
| 3521 | + && !is_float($params[1]) |
|
| 3522 | + && !is_string($params[1]) |
|
| 3523 | + && $params[1] !== null |
|
| 3524 | + && !(is_object($params[1]) && method_exists($params[1], '__toString')) |
|
| 3525 | + ) { |
|
| 3526 | + trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); |
|
| 3527 | + return false; |
|
| 3528 | + } |
|
| 3529 | + |
|
| 3530 | + if (isset($params[2]) |
|
| 3531 | + && !is_int($params[2]) |
|
| 3532 | + && !is_float($params[2]) |
|
| 3533 | + && !is_string($params[2]) |
|
| 3534 | + && !(is_object($params[2]) && method_exists($params[2], '__toString')) |
|
| 3535 | + ) { |
|
| 3536 | + trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); |
|
| 3537 | + return false; |
|
| 3538 | + } |
|
| 3539 | + |
|
| 3540 | + $paramsInput = $params[0]; |
|
| 3541 | + $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null; |
|
| 3542 | + |
|
| 3543 | + $paramsIndexKey = null; |
|
| 3544 | + if (isset($params[2])) { |
|
| 3545 | + if (is_float($params[2]) || is_int($params[2])) { |
|
| 3546 | + $paramsIndexKey = (int) $params[2]; |
|
| 3547 | + } else { |
|
| 3548 | + $paramsIndexKey = (string) $params[2]; |
|
| 3549 | + } |
|
| 3550 | + } |
|
| 3551 | + |
|
| 3552 | + $resultArray = array(); |
|
| 3553 | + |
|
| 3554 | + foreach ($paramsInput as $row) { |
|
| 3555 | + $key = $value = null; |
|
| 3556 | + $keySet = $valueSet = false; |
|
| 3557 | + |
|
| 3558 | + if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) { |
|
| 3559 | + $keySet = true; |
|
| 3560 | + $key = (string) $row[$paramsIndexKey]; |
|
| 3561 | + } |
|
| 3562 | + |
|
| 3563 | + if ($paramsColumnKey === null) { |
|
| 3564 | + $valueSet = true; |
|
| 3565 | + $value = $row; |
|
| 3566 | + } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) { |
|
| 3567 | + $valueSet = true; |
|
| 3568 | + $value = $row[$paramsColumnKey]; |
|
| 3569 | + } |
|
| 3570 | + |
|
| 3571 | + if ($valueSet) { |
|
| 3572 | + if ($keySet) { |
|
| 3573 | + $resultArray[$key] = $value; |
|
| 3574 | + } else { |
|
| 3575 | + $resultArray[] = $value; |
|
| 3576 | + } |
|
| 3577 | + } |
|
| 3578 | + |
|
| 3579 | + } |
|
| 3580 | + |
|
| 3581 | + return $resultArray; |
|
| 3582 | + } |
|
| 3583 | + |
|
| 3584 | + } |
|
| 3586 | 3585 | } |
@@ -1392,8 +1392,7 @@ discard block |
||
| 1392 | 1392 | and $f = find_in_theme("$file_svg_generique")) { |
| 1393 | 1393 | if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) { |
| 1394 | 1394 | return $themefiles["$subdir$file"] = $fsize; |
| 1395 | - } |
|
| 1396 | - else { |
|
| 1395 | + } else { |
|
| 1397 | 1396 | return $themefiles["$subdir$file"] = "$f?".$m[1]."px"; |
| 1398 | 1397 | } |
| 1399 | 1398 | } |
@@ -2333,12 +2332,13 @@ discard block |
||
| 2333 | 2332 | define('_DIR_CHMOD', $pi); |
| 2334 | 2333 | } |
| 2335 | 2334 | |
| 2336 | - if (!isset($GLOBALS['test_dirs'])) |
|
| 2337 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2335 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 2336 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2338 | 2337 | // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
| 2339 | 2338 | { |
| 2340 | 2339 | $GLOBALS['test_dirs'] = array($pa, $ti, $ta); |
| 2341 | 2340 | } |
| 2341 | + } |
|
| 2342 | 2342 | |
| 2343 | 2343 | // Declaration des fichiers |
| 2344 | 2344 | |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | - define('IMG_SVG',128); |
|
| 26 | - define('IMAGETYPE_SVG', 19); |
|
| 24 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | + define('IMG_SVG',128); |
|
| 26 | + define('IMAGETYPE_SVG', 19); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | 41 | function svg_charger($fichier, $maxlen=null) { |
| 42 | - if (strpos($fichier, "data:image/svg+xml") === 0) { |
|
| 43 | - $image = explode(";", $fichier, 2); |
|
| 44 | - $image = end($image); |
|
| 45 | - if (strpos($image, "base64,") === 0) { |
|
| 46 | - $image = base64_decode(substr($image, 7)); |
|
| 47 | - } |
|
| 48 | - if (strpos($image, "<svg") !== false) { |
|
| 49 | - return $image; |
|
| 50 | - } |
|
| 51 | - // encodage inconnu ou autre format d'image ? |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - // c'est peut etre deja une image svg ? |
|
| 55 | - if (strpos($fichier, "<svg") !== false) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - if (!file_exists($fichier)) { |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (is_null($maxlen)) { |
|
| 65 | - $image = file_get_contents($fichier); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - $image = file_get_contents($fichier, false,null,0, $maxlen); |
|
| 69 | - } |
|
| 70 | - // est-ce bien une image svg ? |
|
| 71 | - if (strpos($image, "<svg") !== false) { |
|
| 72 | - return $image; |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 42 | + if (strpos($fichier, "data:image/svg+xml") === 0) { |
|
| 43 | + $image = explode(";", $fichier, 2); |
|
| 44 | + $image = end($image); |
|
| 45 | + if (strpos($image, "base64,") === 0) { |
|
| 46 | + $image = base64_decode(substr($image, 7)); |
|
| 47 | + } |
|
| 48 | + if (strpos($image, "<svg") !== false) { |
|
| 49 | + return $image; |
|
| 50 | + } |
|
| 51 | + // encodage inconnu ou autre format d'image ? |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + // c'est peut etre deja une image svg ? |
|
| 55 | + if (strpos($fichier, "<svg") !== false) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + if (!file_exists($fichier)) { |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (is_null($maxlen)) { |
|
| 65 | + $image = file_get_contents($fichier); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + $image = file_get_contents($fichier, false,null,0, $maxlen); |
|
| 69 | + } |
|
| 70 | + // est-ce bien une image svg ? |
|
| 71 | + if (strpos($image, "<svg") !== false) { |
|
| 72 | + return $image; |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,29 +80,29 @@ discard block |
||
| 80 | 80 | * @return array|bool |
| 81 | 81 | */ |
| 82 | 82 | function svg_lire_balise_svg($fichier) { |
| 83 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 83 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if (($ps = stripos($debut_fichier, "<svg")) !== false) { |
|
| 87 | + if (($ps = stripos($debut_fichier, "<svg")) !== false) { |
|
| 88 | 88 | |
| 89 | - $pe = stripos($debut_fichier, ">", $ps); |
|
| 90 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps +1); |
|
| 89 | + $pe = stripos($debut_fichier, ">", $ps); |
|
| 90 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps +1); |
|
| 91 | 91 | |
| 92 | - if (preg_match_all(",([\w:\-]+)=,Uims", $balise_svg, $matches)) { |
|
| 93 | - if (!function_exists('extraire_attribut')) { |
|
| 94 | - include_spip('inc/filtres'); |
|
| 95 | - } |
|
| 96 | - $attributs = []; |
|
| 97 | - foreach ($matches[1] as $att) { |
|
| 98 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 99 | - } |
|
| 92 | + if (preg_match_all(",([\w:\-]+)=,Uims", $balise_svg, $matches)) { |
|
| 93 | + if (!function_exists('extraire_attribut')) { |
|
| 94 | + include_spip('inc/filtres'); |
|
| 95 | + } |
|
| 96 | + $attributs = []; |
|
| 97 | + foreach ($matches[1] as $att) { |
|
| 98 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return [$balise_svg, $attributs]; |
|
| 102 | - } |
|
| 103 | - } |
|
| 101 | + return [$balise_svg, $attributs]; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return false; |
|
| 105 | + return false; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | function svg_lire_attributs($img) { |
| 114 | 114 | |
| 115 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 116 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 117 | - return $attributs; |
|
| 118 | - } |
|
| 115 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 116 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 117 | + return $attributs; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return false; |
|
| 120 | + return false; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,38 +127,38 @@ discard block |
||
| 127 | 127 | * @return bool|float|int |
| 128 | 128 | */ |
| 129 | 129 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 130 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)){ |
|
| 131 | - switch (strtolower($m[2])) { |
|
| 132 | - case '%': |
|
| 133 | - // on ne sait pas faire :( |
|
| 134 | - return false; |
|
| 135 | - break; |
|
| 136 | - case 'em': |
|
| 137 | - return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 138 | - break; |
|
| 139 | - case 'ex': |
|
| 140 | - return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 141 | - break; |
|
| 142 | - case 'pc': |
|
| 143 | - return round($m[1]*16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 144 | - break; |
|
| 145 | - case 'cm': |
|
| 146 | - return round($m[1]*96/2.54, $precision); // 96px / 2.54cm; |
|
| 147 | - break; |
|
| 148 | - case 'mm': |
|
| 149 | - return round($m[1]*96/25.4, $precision); // 96px / 25.4mm; |
|
| 150 | - break; |
|
| 151 | - case 'in': |
|
| 152 | - return round($m[1]*96, $precision); // 1 inch = 96px in CSS |
|
| 153 | - break; |
|
| 154 | - case 'px': |
|
| 155 | - case 'pt': |
|
| 156 | - default: |
|
| 157 | - return $m[1]; |
|
| 158 | - break; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - return false; |
|
| 130 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)){ |
|
| 131 | + switch (strtolower($m[2])) { |
|
| 132 | + case '%': |
|
| 133 | + // on ne sait pas faire :( |
|
| 134 | + return false; |
|
| 135 | + break; |
|
| 136 | + case 'em': |
|
| 137 | + return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 138 | + break; |
|
| 139 | + case 'ex': |
|
| 140 | + return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 141 | + break; |
|
| 142 | + case 'pc': |
|
| 143 | + return round($m[1]*16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 144 | + break; |
|
| 145 | + case 'cm': |
|
| 146 | + return round($m[1]*96/2.54, $precision); // 96px / 2.54cm; |
|
| 147 | + break; |
|
| 148 | + case 'mm': |
|
| 149 | + return round($m[1]*96/25.4, $precision); // 96px / 25.4mm; |
|
| 150 | + break; |
|
| 151 | + case 'in': |
|
| 152 | + return round($m[1]*96, $precision); // 1 inch = 96px in CSS |
|
| 153 | + break; |
|
| 154 | + case 'px': |
|
| 155 | + case 'pt': |
|
| 156 | + default: |
|
| 157 | + return $m[1]; |
|
| 158 | + break; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + return false; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -169,15 +169,15 @@ discard block |
||
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | 171 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 172 | - $new_balise_svg = "<svg"; |
|
| 173 | - foreach ($attributs as $k=>$v) { |
|
| 174 | - $new_balise_svg .= " $k=\"".entites_html($v)."\""; |
|
| 175 | - } |
|
| 176 | - $new_balise_svg .= ">"; |
|
| 177 | - |
|
| 178 | - $p = strpos($svg, $old_balise_svg); |
|
| 179 | - $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 180 | - return $svg; |
|
| 172 | + $new_balise_svg = "<svg"; |
|
| 173 | + foreach ($attributs as $k=>$v) { |
|
| 174 | + $new_balise_svg .= " $k=\"".entites_html($v)."\""; |
|
| 175 | + } |
|
| 176 | + $new_balise_svg .= ">"; |
|
| 177 | + |
|
| 178 | + $p = strpos($svg, $old_balise_svg); |
|
| 179 | + $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 180 | + return $svg; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -189,15 +189,15 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | function svg_insert_shapes($svg, $shapes, $start=true) { |
| 191 | 191 | |
| 192 | - if ($start === false or $start === 'end') { |
|
| 193 | - $svg = str_replace("</svg>", $shapes . "</svg>", $svg); |
|
| 194 | - } |
|
| 195 | - else { |
|
| 196 | - $p = stripos($svg, "<svg"); |
|
| 197 | - $p = strpos($svg, ">", $p); |
|
| 198 | - $svg = substr_replace($svg, $shapes, $p+1, 0); |
|
| 199 | - } |
|
| 200 | - return $svg; |
|
| 192 | + if ($start === false or $start === 'end') { |
|
| 193 | + $svg = str_replace("</svg>", $shapes . "</svg>", $svg); |
|
| 194 | + } |
|
| 195 | + else { |
|
| 196 | + $p = stripos($svg, "<svg"); |
|
| 197 | + $p = strpos($svg, ">", $p); |
|
| 198 | + $svg = substr_replace($svg, $shapes, $p+1, 0); |
|
| 199 | + } |
|
| 200 | + return $svg; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 213 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 214 | - $id = 'clip-'.substr(md5($rect . strlen($svg)),0,8); |
|
| 215 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 216 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 217 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 218 | - $svg = svg_insert_shapes($svg, "</g>", false); |
|
| 219 | - return $svg; |
|
| 213 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 214 | + $id = 'clip-'.substr(md5($rect . strlen($svg)),0,8); |
|
| 215 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 216 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 217 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 218 | + $svg = svg_insert_shapes($svg, "</g>", false); |
|
| 219 | + return $svg; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,21 +227,21 @@ discard block |
||
| 227 | 227 | * @return bool|string |
| 228 | 228 | */ |
| 229 | 229 | function svg_redimensionner($img, $new_width, $new_height) { |
| 230 | - if ($svg = svg_charger($img) |
|
| 231 | - and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 230 | + if ($svg = svg_charger($img) |
|
| 231 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 232 | 232 | |
| 233 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 234 | - if (!isset($attributs['viewBox'])) { |
|
| 235 | - $attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height']; |
|
| 236 | - } |
|
| 237 | - $attributs['width'] = strval($new_width); |
|
| 238 | - $attributs['height'] = strval($new_height); |
|
| 233 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 234 | + if (!isset($attributs['viewBox'])) { |
|
| 235 | + $attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height']; |
|
| 236 | + } |
|
| 237 | + $attributs['width'] = strval($new_width); |
|
| 238 | + $attributs['height'] = strval($new_height); |
|
| 239 | 239 | |
| 240 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | - return $svg; |
|
| 242 | - } |
|
| 240 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | + return $svg; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - return $img; |
|
| 244 | + return $img; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,15 +250,15 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, "rgb(")===0) { |
|
| 254 | - $c = explode(',', substr($couleur, 4)); |
|
| 255 | - $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | - } |
|
| 257 | - else { |
|
| 258 | - $couleur = couleur_html_to_hex($couleur); |
|
| 259 | - } |
|
| 260 | - $couleur = '#'.ltrim($couleur,'#'); |
|
| 261 | - return $couleur; |
|
| 253 | + if (strpos($couleur, "rgb(")===0) { |
|
| 254 | + $c = explode(',', substr($couleur, 4)); |
|
| 255 | + $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | + } |
|
| 257 | + else { |
|
| 258 | + $couleur = couleur_html_to_hex($couleur); |
|
| 259 | + } |
|
| 260 | + $couleur = '#'.ltrim($couleur,'#'); |
|
| 261 | + return $couleur; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, "rgb(")===0) { |
|
| 271 | - $c = explode(',', substr($couleur, 4)); |
|
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | - } |
|
| 274 | - return _couleur_hex_to_dec($couleur); |
|
| 270 | + if (strpos($couleur, "rgb(")===0) { |
|
| 271 | + $c = explode(',', substr($couleur, 4)); |
|
| 272 | + return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | + } |
|
| 274 | + return _couleur_hex_to_dec($couleur); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -281,66 +281,66 @@ discard block |
||
| 281 | 281 | * @return array |
| 282 | 282 | */ |
| 283 | 283 | function svg_getimagesize_from_attr($attributs) { |
| 284 | - $width = 350; // default width |
|
| 285 | - $height = 150; // default height |
|
| 286 | - |
|
| 287 | - $viewBox = "0 0 $width $height"; |
|
| 288 | - if (isset($attributs['viewBox'])) { |
|
| 289 | - $viewBox = $attributs['viewBox']; |
|
| 290 | - $viewBox = preg_replace(",\s+,", " ", $viewBox); |
|
| 291 | - } |
|
| 292 | - // et on la convertit en px |
|
| 293 | - $viewBox = explode(' ', $viewBox); |
|
| 294 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | - if (!$viewBox[2]) { |
|
| 296 | - $viewBox[2] = $width; |
|
| 297 | - } |
|
| 298 | - if (!$viewBox[3]) { |
|
| 299 | - $viewBox[3] = $height; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $coeff = 1; |
|
| 303 | - if (isset($attributs['width']) |
|
| 304 | - and $w = svg_dimension_to_pixels($attributs['width'])) { |
|
| 305 | - $width = $w; |
|
| 306 | - } |
|
| 307 | - else { |
|
| 308 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 309 | - $width = $viewBox[2]; |
|
| 310 | - if ($width < 1) { |
|
| 311 | - $coeff = max($coeff, 1000); |
|
| 312 | - } |
|
| 313 | - elseif ($width < 10) { |
|
| 314 | - $coeff = max($coeff, 100); |
|
| 315 | - } |
|
| 316 | - elseif ($width < 100) { |
|
| 317 | - $coeff = max($coeff, 10); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - if (isset($attributs['height']) |
|
| 321 | - and $h = svg_dimension_to_pixels($attributs['height'])) { |
|
| 322 | - $height = $h; |
|
| 323 | - } |
|
| 324 | - else { |
|
| 325 | - $height = $viewBox[3]; |
|
| 326 | - if ($height < 1) { |
|
| 327 | - $coeff = max($coeff, 1000); |
|
| 328 | - } |
|
| 329 | - elseif ($height < 10) { |
|
| 330 | - $coeff = max($coeff, 100); |
|
| 331 | - } |
|
| 332 | - elseif ($height < 100) { |
|
| 333 | - $coeff = max($coeff, 10); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - // arrondir le width et height en pixel in fine |
|
| 338 | - $width = round($coeff * $width); |
|
| 339 | - $height = round($coeff * $height); |
|
| 340 | - |
|
| 341 | - $viewBox = implode(' ', $viewBox); |
|
| 342 | - |
|
| 343 | - return array($width, $height, $viewBox); |
|
| 284 | + $width = 350; // default width |
|
| 285 | + $height = 150; // default height |
|
| 286 | + |
|
| 287 | + $viewBox = "0 0 $width $height"; |
|
| 288 | + if (isset($attributs['viewBox'])) { |
|
| 289 | + $viewBox = $attributs['viewBox']; |
|
| 290 | + $viewBox = preg_replace(",\s+,", " ", $viewBox); |
|
| 291 | + } |
|
| 292 | + // et on la convertit en px |
|
| 293 | + $viewBox = explode(' ', $viewBox); |
|
| 294 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | + if (!$viewBox[2]) { |
|
| 296 | + $viewBox[2] = $width; |
|
| 297 | + } |
|
| 298 | + if (!$viewBox[3]) { |
|
| 299 | + $viewBox[3] = $height; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $coeff = 1; |
|
| 303 | + if (isset($attributs['width']) |
|
| 304 | + and $w = svg_dimension_to_pixels($attributs['width'])) { |
|
| 305 | + $width = $w; |
|
| 306 | + } |
|
| 307 | + else { |
|
| 308 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 309 | + $width = $viewBox[2]; |
|
| 310 | + if ($width < 1) { |
|
| 311 | + $coeff = max($coeff, 1000); |
|
| 312 | + } |
|
| 313 | + elseif ($width < 10) { |
|
| 314 | + $coeff = max($coeff, 100); |
|
| 315 | + } |
|
| 316 | + elseif ($width < 100) { |
|
| 317 | + $coeff = max($coeff, 10); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + if (isset($attributs['height']) |
|
| 321 | + and $h = svg_dimension_to_pixels($attributs['height'])) { |
|
| 322 | + $height = $h; |
|
| 323 | + } |
|
| 324 | + else { |
|
| 325 | + $height = $viewBox[3]; |
|
| 326 | + if ($height < 1) { |
|
| 327 | + $coeff = max($coeff, 1000); |
|
| 328 | + } |
|
| 329 | + elseif ($height < 10) { |
|
| 330 | + $coeff = max($coeff, 100); |
|
| 331 | + } |
|
| 332 | + elseif ($height < 100) { |
|
| 333 | + $coeff = max($coeff, 10); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // arrondir le width et height en pixel in fine |
|
| 338 | + $width = round($coeff * $width); |
|
| 339 | + $height = round($coeff * $height); |
|
| 340 | + |
|
| 341 | + $viewBox = implode(' ', $viewBox); |
|
| 342 | + |
|
| 343 | + return array($width, $height, $viewBox); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -356,24 +356,24 @@ discard block |
||
| 356 | 356 | * @return string |
| 357 | 357 | */ |
| 358 | 358 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 359 | - if ($svg = svg_charger($img) |
|
| 360 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 359 | + if ($svg = svg_charger($img) |
|
| 360 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 361 | 361 | |
| 362 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 362 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 363 | 363 | |
| 364 | - list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs); |
|
| 364 | + list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs); |
|
| 365 | 365 | |
| 366 | - if ($force_width_and_height) { |
|
| 367 | - $attributs['width'] = $width; |
|
| 368 | - $attributs['height'] = $height; |
|
| 369 | - } |
|
| 366 | + if ($force_width_and_height) { |
|
| 367 | + $attributs['width'] = $width; |
|
| 368 | + $attributs['height'] = $height; |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - $attributs['viewBox'] = $viewBox; |
|
| 371 | + $attributs['viewBox'] = $viewBox; |
|
| 372 | 372 | |
| 373 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 374 | - return $svg; |
|
| 375 | - } |
|
| 376 | - return $img; |
|
| 373 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 374 | + return $svg; |
|
| 375 | + } |
|
| 376 | + return $img; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -382,12 +382,12 @@ discard block |
||
| 382 | 382 | * @return array|mixed |
| 383 | 383 | */ |
| 384 | 384 | function svg_extract_couleurs($img) { |
| 385 | - if ($svg = svg_charger($img)) { |
|
| 386 | - if (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)) { |
|
| 387 | - return $matches[0]; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - return []; |
|
| 385 | + if ($svg = svg_charger($img)) { |
|
| 386 | + if (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)) { |
|
| 387 | + return $matches[0]; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + return []; |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -398,56 +398,56 @@ discard block |
||
| 398 | 398 | * @return bool|string |
| 399 | 399 | */ |
| 400 | 400 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color='') { |
| 401 | - if ($svg = svg_force_viewBox_px($img) |
|
| 402 | - and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 403 | - |
|
| 404 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 405 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 406 | - |
|
| 407 | - $viewport_w = $new_width; |
|
| 408 | - $viewport_h = $new_height; |
|
| 409 | - $viewport_ox = $offset_width; |
|
| 410 | - $viewport_oy = $offset_height; |
|
| 411 | - |
|
| 412 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 413 | - if (isset ($attributs['width']) |
|
| 414 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 415 | - and isset ($attributs['height']) |
|
| 416 | - and $h = svg_dimension_to_pixels($attributs['height'])) { |
|
| 417 | - |
|
| 418 | - $xscale = $viewBox[2] / $w; |
|
| 419 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 420 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 421 | - $yscale = $viewBox[3] / $h; |
|
| 422 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 423 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) { |
|
| 427 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // maintenant on redefinit la viewBox |
|
| 431 | - $viewBox[0] += $viewport_ox; |
|
| 432 | - $viewBox[1] += $viewport_oy; |
|
| 433 | - $viewBox[2] = $viewport_w; |
|
| 434 | - $viewBox[3] = $viewport_h; |
|
| 435 | - |
|
| 436 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 437 | - $attributs['width'] = strval($new_width); |
|
| 438 | - $attributs['height'] = strval($new_height); |
|
| 439 | - |
|
| 440 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 441 | - |
|
| 442 | - // ajouter un background |
|
| 443 | - if ($background_color and $background_color!=='transparent') { |
|
| 444 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - return $svg; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return $img; |
|
| 401 | + if ($svg = svg_force_viewBox_px($img) |
|
| 402 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 403 | + |
|
| 404 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 405 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 406 | + |
|
| 407 | + $viewport_w = $new_width; |
|
| 408 | + $viewport_h = $new_height; |
|
| 409 | + $viewport_ox = $offset_width; |
|
| 410 | + $viewport_oy = $offset_height; |
|
| 411 | + |
|
| 412 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 413 | + if (isset ($attributs['width']) |
|
| 414 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 415 | + and isset ($attributs['height']) |
|
| 416 | + and $h = svg_dimension_to_pixels($attributs['height'])) { |
|
| 417 | + |
|
| 418 | + $xscale = $viewBox[2] / $w; |
|
| 419 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 420 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 421 | + $yscale = $viewBox[3] / $h; |
|
| 422 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 423 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) { |
|
| 427 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // maintenant on redefinit la viewBox |
|
| 431 | + $viewBox[0] += $viewport_ox; |
|
| 432 | + $viewBox[1] += $viewport_oy; |
|
| 433 | + $viewBox[2] = $viewport_w; |
|
| 434 | + $viewBox[3] = $viewport_h; |
|
| 435 | + |
|
| 436 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 437 | + $attributs['width'] = strval($new_width); |
|
| 438 | + $attributs['height'] = strval($new_height); |
|
| 439 | + |
|
| 440 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 441 | + |
|
| 442 | + // ajouter un background |
|
| 443 | + if ($background_color and $background_color!=='transparent') { |
|
| 444 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + return $svg; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return $img; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -457,25 +457,25 @@ discard block |
||
| 457 | 457 | * @return bool|string |
| 458 | 458 | */ |
| 459 | 459 | function svg_ajouter_background($img, $background_color) { |
| 460 | - if ($svg = svg_charger($img) |
|
| 461 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 462 | - |
|
| 463 | - if ($background_color and $background_color!=='transparent') { |
|
| 464 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 465 | - |
|
| 466 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 467 | - if (isset($attributs['viewBox'])) { |
|
| 468 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 469 | - $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\"/>"; |
|
| 470 | - } |
|
| 471 | - else { |
|
| 472 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 473 | - } |
|
| 474 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 475 | - } |
|
| 476 | - return $svg; |
|
| 477 | - } |
|
| 478 | - return $img; |
|
| 460 | + if ($svg = svg_charger($img) |
|
| 461 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 462 | + |
|
| 463 | + if ($background_color and $background_color!=='transparent') { |
|
| 464 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 465 | + |
|
| 466 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 467 | + if (isset($attributs['viewBox'])) { |
|
| 468 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 469 | + $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\"/>"; |
|
| 470 | + } |
|
| 471 | + else { |
|
| 472 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 473 | + } |
|
| 474 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 475 | + } |
|
| 476 | + return $svg; |
|
| 477 | + } |
|
| 478 | + return $img; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -486,25 +486,25 @@ discard block |
||
| 486 | 486 | * @return bool|string |
| 487 | 487 | */ |
| 488 | 488 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 489 | - if ($svg = svg_charger($img) |
|
| 490 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 491 | - |
|
| 492 | - if ($background_color and $background_color!=='transparent') { |
|
| 493 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 494 | - |
|
| 495 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 496 | - if (isset($attributs['viewBox'])) { |
|
| 497 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 498 | - $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 499 | - } |
|
| 500 | - else { |
|
| 501 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 502 | - } |
|
| 503 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 504 | - } |
|
| 505 | - return $svg; |
|
| 506 | - } |
|
| 507 | - return $img; |
|
| 489 | + if ($svg = svg_charger($img) |
|
| 490 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 491 | + |
|
| 492 | + if ($background_color and $background_color!=='transparent') { |
|
| 493 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 494 | + |
|
| 495 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 496 | + if (isset($attributs['viewBox'])) { |
|
| 497 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 498 | + $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 499 | + } |
|
| 500 | + else { |
|
| 501 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 502 | + } |
|
| 503 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 504 | + } |
|
| 505 | + return $svg; |
|
| 506 | + } |
|
| 507 | + return $img; |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | |
@@ -515,26 +515,26 @@ discard block |
||
| 515 | 515 | * @return bool|string |
| 516 | 516 | */ |
| 517 | 517 | function svg_transformer($img, $attributs) { |
| 518 | - if ($svg = svg_charger($img) |
|
| 519 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 520 | - |
|
| 521 | - if ($attributs) { |
|
| 522 | - list($balise_svg, ) = $svg_infos; |
|
| 523 | - $g = "<g"; |
|
| 524 | - foreach ($attributs as $k=>$v) { |
|
| 525 | - if (strlen($v)) { |
|
| 526 | - $g .= " $k=\"".attribut_html($v)."\""; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - if (strlen($g) > 2) { |
|
| 530 | - $g .= ">"; |
|
| 531 | - $svg = svg_insert_shapes($svg, $g); |
|
| 532 | - $svg = svg_insert_shapes($svg, "</g>", false); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - return $svg; |
|
| 536 | - } |
|
| 537 | - return $img; |
|
| 518 | + if ($svg = svg_charger($img) |
|
| 519 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 520 | + |
|
| 521 | + if ($attributs) { |
|
| 522 | + list($balise_svg, ) = $svg_infos; |
|
| 523 | + $g = "<g"; |
|
| 524 | + foreach ($attributs as $k=>$v) { |
|
| 525 | + if (strlen($v)) { |
|
| 526 | + $g .= " $k=\"".attribut_html($v)."\""; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + if (strlen($g) > 2) { |
|
| 530 | + $g .= ">"; |
|
| 531 | + $svg = svg_insert_shapes($svg, $g); |
|
| 532 | + $svg = svg_insert_shapes($svg, "</g>", false); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + return $svg; |
|
| 536 | + } |
|
| 537 | + return $img; |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -545,20 +545,20 @@ discard block |
||
| 545 | 545 | * @return bool|string |
| 546 | 546 | */ |
| 547 | 547 | function svg_apply_filter($img, $filter_def) { |
| 548 | - if ($svg = svg_charger($img) |
|
| 549 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 550 | - |
|
| 551 | - if ($filter_def) { |
|
| 552 | - list($balise_svg, ) = $svg_infos; |
|
| 553 | - $filter_id = "filter-". substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 554 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 555 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 556 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 557 | - $svg = svg_insert_shapes($svg, "</g>", false); |
|
| 558 | - } |
|
| 559 | - return $svg; |
|
| 560 | - } |
|
| 561 | - return $img; |
|
| 548 | + if ($svg = svg_charger($img) |
|
| 549 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 550 | + |
|
| 551 | + if ($filter_def) { |
|
| 552 | + list($balise_svg, ) = $svg_infos; |
|
| 553 | + $filter_id = "filter-". substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 554 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 555 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 556 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 557 | + $svg = svg_insert_shapes($svg, "</g>", false); |
|
| 558 | + } |
|
| 559 | + return $svg; |
|
| 560 | + } |
|
| 561 | + return $img; |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | * @return string |
| 569 | 569 | */ |
| 570 | 570 | function svg_filter_blur($img, $blur_width) { |
| 571 | - $blur_width = intval($blur_width); |
|
| 572 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 571 | + $blur_width = intval($blur_width); |
|
| 572 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -579,10 +579,10 @@ discard block |
||
| 579 | 579 | * @return bool|string |
| 580 | 580 | */ |
| 581 | 581 | function svg_filter_grayscale($img, $intensity) { |
| 582 | - $value = round(1.0 - $intensity, 2); |
|
| 583 | - //$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\"/>"; |
|
| 584 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 585 | - return svg_apply_filter($img, $filter); |
|
| 582 | + $value = round(1.0 - $intensity, 2); |
|
| 583 | + //$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\"/>"; |
|
| 584 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 585 | + return svg_apply_filter($img, $filter); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -592,8 +592,8 @@ discard block |
||
| 592 | 592 | * @return bool|string |
| 593 | 593 | */ |
| 594 | 594 | function svg_filter_sepia($img, $intensity) { |
| 595 | - $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\"/>"; |
|
| 596 | - return svg_apply_filter($img, $filter); |
|
| 595 | + $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\"/>"; |
|
| 596 | + return svg_apply_filter($img, $filter); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -603,30 +603,30 @@ discard block |
||
| 603 | 603 | * @return bool|string |
| 604 | 604 | */ |
| 605 | 605 | function svg_flip($img, $HorV) { |
| 606 | - if ($svg = svg_force_viewBox_px($img) |
|
| 607 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 608 | - |
|
| 609 | - list($balise_svg, $atts) = $svg_infos; |
|
| 610 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 611 | - |
|
| 612 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 613 | - $transform = "scale(-1,1)"; |
|
| 614 | - |
|
| 615 | - $x = intval($viewBox[0]) + intval($viewBox[2]/2); |
|
| 616 | - $mx = -$x; |
|
| 617 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 618 | - } |
|
| 619 | - else { |
|
| 620 | - $transform = "scale(1,-1)"; |
|
| 621 | - |
|
| 622 | - $y = intval($viewBox[1]) + intval($viewBox[3]/2); |
|
| 623 | - $my = -$y; |
|
| 624 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 625 | - } |
|
| 626 | - $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 627 | - return $svg; |
|
| 628 | - } |
|
| 629 | - return $img; |
|
| 606 | + if ($svg = svg_force_viewBox_px($img) |
|
| 607 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 608 | + |
|
| 609 | + list($balise_svg, $atts) = $svg_infos; |
|
| 610 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 611 | + |
|
| 612 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 613 | + $transform = "scale(-1,1)"; |
|
| 614 | + |
|
| 615 | + $x = intval($viewBox[0]) + intval($viewBox[2]/2); |
|
| 616 | + $mx = -$x; |
|
| 617 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 618 | + } |
|
| 619 | + else { |
|
| 620 | + $transform = "scale(1,-1)"; |
|
| 621 | + |
|
| 622 | + $y = intval($viewBox[1]) + intval($viewBox[3]/2); |
|
| 623 | + $my = -$y; |
|
| 624 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 625 | + } |
|
| 626 | + $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 627 | + return $svg; |
|
| 628 | + } |
|
| 629 | + return $img; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -640,19 +640,19 @@ discard block |
||
| 640 | 640 | * @return bool|string |
| 641 | 641 | */ |
| 642 | 642 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 643 | - if ($svg = svg_force_viewBox_px($img) |
|
| 644 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 643 | + if ($svg = svg_force_viewBox_px($img) |
|
| 644 | + and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 645 | 645 | |
| 646 | - list($balise_svg, $atts) = $svg_infos; |
|
| 647 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 646 | + list($balise_svg, $atts) = $svg_infos; |
|
| 647 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 648 | 648 | |
| 649 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 650 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 651 | - $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 649 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 650 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 651 | + $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 652 | 652 | |
| 653 | - return $svg; |
|
| 654 | - } |
|
| 655 | - return $img; |
|
| 653 | + return $svg; |
|
| 654 | + } |
|
| 655 | + return $img; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -664,40 +664,40 @@ discard block |
||
| 664 | 664 | * @return bool|mixed|string |
| 665 | 665 | */ |
| 666 | 666 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 667 | - if ($svg = svg_force_viewBox_px($img) |
|
| 668 | - and $colors = svg_extract_couleurs($svg)) { |
|
| 669 | - |
|
| 670 | - $colors = array_unique($colors); |
|
| 671 | - |
|
| 672 | - $short = []; |
|
| 673 | - $long = []; |
|
| 674 | - while (count($colors)) { |
|
| 675 | - $c = array_shift($colors); |
|
| 676 | - if (strlen($c) == 4) { |
|
| 677 | - $short[] = $c; |
|
| 678 | - } |
|
| 679 | - else { |
|
| 680 | - $long[] = $c; |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - $colors = array_merge($long, $short); |
|
| 685 | - $new_colors = []; |
|
| 686 | - $colors = array_flip($colors); |
|
| 687 | - foreach ($colors as $c => $k) { |
|
| 688 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - foreach ($colors as $original => $replace) { |
|
| 693 | - $new = svg_couleur_to_hexa($original); |
|
| 694 | - $new_colors[$replace] = $callback_filter($new); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 698 | - $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 699 | - |
|
| 700 | - return $svg; |
|
| 701 | - } |
|
| 702 | - return $img; |
|
| 667 | + if ($svg = svg_force_viewBox_px($img) |
|
| 668 | + and $colors = svg_extract_couleurs($svg)) { |
|
| 669 | + |
|
| 670 | + $colors = array_unique($colors); |
|
| 671 | + |
|
| 672 | + $short = []; |
|
| 673 | + $long = []; |
|
| 674 | + while (count($colors)) { |
|
| 675 | + $c = array_shift($colors); |
|
| 676 | + if (strlen($c) == 4) { |
|
| 677 | + $short[] = $c; |
|
| 678 | + } |
|
| 679 | + else { |
|
| 680 | + $long[] = $c; |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + $colors = array_merge($long, $short); |
|
| 685 | + $new_colors = []; |
|
| 686 | + $colors = array_flip($colors); |
|
| 687 | + foreach ($colors as $c => $k) { |
|
| 688 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + foreach ($colors as $original => $replace) { |
|
| 693 | + $new = svg_couleur_to_hexa($original); |
|
| 694 | + $new_colors[$replace] = $callback_filter($new); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 698 | + $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 699 | + |
|
| 700 | + return $svg; |
|
| 701 | + } |
|
| 702 | + return $img; |
|
| 703 | 703 | } |
| 704 | 704 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | 24 | // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
| 25 | - define('IMG_SVG',128); |
|
| 25 | + define('IMG_SVG', 128); |
|
| 26 | 26 | define('IMAGETYPE_SVG', 19); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return bool|string |
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | -function svg_charger($fichier, $maxlen=null) { |
|
| 41 | +function svg_charger($fichier, $maxlen = null) { |
|
| 42 | 42 | if (strpos($fichier, "data:image/svg+xml") === 0) { |
| 43 | 43 | $image = explode(";", $fichier, 2); |
| 44 | 44 | $image = end($image); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | return $fichier; |
| 57 | 57 | } |
| 58 | 58 | if (!file_exists($fichier)) { |
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | 60 | if (!file_exists($fichier)) { |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $image = file_get_contents($fichier); |
| 66 | 66 | } |
| 67 | 67 | else { |
| 68 | - $image = file_get_contents($fichier, false,null,0, $maxlen); |
|
| 68 | + $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | 69 | } |
| 70 | 70 | // est-ce bien une image svg ? |
| 71 | 71 | if (strpos($image, "<svg") !== false) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if (($ps = stripos($debut_fichier, "<svg")) !== false) { |
| 88 | 88 | |
| 89 | 89 | $pe = stripos($debut_fichier, ">", $ps); |
| 90 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps +1); |
|
| 90 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 91 | 91 | |
| 92 | 92 | if (preg_match_all(",([\w:\-]+)=,Uims", $balise_svg, $matches)) { |
| 93 | 93 | if (!function_exists('extraire_attribut')) { |
@@ -127,29 +127,29 @@ discard block |
||
| 127 | 127 | * @return bool|float|int |
| 128 | 128 | */ |
| 129 | 129 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 130 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)){ |
|
| 130 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 131 | 131 | switch (strtolower($m[2])) { |
| 132 | 132 | case '%': |
| 133 | 133 | // on ne sait pas faire :( |
| 134 | 134 | return false; |
| 135 | 135 | break; |
| 136 | 136 | case 'em': |
| 137 | - return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 137 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 138 | 138 | break; |
| 139 | 139 | case 'ex': |
| 140 | - return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 140 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 141 | 141 | break; |
| 142 | 142 | case 'pc': |
| 143 | - return round($m[1]*16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | + return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 144 | 144 | break; |
| 145 | 145 | case 'cm': |
| 146 | - return round($m[1]*96/2.54, $precision); // 96px / 2.54cm; |
|
| 146 | + return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 147 | 147 | break; |
| 148 | 148 | case 'mm': |
| 149 | - return round($m[1]*96/25.4, $precision); // 96px / 25.4mm; |
|
| 149 | + return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 150 | 150 | break; |
| 151 | 151 | case 'in': |
| 152 | - return round($m[1]*96, $precision); // 1 inch = 96px in CSS |
|
| 152 | + return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 153 | 153 | break; |
| 154 | 154 | case 'px': |
| 155 | 155 | case 'pt': |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | * inserer au debut (true) ou a la fin (false) |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | -function svg_insert_shapes($svg, $shapes, $start=true) { |
|
| 190 | +function svg_insert_shapes($svg, $shapes, $start = true) { |
|
| 191 | 191 | |
| 192 | 192 | if ($start === false or $start === 'end') { |
| 193 | - $svg = str_replace("</svg>", $shapes . "</svg>", $svg); |
|
| 193 | + $svg = str_replace("</svg>", $shapes."</svg>", $svg); |
|
| 194 | 194 | } |
| 195 | 195 | else { |
| 196 | 196 | $p = stripos($svg, "<svg"); |
| 197 | 197 | $p = strpos($svg, ">", $p); |
| 198 | - $svg = substr_replace($svg, $shapes, $p+1, 0); |
|
| 198 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 199 | 199 | } |
| 200 | 200 | return $svg; |
| 201 | 201 | } |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 213 | 213 | $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
| 214 | - $id = 'clip-'.substr(md5($rect . strlen($svg)),0,8); |
|
| 214 | + $id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8); |
|
| 215 | 215 | $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
| 216 | 216 | $g = "<g clip-path=\"url(#$id)\">"; |
| 217 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | + $svg = svg_insert_shapes($svg, $clippath.$g); |
|
| 218 | 218 | $svg = svg_insert_shapes($svg, "</g>", false); |
| 219 | 219 | return $svg; |
| 220 | 220 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | list($balise_svg, $attributs) = $svg_infos; |
| 234 | 234 | if (!isset($attributs['viewBox'])) { |
| 235 | - $attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height']; |
|
| 235 | + $attributs['viewBox'] = "0 0 ".$attributs['width']." ".$attributs['height']; |
|
| 236 | 236 | } |
| 237 | 237 | $attributs['width'] = strval($new_width); |
| 238 | 238 | $attributs['height'] = strval($new_height); |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, "rgb(")===0) { |
|
| 253 | + if (strpos($couleur, "rgb(") === 0) { |
|
| 254 | 254 | $c = explode(',', substr($couleur, 4)); |
| 255 | 255 | $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
| 256 | 256 | } |
| 257 | 257 | else { |
| 258 | 258 | $couleur = couleur_html_to_hex($couleur); |
| 259 | 259 | } |
| 260 | - $couleur = '#'.ltrim($couleur,'#'); |
|
| 260 | + $couleur = '#'.ltrim($couleur, '#'); |
|
| 261 | 261 | return $couleur; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, "rgb(")===0) { |
|
| 270 | + if (strpos($couleur, "rgb(") === 0) { |
|
| 271 | 271 | $c = explode(',', substr($couleur, 4)); |
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 272 | + return ['red' => intval($c[0]), 'green' => intval($c[1]), 'blue' => intval($c[2])]; |
|
| 273 | 273 | } |
| 274 | 274 | return _couleur_hex_to_dec($couleur); |
| 275 | 275 | } |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 359 | 359 | if ($svg = svg_charger($img) |
| 360 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 360 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 361 | 361 | |
| 362 | 362 | list($balise_svg, $attributs) = $svg_infos; |
| 363 | 363 | |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * @param $new_height |
| 398 | 398 | * @return bool|string |
| 399 | 399 | */ |
| 400 | -function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color='') { |
|
| 400 | +function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
|
| 401 | 401 | if ($svg = svg_force_viewBox_px($img) |
| 402 | 402 | and $svg_infos = svg_lire_balise_svg($svg)) { |
| 403 | 403 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $viewport_oy = round($viewport_oy * $yscale, 2); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) { |
|
| 426 | + if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 427 | 427 | $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
| 428 | 428 | } |
| 429 | 429 | |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
| 441 | 441 | |
| 442 | 442 | // ajouter un background |
| 443 | - if ($background_color and $background_color!=='transparent') { |
|
| 443 | + if ($background_color and $background_color !== 'transparent') { |
|
| 444 | 444 | $svg = svg_ajouter_background($svg, $background_color); |
| 445 | 445 | } |
| 446 | 446 | |
@@ -458,9 +458,9 @@ discard block |
||
| 458 | 458 | */ |
| 459 | 459 | function svg_ajouter_background($img, $background_color) { |
| 460 | 460 | if ($svg = svg_charger($img) |
| 461 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 461 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 462 | 462 | |
| 463 | - if ($background_color and $background_color!=='transparent') { |
|
| 463 | + if ($background_color and $background_color !== 'transparent') { |
|
| 464 | 464 | list($balise_svg, $attributs) = $svg_infos; |
| 465 | 465 | |
| 466 | 466 | $background_color = svg_couleur_to_hexa($background_color); |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 489 | 489 | if ($svg = svg_charger($img) |
| 490 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 490 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 491 | 491 | |
| 492 | - if ($background_color and $background_color!=='transparent') { |
|
| 492 | + if ($background_color and $background_color !== 'transparent') { |
|
| 493 | 493 | list($balise_svg, $attributs) = $svg_infos; |
| 494 | 494 | |
| 495 | 495 | $background_color = svg_couleur_to_hexa($background_color); |
@@ -516,10 +516,10 @@ discard block |
||
| 516 | 516 | */ |
| 517 | 517 | function svg_transformer($img, $attributs) { |
| 518 | 518 | if ($svg = svg_charger($img) |
| 519 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 519 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 520 | 520 | |
| 521 | 521 | if ($attributs) { |
| 522 | - list($balise_svg, ) = $svg_infos; |
|
| 522 | + list($balise_svg,) = $svg_infos; |
|
| 523 | 523 | $g = "<g"; |
| 524 | 524 | foreach ($attributs as $k=>$v) { |
| 525 | 525 | if (strlen($v)) { |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | */ |
| 547 | 547 | function svg_apply_filter($img, $filter_def) { |
| 548 | 548 | if ($svg = svg_charger($img) |
| 549 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 549 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 550 | 550 | |
| 551 | 551 | if ($filter_def) { |
| 552 | - list($balise_svg, ) = $svg_infos; |
|
| 553 | - $filter_id = "filter-". substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 552 | + list($balise_svg,) = $svg_infos; |
|
| 553 | + $filter_id = "filter-".substr(md5($filter_def.strlen($svg)), 0, 8); |
|
| 554 | 554 | $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
| 555 | 555 | $g = "<g filter=\"url(#$filter_id)\">"; |
| 556 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 556 | + $svg = svg_insert_shapes($svg, $filter.$g); |
|
| 557 | 557 | $svg = svg_insert_shapes($svg, "</g>", false); |
| 558 | 558 | } |
| 559 | 559 | return $svg; |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | */ |
| 605 | 605 | function svg_flip($img, $HorV) { |
| 606 | 606 | if ($svg = svg_force_viewBox_px($img) |
| 607 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 607 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 608 | 608 | |
| 609 | 609 | list($balise_svg, $atts) = $svg_infos; |
| 610 | 610 | $viewBox = explode(' ', $atts['viewBox']); |
@@ -612,14 +612,14 @@ discard block |
||
| 612 | 612 | if (!in_array($HorV, ['h', 'H'])) { |
| 613 | 613 | $transform = "scale(-1,1)"; |
| 614 | 614 | |
| 615 | - $x = intval($viewBox[0]) + intval($viewBox[2]/2); |
|
| 615 | + $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 616 | 616 | $mx = -$x; |
| 617 | 617 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 618 | 618 | } |
| 619 | 619 | else { |
| 620 | 620 | $transform = "scale(1,-1)"; |
| 621 | 621 | |
| 622 | - $y = intval($viewBox[1]) + intval($viewBox[3]/2); |
|
| 622 | + $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 623 | 623 | $my = -$y; |
| 624 | 624 | $transform = "translate(0, $y) $transform translate(0, $my)"; |
| 625 | 625 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | */ |
| 642 | 642 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 643 | 643 | if ($svg = svg_force_viewBox_px($img) |
| 644 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 644 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 645 | 645 | |
| 646 | 646 | list($balise_svg, $atts) = $svg_infos; |
| 647 | 647 | $viewBox = explode(' ', $atts['viewBox']); |
@@ -63,8 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | if (is_null($maxlen)) { |
| 65 | 65 | $image = file_get_contents($fichier); |
| 66 | - } |
|
| 67 | - else { |
|
| 66 | + } else { |
|
| 68 | 67 | $image = file_get_contents($fichier, false,null,0, $maxlen); |
| 69 | 68 | } |
| 70 | 69 | // est-ce bien une image svg ? |
@@ -191,8 +190,7 @@ discard block |
||
| 191 | 190 | |
| 192 | 191 | if ($start === false or $start === 'end') { |
| 193 | 192 | $svg = str_replace("</svg>", $shapes . "</svg>", $svg); |
| 194 | - } |
|
| 195 | - else { |
|
| 193 | + } else { |
|
| 196 | 194 | $p = stripos($svg, "<svg"); |
| 197 | 195 | $p = strpos($svg, ">", $p); |
| 198 | 196 | $svg = substr_replace($svg, $shapes, $p+1, 0); |
@@ -253,8 +251,7 @@ discard block |
||
| 253 | 251 | if (strpos($couleur, "rgb(")===0) { |
| 254 | 252 | $c = explode(',', substr($couleur, 4)); |
| 255 | 253 | $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
| 256 | - } |
|
| 257 | - else { |
|
| 254 | + } else { |
|
| 258 | 255 | $couleur = couleur_html_to_hex($couleur); |
| 259 | 256 | } |
| 260 | 257 | $couleur = '#'.ltrim($couleur,'#'); |
@@ -303,33 +300,27 @@ discard block |
||
| 303 | 300 | if (isset($attributs['width']) |
| 304 | 301 | and $w = svg_dimension_to_pixels($attributs['width'])) { |
| 305 | 302 | $width = $w; |
| 306 | - } |
|
| 307 | - else { |
|
| 303 | + } else { |
|
| 308 | 304 | // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
| 309 | 305 | $width = $viewBox[2]; |
| 310 | 306 | if ($width < 1) { |
| 311 | 307 | $coeff = max($coeff, 1000); |
| 312 | - } |
|
| 313 | - elseif ($width < 10) { |
|
| 308 | + } elseif ($width < 10) { |
|
| 314 | 309 | $coeff = max($coeff, 100); |
| 315 | - } |
|
| 316 | - elseif ($width < 100) { |
|
| 310 | + } elseif ($width < 100) { |
|
| 317 | 311 | $coeff = max($coeff, 10); |
| 318 | 312 | } |
| 319 | 313 | } |
| 320 | 314 | if (isset($attributs['height']) |
| 321 | 315 | and $h = svg_dimension_to_pixels($attributs['height'])) { |
| 322 | 316 | $height = $h; |
| 323 | - } |
|
| 324 | - else { |
|
| 317 | + } else { |
|
| 325 | 318 | $height = $viewBox[3]; |
| 326 | 319 | if ($height < 1) { |
| 327 | 320 | $coeff = max($coeff, 1000); |
| 328 | - } |
|
| 329 | - elseif ($height < 10) { |
|
| 321 | + } elseif ($height < 10) { |
|
| 330 | 322 | $coeff = max($coeff, 100); |
| 331 | - } |
|
| 332 | - elseif ($height < 100) { |
|
| 323 | + } elseif ($height < 100) { |
|
| 333 | 324 | $coeff = max($coeff, 10); |
| 334 | 325 | } |
| 335 | 326 | } |
@@ -467,8 +458,7 @@ discard block |
||
| 467 | 458 | if (isset($attributs['viewBox'])) { |
| 468 | 459 | $viewBox = explode(' ', $attributs['viewBox']); |
| 469 | 460 | $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\"/>"; |
| 470 | - } |
|
| 471 | - else { |
|
| 461 | + } else { |
|
| 472 | 462 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 473 | 463 | } |
| 474 | 464 | $svg = svg_insert_shapes($svg, $rect); |
@@ -496,8 +486,7 @@ discard block |
||
| 496 | 486 | if (isset($attributs['viewBox'])) { |
| 497 | 487 | $viewBox = explode(' ', $attributs['viewBox']); |
| 498 | 488 | $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
| 499 | - } |
|
| 500 | - else { |
|
| 489 | + } else { |
|
| 501 | 490 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 502 | 491 | } |
| 503 | 492 | $svg = svg_insert_shapes($svg, $rect, false); |
@@ -615,8 +604,7 @@ discard block |
||
| 615 | 604 | $x = intval($viewBox[0]) + intval($viewBox[2]/2); |
| 616 | 605 | $mx = -$x; |
| 617 | 606 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 618 | - } |
|
| 619 | - else { |
|
| 607 | + } else { |
|
| 620 | 608 | $transform = "scale(1,-1)"; |
| 621 | 609 | |
| 622 | 610 | $y = intval($viewBox[1]) + intval($viewBox[3]/2); |
@@ -675,8 +663,7 @@ discard block |
||
| 675 | 663 | $c = array_shift($colors); |
| 676 | 664 | if (strlen($c) == 4) { |
| 677 | 665 | $short[] = $c; |
| 678 | - } |
|
| 679 | - else { |
|
| 666 | + } else { |
|
| 680 | 667 | $long[] = $c; |
| 681 | 668 | } |
| 682 | 669 | } |