@@ -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 | |
@@ -52,68 +52,68 @@ discard block |
||
| 52 | 52 | * cookie sécurisé ou non ? |
| 53 | 53 | **/ |
| 54 | 54 | function spip_setcookie($name = '', $value = '', $options = []) { |
| 55 | - static $to_secure_list = ['spip_session']; |
|
| 56 | - if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | - $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (!is_array($options)) { |
|
| 61 | - // anciens paramètres : |
|
| 62 | - # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | - $opt = func_get_args(); |
|
| 64 | - $opt = array_slice($opt, 2); |
|
| 65 | - $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | - if (isset($opt[0])) { |
|
| 67 | - $options['expires'] = $opt[0]; |
|
| 68 | - } |
|
| 69 | - if (isset($opt[1])) { |
|
| 70 | - $options['path'] = $opt[1]; |
|
| 71 | - } |
|
| 72 | - if (isset($opt[2])) { |
|
| 73 | - $options['domain'] = $opt[2]; |
|
| 74 | - } |
|
| 75 | - if (isset($opt[3])) { |
|
| 76 | - $options['secure'] = $opt[3]; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // expires |
|
| 81 | - if (!isset($options['expires'])) { |
|
| 82 | - $options['expires'] = 0; |
|
| 83 | - } |
|
| 84 | - if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | - if (defined('_COOKIE_PATH')) { |
|
| 86 | - $options['path'] = _COOKIE_PATH; |
|
| 87 | - } else { |
|
| 88 | - $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | - $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | - } |
|
| 94 | - if (in_array($name, $to_secure_list)) { |
|
| 95 | - if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | - $options['secure'] = true; |
|
| 97 | - } |
|
| 98 | - if (empty($options['httponly'])) { |
|
| 99 | - $options['httponly'] = true; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - if (empty($options['samesite'])) { |
|
| 103 | - $options['samesite'] = 'Lax'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // in fine renommer le prefixe si besoin |
|
| 107 | - if (strpos($name, 'spip_') === 0) { |
|
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | - $a = @setcookie($name, $value, $options); |
|
| 113 | - |
|
| 114 | - spip_cookie_envoye(true); |
|
| 115 | - |
|
| 116 | - return $a; |
|
| 55 | + static $to_secure_list = ['spip_session']; |
|
| 56 | + if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | + $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (!is_array($options)) { |
|
| 61 | + // anciens paramètres : |
|
| 62 | + # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | + $opt = func_get_args(); |
|
| 64 | + $opt = array_slice($opt, 2); |
|
| 65 | + $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | + if (isset($opt[0])) { |
|
| 67 | + $options['expires'] = $opt[0]; |
|
| 68 | + } |
|
| 69 | + if (isset($opt[1])) { |
|
| 70 | + $options['path'] = $opt[1]; |
|
| 71 | + } |
|
| 72 | + if (isset($opt[2])) { |
|
| 73 | + $options['domain'] = $opt[2]; |
|
| 74 | + } |
|
| 75 | + if (isset($opt[3])) { |
|
| 76 | + $options['secure'] = $opt[3]; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // expires |
|
| 81 | + if (!isset($options['expires'])) { |
|
| 82 | + $options['expires'] = 0; |
|
| 83 | + } |
|
| 84 | + if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | + if (defined('_COOKIE_PATH')) { |
|
| 86 | + $options['path'] = _COOKIE_PATH; |
|
| 87 | + } else { |
|
| 88 | + $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | + $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | + } |
|
| 94 | + if (in_array($name, $to_secure_list)) { |
|
| 95 | + if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | + $options['secure'] = true; |
|
| 97 | + } |
|
| 98 | + if (empty($options['httponly'])) { |
|
| 99 | + $options['httponly'] = true; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + if (empty($options['samesite'])) { |
|
| 103 | + $options['samesite'] = 'Lax'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // in fine renommer le prefixe si besoin |
|
| 107 | + if (strpos($name, 'spip_') === 0) { |
|
| 108 | + $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | + $a = @setcookie($name, $value, $options); |
|
| 113 | + |
|
| 114 | + spip_cookie_envoye(true); |
|
| 115 | + |
|
| 116 | + return $a; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @return bool |
| 130 | 130 | **/ |
| 131 | 131 | function spip_cookie_envoye($set = '') { |
| 132 | - static $envoye = false; |
|
| 133 | - if ($set) { |
|
| 134 | - $envoye = true; |
|
| 135 | - } |
|
| 132 | + static $envoye = false; |
|
| 133 | + if ($set) { |
|
| 134 | + $envoye = true; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $envoye; |
|
| 137 | + return $envoye; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -153,21 +153,21 @@ discard block |
||
| 153 | 153 | * Préfixe des cookies de SPIP |
| 154 | 154 | **/ |
| 155 | 155 | function recuperer_cookies_spip($cookie_prefix) { |
| 156 | - $prefix_long = strlen($cookie_prefix); |
|
| 157 | - |
|
| 158 | - foreach ($_COOKIE as $name => $value) { |
|
| 159 | - if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | - unset($_COOKIE[$name]); |
|
| 161 | - unset($GLOBALS[$name]); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - foreach ($_COOKIE as $name => $value) { |
|
| 165 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | - $_COOKIE[$spipname] = $value; |
|
| 168 | - $GLOBALS[$spipname] = $value; |
|
| 169 | - } |
|
| 170 | - } |
|
| 156 | + $prefix_long = strlen($cookie_prefix); |
|
| 157 | + |
|
| 158 | + foreach ($_COOKIE as $name => $value) { |
|
| 159 | + if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | + unset($_COOKIE[$name]); |
|
| 161 | + unset($GLOBALS[$name]); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + foreach ($_COOKIE as $name => $value) { |
|
| 165 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | + $_COOKIE[$spipname] = $value; |
|
| 168 | + $GLOBALS[$spipname] = $value; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -186,18 +186,18 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | **/ |
| 188 | 188 | function exec_test_ajax_dist() { |
| 189 | - switch (_request('js')) { |
|
| 190 | - // on est appele par <noscript> |
|
| 191 | - case -1: |
|
| 192 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | - include_spip('inc/headers'); |
|
| 194 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | - break; |
|
| 196 | - |
|
| 197 | - // ou par ajax |
|
| 198 | - case 1: |
|
| 199 | - default: |
|
| 200 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | - break; |
|
| 202 | - } |
|
| 189 | + switch (_request('js')) { |
|
| 190 | + // on est appele par <noscript> |
|
| 191 | + case -1: |
|
| 192 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | + include_spip('inc/headers'); |
|
| 194 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | + break; |
|
| 196 | + |
|
| 197 | + // ou par ajax |
|
| 198 | + case 1: |
|
| 199 | + default: |
|
| 200 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | + break; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | // in fine renommer le prefixe si besoin |
| 107 | 107 | if (strpos($name, 'spip_') === 0) { |
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 108 | + $name = $GLOBALS['cookie_prefix'].'_'.substr($name, 5); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | foreach ($_COOKIE as $name => $value) { |
| 165 | 165 | if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 166 | + $spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name); |
|
| 167 | 167 | $_COOKIE[$spipname] = $value; |
| 168 | 168 | $GLOBALS[$spipname] = $value; |
| 169 | 169 | } |
@@ -121,8 +121,7 @@ discard block |
||
| 121 | 121 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 122 | 122 | spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
| 123 | 123 | @unlink($localrac_tmp); |
| 124 | - } |
|
| 125 | - else { |
|
| 124 | + } else { |
|
| 126 | 125 | spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
| 127 | 126 | } |
| 128 | 127 | if (!$res or !$res['length']) { |
@@ -240,8 +239,7 @@ discard block |
||
| 240 | 239 | break; |
| 241 | 240 | } |
| 242 | 241 | } |
| 243 | - } |
|
| 244 | - else { |
|
| 242 | + } else { |
|
| 245 | 243 | $ip = false; |
| 246 | 244 | } |
| 247 | 245 | } |
@@ -18,32 +18,32 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\Distant |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 25 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 25 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 26 | 26 | } |
| 27 | 27 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 28 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 28 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 29 | 29 | } |
| 30 | 30 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 31 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 31 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 32 | 32 | } |
| 33 | 33 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 34 | - define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 34 | + define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 35 | 35 | } |
| 36 | 36 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 37 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 37 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 41 | - preg_replace( |
|
| 42 | - '@^https?:@', |
|
| 43 | - 'https?:', |
|
| 44 | - ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 45 | - ) |
|
| 46 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 41 | + preg_replace( |
|
| 42 | + '@^https?:@', |
|
| 43 | + 'https?:', |
|
| 44 | + ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 45 | + ) |
|
| 46 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 47 | 47 | |
| 48 | 48 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 49 | 49 | |
@@ -72,107 +72,107 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) { |
| 74 | 74 | |
| 75 | - // si c'est la protection de soi-meme, retourner le path |
|
| 76 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 77 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 78 | - |
|
| 79 | - return @file_exists($source) ? $source : false; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (is_null($local)) { |
|
| 83 | - $local = fichier_copie_locale($source); |
|
| 84 | - } else { |
|
| 85 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 86 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 91 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 92 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 93 | - if (!$local) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $localrac = _DIR_RACINE . $local; |
|
| 98 | - $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 99 | - |
|
| 100 | - // test d'existence du fichier |
|
| 101 | - if ($mode === 'test') { |
|
| 102 | - return $t ? $local : ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // sinon voir si on doit/peut le telecharger |
|
| 106 | - if ($local === $source or !tester_url_absolue($source)) { |
|
| 107 | - return $t ? $local : ''; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($mode === 'modif' or !$t) { |
|
| 111 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 112 | - // et des eventuelles recuperations concurantes |
|
| 113 | - include_spip('inc/acces'); |
|
| 114 | - if (!$taille_max) { |
|
| 115 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 116 | - } |
|
| 117 | - $localrac_tmp = $localrac . '.tmp'; |
|
| 118 | - $res = recuperer_url( |
|
| 119 | - $source, |
|
| 120 | - ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 124 | - spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 125 | - @unlink($localrac_tmp); |
|
| 126 | - } |
|
| 127 | - else { |
|
| 128 | - spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 129 | - } |
|
| 130 | - if (!$res or !$res['length']) { |
|
| 131 | - // si $t c'est sans doute juste un not-modified-since |
|
| 132 | - return $t ? $local : false; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // si option valider url, verifions que l'URL finale est acceptable |
|
| 136 | - if ( |
|
| 137 | - $callback_valider_url |
|
| 138 | - and is_callable($callback_valider_url) |
|
| 139 | - and !$callback_valider_url($res['url']) |
|
| 140 | - ) { |
|
| 141 | - spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 142 | - @unlink($localrac_tmp); |
|
| 143 | - return $t ? $local : false; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // on peut renommer le fichier tmp |
|
| 147 | - @rename($localrac_tmp, $localrac); |
|
| 148 | - |
|
| 149 | - // si on retrouve l'extension |
|
| 150 | - if ( |
|
| 151 | - !empty($res['headers']) |
|
| 152 | - and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 153 | - ) { |
|
| 154 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 155 | - $sanitizer($localrac); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // pour une eventuelle indexation |
|
| 160 | - pipeline( |
|
| 161 | - 'post_edition', |
|
| 162 | - [ |
|
| 163 | - 'args' => [ |
|
| 164 | - 'operation' => 'copie_locale', |
|
| 165 | - 'source' => $source, |
|
| 166 | - 'fichier' => $local, |
|
| 167 | - 'http_res' => $res['length'], |
|
| 168 | - 'url' => $res['url'], |
|
| 169 | - ], |
|
| 170 | - 'data' => null |
|
| 171 | - ] |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $local; |
|
| 75 | + // si c'est la protection de soi-meme, retourner le path |
|
| 76 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 77 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 78 | + |
|
| 79 | + return @file_exists($source) ? $source : false; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (is_null($local)) { |
|
| 83 | + $local = fichier_copie_locale($source); |
|
| 84 | + } else { |
|
| 85 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 86 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 91 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 92 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 93 | + if (!$local) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $localrac = _DIR_RACINE . $local; |
|
| 98 | + $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 99 | + |
|
| 100 | + // test d'existence du fichier |
|
| 101 | + if ($mode === 'test') { |
|
| 102 | + return $t ? $local : ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // sinon voir si on doit/peut le telecharger |
|
| 106 | + if ($local === $source or !tester_url_absolue($source)) { |
|
| 107 | + return $t ? $local : ''; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($mode === 'modif' or !$t) { |
|
| 111 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 112 | + // et des eventuelles recuperations concurantes |
|
| 113 | + include_spip('inc/acces'); |
|
| 114 | + if (!$taille_max) { |
|
| 115 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 116 | + } |
|
| 117 | + $localrac_tmp = $localrac . '.tmp'; |
|
| 118 | + $res = recuperer_url( |
|
| 119 | + $source, |
|
| 120 | + ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 124 | + spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 125 | + @unlink($localrac_tmp); |
|
| 126 | + } |
|
| 127 | + else { |
|
| 128 | + spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 129 | + } |
|
| 130 | + if (!$res or !$res['length']) { |
|
| 131 | + // si $t c'est sans doute juste un not-modified-since |
|
| 132 | + return $t ? $local : false; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // si option valider url, verifions que l'URL finale est acceptable |
|
| 136 | + if ( |
|
| 137 | + $callback_valider_url |
|
| 138 | + and is_callable($callback_valider_url) |
|
| 139 | + and !$callback_valider_url($res['url']) |
|
| 140 | + ) { |
|
| 141 | + spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 142 | + @unlink($localrac_tmp); |
|
| 143 | + return $t ? $local : false; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // on peut renommer le fichier tmp |
|
| 147 | + @rename($localrac_tmp, $localrac); |
|
| 148 | + |
|
| 149 | + // si on retrouve l'extension |
|
| 150 | + if ( |
|
| 151 | + !empty($res['headers']) |
|
| 152 | + and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 153 | + ) { |
|
| 154 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 155 | + $sanitizer($localrac); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // pour une eventuelle indexation |
|
| 160 | + pipeline( |
|
| 161 | + 'post_edition', |
|
| 162 | + [ |
|
| 163 | + 'args' => [ |
|
| 164 | + 'operation' => 'copie_locale', |
|
| 165 | + 'source' => $source, |
|
| 166 | + 'fichier' => $local, |
|
| 167 | + 'http_res' => $res['length'], |
|
| 168 | + 'url' => $res['url'], |
|
| 169 | + ], |
|
| 170 | + 'data' => null |
|
| 171 | + ] |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $local; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -187,99 +187,99 @@ discard block |
||
| 187 | 187 | * url ou false en cas d'echec |
| 188 | 188 | */ |
| 189 | 189 | function valider_url_distante($url, $known_hosts = []) { |
| 190 | - if (!function_exists('protocole_verifier')) { |
|
| 191 | - include_spip('inc/filtres_mini'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $parsed_url = parse_url($url); |
|
| 199 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 200 | - return false; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if (!is_array($known_hosts)) { |
|
| 212 | - $known_hosts = [$known_hosts]; |
|
| 213 | - } |
|
| 214 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 215 | - $known_hosts[] = url_de_base(); |
|
| 216 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 217 | - |
|
| 218 | - $is_known_host = false; |
|
| 219 | - foreach ($known_hosts as $known_host) { |
|
| 220 | - $parse_known = parse_url($known_host); |
|
| 221 | - if ( |
|
| 222 | - $parse_known |
|
| 223 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 224 | - ) { |
|
| 225 | - $is_known_host = true; |
|
| 226 | - break; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if (!$is_known_host) { |
|
| 231 | - $host = trim($parsed_url['host'], '.'); |
|
| 232 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 233 | - $ip = gethostbyname($host); |
|
| 234 | - if ($ip === $host) { |
|
| 235 | - // Error condition for gethostbyname() |
|
| 236 | - $ip = false; |
|
| 237 | - } |
|
| 238 | - if ($records = dns_get_record($host)) { |
|
| 239 | - foreach ($records as $record) { |
|
| 240 | - // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 241 | - // se fasse sur la meme IP |
|
| 242 | - if ($record['ttl'] < 10) { |
|
| 243 | - $ip = false; |
|
| 244 | - break; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - else { |
|
| 249 | - $ip = false; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - if ($ip) { |
|
| 253 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 254 | - return false; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if (empty($parsed_url['port'])) { |
|
| 260 | - return $url; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - $port = $parsed_url['port']; |
|
| 264 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 265 | - return $url; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if ($is_known_host) { |
|
| 269 | - foreach ($known_hosts as $known_host) { |
|
| 270 | - $parse_known = parse_url($known_host); |
|
| 271 | - if ( |
|
| 272 | - $parse_known |
|
| 273 | - and !empty($parse_known['port']) |
|
| 274 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 275 | - and $parse_known['port'] == $port |
|
| 276 | - ) { |
|
| 277 | - return $url; |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - return false; |
|
| 190 | + if (!function_exists('protocole_verifier')) { |
|
| 191 | + include_spip('inc/filtres_mini'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $parsed_url = parse_url($url); |
|
| 199 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 200 | + return false; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if (!is_array($known_hosts)) { |
|
| 212 | + $known_hosts = [$known_hosts]; |
|
| 213 | + } |
|
| 214 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 215 | + $known_hosts[] = url_de_base(); |
|
| 216 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 217 | + |
|
| 218 | + $is_known_host = false; |
|
| 219 | + foreach ($known_hosts as $known_host) { |
|
| 220 | + $parse_known = parse_url($known_host); |
|
| 221 | + if ( |
|
| 222 | + $parse_known |
|
| 223 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 224 | + ) { |
|
| 225 | + $is_known_host = true; |
|
| 226 | + break; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if (!$is_known_host) { |
|
| 231 | + $host = trim($parsed_url['host'], '.'); |
|
| 232 | + if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 233 | + $ip = gethostbyname($host); |
|
| 234 | + if ($ip === $host) { |
|
| 235 | + // Error condition for gethostbyname() |
|
| 236 | + $ip = false; |
|
| 237 | + } |
|
| 238 | + if ($records = dns_get_record($host)) { |
|
| 239 | + foreach ($records as $record) { |
|
| 240 | + // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 241 | + // se fasse sur la meme IP |
|
| 242 | + if ($record['ttl'] < 10) { |
|
| 243 | + $ip = false; |
|
| 244 | + break; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + else { |
|
| 249 | + $ip = false; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + if ($ip) { |
|
| 253 | + if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 254 | + return false; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if (empty($parsed_url['port'])) { |
|
| 260 | + return $url; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + $port = $parsed_url['port']; |
|
| 264 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 265 | + return $url; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if ($is_known_host) { |
|
| 269 | + foreach ($known_hosts as $known_host) { |
|
| 270 | + $parse_known = parse_url($known_host); |
|
| 271 | + if ( |
|
| 272 | + $parse_known |
|
| 273 | + and !empty($parse_known['port']) |
|
| 274 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 275 | + and $parse_known['port'] == $port |
|
| 276 | + ) { |
|
| 277 | + return $url; |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + return false; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -299,86 +299,86 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function prepare_donnees_post($donnees, $boundary = '') { |
| 301 | 301 | |
| 302 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 303 | - // pour un appel soap par exemple |
|
| 304 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 305 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 306 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 307 | - $entete = ''; |
|
| 308 | - // on repasse tous les \r\n et \r en simples \n |
|
| 309 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 310 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 311 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 312 | - $p = strpos($donnees, "\n\n"); |
|
| 313 | - if ($p !== false) { |
|
| 314 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 315 | - $donnees = substr($donnees, $p + 2); |
|
| 316 | - } |
|
| 317 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 318 | - } else { |
|
| 319 | - /* boundary automatique */ |
|
| 320 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 321 | - if ($boundary === '') { |
|
| 322 | - $taille = 0; |
|
| 323 | - foreach ($donnees as $cle => $valeur) { |
|
| 324 | - if (is_array($valeur)) { |
|
| 325 | - foreach ($valeur as $val2) { |
|
| 326 | - $taille += strlen($val2); |
|
| 327 | - } |
|
| 328 | - } else { |
|
| 329 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 330 | - $taille += strlen($valeur); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - if ($taille > 500) { |
|
| 334 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 339 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 340 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 341 | - $chaine = ''; |
|
| 342 | - if (is_array($donnees)) { |
|
| 343 | - foreach ($donnees as $cle => $valeur) { |
|
| 344 | - if (is_array($valeur)) { |
|
| 345 | - foreach ($valeur as $val2) { |
|
| 346 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 347 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 348 | - $chaine .= "\r\n"; |
|
| 349 | - $chaine .= $val2; |
|
| 350 | - } |
|
| 351 | - } else { |
|
| 352 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 353 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 354 | - $chaine .= "\r\n"; |
|
| 355 | - $chaine .= $valeur; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 359 | - } |
|
| 360 | - } else { |
|
| 361 | - // fabrique une chaine HTTP simple pour un POST |
|
| 362 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 363 | - $chaine = []; |
|
| 364 | - if (is_array($donnees)) { |
|
| 365 | - foreach ($donnees as $cle => $valeur) { |
|
| 366 | - if (is_array($valeur)) { |
|
| 367 | - foreach ($valeur as $val2) { |
|
| 368 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 369 | - } |
|
| 370 | - } else { |
|
| 371 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - $chaine = implode('&', $chaine); |
|
| 375 | - } else { |
|
| 376 | - $chaine = $donnees; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - return [$entete, $chaine]; |
|
| 302 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 303 | + // pour un appel soap par exemple |
|
| 304 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 305 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 306 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 307 | + $entete = ''; |
|
| 308 | + // on repasse tous les \r\n et \r en simples \n |
|
| 309 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 310 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 311 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 312 | + $p = strpos($donnees, "\n\n"); |
|
| 313 | + if ($p !== false) { |
|
| 314 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 315 | + $donnees = substr($donnees, $p + 2); |
|
| 316 | + } |
|
| 317 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 318 | + } else { |
|
| 319 | + /* boundary automatique */ |
|
| 320 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 321 | + if ($boundary === '') { |
|
| 322 | + $taille = 0; |
|
| 323 | + foreach ($donnees as $cle => $valeur) { |
|
| 324 | + if (is_array($valeur)) { |
|
| 325 | + foreach ($valeur as $val2) { |
|
| 326 | + $taille += strlen($val2); |
|
| 327 | + } |
|
| 328 | + } else { |
|
| 329 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 330 | + $taille += strlen($valeur); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + if ($taille > 500) { |
|
| 334 | + $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 339 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 340 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 341 | + $chaine = ''; |
|
| 342 | + if (is_array($donnees)) { |
|
| 343 | + foreach ($donnees as $cle => $valeur) { |
|
| 344 | + if (is_array($valeur)) { |
|
| 345 | + foreach ($valeur as $val2) { |
|
| 346 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 347 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 348 | + $chaine .= "\r\n"; |
|
| 349 | + $chaine .= $val2; |
|
| 350 | + } |
|
| 351 | + } else { |
|
| 352 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 353 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 354 | + $chaine .= "\r\n"; |
|
| 355 | + $chaine .= $valeur; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 359 | + } |
|
| 360 | + } else { |
|
| 361 | + // fabrique une chaine HTTP simple pour un POST |
|
| 362 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 363 | + $chaine = []; |
|
| 364 | + if (is_array($donnees)) { |
|
| 365 | + foreach ($donnees as $cle => $valeur) { |
|
| 366 | + if (is_array($valeur)) { |
|
| 367 | + foreach ($valeur as $val2) { |
|
| 368 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 369 | + } |
|
| 370 | + } else { |
|
| 371 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + $chaine = implode('&', $chaine); |
|
| 375 | + } else { |
|
| 376 | + $chaine = $donnees; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + return [$entete, $chaine]; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -389,19 +389,19 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | function url_to_ascii($url_idn) { |
| 391 | 391 | |
| 392 | - if ($parts = parse_url($url_idn)) { |
|
| 393 | - $host = $parts['host']; |
|
| 394 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 395 | - $converter = new ToIdn(); |
|
| 396 | - $host_ascii = $converter->convert($host); |
|
| 397 | - $url_idn = explode($host, $url_idn, 2); |
|
| 398 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 399 | - } |
|
| 400 | - // et on urlencode les char utf si besoin dans le path |
|
| 401 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return $url_idn; |
|
| 392 | + if ($parts = parse_url($url_idn)) { |
|
| 393 | + $host = $parts['host']; |
|
| 394 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 395 | + $converter = new ToIdn(); |
|
| 396 | + $host_ascii = $converter->convert($host); |
|
| 397 | + $url_idn = explode($host, $url_idn, 2); |
|
| 398 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 399 | + } |
|
| 400 | + // et on urlencode les char utf si besoin dans le path |
|
| 401 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return $url_idn; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -442,209 +442,209 @@ discard block |
||
| 442 | 442 | * string file : nom du fichier si enregistre dans un fichier |
| 443 | 443 | */ |
| 444 | 444 | function recuperer_url($url, $options = []) { |
| 445 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 446 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 447 | - $default = [ |
|
| 448 | - 'transcoder' => false, |
|
| 449 | - 'methode' => 'GET', |
|
| 450 | - 'taille_max' => null, |
|
| 451 | - 'headers' => [], |
|
| 452 | - 'datas' => '', |
|
| 453 | - 'boundary' => '', |
|
| 454 | - 'refuser_gz' => false, |
|
| 455 | - 'if_modified_since' => '', |
|
| 456 | - 'uri_referer' => '', |
|
| 457 | - 'file' => '', |
|
| 458 | - 'follow_location' => 10, |
|
| 459 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 460 | - ]; |
|
| 461 | - $options = array_merge($default, $options); |
|
| 462 | - // copier directement dans un fichier ? |
|
| 463 | - $copy = $options['file']; |
|
| 464 | - |
|
| 465 | - if ($options['methode'] == 'HEAD') { |
|
| 466 | - $options['taille_max'] = 0; |
|
| 467 | - } |
|
| 468 | - if (is_null($options['taille_max'])) { |
|
| 469 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 473 | - |
|
| 474 | - // Ajout des en-têtes spécifiques si besoin |
|
| 475 | - $formatted_data = ''; |
|
| 476 | - if (!empty($options['headers'])) { |
|
| 477 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 478 | - $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if (!empty($options['datas'])) { |
|
| 483 | - [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 484 | - $head .= $formatted_data; |
|
| 485 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 486 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 487 | - } |
|
| 488 | - $formatted_data = $head . "\r\n" . $postdata; |
|
| 489 | - if ( |
|
| 490 | - strlen($postdata) |
|
| 491 | - and !$methode_demandee |
|
| 492 | - ) { |
|
| 493 | - $options['methode'] = 'POST'; |
|
| 494 | - } |
|
| 495 | - } elseif ($formatted_data) { |
|
| 496 | - $formatted_data .= "\r\n"; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 500 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 501 | - if (!tester_url_absolue($url)) { |
|
| 502 | - $url = 'http://' . $url; |
|
| 503 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 504 | - $url = 'http:' . $url; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $url = url_to_ascii($url); |
|
| 508 | - |
|
| 509 | - $result = [ |
|
| 510 | - 'status' => 0, |
|
| 511 | - 'headers' => '', |
|
| 512 | - 'page' => '', |
|
| 513 | - 'length' => 0, |
|
| 514 | - 'last_modified' => '', |
|
| 515 | - 'location' => '', |
|
| 516 | - 'url' => $url |
|
| 517 | - ]; |
|
| 518 | - |
|
| 519 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 520 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 521 | - |
|
| 522 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 523 | - [$handle, $fopen] = init_http( |
|
| 524 | - $options['methode'], |
|
| 525 | - $url, |
|
| 526 | - $refuser_gz, |
|
| 527 | - $options['uri_referer'], |
|
| 528 | - $formatted_data, |
|
| 529 | - $options['version_http'], |
|
| 530 | - $options['if_modified_since'] |
|
| 531 | - ); |
|
| 532 | - if (!$handle) { |
|
| 533 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 534 | - |
|
| 535 | - return false; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 539 | - // et recuperer les en-tetes de reponses |
|
| 540 | - if (!$fopen) { |
|
| 541 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 542 | - if (!$res) { |
|
| 543 | - fclose($handle); |
|
| 544 | - $t = @parse_url($url); |
|
| 545 | - $host = $t['host']; |
|
| 546 | - // Chinoisierie inexplicable pour contrer |
|
| 547 | - // les actions liberticides de l'empire du milieu |
|
| 548 | - if ( |
|
| 549 | - !need_proxy($host) |
|
| 550 | - and $res = @file_get_contents($url) |
|
| 551 | - ) { |
|
| 552 | - $result['length'] = strlen($res); |
|
| 553 | - if ($copy) { |
|
| 554 | - ecrire_fichier($copy, $res); |
|
| 555 | - $result['file'] = $copy; |
|
| 556 | - } else { |
|
| 557 | - $result['page'] = $res; |
|
| 558 | - } |
|
| 559 | - $res = [ |
|
| 560 | - 'status' => 200, |
|
| 561 | - ]; |
|
| 562 | - } else { |
|
| 563 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 564 | - return false; |
|
| 565 | - } |
|
| 566 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 567 | - $options['follow_location']--; |
|
| 568 | - fclose($handle); |
|
| 569 | - include_spip('inc/filtres'); |
|
| 570 | - $url = suivre_lien($url, $res['location']); |
|
| 571 | - |
|
| 572 | - // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 573 | - if ($options['methode'] !== 'GET') { |
|
| 574 | - if (empty($res['status']) or !in_array($res['status'], [307, 308])) { |
|
| 575 | - $options['methode'] = 'GET'; |
|
| 576 | - $options['datas'] = ''; |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 580 | - |
|
| 581 | - return recuperer_url($url, $options); |
|
| 582 | - } elseif ($res['status'] !== 200) { |
|
| 583 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 584 | - } |
|
| 585 | - $result['status'] = $res['status']; |
|
| 586 | - if (isset($res['headers'])) { |
|
| 587 | - $result['headers'] = $res['headers']; |
|
| 588 | - } |
|
| 589 | - if (isset($res['last_modified'])) { |
|
| 590 | - $result['last_modified'] = $res['last_modified']; |
|
| 591 | - } |
|
| 592 | - if (isset($res['location'])) { |
|
| 593 | - $result['location'] = $res['location']; |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - // on ne veut que les entetes |
|
| 598 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 599 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 600 | - return $result; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 605 | - // sinon la memoire explose pour les gros flux |
|
| 606 | - |
|
| 607 | - $gz = false; |
|
| 608 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 609 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 613 | - if (!$result['length']) { |
|
| 614 | - $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 615 | - fclose($handle); |
|
| 616 | - if ($copy) { |
|
| 617 | - $result['length'] = $res; |
|
| 618 | - $result['file'] = $copy; |
|
| 619 | - } elseif ($res) { |
|
| 620 | - $result['page'] = &$res; |
|
| 621 | - $result['length'] = strlen($result['page']); |
|
| 622 | - } |
|
| 623 | - if (!$result['status']) { |
|
| 624 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - if (!$result['page']) { |
|
| 628 | - return $result; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - // Decompresser au besoin |
|
| 632 | - if ($gz) { |
|
| 633 | - $result['page'] = implode('', gzfile($gz)); |
|
| 634 | - supprimer_fichier($gz); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - // Faut-il l'importer dans notre charset local ? |
|
| 638 | - if ($options['transcoder']) { |
|
| 639 | - include_spip('inc/charsets'); |
|
| 640 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - $trace = json_decode(json_encode($result), true); |
|
| 644 | - $trace['page'] = '...'; |
|
| 645 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 646 | - |
|
| 647 | - return $result; |
|
| 445 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 446 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 447 | + $default = [ |
|
| 448 | + 'transcoder' => false, |
|
| 449 | + 'methode' => 'GET', |
|
| 450 | + 'taille_max' => null, |
|
| 451 | + 'headers' => [], |
|
| 452 | + 'datas' => '', |
|
| 453 | + 'boundary' => '', |
|
| 454 | + 'refuser_gz' => false, |
|
| 455 | + 'if_modified_since' => '', |
|
| 456 | + 'uri_referer' => '', |
|
| 457 | + 'file' => '', |
|
| 458 | + 'follow_location' => 10, |
|
| 459 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 460 | + ]; |
|
| 461 | + $options = array_merge($default, $options); |
|
| 462 | + // copier directement dans un fichier ? |
|
| 463 | + $copy = $options['file']; |
|
| 464 | + |
|
| 465 | + if ($options['methode'] == 'HEAD') { |
|
| 466 | + $options['taille_max'] = 0; |
|
| 467 | + } |
|
| 468 | + if (is_null($options['taille_max'])) { |
|
| 469 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 473 | + |
|
| 474 | + // Ajout des en-têtes spécifiques si besoin |
|
| 475 | + $formatted_data = ''; |
|
| 476 | + if (!empty($options['headers'])) { |
|
| 477 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 478 | + $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if (!empty($options['datas'])) { |
|
| 483 | + [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 484 | + $head .= $formatted_data; |
|
| 485 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 486 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 487 | + } |
|
| 488 | + $formatted_data = $head . "\r\n" . $postdata; |
|
| 489 | + if ( |
|
| 490 | + strlen($postdata) |
|
| 491 | + and !$methode_demandee |
|
| 492 | + ) { |
|
| 493 | + $options['methode'] = 'POST'; |
|
| 494 | + } |
|
| 495 | + } elseif ($formatted_data) { |
|
| 496 | + $formatted_data .= "\r\n"; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 500 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 501 | + if (!tester_url_absolue($url)) { |
|
| 502 | + $url = 'http://' . $url; |
|
| 503 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 504 | + $url = 'http:' . $url; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $url = url_to_ascii($url); |
|
| 508 | + |
|
| 509 | + $result = [ |
|
| 510 | + 'status' => 0, |
|
| 511 | + 'headers' => '', |
|
| 512 | + 'page' => '', |
|
| 513 | + 'length' => 0, |
|
| 514 | + 'last_modified' => '', |
|
| 515 | + 'location' => '', |
|
| 516 | + 'url' => $url |
|
| 517 | + ]; |
|
| 518 | + |
|
| 519 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 520 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 521 | + |
|
| 522 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 523 | + [$handle, $fopen] = init_http( |
|
| 524 | + $options['methode'], |
|
| 525 | + $url, |
|
| 526 | + $refuser_gz, |
|
| 527 | + $options['uri_referer'], |
|
| 528 | + $formatted_data, |
|
| 529 | + $options['version_http'], |
|
| 530 | + $options['if_modified_since'] |
|
| 531 | + ); |
|
| 532 | + if (!$handle) { |
|
| 533 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 534 | + |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 539 | + // et recuperer les en-tetes de reponses |
|
| 540 | + if (!$fopen) { |
|
| 541 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 542 | + if (!$res) { |
|
| 543 | + fclose($handle); |
|
| 544 | + $t = @parse_url($url); |
|
| 545 | + $host = $t['host']; |
|
| 546 | + // Chinoisierie inexplicable pour contrer |
|
| 547 | + // les actions liberticides de l'empire du milieu |
|
| 548 | + if ( |
|
| 549 | + !need_proxy($host) |
|
| 550 | + and $res = @file_get_contents($url) |
|
| 551 | + ) { |
|
| 552 | + $result['length'] = strlen($res); |
|
| 553 | + if ($copy) { |
|
| 554 | + ecrire_fichier($copy, $res); |
|
| 555 | + $result['file'] = $copy; |
|
| 556 | + } else { |
|
| 557 | + $result['page'] = $res; |
|
| 558 | + } |
|
| 559 | + $res = [ |
|
| 560 | + 'status' => 200, |
|
| 561 | + ]; |
|
| 562 | + } else { |
|
| 563 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 564 | + return false; |
|
| 565 | + } |
|
| 566 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 567 | + $options['follow_location']--; |
|
| 568 | + fclose($handle); |
|
| 569 | + include_spip('inc/filtres'); |
|
| 570 | + $url = suivre_lien($url, $res['location']); |
|
| 571 | + |
|
| 572 | + // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 573 | + if ($options['methode'] !== 'GET') { |
|
| 574 | + if (empty($res['status']) or !in_array($res['status'], [307, 308])) { |
|
| 575 | + $options['methode'] = 'GET'; |
|
| 576 | + $options['datas'] = ''; |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 580 | + |
|
| 581 | + return recuperer_url($url, $options); |
|
| 582 | + } elseif ($res['status'] !== 200) { |
|
| 583 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 584 | + } |
|
| 585 | + $result['status'] = $res['status']; |
|
| 586 | + if (isset($res['headers'])) { |
|
| 587 | + $result['headers'] = $res['headers']; |
|
| 588 | + } |
|
| 589 | + if (isset($res['last_modified'])) { |
|
| 590 | + $result['last_modified'] = $res['last_modified']; |
|
| 591 | + } |
|
| 592 | + if (isset($res['location'])) { |
|
| 593 | + $result['location'] = $res['location']; |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + // on ne veut que les entetes |
|
| 598 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 599 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 600 | + return $result; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 605 | + // sinon la memoire explose pour les gros flux |
|
| 606 | + |
|
| 607 | + $gz = false; |
|
| 608 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 609 | + $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 613 | + if (!$result['length']) { |
|
| 614 | + $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 615 | + fclose($handle); |
|
| 616 | + if ($copy) { |
|
| 617 | + $result['length'] = $res; |
|
| 618 | + $result['file'] = $copy; |
|
| 619 | + } elseif ($res) { |
|
| 620 | + $result['page'] = &$res; |
|
| 621 | + $result['length'] = strlen($result['page']); |
|
| 622 | + } |
|
| 623 | + if (!$result['status']) { |
|
| 624 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (!$result['page']) { |
|
| 628 | + return $result; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + // Decompresser au besoin |
|
| 632 | + if ($gz) { |
|
| 633 | + $result['page'] = implode('', gzfile($gz)); |
|
| 634 | + supprimer_fichier($gz); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + // Faut-il l'importer dans notre charset local ? |
|
| 638 | + if ($options['transcoder']) { |
|
| 639 | + include_spip('inc/charsets'); |
|
| 640 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + $trace = json_decode(json_encode($result), true); |
|
| 644 | + $trace['page'] = '...'; |
|
| 645 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 646 | + |
|
| 647 | + return $result; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /** |
@@ -660,73 +660,73 @@ discard block |
||
| 660 | 660 | * @return array|bool|mixed |
| 661 | 661 | */ |
| 662 | 662 | function recuperer_url_cache($url, $options = []) { |
| 663 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 664 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 665 | - } |
|
| 666 | - $default = [ |
|
| 667 | - 'transcoder' => false, |
|
| 668 | - 'methode' => 'GET', |
|
| 669 | - 'taille_max' => null, |
|
| 670 | - 'datas' => '', |
|
| 671 | - 'boundary' => '', |
|
| 672 | - 'refuser_gz' => false, |
|
| 673 | - 'if_modified_since' => '', |
|
| 674 | - 'uri_referer' => '', |
|
| 675 | - 'file' => '', |
|
| 676 | - 'follow_location' => 10, |
|
| 677 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 678 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 679 | - ]; |
|
| 680 | - $options = array_merge($default, $options); |
|
| 681 | - |
|
| 682 | - // cas ou il n'est pas possible de cacher |
|
| 683 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 684 | - return recuperer_url($url, $options); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 688 | - static $errors = []; |
|
| 689 | - if (isset($errors[$url])) { |
|
| 690 | - return $errors[$url]; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $sig = $options; |
|
| 694 | - unset($sig['if_modified_since']); |
|
| 695 | - unset($sig['delai_cache']); |
|
| 696 | - $sig['url'] = $url; |
|
| 697 | - |
|
| 698 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 699 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 700 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 701 | - $cache = "$sub$cache"; |
|
| 702 | - |
|
| 703 | - $res = false; |
|
| 704 | - $is_cached = file_exists($cache); |
|
| 705 | - if ( |
|
| 706 | - $is_cached |
|
| 707 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 708 | - ) { |
|
| 709 | - lire_fichier($cache, $res); |
|
| 710 | - if ($res = unserialize($res)) { |
|
| 711 | - // mettre le last_modified et le status=304 ? |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - if (!$res) { |
|
| 715 | - $res = recuperer_url($url, $options); |
|
| 716 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 717 | - if (!$res) { |
|
| 718 | - if ($is_cached) { |
|
| 719 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 720 | - lire_fichier($cache, $res); |
|
| 721 | - $res = unserialize($res); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $errors[$url] = $res; |
|
| 725 | - } |
|
| 726 | - ecrire_fichier($cache, serialize($res)); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - return $res; |
|
| 663 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 664 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 665 | + } |
|
| 666 | + $default = [ |
|
| 667 | + 'transcoder' => false, |
|
| 668 | + 'methode' => 'GET', |
|
| 669 | + 'taille_max' => null, |
|
| 670 | + 'datas' => '', |
|
| 671 | + 'boundary' => '', |
|
| 672 | + 'refuser_gz' => false, |
|
| 673 | + 'if_modified_since' => '', |
|
| 674 | + 'uri_referer' => '', |
|
| 675 | + 'file' => '', |
|
| 676 | + 'follow_location' => 10, |
|
| 677 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 678 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 679 | + ]; |
|
| 680 | + $options = array_merge($default, $options); |
|
| 681 | + |
|
| 682 | + // cas ou il n'est pas possible de cacher |
|
| 683 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 684 | + return recuperer_url($url, $options); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 688 | + static $errors = []; |
|
| 689 | + if (isset($errors[$url])) { |
|
| 690 | + return $errors[$url]; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + $sig = $options; |
|
| 694 | + unset($sig['if_modified_since']); |
|
| 695 | + unset($sig['delai_cache']); |
|
| 696 | + $sig['url'] = $url; |
|
| 697 | + |
|
| 698 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 699 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 700 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 701 | + $cache = "$sub$cache"; |
|
| 702 | + |
|
| 703 | + $res = false; |
|
| 704 | + $is_cached = file_exists($cache); |
|
| 705 | + if ( |
|
| 706 | + $is_cached |
|
| 707 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 708 | + ) { |
|
| 709 | + lire_fichier($cache, $res); |
|
| 710 | + if ($res = unserialize($res)) { |
|
| 711 | + // mettre le last_modified et le status=304 ? |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + if (!$res) { |
|
| 715 | + $res = recuperer_url($url, $options); |
|
| 716 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 717 | + if (!$res) { |
|
| 718 | + if ($is_cached) { |
|
| 719 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 720 | + lire_fichier($cache, $res); |
|
| 721 | + $res = unserialize($res); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $errors[$url] = $res; |
|
| 725 | + } |
|
| 726 | + ecrire_fichier($cache, serialize($res)); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + return $res; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -744,42 +744,42 @@ discard block |
||
| 744 | 744 | * string contenu de la resource |
| 745 | 745 | */ |
| 746 | 746 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 747 | - $tmpfile = null; |
|
| 748 | - $taille = 0; |
|
| 749 | - $result = ''; |
|
| 750 | - $fp = false; |
|
| 751 | - if ($fichier) { |
|
| 752 | - include_spip('inc/acces'); |
|
| 753 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 754 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 755 | - if (!$fp and file_exists($fichier)) { |
|
| 756 | - return filesize($fichier); |
|
| 757 | - } |
|
| 758 | - if (!$fp) { |
|
| 759 | - return false; |
|
| 760 | - } |
|
| 761 | - $result = 0; // on renvoie la taille du fichier |
|
| 762 | - } |
|
| 763 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 764 | - $res = fread($handle, 16384); |
|
| 765 | - $taille += strlen($res); |
|
| 766 | - if ($fp) { |
|
| 767 | - fwrite($fp, $res); |
|
| 768 | - $result = $taille; |
|
| 769 | - } else { |
|
| 770 | - $result .= $res; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - if ($fp) { |
|
| 774 | - spip_fclose_unlock($fp); |
|
| 775 | - spip_unlink($fichier); |
|
| 776 | - @rename($tmpfile, $fichier); |
|
| 777 | - if (!file_exists($fichier)) { |
|
| 778 | - return false; |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - return $result; |
|
| 747 | + $tmpfile = null; |
|
| 748 | + $taille = 0; |
|
| 749 | + $result = ''; |
|
| 750 | + $fp = false; |
|
| 751 | + if ($fichier) { |
|
| 752 | + include_spip('inc/acces'); |
|
| 753 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 754 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 755 | + if (!$fp and file_exists($fichier)) { |
|
| 756 | + return filesize($fichier); |
|
| 757 | + } |
|
| 758 | + if (!$fp) { |
|
| 759 | + return false; |
|
| 760 | + } |
|
| 761 | + $result = 0; // on renvoie la taille du fichier |
|
| 762 | + } |
|
| 763 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 764 | + $res = fread($handle, 16384); |
|
| 765 | + $taille += strlen($res); |
|
| 766 | + if ($fp) { |
|
| 767 | + fwrite($fp, $res); |
|
| 768 | + $result = $taille; |
|
| 769 | + } else { |
|
| 770 | + $result .= $res; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + if ($fp) { |
|
| 774 | + spip_fclose_unlock($fp); |
|
| 775 | + spip_unlink($fichier); |
|
| 776 | + @rename($tmpfile, $fichier); |
|
| 777 | + if (!file_exists($fichier)) { |
|
| 778 | + return false; |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + return $result; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /** |
@@ -801,35 +801,35 @@ discard block |
||
| 801 | 801 | * string location |
| 802 | 802 | */ |
| 803 | 803 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 804 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 805 | - |
|
| 806 | - $s = @trim(fgets($handle, 16384)); |
|
| 807 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $result['status'] = intval($r[1]); |
|
| 811 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 812 | - $result['headers'][] = $s . "\n"; |
|
| 813 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 814 | - [, $d, $v] = $r; |
|
| 815 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 816 | - $result['location'] = $v; |
|
| 817 | - } elseif ($d == 'Last-Modified') { |
|
| 818 | - $result['last_modified'] = strtotime($v); |
|
| 819 | - } |
|
| 820 | - } |
|
| 821 | - if ( |
|
| 822 | - $if_modified_since |
|
| 823 | - and $result['last_modified'] |
|
| 824 | - and $if_modified_since > $result['last_modified'] |
|
| 825 | - and $result['status'] == 200 |
|
| 826 | - ) { |
|
| 827 | - $result['status'] = 304; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $result['headers'] = implode('', $result['headers']); |
|
| 831 | - |
|
| 832 | - return $result; |
|
| 804 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 805 | + |
|
| 806 | + $s = @trim(fgets($handle, 16384)); |
|
| 807 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $result['status'] = intval($r[1]); |
|
| 811 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 812 | + $result['headers'][] = $s . "\n"; |
|
| 813 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 814 | + [, $d, $v] = $r; |
|
| 815 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 816 | + $result['location'] = $v; |
|
| 817 | + } elseif ($d == 'Last-Modified') { |
|
| 818 | + $result['last_modified'] = strtotime($v); |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | + if ( |
|
| 822 | + $if_modified_since |
|
| 823 | + and $result['last_modified'] |
|
| 824 | + and $if_modified_since > $result['last_modified'] |
|
| 825 | + and $result['status'] == 200 |
|
| 826 | + ) { |
|
| 827 | + $result['status'] = 304; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $result['headers'] = implode('', $result['headers']); |
|
| 831 | + |
|
| 832 | + return $result; |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
@@ -851,22 +851,22 @@ discard block |
||
| 851 | 851 | * Nom du fichier pour copie locale |
| 852 | 852 | **/ |
| 853 | 853 | function nom_fichier_copie_locale($source, $extension) { |
| 854 | - include_spip('inc/documents'); |
|
| 854 | + include_spip('inc/documents'); |
|
| 855 | 855 | |
| 856 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 857 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 856 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 857 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 858 | 858 | |
| 859 | - // on se place tout le temps comme si on etait a la racine |
|
| 860 | - if (_DIR_RACINE) { |
|
| 861 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 862 | - } |
|
| 859 | + // on se place tout le temps comme si on etait a la racine |
|
| 860 | + if (_DIR_RACINE) { |
|
| 861 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 862 | + } |
|
| 863 | 863 | |
| 864 | - $m = md5($source); |
|
| 864 | + $m = md5($source); |
|
| 865 | 865 | |
| 866 | - return $d |
|
| 867 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 868 | - . substr($m, 0, 4) |
|
| 869 | - . ".$extension"; |
|
| 866 | + return $d |
|
| 867 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 868 | + . substr($m, 0, 4) |
|
| 869 | + . ".$extension"; |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
@@ -885,72 +885,72 @@ discard block |
||
| 885 | 885 | * - null: Copie locale impossible |
| 886 | 886 | **/ |
| 887 | 887 | function fichier_copie_locale($source) { |
| 888 | - // Si c'est deja local pas de souci |
|
| 889 | - if (!tester_url_absolue($source)) { |
|
| 890 | - if (_DIR_RACINE) { |
|
| 891 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - return $source; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 898 | - // a deja ete copie en local avec cette extension |
|
| 899 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 900 | - $path_parts = pathinfo($source); |
|
| 901 | - if (!isset($path_parts['extension'])) { |
|
| 902 | - $path_parts['extension'] = ''; |
|
| 903 | - } |
|
| 904 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 905 | - if ( |
|
| 906 | - $ext |
|
| 907 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 908 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 909 | - and file_exists(_DIR_RACINE . $f) |
|
| 910 | - ) { |
|
| 911 | - return $f; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - // Si c'est deja dans la table des documents, |
|
| 916 | - // ramener le nom de sa copie potentielle |
|
| 917 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 918 | - |
|
| 919 | - if ($ext) { |
|
| 920 | - return nom_fichier_copie_locale($source, $ext); |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 924 | - // et si il n'aurait pas deja ete rapatrie |
|
| 925 | - |
|
| 926 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 927 | - |
|
| 928 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 929 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 930 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 931 | - return $f; |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // Ping pour voir si son extension est connue et autorisee |
|
| 936 | - // avec mise en cache du resultat du ping |
|
| 937 | - |
|
| 938 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 939 | - if ( |
|
| 940 | - !@file_exists($cache) |
|
| 941 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 942 | - or _request('var_mode') === 'recalcul' |
|
| 943 | - ) { |
|
| 944 | - $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 945 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 946 | - } |
|
| 947 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 948 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 949 | - return nom_fichier_copie_locale($source, $ext); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 953 | - return null; |
|
| 888 | + // Si c'est deja local pas de souci |
|
| 889 | + if (!tester_url_absolue($source)) { |
|
| 890 | + if (_DIR_RACINE) { |
|
| 891 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + return $source; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 898 | + // a deja ete copie en local avec cette extension |
|
| 899 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 900 | + $path_parts = pathinfo($source); |
|
| 901 | + if (!isset($path_parts['extension'])) { |
|
| 902 | + $path_parts['extension'] = ''; |
|
| 903 | + } |
|
| 904 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 905 | + if ( |
|
| 906 | + $ext |
|
| 907 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 908 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 909 | + and file_exists(_DIR_RACINE . $f) |
|
| 910 | + ) { |
|
| 911 | + return $f; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + // Si c'est deja dans la table des documents, |
|
| 916 | + // ramener le nom de sa copie potentielle |
|
| 917 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 918 | + |
|
| 919 | + if ($ext) { |
|
| 920 | + return nom_fichier_copie_locale($source, $ext); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 924 | + // et si il n'aurait pas deja ete rapatrie |
|
| 925 | + |
|
| 926 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 927 | + |
|
| 928 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 929 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 930 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 931 | + return $f; |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // Ping pour voir si son extension est connue et autorisee |
|
| 936 | + // avec mise en cache du resultat du ping |
|
| 937 | + |
|
| 938 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 939 | + if ( |
|
| 940 | + !@file_exists($cache) |
|
| 941 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 942 | + or _request('var_mode') === 'recalcul' |
|
| 943 | + ) { |
|
| 944 | + $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 945 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 946 | + } |
|
| 947 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 948 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 949 | + return nom_fichier_copie_locale($source, $ext); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 953 | + return null; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | |
@@ -979,110 +979,110 @@ discard block |
||
| 979 | 979 | **/ |
| 980 | 980 | function recuperer_infos_distantes($source, $options = []) { |
| 981 | 981 | |
| 982 | - // pas la peine de perdre son temps |
|
| 983 | - if (!tester_url_absolue($source)) { |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $taille_max = $options['taille_max'] ?? 0; |
|
| 988 | - $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true); |
|
| 989 | - $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 990 | - |
|
| 991 | - # charger les alias des types mime |
|
| 992 | - include_spip('base/typedoc'); |
|
| 993 | - |
|
| 994 | - $a = []; |
|
| 995 | - $mime_type = ''; |
|
| 996 | - // On va directement charger le debut des images et des fichiers html, |
|
| 997 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 998 | - // ca echoue l'utilisateur devra les entrer... |
|
| 999 | - $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 1000 | - if ( |
|
| 1001 | - $callback_valider_url |
|
| 1002 | - and is_callable($callback_valider_url) |
|
| 1003 | - and !$callback_valider_url($reponse['url']) |
|
| 1004 | - ) { |
|
| 1005 | - return false; |
|
| 1006 | - } |
|
| 1007 | - $headers = $reponse['headers'] ?? ''; |
|
| 1008 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 1009 | - if ($headers) { |
|
| 1010 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1011 | - return false; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - $a['extension'] = $extension; |
|
| 1015 | - |
|
| 1016 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1017 | - $a['taille'] = intval($regs[1]); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // Echec avec HEAD, on tente avec GET |
|
| 1022 | - if (!$a and !$taille_max) { |
|
| 1023 | - spip_log("tenter GET $source", 'distant'); |
|
| 1024 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1025 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - // si on a rien trouve pas la peine d'insister |
|
| 1029 | - if (!$a) { |
|
| 1030 | - return false; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1034 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1035 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 1036 | - if ( |
|
| 1037 | - strpos($mime_type, 'image/') === 0 |
|
| 1038 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1039 | - ) { |
|
| 1040 | - if ( |
|
| 1041 | - $taille_max == 0 |
|
| 1042 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1043 | - and in_array($extension, formats_image_acceptables()) |
|
| 1044 | - and $charger_si_petite_image |
|
| 1045 | - ) { |
|
| 1046 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1047 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1048 | - } else { |
|
| 1049 | - if ($a['body']) { |
|
| 1050 | - $a['extension'] = $extension; |
|
| 1051 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1052 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1053 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1054 | - $a['largeur'] = intval($size_image[0]); |
|
| 1055 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1056 | - $a['type_image'] = true; |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1062 | - // ce sera mieux que 0x0 |
|
| 1063 | - // Flash is dead! |
|
| 1064 | - if ( |
|
| 1065 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1066 | - and empty($a['largeur']) |
|
| 1067 | - ) { |
|
| 1068 | - $a['largeur'] = 425; |
|
| 1069 | - $a['hauteur'] = 350; |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - if ($mime_type == 'text/html') { |
|
| 1073 | - include_spip('inc/filtres'); |
|
| 1074 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1075 | - $page = $page['page'] ?? ''; |
|
| 1076 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1077 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1078 | - } |
|
| 1079 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1080 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - $a['mime_type'] = $mime_type; |
|
| 1084 | - |
|
| 1085 | - return $a; |
|
| 982 | + // pas la peine de perdre son temps |
|
| 983 | + if (!tester_url_absolue($source)) { |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $taille_max = $options['taille_max'] ?? 0; |
|
| 988 | + $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true); |
|
| 989 | + $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 990 | + |
|
| 991 | + # charger les alias des types mime |
|
| 992 | + include_spip('base/typedoc'); |
|
| 993 | + |
|
| 994 | + $a = []; |
|
| 995 | + $mime_type = ''; |
|
| 996 | + // On va directement charger le debut des images et des fichiers html, |
|
| 997 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 998 | + // ca echoue l'utilisateur devra les entrer... |
|
| 999 | + $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 1000 | + if ( |
|
| 1001 | + $callback_valider_url |
|
| 1002 | + and is_callable($callback_valider_url) |
|
| 1003 | + and !$callback_valider_url($reponse['url']) |
|
| 1004 | + ) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 1007 | + $headers = $reponse['headers'] ?? ''; |
|
| 1008 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 1009 | + if ($headers) { |
|
| 1010 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1011 | + return false; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + $a['extension'] = $extension; |
|
| 1015 | + |
|
| 1016 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1017 | + $a['taille'] = intval($regs[1]); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // Echec avec HEAD, on tente avec GET |
|
| 1022 | + if (!$a and !$taille_max) { |
|
| 1023 | + spip_log("tenter GET $source", 'distant'); |
|
| 1024 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1025 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + // si on a rien trouve pas la peine d'insister |
|
| 1029 | + if (!$a) { |
|
| 1030 | + return false; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1034 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1035 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 1036 | + if ( |
|
| 1037 | + strpos($mime_type, 'image/') === 0 |
|
| 1038 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1039 | + ) { |
|
| 1040 | + if ( |
|
| 1041 | + $taille_max == 0 |
|
| 1042 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1043 | + and in_array($extension, formats_image_acceptables()) |
|
| 1044 | + and $charger_si_petite_image |
|
| 1045 | + ) { |
|
| 1046 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1047 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1048 | + } else { |
|
| 1049 | + if ($a['body']) { |
|
| 1050 | + $a['extension'] = $extension; |
|
| 1051 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1052 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1053 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1054 | + $a['largeur'] = intval($size_image[0]); |
|
| 1055 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1056 | + $a['type_image'] = true; |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1062 | + // ce sera mieux que 0x0 |
|
| 1063 | + // Flash is dead! |
|
| 1064 | + if ( |
|
| 1065 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1066 | + and empty($a['largeur']) |
|
| 1067 | + ) { |
|
| 1068 | + $a['largeur'] = 425; |
|
| 1069 | + $a['hauteur'] = 350; |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + if ($mime_type == 'text/html') { |
|
| 1073 | + include_spip('inc/filtres'); |
|
| 1074 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1075 | + $page = $page['page'] ?? ''; |
|
| 1076 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1077 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1078 | + } |
|
| 1079 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1080 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + $a['mime_type'] = $mime_type; |
|
| 1084 | + |
|
| 1085 | + return $a; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
@@ -1091,70 +1091,70 @@ discard block |
||
| 1091 | 1091 | * @return false|mixed |
| 1092 | 1092 | */ |
| 1093 | 1093 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1094 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1095 | - $mime_type = (trim($regs[1])); |
|
| 1096 | - } else { |
|
| 1097 | - $mime_type = ''; |
|
| 1098 | - } // inconnu |
|
| 1099 | - |
|
| 1100 | - // Appliquer les alias |
|
| 1101 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1102 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - // pour corriger_extension() |
|
| 1106 | - include_spip('inc/documents'); |
|
| 1107 | - |
|
| 1108 | - // Si on a un mime-type insignifiant |
|
| 1109 | - // text/plain,application/octet-stream ou vide |
|
| 1110 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1111 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1112 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1113 | - $t = null; |
|
| 1114 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1115 | - if ( |
|
| 1116 | - !$t |
|
| 1117 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1118 | - ) { |
|
| 1119 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1120 | - } |
|
| 1121 | - if ( |
|
| 1122 | - !$t |
|
| 1123 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1124 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1125 | - ) { |
|
| 1126 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1127 | - } |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1131 | - if (!$t) { |
|
| 1132 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1136 | - // On essaie de nouveau avec l'extension |
|
| 1137 | - if ( |
|
| 1138 | - !$t |
|
| 1139 | - and $mime_type != 'text/plain' |
|
| 1140 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1141 | - ) { |
|
| 1142 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1143 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if ($t) { |
|
| 1147 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1148 | - return $t['extension']; |
|
| 1149 | - } else { |
|
| 1150 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1151 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1152 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1153 | - if (!$t) { |
|
| 1154 | - return false; |
|
| 1155 | - } |
|
| 1156 | - return $t['extension']; |
|
| 1157 | - } |
|
| 1094 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1095 | + $mime_type = (trim($regs[1])); |
|
| 1096 | + } else { |
|
| 1097 | + $mime_type = ''; |
|
| 1098 | + } // inconnu |
|
| 1099 | + |
|
| 1100 | + // Appliquer les alias |
|
| 1101 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1102 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + // pour corriger_extension() |
|
| 1106 | + include_spip('inc/documents'); |
|
| 1107 | + |
|
| 1108 | + // Si on a un mime-type insignifiant |
|
| 1109 | + // text/plain,application/octet-stream ou vide |
|
| 1110 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1111 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1112 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1113 | + $t = null; |
|
| 1114 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1115 | + if ( |
|
| 1116 | + !$t |
|
| 1117 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1118 | + ) { |
|
| 1119 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1120 | + } |
|
| 1121 | + if ( |
|
| 1122 | + !$t |
|
| 1123 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1124 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1125 | + ) { |
|
| 1126 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1127 | + } |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1131 | + if (!$t) { |
|
| 1132 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1136 | + // On essaie de nouveau avec l'extension |
|
| 1137 | + if ( |
|
| 1138 | + !$t |
|
| 1139 | + and $mime_type != 'text/plain' |
|
| 1140 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1141 | + ) { |
|
| 1142 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1143 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if ($t) { |
|
| 1147 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1148 | + return $t['extension']; |
|
| 1149 | + } else { |
|
| 1150 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1151 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1152 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1153 | + if (!$t) { |
|
| 1154 | + return false; |
|
| 1155 | + } |
|
| 1156 | + return $t['extension']; |
|
| 1157 | + } |
|
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | /** |
@@ -1170,45 +1170,45 @@ discard block |
||
| 1170 | 1170 | */ |
| 1171 | 1171 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1172 | 1172 | |
| 1173 | - $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1174 | - |
|
| 1175 | - // rien a faire si pas de proxy :) |
|
| 1176 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1177 | - return ''; |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - if (is_null($http_noproxy)) { |
|
| 1181 | - $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1182 | - } |
|
| 1183 | - // si pas d'exception, on retourne le proxy |
|
| 1184 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1185 | - return $http_proxy; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1189 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1190 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1191 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1192 | - $http_noproxy = " $http_noproxy "; |
|
| 1193 | - $domain = $host; |
|
| 1194 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1195 | - if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1196 | - return ''; |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - while (strpos($domain, '.') !== false) { |
|
| 1200 | - $domain = explode('.', $domain); |
|
| 1201 | - array_shift($domain); |
|
| 1202 | - $domain = implode('.', $domain); |
|
| 1203 | - |
|
| 1204 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1205 | - if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1206 | - return ''; |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - // ok c'est pas une exception |
|
| 1211 | - return $http_proxy; |
|
| 1173 | + $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1174 | + |
|
| 1175 | + // rien a faire si pas de proxy :) |
|
| 1176 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1177 | + return ''; |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + if (is_null($http_noproxy)) { |
|
| 1181 | + $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1182 | + } |
|
| 1183 | + // si pas d'exception, on retourne le proxy |
|
| 1184 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1185 | + return $http_proxy; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1189 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1190 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1191 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1192 | + $http_noproxy = " $http_noproxy "; |
|
| 1193 | + $domain = $host; |
|
| 1194 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1195 | + if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1196 | + return ''; |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + while (strpos($domain, '.') !== false) { |
|
| 1200 | + $domain = explode('.', $domain); |
|
| 1201 | + array_shift($domain); |
|
| 1202 | + $domain = implode('.', $domain); |
|
| 1203 | + |
|
| 1204 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1205 | + if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1206 | + return ''; |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + // ok c'est pas une exception |
|
| 1211 | + return $http_proxy; |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | |
@@ -1231,59 +1231,59 @@ discard block |
||
| 1231 | 1231 | * @return array |
| 1232 | 1232 | */ |
| 1233 | 1233 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1234 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1235 | - $fopen = false; |
|
| 1236 | - |
|
| 1237 | - $t = @parse_url($url); |
|
| 1238 | - $host = $t['host']; |
|
| 1239 | - if ($t['scheme'] == 'http') { |
|
| 1240 | - $scheme = 'http'; |
|
| 1241 | - $noproxy = ''; |
|
| 1242 | - } elseif ($t['scheme'] == 'https') { |
|
| 1243 | - $scheme = 'ssl'; |
|
| 1244 | - $noproxy = 'ssl://'; |
|
| 1245 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1246 | - $t['port'] = 443; |
|
| 1247 | - } |
|
| 1248 | - } else { |
|
| 1249 | - $scheme = $t['scheme']; |
|
| 1250 | - $noproxy = $scheme . '://'; |
|
| 1251 | - } |
|
| 1252 | - if (isset($t['user'])) { |
|
| 1253 | - $user = [$t['user'], $t['pass']]; |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1257 | - $port = 80; |
|
| 1258 | - } |
|
| 1259 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1260 | - $path = '/'; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - if (!empty($t['query'])) { |
|
| 1264 | - $path .= '?' . $t['query']; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1268 | - if (!$f or !is_resource($f)) { |
|
| 1269 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1270 | - // ce qui correspond a $f===110 |
|
| 1271 | - if ( |
|
| 1272 | - $f !== 110 |
|
| 1273 | - and !need_proxy($host) |
|
| 1274 | - and !_request('tester_proxy') |
|
| 1275 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1276 | - ) { |
|
| 1277 | - $f = @fopen($url, 'rb'); |
|
| 1278 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1279 | - $fopen = true; |
|
| 1280 | - } else { |
|
| 1281 | - // echec total |
|
| 1282 | - $f = false; |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - return [$f, $fopen]; |
|
| 1234 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1235 | + $fopen = false; |
|
| 1236 | + |
|
| 1237 | + $t = @parse_url($url); |
|
| 1238 | + $host = $t['host']; |
|
| 1239 | + if ($t['scheme'] == 'http') { |
|
| 1240 | + $scheme = 'http'; |
|
| 1241 | + $noproxy = ''; |
|
| 1242 | + } elseif ($t['scheme'] == 'https') { |
|
| 1243 | + $scheme = 'ssl'; |
|
| 1244 | + $noproxy = 'ssl://'; |
|
| 1245 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1246 | + $t['port'] = 443; |
|
| 1247 | + } |
|
| 1248 | + } else { |
|
| 1249 | + $scheme = $t['scheme']; |
|
| 1250 | + $noproxy = $scheme . '://'; |
|
| 1251 | + } |
|
| 1252 | + if (isset($t['user'])) { |
|
| 1253 | + $user = [$t['user'], $t['pass']]; |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1257 | + $port = 80; |
|
| 1258 | + } |
|
| 1259 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1260 | + $path = '/'; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + if (!empty($t['query'])) { |
|
| 1264 | + $path .= '?' . $t['query']; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1268 | + if (!$f or !is_resource($f)) { |
|
| 1269 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1270 | + // ce qui correspond a $f===110 |
|
| 1271 | + if ( |
|
| 1272 | + $f !== 110 |
|
| 1273 | + and !need_proxy($host) |
|
| 1274 | + and !_request('tester_proxy') |
|
| 1275 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1276 | + ) { |
|
| 1277 | + $f = @fopen($url, 'rb'); |
|
| 1278 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1279 | + $fopen = true; |
|
| 1280 | + } else { |
|
| 1281 | + // echec total |
|
| 1282 | + $f = false; |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + return [$f, $fopen]; |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | /** |
@@ -1318,123 +1318,123 @@ discard block |
||
| 1318 | 1318 | * resource socket vers l'url demandee |
| 1319 | 1319 | */ |
| 1320 | 1320 | function lance_requete( |
| 1321 | - $method, |
|
| 1322 | - $scheme, |
|
| 1323 | - $user, |
|
| 1324 | - $host, |
|
| 1325 | - $path, |
|
| 1326 | - $port, |
|
| 1327 | - $noproxy, |
|
| 1328 | - $refuse_gz = false, |
|
| 1329 | - $referer = '', |
|
| 1330 | - $datas = '', |
|
| 1331 | - $vers = 'HTTP/1.0', |
|
| 1332 | - $date = '' |
|
| 1321 | + $method, |
|
| 1322 | + $scheme, |
|
| 1323 | + $user, |
|
| 1324 | + $host, |
|
| 1325 | + $path, |
|
| 1326 | + $port, |
|
| 1327 | + $noproxy, |
|
| 1328 | + $refuse_gz = false, |
|
| 1329 | + $referer = '', |
|
| 1330 | + $datas = '', |
|
| 1331 | + $vers = 'HTTP/1.0', |
|
| 1332 | + $date = '' |
|
| 1333 | 1333 | ) { |
| 1334 | 1334 | |
| 1335 | - $proxy_user = ''; |
|
| 1336 | - $http_proxy = need_proxy($host); |
|
| 1337 | - if ($user) { |
|
| 1338 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - $connect = ''; |
|
| 1342 | - if ($http_proxy) { |
|
| 1343 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1344 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1345 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1346 | - . "Host: $path_host\r\n" |
|
| 1347 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1348 | - } else { |
|
| 1349 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1350 | - . (!$user ? '' : "$user@") |
|
| 1351 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1352 | - } |
|
| 1353 | - $t2 = @parse_url($http_proxy); |
|
| 1354 | - $first_host = $t2['host']; |
|
| 1355 | - $port = ($t2['port'] ?? null) ?: 80; |
|
| 1356 | - if ($t2['user'] ?? null) { |
|
| 1357 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1358 | - } |
|
| 1359 | - } else { |
|
| 1360 | - $first_host = $noproxy . $host; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - if ($connect) { |
|
| 1364 | - $streamContext = stream_context_create([ |
|
| 1365 | - 'ssl' => [ |
|
| 1366 | - 'verify_peer' => false, |
|
| 1367 | - 'allow_self_signed' => true, |
|
| 1368 | - 'SNI_enabled' => true, |
|
| 1369 | - 'peer_name' => $host, |
|
| 1370 | - ] |
|
| 1371 | - ]); |
|
| 1372 | - $f = @stream_socket_client( |
|
| 1373 | - "tcp://$first_host:$port", |
|
| 1374 | - $errno, |
|
| 1375 | - $errstr, |
|
| 1376 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1377 | - STREAM_CLIENT_CONNECT, |
|
| 1378 | - $streamContext |
|
| 1379 | - ); |
|
| 1380 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1381 | - if (!$f) { |
|
| 1382 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1383 | - return $errno; |
|
| 1384 | - } |
|
| 1385 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1386 | - |
|
| 1387 | - fputs($f, $connect); |
|
| 1388 | - fputs($f, "\r\n"); |
|
| 1389 | - $res = fread($f, 1024); |
|
| 1390 | - if ( |
|
| 1391 | - !$res |
|
| 1392 | - or !count($res = explode(' ', $res)) |
|
| 1393 | - or $res[1] !== '200' |
|
| 1394 | - ) { |
|
| 1395 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1396 | - fclose($f); |
|
| 1397 | - |
|
| 1398 | - return false; |
|
| 1399 | - } |
|
| 1400 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1401 | - stream_set_blocking($f, true); |
|
| 1402 | - // envoyer le handshake |
|
| 1403 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1404 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1405 | - } else { |
|
| 1406 | - $ntry = 3; |
|
| 1407 | - do { |
|
| 1408 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1410 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1411 | - if (!$f) { |
|
| 1412 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1413 | - |
|
| 1414 | - return $errno; |
|
| 1415 | - } |
|
| 1416 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1420 | - |
|
| 1421 | - $host_port = $host; |
|
| 1422 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1423 | - $host_port .= ":$port"; |
|
| 1424 | - } |
|
| 1425 | - $req = "$method $path $vers\r\n" |
|
| 1426 | - . "Host: $host_port\r\n" |
|
| 1427 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1429 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1430 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1432 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1433 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1335 | + $proxy_user = ''; |
|
| 1336 | + $http_proxy = need_proxy($host); |
|
| 1337 | + if ($user) { |
|
| 1338 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + $connect = ''; |
|
| 1342 | + if ($http_proxy) { |
|
| 1343 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1344 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1345 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1346 | + . "Host: $path_host\r\n" |
|
| 1347 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1348 | + } else { |
|
| 1349 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1350 | + . (!$user ? '' : "$user@") |
|
| 1351 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1352 | + } |
|
| 1353 | + $t2 = @parse_url($http_proxy); |
|
| 1354 | + $first_host = $t2['host']; |
|
| 1355 | + $port = ($t2['port'] ?? null) ?: 80; |
|
| 1356 | + if ($t2['user'] ?? null) { |
|
| 1357 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1358 | + } |
|
| 1359 | + } else { |
|
| 1360 | + $first_host = $noproxy . $host; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + if ($connect) { |
|
| 1364 | + $streamContext = stream_context_create([ |
|
| 1365 | + 'ssl' => [ |
|
| 1366 | + 'verify_peer' => false, |
|
| 1367 | + 'allow_self_signed' => true, |
|
| 1368 | + 'SNI_enabled' => true, |
|
| 1369 | + 'peer_name' => $host, |
|
| 1370 | + ] |
|
| 1371 | + ]); |
|
| 1372 | + $f = @stream_socket_client( |
|
| 1373 | + "tcp://$first_host:$port", |
|
| 1374 | + $errno, |
|
| 1375 | + $errstr, |
|
| 1376 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1377 | + STREAM_CLIENT_CONNECT, |
|
| 1378 | + $streamContext |
|
| 1379 | + ); |
|
| 1380 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1381 | + if (!$f) { |
|
| 1382 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1383 | + return $errno; |
|
| 1384 | + } |
|
| 1385 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1386 | + |
|
| 1387 | + fputs($f, $connect); |
|
| 1388 | + fputs($f, "\r\n"); |
|
| 1389 | + $res = fread($f, 1024); |
|
| 1390 | + if ( |
|
| 1391 | + !$res |
|
| 1392 | + or !count($res = explode(' ', $res)) |
|
| 1393 | + or $res[1] !== '200' |
|
| 1394 | + ) { |
|
| 1395 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1396 | + fclose($f); |
|
| 1397 | + |
|
| 1398 | + return false; |
|
| 1399 | + } |
|
| 1400 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1401 | + stream_set_blocking($f, true); |
|
| 1402 | + // envoyer le handshake |
|
| 1403 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1404 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1405 | + } else { |
|
| 1406 | + $ntry = 3; |
|
| 1407 | + do { |
|
| 1408 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1410 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1411 | + if (!$f) { |
|
| 1412 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1413 | + |
|
| 1414 | + return $errno; |
|
| 1415 | + } |
|
| 1416 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1420 | + |
|
| 1421 | + $host_port = $host; |
|
| 1422 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1423 | + $host_port .= ":$port"; |
|
| 1424 | + } |
|
| 1425 | + $req = "$method $path $vers\r\n" |
|
| 1426 | + . "Host: $host_port\r\n" |
|
| 1427 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1429 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1430 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1432 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1433 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1434 | 1434 | |
| 1435 | 1435 | # spip_log("Requete\n$req", 'distant'); |
| 1436 | - fputs($f, $req); |
|
| 1437 | - fputs($f, $datas ?: "\r\n"); |
|
| 1436 | + fputs($f, $req); |
|
| 1437 | + fputs($f, $datas ?: "\r\n"); |
|
| 1438 | 1438 | |
| 1439 | - return $f; |
|
| 1439 | + return $f; |
|
| 1440 | 1440 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 29 | 29 | } |
| 30 | 30 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 31 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 31 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 32 | 32 | } |
| 33 | 33 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 34 | 34 | define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 40 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 41 | 41 | preg_replace( |
| 42 | 42 | '@^https?:@', |
| 43 | 43 | 'https?:', |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | // si c'est la protection de soi-meme, retourner le path |
| 76 | 76 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 77 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 77 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 78 | 78 | |
| 79 | 79 | return @file_exists($source) ? $source : false; |
| 80 | 80 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $localrac = _DIR_RACINE . $local; |
|
| 97 | + $localrac = _DIR_RACINE.$local; |
|
| 98 | 98 | $t = ($mode === 'force') ? false : @file_exists($localrac); |
| 99 | 99 | |
| 100 | 100 | // test d'existence du fichier |
@@ -114,18 +114,18 @@ discard block |
||
| 114 | 114 | if (!$taille_max) { |
| 115 | 115 | $taille_max = _COPIE_LOCALE_MAX_SIZE; |
| 116 | 116 | } |
| 117 | - $localrac_tmp = $localrac . '.tmp'; |
|
| 117 | + $localrac_tmp = $localrac.'.tmp'; |
|
| 118 | 118 | $res = recuperer_url( |
| 119 | 119 | $source, |
| 120 | 120 | ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | 123 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 124 | - spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 124 | + spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : ".($res ? $res['status'] : '-'), 'distant'._LOG_INFO_IMPORTANTE); |
|
| 125 | 125 | @unlink($localrac_tmp); |
| 126 | 126 | } |
| 127 | 127 | else { |
| 128 | - spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 128 | + spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille ".$res['length'].' status '.$res['status'], 'distant'); |
|
| 129 | 129 | } |
| 130 | 130 | if (!$res or !$res['length']) { |
| 131 | 131 | // si $t c'est sans doute juste un not-modified-since |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | and is_callable($callback_valider_url) |
| 139 | 139 | and !$callback_valider_url($res['url']) |
| 140 | 140 | ) { |
| 141 | - spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 141 | + spip_log('copie_locale : url finale '.$res['url']." non valide, on refuse le fichier $localrac_tmp", 'distant'._LOG_INFO_IMPORTANTE); |
|
| 142 | 142 | @unlink($localrac_tmp); |
| 143 | 143 | return $t ? $local : false; |
| 144 | 144 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | if (!$is_known_host) { |
| 231 | 231 | $host = trim($parsed_url['host'], '.'); |
| 232 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 232 | + if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 233 | 233 | $ip = gethostbyname($host); |
| 234 | 234 | if ($ip === $host) { |
| 235 | 235 | // Error condition for gethostbyname() |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | if ($ip) { |
| 253 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 253 | + if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 254 | 254 | return false; |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | $port = $parsed_url['port']; |
| 264 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 264 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 265 | 265 | return $url; |
| 266 | 266 | } |
| 267 | 267 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | if ($taille > 500) { |
| 334 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 334 | + $boundary = substr(md5(random_int(0, mt_getrandmax()).'spip'), 0, 8); |
|
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
@@ -359,16 +359,16 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | } else { |
| 361 | 361 | // fabrique une chaine HTTP simple pour un POST |
| 362 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 362 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 363 | 363 | $chaine = []; |
| 364 | 364 | if (is_array($donnees)) { |
| 365 | 365 | foreach ($donnees as $cle => $valeur) { |
| 366 | 366 | if (is_array($valeur)) { |
| 367 | 367 | foreach ($valeur as $val2) { |
| 368 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 368 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 369 | 369 | } |
| 370 | 370 | } else { |
| 371 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 371 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | $chaine = implode('&', $chaine); |
@@ -469,13 +469,13 @@ discard block |
||
| 469 | 469 | $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 472 | + spip_log('recuperer_url '.$options['methode']." sur $url", 'distant'._LOG_DEBUG); |
|
| 473 | 473 | |
| 474 | 474 | // Ajout des en-têtes spécifiques si besoin |
| 475 | 475 | $formatted_data = ''; |
| 476 | 476 | if (!empty($options['headers'])) { |
| 477 | 477 | foreach ($options['headers'] as $champ => $valeur) { |
| 478 | - $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 478 | + $formatted_data .= $champ.': '.$valeur."\r\n"; |
|
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | 481 | |
@@ -483,9 +483,9 @@ discard block |
||
| 483 | 483 | [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
| 484 | 484 | $head .= $formatted_data; |
| 485 | 485 | if (stripos($head, 'Content-Length:') === false) { |
| 486 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 486 | + $head .= 'Content-Length: '.strlen($postdata)."\r\n"; |
|
| 487 | 487 | } |
| 488 | - $formatted_data = $head . "\r\n" . $postdata; |
|
| 488 | + $formatted_data = $head."\r\n".$postdata; |
|
| 489 | 489 | if ( |
| 490 | 490 | strlen($postdata) |
| 491 | 491 | and !$methode_demandee |
@@ -499,9 +499,9 @@ discard block |
||
| 499 | 499 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 500 | 500 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 501 | 501 | if (!tester_url_absolue($url)) { |
| 502 | - $url = 'http://' . $url; |
|
| 502 | + $url = 'http://'.$url; |
|
| 503 | 503 | } elseif (strncmp($url, '//', 2) == 0) { |
| 504 | - $url = 'http:' . $url; |
|
| 504 | + $url = 'http:'.$url; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | $url = url_to_ascii($url); |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | $options['if_modified_since'] |
| 531 | 531 | ); |
| 532 | 532 | if (!$handle) { |
| 533 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 533 | + spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR); |
|
| 534 | 534 | |
| 535 | 535 | return false; |
| 536 | 536 | } |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | 'status' => 200, |
| 561 | 561 | ]; |
| 562 | 562 | } else { |
| 563 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 563 | + spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR); |
|
| 564 | 564 | return false; |
| 565 | 565 | } |
| 566 | 566 | } elseif ($res['location'] and $options['follow_location']) { |
@@ -576,11 +576,11 @@ discard block |
||
| 576 | 576 | $options['datas'] = ''; |
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | - spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 579 | + spip_log('recuperer_url recommence '.$options['methode']." sur $url", 'distant'._LOG_DEBUG); |
|
| 580 | 580 | |
| 581 | 581 | return recuperer_url($url, $options); |
| 582 | 582 | } elseif ($res['status'] !== 200) { |
| 583 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 583 | + spip_log('HTTP status '.$res['status']." pour $url", 'distant'); |
|
| 584 | 584 | } |
| 585 | 585 | $result['status'] = $res['status']; |
| 586 | 586 | if (isset($res['headers'])) { |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | |
| 597 | 597 | // on ne veut que les entetes |
| 598 | 598 | if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
| 599 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 599 | + spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($result), 'distant'._LOG_DEBUG); |
|
| 600 | 600 | return $result; |
| 601 | 601 | } |
| 602 | 602 | |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | |
| 607 | 607 | $gz = false; |
| 608 | 608 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 609 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 609 | + $gz = (_DIR_TMP.md5(uniqid(random_int(0, mt_getrandmax()))).'.tmp.gz'); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | $trace = json_decode(json_encode($result), true); |
| 644 | 644 | $trace['page'] = '...'; |
| 645 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 645 | + spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($trace), 'distant'._LOG_DEBUG); |
|
| 646 | 646 | |
| 647 | 647 | return $result; |
| 648 | 648 | } |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | $sig['url'] = $url; |
| 697 | 697 | |
| 698 | 698 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 699 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 699 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 700 | 700 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 701 | 701 | $cache = "$sub$cache"; |
| 702 | 702 | |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | $fp = false; |
| 751 | 751 | if ($fichier) { |
| 752 | 752 | include_spip('inc/acces'); |
| 753 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 753 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 754 | 754 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 755 | 755 | if (!$fp and file_exists($fichier)) { |
| 756 | 756 | return filesize($fichier); |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | } |
| 810 | 810 | $result['status'] = intval($r[1]); |
| 811 | 811 | while ($s = trim(fgets($handle, 16384))) { |
| 812 | - $result['headers'][] = $s . "\n"; |
|
| 812 | + $result['headers'][] = $s."\n"; |
|
| 813 | 813 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 814 | 814 | [, $d, $v] = $r; |
| 815 | 815 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -858,13 +858,13 @@ discard block |
||
| 858 | 858 | |
| 859 | 859 | // on se place tout le temps comme si on etait a la racine |
| 860 | 860 | if (_DIR_RACINE) { |
| 861 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 861 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | $m = md5($source); |
| 865 | 865 | |
| 866 | 866 | return $d |
| 867 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 867 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 868 | 868 | . substr($m, 0, 4) |
| 869 | 869 | . ".$extension"; |
| 870 | 870 | } |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | // Si c'est deja local pas de souci |
| 889 | 889 | if (!tester_url_absolue($source)) { |
| 890 | 890 | if (_DIR_RACINE) { |
| 891 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 891 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | return $source; |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | $ext |
| 907 | 907 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 908 | 908 | and $f = nom_fichier_copie_locale($source, $ext) |
| 909 | - and file_exists(_DIR_RACINE . $f) |
|
| 909 | + and file_exists(_DIR_RACINE.$f) |
|
| 910 | 910 | ) { |
| 911 | 911 | return $f; |
| 912 | 912 | } |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | |
| 915 | 915 | // Si c'est deja dans la table des documents, |
| 916 | 916 | // ramener le nom de sa copie potentielle |
| 917 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 917 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 918 | 918 | |
| 919 | 919 | if ($ext) { |
| 920 | 920 | return nom_fichier_copie_locale($source, $ext); |
@@ -925,9 +925,9 @@ discard block |
||
| 925 | 925 | |
| 926 | 926 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 927 | 927 | |
| 928 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 928 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 929 | 929 | $f = nom_fichier_copie_locale($source, $ext); |
| 930 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 930 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 931 | 931 | return $f; |
| 932 | 932 | } |
| 933 | 933 | } |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | // Ping pour voir si son extension est connue et autorisee |
| 936 | 936 | // avec mise en cache du resultat du ping |
| 937 | 937 | |
| 938 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 938 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 939 | 939 | if ( |
| 940 | 940 | !@file_exists($cache) |
| 941 | 941 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
@@ -945,11 +945,11 @@ discard block |
||
| 945 | 945 | ecrire_fichier($cache, serialize($path_parts)); |
| 946 | 946 | } |
| 947 | 947 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 948 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 948 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 949 | 949 | return nom_fichier_copie_locale($source, $ext); |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 952 | + spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR); |
|
| 953 | 953 | return null; |
| 954 | 954 | } |
| 955 | 955 | |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | } else { |
| 1049 | 1049 | if ($a['body']) { |
| 1050 | 1050 | $a['extension'] = $extension; |
| 1051 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1051 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension); |
|
| 1052 | 1052 | ecrire_fichier($a['fichier'], $a['body']); |
| 1053 | 1053 | $size_image = @spip_getimagesize($a['fichier']); |
| 1054 | 1054 | $a['largeur'] = intval($size_image[0]); |
@@ -1116,20 +1116,20 @@ discard block |
||
| 1116 | 1116 | !$t |
| 1117 | 1117 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1118 | 1118 | ) { |
| 1119 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1119 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1120 | 1120 | } |
| 1121 | 1121 | if ( |
| 1122 | 1122 | !$t |
| 1123 | 1123 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 1124 | 1124 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 1125 | 1125 | ) { |
| 1126 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1126 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1127 | 1127 | } |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 1131 | 1131 | if (!$t) { |
| 1132 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1132 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -1140,11 +1140,11 @@ discard block |
||
| 1140 | 1140 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1141 | 1141 | ) { |
| 1142 | 1142 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 1143 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1143 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | if ($t) { |
| 1147 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1147 | + spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant'); |
|
| 1148 | 1148 | return $t['extension']; |
| 1149 | 1149 | } else { |
| 1150 | 1150 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1247,7 +1247,7 @@ discard block |
||
| 1247 | 1247 | } |
| 1248 | 1248 | } else { |
| 1249 | 1249 | $scheme = $t['scheme']; |
| 1250 | - $noproxy = $scheme . '://'; |
|
| 1250 | + $noproxy = $scheme.'://'; |
|
| 1251 | 1251 | } |
| 1252 | 1252 | if (isset($t['user'])) { |
| 1253 | 1253 | $user = [$t['user'], $t['pass']]; |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | if (!empty($t['query'])) { |
| 1264 | - $path .= '?' . $t['query']; |
|
| 1264 | + $path .= '?'.$t['query']; |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1335,29 +1335,29 @@ discard block |
||
| 1335 | 1335 | $proxy_user = ''; |
| 1336 | 1336 | $http_proxy = need_proxy($host); |
| 1337 | 1337 | if ($user) { |
| 1338 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1338 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | 1341 | $connect = ''; |
| 1342 | 1342 | if ($http_proxy) { |
| 1343 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1344 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1345 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1343 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) { |
|
| 1344 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1345 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1346 | 1346 | . "Host: $path_host\r\n" |
| 1347 | 1347 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1348 | 1348 | } else { |
| 1349 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1349 | + $path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://") |
|
| 1350 | 1350 | . (!$user ? '' : "$user@") |
| 1351 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1351 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1352 | 1352 | } |
| 1353 | 1353 | $t2 = @parse_url($http_proxy); |
| 1354 | 1354 | $first_host = $t2['host']; |
| 1355 | 1355 | $port = ($t2['port'] ?? null) ?: 80; |
| 1356 | 1356 | if ($t2['user'] ?? null) { |
| 1357 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1357 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1358 | 1358 | } |
| 1359 | 1359 | } else { |
| 1360 | - $first_host = $noproxy . $host; |
|
| 1360 | + $first_host = $noproxy.$host; |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | if ($connect) { |
@@ -1379,7 +1379,7 @@ discard block |
||
| 1379 | 1379 | ); |
| 1380 | 1380 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
| 1381 | 1381 | if (!$f) { |
| 1382 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1382 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1383 | 1383 | return $errno; |
| 1384 | 1384 | } |
| 1385 | 1385 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | or !count($res = explode(' ', $res)) |
| 1393 | 1393 | or $res[1] !== '200' |
| 1394 | 1394 | ) { |
| 1395 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1395 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1396 | 1396 | fclose($f); |
| 1397 | 1397 | |
| 1398 | 1398 | return false; |
@@ -1409,7 +1409,7 @@ discard block |
||
| 1409 | 1409 | } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
| 1410 | 1410 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 1411 | 1411 | if (!$f) { |
| 1412 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1412 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1413 | 1413 | |
| 1414 | 1414 | return $errno; |
| 1415 | 1415 | } |
@@ -1419,16 +1419,16 @@ discard block |
||
| 1419 | 1419 | $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
| 1420 | 1420 | |
| 1421 | 1421 | $host_port = $host; |
| 1422 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1422 | + if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) { |
|
| 1423 | 1423 | $host_port .= ":$port"; |
| 1424 | 1424 | } |
| 1425 | 1425 | $req = "$method $path $vers\r\n" |
| 1426 | 1426 | . "Host: $host_port\r\n" |
| 1427 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1427 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1428 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1429 | 1429 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1430 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1430 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1431 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1432 | 1432 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1433 | 1433 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1434 | 1434 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 46 | + $texte = '<'."?php\n" |
|
| 47 | 47 | . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
| 48 | 48 | . $texte; |
| 49 | 49 | |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | return $regs; |
| 113 | 113 | } else { |
| 114 | 114 | $ar = '\s*\'([^\']*)\''; |
| 115 | - $r = '\s*,' . $ar; |
|
| 115 | + $r = '\s*,'.$ar; |
|
| 116 | 116 | $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
| 117 | 117 | if (preg_match($r, $s, $regs)) { |
| 118 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 118 | + $regs[2] = $regs[1].(!$regs[2] ? '' : ':'.$regs[2].';'); |
|
| 119 | 119 | array_shift($regs); |
| 120 | 120 | array_shift($regs); |
| 121 | 121 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | // Si on n'a pas la bonne version de PHP, c'est la fin |
| 181 | 181 | if ($err) { |
| 182 | 182 | die("<div class='error'>" |
| 183 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 183 | + . '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>" |
|
| 184 | 184 | . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | if ($err) { |
| 203 | 203 | echo "<div class='error'>" |
| 204 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 204 | + . '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"; |
|
| 205 | 205 | foreach ($err as $e) { |
| 206 | 206 | echo "<li><strong>$e</strong></li>\n"; |
| 207 | 207 | } |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | function info_etape($titre, $complement = '') { |
| 237 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 238 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 237 | + return '<h2>'.$titre."</h2>\n". |
|
| 238 | + ($complement ? ''.$complement."\n" : ''); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -249,18 +249,18 @@ discard block |
||
| 249 | 249 | $code = _T('bouton_suivant'); |
| 250 | 250 | } |
| 251 | 251 | static $suivant = 0; |
| 252 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 252 | + $id = 'suivant'.(($suivant > 0) ? strval($suivant) : ''); |
|
| 253 | 253 | $suivant += 1; |
| 254 | 254 | |
| 255 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 256 | - $code . |
|
| 255 | + return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"". |
|
| 256 | + $code. |
|
| 257 | 257 | " >>\" /></p>\n"; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 261 | 261 | $intitule_etat = []; |
| 262 | 262 | //$en_cours = _request('etape')?_request('etape'):""; |
| 263 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 263 | + $liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$'); |
|
| 264 | 264 | $debut = 1; |
| 265 | 265 | $etat = 'ok'; |
| 266 | 266 | $last = count($liste); |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | $aff_etapes .= "<li class='$class'><div class='fond'>"; |
| 301 | 301 | $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
| 302 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 302 | + $aff_etapes .= '<em>'._T('etape')." </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 303 | 303 | $aff_etapes .= $intitule_etat["$phase"][$debut]; |
| 304 | 304 | $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
| 305 | 305 | $aff_etapes .= '</div></li>'; |
@@ -314,11 +314,11 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | |
| 316 | 316 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 317 | - return "<fieldset>\n" . |
|
| 318 | - $avant . |
|
| 319 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 320 | - fieldset_champs($champs) . |
|
| 321 | - $apres . |
|
| 317 | + return "<fieldset>\n". |
|
| 318 | + $avant. |
|
| 319 | + ($legend ? '<legend>'.$legend."</legend>\n" : ''). |
|
| 320 | + fieldset_champs($champs). |
|
| 321 | + $apres. |
|
| 322 | 322 | "</fieldset>\n"; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -328,18 +328,18 @@ discard block |
||
| 328 | 328 | $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
| 329 | 329 | $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
| 330 | 330 | if (isset($contenu['alternatives'])) { |
| 331 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 331 | + $fieldset .= $contenu['label']."\n"; |
|
| 332 | 332 | foreach ($contenu['alternatives'] as $valeur => $label) { |
| 333 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 333 | + $fieldset .= "<input type='radio' name='".$nom. |
|
| 334 | 334 | "' id='$nom-$valeur' value='$valeur'" |
| 335 | 335 | . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
| 336 | 336 | . "/>\n"; |
| 337 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 337 | + $fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n"; |
|
| 338 | 338 | } |
| 339 | 339 | $fieldset .= "<br />\n"; |
| 340 | 340 | } else { |
| 341 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 342 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 341 | + $fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n"; |
|
| 342 | + $fieldset .= '<input '.$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'" |
|
| 343 | 343 | . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
| 344 | 344 | . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
| 345 | 345 | . " />\n"; |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | |
| 352 | 352 | function install_select_serveur() { |
| 353 | 353 | $options = []; |
| 354 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 354 | + $dir = _DIR_RESTREINT.'req/'; |
|
| 355 | 355 | $d = opendir($dir); |
| 356 | 356 | if (!$d) { |
| 357 | 357 | return []; |
@@ -359,17 +359,17 @@ discard block |
||
| 359 | 359 | while (($f = readdir($d)) !== false) { |
| 360 | 360 | if ( |
| 361 | 361 | (preg_match('/^(.*)[.]php$/', $f, $s)) |
| 362 | - and is_readable($f = $dir . $f) |
|
| 362 | + and is_readable($f = $dir.$f) |
|
| 363 | 363 | ) { |
| 364 | 364 | require_once($f); |
| 365 | 365 | $s = $s[1]; |
| 366 | - $v = 'spip_versions_' . $s; |
|
| 366 | + $v = 'spip_versions_'.$s; |
|
| 367 | 367 | if (function_exists($v) and $v()) { |
| 368 | 368 | $titre = _T("install_select_type_$s"); |
| 369 | 369 | // proposer mysql par defaut si dispo |
| 370 | 370 | $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
| 371 | 371 | $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
| 372 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 372 | + . "<label for='$s'>".($titre ?: $s).'</label></li>'; |
|
| 373 | 373 | } else { |
| 374 | 374 | spip_log("$s: portage indisponible"); |
| 375 | 375 | } |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | "\n<input type='hidden' name='etape' value='$etape' />" |
| 388 | 388 | . $hidden |
| 389 | 389 | . (_request('echec') ? |
| 390 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 391 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 390 | + ('<p><b>'._T('avis_connexion_echec_1'). |
|
| 391 | + '</b></p><p>'._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3').'</p>') |
|
| 392 | 392 | : '') |
| 393 | 393 | |
| 394 | 394 | . ($jquery ? http_script('', 'jquery.js') : '') |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | });') |
| 427 | 427 | |
| 428 | 428 | . ($server_db |
| 429 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 429 | + ? '<input type="hidden" name="server_db" value="'.$server_db.'" />' |
|
| 430 | 430 | . (($predef[0]) |
| 431 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 431 | + ? ('<h3>'._T('install_serveur_hebergeur').'</h3>') |
|
| 432 | 432 | : '') |
| 433 | 433 | : ('<fieldset><legend>' |
| 434 | 434 | . _T('install_select_type_db') |
@@ -443,9 +443,9 @@ discard block |
||
| 443 | 443 | . "\n</ul>\n</div></fieldset>") |
| 444 | 444 | ) |
| 445 | 445 | . '<div id="install_adresse_base_hebergeur">' |
| 446 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 446 | + . '<p>'._T('texte_connexion_mysql').'</p>' |
|
| 447 | 447 | . ($predef[1] |
| 448 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 448 | + ? '<h3>'._T('install_adresse_base_hebergeur').'</h3>' |
|
| 449 | 449 | : fieldset( |
| 450 | 450 | _T('entree_base_donnee_1'), |
| 451 | 451 | [ |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | |
| 461 | 461 | . '<div id="install_login_base_hebergeur">' |
| 462 | 462 | . ($predef[2] |
| 463 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 463 | + ? '<h3>'._T('install_login_base_hebergeur').'</h3>' |
|
| 464 | 464 | : fieldset( |
| 465 | 465 | _T('entree_login_connexion_1'), |
| 466 | 466 | [ |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | . '<div id="install_pass_base_hebergeur">' |
| 477 | 477 | . ($predef[3] |
| 478 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 478 | + ? '<h3>'._T('install_pass_base_hebergeur').'</h3>' |
|
| 479 | 479 | : fieldset( |
| 480 | 480 | _T('entree_mot_passe_1'), |
| 481 | 481 | [ |
@@ -497,20 +497,20 @@ discard block |
||
| 497 | 497 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 498 | 498 | return ((defined('_INSTALL_HOST_DB')) |
| 499 | 499 | ? '' |
| 500 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 500 | + : "\n<input type='hidden' name='adresse_db' value=\"".spip_htmlspecialchars($adresse_db).'" />' |
|
| 501 | 501 | ) |
| 502 | 502 | . ((defined('_INSTALL_USER_DB')) |
| 503 | 503 | ? '' |
| 504 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 504 | + : "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db).'" />' |
|
| 505 | 505 | ) |
| 506 | 506 | . ((defined('_INSTALL_PASS_DB')) |
| 507 | 507 | ? '' |
| 508 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 508 | + : "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db).'" />' |
|
| 509 | 509 | ) |
| 510 | 510 | |
| 511 | 511 | . ((defined('_INSTALL_SERVER_DB')) |
| 512 | 512 | ? '' |
| 513 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 513 | + : "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db).'" />' |
|
| 514 | 514 | ); |
| 515 | 515 | } |
| 516 | 516 | |
@@ -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 | |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 47 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | - . $texte; |
|
| 46 | + $texte = '<' . "?php\n" |
|
| 47 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | + . $texte; |
|
| 49 | 49 | |
| 50 | - ecrire_fichier($nom, $texte); |
|
| 50 | + ecrire_fichier($nom, $texte); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -76,20 +76,20 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | **/ |
| 78 | 78 | function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 79 | - $adr = addcslashes($adr, "'\\"); |
|
| 80 | - $port = addcslashes($port, "'\\"); |
|
| 81 | - $login = addcslashes($login, "'\\"); |
|
| 82 | - $pass = addcslashes($pass, "'\\"); |
|
| 83 | - $base = addcslashes($base, "'\\"); |
|
| 84 | - $type = addcslashes($type, "'\\"); |
|
| 85 | - $pref = addcslashes($pref, "'\\"); |
|
| 86 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 87 | - $charset = addcslashes($charset, "'\\"); |
|
| 88 | - |
|
| 89 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 90 | - . 'spip_connect_db(' |
|
| 91 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 92 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 79 | + $adr = addcslashes($adr, "'\\"); |
|
| 80 | + $port = addcslashes($port, "'\\"); |
|
| 81 | + $login = addcslashes($login, "'\\"); |
|
| 82 | + $pass = addcslashes($pass, "'\\"); |
|
| 83 | + $base = addcslashes($base, "'\\"); |
|
| 84 | + $type = addcslashes($type, "'\\"); |
|
| 85 | + $pref = addcslashes($pref, "'\\"); |
|
| 86 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 87 | + $charset = addcslashes($charset, "'\\"); |
|
| 88 | + |
|
| 89 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 90 | + . 'spip_connect_db(' |
|
| 91 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 92 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -105,29 +105,29 @@ discard block |
||
| 105 | 105 | * Tableau des informations sur la connexion |
| 106 | 106 | **/ |
| 107 | 107 | function analyse_fichier_connection(string $file): array { |
| 108 | - if (!file_exists($file)) { |
|
| 109 | - return []; |
|
| 110 | - } |
|
| 111 | - $s = file_get_contents($file); |
|
| 112 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 113 | - array_shift($regs); |
|
| 114 | - |
|
| 115 | - return $regs; |
|
| 116 | - } else { |
|
| 117 | - $ar = '\s*\'([^\']*)\''; |
|
| 118 | - $r = '\s*,' . $ar; |
|
| 119 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 120 | - if (preg_match($r, $s, $regs)) { |
|
| 121 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 122 | - array_shift($regs); |
|
| 123 | - array_shift($regs); |
|
| 124 | - |
|
| 125 | - return $regs; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 129 | - |
|
| 130 | - return []; |
|
| 108 | + if (!file_exists($file)) { |
|
| 109 | + return []; |
|
| 110 | + } |
|
| 111 | + $s = file_get_contents($file); |
|
| 112 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 113 | + array_shift($regs); |
|
| 114 | + |
|
| 115 | + return $regs; |
|
| 116 | + } else { |
|
| 117 | + $ar = '\s*\'([^\']*)\''; |
|
| 118 | + $r = '\s*,' . $ar; |
|
| 119 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 120 | + if (preg_match($r, $s, $regs)) { |
|
| 121 | + $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 122 | + array_shift($regs); |
|
| 123 | + array_shift($regs); |
|
| 124 | + |
|
| 125 | + return $regs; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 129 | + |
|
| 130 | + return []; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -144,75 +144,75 @@ discard block |
||
| 144 | 144 | * Liste des noms de connecteurs |
| 145 | 145 | **/ |
| 146 | 146 | function bases_referencees($exclu = '') { |
| 147 | - $tables = []; |
|
| 148 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 149 | - if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 150 | - $tables[] = basename($f, '.php'); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $tables; |
|
| 147 | + $tables = []; |
|
| 148 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 149 | + if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 150 | + $tables[] = basename($f, '.php'); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $tables; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | function install_mode_appel($server_db, $tout = true) { |
| 159 | - return ($server_db != 'mysql') ? '' |
|
| 160 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 161 | - . test_sql_mode_mysql($server_db)); |
|
| 159 | + return ($server_db != 'mysql') ? '' |
|
| 160 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 161 | + . test_sql_mode_mysql($server_db)); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // |
| 165 | 165 | // Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-) |
| 166 | 166 | // (sert a l'etape 1 de l'installation) |
| 167 | 167 | function tester_compatibilite_hebergement() { |
| 168 | - $err = []; |
|
| 169 | - |
|
| 170 | - $p = phpversion(); |
|
| 171 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 172 | - $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 173 | - } |
|
| 174 | - if (version_compare($p, _PHP_MAX, '>')) { |
|
| 175 | - $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions()); |
|
| 179 | - if (!empty($diff)) { |
|
| 180 | - $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 184 | - if ($err) { |
|
| 185 | - die("<div class='error'>" |
|
| 186 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 187 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // Il faut une base de donnees tout de meme ... |
|
| 191 | - $serveurs = install_select_serveur(); |
|
| 192 | - if (!$serveurs) { |
|
| 193 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 194 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 195 | - . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 196 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0) |
|
| 200 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 201 | - $err[] = _T('install_extension_mbstring') |
|
| 202 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - if ($err) { |
|
| 206 | - echo "<div class='error'>" |
|
| 207 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 208 | - foreach ($err as $e) { |
|
| 209 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 213 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 214 | - echo "</ul></div>\n"; |
|
| 215 | - } |
|
| 168 | + $err = []; |
|
| 169 | + |
|
| 170 | + $p = phpversion(); |
|
| 171 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 172 | + $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 173 | + } |
|
| 174 | + if (version_compare($p, _PHP_MAX, '>')) { |
|
| 175 | + $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions()); |
|
| 179 | + if (!empty($diff)) { |
|
| 180 | + $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 184 | + if ($err) { |
|
| 185 | + die("<div class='error'>" |
|
| 186 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 187 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // Il faut une base de donnees tout de meme ... |
|
| 191 | + $serveurs = install_select_serveur(); |
|
| 192 | + if (!$serveurs) { |
|
| 193 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 194 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 195 | + . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 196 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // et surtout pas ce mbstring.overload (has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0) |
|
| 200 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 201 | + $err[] = _T('install_extension_mbstring') |
|
| 202 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + if ($err) { |
|
| 206 | + echo "<div class='error'>" |
|
| 207 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 208 | + foreach ($err as $e) { |
|
| 209 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 213 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 214 | + echo "</ul></div>\n"; |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -222,23 +222,23 @@ discard block |
||
| 222 | 222 | * @note superflu ?? |
| 223 | 223 | */ |
| 224 | 224 | function login_hebergeur() { |
| 225 | - $base_hebergeur = 'localhost'; # par defaut |
|
| 225 | + $base_hebergeur = 'localhost'; # par defaut |
|
| 226 | 226 | |
| 227 | - // Free |
|
| 228 | - if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 229 | - $base_hebergeur = 'sql.free.fr'; |
|
| 230 | - $login_hebergeur = $regs[1]; |
|
| 231 | - } else { |
|
| 232 | - $login_hebergeur = ''; |
|
| 233 | - } |
|
| 227 | + // Free |
|
| 228 | + if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 229 | + $base_hebergeur = 'sql.free.fr'; |
|
| 230 | + $login_hebergeur = $regs[1]; |
|
| 231 | + } else { |
|
| 232 | + $login_hebergeur = ''; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - return [$base_hebergeur, $login_hebergeur]; |
|
| 235 | + return [$base_hebergeur, $login_hebergeur]; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | function info_etape($titre, $complement = '') { |
| 240 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 241 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 240 | + return '<h2>' . $titre . "</h2>\n" . |
|
| 241 | + ($complement ? '' . $complement . "\n" : ''); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -248,154 +248,154 @@ discard block |
||
| 248 | 248 | * @return string Code HTML du bouton |
| 249 | 249 | **/ |
| 250 | 250 | function bouton_suivant($code = '') { |
| 251 | - if ($code == '') { |
|
| 252 | - $code = _T('bouton_suivant'); |
|
| 253 | - } |
|
| 254 | - static $suivant = 0; |
|
| 255 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 256 | - $suivant += 1; |
|
| 257 | - |
|
| 258 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 259 | - $code . |
|
| 260 | - " >>\" /></p>\n"; |
|
| 251 | + if ($code == '') { |
|
| 252 | + $code = _T('bouton_suivant'); |
|
| 253 | + } |
|
| 254 | + static $suivant = 0; |
|
| 255 | + $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 256 | + $suivant += 1; |
|
| 257 | + |
|
| 258 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 259 | + $code . |
|
| 260 | + " >>\" /></p>\n"; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 264 | - $intitule_etat = []; |
|
| 265 | - //$en_cours = _request('etape')?_request('etape'):""; |
|
| 266 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 267 | - $debut = 1; |
|
| 268 | - $etat = 'ok'; |
|
| 269 | - $last = count($liste); |
|
| 264 | + $intitule_etat = []; |
|
| 265 | + //$en_cours = _request('etape')?_request('etape'):""; |
|
| 266 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 267 | + $debut = 1; |
|
| 268 | + $etat = 'ok'; |
|
| 269 | + $last = count($liste); |
|
| 270 | 270 | // $texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo')); |
| 271 | 271 | |
| 272 | - $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 273 | - $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 274 | - $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 275 | - $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 272 | + $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 273 | + $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 274 | + $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 275 | + $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 276 | 276 | |
| 277 | - $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 278 | - $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 279 | - $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 280 | - $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 281 | - $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 277 | + $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 278 | + $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 279 | + $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 280 | + $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 281 | + $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 282 | 282 | |
| 283 | 283 | // $aff_etapes = "<span id='etapes'>"; |
| 284 | 284 | |
| 285 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 286 | - |
|
| 287 | - foreach ($liste as $etape => $fichier) { |
|
| 288 | - if ($debut < $last) { |
|
| 289 | - if ($debut == $en_cours && $erreur) { |
|
| 290 | - $class = 'on erreur'; |
|
| 291 | - } else { |
|
| 292 | - if ($debut == $en_cours) { |
|
| 293 | - $class = 'on'; |
|
| 294 | - } else { |
|
| 295 | - if ($debut > $en_cours) { |
|
| 296 | - $class = 'prochains'; |
|
| 297 | - } else { |
|
| 298 | - $class = 'valides'; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 304 | - $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 305 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 306 | - $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 307 | - $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 308 | - $aff_etapes .= '</div></li>'; |
|
| 309 | - } |
|
| 310 | - $debut++; |
|
| 311 | - } |
|
| 312 | - $aff_etapes .= '</ul>'; |
|
| 313 | - $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 314 | - |
|
| 315 | - return $aff_etapes; |
|
| 285 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 286 | + |
|
| 287 | + foreach ($liste as $etape => $fichier) { |
|
| 288 | + if ($debut < $last) { |
|
| 289 | + if ($debut == $en_cours && $erreur) { |
|
| 290 | + $class = 'on erreur'; |
|
| 291 | + } else { |
|
| 292 | + if ($debut == $en_cours) { |
|
| 293 | + $class = 'on'; |
|
| 294 | + } else { |
|
| 295 | + if ($debut > $en_cours) { |
|
| 296 | + $class = 'prochains'; |
|
| 297 | + } else { |
|
| 298 | + $class = 'valides'; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 304 | + $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 305 | + $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 306 | + $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 307 | + $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 308 | + $aff_etapes .= '</div></li>'; |
|
| 309 | + } |
|
| 310 | + $debut++; |
|
| 311 | + } |
|
| 312 | + $aff_etapes .= '</ul>'; |
|
| 313 | + $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 314 | + |
|
| 315 | + return $aff_etapes; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 320 | - return "<fieldset>\n" . |
|
| 321 | - $avant . |
|
| 322 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 323 | - fieldset_champs($champs) . |
|
| 324 | - $apres . |
|
| 325 | - "</fieldset>\n"; |
|
| 320 | + return "<fieldset>\n" . |
|
| 321 | + $avant . |
|
| 322 | + ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 323 | + fieldset_champs($champs) . |
|
| 324 | + $apres . |
|
| 325 | + "</fieldset>\n"; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | function fieldset_champs($champs = []) { |
| 329 | - $fieldset = ''; |
|
| 330 | - foreach ($champs as $nom => $contenu) { |
|
| 331 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 332 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 333 | - if (isset($contenu['alternatives'])) { |
|
| 334 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 335 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 336 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 337 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 338 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 339 | - . "/>\n"; |
|
| 340 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 341 | - } |
|
| 342 | - $fieldset .= "<br />\n"; |
|
| 343 | - } else { |
|
| 344 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 345 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 346 | - . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 347 | - . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 348 | - . " />\n"; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return $fieldset; |
|
| 329 | + $fieldset = ''; |
|
| 330 | + foreach ($champs as $nom => $contenu) { |
|
| 331 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 332 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 333 | + if (isset($contenu['alternatives'])) { |
|
| 334 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 335 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 336 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 337 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 338 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 339 | + . "/>\n"; |
|
| 340 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 341 | + } |
|
| 342 | + $fieldset .= "<br />\n"; |
|
| 343 | + } else { |
|
| 344 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 345 | + $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 346 | + . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 347 | + . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 348 | + . " />\n"; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return $fieldset; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | function install_select_serveur() { |
| 356 | - $options = []; |
|
| 357 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 358 | - $d = opendir($dir); |
|
| 359 | - if (!$d) { |
|
| 360 | - return []; |
|
| 361 | - } |
|
| 362 | - while (($f = readdir($d)) !== false) { |
|
| 363 | - if ( |
|
| 364 | - (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 365 | - and is_readable($f = $dir . $f) |
|
| 366 | - ) { |
|
| 367 | - require_once($f); |
|
| 368 | - $s = $s[1]; |
|
| 369 | - $v = 'spip_versions_' . $s; |
|
| 370 | - if (function_exists($v) and $v()) { |
|
| 371 | - $titre = _T("install_select_type_$s"); |
|
| 372 | - // proposer mysql par defaut si dispo |
|
| 373 | - $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 374 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 375 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 376 | - } else { |
|
| 377 | - spip_log("$s: portage indisponible"); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - sort($options); |
|
| 382 | - |
|
| 383 | - return $options; |
|
| 356 | + $options = []; |
|
| 357 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 358 | + $d = opendir($dir); |
|
| 359 | + if (!$d) { |
|
| 360 | + return []; |
|
| 361 | + } |
|
| 362 | + while (($f = readdir($d)) !== false) { |
|
| 363 | + if ( |
|
| 364 | + (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 365 | + and is_readable($f = $dir . $f) |
|
| 366 | + ) { |
|
| 367 | + require_once($f); |
|
| 368 | + $s = $s[1]; |
|
| 369 | + $v = 'spip_versions_' . $s; |
|
| 370 | + if (function_exists($v) and $v()) { |
|
| 371 | + $titre = _T("install_select_type_$s"); |
|
| 372 | + // proposer mysql par defaut si dispo |
|
| 373 | + $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 374 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 375 | + . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 376 | + } else { |
|
| 377 | + spip_log("$s: portage indisponible"); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + sort($options); |
|
| 382 | + |
|
| 383 | + return $options; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 387 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 388 | - |
|
| 389 | - return generer_form_ecrire('install', ( |
|
| 390 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 391 | - . $hidden |
|
| 392 | - . (_request('echec') ? |
|
| 393 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 395 | - : '') |
|
| 396 | - |
|
| 397 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 398 | - . http_script(' |
|
| 387 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 388 | + |
|
| 389 | + return generer_form_ecrire('install', ( |
|
| 390 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 391 | + . $hidden |
|
| 392 | + . (_request('echec') ? |
|
| 393 | + ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | + '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 395 | + : '') |
|
| 396 | + |
|
| 397 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 398 | + . http_script(' |
|
| 399 | 399 | jQuery(function($) { |
| 400 | 400 | $details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur"); |
| 401 | 401 | $("input[type=hidden][name=server_db]").each(function(){ |
@@ -428,145 +428,145 @@ discard block |
||
| 428 | 428 | }); |
| 429 | 429 | });') |
| 430 | 430 | |
| 431 | - . ($server_db |
|
| 432 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 433 | - . (($predef[0]) |
|
| 434 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 435 | - : '') |
|
| 436 | - : ('<fieldset><legend>' |
|
| 437 | - . _T('install_select_type_db') |
|
| 438 | - . '</legend>' |
|
| 439 | - . '<p class="explication">' |
|
| 440 | - . _T('install_types_db_connus') |
|
| 441 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 442 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 443 | - . '</p>' |
|
| 444 | - . "\n<div class='p'>\n<ul>\n" |
|
| 445 | - . join("\n", install_select_serveur()) |
|
| 446 | - . "\n</ul>\n</div></fieldset>") |
|
| 447 | - ) |
|
| 448 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 449 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 450 | - . ($predef[1] |
|
| 451 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 452 | - : fieldset( |
|
| 453 | - _T('entree_base_donnee_1'), |
|
| 454 | - [ |
|
| 455 | - 'adresse_db' => [ |
|
| 456 | - 'label' => $db[1], |
|
| 457 | - 'valeur' => $db[0] |
|
| 458 | - ], |
|
| 459 | - ] |
|
| 460 | - ) |
|
| 461 | - ) |
|
| 462 | - . '</div>' |
|
| 463 | - |
|
| 464 | - . '<div id="install_login_base_hebergeur">' |
|
| 465 | - . ($predef[2] |
|
| 466 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 467 | - : fieldset( |
|
| 468 | - _T('entree_login_connexion_1'), |
|
| 469 | - [ |
|
| 470 | - 'login_db' => [ |
|
| 471 | - 'label' => $login[1], |
|
| 472 | - 'valeur' => $login[0] |
|
| 473 | - ], |
|
| 474 | - ] |
|
| 475 | - ) |
|
| 476 | - ) |
|
| 477 | - . '</div>' |
|
| 478 | - |
|
| 479 | - . '<div id="install_pass_base_hebergeur">' |
|
| 480 | - . ($predef[3] |
|
| 481 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 482 | - : fieldset( |
|
| 483 | - _T('entree_mot_passe_1'), |
|
| 484 | - [ |
|
| 485 | - 'pass_db' => [ |
|
| 486 | - 'label' => $pass[1], |
|
| 487 | - 'valeur' => $pass[0] |
|
| 488 | - ], |
|
| 489 | - ] |
|
| 490 | - ) |
|
| 491 | - ) |
|
| 492 | - . '</div>' |
|
| 493 | - |
|
| 494 | - . bouton_suivant())); |
|
| 431 | + . ($server_db |
|
| 432 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 433 | + . (($predef[0]) |
|
| 434 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 435 | + : '') |
|
| 436 | + : ('<fieldset><legend>' |
|
| 437 | + . _T('install_select_type_db') |
|
| 438 | + . '</legend>' |
|
| 439 | + . '<p class="explication">' |
|
| 440 | + . _T('install_types_db_connus') |
|
| 441 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 442 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 443 | + . '</p>' |
|
| 444 | + . "\n<div class='p'>\n<ul>\n" |
|
| 445 | + . join("\n", install_select_serveur()) |
|
| 446 | + . "\n</ul>\n</div></fieldset>") |
|
| 447 | + ) |
|
| 448 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 449 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 450 | + . ($predef[1] |
|
| 451 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 452 | + : fieldset( |
|
| 453 | + _T('entree_base_donnee_1'), |
|
| 454 | + [ |
|
| 455 | + 'adresse_db' => [ |
|
| 456 | + 'label' => $db[1], |
|
| 457 | + 'valeur' => $db[0] |
|
| 458 | + ], |
|
| 459 | + ] |
|
| 460 | + ) |
|
| 461 | + ) |
|
| 462 | + . '</div>' |
|
| 463 | + |
|
| 464 | + . '<div id="install_login_base_hebergeur">' |
|
| 465 | + . ($predef[2] |
|
| 466 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 467 | + : fieldset( |
|
| 468 | + _T('entree_login_connexion_1'), |
|
| 469 | + [ |
|
| 470 | + 'login_db' => [ |
|
| 471 | + 'label' => $login[1], |
|
| 472 | + 'valeur' => $login[0] |
|
| 473 | + ], |
|
| 474 | + ] |
|
| 475 | + ) |
|
| 476 | + ) |
|
| 477 | + . '</div>' |
|
| 478 | + |
|
| 479 | + . '<div id="install_pass_base_hebergeur">' |
|
| 480 | + . ($predef[3] |
|
| 481 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 482 | + : fieldset( |
|
| 483 | + _T('entree_mot_passe_1'), |
|
| 484 | + [ |
|
| 485 | + 'pass_db' => [ |
|
| 486 | + 'label' => $pass[1], |
|
| 487 | + 'valeur' => $pass[0] |
|
| 488 | + ], |
|
| 489 | + ] |
|
| 490 | + ) |
|
| 491 | + ) |
|
| 492 | + . '</div>' |
|
| 493 | + |
|
| 494 | + . bouton_suivant())); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | // 4 valeurs qu'on reconduit d'un script a l'autre |
| 498 | 498 | // sauf s'ils sont predefinis. |
| 499 | 499 | |
| 500 | 500 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 501 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 502 | - ? '' |
|
| 503 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 504 | - ) |
|
| 505 | - . ((defined('_INSTALL_USER_DB')) |
|
| 506 | - ? '' |
|
| 507 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 508 | - ) |
|
| 509 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 510 | - ? '' |
|
| 511 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 512 | - ) |
|
| 513 | - |
|
| 514 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 515 | - ? '' |
|
| 516 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 517 | - ); |
|
| 501 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 502 | + ? '' |
|
| 503 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 504 | + ) |
|
| 505 | + . ((defined('_INSTALL_USER_DB')) |
|
| 506 | + ? '' |
|
| 507 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 508 | + ) |
|
| 509 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 510 | + ? '' |
|
| 511 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 512 | + ) |
|
| 513 | + |
|
| 514 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 515 | + ? '' |
|
| 516 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 517 | + ); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // presentation des bases existantes |
| 521 | 521 | |
| 522 | 522 | function install_etape_liste_bases($server_db, $login_db, $disabled = []) { |
| 523 | - $bases = $checked = []; |
|
| 524 | - $noms = sql_listdbs($server_db); |
|
| 525 | - if (!$noms) { |
|
| 526 | - return ''; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - foreach ($noms as $nom) { |
|
| 530 | - $id = spip_htmlspecialchars($nom); |
|
| 531 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 532 | - $base = ' name="choix_db" value="' |
|
| 533 | - . $nom |
|
| 534 | - . '"' |
|
| 535 | - . $dis |
|
| 536 | - . " type='radio' id='$id'"; |
|
| 537 | - $label = "<label for='$id'>" |
|
| 538 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 539 | - . '</label>'; |
|
| 540 | - |
|
| 541 | - if ( |
|
| 542 | - !$checked and !$dis and |
|
| 543 | - (($nom == $login_db) or |
|
| 544 | - ($GLOBALS['table_prefix'] == $nom)) |
|
| 545 | - ) { |
|
| 546 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 547 | - } else { |
|
| 548 | - $bases[] = "<input$base />\n$label"; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if (!$bases && !$checked) { |
|
| 553 | - return false; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - if ($checked) { |
|
| 557 | - array_unshift($bases, $checked); |
|
| 558 | - $checked = true; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return [$checked, $bases]; |
|
| 523 | + $bases = $checked = []; |
|
| 524 | + $noms = sql_listdbs($server_db); |
|
| 525 | + if (!$noms) { |
|
| 526 | + return ''; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + foreach ($noms as $nom) { |
|
| 530 | + $id = spip_htmlspecialchars($nom); |
|
| 531 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 532 | + $base = ' name="choix_db" value="' |
|
| 533 | + . $nom |
|
| 534 | + . '"' |
|
| 535 | + . $dis |
|
| 536 | + . " type='radio' id='$id'"; |
|
| 537 | + $label = "<label for='$id'>" |
|
| 538 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 539 | + . '</label>'; |
|
| 540 | + |
|
| 541 | + if ( |
|
| 542 | + !$checked and !$dis and |
|
| 543 | + (($nom == $login_db) or |
|
| 544 | + ($GLOBALS['table_prefix'] == $nom)) |
|
| 545 | + ) { |
|
| 546 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 547 | + } else { |
|
| 548 | + $bases[] = "<input$base />\n$label"; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if (!$bases && !$checked) { |
|
| 553 | + return false; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + if ($checked) { |
|
| 557 | + array_unshift($bases, $checked); |
|
| 558 | + $checked = true; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return [$checked, $bases]; |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | function install_propager($hidden) { |
| 565 | - $res = ''; |
|
| 566 | - foreach ($hidden as $k) { |
|
| 567 | - $v = spip_htmlentities(_request($k)); |
|
| 568 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 569 | - } |
|
| 565 | + $res = ''; |
|
| 566 | + foreach ($hidden as $k) { |
|
| 567 | + $v = spip_htmlentities(_request($k)); |
|
| 568 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - return $res; |
|
| 571 | + return $res; |
|
| 572 | 572 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $id_rubrique, |
| 151 | 151 | [ |
| 152 | 152 | 'data' => $set, |
| 153 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 153 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique').' '._T('info_numero_abbreviation').$id_rubrique] |
|
| 154 | 154 | ], |
| 155 | 155 | $c |
| 156 | 156 | ) |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | ) |
| 255 | 255 | ) { |
| 256 | 256 | if ($s['statut'] != 'prepa') { |
| 257 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 257 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']); |
|
| 258 | 258 | } |
| 259 | 259 | } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
| 260 | 260 | $statut_ancien = $s['statut']; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 55 | - |
|
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - '&' |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - include_spip('inc/headers'); |
|
| 65 | - redirige_par_entete($redirect); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return [$id_rubrique, $err]; |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | + |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + '&' |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + include_spip('inc/headers'); |
|
| 65 | + redirige_par_entete($redirect); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return [$id_rubrique, $err]; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -80,64 +80,64 @@ discard block |
||
| 80 | 80 | * Identifiant de la rubrique crée |
| 81 | 81 | */ |
| 82 | 82 | function rubrique_inserer($id_parent, $set = null) { |
| 83 | - $champs = [ |
|
| 84 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | - 'id_parent' => intval($id_parent), |
|
| 86 | - 'statut' => 'prepa' |
|
| 87 | - ]; |
|
| 88 | - |
|
| 89 | - if ($set) { |
|
| 90 | - $champs = array_merge($champs, $set); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Envoyer aux plugins |
|
| 94 | - $champs = pipeline( |
|
| 95 | - 'pre_insertion', |
|
| 96 | - [ |
|
| 97 | - 'args' => [ |
|
| 98 | - 'table' => 'spip_rubriques', |
|
| 99 | - ], |
|
| 100 | - 'data' => $champs |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | - pipeline( |
|
| 106 | - 'post_insertion', |
|
| 107 | - [ |
|
| 108 | - 'args' => [ |
|
| 109 | - 'table' => 'spip_rubriques', |
|
| 110 | - 'id_objet' => $id_rubrique |
|
| 111 | - ], |
|
| 112 | - 'data' => $champs |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - propager_les_secteurs(); |
|
| 116 | - calculer_langues_rubriques(); |
|
| 117 | - |
|
| 118 | - // Appeler une notification |
|
| 119 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 120 | - $notifications( |
|
| 121 | - 'rubrique_inserer', |
|
| 122 | - $id_rubrique, |
|
| 123 | - [ |
|
| 124 | - 'id_parent' => $id_parent, |
|
| 125 | - 'champs' => $champs, |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - $notifications( |
|
| 129 | - 'objet_inserer', |
|
| 130 | - $id_rubrique, |
|
| 131 | - [ |
|
| 132 | - 'objet' => 'rubrique', |
|
| 133 | - 'id_objet' => $id_rubrique, |
|
| 134 | - 'id_parent' => $id_parent, |
|
| 135 | - 'champs' => $champs, |
|
| 136 | - ] |
|
| 137 | - ); |
|
| 138 | - } |
|
| 83 | + $champs = [ |
|
| 84 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | + 'id_parent' => intval($id_parent), |
|
| 86 | + 'statut' => 'prepa' |
|
| 87 | + ]; |
|
| 88 | + |
|
| 89 | + if ($set) { |
|
| 90 | + $champs = array_merge($champs, $set); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Envoyer aux plugins |
|
| 94 | + $champs = pipeline( |
|
| 95 | + 'pre_insertion', |
|
| 96 | + [ |
|
| 97 | + 'args' => [ |
|
| 98 | + 'table' => 'spip_rubriques', |
|
| 99 | + ], |
|
| 100 | + 'data' => $champs |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | + pipeline( |
|
| 106 | + 'post_insertion', |
|
| 107 | + [ |
|
| 108 | + 'args' => [ |
|
| 109 | + 'table' => 'spip_rubriques', |
|
| 110 | + 'id_objet' => $id_rubrique |
|
| 111 | + ], |
|
| 112 | + 'data' => $champs |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + propager_les_secteurs(); |
|
| 116 | + calculer_langues_rubriques(); |
|
| 117 | + |
|
| 118 | + // Appeler une notification |
|
| 119 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 120 | + $notifications( |
|
| 121 | + 'rubrique_inserer', |
|
| 122 | + $id_rubrique, |
|
| 123 | + [ |
|
| 124 | + 'id_parent' => $id_parent, |
|
| 125 | + 'champs' => $champs, |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + $notifications( |
|
| 129 | + 'objet_inserer', |
|
| 130 | + $id_rubrique, |
|
| 131 | + [ |
|
| 132 | + 'objet' => 'rubrique', |
|
| 133 | + 'id_objet' => $id_rubrique, |
|
| 134 | + 'id_parent' => $id_parent, |
|
| 135 | + 'champs' => $champs, |
|
| 136 | + ] |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return $id_rubrique; |
|
| 140 | + return $id_rubrique; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -153,46 +153,46 @@ discard block |
||
| 153 | 153 | * - chaîne : texte d'un message d'erreur |
| 154 | 154 | */ |
| 155 | 155 | function rubrique_modifier($id_rubrique, $set = null) { |
| 156 | - include_spip('inc/autoriser'); |
|
| 157 | - include_spip('inc/filtres'); |
|
| 158 | - |
|
| 159 | - include_spip('inc/modifier'); |
|
| 160 | - $c = collecter_requests( |
|
| 161 | - // include list |
|
| 162 | - objet_info('rubrique', 'champs_editables'), |
|
| 163 | - // exclude list |
|
| 164 | - ['id_parent', 'confirme_deplace'], |
|
| 165 | - // donnees eventuellement fournies |
|
| 166 | - $set |
|
| 167 | - ); |
|
| 168 | - |
|
| 169 | - if ( |
|
| 170 | - $err = objet_modifier_champs( |
|
| 171 | - 'rubrique', |
|
| 172 | - $id_rubrique, |
|
| 173 | - [ |
|
| 174 | - 'data' => $set, |
|
| 175 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 176 | - ], |
|
| 177 | - $c |
|
| 178 | - ) |
|
| 179 | - ) { |
|
| 180 | - return $err; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 184 | - // Deplacer la rubrique |
|
| 185 | - if (isset($c['id_parent'])) { |
|
| 186 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // invalider les caches marques de cette rubrique |
|
| 190 | - include_spip('inc/invalideur'); |
|
| 191 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 192 | - // et celui de menu_rubriques |
|
| 193 | - effacer_meta('date_calcul_rubriques'); |
|
| 194 | - |
|
| 195 | - return $err; |
|
| 156 | + include_spip('inc/autoriser'); |
|
| 157 | + include_spip('inc/filtres'); |
|
| 158 | + |
|
| 159 | + include_spip('inc/modifier'); |
|
| 160 | + $c = collecter_requests( |
|
| 161 | + // include list |
|
| 162 | + objet_info('rubrique', 'champs_editables'), |
|
| 163 | + // exclude list |
|
| 164 | + ['id_parent', 'confirme_deplace'], |
|
| 165 | + // donnees eventuellement fournies |
|
| 166 | + $set |
|
| 167 | + ); |
|
| 168 | + |
|
| 169 | + if ( |
|
| 170 | + $err = objet_modifier_champs( |
|
| 171 | + 'rubrique', |
|
| 172 | + $id_rubrique, |
|
| 173 | + [ |
|
| 174 | + 'data' => $set, |
|
| 175 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 176 | + ], |
|
| 177 | + $c |
|
| 178 | + ) |
|
| 179 | + ) { |
|
| 180 | + return $err; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 184 | + // Deplacer la rubrique |
|
| 185 | + if (isset($c['id_parent'])) { |
|
| 186 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // invalider les caches marques de cette rubrique |
|
| 190 | + include_spip('inc/invalideur'); |
|
| 191 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 192 | + // et celui de menu_rubriques |
|
| 193 | + effacer_meta('date_calcul_rubriques'); |
|
| 194 | + |
|
| 195 | + return $err; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -215,29 +215,29 @@ discard block |
||
| 215 | 215 | * false si la confirmation du déplacement n'est pas présente |
| 216 | 216 | */ |
| 217 | 217 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) { |
| 218 | - if (!sql_table_exists('spip_breves')) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 223 | - return true; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ( |
|
| 231 | - $id_secteur = sql_getfetsel( |
|
| 232 | - 'id_secteur', |
|
| 233 | - 'spip_rubriques', |
|
| 234 | - "id_rubrique=$id_parent" |
|
| 235 | - ) |
|
| 236 | - ) { |
|
| 237 | - sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return true; |
|
| 218 | + if (!sql_table_exists('spip_breves')) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ( |
|
| 231 | + $id_secteur = sql_getfetsel( |
|
| 232 | + 'id_secteur', |
|
| 233 | + 'spip_rubriques', |
|
| 234 | + "id_rubrique=$id_parent" |
|
| 235 | + ) |
|
| 236 | + ) { |
|
| 237 | + sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return true; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | |
@@ -259,72 +259,72 @@ discard block |
||
| 259 | 259 | * Chaîne : texte du message d'erreur |
| 260 | 260 | */ |
| 261 | 261 | function rubrique_instituer($id_rubrique, $c) { |
| 262 | - // traitement de la rubrique parente |
|
| 263 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 264 | - // qu'on n'administre pas. |
|
| 265 | - |
|
| 266 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 267 | - $id_parent = intval($id_parent); |
|
| 268 | - $filles = calcul_branche_in($id_rubrique); |
|
| 269 | - if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 270 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 271 | - } else { |
|
| 272 | - $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 273 | - $old_parent = $s['id_parent']; |
|
| 274 | - |
|
| 275 | - if ( |
|
| 276 | - !($id_parent != $old_parent |
|
| 277 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 278 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 279 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 280 | - ) |
|
| 281 | - ) { |
|
| 282 | - if ($s['statut'] != 'prepa') { |
|
| 283 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 284 | - } |
|
| 285 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 286 | - $statut_ancien = $s['statut']; |
|
| 287 | - sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - propager_les_secteurs(); |
|
| 291 | - |
|
| 292 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 293 | - if ($statut_ancien == 'publie') { |
|
| 294 | - calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 295 | - } |
|
| 296 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 297 | - // invalider le cache de leur menu |
|
| 298 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 299 | - effacer_meta('date_calcul_rubriques'); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - calculer_langues_rubriques(); |
|
| 262 | + // traitement de la rubrique parente |
|
| 263 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 264 | + // qu'on n'administre pas. |
|
| 265 | + |
|
| 266 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 267 | + $id_parent = intval($id_parent); |
|
| 268 | + $filles = calcul_branche_in($id_rubrique); |
|
| 269 | + if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 270 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 271 | + } else { |
|
| 272 | + $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 273 | + $old_parent = $s['id_parent']; |
|
| 274 | + |
|
| 275 | + if ( |
|
| 276 | + !($id_parent != $old_parent |
|
| 277 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 278 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 279 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 280 | + ) |
|
| 281 | + ) { |
|
| 282 | + if ($s['statut'] != 'prepa') { |
|
| 283 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 284 | + } |
|
| 285 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 286 | + $statut_ancien = $s['statut']; |
|
| 287 | + sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + propager_les_secteurs(); |
|
| 291 | + |
|
| 292 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 293 | + if ($statut_ancien == 'publie') { |
|
| 294 | + calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 295 | + } |
|
| 296 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 297 | + // invalider le cache de leur menu |
|
| 298 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 299 | + effacer_meta('date_calcul_rubriques'); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + calculer_langues_rubriques(); |
|
| 303 | 303 | |
| 304 | - // Appeler une notification |
|
| 305 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 306 | - $notifications( |
|
| 307 | - 'rubrique_instituer', |
|
| 308 | - $id_rubrique, |
|
| 309 | - [ |
|
| 310 | - 'statut_ancien' => $statut_ancien, |
|
| 311 | - 'id_parent_ancien' => $old_parent, |
|
| 312 | - ] |
|
| 313 | - ); |
|
| 314 | - $notifications( |
|
| 315 | - 'objet_instituer', |
|
| 316 | - $id_rubrique, |
|
| 317 | - [ |
|
| 318 | - 'objet' => 'rubrique', |
|
| 319 | - 'id_objet' => $id_rubrique, |
|
| 320 | - 'statut_ancien' => $statut_ancien, |
|
| 321 | - 'id_parent_ancien' => $old_parent, |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return ''; // pas d'erreur |
|
| 304 | + // Appeler une notification |
|
| 305 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 306 | + $notifications( |
|
| 307 | + 'rubrique_instituer', |
|
| 308 | + $id_rubrique, |
|
| 309 | + [ |
|
| 310 | + 'statut_ancien' => $statut_ancien, |
|
| 311 | + 'id_parent_ancien' => $old_parent, |
|
| 312 | + ] |
|
| 313 | + ); |
|
| 314 | + $notifications( |
|
| 315 | + 'objet_instituer', |
|
| 316 | + $id_rubrique, |
|
| 317 | + [ |
|
| 318 | + 'objet' => 'rubrique', |
|
| 319 | + 'id_objet' => $id_rubrique, |
|
| 320 | + 'statut_ancien' => $statut_ancien, |
|
| 321 | + 'id_parent_ancien' => $old_parent, |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return ''; // pas d'erreur |
|
| 330 | 330 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | function extraire_date($texte): string { |
| 40 | 40 | // format = 2001-08 |
| 41 | 41 | if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01'; |
|
| 43 | 43 | } |
| 44 | 44 | return ''; |
| 45 | 45 | } |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 72 | 72 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | + $date = $regs[1].'-00-00'.$regs[3]; |
|
| 74 | 74 | } else { |
| 75 | 75 | if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 76 | 76 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3]; |
|
| 78 | 78 | } else { |
| 79 | 79 | $date = date('Y-m-d H:i:s', strtotime($date)); |
| 80 | 80 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $letexte ??= ''; |
| 102 | 102 | if ( |
| 103 | 103 | !$verif_format_date |
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | + or (in_array(strlen($letexte), [10, 19]) and |
|
| 105 | 105 | preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
| 106 | 106 | ) { |
| 107 | 107 | if (strncmp('0000-00-00', $letexte, 10) == 0) { |
@@ -388,17 +388,17 @@ discard block |
||
| 388 | 388 | if ($decal > 3600 * 24 * 30) { |
| 389 | 389 | $mois = floor($decal / (3600 * 24 * 30)); |
| 390 | 390 | if ($mois < 2) { |
| 391 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 391 | + $delai = "$mois "._T('date_un_mois'); |
|
| 392 | 392 | } else { |
| 393 | - $delai = "$mois " . _T('date_mois'); |
|
| 393 | + $delai = "$mois "._T('date_mois'); |
|
| 394 | 394 | } |
| 395 | 395 | } else { |
| 396 | 396 | if ($decal > 3600 * 24 * 7) { |
| 397 | 397 | $semaines = floor($decal / (3600 * 24 * 7)); |
| 398 | 398 | if ($semaines < 2) { |
| 399 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 399 | + $delai = "$semaines "._T('date_une_semaine'); |
|
| 400 | 400 | } else { |
| 401 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 401 | + $delai = "$semaines "._T('date_semaines'); |
|
| 402 | 402 | } |
| 403 | 403 | } else { |
| 404 | 404 | if ($decal > 3600 * 24) { |
@@ -406,30 +406,30 @@ discard block |
||
| 406 | 406 | if ($jours < 2) { |
| 407 | 407 | return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
| 408 | 408 | } else { |
| 409 | - $delai = "$jours " . _T('date_jours'); |
|
| 409 | + $delai = "$jours "._T('date_jours'); |
|
| 410 | 410 | } |
| 411 | 411 | } else { |
| 412 | 412 | if ($decal >= 3600) { |
| 413 | 413 | $heures = floor($decal / 3600); |
| 414 | 414 | if ($heures < 2) { |
| 415 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 415 | + $delai = "$heures "._T('date_une_heure'); |
|
| 416 | 416 | } else { |
| 417 | - $delai = "$heures " . _T('date_heures'); |
|
| 417 | + $delai = "$heures "._T('date_heures'); |
|
| 418 | 418 | } |
| 419 | 419 | } else { |
| 420 | 420 | if ($decal >= 60) { |
| 421 | 421 | $minutes = floor($decal / 60); |
| 422 | 422 | if ($minutes < 2) { |
| 423 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 423 | + $delai = "$minutes "._T('date_une_minute'); |
|
| 424 | 424 | } else { |
| 425 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 425 | + $delai = "$minutes "._T('date_minutes'); |
|
| 426 | 426 | } |
| 427 | 427 | } else { |
| 428 | 428 | $secondes = ceil($decal); |
| 429 | 429 | if ($secondes < 2) { |
| 430 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 430 | + $delai = "$secondes "._T('date_une_seconde'); |
|
| 431 | 431 | } else { |
| 432 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 432 | + $delai = "$secondes "._T('date_secondes'); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | $njour = 0; |
| 523 | 523 | } else { |
| 524 | 524 | $njour = intval($jour); |
| 525 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 525 | + if ($jourth = _T('date_jnum'.$jour)) { |
|
| 526 | 526 | $jour = $jourth; |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -530,10 +530,10 @@ discard block |
||
| 530 | 530 | $mois = intval($mois); |
| 531 | 531 | if ($mois > 0 and $mois < 13) { |
| 532 | 532 | /* Traiter le cas "abbr" pour les noms de mois */ |
| 533 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 534 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : ''); |
|
| 534 | + $nommois = _T('date_mois_'.$mois.$param); |
|
| 535 | 535 | if ($jour) { |
| 536 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 536 | + $jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 537 | 537 | } else { |
| 538 | 538 | $jourmois = $nommois; |
| 539 | 539 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | if ($annee < 0) { |
| 546 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 546 | + $annee = -$annee.' '._T('date_avant_jc'); |
|
| 547 | 547 | $avjc = true; |
| 548 | 548 | } else { |
| 549 | 549 | $avjc = false; |
@@ -569,11 +569,11 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | if ($vue == 'saison') { |
| 572 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 572 | + return $saison ? _T('date_saison_'.$saison) : ''; |
|
| 573 | 573 | } else { |
| 574 | 574 | return $saison ? trim(_T( |
| 575 | 575 | 'date_fmt_saison_annee', |
| 576 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 576 | + ['saison' => _T('date_saison_'.$saison), 'annee' => $annee] |
|
| 577 | 577 | )) : ''; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | } |
| 651 | 651 | $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
| 652 | 652 | $nom = 1 + (int) date('w', $nom); |
| 653 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 653 | + $param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : ''); |
|
| 654 | 654 | |
| 655 | - return _T('date_jour_' . $nom . $param); |
|
| 655 | + return _T('date_jour_'.$nom.$param); |
|
| 656 | 656 | |
| 657 | 657 | case 'mois_annee': |
| 658 | 658 | if ($avjc) { |
@@ -1047,8 +1047,8 @@ discard block |
||
| 1047 | 1047 | |
| 1048 | 1048 | $dtstart = $dtend = $dtabbr = ''; |
| 1049 | 1049 | if (strpos($forme, 'hcal') !== false) { |
| 1050 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1051 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | + $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
|
| 1051 | + $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
|
| 1052 | 1052 | $dtabbr = '</abbr>'; |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1096,7 +1096,7 @@ discard block |
||
| 1096 | 1096 | } |
| 1097 | 1097 | } else { |
| 1098 | 1098 | if ($dtabbr && $dtstart) { |
| 1099 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1099 | + $s = $dtstart.spip_ucfirst($s).$dtabbr; |
|
| 1100 | 1100 | } else { |
| 1101 | 1101 | $s = spip_ucfirst($s); |
| 1102 | 1102 | } |
@@ -1119,8 +1119,8 @@ discard block |
||
| 1119 | 1119 | $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
| 1120 | 1120 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1121 | 1121 | } |
| 1122 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1123 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1123 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1124 | 1124 | |
| 1125 | 1125 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1126 | 1126 | } else { |
@@ -1137,8 +1137,8 @@ discard block |
||
| 1137 | 1137 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1141 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1141 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1142 | 1142 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1143 | 1143 | } |
| 1144 | 1144 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | $d = date('Y-m-d'); |
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1245 | + return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2); |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | /** |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | $d = date('Y-m-d'); |
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1265 | + return substr($d, 0, 4).substr($d, 5, 2); |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | /** |
@@ -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 | |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 38 | 38 | **/ |
| 39 | 39 | function extraire_date($texte): string { |
| 40 | - // format = 2001-08 |
|
| 41 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | - } |
|
| 44 | - return ''; |
|
| 40 | + // format = 2001-08 |
|
| 41 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | + } |
|
| 44 | + return ''; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
@@ -63,29 +63,29 @@ discard block |
||
| 63 | 63 | * - une chaîne vide si la date est considérée nulle |
| 64 | 64 | **/ |
| 65 | 65 | function normaliser_date($date, $forcer_jour = false): string { |
| 66 | - $date = vider_date($date); |
|
| 67 | - if ($date) { |
|
| 68 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | - $date = date('Y-m-d H:i:s', $date); |
|
| 70 | - } |
|
| 71 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | - } else { |
|
| 75 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | - } else { |
|
| 79 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - if ($forcer_jour) { |
|
| 84 | - $date = str_replace('-00', '-01', $date); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $date; |
|
| 66 | + $date = vider_date($date); |
|
| 67 | + if ($date) { |
|
| 68 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | + $date = date('Y-m-d H:i:s', $date); |
|
| 70 | + } |
|
| 71 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | + } else { |
|
| 75 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | + } else { |
|
| 79 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + if ($forcer_jour) { |
|
| 84 | + $date = str_replace('-00', '-01', $date); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return $date; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -98,23 +98,23 @@ discard block |
||
| 98 | 98 | * - Une chaine vide |
| 99 | 99 | **/ |
| 100 | 100 | function vider_date($letexte, $verif_format_date = false): string { |
| 101 | - $letexte ??= ''; |
|
| 102 | - if ( |
|
| 103 | - !$verif_format_date |
|
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | - ) { |
|
| 107 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | - return ''; |
|
| 112 | - } |
|
| 113 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | - return ''; |
|
| 115 | - } // eviter le bug GMT-1 |
|
| 116 | - } |
|
| 117 | - return $letexte; |
|
| 101 | + $letexte ??= ''; |
|
| 102 | + if ( |
|
| 103 | + !$verif_format_date |
|
| 104 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | + ) { |
|
| 107 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | + return ''; |
|
| 112 | + } |
|
| 113 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | + return ''; |
|
| 115 | + } // eviter le bug GMT-1 |
|
| 116 | + } |
|
| 117 | + return $letexte; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | **/ |
| 131 | 131 | function recup_heure($date): array { |
| 132 | 132 | |
| 133 | - if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | - array_shift($elements); |
|
| 135 | - if (!isset($elements[2])) { |
|
| 136 | - $elements[2] = 0; |
|
| 137 | - } |
|
| 138 | - $heure = $elements; |
|
| 139 | - } else { |
|
| 140 | - $heure = [0, 0, 0]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $heure; |
|
| 133 | + if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | + array_shift($elements); |
|
| 135 | + if (!isset($elements[2])) { |
|
| 136 | + $elements[2] = 0; |
|
| 137 | + } |
|
| 138 | + $heure = $elements; |
|
| 139 | + } else { |
|
| 140 | + $heure = [0, 0, 0]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $heure; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | * @return string heures, sinon 0 |
| 155 | 155 | **/ |
| 156 | 156 | function heures($numdate): string { |
| 157 | - $heures = null; |
|
| 158 | - $date_array = recup_heure($numdate); |
|
| 159 | - if ($date_array) { |
|
| 160 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | - } |
|
| 157 | + $heures = null; |
|
| 158 | + $date_array = recup_heure($numdate); |
|
| 159 | + if ($date_array) { |
|
| 160 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - return $heures; |
|
| 163 | + return $heures; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | * @return string minutes, sinon 0 |
| 175 | 175 | **/ |
| 176 | 176 | function minutes($numdate): string { |
| 177 | - $minutes = null; |
|
| 178 | - $date_array = recup_heure($numdate); |
|
| 179 | - if ($date_array) { |
|
| 180 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | - } |
|
| 177 | + $minutes = null; |
|
| 178 | + $date_array = recup_heure($numdate); |
|
| 179 | + if ($date_array) { |
|
| 180 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $minutes; |
|
| 183 | + return $minutes; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | * @return string secondes, sinon 0 |
| 195 | 195 | **/ |
| 196 | 196 | function secondes($numdate): string { |
| 197 | - $secondes = null; |
|
| 198 | - $date_array = recup_heure($numdate); |
|
| 199 | - if ($date_array) { |
|
| 200 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | - } |
|
| 197 | + $secondes = null; |
|
| 198 | + $date_array = recup_heure($numdate); |
|
| 199 | + if ($date_array) { |
|
| 200 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $secondes; |
|
| 203 | + return $secondes; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | * @return string L'heure formatée dans la langue en cours. |
| 220 | 220 | **/ |
| 221 | 221 | function heures_minutes($numdate, $forme = ''): string { |
| 222 | - if ($forme !== 'abbr') { |
|
| 223 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | - } else { |
|
| 225 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | - } |
|
| 222 | + if ($forme !== 'abbr') { |
|
| 223 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | + } else { |
|
| 225 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | + } |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -248,57 +248,57 @@ discard block |
||
| 248 | 248 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 249 | 249 | **/ |
| 250 | 250 | function recup_date($numdate, $forcer_jour = true): array { |
| 251 | - if (!$numdate) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 254 | - $heures = $minutes = $secondes = 0; |
|
| 255 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | - $jour = $regs[1]; |
|
| 257 | - $mois = $regs[2]; |
|
| 258 | - $annee = $regs[3]; |
|
| 259 | - if ($annee < 90) { |
|
| 260 | - $annee = 2000 + $annee; |
|
| 261 | - } elseif ($annee < 100) { |
|
| 262 | - $annee = 1900 + $annee; |
|
| 263 | - } |
|
| 264 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | - $annee = $regs[1]; |
|
| 267 | - $mois = $regs[2]; |
|
| 268 | - $jour = $regs[3]; |
|
| 269 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | - $annee = $regs[1]; |
|
| 272 | - $mois = $regs[2]; |
|
| 273 | - $jour = ''; |
|
| 274 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | - $annee = $regs[1]; |
|
| 277 | - $mois = $regs[2]; |
|
| 278 | - $jour = $regs[3]; |
|
| 279 | - $heures = $regs[4]; |
|
| 280 | - $minutes = $regs[5]; |
|
| 281 | - $secondes = $regs[6]; |
|
| 282 | - } else { |
|
| 283 | - $annee = $mois = $jour = ''; |
|
| 284 | - } |
|
| 285 | - if ($annee > 4000) { |
|
| 286 | - $annee -= 9000; |
|
| 287 | - } |
|
| 288 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | - $jour = substr($jour, 1); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($forcer_jour and $jour == '0') { |
|
| 293 | - $jour = '1'; |
|
| 294 | - } |
|
| 295 | - if ($forcer_jour and $mois == '0') { |
|
| 296 | - $mois = '1'; |
|
| 297 | - } |
|
| 298 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | - } |
|
| 301 | - return []; |
|
| 251 | + if (!$numdate) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | + $heures = $minutes = $secondes = 0; |
|
| 255 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | + $jour = $regs[1]; |
|
| 257 | + $mois = $regs[2]; |
|
| 258 | + $annee = $regs[3]; |
|
| 259 | + if ($annee < 90) { |
|
| 260 | + $annee = 2000 + $annee; |
|
| 261 | + } elseif ($annee < 100) { |
|
| 262 | + $annee = 1900 + $annee; |
|
| 263 | + } |
|
| 264 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | + $annee = $regs[1]; |
|
| 267 | + $mois = $regs[2]; |
|
| 268 | + $jour = $regs[3]; |
|
| 269 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | + $annee = $regs[1]; |
|
| 272 | + $mois = $regs[2]; |
|
| 273 | + $jour = ''; |
|
| 274 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | + $annee = $regs[1]; |
|
| 277 | + $mois = $regs[2]; |
|
| 278 | + $jour = $regs[3]; |
|
| 279 | + $heures = $regs[4]; |
|
| 280 | + $minutes = $regs[5]; |
|
| 281 | + $secondes = $regs[6]; |
|
| 282 | + } else { |
|
| 283 | + $annee = $mois = $jour = ''; |
|
| 284 | + } |
|
| 285 | + if ($annee > 4000) { |
|
| 286 | + $annee -= 9000; |
|
| 287 | + } |
|
| 288 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | + $jour = substr($jour, 1); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($forcer_jour and $jour == '0') { |
|
| 293 | + $jour = '1'; |
|
| 294 | + } |
|
| 295 | + if ($forcer_jour and $mois == '0') { |
|
| 296 | + $mois = '1'; |
|
| 297 | + } |
|
| 298 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | + } |
|
| 301 | + return []; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | * La date relative ou complète |
| 326 | 326 | **/ |
| 327 | 327 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 328 | - return sinon( |
|
| 329 | - date_relative($date, $decalage_maxi), |
|
| 330 | - affdate_heure($date) |
|
| 331 | - ); |
|
| 328 | + return sinon( |
|
| 329 | + date_relative($date, $decalage_maxi), |
|
| 330 | + affdate_heure($date) |
|
| 331 | + ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -361,86 +361,86 @@ discard block |
||
| 361 | 361 | **/ |
| 362 | 362 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 363 | 363 | |
| 364 | - if (!$date) { |
|
| 365 | - return ''; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - if (is_null($ref_date)) { |
|
| 369 | - $ref_time = time(); |
|
| 370 | - } else { |
|
| 371 | - $ref_time = strtotime($ref_date); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | - |
|
| 376 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | - return ''; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($decal < 0) { |
|
| 381 | - $il_y_a = 'date_dans'; |
|
| 382 | - $decal = -1 * $decal; |
|
| 383 | - } else { |
|
| 384 | - $il_y_a = 'date_il_y_a'; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | - return affdate_court($date); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if ($decal > 3600 * 24 * 30) { |
|
| 392 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | - if ($mois < 2) { |
|
| 394 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | - } else { |
|
| 396 | - $delai = "$mois " . _T('date_mois'); |
|
| 397 | - } |
|
| 398 | - } else { |
|
| 399 | - if ($decal > 3600 * 24 * 7) { |
|
| 400 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | - if ($semaines < 2) { |
|
| 402 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | - } else { |
|
| 404 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | - } |
|
| 406 | - } else { |
|
| 407 | - if ($decal > 3600 * 24) { |
|
| 408 | - $jours = floor($decal / (3600 * 24)); |
|
| 409 | - if ($jours < 2) { |
|
| 410 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | - } else { |
|
| 412 | - $delai = "$jours " . _T('date_jours'); |
|
| 413 | - } |
|
| 414 | - } else { |
|
| 415 | - if ($decal >= 3600) { |
|
| 416 | - $heures = floor($decal / 3600); |
|
| 417 | - if ($heures < 2) { |
|
| 418 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | - } else { |
|
| 420 | - $delai = "$heures " . _T('date_heures'); |
|
| 421 | - } |
|
| 422 | - } else { |
|
| 423 | - if ($decal >= 60) { |
|
| 424 | - $minutes = floor($decal / 60); |
|
| 425 | - if ($minutes < 2) { |
|
| 426 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | - } else { |
|
| 428 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | - } |
|
| 430 | - } else { |
|
| 431 | - $secondes = ceil($decal); |
|
| 432 | - if ($secondes < 2) { |
|
| 433 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | - } else { |
|
| 435 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 364 | + if (!$date) { |
|
| 365 | + return ''; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + if (is_null($ref_date)) { |
|
| 369 | + $ref_time = time(); |
|
| 370 | + } else { |
|
| 371 | + $ref_time = strtotime($ref_date); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | + |
|
| 376 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | + return ''; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($decal < 0) { |
|
| 381 | + $il_y_a = 'date_dans'; |
|
| 382 | + $decal = -1 * $decal; |
|
| 383 | + } else { |
|
| 384 | + $il_y_a = 'date_il_y_a'; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | + return affdate_court($date); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if ($decal > 3600 * 24 * 30) { |
|
| 392 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | + if ($mois < 2) { |
|
| 394 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | + } else { |
|
| 396 | + $delai = "$mois " . _T('date_mois'); |
|
| 397 | + } |
|
| 398 | + } else { |
|
| 399 | + if ($decal > 3600 * 24 * 7) { |
|
| 400 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | + if ($semaines < 2) { |
|
| 402 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | + } else { |
|
| 404 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | + } |
|
| 406 | + } else { |
|
| 407 | + if ($decal > 3600 * 24) { |
|
| 408 | + $jours = floor($decal / (3600 * 24)); |
|
| 409 | + if ($jours < 2) { |
|
| 410 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | + } else { |
|
| 412 | + $delai = "$jours " . _T('date_jours'); |
|
| 413 | + } |
|
| 414 | + } else { |
|
| 415 | + if ($decal >= 3600) { |
|
| 416 | + $heures = floor($decal / 3600); |
|
| 417 | + if ($heures < 2) { |
|
| 418 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | + } else { |
|
| 420 | + $delai = "$heures " . _T('date_heures'); |
|
| 421 | + } |
|
| 422 | + } else { |
|
| 423 | + if ($decal >= 60) { |
|
| 424 | + $minutes = floor($decal / 60); |
|
| 425 | + if ($minutes < 2) { |
|
| 426 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | + } else { |
|
| 428 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | + } |
|
| 430 | + } else { |
|
| 431 | + $secondes = ceil($decal); |
|
| 432 | + if ($secondes < 2) { |
|
| 433 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | + } else { |
|
| 435 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -466,32 +466,32 @@ discard block |
||
| 466 | 466 | **/ |
| 467 | 467 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 468 | 468 | |
| 469 | - if (!$date) { |
|
| 470 | - return ''; |
|
| 471 | - } |
|
| 472 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | - |
|
| 474 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if ($decal < -24 * 3600) { |
|
| 479 | - $retour = date_relative($date, $decalage_maxi); |
|
| 480 | - } elseif ($decal < 0) { |
|
| 481 | - $retour = _T('date_demain'); |
|
| 482 | - } else { |
|
| 483 | - if ($decal < (3600 * 24)) { |
|
| 484 | - $retour = _T('date_aujourdhui'); |
|
| 485 | - } else { |
|
| 486 | - if ($decal < (3600 * 24 * 2)) { |
|
| 487 | - $retour = _T('date_hier'); |
|
| 488 | - } else { |
|
| 489 | - $retour = date_relative($date, $decalage_maxi); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $retour; |
|
| 469 | + if (!$date) { |
|
| 470 | + return ''; |
|
| 471 | + } |
|
| 472 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | + |
|
| 474 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($decal < -24 * 3600) { |
|
| 479 | + $retour = date_relative($date, $decalage_maxi); |
|
| 480 | + } elseif ($decal < 0) { |
|
| 481 | + $retour = _T('date_demain'); |
|
| 482 | + } else { |
|
| 483 | + if ($decal < (3600 * 24)) { |
|
| 484 | + $retour = _T('date_aujourdhui'); |
|
| 485 | + } else { |
|
| 486 | + if ($decal < (3600 * 24 * 2)) { |
|
| 487 | + $retour = _T('date_hier'); |
|
| 488 | + } else { |
|
| 489 | + $retour = date_relative($date, $decalage_maxi); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $retour; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -508,174 +508,174 @@ discard block |
||
| 508 | 508 | * @return string |
| 509 | 509 | */ |
| 510 | 510 | function affdate_base($numdate, $vue, $options = []): string { |
| 511 | - if (is_string($options)) { |
|
| 512 | - $options = ['param' => $options]; |
|
| 513 | - } |
|
| 514 | - $date_array = recup_date($numdate, false); |
|
| 515 | - if (!$date_array) { |
|
| 516 | - return ''; |
|
| 517 | - } |
|
| 518 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | - |
|
| 520 | - // 1er, 21st, etc. |
|
| 521 | - $journum = $jour; |
|
| 522 | - |
|
| 523 | - if ($jour == 0) { |
|
| 524 | - $jour = ''; |
|
| 525 | - $njour = 0; |
|
| 526 | - } else { |
|
| 527 | - $njour = intval($jour); |
|
| 528 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | - $jour = $jourth; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $mois = intval($mois); |
|
| 534 | - if ($mois > 0 and $mois < 13) { |
|
| 535 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | - if ($jour) { |
|
| 539 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | - } else { |
|
| 541 | - $jourmois = $nommois; |
|
| 542 | - } |
|
| 543 | - } else { |
|
| 544 | - $nommois = ''; |
|
| 545 | - $jourmois = ''; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($annee < 0) { |
|
| 549 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | - $avjc = true; |
|
| 551 | - } else { |
|
| 552 | - $avjc = false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - switch ($vue) { |
|
| 556 | - case 'saison': |
|
| 557 | - case 'saison_annee': |
|
| 558 | - $saison = ''; |
|
| 559 | - if ($mois > 0) { |
|
| 560 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | - } |
|
| 564 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | - } |
|
| 567 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | - } |
|
| 570 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - if ($vue == 'saison') { |
|
| 575 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | - } else { |
|
| 577 | - return $saison ? trim(_T( |
|
| 578 | - 'date_fmt_saison_annee', |
|
| 579 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | - )) : ''; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - case 'court': |
|
| 584 | - if ($avjc) { |
|
| 585 | - return $annee; |
|
| 586 | - } |
|
| 587 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | - return $annee; |
|
| 590 | - } |
|
| 591 | - if ($annee != $a) { |
|
| 592 | - return _T( |
|
| 593 | - 'date_fmt_mois_annee', |
|
| 594 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return _T( |
|
| 599 | - 'date_fmt_jour_mois', |
|
| 600 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | - ); |
|
| 602 | - |
|
| 603 | - case 'jourcourt': |
|
| 604 | - if ($avjc) { |
|
| 605 | - return $annee; |
|
| 606 | - } |
|
| 607 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | - return $annee; |
|
| 610 | - } |
|
| 611 | - if ($annee != $a) { |
|
| 612 | - return _T( |
|
| 613 | - 'date_fmt_jour_mois_annee', |
|
| 614 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - return _T( |
|
| 619 | - 'date_fmt_jour_mois', |
|
| 620 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - case 'entier': |
|
| 624 | - if ($avjc) { |
|
| 625 | - return $annee; |
|
| 626 | - } |
|
| 627 | - if ($jour) { |
|
| 628 | - return _T( |
|
| 629 | - 'date_fmt_jour_mois_annee', |
|
| 630 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | - ); |
|
| 632 | - } elseif ($mois) { |
|
| 633 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | - } else { |
|
| 635 | - return $annee; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - case 'nom_mois': |
|
| 639 | - return $nommois; |
|
| 640 | - |
|
| 641 | - case 'mois': |
|
| 642 | - return sprintf('%02s', $mois); |
|
| 643 | - |
|
| 644 | - case 'jour': |
|
| 645 | - return $jour; |
|
| 646 | - |
|
| 647 | - case 'journum': |
|
| 648 | - return $journum; |
|
| 649 | - |
|
| 650 | - case 'nom_jour': |
|
| 651 | - if (!$mois or !$njour) { |
|
| 652 | - return ''; |
|
| 653 | - } |
|
| 654 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | - $nom = 1 + (int) date('w', $nom); |
|
| 656 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | - |
|
| 658 | - return _T('date_jour_' . $nom . $param); |
|
| 659 | - |
|
| 660 | - case 'mois_annee': |
|
| 661 | - if ($avjc) { |
|
| 662 | - return $annee; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | - |
|
| 667 | - case 'annee': |
|
| 668 | - return $annee; |
|
| 669 | - |
|
| 670 | - // Cas d'une vue non definie : retomber sur le format |
|
| 671 | - // de date propose par http://www.php.net/date |
|
| 672 | - default: |
|
| 673 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | - $time = strtotime($numdate); |
|
| 676 | - } |
|
| 677 | - return date($vue, $time); |
|
| 678 | - } |
|
| 511 | + if (is_string($options)) { |
|
| 512 | + $options = ['param' => $options]; |
|
| 513 | + } |
|
| 514 | + $date_array = recup_date($numdate, false); |
|
| 515 | + if (!$date_array) { |
|
| 516 | + return ''; |
|
| 517 | + } |
|
| 518 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | + |
|
| 520 | + // 1er, 21st, etc. |
|
| 521 | + $journum = $jour; |
|
| 522 | + |
|
| 523 | + if ($jour == 0) { |
|
| 524 | + $jour = ''; |
|
| 525 | + $njour = 0; |
|
| 526 | + } else { |
|
| 527 | + $njour = intval($jour); |
|
| 528 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | + $jour = $jourth; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $mois = intval($mois); |
|
| 534 | + if ($mois > 0 and $mois < 13) { |
|
| 535 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | + if ($jour) { |
|
| 539 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | + } else { |
|
| 541 | + $jourmois = $nommois; |
|
| 542 | + } |
|
| 543 | + } else { |
|
| 544 | + $nommois = ''; |
|
| 545 | + $jourmois = ''; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ($annee < 0) { |
|
| 549 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | + $avjc = true; |
|
| 551 | + } else { |
|
| 552 | + $avjc = false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + switch ($vue) { |
|
| 556 | + case 'saison': |
|
| 557 | + case 'saison_annee': |
|
| 558 | + $saison = ''; |
|
| 559 | + if ($mois > 0) { |
|
| 560 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | + } |
|
| 564 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | + } |
|
| 567 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | + } |
|
| 570 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + if ($vue == 'saison') { |
|
| 575 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | + } else { |
|
| 577 | + return $saison ? trim(_T( |
|
| 578 | + 'date_fmt_saison_annee', |
|
| 579 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | + )) : ''; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + case 'court': |
|
| 584 | + if ($avjc) { |
|
| 585 | + return $annee; |
|
| 586 | + } |
|
| 587 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | + return $annee; |
|
| 590 | + } |
|
| 591 | + if ($annee != $a) { |
|
| 592 | + return _T( |
|
| 593 | + 'date_fmt_mois_annee', |
|
| 594 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return _T( |
|
| 599 | + 'date_fmt_jour_mois', |
|
| 600 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | + ); |
|
| 602 | + |
|
| 603 | + case 'jourcourt': |
|
| 604 | + if ($avjc) { |
|
| 605 | + return $annee; |
|
| 606 | + } |
|
| 607 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | + return $annee; |
|
| 610 | + } |
|
| 611 | + if ($annee != $a) { |
|
| 612 | + return _T( |
|
| 613 | + 'date_fmt_jour_mois_annee', |
|
| 614 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + return _T( |
|
| 619 | + 'date_fmt_jour_mois', |
|
| 620 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + case 'entier': |
|
| 624 | + if ($avjc) { |
|
| 625 | + return $annee; |
|
| 626 | + } |
|
| 627 | + if ($jour) { |
|
| 628 | + return _T( |
|
| 629 | + 'date_fmt_jour_mois_annee', |
|
| 630 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | + ); |
|
| 632 | + } elseif ($mois) { |
|
| 633 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | + } else { |
|
| 635 | + return $annee; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + case 'nom_mois': |
|
| 639 | + return $nommois; |
|
| 640 | + |
|
| 641 | + case 'mois': |
|
| 642 | + return sprintf('%02s', $mois); |
|
| 643 | + |
|
| 644 | + case 'jour': |
|
| 645 | + return $jour; |
|
| 646 | + |
|
| 647 | + case 'journum': |
|
| 648 | + return $journum; |
|
| 649 | + |
|
| 650 | + case 'nom_jour': |
|
| 651 | + if (!$mois or !$njour) { |
|
| 652 | + return ''; |
|
| 653 | + } |
|
| 654 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | + $nom = 1 + (int) date('w', $nom); |
|
| 656 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | + |
|
| 658 | + return _T('date_jour_' . $nom . $param); |
|
| 659 | + |
|
| 660 | + case 'mois_annee': |
|
| 661 | + if ($avjc) { |
|
| 662 | + return $annee; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | + |
|
| 667 | + case 'annee': |
|
| 668 | + return $annee; |
|
| 669 | + |
|
| 670 | + // Cas d'une vue non definie : retomber sur le format |
|
| 671 | + // de date propose par http://www.php.net/date |
|
| 672 | + default: |
|
| 673 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | + $time = strtotime($numdate); |
|
| 676 | + } |
|
| 677 | + return date($vue, $time); |
|
| 678 | + } |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | * Nom du jour |
| 703 | 703 | **/ |
| 704 | 704 | function nom_jour($numdate, $forme = ''): string { |
| 705 | - if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | - $forme = ''; |
|
| 707 | - } |
|
| 705 | + if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | + $forme = ''; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 709 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * Numéro du jour |
| 729 | 729 | **/ |
| 730 | 730 | function jour($numdate): string { |
| 731 | - return affdate_base($numdate, 'jour'); |
|
| 731 | + return affdate_base($numdate, 'jour'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | * Numéro du jour |
| 747 | 747 | **/ |
| 748 | 748 | function journum($numdate): string { |
| 749 | - return affdate_base($numdate, 'journum'); |
|
| 749 | + return affdate_base($numdate, 'journum'); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | * Numéro du mois (sur 2 chiffres) |
| 765 | 765 | **/ |
| 766 | 766 | function mois($numdate): string { |
| 767 | - return affdate_base($numdate, 'mois'); |
|
| 767 | + return affdate_base($numdate, 'mois'); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * Nom du mois |
| 789 | 789 | **/ |
| 790 | 790 | function nom_mois($numdate, $forme = ''): string { |
| 791 | - if (!($forme === 'abbr')) { |
|
| 792 | - $forme = ''; |
|
| 793 | - } |
|
| 791 | + if (!($forme === 'abbr')) { |
|
| 792 | + $forme = ''; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 795 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * Année (sur 4 chiffres) |
| 811 | 811 | **/ |
| 812 | 812 | function annee($numdate): string { |
| 813 | - return affdate_base($numdate, 'annee'); |
|
| 813 | + return affdate_base($numdate, 'annee'); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -840,11 +840,11 @@ discard block |
||
| 840 | 840 | * La date formatée |
| 841 | 841 | **/ |
| 842 | 842 | function saison($numdate, $hemisphere = 'nord'): string { |
| 843 | - if ($hemisphere !== 'sud') { |
|
| 844 | - $hemisphere = 'nord'; |
|
| 845 | - } |
|
| 843 | + if ($hemisphere !== 'sud') { |
|
| 844 | + $hemisphere = 'nord'; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 847 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -873,11 +873,11 @@ discard block |
||
| 873 | 873 | * La date formatée |
| 874 | 874 | **/ |
| 875 | 875 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 876 | - if ($hemisphere !== 'sud') { |
|
| 877 | - $hemisphere = 'nord'; |
|
| 878 | - } |
|
| 876 | + if ($hemisphere !== 'sud') { |
|
| 877 | + $hemisphere = 'nord'; |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 880 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | /** |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | * La date formatée |
| 906 | 906 | **/ |
| 907 | 907 | function affdate($numdate, $format = 'entier'): string { |
| 908 | - return affdate_base($numdate, $format); |
|
| 908 | + return affdate_base($numdate, $format); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | * La date formatée |
| 933 | 933 | **/ |
| 934 | 934 | function affdate_court($numdate, $annee_courante = null): string { |
| 935 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 935 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * La date formatée |
| 960 | 960 | **/ |
| 961 | 961 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 962 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 962 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * La date formatée |
| 978 | 978 | **/ |
| 979 | 979 | function affdate_mois_annee($numdate): string { |
| 980 | - return affdate_base($numdate, 'mois_annee'); |
|
| 980 | + return affdate_base($numdate, 'mois_annee'); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -995,16 +995,16 @@ discard block |
||
| 995 | 995 | * La date formatée, sinon '' |
| 996 | 996 | **/ |
| 997 | 997 | function affdate_heure($numdate): string { |
| 998 | - $date_array = recup_date($numdate); |
|
| 999 | - if (!$date_array) { |
|
| 1000 | - return ''; |
|
| 1001 | - } |
|
| 1002 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | - |
|
| 1004 | - return _T('date_fmt_jour_heure', [ |
|
| 1005 | - 'jour' => affdate($numdate), |
|
| 1006 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | - ]); |
|
| 998 | + $date_array = recup_date($numdate); |
|
| 999 | + if (!$date_array) { |
|
| 1000 | + return ''; |
|
| 1001 | + } |
|
| 1002 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | + |
|
| 1004 | + return _T('date_fmt_jour_heure', [ |
|
| 1005 | + 'jour' => affdate($numdate), |
|
| 1006 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | + ]); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1036,117 +1036,117 @@ discard block |
||
| 1036 | 1036 | * texte de la date |
| 1037 | 1037 | */ |
| 1038 | 1038 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1039 | - $abbr = $jour = ''; |
|
| 1040 | - $affdate = 'affdate_jourcourt'; |
|
| 1041 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | - $abbr = 'abbr'; |
|
| 1043 | - } |
|
| 1044 | - if (strpos($forme, 'annee') !== false) { |
|
| 1045 | - $affdate = 'affdate'; |
|
| 1046 | - } |
|
| 1047 | - if (strpos($forme, 'jour') !== false) { |
|
| 1048 | - $jour = 'jour'; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | - $dtabbr = '</abbr>'; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - $date_debut = strtotime($date_debut); |
|
| 1059 | - $date_fin = strtotime($date_fin); |
|
| 1060 | - $d = date('Y-m-d', $date_debut); |
|
| 1061 | - $f = date('Y-m-d', $date_fin); |
|
| 1062 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | - |
|
| 1066 | - if ($d == $f) { // meme jour |
|
| 1067 | - $nomjour = nom_jour($d, $abbr); |
|
| 1068 | - $s = $affdate($d); |
|
| 1069 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | - if ($h) { |
|
| 1071 | - if ($hd == $hf) { |
|
| 1072 | - // Lundi 20 fevrier a 18h25 |
|
| 1073 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | - $s = "$dtstart$s$dtabbr"; |
|
| 1075 | - } else { |
|
| 1076 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | - $s = _T( |
|
| 1079 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | - [ |
|
| 1081 | - 'jour' => spip_ucfirst($s), |
|
| 1082 | - 'heure_debut' => $hd, |
|
| 1083 | - 'heure_fin' => $hf, |
|
| 1084 | - 'dtstart' => $dtstart, |
|
| 1085 | - 'dtend' => $dtend, |
|
| 1086 | - 'dtabbr' => $dtabbr |
|
| 1087 | - ], |
|
| 1088 | - [ |
|
| 1089 | - 'sanitize' => false |
|
| 1090 | - ] |
|
| 1091 | - ); |
|
| 1092 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | - else { |
|
| 1094 | - $s = spip_ucfirst(_T( |
|
| 1095 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | - )); |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - } else { |
|
| 1101 | - if ($dtabbr && $dtstart) { |
|
| 1102 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | - } else { |
|
| 1104 | - $s = spip_ucfirst($s); |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - } else { |
|
| 1108 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | - if (!$h) { |
|
| 1110 | - $date_debut = jour($d); |
|
| 1111 | - } else { |
|
| 1112 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | - } |
|
| 1114 | - $date_fin = $affdate($f); |
|
| 1115 | - if ($jour) { |
|
| 1116 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | - } |
|
| 1121 | - if ($h) { |
|
| 1122 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | - } |
|
| 1125 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | - |
|
| 1128 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | - } else { |
|
| 1130 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | - $date_fin = $affdate($f); |
|
| 1132 | - if ($jour) { |
|
| 1133 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | - } |
|
| 1138 | - if ($h) { |
|
| 1139 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - return $s; |
|
| 1039 | + $abbr = $jour = ''; |
|
| 1040 | + $affdate = 'affdate_jourcourt'; |
|
| 1041 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | + $abbr = 'abbr'; |
|
| 1043 | + } |
|
| 1044 | + if (strpos($forme, 'annee') !== false) { |
|
| 1045 | + $affdate = 'affdate'; |
|
| 1046 | + } |
|
| 1047 | + if (strpos($forme, 'jour') !== false) { |
|
| 1048 | + $jour = 'jour'; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | + $dtabbr = '</abbr>'; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + $date_debut = strtotime($date_debut); |
|
| 1059 | + $date_fin = strtotime($date_fin); |
|
| 1060 | + $d = date('Y-m-d', $date_debut); |
|
| 1061 | + $f = date('Y-m-d', $date_fin); |
|
| 1062 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | + |
|
| 1066 | + if ($d == $f) { // meme jour |
|
| 1067 | + $nomjour = nom_jour($d, $abbr); |
|
| 1068 | + $s = $affdate($d); |
|
| 1069 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | + if ($h) { |
|
| 1071 | + if ($hd == $hf) { |
|
| 1072 | + // Lundi 20 fevrier a 18h25 |
|
| 1073 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | + $s = "$dtstart$s$dtabbr"; |
|
| 1075 | + } else { |
|
| 1076 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | + $s = _T( |
|
| 1079 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | + [ |
|
| 1081 | + 'jour' => spip_ucfirst($s), |
|
| 1082 | + 'heure_debut' => $hd, |
|
| 1083 | + 'heure_fin' => $hf, |
|
| 1084 | + 'dtstart' => $dtstart, |
|
| 1085 | + 'dtend' => $dtend, |
|
| 1086 | + 'dtabbr' => $dtabbr |
|
| 1087 | + ], |
|
| 1088 | + [ |
|
| 1089 | + 'sanitize' => false |
|
| 1090 | + ] |
|
| 1091 | + ); |
|
| 1092 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | + else { |
|
| 1094 | + $s = spip_ucfirst(_T( |
|
| 1095 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | + )); |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + } else { |
|
| 1101 | + if ($dtabbr && $dtstart) { |
|
| 1102 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | + } else { |
|
| 1104 | + $s = spip_ucfirst($s); |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + } else { |
|
| 1108 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | + if (!$h) { |
|
| 1110 | + $date_debut = jour($d); |
|
| 1111 | + } else { |
|
| 1112 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | + } |
|
| 1114 | + $date_fin = $affdate($f); |
|
| 1115 | + if ($jour) { |
|
| 1116 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | + } |
|
| 1121 | + if ($h) { |
|
| 1122 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | + } |
|
| 1125 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | + |
|
| 1128 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | + } else { |
|
| 1130 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | + $date_fin = $affdate($f); |
|
| 1132 | + if ($jour) { |
|
| 1133 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | + } |
|
| 1138 | + if ($h) { |
|
| 1139 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + return $s; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1167,10 +1167,10 @@ discard block |
||
| 1167 | 1167 | * Date au format ical |
| 1168 | 1168 | **/ |
| 1169 | 1169 | function date_ical($date, $addminutes = 0): string { |
| 1170 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1170 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1172 | 1172 | |
| 1173 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1173 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -1194,11 +1194,11 @@ discard block |
||
| 1194 | 1194 | * La date formatée |
| 1195 | 1195 | **/ |
| 1196 | 1196 | function date_iso($date_heure): string { |
| 1197 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1197 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1200 | 1200 | |
| 1201 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1201 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | /** |
@@ -1221,11 +1221,11 @@ discard block |
||
| 1221 | 1221 | * La date formatée |
| 1222 | 1222 | **/ |
| 1223 | 1223 | function date_822($date_heure): string { |
| 1224 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1224 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1227 | 1227 | |
| 1228 | - return date('r', $time); |
|
| 1228 | + return date('r', $time); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | * Date au format `Ymd` |
| 1242 | 1242 | **/ |
| 1243 | 1243 | function date_anneemoisjour($d): string { |
| 1244 | - if (!$d) { |
|
| 1245 | - $d = date('Y-m-d'); |
|
| 1246 | - } |
|
| 1244 | + if (!$d) { |
|
| 1245 | + $d = date('Y-m-d'); |
|
| 1246 | + } |
|
| 1247 | 1247 | |
| 1248 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1248 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
@@ -1261,11 +1261,11 @@ discard block |
||
| 1261 | 1261 | * Date au format `Ym` |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function date_anneemois($d): string { |
| 1264 | - if (!$d) { |
|
| 1265 | - $d = date('Y-m-d'); |
|
| 1266 | - } |
|
| 1264 | + if (!$d) { |
|
| 1265 | + $d = date('Y-m-d'); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1268 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | 1271 | /** |
@@ -1281,13 +1281,13 @@ discard block |
||
| 1281 | 1281 | * Date au lundi de la même semaine au format `Ymd` |
| 1282 | 1282 | **/ |
| 1283 | 1283 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1284 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | - if ($w_day == 0) { |
|
| 1286 | - $w_day = 7; |
|
| 1287 | - } // Gaffe: le dimanche est zero |
|
| 1288 | - $debut = $jour - $w_day + 1; |
|
| 1284 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | + if ($w_day == 0) { |
|
| 1286 | + $w_day = 7; |
|
| 1287 | + } // Gaffe: le dimanche est zero |
|
| 1288 | + $debut = $jour - $w_day + 1; |
|
| 1289 | 1289 | |
| 1290 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1290 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | /** |
@@ -1303,11 +1303,11 @@ discard block |
||
| 1303 | 1303 | * Date au dimanche de la même semaine au format `Ymd` |
| 1304 | 1304 | **/ |
| 1305 | 1305 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1306 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | - if ($w_day == 0) { |
|
| 1308 | - $w_day = 7; |
|
| 1309 | - } // Gaffe: le dimanche est zero |
|
| 1310 | - $debut = $jour - $w_day + 1; |
|
| 1306 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | + if ($w_day == 0) { |
|
| 1308 | + $w_day = 7; |
|
| 1309 | + } // Gaffe: le dimanche est zero |
|
| 1310 | + $debut = $jour - $w_day + 1; |
|
| 1311 | 1311 | |
| 1312 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1312 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1313 | 1313 | } |
@@ -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 | include_spip('inc/actions'); |
@@ -46,33 +46,33 @@ discard block |
||
| 46 | 46 | * Environnement du formulaire |
| 47 | 47 | **/ |
| 48 | 48 | function formulaires_editer_article_charger_dist( |
| 49 | - $id_article = 'new', |
|
| 50 | - $id_rubrique = 0, |
|
| 51 | - $retour = '', |
|
| 52 | - $lier_trad = 0, |
|
| 53 | - $config_fonc = 'articles_edit_config', |
|
| 54 | - $row = [], |
|
| 55 | - $hidden = '' |
|
| 49 | + $id_article = 'new', |
|
| 50 | + $id_rubrique = 0, |
|
| 51 | + $retour = '', |
|
| 52 | + $lier_trad = 0, |
|
| 53 | + $config_fonc = 'articles_edit_config', |
|
| 54 | + $row = [], |
|
| 55 | + $hidden = '' |
|
| 56 | 56 | ) { |
| 57 | - $valeurs = formulaires_editer_objet_charger( |
|
| 58 | - 'article', |
|
| 59 | - $id_article, |
|
| 60 | - $id_rubrique, |
|
| 61 | - $lier_trad, |
|
| 62 | - $retour, |
|
| 63 | - $config_fonc, |
|
| 64 | - $row, |
|
| 65 | - $hidden |
|
| 66 | - ); |
|
| 57 | + $valeurs = formulaires_editer_objet_charger( |
|
| 58 | + 'article', |
|
| 59 | + $id_article, |
|
| 60 | + $id_rubrique, |
|
| 61 | + $lier_trad, |
|
| 62 | + $retour, |
|
| 63 | + $config_fonc, |
|
| 64 | + $row, |
|
| 65 | + $hidden |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 69 | - $valeurs['editable'] = ''; |
|
| 70 | - } |
|
| 68 | + if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 69 | + $valeurs['editable'] = ''; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // il faut enlever l'id_rubrique car la saisie se fait sur id_parent |
|
| 73 | - // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale |
|
| 74 | - // et sera perdue si elle est supposee saisie |
|
| 75 | - return $valeurs; |
|
| 72 | + // il faut enlever l'id_rubrique car la saisie se fait sur id_parent |
|
| 73 | + // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale |
|
| 74 | + // et sera perdue si elle est supposee saisie |
|
| 75 | + return $valeurs; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * Hash du formulaire |
| 98 | 98 | */ |
| 99 | 99 | function formulaires_editer_article_identifier_dist( |
| 100 | - $id_article = 'new', |
|
| 101 | - $id_rubrique = 0, |
|
| 102 | - $retour = '', |
|
| 103 | - $lier_trad = 0, |
|
| 104 | - $config_fonc = 'articles_edit_config', |
|
| 105 | - $row = [], |
|
| 106 | - $hidden = '' |
|
| 100 | + $id_article = 'new', |
|
| 101 | + $id_rubrique = 0, |
|
| 102 | + $retour = '', |
|
| 103 | + $lier_trad = 0, |
|
| 104 | + $config_fonc = 'articles_edit_config', |
|
| 105 | + $row = [], |
|
| 106 | + $hidden = '' |
|
| 107 | 107 | ) { |
| 108 | - return serialize([intval($id_article), $lier_trad]); |
|
| 108 | + return serialize([intval($id_article), $lier_trad]); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function articles_edit_config(array $row): array { |
| 120 | 120 | |
| 121 | - $config = []; |
|
| 122 | - $config['lignes'] = 8; |
|
| 123 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 124 | - $config['restreint'] = ($row['statut'] === 'publie'); |
|
| 121 | + $config = []; |
|
| 122 | + $config['lignes'] = 8; |
|
| 123 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 124 | + $config['restreint'] = ($row['statut'] === 'publie'); |
|
| 125 | 125 | |
| 126 | - return $config; |
|
| 126 | + return $config; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -149,43 +149,43 @@ discard block |
||
| 149 | 149 | * Erreurs du formulaire |
| 150 | 150 | **/ |
| 151 | 151 | function formulaires_editer_article_verifier_dist( |
| 152 | - $id_article = 'new', |
|
| 153 | - $id_rubrique = 0, |
|
| 154 | - $retour = '', |
|
| 155 | - $lier_trad = 0, |
|
| 156 | - $config_fonc = 'articles_edit_config', |
|
| 157 | - $row = [], |
|
| 158 | - $hidden = '' |
|
| 152 | + $id_article = 'new', |
|
| 153 | + $id_rubrique = 0, |
|
| 154 | + $retour = '', |
|
| 155 | + $lier_trad = 0, |
|
| 156 | + $config_fonc = 'articles_edit_config', |
|
| 157 | + $row = [], |
|
| 158 | + $hidden = '' |
|
| 159 | 159 | ) { |
| 160 | - // auto-renseigner le titre si il n'existe pas |
|
| 161 | - titre_automatique('titre', ['descriptif', 'chapo', 'texte']); |
|
| 162 | - if (!_request('id_parent') and !intval($id_article)) { |
|
| 163 | - $valeurs = formulaires_editer_objet_charger( |
|
| 164 | - 'article', |
|
| 165 | - $id_article, |
|
| 166 | - $id_rubrique, |
|
| 167 | - $lier_trad, |
|
| 168 | - $retour, |
|
| 169 | - $config_fonc, |
|
| 170 | - $row, |
|
| 171 | - $hidden |
|
| 172 | - ); |
|
| 173 | - set_request('id_parent', $valeurs['id_parent']); |
|
| 174 | - } |
|
| 175 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 176 | - $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']); |
|
| 177 | - // si on utilise le formulaire dans le public |
|
| 178 | - if (!function_exists('autoriser')) { |
|
| 179 | - include_spip('inc/autoriser'); |
|
| 180 | - } |
|
| 181 | - if ( |
|
| 182 | - !isset($erreurs['id_parent']) |
|
| 183 | - and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 184 | - ) { |
|
| 185 | - $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 186 | - } |
|
| 160 | + // auto-renseigner le titre si il n'existe pas |
|
| 161 | + titre_automatique('titre', ['descriptif', 'chapo', 'texte']); |
|
| 162 | + if (!_request('id_parent') and !intval($id_article)) { |
|
| 163 | + $valeurs = formulaires_editer_objet_charger( |
|
| 164 | + 'article', |
|
| 165 | + $id_article, |
|
| 166 | + $id_rubrique, |
|
| 167 | + $lier_trad, |
|
| 168 | + $retour, |
|
| 169 | + $config_fonc, |
|
| 170 | + $row, |
|
| 171 | + $hidden |
|
| 172 | + ); |
|
| 173 | + set_request('id_parent', $valeurs['id_parent']); |
|
| 174 | + } |
|
| 175 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 176 | + $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']); |
|
| 177 | + // si on utilise le formulaire dans le public |
|
| 178 | + if (!function_exists('autoriser')) { |
|
| 179 | + include_spip('inc/autoriser'); |
|
| 180 | + } |
|
| 181 | + if ( |
|
| 182 | + !isset($erreurs['id_parent']) |
|
| 183 | + and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 184 | + ) { |
|
| 185 | + $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - return $erreurs; |
|
| 188 | + return $erreurs; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -211,29 +211,29 @@ discard block |
||
| 211 | 211 | * Retours des traitements |
| 212 | 212 | **/ |
| 213 | 213 | function formulaires_editer_article_traiter_dist( |
| 214 | - $id_article = 'new', |
|
| 215 | - $id_rubrique = 0, |
|
| 216 | - $retour = '', |
|
| 217 | - $lier_trad = 0, |
|
| 218 | - $config_fonc = 'articles_edit_config', |
|
| 219 | - $row = [], |
|
| 220 | - $hidden = '' |
|
| 214 | + $id_article = 'new', |
|
| 215 | + $id_rubrique = 0, |
|
| 216 | + $retour = '', |
|
| 217 | + $lier_trad = 0, |
|
| 218 | + $config_fonc = 'articles_edit_config', |
|
| 219 | + $row = [], |
|
| 220 | + $hidden = '' |
|
| 221 | 221 | ) { |
| 222 | - // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 223 | - // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 224 | - // en fonction de la config du site et de la rubrique choisie |
|
| 225 | - if (!$lier_trad) { |
|
| 226 | - set_request('changer_lang'); |
|
| 227 | - } |
|
| 222 | + // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 223 | + // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 224 | + // en fonction de la config du site et de la rubrique choisie |
|
| 225 | + if (!$lier_trad) { |
|
| 226 | + set_request('changer_lang'); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return formulaires_editer_objet_traiter( |
|
| 230 | - 'article', |
|
| 231 | - $id_article, |
|
| 232 | - $id_rubrique, |
|
| 233 | - $lier_trad, |
|
| 234 | - $retour, |
|
| 235 | - $config_fonc, |
|
| 236 | - $row, |
|
| 237 | - $hidden |
|
| 238 | - ); |
|
| 229 | + return formulaires_editer_objet_traiter( |
|
| 230 | + 'article', |
|
| 231 | + $id_article, |
|
| 232 | + $id_rubrique, |
|
| 233 | + $lier_trad, |
|
| 234 | + $retour, |
|
| 235 | + $config_fonc, |
|
| 236 | + $row, |
|
| 237 | + $hidden |
|
| 238 | + ); |
|
| 239 | 239 | } |
@@ -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 | include_spip('inc/actions'); |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | * Environnement du formulaire |
| 48 | 48 | **/ |
| 49 | 49 | function formulaires_editer_rubrique_charger_dist( |
| 50 | - $id_rubrique = 'new', |
|
| 51 | - $id_parent = 0, |
|
| 52 | - $retour = '', |
|
| 53 | - $lier_trad = 0, |
|
| 54 | - $config_fonc = 'rubriques_edit_config', |
|
| 55 | - $row = [], |
|
| 56 | - $hidden = '' |
|
| 50 | + $id_rubrique = 'new', |
|
| 51 | + $id_parent = 0, |
|
| 52 | + $retour = '', |
|
| 53 | + $lier_trad = 0, |
|
| 54 | + $config_fonc = 'rubriques_edit_config', |
|
| 55 | + $row = [], |
|
| 56 | + $hidden = '' |
|
| 57 | 57 | ) { |
| 58 | - $valeurs = formulaires_editer_objet_charger( |
|
| 59 | - 'rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - $id_parent, |
|
| 62 | - $lier_trad, |
|
| 63 | - $retour, |
|
| 64 | - $config_fonc, |
|
| 65 | - $row, |
|
| 66 | - $hidden |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | - $valeurs['editable'] = ''; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $valeurs; |
|
| 58 | + $valeurs = formulaires_editer_objet_charger( |
|
| 59 | + 'rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + $id_parent, |
|
| 62 | + $lier_trad, |
|
| 63 | + $retour, |
|
| 64 | + $config_fonc, |
|
| 65 | + $row, |
|
| 66 | + $hidden |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | + $valeurs['editable'] = ''; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $valeurs; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | function rubriques_edit_config(array $row): array { |
| 85 | 85 | |
| 86 | - $config = []; |
|
| 87 | - $config['lignes'] = 8; |
|
| 88 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | - $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 86 | + $config = []; |
|
| 87 | + $config['lignes'] = 8; |
|
| 88 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | + $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 90 | 90 | |
| 91 | - return $config; |
|
| 91 | + return $config; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | * Hash du formulaire |
| 114 | 114 | */ |
| 115 | 115 | function formulaires_editer_rubrique_identifier_dist( |
| 116 | - $id_rubrique = 'new', |
|
| 117 | - $id_parent = 0, |
|
| 118 | - $retour = '', |
|
| 119 | - $lier_trad = 0, |
|
| 120 | - $config_fonc = 'rubriques_edit_config', |
|
| 121 | - $row = [], |
|
| 122 | - $hidden = '' |
|
| 116 | + $id_rubrique = 'new', |
|
| 117 | + $id_parent = 0, |
|
| 118 | + $retour = '', |
|
| 119 | + $lier_trad = 0, |
|
| 120 | + $config_fonc = 'rubriques_edit_config', |
|
| 121 | + $row = [], |
|
| 122 | + $hidden = '' |
|
| 123 | 123 | ) { |
| 124 | - return serialize([intval($id_rubrique), $lier_trad]); |
|
| 124 | + return serialize([intval($id_rubrique), $lier_trad]); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -147,34 +147,34 @@ discard block |
||
| 147 | 147 | * Erreurs du formulaire |
| 148 | 148 | **/ |
| 149 | 149 | function formulaires_editer_rubrique_verifier_dist( |
| 150 | - $id_rubrique = 'new', |
|
| 151 | - $id_parent = 0, |
|
| 152 | - $retour = '', |
|
| 153 | - $lier_trad = 0, |
|
| 154 | - $config_fonc = 'rubriques_edit_config', |
|
| 155 | - $row = [], |
|
| 156 | - $hidden = '' |
|
| 150 | + $id_rubrique = 'new', |
|
| 151 | + $id_parent = 0, |
|
| 152 | + $retour = '', |
|
| 153 | + $lier_trad = 0, |
|
| 154 | + $config_fonc = 'rubriques_edit_config', |
|
| 155 | + $row = [], |
|
| 156 | + $hidden = '' |
|
| 157 | 157 | ) { |
| 158 | - // auto-renseigner le titre si il n'existe pas |
|
| 159 | - titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | - $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | - |
|
| 163 | - // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | - if ( |
|
| 165 | - intval($id_rubrique) |
|
| 166 | - and empty($erreurs['id_parent']) |
|
| 167 | - and $id_parent = _request('id_parent') |
|
| 168 | - ) { |
|
| 169 | - include_spip('inc/rubriques'); |
|
| 170 | - $branche = calcul_branche_in($id_rubrique); |
|
| 171 | - $branche = explode(',', $branche); |
|
| 172 | - if (in_array($id_parent, $branche)) { |
|
| 173 | - $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $erreurs; |
|
| 158 | + // auto-renseigner le titre si il n'existe pas |
|
| 159 | + titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | + $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | + |
|
| 163 | + // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | + if ( |
|
| 165 | + intval($id_rubrique) |
|
| 166 | + and empty($erreurs['id_parent']) |
|
| 167 | + and $id_parent = _request('id_parent') |
|
| 168 | + ) { |
|
| 169 | + include_spip('inc/rubriques'); |
|
| 170 | + $branche = calcul_branche_in($id_rubrique); |
|
| 171 | + $branche = explode(',', $branche); |
|
| 172 | + if (in_array($id_parent, $branche)) { |
|
| 173 | + $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $erreurs; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -200,22 +200,22 @@ discard block |
||
| 200 | 200 | * Retour des traitements |
| 201 | 201 | **/ |
| 202 | 202 | function formulaires_editer_rubrique_traiter_dist( |
| 203 | - $id_rubrique = 'new', |
|
| 204 | - $id_parent = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $lier_trad = 0, |
|
| 207 | - $config_fonc = 'rubriques_edit_config', |
|
| 208 | - $row = [], |
|
| 209 | - $hidden = '' |
|
| 203 | + $id_rubrique = 'new', |
|
| 204 | + $id_parent = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $lier_trad = 0, |
|
| 207 | + $config_fonc = 'rubriques_edit_config', |
|
| 208 | + $row = [], |
|
| 209 | + $hidden = '' |
|
| 210 | 210 | ) { |
| 211 | - return formulaires_editer_objet_traiter( |
|
| 212 | - 'rubrique', |
|
| 213 | - $id_rubrique, |
|
| 214 | - $id_parent, |
|
| 215 | - $lier_trad, |
|
| 216 | - $retour, |
|
| 217 | - $config_fonc, |
|
| 218 | - $row, |
|
| 219 | - $hidden |
|
| 220 | - ); |
|
| 211 | + return formulaires_editer_objet_traiter( |
|
| 212 | + 'rubrique', |
|
| 213 | + $id_rubrique, |
|
| 214 | + $id_parent, |
|
| 215 | + $lier_trad, |
|
| 216 | + $retour, |
|
| 217 | + $config_fonc, |
|
| 218 | + $row, |
|
| 219 | + $hidden |
|
| 220 | + ); |
|
| 221 | 221 | } |
@@ -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 | /** |
@@ -31,46 +31,46 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - $s = ''; |
|
| 38 | - $pass = ''; |
|
| 39 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | - if (!$s) { |
|
| 41 | - $s = random_int(0, mt_getrandmax()); |
|
| 42 | - if (!$s) { |
|
| 43 | - $s = random_int(0, mt_getrandmax()); |
|
| 44 | - } |
|
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | - } |
|
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | - $x = $r['r'] & 63; |
|
| 49 | - if ($x < 10) { |
|
| 50 | - $x = chr($x + 48); |
|
| 51 | - } else { |
|
| 52 | - if ($x < 36) { |
|
| 53 | - $x = chr($x + 55); |
|
| 54 | - } else { |
|
| 55 | - if ($x < 62) { |
|
| 56 | - $x = chr($x + 61); |
|
| 57 | - } else { |
|
| 58 | - if ($x == 63) { |
|
| 59 | - $x = '/'; |
|
| 60 | - } else { |
|
| 61 | - $x = '.'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $pass .= $x; |
|
| 67 | - $s = substr($s, 2); |
|
| 68 | - } |
|
| 69 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | - |
|
| 73 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + $s = ''; |
|
| 38 | + $pass = ''; |
|
| 39 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | + if (!$s) { |
|
| 41 | + $s = random_int(0, mt_getrandmax()); |
|
| 42 | + if (!$s) { |
|
| 43 | + $s = random_int(0, mt_getrandmax()); |
|
| 44 | + } |
|
| 45 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + } |
|
| 47 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $x = $r['r'] & 63; |
|
| 49 | + if ($x < 10) { |
|
| 50 | + $x = chr($x + 48); |
|
| 51 | + } else { |
|
| 52 | + if ($x < 36) { |
|
| 53 | + $x = chr($x + 55); |
|
| 54 | + } else { |
|
| 55 | + if ($x < 62) { |
|
| 56 | + $x = chr($x + 61); |
|
| 57 | + } else { |
|
| 58 | + if ($x == 63) { |
|
| 59 | + $x = '/'; |
|
| 60 | + } else { |
|
| 61 | + $x = '.'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $pass .= $x; |
|
| 67 | + $s = substr($s, 2); |
|
| 68 | + } |
|
| 69 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | + |
|
| 73 | + return $pass; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | * @return string Identifiant |
| 80 | 80 | */ |
| 81 | 81 | function creer_uniqid() { |
| 82 | - static $seeded; |
|
| 82 | + static $seeded; |
|
| 83 | 83 | |
| 84 | - if (!$seeded) { |
|
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | - mt_srand($seed); |
|
| 87 | - $seeded = true; |
|
| 88 | - } |
|
| 84 | + if (!$seeded) { |
|
| 85 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + mt_srand($seed); |
|
| 87 | + $seeded = true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $s = random_int(0, mt_getrandmax()); |
|
| 91 | - if (!$s) { |
|
| 92 | - $s = random_int(0, mt_getrandmax()); |
|
| 93 | - } |
|
| 90 | + $s = random_int(0, mt_getrandmax()); |
|
| 91 | + if (!$s) { |
|
| 92 | + $s = random_int(0, mt_getrandmax()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return uniqid($s, 1); |
|
| 95 | + return uniqid($s, 1); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | * @return string Retourne l'alea éphemère actuel au passage |
| 107 | 107 | */ |
| 108 | 108 | function charger_aleas() { |
| 109 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | - include_spip('base/abstract_sql'); |
|
| 111 | - $aleas = sql_allfetsel( |
|
| 112 | - ['nom', 'valeur'], |
|
| 113 | - 'spip_meta', |
|
| 114 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - 'continue' |
|
| 121 | - ); |
|
| 122 | - if ($aleas) { |
|
| 123 | - foreach ($aleas as $a) { |
|
| 124 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | - } else { |
|
| 128 | - spip_log('aleas indisponibles', 'session'); |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 109 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | + include_spip('base/abstract_sql'); |
|
| 111 | + $aleas = sql_allfetsel( |
|
| 112 | + ['nom', 'valeur'], |
|
| 113 | + 'spip_meta', |
|
| 114 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + 'continue' |
|
| 121 | + ); |
|
| 122 | + if ($aleas) { |
|
| 123 | + foreach ($aleas as $a) { |
|
| 124 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | + } else { |
|
| 128 | + spip_log('aleas indisponibles', 'session'); |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 137 | 137 | **/ |
| 138 | 138 | function renouvelle_alea() { |
| 139 | - charger_aleas(); |
|
| 140 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | + charger_aleas(); |
|
| 140 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * Clé de sécurité. |
| 162 | 162 | **/ |
| 163 | 163 | function low_sec($id_auteur) { |
| 164 | - // Pas d'id_auteur : low_sec |
|
| 165 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | - include_spip('inc/config'); |
|
| 167 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | - if (!$low_sec) { |
|
| 173 | - $low_sec = creer_pass_aleatoire(); |
|
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $low_sec; |
|
| 164 | + // Pas d'id_auteur : low_sec |
|
| 165 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | + include_spip('inc/config'); |
|
| 167 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | + if (!$low_sec) { |
|
| 173 | + $low_sec = creer_pass_aleatoire(); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $low_sec; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * @filtre |
| 209 | 209 | */ |
| 210 | 210 | function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 211 | - if ($op) { |
|
| 212 | - $dir .= " $op $args"; |
|
| 213 | - } |
|
| 211 | + if ($op) { |
|
| 212 | + $dir .= " $op $args"; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 230 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -249,27 +249,27 @@ discard block |
||
| 249 | 249 | * @deprecated 4.1 |
| 250 | 250 | */ |
| 251 | 251 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 252 | - $a = $b = ''; |
|
| 253 | - foreach ($args as $val => $var) { |
|
| 254 | - if ($var) { |
|
| 255 | - if ($val <> 'statut') { |
|
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 257 | - } |
|
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $a = substr($a, 1); |
|
| 262 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | - |
|
| 264 | - return $b |
|
| 265 | - . 'op=' |
|
| 266 | - . $op |
|
| 267 | - . '&id=' |
|
| 268 | - . $id |
|
| 269 | - . '&cle=' |
|
| 270 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | - . (!$a ? '' : "&args=$a") |
|
| 272 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 252 | + $a = $b = ''; |
|
| 253 | + foreach ($args as $val => $var) { |
|
| 254 | + if ($var) { |
|
| 255 | + if ($val <> 'statut') { |
|
| 256 | + $a .= ':' . $val . '-' . $var; |
|
| 257 | + } |
|
| 258 | + $b .= $val . '=' . $var . '&'; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $a = substr($a, 1); |
|
| 262 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | + |
|
| 264 | + return $b |
|
| 265 | + . 'op=' |
|
| 266 | + . $op |
|
| 267 | + . '&id=' |
|
| 268 | + . $id |
|
| 269 | + . '&cle=' |
|
| 270 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | + . (!$a ? '' : "&args=$a") |
|
| 272 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * true si les clés corresponde, false sinon |
| 304 | 304 | **/ |
| 305 | 305 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 306 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Identifiant de l'auteur |
| 314 | 314 | **/ |
| 315 | 315 | function effacer_low_sec($id_auteur) { |
| 316 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | - return; |
|
| 318 | - } // jamais trop prudent ;) |
|
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 316 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | + return; |
|
| 318 | + } // jamais trop prudent ;) |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,31 +334,31 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 339 | - |
|
| 340 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 341 | - // par exemple acces_restreint ; |
|
| 342 | - // si .htaccess existe, outrepasser spip_meta |
|
| 343 | - if ( |
|
| 344 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 345 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 346 | - and !@file_exists($htaccess) |
|
| 347 | - ) { |
|
| 348 | - spip_unlink($htpasswd); |
|
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 354 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 355 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 356 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 357 | - if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 358 | - return; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 337 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 339 | + |
|
| 340 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 341 | + // par exemple acces_restreint ; |
|
| 342 | + // si .htaccess existe, outrepasser spip_meta |
|
| 343 | + if ( |
|
| 344 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 345 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 346 | + and !@file_exists($htaccess) |
|
| 347 | + ) { |
|
| 348 | + spip_unlink($htpasswd); |
|
| 349 | + spip_unlink($htpasswd . '-admin'); |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 354 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 355 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 356 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 357 | + if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 358 | + return; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -367,29 +367,29 @@ discard block |
||
| 367 | 367 | * @param $htpasswd_admin |
| 368 | 368 | */ |
| 369 | 369 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 370 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 371 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $pwd_all = ''; // login:htpass pour tous |
|
| 375 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 376 | - |
|
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | - while ($row = sql_fetch($res)) { |
|
| 379 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 381 | - $pwd_all .= $ligne; |
|
| 382 | - if ($row['statut'] == '0minirezo') { |
|
| 383 | - $pwd_admin .= $ligne; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ($pwd_all) { |
|
| 389 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 390 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 391 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 392 | - } |
|
| 370 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 371 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $pwd_all = ''; // login:htpass pour tous |
|
| 375 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 376 | + |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | + while ($row = sql_fetch($res)) { |
|
| 379 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 380 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 381 | + $pwd_all .= $ligne; |
|
| 382 | + if ($row['statut'] == '0minirezo') { |
|
| 383 | + $pwd_admin .= $ligne; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ($pwd_all) { |
|
| 389 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 390 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 391 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 392 | + } |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 404 | 404 | */ |
| 405 | 405 | function generer_htpass($pass) { |
| 406 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 407 | - return $generer_htpass($pass); |
|
| 408 | - } |
|
| 406 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 407 | + return $generer_htpass($pass); |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | - return ''; |
|
| 410 | + return ''; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 424 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // directive deny compatible Apache 2.0+ |
|
| 429 | - $deny = |
|
| 430 | - '# Deny all requests from Apache 2.4+. |
|
| 423 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 424 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // directive deny compatible Apache 2.0+ |
|
| 429 | + $deny = |
|
| 430 | + '# Deny all requests from Apache 2.4+. |
|
| 431 | 431 | <IfModule mod_authz_core.c> |
| 432 | 432 | Require all denied |
| 433 | 433 | </IfModule> |
@@ -436,32 +436,32 @@ discard block |
||
| 436 | 436 | Deny from all |
| 437 | 437 | </IfModule> |
| 438 | 438 | '; |
| 439 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 440 | - if ( |
|
| 441 | - function_exists('apache_get_version') |
|
| 442 | - and $v = apache_get_version() |
|
| 443 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 444 | - ) { |
|
| 445 | - $deny = "deny from all\n"; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 449 | - fputs($ht, $deny); |
|
| 450 | - fclose($ht); |
|
| 451 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 453 | - if ($ht = @fopen($t, 'w')) { |
|
| 454 | - @fclose($ht); |
|
| 455 | - include_spip('inc/distant'); |
|
| 456 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 457 | - $t = url_de_base() . $t; |
|
| 458 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 459 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 463 | - |
|
| 464 | - return $ht; |
|
| 439 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 440 | + if ( |
|
| 441 | + function_exists('apache_get_version') |
|
| 442 | + and $v = apache_get_version() |
|
| 443 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 444 | + ) { |
|
| 445 | + $deny = "deny from all\n"; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 449 | + fputs($ht, $deny); |
|
| 450 | + fclose($ht); |
|
| 451 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 452 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 453 | + if ($ht = @fopen($t, 'w')) { |
|
| 454 | + @fclose($ht); |
|
| 455 | + include_spip('inc/distant'); |
|
| 456 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 457 | + $t = url_de_base() . $t; |
|
| 458 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 459 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 463 | + |
|
| 464 | + return $ht; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -479,20 +479,20 @@ discard block |
||
| 479 | 479 | * Valeur de la configuration `creer_htaccess` |
| 480 | 480 | */ |
| 481 | 481 | function gerer_htaccess() { |
| 482 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 483 | - // par exemple acces_restreint |
|
| 484 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 485 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 486 | - $dirs[] = ['extension' => 'distant']; |
|
| 487 | - foreach ($dirs as $e) { |
|
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 489 | - if ($f) { |
|
| 490 | - verifier_htaccess($dir); |
|
| 491 | - } else { |
|
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 482 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 483 | + // par exemple acces_restreint |
|
| 484 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 485 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 486 | + $dirs[] = ['extension' => 'distant']; |
|
| 487 | + foreach ($dirs as $e) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 489 | + if ($f) { |
|
| 490 | + verifier_htaccess($dir); |
|
| 491 | + } else { |
|
| 492 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 498 | 498 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 35 | 35 | |
| 36 | 36 | mt_srand($seed); |
| 37 | 37 | $s = ''; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | if (!$s) { |
| 43 | 43 | $s = random_int(0, mt_getrandmax()); |
| 44 | 44 | } |
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 46 | 46 | } |
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 48 | 48 | $x = $r['r'] & 63; |
| 49 | 49 | if ($x < 10) { |
| 50 | 50 | $x = chr($x + 48); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | static $seeded; |
| 83 | 83 | |
| 84 | 84 | if (!$seeded) { |
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 86 | 86 | mt_srand($seed); |
| 87 | 87 | $seeded = true; |
| 88 | 88 | } |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
| 169 | 169 | } |
| 170 | 170 | } else { |
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 172 | 172 | if (!$low_sec) { |
| 173 | 173 | $low_sec = creer_pass_aleatoire(); |
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.intval($id_auteur)); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | 230 | $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
| 231 | 231 | $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | 234 | return generer_url_api($script, $path, $args, $no_entities = false, $public); |
| 235 | 235 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | foreach ($args as $val => $var) { |
| 254 | 254 | if ($var) { |
| 255 | 255 | if ($val <> 'statut') { |
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 256 | + $a .= ':'.$val.'-'.$var; |
|
| 257 | 257 | } |
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 258 | + $b .= $val.'='.$var.'&'; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | $a = substr($a, 1); |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | if (!$id_auteur = intval($id_auteur)) { |
| 317 | 317 | return; |
| 318 | 318 | } // jamais trop prudent ;) |
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 337 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 339 | 339 | |
| 340 | 340 | // Cette variable de configuration peut etre posee par un plugin |
| 341 | 341 | // par exemple acces_restreint ; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | and !@file_exists($htaccess) |
| 347 | 347 | ) { |
| 348 | 348 | spip_unlink($htpasswd); |
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 349 | + spip_unlink($htpasswd.'-admin'); |
|
| 350 | 350 | return; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | $pwd_all = ''; // login:htpass pour tous |
| 375 | 375 | $pwd_admin = ''; // login:htpass pour les admins |
| 376 | 376 | |
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | 378 | while ($row = sql_fetch($res)) { |
| 379 | 379 | if (strlen($row['login']) and strlen($row['htpass'])) { |
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | + $ligne = $row['login'].':'.$row['htpass']."\n"; |
|
| 381 | 381 | $pwd_all .= $ligne; |
| 382 | 382 | if ($row['statut'] == '0minirezo') { |
| 383 | 383 | $pwd_admin .= $ligne; |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 424 | 424 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 425 | 425 | return true; |
| 426 | 426 | } |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | fputs($ht, $deny); |
| 450 | 450 | fclose($ht); |
| 451 | 451 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 453 | 453 | if ($ht = @fopen($t, 'w')) { |
| 454 | 454 | @fclose($ht); |
| 455 | 455 | include_spip('inc/distant'); |
| 456 | 456 | $t = substr($t, strlen(_DIR_RACINE)); |
| 457 | - $t = url_de_base() . $t; |
|
| 457 | + $t = url_de_base().$t; |
|
| 458 | 458 | $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
| 459 | 459 | $ht = ($ht['status'] ?? null) === 403; |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 463 | 463 | |
| 464 | 464 | return $ht; |
| 465 | 465 | } |
@@ -485,11 +485,11 @@ discard block |
||
| 485 | 485 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 486 | 486 | $dirs[] = ['extension' => 'distant']; |
| 487 | 487 | foreach ($dirs as $e) { |
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 489 | 489 | if ($f) { |
| 490 | 490 | verifier_htaccess($dir); |
| 491 | 491 | } else { |
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -312,8 +312,7 @@ |
||
| 312 | 312 | ecrire_meta($casier, $serialized_store, null, $table); |
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | - } |
|
| 316 | - else { |
|
| 315 | + } else { |
|
| 317 | 316 | ecrire_meta($casier, $store, null, $table); |
| 318 | 317 | } |
| 319 | 318 | } |
@@ -303,9 +303,9 @@ |
||
| 303 | 303 | // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
| 304 | 304 | // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
| 305 | 305 | if ($has_planes) { |
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_'.$table, 'nom='.sql_quote($casier)); |
|
| 307 | 307 | if ($check_store !== $serialized_store) { |
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 308 | + array_walk_recursive($store, function(&$value, $key) { |
|
| 309 | 309 | if (is_string($value)) { |
| 310 | 310 | $value = utf8_noplanes($value); |
| 311 | 311 | } |
@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | function inc_config_dist() { |
| 31 | - actualise_metas(liste_metas()); |
|
| 31 | + actualise_metas(liste_metas()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -45,34 +45,34 @@ discard block |
||
| 45 | 45 | * Liste (table, casier, sous_casier) |
| 46 | 46 | */ |
| 47 | 47 | function expliquer_config($cfg) { |
| 48 | - // par defaut, sur la table des meta |
|
| 49 | - $table = 'meta'; |
|
| 50 | - $casier = null; |
|
| 51 | - $sous_casier = []; |
|
| 52 | - $cfg = explode('/', $cfg); |
|
| 53 | - |
|
| 54 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | - if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | - array_shift($cfg); |
|
| 57 | - $table = array_shift($cfg); |
|
| 58 | - if (!isset($GLOBALS[$table])) { |
|
| 59 | - lire_metas($table); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | - if (count($cfg)) { |
|
| 65 | - // pas sur un appel vide '' |
|
| 66 | - if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | - $casier = $c; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (count($cfg)) { |
|
| 72 | - $sous_casier = $cfg; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return [$table, $casier, $sous_casier]; |
|
| 48 | + // par defaut, sur la table des meta |
|
| 49 | + $table = 'meta'; |
|
| 50 | + $casier = null; |
|
| 51 | + $sous_casier = []; |
|
| 52 | + $cfg = explode('/', $cfg); |
|
| 53 | + |
|
| 54 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | + if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | + array_shift($cfg); |
|
| 57 | + $table = array_shift($cfg); |
|
| 58 | + if (!isset($GLOBALS[$table])) { |
|
| 59 | + lire_metas($table); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | + if (count($cfg)) { |
|
| 65 | + // pas sur un appel vide '' |
|
| 66 | + if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | + $casier = $c; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (count($cfg)) { |
|
| 72 | + $sous_casier = $cfg; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return [$table, $casier, $sous_casier]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -100,65 +100,65 @@ discard block |
||
| 100 | 100 | * Contenu de la configuration obtenue |
| 101 | 101 | */ |
| 102 | 102 | function lire_config($cfg = '', $def = null, $unserialize = true) { |
| 103 | - // lire le stockage sous la forme /table/valeur |
|
| 104 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | - |
|
| 107 | - // traiter en priorite le cas simple et frequent |
|
| 108 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | - if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | - $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | - ((!$unserialize |
|
| 112 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | - or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | - or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | - or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | - : $def; |
|
| 118 | - |
|
| 119 | - return $r; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Brancher sur methodes externes si besoin |
|
| 123 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | - $methode = substr($cfg, 0, $p); |
|
| 125 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | - |
|
| 127 | - return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | - |
|
| 132 | - if (!isset($GLOBALS[$table])) { |
|
| 133 | - return $def; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $r = $GLOBALS[$table]; |
|
| 137 | - |
|
| 138 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | - if (!$casier) { |
|
| 140 | - return $unserialize ? $r : serialize($r); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // casier principal : |
|
| 144 | - // le deserializer si demande |
|
| 145 | - // ou si on a besoin |
|
| 146 | - // d'un sous casier |
|
| 147 | - $r = $r[$casier] ?? null; |
|
| 148 | - if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | - $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // aller chercher le sous_casier |
|
| 153 | - while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | - $r = $r[$casier] ?? null; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($r)) { |
|
| 158 | - return $def; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $r; |
|
| 103 | + // lire le stockage sous la forme /table/valeur |
|
| 104 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | + |
|
| 107 | + // traiter en priorite le cas simple et frequent |
|
| 108 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | + if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | + $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | + ((!$unserialize |
|
| 112 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | + or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | + or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | + or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | + : $def; |
|
| 118 | + |
|
| 119 | + return $r; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Brancher sur methodes externes si besoin |
|
| 123 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | + $methode = substr($cfg, 0, $p); |
|
| 125 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | + |
|
| 127 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | + |
|
| 132 | + if (!isset($GLOBALS[$table])) { |
|
| 133 | + return $def; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $r = $GLOBALS[$table]; |
|
| 137 | + |
|
| 138 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | + if (!$casier) { |
|
| 140 | + return $unserialize ? $r : serialize($r); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // casier principal : |
|
| 144 | + // le deserializer si demande |
|
| 145 | + // ou si on a besoin |
|
| 146 | + // d'un sous casier |
|
| 147 | + $r = $r[$casier] ?? null; |
|
| 148 | + if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | + $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // aller chercher le sous_casier |
|
| 153 | + while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | + $r = $r[$casier] ?? null; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($r)) { |
|
| 158 | + return $def; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $r; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | 174 | function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) { |
| 175 | - return lire_config($cfg, $def, $unserialize); |
|
| 175 | + return lire_config($cfg, $def, $unserialize); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -184,144 +184,144 @@ discard block |
||
| 184 | 184 | * @return bool |
| 185 | 185 | */ |
| 186 | 186 | function ecrire_config($cfg, $store) { |
| 187 | - // Brancher sur methodes externes si besoin |
|
| 188 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | - $methode = substr($cfg, 0, $p); |
|
| 190 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | - |
|
| 192 | - return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | - // il faut au moins un casier pour ecrire |
|
| 197 | - if (!$casier) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // trouvons ou creons le pointeur sur le casier |
|
| 202 | - $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | - if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | - if ($st === null) { |
|
| 205 | - // ne rien creer si c'est une demande d'effacement |
|
| 206 | - if ($store === null) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - $st = []; |
|
| 210 | - } else { |
|
| 211 | - $st = unserialize($st); |
|
| 212 | - if ($st === false) { |
|
| 213 | - // ne rien creer si c'est une demande d'effacement |
|
| 214 | - if ($store === null) { |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - $st = []; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $has_planes = false; |
|
| 223 | - // si on a affaire a un sous caiser |
|
| 224 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | - if ($c = $sous_casier) { |
|
| 226 | - $sc = &$st; |
|
| 227 | - $pointeurs = []; |
|
| 228 | - while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | - // creer l'entree si elle n'existe pas |
|
| 230 | - if (!isset($sc[$cc])) { |
|
| 231 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | - // ne rien creer mais sortir |
|
| 233 | - if (is_null($store)) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - $sc[$cc] = []; |
|
| 237 | - } |
|
| 238 | - $pointeurs[$cc] = &$sc; |
|
| 239 | - $sc = &$sc[$cc]; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // si c'est une demande d'effacement |
|
| 243 | - if (is_null($store)) { |
|
| 244 | - $c = $sous_casier; |
|
| 245 | - $sous = array_pop($c); |
|
| 246 | - // effacer, et remonter pour effacer les parents vides |
|
| 247 | - do { |
|
| 248 | - unset($pointeurs[$sous][$sous]); |
|
| 249 | - } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | - |
|
| 251 | - // si on a vide tous les sous casiers, |
|
| 252 | - // et que le casier est vide |
|
| 253 | - // vider aussi la meta |
|
| 254 | - if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | - $st = null; |
|
| 256 | - } |
|
| 257 | - } // dans tous les autres cas, on ecrase |
|
| 258 | - else { |
|
| 259 | - if ( |
|
| 260 | - defined('_MYSQL_NOPLANES') |
|
| 261 | - and _MYSQL_NOPLANES |
|
| 262 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | - ) { |
|
| 265 | - // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | - // @see utf8_noplanes |
|
| 267 | - $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | - // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | - if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | - if (!function_exists('utf8_noplanes')) { |
|
| 271 | - include_spip('inc/charsets'); |
|
| 272 | - } |
|
| 273 | - if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | - $has_planes = true; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $sc = $store; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Maintenant que $st est modifiee |
|
| 283 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | - $store = $st; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (is_null($store)) { |
|
| 288 | - if (is_null($st) and !$sous_casier) { |
|
| 289 | - return false; |
|
| 290 | - } // la config n'existait deja pas ! |
|
| 291 | - effacer_meta($casier, $table); |
|
| 292 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | - } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | - else { |
|
| 295 | - if (!isset($GLOBALS[$table])) { |
|
| 296 | - installer_table_meta($table); |
|
| 297 | - } |
|
| 298 | - // si ce n'est pas une chaine |
|
| 299 | - // il faut serializer |
|
| 300 | - if (!is_string($store)) { |
|
| 301 | - $serialized_store = serialize($store); |
|
| 302 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | - // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | - // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | - if ($has_planes) { |
|
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | - if ($check_store !== $serialized_store) { |
|
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | - if (is_string($value)) { |
|
| 310 | - $value = utf8_noplanes($value); |
|
| 311 | - } |
|
| 312 | - }); |
|
| 313 | - $serialized_store = serialize($store); |
|
| 314 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - else { |
|
| 319 | - ecrire_meta($casier, $store, null, $table); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // verifier que lire_config($cfg)==$store ? |
|
| 324 | - return true; |
|
| 187 | + // Brancher sur methodes externes si besoin |
|
| 188 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | + $methode = substr($cfg, 0, $p); |
|
| 190 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | + |
|
| 192 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | + // il faut au moins un casier pour ecrire |
|
| 197 | + if (!$casier) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // trouvons ou creons le pointeur sur le casier |
|
| 202 | + $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | + if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | + if ($st === null) { |
|
| 205 | + // ne rien creer si c'est une demande d'effacement |
|
| 206 | + if ($store === null) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + $st = []; |
|
| 210 | + } else { |
|
| 211 | + $st = unserialize($st); |
|
| 212 | + if ($st === false) { |
|
| 213 | + // ne rien creer si c'est une demande d'effacement |
|
| 214 | + if ($store === null) { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + $st = []; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $has_planes = false; |
|
| 223 | + // si on a affaire a un sous caiser |
|
| 224 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | + if ($c = $sous_casier) { |
|
| 226 | + $sc = &$st; |
|
| 227 | + $pointeurs = []; |
|
| 228 | + while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | + // creer l'entree si elle n'existe pas |
|
| 230 | + if (!isset($sc[$cc])) { |
|
| 231 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | + // ne rien creer mais sortir |
|
| 233 | + if (is_null($store)) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + $sc[$cc] = []; |
|
| 237 | + } |
|
| 238 | + $pointeurs[$cc] = &$sc; |
|
| 239 | + $sc = &$sc[$cc]; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // si c'est une demande d'effacement |
|
| 243 | + if (is_null($store)) { |
|
| 244 | + $c = $sous_casier; |
|
| 245 | + $sous = array_pop($c); |
|
| 246 | + // effacer, et remonter pour effacer les parents vides |
|
| 247 | + do { |
|
| 248 | + unset($pointeurs[$sous][$sous]); |
|
| 249 | + } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | + |
|
| 251 | + // si on a vide tous les sous casiers, |
|
| 252 | + // et que le casier est vide |
|
| 253 | + // vider aussi la meta |
|
| 254 | + if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | + $st = null; |
|
| 256 | + } |
|
| 257 | + } // dans tous les autres cas, on ecrase |
|
| 258 | + else { |
|
| 259 | + if ( |
|
| 260 | + defined('_MYSQL_NOPLANES') |
|
| 261 | + and _MYSQL_NOPLANES |
|
| 262 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | + ) { |
|
| 265 | + // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | + // @see utf8_noplanes |
|
| 267 | + $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | + // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | + if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | + if (!function_exists('utf8_noplanes')) { |
|
| 271 | + include_spip('inc/charsets'); |
|
| 272 | + } |
|
| 273 | + if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | + $has_planes = true; |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $sc = $store; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Maintenant que $st est modifiee |
|
| 283 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | + $store = $st; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (is_null($store)) { |
|
| 288 | + if (is_null($st) and !$sous_casier) { |
|
| 289 | + return false; |
|
| 290 | + } // la config n'existait deja pas ! |
|
| 291 | + effacer_meta($casier, $table); |
|
| 292 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | + } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | + else { |
|
| 295 | + if (!isset($GLOBALS[$table])) { |
|
| 296 | + installer_table_meta($table); |
|
| 297 | + } |
|
| 298 | + // si ce n'est pas une chaine |
|
| 299 | + // il faut serializer |
|
| 300 | + if (!is_string($store)) { |
|
| 301 | + $serialized_store = serialize($store); |
|
| 302 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | + // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | + // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | + if ($has_planes) { |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | + if ($check_store !== $serialized_store) { |
|
| 308 | + array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | + if (is_string($value)) { |
|
| 310 | + $value = utf8_noplanes($value); |
|
| 311 | + } |
|
| 312 | + }); |
|
| 313 | + $serialized_store = serialize($store); |
|
| 314 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + else { |
|
| 319 | + ecrire_meta($casier, $store, null, $table); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // verifier que lire_config($cfg)==$store ? |
|
| 324 | + return true; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -335,14 +335,14 @@ discard block |
||
| 335 | 335 | * @return bool |
| 336 | 336 | */ |
| 337 | 337 | function ecrire_config_metapack_dist($cfg, $store) { |
| 338 | - // cas particulier en metapack:: |
|
| 339 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | - // intacte en sortie ... |
|
| 341 | - if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | - $store = serialize($store); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return ecrire_config($cfg, $store); |
|
| 338 | + // cas particulier en metapack:: |
|
| 339 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | + // intacte en sortie ... |
|
| 341 | + if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | + $store = serialize($store); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return ecrire_config($cfg, $store); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | * @return bool |
| 353 | 353 | */ |
| 354 | 354 | function effacer_config($cfg) { |
| 355 | - ecrire_config($cfg, null); |
|
| 355 | + ecrire_config($cfg, null); |
|
| 356 | 356 | |
| 357 | - return true; |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,58 +371,58 @@ discard block |
||
| 371 | 371 | * Couples nom de la `meta` => valeur par défaut |
| 372 | 372 | */ |
| 373 | 373 | function liste_metas() { |
| 374 | - return pipeline('configurer_liste_metas', [ |
|
| 375 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | - 'slogan_site' => '', |
|
| 377 | - 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | - 'descriptif_site' => '', |
|
| 379 | - 'activer_logos' => 'oui', |
|
| 380 | - 'activer_logos_survol' => 'non', |
|
| 381 | - 'articles_surtitre' => 'non', |
|
| 382 | - 'articles_soustitre' => 'non', |
|
| 383 | - 'articles_descriptif' => 'non', |
|
| 384 | - 'articles_chapeau' => 'non', |
|
| 385 | - 'articles_texte' => 'oui', |
|
| 386 | - 'articles_ps' => 'non', |
|
| 387 | - 'articles_redac' => 'non', |
|
| 388 | - 'post_dates' => 'non', |
|
| 389 | - 'articles_urlref' => 'non', |
|
| 390 | - 'articles_redirection' => 'non', |
|
| 391 | - 'creer_preview' => 'non', |
|
| 392 | - 'taille_preview' => 150, |
|
| 393 | - 'articles_modif' => 'non', |
|
| 394 | - |
|
| 395 | - 'rubriques_descriptif' => 'non', |
|
| 396 | - 'rubriques_texte' => 'oui', |
|
| 397 | - |
|
| 398 | - 'accepter_inscriptions' => 'non', |
|
| 399 | - 'accepter_visiteurs' => 'non', |
|
| 400 | - 'prevenir_auteurs' => 'non', |
|
| 401 | - 'suivi_edito' => 'non', |
|
| 402 | - 'adresse_suivi' => '', |
|
| 403 | - 'adresse_suivi_inscription' => '', |
|
| 404 | - 'adresse_neuf' => '', |
|
| 405 | - 'jours_neuf' => '', |
|
| 406 | - 'quoi_de_neuf' => 'non', |
|
| 407 | - 'preview' => ',0minirezo,1comite,', |
|
| 408 | - |
|
| 409 | - 'syndication_integrale' => 'oui', |
|
| 410 | - 'charset' => _DEFAULT_CHARSET, |
|
| 411 | - 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | - |
|
| 413 | - 'multi_rubriques' => 'non', |
|
| 414 | - 'multi_secteurs' => 'non', |
|
| 415 | - 'gerer_trad' => 'non', |
|
| 416 | - 'langues_multilingue' => '', |
|
| 417 | - |
|
| 418 | - 'version_html_max' => 'html4', |
|
| 419 | - |
|
| 420 | - 'type_urls' => 'page', |
|
| 421 | - |
|
| 422 | - 'email_envoi' => '', |
|
| 423 | - 'email_webmaster' => '', |
|
| 424 | - 'auto_compress_http' => 'non', |
|
| 425 | - ]); |
|
| 374 | + return pipeline('configurer_liste_metas', [ |
|
| 375 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | + 'slogan_site' => '', |
|
| 377 | + 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | + 'descriptif_site' => '', |
|
| 379 | + 'activer_logos' => 'oui', |
|
| 380 | + 'activer_logos_survol' => 'non', |
|
| 381 | + 'articles_surtitre' => 'non', |
|
| 382 | + 'articles_soustitre' => 'non', |
|
| 383 | + 'articles_descriptif' => 'non', |
|
| 384 | + 'articles_chapeau' => 'non', |
|
| 385 | + 'articles_texte' => 'oui', |
|
| 386 | + 'articles_ps' => 'non', |
|
| 387 | + 'articles_redac' => 'non', |
|
| 388 | + 'post_dates' => 'non', |
|
| 389 | + 'articles_urlref' => 'non', |
|
| 390 | + 'articles_redirection' => 'non', |
|
| 391 | + 'creer_preview' => 'non', |
|
| 392 | + 'taille_preview' => 150, |
|
| 393 | + 'articles_modif' => 'non', |
|
| 394 | + |
|
| 395 | + 'rubriques_descriptif' => 'non', |
|
| 396 | + 'rubriques_texte' => 'oui', |
|
| 397 | + |
|
| 398 | + 'accepter_inscriptions' => 'non', |
|
| 399 | + 'accepter_visiteurs' => 'non', |
|
| 400 | + 'prevenir_auteurs' => 'non', |
|
| 401 | + 'suivi_edito' => 'non', |
|
| 402 | + 'adresse_suivi' => '', |
|
| 403 | + 'adresse_suivi_inscription' => '', |
|
| 404 | + 'adresse_neuf' => '', |
|
| 405 | + 'jours_neuf' => '', |
|
| 406 | + 'quoi_de_neuf' => 'non', |
|
| 407 | + 'preview' => ',0minirezo,1comite,', |
|
| 408 | + |
|
| 409 | + 'syndication_integrale' => 'oui', |
|
| 410 | + 'charset' => _DEFAULT_CHARSET, |
|
| 411 | + 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | + |
|
| 413 | + 'multi_rubriques' => 'non', |
|
| 414 | + 'multi_secteurs' => 'non', |
|
| 415 | + 'gerer_trad' => 'non', |
|
| 416 | + 'langues_multilingue' => '', |
|
| 417 | + |
|
| 418 | + 'version_html_max' => 'html4', |
|
| 419 | + |
|
| 420 | + 'type_urls' => 'page', |
|
| 421 | + |
|
| 422 | + 'email_envoi' => '', |
|
| 423 | + 'email_webmaster' => '', |
|
| 424 | + 'auto_compress_http' => 'non', |
|
| 425 | + ]); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -433,43 +433,43 @@ discard block |
||
| 433 | 433 | * @return void |
| 434 | 434 | */ |
| 435 | 435 | function actualise_metas($liste_meta) { |
| 436 | - $meta_serveur = |
|
| 437 | - [ |
|
| 438 | - 'version_installee', |
|
| 439 | - 'adresse_site', |
|
| 440 | - 'alea_ephemere_ancien', |
|
| 441 | - 'alea_ephemere', |
|
| 442 | - 'alea_ephemere_date', |
|
| 443 | - 'langue_site', |
|
| 444 | - 'langues_proposees', |
|
| 445 | - 'date_calcul_rubriques', |
|
| 446 | - 'derniere_modif', |
|
| 447 | - 'optimiser_table', |
|
| 448 | - 'drapeau_edition', |
|
| 449 | - 'creer_preview', |
|
| 450 | - 'taille_preview', |
|
| 451 | - 'creer_htpasswd', |
|
| 452 | - 'creer_htaccess', |
|
| 453 | - 'gd_formats_read', |
|
| 454 | - 'gd_formats', |
|
| 455 | - 'netpbm_formats', |
|
| 456 | - 'formats_graphiques', |
|
| 457 | - 'image_process', |
|
| 458 | - 'plugin_header', |
|
| 459 | - 'plugin' |
|
| 460 | - ]; |
|
| 461 | - // verifier le impt=non |
|
| 462 | - sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | - |
|
| 464 | - foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | - if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | - ecrire_meta($nom, $valeur); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - include_spip('inc/rubriques'); |
|
| 471 | - $langues = calculer_langues_utilisees(); |
|
| 472 | - ecrire_meta('langues_utilisees', $langues); |
|
| 436 | + $meta_serveur = |
|
| 437 | + [ |
|
| 438 | + 'version_installee', |
|
| 439 | + 'adresse_site', |
|
| 440 | + 'alea_ephemere_ancien', |
|
| 441 | + 'alea_ephemere', |
|
| 442 | + 'alea_ephemere_date', |
|
| 443 | + 'langue_site', |
|
| 444 | + 'langues_proposees', |
|
| 445 | + 'date_calcul_rubriques', |
|
| 446 | + 'derniere_modif', |
|
| 447 | + 'optimiser_table', |
|
| 448 | + 'drapeau_edition', |
|
| 449 | + 'creer_preview', |
|
| 450 | + 'taille_preview', |
|
| 451 | + 'creer_htpasswd', |
|
| 452 | + 'creer_htaccess', |
|
| 453 | + 'gd_formats_read', |
|
| 454 | + 'gd_formats', |
|
| 455 | + 'netpbm_formats', |
|
| 456 | + 'formats_graphiques', |
|
| 457 | + 'image_process', |
|
| 458 | + 'plugin_header', |
|
| 459 | + 'plugin' |
|
| 460 | + ]; |
|
| 461 | + // verifier le impt=non |
|
| 462 | + sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | + |
|
| 464 | + foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | + if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | + ecrire_meta($nom, $valeur); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + include_spip('inc/rubriques'); |
|
| 471 | + $langues = calculer_langues_utilisees(); |
|
| 472 | + ecrire_meta('langues_utilisees', $langues); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | |
@@ -491,18 +491,18 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | function appliquer_modifs_config($purger_skel = false) { |
| 493 | 493 | |
| 494 | - foreach (liste_metas() as $i => $v) { |
|
| 495 | - if (($x = _request($i)) !== null) { |
|
| 496 | - ecrire_meta($i, $x); |
|
| 497 | - } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | - ecrire_meta($i, $v); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - if ($purger_skel) { |
|
| 503 | - include_spip('inc/invalideur'); |
|
| 504 | - purger_repertoire(_DIR_SKELS); |
|
| 505 | - } |
|
| 494 | + foreach (liste_metas() as $i => $v) { |
|
| 495 | + if (($x = _request($i)) !== null) { |
|
| 496 | + ecrire_meta($i, $x); |
|
| 497 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | + ecrire_meta($i, $v); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + if ($purger_skel) { |
|
| 503 | + include_spip('inc/invalideur'); |
|
| 504 | + purger_repertoire(_DIR_SKELS); |
|
| 505 | + } |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -513,21 +513,21 @@ discard block |
||
| 513 | 513 | * @return string |
| 514 | 514 | */ |
| 515 | 515 | function appliquer_adresse_site($adresse_site) { |
| 516 | - if ($adresse_site !== null) { |
|
| 517 | - if (!strlen($adresse_site)) { |
|
| 518 | - $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | - $adresse_site = url_de_base(); |
|
| 520 | - } |
|
| 521 | - $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 516 | + if ($adresse_site !== null) { |
|
| 517 | + if (!strlen($adresse_site)) { |
|
| 518 | + $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | + $adresse_site = url_de_base(); |
|
| 520 | + } |
|
| 521 | + $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 522 | 522 | |
| 523 | - if (!tester_url_absolue($adresse_site)) { |
|
| 524 | - $adresse_site = "http://$adresse_site"; |
|
| 525 | - } |
|
| 523 | + if (!tester_url_absolue($adresse_site)) { |
|
| 524 | + $adresse_site = "http://$adresse_site"; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | - $adresse_site = entites_html($adresse_site); |
|
| 527 | + $adresse_site = entites_html($adresse_site); |
|
| 528 | 528 | |
| 529 | - ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | - } |
|
| 529 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - return $adresse_site; |
|
| 532 | + return $adresse_site; |
|
| 533 | 533 | } |