@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | 19 | return; |
| 20 | 20 | } |
| 21 | -require_once _ROOT_RESTREINT . 'base/objets.php'; |
|
| 21 | +require_once _ROOT_RESTREINT.'base/objets.php'; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
| 60 | 60 | ? '' // nom de serveur mal ecrit |
| 61 | 61 | : ($serveur ? |
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 62 | + (_DIR_CONNECT.$serveur.'.php') // serveur externe |
|
| 63 | 63 | : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
| 64 | 64 | : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
| 65 | 65 | : ''))); // installation pas faite |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | // chargement de la version du jeu de fonctions |
| 103 | 103 | // si pas dans le fichier par defaut |
| 104 | 104 | $type = $GLOBALS['db_ok']['type']; |
| 105 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | + $jeu = 'spip_'.$type.'_functions_'.$version; |
|
| 106 | 106 | if (!isset($GLOBALS[$jeu])) { |
| 107 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | + if (!find_in_path($type.'_'.$version.'.php', 'req/', true)) { |
|
| 108 | 108 | spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
| 109 | 109 | |
| 110 | 110 | // ne plus reessayer |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | $connexion = spip_connect($serveur); |
| 167 | 167 | $e = sql_errno($serveur); |
| 168 | 168 | $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
| 169 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 170 | - $f = $t . $serveur; |
|
| 171 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 169 | + $m = "Erreur $e de $t: ".sql_error($serveur)."\nin ".sql_error_backtrace()."\n".trim($connexion['last']); |
|
| 170 | + $f = $t.$serveur; |
|
| 171 | + spip_log($m, $f.'.'._LOG_ERREUR); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | // si en cours d'installation ou si db=@test@ on ne pose rien |
| 251 | 251 | // car c'est un test de connexion |
| 252 | 252 | if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
| 253 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 253 | + $f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out'; |
|
| 254 | 254 | } elseif ($db == '@test@') { |
| 255 | 255 | $db = ''; |
| 256 | 256 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | // En cas d'indisponibilite du serveur, eviter de le bombarder |
| 291 | 291 | if ($f) { |
| 292 | 292 | @touch($f); |
| 293 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 293 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
@@ -382,8 +382,7 @@ discard block |
||
| 382 | 382 | * @return string Valeur échappée. |
| 383 | 383 | **/ |
| 384 | 384 | function _q($a) { |
| 385 | - return (is_numeric($a)) ? strval($a) : |
|
| 386 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 385 | + return (is_numeric($a)) ? strval($a) : (!is_array($a) ? ("'".addslashes($a)."'") |
|
| 387 | 386 | : join(',', array_map('_q', $a))); |
| 388 | 387 | } |
| 389 | 388 | |
@@ -425,7 +424,7 @@ discard block |
||
| 425 | 424 | break; |
| 426 | 425 | default: |
| 427 | 426 | $replace = range(1, count($textes)); |
| 428 | - $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 427 | + $replace = '%'.implode('$s,%', $replace).'$s'; |
|
| 429 | 428 | $replace = explode(',', $replace); |
| 430 | 429 | break; |
| 431 | 430 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 22 | 22 | |
@@ -42,119 +42,119 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function spip_connect($serveur = '', $version = '') { |
| 44 | 44 | |
| 45 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | - $index = $serveur ? $serveur : 0; |
|
| 47 | - if (!$version) { |
|
| 48 | - $version = $GLOBALS['spip_sql_version']; |
|
| 49 | - } |
|
| 50 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | - return $GLOBALS['connexions'][$index]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - include_spip('base/abstract_sql'); |
|
| 55 | - $install = (_request('exec') == 'install'); |
|
| 56 | - |
|
| 57 | - // Premiere connexion ? |
|
| 58 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | - ? '' // nom de serveur mal ecrit |
|
| 61 | - : ($serveur ? |
|
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | - : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 64 | - : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 65 | - : ''))); // installation pas faite |
|
| 66 | - |
|
| 67 | - unset($GLOBALS['db_ok']); |
|
| 68 | - unset($GLOBALS['spip_connect_version']); |
|
| 69 | - if ($f) { |
|
| 70 | - if (is_readable($f)) { |
|
| 71 | - include($f); |
|
| 72 | - } elseif ($serveur and !$install) { |
|
| 73 | - // chercher une declaration de serveur dans le path |
|
| 74 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 75 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 76 | - find_in_path("$serveur.php", 'connect/', true); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 80 | - // fera mieux la prochaine fois |
|
| 81 | - if ($install) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - if ($f and is_readable($f)) { |
|
| 85 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 86 | - } else { |
|
| 87 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 88 | - } |
|
| 89 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 90 | - |
|
| 91 | - // ne plus reessayer si ce n'est pas l'install |
|
| 92 | - return $GLOBALS['connexions'][$index] = false; |
|
| 93 | - } |
|
| 94 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 95 | - } |
|
| 96 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 97 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // la connexion a reussi ou etait deja faite. |
|
| 102 | - // chargement de la version du jeu de fonctions |
|
| 103 | - // si pas dans le fichier par defaut |
|
| 104 | - $type = $GLOBALS['db_ok']['type']; |
|
| 105 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 106 | - if (!isset($GLOBALS[$jeu])) { |
|
| 107 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 108 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 109 | - |
|
| 110 | - // ne plus reessayer |
|
| 111 | - return $GLOBALS['connexions'][$index][$version] = []; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 115 | - if ($old) { |
|
| 116 | - return $GLOBALS['connexions'][$index]; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 120 | - |
|
| 121 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 122 | - // si l'installation l'a determine. |
|
| 123 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 124 | - // s'ils le connaissent |
|
| 125 | - |
|
| 126 | - if (!$serveur) { |
|
| 127 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 128 | - if (!$charset) { |
|
| 129 | - unset($GLOBALS['connexions'][$index]); |
|
| 130 | - spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 131 | - |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - } else { |
|
| 135 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 136 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 137 | - } |
|
| 138 | - // spip_meta n'existe pas toujours dans la base |
|
| 139 | - // C'est le cas d'un dump sqlite par exemple |
|
| 140 | - elseif ( |
|
| 141 | - $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 142 | - and sql_showtable('spip_meta', true, $serveur) |
|
| 143 | - and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 144 | - ) { |
|
| 145 | - $charset = $r; |
|
| 146 | - } else { |
|
| 147 | - $charset = -1; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if ($charset != -1) { |
|
| 151 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 152 | - if (function_exists($f)) { |
|
| 153 | - $f($charset, $serveur); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return $GLOBALS['connexions'][$index]; |
|
| 45 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | + $index = $serveur ? $serveur : 0; |
|
| 47 | + if (!$version) { |
|
| 48 | + $version = $GLOBALS['spip_sql_version']; |
|
| 49 | + } |
|
| 50 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | + return $GLOBALS['connexions'][$index]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + include_spip('base/abstract_sql'); |
|
| 55 | + $install = (_request('exec') == 'install'); |
|
| 56 | + |
|
| 57 | + // Premiere connexion ? |
|
| 58 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | + ? '' // nom de serveur mal ecrit |
|
| 61 | + : ($serveur ? |
|
| 62 | + (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | + : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 64 | + : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 65 | + : ''))); // installation pas faite |
|
| 66 | + |
|
| 67 | + unset($GLOBALS['db_ok']); |
|
| 68 | + unset($GLOBALS['spip_connect_version']); |
|
| 69 | + if ($f) { |
|
| 70 | + if (is_readable($f)) { |
|
| 71 | + include($f); |
|
| 72 | + } elseif ($serveur and !$install) { |
|
| 73 | + // chercher une declaration de serveur dans le path |
|
| 74 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 75 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 76 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 80 | + // fera mieux la prochaine fois |
|
| 81 | + if ($install) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + if ($f and is_readable($f)) { |
|
| 85 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 86 | + } else { |
|
| 87 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 88 | + } |
|
| 89 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 90 | + |
|
| 91 | + // ne plus reessayer si ce n'est pas l'install |
|
| 92 | + return $GLOBALS['connexions'][$index] = false; |
|
| 93 | + } |
|
| 94 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 95 | + } |
|
| 96 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 97 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // la connexion a reussi ou etait deja faite. |
|
| 102 | + // chargement de la version du jeu de fonctions |
|
| 103 | + // si pas dans le fichier par defaut |
|
| 104 | + $type = $GLOBALS['db_ok']['type']; |
|
| 105 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 106 | + if (!isset($GLOBALS[$jeu])) { |
|
| 107 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 108 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 109 | + |
|
| 110 | + // ne plus reessayer |
|
| 111 | + return $GLOBALS['connexions'][$index][$version] = []; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 115 | + if ($old) { |
|
| 116 | + return $GLOBALS['connexions'][$index]; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 120 | + |
|
| 121 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 122 | + // si l'installation l'a determine. |
|
| 123 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 124 | + // s'ils le connaissent |
|
| 125 | + |
|
| 126 | + if (!$serveur) { |
|
| 127 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 128 | + if (!$charset) { |
|
| 129 | + unset($GLOBALS['connexions'][$index]); |
|
| 130 | + spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 131 | + |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + } else { |
|
| 135 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 136 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 137 | + } |
|
| 138 | + // spip_meta n'existe pas toujours dans la base |
|
| 139 | + // C'est le cas d'un dump sqlite par exemple |
|
| 140 | + elseif ( |
|
| 141 | + $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 142 | + and sql_showtable('spip_meta', true, $serveur) |
|
| 143 | + and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 144 | + ) { |
|
| 145 | + $charset = $r; |
|
| 146 | + } else { |
|
| 147 | + $charset = -1; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if ($charset != -1) { |
|
| 151 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 152 | + if (function_exists($f)) { |
|
| 153 | + $f($charset, $serveur); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return $GLOBALS['connexions'][$index]; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 164 | 164 | **/ |
| 165 | 165 | function spip_sql_erreur($serveur = '') { |
| 166 | - $connexion = spip_connect($serveur); |
|
| 167 | - $e = sql_errno($serveur); |
|
| 168 | - $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 169 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 170 | - $f = $t . $serveur; |
|
| 171 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 166 | + $connexion = spip_connect($serveur); |
|
| 167 | + $e = sql_errno($serveur); |
|
| 168 | + $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 169 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 170 | + $f = $t . $serveur; |
|
| 171 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -190,19 +190,19 @@ discard block |
||
| 190 | 190 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 191 | 191 | **/ |
| 192 | 192 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 193 | - $desc = spip_connect($serveur, $version); |
|
| 194 | - if (function_exists($f = @$desc[$version][$ins])) { |
|
| 195 | - return $f; |
|
| 196 | - } |
|
| 197 | - if ($continue) { |
|
| 198 | - return $desc; |
|
| 199 | - } |
|
| 200 | - if ($ins) { |
|
| 201 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 202 | - } |
|
| 203 | - include_spip('inc/minipres'); |
|
| 204 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 205 | - exit; |
|
| 193 | + $desc = spip_connect($serveur, $version); |
|
| 194 | + if (function_exists($f = @$desc[$version][$ins])) { |
|
| 195 | + return $f; |
|
| 196 | + } |
|
| 197 | + if ($continue) { |
|
| 198 | + return $desc; |
|
| 199 | + } |
|
| 200 | + if ($ins) { |
|
| 201 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 202 | + } |
|
| 203 | + include_spip('inc/minipres'); |
|
| 204 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 205 | + exit; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -228,70 +228,70 @@ discard block |
||
| 228 | 228 | * @return array Description de la connexion |
| 229 | 229 | */ |
| 230 | 230 | function spip_connect_db( |
| 231 | - $host, |
|
| 232 | - $port, |
|
| 233 | - $login, |
|
| 234 | - $pass, |
|
| 235 | - $db = '', |
|
| 236 | - $type = 'mysql', |
|
| 237 | - $prefixe = '', |
|
| 238 | - $auth = '', |
|
| 239 | - $charset = '' |
|
| 231 | + $host, |
|
| 232 | + $port, |
|
| 233 | + $login, |
|
| 234 | + $pass, |
|
| 235 | + $db = '', |
|
| 236 | + $type = 'mysql', |
|
| 237 | + $prefixe = '', |
|
| 238 | + $auth = '', |
|
| 239 | + $charset = '' |
|
| 240 | 240 | ) { |
| 241 | - // temps avant nouvelle tentative de connexion |
|
| 242 | - // suite a une connection echouee |
|
| 243 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 244 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $f = ''; |
|
| 248 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 249 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 250 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 251 | - // car c'est un test de connexion |
|
| 252 | - if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 253 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 254 | - } elseif ($db == '@test@') { |
|
| 255 | - $db = ''; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - if ( |
|
| 259 | - $f |
|
| 260 | - and @file_exists($f) |
|
| 261 | - and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 262 | - ) { |
|
| 263 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 264 | - |
|
| 265 | - return; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if (!$prefixe) { |
|
| 269 | - $prefixe = isset($GLOBALS['table_prefix']) |
|
| 270 | - ? $GLOBALS['table_prefix'] : $db; |
|
| 271 | - } |
|
| 272 | - $h = charger_fonction($type, 'req', true); |
|
| 273 | - if (!$h) { |
|
| 274 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 275 | - |
|
| 276 | - return; |
|
| 277 | - } |
|
| 278 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 279 | - if (!is_array($auth)) { |
|
| 280 | - // compatibilite version 0.7 initiale |
|
| 281 | - $g['ldap'] = $auth; |
|
| 282 | - $auth = ['ldap' => $auth]; |
|
| 283 | - } |
|
| 284 | - $g['authentification'] = $auth; |
|
| 285 | - $g['type'] = $type; |
|
| 286 | - $g['charset'] = $charset; |
|
| 287 | - |
|
| 288 | - return $GLOBALS['db_ok'] = $g; |
|
| 289 | - } |
|
| 290 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 291 | - if ($f) { |
|
| 292 | - @touch($f); |
|
| 293 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 294 | - } |
|
| 241 | + // temps avant nouvelle tentative de connexion |
|
| 242 | + // suite a une connection echouee |
|
| 243 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 244 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $f = ''; |
|
| 248 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 249 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 250 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 251 | + // car c'est un test de connexion |
|
| 252 | + if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 253 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 254 | + } elseif ($db == '@test@') { |
|
| 255 | + $db = ''; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + if ( |
|
| 259 | + $f |
|
| 260 | + and @file_exists($f) |
|
| 261 | + and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 262 | + ) { |
|
| 263 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 264 | + |
|
| 265 | + return; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if (!$prefixe) { |
|
| 269 | + $prefixe = isset($GLOBALS['table_prefix']) |
|
| 270 | + ? $GLOBALS['table_prefix'] : $db; |
|
| 271 | + } |
|
| 272 | + $h = charger_fonction($type, 'req', true); |
|
| 273 | + if (!$h) { |
|
| 274 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 275 | + |
|
| 276 | + return; |
|
| 277 | + } |
|
| 278 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 279 | + if (!is_array($auth)) { |
|
| 280 | + // compatibilite version 0.7 initiale |
|
| 281 | + $g['ldap'] = $auth; |
|
| 282 | + $auth = ['ldap' => $auth]; |
|
| 283 | + } |
|
| 284 | + $g['authentification'] = $auth; |
|
| 285 | + $g['type'] = $type; |
|
| 286 | + $g['charset'] = $charset; |
|
| 287 | + |
|
| 288 | + return $GLOBALS['db_ok'] = $g; |
|
| 289 | + } |
|
| 290 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 291 | + if ($f) { |
|
| 292 | + @touch($f); |
|
| 293 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 294 | + } |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | |
@@ -323,32 +323,32 @@ discard block |
||
| 323 | 323 | * - nom du charset sinon |
| 324 | 324 | **/ |
| 325 | 325 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 326 | - if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 327 | - include_spip('inc/headers'); |
|
| 328 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - if (!($f = $connexion['select'])) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - // si le charset est fourni, l'utiliser |
|
| 335 | - if ($charset_sql_connexion) { |
|
| 336 | - return $charset_sql_connexion; |
|
| 337 | - } |
|
| 338 | - // sinon on regarde la table spip_meta |
|
| 339 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 340 | - if ( |
|
| 341 | - !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 342 | - or is_string($r) |
|
| 343 | - ) { |
|
| 344 | - return false; |
|
| 345 | - } |
|
| 346 | - if (!($f = $connexion['fetch'])) { |
|
| 347 | - return false; |
|
| 348 | - } |
|
| 349 | - $r = $f($r); |
|
| 350 | - |
|
| 351 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 326 | + if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 327 | + include_spip('inc/headers'); |
|
| 328 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + if (!($f = $connexion['select'])) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + // si le charset est fourni, l'utiliser |
|
| 335 | + if ($charset_sql_connexion) { |
|
| 336 | + return $charset_sql_connexion; |
|
| 337 | + } |
|
| 338 | + // sinon on regarde la table spip_meta |
|
| 339 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 340 | + if ( |
|
| 341 | + !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 342 | + or is_string($r) |
|
| 343 | + ) { |
|
| 344 | + return false; |
|
| 345 | + } |
|
| 346 | + if (!($f = $connexion['fetch'])) { |
|
| 347 | + return false; |
|
| 348 | + } |
|
| 349 | + $r = $f($r); |
|
| 350 | + |
|
| 351 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | * @return array |
| 365 | 365 | */ |
| 366 | 366 | function spip_connect_ldap($serveur = '') { |
| 367 | - include_spip('auth/ldap'); |
|
| 367 | + include_spip('auth/ldap'); |
|
| 368 | 368 | |
| 369 | - return auth_ldap_connect($serveur); |
|
| 369 | + return auth_ldap_connect($serveur); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -382,9 +382,9 @@ discard block |
||
| 382 | 382 | * @return string Valeur échappée. |
| 383 | 383 | **/ |
| 384 | 384 | function _q($a) { |
| 385 | - return (is_numeric($a)) ? strval($a) : |
|
| 386 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 387 | - : join(',', array_map('_q', $a))); |
|
| 385 | + return (is_numeric($a)) ? strval($a) : |
|
| 386 | + (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 387 | + : join(',', array_map('_q', $a))); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -400,66 +400,66 @@ discard block |
||
| 400 | 400 | * @return array |
| 401 | 401 | */ |
| 402 | 402 | function query_echappe_textes($query, $uniqid = null) { |
| 403 | - static $codeEchappements = null; |
|
| 404 | - if (is_null($codeEchappements) or $uniqid) { |
|
| 405 | - if (is_null($uniqid)) { |
|
| 406 | - $uniqid = uniqid(); |
|
| 407 | - } |
|
| 408 | - $uniqid = substr(md5($uniqid), 0, 4); |
|
| 409 | - $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3"]; |
|
| 410 | - } |
|
| 411 | - if ($query === null) { |
|
| 412 | - return $codeEchappements; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 416 | - // ce n'est pas un cas legitime |
|
| 417 | - foreach ($codeEchappements as $codeEchappement) { |
|
| 418 | - if (strpos($query, $codeEchappement) !== false) { |
|
| 419 | - return [$query, []]; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 424 | - if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 425 | - $textes = reset($textes); // indice 0 du match |
|
| 426 | - switch (count($textes)) { |
|
| 427 | - case 0: |
|
| 428 | - $replace = []; |
|
| 429 | - break; |
|
| 430 | - case 1: |
|
| 431 | - $replace = ['%1$s']; |
|
| 432 | - break; |
|
| 433 | - case 2: |
|
| 434 | - $replace = ['%1$s', '%2$s']; |
|
| 435 | - break; |
|
| 436 | - case 3: |
|
| 437 | - $replace = ['%1$s', '%2$s', '%3$s']; |
|
| 438 | - break; |
|
| 439 | - case 4: |
|
| 440 | - $replace = ['%1$s', '%2$s', '%3$s', '%4$s']; |
|
| 441 | - break; |
|
| 442 | - case 5: |
|
| 443 | - $replace = ['%1$s', '%2$s', '%3$s', '%4$s', '%5$s']; |
|
| 444 | - break; |
|
| 445 | - default: |
|
| 446 | - $replace = range(1, count($textes)); |
|
| 447 | - $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 448 | - $replace = explode(',', $replace); |
|
| 449 | - break; |
|
| 450 | - } |
|
| 451 | - $query_echappees = str_replace($textes, $replace, $query_echappees); |
|
| 452 | - } else { |
|
| 453 | - $textes = []; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelles les pinceaux |
|
| 457 | - // dans le doute on ne touche a rien |
|
| 458 | - if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 459 | - return [$query, []]; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - return [$query_echappees, $textes]; |
|
| 403 | + static $codeEchappements = null; |
|
| 404 | + if (is_null($codeEchappements) or $uniqid) { |
|
| 405 | + if (is_null($uniqid)) { |
|
| 406 | + $uniqid = uniqid(); |
|
| 407 | + } |
|
| 408 | + $uniqid = substr(md5($uniqid), 0, 4); |
|
| 409 | + $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3"]; |
|
| 410 | + } |
|
| 411 | + if ($query === null) { |
|
| 412 | + return $codeEchappements; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 416 | + // ce n'est pas un cas legitime |
|
| 417 | + foreach ($codeEchappements as $codeEchappement) { |
|
| 418 | + if (strpos($query, $codeEchappement) !== false) { |
|
| 419 | + return [$query, []]; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 424 | + if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 425 | + $textes = reset($textes); // indice 0 du match |
|
| 426 | + switch (count($textes)) { |
|
| 427 | + case 0: |
|
| 428 | + $replace = []; |
|
| 429 | + break; |
|
| 430 | + case 1: |
|
| 431 | + $replace = ['%1$s']; |
|
| 432 | + break; |
|
| 433 | + case 2: |
|
| 434 | + $replace = ['%1$s', '%2$s']; |
|
| 435 | + break; |
|
| 436 | + case 3: |
|
| 437 | + $replace = ['%1$s', '%2$s', '%3$s']; |
|
| 438 | + break; |
|
| 439 | + case 4: |
|
| 440 | + $replace = ['%1$s', '%2$s', '%3$s', '%4$s']; |
|
| 441 | + break; |
|
| 442 | + case 5: |
|
| 443 | + $replace = ['%1$s', '%2$s', '%3$s', '%4$s', '%5$s']; |
|
| 444 | + break; |
|
| 445 | + default: |
|
| 446 | + $replace = range(1, count($textes)); |
|
| 447 | + $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 448 | + $replace = explode(',', $replace); |
|
| 449 | + break; |
|
| 450 | + } |
|
| 451 | + $query_echappees = str_replace($textes, $replace, $query_echappees); |
|
| 452 | + } else { |
|
| 453 | + $textes = []; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelles les pinceaux |
|
| 457 | + // dans le doute on ne touche a rien |
|
| 458 | + if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 459 | + return [$query, []]; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + return [$query_echappees, $textes]; |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -473,14 +473,14 @@ discard block |
||
| 473 | 473 | * @return string |
| 474 | 474 | */ |
| 475 | 475 | function query_reinjecte_textes($query, $textes) { |
| 476 | - // recuperer les codes echappements |
|
| 477 | - $codeEchappements = query_echappe_textes(null); |
|
| 476 | + // recuperer les codes echappements |
|
| 477 | + $codeEchappements = query_echappe_textes(null); |
|
| 478 | 478 | |
| 479 | - $query = sprintf($query, ...$textes); |
|
| 479 | + $query = sprintf($query, ...$textes); |
|
| 480 | 480 | |
| 481 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 481 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 482 | 482 | |
| 483 | - return $query; |
|
| 483 | + return $query; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | **/ |
| 500 | 500 | function spip_query($query, $serveur = '') { |
| 501 | 501 | |
| 502 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 502 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 503 | 503 | |
| 504 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 504 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 505 | 505 | } |
@@ -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 | |
@@ -34,53 +34,53 @@ discard block |
||
| 34 | 34 | * @package SPIP\Core\Compilateur\AST |
| 35 | 35 | */ |
| 36 | 36 | class Contexte { |
| 37 | - /** |
|
| 38 | - * Description du squelette |
|
| 39 | - * |
|
| 40 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | - * |
|
| 42 | - * Peut contenir les index : |
|
| 43 | - * |
|
| 44 | - * - nom : Nom du fichier de cache |
|
| 45 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | - * - sourcefile : Chemin du squelette |
|
| 47 | - * - squelette : Code du squelette |
|
| 48 | - * - id_mere : Identifiant de la boucle parente |
|
| 49 | - * - documents : Pour embed et img dans les textes |
|
| 50 | - * - session : Pour un cache sessionné par auteur |
|
| 51 | - * - niv : Niveau de tabulation |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $descr = []; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Identifiant de la boucle |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $id_boucle = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Numéro de ligne dans le code source du squelette |
|
| 66 | - * |
|
| 67 | - * @var int |
|
| 68 | - */ |
|
| 69 | - public $ligne = 0; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Langue d'exécution |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $lang = ''; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Résultat de la compilation: toujours une expression PHP |
|
| 80 | - * |
|
| 81 | - * @var string |
|
| 82 | - */ |
|
| 83 | - public $code = ''; |
|
| 37 | + /** |
|
| 38 | + * Description du squelette |
|
| 39 | + * |
|
| 40 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | + * |
|
| 42 | + * Peut contenir les index : |
|
| 43 | + * |
|
| 44 | + * - nom : Nom du fichier de cache |
|
| 45 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | + * - sourcefile : Chemin du squelette |
|
| 47 | + * - squelette : Code du squelette |
|
| 48 | + * - id_mere : Identifiant de la boucle parente |
|
| 49 | + * - documents : Pour embed et img dans les textes |
|
| 50 | + * - session : Pour un cache sessionné par auteur |
|
| 51 | + * - niv : Niveau de tabulation |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $descr = []; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Identifiant de la boucle |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $id_boucle = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Numéro de ligne dans le code source du squelette |
|
| 66 | + * |
|
| 67 | + * @var int |
|
| 68 | + */ |
|
| 69 | + public $ligne = 0; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Langue d'exécution |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $lang = ''; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Résultat de la compilation: toujours une expression PHP |
|
| 80 | + * |
|
| 81 | + * @var string |
|
| 82 | + */ |
|
| 83 | + public $code = ''; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -90,44 +90,44 @@ discard block |
||
| 90 | 90 | * @package SPIP\Core\Compilateur\AST |
| 91 | 91 | **/ |
| 92 | 92 | class Texte { |
| 93 | - /** |
|
| 94 | - * Type de noeud |
|
| 95 | - * |
|
| 96 | - * @var string |
|
| 97 | - */ |
|
| 98 | - public $type = 'texte'; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Le texte |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $texte; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Contenu avant le texte. |
|
| 109 | - * |
|
| 110 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | - * |
|
| 112 | - * @var string|array |
|
| 113 | - */ |
|
| 114 | - public $avant = ''; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Contenu après le texte. |
|
| 118 | - * |
|
| 119 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | - * |
|
| 121 | - * @var string|array |
|
| 122 | - */ |
|
| 123 | - public $apres = ''; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Numéro de ligne dans le code source du squelette |
|
| 127 | - * |
|
| 128 | - * @var int |
|
| 129 | - */ |
|
| 130 | - public $ligne = 0; |
|
| 93 | + /** |
|
| 94 | + * Type de noeud |
|
| 95 | + * |
|
| 96 | + * @var string |
|
| 97 | + */ |
|
| 98 | + public $type = 'texte'; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Le texte |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $texte; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Contenu avant le texte. |
|
| 109 | + * |
|
| 110 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | + * |
|
| 112 | + * @var string|array |
|
| 113 | + */ |
|
| 114 | + public $avant = ''; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Contenu après le texte. |
|
| 118 | + * |
|
| 119 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | + * |
|
| 121 | + * @var string|array |
|
| 122 | + */ |
|
| 123 | + public $apres = ''; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Numéro de ligne dans le code source du squelette |
|
| 127 | + * |
|
| 128 | + * @var int |
|
| 129 | + */ |
|
| 130 | + public $ligne = 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,50 +136,50 @@ discard block |
||
| 136 | 136 | * @package SPIP\Core\Compilateur\AST |
| 137 | 137 | **/ |
| 138 | 138 | class Inclure { |
| 139 | - /** |
|
| 140 | - * Type de noeud |
|
| 141 | - * |
|
| 142 | - * @var string |
|
| 143 | - */ |
|
| 144 | - public $type = 'include'; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Nom d'un fichier inclu |
|
| 148 | - * |
|
| 149 | - * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | - * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | - * |
|
| 152 | - * @var string|Texte |
|
| 153 | - */ |
|
| 154 | - public $texte; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Inutilisé, propriété générique de l'AST |
|
| 158 | - * |
|
| 159 | - * @var string|array |
|
| 160 | - */ |
|
| 161 | - public $avant = ''; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Inutilisé, propriété générique de l'AST |
|
| 165 | - * |
|
| 166 | - * @var string|array |
|
| 167 | - */ |
|
| 168 | - public $apres = ''; |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Numéro de ligne dans le code source du squelette |
|
| 172 | - * |
|
| 173 | - * @var int |
|
| 174 | - */ |
|
| 175 | - public $ligne = 0; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Valeurs des paramètres |
|
| 179 | - * |
|
| 180 | - * @var array |
|
| 181 | - */ |
|
| 182 | - public $param = []; |
|
| 139 | + /** |
|
| 140 | + * Type de noeud |
|
| 141 | + * |
|
| 142 | + * @var string |
|
| 143 | + */ |
|
| 144 | + public $type = 'include'; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Nom d'un fichier inclu |
|
| 148 | + * |
|
| 149 | + * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | + * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | + * |
|
| 152 | + * @var string|Texte |
|
| 153 | + */ |
|
| 154 | + public $texte; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Inutilisé, propriété générique de l'AST |
|
| 158 | + * |
|
| 159 | + * @var string|array |
|
| 160 | + */ |
|
| 161 | + public $avant = ''; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Inutilisé, propriété générique de l'AST |
|
| 165 | + * |
|
| 166 | + * @var string|array |
|
| 167 | + */ |
|
| 168 | + public $apres = ''; |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Numéro de ligne dans le code source du squelette |
|
| 172 | + * |
|
| 173 | + * @var int |
|
| 174 | + */ |
|
| 175 | + public $ligne = 0; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Valeurs des paramètres |
|
| 179 | + * |
|
| 180 | + * @var array |
|
| 181 | + */ |
|
| 182 | + public $param = []; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -189,386 +189,386 @@ discard block |
||
| 189 | 189 | * @package SPIP\Core\Compilateur\AST |
| 190 | 190 | **/ |
| 191 | 191 | class Boucle { |
| 192 | - /** |
|
| 193 | - * Type de noeud |
|
| 194 | - * |
|
| 195 | - * @var string |
|
| 196 | - */ |
|
| 197 | - public $type = 'boucle'; |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Identifiant de la boucle |
|
| 201 | - * |
|
| 202 | - * @var string |
|
| 203 | - */ |
|
| 204 | - public $id_boucle; |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Identifiant de la boucle parente |
|
| 208 | - * |
|
| 209 | - * @var string |
|
| 210 | - */ |
|
| 211 | - public $id_parent = ''; |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Partie avant toujours affichee |
|
| 215 | - * |
|
| 216 | - * @var string|array |
|
| 217 | - */ |
|
| 218 | - public $preaff = ''; |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Partie optionnelle avant |
|
| 222 | - * |
|
| 223 | - * @var string|array |
|
| 224 | - */ |
|
| 225 | - public $avant = ''; |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Pour chaque élément |
|
| 229 | - * |
|
| 230 | - * @var string|array |
|
| 231 | - */ |
|
| 232 | - public $milieu = ''; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Partie optionnelle après |
|
| 236 | - * |
|
| 237 | - * @var string|array |
|
| 238 | - */ |
|
| 239 | - public $apres = ''; |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | - * |
|
| 244 | - * @var string|array |
|
| 245 | - */ |
|
| 246 | - public $altern = ''; |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Partie apres toujours affichee |
|
| 250 | - * |
|
| 251 | - * @var string|array |
|
| 252 | - */ |
|
| 253 | - public $postaff = ''; |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * La boucle doit-elle sélectionner la langue ? |
|
| 258 | - * |
|
| 259 | - * @var string|null |
|
| 260 | - */ |
|
| 261 | - public $lang_select; |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | - * |
|
| 266 | - * @var string|null |
|
| 267 | - */ |
|
| 268 | - public $type_requete; |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * La table est elle optionnelle ? |
|
| 272 | - * |
|
| 273 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | - * |
|
| 275 | - * @var bool |
|
| 276 | - */ |
|
| 277 | - public $table_optionnelle = false; |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Nom du fichier de connexion |
|
| 281 | - * |
|
| 282 | - * @var string |
|
| 283 | - */ |
|
| 284 | - public $sql_serveur = ''; |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Paramètres de la boucle |
|
| 288 | - * |
|
| 289 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | - * au calcul des critères |
|
| 291 | - * |
|
| 292 | - * @var array |
|
| 293 | - */ |
|
| 294 | - public $param = []; |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Critères de la boucle |
|
| 298 | - * |
|
| 299 | - * @var Critere[] |
|
| 300 | - */ |
|
| 301 | - public $criteres = []; |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | - * |
|
| 306 | - * @var string[] |
|
| 307 | - */ |
|
| 308 | - public $separateur = []; |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Liste des jointures possibles avec cette table |
|
| 312 | - * |
|
| 313 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | - * des jointures déclarées explicitement sur la boucle |
|
| 315 | - * |
|
| 316 | - * @see base_trouver_table_dist() |
|
| 317 | - * @var array |
|
| 318 | - */ |
|
| 319 | - public $jointures = []; |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Jointures explicites avec cette table |
|
| 323 | - * |
|
| 324 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | - * à la boucle. |
|
| 327 | - * |
|
| 328 | - * @var string|bool |
|
| 329 | - */ |
|
| 330 | - public $jointures_explicites = false; |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | - * |
|
| 335 | - * @var string|null |
|
| 336 | - */ |
|
| 337 | - public $doublons; |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | - * |
|
| 342 | - * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | - * |
|
| 344 | - * @var string |
|
| 345 | - */ |
|
| 346 | - public $partie = ''; |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | - * ou de soustractions d'éléments à faire |
|
| 351 | - * |
|
| 352 | - * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | - * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | - * |
|
| 355 | - * @var string |
|
| 356 | - */ |
|
| 357 | - public $total_parties = ''; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | - * |
|
| 362 | - * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | - * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | - * |
|
| 365 | - * @var string |
|
| 366 | - */ |
|
| 367 | - public $mode_partie = ''; |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | - * |
|
| 372 | - * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | - * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | - * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | - * de l'appelant (rec) |
|
| 376 | - * |
|
| 377 | - * @var string |
|
| 378 | - */ |
|
| 379 | - public $externe = ''; |
|
| 380 | - |
|
| 381 | - // champs pour la construction de la requete SQL |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Liste des champs à récupérer par la boucle |
|
| 385 | - * |
|
| 386 | - * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | - * |
|
| 388 | - * @var string[] |
|
| 389 | - */ |
|
| 390 | - public $select = []; |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | - * |
|
| 395 | - * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | - * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | - * |
|
| 398 | - * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | - * |
|
| 400 | - * @var string[] |
|
| 401 | - */ |
|
| 402 | - public $from = []; |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | - * |
|
| 407 | - * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | - * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | - * |
|
| 410 | - * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | - * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | - * |
|
| 413 | - * @var string[] |
|
| 414 | - */ |
|
| 415 | - public $from_type = []; |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Liste des conditions WHERE de la boucle |
|
| 419 | - * |
|
| 420 | - * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | - * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | - * |
|
| 423 | - * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | - * |
|
| 425 | - * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | - * chaque élément ajouté directement au where par |
|
| 427 | - * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | - * est une condition AND en plus. |
|
| 429 | - * |
|
| 430 | - * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | - * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | - * $expr = array(operateur, val1, val2) |
|
| 433 | - * |
|
| 434 | - * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | - * à réaliser tel que : |
|
| 436 | - * |
|
| 437 | - * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | - * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | - * suivant cet ordre : "val1 operateur val2". |
|
| 440 | - * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | - * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | - * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | - * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | - * Exemples : |
|
| 445 | - * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | - * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | - * |
|
| 448 | - * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | - * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | - * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | - * |
|
| 452 | - * @var array |
|
| 453 | - */ |
|
| 454 | - public $where = []; |
|
| 455 | - |
|
| 456 | - public $join = []; |
|
| 457 | - public $having = []; |
|
| 458 | - public $limit; |
|
| 459 | - public $group = []; |
|
| 460 | - public $order = []; |
|
| 461 | - public $default_order = []; |
|
| 462 | - public $date = 'date'; |
|
| 463 | - public $hash = ''; |
|
| 464 | - public $in = ''; |
|
| 465 | - public $sous_requete = false; |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | - * |
|
| 470 | - * Il sert à insérer le code calculant une hierarchie |
|
| 471 | - * |
|
| 472 | - * @var string |
|
| 473 | - */ |
|
| 474 | - public $hierarchie = ''; |
|
| 475 | - |
|
| 476 | - // champs pour la construction du corps PHP |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Description des sources de données de la boucle |
|
| 480 | - * |
|
| 481 | - * Description des données de la boucle issu de trouver_table |
|
| 482 | - * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 483 | - * |
|
| 484 | - * @see base_trouver_table_dist() |
|
| 485 | - * @var array |
|
| 486 | - */ |
|
| 487 | - public $show = []; |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 491 | - * |
|
| 492 | - * @var string |
|
| 493 | - */ |
|
| 494 | - public $id_table; |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 498 | - * |
|
| 499 | - * @var string |
|
| 500 | - */ |
|
| 501 | - public $primary; |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Code PHP compilé de la boucle |
|
| 505 | - * |
|
| 506 | - * @var string |
|
| 507 | - */ |
|
| 508 | - public $return; |
|
| 509 | - |
|
| 510 | - public $numrows = false; |
|
| 511 | - public $cptrows = false; |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Description du squelette |
|
| 515 | - * |
|
| 516 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 517 | - * |
|
| 518 | - * Peut contenir les index : |
|
| 519 | - * |
|
| 520 | - * - nom : Nom du fichier de cache |
|
| 521 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 522 | - * - sourcefile : Chemin du squelette |
|
| 523 | - * - squelette : Code du squelette |
|
| 524 | - * - id_mere : Identifiant de la boucle parente |
|
| 525 | - * - documents : Pour embed et img dans les textes |
|
| 526 | - * - session : Pour un cache sessionné par auteur |
|
| 527 | - * - niv : Niveau de tabulation |
|
| 528 | - * |
|
| 529 | - * @var array |
|
| 530 | - */ |
|
| 531 | - public $descr = []; |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Numéro de ligne dans le code source du squelette |
|
| 535 | - * |
|
| 536 | - * @var int |
|
| 537 | - */ |
|
| 538 | - public $ligne = 0; |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - public $modificateur = []; // table pour stocker les modificateurs de boucle tels que tout, plat ..., utilisable par les plugins egalement |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Type d'itérateur utilisé pour cette boucle |
|
| 545 | - * |
|
| 546 | - * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 547 | - * - 'DATA' pour l'itérateur DATA, ... |
|
| 548 | - * |
|
| 549 | - * @var string |
|
| 550 | - */ |
|
| 551 | - public $iterateur = ''; // type d'iterateur |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 555 | - */ |
|
| 556 | - public $debug = []; |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 560 | - * notamment si le champ a été trouve dans une boucle parente |
|
| 561 | - * |
|
| 562 | - * Tableau nom du champ => index de boucle |
|
| 563 | - * |
|
| 564 | - * @var array $index_champ |
|
| 565 | - */ |
|
| 566 | - public $index_champ = []; |
|
| 567 | - |
|
| 568 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 569 | - public $tout = false; |
|
| 570 | - public $plat = false; |
|
| 571 | - public $lien = false; |
|
| 192 | + /** |
|
| 193 | + * Type de noeud |
|
| 194 | + * |
|
| 195 | + * @var string |
|
| 196 | + */ |
|
| 197 | + public $type = 'boucle'; |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Identifiant de la boucle |
|
| 201 | + * |
|
| 202 | + * @var string |
|
| 203 | + */ |
|
| 204 | + public $id_boucle; |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Identifiant de la boucle parente |
|
| 208 | + * |
|
| 209 | + * @var string |
|
| 210 | + */ |
|
| 211 | + public $id_parent = ''; |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Partie avant toujours affichee |
|
| 215 | + * |
|
| 216 | + * @var string|array |
|
| 217 | + */ |
|
| 218 | + public $preaff = ''; |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Partie optionnelle avant |
|
| 222 | + * |
|
| 223 | + * @var string|array |
|
| 224 | + */ |
|
| 225 | + public $avant = ''; |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Pour chaque élément |
|
| 229 | + * |
|
| 230 | + * @var string|array |
|
| 231 | + */ |
|
| 232 | + public $milieu = ''; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Partie optionnelle après |
|
| 236 | + * |
|
| 237 | + * @var string|array |
|
| 238 | + */ |
|
| 239 | + public $apres = ''; |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | + * |
|
| 244 | + * @var string|array |
|
| 245 | + */ |
|
| 246 | + public $altern = ''; |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Partie apres toujours affichee |
|
| 250 | + * |
|
| 251 | + * @var string|array |
|
| 252 | + */ |
|
| 253 | + public $postaff = ''; |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * La boucle doit-elle sélectionner la langue ? |
|
| 258 | + * |
|
| 259 | + * @var string|null |
|
| 260 | + */ |
|
| 261 | + public $lang_select; |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | + * |
|
| 266 | + * @var string|null |
|
| 267 | + */ |
|
| 268 | + public $type_requete; |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * La table est elle optionnelle ? |
|
| 272 | + * |
|
| 273 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | + * |
|
| 275 | + * @var bool |
|
| 276 | + */ |
|
| 277 | + public $table_optionnelle = false; |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Nom du fichier de connexion |
|
| 281 | + * |
|
| 282 | + * @var string |
|
| 283 | + */ |
|
| 284 | + public $sql_serveur = ''; |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Paramètres de la boucle |
|
| 288 | + * |
|
| 289 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | + * au calcul des critères |
|
| 291 | + * |
|
| 292 | + * @var array |
|
| 293 | + */ |
|
| 294 | + public $param = []; |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Critères de la boucle |
|
| 298 | + * |
|
| 299 | + * @var Critere[] |
|
| 300 | + */ |
|
| 301 | + public $criteres = []; |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | + * |
|
| 306 | + * @var string[] |
|
| 307 | + */ |
|
| 308 | + public $separateur = []; |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Liste des jointures possibles avec cette table |
|
| 312 | + * |
|
| 313 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | + * des jointures déclarées explicitement sur la boucle |
|
| 315 | + * |
|
| 316 | + * @see base_trouver_table_dist() |
|
| 317 | + * @var array |
|
| 318 | + */ |
|
| 319 | + public $jointures = []; |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Jointures explicites avec cette table |
|
| 323 | + * |
|
| 324 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | + * à la boucle. |
|
| 327 | + * |
|
| 328 | + * @var string|bool |
|
| 329 | + */ |
|
| 330 | + public $jointures_explicites = false; |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | + * |
|
| 335 | + * @var string|null |
|
| 336 | + */ |
|
| 337 | + public $doublons; |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | + * |
|
| 342 | + * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | + * |
|
| 344 | + * @var string |
|
| 345 | + */ |
|
| 346 | + public $partie = ''; |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | + * ou de soustractions d'éléments à faire |
|
| 351 | + * |
|
| 352 | + * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | + * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | + * |
|
| 355 | + * @var string |
|
| 356 | + */ |
|
| 357 | + public $total_parties = ''; |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | + * |
|
| 362 | + * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | + * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | + * |
|
| 365 | + * @var string |
|
| 366 | + */ |
|
| 367 | + public $mode_partie = ''; |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | + * |
|
| 372 | + * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | + * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | + * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | + * de l'appelant (rec) |
|
| 376 | + * |
|
| 377 | + * @var string |
|
| 378 | + */ |
|
| 379 | + public $externe = ''; |
|
| 380 | + |
|
| 381 | + // champs pour la construction de la requete SQL |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Liste des champs à récupérer par la boucle |
|
| 385 | + * |
|
| 386 | + * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | + * |
|
| 388 | + * @var string[] |
|
| 389 | + */ |
|
| 390 | + public $select = []; |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | + * |
|
| 395 | + * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | + * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | + * |
|
| 398 | + * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | + * |
|
| 400 | + * @var string[] |
|
| 401 | + */ |
|
| 402 | + public $from = []; |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | + * |
|
| 407 | + * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | + * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | + * |
|
| 410 | + * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | + * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | + * |
|
| 413 | + * @var string[] |
|
| 414 | + */ |
|
| 415 | + public $from_type = []; |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Liste des conditions WHERE de la boucle |
|
| 419 | + * |
|
| 420 | + * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | + * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | + * |
|
| 423 | + * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | + * |
|
| 425 | + * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | + * chaque élément ajouté directement au where par |
|
| 427 | + * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | + * est une condition AND en plus. |
|
| 429 | + * |
|
| 430 | + * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | + * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | + * $expr = array(operateur, val1, val2) |
|
| 433 | + * |
|
| 434 | + * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | + * à réaliser tel que : |
|
| 436 | + * |
|
| 437 | + * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | + * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | + * suivant cet ordre : "val1 operateur val2". |
|
| 440 | + * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | + * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | + * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | + * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | + * Exemples : |
|
| 445 | + * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | + * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | + * |
|
| 448 | + * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | + * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | + * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | + * |
|
| 452 | + * @var array |
|
| 453 | + */ |
|
| 454 | + public $where = []; |
|
| 455 | + |
|
| 456 | + public $join = []; |
|
| 457 | + public $having = []; |
|
| 458 | + public $limit; |
|
| 459 | + public $group = []; |
|
| 460 | + public $order = []; |
|
| 461 | + public $default_order = []; |
|
| 462 | + public $date = 'date'; |
|
| 463 | + public $hash = ''; |
|
| 464 | + public $in = ''; |
|
| 465 | + public $sous_requete = false; |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | + * |
|
| 470 | + * Il sert à insérer le code calculant une hierarchie |
|
| 471 | + * |
|
| 472 | + * @var string |
|
| 473 | + */ |
|
| 474 | + public $hierarchie = ''; |
|
| 475 | + |
|
| 476 | + // champs pour la construction du corps PHP |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Description des sources de données de la boucle |
|
| 480 | + * |
|
| 481 | + * Description des données de la boucle issu de trouver_table |
|
| 482 | + * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 483 | + * |
|
| 484 | + * @see base_trouver_table_dist() |
|
| 485 | + * @var array |
|
| 486 | + */ |
|
| 487 | + public $show = []; |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 491 | + * |
|
| 492 | + * @var string |
|
| 493 | + */ |
|
| 494 | + public $id_table; |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 498 | + * |
|
| 499 | + * @var string |
|
| 500 | + */ |
|
| 501 | + public $primary; |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Code PHP compilé de la boucle |
|
| 505 | + * |
|
| 506 | + * @var string |
|
| 507 | + */ |
|
| 508 | + public $return; |
|
| 509 | + |
|
| 510 | + public $numrows = false; |
|
| 511 | + public $cptrows = false; |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Description du squelette |
|
| 515 | + * |
|
| 516 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 517 | + * |
|
| 518 | + * Peut contenir les index : |
|
| 519 | + * |
|
| 520 | + * - nom : Nom du fichier de cache |
|
| 521 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 522 | + * - sourcefile : Chemin du squelette |
|
| 523 | + * - squelette : Code du squelette |
|
| 524 | + * - id_mere : Identifiant de la boucle parente |
|
| 525 | + * - documents : Pour embed et img dans les textes |
|
| 526 | + * - session : Pour un cache sessionné par auteur |
|
| 527 | + * - niv : Niveau de tabulation |
|
| 528 | + * |
|
| 529 | + * @var array |
|
| 530 | + */ |
|
| 531 | + public $descr = []; |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Numéro de ligne dans le code source du squelette |
|
| 535 | + * |
|
| 536 | + * @var int |
|
| 537 | + */ |
|
| 538 | + public $ligne = 0; |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + public $modificateur = []; // table pour stocker les modificateurs de boucle tels que tout, plat ..., utilisable par les plugins egalement |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Type d'itérateur utilisé pour cette boucle |
|
| 545 | + * |
|
| 546 | + * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 547 | + * - 'DATA' pour l'itérateur DATA, ... |
|
| 548 | + * |
|
| 549 | + * @var string |
|
| 550 | + */ |
|
| 551 | + public $iterateur = ''; // type d'iterateur |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 555 | + */ |
|
| 556 | + public $debug = []; |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 560 | + * notamment si le champ a été trouve dans une boucle parente |
|
| 561 | + * |
|
| 562 | + * Tableau nom du champ => index de boucle |
|
| 563 | + * |
|
| 564 | + * @var array $index_champ |
|
| 565 | + */ |
|
| 566 | + public $index_champ = []; |
|
| 567 | + |
|
| 568 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 569 | + public $tout = false; |
|
| 570 | + public $plat = false; |
|
| 571 | + public $lien = false; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -579,56 +579,56 @@ discard block |
||
| 579 | 579 | * @package SPIP\Core\Compilateur\AST |
| 580 | 580 | **/ |
| 581 | 581 | class Critere { |
| 582 | - /** |
|
| 583 | - * Type de noeud |
|
| 584 | - * |
|
| 585 | - * @var string |
|
| 586 | - */ |
|
| 587 | - public $type = 'critere'; |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Opérateur (>, <, >=, IN, ...) |
|
| 591 | - * |
|
| 592 | - * @var null|string |
|
| 593 | - */ |
|
| 594 | - public $op; |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Présence d'une négation (truc !op valeur) |
|
| 598 | - * |
|
| 599 | - * @var null|string |
|
| 600 | - */ |
|
| 601 | - public $not; |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Présence d'une exclusion (!truc op valeur) |
|
| 605 | - * |
|
| 606 | - * @var null|string |
|
| 607 | - */ |
|
| 608 | - public $exclus; |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Présence d'une condition dans le critère (truc ?) |
|
| 612 | - * |
|
| 613 | - * @var bool |
|
| 614 | - */ |
|
| 615 | - public $cond = false; |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Paramètres du critère |
|
| 619 | - * - $param[0] : élément avant l'opérateur |
|
| 620 | - * - $param[1..n] : éléments après l'opérateur |
|
| 621 | - * |
|
| 622 | - * @var array |
|
| 623 | - */ |
|
| 624 | - public $param = []; |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Numéro de ligne dans le code source du squelette |
|
| 628 | - * |
|
| 629 | - * @var int |
|
| 630 | - */ |
|
| 631 | - public $ligne = 0; |
|
| 582 | + /** |
|
| 583 | + * Type de noeud |
|
| 584 | + * |
|
| 585 | + * @var string |
|
| 586 | + */ |
|
| 587 | + public $type = 'critere'; |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Opérateur (>, <, >=, IN, ...) |
|
| 591 | + * |
|
| 592 | + * @var null|string |
|
| 593 | + */ |
|
| 594 | + public $op; |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Présence d'une négation (truc !op valeur) |
|
| 598 | + * |
|
| 599 | + * @var null|string |
|
| 600 | + */ |
|
| 601 | + public $not; |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Présence d'une exclusion (!truc op valeur) |
|
| 605 | + * |
|
| 606 | + * @var null|string |
|
| 607 | + */ |
|
| 608 | + public $exclus; |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Présence d'une condition dans le critère (truc ?) |
|
| 612 | + * |
|
| 613 | + * @var bool |
|
| 614 | + */ |
|
| 615 | + public $cond = false; |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Paramètres du critère |
|
| 619 | + * - $param[0] : élément avant l'opérateur |
|
| 620 | + * - $param[1..n] : éléments après l'opérateur |
|
| 621 | + * |
|
| 622 | + * @var array |
|
| 623 | + */ |
|
| 624 | + public $param = []; |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Numéro de ligne dans le code source du squelette |
|
| 628 | + * |
|
| 629 | + * @var int |
|
| 630 | + */ |
|
| 631 | + public $ligne = 0; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -637,139 +637,139 @@ discard block |
||
| 637 | 637 | * @package SPIP\Core\Compilateur\AST |
| 638 | 638 | **/ |
| 639 | 639 | class Champ { |
| 640 | - /** |
|
| 641 | - * Type de noeud |
|
| 642 | - * |
|
| 643 | - * @var string |
|
| 644 | - */ |
|
| 645 | - public $type = 'champ'; |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 649 | - * |
|
| 650 | - * @var string|null |
|
| 651 | - */ |
|
| 652 | - public $nom_champ; |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Identifiant de la boucle parente si explicité |
|
| 656 | - * |
|
| 657 | - * @var string|null |
|
| 658 | - */ |
|
| 659 | - public $nom_boucle = ''; |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Partie optionnelle avant |
|
| 663 | - * |
|
| 664 | - * @var null|string|array |
|
| 665 | - */ |
|
| 666 | - public $avant; |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Partie optionnelle après |
|
| 670 | - * |
|
| 671 | - * @var null|string|array |
|
| 672 | - */ |
|
| 673 | - public $apres; |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Étoiles : annuler des automatismes |
|
| 677 | - * |
|
| 678 | - * - '*' annule les filtres automatiques |
|
| 679 | - * - '**' annule en plus les protections de scripts |
|
| 680 | - * |
|
| 681 | - * @var null|string |
|
| 682 | - */ |
|
| 683 | - public $etoile; |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Arguments et filtres explicites sur la balise |
|
| 687 | - * |
|
| 688 | - * - $param[0] contient les arguments de la balise |
|
| 689 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 690 | - * |
|
| 691 | - * @var array |
|
| 692 | - */ |
|
| 693 | - public $param = []; |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Source des filtres (compatibilité) (?) |
|
| 697 | - * |
|
| 698 | - * @var array|null |
|
| 699 | - */ |
|
| 700 | - public $fonctions = []; |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Identifiant de la boucle |
|
| 704 | - * |
|
| 705 | - * @var string |
|
| 706 | - */ |
|
| 707 | - public $id_boucle = ''; |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * AST du squelette, liste de toutes les boucles |
|
| 711 | - * |
|
| 712 | - * @var Boucles[] |
|
| 713 | - */ |
|
| 714 | - public $boucles; |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 718 | - * |
|
| 719 | - * @var string|null |
|
| 720 | - */ |
|
| 721 | - public $type_requete; |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * Résultat de la compilation: toujours une expression PHP |
|
| 725 | - * |
|
| 726 | - * @var string |
|
| 727 | - */ |
|
| 728 | - public $code = ''; |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * Interdire les scripts |
|
| 732 | - * |
|
| 733 | - * false si on est sûr de cette balise |
|
| 734 | - * |
|
| 735 | - * @see interdire_scripts() |
|
| 736 | - * @var bool |
|
| 737 | - */ |
|
| 738 | - public $interdire_scripts = true; |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Description du squelette |
|
| 742 | - * |
|
| 743 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 744 | - * |
|
| 745 | - * Peut contenir les index : |
|
| 746 | - * |
|
| 747 | - * - nom : Nom du fichier de cache |
|
| 748 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 749 | - * - sourcefile : Chemin du squelette |
|
| 750 | - * - squelette : Code du squelette |
|
| 751 | - * - id_mere : Identifiant de la boucle parente |
|
| 752 | - * - documents : Pour embed et img dans les textes |
|
| 753 | - * - session : Pour un cache sessionné par auteur |
|
| 754 | - * - niv : Niveau de tabulation |
|
| 755 | - * |
|
| 756 | - * @var array |
|
| 757 | - */ |
|
| 758 | - public $descr = []; |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Numéro de ligne dans le code source du squelette |
|
| 762 | - * |
|
| 763 | - * @var int |
|
| 764 | - */ |
|
| 765 | - public $ligne = 0; |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 769 | - * |
|
| 770 | - * @var bool |
|
| 771 | - */ |
|
| 772 | - public $balise_calculee = false; |
|
| 640 | + /** |
|
| 641 | + * Type de noeud |
|
| 642 | + * |
|
| 643 | + * @var string |
|
| 644 | + */ |
|
| 645 | + public $type = 'champ'; |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 649 | + * |
|
| 650 | + * @var string|null |
|
| 651 | + */ |
|
| 652 | + public $nom_champ; |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Identifiant de la boucle parente si explicité |
|
| 656 | + * |
|
| 657 | + * @var string|null |
|
| 658 | + */ |
|
| 659 | + public $nom_boucle = ''; |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Partie optionnelle avant |
|
| 663 | + * |
|
| 664 | + * @var null|string|array |
|
| 665 | + */ |
|
| 666 | + public $avant; |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Partie optionnelle après |
|
| 670 | + * |
|
| 671 | + * @var null|string|array |
|
| 672 | + */ |
|
| 673 | + public $apres; |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Étoiles : annuler des automatismes |
|
| 677 | + * |
|
| 678 | + * - '*' annule les filtres automatiques |
|
| 679 | + * - '**' annule en plus les protections de scripts |
|
| 680 | + * |
|
| 681 | + * @var null|string |
|
| 682 | + */ |
|
| 683 | + public $etoile; |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Arguments et filtres explicites sur la balise |
|
| 687 | + * |
|
| 688 | + * - $param[0] contient les arguments de la balise |
|
| 689 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 690 | + * |
|
| 691 | + * @var array |
|
| 692 | + */ |
|
| 693 | + public $param = []; |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Source des filtres (compatibilité) (?) |
|
| 697 | + * |
|
| 698 | + * @var array|null |
|
| 699 | + */ |
|
| 700 | + public $fonctions = []; |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Identifiant de la boucle |
|
| 704 | + * |
|
| 705 | + * @var string |
|
| 706 | + */ |
|
| 707 | + public $id_boucle = ''; |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * AST du squelette, liste de toutes les boucles |
|
| 711 | + * |
|
| 712 | + * @var Boucles[] |
|
| 713 | + */ |
|
| 714 | + public $boucles; |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 718 | + * |
|
| 719 | + * @var string|null |
|
| 720 | + */ |
|
| 721 | + public $type_requete; |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * Résultat de la compilation: toujours une expression PHP |
|
| 725 | + * |
|
| 726 | + * @var string |
|
| 727 | + */ |
|
| 728 | + public $code = ''; |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * Interdire les scripts |
|
| 732 | + * |
|
| 733 | + * false si on est sûr de cette balise |
|
| 734 | + * |
|
| 735 | + * @see interdire_scripts() |
|
| 736 | + * @var bool |
|
| 737 | + */ |
|
| 738 | + public $interdire_scripts = true; |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Description du squelette |
|
| 742 | + * |
|
| 743 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 744 | + * |
|
| 745 | + * Peut contenir les index : |
|
| 746 | + * |
|
| 747 | + * - nom : Nom du fichier de cache |
|
| 748 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 749 | + * - sourcefile : Chemin du squelette |
|
| 750 | + * - squelette : Code du squelette |
|
| 751 | + * - id_mere : Identifiant de la boucle parente |
|
| 752 | + * - documents : Pour embed et img dans les textes |
|
| 753 | + * - session : Pour un cache sessionné par auteur |
|
| 754 | + * - niv : Niveau de tabulation |
|
| 755 | + * |
|
| 756 | + * @var array |
|
| 757 | + */ |
|
| 758 | + public $descr = []; |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Numéro de ligne dans le code source du squelette |
|
| 762 | + * |
|
| 763 | + * @var int |
|
| 764 | + */ |
|
| 765 | + public $ligne = 0; |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 769 | + * |
|
| 770 | + * @var bool |
|
| 771 | + */ |
|
| 772 | + public $balise_calculee = false; |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
@@ -777,123 +777,123 @@ discard block |
||
| 777 | 777 | * Description d'une chaîne de langue |
| 778 | 778 | **/ |
| 779 | 779 | class Idiome { |
| 780 | - /** |
|
| 781 | - * Type de noeud |
|
| 782 | - * |
|
| 783 | - * @var string |
|
| 784 | - */ |
|
| 785 | - public $type = 'idiome'; |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Clé de traduction demandée. Exemple 'item_oui' |
|
| 789 | - * |
|
| 790 | - * @var string |
|
| 791 | - */ |
|
| 792 | - public $nom_champ = ''; |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 796 | - * |
|
| 797 | - * @var string |
|
| 798 | - */ |
|
| 799 | - public $module = ''; |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Arguments à passer à la chaîne |
|
| 803 | - * |
|
| 804 | - * @var array |
|
| 805 | - */ |
|
| 806 | - public $arg = []; |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * Filtres à appliquer au résultat |
|
| 810 | - * |
|
| 811 | - * @var array |
|
| 812 | - */ |
|
| 813 | - public $param = []; |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Source des filtres (compatibilité) (?) |
|
| 817 | - * |
|
| 818 | - * @var array|null |
|
| 819 | - */ |
|
| 820 | - public $fonctions = []; |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Inutilisé, propriété générique de l'AST |
|
| 824 | - * |
|
| 825 | - * @var string|array |
|
| 826 | - */ |
|
| 827 | - public $avant = ''; |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * Inutilisé, propriété générique de l'AST |
|
| 831 | - * |
|
| 832 | - * @var string|array |
|
| 833 | - */ |
|
| 834 | - public $apres = ''; |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * Identifiant de la boucle |
|
| 838 | - * |
|
| 839 | - * @var string |
|
| 840 | - */ |
|
| 841 | - public $id_boucle = ''; |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * AST du squelette, liste de toutes les boucles |
|
| 845 | - * |
|
| 846 | - * @var Boucles[] |
|
| 847 | - */ |
|
| 848 | - public $boucles; |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 852 | - * |
|
| 853 | - * @var string|null |
|
| 854 | - */ |
|
| 855 | - public $type_requete; |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Résultat de la compilation: toujours une expression PHP |
|
| 859 | - * |
|
| 860 | - * @var string |
|
| 861 | - */ |
|
| 862 | - public $code = ''; |
|
| 863 | - |
|
| 864 | - /** |
|
| 865 | - * Interdire les scripts |
|
| 866 | - * |
|
| 867 | - * @see interdire_scripts() |
|
| 868 | - * @var bool |
|
| 869 | - */ |
|
| 870 | - public $interdire_scripts = false; |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Description du squelette |
|
| 874 | - * |
|
| 875 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 876 | - * |
|
| 877 | - * Peut contenir les index : |
|
| 878 | - * - nom : Nom du fichier de cache |
|
| 879 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 880 | - * - sourcefile : Chemin du squelette |
|
| 881 | - * - squelette : Code du squelette |
|
| 882 | - * - id_mere : Identifiant de la boucle parente |
|
| 883 | - * - documents : Pour embed et img dans les textes |
|
| 884 | - * - session : Pour un cache sessionné par auteur |
|
| 885 | - * - niv : Niveau de tabulation |
|
| 886 | - * |
|
| 887 | - * @var array |
|
| 888 | - */ |
|
| 889 | - public $descr = []; |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * Numéro de ligne dans le code source du squelette |
|
| 893 | - * |
|
| 894 | - * @var int |
|
| 895 | - */ |
|
| 896 | - public $ligne = 0; |
|
| 780 | + /** |
|
| 781 | + * Type de noeud |
|
| 782 | + * |
|
| 783 | + * @var string |
|
| 784 | + */ |
|
| 785 | + public $type = 'idiome'; |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Clé de traduction demandée. Exemple 'item_oui' |
|
| 789 | + * |
|
| 790 | + * @var string |
|
| 791 | + */ |
|
| 792 | + public $nom_champ = ''; |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 796 | + * |
|
| 797 | + * @var string |
|
| 798 | + */ |
|
| 799 | + public $module = ''; |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Arguments à passer à la chaîne |
|
| 803 | + * |
|
| 804 | + * @var array |
|
| 805 | + */ |
|
| 806 | + public $arg = []; |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Filtres à appliquer au résultat |
|
| 810 | + * |
|
| 811 | + * @var array |
|
| 812 | + */ |
|
| 813 | + public $param = []; |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Source des filtres (compatibilité) (?) |
|
| 817 | + * |
|
| 818 | + * @var array|null |
|
| 819 | + */ |
|
| 820 | + public $fonctions = []; |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Inutilisé, propriété générique de l'AST |
|
| 824 | + * |
|
| 825 | + * @var string|array |
|
| 826 | + */ |
|
| 827 | + public $avant = ''; |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * Inutilisé, propriété générique de l'AST |
|
| 831 | + * |
|
| 832 | + * @var string|array |
|
| 833 | + */ |
|
| 834 | + public $apres = ''; |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * Identifiant de la boucle |
|
| 838 | + * |
|
| 839 | + * @var string |
|
| 840 | + */ |
|
| 841 | + public $id_boucle = ''; |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * AST du squelette, liste de toutes les boucles |
|
| 845 | + * |
|
| 846 | + * @var Boucles[] |
|
| 847 | + */ |
|
| 848 | + public $boucles; |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 852 | + * |
|
| 853 | + * @var string|null |
|
| 854 | + */ |
|
| 855 | + public $type_requete; |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Résultat de la compilation: toujours une expression PHP |
|
| 859 | + * |
|
| 860 | + * @var string |
|
| 861 | + */ |
|
| 862 | + public $code = ''; |
|
| 863 | + |
|
| 864 | + /** |
|
| 865 | + * Interdire les scripts |
|
| 866 | + * |
|
| 867 | + * @see interdire_scripts() |
|
| 868 | + * @var bool |
|
| 869 | + */ |
|
| 870 | + public $interdire_scripts = false; |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Description du squelette |
|
| 874 | + * |
|
| 875 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 876 | + * |
|
| 877 | + * Peut contenir les index : |
|
| 878 | + * - nom : Nom du fichier de cache |
|
| 879 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 880 | + * - sourcefile : Chemin du squelette |
|
| 881 | + * - squelette : Code du squelette |
|
| 882 | + * - id_mere : Identifiant de la boucle parente |
|
| 883 | + * - documents : Pour embed et img dans les textes |
|
| 884 | + * - session : Pour un cache sessionné par auteur |
|
| 885 | + * - niv : Niveau de tabulation |
|
| 886 | + * |
|
| 887 | + * @var array |
|
| 888 | + */ |
|
| 889 | + public $descr = []; |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * Numéro de ligne dans le code source du squelette |
|
| 893 | + * |
|
| 894 | + * @var int |
|
| 895 | + */ |
|
| 896 | + public $ligne = 0; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -902,28 +902,28 @@ discard block |
||
| 902 | 902 | * @package SPIP\Core\Compilateur\AST |
| 903 | 903 | **/ |
| 904 | 904 | class Polyglotte { |
| 905 | - /** |
|
| 906 | - * Type de noeud |
|
| 907 | - * |
|
| 908 | - * @var string |
|
| 909 | - */ |
|
| 910 | - public $type = 'polyglotte'; |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * Tableau des traductions possibles classées par langue |
|
| 914 | - * |
|
| 915 | - * Tableau code de langue => texte |
|
| 916 | - * |
|
| 917 | - * @var array |
|
| 918 | - */ |
|
| 919 | - public $traductions = []; |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * Numéro de ligne dans le code source du squelette |
|
| 923 | - * |
|
| 924 | - * @var int |
|
| 925 | - */ |
|
| 926 | - public $ligne = 0; |
|
| 905 | + /** |
|
| 906 | + * Type de noeud |
|
| 907 | + * |
|
| 908 | + * @var string |
|
| 909 | + */ |
|
| 910 | + public $type = 'polyglotte'; |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * Tableau des traductions possibles classées par langue |
|
| 914 | + * |
|
| 915 | + * Tableau code de langue => texte |
|
| 916 | + * |
|
| 917 | + * @var array |
|
| 918 | + */ |
|
| 919 | + public $traductions = []; |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * Numéro de ligne dans le code source du squelette |
|
| 923 | + * |
|
| 924 | + * @var int |
|
| 925 | + */ |
|
| 926 | + public $ligne = 0; |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | |
@@ -948,90 +948,90 @@ discard block |
||
| 948 | 948 | */ |
| 949 | 949 | function declarer_interfaces() { |
| 950 | 950 | |
| 951 | - $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 952 | - $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 953 | - $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 954 | - $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 955 | - |
|
| 956 | - // definition des statuts de publication |
|
| 957 | - $GLOBALS['table_statut'] = []; |
|
| 958 | - |
|
| 959 | - // |
|
| 960 | - // tableau des tables de jointures |
|
| 961 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 962 | - $GLOBALS['tables_jointures'] = []; |
|
| 963 | - $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 964 | - |
|
| 965 | - // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 966 | - $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 967 | - |
|
| 968 | - |
|
| 969 | - if (!defined('_TRAITEMENT_TYPO')) { |
|
| 970 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 971 | - } |
|
| 972 | - if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 973 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 974 | - } |
|
| 975 | - if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 976 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 977 | - } |
|
| 978 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 979 | - $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 980 | - $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(%s)'; |
|
| 981 | - $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 982 | - $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 983 | - $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 984 | - $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 985 | - $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 986 | - $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 987 | - $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 988 | - $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 989 | - $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 990 | - $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 991 | - $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 992 | - $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 993 | - $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 994 | - $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 995 | - $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 996 | - $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 997 | - $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 998 | - $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 999 | - $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1000 | - $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 1001 | - $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 1002 | - |
|
| 1003 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 1004 | - $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 1005 | - // toujours securiser les DATA |
|
| 1006 | - $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 1007 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 1008 | - $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1012 | - $interfaces = pipeline( |
|
| 1013 | - 'declarer_tables_interfaces', |
|
| 1014 | - [ |
|
| 1015 | - 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1016 | - 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1017 | - 'table_date' => $GLOBALS['table_date'], |
|
| 1018 | - 'table_titre' => $GLOBALS['table_titre'], |
|
| 1019 | - 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1020 | - 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1021 | - 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1022 | - 'table_statut' => $GLOBALS['table_statut'], |
|
| 1023 | - ] |
|
| 1024 | - ); |
|
| 1025 | - if ($interfaces) { |
|
| 1026 | - $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1027 | - $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1028 | - $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1029 | - $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1030 | - $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1031 | - $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1032 | - $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1033 | - $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1034 | - } |
|
| 951 | + $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 952 | + $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 953 | + $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 954 | + $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 955 | + |
|
| 956 | + // definition des statuts de publication |
|
| 957 | + $GLOBALS['table_statut'] = []; |
|
| 958 | + |
|
| 959 | + // |
|
| 960 | + // tableau des tables de jointures |
|
| 961 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 962 | + $GLOBALS['tables_jointures'] = []; |
|
| 963 | + $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 964 | + |
|
| 965 | + // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 966 | + $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 967 | + |
|
| 968 | + |
|
| 969 | + if (!defined('_TRAITEMENT_TYPO')) { |
|
| 970 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 971 | + } |
|
| 972 | + if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 973 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 974 | + } |
|
| 975 | + if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 976 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 977 | + } |
|
| 978 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 979 | + $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 980 | + $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(%s)'; |
|
| 981 | + $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 982 | + $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 983 | + $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 984 | + $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 985 | + $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 986 | + $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 987 | + $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 988 | + $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 989 | + $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 990 | + $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 991 | + $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 992 | + $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 993 | + $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 994 | + $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 995 | + $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 996 | + $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 997 | + $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 998 | + $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 999 | + $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1000 | + $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 1001 | + $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 1002 | + |
|
| 1003 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 1004 | + $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 1005 | + // toujours securiser les DATA |
|
| 1006 | + $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 1007 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 1008 | + $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1012 | + $interfaces = pipeline( |
|
| 1013 | + 'declarer_tables_interfaces', |
|
| 1014 | + [ |
|
| 1015 | + 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1016 | + 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1017 | + 'table_date' => $GLOBALS['table_date'], |
|
| 1018 | + 'table_titre' => $GLOBALS['table_titre'], |
|
| 1019 | + 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1020 | + 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1021 | + 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1022 | + 'table_statut' => $GLOBALS['table_statut'], |
|
| 1023 | + ] |
|
| 1024 | + ); |
|
| 1025 | + if ($interfaces) { |
|
| 1026 | + $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1027 | + $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1028 | + $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1029 | + $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1030 | + $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1031 | + $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1032 | + $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1033 | + $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1034 | + } |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | declarer_interfaces(); |
@@ -975,7 +975,7 @@ |
||
| 975 | 975 | if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
| 976 | 976 | define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
| 977 | 977 | } |
| 978 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 978 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml('._TRAITEMENT_RACCOURCIS.')'; |
|
| 979 | 979 | $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
| 980 | 980 | $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(%s)'; |
| 981 | 981 | $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
@@ -16,32 +16,32 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 23 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 26 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | - define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 35 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 39 | - preg_replace( |
|
| 40 | - '@^https?:@', |
|
| 41 | - 'https?:', |
|
| 42 | - (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | + ) |
|
| 44 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 45 | 45 | |
| 46 | 46 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 47 | 47 | |
@@ -68,87 +68,87 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
| 71 | - // si c'est la protection de soi-meme, retourner le path |
|
| 72 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | - |
|
| 75 | - return @file_exists($source) ? $source : false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (is_null($local)) { |
|
| 79 | - $local = fichier_copie_locale($source); |
|
| 80 | - } else { |
|
| 81 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | - if (!$local) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 94 | - $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | - |
|
| 96 | - // test d'existence du fichier |
|
| 97 | - if ($mode == 'test') { |
|
| 98 | - return $t ? $local : ''; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // sinon voir si on doit/peut le telecharger |
|
| 102 | - if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | - return $local; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($mode == 'modif' or !$t) { |
|
| 107 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | - // et des eventuelles recuperations concurantes |
|
| 109 | - include_spip('inc/acces'); |
|
| 110 | - if (!$taille_max) { |
|
| 111 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | - } |
|
| 113 | - $res = recuperer_url( |
|
| 114 | - $source, |
|
| 115 | - ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 116 | - ); |
|
| 117 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - if (!$res['length']) { |
|
| 121 | - // si $t c'est sans doute juste un not-modified-since |
|
| 122 | - return $t ? $local : false; |
|
| 123 | - } |
|
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | - |
|
| 126 | - // si on retrouve l'extension |
|
| 127 | - if ( |
|
| 128 | - !empty($res['headers']) |
|
| 129 | - and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 130 | - ) { |
|
| 131 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 132 | - $sanitizer($localrac); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // pour une eventuelle indexation |
|
| 137 | - pipeline( |
|
| 138 | - 'post_edition', |
|
| 139 | - [ |
|
| 140 | - 'args' => [ |
|
| 141 | - 'operation' => 'copie_locale', |
|
| 142 | - 'source' => $source, |
|
| 143 | - 'fichier' => $local, |
|
| 144 | - 'http_res' => $res['length'], |
|
| 145 | - ], |
|
| 146 | - 'data' => null |
|
| 147 | - ] |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $local; |
|
| 71 | + // si c'est la protection de soi-meme, retourner le path |
|
| 72 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | + |
|
| 75 | + return @file_exists($source) ? $source : false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (is_null($local)) { |
|
| 79 | + $local = fichier_copie_locale($source); |
|
| 80 | + } else { |
|
| 81 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | + if (!$local) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $localrac = _DIR_RACINE . $local; |
|
| 94 | + $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | + |
|
| 96 | + // test d'existence du fichier |
|
| 97 | + if ($mode == 'test') { |
|
| 98 | + return $t ? $local : ''; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // sinon voir si on doit/peut le telecharger |
|
| 102 | + if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | + return $local; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($mode == 'modif' or !$t) { |
|
| 107 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | + // et des eventuelles recuperations concurantes |
|
| 109 | + include_spip('inc/acces'); |
|
| 110 | + if (!$taille_max) { |
|
| 111 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | + } |
|
| 113 | + $res = recuperer_url( |
|
| 114 | + $source, |
|
| 115 | + ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 116 | + ); |
|
| 117 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + if (!$res['length']) { |
|
| 121 | + // si $t c'est sans doute juste un not-modified-since |
|
| 122 | + return $t ? $local : false; |
|
| 123 | + } |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | + |
|
| 126 | + // si on retrouve l'extension |
|
| 127 | + if ( |
|
| 128 | + !empty($res['headers']) |
|
| 129 | + and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 130 | + ) { |
|
| 131 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 132 | + $sanitizer($localrac); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // pour une eventuelle indexation |
|
| 137 | + pipeline( |
|
| 138 | + 'post_edition', |
|
| 139 | + [ |
|
| 140 | + 'args' => [ |
|
| 141 | + 'operation' => 'copie_locale', |
|
| 142 | + 'source' => $source, |
|
| 143 | + 'fichier' => $local, |
|
| 144 | + 'http_res' => $res['length'], |
|
| 145 | + ], |
|
| 146 | + 'data' => null |
|
| 147 | + ] |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $local; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -163,93 +163,93 @@ discard block |
||
| 163 | 163 | * url ou false en cas d'echec |
| 164 | 164 | */ |
| 165 | 165 | function valider_url_distante($url, $known_hosts = []) { |
| 166 | - if (!function_exists('protocole_verifier')) { |
|
| 167 | - include_spip('inc/filtres_mini'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $parsed_url = parse_url($url); |
|
| 175 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 184 | - return false; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if (!is_array($known_hosts)) { |
|
| 188 | - $known_hosts = [$known_hosts]; |
|
| 189 | - } |
|
| 190 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 191 | - $known_hosts[] = url_de_base(); |
|
| 192 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 193 | - |
|
| 194 | - $is_known_host = false; |
|
| 195 | - foreach ($known_hosts as $known_host) { |
|
| 196 | - $parse_known = parse_url($known_host); |
|
| 197 | - if ( |
|
| 198 | - $parse_known |
|
| 199 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 200 | - ) { |
|
| 201 | - $is_known_host = true; |
|
| 202 | - break; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if (!$is_known_host) { |
|
| 207 | - $host = trim($parsed_url['host'], '.'); |
|
| 208 | - if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 209 | - $ip = $host; |
|
| 210 | - } else { |
|
| 211 | - $ip = gethostbyname($host); |
|
| 212 | - if ($ip === $host) { |
|
| 213 | - // Error condition for gethostbyname() |
|
| 214 | - $ip = false; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - if ($ip) { |
|
| 218 | - $parts = array_map('intval', explode('.', $ip)); |
|
| 219 | - if ( |
|
| 220 | - 127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 221 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 222 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 223 | - ) { |
|
| 224 | - return false; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if (empty($parsed_url['port'])) { |
|
| 230 | - return $url; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - $port = $parsed_url['port']; |
|
| 234 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 235 | - return $url; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - if ($is_known_host) { |
|
| 239 | - foreach ($known_hosts as $known_host) { |
|
| 240 | - $parse_known = parse_url($known_host); |
|
| 241 | - if ( |
|
| 242 | - $parse_known |
|
| 243 | - and !empty($parse_known['port']) |
|
| 244 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 245 | - and $parse_known['port'] == $port |
|
| 246 | - ) { |
|
| 247 | - return $url; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return false; |
|
| 166 | + if (!function_exists('protocole_verifier')) { |
|
| 167 | + include_spip('inc/filtres_mini'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $parsed_url = parse_url($url); |
|
| 175 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if (!is_array($known_hosts)) { |
|
| 188 | + $known_hosts = [$known_hosts]; |
|
| 189 | + } |
|
| 190 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 191 | + $known_hosts[] = url_de_base(); |
|
| 192 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 193 | + |
|
| 194 | + $is_known_host = false; |
|
| 195 | + foreach ($known_hosts as $known_host) { |
|
| 196 | + $parse_known = parse_url($known_host); |
|
| 197 | + if ( |
|
| 198 | + $parse_known |
|
| 199 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 200 | + ) { |
|
| 201 | + $is_known_host = true; |
|
| 202 | + break; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if (!$is_known_host) { |
|
| 207 | + $host = trim($parsed_url['host'], '.'); |
|
| 208 | + if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 209 | + $ip = $host; |
|
| 210 | + } else { |
|
| 211 | + $ip = gethostbyname($host); |
|
| 212 | + if ($ip === $host) { |
|
| 213 | + // Error condition for gethostbyname() |
|
| 214 | + $ip = false; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + if ($ip) { |
|
| 218 | + $parts = array_map('intval', explode('.', $ip)); |
|
| 219 | + if ( |
|
| 220 | + 127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 221 | + or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 222 | + or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 223 | + ) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if (empty($parsed_url['port'])) { |
|
| 230 | + return $url; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + $port = $parsed_url['port']; |
|
| 234 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 235 | + return $url; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + if ($is_known_host) { |
|
| 239 | + foreach ($known_hosts as $known_host) { |
|
| 240 | + $parse_known = parse_url($known_host); |
|
| 241 | + if ( |
|
| 242 | + $parse_known |
|
| 243 | + and !empty($parse_known['port']) |
|
| 244 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 245 | + and $parse_known['port'] == $port |
|
| 246 | + ) { |
|
| 247 | + return $url; |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return false; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -269,86 +269,86 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | function prepare_donnees_post($donnees, $boundary = '') { |
| 271 | 271 | |
| 272 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 273 | - // pour un appel soap par exemple |
|
| 274 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 275 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 276 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 277 | - $entete = ''; |
|
| 278 | - // on repasse tous les \r\n et \r en simples \n |
|
| 279 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 280 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 281 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 282 | - $p = strpos($donnees, "\n\n"); |
|
| 283 | - if ($p !== false) { |
|
| 284 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 285 | - $donnees = substr($donnees, $p + 2); |
|
| 286 | - } |
|
| 287 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 288 | - } else { |
|
| 289 | - /* boundary automatique */ |
|
| 290 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 291 | - if ($boundary === '') { |
|
| 292 | - $taille = 0; |
|
| 293 | - foreach ($donnees as $cle => $valeur) { |
|
| 294 | - if (is_array($valeur)) { |
|
| 295 | - foreach ($valeur as $val2) { |
|
| 296 | - $taille += strlen($val2); |
|
| 297 | - } |
|
| 298 | - } else { |
|
| 299 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 300 | - $taille += strlen($valeur); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if ($taille > 500) { |
|
| 304 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 309 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 310 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 311 | - $chaine = ''; |
|
| 312 | - if (is_array($donnees)) { |
|
| 313 | - foreach ($donnees as $cle => $valeur) { |
|
| 314 | - if (is_array($valeur)) { |
|
| 315 | - foreach ($valeur as $val2) { |
|
| 316 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 317 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 318 | - $chaine .= "\r\n"; |
|
| 319 | - $chaine .= $val2; |
|
| 320 | - } |
|
| 321 | - } else { |
|
| 322 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 323 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 324 | - $chaine .= "\r\n"; |
|
| 325 | - $chaine .= $valeur; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 329 | - } |
|
| 330 | - } else { |
|
| 331 | - // fabrique une chaine HTTP simple pour un POST |
|
| 332 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 333 | - $chaine = []; |
|
| 334 | - if (is_array($donnees)) { |
|
| 335 | - foreach ($donnees as $cle => $valeur) { |
|
| 336 | - if (is_array($valeur)) { |
|
| 337 | - foreach ($valeur as $val2) { |
|
| 338 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - $chaine = implode('&', $chaine); |
|
| 345 | - } else { |
|
| 346 | - $chaine = $donnees; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return [$entete, $chaine]; |
|
| 272 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 273 | + // pour un appel soap par exemple |
|
| 274 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 275 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 276 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 277 | + $entete = ''; |
|
| 278 | + // on repasse tous les \r\n et \r en simples \n |
|
| 279 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 280 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 281 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 282 | + $p = strpos($donnees, "\n\n"); |
|
| 283 | + if ($p !== false) { |
|
| 284 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 285 | + $donnees = substr($donnees, $p + 2); |
|
| 286 | + } |
|
| 287 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 288 | + } else { |
|
| 289 | + /* boundary automatique */ |
|
| 290 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 291 | + if ($boundary === '') { |
|
| 292 | + $taille = 0; |
|
| 293 | + foreach ($donnees as $cle => $valeur) { |
|
| 294 | + if (is_array($valeur)) { |
|
| 295 | + foreach ($valeur as $val2) { |
|
| 296 | + $taille += strlen($val2); |
|
| 297 | + } |
|
| 298 | + } else { |
|
| 299 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 300 | + $taille += strlen($valeur); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if ($taille > 500) { |
|
| 304 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 309 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 310 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 311 | + $chaine = ''; |
|
| 312 | + if (is_array($donnees)) { |
|
| 313 | + foreach ($donnees as $cle => $valeur) { |
|
| 314 | + if (is_array($valeur)) { |
|
| 315 | + foreach ($valeur as $val2) { |
|
| 316 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 317 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 318 | + $chaine .= "\r\n"; |
|
| 319 | + $chaine .= $val2; |
|
| 320 | + } |
|
| 321 | + } else { |
|
| 322 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 323 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 324 | + $chaine .= "\r\n"; |
|
| 325 | + $chaine .= $valeur; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 329 | + } |
|
| 330 | + } else { |
|
| 331 | + // fabrique une chaine HTTP simple pour un POST |
|
| 332 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 333 | + $chaine = []; |
|
| 334 | + if (is_array($donnees)) { |
|
| 335 | + foreach ($donnees as $cle => $valeur) { |
|
| 336 | + if (is_array($valeur)) { |
|
| 337 | + foreach ($valeur as $val2) { |
|
| 338 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + $chaine = implode('&', $chaine); |
|
| 345 | + } else { |
|
| 346 | + $chaine = $donnees; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return [$entete, $chaine]; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -362,22 +362,22 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | function url_to_ascii($url_idn) { |
| 364 | 364 | |
| 365 | - if ($parts = parse_url($url_idn)) { |
|
| 366 | - $host = $parts['host']; |
|
| 367 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 368 | - include_spip('inc/idna_convert.class'); |
|
| 369 | - $IDN = new idna_convert(); |
|
| 370 | - $host_ascii = $IDN->encode($host); |
|
| 371 | - $url_idn = explode($host, $url_idn, 2); |
|
| 372 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 373 | - } |
|
| 374 | - // et on urlencode les char utf si besoin dans le path |
|
| 375 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 376 | - return urlencode($match[0]); |
|
| 377 | - }, $url_idn); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - return $url_idn; |
|
| 365 | + if ($parts = parse_url($url_idn)) { |
|
| 366 | + $host = $parts['host']; |
|
| 367 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 368 | + include_spip('inc/idna_convert.class'); |
|
| 369 | + $IDN = new idna_convert(); |
|
| 370 | + $host_ascii = $IDN->encode($host); |
|
| 371 | + $url_idn = explode($host, $url_idn, 2); |
|
| 372 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 373 | + } |
|
| 374 | + // et on urlencode les char utf si besoin dans le path |
|
| 375 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 376 | + return urlencode($match[0]); |
|
| 377 | + }, $url_idn); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + return $url_idn; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -418,197 +418,197 @@ discard block |
||
| 418 | 418 | * string file : nom du fichier si enregistre dans un fichier |
| 419 | 419 | */ |
| 420 | 420 | function recuperer_url($url, $options = []) { |
| 421 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 422 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 423 | - $default = [ |
|
| 424 | - 'transcoder' => false, |
|
| 425 | - 'methode' => 'GET', |
|
| 426 | - 'taille_max' => null, |
|
| 427 | - 'headers' => [], |
|
| 428 | - 'datas' => '', |
|
| 429 | - 'boundary' => '', |
|
| 430 | - 'refuser_gz' => false, |
|
| 431 | - 'if_modified_since' => '', |
|
| 432 | - 'uri_referer' => '', |
|
| 433 | - 'file' => '', |
|
| 434 | - 'follow_location' => 10, |
|
| 435 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 436 | - ]; |
|
| 437 | - $options = array_merge($default, $options); |
|
| 438 | - // copier directement dans un fichier ? |
|
| 439 | - $copy = $options['file']; |
|
| 440 | - |
|
| 441 | - if ($options['methode'] == 'HEAD') { |
|
| 442 | - $options['taille_max'] = 0; |
|
| 443 | - } |
|
| 444 | - if (is_null($options['taille_max'])) { |
|
| 445 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - // Ajout des en-têtes spécifiques si besoin |
|
| 450 | - $head_add = ''; |
|
| 451 | - if (!empty($options['headers'])) { |
|
| 452 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 453 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 454 | - } |
|
| 455 | - // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 456 | - unset($options['headers']); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - if (!empty($options['datas'])) { |
|
| 460 | - list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 461 | - $head .= $head_add; |
|
| 462 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 463 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 464 | - } |
|
| 465 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 466 | - if ( |
|
| 467 | - strlen($postdata) |
|
| 468 | - and !$methode_demandee |
|
| 469 | - ) { |
|
| 470 | - $options['methode'] = 'POST'; |
|
| 471 | - } |
|
| 472 | - } elseif ($head_add) { |
|
| 473 | - $options['datas'] = $head_add . "\r\n"; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 477 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 478 | - if (!tester_url_absolue($url)) { |
|
| 479 | - $url = 'http://' . $url; |
|
| 480 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 481 | - $url = 'http:' . $url; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $url = url_to_ascii($url); |
|
| 485 | - |
|
| 486 | - $result = [ |
|
| 487 | - 'status' => 0, |
|
| 488 | - 'headers' => '', |
|
| 489 | - 'page' => '', |
|
| 490 | - 'length' => 0, |
|
| 491 | - 'last_modified' => '', |
|
| 492 | - 'location' => '', |
|
| 493 | - 'url' => $url |
|
| 494 | - ]; |
|
| 495 | - |
|
| 496 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 497 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 498 | - |
|
| 499 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 500 | - list($handle, $fopen) = init_http( |
|
| 501 | - $options['methode'], |
|
| 502 | - $url, |
|
| 503 | - $refuser_gz, |
|
| 504 | - $options['uri_referer'], |
|
| 505 | - $options['datas'], |
|
| 506 | - $options['version_http'], |
|
| 507 | - $options['if_modified_since'] |
|
| 508 | - ); |
|
| 509 | - if (!$handle) { |
|
| 510 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 511 | - |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 516 | - // et recuperer les en-tetes de reponses |
|
| 517 | - if (!$fopen) { |
|
| 518 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 519 | - if (!$res) { |
|
| 520 | - fclose($handle); |
|
| 521 | - $t = @parse_url($url); |
|
| 522 | - $host = $t['host']; |
|
| 523 | - // Chinoisierie inexplicable pour contrer |
|
| 524 | - // les actions liberticides de l'empire du milieu |
|
| 525 | - if ( |
|
| 526 | - !need_proxy($host) |
|
| 527 | - and $res = @file_get_contents($url) |
|
| 528 | - ) { |
|
| 529 | - $result['length'] = strlen($res); |
|
| 530 | - if ($copy) { |
|
| 531 | - ecrire_fichier($copy, $res); |
|
| 532 | - $result['file'] = $copy; |
|
| 533 | - } else { |
|
| 534 | - $result['page'] = $res; |
|
| 535 | - } |
|
| 536 | - $res = [ |
|
| 537 | - 'status' => 200, |
|
| 538 | - ]; |
|
| 539 | - } else { |
|
| 540 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 541 | - return false; |
|
| 542 | - } |
|
| 543 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 544 | - $options['follow_location']--; |
|
| 545 | - fclose($handle); |
|
| 546 | - include_spip('inc/filtres'); |
|
| 547 | - $url = suivre_lien($url, $res['location']); |
|
| 548 | - spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 549 | - |
|
| 550 | - return recuperer_url($url, $options); |
|
| 551 | - } elseif ($res['status'] !== 200) { |
|
| 552 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 553 | - } |
|
| 554 | - $result['status'] = $res['status']; |
|
| 555 | - if (isset($res['headers'])) { |
|
| 556 | - $result['headers'] = $res['headers']; |
|
| 557 | - } |
|
| 558 | - if (isset($res['last_modified'])) { |
|
| 559 | - $result['last_modified'] = $res['last_modified']; |
|
| 560 | - } |
|
| 561 | - if (isset($res['location'])) { |
|
| 562 | - $result['location'] = $res['location']; |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - // on ne veut que les entetes |
|
| 567 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 568 | - return $result; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 573 | - // sinon la memoire explose pour les gros flux |
|
| 574 | - |
|
| 575 | - $gz = false; |
|
| 576 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 577 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 581 | - if (!$result['length']) { |
|
| 582 | - $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 583 | - fclose($handle); |
|
| 584 | - if ($copy) { |
|
| 585 | - $result['length'] = $res; |
|
| 586 | - $result['file'] = $copy; |
|
| 587 | - } elseif ($res) { |
|
| 588 | - $result['page'] = &$res; |
|
| 589 | - $result['length'] = strlen($result['page']); |
|
| 590 | - } |
|
| 591 | - if (!$result['status']) { |
|
| 592 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - if (!$result['page']) { |
|
| 596 | - return $result; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - // Decompresser au besoin |
|
| 600 | - if ($gz) { |
|
| 601 | - $result['page'] = implode('', gzfile($gz)); |
|
| 602 | - supprimer_fichier($gz); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // Faut-il l'importer dans notre charset local ? |
|
| 606 | - if ($options['transcoder']) { |
|
| 607 | - include_spip('inc/charsets'); |
|
| 608 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - return $result; |
|
| 421 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 422 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 423 | + $default = [ |
|
| 424 | + 'transcoder' => false, |
|
| 425 | + 'methode' => 'GET', |
|
| 426 | + 'taille_max' => null, |
|
| 427 | + 'headers' => [], |
|
| 428 | + 'datas' => '', |
|
| 429 | + 'boundary' => '', |
|
| 430 | + 'refuser_gz' => false, |
|
| 431 | + 'if_modified_since' => '', |
|
| 432 | + 'uri_referer' => '', |
|
| 433 | + 'file' => '', |
|
| 434 | + 'follow_location' => 10, |
|
| 435 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 436 | + ]; |
|
| 437 | + $options = array_merge($default, $options); |
|
| 438 | + // copier directement dans un fichier ? |
|
| 439 | + $copy = $options['file']; |
|
| 440 | + |
|
| 441 | + if ($options['methode'] == 'HEAD') { |
|
| 442 | + $options['taille_max'] = 0; |
|
| 443 | + } |
|
| 444 | + if (is_null($options['taille_max'])) { |
|
| 445 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + // Ajout des en-têtes spécifiques si besoin |
|
| 450 | + $head_add = ''; |
|
| 451 | + if (!empty($options['headers'])) { |
|
| 452 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 453 | + $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 454 | + } |
|
| 455 | + // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 456 | + unset($options['headers']); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + if (!empty($options['datas'])) { |
|
| 460 | + list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 461 | + $head .= $head_add; |
|
| 462 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 463 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 464 | + } |
|
| 465 | + $options['datas'] = $head . "\r\n" . $postdata; |
|
| 466 | + if ( |
|
| 467 | + strlen($postdata) |
|
| 468 | + and !$methode_demandee |
|
| 469 | + ) { |
|
| 470 | + $options['methode'] = 'POST'; |
|
| 471 | + } |
|
| 472 | + } elseif ($head_add) { |
|
| 473 | + $options['datas'] = $head_add . "\r\n"; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 477 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 478 | + if (!tester_url_absolue($url)) { |
|
| 479 | + $url = 'http://' . $url; |
|
| 480 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 481 | + $url = 'http:' . $url; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $url = url_to_ascii($url); |
|
| 485 | + |
|
| 486 | + $result = [ |
|
| 487 | + 'status' => 0, |
|
| 488 | + 'headers' => '', |
|
| 489 | + 'page' => '', |
|
| 490 | + 'length' => 0, |
|
| 491 | + 'last_modified' => '', |
|
| 492 | + 'location' => '', |
|
| 493 | + 'url' => $url |
|
| 494 | + ]; |
|
| 495 | + |
|
| 496 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 497 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 498 | + |
|
| 499 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 500 | + list($handle, $fopen) = init_http( |
|
| 501 | + $options['methode'], |
|
| 502 | + $url, |
|
| 503 | + $refuser_gz, |
|
| 504 | + $options['uri_referer'], |
|
| 505 | + $options['datas'], |
|
| 506 | + $options['version_http'], |
|
| 507 | + $options['if_modified_since'] |
|
| 508 | + ); |
|
| 509 | + if (!$handle) { |
|
| 510 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 511 | + |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 516 | + // et recuperer les en-tetes de reponses |
|
| 517 | + if (!$fopen) { |
|
| 518 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 519 | + if (!$res) { |
|
| 520 | + fclose($handle); |
|
| 521 | + $t = @parse_url($url); |
|
| 522 | + $host = $t['host']; |
|
| 523 | + // Chinoisierie inexplicable pour contrer |
|
| 524 | + // les actions liberticides de l'empire du milieu |
|
| 525 | + if ( |
|
| 526 | + !need_proxy($host) |
|
| 527 | + and $res = @file_get_contents($url) |
|
| 528 | + ) { |
|
| 529 | + $result['length'] = strlen($res); |
|
| 530 | + if ($copy) { |
|
| 531 | + ecrire_fichier($copy, $res); |
|
| 532 | + $result['file'] = $copy; |
|
| 533 | + } else { |
|
| 534 | + $result['page'] = $res; |
|
| 535 | + } |
|
| 536 | + $res = [ |
|
| 537 | + 'status' => 200, |
|
| 538 | + ]; |
|
| 539 | + } else { |
|
| 540 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 544 | + $options['follow_location']--; |
|
| 545 | + fclose($handle); |
|
| 546 | + include_spip('inc/filtres'); |
|
| 547 | + $url = suivre_lien($url, $res['location']); |
|
| 548 | + spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 549 | + |
|
| 550 | + return recuperer_url($url, $options); |
|
| 551 | + } elseif ($res['status'] !== 200) { |
|
| 552 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 553 | + } |
|
| 554 | + $result['status'] = $res['status']; |
|
| 555 | + if (isset($res['headers'])) { |
|
| 556 | + $result['headers'] = $res['headers']; |
|
| 557 | + } |
|
| 558 | + if (isset($res['last_modified'])) { |
|
| 559 | + $result['last_modified'] = $res['last_modified']; |
|
| 560 | + } |
|
| 561 | + if (isset($res['location'])) { |
|
| 562 | + $result['location'] = $res['location']; |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // on ne veut que les entetes |
|
| 567 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 568 | + return $result; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 573 | + // sinon la memoire explose pour les gros flux |
|
| 574 | + |
|
| 575 | + $gz = false; |
|
| 576 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 577 | + $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 581 | + if (!$result['length']) { |
|
| 582 | + $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 583 | + fclose($handle); |
|
| 584 | + if ($copy) { |
|
| 585 | + $result['length'] = $res; |
|
| 586 | + $result['file'] = $copy; |
|
| 587 | + } elseif ($res) { |
|
| 588 | + $result['page'] = &$res; |
|
| 589 | + $result['length'] = strlen($result['page']); |
|
| 590 | + } |
|
| 591 | + if (!$result['status']) { |
|
| 592 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + if (!$result['page']) { |
|
| 596 | + return $result; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + // Decompresser au besoin |
|
| 600 | + if ($gz) { |
|
| 601 | + $result['page'] = implode('', gzfile($gz)); |
|
| 602 | + supprimer_fichier($gz); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // Faut-il l'importer dans notre charset local ? |
|
| 606 | + if ($options['transcoder']) { |
|
| 607 | + include_spip('inc/charsets'); |
|
| 608 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + return $result; |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -624,73 +624,73 @@ discard block |
||
| 624 | 624 | * @return array|bool|mixed |
| 625 | 625 | */ |
| 626 | 626 | function recuperer_url_cache($url, $options = []) { |
| 627 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 628 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 629 | - } |
|
| 630 | - $default = [ |
|
| 631 | - 'transcoder' => false, |
|
| 632 | - 'methode' => 'GET', |
|
| 633 | - 'taille_max' => null, |
|
| 634 | - 'datas' => '', |
|
| 635 | - 'boundary' => '', |
|
| 636 | - 'refuser_gz' => false, |
|
| 637 | - 'if_modified_since' => '', |
|
| 638 | - 'uri_referer' => '', |
|
| 639 | - 'file' => '', |
|
| 640 | - 'follow_location' => 10, |
|
| 641 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 642 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 643 | - ]; |
|
| 644 | - $options = array_merge($default, $options); |
|
| 645 | - |
|
| 646 | - // cas ou il n'est pas possible de cacher |
|
| 647 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 648 | - return recuperer_url($url, $options); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 652 | - static $errors = []; |
|
| 653 | - if (isset($errors[$url])) { |
|
| 654 | - return $errors[$url]; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - $sig = $options; |
|
| 658 | - unset($sig['if_modified_since']); |
|
| 659 | - unset($sig['delai_cache']); |
|
| 660 | - $sig['url'] = $url; |
|
| 661 | - |
|
| 662 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 663 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 664 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 665 | - $cache = "$sub$cache"; |
|
| 666 | - |
|
| 667 | - $res = false; |
|
| 668 | - $is_cached = file_exists($cache); |
|
| 669 | - if ( |
|
| 670 | - $is_cached |
|
| 671 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 672 | - ) { |
|
| 673 | - lire_fichier($cache, $res); |
|
| 674 | - if ($res = unserialize($res)) { |
|
| 675 | - // mettre le last_modified et le status=304 ? |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - if (!$res) { |
|
| 679 | - $res = recuperer_url($url, $options); |
|
| 680 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 681 | - if (!$res) { |
|
| 682 | - if ($is_cached) { |
|
| 683 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 684 | - lire_fichier($cache, $res); |
|
| 685 | - $res = unserialize($res); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - return $errors[$url] = $res; |
|
| 689 | - } |
|
| 690 | - ecrire_fichier($cache, serialize($res)); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return $res; |
|
| 627 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 628 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 629 | + } |
|
| 630 | + $default = [ |
|
| 631 | + 'transcoder' => false, |
|
| 632 | + 'methode' => 'GET', |
|
| 633 | + 'taille_max' => null, |
|
| 634 | + 'datas' => '', |
|
| 635 | + 'boundary' => '', |
|
| 636 | + 'refuser_gz' => false, |
|
| 637 | + 'if_modified_since' => '', |
|
| 638 | + 'uri_referer' => '', |
|
| 639 | + 'file' => '', |
|
| 640 | + 'follow_location' => 10, |
|
| 641 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 642 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 643 | + ]; |
|
| 644 | + $options = array_merge($default, $options); |
|
| 645 | + |
|
| 646 | + // cas ou il n'est pas possible de cacher |
|
| 647 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 648 | + return recuperer_url($url, $options); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 652 | + static $errors = []; |
|
| 653 | + if (isset($errors[$url])) { |
|
| 654 | + return $errors[$url]; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + $sig = $options; |
|
| 658 | + unset($sig['if_modified_since']); |
|
| 659 | + unset($sig['delai_cache']); |
|
| 660 | + $sig['url'] = $url; |
|
| 661 | + |
|
| 662 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 663 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 664 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 665 | + $cache = "$sub$cache"; |
|
| 666 | + |
|
| 667 | + $res = false; |
|
| 668 | + $is_cached = file_exists($cache); |
|
| 669 | + if ( |
|
| 670 | + $is_cached |
|
| 671 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 672 | + ) { |
|
| 673 | + lire_fichier($cache, $res); |
|
| 674 | + if ($res = unserialize($res)) { |
|
| 675 | + // mettre le last_modified et le status=304 ? |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + if (!$res) { |
|
| 679 | + $res = recuperer_url($url, $options); |
|
| 680 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 681 | + if (!$res) { |
|
| 682 | + if ($is_cached) { |
|
| 683 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 684 | + lire_fichier($cache, $res); |
|
| 685 | + $res = unserialize($res); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + return $errors[$url] = $res; |
|
| 689 | + } |
|
| 690 | + ecrire_fichier($cache, serialize($res)); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return $res; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | /** |
@@ -708,41 +708,41 @@ discard block |
||
| 708 | 708 | * string contenu de la resource |
| 709 | 709 | */ |
| 710 | 710 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 711 | - $taille = 0; |
|
| 712 | - $result = ''; |
|
| 713 | - $fp = false; |
|
| 714 | - if ($fichier) { |
|
| 715 | - include_spip('inc/acces'); |
|
| 716 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 717 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 718 | - if (!$fp and file_exists($fichier)) { |
|
| 719 | - return filesize($fichier); |
|
| 720 | - } |
|
| 721 | - if (!$fp) { |
|
| 722 | - return false; |
|
| 723 | - } |
|
| 724 | - $result = 0; // on renvoie la taille du fichier |
|
| 725 | - } |
|
| 726 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 727 | - $res = fread($handle, 16384); |
|
| 728 | - $taille += strlen($res); |
|
| 729 | - if ($fp) { |
|
| 730 | - fwrite($fp, $res); |
|
| 731 | - $result = $taille; |
|
| 732 | - } else { |
|
| 733 | - $result .= $res; |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - if ($fp) { |
|
| 737 | - spip_fclose_unlock($fp); |
|
| 738 | - spip_unlink($fichier); |
|
| 739 | - @rename($tmpfile, $fichier); |
|
| 740 | - if (!file_exists($fichier)) { |
|
| 741 | - return false; |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return $result; |
|
| 711 | + $taille = 0; |
|
| 712 | + $result = ''; |
|
| 713 | + $fp = false; |
|
| 714 | + if ($fichier) { |
|
| 715 | + include_spip('inc/acces'); |
|
| 716 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 717 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 718 | + if (!$fp and file_exists($fichier)) { |
|
| 719 | + return filesize($fichier); |
|
| 720 | + } |
|
| 721 | + if (!$fp) { |
|
| 722 | + return false; |
|
| 723 | + } |
|
| 724 | + $result = 0; // on renvoie la taille du fichier |
|
| 725 | + } |
|
| 726 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 727 | + $res = fread($handle, 16384); |
|
| 728 | + $taille += strlen($res); |
|
| 729 | + if ($fp) { |
|
| 730 | + fwrite($fp, $res); |
|
| 731 | + $result = $taille; |
|
| 732 | + } else { |
|
| 733 | + $result .= $res; |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + if ($fp) { |
|
| 737 | + spip_fclose_unlock($fp); |
|
| 738 | + spip_unlink($fichier); |
|
| 739 | + @rename($tmpfile, $fichier); |
|
| 740 | + if (!file_exists($fichier)) { |
|
| 741 | + return false; |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return $result; |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
@@ -764,35 +764,35 @@ discard block |
||
| 764 | 764 | * string location |
| 765 | 765 | */ |
| 766 | 766 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 767 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 768 | - |
|
| 769 | - $s = @trim(fgets($handle, 16384)); |
|
| 770 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 771 | - return false; |
|
| 772 | - } |
|
| 773 | - $result['status'] = intval($r[1]); |
|
| 774 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 775 | - $result['headers'][] = $s . "\n"; |
|
| 776 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 777 | - list(, $d, $v) = $r; |
|
| 778 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 779 | - $result['location'] = $v; |
|
| 780 | - } elseif ($d == 'Last-Modified') { |
|
| 781 | - $result['last_modified'] = strtotime($v); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - if ( |
|
| 785 | - $if_modified_since |
|
| 786 | - and $result['last_modified'] |
|
| 787 | - and $if_modified_since > $result['last_modified'] |
|
| 788 | - and $result['status'] == 200 |
|
| 789 | - ) { |
|
| 790 | - $result['status'] = 304; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - $result['headers'] = implode('', $result['headers']); |
|
| 794 | - |
|
| 795 | - return $result; |
|
| 767 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 768 | + |
|
| 769 | + $s = @trim(fgets($handle, 16384)); |
|
| 770 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 771 | + return false; |
|
| 772 | + } |
|
| 773 | + $result['status'] = intval($r[1]); |
|
| 774 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 775 | + $result['headers'][] = $s . "\n"; |
|
| 776 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 777 | + list(, $d, $v) = $r; |
|
| 778 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 779 | + $result['location'] = $v; |
|
| 780 | + } elseif ($d == 'Last-Modified') { |
|
| 781 | + $result['last_modified'] = strtotime($v); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + if ( |
|
| 785 | + $if_modified_since |
|
| 786 | + and $result['last_modified'] |
|
| 787 | + and $if_modified_since > $result['last_modified'] |
|
| 788 | + and $result['status'] == 200 |
|
| 789 | + ) { |
|
| 790 | + $result['status'] = 304; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + $result['headers'] = implode('', $result['headers']); |
|
| 794 | + |
|
| 795 | + return $result; |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -814,22 +814,22 @@ discard block |
||
| 814 | 814 | * Nom du fichier pour copie locale |
| 815 | 815 | **/ |
| 816 | 816 | function nom_fichier_copie_locale($source, $extension) { |
| 817 | - include_spip('inc/documents'); |
|
| 817 | + include_spip('inc/documents'); |
|
| 818 | 818 | |
| 819 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 820 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 819 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 820 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 821 | 821 | |
| 822 | - // on se place tout le temps comme si on etait a la racine |
|
| 823 | - if (_DIR_RACINE) { |
|
| 824 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 825 | - } |
|
| 822 | + // on se place tout le temps comme si on etait a la racine |
|
| 823 | + if (_DIR_RACINE) { |
|
| 824 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | - $m = md5($source); |
|
| 827 | + $m = md5($source); |
|
| 828 | 828 | |
| 829 | - return $d |
|
| 830 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 831 | - . substr($m, 0, 4) |
|
| 832 | - . ".$extension"; |
|
| 829 | + return $d |
|
| 830 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 831 | + . substr($m, 0, 4) |
|
| 832 | + . ".$extension"; |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
@@ -847,70 +847,70 @@ discard block |
||
| 847 | 847 | * Nom du fichier calculé |
| 848 | 848 | **/ |
| 849 | 849 | function fichier_copie_locale($source) { |
| 850 | - // Si c'est deja local pas de souci |
|
| 851 | - if (!tester_url_absolue($source)) { |
|
| 852 | - if (_DIR_RACINE) { |
|
| 853 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $source; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 860 | - // a deja ete copie en local avec cette extension |
|
| 861 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 862 | - $path_parts = pathinfo($source); |
|
| 863 | - if (!isset($path_parts['extension'])) { |
|
| 864 | - $path_parts['extension'] = ''; |
|
| 865 | - } |
|
| 866 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 867 | - if ( |
|
| 868 | - $ext |
|
| 869 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 870 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 871 | - and file_exists(_DIR_RACINE . $f) |
|
| 872 | - ) { |
|
| 873 | - return $f; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - // Si c'est deja dans la table des documents, |
|
| 878 | - // ramener le nom de sa copie potentielle |
|
| 879 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 880 | - |
|
| 881 | - if ($ext) { |
|
| 882 | - return nom_fichier_copie_locale($source, $ext); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 886 | - // et si il n'aurait pas deja ete rapatrie |
|
| 887 | - |
|
| 888 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 889 | - |
|
| 890 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 891 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 892 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 893 | - return $f; |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - // Ping pour voir si son extension est connue et autorisee |
|
| 898 | - // avec mise en cache du resultat du ping |
|
| 899 | - |
|
| 900 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 901 | - if ( |
|
| 902 | - !@file_exists($cache) |
|
| 903 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 904 | - or _request('var_mode') == 'recalcul' |
|
| 905 | - ) { |
|
| 906 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 907 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 908 | - } |
|
| 909 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 910 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 911 | - return nom_fichier_copie_locale($source, $ext); |
|
| 912 | - } |
|
| 913 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 850 | + // Si c'est deja local pas de souci |
|
| 851 | + if (!tester_url_absolue($source)) { |
|
| 852 | + if (_DIR_RACINE) { |
|
| 853 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $source; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 860 | + // a deja ete copie en local avec cette extension |
|
| 861 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 862 | + $path_parts = pathinfo($source); |
|
| 863 | + if (!isset($path_parts['extension'])) { |
|
| 864 | + $path_parts['extension'] = ''; |
|
| 865 | + } |
|
| 866 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 867 | + if ( |
|
| 868 | + $ext |
|
| 869 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 870 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 871 | + and file_exists(_DIR_RACINE . $f) |
|
| 872 | + ) { |
|
| 873 | + return $f; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + // Si c'est deja dans la table des documents, |
|
| 878 | + // ramener le nom de sa copie potentielle |
|
| 879 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 880 | + |
|
| 881 | + if ($ext) { |
|
| 882 | + return nom_fichier_copie_locale($source, $ext); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 886 | + // et si il n'aurait pas deja ete rapatrie |
|
| 887 | + |
|
| 888 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 889 | + |
|
| 890 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 891 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 892 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 893 | + return $f; |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + // Ping pour voir si son extension est connue et autorisee |
|
| 898 | + // avec mise en cache du resultat du ping |
|
| 899 | + |
|
| 900 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 901 | + if ( |
|
| 902 | + !@file_exists($cache) |
|
| 903 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 904 | + or _request('var_mode') == 'recalcul' |
|
| 905 | + ) { |
|
| 906 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 907 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 908 | + } |
|
| 909 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 910 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 911 | + return nom_fichier_copie_locale($source, $ext); |
|
| 912 | + } |
|
| 913 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | |
@@ -938,97 +938,97 @@ discard block |
||
| 938 | 938 | **/ |
| 939 | 939 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 940 | 940 | |
| 941 | - // pas la peine de perdre son temps |
|
| 942 | - if (!tester_url_absolue($source)) { |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - # charger les alias des types mime |
|
| 947 | - include_spip('base/typedoc'); |
|
| 948 | - |
|
| 949 | - $a = []; |
|
| 950 | - $mime_type = ''; |
|
| 951 | - // On va directement charger le debut des images et des fichiers html, |
|
| 952 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 953 | - // ca echoue l'utilisateur devra les entrer... |
|
| 954 | - $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 955 | - $headers = $reponse['headers'] ?? ''; |
|
| 956 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 957 | - if ($headers) { |
|
| 958 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 959 | - return false; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - $a['extension'] = $extension; |
|
| 963 | - |
|
| 964 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 965 | - $a['taille'] = intval($regs[1]); |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - // Echec avec HEAD, on tente avec GET |
|
| 970 | - if (!$a and !$max) { |
|
| 971 | - spip_log("tenter GET $source", 'distant'); |
|
| 972 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - // si on a rien trouve pas la peine d'insister |
|
| 976 | - if (!$a) { |
|
| 977 | - return false; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 981 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 982 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 983 | - if ( |
|
| 984 | - strpos($mime_type, 'image/') === 0 |
|
| 985 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 986 | - ) { |
|
| 987 | - if ( |
|
| 988 | - $max == 0 |
|
| 989 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 990 | - and in_array($extension, formats_image_acceptables()) |
|
| 991 | - and $charger_si_petite_image |
|
| 992 | - ) { |
|
| 993 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 994 | - } else { |
|
| 995 | - if ($a['body']) { |
|
| 996 | - $a['extension'] = $extension; |
|
| 997 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 998 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 999 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1000 | - $a['largeur'] = intval($size_image[0]); |
|
| 1001 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1002 | - $a['type_image'] = true; |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1008 | - // ce sera mieux que 0x0 |
|
| 1009 | - // Flash is dead! |
|
| 1010 | - if ( |
|
| 1011 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1012 | - and empty($a['largeur']) |
|
| 1013 | - ) { |
|
| 1014 | - $a['largeur'] = 425; |
|
| 1015 | - $a['hauteur'] = 350; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - if ($mime_type == 'text/html') { |
|
| 1019 | - include_spip('inc/filtres'); |
|
| 1020 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1021 | - $page = $page['page'] ?? ''; |
|
| 1022 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1023 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1024 | - } |
|
| 1025 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1026 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - $a['mime_type'] = $mime_type; |
|
| 1030 | - |
|
| 1031 | - return $a; |
|
| 941 | + // pas la peine de perdre son temps |
|
| 942 | + if (!tester_url_absolue($source)) { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + # charger les alias des types mime |
|
| 947 | + include_spip('base/typedoc'); |
|
| 948 | + |
|
| 949 | + $a = []; |
|
| 950 | + $mime_type = ''; |
|
| 951 | + // On va directement charger le debut des images et des fichiers html, |
|
| 952 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 953 | + // ca echoue l'utilisateur devra les entrer... |
|
| 954 | + $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 955 | + $headers = $reponse['headers'] ?? ''; |
|
| 956 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 957 | + if ($headers) { |
|
| 958 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 959 | + return false; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + $a['extension'] = $extension; |
|
| 963 | + |
|
| 964 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 965 | + $a['taille'] = intval($regs[1]); |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + // Echec avec HEAD, on tente avec GET |
|
| 970 | + if (!$a and !$max) { |
|
| 971 | + spip_log("tenter GET $source", 'distant'); |
|
| 972 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + // si on a rien trouve pas la peine d'insister |
|
| 976 | + if (!$a) { |
|
| 977 | + return false; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 981 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 982 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 983 | + if ( |
|
| 984 | + strpos($mime_type, 'image/') === 0 |
|
| 985 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 986 | + ) { |
|
| 987 | + if ( |
|
| 988 | + $max == 0 |
|
| 989 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 990 | + and in_array($extension, formats_image_acceptables()) |
|
| 991 | + and $charger_si_petite_image |
|
| 992 | + ) { |
|
| 993 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 994 | + } else { |
|
| 995 | + if ($a['body']) { |
|
| 996 | + $a['extension'] = $extension; |
|
| 997 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 998 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 999 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1000 | + $a['largeur'] = intval($size_image[0]); |
|
| 1001 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1002 | + $a['type_image'] = true; |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1008 | + // ce sera mieux que 0x0 |
|
| 1009 | + // Flash is dead! |
|
| 1010 | + if ( |
|
| 1011 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1012 | + and empty($a['largeur']) |
|
| 1013 | + ) { |
|
| 1014 | + $a['largeur'] = 425; |
|
| 1015 | + $a['hauteur'] = 350; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + if ($mime_type == 'text/html') { |
|
| 1019 | + include_spip('inc/filtres'); |
|
| 1020 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1021 | + $page = $page['page'] ?? ''; |
|
| 1022 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1023 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1024 | + } |
|
| 1025 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1026 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + $a['mime_type'] = $mime_type; |
|
| 1030 | + |
|
| 1031 | + return $a; |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | /** |
@@ -1037,67 +1037,67 @@ discard block |
||
| 1037 | 1037 | * @return false|mixed |
| 1038 | 1038 | */ |
| 1039 | 1039 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1040 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1041 | - $mime_type = (trim($regs[1])); |
|
| 1042 | - } else { |
|
| 1043 | - $mime_type = ''; |
|
| 1044 | - } // inconnu |
|
| 1045 | - |
|
| 1046 | - // Appliquer les alias |
|
| 1047 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1048 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - // Si on a un mime-type insignifiant |
|
| 1052 | - // text/plain,application/octet-stream ou vide |
|
| 1053 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1054 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1055 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1056 | - $t = null; |
|
| 1057 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1058 | - if ( |
|
| 1059 | - !$t |
|
| 1060 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1061 | - ) { |
|
| 1062 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1063 | - } |
|
| 1064 | - if ( |
|
| 1065 | - !$t |
|
| 1066 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1067 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1068 | - ) { |
|
| 1069 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1074 | - if (!$t) { |
|
| 1075 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1079 | - // On essaie de nouveau avec l'extension |
|
| 1080 | - if ( |
|
| 1081 | - !$t |
|
| 1082 | - and $mime_type != 'text/plain' |
|
| 1083 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1084 | - ) { |
|
| 1085 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1086 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - if ($t) { |
|
| 1090 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1091 | - return $t['extension']; |
|
| 1092 | - } else { |
|
| 1093 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1094 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1095 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1096 | - if (!$t) { |
|
| 1097 | - return false; |
|
| 1098 | - } |
|
| 1099 | - return $t['extension']; |
|
| 1100 | - } |
|
| 1040 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1041 | + $mime_type = (trim($regs[1])); |
|
| 1042 | + } else { |
|
| 1043 | + $mime_type = ''; |
|
| 1044 | + } // inconnu |
|
| 1045 | + |
|
| 1046 | + // Appliquer les alias |
|
| 1047 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1048 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + // Si on a un mime-type insignifiant |
|
| 1052 | + // text/plain,application/octet-stream ou vide |
|
| 1053 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1054 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1055 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1056 | + $t = null; |
|
| 1057 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1058 | + if ( |
|
| 1059 | + !$t |
|
| 1060 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1061 | + ) { |
|
| 1062 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1063 | + } |
|
| 1064 | + if ( |
|
| 1065 | + !$t |
|
| 1066 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1067 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1068 | + ) { |
|
| 1069 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1074 | + if (!$t) { |
|
| 1075 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1079 | + // On essaie de nouveau avec l'extension |
|
| 1080 | + if ( |
|
| 1081 | + !$t |
|
| 1082 | + and $mime_type != 'text/plain' |
|
| 1083 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1084 | + ) { |
|
| 1085 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1086 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + if ($t) { |
|
| 1090 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1091 | + return $t['extension']; |
|
| 1092 | + } else { |
|
| 1093 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1094 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1095 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1096 | + if (!$t) { |
|
| 1097 | + return false; |
|
| 1098 | + } |
|
| 1099 | + return $t['extension']; |
|
| 1100 | + } |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
@@ -1112,46 +1112,46 @@ discard block |
||
| 1112 | 1112 | * @return string |
| 1113 | 1113 | */ |
| 1114 | 1114 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1115 | - if (is_null($http_proxy)) { |
|
| 1116 | - $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1117 | - } |
|
| 1118 | - // rien a faire si pas de proxy :) |
|
| 1119 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1120 | - return ''; |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - if (is_null($http_noproxy)) { |
|
| 1124 | - $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1125 | - } |
|
| 1126 | - // si pas d'exception, on retourne le proxy |
|
| 1127 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1128 | - return $http_proxy; |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1132 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1133 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1134 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1135 | - $http_noproxy = " $http_noproxy "; |
|
| 1136 | - $domain = $host; |
|
| 1137 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1138 | - if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1139 | - return ''; |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - while (strpos($domain, '.') !== false) { |
|
| 1143 | - $domain = explode('.', $domain); |
|
| 1144 | - array_shift($domain); |
|
| 1145 | - $domain = implode('.', $domain); |
|
| 1146 | - |
|
| 1147 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1148 | - if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1149 | - return ''; |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - // ok c'est pas une exception |
|
| 1154 | - return $http_proxy; |
|
| 1115 | + if (is_null($http_proxy)) { |
|
| 1116 | + $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1117 | + } |
|
| 1118 | + // rien a faire si pas de proxy :) |
|
| 1119 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1120 | + return ''; |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + if (is_null($http_noproxy)) { |
|
| 1124 | + $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1125 | + } |
|
| 1126 | + // si pas d'exception, on retourne le proxy |
|
| 1127 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1128 | + return $http_proxy; |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1132 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1133 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1134 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1135 | + $http_noproxy = " $http_noproxy "; |
|
| 1136 | + $domain = $host; |
|
| 1137 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1138 | + if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1139 | + return ''; |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + while (strpos($domain, '.') !== false) { |
|
| 1143 | + $domain = explode('.', $domain); |
|
| 1144 | + array_shift($domain); |
|
| 1145 | + $domain = implode('.', $domain); |
|
| 1146 | + |
|
| 1147 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1148 | + if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1149 | + return ''; |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + // ok c'est pas une exception |
|
| 1154 | + return $http_proxy; |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | |
@@ -1174,59 +1174,59 @@ discard block |
||
| 1174 | 1174 | * @return array |
| 1175 | 1175 | */ |
| 1176 | 1176 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1177 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1178 | - $fopen = false; |
|
| 1179 | - |
|
| 1180 | - $t = @parse_url($url); |
|
| 1181 | - $host = $t['host']; |
|
| 1182 | - if ($t['scheme'] == 'http') { |
|
| 1183 | - $scheme = 'http'; |
|
| 1184 | - $noproxy = ''; |
|
| 1185 | - } elseif ($t['scheme'] == 'https') { |
|
| 1186 | - $scheme = 'ssl'; |
|
| 1187 | - $noproxy = 'ssl://'; |
|
| 1188 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1189 | - $t['port'] = 443; |
|
| 1190 | - } |
|
| 1191 | - } else { |
|
| 1192 | - $scheme = $t['scheme']; |
|
| 1193 | - $noproxy = $scheme . '://'; |
|
| 1194 | - } |
|
| 1195 | - if (isset($t['user'])) { |
|
| 1196 | - $user = [$t['user'], $t['pass']]; |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1200 | - $port = 80; |
|
| 1201 | - } |
|
| 1202 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1203 | - $path = '/'; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - if (!empty($t['query'])) { |
|
| 1207 | - $path .= '?' . $t['query']; |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1211 | - if (!$f or !is_resource($f)) { |
|
| 1212 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1213 | - // ce qui correspond a $f===110 |
|
| 1214 | - if ( |
|
| 1215 | - $f !== 110 |
|
| 1216 | - and !need_proxy($host) |
|
| 1217 | - and !_request('tester_proxy') |
|
| 1218 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1219 | - ) { |
|
| 1220 | - $f = @fopen($url, 'rb'); |
|
| 1221 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1222 | - $fopen = true; |
|
| 1223 | - } else { |
|
| 1224 | - // echec total |
|
| 1225 | - $f = false; |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - return [$f, $fopen]; |
|
| 1177 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1178 | + $fopen = false; |
|
| 1179 | + |
|
| 1180 | + $t = @parse_url($url); |
|
| 1181 | + $host = $t['host']; |
|
| 1182 | + if ($t['scheme'] == 'http') { |
|
| 1183 | + $scheme = 'http'; |
|
| 1184 | + $noproxy = ''; |
|
| 1185 | + } elseif ($t['scheme'] == 'https') { |
|
| 1186 | + $scheme = 'ssl'; |
|
| 1187 | + $noproxy = 'ssl://'; |
|
| 1188 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1189 | + $t['port'] = 443; |
|
| 1190 | + } |
|
| 1191 | + } else { |
|
| 1192 | + $scheme = $t['scheme']; |
|
| 1193 | + $noproxy = $scheme . '://'; |
|
| 1194 | + } |
|
| 1195 | + if (isset($t['user'])) { |
|
| 1196 | + $user = [$t['user'], $t['pass']]; |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1200 | + $port = 80; |
|
| 1201 | + } |
|
| 1202 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1203 | + $path = '/'; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + if (!empty($t['query'])) { |
|
| 1207 | + $path .= '?' . $t['query']; |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1211 | + if (!$f or !is_resource($f)) { |
|
| 1212 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1213 | + // ce qui correspond a $f===110 |
|
| 1214 | + if ( |
|
| 1215 | + $f !== 110 |
|
| 1216 | + and !need_proxy($host) |
|
| 1217 | + and !_request('tester_proxy') |
|
| 1218 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1219 | + ) { |
|
| 1220 | + $f = @fopen($url, 'rb'); |
|
| 1221 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1222 | + $fopen = true; |
|
| 1223 | + } else { |
|
| 1224 | + // echec total |
|
| 1225 | + $f = false; |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + return [$f, $fopen]; |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1261,125 +1261,125 @@ discard block |
||
| 1261 | 1261 | * resource socket vers l'url demandee |
| 1262 | 1262 | */ |
| 1263 | 1263 | function lance_requete( |
| 1264 | - $method, |
|
| 1265 | - $scheme, |
|
| 1266 | - $user, |
|
| 1267 | - $host, |
|
| 1268 | - $path, |
|
| 1269 | - $port, |
|
| 1270 | - $noproxy, |
|
| 1271 | - $refuse_gz = false, |
|
| 1272 | - $referer = '', |
|
| 1273 | - $datas = '', |
|
| 1274 | - $vers = 'HTTP/1.0', |
|
| 1275 | - $date = '' |
|
| 1264 | + $method, |
|
| 1265 | + $scheme, |
|
| 1266 | + $user, |
|
| 1267 | + $host, |
|
| 1268 | + $path, |
|
| 1269 | + $port, |
|
| 1270 | + $noproxy, |
|
| 1271 | + $refuse_gz = false, |
|
| 1272 | + $referer = '', |
|
| 1273 | + $datas = '', |
|
| 1274 | + $vers = 'HTTP/1.0', |
|
| 1275 | + $date = '' |
|
| 1276 | 1276 | ) { |
| 1277 | 1277 | |
| 1278 | - $proxy_user = ''; |
|
| 1279 | - $http_proxy = need_proxy($host); |
|
| 1280 | - if ($user) { |
|
| 1281 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $connect = ''; |
|
| 1285 | - if ($http_proxy) { |
|
| 1286 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1287 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1288 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1289 | - . "Host: $path_host\r\n" |
|
| 1290 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1291 | - } else { |
|
| 1292 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1293 | - . (!$user ? '' : "$user@") |
|
| 1294 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1295 | - } |
|
| 1296 | - $t2 = @parse_url($http_proxy); |
|
| 1297 | - $first_host = $t2['host']; |
|
| 1298 | - if (!($port = $t2['port'])) { |
|
| 1299 | - $port = 80; |
|
| 1300 | - } |
|
| 1301 | - if ($t2['user']) { |
|
| 1302 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1303 | - } |
|
| 1304 | - } else { |
|
| 1305 | - $first_host = $noproxy . $host; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - if ($connect) { |
|
| 1309 | - $streamContext = stream_context_create([ |
|
| 1310 | - 'ssl' => [ |
|
| 1311 | - 'verify_peer' => false, |
|
| 1312 | - 'allow_self_signed' => true, |
|
| 1313 | - 'SNI_enabled' => true, |
|
| 1314 | - 'peer_name' => $host, |
|
| 1315 | - ] |
|
| 1316 | - ]); |
|
| 1317 | - $f = @stream_socket_client( |
|
| 1318 | - "tcp://$first_host:$port", |
|
| 1319 | - $errno, |
|
| 1320 | - $errstr, |
|
| 1321 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1322 | - STREAM_CLIENT_CONNECT, |
|
| 1323 | - $streamContext |
|
| 1324 | - ); |
|
| 1325 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1326 | - if (!$f) { |
|
| 1327 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1328 | - return $errno; |
|
| 1329 | - } |
|
| 1330 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1331 | - |
|
| 1332 | - fputs($f, $connect); |
|
| 1333 | - fputs($f, "\r\n"); |
|
| 1334 | - $res = fread($f, 1024); |
|
| 1335 | - if ( |
|
| 1336 | - !$res |
|
| 1337 | - or !count($res = explode(' ', $res)) |
|
| 1338 | - or $res[1] !== '200' |
|
| 1339 | - ) { |
|
| 1340 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1341 | - fclose($f); |
|
| 1342 | - |
|
| 1343 | - return false; |
|
| 1344 | - } |
|
| 1345 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1346 | - stream_set_blocking($f, true); |
|
| 1347 | - // envoyer le handshake |
|
| 1348 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1349 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1350 | - } else { |
|
| 1351 | - $ntry = 3; |
|
| 1352 | - do { |
|
| 1353 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1354 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1355 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1356 | - if (!$f) { |
|
| 1357 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1358 | - |
|
| 1359 | - return $errno; |
|
| 1360 | - } |
|
| 1361 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1365 | - |
|
| 1366 | - $host_port = $host; |
|
| 1367 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1368 | - $host_port .= ":$port"; |
|
| 1369 | - } |
|
| 1370 | - $req = "$method $path $vers\r\n" |
|
| 1371 | - . "Host: $host_port\r\n" |
|
| 1372 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1373 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1374 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1375 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1376 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1377 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1378 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1278 | + $proxy_user = ''; |
|
| 1279 | + $http_proxy = need_proxy($host); |
|
| 1280 | + if ($user) { |
|
| 1281 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $connect = ''; |
|
| 1285 | + if ($http_proxy) { |
|
| 1286 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1287 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1288 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1289 | + . "Host: $path_host\r\n" |
|
| 1290 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1291 | + } else { |
|
| 1292 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1293 | + . (!$user ? '' : "$user@") |
|
| 1294 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1295 | + } |
|
| 1296 | + $t2 = @parse_url($http_proxy); |
|
| 1297 | + $first_host = $t2['host']; |
|
| 1298 | + if (!($port = $t2['port'])) { |
|
| 1299 | + $port = 80; |
|
| 1300 | + } |
|
| 1301 | + if ($t2['user']) { |
|
| 1302 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1303 | + } |
|
| 1304 | + } else { |
|
| 1305 | + $first_host = $noproxy . $host; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + if ($connect) { |
|
| 1309 | + $streamContext = stream_context_create([ |
|
| 1310 | + 'ssl' => [ |
|
| 1311 | + 'verify_peer' => false, |
|
| 1312 | + 'allow_self_signed' => true, |
|
| 1313 | + 'SNI_enabled' => true, |
|
| 1314 | + 'peer_name' => $host, |
|
| 1315 | + ] |
|
| 1316 | + ]); |
|
| 1317 | + $f = @stream_socket_client( |
|
| 1318 | + "tcp://$first_host:$port", |
|
| 1319 | + $errno, |
|
| 1320 | + $errstr, |
|
| 1321 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1322 | + STREAM_CLIENT_CONNECT, |
|
| 1323 | + $streamContext |
|
| 1324 | + ); |
|
| 1325 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1326 | + if (!$f) { |
|
| 1327 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1328 | + return $errno; |
|
| 1329 | + } |
|
| 1330 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1331 | + |
|
| 1332 | + fputs($f, $connect); |
|
| 1333 | + fputs($f, "\r\n"); |
|
| 1334 | + $res = fread($f, 1024); |
|
| 1335 | + if ( |
|
| 1336 | + !$res |
|
| 1337 | + or !count($res = explode(' ', $res)) |
|
| 1338 | + or $res[1] !== '200' |
|
| 1339 | + ) { |
|
| 1340 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1341 | + fclose($f); |
|
| 1342 | + |
|
| 1343 | + return false; |
|
| 1344 | + } |
|
| 1345 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1346 | + stream_set_blocking($f, true); |
|
| 1347 | + // envoyer le handshake |
|
| 1348 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1349 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1350 | + } else { |
|
| 1351 | + $ntry = 3; |
|
| 1352 | + do { |
|
| 1353 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1354 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1355 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1356 | + if (!$f) { |
|
| 1357 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1358 | + |
|
| 1359 | + return $errno; |
|
| 1360 | + } |
|
| 1361 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1365 | + |
|
| 1366 | + $host_port = $host; |
|
| 1367 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1368 | + $host_port .= ":$port"; |
|
| 1369 | + } |
|
| 1370 | + $req = "$method $path $vers\r\n" |
|
| 1371 | + . "Host: $host_port\r\n" |
|
| 1372 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1373 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1374 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1375 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1376 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1377 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1378 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1379 | 1379 | |
| 1380 | 1380 | # spip_log("Requete\n$req", 'distant'); |
| 1381 | - fputs($f, $req); |
|
| 1382 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 1381 | + fputs($f, $req); |
|
| 1382 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 1383 | 1383 | |
| 1384 | - return $f; |
|
| 1384 | + return $f; |
|
| 1385 | 1385 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | 32 | define('_INC_DISTANT_MAX_SIZE', 2097152); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 38 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 39 | 39 | preg_replace( |
| 40 | 40 | '@^https?:@', |
| 41 | 41 | 'https?:', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // si c'est la protection de soi-meme, retourner le path |
| 72 | 72 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 74 | 74 | |
| 75 | 75 | return @file_exists($source) ? $source : false; |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 93 | + $localrac = _DIR_RACINE.$local; |
|
| 94 | 94 | $t = ($mode == 'force') ? false : @file_exists($localrac); |
| 95 | 95 | |
| 96 | 96 | // test d'existence du fichier |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
| 116 | 116 | ); |
| 117 | 117 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE); |
|
| 119 | 119 | } |
| 120 | 120 | if (!$res['length']) { |
| 121 | 121 | // si $t c'est sans doute juste un not-modified-since |
| 122 | 122 | return $t ? $local : false; |
| 123 | 123 | } |
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant'); |
|
| 125 | 125 | |
| 126 | 126 | // si on retrouve l'extension |
| 127 | 127 | if ( |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | $parts = array_map('intval', explode('.', $ip)); |
| 219 | 219 | if ( |
| 220 | 220 | 127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
| 221 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 222 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 221 | + or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1]) |
|
| 222 | + or (192 === $parts[0] && 168 === $parts[1]) |
|
| 223 | 223 | ) { |
| 224 | 224 | return false; |
| 225 | 225 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | $port = $parsed_url['port']; |
| 234 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 234 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 235 | 235 | return $url; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | if ($taille > 500) { |
| 304 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 304 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
@@ -329,16 +329,16 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | } else { |
| 331 | 331 | // fabrique une chaine HTTP simple pour un POST |
| 332 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 332 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 333 | 333 | $chaine = []; |
| 334 | 334 | if (is_array($donnees)) { |
| 335 | 335 | foreach ($donnees as $cle => $valeur) { |
| 336 | 336 | if (is_array($valeur)) { |
| 337 | 337 | foreach ($valeur as $val2) { |
| 338 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 338 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 339 | 339 | } |
| 340 | 340 | } else { |
| 341 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 341 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | $chaine = implode('&', $chaine); |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | $url_idn = implode($host_ascii, $url_idn); |
| 373 | 373 | } |
| 374 | 374 | // et on urlencode les char utf si besoin dans le path |
| 375 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 375 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { |
|
| 376 | 376 | return urlencode($match[0]); |
| 377 | 377 | }, $url_idn); |
| 378 | 378 | } |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $head_add = ''; |
| 451 | 451 | if (!empty($options['headers'])) { |
| 452 | 452 | foreach ($options['headers'] as $champ => $valeur) { |
| 453 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 453 | + $head_add .= $champ.': '.$valeur."\r\n"; |
|
| 454 | 454 | } |
| 455 | 455 | // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
| 456 | 456 | unset($options['headers']); |
@@ -460,9 +460,9 @@ discard block |
||
| 460 | 460 | list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
| 461 | 461 | $head .= $head_add; |
| 462 | 462 | if (stripos($head, 'Content-Length:') === false) { |
| 463 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 463 | + $head .= 'Content-Length: '.strlen($postdata)."\r\n"; |
|
| 464 | 464 | } |
| 465 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 465 | + $options['datas'] = $head."\r\n".$postdata; |
|
| 466 | 466 | if ( |
| 467 | 467 | strlen($postdata) |
| 468 | 468 | and !$methode_demandee |
@@ -470,15 +470,15 @@ discard block |
||
| 470 | 470 | $options['methode'] = 'POST'; |
| 471 | 471 | } |
| 472 | 472 | } elseif ($head_add) { |
| 473 | - $options['datas'] = $head_add . "\r\n"; |
|
| 473 | + $options['datas'] = $head_add."\r\n"; |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 477 | 477 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 478 | 478 | if (!tester_url_absolue($url)) { |
| 479 | - $url = 'http://' . $url; |
|
| 479 | + $url = 'http://'.$url; |
|
| 480 | 480 | } elseif (strncmp($url, '//', 2) == 0) { |
| 481 | - $url = 'http:' . $url; |
|
| 481 | + $url = 'http:'.$url; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | $url = url_to_ascii($url); |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | $options['if_modified_since'] |
| 508 | 508 | ); |
| 509 | 509 | if (!$handle) { |
| 510 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 510 | + spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR); |
|
| 511 | 511 | |
| 512 | 512 | return false; |
| 513 | 513 | } |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | 'status' => 200, |
| 538 | 538 | ]; |
| 539 | 539 | } else { |
| 540 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 540 | + spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR); |
|
| 541 | 541 | return false; |
| 542 | 542 | } |
| 543 | 543 | } elseif ($res['location'] and $options['follow_location']) { |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | |
| 550 | 550 | return recuperer_url($url, $options); |
| 551 | 551 | } elseif ($res['status'] !== 200) { |
| 552 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 552 | + spip_log('HTTP status '.$res['status']." pour $url", 'distant'); |
|
| 553 | 553 | } |
| 554 | 554 | $result['status'] = $res['status']; |
| 555 | 555 | if (isset($res['headers'])) { |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | |
| 575 | 575 | $gz = false; |
| 576 | 576 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 577 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 577 | + $gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz'); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | $sig['url'] = $url; |
| 661 | 661 | |
| 662 | 662 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 663 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 663 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 664 | 664 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 665 | 665 | $cache = "$sub$cache"; |
| 666 | 666 | |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | $fp = false; |
| 714 | 714 | if ($fichier) { |
| 715 | 715 | include_spip('inc/acces'); |
| 716 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 716 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 717 | 717 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 718 | 718 | if (!$fp and file_exists($fichier)) { |
| 719 | 719 | return filesize($fichier); |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | } |
| 773 | 773 | $result['status'] = intval($r[1]); |
| 774 | 774 | while ($s = trim(fgets($handle, 16384))) { |
| 775 | - $result['headers'][] = $s . "\n"; |
|
| 775 | + $result['headers'][] = $s."\n"; |
|
| 776 | 776 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 777 | 777 | list(, $d, $v) = $r; |
| 778 | 778 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -821,13 +821,13 @@ discard block |
||
| 821 | 821 | |
| 822 | 822 | // on se place tout le temps comme si on etait a la racine |
| 823 | 823 | if (_DIR_RACINE) { |
| 824 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 824 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | $m = md5($source); |
| 828 | 828 | |
| 829 | 829 | return $d |
| 830 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 830 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 831 | 831 | . substr($m, 0, 4) |
| 832 | 832 | . ".$extension"; |
| 833 | 833 | } |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | // Si c'est deja local pas de souci |
| 851 | 851 | if (!tester_url_absolue($source)) { |
| 852 | 852 | if (_DIR_RACINE) { |
| 853 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 853 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | return $source; |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | $ext |
| 869 | 869 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 870 | 870 | and $f = nom_fichier_copie_locale($source, $ext) |
| 871 | - and file_exists(_DIR_RACINE . $f) |
|
| 871 | + and file_exists(_DIR_RACINE.$f) |
|
| 872 | 872 | ) { |
| 873 | 873 | return $f; |
| 874 | 874 | } |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | |
| 877 | 877 | // Si c'est deja dans la table des documents, |
| 878 | 878 | // ramener le nom de sa copie potentielle |
| 879 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 879 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 880 | 880 | |
| 881 | 881 | if ($ext) { |
| 882 | 882 | return nom_fichier_copie_locale($source, $ext); |
@@ -887,9 +887,9 @@ discard block |
||
| 887 | 887 | |
| 888 | 888 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 889 | 889 | |
| 890 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 890 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 891 | 891 | $f = nom_fichier_copie_locale($source, $ext); |
| 892 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 892 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 893 | 893 | return $f; |
| 894 | 894 | } |
| 895 | 895 | } |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | // Ping pour voir si son extension est connue et autorisee |
| 898 | 898 | // avec mise en cache du resultat du ping |
| 899 | 899 | |
| 900 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 900 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 901 | 901 | if ( |
| 902 | 902 | !@file_exists($cache) |
| 903 | 903 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
@@ -907,10 +907,10 @@ discard block |
||
| 907 | 907 | ecrire_fichier($cache, serialize($path_parts)); |
| 908 | 908 | } |
| 909 | 909 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 910 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 910 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 911 | 911 | return nom_fichier_copie_locale($source, $ext); |
| 912 | 912 | } |
| 913 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 913 | + spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR); |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | } else { |
| 995 | 995 | if ($a['body']) { |
| 996 | 996 | $a['extension'] = $extension; |
| 997 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 997 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension); |
|
| 998 | 998 | ecrire_fichier($a['fichier'], $a['body']); |
| 999 | 999 | $size_image = @spip_getimagesize($a['fichier']); |
| 1000 | 1000 | $a['largeur'] = intval($size_image[0]); |
@@ -1059,20 +1059,20 @@ discard block |
||
| 1059 | 1059 | !$t |
| 1060 | 1060 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1061 | 1061 | ) { |
| 1062 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1062 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | if ( |
| 1065 | 1065 | !$t |
| 1066 | 1066 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 1067 | 1067 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 1068 | 1068 | ) { |
| 1069 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1069 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 1074 | 1074 | if (!$t) { |
| 1075 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1075 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -1083,11 +1083,11 @@ discard block |
||
| 1083 | 1083 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1084 | 1084 | ) { |
| 1085 | 1085 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 1086 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1086 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | if ($t) { |
| 1090 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1090 | + spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant'); |
|
| 1091 | 1091 | return $t['extension']; |
| 1092 | 1092 | } else { |
| 1093 | 1093 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | } |
| 1191 | 1191 | } else { |
| 1192 | 1192 | $scheme = $t['scheme']; |
| 1193 | - $noproxy = $scheme . '://'; |
|
| 1193 | + $noproxy = $scheme.'://'; |
|
| 1194 | 1194 | } |
| 1195 | 1195 | if (isset($t['user'])) { |
| 1196 | 1196 | $user = [$t['user'], $t['pass']]; |
@@ -1204,7 +1204,7 @@ discard block |
||
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | if (!empty($t['query'])) { |
| 1207 | - $path .= '?' . $t['query']; |
|
| 1207 | + $path .= '?'.$t['query']; |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1278,20 +1278,20 @@ discard block |
||
| 1278 | 1278 | $proxy_user = ''; |
| 1279 | 1279 | $http_proxy = need_proxy($host); |
| 1280 | 1280 | if ($user) { |
| 1281 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1281 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | $connect = ''; |
| 1285 | 1285 | if ($http_proxy) { |
| 1286 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1287 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1288 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1286 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) { |
|
| 1287 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1288 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1289 | 1289 | . "Host: $path_host\r\n" |
| 1290 | 1290 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1291 | 1291 | } else { |
| 1292 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1292 | + $path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://") |
|
| 1293 | 1293 | . (!$user ? '' : "$user@") |
| 1294 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1294 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1295 | 1295 | } |
| 1296 | 1296 | $t2 = @parse_url($http_proxy); |
| 1297 | 1297 | $first_host = $t2['host']; |
@@ -1299,10 +1299,10 @@ discard block |
||
| 1299 | 1299 | $port = 80; |
| 1300 | 1300 | } |
| 1301 | 1301 | if ($t2['user']) { |
| 1302 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1302 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | } else { |
| 1305 | - $first_host = $noproxy . $host; |
|
| 1305 | + $first_host = $noproxy.$host; |
|
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | if ($connect) { |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | ); |
| 1325 | 1325 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
| 1326 | 1326 | if (!$f) { |
| 1327 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1327 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1328 | 1328 | return $errno; |
| 1329 | 1329 | } |
| 1330 | 1330 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -1337,7 +1337,7 @@ discard block |
||
| 1337 | 1337 | or !count($res = explode(' ', $res)) |
| 1338 | 1338 | or $res[1] !== '200' |
| 1339 | 1339 | ) { |
| 1340 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1340 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1341 | 1341 | fclose($f); |
| 1342 | 1342 | |
| 1343 | 1343 | return false; |
@@ -1354,7 +1354,7 @@ discard block |
||
| 1354 | 1354 | } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
| 1355 | 1355 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 1356 | 1356 | if (!$f) { |
| 1357 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1357 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1358 | 1358 | |
| 1359 | 1359 | return $errno; |
| 1360 | 1360 | } |
@@ -1364,16 +1364,16 @@ discard block |
||
| 1364 | 1364 | $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
| 1365 | 1365 | |
| 1366 | 1366 | $host_port = $host; |
| 1367 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1367 | + if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) { |
|
| 1368 | 1368 | $host_port .= ":$port"; |
| 1369 | 1369 | } |
| 1370 | 1370 | $req = "$method $path $vers\r\n" |
| 1371 | 1371 | . "Host: $host_port\r\n" |
| 1372 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1373 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1372 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1373 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1374 | 1374 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1375 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1376 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1375 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1376 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1377 | 1377 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1378 | 1378 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1379 | 1379 | |
@@ -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 | /** |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | function set_spip_doc($fichier) { |
| 33 | - if (strpos($fichier, _DIR_IMG) === 0) { |
|
| 34 | - return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | - } else { |
|
| 36 | - return $fichier; |
|
| 37 | - } // ex: fichier distant |
|
| 33 | + if (strpos($fichier, _DIR_IMG) === 0) { |
|
| 34 | + return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | + } else { |
|
| 36 | + return $fichier; |
|
| 37 | + } // ex: fichier distant |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * @return bool|string |
| 47 | 47 | */ |
| 48 | 48 | function get_spip_doc($fichier) { |
| 49 | - // fichier distant |
|
| 50 | - if (tester_url_absolue($fichier)) { |
|
| 51 | - return $fichier; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // gestion d'erreurs, fichier='' |
|
| 55 | - if (!strlen($fichier)) { |
|
| 56 | - return false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $fichier = ( |
|
| 60 | - strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0 |
|
| 61 | - ) |
|
| 62 | - ? _DIR_IMG . $fichier |
|
| 63 | - : $fichier; |
|
| 64 | - |
|
| 65 | - // fichier normal |
|
| 66 | - return $fichier; |
|
| 49 | + // fichier distant |
|
| 50 | + if (tester_url_absolue($fichier)) { |
|
| 51 | + return $fichier; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // gestion d'erreurs, fichier='' |
|
| 55 | + if (!strlen($fichier)) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $fichier = ( |
|
| 60 | + strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0 |
|
| 61 | + ) |
|
| 62 | + ? _DIR_IMG . $fichier |
|
| 63 | + : $fichier; |
|
| 64 | + |
|
| 65 | + // fichier normal |
|
| 66 | + return $fichier; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -77,26 +77,26 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | 79 | function creer_repertoire_documents($ext) { |
| 80 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 81 | - |
|
| 82 | - if (!$ext or !$rep) { |
|
| 83 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 84 | - exit; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 88 | - // par exemple acces_restreint |
|
| 89 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 90 | - if ( |
|
| 91 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 92 | - and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 93 | - and $ext !== 'logo' |
|
| 94 | - ) { |
|
| 95 | - include_spip('inc/acces'); |
|
| 96 | - verifier_htaccess($rep); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $rep; |
|
| 80 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 81 | + |
|
| 82 | + if (!$ext or !$rep) { |
|
| 83 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 84 | + exit; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 88 | + // par exemple acces_restreint |
|
| 89 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 90 | + if ( |
|
| 91 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 92 | + and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 93 | + and $ext !== 'logo' |
|
| 94 | + ) { |
|
| 95 | + include_spip('inc/acces'); |
|
| 96 | + verifier_htaccess($rep); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $rep; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,22 +105,22 @@ discard block |
||
| 105 | 105 | * @param string $nom |
| 106 | 106 | */ |
| 107 | 107 | function effacer_repertoire_temporaire($nom) { |
| 108 | - if ($d = opendir($nom)) { |
|
| 109 | - while (($f = readdir($d)) !== false) { |
|
| 110 | - if (is_file("$nom/$f")) { |
|
| 111 | - spip_unlink("$nom/$f"); |
|
| 112 | - } else { |
|
| 113 | - if ( |
|
| 114 | - $f <> '.' and $f <> '..' |
|
| 115 | - and is_dir("$nom/$f") |
|
| 116 | - ) { |
|
| 117 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - closedir($d); |
|
| 123 | - @rmdir($nom); |
|
| 108 | + if ($d = opendir($nom)) { |
|
| 109 | + while (($f = readdir($d)) !== false) { |
|
| 110 | + if (is_file("$nom/$f")) { |
|
| 111 | + spip_unlink("$nom/$f"); |
|
| 112 | + } else { |
|
| 113 | + if ( |
|
| 114 | + $f <> '.' and $f <> '..' |
|
| 115 | + and is_dir("$nom/$f") |
|
| 116 | + ) { |
|
| 117 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + closedir($d); |
|
| 123 | + @rmdir($nom); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // |
@@ -137,45 +137,45 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 139 | 139 | |
| 140 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 141 | - $dir = creer_repertoire_documents($subdir ? $subdir : $ext); |
|
| 142 | - |
|
| 143 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 144 | - $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 145 | - $dest = translitteration($dest); |
|
| 146 | - $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 147 | - |
|
| 148 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 149 | - // pour les images transformees par rotation (action/documenter) |
|
| 150 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 151 | - |
|
| 152 | - while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 153 | - if ( |
|
| 154 | - !function_exists('verifier_upload_autorise') |
|
| 155 | - or !$r = verifier_upload_autorise($dest) |
|
| 156 | - or $r['autozip'] |
|
| 157 | - ) { |
|
| 158 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 159 | - break; |
|
| 160 | - } |
|
| 161 | - else { |
|
| 162 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 163 | - $ext = $m[1] . '.' . $ext; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 168 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 169 | - return $source; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 173 | - $n = 0; |
|
| 174 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 175 | - ; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return deplacer_fichier_upload($source, $newFile); |
|
| 140 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 141 | + $dir = creer_repertoire_documents($subdir ? $subdir : $ext); |
|
| 142 | + |
|
| 143 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 144 | + $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 145 | + $dest = translitteration($dest); |
|
| 146 | + $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 147 | + |
|
| 148 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 149 | + // pour les images transformees par rotation (action/documenter) |
|
| 150 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 151 | + |
|
| 152 | + while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 153 | + if ( |
|
| 154 | + !function_exists('verifier_upload_autorise') |
|
| 155 | + or !$r = verifier_upload_autorise($dest) |
|
| 156 | + or $r['autozip'] |
|
| 157 | + ) { |
|
| 158 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 159 | + break; |
|
| 160 | + } |
|
| 161 | + else { |
|
| 162 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 163 | + $ext = $m[1] . '.' . $ext; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 168 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 169 | + return $source; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 173 | + $n = 0; |
|
| 174 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 175 | + ; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return deplacer_fichier_upload($source, $newFile); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -190,28 +190,28 @@ discard block |
||
| 190 | 190 | * @return bool|string |
| 191 | 191 | */ |
| 192 | 192 | function determine_upload($type = '') { |
| 193 | - if (!function_exists('autoriser')) { |
|
| 194 | - include_spip('inc/autoriser'); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if ( |
|
| 198 | - !autoriser('chargerftp') |
|
| 199 | - or $type == 'logos' |
|
| 200 | - ) { # on ne le permet pas pour les logos |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $repertoire = _DIR_TRANSFERT; |
|
| 205 | - if (!@is_dir($repertoire)) { |
|
| 206 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 207 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 211 | - return $repertoire; |
|
| 212 | - } else { |
|
| 213 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 214 | - } |
|
| 193 | + if (!function_exists('autoriser')) { |
|
| 194 | + include_spip('inc/autoriser'); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if ( |
|
| 198 | + !autoriser('chargerftp') |
|
| 199 | + or $type == 'logos' |
|
| 200 | + ) { # on ne le permet pas pour les logos |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $repertoire = _DIR_TRANSFERT; |
|
| 205 | + if (!@is_dir($repertoire)) { |
|
| 206 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 207 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 211 | + return $repertoire; |
|
| 212 | + } else { |
|
| 213 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 214 | + } |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -230,35 +230,35 @@ discard block |
||
| 230 | 230 | * @return bool|mixed|string |
| 231 | 231 | */ |
| 232 | 232 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 233 | - // Securite |
|
| 234 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 235 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 236 | - } else { |
|
| 237 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - if ($move) { |
|
| 241 | - $ok = @rename($source, $dest); |
|
| 242 | - } else { |
|
| 243 | - $ok = @copy($source, $dest); |
|
| 244 | - } |
|
| 245 | - if (!$ok) { |
|
| 246 | - $ok = @move_uploaded_file($source, $dest); |
|
| 247 | - } |
|
| 248 | - if ($ok) { |
|
| 249 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 250 | - } else { |
|
| 251 | - $f = @fopen($dest, 'w'); |
|
| 252 | - if ($f) { |
|
| 253 | - fclose($f); |
|
| 254 | - } else { |
|
| 255 | - include_spip('inc/flock'); |
|
| 256 | - raler_fichier($dest); |
|
| 257 | - } |
|
| 258 | - spip_unlink($dest); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - return $ok ? $dest : false; |
|
| 233 | + // Securite |
|
| 234 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 235 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 236 | + } else { |
|
| 237 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + if ($move) { |
|
| 241 | + $ok = @rename($source, $dest); |
|
| 242 | + } else { |
|
| 243 | + $ok = @copy($source, $dest); |
|
| 244 | + } |
|
| 245 | + if (!$ok) { |
|
| 246 | + $ok = @move_uploaded_file($source, $dest); |
|
| 247 | + } |
|
| 248 | + if ($ok) { |
|
| 249 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 250 | + } else { |
|
| 251 | + $f = @fopen($dest, 'w'); |
|
| 252 | + if ($f) { |
|
| 253 | + fclose($f); |
|
| 254 | + } else { |
|
| 255 | + include_spip('inc/flock'); |
|
| 256 | + raler_fichier($dest); |
|
| 257 | + } |
|
| 258 | + spip_unlink($dest); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + return $ok ? $dest : false; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | |
@@ -282,58 +282,58 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function check_upload_error($error, $msg = '', $return = false) { |
| 284 | 284 | |
| 285 | - if (!$error) { |
|
| 286 | - return false; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 290 | - |
|
| 291 | - switch ($error) { |
|
| 292 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 293 | - return true; |
|
| 294 | - |
|
| 295 | - # on peut affiner les differents messages d'erreur |
|
| 296 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 297 | - $msg = _T( |
|
| 298 | - 'upload_limit', |
|
| 299 | - ['max' => ini_get('upload_max_filesize')] |
|
| 300 | - ); |
|
| 301 | - break; |
|
| 302 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 303 | - $msg = _T( |
|
| 304 | - 'upload_limit', |
|
| 305 | - ['max' => ini_get('upload_max_filesize')] |
|
| 306 | - ); |
|
| 307 | - break; |
|
| 308 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 309 | - $msg = _T( |
|
| 310 | - 'upload_limit', |
|
| 311 | - ['max' => ini_get('upload_max_filesize')] |
|
| 312 | - ); |
|
| 313 | - break; |
|
| 314 | - |
|
| 315 | - default: /* autre */ |
|
| 316 | - if (!$msg) { |
|
| 317 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 318 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 319 | - } |
|
| 320 | - break; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - spip_log("erreur upload $error"); |
|
| 324 | - if ($return) { |
|
| 325 | - return $msg; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - if (_request('iframe') == 'iframe') { |
|
| 329 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 330 | - exit; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - include_spip('inc/minipres'); |
|
| 334 | - echo minipres( |
|
| 335 | - $msg, |
|
| 336 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 337 | - ); |
|
| 338 | - exit; |
|
| 285 | + if (!$error) { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 290 | + |
|
| 291 | + switch ($error) { |
|
| 292 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 293 | + return true; |
|
| 294 | + |
|
| 295 | + # on peut affiner les differents messages d'erreur |
|
| 296 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 297 | + $msg = _T( |
|
| 298 | + 'upload_limit', |
|
| 299 | + ['max' => ini_get('upload_max_filesize')] |
|
| 300 | + ); |
|
| 301 | + break; |
|
| 302 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 303 | + $msg = _T( |
|
| 304 | + 'upload_limit', |
|
| 305 | + ['max' => ini_get('upload_max_filesize')] |
|
| 306 | + ); |
|
| 307 | + break; |
|
| 308 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 309 | + $msg = _T( |
|
| 310 | + 'upload_limit', |
|
| 311 | + ['max' => ini_get('upload_max_filesize')] |
|
| 312 | + ); |
|
| 313 | + break; |
|
| 314 | + |
|
| 315 | + default: /* autre */ |
|
| 316 | + if (!$msg) { |
|
| 317 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 318 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 319 | + } |
|
| 320 | + break; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + spip_log("erreur upload $error"); |
|
| 324 | + if ($return) { |
|
| 325 | + return $msg; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + if (_request('iframe') == 'iframe') { |
|
| 329 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 330 | + exit; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + include_spip('inc/minipres'); |
|
| 334 | + echo minipres( |
|
| 335 | + $msg, |
|
| 336 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 337 | + ); |
|
| 338 | + exit; |
|
| 339 | 339 | } |
@@ -155,23 +155,23 @@ discard block |
||
| 155 | 155 | or !$r = verifier_upload_autorise($dest) |
| 156 | 156 | or $r['autozip'] |
| 157 | 157 | ) { |
| 158 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 158 | + $dest = substr($dest, 0, -strlen($m[0])).'_'.$m[1]; |
|
| 159 | 159 | break; |
| 160 | 160 | } |
| 161 | 161 | else { |
| 162 | 162 | $dest = substr($dest, 0, -strlen($m[0])); |
| 163 | - $ext = $m[1] . '.' . $ext; |
|
| 163 | + $ext = $m[1].'.'.$ext; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Si le document "source" est deja au bon endroit, ne rien faire |
| 168 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 168 | + if ($source == ($dir.$dest.'.'.$ext)) { |
|
| 169 | 169 | return $source; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // sinon tourner jusqu'a trouver un numero correct |
| 173 | 173 | $n = 0; |
| 174 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 174 | + while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) { |
|
| 175 | 175 | ; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 233 | 233 | // Securite |
| 234 | 234 | if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
| 235 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 235 | + $dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 236 | 236 | } else { |
| 237 | 237 | $dest = preg_replace(',\.\.+,', '.', $dest); |
| 238 | 238 | } |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | default: /* autre */ |
| 316 | 316 | if (!$msg) { |
| 317 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 318 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 317 | + $msg = _T('pass_erreur').' '.$error |
|
| 318 | + . '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 319 | 319 | } |
| 320 | 320 | break; |
| 321 | 321 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | include_spip('inc/minipres'); |
| 334 | 334 | echo minipres( |
| 335 | 335 | $msg, |
| 336 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 336 | + "<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode($GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>' |
|
| 337 | 337 | ); |
| 338 | 338 | exit; |
| 339 | 339 | } |
@@ -157,8 +157,7 @@ |
||
| 157 | 157 | ) { |
| 158 | 158 | $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
| 159 | 159 | break; |
| 160 | - } |
|
| 161 | - else { |
|
| 160 | + } else { |
|
| 162 | 161 | $dest = substr($dest, 0, -strlen($m[0])); |
| 163 | 162 | $ext = $m[1] . '.' . $ext; |
| 164 | 163 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - // fonction ou name\space\fonction |
|
| 102 | - if (is_callable($f)) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | - elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | - return $f; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + // fonction ou name\space\fonction |
|
| 102 | + if (is_callable($f)) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | + elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | + return $f; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $default; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Chaîne vide sinon. |
| 153 | 153 | **/ |
| 154 | 154 | function appliquer_filtre($arg, $filtre) { |
| 155 | - $args = func_get_args(); |
|
| 156 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 155 | + $args = func_get_args(); |
|
| 156 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * Texte d'origine sinon |
| 179 | 179 | **/ |
| 180 | 180 | function appliquer_si_filtre($arg, $filtre) { |
| 181 | - $args = func_get_args(); |
|
| 182 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 181 | + $args = func_get_args(); |
|
| 182 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * Version de SPIP |
| 196 | 196 | **/ |
| 197 | 197 | function spip_version() { |
| 198 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | - $version .= " $vcs_version"; |
|
| 201 | - } |
|
| 198 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | + $version .= " $vcs_version"; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $version; |
|
| 203 | + return $version; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | * - string|null si $raw = false |
| 214 | 214 | */ |
| 215 | 215 | function version_vcs_courante($dir, $raw = false) { |
| 216 | - $desc = decrire_version_git($dir); |
|
| 217 | - if ($desc === null) { |
|
| 218 | - $desc = decrire_version_svn($dir); |
|
| 219 | - } |
|
| 220 | - if ($desc === null or $raw) { |
|
| 221 | - return $desc; |
|
| 222 | - } |
|
| 223 | - // affichage "GIT [master: abcdef]" |
|
| 224 | - $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
|
| 225 | - if ($desc['branch']) { |
|
| 226 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 227 | - } |
|
| 228 | - return "{$desc['vcs']} [$commit]"; |
|
| 216 | + $desc = decrire_version_git($dir); |
|
| 217 | + if ($desc === null) { |
|
| 218 | + $desc = decrire_version_svn($dir); |
|
| 219 | + } |
|
| 220 | + if ($desc === null or $raw) { |
|
| 221 | + return $desc; |
|
| 222 | + } |
|
| 223 | + // affichage "GIT [master: abcdef]" |
|
| 224 | + $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
|
| 225 | + if ($desc['branch']) { |
|
| 226 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 227 | + } |
|
| 228 | + return "{$desc['vcs']} [$commit]"; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -237,24 +237,24 @@ discard block |
||
| 237 | 237 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 238 | 238 | **/ |
| 239 | 239 | function decrire_version_git($dir) { |
| 240 | - if (!$dir) { |
|
| 241 | - $dir = '.'; |
|
| 242 | - } |
|
| 240 | + if (!$dir) { |
|
| 241 | + $dir = '.'; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - // version installee par GIT |
|
| 245 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 246 | - $currentHead = trim(substr($c, 4)); |
|
| 247 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 248 | - return [ |
|
| 249 | - 'vcs' => 'GIT', |
|
| 250 | - 'branch' => basename($currentHead), |
|
| 251 | - 'commit' => trim($hash), |
|
| 252 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 253 | - ]; |
|
| 254 | - } |
|
| 255 | - } |
|
| 244 | + // version installee par GIT |
|
| 245 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 246 | + $currentHead = trim(substr($c, 4)); |
|
| 247 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 248 | + return [ |
|
| 249 | + 'vcs' => 'GIT', |
|
| 250 | + 'branch' => basename($currentHead), |
|
| 251 | + 'commit' => trim($hash), |
|
| 252 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 253 | + ]; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - return null; |
|
| 257 | + return null; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -267,25 +267,25 @@ discard block |
||
| 267 | 267 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 268 | 268 | **/ |
| 269 | 269 | function decrire_version_svn($dir) { |
| 270 | - if (!$dir) { |
|
| 271 | - $dir = '.'; |
|
| 272 | - } |
|
| 273 | - // version installee par SVN |
|
| 274 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 275 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 276 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 277 | - if ($result) { |
|
| 278 | - $row = $result->fetchArray(); |
|
| 279 | - if ($row['changed_revision'] != '') { |
|
| 280 | - return [ |
|
| 281 | - 'vcs' => 'SVN', |
|
| 282 | - 'branch' => '', |
|
| 283 | - 'commit' => $row['changed_revision'], |
|
| 284 | - ]; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - return null; |
|
| 270 | + if (!$dir) { |
|
| 271 | + $dir = '.'; |
|
| 272 | + } |
|
| 273 | + // version installee par SVN |
|
| 274 | + if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 275 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 276 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 277 | + if ($result) { |
|
| 278 | + $row = $result->fetchArray(); |
|
| 279 | + if ($row['changed_revision'] != '') { |
|
| 280 | + return [ |
|
| 281 | + 'vcs' => 'SVN', |
|
| 282 | + 'branch' => '', |
|
| 283 | + 'commit' => $row['changed_revision'], |
|
| 284 | + ]; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + return null; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -332,18 +332,18 @@ discard block |
||
| 332 | 332 | * Code HTML retourné par le filtre |
| 333 | 333 | **/ |
| 334 | 334 | function filtrer($filtre) { |
| 335 | - $tous = func_get_args(); |
|
| 336 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 337 | - return image_filtrer($tous); |
|
| 338 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 339 | - array_shift($tous); |
|
| 340 | - return call_user_func_array($f, $tous); |
|
| 341 | - } else { |
|
| 342 | - // le filtre n'existe pas, on provoque une erreur |
|
| 343 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 344 | - erreur_squelette($msg); |
|
| 345 | - return ''; |
|
| 346 | - } |
|
| 335 | + $tous = func_get_args(); |
|
| 336 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 337 | + return image_filtrer($tous); |
|
| 338 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 339 | + array_shift($tous); |
|
| 340 | + return call_user_func_array($f, $tous); |
|
| 341 | + } else { |
|
| 342 | + // le filtre n'existe pas, on provoque une erreur |
|
| 343 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 344 | + erreur_squelette($msg); |
|
| 345 | + return ''; |
|
| 346 | + } |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -360,11 +360,11 @@ discard block |
||
| 360 | 360 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 361 | 361 | */ |
| 362 | 362 | function trouver_filtre_matrice($filtre) { |
| 363 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 364 | - find_in_path($f, '', true); |
|
| 365 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 366 | - } |
|
| 367 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 363 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 364 | + find_in_path($f, '', true); |
|
| 365 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 366 | + } |
|
| 367 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
@@ -392,8 +392,8 @@ discard block |
||
| 392 | 392 | * @return mixed |
| 393 | 393 | */ |
| 394 | 394 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 395 | - $Pile['vars'][$key] = $val; |
|
| 396 | - return $continue ? $val : ''; |
|
| 395 | + $Pile['vars'][$key] = $val; |
|
| 396 | + return $continue ? $val : ''; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 420 | 420 | */ |
| 421 | 421 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 422 | - $Pile[0][$key] = $val; |
|
| 423 | - return $continue ? $val : ''; |
|
| 422 | + $Pile[0][$key] = $val; |
|
| 423 | + return $continue ? $val : ''; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * @return string |
| 430 | 430 | */ |
| 431 | 431 | function filtre_sanitize_env(&$Pile, $keys) { |
| 432 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 433 | - return ''; |
|
| 432 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 433 | + return ''; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | |
@@ -453,18 +453,18 @@ discard block |
||
| 453 | 453 | * @return mixed Retourne la valeur (sans la modifier). |
| 454 | 454 | */ |
| 455 | 455 | function filtre_debug($val, $key = null) { |
| 456 | - $debug = ( |
|
| 457 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 458 | - ) . var_export($val, true); |
|
| 456 | + $debug = ( |
|
| 457 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 458 | + ) . var_export($val, true); |
|
| 459 | 459 | |
| 460 | - include_spip('inc/autoriser'); |
|
| 461 | - if (autoriser('webmestre')) { |
|
| 462 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 463 | - } |
|
| 460 | + include_spip('inc/autoriser'); |
|
| 461 | + if (autoriser('webmestre')) { |
|
| 462 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - spip_log($debug, 'debug'); |
|
| 465 | + spip_log($debug, 'debug'); |
|
| 466 | 466 | |
| 467 | - return $val; |
|
| 467 | + return $val; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | |
@@ -492,89 +492,89 @@ discard block |
||
| 492 | 492 | * Texte qui a reçu les filtres |
| 493 | 493 | **/ |
| 494 | 494 | function image_filtrer($args) { |
| 495 | - $filtre = array_shift($args); # enlever $filtre |
|
| 496 | - $texte = array_shift($args); |
|
| 497 | - if (!strlen($texte)) { |
|
| 498 | - return; |
|
| 499 | - } |
|
| 500 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 501 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 502 | - // Cas du nom de fichier local |
|
| 503 | - $is_file = trim($texte); |
|
| 504 | - if ( |
|
| 505 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 506 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 507 | - or strpos($is_file, '/') === 0 |
|
| 508 | - ) { |
|
| 509 | - $is_file = false; |
|
| 510 | - } |
|
| 511 | - if ($is_file) { |
|
| 512 | - $is_local_file = function ($path) { |
|
| 513 | - if (strpos($path, '?') !== false) { |
|
| 514 | - $path = supprimer_timestamp($path); |
|
| 515 | - // remove ?24px added by find_in_theme on .svg files |
|
| 516 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 517 | - } |
|
| 518 | - return file_exists($path); |
|
| 519 | - }; |
|
| 520 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 521 | - array_unshift($args, "<img src='$is_file' />"); |
|
| 522 | - $res = call_user_func_array($filtre, $args); |
|
| 523 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 524 | - return $res; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 529 | - if ( |
|
| 530 | - preg_match_all( |
|
| 531 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 532 | - $texte, |
|
| 533 | - $tags, |
|
| 534 | - PREG_SET_ORDER |
|
| 535 | - ) |
|
| 536 | - ) { |
|
| 537 | - foreach ($tags as $tag) { |
|
| 538 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 539 | - if ( |
|
| 540 | - !$class or |
|
| 541 | - (strpos($class, 'filtre_inactif') === false |
|
| 542 | - // compat historique a virer en 3.2 |
|
| 543 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 544 | - ) { |
|
| 545 | - array_unshift($args, $tag[3]); |
|
| 546 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 547 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 548 | - if ($tag[1]) { |
|
| 549 | - $w = extraire_attribut($reduit, 'width'); |
|
| 550 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 551 | - $w = $regs[1]; |
|
| 552 | - } |
|
| 553 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 554 | - $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 555 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 556 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - // traiter aussi un eventuel mouseover |
|
| 560 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 561 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 562 | - $srcover = $match[1]; |
|
| 563 | - array_shift($args); |
|
| 564 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 565 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 566 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 567 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 571 | - } |
|
| 572 | - array_shift($args); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 577 | - return $texte; |
|
| 495 | + $filtre = array_shift($args); # enlever $filtre |
|
| 496 | + $texte = array_shift($args); |
|
| 497 | + if (!strlen($texte)) { |
|
| 498 | + return; |
|
| 499 | + } |
|
| 500 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 501 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 502 | + // Cas du nom de fichier local |
|
| 503 | + $is_file = trim($texte); |
|
| 504 | + if ( |
|
| 505 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 506 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 507 | + or strpos($is_file, '/') === 0 |
|
| 508 | + ) { |
|
| 509 | + $is_file = false; |
|
| 510 | + } |
|
| 511 | + if ($is_file) { |
|
| 512 | + $is_local_file = function ($path) { |
|
| 513 | + if (strpos($path, '?') !== false) { |
|
| 514 | + $path = supprimer_timestamp($path); |
|
| 515 | + // remove ?24px added by find_in_theme on .svg files |
|
| 516 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 517 | + } |
|
| 518 | + return file_exists($path); |
|
| 519 | + }; |
|
| 520 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 521 | + array_unshift($args, "<img src='$is_file' />"); |
|
| 522 | + $res = call_user_func_array($filtre, $args); |
|
| 523 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 524 | + return $res; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 529 | + if ( |
|
| 530 | + preg_match_all( |
|
| 531 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 532 | + $texte, |
|
| 533 | + $tags, |
|
| 534 | + PREG_SET_ORDER |
|
| 535 | + ) |
|
| 536 | + ) { |
|
| 537 | + foreach ($tags as $tag) { |
|
| 538 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 539 | + if ( |
|
| 540 | + !$class or |
|
| 541 | + (strpos($class, 'filtre_inactif') === false |
|
| 542 | + // compat historique a virer en 3.2 |
|
| 543 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 544 | + ) { |
|
| 545 | + array_unshift($args, $tag[3]); |
|
| 546 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 547 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 548 | + if ($tag[1]) { |
|
| 549 | + $w = extraire_attribut($reduit, 'width'); |
|
| 550 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 551 | + $w = $regs[1]; |
|
| 552 | + } |
|
| 553 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 554 | + $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 555 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 556 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + // traiter aussi un eventuel mouseover |
|
| 560 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 561 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 562 | + $srcover = $match[1]; |
|
| 563 | + array_shift($args); |
|
| 564 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 565 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 566 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 567 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 571 | + } |
|
| 572 | + array_shift($args); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 577 | + return $texte; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -589,78 +589,78 @@ discard block |
||
| 589 | 589 | **/ |
| 590 | 590 | function taille_image($img, $force_refresh = false) { |
| 591 | 591 | |
| 592 | - static $largeur_img = [], $hauteur_img = []; |
|
| 593 | - $srcWidth = 0; |
|
| 594 | - $srcHeight = 0; |
|
| 595 | - |
|
| 596 | - $src = extraire_attribut($img, 'src'); |
|
| 597 | - |
|
| 598 | - if (!$src) { |
|
| 599 | - $src = $img; |
|
| 600 | - } else { |
|
| 601 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 602 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 606 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 607 | - if (tester_url_absolue($src)) { |
|
| 608 | - include_spip('inc/distant'); |
|
| 609 | - $fichier = copie_locale($src); |
|
| 610 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 611 | - } |
|
| 612 | - if (($p = strpos($src, '?')) !== false) { |
|
| 613 | - $src = substr($src, 0, $p); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - $srcsize = false; |
|
| 617 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 618 | - $srcWidth = $largeur_img[$src]; |
|
| 619 | - } |
|
| 620 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 621 | - $srcHeight = $hauteur_img[$src]; |
|
| 622 | - } |
|
| 623 | - if (!$srcWidth or !$srcHeight) { |
|
| 624 | - if ( |
|
| 625 | - file_exists($src) |
|
| 626 | - and $srcsize = spip_getimagesize($src) |
|
| 627 | - ) { |
|
| 628 | - if (!$srcWidth) { |
|
| 629 | - $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 630 | - } |
|
| 631 | - if (!$srcHeight) { |
|
| 632 | - $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - elseif (strpos($src, '<svg') !== false) { |
|
| 636 | - include_spip('inc/svg'); |
|
| 637 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 638 | - list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 639 | - if (!$srcWidth) { |
|
| 640 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 641 | - } |
|
| 642 | - if (!$srcHeight) { |
|
| 643 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 648 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 649 | - elseif ( |
|
| 650 | - @file_exists($f = "$src.src") |
|
| 651 | - and lire_fichier($f, $valeurs) |
|
| 652 | - and $valeurs = unserialize($valeurs) |
|
| 653 | - ) { |
|
| 654 | - if (!$srcWidth) { |
|
| 655 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 656 | - } |
|
| 657 | - if (!$srcHeight) { |
|
| 658 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - return [$srcHeight, $srcWidth]; |
|
| 592 | + static $largeur_img = [], $hauteur_img = []; |
|
| 593 | + $srcWidth = 0; |
|
| 594 | + $srcHeight = 0; |
|
| 595 | + |
|
| 596 | + $src = extraire_attribut($img, 'src'); |
|
| 597 | + |
|
| 598 | + if (!$src) { |
|
| 599 | + $src = $img; |
|
| 600 | + } else { |
|
| 601 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 602 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 606 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 607 | + if (tester_url_absolue($src)) { |
|
| 608 | + include_spip('inc/distant'); |
|
| 609 | + $fichier = copie_locale($src); |
|
| 610 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 611 | + } |
|
| 612 | + if (($p = strpos($src, '?')) !== false) { |
|
| 613 | + $src = substr($src, 0, $p); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + $srcsize = false; |
|
| 617 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 618 | + $srcWidth = $largeur_img[$src]; |
|
| 619 | + } |
|
| 620 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 621 | + $srcHeight = $hauteur_img[$src]; |
|
| 622 | + } |
|
| 623 | + if (!$srcWidth or !$srcHeight) { |
|
| 624 | + if ( |
|
| 625 | + file_exists($src) |
|
| 626 | + and $srcsize = spip_getimagesize($src) |
|
| 627 | + ) { |
|
| 628 | + if (!$srcWidth) { |
|
| 629 | + $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 630 | + } |
|
| 631 | + if (!$srcHeight) { |
|
| 632 | + $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + elseif (strpos($src, '<svg') !== false) { |
|
| 636 | + include_spip('inc/svg'); |
|
| 637 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 638 | + list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 639 | + if (!$srcWidth) { |
|
| 640 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 641 | + } |
|
| 642 | + if (!$srcHeight) { |
|
| 643 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 648 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 649 | + elseif ( |
|
| 650 | + @file_exists($f = "$src.src") |
|
| 651 | + and lire_fichier($f, $valeurs) |
|
| 652 | + and $valeurs = unserialize($valeurs) |
|
| 653 | + ) { |
|
| 654 | + if (!$srcWidth) { |
|
| 655 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 656 | + } |
|
| 657 | + if (!$srcHeight) { |
|
| 658 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + return [$srcHeight, $srcWidth]; |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | |
@@ -678,12 +678,12 @@ discard block |
||
| 678 | 678 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 679 | 679 | **/ |
| 680 | 680 | function largeur($img) { |
| 681 | - if (!$img) { |
|
| 682 | - return; |
|
| 683 | - } |
|
| 684 | - list($h, $l) = taille_image($img); |
|
| 681 | + if (!$img) { |
|
| 682 | + return; |
|
| 683 | + } |
|
| 684 | + list($h, $l) = taille_image($img); |
|
| 685 | 685 | |
| 686 | - return $l; |
|
| 686 | + return $l; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -700,12 +700,12 @@ discard block |
||
| 700 | 700 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 701 | 701 | **/ |
| 702 | 702 | function hauteur($img) { |
| 703 | - if (!$img) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - list($h, $l) = taille_image($img); |
|
| 703 | + if (!$img) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + list($h, $l) = taille_image($img); |
|
| 707 | 707 | |
| 708 | - return $h; |
|
| 708 | + return $h; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | |
@@ -725,11 +725,11 @@ discard block |
||
| 725 | 725 | * @return string |
| 726 | 726 | **/ |
| 727 | 727 | function corriger_entites_html($texte) { |
| 728 | - if (strpos($texte, '&') === false) { |
|
| 729 | - return $texte; |
|
| 730 | - } |
|
| 728 | + if (strpos($texte, '&') === false) { |
|
| 729 | + return $texte; |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 732 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
@@ -744,11 +744,11 @@ discard block |
||
| 744 | 744 | * @return string |
| 745 | 745 | **/ |
| 746 | 746 | function corriger_toutes_entites_html($texte) { |
| 747 | - if (strpos($texte, '&') === false) { |
|
| 748 | - return $texte; |
|
| 749 | - } |
|
| 747 | + if (strpos($texte, '&') === false) { |
|
| 748 | + return $texte; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 751 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | * @return string |
| 759 | 759 | **/ |
| 760 | 760 | function proteger_amp($texte) { |
| 761 | - return str_replace('&', '&', $texte); |
|
| 761 | + return str_replace('&', '&', $texte); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -789,21 +789,21 @@ discard block |
||
| 789 | 789 | * @return mixed|string |
| 790 | 790 | */ |
| 791 | 791 | function entites_html($texte, $tout = false, $quote = true) { |
| 792 | - if ( |
|
| 793 | - !is_string($texte) or !$texte |
|
| 794 | - or strpbrk($texte, "&\"'<>") == false |
|
| 795 | - ) { |
|
| 796 | - return $texte; |
|
| 797 | - } |
|
| 798 | - include_spip('inc/texte'); |
|
| 799 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 800 | - $flags |= ENT_HTML401; |
|
| 801 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 802 | - if ($tout) { |
|
| 803 | - return corriger_toutes_entites_html($texte); |
|
| 804 | - } else { |
|
| 805 | - return corriger_entites_html($texte); |
|
| 806 | - } |
|
| 792 | + if ( |
|
| 793 | + !is_string($texte) or !$texte |
|
| 794 | + or strpbrk($texte, "&\"'<>") == false |
|
| 795 | + ) { |
|
| 796 | + return $texte; |
|
| 797 | + } |
|
| 798 | + include_spip('inc/texte'); |
|
| 799 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 800 | + $flags |= ENT_HTML401; |
|
| 801 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 802 | + if ($tout) { |
|
| 803 | + return corriger_toutes_entites_html($texte); |
|
| 804 | + } else { |
|
| 805 | + return corriger_entites_html($texte); |
|
| 806 | + } |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -822,37 +822,37 @@ discard block |
||
| 822 | 822 | * Texte converti |
| 823 | 823 | **/ |
| 824 | 824 | function filtrer_entites($texte) { |
| 825 | - if (strpos($texte, '&') === false) { |
|
| 826 | - return $texte; |
|
| 827 | - } |
|
| 828 | - // filtrer |
|
| 829 | - $texte = html2unicode($texte); |
|
| 830 | - // remettre le tout dans le charset cible |
|
| 831 | - $texte = unicode2charset($texte); |
|
| 832 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 833 | - // (on le faisait deja avec un ") |
|
| 834 | - if (strpos($texte, '&#') !== false) { |
|
| 835 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 836 | - } |
|
| 825 | + if (strpos($texte, '&') === false) { |
|
| 826 | + return $texte; |
|
| 827 | + } |
|
| 828 | + // filtrer |
|
| 829 | + $texte = html2unicode($texte); |
|
| 830 | + // remettre le tout dans le charset cible |
|
| 831 | + $texte = unicode2charset($texte); |
|
| 832 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 833 | + // (on le faisait deja avec un ") |
|
| 834 | + if (strpos($texte, '&#') !== false) { |
|
| 835 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | - return $texte; |
|
| 838 | + return $texte; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | |
| 842 | 842 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 843 | - /** |
|
| 844 | - * Version sécurisée de filtrer_entites |
|
| 845 | - * |
|
| 846 | - * @uses interdire_scripts() |
|
| 847 | - * @uses filtrer_entites() |
|
| 848 | - * |
|
| 849 | - * @param string $t |
|
| 850 | - * @return string |
|
| 851 | - */ |
|
| 852 | - function filtre_filtrer_entites_dist($t) { |
|
| 853 | - include_spip('inc/texte'); |
|
| 854 | - return interdire_scripts(filtrer_entites($t)); |
|
| 855 | - } |
|
| 843 | + /** |
|
| 844 | + * Version sécurisée de filtrer_entites |
|
| 845 | + * |
|
| 846 | + * @uses interdire_scripts() |
|
| 847 | + * @uses filtrer_entites() |
|
| 848 | + * |
|
| 849 | + * @param string $t |
|
| 850 | + * @return string |
|
| 851 | + */ |
|
| 852 | + function filtre_filtrer_entites_dist($t) { |
|
| 853 | + include_spip('inc/texte'); |
|
| 854 | + return interdire_scripts(filtrer_entites($t)); |
|
| 855 | + } |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | |
@@ -867,18 +867,18 @@ discard block |
||
| 867 | 867 | * @return string|array |
| 868 | 868 | **/ |
| 869 | 869 | function supprimer_caracteres_illegaux($texte) { |
| 870 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 871 | - static $to = null; |
|
| 870 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 871 | + static $to = null; |
|
| 872 | 872 | |
| 873 | - if (is_array($texte)) { |
|
| 874 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 875 | - } |
|
| 873 | + if (is_array($texte)) { |
|
| 874 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | - if (!$to) { |
|
| 878 | - $to = str_repeat('-', strlen($from)); |
|
| 879 | - } |
|
| 877 | + if (!$to) { |
|
| 878 | + $to = str_repeat('-', strlen($from)); |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - return strtr($texte, $from, $to); |
|
| 881 | + return strtr($texte, $from, $to); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -890,10 +890,10 @@ discard block |
||
| 890 | 890 | * @return string|array |
| 891 | 891 | **/ |
| 892 | 892 | function corriger_caracteres($texte) { |
| 893 | - $texte = corriger_caracteres_windows($texte); |
|
| 894 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 893 | + $texte = corriger_caracteres_windows($texte); |
|
| 894 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 895 | 895 | |
| 896 | - return $texte; |
|
| 896 | + return $texte; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -911,40 +911,40 @@ discard block |
||
| 911 | 911 | */ |
| 912 | 912 | function texte_backend($texte) { |
| 913 | 913 | |
| 914 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 914 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 915 | 915 | |
| 916 | - // si on a des liens ou des images, les passer en absolu |
|
| 917 | - $texte = liens_absolus($texte); |
|
| 916 | + // si on a des liens ou des images, les passer en absolu |
|
| 917 | + $texte = liens_absolus($texte); |
|
| 918 | 918 | |
| 919 | - // echapper les tags > < |
|
| 920 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 919 | + // echapper les tags > < |
|
| 920 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 921 | 921 | |
| 922 | - // importer les é |
|
| 923 | - $texte = filtrer_entites($texte); |
|
| 922 | + // importer les é |
|
| 923 | + $texte = filtrer_entites($texte); |
|
| 924 | 924 | |
| 925 | - // " -> " et tout ce genre de choses |
|
| 926 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 927 | - $texte = str_replace(' ', ' ', $texte); |
|
| 928 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 929 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 930 | - $texte = entites_html($texte, false, false); |
|
| 931 | - // mais bien echapper les double quotes ! |
|
| 932 | - $texte = str_replace('"', '"', $texte); |
|
| 925 | + // " -> " et tout ce genre de choses |
|
| 926 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 927 | + $texte = str_replace(' ', ' ', $texte); |
|
| 928 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 929 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 930 | + $texte = entites_html($texte, false, false); |
|
| 931 | + // mais bien echapper les double quotes ! |
|
| 932 | + $texte = str_replace('"', '"', $texte); |
|
| 933 | 933 | |
| 934 | - // verifier le charset |
|
| 935 | - $texte = charset2unicode($texte); |
|
| 934 | + // verifier le charset |
|
| 935 | + $texte = charset2unicode($texte); |
|
| 936 | 936 | |
| 937 | - // Caracteres problematiques en iso-latin 1 |
|
| 938 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 939 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 940 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 941 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 942 | - } |
|
| 937 | + // Caracteres problematiques en iso-latin 1 |
|
| 938 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 939 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 940 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 941 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 942 | + } |
|
| 943 | 943 | |
| 944 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 945 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 946 | - // ==> on les remplace par l'entite HTML |
|
| 947 | - return str_replace($apostrophe, "'", $texte); |
|
| 944 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 945 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 946 | + // ==> on les remplace par l'entite HTML |
|
| 947 | + return str_replace($apostrophe, "'", $texte); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | /** |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | * Texte encodé et quote pour XML |
| 962 | 962 | */ |
| 963 | 963 | function texte_backendq($texte) { |
| 964 | - return addslashes(texte_backend($texte)); |
|
| 964 | + return addslashes(texte_backend($texte)); |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
@@ -984,11 +984,11 @@ discard block |
||
| 984 | 984 | * Numéro de titre, sinon chaîne vide |
| 985 | 985 | **/ |
| 986 | 986 | function supprimer_numero($texte) { |
| 987 | - return preg_replace( |
|
| 988 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 989 | - '', |
|
| 990 | - $texte |
|
| 991 | - ); |
|
| 987 | + return preg_replace( |
|
| 988 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 989 | + '', |
|
| 990 | + $texte |
|
| 991 | + ); |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -1011,17 +1011,17 @@ discard block |
||
| 1011 | 1011 | * Numéro de titre, sinon chaîne vide |
| 1012 | 1012 | **/ |
| 1013 | 1013 | function recuperer_numero($texte) { |
| 1014 | - if ( |
|
| 1015 | - preg_match( |
|
| 1016 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1017 | - $texte, |
|
| 1018 | - $regs |
|
| 1019 | - ) |
|
| 1020 | - ) { |
|
| 1021 | - return strval($regs[1]); |
|
| 1022 | - } else { |
|
| 1023 | - return ''; |
|
| 1024 | - } |
|
| 1014 | + if ( |
|
| 1015 | + preg_match( |
|
| 1016 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1017 | + $texte, |
|
| 1018 | + $regs |
|
| 1019 | + ) |
|
| 1020 | + ) { |
|
| 1021 | + return strval($regs[1]); |
|
| 1022 | + } else { |
|
| 1023 | + return ''; |
|
| 1024 | + } |
|
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | /** |
@@ -1048,13 +1048,13 @@ discard block |
||
| 1048 | 1048 | * Texte converti |
| 1049 | 1049 | **/ |
| 1050 | 1050 | function supprimer_tags($texte, $rempl = '') { |
| 1051 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1052 | - // ne pas oublier un < final non ferme car coupe |
|
| 1053 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1054 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1055 | - $texte = str_replace('<', '<', $texte); |
|
| 1051 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1052 | + // ne pas oublier un < final non ferme car coupe |
|
| 1053 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1054 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1055 | + $texte = str_replace('<', '<', $texte); |
|
| 1056 | 1056 | |
| 1057 | - return $texte; |
|
| 1057 | + return $texte; |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | /** |
@@ -1077,9 +1077,9 @@ discard block |
||
| 1077 | 1077 | * Texte converti |
| 1078 | 1078 | **/ |
| 1079 | 1079 | function echapper_tags($texte, $rempl = '') { |
| 1080 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1080 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1081 | 1081 | |
| 1082 | - return $texte; |
|
| 1082 | + return $texte; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1100,18 +1100,18 @@ discard block |
||
| 1100 | 1100 | * Texte converti |
| 1101 | 1101 | **/ |
| 1102 | 1102 | function textebrut($texte) { |
| 1103 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1104 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1105 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1106 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1107 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1108 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1109 | - $texte = supprimer_tags($texte); |
|
| 1110 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1111 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1112 | - $texte = str_replace('’', "'", $texte); |
|
| 1103 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1104 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1105 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1106 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1107 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1108 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1109 | + $texte = supprimer_tags($texte); |
|
| 1110 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1111 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1112 | + $texte = str_replace('’', "'", $texte); |
|
| 1113 | 1113 | |
| 1114 | - return $texte; |
|
| 1114 | + return $texte; |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1127,23 +1127,23 @@ discard block |
||
| 1127 | 1127 | * Texte avec liens ouvrants |
| 1128 | 1128 | **/ |
| 1129 | 1129 | function liens_ouvrants($texte) { |
| 1130 | - if ( |
|
| 1131 | - preg_match_all( |
|
| 1132 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1133 | - $texte, |
|
| 1134 | - $liens, |
|
| 1135 | - PREG_PATTERN_ORDER |
|
| 1136 | - ) |
|
| 1137 | - ) { |
|
| 1138 | - foreach ($liens[0] as $a) { |
|
| 1139 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1140 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1141 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1142 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - return $texte; |
|
| 1130 | + if ( |
|
| 1131 | + preg_match_all( |
|
| 1132 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1133 | + $texte, |
|
| 1134 | + $liens, |
|
| 1135 | + PREG_PATTERN_ORDER |
|
| 1136 | + ) |
|
| 1137 | + ) { |
|
| 1138 | + foreach ($liens[0] as $a) { |
|
| 1139 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1140 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1141 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1142 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + return $texte; |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | /** |
@@ -1153,22 +1153,22 @@ discard block |
||
| 1153 | 1153 | * @return string |
| 1154 | 1154 | */ |
| 1155 | 1155 | function liens_nofollow($texte) { |
| 1156 | - if (stripos($texte, '<a') === false) { |
|
| 1157 | - return $texte; |
|
| 1158 | - } |
|
| 1156 | + if (stripos($texte, '<a') === false) { |
|
| 1157 | + return $texte; |
|
| 1158 | + } |
|
| 1159 | 1159 | |
| 1160 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1161 | - foreach ($regs[0] as $a) { |
|
| 1162 | - $rel = extraire_attribut($a, 'rel'); |
|
| 1163 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1164 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1165 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1166 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1160 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1161 | + foreach ($regs[0] as $a) { |
|
| 1162 | + $rel = extraire_attribut($a, 'rel'); |
|
| 1163 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1164 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1165 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1166 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | 1170 | |
| 1171 | - return $texte; |
|
| 1171 | + return $texte; |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | /** |
@@ -1187,12 +1187,12 @@ discard block |
||
| 1187 | 1187 | * Texte sans paraghaphes |
| 1188 | 1188 | **/ |
| 1189 | 1189 | function PtoBR($texte) { |
| 1190 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1191 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1192 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1193 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1190 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1191 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1192 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1193 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1194 | 1194 | |
| 1195 | - return $texte; |
|
| 1195 | + return $texte; |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | 1198 | |
@@ -1217,14 +1217,14 @@ discard block |
||
| 1217 | 1217 | * @return string Texte encadré du style CSS |
| 1218 | 1218 | */ |
| 1219 | 1219 | function lignes_longues($texte) { |
| 1220 | - if (!strlen(trim($texte))) { |
|
| 1221 | - return $texte; |
|
| 1222 | - } |
|
| 1223 | - include_spip('inc/texte'); |
|
| 1224 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1225 | - 'div' : 'span'; |
|
| 1220 | + if (!strlen(trim($texte))) { |
|
| 1221 | + return $texte; |
|
| 1222 | + } |
|
| 1223 | + include_spip('inc/texte'); |
|
| 1224 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1225 | + 'div' : 'span'; |
|
| 1226 | 1226 | |
| 1227 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1227 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | /** |
@@ -1243,30 +1243,30 @@ discard block |
||
| 1243 | 1243 | * @return string Texte en majuscule |
| 1244 | 1244 | */ |
| 1245 | 1245 | function majuscules($texte) { |
| 1246 | - if (!strlen($texte)) { |
|
| 1247 | - return ''; |
|
| 1248 | - } |
|
| 1246 | + if (!strlen($texte)) { |
|
| 1247 | + return ''; |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - // Cas du turc |
|
| 1251 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1252 | - # remplacer hors des tags et des entites |
|
| 1253 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1254 | - foreach ($regs as $n => $match) { |
|
| 1255 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1250 | + // Cas du turc |
|
| 1251 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1252 | + # remplacer hors des tags et des entites |
|
| 1253 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1254 | + foreach ($regs as $n => $match) { |
|
| 1255 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1259 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1260 | 1260 | |
| 1261 | - if ($regs) { |
|
| 1262 | - foreach ($regs as $n => $match) { |
|
| 1263 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1261 | + if ($regs) { |
|
| 1262 | + foreach ($regs as $n => $match) { |
|
| 1263 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | - // Cas general |
|
| 1269 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1268 | + // Cas general |
|
| 1269 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | /** |
@@ -1284,29 +1284,29 @@ discard block |
||
| 1284 | 1284 | * @return string |
| 1285 | 1285 | **/ |
| 1286 | 1286 | function taille_en_octets($taille) { |
| 1287 | - if (!defined('_KILOBYTE')) { |
|
| 1288 | - /** |
|
| 1289 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1290 | - * |
|
| 1291 | - * @var int |
|
| 1292 | - **/ |
|
| 1293 | - define('_KILOBYTE', 1024); |
|
| 1294 | - } |
|
| 1287 | + if (!defined('_KILOBYTE')) { |
|
| 1288 | + /** |
|
| 1289 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1290 | + * |
|
| 1291 | + * @var int |
|
| 1292 | + **/ |
|
| 1293 | + define('_KILOBYTE', 1024); |
|
| 1294 | + } |
|
| 1295 | 1295 | |
| 1296 | - if ($taille < 1) { |
|
| 1297 | - return ''; |
|
| 1298 | - } |
|
| 1299 | - if ($taille < _KILOBYTE) { |
|
| 1300 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1301 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1302 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1303 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1304 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1305 | - } else { |
|
| 1306 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1307 | - } |
|
| 1296 | + if ($taille < 1) { |
|
| 1297 | + return ''; |
|
| 1298 | + } |
|
| 1299 | + if ($taille < _KILOBYTE) { |
|
| 1300 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1301 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1302 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1303 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1304 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1305 | + } else { |
|
| 1306 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1307 | + } |
|
| 1308 | 1308 | |
| 1309 | - return $taille; |
|
| 1309 | + return $taille; |
|
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | |
@@ -1328,18 +1328,18 @@ discard block |
||
| 1328 | 1328 | * Texte prêt pour être utilisé en attribut HTML |
| 1329 | 1329 | **/ |
| 1330 | 1330 | function attribut_html($texte, $textebrut = true) { |
| 1331 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1332 | - if ($textebrut) { |
|
| 1333 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1334 | - } |
|
| 1335 | - $texte = texte_backend($texte); |
|
| 1336 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1331 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1332 | + if ($textebrut) { |
|
| 1333 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1334 | + } |
|
| 1335 | + $texte = texte_backend($texte); |
|
| 1336 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1337 | 1337 | |
| 1338 | - return preg_replace( |
|
| 1339 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1340 | - ['&', '&'], |
|
| 1341 | - $texte |
|
| 1342 | - ); |
|
| 1338 | + return preg_replace( |
|
| 1339 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1340 | + ['&', '&'], |
|
| 1341 | + $texte |
|
| 1342 | + ); |
|
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | |
@@ -1359,12 +1359,12 @@ discard block |
||
| 1359 | 1359 | * URL ou chaîne vide |
| 1360 | 1360 | **/ |
| 1361 | 1361 | function vider_url($url, $entites = true) { |
| 1362 | - # un message pour abs_url |
|
| 1363 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1364 | - $url = trim($url); |
|
| 1365 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1362 | + # un message pour abs_url |
|
| 1363 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1364 | + $url = trim($url); |
|
| 1365 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1366 | 1366 | |
| 1367 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1367 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
@@ -1379,10 +1379,10 @@ discard block |
||
| 1379 | 1379 | * @return string Adresse email maquillée |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function antispam($texte) { |
| 1382 | - include_spip('inc/acces'); |
|
| 1383 | - $masque = creer_pass_aleatoire(3); |
|
| 1382 | + include_spip('inc/acces'); |
|
| 1383 | + $masque = creer_pass_aleatoire(3); |
|
| 1384 | 1384 | |
| 1385 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1385 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | /** |
@@ -1414,12 +1414,12 @@ discard block |
||
| 1414 | 1414 | * True si on a le droit d'accès, false sinon. |
| 1415 | 1415 | **/ |
| 1416 | 1416 | function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1417 | - include_spip('inc/acces'); |
|
| 1418 | - if ($op) { |
|
| 1419 | - $dir .= " $op $args"; |
|
| 1420 | - } |
|
| 1417 | + include_spip('inc/acces'); |
|
| 1418 | + if ($op) { |
|
| 1419 | + $dir .= " $op $args"; |
|
| 1420 | + } |
|
| 1421 | 1421 | |
| 1422 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1422 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1444,11 +1444,11 @@ discard block |
||
| 1444 | 1444 | * Retourne $texte, sinon $sinon. |
| 1445 | 1445 | **/ |
| 1446 | 1446 | function sinon($texte, $sinon = '') { |
| 1447 | - if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1448 | - return $texte; |
|
| 1449 | - } else { |
|
| 1450 | - return $sinon; |
|
| 1451 | - } |
|
| 1447 | + if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1448 | + return $texte; |
|
| 1449 | + } else { |
|
| 1450 | + return $sinon; |
|
| 1451 | + } |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | 1454 | /** |
@@ -1472,7 +1472,7 @@ discard block |
||
| 1472 | 1472 | * @return mixed |
| 1473 | 1473 | **/ |
| 1474 | 1474 | function choixsivide($a, $vide, $pasvide) { |
| 1475 | - return $a ? $pasvide : $vide; |
|
| 1475 | + return $a ? $pasvide : $vide; |
|
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | /** |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | * @return mixed |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function choixsiegal($a1, $a2, $v, $f) { |
| 1499 | - return ($a1 == $a2) ? $v : $f; |
|
| 1499 | + return ($a1 == $a2) ? $v : $f; |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | // |
@@ -1515,13 +1515,13 @@ discard block |
||
| 1515 | 1515 | * @return string |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function filtrer_ical($texte) { |
| 1518 | - #include_spip('inc/charsets'); |
|
| 1519 | - $texte = html2unicode($texte); |
|
| 1520 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1521 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1522 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1518 | + #include_spip('inc/charsets'); |
|
| 1519 | + $texte = html2unicode($texte); |
|
| 1520 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1521 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1522 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1523 | 1523 | |
| 1524 | - return $texte; |
|
| 1524 | + return $texte; |
|
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | |
@@ -1546,54 +1546,54 @@ discard block |
||
| 1546 | 1546 | * @return string |
| 1547 | 1547 | **/ |
| 1548 | 1548 | function post_autobr($texte, $delim = "\n_ ") { |
| 1549 | - if (!function_exists('echappe_html')) { |
|
| 1550 | - include_spip('inc/texte_mini'); |
|
| 1551 | - } |
|
| 1552 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1553 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1554 | - |
|
| 1555 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1556 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1557 | - } else { |
|
| 1558 | - $fin = ''; |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - $texte = echappe_html($texte, '', true); |
|
| 1562 | - |
|
| 1563 | - // echapper les modeles |
|
| 1564 | - if (strpos($texte, '<') !== false) { |
|
| 1565 | - include_spip('inc/lien'); |
|
| 1566 | - if (defined('_PREG_MODELE')) { |
|
| 1567 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1568 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1569 | - } |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - $debut = ''; |
|
| 1573 | - $suite = $texte; |
|
| 1574 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1575 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1576 | - $suite = substr($suite, $t); |
|
| 1577 | - $car = substr($suite, 0, 1); |
|
| 1578 | - if ( |
|
| 1579 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1580 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1581 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1582 | - ) { |
|
| 1583 | - $debut .= $delim; |
|
| 1584 | - } else { |
|
| 1585 | - $debut .= "\n"; |
|
| 1586 | - } |
|
| 1587 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1588 | - $debut .= $regs[0]; |
|
| 1589 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - $texte = $debut . $suite; |
|
| 1593 | - |
|
| 1594 | - $texte = echappe_retour($texte); |
|
| 1595 | - |
|
| 1596 | - return $texte . $fin; |
|
| 1549 | + if (!function_exists('echappe_html')) { |
|
| 1550 | + include_spip('inc/texte_mini'); |
|
| 1551 | + } |
|
| 1552 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1553 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1554 | + |
|
| 1555 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1556 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1557 | + } else { |
|
| 1558 | + $fin = ''; |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + $texte = echappe_html($texte, '', true); |
|
| 1562 | + |
|
| 1563 | + // echapper les modeles |
|
| 1564 | + if (strpos($texte, '<') !== false) { |
|
| 1565 | + include_spip('inc/lien'); |
|
| 1566 | + if (defined('_PREG_MODELE')) { |
|
| 1567 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1568 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1569 | + } |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + $debut = ''; |
|
| 1573 | + $suite = $texte; |
|
| 1574 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1575 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1576 | + $suite = substr($suite, $t); |
|
| 1577 | + $car = substr($suite, 0, 1); |
|
| 1578 | + if ( |
|
| 1579 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1580 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1581 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1582 | + ) { |
|
| 1583 | + $debut .= $delim; |
|
| 1584 | + } else { |
|
| 1585 | + $debut .= "\n"; |
|
| 1586 | + } |
|
| 1587 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1588 | + $debut .= $regs[0]; |
|
| 1589 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + $texte = $debut . $suite; |
|
| 1593 | + |
|
| 1594 | + $texte = echappe_retour($texte); |
|
| 1595 | + |
|
| 1596 | + return $texte . $fin; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | |
@@ -1634,47 +1634,47 @@ discard block |
||
| 1634 | 1634 | * @return string |
| 1635 | 1635 | **/ |
| 1636 | 1636 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1637 | - static $traduire = false; |
|
| 1638 | - if ( |
|
| 1639 | - $letexte |
|
| 1640 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1641 | - ) { |
|
| 1642 | - if (!$traduire) { |
|
| 1643 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1644 | - include_spip('inc/lang'); |
|
| 1645 | - } |
|
| 1646 | - if (!$lang) { |
|
| 1647 | - $lang = $GLOBALS['spip_lang']; |
|
| 1648 | - } |
|
| 1649 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1650 | - if (is_bool($options)) { |
|
| 1651 | - $options = ['echappe_span' => $options]; |
|
| 1652 | - } |
|
| 1653 | - if (!isset($options['echappe_span'])) { |
|
| 1654 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - foreach ($regs as $reg) { |
|
| 1658 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1659 | - $desc = $traduire($cle, $lang, true); |
|
| 1660 | - $l = $desc->langue; |
|
| 1661 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1662 | - if (strlen($desc->texte)) { |
|
| 1663 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1664 | - if ($l !== $lang) { |
|
| 1665 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1666 | - } |
|
| 1667 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1668 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1669 | - } |
|
| 1670 | - if (!$options['echappe_span']) { |
|
| 1671 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1672 | - } |
|
| 1673 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1674 | - } |
|
| 1675 | - } |
|
| 1676 | - } |
|
| 1677 | - return $letexte; |
|
| 1637 | + static $traduire = false; |
|
| 1638 | + if ( |
|
| 1639 | + $letexte |
|
| 1640 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1641 | + ) { |
|
| 1642 | + if (!$traduire) { |
|
| 1643 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1644 | + include_spip('inc/lang'); |
|
| 1645 | + } |
|
| 1646 | + if (!$lang) { |
|
| 1647 | + $lang = $GLOBALS['spip_lang']; |
|
| 1648 | + } |
|
| 1649 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1650 | + if (is_bool($options)) { |
|
| 1651 | + $options = ['echappe_span' => $options]; |
|
| 1652 | + } |
|
| 1653 | + if (!isset($options['echappe_span'])) { |
|
| 1654 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + foreach ($regs as $reg) { |
|
| 1658 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1659 | + $desc = $traduire($cle, $lang, true); |
|
| 1660 | + $l = $desc->langue; |
|
| 1661 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1662 | + if (strlen($desc->texte)) { |
|
| 1663 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1664 | + if ($l !== $lang) { |
|
| 1665 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1666 | + } |
|
| 1667 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1668 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1669 | + } |
|
| 1670 | + if (!$options['echappe_span']) { |
|
| 1671 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1672 | + } |
|
| 1673 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1674 | + } |
|
| 1675 | + } |
|
| 1676 | + } |
|
| 1677 | + return $letexte; |
|
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | 1680 | /** |
@@ -1726,68 +1726,68 @@ discard block |
||
| 1726 | 1726 | **/ |
| 1727 | 1727 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1728 | 1728 | |
| 1729 | - if ( |
|
| 1730 | - $letexte |
|
| 1731 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1732 | - ) { |
|
| 1733 | - if (!$lang) { |
|
| 1734 | - $lang = $GLOBALS['spip_lang']; |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1738 | - if (is_bool($options)) { |
|
| 1739 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1740 | - } |
|
| 1741 | - if (!isset($options['echappe_span'])) { |
|
| 1742 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1743 | - } |
|
| 1744 | - if (!isset($options['lang_defaut'])) { |
|
| 1745 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - include_spip('inc/lang'); |
|
| 1749 | - foreach ($regs as $reg) { |
|
| 1750 | - // chercher la version de la langue courante |
|
| 1751 | - $trads = extraire_trads($reg[1]); |
|
| 1752 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1753 | - $trad = $trads[$l]; |
|
| 1754 | - } else { |
|
| 1755 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1756 | - $trad = ''; |
|
| 1757 | - } else { |
|
| 1758 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1759 | - // ou la premiere dispo |
|
| 1760 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1761 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1762 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1763 | - $l = key($trads); |
|
| 1764 | - } |
|
| 1765 | - $trad = $trads[$l]; |
|
| 1766 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1767 | - $trad = $typographie($trad); |
|
| 1768 | - // Tester si on echappe en span ou en div |
|
| 1769 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1770 | - include_spip('inc/texte'); |
|
| 1771 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1772 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1773 | - if ($mode === 'div') { |
|
| 1774 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1775 | - } |
|
| 1776 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1777 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1778 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1779 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1780 | - } |
|
| 1781 | - if (!$options['echappe_span']) { |
|
| 1782 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1783 | - } |
|
| 1784 | - } |
|
| 1785 | - } |
|
| 1786 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1787 | - } |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - return $letexte; |
|
| 1729 | + if ( |
|
| 1730 | + $letexte |
|
| 1731 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1732 | + ) { |
|
| 1733 | + if (!$lang) { |
|
| 1734 | + $lang = $GLOBALS['spip_lang']; |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1738 | + if (is_bool($options)) { |
|
| 1739 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1740 | + } |
|
| 1741 | + if (!isset($options['echappe_span'])) { |
|
| 1742 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1743 | + } |
|
| 1744 | + if (!isset($options['lang_defaut'])) { |
|
| 1745 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + include_spip('inc/lang'); |
|
| 1749 | + foreach ($regs as $reg) { |
|
| 1750 | + // chercher la version de la langue courante |
|
| 1751 | + $trads = extraire_trads($reg[1]); |
|
| 1752 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1753 | + $trad = $trads[$l]; |
|
| 1754 | + } else { |
|
| 1755 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1756 | + $trad = ''; |
|
| 1757 | + } else { |
|
| 1758 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1759 | + // ou la premiere dispo |
|
| 1760 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1761 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1762 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1763 | + $l = key($trads); |
|
| 1764 | + } |
|
| 1765 | + $trad = $trads[$l]; |
|
| 1766 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1767 | + $trad = $typographie($trad); |
|
| 1768 | + // Tester si on echappe en span ou en div |
|
| 1769 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1770 | + include_spip('inc/texte'); |
|
| 1771 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1772 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1773 | + if ($mode === 'div') { |
|
| 1774 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1775 | + } |
|
| 1776 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1777 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1778 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1779 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1780 | + } |
|
| 1781 | + if (!$options['echappe_span']) { |
|
| 1782 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + } |
|
| 1786 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1787 | + } |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + return $letexte; |
|
| 1791 | 1791 | } |
| 1792 | 1792 | |
| 1793 | 1793 | /** |
@@ -1803,20 +1803,20 @@ discard block |
||
| 1803 | 1803 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1804 | 1804 | **/ |
| 1805 | 1805 | function extraire_trads($bloc) { |
| 1806 | - $lang = ''; |
|
| 1806 | + $lang = ''; |
|
| 1807 | 1807 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1808 | 1808 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1809 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1810 | - $texte = trim($regs[1]); |
|
| 1811 | - if ($texte or $lang) { |
|
| 1812 | - $trads[$lang] = $texte; |
|
| 1813 | - } |
|
| 1814 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1815 | - $lang = $regs[2]; |
|
| 1816 | - } |
|
| 1817 | - $trads[$lang] = $bloc; |
|
| 1809 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1810 | + $texte = trim($regs[1]); |
|
| 1811 | + if ($texte or $lang) { |
|
| 1812 | + $trads[$lang] = $texte; |
|
| 1813 | + } |
|
| 1814 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1815 | + $lang = $regs[2]; |
|
| 1816 | + } |
|
| 1817 | + $trads[$lang] = $bloc; |
|
| 1818 | 1818 | |
| 1819 | - return $trads; |
|
| 1819 | + return $trads; |
|
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | 1822 | |
@@ -1827,7 +1827,7 @@ discard block |
||
| 1827 | 1827 | * @return string L'initiale en majuscule |
| 1828 | 1828 | */ |
| 1829 | 1829 | function filtre_initiale($nom) { |
| 1830 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1830 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | 1833 | |
@@ -1872,33 +1872,33 @@ discard block |
||
| 1872 | 1872 | * - null (interne) : si on empile |
| 1873 | 1873 | **/ |
| 1874 | 1874 | function unique($donnee, $famille = '', $cpt = false) { |
| 1875 | - static $mem = []; |
|
| 1876 | - // permettre de vider la pile et de la restaurer |
|
| 1877 | - // pour le calcul de introduction... |
|
| 1878 | - if ($famille == '_spip_raz_') { |
|
| 1879 | - $tmp = $mem; |
|
| 1880 | - $mem = []; |
|
| 1881 | - |
|
| 1882 | - return $tmp; |
|
| 1883 | - } elseif ($famille == '_spip_set_') { |
|
| 1884 | - $mem = $donnee; |
|
| 1885 | - |
|
| 1886 | - return; |
|
| 1887 | - } |
|
| 1888 | - // eviter une notice |
|
| 1889 | - if (!isset($mem[$famille])) { |
|
| 1890 | - $mem[$famille] = []; |
|
| 1891 | - } |
|
| 1892 | - if ($cpt) { |
|
| 1893 | - return count($mem[$famille]); |
|
| 1894 | - } |
|
| 1895 | - // eviter une notice |
|
| 1896 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1897 | - $mem[$famille][$donnee] = 0; |
|
| 1898 | - } |
|
| 1899 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1900 | - return $donnee; |
|
| 1901 | - } |
|
| 1875 | + static $mem = []; |
|
| 1876 | + // permettre de vider la pile et de la restaurer |
|
| 1877 | + // pour le calcul de introduction... |
|
| 1878 | + if ($famille == '_spip_raz_') { |
|
| 1879 | + $tmp = $mem; |
|
| 1880 | + $mem = []; |
|
| 1881 | + |
|
| 1882 | + return $tmp; |
|
| 1883 | + } elseif ($famille == '_spip_set_') { |
|
| 1884 | + $mem = $donnee; |
|
| 1885 | + |
|
| 1886 | + return; |
|
| 1887 | + } |
|
| 1888 | + // eviter une notice |
|
| 1889 | + if (!isset($mem[$famille])) { |
|
| 1890 | + $mem[$famille] = []; |
|
| 1891 | + } |
|
| 1892 | + if ($cpt) { |
|
| 1893 | + return count($mem[$famille]); |
|
| 1894 | + } |
|
| 1895 | + // eviter une notice |
|
| 1896 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1897 | + $mem[$famille][$donnee] = 0; |
|
| 1898 | + } |
|
| 1899 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1900 | + return $donnee; |
|
| 1901 | + } |
|
| 1902 | 1902 | } |
| 1903 | 1903 | |
| 1904 | 1904 | |
@@ -1928,16 +1928,16 @@ discard block |
||
| 1928 | 1928 | * Une des valeurs en fonction du compteur. |
| 1929 | 1929 | **/ |
| 1930 | 1930 | function alterner($i, ...$args) { |
| 1931 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1932 | - $num = count($args); |
|
| 1931 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1932 | + $num = count($args); |
|
| 1933 | 1933 | |
| 1934 | - if ($num === 1 && is_array($args[0])) { |
|
| 1935 | - $args = $args[0]; |
|
| 1936 | - $num = count($args); |
|
| 1937 | - } |
|
| 1934 | + if ($num === 1 && is_array($args[0])) { |
|
| 1935 | + $args = $args[0]; |
|
| 1936 | + $num = count($args); |
|
| 1937 | + } |
|
| 1938 | 1938 | |
| 1939 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1940 | - return $args[(intval($i) - 1) % $num]; |
|
| 1939 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1940 | + return $args[(intval($i) - 1) % $num]; |
|
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | 1943 | |
@@ -1962,49 +1962,49 @@ discard block |
||
| 1962 | 1962 | * - Tableau complet (si 2e argument) |
| 1963 | 1963 | **/ |
| 1964 | 1964 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1965 | - if (is_array($balise)) { |
|
| 1966 | - array_walk( |
|
| 1967 | - $balise, |
|
| 1968 | - function (&$a, $key, $t) { |
|
| 1969 | - $a = extraire_attribut($a, $t); |
|
| 1970 | - }, |
|
| 1971 | - $attribut |
|
| 1972 | - ); |
|
| 1973 | - |
|
| 1974 | - return $balise; |
|
| 1975 | - } |
|
| 1976 | - if ( |
|
| 1977 | - preg_match( |
|
| 1978 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1979 | - . $attribut |
|
| 1980 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1981 | - $balise, |
|
| 1982 | - $r |
|
| 1983 | - ) |
|
| 1984 | - ) { |
|
| 1985 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1986 | - $r[4] = substr($r[3], 1, -1); |
|
| 1987 | - $r[3] = $r[3][0]; |
|
| 1988 | - } elseif ($r[3] !== '') { |
|
| 1989 | - $r[4] = $r[3]; |
|
| 1990 | - $r[3] = ''; |
|
| 1991 | - } else { |
|
| 1992 | - $r[4] = trim($r[2]); |
|
| 1993 | - } |
|
| 1994 | - $att = $r[4]; |
|
| 1995 | - if (strpos($att, '&#') !== false) { |
|
| 1996 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1997 | - } |
|
| 1998 | - $att = filtrer_entites($att); |
|
| 1999 | - } else { |
|
| 2000 | - $att = null; |
|
| 2001 | - } |
|
| 2002 | - |
|
| 2003 | - if ($complet) { |
|
| 2004 | - return [$att, $r]; |
|
| 2005 | - } else { |
|
| 2006 | - return $att; |
|
| 2007 | - } |
|
| 1965 | + if (is_array($balise)) { |
|
| 1966 | + array_walk( |
|
| 1967 | + $balise, |
|
| 1968 | + function (&$a, $key, $t) { |
|
| 1969 | + $a = extraire_attribut($a, $t); |
|
| 1970 | + }, |
|
| 1971 | + $attribut |
|
| 1972 | + ); |
|
| 1973 | + |
|
| 1974 | + return $balise; |
|
| 1975 | + } |
|
| 1976 | + if ( |
|
| 1977 | + preg_match( |
|
| 1978 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1979 | + . $attribut |
|
| 1980 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1981 | + $balise, |
|
| 1982 | + $r |
|
| 1983 | + ) |
|
| 1984 | + ) { |
|
| 1985 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1986 | + $r[4] = substr($r[3], 1, -1); |
|
| 1987 | + $r[3] = $r[3][0]; |
|
| 1988 | + } elseif ($r[3] !== '') { |
|
| 1989 | + $r[4] = $r[3]; |
|
| 1990 | + $r[3] = ''; |
|
| 1991 | + } else { |
|
| 1992 | + $r[4] = trim($r[2]); |
|
| 1993 | + } |
|
| 1994 | + $att = $r[4]; |
|
| 1995 | + if (strpos($att, '&#') !== false) { |
|
| 1996 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1997 | + } |
|
| 1998 | + $att = filtrer_entites($att); |
|
| 1999 | + } else { |
|
| 2000 | + $att = null; |
|
| 2001 | + } |
|
| 2002 | + |
|
| 2003 | + if ($complet) { |
|
| 2004 | + return [$att, $r]; |
|
| 2005 | + } else { |
|
| 2006 | + return $att; |
|
| 2007 | + } |
|
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | 2010 | /** |
@@ -2036,37 +2036,37 @@ discard block |
||
| 2036 | 2036 | * Code html modifié |
| 2037 | 2037 | **/ |
| 2038 | 2038 | function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) { |
| 2039 | - // preparer l'attribut |
|
| 2040 | - // supprimer les etc mais pas les balises html |
|
| 2041 | - // qui ont un sens dans un attribut value d'un input |
|
| 2042 | - if ($proteger) { |
|
| 2043 | - $val = attribut_html($val, false); |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - // echapper les ' pour eviter tout bug |
|
| 2047 | - $val = str_replace("'", ''', $val); |
|
| 2048 | - if ($vider and strlen($val) == 0) { |
|
| 2049 | - $insert = ''; |
|
| 2050 | - } else { |
|
| 2051 | - $insert = " $attribut='$val'"; |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 2055 | - |
|
| 2056 | - if ($old !== null) { |
|
| 2057 | - // Remplacer l'ancien attribut du meme nom |
|
| 2058 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2059 | - } else { |
|
| 2060 | - // preferer une balise " />" (comme <img />) |
|
| 2061 | - if (preg_match(',/>,', $balise)) { |
|
| 2062 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2063 | - } // sinon une balise <a ...> ... </a> |
|
| 2064 | - else { |
|
| 2065 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2066 | - } |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - return $balise; |
|
| 2039 | + // preparer l'attribut |
|
| 2040 | + // supprimer les etc mais pas les balises html |
|
| 2041 | + // qui ont un sens dans un attribut value d'un input |
|
| 2042 | + if ($proteger) { |
|
| 2043 | + $val = attribut_html($val, false); |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + // echapper les ' pour eviter tout bug |
|
| 2047 | + $val = str_replace("'", ''', $val); |
|
| 2048 | + if ($vider and strlen($val) == 0) { |
|
| 2049 | + $insert = ''; |
|
| 2050 | + } else { |
|
| 2051 | + $insert = " $attribut='$val'"; |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 2055 | + |
|
| 2056 | + if ($old !== null) { |
|
| 2057 | + // Remplacer l'ancien attribut du meme nom |
|
| 2058 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2059 | + } else { |
|
| 2060 | + // preferer une balise " />" (comme <img />) |
|
| 2061 | + if (preg_match(',/>,', $balise)) { |
|
| 2062 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2063 | + } // sinon une balise <a ...> ... </a> |
|
| 2064 | + else { |
|
| 2065 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2066 | + } |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + return $balise; |
|
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | 2072 | /** |
@@ -2084,7 +2084,7 @@ discard block |
||
| 2084 | 2084 | * @return string Code HTML sans l'attribut |
| 2085 | 2085 | **/ |
| 2086 | 2086 | function vider_attribut($balise, $attribut) { |
| 2087 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2087 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2088 | 2088 | } |
| 2089 | 2089 | |
| 2090 | 2090 | /** |
@@ -2096,56 +2096,56 @@ discard block |
||
| 2096 | 2096 | * @return string |
| 2097 | 2097 | */ |
| 2098 | 2098 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2099 | - if (is_string($class)) { |
|
| 2100 | - $class = explode(' ', trim($class)); |
|
| 2101 | - } |
|
| 2102 | - $class = array_filter($class); |
|
| 2103 | - |
|
| 2104 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2105 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2106 | - return $balise; |
|
| 2107 | - } |
|
| 2108 | - |
|
| 2109 | - if ($class) { |
|
| 2110 | - $class = array_unique($class); |
|
| 2111 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2112 | - |
|
| 2113 | - $class_new = $class_courante; |
|
| 2114 | - foreach ($class as $c) { |
|
| 2115 | - if ($c) { |
|
| 2116 | - $is_class_presente = false; |
|
| 2117 | - if ( |
|
| 2118 | - strpos($class_courante, $c) !== false |
|
| 2119 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2120 | - ) { |
|
| 2121 | - $is_class_presente = true; |
|
| 2122 | - } |
|
| 2123 | - if ( |
|
| 2124 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2125 | - and !$is_class_presente |
|
| 2126 | - ) { |
|
| 2127 | - $class_new = rtrim($class_new) . ' ' . $c; |
|
| 2128 | - } |
|
| 2129 | - elseif ( |
|
| 2130 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2131 | - and $is_class_presente |
|
| 2132 | - ) { |
|
| 2133 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2134 | - } |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - if ($class_new !== $class_courante) { |
|
| 2139 | - if (strlen($class_new)) { |
|
| 2140 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2141 | - } |
|
| 2142 | - elseif ($class_courante) { |
|
| 2143 | - $balise = vider_attribut($balise, 'class'); |
|
| 2144 | - } |
|
| 2145 | - } |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - return $balise; |
|
| 2099 | + if (is_string($class)) { |
|
| 2100 | + $class = explode(' ', trim($class)); |
|
| 2101 | + } |
|
| 2102 | + $class = array_filter($class); |
|
| 2103 | + |
|
| 2104 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2105 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2106 | + return $balise; |
|
| 2107 | + } |
|
| 2108 | + |
|
| 2109 | + if ($class) { |
|
| 2110 | + $class = array_unique($class); |
|
| 2111 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2112 | + |
|
| 2113 | + $class_new = $class_courante; |
|
| 2114 | + foreach ($class as $c) { |
|
| 2115 | + if ($c) { |
|
| 2116 | + $is_class_presente = false; |
|
| 2117 | + if ( |
|
| 2118 | + strpos($class_courante, $c) !== false |
|
| 2119 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2120 | + ) { |
|
| 2121 | + $is_class_presente = true; |
|
| 2122 | + } |
|
| 2123 | + if ( |
|
| 2124 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2125 | + and !$is_class_presente |
|
| 2126 | + ) { |
|
| 2127 | + $class_new = rtrim($class_new) . ' ' . $c; |
|
| 2128 | + } |
|
| 2129 | + elseif ( |
|
| 2130 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2131 | + and $is_class_presente |
|
| 2132 | + ) { |
|
| 2133 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2134 | + } |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + if ($class_new !== $class_courante) { |
|
| 2139 | + if (strlen($class_new)) { |
|
| 2140 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2141 | + } |
|
| 2142 | + elseif ($class_courante) { |
|
| 2143 | + $balise = vider_attribut($balise, 'class'); |
|
| 2144 | + } |
|
| 2145 | + } |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + return $balise; |
|
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | 2151 | /** |
@@ -2155,7 +2155,7 @@ discard block |
||
| 2155 | 2155 | * @return string |
| 2156 | 2156 | */ |
| 2157 | 2157 | function ajouter_class($balise, $class) { |
| 2158 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2158 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
@@ -2165,7 +2165,7 @@ discard block |
||
| 2165 | 2165 | * @return string |
| 2166 | 2166 | */ |
| 2167 | 2167 | function supprimer_class($balise, $class) { |
| 2168 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2168 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2169 | 2169 | } |
| 2170 | 2170 | |
| 2171 | 2171 | /** |
@@ -2176,7 +2176,7 @@ discard block |
||
| 2176 | 2176 | * @return string |
| 2177 | 2177 | */ |
| 2178 | 2178 | function commuter_class($balise, $class) { |
| 2179 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2179 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2180 | 2180 | } |
| 2181 | 2181 | |
| 2182 | 2182 | /** |
@@ -2187,19 +2187,19 @@ discard block |
||
| 2187 | 2187 | * @return string |
| 2188 | 2188 | */ |
| 2189 | 2189 | function tester_config($id, $mode = '') { |
| 2190 | - include_spip('action/inscrire_auteur'); |
|
| 2190 | + include_spip('action/inscrire_auteur'); |
|
| 2191 | 2191 | |
| 2192 | - return tester_statut_inscription($mode, $id); |
|
| 2192 | + return tester_statut_inscription($mode, $id); |
|
| 2193 | 2193 | } |
| 2194 | 2194 | |
| 2195 | 2195 | // |
| 2196 | 2196 | // Quelques fonctions de calcul arithmetique |
| 2197 | 2197 | // |
| 2198 | 2198 | function floatstr($a) { |
| 2199 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2199 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2200 | 2200 | } |
| 2201 | 2201 | function strize($f, $a, $b) { |
| 2202 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2202 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | 2205 | /** |
@@ -2218,7 +2218,7 @@ discard block |
||
| 2218 | 2218 | * @return int $a+$b |
| 2219 | 2219 | **/ |
| 2220 | 2220 | function plus($a, $b) { |
| 2221 | - return $a + $b; |
|
| 2221 | + return $a + $b; |
|
| 2222 | 2222 | } |
| 2223 | 2223 | function strplus($a, $b) { |
| 2224 | 2224 | return strize('plus', $a, $b); |
@@ -2239,7 +2239,7 @@ discard block |
||
| 2239 | 2239 | * @return int $a-$b |
| 2240 | 2240 | **/ |
| 2241 | 2241 | function moins($a, $b) { |
| 2242 | - return $a - $b; |
|
| 2242 | + return $a - $b; |
|
| 2243 | 2243 | } |
| 2244 | 2244 | function strmoins($a, $b) { |
| 2245 | 2245 | return strize('moins', $a, $b); |
@@ -2262,7 +2262,7 @@ discard block |
||
| 2262 | 2262 | * @return int $a*$b |
| 2263 | 2263 | **/ |
| 2264 | 2264 | function mult($a, $b) { |
| 2265 | - return $a * $b; |
|
| 2265 | + return $a * $b; |
|
| 2266 | 2266 | } |
| 2267 | 2267 | function strmult($a, $b) { |
| 2268 | 2268 | return strize('mult', $a, $b); |
@@ -2285,7 +2285,7 @@ discard block |
||
| 2285 | 2285 | * @return int $a/$b (ou 0 si $b est nul) |
| 2286 | 2286 | **/ |
| 2287 | 2287 | function div($a, $b) { |
| 2288 | - return $b ? $a / $b : 0; |
|
| 2288 | + return $b ? $a / $b : 0; |
|
| 2289 | 2289 | } |
| 2290 | 2290 | function strdiv($a, $b) { |
| 2291 | 2291 | return strize('div', $a, $b); |
@@ -2309,7 +2309,7 @@ discard block |
||
| 2309 | 2309 | * @return int ($nb % $mod) + $add |
| 2310 | 2310 | **/ |
| 2311 | 2311 | function modulo($nb, $mod, $add = 0) { |
| 2312 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2312 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2313 | 2313 | } |
| 2314 | 2314 | |
| 2315 | 2315 | |
@@ -2324,24 +2324,24 @@ discard block |
||
| 2324 | 2324 | * - true sinon |
| 2325 | 2325 | **/ |
| 2326 | 2326 | function nom_acceptable($nom) { |
| 2327 | - if (!is_string($nom)) { |
|
| 2328 | - return false; |
|
| 2329 | - } |
|
| 2330 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2331 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2332 | - } |
|
| 2333 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2334 | - foreach ($tags_acceptes as $tag) { |
|
| 2335 | - if (strlen($tag)) { |
|
| 2336 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2337 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2338 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2339 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2340 | - } |
|
| 2341 | - } |
|
| 2342 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2327 | + if (!is_string($nom)) { |
|
| 2328 | + return false; |
|
| 2329 | + } |
|
| 2330 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2331 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2332 | + } |
|
| 2333 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2334 | + foreach ($tags_acceptes as $tag) { |
|
| 2335 | + if (strlen($tag)) { |
|
| 2336 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2337 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2338 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2339 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2340 | + } |
|
| 2341 | + } |
|
| 2342 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2343 | 2343 | |
| 2344 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2344 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2345 | 2345 | } |
| 2346 | 2346 | |
| 2347 | 2347 | |
@@ -2357,14 +2357,14 @@ discard block |
||
| 2357 | 2357 | * - renvoie un tableau si l'entree est un tableau |
| 2358 | 2358 | **/ |
| 2359 | 2359 | function email_valide($adresses) { |
| 2360 | - if (is_array($adresses)) { |
|
| 2361 | - $adresses = array_map('email_valide', $adresses); |
|
| 2362 | - $adresses = array_filter($adresses); |
|
| 2363 | - return $adresses; |
|
| 2364 | - } |
|
| 2360 | + if (is_array($adresses)) { |
|
| 2361 | + $adresses = array_map('email_valide', $adresses); |
|
| 2362 | + $adresses = array_filter($adresses); |
|
| 2363 | + return $adresses; |
|
| 2364 | + } |
|
| 2365 | 2365 | |
| 2366 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2367 | - return $email_valide($adresses); |
|
| 2366 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2367 | + return $email_valide($adresses); |
|
| 2368 | 2368 | } |
| 2369 | 2369 | |
| 2370 | 2370 | /** |
@@ -2378,27 +2378,27 @@ discard block |
||
| 2378 | 2378 | * @return string Texte |
| 2379 | 2379 | **/ |
| 2380 | 2380 | function afficher_enclosures($tags) { |
| 2381 | - $s = []; |
|
| 2382 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2383 | - if ( |
|
| 2384 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2385 | - and $t = extraire_attribut($tag, 'href') |
|
| 2386 | - ) { |
|
| 2387 | - $s[] = preg_replace( |
|
| 2388 | - ',>[^<]+</a>,S', |
|
| 2389 | - '>' |
|
| 2390 | - . http_img_pack( |
|
| 2391 | - 'attachment-16.png', |
|
| 2392 | - $t, |
|
| 2393 | - 'title="' . attribut_html($t) . '"' |
|
| 2394 | - ) |
|
| 2395 | - . '</a>', |
|
| 2396 | - $tag |
|
| 2397 | - ); |
|
| 2398 | - } |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - return join(' ', $s); |
|
| 2381 | + $s = []; |
|
| 2382 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2383 | + if ( |
|
| 2384 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2385 | + and $t = extraire_attribut($tag, 'href') |
|
| 2386 | + ) { |
|
| 2387 | + $s[] = preg_replace( |
|
| 2388 | + ',>[^<]+</a>,S', |
|
| 2389 | + '>' |
|
| 2390 | + . http_img_pack( |
|
| 2391 | + 'attachment-16.png', |
|
| 2392 | + $t, |
|
| 2393 | + 'title="' . attribut_html($t) . '"' |
|
| 2394 | + ) |
|
| 2395 | + . '</a>', |
|
| 2396 | + $tag |
|
| 2397 | + ); |
|
| 2398 | + } |
|
| 2399 | + } |
|
| 2400 | + |
|
| 2401 | + return join(' ', $s); |
|
| 2402 | 2402 | } |
| 2403 | 2403 | |
| 2404 | 2404 | /** |
@@ -2413,15 +2413,15 @@ discard block |
||
| 2413 | 2413 | * @return string Liens trouvés |
| 2414 | 2414 | **/ |
| 2415 | 2415 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2416 | - $s = []; |
|
| 2417 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2418 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2419 | - if (strstr(",$rels,", ",$rel,")) { |
|
| 2420 | - $s[] = $tag; |
|
| 2421 | - } |
|
| 2422 | - } |
|
| 2416 | + $s = []; |
|
| 2417 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2418 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2419 | + if (strstr(",$rels,", ",$rel,")) { |
|
| 2420 | + $s[] = $tag; |
|
| 2421 | + } |
|
| 2422 | + } |
|
| 2423 | 2423 | |
| 2424 | - return join(', ', $s); |
|
| 2424 | + return join(', ', $s); |
|
| 2425 | 2425 | } |
| 2426 | 2426 | |
| 2427 | 2427 | |
@@ -2443,21 +2443,21 @@ discard block |
||
| 2443 | 2443 | * @return string Tag HTML `<a>` avec microformat. |
| 2444 | 2444 | **/ |
| 2445 | 2445 | function enclosure2microformat($e) { |
| 2446 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2447 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2448 | - } |
|
| 2449 | - $type = extraire_attribut($e, 'type'); |
|
| 2450 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2451 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2452 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2453 | - } |
|
| 2454 | - $fichier = basename($url); |
|
| 2446 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2447 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2448 | + } |
|
| 2449 | + $type = extraire_attribut($e, 'type'); |
|
| 2450 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2451 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2452 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2453 | + } |
|
| 2454 | + $fichier = basename($url); |
|
| 2455 | 2455 | |
| 2456 | - return '<a rel="enclosure"' |
|
| 2457 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2458 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2459 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2460 | - . '>' . $fichier . '</a>'; |
|
| 2456 | + return '<a rel="enclosure"' |
|
| 2457 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2458 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2459 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2460 | + . '>' . $fichier . '</a>'; |
|
| 2461 | 2461 | } |
| 2462 | 2462 | |
| 2463 | 2463 | /** |
@@ -2475,24 +2475,24 @@ discard block |
||
| 2475 | 2475 | * @return string Tags RSS `<enclosure>`. |
| 2476 | 2476 | **/ |
| 2477 | 2477 | function microformat2enclosure($tags) { |
| 2478 | - $enclosures = []; |
|
| 2479 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2480 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2481 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2482 | - $type = extraire_attribut($e, 'type'); |
|
| 2483 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2484 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2485 | - } # vieux data |
|
| 2486 | - $fichier = basename($url); |
|
| 2487 | - $enclosures[] = '<enclosure' |
|
| 2488 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2489 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2490 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2491 | - . ' />'; |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2478 | + $enclosures = []; |
|
| 2479 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2480 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2481 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2482 | + $type = extraire_attribut($e, 'type'); |
|
| 2483 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2484 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2485 | + } # vieux data |
|
| 2486 | + $fichier = basename($url); |
|
| 2487 | + $enclosures[] = '<enclosure' |
|
| 2488 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2489 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2490 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2491 | + . ' />'; |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | 2494 | |
| 2495 | - return join("\n", $enclosures); |
|
| 2495 | + return join("\n", $enclosures); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | |
@@ -2508,16 +2508,16 @@ discard block |
||
| 2508 | 2508 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2509 | 2509 | **/ |
| 2510 | 2510 | function tags2dcsubject($tags) { |
| 2511 | - $subjects = ''; |
|
| 2512 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2513 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2514 | - $subjects .= '<dc:subject>' |
|
| 2515 | - . texte_backend(textebrut($e)) |
|
| 2516 | - . '</dc:subject>' . "\n"; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2511 | + $subjects = ''; |
|
| 2512 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2513 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2514 | + $subjects .= '<dc:subject>' |
|
| 2515 | + . texte_backend(textebrut($e)) |
|
| 2516 | + . '</dc:subject>' . "\n"; |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | 2519 | |
| 2520 | - return $subjects; |
|
| 2520 | + return $subjects; |
|
| 2521 | 2521 | } |
| 2522 | 2522 | |
| 2523 | 2523 | /** |
@@ -2546,27 +2546,27 @@ discard block |
||
| 2546 | 2546 | * - Tableau de résultats, si tableau en entrée. |
| 2547 | 2547 | **/ |
| 2548 | 2548 | function extraire_balise($texte, $tag = 'a') { |
| 2549 | - if (is_array($texte)) { |
|
| 2550 | - array_walk( |
|
| 2551 | - $texte, |
|
| 2552 | - function (&$a, $key, $t) { |
|
| 2553 | - $a = extraire_balise($a, $t); |
|
| 2554 | - }, |
|
| 2555 | - $tag |
|
| 2556 | - ); |
|
| 2557 | - |
|
| 2558 | - return $texte; |
|
| 2559 | - } |
|
| 2560 | - |
|
| 2561 | - if ( |
|
| 2562 | - preg_match( |
|
| 2563 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2564 | - $texte, |
|
| 2565 | - $regs |
|
| 2566 | - ) |
|
| 2567 | - ) { |
|
| 2568 | - return $regs[0]; |
|
| 2569 | - } |
|
| 2549 | + if (is_array($texte)) { |
|
| 2550 | + array_walk( |
|
| 2551 | + $texte, |
|
| 2552 | + function (&$a, $key, $t) { |
|
| 2553 | + $a = extraire_balise($a, $t); |
|
| 2554 | + }, |
|
| 2555 | + $tag |
|
| 2556 | + ); |
|
| 2557 | + |
|
| 2558 | + return $texte; |
|
| 2559 | + } |
|
| 2560 | + |
|
| 2561 | + if ( |
|
| 2562 | + preg_match( |
|
| 2563 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2564 | + $texte, |
|
| 2565 | + $regs |
|
| 2566 | + ) |
|
| 2567 | + ) { |
|
| 2568 | + return $regs[0]; |
|
| 2569 | + } |
|
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | /** |
@@ -2594,30 +2594,30 @@ discard block |
||
| 2594 | 2594 | * - Tableau de résultats, si tableau en entrée. |
| 2595 | 2595 | **/ |
| 2596 | 2596 | function extraire_balises($texte, $tag = 'a') { |
| 2597 | - if (is_array($texte)) { |
|
| 2598 | - array_walk( |
|
| 2599 | - $texte, |
|
| 2600 | - function (&$a, $key, $t) { |
|
| 2601 | - $a = extraire_balises($a, $t); |
|
| 2602 | - }, |
|
| 2603 | - $tag |
|
| 2604 | - ); |
|
| 2605 | - |
|
| 2606 | - return $texte; |
|
| 2607 | - } |
|
| 2608 | - |
|
| 2609 | - if ( |
|
| 2610 | - preg_match_all( |
|
| 2611 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2612 | - $texte, |
|
| 2613 | - $regs, |
|
| 2614 | - PREG_PATTERN_ORDER |
|
| 2615 | - ) |
|
| 2616 | - ) { |
|
| 2617 | - return $regs[0]; |
|
| 2618 | - } else { |
|
| 2619 | - return []; |
|
| 2620 | - } |
|
| 2597 | + if (is_array($texte)) { |
|
| 2598 | + array_walk( |
|
| 2599 | + $texte, |
|
| 2600 | + function (&$a, $key, $t) { |
|
| 2601 | + $a = extraire_balises($a, $t); |
|
| 2602 | + }, |
|
| 2603 | + $tag |
|
| 2604 | + ); |
|
| 2605 | + |
|
| 2606 | + return $texte; |
|
| 2607 | + } |
|
| 2608 | + |
|
| 2609 | + if ( |
|
| 2610 | + preg_match_all( |
|
| 2611 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2612 | + $texte, |
|
| 2613 | + $regs, |
|
| 2614 | + PREG_PATTERN_ORDER |
|
| 2615 | + ) |
|
| 2616 | + ) { |
|
| 2617 | + return $regs[0]; |
|
| 2618 | + } else { |
|
| 2619 | + return []; |
|
| 2620 | + } |
|
| 2621 | 2621 | } |
| 2622 | 2622 | |
| 2623 | 2623 | /** |
@@ -2646,11 +2646,11 @@ discard block |
||
| 2646 | 2646 | * - `$def` si on n'a pas transmis de tableau |
| 2647 | 2647 | **/ |
| 2648 | 2648 | function in_any($val, $vals, $def = '') { |
| 2649 | - if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2650 | - $vals = $v; |
|
| 2651 | - } |
|
| 2649 | + if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2650 | + $vals = $v; |
|
| 2651 | + } |
|
| 2652 | 2652 | |
| 2653 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2653 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2654 | 2654 | } |
| 2655 | 2655 | |
| 2656 | 2656 | |
@@ -2671,12 +2671,12 @@ discard block |
||
| 2671 | 2671 | * Résultat du calcul |
| 2672 | 2672 | **/ |
| 2673 | 2673 | function valeur_numerique($expr) { |
| 2674 | - $a = 0; |
|
| 2675 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2676 | - eval("\$a = $expr;"); |
|
| 2677 | - } |
|
| 2674 | + $a = 0; |
|
| 2675 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2676 | + eval("\$a = $expr;"); |
|
| 2677 | + } |
|
| 2678 | 2678 | |
| 2679 | - return intval($a); |
|
| 2679 | + return intval($a); |
|
| 2680 | 2680 | } |
| 2681 | 2681 | |
| 2682 | 2682 | /** |
@@ -2695,7 +2695,7 @@ discard block |
||
| 2695 | 2695 | * Retourne `$a*$b/$c` |
| 2696 | 2696 | **/ |
| 2697 | 2697 | function regledetrois($a, $b, $c) { |
| 2698 | - return round($a * $b / $c); |
|
| 2698 | + return round($a * $b / $c); |
|
| 2699 | 2699 | } |
| 2700 | 2700 | |
| 2701 | 2701 | |
@@ -2719,77 +2719,77 @@ discard block |
||
| 2719 | 2719 | **/ |
| 2720 | 2720 | function form_hidden($action) { |
| 2721 | 2721 | |
| 2722 | - $contexte = []; |
|
| 2723 | - include_spip('inc/urls'); |
|
| 2724 | - if ( |
|
| 2725 | - $p = urls_decoder_url($action, '') |
|
| 2726 | - and reset($p) |
|
| 2727 | - ) { |
|
| 2728 | - $fond = array_shift($p); |
|
| 2729 | - if ($fond != '404') { |
|
| 2730 | - $contexte = array_shift($p); |
|
| 2731 | - $contexte['page'] = $fond; |
|
| 2732 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2733 | - } |
|
| 2734 | - } |
|
| 2735 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2736 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2737 | - unset($contexte['type']); |
|
| 2738 | - } |
|
| 2739 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2740 | - unset($contexte['type-page']); |
|
| 2741 | - } |
|
| 2742 | - |
|
| 2743 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2744 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2745 | - $values = []; |
|
| 2746 | - |
|
| 2747 | - // d'abord avec celles de l'url |
|
| 2748 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2749 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2750 | - $c = explode('=', $c, 2); |
|
| 2751 | - $var = array_shift($c); |
|
| 2752 | - $val = array_shift($c); |
|
| 2753 | - if ($var) { |
|
| 2754 | - $val = rawurldecode($val); |
|
| 2755 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2756 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2757 | - $values[] = [$var, $val]; |
|
| 2758 | - } else { |
|
| 2759 | - if (!isset($values[$var])) { |
|
| 2760 | - $values[$var] = [$var, $val]; |
|
| 2761 | - } |
|
| 2762 | - } |
|
| 2763 | - } |
|
| 2764 | - } |
|
| 2765 | - } |
|
| 2766 | - |
|
| 2767 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2768 | - foreach ($contexte as $var => $val) { |
|
| 2769 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2770 | - $values[] = [$var, $val]; |
|
| 2771 | - } else { |
|
| 2772 | - if (!isset($values[$var])) { |
|
| 2773 | - $values[$var] = [$var, $val]; |
|
| 2774 | - } |
|
| 2775 | - } |
|
| 2776 | - } |
|
| 2777 | - |
|
| 2778 | - // puis on rassemble le tout |
|
| 2779 | - $hidden = []; |
|
| 2780 | - foreach ($values as $value) { |
|
| 2781 | - list($var, $val) = $value; |
|
| 2782 | - $hidden[] = '<input name="' |
|
| 2783 | - . entites_html($var) |
|
| 2784 | - . '"' |
|
| 2785 | - . (is_null($val) |
|
| 2786 | - ? '' |
|
| 2787 | - : ' value="' . entites_html($val) . '"' |
|
| 2788 | - ) |
|
| 2789 | - . ' type="hidden"' . "\n/>"; |
|
| 2790 | - } |
|
| 2791 | - |
|
| 2792 | - return join('', $hidden); |
|
| 2722 | + $contexte = []; |
|
| 2723 | + include_spip('inc/urls'); |
|
| 2724 | + if ( |
|
| 2725 | + $p = urls_decoder_url($action, '') |
|
| 2726 | + and reset($p) |
|
| 2727 | + ) { |
|
| 2728 | + $fond = array_shift($p); |
|
| 2729 | + if ($fond != '404') { |
|
| 2730 | + $contexte = array_shift($p); |
|
| 2731 | + $contexte['page'] = $fond; |
|
| 2732 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2733 | + } |
|
| 2734 | + } |
|
| 2735 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2736 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2737 | + unset($contexte['type']); |
|
| 2738 | + } |
|
| 2739 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2740 | + unset($contexte['type-page']); |
|
| 2741 | + } |
|
| 2742 | + |
|
| 2743 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2744 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2745 | + $values = []; |
|
| 2746 | + |
|
| 2747 | + // d'abord avec celles de l'url |
|
| 2748 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2749 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2750 | + $c = explode('=', $c, 2); |
|
| 2751 | + $var = array_shift($c); |
|
| 2752 | + $val = array_shift($c); |
|
| 2753 | + if ($var) { |
|
| 2754 | + $val = rawurldecode($val); |
|
| 2755 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2756 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2757 | + $values[] = [$var, $val]; |
|
| 2758 | + } else { |
|
| 2759 | + if (!isset($values[$var])) { |
|
| 2760 | + $values[$var] = [$var, $val]; |
|
| 2761 | + } |
|
| 2762 | + } |
|
| 2763 | + } |
|
| 2764 | + } |
|
| 2765 | + } |
|
| 2766 | + |
|
| 2767 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2768 | + foreach ($contexte as $var => $val) { |
|
| 2769 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2770 | + $values[] = [$var, $val]; |
|
| 2771 | + } else { |
|
| 2772 | + if (!isset($values[$var])) { |
|
| 2773 | + $values[$var] = [$var, $val]; |
|
| 2774 | + } |
|
| 2775 | + } |
|
| 2776 | + } |
|
| 2777 | + |
|
| 2778 | + // puis on rassemble le tout |
|
| 2779 | + $hidden = []; |
|
| 2780 | + foreach ($values as $value) { |
|
| 2781 | + list($var, $val) = $value; |
|
| 2782 | + $hidden[] = '<input name="' |
|
| 2783 | + . entites_html($var) |
|
| 2784 | + . '"' |
|
| 2785 | + . (is_null($val) |
|
| 2786 | + ? '' |
|
| 2787 | + : ' value="' . entites_html($val) . '"' |
|
| 2788 | + ) |
|
| 2789 | + . ' type="hidden"' . "\n/>"; |
|
| 2790 | + } |
|
| 2791 | + |
|
| 2792 | + return join('', $hidden); |
|
| 2793 | 2793 | } |
| 2794 | 2794 | |
| 2795 | 2795 | |
@@ -2811,7 +2811,7 @@ discard block |
||
| 2811 | 2811 | * - la première valeur du tableau sinon. |
| 2812 | 2812 | **/ |
| 2813 | 2813 | function filtre_reset($array) { |
| 2814 | - return !is_array($array) ? null : reset($array); |
|
| 2814 | + return !is_array($array) ? null : reset($array); |
|
| 2815 | 2815 | } |
| 2816 | 2816 | |
| 2817 | 2817 | /** |
@@ -2832,7 +2832,7 @@ discard block |
||
| 2832 | 2832 | * - la dernière valeur du tableau sinon. |
| 2833 | 2833 | **/ |
| 2834 | 2834 | function filtre_end($array) { |
| 2835 | - return !is_array($array) ? null : end($array); |
|
| 2835 | + return !is_array($array) ? null : end($array); |
|
| 2836 | 2836 | } |
| 2837 | 2837 | |
| 2838 | 2838 | /** |
@@ -2852,11 +2852,11 @@ discard block |
||
| 2852 | 2852 | * |
| 2853 | 2853 | **/ |
| 2854 | 2854 | function filtre_push($array, $val) { |
| 2855 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2856 | - return ''; |
|
| 2857 | - } |
|
| 2855 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2856 | + return ''; |
|
| 2857 | + } |
|
| 2858 | 2858 | |
| 2859 | - return $array; |
|
| 2859 | + return $array; |
|
| 2860 | 2860 | } |
| 2861 | 2861 | |
| 2862 | 2862 | /** |
@@ -2875,7 +2875,7 @@ discard block |
||
| 2875 | 2875 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2876 | 2876 | **/ |
| 2877 | 2877 | function filtre_find($array, $val) { |
| 2878 | - return (is_array($array) and in_array($val, $array)); |
|
| 2878 | + return (is_array($array) and in_array($val, $array)); |
|
| 2879 | 2879 | } |
| 2880 | 2880 | |
| 2881 | 2881 | |
@@ -2892,15 +2892,15 @@ discard block |
||
| 2892 | 2892 | * Contenu avec urls en absolus |
| 2893 | 2893 | **/ |
| 2894 | 2894 | function urls_absolues_css($contenu, $source) { |
| 2895 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2895 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2896 | 2896 | |
| 2897 | - return preg_replace_callback( |
|
| 2898 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2899 | - function ($x) use ($path) { |
|
| 2900 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2901 | - }, |
|
| 2902 | - $contenu |
|
| 2903 | - ); |
|
| 2897 | + return preg_replace_callback( |
|
| 2898 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2899 | + function ($x) use ($path) { |
|
| 2900 | + return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2901 | + }, |
|
| 2902 | + $contenu |
|
| 2903 | + ); |
|
| 2904 | 2904 | } |
| 2905 | 2905 | |
| 2906 | 2906 | |
@@ -2929,119 +2929,119 @@ discard block |
||
| 2929 | 2929 | * Chemin du fichier CSS inversé |
| 2930 | 2930 | **/ |
| 2931 | 2931 | function direction_css($css, $voulue = '') { |
| 2932 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2933 | - return $css; |
|
| 2934 | - } |
|
| 2935 | - include_spip('inc/lang'); |
|
| 2936 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2937 | - if ($voulue = strtolower($voulue)) { |
|
| 2938 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2939 | - $voulue = lang_dir($voulue); |
|
| 2940 | - } |
|
| 2941 | - } else { |
|
| 2942 | - $voulue = lang_dir(); |
|
| 2943 | - } |
|
| 2944 | - |
|
| 2945 | - $r = count($r) > 1; |
|
| 2946 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2947 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2948 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2949 | - |
|
| 2950 | - if ($voulue == $dir) { |
|
| 2951 | - return $css; |
|
| 2952 | - } |
|
| 2953 | - |
|
| 2954 | - if ( |
|
| 2955 | - // url absolue |
|
| 2956 | - preg_match(',^https?:,i', $css) |
|
| 2957 | - // ou qui contient un ? |
|
| 2958 | - or (($p = strpos($css, '?')) !== false) |
|
| 2959 | - ) { |
|
| 2960 | - $distant = true; |
|
| 2961 | - $cssf = parse_url($css); |
|
| 2962 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2963 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2964 | - } else { |
|
| 2965 | - $distant = false; |
|
| 2966 | - $cssf = $css; |
|
| 2967 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2968 | - //propose (rien a faire dans ce cas) |
|
| 2969 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2970 | - if (@file_exists($f)) { |
|
| 2971 | - return $f; |
|
| 2972 | - } |
|
| 2973 | - } |
|
| 2974 | - |
|
| 2975 | - // 2. |
|
| 2976 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2977 | - $f = $dir_var |
|
| 2978 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2979 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2980 | - |
|
| 2981 | - // la css peut etre distante (url absolue !) |
|
| 2982 | - if ($distant) { |
|
| 2983 | - include_spip('inc/distant'); |
|
| 2984 | - $res = recuperer_url($css); |
|
| 2985 | - if (!$res or !$contenu = $res['page']) { |
|
| 2986 | - return $css; |
|
| 2987 | - } |
|
| 2988 | - } else { |
|
| 2989 | - if ( |
|
| 2990 | - (@filemtime($f) > @filemtime($css)) |
|
| 2991 | - and (_VAR_MODE != 'recalcul') |
|
| 2992 | - ) { |
|
| 2993 | - return $f; |
|
| 2994 | - } |
|
| 2995 | - if (!lire_fichier($css, $contenu)) { |
|
| 2996 | - return $css; |
|
| 2997 | - } |
|
| 2998 | - } |
|
| 2999 | - |
|
| 3000 | - |
|
| 3001 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3002 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3003 | - $parser = new csstidy(); |
|
| 3004 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3005 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3006 | - $parser->parse($contenu); |
|
| 3007 | - |
|
| 3008 | - $contenu = $parser->print->plain(); |
|
| 3009 | - |
|
| 3010 | - |
|
| 3011 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3012 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3013 | - $src = []; |
|
| 3014 | - $src_direction_css = []; |
|
| 3015 | - $src_faux_abs = []; |
|
| 3016 | - $d = dirname($css); |
|
| 3017 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3018 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3019 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3020 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3021 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3022 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3023 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3024 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3025 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3026 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3027 | - } |
|
| 3028 | - $src[] = $regs[0][$k]; |
|
| 3029 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3030 | - } |
|
| 3031 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3032 | - |
|
| 3033 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3034 | - |
|
| 3035 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3036 | - if (count($src_faux_abs)) { |
|
| 3037 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3038 | - } |
|
| 3039 | - |
|
| 3040 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3041 | - return $css; |
|
| 3042 | - } |
|
| 3043 | - |
|
| 3044 | - return $f; |
|
| 2932 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2933 | + return $css; |
|
| 2934 | + } |
|
| 2935 | + include_spip('inc/lang'); |
|
| 2936 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2937 | + if ($voulue = strtolower($voulue)) { |
|
| 2938 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2939 | + $voulue = lang_dir($voulue); |
|
| 2940 | + } |
|
| 2941 | + } else { |
|
| 2942 | + $voulue = lang_dir(); |
|
| 2943 | + } |
|
| 2944 | + |
|
| 2945 | + $r = count($r) > 1; |
|
| 2946 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2947 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2948 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2949 | + |
|
| 2950 | + if ($voulue == $dir) { |
|
| 2951 | + return $css; |
|
| 2952 | + } |
|
| 2953 | + |
|
| 2954 | + if ( |
|
| 2955 | + // url absolue |
|
| 2956 | + preg_match(',^https?:,i', $css) |
|
| 2957 | + // ou qui contient un ? |
|
| 2958 | + or (($p = strpos($css, '?')) !== false) |
|
| 2959 | + ) { |
|
| 2960 | + $distant = true; |
|
| 2961 | + $cssf = parse_url($css); |
|
| 2962 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2963 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2964 | + } else { |
|
| 2965 | + $distant = false; |
|
| 2966 | + $cssf = $css; |
|
| 2967 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2968 | + //propose (rien a faire dans ce cas) |
|
| 2969 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2970 | + if (@file_exists($f)) { |
|
| 2971 | + return $f; |
|
| 2972 | + } |
|
| 2973 | + } |
|
| 2974 | + |
|
| 2975 | + // 2. |
|
| 2976 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2977 | + $f = $dir_var |
|
| 2978 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2979 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2980 | + |
|
| 2981 | + // la css peut etre distante (url absolue !) |
|
| 2982 | + if ($distant) { |
|
| 2983 | + include_spip('inc/distant'); |
|
| 2984 | + $res = recuperer_url($css); |
|
| 2985 | + if (!$res or !$contenu = $res['page']) { |
|
| 2986 | + return $css; |
|
| 2987 | + } |
|
| 2988 | + } else { |
|
| 2989 | + if ( |
|
| 2990 | + (@filemtime($f) > @filemtime($css)) |
|
| 2991 | + and (_VAR_MODE != 'recalcul') |
|
| 2992 | + ) { |
|
| 2993 | + return $f; |
|
| 2994 | + } |
|
| 2995 | + if (!lire_fichier($css, $contenu)) { |
|
| 2996 | + return $css; |
|
| 2997 | + } |
|
| 2998 | + } |
|
| 2999 | + |
|
| 3000 | + |
|
| 3001 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3002 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3003 | + $parser = new csstidy(); |
|
| 3004 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3005 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3006 | + $parser->parse($contenu); |
|
| 3007 | + |
|
| 3008 | + $contenu = $parser->print->plain(); |
|
| 3009 | + |
|
| 3010 | + |
|
| 3011 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3012 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3013 | + $src = []; |
|
| 3014 | + $src_direction_css = []; |
|
| 3015 | + $src_faux_abs = []; |
|
| 3016 | + $d = dirname($css); |
|
| 3017 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3018 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3019 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3020 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3021 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3022 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3023 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3024 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3025 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3026 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3027 | + } |
|
| 3028 | + $src[] = $regs[0][$k]; |
|
| 3029 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3030 | + } |
|
| 3031 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3032 | + |
|
| 3033 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3034 | + |
|
| 3035 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3036 | + if (count($src_faux_abs)) { |
|
| 3037 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3038 | + } |
|
| 3039 | + |
|
| 3040 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3041 | + return $css; |
|
| 3042 | + } |
|
| 3043 | + |
|
| 3044 | + return $f; |
|
| 3045 | 3045 | } |
| 3046 | 3046 | |
| 3047 | 3047 | |
@@ -3064,46 +3064,46 @@ discard block |
||
| 3064 | 3064 | * - Chemin ou URL du fichier CSS source sinon. |
| 3065 | 3065 | **/ |
| 3066 | 3066 | function url_absolue_css($css) { |
| 3067 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3068 | - return $css; |
|
| 3069 | - } |
|
| 3067 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3068 | + return $css; |
|
| 3069 | + } |
|
| 3070 | 3070 | |
| 3071 | - $url_absolue_css = url_absolue($css); |
|
| 3071 | + $url_absolue_css = url_absolue($css); |
|
| 3072 | 3072 | |
| 3073 | - $f = basename($css, '.css'); |
|
| 3074 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3075 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3076 | - . '.css'; |
|
| 3073 | + $f = basename($css, '.css'); |
|
| 3074 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3075 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3076 | + . '.css'; |
|
| 3077 | 3077 | |
| 3078 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3079 | - return $f; |
|
| 3080 | - } |
|
| 3078 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3079 | + return $f; |
|
| 3080 | + } |
|
| 3081 | 3081 | |
| 3082 | - if ($url_absolue_css == $css) { |
|
| 3083 | - if ( |
|
| 3084 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3085 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3086 | - ) { |
|
| 3087 | - include_spip('inc/distant'); |
|
| 3088 | - $contenu = recuperer_url($css); |
|
| 3089 | - $contenu = $contenu['page'] ?? ''; |
|
| 3090 | - if (!$contenu) { |
|
| 3091 | - return $css; |
|
| 3092 | - } |
|
| 3093 | - } |
|
| 3094 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3095 | - return $css; |
|
| 3096 | - } |
|
| 3082 | + if ($url_absolue_css == $css) { |
|
| 3083 | + if ( |
|
| 3084 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3085 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3086 | + ) { |
|
| 3087 | + include_spip('inc/distant'); |
|
| 3088 | + $contenu = recuperer_url($css); |
|
| 3089 | + $contenu = $contenu['page'] ?? ''; |
|
| 3090 | + if (!$contenu) { |
|
| 3091 | + return $css; |
|
| 3092 | + } |
|
| 3093 | + } |
|
| 3094 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3095 | + return $css; |
|
| 3096 | + } |
|
| 3097 | 3097 | |
| 3098 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3099 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3098 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3099 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3100 | 3100 | |
| 3101 | - // ecrire la css |
|
| 3102 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3103 | - return $css; |
|
| 3104 | - } |
|
| 3101 | + // ecrire la css |
|
| 3102 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3103 | + return $css; |
|
| 3104 | + } |
|
| 3105 | 3105 | |
| 3106 | - return $f; |
|
| 3106 | + return $f; |
|
| 3107 | 3107 | } |
| 3108 | 3108 | |
| 3109 | 3109 | |
@@ -3137,24 +3137,24 @@ discard block |
||
| 3137 | 3137 | * Valeur trouvée ou valeur par défaut. |
| 3138 | 3138 | **/ |
| 3139 | 3139 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3140 | - foreach (explode('/', $cle) as $k) { |
|
| 3141 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3140 | + foreach (explode('/', $cle) as $k) { |
|
| 3141 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3142 | 3142 | |
| 3143 | - if (is_object($table)) { |
|
| 3144 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3145 | - } elseif (is_array($table)) { |
|
| 3146 | - if ($conserver_null) { |
|
| 3147 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3148 | - } else { |
|
| 3149 | - $table = ($table[$k] ?? $defaut); |
|
| 3150 | - } |
|
| 3151 | - } else { |
|
| 3152 | - $table = $defaut; |
|
| 3153 | - break; |
|
| 3154 | - } |
|
| 3155 | - } |
|
| 3143 | + if (is_object($table)) { |
|
| 3144 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3145 | + } elseif (is_array($table)) { |
|
| 3146 | + if ($conserver_null) { |
|
| 3147 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3148 | + } else { |
|
| 3149 | + $table = ($table[$k] ?? $defaut); |
|
| 3150 | + } |
|
| 3151 | + } else { |
|
| 3152 | + $table = $defaut; |
|
| 3153 | + break; |
|
| 3154 | + } |
|
| 3155 | + } |
|
| 3156 | 3156 | |
| 3157 | - return $table; |
|
| 3157 | + return $table; |
|
| 3158 | 3158 | } |
| 3159 | 3159 | |
| 3160 | 3160 | /** |
@@ -3187,22 +3187,22 @@ discard block |
||
| 3187 | 3187 | * - string : expression trouvée. |
| 3188 | 3188 | **/ |
| 3189 | 3189 | function filtre_match_dist($texte, $expression, $modif = 'UimsS', $capte = 0) { |
| 3190 | - if (intval($modif) and $capte == 0) { |
|
| 3191 | - $capte = $modif; |
|
| 3192 | - $modif = 'UimsS'; |
|
| 3193 | - } |
|
| 3194 | - $expression = str_replace('\/', '/', $expression); |
|
| 3195 | - $expression = str_replace('/', '\/', $expression); |
|
| 3190 | + if (intval($modif) and $capte == 0) { |
|
| 3191 | + $capte = $modif; |
|
| 3192 | + $modif = 'UimsS'; |
|
| 3193 | + } |
|
| 3194 | + $expression = str_replace('\/', '/', $expression); |
|
| 3195 | + $expression = str_replace('/', '\/', $expression); |
|
| 3196 | 3196 | |
| 3197 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3198 | - if (isset($r[$capte])) { |
|
| 3199 | - return $r[$capte]; |
|
| 3200 | - } else { |
|
| 3201 | - return true; |
|
| 3202 | - } |
|
| 3203 | - } |
|
| 3197 | + if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3198 | + if (isset($r[$capte])) { |
|
| 3199 | + return $r[$capte]; |
|
| 3200 | + } else { |
|
| 3201 | + return true; |
|
| 3202 | + } |
|
| 3203 | + } |
|
| 3204 | 3204 | |
| 3205 | - return false; |
|
| 3205 | + return false; |
|
| 3206 | 3206 | } |
| 3207 | 3207 | |
| 3208 | 3208 | |
@@ -3229,10 +3229,10 @@ discard block |
||
| 3229 | 3229 | * Texte |
| 3230 | 3230 | **/ |
| 3231 | 3231 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3232 | - $expression = str_replace('\/', '/', $expression); |
|
| 3233 | - $expression = str_replace('/', '\/', $expression); |
|
| 3232 | + $expression = str_replace('\/', '/', $expression); |
|
| 3233 | + $expression = str_replace('/', '\/', $expression); |
|
| 3234 | 3234 | |
| 3235 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3235 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3236 | 3236 | } |
| 3237 | 3237 | |
| 3238 | 3238 | |
@@ -3250,25 +3250,25 @@ discard block |
||
| 3250 | 3250 | **/ |
| 3251 | 3251 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3252 | 3252 | |
| 3253 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3254 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3253 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3254 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3255 | 3255 | |
| 3256 | - if ( |
|
| 3257 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3258 | - and preg_match_all( |
|
| 3259 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3260 | - $t, |
|
| 3261 | - $matches, |
|
| 3262 | - PREG_PATTERN_ORDER |
|
| 3263 | - ) |
|
| 3264 | - ) { |
|
| 3265 | - if (!isset($doublons['documents'])) { |
|
| 3266 | - $doublons['documents'] = ''; |
|
| 3267 | - } |
|
| 3268 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3269 | - } |
|
| 3256 | + if ( |
|
| 3257 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3258 | + and preg_match_all( |
|
| 3259 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3260 | + $t, |
|
| 3261 | + $matches, |
|
| 3262 | + PREG_PATTERN_ORDER |
|
| 3263 | + ) |
|
| 3264 | + ) { |
|
| 3265 | + if (!isset($doublons['documents'])) { |
|
| 3266 | + $doublons['documents'] = ''; |
|
| 3267 | + } |
|
| 3268 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3269 | + } |
|
| 3270 | 3270 | |
| 3271 | - return $letexte; |
|
| 3271 | + return $letexte; |
|
| 3272 | 3272 | } |
| 3273 | 3273 | |
| 3274 | 3274 | /** |
@@ -3282,7 +3282,7 @@ discard block |
||
| 3282 | 3282 | * @return string Chaîne vide |
| 3283 | 3283 | **/ |
| 3284 | 3284 | function vide($texte) { |
| 3285 | - return ''; |
|
| 3285 | + return ''; |
|
| 3286 | 3286 | } |
| 3287 | 3287 | |
| 3288 | 3288 | // |
@@ -3311,23 +3311,23 @@ discard block |
||
| 3311 | 3311 | * Code HTML résultant |
| 3312 | 3312 | **/ |
| 3313 | 3313 | function env_to_params($env, $ignore_params = []) { |
| 3314 | - $ignore_params = array_merge( |
|
| 3315 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3316 | - $ignore_params |
|
| 3317 | - ); |
|
| 3318 | - if (!is_array($env)) { |
|
| 3319 | - $env = unserialize($env); |
|
| 3320 | - } |
|
| 3321 | - $texte = ''; |
|
| 3322 | - if ($env) { |
|
| 3323 | - foreach ($env as $i => $j) { |
|
| 3324 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3325 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3326 | - } |
|
| 3327 | - } |
|
| 3328 | - } |
|
| 3329 | - |
|
| 3330 | - return $texte; |
|
| 3314 | + $ignore_params = array_merge( |
|
| 3315 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3316 | + $ignore_params |
|
| 3317 | + ); |
|
| 3318 | + if (!is_array($env)) { |
|
| 3319 | + $env = unserialize($env); |
|
| 3320 | + } |
|
| 3321 | + $texte = ''; |
|
| 3322 | + if ($env) { |
|
| 3323 | + foreach ($env as $i => $j) { |
|
| 3324 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3325 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3326 | + } |
|
| 3327 | + } |
|
| 3328 | + } |
|
| 3329 | + |
|
| 3330 | + return $texte; |
|
| 3331 | 3331 | } |
| 3332 | 3332 | |
| 3333 | 3333 | /** |
@@ -3350,23 +3350,23 @@ discard block |
||
| 3350 | 3350 | * Code HTML résultant |
| 3351 | 3351 | **/ |
| 3352 | 3352 | function env_to_attributs($env, $ignore_params = []) { |
| 3353 | - $ignore_params = array_merge( |
|
| 3354 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3355 | - $ignore_params |
|
| 3356 | - ); |
|
| 3357 | - if (!is_array($env)) { |
|
| 3358 | - $env = unserialize($env); |
|
| 3359 | - } |
|
| 3360 | - $texte = ''; |
|
| 3361 | - if ($env) { |
|
| 3362 | - foreach ($env as $i => $j) { |
|
| 3363 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3364 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3365 | - } |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3353 | + $ignore_params = array_merge( |
|
| 3354 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3355 | + $ignore_params |
|
| 3356 | + ); |
|
| 3357 | + if (!is_array($env)) { |
|
| 3358 | + $env = unserialize($env); |
|
| 3359 | + } |
|
| 3360 | + $texte = ''; |
|
| 3361 | + if ($env) { |
|
| 3362 | + foreach ($env as $i => $j) { |
|
| 3363 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3364 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3365 | + } |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3368 | 3368 | |
| 3369 | - return $texte; |
|
| 3369 | + return $texte; |
|
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | 3372 | |
@@ -3384,7 +3384,7 @@ discard block |
||
| 3384 | 3384 | * @return string Chaînes concaténés |
| 3385 | 3385 | **/ |
| 3386 | 3386 | function concat(...$args): string { |
| 3387 | - return join('', $args); |
|
| 3387 | + return join('', $args); |
|
| 3388 | 3388 | } |
| 3389 | 3389 | |
| 3390 | 3390 | |
@@ -3404,23 +3404,23 @@ discard block |
||
| 3404 | 3404 | * Contenu du ou des fichiers, concaténé |
| 3405 | 3405 | **/ |
| 3406 | 3406 | function charge_scripts($files, $script = true) { |
| 3407 | - $flux = ''; |
|
| 3408 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3409 | - if (!is_string($file)) { |
|
| 3410 | - continue; |
|
| 3411 | - } |
|
| 3412 | - if ($script) { |
|
| 3413 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3414 | - } |
|
| 3415 | - if ($file) { |
|
| 3416 | - $path = find_in_path($file); |
|
| 3417 | - if ($path) { |
|
| 3418 | - $flux .= spip_file_get_contents($path); |
|
| 3419 | - } |
|
| 3420 | - } |
|
| 3421 | - } |
|
| 3422 | - |
|
| 3423 | - return $flux; |
|
| 3407 | + $flux = ''; |
|
| 3408 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3409 | + if (!is_string($file)) { |
|
| 3410 | + continue; |
|
| 3411 | + } |
|
| 3412 | + if ($script) { |
|
| 3413 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3414 | + } |
|
| 3415 | + if ($file) { |
|
| 3416 | + $path = find_in_path($file); |
|
| 3417 | + if ($path) { |
|
| 3418 | + $flux .= spip_file_get_contents($path); |
|
| 3419 | + } |
|
| 3420 | + } |
|
| 3421 | + } |
|
| 3422 | + |
|
| 3423 | + return $flux; |
|
| 3424 | 3424 | } |
| 3425 | 3425 | |
| 3426 | 3426 | /** |
@@ -3431,22 +3431,22 @@ discard block |
||
| 3431 | 3431 | * @return string |
| 3432 | 3432 | */ |
| 3433 | 3433 | function http_img_variante_svg_si_possible($img_file) { |
| 3434 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3435 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3436 | - if ( |
|
| 3437 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3438 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3439 | - and file_exists($variante_svg_generique) |
|
| 3440 | - ) { |
|
| 3441 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3442 | - $img_file = $variante_svg_size; |
|
| 3443 | - } |
|
| 3444 | - else { |
|
| 3445 | - $img_file = $variante_svg_generique; |
|
| 3446 | - } |
|
| 3447 | - } |
|
| 3434 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3435 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3436 | + if ( |
|
| 3437 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3438 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3439 | + and file_exists($variante_svg_generique) |
|
| 3440 | + ) { |
|
| 3441 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3442 | + $img_file = $variante_svg_size; |
|
| 3443 | + } |
|
| 3444 | + else { |
|
| 3445 | + $img_file = $variante_svg_generique; |
|
| 3446 | + } |
|
| 3447 | + } |
|
| 3448 | 3448 | |
| 3449 | - return $img_file; |
|
| 3449 | + return $img_file; |
|
| 3450 | 3450 | } |
| 3451 | 3451 | |
| 3452 | 3452 | /** |
@@ -3467,54 +3467,54 @@ discard block |
||
| 3467 | 3467 | */ |
| 3468 | 3468 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3469 | 3469 | |
| 3470 | - $img_file = $img; |
|
| 3471 | - if ($p = strpos($img_file, '?')) { |
|
| 3472 | - $img_file = substr($img_file, 0, $p); |
|
| 3473 | - } |
|
| 3474 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3475 | - $img_file = chemin_image($img); |
|
| 3476 | - } |
|
| 3477 | - else { |
|
| 3478 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3479 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3480 | - } |
|
| 3481 | - } |
|
| 3482 | - if (stripos($atts, 'width') === false) { |
|
| 3483 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3484 | - if ( |
|
| 3485 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3486 | - or $options['utiliser_suffixe_size'] == true |
|
| 3487 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3488 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3489 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3490 | - ) { |
|
| 3491 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3492 | - } else { |
|
| 3493 | - $taille = taille_image($img_file); |
|
| 3494 | - list($hauteur, $largeur) = $taille; |
|
| 3495 | - if (!$hauteur or !$largeur) { |
|
| 3496 | - return ''; |
|
| 3497 | - } |
|
| 3498 | - } |
|
| 3499 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3500 | - } |
|
| 3501 | - |
|
| 3502 | - if (file_exists($img_file)) { |
|
| 3503 | - $img_file = timestamp($img_file); |
|
| 3504 | - } |
|
| 3505 | - if ($alt === false) { |
|
| 3506 | - $alt = ''; |
|
| 3507 | - } |
|
| 3508 | - elseif ($alt or $alt === '') { |
|
| 3509 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3510 | - } |
|
| 3511 | - else { |
|
| 3512 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3513 | - } |
|
| 3514 | - return "<img src='$img_file'$alt" |
|
| 3515 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3516 | - . ' ' . ltrim($atts) |
|
| 3517 | - . ' />'; |
|
| 3470 | + $img_file = $img; |
|
| 3471 | + if ($p = strpos($img_file, '?')) { |
|
| 3472 | + $img_file = substr($img_file, 0, $p); |
|
| 3473 | + } |
|
| 3474 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3475 | + $img_file = chemin_image($img); |
|
| 3476 | + } |
|
| 3477 | + else { |
|
| 3478 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3479 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3480 | + } |
|
| 3481 | + } |
|
| 3482 | + if (stripos($atts, 'width') === false) { |
|
| 3483 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3484 | + if ( |
|
| 3485 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3486 | + or $options['utiliser_suffixe_size'] == true |
|
| 3487 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3488 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3489 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3490 | + ) { |
|
| 3491 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3492 | + } else { |
|
| 3493 | + $taille = taille_image($img_file); |
|
| 3494 | + list($hauteur, $largeur) = $taille; |
|
| 3495 | + if (!$hauteur or !$largeur) { |
|
| 3496 | + return ''; |
|
| 3497 | + } |
|
| 3498 | + } |
|
| 3499 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3500 | + } |
|
| 3501 | + |
|
| 3502 | + if (file_exists($img_file)) { |
|
| 3503 | + $img_file = timestamp($img_file); |
|
| 3504 | + } |
|
| 3505 | + if ($alt === false) { |
|
| 3506 | + $alt = ''; |
|
| 3507 | + } |
|
| 3508 | + elseif ($alt or $alt === '') { |
|
| 3509 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3510 | + } |
|
| 3511 | + else { |
|
| 3512 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3513 | + } |
|
| 3514 | + return "<img src='$img_file'$alt" |
|
| 3515 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3516 | + . ' ' . ltrim($atts) |
|
| 3517 | + . ' />'; |
|
| 3518 | 3518 | } |
| 3519 | 3519 | |
| 3520 | 3520 | /** |
@@ -3526,70 +3526,70 @@ discard block |
||
| 3526 | 3526 | * @return string |
| 3527 | 3527 | */ |
| 3528 | 3528 | function http_style_background($img, $att = '', $size = null) { |
| 3529 | - if ($size and is_numeric($size)) { |
|
| 3530 | - $size = trim($size) . 'px'; |
|
| 3531 | - } |
|
| 3532 | - return " style='background" . |
|
| 3533 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3534 | - . ($size ? "background-size:{$size};" : '') |
|
| 3535 | - . "'"; |
|
| 3529 | + if ($size and is_numeric($size)) { |
|
| 3530 | + $size = trim($size) . 'px'; |
|
| 3531 | + } |
|
| 3532 | + return " style='background" . |
|
| 3533 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3534 | + . ($size ? "background-size:{$size};" : '') |
|
| 3535 | + . "'"; |
|
| 3536 | 3536 | } |
| 3537 | 3537 | |
| 3538 | 3538 | |
| 3539 | 3539 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3540 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3541 | - while (is_null(end($args)) and count($args)) { |
|
| 3542 | - array_pop($args); |
|
| 3543 | - } |
|
| 3544 | - if (!count($args)) { |
|
| 3545 | - return [null, null, null]; |
|
| 3546 | - } |
|
| 3547 | - if (count($args) < 3) { |
|
| 3548 | - $maybe_size = array_pop($args); |
|
| 3549 | - // @2x |
|
| 3550 | - // @1.5x |
|
| 3551 | - // 512 |
|
| 3552 | - // 512x* |
|
| 3553 | - // 512x300 |
|
| 3554 | - if ( |
|
| 3555 | - !strlen($maybe_size) |
|
| 3556 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3557 | - ) { |
|
| 3558 | - $args[] = $maybe_size; |
|
| 3559 | - $maybe_size = null; |
|
| 3560 | - } |
|
| 3561 | - while (count($args) < 2) { |
|
| 3562 | - $args[] = null; // default alt or class |
|
| 3563 | - } |
|
| 3564 | - $args[] = $maybe_size; |
|
| 3565 | - } |
|
| 3566 | - return $args; |
|
| 3540 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3541 | + while (is_null(end($args)) and count($args)) { |
|
| 3542 | + array_pop($args); |
|
| 3543 | + } |
|
| 3544 | + if (!count($args)) { |
|
| 3545 | + return [null, null, null]; |
|
| 3546 | + } |
|
| 3547 | + if (count($args) < 3) { |
|
| 3548 | + $maybe_size = array_pop($args); |
|
| 3549 | + // @2x |
|
| 3550 | + // @1.5x |
|
| 3551 | + // 512 |
|
| 3552 | + // 512x* |
|
| 3553 | + // 512x300 |
|
| 3554 | + if ( |
|
| 3555 | + !strlen($maybe_size) |
|
| 3556 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3557 | + ) { |
|
| 3558 | + $args[] = $maybe_size; |
|
| 3559 | + $maybe_size = null; |
|
| 3560 | + } |
|
| 3561 | + while (count($args) < 2) { |
|
| 3562 | + $args[] = null; // default alt or class |
|
| 3563 | + } |
|
| 3564 | + $args[] = $maybe_size; |
|
| 3565 | + } |
|
| 3566 | + return $args; |
|
| 3567 | 3567 | } |
| 3568 | 3568 | |
| 3569 | 3569 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3570 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3571 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3572 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3573 | - list($h, $w) = taille_image($img); |
|
| 3574 | - $height = intval(round($h / $coef)); |
|
| 3575 | - $width = intval(round($w / $coef)); |
|
| 3576 | - } |
|
| 3577 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3578 | - else { |
|
| 3579 | - $size = explode('x', $size, 2); |
|
| 3580 | - $size = array_map('trim', $size); |
|
| 3581 | - $height = $width = intval(array_shift($size)); |
|
| 3582 | - |
|
| 3583 | - if (count($size) and reset($size)) { |
|
| 3584 | - $height = array_shift($size); |
|
| 3585 | - if ($height === '*') { |
|
| 3586 | - list($h, $w) = taille_image($img); |
|
| 3587 | - $height = intval(round($h * $width / $w)); |
|
| 3588 | - } |
|
| 3589 | - } |
|
| 3590 | - } |
|
| 3591 | - |
|
| 3592 | - return [$width, $height]; |
|
| 3570 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3571 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3572 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3573 | + list($h, $w) = taille_image($img); |
|
| 3574 | + $height = intval(round($h / $coef)); |
|
| 3575 | + $width = intval(round($w / $coef)); |
|
| 3576 | + } |
|
| 3577 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3578 | + else { |
|
| 3579 | + $size = explode('x', $size, 2); |
|
| 3580 | + $size = array_map('trim', $size); |
|
| 3581 | + $height = $width = intval(array_shift($size)); |
|
| 3582 | + |
|
| 3583 | + if (count($size) and reset($size)) { |
|
| 3584 | + $height = array_shift($size); |
|
| 3585 | + if ($height === '*') { |
|
| 3586 | + list($h, $w) = taille_image($img); |
|
| 3587 | + $height = intval(round($h * $width / $w)); |
|
| 3588 | + } |
|
| 3589 | + } |
|
| 3590 | + } |
|
| 3591 | + |
|
| 3592 | + return [$width, $height]; |
|
| 3593 | 3593 | } |
| 3594 | 3594 | |
| 3595 | 3595 | /** |
@@ -3625,43 +3625,43 @@ discard block |
||
| 3625 | 3625 | */ |
| 3626 | 3626 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3627 | 3627 | |
| 3628 | - list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3629 | - |
|
| 3630 | - $img = trim($img); |
|
| 3631 | - if (strpos($img, '<img') === 0) { |
|
| 3632 | - if (!is_null($alt)) { |
|
| 3633 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3634 | - } |
|
| 3635 | - if (!is_null($class)) { |
|
| 3636 | - if (strlen($class)) { |
|
| 3637 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3638 | - } |
|
| 3639 | - else { |
|
| 3640 | - $img = vider_attribut($img, 'class'); |
|
| 3641 | - } |
|
| 3642 | - } |
|
| 3643 | - } |
|
| 3644 | - else { |
|
| 3645 | - $img = http_img_pack( |
|
| 3646 | - $img, |
|
| 3647 | - $alt, |
|
| 3648 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3649 | - '', |
|
| 3650 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3651 | - ); |
|
| 3652 | - if (is_null($alt)) { |
|
| 3653 | - $img = vider_attribut($img, 'alt'); |
|
| 3654 | - } |
|
| 3655 | - } |
|
| 3656 | - |
|
| 3657 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3658 | - list($width, $height) = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3659 | - |
|
| 3660 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3661 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3662 | - } |
|
| 3663 | - |
|
| 3664 | - return $img; |
|
| 3628 | + list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3629 | + |
|
| 3630 | + $img = trim($img); |
|
| 3631 | + if (strpos($img, '<img') === 0) { |
|
| 3632 | + if (!is_null($alt)) { |
|
| 3633 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3634 | + } |
|
| 3635 | + if (!is_null($class)) { |
|
| 3636 | + if (strlen($class)) { |
|
| 3637 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3638 | + } |
|
| 3639 | + else { |
|
| 3640 | + $img = vider_attribut($img, 'class'); |
|
| 3641 | + } |
|
| 3642 | + } |
|
| 3643 | + } |
|
| 3644 | + else { |
|
| 3645 | + $img = http_img_pack( |
|
| 3646 | + $img, |
|
| 3647 | + $alt, |
|
| 3648 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3649 | + '', |
|
| 3650 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3651 | + ); |
|
| 3652 | + if (is_null($alt)) { |
|
| 3653 | + $img = vider_attribut($img, 'alt'); |
|
| 3654 | + } |
|
| 3655 | + } |
|
| 3656 | + |
|
| 3657 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3658 | + list($width, $height) = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3659 | + |
|
| 3660 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3661 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3662 | + } |
|
| 3663 | + |
|
| 3664 | + return $img; |
|
| 3665 | 3665 | } |
| 3666 | 3666 | |
| 3667 | 3667 | |
@@ -3695,79 +3695,79 @@ discard block |
||
| 3695 | 3695 | */ |
| 3696 | 3696 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3697 | 3697 | |
| 3698 | - $img = trim($img); |
|
| 3699 | - $img_file = $img; |
|
| 3700 | - if (strpos($img, '<svg') === false) { |
|
| 3701 | - if ($p = strpos($img_file, '?')) { |
|
| 3702 | - $img_file = substr($img_file, 0, $p); |
|
| 3703 | - } |
|
| 3698 | + $img = trim($img); |
|
| 3699 | + $img_file = $img; |
|
| 3700 | + if (strpos($img, '<svg') === false) { |
|
| 3701 | + if ($p = strpos($img_file, '?')) { |
|
| 3702 | + $img_file = substr($img_file, 0, $p); |
|
| 3703 | + } |
|
| 3704 | 3704 | |
| 3705 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3706 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3707 | - if (tester_url_absolue($img_file)) { |
|
| 3708 | - include_spip('inc/distant'); |
|
| 3709 | - $fichier = copie_locale($img_file); |
|
| 3710 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3711 | - } |
|
| 3705 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3706 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3707 | + if (tester_url_absolue($img_file)) { |
|
| 3708 | + include_spip('inc/distant'); |
|
| 3709 | + $fichier = copie_locale($img_file); |
|
| 3710 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3711 | + } |
|
| 3712 | 3712 | |
| 3713 | - if ( |
|
| 3714 | - !$img_file |
|
| 3715 | - or !file_exists($img_file) |
|
| 3716 | - or !$svg = file_get_contents($img_file) |
|
| 3717 | - ) { |
|
| 3718 | - return ''; |
|
| 3719 | - } |
|
| 3720 | - } |
|
| 3713 | + if ( |
|
| 3714 | + !$img_file |
|
| 3715 | + or !file_exists($img_file) |
|
| 3716 | + or !$svg = file_get_contents($img_file) |
|
| 3717 | + ) { |
|
| 3718 | + return ''; |
|
| 3719 | + } |
|
| 3720 | + } |
|
| 3721 | 3721 | |
| 3722 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3723 | - return ''; |
|
| 3724 | - } |
|
| 3722 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3723 | + return ''; |
|
| 3724 | + } |
|
| 3725 | 3725 | |
| 3726 | - list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3726 | + list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3727 | 3727 | |
| 3728 | - $balise_svg = $match[0]; |
|
| 3729 | - $balise_svg_source = $balise_svg; |
|
| 3728 | + $balise_svg = $match[0]; |
|
| 3729 | + $balise_svg_source = $balise_svg; |
|
| 3730 | 3730 | |
| 3731 | - // entete XML à supprimer |
|
| 3732 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3731 | + // entete XML à supprimer |
|
| 3732 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3733 | 3733 | |
| 3734 | - // IE est toujours mon ami |
|
| 3735 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3734 | + // IE est toujours mon ami |
|
| 3735 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3736 | 3736 | |
| 3737 | - // regler la classe |
|
| 3738 | - if (!is_null($class)) { |
|
| 3739 | - if (strlen($class)) { |
|
| 3740 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3741 | - } |
|
| 3742 | - else { |
|
| 3743 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3744 | - } |
|
| 3745 | - } |
|
| 3737 | + // regler la classe |
|
| 3738 | + if (!is_null($class)) { |
|
| 3739 | + if (strlen($class)) { |
|
| 3740 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3741 | + } |
|
| 3742 | + else { |
|
| 3743 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3744 | + } |
|
| 3745 | + } |
|
| 3746 | 3746 | |
| 3747 | - // regler le alt |
|
| 3748 | - if ($alt) { |
|
| 3749 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3750 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3751 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3752 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3753 | - $balise_svg .= $title; |
|
| 3754 | - } |
|
| 3755 | - else { |
|
| 3756 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3757 | - } |
|
| 3747 | + // regler le alt |
|
| 3748 | + if ($alt) { |
|
| 3749 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3750 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3751 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3752 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3753 | + $balise_svg .= $title; |
|
| 3754 | + } |
|
| 3755 | + else { |
|
| 3756 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3757 | + } |
|
| 3758 | 3758 | |
| 3759 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3759 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3760 | 3760 | |
| 3761 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3762 | - list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3761 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3762 | + list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3763 | 3763 | |
| 3764 | - if (!function_exists('svg_redimensionner')) { |
|
| 3765 | - include_spip('inc/svg'); |
|
| 3766 | - } |
|
| 3767 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3768 | - } |
|
| 3764 | + if (!function_exists('svg_redimensionner')) { |
|
| 3765 | + include_spip('inc/svg'); |
|
| 3766 | + } |
|
| 3767 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3768 | + } |
|
| 3769 | 3769 | |
| 3770 | - return $svg; |
|
| 3770 | + return $svg; |
|
| 3771 | 3771 | } |
| 3772 | 3772 | |
| 3773 | 3773 | |
@@ -3793,18 +3793,18 @@ discard block |
||
| 3793 | 3793 | * Code HTML résultant |
| 3794 | 3794 | **/ |
| 3795 | 3795 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3796 | - $texte = ''; |
|
| 3797 | - if (is_array($tableau)) { |
|
| 3798 | - foreach ($tableau as $k => $v) { |
|
| 3799 | - $res = recuperer_fond( |
|
| 3800 | - 'modeles/' . $modele, |
|
| 3801 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3802 | - ); |
|
| 3803 | - $texte .= $res; |
|
| 3804 | - } |
|
| 3805 | - } |
|
| 3796 | + $texte = ''; |
|
| 3797 | + if (is_array($tableau)) { |
|
| 3798 | + foreach ($tableau as $k => $v) { |
|
| 3799 | + $res = recuperer_fond( |
|
| 3800 | + 'modeles/' . $modele, |
|
| 3801 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3802 | + ); |
|
| 3803 | + $texte .= $res; |
|
| 3804 | + } |
|
| 3805 | + } |
|
| 3806 | 3806 | |
| 3807 | - return $texte; |
|
| 3807 | + return $texte; |
|
| 3808 | 3808 | } |
| 3809 | 3809 | |
| 3810 | 3810 | |
@@ -3829,37 +3829,37 @@ discard block |
||
| 3829 | 3829 | * - tout : retourne toutes les informations du plugin actif |
| 3830 | 3830 | **/ |
| 3831 | 3831 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3832 | - include_spip('inc/plugin'); |
|
| 3833 | - $plugin = strtoupper($plugin); |
|
| 3834 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3835 | - |
|
| 3836 | - if (!$plugin) { |
|
| 3837 | - return serialize(array_keys($plugins_actifs)); |
|
| 3838 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3839 | - return ''; |
|
| 3840 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3841 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3842 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3843 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3844 | - } else { |
|
| 3845 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3846 | - // On prend en compte les extensions |
|
| 3847 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3848 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3849 | - } else { |
|
| 3850 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3851 | - } |
|
| 3852 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3853 | - return ''; |
|
| 3854 | - } |
|
| 3855 | - if ($type_info == 'tout') { |
|
| 3856 | - return $infos; |
|
| 3857 | - } elseif ($type_info == 'est_actif') { |
|
| 3858 | - return $infos ? 1 : 0; |
|
| 3859 | - } else { |
|
| 3860 | - return strval($infos[$type_info]); |
|
| 3861 | - } |
|
| 3862 | - } |
|
| 3832 | + include_spip('inc/plugin'); |
|
| 3833 | + $plugin = strtoupper($plugin); |
|
| 3834 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3835 | + |
|
| 3836 | + if (!$plugin) { |
|
| 3837 | + return serialize(array_keys($plugins_actifs)); |
|
| 3838 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3839 | + return ''; |
|
| 3840 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3841 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3842 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3843 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3844 | + } else { |
|
| 3845 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3846 | + // On prend en compte les extensions |
|
| 3847 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3848 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3849 | + } else { |
|
| 3850 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3851 | + } |
|
| 3852 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3853 | + return ''; |
|
| 3854 | + } |
|
| 3855 | + if ($type_info == 'tout') { |
|
| 3856 | + return $infos; |
|
| 3857 | + } elseif ($type_info == 'est_actif') { |
|
| 3858 | + return $infos ? 1 : 0; |
|
| 3859 | + } else { |
|
| 3860 | + return strval($infos[$type_info]); |
|
| 3861 | + } |
|
| 3862 | + } |
|
| 3863 | 3863 | } |
| 3864 | 3864 | |
| 3865 | 3865 | |
@@ -3886,9 +3886,9 @@ discard block |
||
| 3886 | 3886 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3887 | 3887 | */ |
| 3888 | 3888 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3889 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3889 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3890 | 3890 | |
| 3891 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3891 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3892 | 3892 | } |
| 3893 | 3893 | |
| 3894 | 3894 | |
@@ -3918,19 +3918,19 @@ discard block |
||
| 3918 | 3918 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3919 | 3919 | */ |
| 3920 | 3920 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3921 | - static $puce_statut = null; |
|
| 3922 | - if (!$puce_statut) { |
|
| 3923 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3924 | - } |
|
| 3921 | + static $puce_statut = null; |
|
| 3922 | + if (!$puce_statut) { |
|
| 3923 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3924 | + } |
|
| 3925 | 3925 | |
| 3926 | - return $puce_statut( |
|
| 3927 | - $id_objet, |
|
| 3928 | - $statut, |
|
| 3929 | - $id_parent, |
|
| 3930 | - $objet, |
|
| 3931 | - false, |
|
| 3932 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3933 | - ); |
|
| 3926 | + return $puce_statut( |
|
| 3927 | + $id_objet, |
|
| 3928 | + $statut, |
|
| 3929 | + $id_parent, |
|
| 3930 | + $objet, |
|
| 3931 | + false, |
|
| 3932 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3933 | + ); |
|
| 3934 | 3934 | } |
| 3935 | 3935 | |
| 3936 | 3936 | |
@@ -3957,97 +3957,97 @@ discard block |
||
| 3957 | 3957 | * hash du contexte |
| 3958 | 3958 | */ |
| 3959 | 3959 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3960 | - if ( |
|
| 3961 | - is_string($c) |
|
| 3962 | - and @unserialize($c) !== false |
|
| 3963 | - ) { |
|
| 3964 | - $c = unserialize($c); |
|
| 3965 | - } |
|
| 3966 | - |
|
| 3967 | - // supprimer les parametres debut_x |
|
| 3968 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3969 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3970 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3971 | - if (is_array($c)) { |
|
| 3972 | - foreach ($c as $k => $v) { |
|
| 3973 | - if (strpos($k, 'debut_') === 0) { |
|
| 3974 | - unset($c[$k]); |
|
| 3975 | - } |
|
| 3976 | - } |
|
| 3977 | - } |
|
| 3978 | - |
|
| 3979 | - if (!function_exists('calculer_cle_action')) { |
|
| 3980 | - include_spip('inc/securiser_action'); |
|
| 3981 | - } |
|
| 3982 | - |
|
| 3983 | - $c = serialize($c); |
|
| 3984 | - $cle = calculer_cle_action($form . $c); |
|
| 3985 | - $c = "$cle:$c"; |
|
| 3986 | - |
|
| 3987 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3988 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3989 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3990 | - // que ce qui est toléré. |
|
| 3991 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3992 | - if (!$cache_contextes_ajax) { |
|
| 3993 | - $env = $c; |
|
| 3994 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3995 | - $env = gzdeflate($env); |
|
| 3996 | - } |
|
| 3997 | - $env = _xor($env); |
|
| 3998 | - $env = base64_encode($env); |
|
| 3999 | - $len = strlen($env); |
|
| 4000 | - // Si l’url est trop longue pour le navigateur |
|
| 4001 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4002 | - if ($len > $max_len) { |
|
| 4003 | - $cache_contextes_ajax = true; |
|
| 4004 | - spip_log( |
|
| 4005 | - 'Contextes AJAX forces en fichiers !' |
|
| 4006 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4007 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4008 | - _LOG_AVERTISSEMENT |
|
| 4009 | - ); |
|
| 4010 | - } |
|
| 4011 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4012 | - elseif ( |
|
| 4013 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4014 | - and $max_len < $len |
|
| 4015 | - ) { |
|
| 4016 | - $cache_contextes_ajax = true; |
|
| 4017 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4018 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4019 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4020 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4021 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4022 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4023 | - } |
|
| 4024 | - } |
|
| 4025 | - |
|
| 4026 | - if ($cache_contextes_ajax) { |
|
| 4027 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4028 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4029 | - $md5 = md5($c); |
|
| 4030 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4031 | - $env = $md5; |
|
| 4032 | - } |
|
| 4033 | - |
|
| 4034 | - if ($emboite === null) { |
|
| 4035 | - return $env; |
|
| 4036 | - } |
|
| 4037 | - if (!trim($emboite)) { |
|
| 4038 | - return ''; |
|
| 4039 | - } |
|
| 4040 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4041 | - $r = self(); |
|
| 4042 | - $r = ' data-origin="' . $r . '"'; |
|
| 4043 | - $class = 'ajaxbloc'; |
|
| 4044 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4045 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4046 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4047 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4048 | - } |
|
| 4049 | - |
|
| 4050 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3960 | + if ( |
|
| 3961 | + is_string($c) |
|
| 3962 | + and @unserialize($c) !== false |
|
| 3963 | + ) { |
|
| 3964 | + $c = unserialize($c); |
|
| 3965 | + } |
|
| 3966 | + |
|
| 3967 | + // supprimer les parametres debut_x |
|
| 3968 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3969 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3970 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3971 | + if (is_array($c)) { |
|
| 3972 | + foreach ($c as $k => $v) { |
|
| 3973 | + if (strpos($k, 'debut_') === 0) { |
|
| 3974 | + unset($c[$k]); |
|
| 3975 | + } |
|
| 3976 | + } |
|
| 3977 | + } |
|
| 3978 | + |
|
| 3979 | + if (!function_exists('calculer_cle_action')) { |
|
| 3980 | + include_spip('inc/securiser_action'); |
|
| 3981 | + } |
|
| 3982 | + |
|
| 3983 | + $c = serialize($c); |
|
| 3984 | + $cle = calculer_cle_action($form . $c); |
|
| 3985 | + $c = "$cle:$c"; |
|
| 3986 | + |
|
| 3987 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3988 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3989 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3990 | + // que ce qui est toléré. |
|
| 3991 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3992 | + if (!$cache_contextes_ajax) { |
|
| 3993 | + $env = $c; |
|
| 3994 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3995 | + $env = gzdeflate($env); |
|
| 3996 | + } |
|
| 3997 | + $env = _xor($env); |
|
| 3998 | + $env = base64_encode($env); |
|
| 3999 | + $len = strlen($env); |
|
| 4000 | + // Si l’url est trop longue pour le navigateur |
|
| 4001 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4002 | + if ($len > $max_len) { |
|
| 4003 | + $cache_contextes_ajax = true; |
|
| 4004 | + spip_log( |
|
| 4005 | + 'Contextes AJAX forces en fichiers !' |
|
| 4006 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4007 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4008 | + _LOG_AVERTISSEMENT |
|
| 4009 | + ); |
|
| 4010 | + } |
|
| 4011 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4012 | + elseif ( |
|
| 4013 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4014 | + and $max_len < $len |
|
| 4015 | + ) { |
|
| 4016 | + $cache_contextes_ajax = true; |
|
| 4017 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4018 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4019 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4020 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4021 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4022 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4023 | + } |
|
| 4024 | + } |
|
| 4025 | + |
|
| 4026 | + if ($cache_contextes_ajax) { |
|
| 4027 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4028 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4029 | + $md5 = md5($c); |
|
| 4030 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4031 | + $env = $md5; |
|
| 4032 | + } |
|
| 4033 | + |
|
| 4034 | + if ($emboite === null) { |
|
| 4035 | + return $env; |
|
| 4036 | + } |
|
| 4037 | + if (!trim($emboite)) { |
|
| 4038 | + return ''; |
|
| 4039 | + } |
|
| 4040 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4041 | + $r = self(); |
|
| 4042 | + $r = ' data-origin="' . $r . '"'; |
|
| 4043 | + $class = 'ajaxbloc'; |
|
| 4044 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4045 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4046 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4047 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4048 | + } |
|
| 4049 | + |
|
| 4050 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4051 | 4051 | } |
| 4052 | 4052 | |
| 4053 | 4053 | /** |
@@ -4067,37 +4067,37 @@ discard block |
||
| 4067 | 4067 | * - false : erreur de décodage |
| 4068 | 4068 | */ |
| 4069 | 4069 | function decoder_contexte_ajax($c, $form = '') { |
| 4070 | - if (!function_exists('calculer_cle_action')) { |
|
| 4071 | - include_spip('inc/securiser_action'); |
|
| 4072 | - } |
|
| 4073 | - if ( |
|
| 4074 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4075 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4076 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4077 | - ) { |
|
| 4078 | - $c = $contexte; |
|
| 4079 | - } else { |
|
| 4080 | - $c = @base64_decode($c); |
|
| 4081 | - $c = _xor($c); |
|
| 4082 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4083 | - $c = @gzinflate($c); |
|
| 4084 | - } |
|
| 4085 | - } |
|
| 4086 | - |
|
| 4087 | - // extraire la signature en debut de contexte |
|
| 4088 | - // et la verifier avant de deserializer |
|
| 4089 | - // format : signature:donneesserializees |
|
| 4090 | - if ($p = strpos($c, ':')) { |
|
| 4091 | - $cle = substr($c, 0, $p); |
|
| 4092 | - $c = substr($c, $p + 1); |
|
| 4093 | - |
|
| 4094 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4095 | - $env = @unserialize($c); |
|
| 4096 | - return $env; |
|
| 4097 | - } |
|
| 4098 | - } |
|
| 4099 | - |
|
| 4100 | - return false; |
|
| 4070 | + if (!function_exists('calculer_cle_action')) { |
|
| 4071 | + include_spip('inc/securiser_action'); |
|
| 4072 | + } |
|
| 4073 | + if ( |
|
| 4074 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4075 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4076 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4077 | + ) { |
|
| 4078 | + $c = $contexte; |
|
| 4079 | + } else { |
|
| 4080 | + $c = @base64_decode($c); |
|
| 4081 | + $c = _xor($c); |
|
| 4082 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4083 | + $c = @gzinflate($c); |
|
| 4084 | + } |
|
| 4085 | + } |
|
| 4086 | + |
|
| 4087 | + // extraire la signature en debut de contexte |
|
| 4088 | + // et la verifier avant de deserializer |
|
| 4089 | + // format : signature:donneesserializees |
|
| 4090 | + if ($p = strpos($c, ':')) { |
|
| 4091 | + $cle = substr($c, 0, $p); |
|
| 4092 | + $c = substr($c, $p + 1); |
|
| 4093 | + |
|
| 4094 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4095 | + $env = @unserialize($c); |
|
| 4096 | + return $env; |
|
| 4097 | + } |
|
| 4098 | + } |
|
| 4099 | + |
|
| 4100 | + return false; |
|
| 4101 | 4101 | } |
| 4102 | 4102 | |
| 4103 | 4103 | |
@@ -4115,20 +4115,20 @@ discard block |
||
| 4115 | 4115 | * Message décrypté ou encrypté |
| 4116 | 4116 | **/ |
| 4117 | 4117 | function _xor($message, $key = null) { |
| 4118 | - if (is_null($key)) { |
|
| 4119 | - if (!function_exists('calculer_cle_action')) { |
|
| 4120 | - include_spip('inc/securiser_action'); |
|
| 4121 | - } |
|
| 4122 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4123 | - } |
|
| 4118 | + if (is_null($key)) { |
|
| 4119 | + if (!function_exists('calculer_cle_action')) { |
|
| 4120 | + include_spip('inc/securiser_action'); |
|
| 4121 | + } |
|
| 4122 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4123 | + } |
|
| 4124 | 4124 | |
| 4125 | - $keylen = strlen($key); |
|
| 4126 | - $messagelen = strlen($message); |
|
| 4127 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4128 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4129 | - } |
|
| 4125 | + $keylen = strlen($key); |
|
| 4126 | + $messagelen = strlen($message); |
|
| 4127 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4128 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4129 | + } |
|
| 4130 | 4130 | |
| 4131 | - return $message; |
|
| 4131 | + return $message; |
|
| 4132 | 4132 | } |
| 4133 | 4133 | |
| 4134 | 4134 | /** |
@@ -4142,7 +4142,7 @@ discard block |
||
| 4142 | 4142 | * @return string |
| 4143 | 4143 | */ |
| 4144 | 4144 | function url_reponse_forum($texte) { |
| 4145 | - return $texte; |
|
| 4145 | + return $texte; |
|
| 4146 | 4146 | } |
| 4147 | 4147 | |
| 4148 | 4148 | /** |
@@ -4156,7 +4156,7 @@ discard block |
||
| 4156 | 4156 | * @return string |
| 4157 | 4157 | */ |
| 4158 | 4158 | function url_rss_forum($texte) { |
| 4159 | - return $texte; |
|
| 4159 | + return $texte; |
|
| 4160 | 4160 | } |
| 4161 | 4161 | |
| 4162 | 4162 | |
@@ -4195,37 +4195,37 @@ discard block |
||
| 4195 | 4195 | * Code HTML |
| 4196 | 4196 | */ |
| 4197 | 4197 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4198 | - if ($on) { |
|
| 4199 | - $bal = 'strong'; |
|
| 4200 | - $class = ''; |
|
| 4201 | - $att = ''; |
|
| 4202 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4203 | - // a.active span.selected.active etc.... |
|
| 4204 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4205 | - $on = explode('.', $on); |
|
| 4206 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4207 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4208 | - $bal = array_shift($on); |
|
| 4209 | - $class = implode(' ', $on); |
|
| 4210 | - if ($bal == 'a') { |
|
| 4211 | - $att = 'href="#" '; |
|
| 4212 | - } |
|
| 4213 | - } |
|
| 4214 | - } |
|
| 4215 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4216 | - } else { |
|
| 4217 | - $bal = 'a'; |
|
| 4218 | - $att = "href='$url'" |
|
| 4219 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4220 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4221 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4222 | - . $evt; |
|
| 4223 | - } |
|
| 4224 | - if ($libelle === null) { |
|
| 4225 | - $libelle = $url; |
|
| 4226 | - } |
|
| 4227 | - |
|
| 4228 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4198 | + if ($on) { |
|
| 4199 | + $bal = 'strong'; |
|
| 4200 | + $class = ''; |
|
| 4201 | + $att = ''; |
|
| 4202 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4203 | + // a.active span.selected.active etc.... |
|
| 4204 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4205 | + $on = explode('.', $on); |
|
| 4206 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4207 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4208 | + $bal = array_shift($on); |
|
| 4209 | + $class = implode(' ', $on); |
|
| 4210 | + if ($bal == 'a') { |
|
| 4211 | + $att = 'href="#" '; |
|
| 4212 | + } |
|
| 4213 | + } |
|
| 4214 | + } |
|
| 4215 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4216 | + } else { |
|
| 4217 | + $bal = 'a'; |
|
| 4218 | + $att = "href='$url'" |
|
| 4219 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4220 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4221 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4222 | + . $evt; |
|
| 4223 | + } |
|
| 4224 | + if ($libelle === null) { |
|
| 4225 | + $libelle = $url; |
|
| 4226 | + } |
|
| 4227 | + |
|
| 4228 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4229 | 4229 | } |
| 4230 | 4230 | |
| 4231 | 4231 | |
@@ -4242,39 +4242,39 @@ discard block |
||
| 4242 | 4242 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4243 | 4243 | */ |
| 4244 | 4244 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4245 | - static $local_singulier_ou_pluriel = []; |
|
| 4246 | - |
|
| 4247 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4248 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4249 | - return ''; |
|
| 4250 | - } |
|
| 4251 | - if (!is_array($vars)) { |
|
| 4252 | - return ''; |
|
| 4253 | - } |
|
| 4254 | - |
|
| 4255 | - $langue = $GLOBALS['spip_lang']; |
|
| 4256 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4257 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4258 | - if ( |
|
| 4259 | - $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4260 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4261 | - ) { |
|
| 4262 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4263 | - } |
|
| 4264 | - } |
|
| 4265 | - |
|
| 4266 | - // si on a une surcharge on l'utilise |
|
| 4267 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4268 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4269 | - } |
|
| 4270 | - |
|
| 4271 | - // sinon traitement par defaut |
|
| 4272 | - $vars[$var] = $nb; |
|
| 4273 | - if ($nb >= 2) { |
|
| 4274 | - return _T($chaine_plusieurs, $vars); |
|
| 4275 | - } else { |
|
| 4276 | - return _T($chaine_un, $vars); |
|
| 4277 | - } |
|
| 4245 | + static $local_singulier_ou_pluriel = []; |
|
| 4246 | + |
|
| 4247 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4248 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4249 | + return ''; |
|
| 4250 | + } |
|
| 4251 | + if (!is_array($vars)) { |
|
| 4252 | + return ''; |
|
| 4253 | + } |
|
| 4254 | + |
|
| 4255 | + $langue = $GLOBALS['spip_lang']; |
|
| 4256 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4257 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4258 | + if ( |
|
| 4259 | + $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4260 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4261 | + ) { |
|
| 4262 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4263 | + } |
|
| 4264 | + } |
|
| 4265 | + |
|
| 4266 | + // si on a une surcharge on l'utilise |
|
| 4267 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4268 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4269 | + } |
|
| 4270 | + |
|
| 4271 | + // sinon traitement par defaut |
|
| 4272 | + $vars[$var] = $nb; |
|
| 4273 | + if ($nb >= 2) { |
|
| 4274 | + return _T($chaine_plusieurs, $vars); |
|
| 4275 | + } else { |
|
| 4276 | + return _T($chaine_un, $vars); |
|
| 4277 | + } |
|
| 4278 | 4278 | } |
| 4279 | 4279 | |
| 4280 | 4280 | |
@@ -4302,73 +4302,73 @@ discard block |
||
| 4302 | 4302 | */ |
| 4303 | 4303 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4304 | 4304 | |
| 4305 | - $class_lien = $class_bouton = $class; |
|
| 4306 | - |
|
| 4307 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4308 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4309 | - $class_lien .= ' danger'; |
|
| 4310 | - $class_bouton .= ' btn_danger'; |
|
| 4311 | - } elseif ($fonction == 'rien.gif') { |
|
| 4312 | - $fonction = ''; |
|
| 4313 | - } elseif ($fonction == 'delsafe') { |
|
| 4314 | - $fonction = 'del'; |
|
| 4315 | - } |
|
| 4316 | - |
|
| 4317 | - $fond_origine = $fond; |
|
| 4318 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4319 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4320 | - list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 4321 | - } |
|
| 4322 | - |
|
| 4323 | - // Ajouter le type d'objet dans la classe |
|
| 4324 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4325 | - $class_lien .= " $objet_type"; |
|
| 4326 | - $class_bouton .= " $objet_type"; |
|
| 4327 | - |
|
| 4328 | - // Texte |
|
| 4329 | - $alt = attribut_html($texte); |
|
| 4330 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4331 | - |
|
| 4332 | - // Liens : préparer les classes ajax |
|
| 4333 | - $ajax = ''; |
|
| 4334 | - if ($type === 'lien') { |
|
| 4335 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4336 | - $ajax = 'ajax'; |
|
| 4337 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4338 | - $ajax .= ' preload'; |
|
| 4339 | - } |
|
| 4340 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4341 | - $ajax .= ' nocache'; |
|
| 4342 | - } |
|
| 4343 | - $ajax = " class='$ajax'"; |
|
| 4344 | - } |
|
| 4345 | - } |
|
| 4346 | - |
|
| 4347 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4348 | - $size = 24; |
|
| 4349 | - if ( |
|
| 4350 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4351 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4352 | - ) { |
|
| 4353 | - $size = $match[1]; |
|
| 4354 | - } |
|
| 4355 | - $class_lien .= " s$size"; |
|
| 4356 | - $class_bouton .= " s$size"; |
|
| 4357 | - |
|
| 4358 | - // Icône |
|
| 4359 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4360 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4361 | - |
|
| 4362 | - // Markup final |
|
| 4363 | - if ($type == 'lien') { |
|
| 4364 | - return "<span class='icone $class_lien'>" |
|
| 4365 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4366 | - . $icone |
|
| 4367 | - . "<b>$texte</b>" |
|
| 4368 | - . "</a></span>\n"; |
|
| 4369 | - } else { |
|
| 4370 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4371 | - } |
|
| 4305 | + $class_lien = $class_bouton = $class; |
|
| 4306 | + |
|
| 4307 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4308 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4309 | + $class_lien .= ' danger'; |
|
| 4310 | + $class_bouton .= ' btn_danger'; |
|
| 4311 | + } elseif ($fonction == 'rien.gif') { |
|
| 4312 | + $fonction = ''; |
|
| 4313 | + } elseif ($fonction == 'delsafe') { |
|
| 4314 | + $fonction = 'del'; |
|
| 4315 | + } |
|
| 4316 | + |
|
| 4317 | + $fond_origine = $fond; |
|
| 4318 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4319 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4320 | + list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 4321 | + } |
|
| 4322 | + |
|
| 4323 | + // Ajouter le type d'objet dans la classe |
|
| 4324 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4325 | + $class_lien .= " $objet_type"; |
|
| 4326 | + $class_bouton .= " $objet_type"; |
|
| 4327 | + |
|
| 4328 | + // Texte |
|
| 4329 | + $alt = attribut_html($texte); |
|
| 4330 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4331 | + |
|
| 4332 | + // Liens : préparer les classes ajax |
|
| 4333 | + $ajax = ''; |
|
| 4334 | + if ($type === 'lien') { |
|
| 4335 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4336 | + $ajax = 'ajax'; |
|
| 4337 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4338 | + $ajax .= ' preload'; |
|
| 4339 | + } |
|
| 4340 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4341 | + $ajax .= ' nocache'; |
|
| 4342 | + } |
|
| 4343 | + $ajax = " class='$ajax'"; |
|
| 4344 | + } |
|
| 4345 | + } |
|
| 4346 | + |
|
| 4347 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4348 | + $size = 24; |
|
| 4349 | + if ( |
|
| 4350 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4351 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4352 | + ) { |
|
| 4353 | + $size = $match[1]; |
|
| 4354 | + } |
|
| 4355 | + $class_lien .= " s$size"; |
|
| 4356 | + $class_bouton .= " s$size"; |
|
| 4357 | + |
|
| 4358 | + // Icône |
|
| 4359 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4360 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4361 | + |
|
| 4362 | + // Markup final |
|
| 4363 | + if ($type == 'lien') { |
|
| 4364 | + return "<span class='icone $class_lien'>" |
|
| 4365 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4366 | + . $icone |
|
| 4367 | + . "<b>$texte</b>" |
|
| 4368 | + . "</a></span>\n"; |
|
| 4369 | + } else { |
|
| 4370 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4371 | + } |
|
| 4372 | 4372 | } |
| 4373 | 4373 | |
| 4374 | 4374 | /** |
@@ -4392,7 +4392,7 @@ discard block |
||
| 4392 | 4392 | * Code HTML du lien |
| 4393 | 4393 | **/ |
| 4394 | 4394 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4395 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4395 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4396 | 4396 | } |
| 4397 | 4397 | |
| 4398 | 4398 | /** |
@@ -4427,7 +4427,7 @@ discard block |
||
| 4427 | 4427 | * Code HTML du lien |
| 4428 | 4428 | **/ |
| 4429 | 4429 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4430 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4430 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4431 | 4431 | } |
| 4432 | 4432 | |
| 4433 | 4433 | /** |
@@ -4472,7 +4472,7 @@ discard block |
||
| 4472 | 4472 | * Code HTML du lien |
| 4473 | 4473 | **/ |
| 4474 | 4474 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4475 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4475 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4476 | 4476 | } |
| 4477 | 4477 | |
| 4478 | 4478 | /** |
@@ -4503,7 +4503,7 @@ discard block |
||
| 4503 | 4503 | * Code HTML du lien |
| 4504 | 4504 | **/ |
| 4505 | 4505 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4506 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4506 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4507 | 4507 | } |
| 4508 | 4508 | |
| 4509 | 4509 | /** |
@@ -4534,7 +4534,7 @@ discard block |
||
| 4534 | 4534 | * Code HTML du lien |
| 4535 | 4535 | */ |
| 4536 | 4536 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4537 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4537 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4538 | 4538 | } |
| 4539 | 4539 | |
| 4540 | 4540 | |
@@ -4556,7 +4556,7 @@ discard block |
||
| 4556 | 4556 | * @return array Liste des éléments |
| 4557 | 4557 | */ |
| 4558 | 4558 | function filtre_explode_dist($a, $b) { |
| 4559 | - return explode($b, $a); |
|
| 4559 | + return explode($b, $a); |
|
| 4560 | 4560 | } |
| 4561 | 4561 | |
| 4562 | 4562 | /** |
@@ -4577,7 +4577,7 @@ discard block |
||
| 4577 | 4577 | * @return string Texte |
| 4578 | 4578 | */ |
| 4579 | 4579 | function filtre_implode_dist($a, $b) { |
| 4580 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4580 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4581 | 4581 | } |
| 4582 | 4582 | |
| 4583 | 4583 | /** |
@@ -4586,24 +4586,24 @@ discard block |
||
| 4586 | 4586 | * @return string Code CSS |
| 4587 | 4587 | */ |
| 4588 | 4588 | function bando_images_background() { |
| 4589 | - include_spip('inc/bandeau'); |
|
| 4590 | - // recuperer tous les boutons et leurs images |
|
| 4591 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4589 | + include_spip('inc/bandeau'); |
|
| 4590 | + // recuperer tous les boutons et leurs images |
|
| 4591 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4592 | 4592 | |
| 4593 | - $res = ''; |
|
| 4594 | - foreach ($boutons as $page => $detail) { |
|
| 4595 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4596 | - if (is_array($detail->sousmenu)) { |
|
| 4597 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4598 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4599 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4600 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4601 | - } |
|
| 4602 | - } |
|
| 4603 | - } |
|
| 4604 | - } |
|
| 4593 | + $res = ''; |
|
| 4594 | + foreach ($boutons as $page => $detail) { |
|
| 4595 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4596 | + if (is_array($detail->sousmenu)) { |
|
| 4597 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4598 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4599 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4600 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4601 | + } |
|
| 4602 | + } |
|
| 4603 | + } |
|
| 4604 | + } |
|
| 4605 | 4605 | |
| 4606 | - return $res; |
|
| 4606 | + return $res; |
|
| 4607 | 4607 | } |
| 4608 | 4608 | |
| 4609 | 4609 | /** |
@@ -4628,27 +4628,27 @@ discard block |
||
| 4628 | 4628 | */ |
| 4629 | 4629 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4630 | 4630 | |
| 4631 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4632 | - $class_form = ''; |
|
| 4633 | - if (strpos($class, 'ajax') !== false) { |
|
| 4634 | - $class_form = 'ajax'; |
|
| 4635 | - $class = str_replace('ajax', '', $class); |
|
| 4636 | - } |
|
| 4637 | - $class_btn = 'submit ' . trim($class); |
|
| 4631 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4632 | + $class_form = ''; |
|
| 4633 | + if (strpos($class, 'ajax') !== false) { |
|
| 4634 | + $class_form = 'ajax'; |
|
| 4635 | + $class = str_replace('ajax', '', $class); |
|
| 4636 | + } |
|
| 4637 | + $class_btn = 'submit ' . trim($class); |
|
| 4638 | 4638 | |
| 4639 | - if ($confirm) { |
|
| 4640 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4641 | - if ($callback) { |
|
| 4642 | - $callback = "$confirm?($callback):false"; |
|
| 4643 | - } else { |
|
| 4644 | - $callback = $confirm; |
|
| 4645 | - } |
|
| 4646 | - } |
|
| 4647 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4648 | - $title = $title ? " title='$title'" : ''; |
|
| 4639 | + if ($confirm) { |
|
| 4640 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4641 | + if ($callback) { |
|
| 4642 | + $callback = "$confirm?($callback):false"; |
|
| 4643 | + } else { |
|
| 4644 | + $callback = $confirm; |
|
| 4645 | + } |
|
| 4646 | + } |
|
| 4647 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4648 | + $title = $title ? " title='$title'" : ''; |
|
| 4649 | 4649 | |
| 4650 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4651 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4650 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4651 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4652 | 4652 | } |
| 4653 | 4653 | |
| 4654 | 4654 | /** |
@@ -4671,94 +4671,94 @@ discard block |
||
| 4671 | 4671 | * @return string |
| 4672 | 4672 | */ |
| 4673 | 4673 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4674 | - static $trouver_table = null; |
|
| 4675 | - static $objets; |
|
| 4676 | - |
|
| 4677 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4678 | - $id_objet = intval($id_objet); |
|
| 4679 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4680 | - return ''; |
|
| 4681 | - } |
|
| 4682 | - |
|
| 4683 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4684 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4685 | - return ''; |
|
| 4686 | - } |
|
| 4687 | - |
|
| 4688 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4689 | - if ($info == 'url') { |
|
| 4690 | - return generer_url_entite($id_objet, $type_objet, ...$params); |
|
| 4691 | - } |
|
| 4692 | - |
|
| 4693 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4694 | - $demande_titre = ($info === 'titre'); |
|
| 4695 | - $demande_introduction = ($info === 'introduction'); |
|
| 4696 | - |
|
| 4697 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4698 | - if ( |
|
| 4699 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4700 | - or |
|
| 4701 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4702 | - ) { |
|
| 4703 | - if (!$trouver_table) { |
|
| 4704 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4705 | - } |
|
| 4706 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4707 | - if (!$desc) { |
|
| 4708 | - return $objets[$type_objet] = false; |
|
| 4709 | - } |
|
| 4710 | - |
|
| 4711 | - // Si on demande le titre, on le gere en interne |
|
| 4712 | - $champ_titre = ''; |
|
| 4713 | - if ($demande_titre) { |
|
| 4714 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4715 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4716 | - } |
|
| 4717 | - include_spip('base/abstract_sql'); |
|
| 4718 | - include_spip('base/connect_sql'); |
|
| 4719 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4720 | - '*' . $champ_titre, |
|
| 4721 | - $desc['table_sql'], |
|
| 4722 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4723 | - ); |
|
| 4724 | - |
|
| 4725 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4726 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4727 | - } |
|
| 4728 | - |
|
| 4729 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4730 | - // ajouter la longueur au début des params supplémentaires |
|
| 4731 | - if ($demande_introduction) { |
|
| 4732 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4733 | - array_unshift($params, $introduction_longueur); |
|
| 4734 | - } |
|
| 4735 | - |
|
| 4736 | - // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4737 | - if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4738 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4739 | - } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4740 | - else { |
|
| 4741 | - if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4742 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4743 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4744 | - else { |
|
| 4745 | - $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4746 | - } |
|
| 4747 | - } |
|
| 4748 | - |
|
| 4749 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4750 | - if (!$etoile) { |
|
| 4751 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4752 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4753 | - $info_generee = appliquer_traitement_champ( |
|
| 4754 | - $info_generee, |
|
| 4755 | - $info, |
|
| 4756 | - table_objet($type_objet), |
|
| 4757 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4758 | - ); |
|
| 4759 | - } |
|
| 4760 | - |
|
| 4761 | - return $info_generee; |
|
| 4674 | + static $trouver_table = null; |
|
| 4675 | + static $objets; |
|
| 4676 | + |
|
| 4677 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4678 | + $id_objet = intval($id_objet); |
|
| 4679 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4680 | + return ''; |
|
| 4681 | + } |
|
| 4682 | + |
|
| 4683 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4684 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4685 | + return ''; |
|
| 4686 | + } |
|
| 4687 | + |
|
| 4688 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4689 | + if ($info == 'url') { |
|
| 4690 | + return generer_url_entite($id_objet, $type_objet, ...$params); |
|
| 4691 | + } |
|
| 4692 | + |
|
| 4693 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4694 | + $demande_titre = ($info === 'titre'); |
|
| 4695 | + $demande_introduction = ($info === 'introduction'); |
|
| 4696 | + |
|
| 4697 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4698 | + if ( |
|
| 4699 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4700 | + or |
|
| 4701 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4702 | + ) { |
|
| 4703 | + if (!$trouver_table) { |
|
| 4704 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4705 | + } |
|
| 4706 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4707 | + if (!$desc) { |
|
| 4708 | + return $objets[$type_objet] = false; |
|
| 4709 | + } |
|
| 4710 | + |
|
| 4711 | + // Si on demande le titre, on le gere en interne |
|
| 4712 | + $champ_titre = ''; |
|
| 4713 | + if ($demande_titre) { |
|
| 4714 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4715 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4716 | + } |
|
| 4717 | + include_spip('base/abstract_sql'); |
|
| 4718 | + include_spip('base/connect_sql'); |
|
| 4719 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4720 | + '*' . $champ_titre, |
|
| 4721 | + $desc['table_sql'], |
|
| 4722 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4723 | + ); |
|
| 4724 | + |
|
| 4725 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4726 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4727 | + } |
|
| 4728 | + |
|
| 4729 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4730 | + // ajouter la longueur au début des params supplémentaires |
|
| 4731 | + if ($demande_introduction) { |
|
| 4732 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4733 | + array_unshift($params, $introduction_longueur); |
|
| 4734 | + } |
|
| 4735 | + |
|
| 4736 | + // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4737 | + if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4738 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4739 | + } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4740 | + else { |
|
| 4741 | + if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4742 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4743 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4744 | + else { |
|
| 4745 | + $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4746 | + } |
|
| 4747 | + } |
|
| 4748 | + |
|
| 4749 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4750 | + if (!$etoile) { |
|
| 4751 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4752 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4753 | + $info_generee = appliquer_traitement_champ( |
|
| 4754 | + $info_generee, |
|
| 4755 | + $info, |
|
| 4756 | + table_objet($type_objet), |
|
| 4757 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4758 | + ); |
|
| 4759 | + } |
|
| 4760 | + |
|
| 4761 | + return $info_generee; |
|
| 4762 | 4762 | } |
| 4763 | 4763 | |
| 4764 | 4764 | /** |
@@ -4791,36 +4791,36 @@ discard block |
||
| 4791 | 4791 | */ |
| 4792 | 4792 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, $connect = '') { |
| 4793 | 4793 | |
| 4794 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4795 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4796 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4797 | - if (isset($ligne_sql['chapo'])) { |
|
| 4798 | - $chapo = $ligne_sql['chapo']; |
|
| 4799 | - $texte = strlen($descriptif) ? |
|
| 4800 | - '' : |
|
| 4801 | - "$chapo \n\n $texte"; |
|
| 4802 | - } |
|
| 4794 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4795 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4796 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4797 | + if (isset($ligne_sql['chapo'])) { |
|
| 4798 | + $chapo = $ligne_sql['chapo']; |
|
| 4799 | + $texte = strlen($descriptif) ? |
|
| 4800 | + '' : |
|
| 4801 | + "$chapo \n\n $texte"; |
|
| 4802 | + } |
|
| 4803 | 4803 | |
| 4804 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4805 | - if (!intval($longueur_ou_suite)) { |
|
| 4806 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4807 | - } else { |
|
| 4808 | - $longueur = intval($longueur_ou_suite); |
|
| 4809 | - } |
|
| 4804 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4805 | + if (!intval($longueur_ou_suite)) { |
|
| 4806 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4807 | + } else { |
|
| 4808 | + $longueur = intval($longueur_ou_suite); |
|
| 4809 | + } |
|
| 4810 | 4810 | |
| 4811 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4812 | - // Ex : #INTRODUCTION{...} |
|
| 4813 | - if ( |
|
| 4814 | - is_null($suite) |
|
| 4815 | - and !intval($longueur_ou_suite) |
|
| 4816 | - ) { |
|
| 4817 | - $suite = $longueur_ou_suite; |
|
| 4818 | - } |
|
| 4811 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4812 | + // Ex : #INTRODUCTION{...} |
|
| 4813 | + if ( |
|
| 4814 | + is_null($suite) |
|
| 4815 | + and !intval($longueur_ou_suite) |
|
| 4816 | + ) { |
|
| 4817 | + $suite = $longueur_ou_suite; |
|
| 4818 | + } |
|
| 4819 | 4819 | |
| 4820 | - $f = chercher_filtre('introduction'); |
|
| 4821 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4820 | + $f = chercher_filtre('introduction'); |
|
| 4821 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4822 | 4822 | |
| 4823 | - return $introduction; |
|
| 4823 | + return $introduction; |
|
| 4824 | 4824 | } |
| 4825 | 4825 | |
| 4826 | 4826 | /** |
@@ -4834,44 +4834,44 @@ discard block |
||
| 4834 | 4834 | * @return string |
| 4835 | 4835 | */ |
| 4836 | 4836 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], $connect = '') { |
| 4837 | - if (!$champ) { |
|
| 4838 | - return $texte; |
|
| 4839 | - } |
|
| 4837 | + if (!$champ) { |
|
| 4838 | + return $texte; |
|
| 4839 | + } |
|
| 4840 | 4840 | |
| 4841 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4842 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4843 | - include_fichiers_fonctions(); |
|
| 4841 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4842 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4843 | + include_fichiers_fonctions(); |
|
| 4844 | 4844 | |
| 4845 | - $champ = strtoupper($champ); |
|
| 4846 | - $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4847 | - if (!$traitements or !is_array($traitements)) { |
|
| 4848 | - return $texte; |
|
| 4849 | - } |
|
| 4845 | + $champ = strtoupper($champ); |
|
| 4846 | + $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4847 | + if (!$traitements or !is_array($traitements)) { |
|
| 4848 | + return $texte; |
|
| 4849 | + } |
|
| 4850 | 4850 | |
| 4851 | - $traitement = ''; |
|
| 4852 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4853 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4854 | - $table_objet = table_objet($table_objet); |
|
| 4855 | - if (isset($traitements[$table_objet])) { |
|
| 4856 | - $traitement = $traitements[$table_objet]; |
|
| 4857 | - } |
|
| 4858 | - } |
|
| 4859 | - if (!$traitement and isset($traitements[0])) { |
|
| 4860 | - $traitement = $traitements[0]; |
|
| 4861 | - } |
|
| 4862 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4851 | + $traitement = ''; |
|
| 4852 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4853 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4854 | + $table_objet = table_objet($table_objet); |
|
| 4855 | + if (isset($traitements[$table_objet])) { |
|
| 4856 | + $traitement = $traitements[$table_objet]; |
|
| 4857 | + } |
|
| 4858 | + } |
|
| 4859 | + if (!$traitement and isset($traitements[0])) { |
|
| 4860 | + $traitement = $traitements[0]; |
|
| 4861 | + } |
|
| 4862 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4863 | 4863 | |
| 4864 | - if (!$traitement) { |
|
| 4865 | - return $texte; |
|
| 4866 | - } |
|
| 4864 | + if (!$traitement) { |
|
| 4865 | + return $texte; |
|
| 4866 | + } |
|
| 4867 | 4867 | |
| 4868 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4868 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4869 | 4869 | |
| 4870 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4871 | - $Pile = [0 => $env]; |
|
| 4872 | - eval("\$texte = $traitement;"); |
|
| 4870 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4871 | + $Pile = [0 => $env]; |
|
| 4872 | + eval("\$texte = $traitement;"); |
|
| 4873 | 4873 | |
| 4874 | - return $texte; |
|
| 4874 | + return $texte; |
|
| 4875 | 4875 | } |
| 4876 | 4876 | |
| 4877 | 4877 | |
@@ -4885,21 +4885,21 @@ discard block |
||
| 4885 | 4885 | * @return string |
| 4886 | 4886 | */ |
| 4887 | 4887 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4888 | - include_spip('inc/liens'); |
|
| 4889 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4890 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4891 | - // le raccourcis n'est plus valide |
|
| 4892 | - $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4893 | - // on essaye avec generer_info_entite ? |
|
| 4894 | - if (!strlen($titre) and !$connect) { |
|
| 4895 | - $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4896 | - } |
|
| 4897 | - if (!strlen($titre)) { |
|
| 4898 | - $titre = _T('info_sans_titre'); |
|
| 4899 | - } |
|
| 4900 | - $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4888 | + include_spip('inc/liens'); |
|
| 4889 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4890 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4891 | + // le raccourcis n'est plus valide |
|
| 4892 | + $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4893 | + // on essaye avec generer_info_entite ? |
|
| 4894 | + if (!strlen($titre) and !$connect) { |
|
| 4895 | + $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4896 | + } |
|
| 4897 | + if (!strlen($titre)) { |
|
| 4898 | + $titre = _T('info_sans_titre'); |
|
| 4899 | + } |
|
| 4900 | + $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4901 | 4901 | |
| 4902 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4902 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4903 | 4903 | } |
| 4904 | 4904 | |
| 4905 | 4905 | |
@@ -4916,15 +4916,15 @@ discard block |
||
| 4916 | 4916 | * @return string |
| 4917 | 4917 | */ |
| 4918 | 4918 | function wrap($texte, $wrap) { |
| 4919 | - $balises = extraire_balises($wrap); |
|
| 4920 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | - $texte = $wrap . $texte; |
|
| 4922 | - $regs = array_reverse($regs[1]); |
|
| 4923 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | - $texte = $texte . $wrap; |
|
| 4925 | - } |
|
| 4919 | + $balises = extraire_balises($wrap); |
|
| 4920 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | + $texte = $wrap . $texte; |
|
| 4922 | + $regs = array_reverse($regs[1]); |
|
| 4923 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | + $texte = $texte . $wrap; |
|
| 4925 | + } |
|
| 4926 | 4926 | |
| 4927 | - return $texte; |
|
| 4927 | + return $texte; |
|
| 4928 | 4928 | } |
| 4929 | 4929 | |
| 4930 | 4930 | |
@@ -4944,44 +4944,44 @@ discard block |
||
| 4944 | 4944 | * @return array|mixed|string |
| 4945 | 4945 | */ |
| 4946 | 4946 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4947 | - if (is_string($u)) { |
|
| 4948 | - $u = typo($u); |
|
| 4947 | + if (is_string($u)) { |
|
| 4948 | + $u = typo($u); |
|
| 4949 | 4949 | |
| 4950 | - return $u; |
|
| 4951 | - } |
|
| 4950 | + return $u; |
|
| 4951 | + } |
|
| 4952 | 4952 | |
| 4953 | - // caster $u en array si besoin |
|
| 4954 | - if (is_object($u)) { |
|
| 4955 | - $u = (array)$u; |
|
| 4956 | - } |
|
| 4953 | + // caster $u en array si besoin |
|
| 4954 | + if (is_object($u)) { |
|
| 4955 | + $u = (array)$u; |
|
| 4956 | + } |
|
| 4957 | 4957 | |
| 4958 | - if (is_array($u)) { |
|
| 4959 | - $out = ''; |
|
| 4960 | - // toutes les cles sont numeriques ? |
|
| 4961 | - // et aucun enfant n'est un tableau |
|
| 4962 | - // liste simple separee par des virgules |
|
| 4963 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | - $array_values = array_map('is_array', $u); |
|
| 4965 | - $object_values = array_map('is_object', $u); |
|
| 4966 | - if ( |
|
| 4967 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | - and !array_sum($array_values) |
|
| 4969 | - and !array_sum($object_values) |
|
| 4970 | - ) { |
|
| 4971 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | - } |
|
| 4958 | + if (is_array($u)) { |
|
| 4959 | + $out = ''; |
|
| 4960 | + // toutes les cles sont numeriques ? |
|
| 4961 | + // et aucun enfant n'est un tableau |
|
| 4962 | + // liste simple separee par des virgules |
|
| 4963 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | + $array_values = array_map('is_array', $u); |
|
| 4965 | + $object_values = array_map('is_object', $u); |
|
| 4966 | + if ( |
|
| 4967 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | + and !array_sum($array_values) |
|
| 4969 | + and !array_sum($object_values) |
|
| 4970 | + ) { |
|
| 4971 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | + } |
|
| 4973 | 4973 | |
| 4974 | - // sinon on passe a la ligne et on indente |
|
| 4975 | - $i_str = str_pad('', $indent, ' '); |
|
| 4976 | - foreach ($u as $k => $v) { |
|
| 4977 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | - } |
|
| 4974 | + // sinon on passe a la ligne et on indente |
|
| 4975 | + $i_str = str_pad('', $indent, ' '); |
|
| 4976 | + foreach ($u as $k => $v) { |
|
| 4977 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | + } |
|
| 4979 | 4979 | |
| 4980 | - return $out; |
|
| 4981 | - } |
|
| 4980 | + return $out; |
|
| 4981 | + } |
|
| 4982 | 4982 | |
| 4983 | - // on sait pas quoi faire... |
|
| 4984 | - return $u; |
|
| 4983 | + // on sait pas quoi faire... |
|
| 4984 | + return $u; |
|
| 4985 | 4985 | } |
| 4986 | 4986 | |
| 4987 | 4987 | |
@@ -4994,10 +4994,10 @@ discard block |
||
| 4994 | 4994 | * @return string|array |
| 4995 | 4995 | */ |
| 4996 | 4996 | function objet_info($objet, $info) { |
| 4997 | - $table = table_objet_sql($objet); |
|
| 4998 | - $infos = lister_tables_objets_sql($table); |
|
| 4997 | + $table = table_objet_sql($objet); |
|
| 4998 | + $infos = lister_tables_objets_sql($table); |
|
| 4999 | 4999 | |
| 5000 | - return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 5000 | + return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 5001 | 5001 | } |
| 5002 | 5002 | |
| 5003 | 5003 | /** |
@@ -5012,11 +5012,11 @@ discard block |
||
| 5012 | 5012 | * Texte traduit du comptage, tel que '3 articles' |
| 5013 | 5013 | */ |
| 5014 | 5014 | function objet_afficher_nb($nb, $objet) { |
| 5015 | - if (!$nb) { |
|
| 5016 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | - } else { |
|
| 5018 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | - } |
|
| 5015 | + if (!$nb) { |
|
| 5016 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | + } else { |
|
| 5018 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | + } |
|
| 5020 | 5020 | } |
| 5021 | 5021 | |
| 5022 | 5022 | /** |
@@ -5028,11 +5028,11 @@ discard block |
||
| 5028 | 5028 | * @return string |
| 5029 | 5029 | */ |
| 5030 | 5030 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5031 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | - $icone = chemin_image($icone); |
|
| 5033 | - $balise_img = charger_filtre('balise_img'); |
|
| 5031 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | + $icone = chemin_image($icone); |
|
| 5033 | + $balise_img = charger_filtre('balise_img'); |
|
| 5034 | 5034 | |
| 5035 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5035 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5036 | 5036 | } |
| 5037 | 5037 | |
| 5038 | 5038 | /** |
@@ -5053,12 +5053,12 @@ discard block |
||
| 5053 | 5053 | * @return string |
| 5054 | 5054 | */ |
| 5055 | 5055 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5056 | - $chaine = explode(':', $chaine); |
|
| 5057 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | - return $t; |
|
| 5059 | - } |
|
| 5060 | - $chaine = implode(':', $chaine); |
|
| 5061 | - return _T($chaine, $args, $options); |
|
| 5056 | + $chaine = explode(':', $chaine); |
|
| 5057 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | + return $t; |
|
| 5059 | + } |
|
| 5060 | + $chaine = implode(':', $chaine); |
|
| 5061 | + return _T($chaine, $args, $options); |
|
| 5062 | 5062 | } |
| 5063 | 5063 | |
| 5064 | 5064 | /** |
@@ -5072,18 +5072,18 @@ discard block |
||
| 5072 | 5072 | * @return string Code HTML |
| 5073 | 5073 | */ |
| 5074 | 5074 | function insert_head_css_conditionnel($flux) { |
| 5075 | - if ( |
|
| 5076 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | - ) { |
|
| 5079 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | - $p = $p1; |
|
| 5082 | - } |
|
| 5083 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | - } |
|
| 5075 | + if ( |
|
| 5076 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | + ) { |
|
| 5079 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | + $p = $p1; |
|
| 5082 | + } |
|
| 5083 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | + } |
|
| 5085 | 5085 | |
| 5086 | - return $flux; |
|
| 5086 | + return $flux; |
|
| 5087 | 5087 | } |
| 5088 | 5088 | |
| 5089 | 5089 | /** |
@@ -5106,72 +5106,72 @@ discard block |
||
| 5106 | 5106 | * @return string |
| 5107 | 5107 | */ |
| 5108 | 5108 | function produire_fond_statique($fond, $contexte = [], $options = [], $connect = '') { |
| 5109 | - if (isset($contexte['format'])) { |
|
| 5110 | - $extension = $contexte['format']; |
|
| 5111 | - unset($contexte['format']); |
|
| 5112 | - } else { |
|
| 5113 | - $extension = 'html'; |
|
| 5114 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | - $extension = $m[1]; |
|
| 5116 | - } |
|
| 5117 | - } |
|
| 5118 | - // recuperer le contenu produit par le squelette |
|
| 5119 | - $options['raw'] = true; |
|
| 5120 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | - |
|
| 5122 | - // calculer le nom de la css |
|
| 5123 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | - |
|
| 5127 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | - } |
|
| 5133 | - else { |
|
| 5134 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | - ksort($contexte); |
|
| 5136 | - $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 5137 | - } |
|
| 5138 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | - |
|
| 5140 | - // mettre a jour le fichier si il n'existe pas |
|
| 5141 | - // ou trop ancien |
|
| 5142 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | - if ( |
|
| 5145 | - !file_exists($filename) |
|
| 5146 | - or !file_exists($filename . '.last') |
|
| 5147 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | - ) { |
|
| 5150 | - $contenu = $cache['texte']; |
|
| 5151 | - // passer les urls en absolu si c'est une css |
|
| 5152 | - if ($extension == 'css') { |
|
| 5153 | - $contenu = urls_absolues_css( |
|
| 5154 | - $contenu, |
|
| 5155 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | - ); |
|
| 5157 | - } |
|
| 5158 | - |
|
| 5159 | - $comment = ''; |
|
| 5160 | - // ne pas insérer de commentaire sur certains formats |
|
| 5161 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | - foreach ($contexte as $k => $v) { |
|
| 5164 | - $comment .= ",$k=$v"; |
|
| 5165 | - } |
|
| 5166 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5167 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5168 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5169 | - } |
|
| 5170 | - // et ecrire le fichier si il change |
|
| 5171 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5172 | - } |
|
| 5173 | - |
|
| 5174 | - return timestamp($filename); |
|
| 5109 | + if (isset($contexte['format'])) { |
|
| 5110 | + $extension = $contexte['format']; |
|
| 5111 | + unset($contexte['format']); |
|
| 5112 | + } else { |
|
| 5113 | + $extension = 'html'; |
|
| 5114 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | + $extension = $m[1]; |
|
| 5116 | + } |
|
| 5117 | + } |
|
| 5118 | + // recuperer le contenu produit par le squelette |
|
| 5119 | + $options['raw'] = true; |
|
| 5120 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | + |
|
| 5122 | + // calculer le nom de la css |
|
| 5123 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | + |
|
| 5127 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | + } |
|
| 5133 | + else { |
|
| 5134 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | + ksort($contexte); |
|
| 5136 | + $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 5137 | + } |
|
| 5138 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | + |
|
| 5140 | + // mettre a jour le fichier si il n'existe pas |
|
| 5141 | + // ou trop ancien |
|
| 5142 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | + if ( |
|
| 5145 | + !file_exists($filename) |
|
| 5146 | + or !file_exists($filename . '.last') |
|
| 5147 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | + ) { |
|
| 5150 | + $contenu = $cache['texte']; |
|
| 5151 | + // passer les urls en absolu si c'est une css |
|
| 5152 | + if ($extension == 'css') { |
|
| 5153 | + $contenu = urls_absolues_css( |
|
| 5154 | + $contenu, |
|
| 5155 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | + ); |
|
| 5157 | + } |
|
| 5158 | + |
|
| 5159 | + $comment = ''; |
|
| 5160 | + // ne pas insérer de commentaire sur certains formats |
|
| 5161 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | + foreach ($contexte as $k => $v) { |
|
| 5164 | + $comment .= ",$k=$v"; |
|
| 5165 | + } |
|
| 5166 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5167 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5168 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5169 | + } |
|
| 5170 | + // et ecrire le fichier si il change |
|
| 5171 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5172 | + } |
|
| 5173 | + |
|
| 5174 | + return timestamp($filename); |
|
| 5175 | 5175 | } |
| 5176 | 5176 | |
| 5177 | 5177 | /** |
@@ -5184,15 +5184,15 @@ discard block |
||
| 5184 | 5184 | * $fichier auquel on a ajouté le timestamp |
| 5185 | 5185 | */ |
| 5186 | 5186 | function timestamp($fichier) { |
| 5187 | - if ( |
|
| 5188 | - !$fichier |
|
| 5189 | - or !file_exists($fichier) |
|
| 5190 | - or !$m = filemtime($fichier) |
|
| 5191 | - ) { |
|
| 5192 | - return $fichier; |
|
| 5193 | - } |
|
| 5187 | + if ( |
|
| 5188 | + !$fichier |
|
| 5189 | + or !file_exists($fichier) |
|
| 5190 | + or !$m = filemtime($fichier) |
|
| 5191 | + ) { |
|
| 5192 | + return $fichier; |
|
| 5193 | + } |
|
| 5194 | 5194 | |
| 5195 | - return "$fichier?$m"; |
|
| 5195 | + return "$fichier?$m"; |
|
| 5196 | 5196 | } |
| 5197 | 5197 | |
| 5198 | 5198 | /** |
@@ -5202,11 +5202,11 @@ discard block |
||
| 5202 | 5202 | * @return string |
| 5203 | 5203 | */ |
| 5204 | 5204 | function supprimer_timestamp($url) { |
| 5205 | - if (strpos($url, '?') === false) { |
|
| 5206 | - return $url; |
|
| 5207 | - } |
|
| 5205 | + if (strpos($url, '?') === false) { |
|
| 5206 | + return $url; |
|
| 5207 | + } |
|
| 5208 | 5208 | |
| 5209 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5209 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5210 | 5210 | } |
| 5211 | 5211 | |
| 5212 | 5212 | /** |
@@ -5221,9 +5221,9 @@ discard block |
||
| 5221 | 5221 | * @return string |
| 5222 | 5222 | */ |
| 5223 | 5223 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5224 | - include_spip('inc/envoyer_mail'); |
|
| 5224 | + include_spip('inc/envoyer_mail'); |
|
| 5225 | 5225 | |
| 5226 | - return nettoyer_titre_email($titre); |
|
| 5226 | + return nettoyer_titre_email($titre); |
|
| 5227 | 5227 | } |
| 5228 | 5228 | |
| 5229 | 5229 | /** |
@@ -5245,27 +5245,27 @@ discard block |
||
| 5245 | 5245 | * @return string |
| 5246 | 5246 | */ |
| 5247 | 5247 | function filtre_chercher_rubrique_dist( |
| 5248 | - $titre, |
|
| 5249 | - $id_objet, |
|
| 5250 | - $id_parent, |
|
| 5251 | - $objet, |
|
| 5252 | - $id_secteur, |
|
| 5253 | - $restreint, |
|
| 5254 | - $actionable = false, |
|
| 5255 | - $retour_sans_cadre = false |
|
| 5248 | + $titre, |
|
| 5249 | + $id_objet, |
|
| 5250 | + $id_parent, |
|
| 5251 | + $objet, |
|
| 5252 | + $id_secteur, |
|
| 5253 | + $restreint, |
|
| 5254 | + $actionable = false, |
|
| 5255 | + $retour_sans_cadre = false |
|
| 5256 | 5256 | ) { |
| 5257 | - include_spip('inc/filtres_ecrire'); |
|
| 5257 | + include_spip('inc/filtres_ecrire'); |
|
| 5258 | 5258 | |
| 5259 | - return chercher_rubrique( |
|
| 5260 | - $titre, |
|
| 5261 | - $id_objet, |
|
| 5262 | - $id_parent, |
|
| 5263 | - $objet, |
|
| 5264 | - $id_secteur, |
|
| 5265 | - $restreint, |
|
| 5266 | - $actionable, |
|
| 5267 | - $retour_sans_cadre |
|
| 5268 | - ); |
|
| 5259 | + return chercher_rubrique( |
|
| 5260 | + $titre, |
|
| 5261 | + $id_objet, |
|
| 5262 | + $id_parent, |
|
| 5263 | + $objet, |
|
| 5264 | + $id_secteur, |
|
| 5265 | + $restreint, |
|
| 5266 | + $actionable, |
|
| 5267 | + $retour_sans_cadre |
|
| 5268 | + ); |
|
| 5269 | 5269 | } |
| 5270 | 5270 | |
| 5271 | 5271 | /** |
@@ -5294,56 +5294,56 @@ discard block |
||
| 5294 | 5294 | * Chaîne vide si l'accès est autorisé |
| 5295 | 5295 | */ |
| 5296 | 5296 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5297 | - if ($ok) { |
|
| 5298 | - return ''; |
|
| 5299 | - } |
|
| 5300 | - |
|
| 5301 | - // Vider tous les tampons |
|
| 5302 | - $level = @ob_get_level(); |
|
| 5303 | - while ($level--) { |
|
| 5304 | - @ob_end_clean(); |
|
| 5305 | - } |
|
| 5306 | - |
|
| 5307 | - include_spip('inc/headers'); |
|
| 5308 | - |
|
| 5309 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5310 | - if ($url) { |
|
| 5311 | - redirige_par_entete($url, '', $statut); |
|
| 5312 | - } |
|
| 5313 | - |
|
| 5314 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5315 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5316 | - $message = $statut; |
|
| 5317 | - $statut = 0; |
|
| 5318 | - } |
|
| 5319 | - if (!$message) { |
|
| 5320 | - $message = ''; |
|
| 5321 | - } |
|
| 5322 | - $statut = intval($statut); |
|
| 5323 | - |
|
| 5324 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5325 | - if (test_espace_prive()) { |
|
| 5326 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5327 | - $statut = 403; |
|
| 5328 | - } |
|
| 5329 | - http_response_code(403); |
|
| 5330 | - $echec = charger_fonction('403', 'exec'); |
|
| 5331 | - $echec($message); |
|
| 5332 | - } else { |
|
| 5333 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5334 | - if (!$statut) { |
|
| 5335 | - $statut = 404; |
|
| 5336 | - } |
|
| 5337 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5338 | - http_response_code($statut); |
|
| 5339 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5340 | - if ($statut >= 400) { |
|
| 5341 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5342 | - } |
|
| 5343 | - } |
|
| 5344 | - |
|
| 5345 | - |
|
| 5346 | - exit; |
|
| 5297 | + if ($ok) { |
|
| 5298 | + return ''; |
|
| 5299 | + } |
|
| 5300 | + |
|
| 5301 | + // Vider tous les tampons |
|
| 5302 | + $level = @ob_get_level(); |
|
| 5303 | + while ($level--) { |
|
| 5304 | + @ob_end_clean(); |
|
| 5305 | + } |
|
| 5306 | + |
|
| 5307 | + include_spip('inc/headers'); |
|
| 5308 | + |
|
| 5309 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5310 | + if ($url) { |
|
| 5311 | + redirige_par_entete($url, '', $statut); |
|
| 5312 | + } |
|
| 5313 | + |
|
| 5314 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5315 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5316 | + $message = $statut; |
|
| 5317 | + $statut = 0; |
|
| 5318 | + } |
|
| 5319 | + if (!$message) { |
|
| 5320 | + $message = ''; |
|
| 5321 | + } |
|
| 5322 | + $statut = intval($statut); |
|
| 5323 | + |
|
| 5324 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5325 | + if (test_espace_prive()) { |
|
| 5326 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5327 | + $statut = 403; |
|
| 5328 | + } |
|
| 5329 | + http_response_code(403); |
|
| 5330 | + $echec = charger_fonction('403', 'exec'); |
|
| 5331 | + $echec($message); |
|
| 5332 | + } else { |
|
| 5333 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5334 | + if (!$statut) { |
|
| 5335 | + $statut = 404; |
|
| 5336 | + } |
|
| 5337 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5338 | + http_response_code($statut); |
|
| 5339 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5340 | + if ($statut >= 400) { |
|
| 5341 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5342 | + } |
|
| 5343 | + } |
|
| 5344 | + |
|
| 5345 | + |
|
| 5346 | + exit; |
|
| 5347 | 5347 | } |
| 5348 | 5348 | |
| 5349 | 5349 | /** |
@@ -5354,11 +5354,11 @@ discard block |
||
| 5354 | 5354 | * @return string |
| 5355 | 5355 | */ |
| 5356 | 5356 | function filtre_compacte_dist($source, $format = null) { |
| 5357 | - if (function_exists('compacte')) { |
|
| 5358 | - return compacte($source, $format); |
|
| 5359 | - } |
|
| 5357 | + if (function_exists('compacte')) { |
|
| 5358 | + return compacte($source, $format); |
|
| 5359 | + } |
|
| 5360 | 5360 | |
| 5361 | - return $source; |
|
| 5361 | + return $source; |
|
| 5362 | 5362 | } |
| 5363 | 5363 | |
| 5364 | 5364 | |
@@ -5370,31 +5370,31 @@ discard block |
||
| 5370 | 5370 | * @return string |
| 5371 | 5371 | */ |
| 5372 | 5372 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 5373 | - $l = strlen($passe); |
|
| 5374 | - |
|
| 5375 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5376 | - if (!$l) { |
|
| 5377 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5378 | - } |
|
| 5379 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5380 | - } |
|
| 5381 | - |
|
| 5382 | - if (is_null($portion_pourcent)) { |
|
| 5383 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5384 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5385 | - } |
|
| 5386 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5387 | - } |
|
| 5388 | - if ($portion_pourcent >= 100) { |
|
| 5389 | - return $passe; |
|
| 5390 | - } |
|
| 5391 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5392 | - $e = max($e, 0); |
|
| 5393 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5394 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5395 | - $mid = '***...***'; |
|
| 5396 | - } |
|
| 5397 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5373 | + $l = strlen($passe); |
|
| 5374 | + |
|
| 5375 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5376 | + if (!$l) { |
|
| 5377 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5378 | + } |
|
| 5379 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5380 | + } |
|
| 5381 | + |
|
| 5382 | + if (is_null($portion_pourcent)) { |
|
| 5383 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5384 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5385 | + } |
|
| 5386 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5387 | + } |
|
| 5388 | + if ($portion_pourcent >= 100) { |
|
| 5389 | + return $passe; |
|
| 5390 | + } |
|
| 5391 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5392 | + $e = max($e, 0); |
|
| 5393 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5394 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5395 | + $mid = '***...***'; |
|
| 5396 | + } |
|
| 5397 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5398 | 5398 | } |
| 5399 | 5399 | |
| 5400 | 5400 | |
@@ -5415,64 +5415,64 @@ discard block |
||
| 5415 | 5415 | */ |
| 5416 | 5416 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5417 | 5417 | |
| 5418 | - $original = $texte; |
|
| 5419 | - $separateur = (isset($options['separateur']) ? $options['separateur'] : '_'); |
|
| 5420 | - $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60); |
|
| 5421 | - $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0); |
|
| 5418 | + $original = $texte; |
|
| 5419 | + $separateur = (isset($options['separateur']) ? $options['separateur'] : '_'); |
|
| 5420 | + $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60); |
|
| 5421 | + $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0); |
|
| 5422 | 5422 | |
| 5423 | - if (!function_exists('translitteration')) { |
|
| 5424 | - include_spip('inc/charsets'); |
|
| 5425 | - } |
|
| 5423 | + if (!function_exists('translitteration')) { |
|
| 5424 | + include_spip('inc/charsets'); |
|
| 5425 | + } |
|
| 5426 | 5426 | |
| 5427 | - // pas de balise html |
|
| 5428 | - if (strpos($texte, '<') !== false) { |
|
| 5429 | - $texte = strip_tags($texte); |
|
| 5430 | - } |
|
| 5431 | - if (strpos($texte, '&') !== false) { |
|
| 5432 | - $texte = unicode2charset($texte); |
|
| 5433 | - } |
|
| 5434 | - // On enlève les espaces indésirables |
|
| 5435 | - $texte = trim($texte); |
|
| 5427 | + // pas de balise html |
|
| 5428 | + if (strpos($texte, '<') !== false) { |
|
| 5429 | + $texte = strip_tags($texte); |
|
| 5430 | + } |
|
| 5431 | + if (strpos($texte, '&') !== false) { |
|
| 5432 | + $texte = unicode2charset($texte); |
|
| 5433 | + } |
|
| 5434 | + // On enlève les espaces indésirables |
|
| 5435 | + $texte = trim($texte); |
|
| 5436 | 5436 | |
| 5437 | - // On enlève les accents et cie |
|
| 5438 | - $texte = translitteration($texte); |
|
| 5437 | + // On enlève les accents et cie |
|
| 5438 | + $texte = translitteration($texte); |
|
| 5439 | 5439 | |
| 5440 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5441 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5440 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5441 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5442 | 5442 | |
| 5443 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5444 | - while (strpos($texte, "$separateur$separateur") !== false) { |
|
| 5445 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5446 | - } |
|
| 5443 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5444 | + while (strpos($texte, "$separateur$separateur") !== false) { |
|
| 5445 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5446 | + } |
|
| 5447 | 5447 | |
| 5448 | - // pas de separateur au debut ni a la fin |
|
| 5449 | - $texte = trim($texte, $separateur); |
|
| 5448 | + // pas de separateur au debut ni a la fin |
|
| 5449 | + $texte = trim($texte, $separateur); |
|
| 5450 | 5450 | |
| 5451 | - // en minuscules |
|
| 5452 | - $texte = strtolower($texte); |
|
| 5451 | + // en minuscules |
|
| 5452 | + $texte = strtolower($texte); |
|
| 5453 | 5453 | |
| 5454 | - switch ($type) { |
|
| 5455 | - case 'class': |
|
| 5456 | - case 'id': |
|
| 5457 | - case 'anchor': |
|
| 5458 | - if (preg_match(',^\d,', $texte)) { |
|
| 5459 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5460 | - } |
|
| 5461 | - } |
|
| 5454 | + switch ($type) { |
|
| 5455 | + case 'class': |
|
| 5456 | + case 'id': |
|
| 5457 | + case 'anchor': |
|
| 5458 | + if (preg_match(',^\d,', $texte)) { |
|
| 5459 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5460 | + } |
|
| 5461 | + } |
|
| 5462 | 5462 | |
| 5463 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5464 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5465 | - } |
|
| 5463 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5464 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5465 | + } |
|
| 5466 | 5466 | |
| 5467 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5468 | - if (preg_match(',^\d,', $texte)) { |
|
| 5469 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5470 | - } |
|
| 5471 | - $texte .= $separateur . md5($original); |
|
| 5472 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5473 | - } |
|
| 5467 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5468 | + if (preg_match(',^\d,', $texte)) { |
|
| 5469 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5470 | + } |
|
| 5471 | + $texte .= $separateur . md5($original); |
|
| 5472 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5473 | + } |
|
| 5474 | 5474 | |
| 5475 | - return $texte; |
|
| 5475 | + return $texte; |
|
| 5476 | 5476 | } |
| 5477 | 5477 | |
| 5478 | 5478 | |
@@ -5493,11 +5493,11 @@ discard block |
||
| 5493 | 5493 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5494 | 5494 | */ |
| 5495 | 5495 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5496 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5497 | - if ($ucfirst) { |
|
| 5498 | - $label = spip_ucfirst($label); |
|
| 5499 | - } |
|
| 5500 | - return $label; |
|
| 5496 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5497 | + if ($ucfirst) { |
|
| 5498 | + $label = spip_ucfirst($label); |
|
| 5499 | + } |
|
| 5500 | + return $label; |
|
| 5501 | 5501 | } |
| 5502 | 5502 | |
| 5503 | 5503 | /** |
@@ -5510,8 +5510,8 @@ discard block |
||
| 5510 | 5510 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5511 | 5511 | */ |
| 5512 | 5512 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5513 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5514 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5513 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5514 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5515 | 5515 | } |
| 5516 | 5516 | |
| 5517 | 5517 | |
@@ -5524,19 +5524,19 @@ discard block |
||
| 5524 | 5524 | * @return array |
| 5525 | 5525 | */ |
| 5526 | 5526 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5527 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5528 | - return []; |
|
| 5529 | - } |
|
| 5527 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5528 | + return []; |
|
| 5529 | + } |
|
| 5530 | 5530 | |
| 5531 | - // compatibilite signature inversee |
|
| 5532 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5533 | - list($objet, $id_objet) = [$id_objet, $objet]; |
|
| 5534 | - } |
|
| 5531 | + // compatibilite signature inversee |
|
| 5532 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5533 | + list($objet, $id_objet) = [$id_objet, $objet]; |
|
| 5534 | + } |
|
| 5535 | 5535 | |
| 5536 | - if (!function_exists($fonction)) { |
|
| 5537 | - include_spip('base/objets'); |
|
| 5538 | - } |
|
| 5539 | - return $fonction($objet, $id_objet); |
|
| 5536 | + if (!function_exists($fonction)) { |
|
| 5537 | + include_spip('base/objets'); |
|
| 5538 | + } |
|
| 5539 | + return $fonction($objet, $id_objet); |
|
| 5540 | 5540 | } |
| 5541 | 5541 | |
| 5542 | 5542 | |
@@ -5551,7 +5551,7 @@ discard block |
||
| 5551 | 5551 | * @return array |
| 5552 | 5552 | */ |
| 5553 | 5553 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5554 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5554 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5555 | 5555 | } |
| 5556 | 5556 | |
| 5557 | 5557 | /** |
@@ -5565,7 +5565,7 @@ discard block |
||
| 5565 | 5565 | * @return array |
| 5566 | 5566 | */ |
| 5567 | 5567 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5568 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5568 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5569 | 5569 | } |
| 5570 | 5570 | |
| 5571 | 5571 | /** |
@@ -5579,7 +5579,7 @@ discard block |
||
| 5579 | 5579 | * @return array |
| 5580 | 5580 | */ |
| 5581 | 5581 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5582 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5582 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5583 | 5583 | } |
| 5584 | 5584 | |
| 5585 | 5585 | /** |
@@ -5593,5 +5593,5 @@ discard block |
||
| 5593 | 5593 | * @return array |
| 5594 | 5594 | */ |
| 5595 | 5595 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5596 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5596 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5597 | 5597 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres'); // par precaution |
| 24 | 24 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | * Le code de la couleur en hexadécimal. |
| 39 | 39 | */ |
| 40 | 40 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 41 | - $red = dechex($red); |
|
| 42 | - $green = dechex($green); |
|
| 43 | - $blue = dechex($blue); |
|
| 44 | - |
|
| 45 | - if (strlen($red) == 1) { |
|
| 46 | - $red = '0' . $red; |
|
| 47 | - } |
|
| 48 | - if (strlen($green) == 1) { |
|
| 49 | - $green = '0' . $green; |
|
| 50 | - } |
|
| 51 | - if (strlen($blue) == 1) { |
|
| 52 | - $blue = '0' . $blue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return "$red$green$blue"; |
|
| 41 | + $red = dechex($red); |
|
| 42 | + $green = dechex($green); |
|
| 43 | + $blue = dechex($blue); |
|
| 44 | + |
|
| 45 | + if (strlen($red) == 1) { |
|
| 46 | + $red = '0' . $red; |
|
| 47 | + } |
|
| 48 | + if (strlen($green) == 1) { |
|
| 49 | + $green = '0' . $green; |
|
| 50 | + } |
|
| 51 | + if (strlen($blue) == 1) { |
|
| 52 | + $blue = '0' . $blue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return "$red$green$blue"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 65 | 65 | */ |
| 66 | 66 | function _couleur_hex_to_dec($couleur) { |
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,58 +120,58 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 124 | - $var_G = ($G / 255); |
|
| 125 | - $var_B = ($B / 255); |
|
| 126 | - |
|
| 127 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 128 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 129 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 130 | - |
|
| 131 | - $L = ($var_Max + $var_Min) / 2; |
|
| 132 | - |
|
| 133 | - if ($del_Max == 0) { |
|
| 134 | - //This is a gray, no chroma... |
|
| 135 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 136 | - $S = 0; |
|
| 137 | - } else { |
|
| 138 | - // Chromatic data... |
|
| 139 | - if ($L < 0.5) { |
|
| 140 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 141 | - } else { |
|
| 142 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 146 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - |
|
| 149 | - if ($var_R == $var_Max) { |
|
| 150 | - $H = $del_B - $del_G; |
|
| 151 | - } else { |
|
| 152 | - if ($var_G == $var_Max) { |
|
| 153 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 154 | - } else { |
|
| 155 | - if ($var_B == $var_Max) { |
|
| 156 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ($H < 0) { |
|
| 162 | - $H += 1; |
|
| 163 | - } |
|
| 164 | - if ($H > 1) { |
|
| 165 | - $H -= 1; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $ret = []; |
|
| 170 | - $ret['h'] = $H; |
|
| 171 | - $ret['s'] = $S; |
|
| 172 | - $ret['l'] = $L; |
|
| 173 | - |
|
| 174 | - return $ret; |
|
| 123 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 124 | + $var_G = ($G / 255); |
|
| 125 | + $var_B = ($B / 255); |
|
| 126 | + |
|
| 127 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 128 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 129 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 130 | + |
|
| 131 | + $L = ($var_Max + $var_Min) / 2; |
|
| 132 | + |
|
| 133 | + if ($del_Max == 0) { |
|
| 134 | + //This is a gray, no chroma... |
|
| 135 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 136 | + $S = 0; |
|
| 137 | + } else { |
|
| 138 | + // Chromatic data... |
|
| 139 | + if ($L < 0.5) { |
|
| 140 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 141 | + } else { |
|
| 142 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 146 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + |
|
| 149 | + if ($var_R == $var_Max) { |
|
| 150 | + $H = $del_B - $del_G; |
|
| 151 | + } else { |
|
| 152 | + if ($var_G == $var_Max) { |
|
| 153 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 154 | + } else { |
|
| 155 | + if ($var_B == $var_Max) { |
|
| 156 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ($H < 0) { |
|
| 162 | + $H += 1; |
|
| 163 | + } |
|
| 164 | + if ($H > 1) { |
|
| 165 | + $H -= 1; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $ret = []; |
|
| 170 | + $ret['h'] = $H; |
|
| 171 | + $ret['s'] = $S; |
|
| 172 | + $ret['l'] = $L; |
|
| 173 | + |
|
| 174 | + return $ret; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -187,52 +187,52 @@ discard block |
||
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | 189 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 190 | - // helper |
|
| 191 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | - if ($vH < 0) { |
|
| 193 | - $vH += 1; |
|
| 194 | - } |
|
| 195 | - if ($vH > 1) { |
|
| 196 | - $vH -= 1; |
|
| 197 | - } |
|
| 198 | - if ((6 * $vH) < 1) { |
|
| 199 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 200 | - } |
|
| 201 | - if ((2 * $vH) < 1) { |
|
| 202 | - return ($v2); |
|
| 203 | - } |
|
| 204 | - if ((3 * $vH) < 2) { |
|
| 205 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return ($v1); |
|
| 209 | - }; |
|
| 210 | - |
|
| 211 | - if ($S == 0) { |
|
| 212 | - // HSV values = 0 -> 1 |
|
| 213 | - $R = $L * 255; |
|
| 214 | - $G = $L * 255; |
|
| 215 | - $B = $L * 255; |
|
| 216 | - } else { |
|
| 217 | - if ($L < 0.5) { |
|
| 218 | - $var_2 = $L * (1 + $S); |
|
| 219 | - } else { |
|
| 220 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $var_1 = 2 * $L - $var_2; |
|
| 224 | - |
|
| 225 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 226 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 227 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $ret = []; |
|
| 231 | - $ret['r'] = floor($R); |
|
| 232 | - $ret['g'] = floor($G); |
|
| 233 | - $ret['b'] = floor($B); |
|
| 234 | - |
|
| 235 | - return $ret; |
|
| 190 | + // helper |
|
| 191 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | + if ($vH < 0) { |
|
| 193 | + $vH += 1; |
|
| 194 | + } |
|
| 195 | + if ($vH > 1) { |
|
| 196 | + $vH -= 1; |
|
| 197 | + } |
|
| 198 | + if ((6 * $vH) < 1) { |
|
| 199 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 200 | + } |
|
| 201 | + if ((2 * $vH) < 1) { |
|
| 202 | + return ($v2); |
|
| 203 | + } |
|
| 204 | + if ((3 * $vH) < 2) { |
|
| 205 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return ($v1); |
|
| 209 | + }; |
|
| 210 | + |
|
| 211 | + if ($S == 0) { |
|
| 212 | + // HSV values = 0 -> 1 |
|
| 213 | + $R = $L * 255; |
|
| 214 | + $G = $L * 255; |
|
| 215 | + $B = $L * 255; |
|
| 216 | + } else { |
|
| 217 | + if ($L < 0.5) { |
|
| 218 | + $var_2 = $L * (1 + $S); |
|
| 219 | + } else { |
|
| 220 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $var_1 = 2 * $L - $var_2; |
|
| 224 | + |
|
| 225 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 226 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 227 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $ret = []; |
|
| 231 | + $ret['r'] = floor($R); |
|
| 232 | + $ret['g'] = floor($G); |
|
| 233 | + $ret['b'] = floor($B); |
|
| 234 | + |
|
| 235 | + return $ret; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 250 | 250 | */ |
| 251 | 251 | function statut_effacer_images_temporaires($stat) { |
| 252 | - static $statut = false; // par defaut on grave toute les images |
|
| 253 | - if ($stat === 'get') { |
|
| 254 | - return $statut; |
|
| 255 | - } |
|
| 256 | - $statut = $stat ? true : false; |
|
| 252 | + static $statut = false; // par defaut on grave toute les images |
|
| 253 | + if ($stat === 'get') { |
|
| 254 | + return $statut; |
|
| 255 | + } |
|
| 256 | + $statut = $stat ? true : false; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -306,241 +306,241 @@ discard block |
||
| 306 | 306 | * - array : tableau décrivant de l'image |
| 307 | 307 | */ |
| 308 | 308 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 309 | - static $images_recalcul = []; |
|
| 310 | - if (strlen($img) == 0) { |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $source = trim(extraire_attribut($img, 'src')); |
|
| 315 | - if (strlen($source) < 1) { |
|
| 316 | - $source = $img; |
|
| 317 | - $img = "<img src='$source' />"; |
|
| 318 | - } # gerer img src="data:....base64" |
|
| 319 | - elseif ( |
|
| 320 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 321 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 322 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 323 | - ) { |
|
| 324 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 325 | - if (!file_exists($local)) { |
|
| 326 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 327 | - } |
|
| 328 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 329 | - $sanitizer($local); |
|
| 330 | - } |
|
| 331 | - $source = $local; |
|
| 332 | - $img = inserer_attribut($img, 'src', $source); |
|
| 333 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 334 | - $img = inserer_attribut($img, 'width', ''); |
|
| 335 | - $img = inserer_attribut($img, 'height', ''); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - // les protocoles web prennent au moins 3 lettres |
|
| 339 | - if (tester_url_absolue($source)) { |
|
| 340 | - include_spip('inc/distant'); |
|
| 341 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 342 | - if (!$fichier) { |
|
| 343 | - return ''; |
|
| 344 | - } |
|
| 345 | - if ( |
|
| 346 | - $extension = _image_trouver_extension($fichier) |
|
| 347 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 348 | - ) { |
|
| 349 | - $sanitizer($fichier); |
|
| 350 | - } |
|
| 351 | - } else { |
|
| 352 | - // enlever le timestamp eventuel |
|
| 353 | - if (strpos($source, '?') !== false) { |
|
| 354 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 355 | - } |
|
| 356 | - if ( |
|
| 357 | - strpos($source, '?') !== false |
|
| 358 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 359 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 360 | - ) { |
|
| 361 | - $source = $f; |
|
| 362 | - } |
|
| 363 | - $fichier = $source; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - $terminaison_dest = ''; |
|
| 367 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 368 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - if ( |
|
| 372 | - $forcer_format !== false |
|
| 373 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 374 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 375 | - ) { |
|
| 376 | - $terminaison_dest = $forcer_format; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if (!$terminaison_dest) { |
|
| 380 | - return false; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 384 | - $fichier_dest = $nom_fichier; |
|
| 385 | - if ( |
|
| 386 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 387 | - or @file_exists($f = $fichier) |
|
| 388 | - ) { |
|
| 389 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 390 | - // au lieu de faire un acces disque sur le fichier |
|
| 391 | - list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img); |
|
| 392 | - $date_src = @filemtime($f); |
|
| 393 | - } elseif ( |
|
| 394 | - @file_exists($f = "$fichier.src") |
|
| 395 | - and lire_fichier($f, $valeurs) |
|
| 396 | - and $valeurs = unserialize($valeurs) |
|
| 397 | - and isset($valeurs['hauteur_dest']) |
|
| 398 | - and isset($valeurs['largeur_dest']) |
|
| 399 | - ) { |
|
| 400 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 401 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 402 | - $date_src = $valeurs['date']; |
|
| 403 | - } // pas de fichier source par la |
|
| 404 | - else { |
|
| 405 | - return false; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // pas de taille mesurable |
|
| 409 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 410 | - return false; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - // les images calculees dependent du chemin du fichier source |
|
| 414 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 415 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 416 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 417 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 418 | - // alors que ca concerne peu de site au final |
|
| 419 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 420 | - $identifiant = $fichier; |
|
| 421 | - |
|
| 422 | - // cas general : |
|
| 423 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 424 | - // cas particulier de reduire : |
|
| 425 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 426 | - $cache = 'cache-gd2'; |
|
| 427 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 428 | - list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 429 | - list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 430 | - $ret['largeur_dest'] = $destWidth; |
|
| 431 | - $ret['hauteur_dest'] = $destHeight; |
|
| 432 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 433 | - $cache = 'cache-vignettes'; |
|
| 434 | - $fichier_dest = basename($fichier_dest); |
|
| 435 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 436 | - // on garde la terminaison initiale car image simplement copiee |
|
| 437 | - // et on postfixe son nom avec un md5 du path |
|
| 438 | - $terminaison_dest = $terminaison; |
|
| 439 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 440 | - } else { |
|
| 441 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 442 | - } |
|
| 443 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 444 | - $cache = sous_repertoire($cache, $effet); |
|
| 445 | - } else { |
|
| 446 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 447 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 448 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 449 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 453 | - |
|
| 454 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 455 | - |
|
| 456 | - $creer = true; |
|
| 457 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 458 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 459 | - $images_recalcul[$fichier_dest] = true; |
|
| 460 | - } else { |
|
| 461 | - if (@file_exists($f = $fichier_dest)) { |
|
| 462 | - if (filemtime($f) >= $date_src) { |
|
| 463 | - $creer = false; |
|
| 464 | - } |
|
| 465 | - } else { |
|
| 466 | - if ( |
|
| 467 | - @file_exists($f = "$fichier_dest.src") |
|
| 468 | - and lire_fichier($f, $valeurs) |
|
| 469 | - and $valeurs = unserialize($valeurs) |
|
| 470 | - and $valeurs['date'] >= $date_src |
|
| 471 | - ) { |
|
| 472 | - $creer = false; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - if ($creer) { |
|
| 477 | - if (!@file_exists($fichier)) { |
|
| 478 | - if (!@file_exists("$fichier.src")) { |
|
| 479 | - spip_log("Image absente : $fichier"); |
|
| 480 | - |
|
| 481 | - return false; |
|
| 482 | - } |
|
| 483 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 484 | - reconstruire_image_intermediaire($fichier); |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - if ($creer) { |
|
| 489 | - spip_log( |
|
| 490 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 491 | - 'images' . _LOG_DEBUG |
|
| 492 | - ); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 496 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 497 | - $ret['fichier'] = $fichier; |
|
| 498 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 499 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 500 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 501 | - $ret['format_dest'] = $terminaison_dest; |
|
| 502 | - $ret['date_src'] = $date_src; |
|
| 503 | - $ret['creer'] = $creer; |
|
| 504 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 505 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 506 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 507 | - $ret['tag'] = $img; |
|
| 508 | - if ($fonction_creation) { |
|
| 509 | - $ret['reconstruction'] = $fonction_creation; |
|
| 510 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 511 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 512 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 513 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 517 | - 'args' => [ |
|
| 518 | - 'img' => $img, |
|
| 519 | - 'effet' => $effet, |
|
| 520 | - 'forcer_format' => $forcer_format, |
|
| 521 | - 'fonction_creation' => $fonction_creation, |
|
| 522 | - 'find_in_path' => $find_in_path, |
|
| 523 | - ], |
|
| 524 | - 'data' => $ret |
|
| 525 | - ]); |
|
| 526 | - |
|
| 527 | - // une globale pour le debug en cas de crash memoire |
|
| 528 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 529 | - |
|
| 530 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 531 | - if ($term_fonction === 'svg') { |
|
| 532 | - if ($creer and !$support_svg) { |
|
| 533 | - process_image_svg_identite($ret); |
|
| 534 | - $ret['creer'] = false; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - else { |
|
| 538 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 539 | - return false; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - return $ret; |
|
| 309 | + static $images_recalcul = []; |
|
| 310 | + if (strlen($img) == 0) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $source = trim(extraire_attribut($img, 'src')); |
|
| 315 | + if (strlen($source) < 1) { |
|
| 316 | + $source = $img; |
|
| 317 | + $img = "<img src='$source' />"; |
|
| 318 | + } # gerer img src="data:....base64" |
|
| 319 | + elseif ( |
|
| 320 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 321 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 322 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 323 | + ) { |
|
| 324 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 325 | + if (!file_exists($local)) { |
|
| 326 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 327 | + } |
|
| 328 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 329 | + $sanitizer($local); |
|
| 330 | + } |
|
| 331 | + $source = $local; |
|
| 332 | + $img = inserer_attribut($img, 'src', $source); |
|
| 333 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 334 | + $img = inserer_attribut($img, 'width', ''); |
|
| 335 | + $img = inserer_attribut($img, 'height', ''); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + // les protocoles web prennent au moins 3 lettres |
|
| 339 | + if (tester_url_absolue($source)) { |
|
| 340 | + include_spip('inc/distant'); |
|
| 341 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 342 | + if (!$fichier) { |
|
| 343 | + return ''; |
|
| 344 | + } |
|
| 345 | + if ( |
|
| 346 | + $extension = _image_trouver_extension($fichier) |
|
| 347 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 348 | + ) { |
|
| 349 | + $sanitizer($fichier); |
|
| 350 | + } |
|
| 351 | + } else { |
|
| 352 | + // enlever le timestamp eventuel |
|
| 353 | + if (strpos($source, '?') !== false) { |
|
| 354 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 355 | + } |
|
| 356 | + if ( |
|
| 357 | + strpos($source, '?') !== false |
|
| 358 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 359 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 360 | + ) { |
|
| 361 | + $source = $f; |
|
| 362 | + } |
|
| 363 | + $fichier = $source; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + $terminaison_dest = ''; |
|
| 367 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 368 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + if ( |
|
| 372 | + $forcer_format !== false |
|
| 373 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 374 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 375 | + ) { |
|
| 376 | + $terminaison_dest = $forcer_format; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if (!$terminaison_dest) { |
|
| 380 | + return false; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 384 | + $fichier_dest = $nom_fichier; |
|
| 385 | + if ( |
|
| 386 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 387 | + or @file_exists($f = $fichier) |
|
| 388 | + ) { |
|
| 389 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 390 | + // au lieu de faire un acces disque sur le fichier |
|
| 391 | + list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img); |
|
| 392 | + $date_src = @filemtime($f); |
|
| 393 | + } elseif ( |
|
| 394 | + @file_exists($f = "$fichier.src") |
|
| 395 | + and lire_fichier($f, $valeurs) |
|
| 396 | + and $valeurs = unserialize($valeurs) |
|
| 397 | + and isset($valeurs['hauteur_dest']) |
|
| 398 | + and isset($valeurs['largeur_dest']) |
|
| 399 | + ) { |
|
| 400 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 401 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 402 | + $date_src = $valeurs['date']; |
|
| 403 | + } // pas de fichier source par la |
|
| 404 | + else { |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // pas de taille mesurable |
|
| 409 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + // les images calculees dependent du chemin du fichier source |
|
| 414 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 415 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 416 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 417 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 418 | + // alors que ca concerne peu de site au final |
|
| 419 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 420 | + $identifiant = $fichier; |
|
| 421 | + |
|
| 422 | + // cas general : |
|
| 423 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 424 | + // cas particulier de reduire : |
|
| 425 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 426 | + $cache = 'cache-gd2'; |
|
| 427 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 428 | + list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 429 | + list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 430 | + $ret['largeur_dest'] = $destWidth; |
|
| 431 | + $ret['hauteur_dest'] = $destHeight; |
|
| 432 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 433 | + $cache = 'cache-vignettes'; |
|
| 434 | + $fichier_dest = basename($fichier_dest); |
|
| 435 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 436 | + // on garde la terminaison initiale car image simplement copiee |
|
| 437 | + // et on postfixe son nom avec un md5 du path |
|
| 438 | + $terminaison_dest = $terminaison; |
|
| 439 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 440 | + } else { |
|
| 441 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 442 | + } |
|
| 443 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 444 | + $cache = sous_repertoire($cache, $effet); |
|
| 445 | + } else { |
|
| 446 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 447 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 448 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 449 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 453 | + |
|
| 454 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 455 | + |
|
| 456 | + $creer = true; |
|
| 457 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 458 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 459 | + $images_recalcul[$fichier_dest] = true; |
|
| 460 | + } else { |
|
| 461 | + if (@file_exists($f = $fichier_dest)) { |
|
| 462 | + if (filemtime($f) >= $date_src) { |
|
| 463 | + $creer = false; |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + if ( |
|
| 467 | + @file_exists($f = "$fichier_dest.src") |
|
| 468 | + and lire_fichier($f, $valeurs) |
|
| 469 | + and $valeurs = unserialize($valeurs) |
|
| 470 | + and $valeurs['date'] >= $date_src |
|
| 471 | + ) { |
|
| 472 | + $creer = false; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + if ($creer) { |
|
| 477 | + if (!@file_exists($fichier)) { |
|
| 478 | + if (!@file_exists("$fichier.src")) { |
|
| 479 | + spip_log("Image absente : $fichier"); |
|
| 480 | + |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 483 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 484 | + reconstruire_image_intermediaire($fichier); |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + if ($creer) { |
|
| 489 | + spip_log( |
|
| 490 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 491 | + 'images' . _LOG_DEBUG |
|
| 492 | + ); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 496 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 497 | + $ret['fichier'] = $fichier; |
|
| 498 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 499 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 500 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 501 | + $ret['format_dest'] = $terminaison_dest; |
|
| 502 | + $ret['date_src'] = $date_src; |
|
| 503 | + $ret['creer'] = $creer; |
|
| 504 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 505 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 506 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 507 | + $ret['tag'] = $img; |
|
| 508 | + if ($fonction_creation) { |
|
| 509 | + $ret['reconstruction'] = $fonction_creation; |
|
| 510 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 511 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 512 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 513 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 517 | + 'args' => [ |
|
| 518 | + 'img' => $img, |
|
| 519 | + 'effet' => $effet, |
|
| 520 | + 'forcer_format' => $forcer_format, |
|
| 521 | + 'fonction_creation' => $fonction_creation, |
|
| 522 | + 'find_in_path' => $find_in_path, |
|
| 523 | + ], |
|
| 524 | + 'data' => $ret |
|
| 525 | + ]); |
|
| 526 | + |
|
| 527 | + // une globale pour le debug en cas de crash memoire |
|
| 528 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 529 | + |
|
| 530 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 531 | + if ($term_fonction === 'svg') { |
|
| 532 | + if ($creer and !$support_svg) { |
|
| 533 | + process_image_svg_identite($ret); |
|
| 534 | + $ret['creer'] = false; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + else { |
|
| 538 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 539 | + return false; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + return $ret; |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | |
@@ -549,53 +549,53 @@ discard block |
||
| 549 | 549 | * @return array |
| 550 | 550 | */ |
| 551 | 551 | function _image_extensions_acceptees_en_entree() { |
| 552 | - static $extensions = null; |
|
| 553 | - if (empty($extensions)) { |
|
| 554 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 555 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 556 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 557 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 558 | - $extensions = array_map('trim', $extensions); |
|
| 559 | - $extensions = array_filter($extensions); |
|
| 560 | - $extensions = array_unique($extensions); |
|
| 561 | - if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - return $extensions; |
|
| 552 | + static $extensions = null; |
|
| 553 | + if (empty($extensions)) { |
|
| 554 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 555 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 556 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 557 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 558 | + $extensions = array_map('trim', $extensions); |
|
| 559 | + $extensions = array_filter($extensions); |
|
| 560 | + $extensions = array_unique($extensions); |
|
| 561 | + if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + return $extensions; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
| 571 | 571 | * @return array|string[]|null |
| 572 | 572 | */ |
| 573 | 573 | function _image_extensions_acceptees_en_sortie() { |
| 574 | - static $extensions = null; |
|
| 575 | - if (empty($extensions)) { |
|
| 576 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 577 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 578 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 579 | - $extensions = array_diff($extensions, ['gif']); |
|
| 580 | - } |
|
| 581 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 582 | - $extensions = array_diff($extensions, ['webp']); |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - return $extensions; |
|
| 574 | + static $extensions = null; |
|
| 575 | + if (empty($extensions)) { |
|
| 576 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 577 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 578 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 579 | + $extensions = array_diff($extensions, ['gif']); |
|
| 580 | + } |
|
| 581 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 582 | + $extensions = array_diff($extensions, ['webp']); |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + return $extensions; |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | function _image_extension_normalisee($extension) { |
| 590 | - $extension = strtolower($extension); |
|
| 591 | - if ($extension === 'jpeg') { |
|
| 592 | - $extension = 'jpg'; |
|
| 593 | - } |
|
| 594 | - return $extension; |
|
| 590 | + $extension = strtolower($extension); |
|
| 591 | + if ($extension === 'jpeg') { |
|
| 592 | + $extension = 'jpg'; |
|
| 593 | + } |
|
| 594 | + return $extension; |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | function _image_extensions_conservent_transparence() { |
| 598 | - return ['png', 'webp']; |
|
| 598 | + return ['png', 'webp']; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | |
@@ -605,12 +605,12 @@ discard block |
||
| 605 | 605 | * @return string |
| 606 | 606 | */ |
| 607 | 607 | function _image_trouver_extension($path) { |
| 608 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 609 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 610 | - $terminaison = strtolower($regs[1]); |
|
| 611 | - return $terminaison; |
|
| 612 | - } |
|
| 613 | - return ''; |
|
| 608 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 609 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 610 | + $terminaison = strtolower($regs[1]); |
|
| 611 | + return $terminaison; |
|
| 612 | + } |
|
| 613 | + return ''; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -621,33 +621,33 @@ discard block |
||
| 621 | 621 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 622 | 622 | */ |
| 623 | 623 | function _image_trouver_extension_pertinente($path) { |
| 624 | - $path = supprimer_timestamp($path); |
|
| 625 | - $terminaison = _image_trouver_extension($path); |
|
| 626 | - if ($terminaison == 'jpg') { |
|
| 627 | - $terminaison = 'jpeg'; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - if (!file_exists($path)) { |
|
| 631 | - return $terminaison; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if (!$info = @spip_getimagesize($path)) { |
|
| 635 | - return $terminaison; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - if (isset($info['mime'])) { |
|
| 639 | - $mime = $info['mime']; |
|
| 640 | - } |
|
| 641 | - else { |
|
| 642 | - $mime = image_type_to_mime_type($info[2]); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 646 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 647 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 648 | - $terminaison = $_terminaison; |
|
| 649 | - } |
|
| 650 | - return $terminaison; |
|
| 624 | + $path = supprimer_timestamp($path); |
|
| 625 | + $terminaison = _image_trouver_extension($path); |
|
| 626 | + if ($terminaison == 'jpg') { |
|
| 627 | + $terminaison = 'jpeg'; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + if (!file_exists($path)) { |
|
| 631 | + return $terminaison; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if (!$info = @spip_getimagesize($path)) { |
|
| 635 | + return $terminaison; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + if (isset($info['mime'])) { |
|
| 639 | + $mime = $info['mime']; |
|
| 640 | + } |
|
| 641 | + else { |
|
| 642 | + $mime = image_type_to_mime_type($info[2]); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 646 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 647 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 648 | + $terminaison = $_terminaison; |
|
| 649 | + } |
|
| 650 | + return $terminaison; |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
@@ -655,36 +655,36 @@ discard block |
||
| 655 | 655 | * @return string |
| 656 | 656 | */ |
| 657 | 657 | function _image_trouver_extension_depuis_mime($mime) { |
| 658 | - switch (strtolower($mime)) { |
|
| 659 | - case 'image/png': |
|
| 660 | - case 'image/x-png': |
|
| 661 | - $terminaison = 'png'; |
|
| 662 | - break; |
|
| 663 | - |
|
| 664 | - case 'image/jpg': |
|
| 665 | - case 'image/jpeg': |
|
| 666 | - case 'image/pjpeg': |
|
| 667 | - $terminaison = 'jpeg'; |
|
| 668 | - break; |
|
| 669 | - |
|
| 670 | - case 'image/gif': |
|
| 671 | - $terminaison = 'gif'; |
|
| 672 | - break; |
|
| 673 | - |
|
| 674 | - case 'image/webp': |
|
| 675 | - case 'image/x-webp': |
|
| 676 | - $terminaison = 'webp'; |
|
| 677 | - break; |
|
| 678 | - |
|
| 679 | - case 'image/svg+xml': |
|
| 680 | - $terminaison = 'svg'; |
|
| 681 | - break; |
|
| 682 | - |
|
| 683 | - default: |
|
| 684 | - $terminaison = ''; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - return $terminaison; |
|
| 658 | + switch (strtolower($mime)) { |
|
| 659 | + case 'image/png': |
|
| 660 | + case 'image/x-png': |
|
| 661 | + $terminaison = 'png'; |
|
| 662 | + break; |
|
| 663 | + |
|
| 664 | + case 'image/jpg': |
|
| 665 | + case 'image/jpeg': |
|
| 666 | + case 'image/pjpeg': |
|
| 667 | + $terminaison = 'jpeg'; |
|
| 668 | + break; |
|
| 669 | + |
|
| 670 | + case 'image/gif': |
|
| 671 | + $terminaison = 'gif'; |
|
| 672 | + break; |
|
| 673 | + |
|
| 674 | + case 'image/webp': |
|
| 675 | + case 'image/x-webp': |
|
| 676 | + $terminaison = 'webp'; |
|
| 677 | + break; |
|
| 678 | + |
|
| 679 | + case 'image/svg+xml': |
|
| 680 | + $terminaison = 'svg'; |
|
| 681 | + break; |
|
| 682 | + |
|
| 683 | + default: |
|
| 684 | + $terminaison = ''; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + return $terminaison; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -704,18 +704,18 @@ discard block |
||
| 704 | 704 | * Une ressource de type Image GD. |
| 705 | 705 | */ |
| 706 | 706 | function _imagecreatefrom_func(string $func, string $filename) { |
| 707 | - if (!function_exists($func)) { |
|
| 708 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 709 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 710 | - return null; |
|
| 711 | - } |
|
| 712 | - $img = @$func($filename); |
|
| 713 | - if (!$img) { |
|
| 714 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 715 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 716 | - $img = imagecreate(10, 10); |
|
| 717 | - } |
|
| 718 | - return $img; |
|
| 707 | + if (!function_exists($func)) { |
|
| 708 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 709 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 710 | + return null; |
|
| 711 | + } |
|
| 712 | + $img = @$func($filename); |
|
| 713 | + if (!$img) { |
|
| 714 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 715 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 716 | + $img = imagecreate(10, 10); |
|
| 717 | + } |
|
| 718 | + return $img; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | * Une ressource de type Image GD. |
| 732 | 732 | */ |
| 733 | 733 | function _imagecreatefromjpeg($filename) { |
| 734 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 734 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | * Une ressource de type Image GD. |
| 748 | 748 | */ |
| 749 | 749 | function _imagecreatefrompng($filename) { |
| 750 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 750 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | /** |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | * Une ressource de type Image GD. |
| 764 | 764 | */ |
| 765 | 765 | function _imagecreatefromgif($filename) { |
| 766 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 766 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * Une ressource de type Image GD. |
| 781 | 781 | */ |
| 782 | 782 | function _imagecreatefromwebp($filename) { |
| 783 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 783 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -798,24 +798,24 @@ discard block |
||
| 798 | 798 | * - true si une image est bien retournée. |
| 799 | 799 | */ |
| 800 | 800 | function _image_imagepng($img, $fichier) { |
| 801 | - if (!function_exists('imagepng')) { |
|
| 802 | - return false; |
|
| 803 | - } |
|
| 804 | - $tmp = $fichier . '.tmp'; |
|
| 805 | - $ret = imagepng($img, $tmp); |
|
| 806 | - if (file_exists($tmp)) { |
|
| 807 | - $taille_test = getimagesize($tmp); |
|
| 808 | - if ($taille_test[0] < 1) { |
|
| 809 | - return false; |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 813 | - @rename($tmp, $fichier); |
|
| 814 | - |
|
| 815 | - return $ret; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - return false; |
|
| 801 | + if (!function_exists('imagepng')) { |
|
| 802 | + return false; |
|
| 803 | + } |
|
| 804 | + $tmp = $fichier . '.tmp'; |
|
| 805 | + $ret = imagepng($img, $tmp); |
|
| 806 | + if (file_exists($tmp)) { |
|
| 807 | + $taille_test = getimagesize($tmp); |
|
| 808 | + if ($taille_test[0] < 1) { |
|
| 809 | + return false; |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 813 | + @rename($tmp, $fichier); |
|
| 814 | + |
|
| 815 | + return $ret; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + return false; |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | /** |
@@ -833,24 +833,24 @@ discard block |
||
| 833 | 833 | * - true si une image est bien retournée. |
| 834 | 834 | */ |
| 835 | 835 | function _image_imagegif($img, $fichier) { |
| 836 | - if (!function_exists('imagegif')) { |
|
| 837 | - return false; |
|
| 838 | - } |
|
| 839 | - $tmp = $fichier . '.tmp'; |
|
| 840 | - $ret = imagegif($img, $tmp); |
|
| 841 | - if (file_exists($tmp)) { |
|
| 842 | - $taille_test = getimagesize($tmp); |
|
| 843 | - if ($taille_test[0] < 1) { |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 848 | - @rename($tmp, $fichier); |
|
| 849 | - |
|
| 850 | - return $ret; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - return false; |
|
| 836 | + if (!function_exists('imagegif')) { |
|
| 837 | + return false; |
|
| 838 | + } |
|
| 839 | + $tmp = $fichier . '.tmp'; |
|
| 840 | + $ret = imagegif($img, $tmp); |
|
| 841 | + if (file_exists($tmp)) { |
|
| 842 | + $taille_test = getimagesize($tmp); |
|
| 843 | + if ($taille_test[0] < 1) { |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 848 | + @rename($tmp, $fichier); |
|
| 849 | + |
|
| 850 | + return $ret; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + return false; |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -873,29 +873,29 @@ discard block |
||
| 873 | 873 | * - true si une image est bien retournée. |
| 874 | 874 | */ |
| 875 | 875 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 876 | - if (!function_exists('imagejpeg')) { |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 879 | - $tmp = $fichier . '.tmp'; |
|
| 876 | + if (!function_exists('imagejpeg')) { |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | + $tmp = $fichier . '.tmp'; |
|
| 880 | 880 | |
| 881 | - // Enable interlancing |
|
| 882 | - imageinterlace($img, true); |
|
| 881 | + // Enable interlancing |
|
| 882 | + imageinterlace($img, true); |
|
| 883 | 883 | |
| 884 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 884 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 885 | 885 | |
| 886 | - if (file_exists($tmp)) { |
|
| 887 | - $taille_test = getimagesize($tmp); |
|
| 888 | - if ($taille_test[0] < 1) { |
|
| 889 | - return false; |
|
| 890 | - } |
|
| 886 | + if (file_exists($tmp)) { |
|
| 887 | + $taille_test = getimagesize($tmp); |
|
| 888 | + if ($taille_test[0] < 1) { |
|
| 889 | + return false; |
|
| 890 | + } |
|
| 891 | 891 | |
| 892 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 893 | - @rename($tmp, $fichier); |
|
| 892 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 893 | + @rename($tmp, $fichier); |
|
| 894 | 894 | |
| 895 | - return $ret; |
|
| 896 | - } |
|
| 895 | + return $ret; |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | - return false; |
|
| 898 | + return false; |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -913,9 +913,9 @@ discard block |
||
| 913 | 913 | * true si le fichier a bien été créé ; false sinon. |
| 914 | 914 | */ |
| 915 | 915 | function _image_imageico($img, $fichier) { |
| 916 | - $gd_image_array = [$img]; |
|
| 916 | + $gd_image_array = [$img]; |
|
| 917 | 917 | |
| 918 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 918 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | |
@@ -934,24 +934,24 @@ discard block |
||
| 934 | 934 | * - true si une image est bien retournée. |
| 935 | 935 | */ |
| 936 | 936 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 937 | - if (!function_exists('imagewebp')) { |
|
| 938 | - return false; |
|
| 939 | - } |
|
| 940 | - $tmp = $fichier . '.tmp'; |
|
| 941 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 942 | - if (file_exists($tmp)) { |
|
| 943 | - $taille_test = getimagesize($tmp); |
|
| 944 | - if ($taille_test[0] < 1) { |
|
| 945 | - return false; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 949 | - @rename($tmp, $fichier); |
|
| 950 | - |
|
| 951 | - return $ret; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - return false; |
|
| 937 | + if (!function_exists('imagewebp')) { |
|
| 938 | + return false; |
|
| 939 | + } |
|
| 940 | + $tmp = $fichier . '.tmp'; |
|
| 941 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 942 | + if (file_exists($tmp)) { |
|
| 943 | + $taille_test = getimagesize($tmp); |
|
| 944 | + if ($taille_test[0] < 1) { |
|
| 945 | + return false; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 949 | + @rename($tmp, $fichier); |
|
| 950 | + |
|
| 951 | + return $ret; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + return false; |
|
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | /** |
@@ -971,35 +971,35 @@ discard block |
||
| 971 | 971 | */ |
| 972 | 972 | function _image_imagesvg($img, $fichier) { |
| 973 | 973 | |
| 974 | - $tmp = $fichier . '.tmp'; |
|
| 975 | - if (strpos($img, '<') === false) { |
|
| 976 | - $img = supprimer_timestamp($img); |
|
| 977 | - if (!file_exists($img)) { |
|
| 978 | - return false; |
|
| 979 | - } |
|
| 980 | - @copy($img, $tmp); |
|
| 981 | - if (filesize($tmp) == filesize($img)) { |
|
| 982 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 983 | - @rename($tmp, $fichier); |
|
| 984 | - return true; |
|
| 985 | - } |
|
| 986 | - return false; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - file_put_contents($tmp, $img); |
|
| 990 | - if (file_exists($tmp)) { |
|
| 991 | - $taille_test = spip_getimagesize($tmp); |
|
| 992 | - if ($taille_test[0] < 1) { |
|
| 993 | - return false; |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 997 | - @rename($tmp, $fichier); |
|
| 998 | - |
|
| 999 | - return true; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - return false; |
|
| 974 | + $tmp = $fichier . '.tmp'; |
|
| 975 | + if (strpos($img, '<') === false) { |
|
| 976 | + $img = supprimer_timestamp($img); |
|
| 977 | + if (!file_exists($img)) { |
|
| 978 | + return false; |
|
| 979 | + } |
|
| 980 | + @copy($img, $tmp); |
|
| 981 | + if (filesize($tmp) == filesize($img)) { |
|
| 982 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 983 | + @rename($tmp, $fichier); |
|
| 984 | + return true; |
|
| 985 | + } |
|
| 986 | + return false; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + file_put_contents($tmp, $img); |
|
| 990 | + if (file_exists($tmp)) { |
|
| 991 | + $taille_test = spip_getimagesize($tmp); |
|
| 992 | + if ($taille_test[0] < 1) { |
|
| 993 | + return false; |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 997 | + @rename($tmp, $fichier); |
|
| 998 | + |
|
| 999 | + return true; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + return false; |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | |
@@ -1027,29 +1027,29 @@ discard block |
||
| 1027 | 1027 | * - false sinon. |
| 1028 | 1028 | */ |
| 1029 | 1029 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1030 | - if (is_null($fonction)) { |
|
| 1031 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1032 | - } |
|
| 1033 | - $ret = false; |
|
| 1034 | - #un flag pour reperer les images gravees |
|
| 1035 | - $lock = |
|
| 1036 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1037 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1038 | - if ( |
|
| 1039 | - function_exists($fonction) |
|
| 1040 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1041 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1042 | - && !$lock |
|
| 1043 | - ) { |
|
| 1044 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1045 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1046 | - list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']); |
|
| 1047 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1048 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - return $ret; |
|
| 1030 | + if (is_null($fonction)) { |
|
| 1031 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1032 | + } |
|
| 1033 | + $ret = false; |
|
| 1034 | + #un flag pour reperer les images gravees |
|
| 1035 | + $lock = |
|
| 1036 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1037 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1038 | + if ( |
|
| 1039 | + function_exists($fonction) |
|
| 1040 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1041 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1042 | + && !$lock |
|
| 1043 | + ) { |
|
| 1044 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1045 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1046 | + list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']); |
|
| 1047 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1048 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + return $ret; |
|
| 1053 | 1053 | } |
| 1054 | 1054 | |
| 1055 | 1055 | /** |
@@ -1062,27 +1062,27 @@ discard block |
||
| 1062 | 1062 | * Chemin vers le fichier manquant |
| 1063 | 1063 | **/ |
| 1064 | 1064 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1065 | - $reconstruire = []; |
|
| 1066 | - $fichier = $fichier_manquant; |
|
| 1067 | - while ( |
|
| 1068 | - strpos($fichier, '://') === false |
|
| 1069 | - and !@file_exists($fichier) |
|
| 1070 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1071 | - and $valeurs = unserialize($source) |
|
| 1072 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1073 | - ) { |
|
| 1074 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1075 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1076 | - } |
|
| 1077 | - while (count($reconstruire)) { |
|
| 1078 | - $r = array_pop($reconstruire); |
|
| 1079 | - $fonction = $r[0]; |
|
| 1080 | - $args = $r[1]; |
|
| 1081 | - call_user_func_array($fonction, $args); |
|
| 1082 | - } |
|
| 1083 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1084 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1085 | - ramasse_miettes($fichier_manquant); |
|
| 1065 | + $reconstruire = []; |
|
| 1066 | + $fichier = $fichier_manquant; |
|
| 1067 | + while ( |
|
| 1068 | + strpos($fichier, '://') === false |
|
| 1069 | + and !@file_exists($fichier) |
|
| 1070 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1071 | + and $valeurs = unserialize($source) |
|
| 1072 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1073 | + ) { |
|
| 1074 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1075 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1076 | + } |
|
| 1077 | + while (count($reconstruire)) { |
|
| 1078 | + $r = array_pop($reconstruire); |
|
| 1079 | + $fonction = $r[0]; |
|
| 1080 | + $args = $r[1]; |
|
| 1081 | + call_user_func_array($fonction, $args); |
|
| 1082 | + } |
|
| 1083 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1084 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1085 | + ramasse_miettes($fichier_manquant); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
@@ -1102,28 +1102,28 @@ discard block |
||
| 1102 | 1102 | * Chemin du fichier d'image calculé |
| 1103 | 1103 | **/ |
| 1104 | 1104 | function ramasse_miettes($fichier) { |
| 1105 | - if ( |
|
| 1106 | - strpos($fichier, '://') !== false |
|
| 1107 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1108 | - or !$valeurs = unserialize($source) |
|
| 1109 | - ) { |
|
| 1110 | - return; |
|
| 1111 | - } |
|
| 1112 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1113 | - while ( |
|
| 1114 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1115 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1116 | - and (lire_fichier( |
|
| 1117 | - $src = "$fichier.src", |
|
| 1118 | - $source |
|
| 1119 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1120 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1121 | - ) { |
|
| 1122 | - # on efface le fichier |
|
| 1123 | - spip_unlink($fichier); |
|
| 1124 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1125 | - #spip_unlink($src); |
|
| 1126 | - } |
|
| 1105 | + if ( |
|
| 1106 | + strpos($fichier, '://') !== false |
|
| 1107 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1108 | + or !$valeurs = unserialize($source) |
|
| 1109 | + ) { |
|
| 1110 | + return; |
|
| 1111 | + } |
|
| 1112 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1113 | + while ( |
|
| 1114 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1115 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1116 | + and (lire_fichier( |
|
| 1117 | + $src = "$fichier.src", |
|
| 1118 | + $source |
|
| 1119 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1120 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1121 | + ) { |
|
| 1122 | + # on efface le fichier |
|
| 1123 | + spip_unlink($fichier); |
|
| 1124 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1125 | + #spip_unlink($src); |
|
| 1126 | + } |
|
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | |
@@ -1148,71 +1148,71 @@ discard block |
||
| 1148 | 1148 | * Code HTML de l'image |
| 1149 | 1149 | **/ |
| 1150 | 1150 | function image_graver($img) { |
| 1151 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1152 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1153 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1154 | - |
|
| 1155 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1156 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1157 | - $fichier = substr($fichier, 0, $p); |
|
| 1158 | - } |
|
| 1159 | - if (strlen($fichier) < 1) { |
|
| 1160 | - $fichier = $img; |
|
| 1161 | - } |
|
| 1162 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1163 | - # et qu'il ne s'agit pas d'une URL |
|
| 1164 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1165 | - reconstruire_image_intermediaire($fichier); |
|
| 1166 | - } |
|
| 1167 | - ramasse_miettes($fichier); |
|
| 1168 | - |
|
| 1169 | - // ajouter le timestamp si besoin |
|
| 1170 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1171 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1172 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - return $img; |
|
| 1151 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1152 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1153 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1154 | + |
|
| 1155 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1156 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1157 | + $fichier = substr($fichier, 0, $p); |
|
| 1158 | + } |
|
| 1159 | + if (strlen($fichier) < 1) { |
|
| 1160 | + $fichier = $img; |
|
| 1161 | + } |
|
| 1162 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1163 | + # et qu'il ne s'agit pas d'une URL |
|
| 1164 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1165 | + reconstruire_image_intermediaire($fichier); |
|
| 1166 | + } |
|
| 1167 | + ramasse_miettes($fichier); |
|
| 1168 | + |
|
| 1169 | + // ajouter le timestamp si besoin |
|
| 1170 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1171 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1172 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + return $img; |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | |
| 1179 | 1179 | if (!function_exists('imagepalettetotruecolor')) { |
| 1180 | - /** |
|
| 1181 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1182 | - * |
|
| 1183 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 1184 | - * |
|
| 1185 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1186 | - * |
|
| 1187 | - * @param ressource $img |
|
| 1188 | - * @return bool |
|
| 1189 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1190 | - * - false si la transformation ne peut être faite. |
|
| 1191 | - **/ |
|
| 1192 | - function imagepalettetotruecolor(&$img) { |
|
| 1193 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1194 | - return false; |
|
| 1195 | - } elseif (!imageistruecolor($img)) { |
|
| 1196 | - $w = imagesx($img); |
|
| 1197 | - $h = imagesy($img); |
|
| 1198 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 1199 | - //Conserver la transparence si possible |
|
| 1200 | - if (function_exists('ImageCopyResampled')) { |
|
| 1201 | - if (function_exists('imageAntiAlias')) { |
|
| 1202 | - imageAntiAlias($img1, true); |
|
| 1203 | - } |
|
| 1204 | - @imagealphablending($img1, false); |
|
| 1205 | - @imagesavealpha($img1, true); |
|
| 1206 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1207 | - } else { |
|
| 1208 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - $img = $img1; |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - return true; |
|
| 1215 | - } |
|
| 1180 | + /** |
|
| 1181 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1182 | + * |
|
| 1183 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 1184 | + * |
|
| 1185 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1186 | + * |
|
| 1187 | + * @param ressource $img |
|
| 1188 | + * @return bool |
|
| 1189 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1190 | + * - false si la transformation ne peut être faite. |
|
| 1191 | + **/ |
|
| 1192 | + function imagepalettetotruecolor(&$img) { |
|
| 1193 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1194 | + return false; |
|
| 1195 | + } elseif (!imageistruecolor($img)) { |
|
| 1196 | + $w = imagesx($img); |
|
| 1197 | + $h = imagesy($img); |
|
| 1198 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 1199 | + //Conserver la transparence si possible |
|
| 1200 | + if (function_exists('ImageCopyResampled')) { |
|
| 1201 | + if (function_exists('imageAntiAlias')) { |
|
| 1202 | + imageAntiAlias($img1, true); |
|
| 1203 | + } |
|
| 1204 | + @imagealphablending($img1, false); |
|
| 1205 | + @imagesavealpha($img1, true); |
|
| 1206 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1207 | + } else { |
|
| 1208 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + $img = $img1; |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + return true; |
|
| 1215 | + } |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | 1218 | /** |
@@ -1239,32 +1239,32 @@ discard block |
||
| 1239 | 1239 | * Code html modifié de la balise. |
| 1240 | 1240 | **/ |
| 1241 | 1241 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1242 | - if ($style === false) { |
|
| 1243 | - $style = extraire_attribut($tag, 'style'); |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - // enlever le width et height du style |
|
| 1247 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1248 | - if ($style and $style[0] == ';') { |
|
| 1249 | - $style = substr($style, 1); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - // mettre des attributs de width et height sur les images, |
|
| 1253 | - // ca accelere le rendu du navigateur |
|
| 1254 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1255 | - // quand on a desactive l'affichage des images. |
|
| 1256 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1257 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1258 | - |
|
| 1259 | - // attributs deprecies. Transformer en CSS |
|
| 1260 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1261 | - $style = "margin:${espace}px;" . $style; |
|
| 1262 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 1266 | - |
|
| 1267 | - return $tag; |
|
| 1242 | + if ($style === false) { |
|
| 1243 | + $style = extraire_attribut($tag, 'style'); |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + // enlever le width et height du style |
|
| 1247 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1248 | + if ($style and $style[0] == ';') { |
|
| 1249 | + $style = substr($style, 1); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + // mettre des attributs de width et height sur les images, |
|
| 1253 | + // ca accelere le rendu du navigateur |
|
| 1254 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1255 | + // quand on a desactive l'affichage des images. |
|
| 1256 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1257 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1258 | + |
|
| 1259 | + // attributs deprecies. Transformer en CSS |
|
| 1260 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1261 | + $style = "margin:${espace}px;" . $style; |
|
| 1262 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 1266 | + |
|
| 1267 | + return $tag; |
|
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | |
@@ -1290,72 +1290,72 @@ discard block |
||
| 1290 | 1290 | * Retourne le code HTML de l'image |
| 1291 | 1291 | **/ |
| 1292 | 1292 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1293 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1294 | - |
|
| 1295 | - // fermer les tags img pas bien fermes; |
|
| 1296 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1297 | - |
|
| 1298 | - // le style |
|
| 1299 | - $style = $valeurs['style']; |
|
| 1300 | - if (isset($surcharge['style'])) { |
|
| 1301 | - $style = $surcharge['style']; |
|
| 1302 | - unset($surcharge['style']); |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - // traiter specifiquement la largeur et la hauteur |
|
| 1306 | - $width = $valeurs['largeur']; |
|
| 1307 | - if (isset($surcharge['width'])) { |
|
| 1308 | - $width = $surcharge['width']; |
|
| 1309 | - unset($surcharge['width']); |
|
| 1310 | - } |
|
| 1311 | - $height = $valeurs['hauteur']; |
|
| 1312 | - if (isset($surcharge['height'])) { |
|
| 1313 | - $height = $surcharge['height']; |
|
| 1314 | - unset($surcharge['height']); |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1318 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1319 | - // on remplace toute les ref a src dans le tag |
|
| 1320 | - $src = extraire_attribut($tag, 'src'); |
|
| 1321 | - if (isset($surcharge['src'])) { |
|
| 1322 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1323 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1324 | - // pas garanti comme methode, mais mieux que rien |
|
| 1325 | - if (strpos($src, '&') !== false) { |
|
| 1326 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1327 | - } |
|
| 1328 | - $src = $surcharge['src']; |
|
| 1329 | - unset($surcharge['src']); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - $class = $valeurs['class']; |
|
| 1333 | - if (isset($surcharge['class'])) { |
|
| 1334 | - $class = $surcharge['class']; |
|
| 1335 | - unset($surcharge['class']); |
|
| 1336 | - } |
|
| 1337 | - if (strlen($class)) { |
|
| 1338 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - if (count($surcharge)) { |
|
| 1342 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1343 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1344 | - } |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - $tag = pipeline( |
|
| 1348 | - 'image_ecrire_tag_finir', |
|
| 1349 | - [ |
|
| 1350 | - 'args' => [ |
|
| 1351 | - 'valeurs' => $valeurs, |
|
| 1352 | - 'surcharge' => $surcharge, |
|
| 1353 | - ], |
|
| 1354 | - 'data' => $tag |
|
| 1355 | - ] |
|
| 1356 | - ); |
|
| 1357 | - |
|
| 1358 | - return $tag; |
|
| 1293 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1294 | + |
|
| 1295 | + // fermer les tags img pas bien fermes; |
|
| 1296 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1297 | + |
|
| 1298 | + // le style |
|
| 1299 | + $style = $valeurs['style']; |
|
| 1300 | + if (isset($surcharge['style'])) { |
|
| 1301 | + $style = $surcharge['style']; |
|
| 1302 | + unset($surcharge['style']); |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + // traiter specifiquement la largeur et la hauteur |
|
| 1306 | + $width = $valeurs['largeur']; |
|
| 1307 | + if (isset($surcharge['width'])) { |
|
| 1308 | + $width = $surcharge['width']; |
|
| 1309 | + unset($surcharge['width']); |
|
| 1310 | + } |
|
| 1311 | + $height = $valeurs['hauteur']; |
|
| 1312 | + if (isset($surcharge['height'])) { |
|
| 1313 | + $height = $surcharge['height']; |
|
| 1314 | + unset($surcharge['height']); |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1318 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1319 | + // on remplace toute les ref a src dans le tag |
|
| 1320 | + $src = extraire_attribut($tag, 'src'); |
|
| 1321 | + if (isset($surcharge['src'])) { |
|
| 1322 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1323 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1324 | + // pas garanti comme methode, mais mieux que rien |
|
| 1325 | + if (strpos($src, '&') !== false) { |
|
| 1326 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1327 | + } |
|
| 1328 | + $src = $surcharge['src']; |
|
| 1329 | + unset($surcharge['src']); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + $class = $valeurs['class']; |
|
| 1333 | + if (isset($surcharge['class'])) { |
|
| 1334 | + $class = $surcharge['class']; |
|
| 1335 | + unset($surcharge['class']); |
|
| 1336 | + } |
|
| 1337 | + if (strlen($class)) { |
|
| 1338 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + if (count($surcharge)) { |
|
| 1342 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1343 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1344 | + } |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + $tag = pipeline( |
|
| 1348 | + 'image_ecrire_tag_finir', |
|
| 1349 | + [ |
|
| 1350 | + 'args' => [ |
|
| 1351 | + 'valeurs' => $valeurs, |
|
| 1352 | + 'surcharge' => $surcharge, |
|
| 1353 | + ], |
|
| 1354 | + 'data' => $tag |
|
| 1355 | + ] |
|
| 1356 | + ); |
|
| 1357 | + |
|
| 1358 | + return $tag; |
|
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | /** |
@@ -1378,257 +1378,257 @@ discard block |
||
| 1378 | 1378 | * Description de l'image, sinon null. |
| 1379 | 1379 | **/ |
| 1380 | 1380 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1381 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1382 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1383 | - $image = $valeurs['fichier']; |
|
| 1384 | - $format = $valeurs['format_source']; |
|
| 1385 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1386 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1387 | - |
|
| 1388 | - $format_sortie = $valeurs['format_dest']; |
|
| 1389 | - |
|
| 1390 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1391 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1395 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1396 | - return; |
|
| 1397 | - } |
|
| 1398 | - $destination = "$destdir/$destfile"; |
|
| 1399 | - |
|
| 1400 | - // calculer la taille |
|
| 1401 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1402 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1403 | - list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 1404 | - } |
|
| 1405 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1406 | - $destWidth = $maxWidth; |
|
| 1407 | - $destHeight = $maxHeight; |
|
| 1408 | - } else { |
|
| 1409 | - spip_log("echec $process sur $image"); |
|
| 1410 | - |
|
| 1411 | - return; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - $vignette = ''; |
|
| 1415 | - |
|
| 1416 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1417 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1418 | - $vignette = $destination . '.' . $format; |
|
| 1419 | - @copy($image, $vignette); |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1423 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1424 | - $format_sortie = 'svg'; |
|
| 1425 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1426 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1427 | - _image_gd_output($svg, $valeurs); |
|
| 1428 | - } |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - // imagemagick en ligne de commande |
|
| 1432 | - elseif ($process == 'convert') { |
|
| 1433 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1434 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1435 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1436 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1437 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1438 | - } |
|
| 1439 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1440 | - $commande = str_replace( |
|
| 1441 | - ['%x', '%y', '%src', '%dest'], |
|
| 1442 | - [ |
|
| 1443 | - $destWidth, |
|
| 1444 | - $destHeight, |
|
| 1445 | - escapeshellcmd($image), |
|
| 1446 | - escapeshellcmd($vignette) |
|
| 1447 | - ], |
|
| 1448 | - _RESIZE_COMMAND |
|
| 1449 | - ); |
|
| 1450 | - spip_log($commande); |
|
| 1451 | - exec($commande); |
|
| 1452 | - if (!@file_exists($vignette)) { |
|
| 1453 | - spip_log("echec convert sur $vignette"); |
|
| 1454 | - |
|
| 1455 | - return; // echec commande |
|
| 1456 | - } |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - // php5 imagemagick |
|
| 1460 | - elseif ($process == 'imagick') { |
|
| 1461 | - $vignette = "$destination." . $format_sortie; |
|
| 1462 | - |
|
| 1463 | - if (!class_exists('Imagick')) { |
|
| 1464 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1465 | - |
|
| 1466 | - return; |
|
| 1467 | - } |
|
| 1468 | - $imagick = new Imagick(); |
|
| 1469 | - $imagick->readImage($image); |
|
| 1470 | - $imagick->resizeImage( |
|
| 1471 | - $destWidth, |
|
| 1472 | - $destHeight, |
|
| 1473 | - Imagick::FILTER_LANCZOS, |
|
| 1474 | - 1 |
|
| 1475 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1476 | - $imagick->writeImage($vignette); |
|
| 1477 | - |
|
| 1478 | - if (!@file_exists($vignette)) { |
|
| 1479 | - spip_log("echec imagick sur $vignette"); |
|
| 1480 | - |
|
| 1481 | - return; |
|
| 1482 | - } |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - // netpbm |
|
| 1486 | - elseif ($process == 'netpbm') { |
|
| 1487 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1488 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1489 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1490 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1491 | - return; |
|
| 1492 | - } |
|
| 1493 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1494 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1495 | - if ($format == 'jpg') { |
|
| 1496 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1497 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1498 | - if (!($s = @filesize($vignette))) { |
|
| 1499 | - spip_unlink($vignette); |
|
| 1500 | - } |
|
| 1501 | - if (!@file_exists($vignette)) { |
|
| 1502 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1503 | - |
|
| 1504 | - return; |
|
| 1505 | - } |
|
| 1506 | - } else { |
|
| 1507 | - if ($format == 'gif') { |
|
| 1508 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1509 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1510 | - if (!($s = @filesize($vignette))) { |
|
| 1511 | - spip_unlink($vignette); |
|
| 1512 | - } |
|
| 1513 | - if (!@file_exists($vignette)) { |
|
| 1514 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1515 | - |
|
| 1516 | - return; |
|
| 1517 | - } |
|
| 1518 | - } else { |
|
| 1519 | - if ($format == 'png') { |
|
| 1520 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1521 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1522 | - if (!($s = @filesize($vignette))) { |
|
| 1523 | - spip_unlink($vignette); |
|
| 1524 | - } |
|
| 1525 | - if (!@file_exists($vignette)) { |
|
| 1526 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1527 | - |
|
| 1528 | - return; |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - } |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - // gd ou gd2 |
|
| 1536 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1537 | - if (!function_exists('gd_info')) { |
|
| 1538 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1539 | - |
|
| 1540 | - return; |
|
| 1541 | - } |
|
| 1542 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1543 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1544 | - |
|
| 1545 | - return; |
|
| 1546 | - } |
|
| 1547 | - $destFormat = $format_sortie; |
|
| 1548 | - if (!$destFormat) { |
|
| 1549 | - spip_log("pas de format pour $image"); |
|
| 1550 | - |
|
| 1551 | - return; |
|
| 1552 | - } |
|
| 1553 | - |
|
| 1554 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1555 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1556 | - return ''; |
|
| 1557 | - } |
|
| 1558 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1559 | - if (!$srcImage) { |
|
| 1560 | - spip_log('echec gd1/gd2'); |
|
| 1561 | - |
|
| 1562 | - return; |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - // Initialisation de l'image destination |
|
| 1566 | - $destImage = null; |
|
| 1567 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1568 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1569 | - } |
|
| 1570 | - if (!$destImage) { |
|
| 1571 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1572 | - } |
|
| 1573 | - |
|
| 1574 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1575 | - $ok = false; |
|
| 1576 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1577 | - if ($format == 'gif') { |
|
| 1578 | - // Si un GIF est transparent, |
|
| 1579 | - // fabriquer un PNG transparent |
|
| 1580 | - $transp = imagecolortransparent($srcImage); |
|
| 1581 | - if ($transp > 0) { |
|
| 1582 | - $destFormat = 'png'; |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1586 | - // Conserver la transparence |
|
| 1587 | - if (function_exists('imageAntiAlias')) { |
|
| 1588 | - imageAntiAlias($destImage, true); |
|
| 1589 | - } |
|
| 1590 | - @imagealphablending($destImage, false); |
|
| 1591 | - @imagesavealpha($destImage, true); |
|
| 1592 | - } |
|
| 1593 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1594 | - } |
|
| 1595 | - if (!$ok) { |
|
| 1596 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - // Sauvegarde de l'image destination |
|
| 1600 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1601 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1602 | - _image_gd_output($destImage, $valeurs); |
|
| 1603 | - |
|
| 1604 | - if ($srcImage) { |
|
| 1605 | - ImageDestroy($srcImage); |
|
| 1606 | - } |
|
| 1607 | - ImageDestroy($destImage); |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1611 | - $size = [$destWidth, $destHeight]; |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1615 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1616 | - if ($size[0] < 1) { |
|
| 1617 | - $size[0] = $destWidth; |
|
| 1618 | - } |
|
| 1619 | - if ($size[1] < 1) { |
|
| 1620 | - $size[1] = $destHeight; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - $retour['width'] = $largeur = $size[0]; |
|
| 1624 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1625 | - |
|
| 1626 | - $retour['fichier'] = $vignette; |
|
| 1627 | - $retour['format'] = $format; |
|
| 1628 | - $retour['date'] = @filemtime($vignette); |
|
| 1629 | - |
|
| 1630 | - // renvoyer l'image |
|
| 1631 | - return $retour; |
|
| 1381 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1382 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1383 | + $image = $valeurs['fichier']; |
|
| 1384 | + $format = $valeurs['format_source']; |
|
| 1385 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1386 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1387 | + |
|
| 1388 | + $format_sortie = $valeurs['format_dest']; |
|
| 1389 | + |
|
| 1390 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1391 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1395 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1396 | + return; |
|
| 1397 | + } |
|
| 1398 | + $destination = "$destdir/$destfile"; |
|
| 1399 | + |
|
| 1400 | + // calculer la taille |
|
| 1401 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1402 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1403 | + list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 1404 | + } |
|
| 1405 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1406 | + $destWidth = $maxWidth; |
|
| 1407 | + $destHeight = $maxHeight; |
|
| 1408 | + } else { |
|
| 1409 | + spip_log("echec $process sur $image"); |
|
| 1410 | + |
|
| 1411 | + return; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + $vignette = ''; |
|
| 1415 | + |
|
| 1416 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1417 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1418 | + $vignette = $destination . '.' . $format; |
|
| 1419 | + @copy($image, $vignette); |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1423 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1424 | + $format_sortie = 'svg'; |
|
| 1425 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1426 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1427 | + _image_gd_output($svg, $valeurs); |
|
| 1428 | + } |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + // imagemagick en ligne de commande |
|
| 1432 | + elseif ($process == 'convert') { |
|
| 1433 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1434 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1435 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1436 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1437 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1438 | + } |
|
| 1439 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1440 | + $commande = str_replace( |
|
| 1441 | + ['%x', '%y', '%src', '%dest'], |
|
| 1442 | + [ |
|
| 1443 | + $destWidth, |
|
| 1444 | + $destHeight, |
|
| 1445 | + escapeshellcmd($image), |
|
| 1446 | + escapeshellcmd($vignette) |
|
| 1447 | + ], |
|
| 1448 | + _RESIZE_COMMAND |
|
| 1449 | + ); |
|
| 1450 | + spip_log($commande); |
|
| 1451 | + exec($commande); |
|
| 1452 | + if (!@file_exists($vignette)) { |
|
| 1453 | + spip_log("echec convert sur $vignette"); |
|
| 1454 | + |
|
| 1455 | + return; // echec commande |
|
| 1456 | + } |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + // php5 imagemagick |
|
| 1460 | + elseif ($process == 'imagick') { |
|
| 1461 | + $vignette = "$destination." . $format_sortie; |
|
| 1462 | + |
|
| 1463 | + if (!class_exists('Imagick')) { |
|
| 1464 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1465 | + |
|
| 1466 | + return; |
|
| 1467 | + } |
|
| 1468 | + $imagick = new Imagick(); |
|
| 1469 | + $imagick->readImage($image); |
|
| 1470 | + $imagick->resizeImage( |
|
| 1471 | + $destWidth, |
|
| 1472 | + $destHeight, |
|
| 1473 | + Imagick::FILTER_LANCZOS, |
|
| 1474 | + 1 |
|
| 1475 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1476 | + $imagick->writeImage($vignette); |
|
| 1477 | + |
|
| 1478 | + if (!@file_exists($vignette)) { |
|
| 1479 | + spip_log("echec imagick sur $vignette"); |
|
| 1480 | + |
|
| 1481 | + return; |
|
| 1482 | + } |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + // netpbm |
|
| 1486 | + elseif ($process == 'netpbm') { |
|
| 1487 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1488 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1489 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1490 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1491 | + return; |
|
| 1492 | + } |
|
| 1493 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1494 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1495 | + if ($format == 'jpg') { |
|
| 1496 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1497 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1498 | + if (!($s = @filesize($vignette))) { |
|
| 1499 | + spip_unlink($vignette); |
|
| 1500 | + } |
|
| 1501 | + if (!@file_exists($vignette)) { |
|
| 1502 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1503 | + |
|
| 1504 | + return; |
|
| 1505 | + } |
|
| 1506 | + } else { |
|
| 1507 | + if ($format == 'gif') { |
|
| 1508 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1509 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1510 | + if (!($s = @filesize($vignette))) { |
|
| 1511 | + spip_unlink($vignette); |
|
| 1512 | + } |
|
| 1513 | + if (!@file_exists($vignette)) { |
|
| 1514 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1515 | + |
|
| 1516 | + return; |
|
| 1517 | + } |
|
| 1518 | + } else { |
|
| 1519 | + if ($format == 'png') { |
|
| 1520 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1521 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1522 | + if (!($s = @filesize($vignette))) { |
|
| 1523 | + spip_unlink($vignette); |
|
| 1524 | + } |
|
| 1525 | + if (!@file_exists($vignette)) { |
|
| 1526 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1527 | + |
|
| 1528 | + return; |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + } |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + // gd ou gd2 |
|
| 1536 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1537 | + if (!function_exists('gd_info')) { |
|
| 1538 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1539 | + |
|
| 1540 | + return; |
|
| 1541 | + } |
|
| 1542 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1543 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1544 | + |
|
| 1545 | + return; |
|
| 1546 | + } |
|
| 1547 | + $destFormat = $format_sortie; |
|
| 1548 | + if (!$destFormat) { |
|
| 1549 | + spip_log("pas de format pour $image"); |
|
| 1550 | + |
|
| 1551 | + return; |
|
| 1552 | + } |
|
| 1553 | + |
|
| 1554 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1555 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1556 | + return ''; |
|
| 1557 | + } |
|
| 1558 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1559 | + if (!$srcImage) { |
|
| 1560 | + spip_log('echec gd1/gd2'); |
|
| 1561 | + |
|
| 1562 | + return; |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + // Initialisation de l'image destination |
|
| 1566 | + $destImage = null; |
|
| 1567 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1568 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1569 | + } |
|
| 1570 | + if (!$destImage) { |
|
| 1571 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1572 | + } |
|
| 1573 | + |
|
| 1574 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1575 | + $ok = false; |
|
| 1576 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1577 | + if ($format == 'gif') { |
|
| 1578 | + // Si un GIF est transparent, |
|
| 1579 | + // fabriquer un PNG transparent |
|
| 1580 | + $transp = imagecolortransparent($srcImage); |
|
| 1581 | + if ($transp > 0) { |
|
| 1582 | + $destFormat = 'png'; |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1586 | + // Conserver la transparence |
|
| 1587 | + if (function_exists('imageAntiAlias')) { |
|
| 1588 | + imageAntiAlias($destImage, true); |
|
| 1589 | + } |
|
| 1590 | + @imagealphablending($destImage, false); |
|
| 1591 | + @imagesavealpha($destImage, true); |
|
| 1592 | + } |
|
| 1593 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1594 | + } |
|
| 1595 | + if (!$ok) { |
|
| 1596 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + // Sauvegarde de l'image destination |
|
| 1600 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1601 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1602 | + _image_gd_output($destImage, $valeurs); |
|
| 1603 | + |
|
| 1604 | + if ($srcImage) { |
|
| 1605 | + ImageDestroy($srcImage); |
|
| 1606 | + } |
|
| 1607 | + ImageDestroy($destImage); |
|
| 1608 | + } |
|
| 1609 | + |
|
| 1610 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1611 | + $size = [$destWidth, $destHeight]; |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1615 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1616 | + if ($size[0] < 1) { |
|
| 1617 | + $size[0] = $destWidth; |
|
| 1618 | + } |
|
| 1619 | + if ($size[1] < 1) { |
|
| 1620 | + $size[1] = $destHeight; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + $retour['width'] = $largeur = $size[0]; |
|
| 1624 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1625 | + |
|
| 1626 | + $retour['fichier'] = $vignette; |
|
| 1627 | + $retour['format'] = $format; |
|
| 1628 | + $retour['date'] = @filemtime($vignette); |
|
| 1629 | + |
|
| 1630 | + // renvoyer l'image |
|
| 1631 | + return $retour; |
|
| 1632 | 1632 | } |
| 1633 | 1633 | |
| 1634 | 1634 | /** |
@@ -1648,25 +1648,25 @@ discard block |
||
| 1648 | 1648 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1649 | 1649 | **/ |
| 1650 | 1650 | function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1651 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1652 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1653 | - |
|
| 1654 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1655 | - $destWidth = $srcWidth; |
|
| 1656 | - $destHeight = $srcHeight; |
|
| 1657 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1658 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1659 | - $destHeight = $maxHeight; |
|
| 1660 | - } else { |
|
| 1661 | - $destWidth = $maxWidth; |
|
| 1662 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1663 | - } |
|
| 1664 | - |
|
| 1665 | - return [ |
|
| 1666 | - intval(round($destWidth)), |
|
| 1667 | - intval(round($destHeight)), |
|
| 1668 | - max($ratioWidth, $ratioHeight) |
|
| 1669 | - ]; |
|
| 1651 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1652 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1653 | + |
|
| 1654 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1655 | + $destWidth = $srcWidth; |
|
| 1656 | + $destHeight = $srcHeight; |
|
| 1657 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1658 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1659 | + $destHeight = $maxHeight; |
|
| 1660 | + } else { |
|
| 1661 | + $destWidth = $maxWidth; |
|
| 1662 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1663 | + } |
|
| 1664 | + |
|
| 1665 | + return [ |
|
| 1666 | + intval(round($destWidth)), |
|
| 1667 | + intval(round($destHeight)), |
|
| 1668 | + max($ratioWidth, $ratioHeight) |
|
| 1669 | + ]; |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | /** |
@@ -1686,25 +1686,25 @@ discard block |
||
| 1686 | 1686 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1687 | 1687 | **/ |
| 1688 | 1688 | function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1689 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1690 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1691 | - |
|
| 1692 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1693 | - $destWidth = $srcWidth; |
|
| 1694 | - $destHeight = $srcHeight; |
|
| 1695 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1696 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1697 | - $destHeight = $maxHeight; |
|
| 1698 | - } else { |
|
| 1699 | - $destWidth = $maxWidth; |
|
| 1700 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1701 | - } |
|
| 1702 | - |
|
| 1703 | - return [ |
|
| 1704 | - intval(round($destWidth)), |
|
| 1705 | - intval(round($destHeight)), |
|
| 1706 | - min($ratioWidth, $ratioHeight) |
|
| 1707 | - ]; |
|
| 1689 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1690 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1691 | + |
|
| 1692 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1693 | + $destWidth = $srcWidth; |
|
| 1694 | + $destHeight = $srcHeight; |
|
| 1695 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1696 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1697 | + $destHeight = $maxHeight; |
|
| 1698 | + } else { |
|
| 1699 | + $destWidth = $maxWidth; |
|
| 1700 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1701 | + } |
|
| 1702 | + |
|
| 1703 | + return [ |
|
| 1704 | + intval(round($destWidth)), |
|
| 1705 | + intval(round($destHeight)), |
|
| 1706 | + min($ratioWidth, $ratioHeight) |
|
| 1707 | + ]; |
|
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | 1710 | |
@@ -1717,12 +1717,12 @@ discard block |
||
| 1717 | 1717 | * @return string |
| 1718 | 1718 | */ |
| 1719 | 1719 | function process_image_svg_identite($image) { |
| 1720 | - if ($image['creer']) { |
|
| 1721 | - $source = $image['fichier']; |
|
| 1722 | - _image_gd_output($source, $image); |
|
| 1723 | - } |
|
| 1720 | + if ($image['creer']) { |
|
| 1721 | + $source = $image['fichier']; |
|
| 1722 | + _image_gd_output($source, $image); |
|
| 1723 | + } |
|
| 1724 | 1724 | |
| 1725 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1725 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | 1728 | |
@@ -1755,111 +1755,111 @@ discard block |
||
| 1755 | 1755 | * Code HTML de la balise img produite |
| 1756 | 1756 | **/ |
| 1757 | 1757 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1758 | - $image = false; |
|
| 1759 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1760 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1761 | - } |
|
| 1762 | - # determiner le format de sortie |
|
| 1763 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1764 | - if ($process == 'netpbm') { |
|
| 1765 | - $format_sortie = 'jpg'; |
|
| 1766 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1767 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1768 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1769 | - $gd_formats = formats_image_acceptables(true); |
|
| 1770 | - if ( |
|
| 1771 | - is_array($image) |
|
| 1772 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1773 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1774 | - ) |
|
| 1775 | - ) { |
|
| 1776 | - if ($image['format_source'] == 'jpg') { |
|
| 1777 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1778 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1779 | - { |
|
| 1780 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1781 | - } |
|
| 1782 | - // Choisir le format destination |
|
| 1783 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1784 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1785 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1786 | - # pas *ecrire* |
|
| 1787 | - $format_sortie = ''; |
|
| 1788 | - foreach ($formats_sortie as $fmt) { |
|
| 1789 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1790 | - $format_sortie = $fmt; |
|
| 1791 | - break; |
|
| 1792 | - } |
|
| 1793 | - } |
|
| 1794 | - $image = false; |
|
| 1795 | - } |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - if (!is_array($image)) { |
|
| 1799 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1800 | - } |
|
| 1801 | - |
|
| 1802 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1803 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1804 | - // on peut resizer en mode html si on dispose des elements |
|
| 1805 | - if ( |
|
| 1806 | - $srcw = extraire_attribut($img, 'width') |
|
| 1807 | - and $srch = extraire_attribut($img, 'height') |
|
| 1808 | - ) { |
|
| 1809 | - list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1810 | - |
|
| 1811 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1812 | - } |
|
| 1813 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1814 | - // sous la forme style='max-width: NNpx;' |
|
| 1815 | - return inserer_attribut( |
|
| 1816 | - $img, |
|
| 1817 | - 'style', |
|
| 1818 | - "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1819 | - ); |
|
| 1820 | - } |
|
| 1821 | - |
|
| 1822 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1823 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1824 | - if ($image['creer']) { |
|
| 1825 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1829 | - } |
|
| 1830 | - |
|
| 1831 | - if ($image['creer'] == false && !$force) { |
|
| 1832 | - return _image_ecrire_tag( |
|
| 1833 | - $image, |
|
| 1834 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1835 | - ); |
|
| 1836 | - } |
|
| 1837 | - |
|
| 1838 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1839 | - $destWidth = $image['largeur_dest']; |
|
| 1840 | - $destHeight = $image['hauteur_dest']; |
|
| 1841 | - $logo = $image['fichier']; |
|
| 1842 | - $date = $image['date_src']; |
|
| 1843 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1844 | - |
|
| 1845 | - if ($preview && $preview['fichier']) { |
|
| 1846 | - $logo = $preview['fichier']; |
|
| 1847 | - $destWidth = $preview['width']; |
|
| 1848 | - $destHeight = $preview['height']; |
|
| 1849 | - $date = $preview['date']; |
|
| 1850 | - } |
|
| 1851 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1852 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1853 | - // quand on fait supprimer/reuploader un logo |
|
| 1854 | - // (pas de filemtime si SAFE MODE) |
|
| 1855 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1856 | - |
|
| 1857 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1858 | - } |
|
| 1859 | - else { |
|
| 1860 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1861 | - return $img; |
|
| 1862 | - } |
|
| 1758 | + $image = false; |
|
| 1759 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1760 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1761 | + } |
|
| 1762 | + # determiner le format de sortie |
|
| 1763 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1764 | + if ($process == 'netpbm') { |
|
| 1765 | + $format_sortie = 'jpg'; |
|
| 1766 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1767 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1768 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1769 | + $gd_formats = formats_image_acceptables(true); |
|
| 1770 | + if ( |
|
| 1771 | + is_array($image) |
|
| 1772 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1773 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1774 | + ) |
|
| 1775 | + ) { |
|
| 1776 | + if ($image['format_source'] == 'jpg') { |
|
| 1777 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1778 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1779 | + { |
|
| 1780 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1781 | + } |
|
| 1782 | + // Choisir le format destination |
|
| 1783 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1784 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1785 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1786 | + # pas *ecrire* |
|
| 1787 | + $format_sortie = ''; |
|
| 1788 | + foreach ($formats_sortie as $fmt) { |
|
| 1789 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1790 | + $format_sortie = $fmt; |
|
| 1791 | + break; |
|
| 1792 | + } |
|
| 1793 | + } |
|
| 1794 | + $image = false; |
|
| 1795 | + } |
|
| 1796 | + } |
|
| 1797 | + |
|
| 1798 | + if (!is_array($image)) { |
|
| 1799 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1800 | + } |
|
| 1801 | + |
|
| 1802 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1803 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1804 | + // on peut resizer en mode html si on dispose des elements |
|
| 1805 | + if ( |
|
| 1806 | + $srcw = extraire_attribut($img, 'width') |
|
| 1807 | + and $srch = extraire_attribut($img, 'height') |
|
| 1808 | + ) { |
|
| 1809 | + list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1810 | + |
|
| 1811 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1812 | + } |
|
| 1813 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1814 | + // sous la forme style='max-width: NNpx;' |
|
| 1815 | + return inserer_attribut( |
|
| 1816 | + $img, |
|
| 1817 | + 'style', |
|
| 1818 | + "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1819 | + ); |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1823 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1824 | + if ($image['creer']) { |
|
| 1825 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1829 | + } |
|
| 1830 | + |
|
| 1831 | + if ($image['creer'] == false && !$force) { |
|
| 1832 | + return _image_ecrire_tag( |
|
| 1833 | + $image, |
|
| 1834 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1835 | + ); |
|
| 1836 | + } |
|
| 1837 | + |
|
| 1838 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1839 | + $destWidth = $image['largeur_dest']; |
|
| 1840 | + $destHeight = $image['hauteur_dest']; |
|
| 1841 | + $logo = $image['fichier']; |
|
| 1842 | + $date = $image['date_src']; |
|
| 1843 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1844 | + |
|
| 1845 | + if ($preview && $preview['fichier']) { |
|
| 1846 | + $logo = $preview['fichier']; |
|
| 1847 | + $destWidth = $preview['width']; |
|
| 1848 | + $destHeight = $preview['height']; |
|
| 1849 | + $date = $preview['date']; |
|
| 1850 | + } |
|
| 1851 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1852 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1853 | + // quand on fait supprimer/reuploader un logo |
|
| 1854 | + // (pas de filemtime si SAFE MODE) |
|
| 1855 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1856 | + |
|
| 1857 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1858 | + } |
|
| 1859 | + else { |
|
| 1860 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1861 | + return $img; |
|
| 1862 | + } |
|
| 1863 | 1863 | } |
| 1864 | 1864 | |
| 1865 | 1865 | /** |
@@ -1874,145 +1874,145 @@ discard block |
||
| 1874 | 1874 | */ |
| 1875 | 1875 | class phpthumb_functions { |
| 1876 | 1876 | |
| 1877 | - /** |
|
| 1878 | - * Retourne la couleur d'un pixel dans une image |
|
| 1879 | - * |
|
| 1880 | - * @param ressource $img |
|
| 1881 | - * @param int $x |
|
| 1882 | - * @param int $y |
|
| 1883 | - * @return array|bool |
|
| 1884 | - */ |
|
| 1885 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1886 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1887 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1888 | - } |
|
| 1889 | - return false; |
|
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - /** |
|
| 1893 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1894 | - * |
|
| 1895 | - * @param int $number |
|
| 1896 | - * @param int $minbytes |
|
| 1897 | - * @return string |
|
| 1898 | - */ |
|
| 1899 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1900 | - $intstring = ''; |
|
| 1901 | - while ($number > 0) { |
|
| 1902 | - $intstring = $intstring . chr($number & 255); |
|
| 1903 | - $number >>= 8; |
|
| 1904 | - } |
|
| 1905 | - |
|
| 1906 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1907 | - } |
|
| 1908 | - |
|
| 1909 | - /** |
|
| 1910 | - * Transforme une ressource GD en image au format ICO |
|
| 1911 | - * |
|
| 1912 | - * @param array $gd_image_array |
|
| 1913 | - * Tableau de ressources d'images GD |
|
| 1914 | - * @return string |
|
| 1915 | - * Image au format ICO |
|
| 1916 | - */ |
|
| 1917 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1918 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1919 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1920 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1921 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1922 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1923 | - |
|
| 1924 | - $icXOR[$key] = ''; |
|
| 1925 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1926 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1927 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1928 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1929 | - $r = $argb['red']; |
|
| 1930 | - $g = $argb['green']; |
|
| 1931 | - $b = $argb['blue']; |
|
| 1932 | - |
|
| 1933 | - if ($bpp[$key] == 32) { |
|
| 1934 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1935 | - } elseif ($bpp[$key] == 24) { |
|
| 1936 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1937 | - } |
|
| 1938 | - |
|
| 1939 | - if ($a < 128) { |
|
| 1940 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1941 | - } else { |
|
| 1942 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1943 | - } |
|
| 1944 | - } |
|
| 1945 | - // mask bits are 32-bit aligned per scanline |
|
| 1946 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1947 | - $icANDmask[$key][$y] .= '0'; |
|
| 1948 | - } |
|
| 1949 | - } |
|
| 1950 | - $icAND[$key] = ''; |
|
| 1951 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1952 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1953 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1954 | - } |
|
| 1955 | - } |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1959 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1960 | - |
|
| 1961 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1962 | - $BitmapInfoHeader[$key] = ''; |
|
| 1963 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1964 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1965 | - // The biHeight member specifies the combined |
|
| 1966 | - // height of the XOR and AND masks. |
|
| 1967 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1968 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1969 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1970 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1971 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1972 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1973 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1974 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1975 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - |
|
| 1979 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1980 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1981 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1982 | - |
|
| 1983 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1984 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1985 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1986 | - |
|
| 1987 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1988 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1989 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1990 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1991 | - |
|
| 1992 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1993 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1994 | - |
|
| 1995 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1996 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1997 | - $dwBytesInRes, |
|
| 1998 | - 4 |
|
| 1999 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2000 | - |
|
| 2001 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2002 | - $dwImageOffset, |
|
| 2003 | - 4 |
|
| 2004 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 2005 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2006 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 2007 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 2008 | - } |
|
| 2009 | - |
|
| 2010 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 2011 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 2012 | - $icondata .= $icXOR[$key]; |
|
| 2013 | - $icondata .= $icAND[$key]; |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - return $icondata; |
|
| 2017 | - } |
|
| 1877 | + /** |
|
| 1878 | + * Retourne la couleur d'un pixel dans une image |
|
| 1879 | + * |
|
| 1880 | + * @param ressource $img |
|
| 1881 | + * @param int $x |
|
| 1882 | + * @param int $y |
|
| 1883 | + * @return array|bool |
|
| 1884 | + */ |
|
| 1885 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1886 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1887 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1888 | + } |
|
| 1889 | + return false; |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + /** |
|
| 1893 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1894 | + * |
|
| 1895 | + * @param int $number |
|
| 1896 | + * @param int $minbytes |
|
| 1897 | + * @return string |
|
| 1898 | + */ |
|
| 1899 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1900 | + $intstring = ''; |
|
| 1901 | + while ($number > 0) { |
|
| 1902 | + $intstring = $intstring . chr($number & 255); |
|
| 1903 | + $number >>= 8; |
|
| 1904 | + } |
|
| 1905 | + |
|
| 1906 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1907 | + } |
|
| 1908 | + |
|
| 1909 | + /** |
|
| 1910 | + * Transforme une ressource GD en image au format ICO |
|
| 1911 | + * |
|
| 1912 | + * @param array $gd_image_array |
|
| 1913 | + * Tableau de ressources d'images GD |
|
| 1914 | + * @return string |
|
| 1915 | + * Image au format ICO |
|
| 1916 | + */ |
|
| 1917 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1918 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1919 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1920 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1921 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1922 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1923 | + |
|
| 1924 | + $icXOR[$key] = ''; |
|
| 1925 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1926 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1927 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1928 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1929 | + $r = $argb['red']; |
|
| 1930 | + $g = $argb['green']; |
|
| 1931 | + $b = $argb['blue']; |
|
| 1932 | + |
|
| 1933 | + if ($bpp[$key] == 32) { |
|
| 1934 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1935 | + } elseif ($bpp[$key] == 24) { |
|
| 1936 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1937 | + } |
|
| 1938 | + |
|
| 1939 | + if ($a < 128) { |
|
| 1940 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1941 | + } else { |
|
| 1942 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1943 | + } |
|
| 1944 | + } |
|
| 1945 | + // mask bits are 32-bit aligned per scanline |
|
| 1946 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1947 | + $icANDmask[$key][$y] .= '0'; |
|
| 1948 | + } |
|
| 1949 | + } |
|
| 1950 | + $icAND[$key] = ''; |
|
| 1951 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1952 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1953 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1954 | + } |
|
| 1955 | + } |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1959 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1960 | + |
|
| 1961 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1962 | + $BitmapInfoHeader[$key] = ''; |
|
| 1963 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1964 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1965 | + // The biHeight member specifies the combined |
|
| 1966 | + // height of the XOR and AND masks. |
|
| 1967 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1968 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1969 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1970 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1971 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1972 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1973 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1974 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1975 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + |
|
| 1979 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1980 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1981 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1982 | + |
|
| 1983 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1984 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1985 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1986 | + |
|
| 1987 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1988 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1989 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1990 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1991 | + |
|
| 1992 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1993 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1994 | + |
|
| 1995 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1996 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1997 | + $dwBytesInRes, |
|
| 1998 | + 4 |
|
| 1999 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2000 | + |
|
| 2001 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2002 | + $dwImageOffset, |
|
| 2003 | + 4 |
|
| 2004 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 2005 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2006 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 2007 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 2008 | + } |
|
| 2009 | + |
|
| 2010 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 2011 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 2012 | + $icondata .= $icXOR[$key]; |
|
| 2013 | + $icondata .= $icAND[$key]; |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + return $icondata; |
|
| 2017 | + } |
|
| 2018 | 2018 | } |