@@ -18,21 +18,21 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 25 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 26 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 25 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 26 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | $GLOBALS['maj'][2022_02_23_02] = [ |
| 30 | - ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL" ], |
|
| 31 | - ['sql_delete', 'spip_meta', "nom='secret_du_site'" ], |
|
| 30 | + ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL" ], |
|
| 31 | + ['sql_delete', 'spip_meta', "nom='secret_du_site'" ], |
|
| 32 | 32 | ]; |
| 33 | 33 | |
| 34 | 34 | $GLOBALS['maj'][2022_02_23_03] = [ |
| 35 | - ['maj2021_supprimer_toutes_sessions_si_aucun_backup_cles'], |
|
| 35 | + ['maj2021_supprimer_toutes_sessions_si_aucun_backup_cles'], |
|
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -43,15 +43,15 @@ discard block |
||
| 43 | 43 | * - les autres auteurs vont tous regénérer un mot de passe plus sécure au premier login |
| 44 | 44 | **/ |
| 45 | 45 | function maj2021_supprimer_toutes_sessions_si_aucun_backup_cles() { |
| 46 | - if (!sql_countsel('spip_auteurs', "webmestre='oui' AND backup_cles!=''")) { |
|
| 47 | - spip_logger('maj')->info('supprimer sessions auteur'); |
|
| 48 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 49 | - while (($f = readdir($dir)) !== false) { |
|
| 50 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 51 | - if (time() >= _TIME_OUT) { |
|
| 52 | - return; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 46 | + if (!sql_countsel('spip_auteurs', "webmestre='oui' AND backup_cles!=''")) { |
|
| 47 | + spip_logger('maj')->info('supprimer sessions auteur'); |
|
| 48 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 49 | + while (($f = readdir($dir)) !== false) { |
|
| 50 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 51 | + if (time() >= _TIME_OUT) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 25 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 26 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 25 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL"], |
|
| 26 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL"], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | $GLOBALS['maj'][2022_02_23_02] = [ |
| 30 | - ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL" ], |
|
| 31 | - ['sql_delete', 'spip_meta', "nom='secret_du_site'" ], |
|
| 30 | + ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL"], |
|
| 31 | + ['sql_delete', 'spip_meta', "nom='secret_du_site'"], |
|
| 32 | 32 | ]; |
| 33 | 33 | |
| 34 | 34 | $GLOBALS['maj'][2022_02_23_03] = [ |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | spip_logger('maj')->info('supprimer sessions auteur'); |
| 48 | 48 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 49 | 49 | while (($f = readdir($dir)) !== false) { |
| 50 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 50 | + spip_unlink(_DIR_SESSIONS.$f); |
|
| 51 | 51 | if (time() >= _TIME_OUT) { |
| 52 | 52 | return; |
| 53 | 53 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 25 | 25 | // ne pas ecraser une definition perso dans mes_options |
| 26 | 26 | if (!isset($GLOBALS['ldap_attributes']) || !is_array($GLOBALS['ldap_attributes'])) { |
| 27 | - $GLOBALS['ldap_attributes'] = [ |
|
| 28 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | - 'nom' => 'cn', |
|
| 30 | - 'email' => 'mail', |
|
| 31 | - 'bio' => 'description' |
|
| 32 | - ]; |
|
| 27 | + $GLOBALS['ldap_attributes'] = [ |
|
| 28 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | + 'nom' => 'cn', |
|
| 30 | + 'email' => 'mail', |
|
| 31 | + 'bio' => 'description' |
|
| 32 | + ]; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,49 +55,49 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function auth_ldap_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 57 | 57 | |
| 58 | - #spip_logger()->info("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | - |
|
| 60 | - // Utilisateur connu ? |
|
| 61 | - // si http auth, inutile de reauthentifier: cela |
|
| 62 | - // ne marchera pas avec auth http autre que basic. |
|
| 63 | - $checkpass = !isset($_SERVER['REMOTE_USER']); |
|
| 64 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | - return []; |
|
| 66 | - } |
|
| 67 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | - |
|
| 69 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | - |
|
| 72 | - if ($r) { |
|
| 73 | - return array_merge($r, $credentials_ldap); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // sinon importer les infos depuis LDAP, |
|
| 77 | - |
|
| 78 | - if ( |
|
| 79 | - $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur)) |
|
| 80 | - ) { |
|
| 81 | - // rajouter le statut indique a l'install |
|
| 82 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 83 | - $desc['login'] = $login; |
|
| 84 | - $desc['source'] = 'ldap'; |
|
| 85 | - $desc['pass'] = ''; |
|
| 86 | - |
|
| 87 | - $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - if ($r) { |
|
| 91 | - return array_merge( |
|
| 92 | - $credentials_ldap, |
|
| 93 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // sinon echec |
|
| 98 | - spip_logger()->info("Creation de l'auteur '$login' impossible"); |
|
| 99 | - |
|
| 100 | - return []; |
|
| 58 | + #spip_logger()->info("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | + |
|
| 60 | + // Utilisateur connu ? |
|
| 61 | + // si http auth, inutile de reauthentifier: cela |
|
| 62 | + // ne marchera pas avec auth http autre que basic. |
|
| 63 | + $checkpass = !isset($_SERVER['REMOTE_USER']); |
|
| 64 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | + return []; |
|
| 66 | + } |
|
| 67 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | + |
|
| 69 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + |
|
| 72 | + if ($r) { |
|
| 73 | + return array_merge($r, $credentials_ldap); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // sinon importer les infos depuis LDAP, |
|
| 77 | + |
|
| 78 | + if ( |
|
| 79 | + $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur)) |
|
| 80 | + ) { |
|
| 81 | + // rajouter le statut indique a l'install |
|
| 82 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 83 | + $desc['login'] = $login; |
|
| 84 | + $desc['source'] = 'ldap'; |
|
| 85 | + $desc['pass'] = ''; |
|
| 86 | + |
|
| 87 | + $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + if ($r) { |
|
| 91 | + return array_merge( |
|
| 92 | + $credentials_ldap, |
|
| 93 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // sinon echec |
|
| 98 | + spip_logger()->info("Creation de l'auteur '$login' impossible"); |
|
| 99 | + |
|
| 100 | + return []; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -111,36 +111,36 @@ discard block |
||
| 111 | 111 | * @return array |
| 112 | 112 | */ |
| 113 | 113 | function auth_ldap_connect($serveur = '') { |
| 114 | - include_spip('base/connect_sql'); |
|
| 115 | - static $connexions_ldap = []; |
|
| 116 | - if (isset($connexions_ldap[$serveur])) { |
|
| 117 | - return $connexions_ldap[$serveur]; |
|
| 118 | - } |
|
| 119 | - $connexion = spip_connect($serveur); |
|
| 120 | - if (!is_array($connexion['ldap'])) { |
|
| 121 | - if ($connexion['authentification']['ldap']) { |
|
| 122 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | - unset($GLOBALS['ldap_link']); |
|
| 124 | - if (is_readable($f)) { |
|
| 125 | - include_once($f); |
|
| 126 | - }; |
|
| 127 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 128 | - $connexion['ldap'] = [ |
|
| 129 | - 'link' => $GLOBALS['ldap_link'], |
|
| 130 | - 'base' => $GLOBALS['ldap_base'] |
|
| 131 | - ]; |
|
| 132 | - } else { |
|
| 133 | - spip_logger()->info("connection LDAP $serveur mal definie dans $f"); |
|
| 134 | - } |
|
| 135 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 136 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 137 | - } |
|
| 138 | - } else { |
|
| 139 | - spip_logger()->info("connection LDAP $serveur inconnue"); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 114 | + include_spip('base/connect_sql'); |
|
| 115 | + static $connexions_ldap = []; |
|
| 116 | + if (isset($connexions_ldap[$serveur])) { |
|
| 117 | + return $connexions_ldap[$serveur]; |
|
| 118 | + } |
|
| 119 | + $connexion = spip_connect($serveur); |
|
| 120 | + if (!is_array($connexion['ldap'])) { |
|
| 121 | + if ($connexion['authentification']['ldap']) { |
|
| 122 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | + unset($GLOBALS['ldap_link']); |
|
| 124 | + if (is_readable($f)) { |
|
| 125 | + include_once($f); |
|
| 126 | + }; |
|
| 127 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 128 | + $connexion['ldap'] = [ |
|
| 129 | + 'link' => $GLOBALS['ldap_link'], |
|
| 130 | + 'base' => $GLOBALS['ldap_base'] |
|
| 131 | + ]; |
|
| 132 | + } else { |
|
| 133 | + spip_logger()->info("connection LDAP $serveur mal definie dans $f"); |
|
| 134 | + } |
|
| 135 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 136 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 139 | + spip_logger()->info("connection LDAP $serveur inconnue"); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,52 +154,52 @@ discard block |
||
| 154 | 154 | * Le login trouvé ou chaine vide si non trouvé |
| 155 | 155 | */ |
| 156 | 156 | function auth_ldap_search($login, #[\SensitiveParameter] $pass, $checkpass = true, $serveur = '') { |
| 157 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 158 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 159 | - if (!strlen($login_search) || $checkpass && !strlen($pass)) { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // verifier la connexion |
|
| 164 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 165 | - return ''; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $ldap_link = $ldap['link'] ?? null; |
|
| 169 | - $ldap_base = $ldap['base'] ?? null; |
|
| 170 | - $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes']; |
|
| 171 | - |
|
| 172 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 173 | - |
|
| 174 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 175 | - foreach ($logins as $att) { |
|
| 176 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 177 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 178 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 179 | - // (on veut un attribut unique) |
|
| 180 | - |
|
| 181 | - if (is_array($info) && $info['count'] == 1) { |
|
| 182 | - $dn = $info[0]['dn']; |
|
| 183 | - if (!$checkpass) { |
|
| 184 | - return $dn; |
|
| 185 | - } |
|
| 186 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 187 | - return $dn; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if ($checkpass && !isset($dn)) { |
|
| 193 | - // Si echec, essayer de deviner le DN |
|
| 194 | - foreach ($logins as $att) { |
|
| 195 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 196 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 197 | - return "$att=$login_search, $ldap_base"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return ''; |
|
| 157 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 158 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 159 | + if (!strlen($login_search) || $checkpass && !strlen($pass)) { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // verifier la connexion |
|
| 164 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 165 | + return ''; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $ldap_link = $ldap['link'] ?? null; |
|
| 169 | + $ldap_base = $ldap['base'] ?? null; |
|
| 170 | + $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes']; |
|
| 171 | + |
|
| 172 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 173 | + |
|
| 174 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 175 | + foreach ($logins as $att) { |
|
| 176 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 177 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 178 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 179 | + // (on veut un attribut unique) |
|
| 180 | + |
|
| 181 | + if (is_array($info) && $info['count'] == 1) { |
|
| 182 | + $dn = $info[0]['dn']; |
|
| 183 | + if (!$checkpass) { |
|
| 184 | + return $dn; |
|
| 185 | + } |
|
| 186 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 187 | + return $dn; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if ($checkpass && !isset($dn)) { |
|
| 193 | + // Si echec, essayer de deviner le DN |
|
| 194 | + foreach ($logins as $att) { |
|
| 195 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 196 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 197 | + return "$att=$login_search, $ldap_base"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return ''; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -211,40 +211,40 @@ discard block |
||
| 211 | 211 | * @return array |
| 212 | 212 | */ |
| 213 | 213 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 214 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 214 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 215 | 215 | |
| 216 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 217 | - spip_logger()->info("ldap $serveur injoignable"); |
|
| 216 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 217 | + spip_logger()->info("ldap $serveur injoignable"); |
|
| 218 | 218 | |
| 219 | - return []; |
|
| 220 | - } |
|
| 219 | + return []; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $ldap_link = $ldap['link']; |
|
| 223 | - if (!$desc) { |
|
| 224 | - $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 225 | - unset($desc['login']); |
|
| 226 | - } |
|
| 227 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 222 | + $ldap_link = $ldap['link']; |
|
| 223 | + if (!$desc) { |
|
| 224 | + $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 225 | + unset($desc['login']); |
|
| 226 | + } |
|
| 227 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 228 | 228 | |
| 229 | - if (!$result) { |
|
| 230 | - return []; |
|
| 231 | - } |
|
| 229 | + if (!$result) { |
|
| 230 | + return []; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 234 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 235 | - if (!is_array($val) || !is_array($val[0])) { |
|
| 236 | - return []; |
|
| 237 | - } |
|
| 238 | - $val = $val[0]; |
|
| 233 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 234 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 235 | + if (!is_array($val) || !is_array($val[0])) { |
|
| 236 | + return []; |
|
| 237 | + } |
|
| 238 | + $val = $val[0]; |
|
| 239 | 239 | |
| 240 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 241 | - include_spip('inc/charsets'); |
|
| 240 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 241 | + include_spip('inc/charsets'); |
|
| 242 | 242 | |
| 243 | - foreach ($desc as $k => $v) { |
|
| 244 | - $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8'); |
|
| 245 | - } |
|
| 243 | + foreach ($desc as $k => $v) { |
|
| 244 | + $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8'); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return $desc; |
|
| 247 | + return $desc; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 259 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 259 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * Message d'erreur si login non valide, chaîne vide sinon |
| 277 | 277 | */ |
| 278 | 278 | function auth_ldap_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 279 | - include_spip('auth/spip'); |
|
| 279 | + include_spip('auth/spip'); |
|
| 280 | 280 | |
| 281 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 281 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * ``` |
| 300 | 300 | */ |
| 301 | 301 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 302 | - return true; |
|
| 302 | + return true; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -317,22 +317,22 @@ discard block |
||
| 317 | 317 | * Informe du succès ou de l'echec du changement du mot de passe |
| 318 | 318 | */ |
| 319 | 319 | function auth_ldap_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 320 | - if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 324 | - return false; |
|
| 325 | - } |
|
| 326 | - $link = $ldap['link']; |
|
| 327 | - include_spip('inc/session'); |
|
| 328 | - $dn = session_get('ldap_dn'); |
|
| 329 | - if ('' == $dn) { |
|
| 330 | - return false; |
|
| 331 | - } |
|
| 332 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | - |
|
| 337 | - return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 320 | + if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 324 | + return false; |
|
| 325 | + } |
|
| 326 | + $link = $ldap['link']; |
|
| 327 | + include_spip('inc/session'); |
|
| 328 | + $dn = session_get('ldap_dn'); |
|
| 329 | + if ('' == $dn) { |
|
| 330 | + return false; |
|
| 331 | + } |
|
| 332 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | + |
|
| 337 | + return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 338 | 338 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | use Spip\Chiffrer\SpipCles; |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -33,167 +33,167 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function auth_spip_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 35 | 35 | |
| 36 | - $methode = null; |
|
| 37 | - // retrouver le login |
|
| 38 | - $login = auth_spip_retrouver_login($login); |
|
| 39 | - // login inconnu, n'allons pas plus loin |
|
| 40 | - if (!$login) { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $md5pass = ''; |
|
| 45 | - $shapass = $shanext = ''; |
|
| 46 | - $auteur_peut_sauver_cles = false; |
|
| 47 | - |
|
| 48 | - if ($pass) { |
|
| 49 | - $row = sql_fetsel( |
|
| 50 | - '*', |
|
| 51 | - 'spip_auteurs', |
|
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | - '', |
|
| 54 | - '', |
|
| 55 | - '', |
|
| 56 | - '', |
|
| 57 | - $serveur |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - // lever un flag si cet auteur peut sauver les cles |
|
| 61 | - if ($row['statut'] === '0minirezo' && $row['webmestre'] === 'oui' && isset($row['backup_cles'])) { |
|
| 62 | - $auteur_peut_sauver_cles = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // login inexistant ou mot de passe vide |
|
| 67 | - if (!$pass || !$row) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $cles = SpipCles::instance(); |
|
| 72 | - $secret = $cles->getSecretAuth(); |
|
| 73 | - |
|
| 74 | - $hash = null; |
|
| 75 | - switch (strlen((string) $row['pass'])) { |
|
| 76 | - // legacy = md5 ou sha256 |
|
| 77 | - case 32: |
|
| 78 | - // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | - $methode = 'md5'; |
|
| 81 | - case 64: |
|
| 82 | - if (empty($hash)) { |
|
| 83 | - // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | - $hash = hash('sha256', $row['alea_actuel'] . $pass); |
|
| 85 | - $methode = 'sha256'; |
|
| 86 | - } |
|
| 87 | - if ($row['pass'] === $hash) { |
|
| 88 | - spip_logger('auth')->debug("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode"); |
|
| 89 | - // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 90 | - if (!empty($row['backup_cles'])) { |
|
| 91 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 97 | - |
|
| 98 | - case 60: |
|
| 99 | - case 98: |
|
| 100 | - default: |
|
| 101 | - // doit-on restaurer un backup des cles ? |
|
| 102 | - // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 103 | - if ( |
|
| 104 | - !$secret |
|
| 105 | - && $auteur_peut_sauver_cles |
|
| 106 | - && !empty($row['backup_cles']) |
|
| 107 | - ) { |
|
| 108 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 109 | - spip_logger('auth')->notice('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur']); |
|
| 110 | - if ($cles->save()) { |
|
| 111 | - $secret = $cles->getSecretAuth(); |
|
| 112 | - } |
|
| 113 | - else { |
|
| 114 | - spip_logger('auth')->error("Echec restauration des cles : verifier les droits d'ecriture ?"); |
|
| 115 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 116 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - else { |
|
| 120 | - spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide"); |
|
| 121 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 126 | - unset($row); |
|
| 127 | - } |
|
| 128 | - else { |
|
| 129 | - spip_logger('auth')->error("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier"); |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 135 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 136 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 137 | - // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 138 | - if (!$secret && $auteur_peut_sauver_cles && auth_spip_initialiser_secret()) { |
|
| 139 | - $secret = $cles->getSecretAuth(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // login/mot de passe incorrect |
|
| 143 | - if (empty($row)) { |
|
| 144 | - return []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // fait tourner le codage du pass dans la base |
|
| 148 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 149 | - if (!$phpauth && $secret) { |
|
| 150 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 151 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 152 | - if ($pass_hash_next) { |
|
| 153 | - $set = [ |
|
| 154 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 155 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 156 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 157 | - ]; |
|
| 158 | - |
|
| 159 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 160 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 161 | - $htpass = generer_htpass($pass); |
|
| 162 | - if (strlen((string) $htpass) !== strlen((string) $row['htpass'])) { |
|
| 163 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 167 | - if ($auteur_peut_sauver_cles) { |
|
| 168 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - @sql_update( |
|
| 172 | - 'spip_auteurs', |
|
| 173 | - $set, |
|
| 174 | - 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 175 | - $row['pass'], |
|
| 176 | - $serveur, |
|
| 177 | - 'text' |
|
| 178 | - ), |
|
| 179 | - [], |
|
| 180 | - $serveur |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 184 | - if (isset($set['htpass'])) { |
|
| 185 | - ecrire_acces(); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // En profiter pour verifier la securite de tmp/ |
|
| 190 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 191 | - if (!verifier_htaccess(_DIR_TMP) && defined('_ECRIRE_INSTALL')) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $row; |
|
| 36 | + $methode = null; |
|
| 37 | + // retrouver le login |
|
| 38 | + $login = auth_spip_retrouver_login($login); |
|
| 39 | + // login inconnu, n'allons pas plus loin |
|
| 40 | + if (!$login) { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $md5pass = ''; |
|
| 45 | + $shapass = $shanext = ''; |
|
| 46 | + $auteur_peut_sauver_cles = false; |
|
| 47 | + |
|
| 48 | + if ($pass) { |
|
| 49 | + $row = sql_fetsel( |
|
| 50 | + '*', |
|
| 51 | + 'spip_auteurs', |
|
| 52 | + 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | + '', |
|
| 54 | + '', |
|
| 55 | + '', |
|
| 56 | + '', |
|
| 57 | + $serveur |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + // lever un flag si cet auteur peut sauver les cles |
|
| 61 | + if ($row['statut'] === '0minirezo' && $row['webmestre'] === 'oui' && isset($row['backup_cles'])) { |
|
| 62 | + $auteur_peut_sauver_cles = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // login inexistant ou mot de passe vide |
|
| 67 | + if (!$pass || !$row) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $cles = SpipCles::instance(); |
|
| 72 | + $secret = $cles->getSecretAuth(); |
|
| 73 | + |
|
| 74 | + $hash = null; |
|
| 75 | + switch (strlen((string) $row['pass'])) { |
|
| 76 | + // legacy = md5 ou sha256 |
|
| 77 | + case 32: |
|
| 78 | + // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | + $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $methode = 'md5'; |
|
| 81 | + case 64: |
|
| 82 | + if (empty($hash)) { |
|
| 83 | + // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | + $hash = hash('sha256', $row['alea_actuel'] . $pass); |
|
| 85 | + $methode = 'sha256'; |
|
| 86 | + } |
|
| 87 | + if ($row['pass'] === $hash) { |
|
| 88 | + spip_logger('auth')->debug("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode"); |
|
| 89 | + // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 90 | + if (!empty($row['backup_cles'])) { |
|
| 91 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 97 | + |
|
| 98 | + case 60: |
|
| 99 | + case 98: |
|
| 100 | + default: |
|
| 101 | + // doit-on restaurer un backup des cles ? |
|
| 102 | + // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 103 | + if ( |
|
| 104 | + !$secret |
|
| 105 | + && $auteur_peut_sauver_cles |
|
| 106 | + && !empty($row['backup_cles']) |
|
| 107 | + ) { |
|
| 108 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 109 | + spip_logger('auth')->notice('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur']); |
|
| 110 | + if ($cles->save()) { |
|
| 111 | + $secret = $cles->getSecretAuth(); |
|
| 112 | + } |
|
| 113 | + else { |
|
| 114 | + spip_logger('auth')->error("Echec restauration des cles : verifier les droits d'ecriture ?"); |
|
| 115 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 116 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + else { |
|
| 120 | + spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide"); |
|
| 121 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 126 | + unset($row); |
|
| 127 | + } |
|
| 128 | + else { |
|
| 129 | + spip_logger('auth')->error("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier"); |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 135 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 136 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 137 | + // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 138 | + if (!$secret && $auteur_peut_sauver_cles && auth_spip_initialiser_secret()) { |
|
| 139 | + $secret = $cles->getSecretAuth(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // login/mot de passe incorrect |
|
| 143 | + if (empty($row)) { |
|
| 144 | + return []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // fait tourner le codage du pass dans la base |
|
| 148 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 149 | + if (!$phpauth && $secret) { |
|
| 150 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 151 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 152 | + if ($pass_hash_next) { |
|
| 153 | + $set = [ |
|
| 154 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 155 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 156 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 157 | + ]; |
|
| 158 | + |
|
| 159 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 160 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 161 | + $htpass = generer_htpass($pass); |
|
| 162 | + if (strlen((string) $htpass) !== strlen((string) $row['htpass'])) { |
|
| 163 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 167 | + if ($auteur_peut_sauver_cles) { |
|
| 168 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + @sql_update( |
|
| 172 | + 'spip_auteurs', |
|
| 173 | + $set, |
|
| 174 | + 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 175 | + $row['pass'], |
|
| 176 | + $serveur, |
|
| 177 | + 'text' |
|
| 178 | + ), |
|
| 179 | + [], |
|
| 180 | + $serveur |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 184 | + if (isset($set['htpass'])) { |
|
| 185 | + ecrire_acces(); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // En profiter pour verifier la securite de tmp/ |
|
| 190 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 191 | + if (!verifier_htaccess(_DIR_TMP) && defined('_ECRIRE_INSTALL')) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $row; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -208,36 +208,36 @@ discard block |
||
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | 210 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 211 | - $cles = SpipCles::instance(); |
|
| 212 | - $secret = $cles->getSecretAuth(); |
|
| 213 | - |
|
| 214 | - // on ne fait rien si on a un secret dispo |
|
| 215 | - if ($secret) { |
|
| 216 | - return false; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 220 | - if ($force) { |
|
| 221 | - spip_logger('auth')->notice('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides'); |
|
| 222 | - $secret = $cles->getSecretAuth(true); |
|
| 223 | - return true; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 227 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 228 | - if ($has_backup === []) { |
|
| 229 | - spip_logger('auth')->notice("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides"); |
|
| 230 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 231 | - return true; |
|
| 232 | - } |
|
| 233 | - spip_logger('auth')->error("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?"); |
|
| 234 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 235 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 236 | - } |
|
| 237 | - else { |
|
| 238 | - spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles'); |
|
| 239 | - } |
|
| 240 | - return false; |
|
| 211 | + $cles = SpipCles::instance(); |
|
| 212 | + $secret = $cles->getSecretAuth(); |
|
| 213 | + |
|
| 214 | + // on ne fait rien si on a un secret dispo |
|
| 215 | + if ($secret) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 220 | + if ($force) { |
|
| 221 | + spip_logger('auth')->notice('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides'); |
|
| 222 | + $secret = $cles->getSecretAuth(true); |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 227 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 228 | + if ($has_backup === []) { |
|
| 229 | + spip_logger('auth')->notice("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides"); |
|
| 230 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 231 | + return true; |
|
| 232 | + } |
|
| 233 | + spip_logger('auth')->error("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?"); |
|
| 234 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 235 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 236 | + } |
|
| 237 | + else { |
|
| 238 | + spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles'); |
|
| 239 | + } |
|
| 240 | + return false; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -247,19 +247,19 @@ discard block |
||
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | function auth_spip_formulaire_login($flux) { |
| 250 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 251 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 252 | - $flux['data'] .= |
|
| 253 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 254 | - . "$js\n" |
|
| 255 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 256 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 257 | - . "'informe_auteur_en_cours':false," |
|
| 258 | - . "'attente_informe':0};" |
|
| 259 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 260 | - . '/*]]>*/</script>'; |
|
| 261 | - |
|
| 262 | - return $flux; |
|
| 250 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 251 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 252 | + $flux['data'] .= |
|
| 253 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 254 | + . "$js\n" |
|
| 255 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 256 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 257 | + . "'informe_auteur_en_cours':false," |
|
| 258 | + . "'attente_informe':0};" |
|
| 259 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 260 | + . '/*]]>*/</script>'; |
|
| 261 | + |
|
| 262 | + return $flux; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -271,8 +271,8 @@ discard block |
||
| 271 | 271 | * toujours true pour un auteur cree dans SPIP |
| 272 | 272 | */ |
| 273 | 273 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 274 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 275 | - return !strlen($serveur); |
|
| 274 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 275 | + return !strlen($serveur); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -286,25 +286,25 @@ discard block |
||
| 286 | 286 | * message d'erreur si login non valide, chaine vide sinon |
| 287 | 287 | */ |
| 288 | 288 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 289 | - // login et mot de passe |
|
| 290 | - if (strlen($new_login)) { |
|
| 291 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 292 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 293 | - } else { |
|
| 294 | - $n = sql_countsel( |
|
| 295 | - 'spip_auteurs', |
|
| 296 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 297 | - '', |
|
| 298 | - '', |
|
| 299 | - $serveur |
|
| 300 | - ); |
|
| 301 | - if ($n) { |
|
| 302 | - return _T('info_login_existant'); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return ''; |
|
| 289 | + // login et mot de passe |
|
| 290 | + if (strlen($new_login)) { |
|
| 291 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 292 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 293 | + } else { |
|
| 294 | + $n = sql_countsel( |
|
| 295 | + 'spip_auteurs', |
|
| 296 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 297 | + '', |
|
| 298 | + '', |
|
| 299 | + $serveur |
|
| 300 | + ); |
|
| 301 | + if ($n) { |
|
| 302 | + return _T('info_login_existant'); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return ''; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -316,41 +316,41 @@ discard block |
||
| 316 | 316 | * @return bool |
| 317 | 317 | */ |
| 318 | 318 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 319 | - if (is_null($new_login) || auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - if ( |
|
| 323 | - !($id_auteur = (int) $id_auteur) |
|
| 324 | - || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | - ) { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - if ($new_login == $auteur['login']) { |
|
| 329 | - return true; |
|
| 330 | - } // on a rien fait mais c'est bon ! |
|
| 331 | - |
|
| 332 | - include_spip('action/editer_auteur'); |
|
| 333 | - |
|
| 334 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 335 | - if (strlen($new_login)) { |
|
| 336 | - $anciens = sql_allfetsel( |
|
| 337 | - 'id_auteur', |
|
| 338 | - 'spip_auteurs', |
|
| 339 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 340 | - '', |
|
| 341 | - '', |
|
| 342 | - '', |
|
| 343 | - '', |
|
| 344 | - $serveur |
|
| 345 | - ); |
|
| 346 | - while ($row = array_pop($anciens)) { |
|
| 347 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 352 | - |
|
| 353 | - return true; |
|
| 319 | + if (is_null($new_login) || auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + if ( |
|
| 323 | + !($id_auteur = (int) $id_auteur) |
|
| 324 | + || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | + ) { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + if ($new_login == $auteur['login']) { |
|
| 329 | + return true; |
|
| 330 | + } // on a rien fait mais c'est bon ! |
|
| 331 | + |
|
| 332 | + include_spip('action/editer_auteur'); |
|
| 333 | + |
|
| 334 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 335 | + if (strlen($new_login)) { |
|
| 336 | + $anciens = sql_allfetsel( |
|
| 337 | + 'id_auteur', |
|
| 338 | + 'spip_auteurs', |
|
| 339 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 340 | + '', |
|
| 341 | + '', |
|
| 342 | + '', |
|
| 343 | + '', |
|
| 344 | + $serveur |
|
| 345 | + ); |
|
| 346 | + while ($row = array_pop($anciens)) { |
|
| 347 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 352 | + |
|
| 353 | + return true; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -362,44 +362,44 @@ discard block |
||
| 362 | 362 | * @return string |
| 363 | 363 | */ |
| 364 | 364 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 365 | - if (!strlen($login)) { |
|
| 366 | - return null; |
|
| 367 | - } // pas la peine de requeter |
|
| 368 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 369 | - if ( |
|
| 370 | - $r = sql_getfetsel( |
|
| 371 | - 'login', |
|
| 372 | - 'spip_auteurs', |
|
| 373 | - "statut<>'5poubelle'" . |
|
| 374 | - ' AND (length(pass)>0)' . |
|
| 375 | - " AND (login=$l)", |
|
| 376 | - '', |
|
| 377 | - '', |
|
| 378 | - '', |
|
| 379 | - '', |
|
| 380 | - $serveur |
|
| 381 | - ) |
|
| 382 | - ) { |
|
| 383 | - return $r; |
|
| 384 | - } |
|
| 385 | - // Si pas d'auteur avec ce login |
|
| 386 | - // regarder s'il a saisi son nom ou son mail. |
|
| 387 | - // Ne pas fusionner avec la requete precedente |
|
| 388 | - // car un nom peut etre homonyme d'un autre login |
|
| 389 | - else { |
|
| 390 | - return sql_getfetsel( |
|
| 391 | - 'login', |
|
| 392 | - 'spip_auteurs', |
|
| 393 | - "statut<>'5poubelle'" . |
|
| 394 | - ' AND (length(pass)>0)' . |
|
| 395 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 396 | - '', |
|
| 397 | - '', |
|
| 398 | - '', |
|
| 399 | - '', |
|
| 400 | - $serveur |
|
| 401 | - ); |
|
| 402 | - } |
|
| 365 | + if (!strlen($login)) { |
|
| 366 | + return null; |
|
| 367 | + } // pas la peine de requeter |
|
| 368 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 369 | + if ( |
|
| 370 | + $r = sql_getfetsel( |
|
| 371 | + 'login', |
|
| 372 | + 'spip_auteurs', |
|
| 373 | + "statut<>'5poubelle'" . |
|
| 374 | + ' AND (length(pass)>0)' . |
|
| 375 | + " AND (login=$l)", |
|
| 376 | + '', |
|
| 377 | + '', |
|
| 378 | + '', |
|
| 379 | + '', |
|
| 380 | + $serveur |
|
| 381 | + ) |
|
| 382 | + ) { |
|
| 383 | + return $r; |
|
| 384 | + } |
|
| 385 | + // Si pas d'auteur avec ce login |
|
| 386 | + // regarder s'il a saisi son nom ou son mail. |
|
| 387 | + // Ne pas fusionner avec la requete precedente |
|
| 388 | + // car un nom peut etre homonyme d'un autre login |
|
| 389 | + else { |
|
| 390 | + return sql_getfetsel( |
|
| 391 | + 'login', |
|
| 392 | + 'spip_auteurs', |
|
| 393 | + "statut<>'5poubelle'" . |
|
| 394 | + ' AND (length(pass)>0)' . |
|
| 395 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 396 | + '', |
|
| 397 | + '', |
|
| 398 | + '', |
|
| 399 | + '', |
|
| 400 | + $serveur |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | * toujours true pour un auteur cree dans SPIP |
| 411 | 411 | */ |
| 412 | 412 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 413 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 414 | - return !strlen($serveur); |
|
| 413 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 414 | + return !strlen($serveur); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -432,12 +432,12 @@ discard block |
||
| 432 | 432 | * message d'erreur si login non valide, chaine vide sinon |
| 433 | 433 | */ |
| 434 | 434 | function auth_spip_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 435 | - // login et mot de passe |
|
| 436 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 437 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 438 | - } |
|
| 435 | + // login et mot de passe |
|
| 436 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 437 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - return ''; |
|
| 440 | + return ''; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -451,47 +451,47 @@ discard block |
||
| 451 | 451 | * @return bool |
| 452 | 452 | */ |
| 453 | 453 | function auth_spip_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 454 | - if (is_null($new_pass) || auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - if ( |
|
| 459 | - !($id_auteur = (int) $id_auteur) |
|
| 460 | - || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | - ) { |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $cles = SpipCles::instance(); |
|
| 466 | - $secret = $cles->getSecretAuth(); |
|
| 467 | - if (!$secret) { |
|
| 468 | - if (auth_spip_initialiser_secret()) { |
|
| 469 | - $secret = $cles->getSecretAuth(); |
|
| 470 | - } |
|
| 471 | - else { |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - include_spip('inc/acces'); |
|
| 478 | - $set = [ |
|
| 479 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 480 | - 'htpass' => generer_htpass($new_pass), |
|
| 481 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 482 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 483 | - 'low_sec' => '', |
|
| 484 | - ]; |
|
| 485 | - |
|
| 486 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 487 | - if ($auteur['statut'] === '0minirezo' && $auteur['webmestre'] === 'oui') { |
|
| 488 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - include_spip('action/editer_auteur'); |
|
| 492 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 493 | - |
|
| 494 | - return true; // on a bien modifie le pass |
|
| 454 | + if (is_null($new_pass) || auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + if ( |
|
| 459 | + !($id_auteur = (int) $id_auteur) |
|
| 460 | + || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | + ) { |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $cles = SpipCles::instance(); |
|
| 466 | + $secret = $cles->getSecretAuth(); |
|
| 467 | + if (!$secret) { |
|
| 468 | + if (auth_spip_initialiser_secret()) { |
|
| 469 | + $secret = $cles->getSecretAuth(); |
|
| 470 | + } |
|
| 471 | + else { |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + include_spip('inc/acces'); |
|
| 478 | + $set = [ |
|
| 479 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 480 | + 'htpass' => generer_htpass($new_pass), |
|
| 481 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 482 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 483 | + 'low_sec' => '', |
|
| 484 | + ]; |
|
| 485 | + |
|
| 486 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 487 | + if ($auteur['statut'] === '0minirezo' && $auteur['webmestre'] === 'oui') { |
|
| 488 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + include_spip('action/editer_auteur'); |
|
| 492 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 493 | + |
|
| 494 | + return true; // on a bien modifie le pass |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -505,54 +505,54 @@ discard block |
||
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | 507 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 508 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 509 | - if (strlen($serveur)) { |
|
| 510 | - return; |
|
| 511 | - } |
|
| 512 | - // si un login, pass ou statut a ete modifie |
|
| 513 | - // regenerer les fichier htpass |
|
| 514 | - if ( |
|
| 515 | - isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
|
| 516 | - ) { |
|
| 517 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 518 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 519 | - |
|
| 520 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 521 | - // par exemple acces_restreint ; |
|
| 522 | - // si .htaccess existe, outrepasser spip_meta |
|
| 523 | - if ( |
|
| 524 | - (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 525 | - ) { |
|
| 526 | - spip_unlink($htpasswd); |
|
| 527 | - spip_unlink($htpasswd . '-admin'); |
|
| 528 | - |
|
| 529 | - return; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 533 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 534 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 535 | - |
|
| 536 | - $p1 = ''; // login:htpass pour tous |
|
| 537 | - $p2 = ''; // login:htpass pour les admins |
|
| 538 | - $s = sql_select( |
|
| 539 | - 'login, htpass, statut', |
|
| 540 | - 'spip_auteurs', |
|
| 541 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 542 | - ); |
|
| 543 | - while ($t = sql_fetch($s)) { |
|
| 544 | - if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
|
| 545 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 546 | - if ($t['statut'] == '0minirezo') { |
|
| 547 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - sql_free($s); |
|
| 552 | - if ($p1) { |
|
| 553 | - ecrire_fichier($htpasswd, $p1); |
|
| 554 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 555 | - spip_logger()->info("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 556 | - } |
|
| 557 | - } |
|
| 508 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 509 | + if (strlen($serveur)) { |
|
| 510 | + return; |
|
| 511 | + } |
|
| 512 | + // si un login, pass ou statut a ete modifie |
|
| 513 | + // regenerer les fichier htpass |
|
| 514 | + if ( |
|
| 515 | + isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
|
| 516 | + ) { |
|
| 517 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 518 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 519 | + |
|
| 520 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 521 | + // par exemple acces_restreint ; |
|
| 522 | + // si .htaccess existe, outrepasser spip_meta |
|
| 523 | + if ( |
|
| 524 | + (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 525 | + ) { |
|
| 526 | + spip_unlink($htpasswd); |
|
| 527 | + spip_unlink($htpasswd . '-admin'); |
|
| 528 | + |
|
| 529 | + return; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 533 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 534 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 535 | + |
|
| 536 | + $p1 = ''; // login:htpass pour tous |
|
| 537 | + $p2 = ''; // login:htpass pour les admins |
|
| 538 | + $s = sql_select( |
|
| 539 | + 'login, htpass, statut', |
|
| 540 | + 'spip_auteurs', |
|
| 541 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 542 | + ); |
|
| 543 | + while ($t = sql_fetch($s)) { |
|
| 544 | + if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
|
| 545 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 546 | + if ($t['statut'] == '0minirezo') { |
|
| 547 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + sql_free($s); |
|
| 552 | + if ($p1) { |
|
| 553 | + ecrire_fichier($htpasswd, $p1); |
|
| 554 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 555 | + spip_logger()->info("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | 558 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $row = sql_fetsel( |
| 50 | 50 | '*', |
| 51 | 51 | 'spip_auteurs', |
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | + 'login='.sql_quote($login, $serveur, 'text')." AND statut<>'5poubelle'", |
|
| 53 | 53 | '', |
| 54 | 54 | '', |
| 55 | 55 | '', |
@@ -76,19 +76,19 @@ discard block |
||
| 76 | 76 | // legacy = md5 ou sha256 |
| 77 | 77 | case 32: |
| 78 | 78 | // tres anciens mots de passe encodes en md5(alea.pass) |
| 79 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 79 | + $hash = md5($row['alea_actuel'].$pass); |
|
| 80 | 80 | $methode = 'md5'; |
| 81 | 81 | case 64: |
| 82 | 82 | if (empty($hash)) { |
| 83 | 83 | // anciens mots de passe encodes en sha256(alea.pass) |
| 84 | - $hash = hash('sha256', $row['alea_actuel'] . $pass); |
|
| 84 | + $hash = hash('sha256', $row['alea_actuel'].$pass); |
|
| 85 | 85 | $methode = 'sha256'; |
| 86 | 86 | } |
| 87 | 87 | if ($row['pass'] === $hash) { |
| 88 | - spip_logger('auth')->debug("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode"); |
|
| 88 | + spip_logger('auth')->debug("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode"); |
|
| 89 | 89 | // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
| 90 | 90 | if (!empty($row['backup_cles'])) { |
| 91 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 91 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.(int) $row['id_auteur']); |
|
| 92 | 92 | } |
| 93 | 93 | break; |
| 94 | 94 | } |
@@ -106,19 +106,19 @@ discard block |
||
| 106 | 106 | && !empty($row['backup_cles']) |
| 107 | 107 | ) { |
| 108 | 108 | if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
| 109 | - spip_logger('auth')->notice('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur']); |
|
| 109 | + spip_logger('auth')->notice('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur']); |
|
| 110 | 110 | if ($cles->save()) { |
| 111 | 111 | $secret = $cles->getSecretAuth(); |
| 112 | 112 | } |
| 113 | 113 | else { |
| 114 | 114 | spip_logger('auth')->error("Echec restauration des cles : verifier les droits d'ecriture ?"); |
| 115 | 115 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 116 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 116 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | else { |
| 120 | - spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide"); |
|
| 121 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 120 | + spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide"); |
|
| 121 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.(int) $row['id_auteur']); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | unset($row); |
| 127 | 127 | } |
| 128 | 128 | else { |
| 129 | - spip_logger('auth')->error("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier"); |
|
| 129 | + spip_logger('auth')->error("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier"); |
|
| 130 | 130 | } |
| 131 | 131 | break; |
| 132 | 132 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | @sql_update( |
| 172 | 172 | 'spip_auteurs', |
| 173 | 173 | $set, |
| 174 | - 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 174 | + 'id_auteur='.(int) $row['id_auteur'].' AND pass='.sql_quote( |
|
| 175 | 175 | $row['pass'], |
| 176 | 176 | $serveur, |
| 177 | 177 | 'text' |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | return true; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 226 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''"); |
|
| 227 | 227 | $has_backup = array_column($has_backup, 'id_auteur'); |
| 228 | 228 | if ($has_backup === []) { |
| 229 | 229 | spip_logger('auth')->notice("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides"); |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | } |
| 233 | 233 | spip_logger('auth')->error("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?"); |
| 234 | 234 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 235 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 235 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 236 | 236 | } |
| 237 | 237 | else { |
| 238 | - spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles'); |
|
| 238 | + spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #'.implode(', #', $has_backup).' doit se connecter pour restaurer son backup des cles'); |
|
| 239 | 239 | } |
| 240 | 240 | return false; |
| 241 | 241 | } |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | $flux['data'] .= |
| 253 | 253 | '<script type="text/javascript">/*<![CDATA[*/' |
| 254 | 254 | . "$js\n" |
| 255 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 256 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 255 | + . "var login_info={'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 256 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 257 | 257 | . "'informe_auteur_en_cours':false," |
| 258 | 258 | . "'attente_informe':0};" |
| 259 | 259 | . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | } else { |
| 294 | 294 | $n = sql_countsel( |
| 295 | 295 | 'spip_auteurs', |
| 296 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 296 | + 'login='.sql_quote($new_login).' AND id_auteur!='.(int) $id_auteur." AND statut!='5poubelle'", |
|
| 297 | 297 | '', |
| 298 | 298 | '', |
| 299 | 299 | $serveur |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | if ( |
| 323 | 323 | !($id_auteur = (int) $id_auteur) |
| 324 | - || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 324 | + || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.(int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | 325 | ) { |
| 326 | 326 | return false; |
| 327 | 327 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | $anciens = sql_allfetsel( |
| 337 | 337 | 'id_auteur', |
| 338 | 338 | 'spip_auteurs', |
| 339 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 339 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", |
|
| 340 | 340 | '', |
| 341 | 341 | '', |
| 342 | 342 | '', |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | $r = sql_getfetsel( |
| 371 | 371 | 'login', |
| 372 | 372 | 'spip_auteurs', |
| 373 | - "statut<>'5poubelle'" . |
|
| 374 | - ' AND (length(pass)>0)' . |
|
| 373 | + "statut<>'5poubelle'". |
|
| 374 | + ' AND (length(pass)>0)'. |
|
| 375 | 375 | " AND (login=$l)", |
| 376 | 376 | '', |
| 377 | 377 | '', |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | return sql_getfetsel( |
| 391 | 391 | 'login', |
| 392 | 392 | 'spip_auteurs', |
| 393 | - "statut<>'5poubelle'" . |
|
| 394 | - ' AND (length(pass)>0)' . |
|
| 393 | + "statut<>'5poubelle'". |
|
| 394 | + ' AND (length(pass)>0)'. |
|
| 395 | 395 | " AND (login<>'' AND (nom=$l OR email=$l))", |
| 396 | 396 | '', |
| 397 | 397 | '', |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | if ( |
| 459 | 459 | !($id_auteur = (int) $id_auteur) |
| 460 | - || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 460 | + || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.(int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | 461 | ) { |
| 462 | 462 | return false; |
| 463 | 463 | } |
@@ -514,8 +514,8 @@ discard block |
||
| 514 | 514 | if ( |
| 515 | 515 | isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
| 516 | 516 | ) { |
| 517 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 518 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 517 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 518 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 519 | 519 | |
| 520 | 520 | // Cette variable de configuration peut etre posee par un plugin |
| 521 | 521 | // par exemple acces_restreint ; |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
| 525 | 525 | ) { |
| 526 | 526 | spip_unlink($htpasswd); |
| 527 | - spip_unlink($htpasswd . '-admin'); |
|
| 527 | + spip_unlink($htpasswd.'-admin'); |
|
| 528 | 528 | |
| 529 | 529 | return; |
| 530 | 530 | } |
@@ -542,16 +542,16 @@ discard block |
||
| 542 | 542 | ); |
| 543 | 543 | while ($t = sql_fetch($s)) { |
| 544 | 544 | if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
| 545 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 545 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 546 | 546 | if ($t['statut'] == '0minirezo') { |
| 547 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 547 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | sql_free($s); |
| 552 | 552 | if ($p1) { |
| 553 | 553 | ecrire_fichier($htpasswd, $p1); |
| 554 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 554 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 555 | 555 | spip_logger()->info("Ecriture de $htpasswd et $htpasswd-admin"); |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -109,14 +109,12 @@ discard block |
||
| 109 | 109 | spip_logger('auth')->notice('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur']); |
| 110 | 110 | if ($cles->save()) { |
| 111 | 111 | $secret = $cles->getSecretAuth(); |
| 112 | - } |
|
| 113 | - else { |
|
| 112 | + } else { |
|
| 114 | 113 | spip_logger('auth')->error("Echec restauration des cles : verifier les droits d'ecriture ?"); |
| 115 | 114 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 116 | 115 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 117 | 116 | } |
| 118 | - } |
|
| 119 | - else { |
|
| 117 | + } else { |
|
| 120 | 118 | spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide"); |
| 121 | 119 | sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
| 122 | 120 | } |
@@ -124,8 +122,7 @@ discard block |
||
| 124 | 122 | |
| 125 | 123 | if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
| 126 | 124 | unset($row); |
| 127 | - } |
|
| 128 | - else { |
|
| 125 | + } else { |
|
| 129 | 126 | spip_logger('auth')->error("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier"); |
| 130 | 127 | } |
| 131 | 128 | break; |
@@ -233,8 +230,7 @@ discard block |
||
| 233 | 230 | spip_logger('auth')->error("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?"); |
| 234 | 231 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 235 | 232 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 236 | - } |
|
| 237 | - else { |
|
| 233 | + } else { |
|
| 238 | 234 | spip_logger('auth')->error('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles'); |
| 239 | 235 | } |
| 240 | 236 | return false; |
@@ -467,8 +463,7 @@ discard block |
||
| 467 | 463 | if (!$secret) { |
| 468 | 464 | if (auth_spip_initialiser_secret()) { |
| 469 | 465 | $secret = $cles->getSecretAuth(); |
| 470 | - } |
|
| 471 | - else { |
|
| 466 | + } else { |
|
| 472 | 467 | return false; |
| 473 | 468 | } |
| 474 | 469 | } |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 25 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | * Description de la boucle complétée des champs |
| 44 | 44 | */ |
| 45 | 45 | function iterateur_DATA_dist($b) { |
| 46 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | - $b->show = [ |
|
| 48 | - 'field' => [ |
|
| 49 | - 'cle' => 'STRING', |
|
| 50 | - 'valeur' => 'STRING', |
|
| 51 | - '*' => 'ALL' // Champ joker * |
|
| 52 | - ] |
|
| 53 | - ]; |
|
| 54 | - $b->select[] = '.valeur'; |
|
| 55 | - |
|
| 56 | - return $b; |
|
| 46 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | + $b->show = [ |
|
| 48 | + 'field' => [ |
|
| 49 | + 'cle' => 'STRING', |
|
| 50 | + 'valeur' => 'STRING', |
|
| 51 | + '*' => 'ALL' // Champ joker * |
|
| 52 | + ] |
|
| 53 | + ]; |
|
| 54 | + $b->select[] = '.valeur'; |
|
| 55 | + |
|
| 56 | + return $b; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | 70 | function inc_file_to_array_dist($data) { |
| 71 | - return preg_split('/\r?\n/', $data); |
|
| 71 | + return preg_split('/\r?\n/', $data); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function inc_plugins_to_array_dist() { |
| 80 | - include_spip('inc/plugin'); |
|
| 80 | + include_spip('inc/plugin'); |
|
| 81 | 81 | |
| 82 | - return liste_chemin_plugin_actifs(); |
|
| 82 | + return liste_chemin_plugin_actifs(); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | 91 | function inc_xml_to_array_dist($data) { |
| 92 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 92 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | 103 | function inc_object_to_array($object) { |
| 104 | - if (!is_object($object) && !is_array($object)) { |
|
| 105 | - return $object; |
|
| 106 | - } |
|
| 107 | - if (is_object($object)) { |
|
| 108 | - $object = get_object_vars($object); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return array_map('inc_object_to_array', $object); |
|
| 104 | + if (!is_object($object) && !is_array($object)) { |
|
| 105 | + return $object; |
|
| 106 | + } |
|
| 107 | + if (is_object($object)) { |
|
| 108 | + $object = get_object_vars($object); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return array_map('inc_object_to_array', $object); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,20 +118,20 @@ discard block |
||
| 118 | 118 | * @return array|bool |
| 119 | 119 | */ |
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | - # sortir le connecteur de $data |
|
| 122 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | - $serveur = (string)$v[1]; |
|
| 124 | - $req = trim($v[2]); |
|
| 125 | - if ($s = sql_query($req, $serveur)) { |
|
| 126 | - $r = []; |
|
| 127 | - while ($t = sql_fetch($s)) { |
|
| 128 | - $r[] = $t; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $r; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return false; |
|
| 121 | + # sortir le connecteur de $data |
|
| 122 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | + $serveur = (string)$v[1]; |
|
| 124 | + $req = trim($v[2]); |
|
| 125 | + if ($s = sql_query($req, $serveur)) { |
|
| 126 | + $r = []; |
|
| 127 | + while ($t = sql_fetch($s)) { |
|
| 128 | + $r[] = $t; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $r; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @return array|bool |
| 142 | 142 | */ |
| 143 | 143 | function inc_json_to_array_dist($data) { |
| 144 | - try { |
|
| 145 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | - } catch (JsonException $e) { |
|
| 147 | - $json = null; |
|
| 148 | - spip_logger()->info('Failed to parse Json data : ' . $e->getMessage()); |
|
| 149 | - } |
|
| 150 | - return is_array($json) ? (array) $json : []; |
|
| 144 | + try { |
|
| 145 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | + } catch (JsonException $e) { |
|
| 147 | + $json = null; |
|
| 148 | + spip_logger()->info('Failed to parse Json data : ' . $e->getMessage()); |
|
| 149 | + } |
|
| 150 | + return is_array($json) ? (array) $json : []; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,30 +157,30 @@ discard block |
||
| 157 | 157 | * @return array|bool |
| 158 | 158 | */ |
| 159 | 159 | function inc_csv_to_array_dist($data) { |
| 160 | - include_spip('inc/csv'); |
|
| 161 | - [$entete, $csv] = analyse_csv($data); |
|
| 162 | - array_unshift($csv, $entete); |
|
| 163 | - |
|
| 164 | - include_spip('inc/charsets'); |
|
| 165 | - $i = 1; |
|
| 166 | - foreach ($entete as $k => $v) { |
|
| 167 | - if (trim((string) $v) == '') { |
|
| 168 | - $v = 'col' . $i; |
|
| 169 | - } // reperer des eventuelles cases vides |
|
| 170 | - if (is_numeric($v) && $v < 0) { |
|
| 171 | - $v = '__' . $v; |
|
| 172 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | - if (is_numeric($v)) { |
|
| 174 | - $v = '_' . $v; |
|
| 175 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | - $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
|
| 177 | - foreach ($csv as &$item) { |
|
| 178 | - $item[$v] = &$item[$k]; |
|
| 179 | - } |
|
| 180 | - $i++; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $csv; |
|
| 160 | + include_spip('inc/csv'); |
|
| 161 | + [$entete, $csv] = analyse_csv($data); |
|
| 162 | + array_unshift($csv, $entete); |
|
| 163 | + |
|
| 164 | + include_spip('inc/charsets'); |
|
| 165 | + $i = 1; |
|
| 166 | + foreach ($entete as $k => $v) { |
|
| 167 | + if (trim((string) $v) == '') { |
|
| 168 | + $v = 'col' . $i; |
|
| 169 | + } // reperer des eventuelles cases vides |
|
| 170 | + if (is_numeric($v) && $v < 0) { |
|
| 171 | + $v = '__' . $v; |
|
| 172 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | + if (is_numeric($v)) { |
|
| 174 | + $v = '_' . $v; |
|
| 175 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | + $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
|
| 177 | + foreach ($csv as &$item) { |
|
| 178 | + $item[$v] = &$item[$k]; |
|
| 179 | + } |
|
| 180 | + $i++; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $csv; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | * @return array|bool |
| 191 | 191 | */ |
| 192 | 192 | function inc_rss_to_array_dist($data) { |
| 193 | - $tableau = null; |
|
| 194 | - include_spip('inc/syndic'); |
|
| 195 | - if (is_array($rss = analyser_backend($data))) { |
|
| 196 | - $tableau = $rss; |
|
| 197 | - } |
|
| 193 | + $tableau = null; |
|
| 194 | + include_spip('inc/syndic'); |
|
| 195 | + if (is_array($rss = analyser_backend($data))) { |
|
| 196 | + $tableau = $rss; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $tableau; |
|
| 199 | + return $tableau; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @return array|bool |
| 207 | 207 | */ |
| 208 | 208 | function inc_atom_to_array_dist($data) { |
| 209 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 209 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | 210 | |
| 211 | - return $rss_to_array($data); |
|
| 211 | + return $rss_to_array($data); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | * @return array|bool |
| 220 | 220 | */ |
| 221 | 221 | function inc_glob_to_array_dist($data) { |
| 222 | - $a = glob( |
|
| 223 | - $data, |
|
| 224 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | - ); |
|
| 222 | + $a = glob( |
|
| 223 | + $data, |
|
| 224 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | + ); |
|
| 226 | 226 | |
| 227 | - return $a ?: []; |
|
| 227 | + return $a ?: []; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | * @throws Exception |
| 236 | 236 | */ |
| 237 | 237 | function inc_yaml_to_array_dist($data) { |
| 238 | - include_spip('inc/yaml-mini'); |
|
| 239 | - if (!function_exists('yaml_decode')) { |
|
| 240 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 238 | + include_spip('inc/yaml-mini'); |
|
| 239 | + if (!function_exists('yaml_decode')) { |
|
| 240 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 241 | 241 | |
| 242 | - return false; |
|
| 243 | - } |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return yaml_decode($data); |
|
| 245 | + return yaml_decode($data); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -269,23 +269,23 @@ discard block |
||
| 269 | 269 | * @return array|bool |
| 270 | 270 | */ |
| 271 | 271 | function inc_ls_to_array_dist($data) { |
| 272 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | - $a = $glob_to_array($data); |
|
| 274 | - foreach ($a as &$v) { |
|
| 275 | - $b = (array)@stat($v); |
|
| 276 | - foreach (array_keys($b) as $k) { |
|
| 277 | - if (is_numeric($k)) { |
|
| 278 | - unset($b[$k]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 282 | - $v = array_merge( |
|
| 283 | - pathinfo((string) $v), |
|
| 284 | - $b |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return $a; |
|
| 272 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | + $a = $glob_to_array($data); |
|
| 274 | + foreach ($a as &$v) { |
|
| 275 | + $b = (array)@stat($v); |
|
| 276 | + foreach (array_keys($b) as $k) { |
|
| 277 | + if (is_numeric($k)) { |
|
| 278 | + unset($b[$k]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 282 | + $v = array_merge( |
|
| 283 | + pathinfo((string) $v), |
|
| 284 | + $b |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return $a; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | * @return array|bool |
| 296 | 296 | */ |
| 297 | 297 | function XMLObjectToArray($object) { |
| 298 | - $xml_array = []; |
|
| 299 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | - $key .= '-' . uniqid(); |
|
| 302 | - } |
|
| 303 | - $vars = get_object_vars($object->current()); |
|
| 304 | - if (isset($vars['@attributes'])) { |
|
| 305 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | - $xml_array[$key][$k] = $v; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - $xml_array[$key][] = $object->hasChildren() |
|
| 310 | - ? XMLObjectToArray($object->current()) |
|
| 311 | - : (string) $object->current(); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $xml_array; |
|
| 298 | + $xml_array = []; |
|
| 299 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | + $key .= '-' . uniqid(); |
|
| 302 | + } |
|
| 303 | + $vars = get_object_vars($object->current()); |
|
| 304 | + if (isset($vars['@attributes'])) { |
|
| 305 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | + $xml_array[$key][$k] = $v; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + $xml_array[$key][] = $object->hasChildren() |
|
| 310 | + ? XMLObjectToArray($object->current()) |
|
| 311 | + : (string) $object->current(); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $xml_array; |
|
| 315 | 315 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | 121 | # sortir le connecteur de $data |
| 122 | 122 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 123 | - $serveur = (string)$v[1]; |
|
| 123 | + $serveur = (string) $v[1]; |
|
| 124 | 124 | $req = trim($v[2]); |
| 125 | 125 | if ($s = sql_query($req, $serveur)) { |
| 126 | 126 | $r = []; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 146 | 146 | } catch (JsonException $e) { |
| 147 | 147 | $json = null; |
| 148 | - spip_logger()->info('Failed to parse Json data : ' . $e->getMessage()); |
|
| 148 | + spip_logger()->info('Failed to parse Json data : '.$e->getMessage()); |
|
| 149 | 149 | } |
| 150 | 150 | return is_array($json) ? (array) $json : []; |
| 151 | 151 | } |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | $i = 1; |
| 166 | 166 | foreach ($entete as $k => $v) { |
| 167 | 167 | if (trim((string) $v) == '') { |
| 168 | - $v = 'col' . $i; |
|
| 168 | + $v = 'col'.$i; |
|
| 169 | 169 | } // reperer des eventuelles cases vides |
| 170 | 170 | if (is_numeric($v) && $v < 0) { |
| 171 | - $v = '__' . $v; |
|
| 171 | + $v = '__'.$v; |
|
| 172 | 172 | } // ne pas risquer d'ecraser une cle numerique |
| 173 | 173 | if (is_numeric($v)) { |
| 174 | - $v = '_' . $v; |
|
| 174 | + $v = '_'.$v; |
|
| 175 | 175 | } // ne pas risquer d'ecraser une cle numerique |
| 176 | 176 | $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
| 177 | 177 | foreach ($csv as &$item) { |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 273 | 273 | $a = $glob_to_array($data); |
| 274 | 274 | foreach ($a as &$v) { |
| 275 | - $b = (array)@stat($v); |
|
| 275 | + $b = (array) @stat($v); |
|
| 276 | 276 | foreach (array_keys($b) as $k) { |
| 277 | 277 | if (is_numeric($k)) { |
| 278 | 278 | unset($b[$k]); |
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | - $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', (string) $v); |
|
| 282 | 282 | $v = array_merge( |
| 283 | 283 | pathinfo((string) $v), |
| 284 | 284 | $b |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $xml_array = []; |
| 299 | 299 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 300 | 300 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 301 | - $key .= '-' . uniqid(); |
|
| 301 | + $key .= '-'.uniqid(); |
|
| 302 | 302 | } |
| 303 | 303 | $vars = get_object_vars($object->current()); |
| 304 | 304 | if (isset($vars['@attributes'])) { |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Pipelines |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | if (test_espace_prive()) { |
| 21 | - include_spip('inc/pipelines_ecrire'); |
|
| 21 | + include_spip('inc/pipelines_ecrire'); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @return string Contenu qui sera inséré dans le head HTML |
| 45 | 45 | **/ |
| 46 | 46 | function f_jQuery($texte) { |
| 47 | - $x = ''; |
|
| 48 | - $jquery_plugins = pipeline( |
|
| 49 | - 'jquery_plugins', |
|
| 50 | - [ |
|
| 51 | - 'javascript/jquery.js', |
|
| 52 | - 'javascript/jquery.form.js', |
|
| 53 | - 'javascript/jquery.autosave.js', |
|
| 54 | - 'javascript/jquery.placeholder-label.js', |
|
| 55 | - 'javascript/ajaxCallback.js', |
|
| 56 | - 'javascript/js.cookie.js', |
|
| 57 | - ] |
|
| 58 | - ); |
|
| 59 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | - $script = timestamp($script); |
|
| 62 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $x . $texte; |
|
| 47 | + $x = ''; |
|
| 48 | + $jquery_plugins = pipeline( |
|
| 49 | + 'jquery_plugins', |
|
| 50 | + [ |
|
| 51 | + 'javascript/jquery.js', |
|
| 52 | + 'javascript/jquery.form.js', |
|
| 53 | + 'javascript/jquery.autosave.js', |
|
| 54 | + 'javascript/jquery.placeholder-label.js', |
|
| 55 | + 'javascript/ajaxCallback.js', |
|
| 56 | + 'javascript/js.cookie.js', |
|
| 57 | + ] |
|
| 58 | + ); |
|
| 59 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | + $script = timestamp($script); |
|
| 62 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $x . $texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -80,33 +80,33 @@ discard block |
||
| 80 | 80 | * @return string Contenu de la page envoyée au navigateur |
| 81 | 81 | **/ |
| 82 | 82 | function f_tidy($texte) { |
| 83 | - /** |
|
| 84 | - * Indentation à faire ? |
|
| 85 | - * |
|
| 86 | - * - true : actif. |
|
| 87 | - * - false par défaut. |
|
| 88 | - */ |
|
| 89 | - |
|
| 90 | - if ( |
|
| 91 | - $GLOBALS['xhtml'] |
|
| 92 | - && $GLOBALS['html'] |
|
| 93 | - && strlen($texte) |
|
| 94 | - && !headers_sent() |
|
| 95 | - ) { |
|
| 96 | - # Compatibilite ascendante |
|
| 97 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 98 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 102 | - spip_logger()->info("tidy absent, l'indenteur SPIP le remplace"); |
|
| 103 | - $f = charger_fonction('sax', 'xml'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $f($texte); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return $texte; |
|
| 83 | + /** |
|
| 84 | + * Indentation à faire ? |
|
| 85 | + * |
|
| 86 | + * - true : actif. |
|
| 87 | + * - false par défaut. |
|
| 88 | + */ |
|
| 89 | + |
|
| 90 | + if ( |
|
| 91 | + $GLOBALS['xhtml'] |
|
| 92 | + && $GLOBALS['html'] |
|
| 93 | + && strlen($texte) |
|
| 94 | + && !headers_sent() |
|
| 95 | + ) { |
|
| 96 | + # Compatibilite ascendante |
|
| 97 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 98 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 102 | + spip_logger()->info("tidy absent, l'indenteur SPIP le remplace"); |
|
| 103 | + $f = charger_fonction('sax', 'xml'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $f($texte); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $texte; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -125,24 +125,24 @@ discard block |
||
| 125 | 125 | * @return string Contenu de la page envoyée au navigateur |
| 126 | 126 | **/ |
| 127 | 127 | function f_insert_head($texte) { |
| 128 | - if (!$GLOBALS['html']) { |
|
| 129 | - return $texte; |
|
| 130 | - } |
|
| 131 | - include_spip('public/admin'); // pour strripos |
|
| 132 | - |
|
| 133 | - if ( |
|
| 134 | - !($pos = stripos($texte, '</head>')) |
|
| 135 | - && !($pos = stripos($texte, '<body>')) |
|
| 136 | - ) { |
|
| 137 | - $pos = 0; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 141 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 142 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $texte; |
|
| 128 | + if (!$GLOBALS['html']) { |
|
| 129 | + return $texte; |
|
| 130 | + } |
|
| 131 | + include_spip('public/admin'); // pour strripos |
|
| 132 | + |
|
| 133 | + if ( |
|
| 134 | + !($pos = stripos($texte, '</head>')) |
|
| 135 | + && !($pos = stripos($texte, '<body>')) |
|
| 136 | + ) { |
|
| 137 | + $pos = 0; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 141 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 142 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $texte; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -158,34 +158,34 @@ discard block |
||
| 158 | 158 | * @return string Contenu de la page envoyée au navigateur |
| 159 | 159 | **/ |
| 160 | 160 | function f_admin($texte) { |
| 161 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 162 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 163 | - $x = "<div class='spip-previsu' " |
|
| 164 | - . http_style_background('preview-32.png', '', 32) |
|
| 165 | - . '>' |
|
| 166 | - . _T('previsualisation') |
|
| 167 | - . '</div>'; |
|
| 168 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 169 | - $pos = strlen($texte); |
|
| 170 | - } |
|
| 171 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 172 | - // pas de preview en fenetre enfant |
|
| 173 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 174 | - if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
|
| 175 | - $pos = -1; |
|
| 176 | - } |
|
| 177 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 181 | - include_spip('public/admin'); |
|
| 182 | - $texte = affiche_boutons_admin($texte); |
|
| 183 | - } |
|
| 184 | - if (_request('var_mode') == 'noajax') { |
|
| 185 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $texte; |
|
| 161 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 162 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 163 | + $x = "<div class='spip-previsu' " |
|
| 164 | + . http_style_background('preview-32.png', '', 32) |
|
| 165 | + . '>' |
|
| 166 | + . _T('previsualisation') |
|
| 167 | + . '</div>'; |
|
| 168 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 169 | + $pos = strlen($texte); |
|
| 170 | + } |
|
| 171 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 172 | + // pas de preview en fenetre enfant |
|
| 173 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 174 | + if ((!$pos = stripos($texte, '<head')) || (!$pos = strpos($texte, '>', $pos))) { |
|
| 175 | + $pos = -1; |
|
| 176 | + } |
|
| 177 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 181 | + include_spip('public/admin'); |
|
| 182 | + $texte = affiche_boutons_admin($texte); |
|
| 183 | + } |
|
| 184 | + if (_request('var_mode') == 'noajax') { |
|
| 185 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $texte; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @return array $flux Description et contenu de l'inclusion |
| 204 | 204 | **/ |
| 205 | 205 | function f_recuperer_fond($flux) { |
| 206 | - if (!test_espace_prive()) { |
|
| 207 | - return $flux; |
|
| 208 | - } |
|
| 206 | + if (!test_espace_prive()) { |
|
| 207 | + return $flux; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return f_afficher_blocs_ecrire($flux); |
|
| 210 | + return f_afficher_blocs_ecrire($flux); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -221,30 +221,30 @@ discard block |
||
| 221 | 221 | * @return string Contenu de la page envoyée au navigateur |
| 222 | 222 | */ |
| 223 | 223 | function f_queue($texte) { |
| 224 | - // eviter une inclusion si rien a faire |
|
| 225 | - if ( |
|
| 226 | - _request('action') == 'cron' |
|
| 227 | - || queue_sleep_time_to_next_job() > 0 |
|
| 228 | - || defined('_DEBUG_BLOCK_QUEUE') |
|
| 229 | - ) { |
|
| 230 | - return $texte; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - include_spip('inc/queue'); |
|
| 234 | - $code = queue_affichage_cron(); |
|
| 235 | - |
|
| 236 | - // si rien a afficher |
|
| 237 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 238 | - if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 239 | - return $texte; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 243 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 244 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 245 | - } else { |
|
| 246 | - $texte .= $code; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $texte; |
|
| 224 | + // eviter une inclusion si rien a faire |
|
| 225 | + if ( |
|
| 226 | + _request('action') == 'cron' |
|
| 227 | + || queue_sleep_time_to_next_job() > 0 |
|
| 228 | + || defined('_DEBUG_BLOCK_QUEUE') |
|
| 229 | + ) { |
|
| 230 | + return $texte; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + include_spip('inc/queue'); |
|
| 234 | + $code = queue_affichage_cron(); |
|
| 235 | + |
|
| 236 | + // si rien a afficher |
|
| 237 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 238 | + if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 239 | + return $texte; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 243 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 244 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 245 | + } else { |
|
| 246 | + $texte .= $code; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $texte; |
|
| 250 | 250 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -37,133 +37,133 @@ discard block |
||
| 37 | 37 | * @param int $status Code de redirection (301 ou 302) |
| 38 | 38 | **/ |
| 39 | 39 | function redirige_par_entete($url, $equiv = '', $status = 302) { |
| 40 | - if (!in_array($status, [301, 302])) { |
|
| 41 | - $status = 302; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $url = trim(strtr($url, "\n\r", ' ')); |
|
| 45 | - # si l'url de redirection est relative, on la passe en absolue |
|
| 46 | - if (!preg_match(',^(\w+:)?//,', $url)) { |
|
| 47 | - include_spip('inc/filtres_mini'); |
|
| 48 | - $url = url_absolue($url); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if (defined('_AJAX') && _AJAX) { |
|
| 52 | - $url = parametre_url($url, 'var_ajax_redir', 1, '&'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // ne pas laisser passer n'importe quoi dans l'url |
|
| 56 | - $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 57 | - $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url); |
|
| 58 | - while (str_contains($url, '%0A')) { |
|
| 59 | - $url = str_replace('%0A', '', $url); |
|
| 60 | - } |
|
| 61 | - // interdire les url inline avec des pseudo-protocoles : |
|
| 62 | - if ( |
|
| 63 | - preg_match(',data:,i', $url) && preg_match('/base64\s*,/i', $url) || preg_match(',(javascript|mailto):,i', $url) |
|
| 64 | - ) { |
|
| 65 | - $url = './'; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // Il n'y a que sous Apache que setcookie puis redirection fonctionne |
|
| 69 | - include_spip('inc/cookie'); |
|
| 70 | - if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 71 | - define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)'); |
|
| 72 | - } |
|
| 73 | - if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 74 | - define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx'); |
|
| 75 | - } |
|
| 76 | - if ( |
|
| 77 | - !$equiv && !spip_cookie_envoye() |
|
| 78 | - || ( |
|
| 79 | - !empty($_SERVER['SERVER_SOFTWARE']) |
|
| 80 | - && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 81 | - && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 82 | - || !empty($_SERVER['SERVER_SIGNATURE']) |
|
| 83 | - && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 84 | - && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 85 | - || function_exists('apache_getenv') |
|
| 86 | - || defined('_SERVER_APACHE') |
|
| 87 | - ) |
|
| 88 | - ) { |
|
| 89 | - @header('Location: ' . $url); |
|
| 90 | - $equiv = ''; |
|
| 91 | - } else { |
|
| 92 | - @header('Refresh: 0; url=' . $url); |
|
| 93 | - if (isset($GLOBALS['meta']['charset'])) { |
|
| 94 | - @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 95 | - } |
|
| 96 | - $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
|
| 97 | - } |
|
| 98 | - include_spip('inc/lang'); |
|
| 99 | - if ($status != 302) { |
|
| 100 | - http_response_code($status); |
|
| 101 | - } |
|
| 102 | - echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n", |
|
| 103 | - html_lang_attributes(), ' |
|
| 40 | + if (!in_array($status, [301, 302])) { |
|
| 41 | + $status = 302; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $url = trim(strtr($url, "\n\r", ' ')); |
|
| 45 | + # si l'url de redirection est relative, on la passe en absolue |
|
| 46 | + if (!preg_match(',^(\w+:)?//,', $url)) { |
|
| 47 | + include_spip('inc/filtres_mini'); |
|
| 48 | + $url = url_absolue($url); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if (defined('_AJAX') && _AJAX) { |
|
| 52 | + $url = parametre_url($url, 'var_ajax_redir', 1, '&'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // ne pas laisser passer n'importe quoi dans l'url |
|
| 56 | + $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 57 | + $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url); |
|
| 58 | + while (str_contains($url, '%0A')) { |
|
| 59 | + $url = str_replace('%0A', '', $url); |
|
| 60 | + } |
|
| 61 | + // interdire les url inline avec des pseudo-protocoles : |
|
| 62 | + if ( |
|
| 63 | + preg_match(',data:,i', $url) && preg_match('/base64\s*,/i', $url) || preg_match(',(javascript|mailto):,i', $url) |
|
| 64 | + ) { |
|
| 65 | + $url = './'; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // Il n'y a que sous Apache que setcookie puis redirection fonctionne |
|
| 69 | + include_spip('inc/cookie'); |
|
| 70 | + if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 71 | + define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)'); |
|
| 72 | + } |
|
| 73 | + if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 74 | + define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx'); |
|
| 75 | + } |
|
| 76 | + if ( |
|
| 77 | + !$equiv && !spip_cookie_envoye() |
|
| 78 | + || ( |
|
| 79 | + !empty($_SERVER['SERVER_SOFTWARE']) |
|
| 80 | + && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 81 | + && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 82 | + || !empty($_SERVER['SERVER_SIGNATURE']) |
|
| 83 | + && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 84 | + && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 85 | + || function_exists('apache_getenv') |
|
| 86 | + || defined('_SERVER_APACHE') |
|
| 87 | + ) |
|
| 88 | + ) { |
|
| 89 | + @header('Location: ' . $url); |
|
| 90 | + $equiv = ''; |
|
| 91 | + } else { |
|
| 92 | + @header('Refresh: 0; url=' . $url); |
|
| 93 | + if (isset($GLOBALS['meta']['charset'])) { |
|
| 94 | + @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 95 | + } |
|
| 96 | + $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
|
| 97 | + } |
|
| 98 | + include_spip('inc/lang'); |
|
| 99 | + if ($status != 302) { |
|
| 100 | + http_response_code($status); |
|
| 101 | + } |
|
| 102 | + echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n", |
|
| 103 | + html_lang_attributes(), ' |
|
| 104 | 104 | <head>', |
| 105 | - $equiv, ' |
|
| 105 | + $equiv, ' |
|
| 106 | 106 | <title>HTTP ' . $status . '</title> |
| 107 | 107 | ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . ' |
| 108 | 108 | </head> |
| 109 | 109 | <body> |
| 110 | 110 | <h1>HTTP ' . $status . '</h1> |
| 111 | 111 | <a href="', |
| 112 | - quote_amp($url), |
|
| 113 | - '">', |
|
| 114 | - _T('navigateur_pas_redirige'), |
|
| 115 | - '</a></body></html>'; |
|
| 112 | + quote_amp($url), |
|
| 113 | + '">', |
|
| 114 | + _T('navigateur_pas_redirige'), |
|
| 115 | + '</a></body></html>'; |
|
| 116 | 116 | |
| 117 | - spip_logger()->info("redirige $status: $url"); |
|
| 117 | + spip_logger()->info("redirige $status: $url"); |
|
| 118 | 118 | |
| 119 | - exit; |
|
| 119 | + exit; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | function redirige_formulaire($url, $equiv = '', $format = 'message') { |
| 123 | - if ( |
|
| 124 | - !_AJAX |
|
| 125 | - && !headers_sent() |
|
| 126 | - && !_request('var_ajax') |
|
| 127 | - ) { |
|
| 128 | - redirige_par_entete(str_replace('&', '&', (string) $url), $equiv); |
|
| 129 | - } // si c'est une ancre, fixer simplement le window.location.hash |
|
| 130 | - elseif ($format == 'ajaxform' && preg_match(',^#[0-9a-z\-_]+$,i', (string) $url)) { |
|
| 131 | - return [ |
|
| 132 | - // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 133 | - "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>", |
|
| 134 | - // et rien dans le message ok |
|
| 135 | - '' |
|
| 136 | - ]; |
|
| 137 | - } else { |
|
| 138 | - // ne pas laisser passer n'importe quoi dans l'url |
|
| 139 | - $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 140 | - |
|
| 141 | - $url = strtr($url, "\n\r", ' '); |
|
| 142 | - # en theorie on devrait faire ca tout le temps, mais quand la chaine |
|
| 143 | - # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne |
|
| 144 | - if ($url[0] == '?') { |
|
| 145 | - $url = url_de_base() . $url; |
|
| 146 | - } |
|
| 147 | - $url = str_replace('&', '&', (string) $url); |
|
| 148 | - spip_logger()->info("redirige formulaire ajax: $url"); |
|
| 149 | - include_spip('inc/filtres'); |
|
| 150 | - if ($format == 'ajaxform') { |
|
| 151 | - return [ |
|
| 152 | - // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 153 | - '<a href="' . quote_amp($url) . '" name="ajax_redirect" style="display:none;">' . _T('navigateur_pas_redirige') . '</a>', |
|
| 154 | - // et un message au cas ou |
|
| 155 | - '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>' |
|
| 156 | - ]; |
|
| 157 | - } else // format message texte, tout en js inline |
|
| 158 | - { |
|
| 159 | - return |
|
| 160 | - // ie poste les formulaires dans une iframe, il faut donc rediriger son parent |
|
| 161 | - "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>" |
|
| 162 | - . http_img_pack('loader.svg', '', " class='loader'") |
|
| 163 | - . '<br />' |
|
| 164 | - . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'; |
|
| 165 | - } |
|
| 166 | - } |
|
| 123 | + if ( |
|
| 124 | + !_AJAX |
|
| 125 | + && !headers_sent() |
|
| 126 | + && !_request('var_ajax') |
|
| 127 | + ) { |
|
| 128 | + redirige_par_entete(str_replace('&', '&', (string) $url), $equiv); |
|
| 129 | + } // si c'est une ancre, fixer simplement le window.location.hash |
|
| 130 | + elseif ($format == 'ajaxform' && preg_match(',^#[0-9a-z\-_]+$,i', (string) $url)) { |
|
| 131 | + return [ |
|
| 132 | + // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 133 | + "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>", |
|
| 134 | + // et rien dans le message ok |
|
| 135 | + '' |
|
| 136 | + ]; |
|
| 137 | + } else { |
|
| 138 | + // ne pas laisser passer n'importe quoi dans l'url |
|
| 139 | + $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 140 | + |
|
| 141 | + $url = strtr($url, "\n\r", ' '); |
|
| 142 | + # en theorie on devrait faire ca tout le temps, mais quand la chaine |
|
| 143 | + # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne |
|
| 144 | + if ($url[0] == '?') { |
|
| 145 | + $url = url_de_base() . $url; |
|
| 146 | + } |
|
| 147 | + $url = str_replace('&', '&', (string) $url); |
|
| 148 | + spip_logger()->info("redirige formulaire ajax: $url"); |
|
| 149 | + include_spip('inc/filtres'); |
|
| 150 | + if ($format == 'ajaxform') { |
|
| 151 | + return [ |
|
| 152 | + // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 153 | + '<a href="' . quote_amp($url) . '" name="ajax_redirect" style="display:none;">' . _T('navigateur_pas_redirige') . '</a>', |
|
| 154 | + // et un message au cas ou |
|
| 155 | + '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>' |
|
| 156 | + ]; |
|
| 157 | + } else // format message texte, tout en js inline |
|
| 158 | + { |
|
| 159 | + return |
|
| 160 | + // ie poste les formulaires dans une iframe, il faut donc rediriger son parent |
|
| 161 | + "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>" |
|
| 162 | + . http_img_pack('loader.svg', '', " class='loader'") |
|
| 163 | + . '<br />' |
|
| 164 | + . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -184,27 +184,27 @@ discard block |
||
| 184 | 184 | * @return void |
| 185 | 185 | **/ |
| 186 | 186 | function redirige_url_ecrire($script = '', $args = '', $equiv = '') { |
| 187 | - return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv); |
|
| 187 | + return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache |
| 191 | 191 | function http_no_cache() { |
| 192 | - if (headers_sent()) { |
|
| 193 | - spip_logger()->info('http_no_cache arrive trop tard'); |
|
| 194 | - |
|
| 195 | - return; |
|
| 196 | - } |
|
| 197 | - $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; |
|
| 198 | - |
|
| 199 | - // selon http://developer.apple.com/internet/safari/faq.html#anchor5 |
|
| 200 | - // il faudrait aussi pour Safari |
|
| 201 | - // header("Cache-Control: post-check=0, pre-check=0", false) |
|
| 202 | - // mais ca ne respecte pas |
|
| 203 | - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 |
|
| 204 | - |
|
| 205 | - header("Content-Type: text/html; charset=$charset"); |
|
| 206 | - header('Expires: 0'); |
|
| 207 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 208 | - header('Cache-Control: no-cache, must-revalidate'); |
|
| 209 | - header('Pragma: no-cache'); |
|
| 192 | + if (headers_sent()) { |
|
| 193 | + spip_logger()->info('http_no_cache arrive trop tard'); |
|
| 194 | + |
|
| 195 | + return; |
|
| 196 | + } |
|
| 197 | + $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; |
|
| 198 | + |
|
| 199 | + // selon http://developer.apple.com/internet/safari/faq.html#anchor5 |
|
| 200 | + // il faudrait aussi pour Safari |
|
| 201 | + // header("Cache-Control: post-check=0, pre-check=0", false) |
|
| 202 | + // mais ca ne respecte pas |
|
| 203 | + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 |
|
| 204 | + |
|
| 205 | + header("Content-Type: text/html; charset=$charset"); |
|
| 206 | + header('Expires: 0'); |
|
| 207 | + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 208 | + header('Cache-Control: no-cache, must-revalidate'); |
|
| 209 | + header('Pragma: no-cache'); |
|
| 210 | 210 | } |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | || ( |
| 79 | 79 | !empty($_SERVER['SERVER_SOFTWARE']) |
| 80 | 80 | && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE |
| 81 | - && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 81 | + && preg_match('/'._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE.'/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 82 | 82 | || !empty($_SERVER['SERVER_SIGNATURE']) |
| 83 | 83 | && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE |
| 84 | - && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 84 | + && preg_match('/'._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE.'/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 85 | 85 | || function_exists('apache_getenv') |
| 86 | 86 | || defined('_SERVER_APACHE') |
| 87 | 87 | ) |
| 88 | 88 | ) { |
| 89 | - @header('Location: ' . $url); |
|
| 89 | + @header('Location: '.$url); |
|
| 90 | 90 | $equiv = ''; |
| 91 | 91 | } else { |
| 92 | - @header('Refresh: 0; url=' . $url); |
|
| 92 | + @header('Refresh: 0; url='.$url); |
|
| 93 | 93 | if (isset($GLOBALS['meta']['charset'])) { |
| 94 | - @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 94 | + @header('Content-Type: text/html; charset='.$GLOBALS['meta']['charset']); |
|
| 95 | 95 | } |
| 96 | 96 | $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
| 97 | 97 | } |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | html_lang_attributes(), ' |
| 104 | 104 | <head>', |
| 105 | 105 | $equiv, ' |
| 106 | -<title>HTTP ' . $status . '</title> |
|
| 107 | -' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . ' |
|
| 106 | +<title>HTTP ' . $status.'</title> |
|
| 107 | +' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset='.$GLOBALS['meta']['charset'].'">' : '').' |
|
| 108 | 108 | </head> |
| 109 | 109 | <body> |
| 110 | -<h1>HTTP ' . $status . '</h1> |
|
| 110 | +<h1>HTTP ' . $status.'</h1> |
|
| 111 | 111 | <a href="', |
| 112 | 112 | quote_amp($url), |
| 113 | 113 | '">', |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | # en theorie on devrait faire ca tout le temps, mais quand la chaine |
| 143 | 143 | # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne |
| 144 | 144 | if ($url[0] == '?') { |
| 145 | - $url = url_de_base() . $url; |
|
| 145 | + $url = url_de_base().$url; |
|
| 146 | 146 | } |
| 147 | 147 | $url = str_replace('&', '&', (string) $url); |
| 148 | 148 | spip_logger()->info("redirige formulaire ajax: $url"); |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | if ($format == 'ajaxform') { |
| 151 | 151 | return [ |
| 152 | 152 | // on renvoie un lien masque qui sera traite par ajaxCallback.js |
| 153 | - '<a href="' . quote_amp($url) . '" name="ajax_redirect" style="display:none;">' . _T('navigateur_pas_redirige') . '</a>', |
|
| 153 | + '<a href="'.quote_amp($url).'" name="ajax_redirect" style="display:none;">'._T('navigateur_pas_redirige').'</a>', |
|
| 154 | 154 | // et un message au cas ou |
| 155 | - '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>' |
|
| 155 | + '<br /><a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>' |
|
| 156 | 156 | ]; |
| 157 | 157 | } else // format message texte, tout en js inline |
| 158 | 158 | { |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>" |
| 162 | 162 | . http_img_pack('loader.svg', '', " class='loader'") |
| 163 | 163 | . '<br />' |
| 164 | - . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'; |
|
| 164 | + . '<a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>'; |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | header("Content-Type: text/html; charset=$charset"); |
| 206 | 206 | header('Expires: 0'); |
| 207 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 207 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
| 208 | 208 | header('Cache-Control: no-cache, must-revalidate'); |
| 209 | 209 | header('Pragma: no-cache'); |
| 210 | 210 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Langue |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -38,35 +38,35 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | - if (empty($lang)) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (is_null($liste_langues)) { |
|
| 46 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 47 | - } else { |
|
| 48 | - if (is_array($liste_langues)) { |
|
| 49 | - $liste_langues = implode(',', $liste_langues); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 53 | - |
|
| 54 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 55 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 56 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | - || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 61 | - ) { |
|
| 62 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 63 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 64 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 65 | - |
|
| 66 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 41 | + if (empty($lang)) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (is_null($liste_langues)) { |
|
| 46 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 47 | + } else { |
|
| 48 | + if (is_array($liste_langues)) { |
|
| 49 | + $liste_langues = implode(',', $liste_langues); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 53 | + |
|
| 54 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 55 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 56 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | + || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 61 | + ) { |
|
| 62 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 63 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 64 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 65 | + |
|
| 66 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 80 | 80 | |
| 81 | 81 | function choisir_traduction($trads, $lang = '') { |
| 82 | - $k = approcher_langue($trads, $lang); |
|
| 82 | + $k = approcher_langue($trads, $lang); |
|
| 83 | 83 | |
| 84 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 84 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // retourne son 2e argument si c'est un index du premier |
@@ -89,21 +89,21 @@ discard block |
||
| 89 | 89 | // la langue X etant consideree comme une approche de X_Y |
| 90 | 90 | function approcher_langue($trads, $lang = '') { |
| 91 | 91 | |
| 92 | - if (!$lang) { |
|
| 93 | - $lang = $GLOBALS['spip_lang']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if (isset($trads[$lang])) { |
|
| 97 | - return $lang; |
|
| 98 | - } // cas des langues xx_yy |
|
| 99 | - else { |
|
| 100 | - $r = explode('_', (string) $lang); |
|
| 101 | - if (isset($trads[$r[0]])) { |
|
| 102 | - return $r[0]; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return ''; |
|
| 92 | + if (!$lang) { |
|
| 93 | + $lang = $GLOBALS['spip_lang']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if (isset($trads[$lang])) { |
|
| 97 | + return $lang; |
|
| 98 | + } // cas des langues xx_yy |
|
| 99 | + else { |
|
| 100 | + $r = explode('_', (string) $lang); |
|
| 101 | + if (isset($trads[$r[0]])) { |
|
| 102 | + return $r[0]; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return ''; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | * Nom de la langue, sinon son code. |
| 119 | 119 | **/ |
| 120 | 120 | function traduire_nom_langue($lang) { |
| 121 | - include_spip('inc/lang_liste'); |
|
| 122 | - include_spip('inc/charsets'); |
|
| 121 | + include_spip('inc/lang_liste'); |
|
| 122 | + include_spip('inc/charsets'); |
|
| 123 | 123 | |
| 124 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 124 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | // hebreu a priori), 'droitier' sinon. |
| 135 | 135 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 136 | 136 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 137 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 137 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | 138 | |
| 139 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 140 | - $gaucher : $droitier; |
|
| 139 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 140 | + $gaucher : $droitier; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // typo francaise ou anglaise ? |
@@ -146,29 +146,29 @@ discard block |
||
| 146 | 146 | // sinon determiner la typo en fonction de la langue courante |
| 147 | 147 | |
| 148 | 148 | function lang_typo($lang = '') { |
| 149 | - if (!$lang) { |
|
| 150 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 151 | - } |
|
| 152 | - if ( |
|
| 153 | - $lang == 'eo' |
|
| 154 | - || $lang == 'fr' |
|
| 155 | - || str_starts_with((string) $lang, 'fr_') |
|
| 156 | - || $lang == 'cpf' |
|
| 157 | - ) { |
|
| 158 | - return 'fr'; |
|
| 159 | - } else { |
|
| 160 | - return 'en'; |
|
| 161 | - } |
|
| 149 | + if (!$lang) { |
|
| 150 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 151 | + } |
|
| 152 | + if ( |
|
| 153 | + $lang == 'eo' |
|
| 154 | + || $lang == 'fr' |
|
| 155 | + || str_starts_with((string) $lang, 'fr_') |
|
| 156 | + || $lang == 'cpf' |
|
| 157 | + ) { |
|
| 158 | + return 'fr'; |
|
| 159 | + } else { |
|
| 160 | + return 'en'; |
|
| 161 | + } |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 165 | 165 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 166 | 166 | function changer_typo($lang = '') { |
| 167 | - if ($lang) { |
|
| 168 | - $GLOBALS['lang_objet'] = $lang; |
|
| 169 | - } else { |
|
| 170 | - unset($GLOBALS['lang_objet']); |
|
| 171 | - } |
|
| 167 | + if ($lang) { |
|
| 168 | + $GLOBALS['lang_objet'] = $lang; |
|
| 169 | + } else { |
|
| 170 | + unset($GLOBALS['lang_objet']); |
|
| 171 | + } |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // |
@@ -178,56 +178,56 @@ discard block |
||
| 178 | 178 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 179 | 179 | // |
| 180 | 180 | function menu_langues($nom_select, $default = '') { |
| 181 | - include_spip('inc/actions'); |
|
| 182 | - |
|
| 183 | - $langues = liste_options_langues($nom_select); |
|
| 184 | - $ret = ''; |
|
| 185 | - if ($langues === []) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!$default) { |
|
| 190 | - $default = $GLOBALS['spip_lang']; |
|
| 191 | - } |
|
| 192 | - foreach ($langues as $l) { |
|
| 193 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 194 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if (!test_espace_prive()) { |
|
| 198 | - $cible = self(); |
|
| 199 | - $base = ''; |
|
| 200 | - } else { |
|
| 201 | - $cible = self(); |
|
| 202 | - $base = spip_connect() ? 'base' : ''; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 206 | - |
|
| 207 | - return generer_action_auteur( |
|
| 208 | - 'converser', |
|
| 209 | - $base, |
|
| 210 | - $cible, |
|
| 211 | - (select_langues($nom_select, $change, $ret) |
|
| 212 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | - " method='post'" |
|
| 214 | - ); |
|
| 181 | + include_spip('inc/actions'); |
|
| 182 | + |
|
| 183 | + $langues = liste_options_langues($nom_select); |
|
| 184 | + $ret = ''; |
|
| 185 | + if ($langues === []) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!$default) { |
|
| 190 | + $default = $GLOBALS['spip_lang']; |
|
| 191 | + } |
|
| 192 | + foreach ($langues as $l) { |
|
| 193 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 194 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if (!test_espace_prive()) { |
|
| 198 | + $cible = self(); |
|
| 199 | + $base = ''; |
|
| 200 | + } else { |
|
| 201 | + $cible = self(); |
|
| 202 | + $base = spip_connect() ? 'base' : ''; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 206 | + |
|
| 207 | + return generer_action_auteur( |
|
| 208 | + 'converser', |
|
| 209 | + $base, |
|
| 210 | + $cible, |
|
| 211 | + (select_langues($nom_select, $change, $ret) |
|
| 212 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | + " method='post'" |
|
| 214 | + ); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | function select_langues($nom_select, $change, $options, $label = '') { |
| 218 | - static $cpt = 0; |
|
| 219 | - $id = 'menu_langues' . $cpt++; |
|
| 220 | - |
|
| 221 | - return |
|
| 222 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | - "<select name='$nom_select' id='$id' " |
|
| 224 | - . ((test_espace_prive()) ? |
|
| 225 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 226 | - ("class='forml menu_langues'")) |
|
| 227 | - . $change |
|
| 228 | - . ">\n" |
|
| 229 | - . $options |
|
| 230 | - . '</select>'; |
|
| 218 | + static $cpt = 0; |
|
| 219 | + $id = 'menu_langues' . $cpt++; |
|
| 220 | + |
|
| 221 | + return |
|
| 222 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | + "<select name='$nom_select' id='$id' " |
|
| 224 | + . ((test_espace_prive()) ? |
|
| 225 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 226 | + ("class='forml menu_langues'")) |
|
| 227 | + . $change |
|
| 228 | + . ">\n" |
|
| 229 | + . $options |
|
| 230 | + . '</select>'; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -249,34 +249,34 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | function liste_options_langues($nom_select) { |
| 251 | 251 | |
| 252 | - switch ($nom_select) { |
|
| 253 | - # #MENU_LANG |
|
| 254 | - case 'var_lang': |
|
| 255 | - # menu de changement de la langue d'un article |
|
| 256 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 257 | - case 'changer_lang': |
|
| 258 | - $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 259 | - break; |
|
| 260 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 261 | - # les langues presentes sous forme de fichiers de langue |
|
| 262 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 263 | - case 'var_lang_ecrire': |
|
| 264 | - default: |
|
| 265 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 266 | - init_langues(); |
|
| 267 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 268 | - break; |
|
| 252 | + switch ($nom_select) { |
|
| 253 | + # #MENU_LANG |
|
| 254 | + case 'var_lang': |
|
| 255 | + # menu de changement de la langue d'un article |
|
| 256 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 257 | + case 'changer_lang': |
|
| 258 | + $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 259 | + break; |
|
| 260 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 261 | + # les langues presentes sous forme de fichiers de langue |
|
| 262 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 263 | + case 'var_lang_ecrire': |
|
| 264 | + default: |
|
| 265 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 266 | + init_langues(); |
|
| 267 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 268 | + break; |
|
| 269 | 269 | |
| 270 | 270 | # dernier choix possible : toutes les langues = langues_proposees |
| 271 | 271 | # + langues_multilingues ; mais, ne sert pas |
| 272 | 272 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 273 | - } |
|
| 274 | - if (count($langues) <= 1) { |
|
| 275 | - return []; |
|
| 276 | - } |
|
| 277 | - sort($langues); |
|
| 273 | + } |
|
| 274 | + if (count($langues) <= 1) { |
|
| 275 | + return []; |
|
| 276 | + } |
|
| 277 | + sort($langues); |
|
| 278 | 278 | |
| 279 | - return $langues; |
|
| 279 | + return $langues; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -291,39 +291,39 @@ discard block |
||
| 291 | 291 | **/ |
| 292 | 292 | function verifier_lang_url() { |
| 293 | 293 | |
| 294 | - // quelle langue est demandee ? |
|
| 295 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 296 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 297 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 298 | - } |
|
| 299 | - if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 301 | - } |
|
| 302 | - if (isset($_GET['lang'])) { |
|
| 303 | - $lang_demandee = $_GET['lang']; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 307 | - if ( |
|
| 308 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 309 | - && changer_langue($lang_demandee) |
|
| 310 | - && $lang_demandee != @$_GET['lang'] |
|
| 311 | - ) { |
|
| 312 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 313 | - // ici on a besoin des var_truc |
|
| 314 | - foreach ($_GET as $var => $val) { |
|
| 315 | - if (!strncmp('var_', $var, 4)) { |
|
| 316 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - include_spip('inc/headers'); |
|
| 320 | - redirige_par_entete($destination); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 324 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 325 | - // (pour criteres {lang}). |
|
| 326 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 294 | + // quelle langue est demandee ? |
|
| 295 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 296 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 297 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 298 | + } |
|
| 299 | + if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 301 | + } |
|
| 302 | + if (isset($_GET['lang'])) { |
|
| 303 | + $lang_demandee = $_GET['lang']; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 307 | + if ( |
|
| 308 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 309 | + && changer_langue($lang_demandee) |
|
| 310 | + && $lang_demandee != @$_GET['lang'] |
|
| 311 | + ) { |
|
| 312 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 313 | + // ici on a besoin des var_truc |
|
| 314 | + foreach ($_GET as $var => $val) { |
|
| 315 | + if (!strncmp('var_', $var, 4)) { |
|
| 316 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + include_spip('inc/headers'); |
|
| 320 | + redirige_par_entete($destination); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 324 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 325 | + // (pour criteres {lang}). |
|
| 326 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | |
@@ -341,19 +341,19 @@ discard block |
||
| 341 | 341 | * La langue sélectionnée |
| 342 | 342 | **/ |
| 343 | 343 | function utiliser_langue_site($liste_langues = null) { |
| 344 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 345 | - if ( |
|
| 346 | - isset($GLOBALS['meta']['langue_site']) |
|
| 347 | - && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 348 | - ) { |
|
| 349 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 350 | - } |
|
| 351 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 352 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 353 | - spip_logger()->error('La globale spip_lang est indéfinie dans utiliser_langue_site() !'); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - return $GLOBALS['spip_lang']; |
|
| 344 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 345 | + if ( |
|
| 346 | + isset($GLOBALS['meta']['langue_site']) |
|
| 347 | + && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 348 | + ) { |
|
| 349 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 350 | + } |
|
| 351 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 352 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 353 | + spip_logger()->error('La globale spip_lang est indéfinie dans utiliser_langue_site() !'); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + return $GLOBALS['spip_lang']; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,38 +372,38 @@ discard block |
||
| 372 | 372 | **/ |
| 373 | 373 | function utiliser_langue_visiteur($liste_langues = null) { |
| 374 | 374 | |
| 375 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 376 | - if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 377 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 381 | - if ( |
|
| 382 | - isset($_COOKIE[$l]) |
|
| 383 | - && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 384 | - ) { |
|
| 385 | - return $l; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( |
|
| 389 | - isset($GLOBALS['visiteur_session']['lang']) |
|
| 390 | - && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 391 | - ) { |
|
| 392 | - return $l; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | - foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | - if ( |
|
| 398 | - preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 399 | - && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 400 | - ) { |
|
| 401 | - return $l; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return utiliser_langue_site($liste_langues); |
|
| 375 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 376 | + if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 377 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 381 | + if ( |
|
| 382 | + isset($_COOKIE[$l]) |
|
| 383 | + && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 384 | + ) { |
|
| 385 | + return $l; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( |
|
| 389 | + isset($GLOBALS['visiteur_session']['lang']) |
|
| 390 | + && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 391 | + ) { |
|
| 392 | + return $l; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | + foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | + if ( |
|
| 398 | + preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 399 | + && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 400 | + ) { |
|
| 401 | + return $l; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return utiliser_langue_site($liste_langues); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * @return int |
| 414 | 414 | */ |
| 415 | 415 | function match_langue($chaine) { |
| 416 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -431,38 +431,38 @@ discard block |
||
| 431 | 431 | **/ |
| 432 | 432 | function init_langues() { |
| 433 | 433 | |
| 434 | - // liste des langues dans les meta, sauf a l'install |
|
| 435 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 436 | - |
|
| 437 | - $tout = []; |
|
| 438 | - if (!$all_langs) { |
|
| 439 | - // trouver tous les modules lang/spip_xx.php |
|
| 440 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 441 | - foreach (array_keys($modules) as $name) { |
|
| 442 | - if ( |
|
| 443 | - preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 444 | - && match_langue($regs[1]) |
|
| 445 | - ) { |
|
| 446 | - $tout[] = $regs[1]; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - sort($tout); |
|
| 450 | - $tout = implode(',', $tout); |
|
| 451 | - // Si les langues n'ont pas change, ne rien faire |
|
| 452 | - if ($tout != $all_langs) { |
|
| 453 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 454 | - include_spip('inc/meta'); |
|
| 455 | - ecrire_meta('langues_proposees', $tout); |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 459 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 460 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 461 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 462 | - ? _LANGUE_PAR_DEFAUT |
|
| 463 | - : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 464 | - ecrire_meta('langue_site', $tout); |
|
| 465 | - } |
|
| 434 | + // liste des langues dans les meta, sauf a l'install |
|
| 435 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 436 | + |
|
| 437 | + $tout = []; |
|
| 438 | + if (!$all_langs) { |
|
| 439 | + // trouver tous les modules lang/spip_xx.php |
|
| 440 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 441 | + foreach (array_keys($modules) as $name) { |
|
| 442 | + if ( |
|
| 443 | + preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 444 | + && match_langue($regs[1]) |
|
| 445 | + ) { |
|
| 446 | + $tout[] = $regs[1]; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + sort($tout); |
|
| 450 | + $tout = implode(',', $tout); |
|
| 451 | + // Si les langues n'ont pas change, ne rien faire |
|
| 452 | + if ($tout != $all_langs) { |
|
| 453 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 454 | + include_spip('inc/meta'); |
|
| 455 | + ecrire_meta('langues_proposees', $tout); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 459 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 460 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 461 | + (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 462 | + ? _LANGUE_PAR_DEFAUT |
|
| 463 | + : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 464 | + ecrire_meta('langue_site', $tout); |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -476,10 +476,10 @@ discard block |
||
| 476 | 476 | * Code html de la balise <html> |
| 477 | 477 | **/ |
| 478 | 478 | function html_lang_attributes() { |
| 479 | - $lang = $GLOBALS['spip_lang']; |
|
| 480 | - $dir = lang_dir($lang); |
|
| 479 | + $lang = $GLOBALS['spip_lang']; |
|
| 480 | + $dir = lang_dir($lang); |
|
| 481 | 481 | |
| 482 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 482 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | * @return string |
| 494 | 494 | */ |
| 495 | 495 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 496 | - return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 496 | + return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * @return |
| 75 | 75 | **/ |
| 76 | 76 | function inc_genie_dist($taches = []) { |
| 77 | - include_spip('inc/queue'); |
|
| 78 | - |
|
| 79 | - if (_request('exec') == 'job_queue') { |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $force_jobs = []; |
|
| 84 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | - // etait de la passer en parametre a ing_genie_dist |
|
| 86 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | - foreach ($taches as $function => $period) { |
|
| 88 | - $force_jobs[] = queue_add_job( |
|
| 89 | - $function, |
|
| 90 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | - [time() - abs($period)], |
|
| 92 | - 'genie/' |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // et on passe la main a la gestion de la queue ! |
|
| 97 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 77 | + include_spip('inc/queue'); |
|
| 78 | + |
|
| 79 | + if (_request('exec') == 'job_queue') { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $force_jobs = []; |
|
| 84 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | + // etait de la passer en parametre a ing_genie_dist |
|
| 86 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | + foreach ($taches as $function => $period) { |
|
| 88 | + $force_jobs[] = queue_add_job( |
|
| 89 | + $function, |
|
| 90 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | + [time() - abs($period)], |
|
| 92 | + 'genie/' |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // et on passe la main a la gestion de la queue ! |
|
| 97 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | // |
| 109 | 109 | function taches_generales($taches_generales = []) { |
| 110 | 110 | |
| 111 | - // verifier que toutes les taches cron sont planifiees |
|
| 112 | - // c'est une tache cron ! |
|
| 113 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 111 | + // verifier que toutes les taches cron sont planifiees |
|
| 112 | + // c'est une tache cron ! |
|
| 113 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 114 | 114 | |
| 115 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | - // est fait au coup par coup a present |
|
| 117 | - // $taches_generales['rubriques'] = 3600; |
|
| 115 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | + // est fait au coup par coup a present |
|
| 117 | + // $taches_generales['rubriques'] = 3600; |
|
| 118 | 118 | |
| 119 | - // Optimisation de la base |
|
| 120 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 119 | + // Optimisation de la base |
|
| 120 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 121 | 121 | |
| 122 | - // nouveautes |
|
| 123 | - if ( |
|
| 124 | - isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | - && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | - && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | - && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | - ) { |
|
| 129 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | - } |
|
| 122 | + // nouveautes |
|
| 123 | + if ( |
|
| 124 | + isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | + && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | + && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | + && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | + ) { |
|
| 129 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // maintenance (ajax, verifications diverses) |
|
| 133 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 132 | + // maintenance (ajax, verifications diverses) |
|
| 133 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 134 | 134 | |
| 135 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 135 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 137 | 137 | |
| 138 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 138 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | 153 | function genie_queue_watch_dist() { |
| 154 | - static $deja_la = false; |
|
| 155 | - if ($deja_la) { |
|
| 156 | - return; |
|
| 157 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | - $deja_la = true; |
|
| 159 | - $taches = taches_generales(); |
|
| 160 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | - $programmees = array_column($programmees, 'fonction'); |
|
| 162 | - foreach ($taches as $tache => $periode) { |
|
| 163 | - if (!in_array($tache, $programmees)) { |
|
| 164 | - queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $deja_la = false; |
|
| 168 | - |
|
| 169 | - return 1; |
|
| 154 | + static $deja_la = false; |
|
| 155 | + if ($deja_la) { |
|
| 156 | + return; |
|
| 157 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | + $deja_la = true; |
|
| 159 | + $taches = taches_generales(); |
|
| 160 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | + $programmees = array_column($programmees, 'fonction'); |
|
| 162 | + foreach ($taches as $tache => $periode) { |
|
| 163 | + if (!in_array($tache, $programmees)) { |
|
| 164 | + queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $deja_la = false; |
|
| 168 | + |
|
| 169 | + return 1; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | 189 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 190 | - static $done = []; |
|
| 191 | - if (isset($done[$function])) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $done[$function] = true; |
|
| 195 | - if (is_null($time)) { |
|
| 196 | - $time = time(); |
|
| 197 | - if ($last) { |
|
| 198 | - $time = max($last + $period, $time); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - if (!$last) { |
|
| 202 | - $last = $time - $period; |
|
| 203 | - } |
|
| 204 | - spip_logger('queue')->info("replan_job $function $period $last $time $priority"); |
|
| 205 | - include_spip('inc/queue'); |
|
| 206 | - // on replanifie un job cron |
|
| 207 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | - // independament de l'argument |
|
| 209 | - queue_add_job( |
|
| 210 | - $function, |
|
| 211 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | - [$last], |
|
| 213 | - 'genie/', |
|
| 214 | - 'function_only', |
|
| 215 | - $time, |
|
| 216 | - $priority |
|
| 217 | - ); |
|
| 190 | + static $done = []; |
|
| 191 | + if (isset($done[$function])) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $done[$function] = true; |
|
| 195 | + if (is_null($time)) { |
|
| 196 | + $time = time(); |
|
| 197 | + if ($last) { |
|
| 198 | + $time = max($last + $period, $time); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + if (!$last) { |
|
| 202 | + $last = $time - $period; |
|
| 203 | + } |
|
| 204 | + spip_logger('queue')->info("replan_job $function $period $last $time $priority"); |
|
| 205 | + include_spip('inc/queue'); |
|
| 206 | + // on replanifie un job cron |
|
| 207 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | + // independament de l'argument |
|
| 209 | + queue_add_job( |
|
| 210 | + $function, |
|
| 211 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | + [$last], |
|
| 213 | + 'genie/', |
|
| 214 | + 'function_only', |
|
| 215 | + $time, |
|
| 216 | + $priority |
|
| 217 | + ); |
|
| 218 | 218 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // |
@@ -22,52 +22,52 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | function produire_image_math($tex) { |
| 24 | 24 | |
| 25 | - switch ($GLOBALS['traiter_math']) { |
|
| 26 | - // Attention: mathml desactiv'e pour l'instant |
|
| 27 | - case 'mathml': |
|
| 28 | - $ext = '.xhtml'; |
|
| 29 | - $server = $GLOBALS['mathml_server']; |
|
| 30 | - break; |
|
| 31 | - case 'tex': |
|
| 32 | - $ext = '.png'; |
|
| 33 | - $server = $GLOBALS['tex_server']; |
|
| 34 | - break; |
|
| 35 | - default: |
|
| 36 | - return $tex; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | - } |
|
| 43 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // Aller chercher l'image sur le serveur |
|
| 47 | - if (!@file_exists($fichier) && $server) { |
|
| 48 | - spip_logger()->info($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 49 | - include_spip('inc/distant'); |
|
| 50 | - recuperer_url($url, ['file' => $fichier]); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - // Composer la reponse selon presence ou non de l'image |
|
| 55 | - $tex = entites_html($tex); |
|
| 56 | - if (@file_exists($fichier)) { |
|
| 57 | - // MathML |
|
| 58 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 59 | - return implode('', file($fichier)); |
|
| 60 | - } // TeX |
|
| 61 | - else { |
|
| 62 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 63 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 64 | - |
|
| 65 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 66 | - } |
|
| 67 | - } else // pas de fichier |
|
| 68 | - { |
|
| 69 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 70 | - } |
|
| 25 | + switch ($GLOBALS['traiter_math']) { |
|
| 26 | + // Attention: mathml desactiv'e pour l'instant |
|
| 27 | + case 'mathml': |
|
| 28 | + $ext = '.xhtml'; |
|
| 29 | + $server = $GLOBALS['mathml_server']; |
|
| 30 | + break; |
|
| 31 | + case 'tex': |
|
| 32 | + $ext = '.png'; |
|
| 33 | + $server = $GLOBALS['tex_server']; |
|
| 34 | + break; |
|
| 35 | + default: |
|
| 36 | + return $tex; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | + } |
|
| 43 | + $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // Aller chercher l'image sur le serveur |
|
| 47 | + if (!@file_exists($fichier) && $server) { |
|
| 48 | + spip_logger()->info($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 49 | + include_spip('inc/distant'); |
|
| 50 | + recuperer_url($url, ['file' => $fichier]); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + // Composer la reponse selon presence ou non de l'image |
|
| 55 | + $tex = entites_html($tex); |
|
| 56 | + if (@file_exists($fichier)) { |
|
| 57 | + // MathML |
|
| 58 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 59 | + return implode('', file($fichier)); |
|
| 60 | + } // TeX |
|
| 61 | + else { |
|
| 62 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 63 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 64 | + |
|
| 65 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 66 | + } |
|
| 67 | + } else // pas de fichier |
|
| 68 | + { |
|
| 69 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
@@ -102,39 +102,39 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 104 | 104 | |
| 105 | - $collecteurMath = new CollecteurHtmlTag('math', '@<math>(.*)(</math>|$)@iUsS', ''); |
|
| 106 | - $collection = $collecteurMath->collecter($letexte); |
|
| 107 | - $collection = array_reverse($collection); |
|
| 108 | - |
|
| 109 | - foreach ($collection as $c) { |
|
| 110 | - $texte_milieu = $c['match'][1]; |
|
| 111 | - |
|
| 112 | - $traitements = [ |
|
| 113 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 114 | - ['str' => '$$', 'preg' => ',[$][$]([^$]+)[$][$],', 'pre' => "\n<p class=\"spip\" style=\"text-align: center;\">", 'post' => "</p>\n"], |
|
| 115 | - // Les simples $x^2$ en mode 'span' |
|
| 116 | - ['str' => '$', 'preg' => ',[$]([^$]+)[$],'], |
|
| 117 | - ]; |
|
| 118 | - foreach ($traitements as $t) { |
|
| 119 | - while ( |
|
| 120 | - str_contains($texte_milieu, $t['str']) |
|
| 121 | - && preg_match($t['preg'], $texte_milieu, $regs) |
|
| 122 | - ) { |
|
| 123 | - $expression = $regs[1]; |
|
| 124 | - if ($defaire_amp) { |
|
| 125 | - $expression = str_replace('&', '&', $expression); |
|
| 126 | - } |
|
| 127 | - $echap = produire_image_math($expression); |
|
| 128 | - $echap = ($t['pre'] ?? '') . $echap . ($t['post'] ?? ''); |
|
| 129 | - $echap = CollecteurHtmlTag::echappementHtmlBase64($echap, $source); |
|
| 130 | - |
|
| 131 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 132 | - $texte_milieu = substr_replace($texte_milieu, $echap, $pos, strlen($regs[0])); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $letexte = substr_replace($letexte, $texte_milieu, $c['pos'], $c['length']); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $letexte; |
|
| 105 | + $collecteurMath = new CollecteurHtmlTag('math', '@<math>(.*)(</math>|$)@iUsS', ''); |
|
| 106 | + $collection = $collecteurMath->collecter($letexte); |
|
| 107 | + $collection = array_reverse($collection); |
|
| 108 | + |
|
| 109 | + foreach ($collection as $c) { |
|
| 110 | + $texte_milieu = $c['match'][1]; |
|
| 111 | + |
|
| 112 | + $traitements = [ |
|
| 113 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 114 | + ['str' => '$$', 'preg' => ',[$][$]([^$]+)[$][$],', 'pre' => "\n<p class=\"spip\" style=\"text-align: center;\">", 'post' => "</p>\n"], |
|
| 115 | + // Les simples $x^2$ en mode 'span' |
|
| 116 | + ['str' => '$', 'preg' => ',[$]([^$]+)[$],'], |
|
| 117 | + ]; |
|
| 118 | + foreach ($traitements as $t) { |
|
| 119 | + while ( |
|
| 120 | + str_contains($texte_milieu, $t['str']) |
|
| 121 | + && preg_match($t['preg'], $texte_milieu, $regs) |
|
| 122 | + ) { |
|
| 123 | + $expression = $regs[1]; |
|
| 124 | + if ($defaire_amp) { |
|
| 125 | + $expression = str_replace('&', '&', $expression); |
|
| 126 | + } |
|
| 127 | + $echap = produire_image_math($expression); |
|
| 128 | + $echap = ($t['pre'] ?? '') . $echap . ($t['post'] ?? ''); |
|
| 129 | + $echap = CollecteurHtmlTag::echappementHtmlBase64($echap, $source); |
|
| 130 | + |
|
| 131 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 132 | + $texte_milieu = substr_replace($texte_milieu, $echap, $pos, strlen($regs[0])); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $letexte = substr_replace($letexte, $texte_milieu, $c['pos'], $c['length']); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $letexte; |
|
| 140 | 140 | } |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 41 | 41 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 42 | 42 | } |
| 43 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 43 | + $fichier = $dir_tex.md5(trim((string) $tex)).$ext; |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | // Aller chercher l'image sur le serveur |
| 47 | 47 | if (!@file_exists($fichier) && $server) { |
| 48 | - spip_logger()->info($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 48 | + spip_logger()->info($url = $server.'?'.rawurlencode((string) $tex)); |
|
| 49 | 49 | include_spip('inc/distant'); |
| 50 | 50 | recuperer_url($url, ['file' => $fichier]); |
| 51 | 51 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | return implode('', file($fichier)); |
| 60 | 60 | } // TeX |
| 61 | 61 | else { |
| 62 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 62 | + [,,, $size] = @spip_getimagesize($fichier); |
|
| 63 | 63 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 64 | 64 | |
| 65 | 65 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $expression = str_replace('&', '&', $expression); |
| 126 | 126 | } |
| 127 | 127 | $echap = produire_image_math($expression); |
| 128 | - $echap = ($t['pre'] ?? '') . $echap . ($t['post'] ?? ''); |
|
| 128 | + $echap = ($t['pre'] ?? '').$echap.($t['post'] ?? ''); |
|
| 129 | 129 | $echap = CollecteurHtmlTag::echappementHtmlBase64($echap, $source); |
| 130 | 130 | |
| 131 | 131 | $pos = strpos($texte_milieu, (string) $regs[0]); |