@@ -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,168 +33,168 @@ 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 | - include_spip('auth/sha256.inc'); |
|
| 85 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | - $methode = 'sha256'; |
|
| 87 | - } |
|
| 88 | - if ($row['pass'] === $hash) { |
|
| 89 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | - // 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 |
|
| 91 | - if (!empty($row['backup_cles'])) { |
|
| 92 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 93 | - } |
|
| 94 | - break; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 98 | - |
|
| 99 | - case 60: |
|
| 100 | - case 98: |
|
| 101 | - default: |
|
| 102 | - // doit-on restaurer un backup des cles ? |
|
| 103 | - // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 104 | - if ( |
|
| 105 | - !$secret |
|
| 106 | - && $auteur_peut_sauver_cles |
|
| 107 | - && !empty($row['backup_cles']) |
|
| 108 | - ) { |
|
| 109 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 110 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | - if ($cles->save()) { |
|
| 112 | - $secret = $cles->getSecretAuth(); |
|
| 113 | - } |
|
| 114 | - else { |
|
| 115 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 117 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - else { |
|
| 121 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 127 | - unset($row); |
|
| 128 | - } |
|
| 129 | - else { |
|
| 130 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | - } |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 136 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 137 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 138 | - // 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 |
|
| 139 | - if (!$secret && $auteur_peut_sauver_cles && auth_spip_initialiser_secret()) { |
|
| 140 | - $secret = $cles->getSecretAuth(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // login/mot de passe incorrect |
|
| 144 | - if (empty($row)) { |
|
| 145 | - return []; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // fait tourner le codage du pass dans la base |
|
| 149 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 150 | - if (!$phpauth && $secret) { |
|
| 151 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 152 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 153 | - if ($pass_hash_next) { |
|
| 154 | - $set = [ |
|
| 155 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 156 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 157 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 158 | - ]; |
|
| 159 | - |
|
| 160 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 161 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 162 | - $htpass = generer_htpass($pass); |
|
| 163 | - if (strlen((string) $htpass) !== strlen((string) $row['htpass'])) { |
|
| 164 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 168 | - if ($auteur_peut_sauver_cles) { |
|
| 169 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - @sql_update( |
|
| 173 | - 'spip_auteurs', |
|
| 174 | - $set, |
|
| 175 | - 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 176 | - $row['pass'], |
|
| 177 | - $serveur, |
|
| 178 | - 'text' |
|
| 179 | - ), |
|
| 180 | - [], |
|
| 181 | - $serveur |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 185 | - if (isset($set['htpass'])) { |
|
| 186 | - ecrire_acces(); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // En profiter pour verifier la securite de tmp/ |
|
| 191 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 192 | - if (!verifier_htaccess(_DIR_TMP) && defined('_ECRIRE_INSTALL')) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - 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 | + include_spip('auth/sha256.inc'); |
|
| 85 | + $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | + $methode = 'sha256'; |
|
| 87 | + } |
|
| 88 | + if ($row['pass'] === $hash) { |
|
| 89 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | + // 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 |
|
| 91 | + if (!empty($row['backup_cles'])) { |
|
| 92 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 93 | + } |
|
| 94 | + break; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 98 | + |
|
| 99 | + case 60: |
|
| 100 | + case 98: |
|
| 101 | + default: |
|
| 102 | + // doit-on restaurer un backup des cles ? |
|
| 103 | + // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 104 | + if ( |
|
| 105 | + !$secret |
|
| 106 | + && $auteur_peut_sauver_cles |
|
| 107 | + && !empty($row['backup_cles']) |
|
| 108 | + ) { |
|
| 109 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 110 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | + if ($cles->save()) { |
|
| 112 | + $secret = $cles->getSecretAuth(); |
|
| 113 | + } |
|
| 114 | + else { |
|
| 115 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 117 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + else { |
|
| 121 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 127 | + unset($row); |
|
| 128 | + } |
|
| 129 | + else { |
|
| 130 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | + } |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 136 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 137 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 138 | + // 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 |
|
| 139 | + if (!$secret && $auteur_peut_sauver_cles && auth_spip_initialiser_secret()) { |
|
| 140 | + $secret = $cles->getSecretAuth(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // login/mot de passe incorrect |
|
| 144 | + if (empty($row)) { |
|
| 145 | + return []; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // fait tourner le codage du pass dans la base |
|
| 149 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 150 | + if (!$phpauth && $secret) { |
|
| 151 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 152 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 153 | + if ($pass_hash_next) { |
|
| 154 | + $set = [ |
|
| 155 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 156 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 157 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 158 | + ]; |
|
| 159 | + |
|
| 160 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 161 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 162 | + $htpass = generer_htpass($pass); |
|
| 163 | + if (strlen((string) $htpass) !== strlen((string) $row['htpass'])) { |
|
| 164 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 168 | + if ($auteur_peut_sauver_cles) { |
|
| 169 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + @sql_update( |
|
| 173 | + 'spip_auteurs', |
|
| 174 | + $set, |
|
| 175 | + 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 176 | + $row['pass'], |
|
| 177 | + $serveur, |
|
| 178 | + 'text' |
|
| 179 | + ), |
|
| 180 | + [], |
|
| 181 | + $serveur |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 185 | + if (isset($set['htpass'])) { |
|
| 186 | + ecrire_acces(); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // En profiter pour verifier la securite de tmp/ |
|
| 191 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 192 | + if (!verifier_htaccess(_DIR_TMP) && defined('_ECRIRE_INSTALL')) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $row; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -209,36 +209,36 @@ discard block |
||
| 209 | 209 | * @return bool |
| 210 | 210 | */ |
| 211 | 211 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 212 | - $cles = SpipCles::instance(); |
|
| 213 | - $secret = $cles->getSecretAuth(); |
|
| 214 | - |
|
| 215 | - // on ne fait rien si on a un secret dispo |
|
| 216 | - if ($secret) { |
|
| 217 | - return false; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 221 | - if ($force) { |
|
| 222 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 223 | - $secret = $cles->getSecretAuth(true); |
|
| 224 | - return true; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 228 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 229 | - if ($has_backup === []) { |
|
| 230 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 231 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 232 | - return true; |
|
| 233 | - } |
|
| 234 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 235 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 236 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 237 | - } |
|
| 238 | - else { |
|
| 239 | - spip_log('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', 'auth' . _LOG_ERREUR); |
|
| 240 | - } |
|
| 241 | - return false; |
|
| 212 | + $cles = SpipCles::instance(); |
|
| 213 | + $secret = $cles->getSecretAuth(); |
|
| 214 | + |
|
| 215 | + // on ne fait rien si on a un secret dispo |
|
| 216 | + if ($secret) { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 221 | + if ($force) { |
|
| 222 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 223 | + $secret = $cles->getSecretAuth(true); |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 228 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 229 | + if ($has_backup === []) { |
|
| 230 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 231 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 232 | + return true; |
|
| 233 | + } |
|
| 234 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 235 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 236 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 237 | + } |
|
| 238 | + else { |
|
| 239 | + spip_log('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', 'auth' . _LOG_ERREUR); |
|
| 240 | + } |
|
| 241 | + return false; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -248,19 +248,19 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function auth_spip_formulaire_login($flux) { |
| 251 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 252 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 253 | - $flux['data'] .= |
|
| 254 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 255 | - . "$js\n" |
|
| 256 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 257 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 258 | - . "'informe_auteur_en_cours':false," |
|
| 259 | - . "'attente_informe':0};" |
|
| 260 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 261 | - . '/*]]>*/</script>'; |
|
| 262 | - |
|
| 263 | - return $flux; |
|
| 251 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 252 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 253 | + $flux['data'] .= |
|
| 254 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 255 | + . "$js\n" |
|
| 256 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 257 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 258 | + . "'informe_auteur_en_cours':false," |
|
| 259 | + . "'attente_informe':0};" |
|
| 260 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 261 | + . '/*]]>*/</script>'; |
|
| 262 | + |
|
| 263 | + return $flux; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | * toujours true pour un auteur cree dans SPIP |
| 273 | 273 | */ |
| 274 | 274 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 275 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 276 | - return !strlen($serveur); |
|
| 275 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 276 | + return !strlen($serveur); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -287,25 +287,25 @@ discard block |
||
| 287 | 287 | * message d'erreur si login non valide, chaine vide sinon |
| 288 | 288 | */ |
| 289 | 289 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 290 | - // login et mot de passe |
|
| 291 | - if (strlen($new_login)) { |
|
| 292 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 293 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 294 | - } else { |
|
| 295 | - $n = sql_countsel( |
|
| 296 | - 'spip_auteurs', |
|
| 297 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 298 | - '', |
|
| 299 | - '', |
|
| 300 | - $serveur |
|
| 301 | - ); |
|
| 302 | - if ($n) { |
|
| 303 | - return _T('info_login_existant'); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return ''; |
|
| 290 | + // login et mot de passe |
|
| 291 | + if (strlen($new_login)) { |
|
| 292 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 293 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 294 | + } else { |
|
| 295 | + $n = sql_countsel( |
|
| 296 | + 'spip_auteurs', |
|
| 297 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 298 | + '', |
|
| 299 | + '', |
|
| 300 | + $serveur |
|
| 301 | + ); |
|
| 302 | + if ($n) { |
|
| 303 | + return _T('info_login_existant'); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return ''; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -317,41 +317,41 @@ discard block |
||
| 317 | 317 | * @return bool |
| 318 | 318 | */ |
| 319 | 319 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 320 | - if (is_null($new_login) || auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - if ( |
|
| 324 | - !($id_auteur = (int) $id_auteur) |
|
| 325 | - || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 326 | - ) { |
|
| 327 | - return false; |
|
| 328 | - } |
|
| 329 | - if ($new_login == $auteur['login']) { |
|
| 330 | - return true; |
|
| 331 | - } // on a rien fait mais c'est bon ! |
|
| 332 | - |
|
| 333 | - include_spip('action/editer_auteur'); |
|
| 334 | - |
|
| 335 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 336 | - if (strlen($new_login)) { |
|
| 337 | - $anciens = sql_allfetsel( |
|
| 338 | - 'id_auteur', |
|
| 339 | - 'spip_auteurs', |
|
| 340 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 341 | - '', |
|
| 342 | - '', |
|
| 343 | - '', |
|
| 344 | - '', |
|
| 345 | - $serveur |
|
| 346 | - ); |
|
| 347 | - while ($row = array_pop($anciens)) { |
|
| 348 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 353 | - |
|
| 354 | - return true; |
|
| 320 | + if (is_null($new_login) || auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + if ( |
|
| 324 | + !($id_auteur = (int) $id_auteur) |
|
| 325 | + || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 326 | + ) { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 329 | + if ($new_login == $auteur['login']) { |
|
| 330 | + return true; |
|
| 331 | + } // on a rien fait mais c'est bon ! |
|
| 332 | + |
|
| 333 | + include_spip('action/editer_auteur'); |
|
| 334 | + |
|
| 335 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 336 | + if (strlen($new_login)) { |
|
| 337 | + $anciens = sql_allfetsel( |
|
| 338 | + 'id_auteur', |
|
| 339 | + 'spip_auteurs', |
|
| 340 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 341 | + '', |
|
| 342 | + '', |
|
| 343 | + '', |
|
| 344 | + '', |
|
| 345 | + $serveur |
|
| 346 | + ); |
|
| 347 | + while ($row = array_pop($anciens)) { |
|
| 348 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 353 | + |
|
| 354 | + return true; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -363,44 +363,44 @@ discard block |
||
| 363 | 363 | * @return string |
| 364 | 364 | */ |
| 365 | 365 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 366 | - if (!strlen($login)) { |
|
| 367 | - return null; |
|
| 368 | - } // pas la peine de requeter |
|
| 369 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 370 | - if ( |
|
| 371 | - $r = sql_getfetsel( |
|
| 372 | - 'login', |
|
| 373 | - 'spip_auteurs', |
|
| 374 | - "statut<>'5poubelle'" . |
|
| 375 | - ' AND (length(pass)>0)' . |
|
| 376 | - " AND (login=$l)", |
|
| 377 | - '', |
|
| 378 | - '', |
|
| 379 | - '', |
|
| 380 | - '', |
|
| 381 | - $serveur |
|
| 382 | - ) |
|
| 383 | - ) { |
|
| 384 | - return $r; |
|
| 385 | - } |
|
| 386 | - // Si pas d'auteur avec ce login |
|
| 387 | - // regarder s'il a saisi son nom ou son mail. |
|
| 388 | - // Ne pas fusionner avec la requete precedente |
|
| 389 | - // car un nom peut etre homonyme d'un autre login |
|
| 390 | - else { |
|
| 391 | - return sql_getfetsel( |
|
| 392 | - 'login', |
|
| 393 | - 'spip_auteurs', |
|
| 394 | - "statut<>'5poubelle'" . |
|
| 395 | - ' AND (length(pass)>0)' . |
|
| 396 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 397 | - '', |
|
| 398 | - '', |
|
| 399 | - '', |
|
| 400 | - '', |
|
| 401 | - $serveur |
|
| 402 | - ); |
|
| 403 | - } |
|
| 366 | + if (!strlen($login)) { |
|
| 367 | + return null; |
|
| 368 | + } // pas la peine de requeter |
|
| 369 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 370 | + if ( |
|
| 371 | + $r = sql_getfetsel( |
|
| 372 | + 'login', |
|
| 373 | + 'spip_auteurs', |
|
| 374 | + "statut<>'5poubelle'" . |
|
| 375 | + ' AND (length(pass)>0)' . |
|
| 376 | + " AND (login=$l)", |
|
| 377 | + '', |
|
| 378 | + '', |
|
| 379 | + '', |
|
| 380 | + '', |
|
| 381 | + $serveur |
|
| 382 | + ) |
|
| 383 | + ) { |
|
| 384 | + return $r; |
|
| 385 | + } |
|
| 386 | + // Si pas d'auteur avec ce login |
|
| 387 | + // regarder s'il a saisi son nom ou son mail. |
|
| 388 | + // Ne pas fusionner avec la requete precedente |
|
| 389 | + // car un nom peut etre homonyme d'un autre login |
|
| 390 | + else { |
|
| 391 | + return sql_getfetsel( |
|
| 392 | + 'login', |
|
| 393 | + 'spip_auteurs', |
|
| 394 | + "statut<>'5poubelle'" . |
|
| 395 | + ' AND (length(pass)>0)' . |
|
| 396 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 397 | + '', |
|
| 398 | + '', |
|
| 399 | + '', |
|
| 400 | + '', |
|
| 401 | + $serveur |
|
| 402 | + ); |
|
| 403 | + } |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | * toujours true pour un auteur cree dans SPIP |
| 412 | 412 | */ |
| 413 | 413 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 414 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 415 | - return !strlen($serveur); |
|
| 414 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 415 | + return !strlen($serveur); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -433,12 +433,12 @@ discard block |
||
| 433 | 433 | * message d'erreur si login non valide, chaine vide sinon |
| 434 | 434 | */ |
| 435 | 435 | function auth_spip_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 436 | - // login et mot de passe |
|
| 437 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 438 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 439 | - } |
|
| 436 | + // login et mot de passe |
|
| 437 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 438 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - return ''; |
|
| 441 | + return ''; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
@@ -452,47 +452,47 @@ discard block |
||
| 452 | 452 | * @return bool |
| 453 | 453 | */ |
| 454 | 454 | function auth_spip_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 455 | - if (is_null($new_pass) || auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - if ( |
|
| 460 | - !($id_auteur = (int) $id_auteur) |
|
| 461 | - || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 462 | - ) { |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - $cles = SpipCles::instance(); |
|
| 467 | - $secret = $cles->getSecretAuth(); |
|
| 468 | - if (!$secret) { |
|
| 469 | - if (auth_spip_initialiser_secret()) { |
|
| 470 | - $secret = $cles->getSecretAuth(); |
|
| 471 | - } |
|
| 472 | - else { |
|
| 473 | - return false; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - include_spip('inc/acces'); |
|
| 479 | - $set = [ |
|
| 480 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 481 | - 'htpass' => generer_htpass($new_pass), |
|
| 482 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 483 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 484 | - 'low_sec' => '', |
|
| 485 | - ]; |
|
| 486 | - |
|
| 487 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 488 | - if ($auteur['statut'] === '0minirezo' && $auteur['webmestre'] === 'oui') { |
|
| 489 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - include_spip('action/editer_auteur'); |
|
| 493 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 494 | - |
|
| 495 | - return true; // on a bien modifie le pass |
|
| 455 | + if (is_null($new_pass) || auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + if ( |
|
| 460 | + !($id_auteur = (int) $id_auteur) |
|
| 461 | + || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 462 | + ) { |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + $cles = SpipCles::instance(); |
|
| 467 | + $secret = $cles->getSecretAuth(); |
|
| 468 | + if (!$secret) { |
|
| 469 | + if (auth_spip_initialiser_secret()) { |
|
| 470 | + $secret = $cles->getSecretAuth(); |
|
| 471 | + } |
|
| 472 | + else { |
|
| 473 | + return false; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + include_spip('inc/acces'); |
|
| 479 | + $set = [ |
|
| 480 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 481 | + 'htpass' => generer_htpass($new_pass), |
|
| 482 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 483 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 484 | + 'low_sec' => '', |
|
| 485 | + ]; |
|
| 486 | + |
|
| 487 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 488 | + if ($auteur['statut'] === '0minirezo' && $auteur['webmestre'] === 'oui') { |
|
| 489 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + include_spip('action/editer_auteur'); |
|
| 493 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 494 | + |
|
| 495 | + return true; // on a bien modifie le pass |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
@@ -506,54 +506,54 @@ discard block |
||
| 506 | 506 | * @return void |
| 507 | 507 | */ |
| 508 | 508 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 509 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 510 | - if (strlen($serveur)) { |
|
| 511 | - return; |
|
| 512 | - } |
|
| 513 | - // si un login, pass ou statut a ete modifie |
|
| 514 | - // regenerer les fichier htpass |
|
| 515 | - if ( |
|
| 516 | - isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
|
| 517 | - ) { |
|
| 518 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 519 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 520 | - |
|
| 521 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 522 | - // par exemple acces_restreint ; |
|
| 523 | - // si .htaccess existe, outrepasser spip_meta |
|
| 524 | - if ( |
|
| 525 | - (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 526 | - ) { |
|
| 527 | - spip_unlink($htpasswd); |
|
| 528 | - spip_unlink($htpasswd . '-admin'); |
|
| 529 | - |
|
| 530 | - return; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 534 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 535 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 536 | - |
|
| 537 | - $p1 = ''; // login:htpass pour tous |
|
| 538 | - $p2 = ''; // login:htpass pour les admins |
|
| 539 | - $s = sql_select( |
|
| 540 | - 'login, htpass, statut', |
|
| 541 | - 'spip_auteurs', |
|
| 542 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 543 | - ); |
|
| 544 | - while ($t = sql_fetch($s)) { |
|
| 545 | - if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
|
| 546 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 547 | - if ($t['statut'] == '0minirezo') { |
|
| 548 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - sql_free($s); |
|
| 553 | - if ($p1) { |
|
| 554 | - ecrire_fichier($htpasswd, $p1); |
|
| 555 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 556 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 557 | - } |
|
| 558 | - } |
|
| 509 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 510 | + if (strlen($serveur)) { |
|
| 511 | + return; |
|
| 512 | + } |
|
| 513 | + // si un login, pass ou statut a ete modifie |
|
| 514 | + // regenerer les fichier htpass |
|
| 515 | + if ( |
|
| 516 | + isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
|
| 517 | + ) { |
|
| 518 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 519 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 520 | + |
|
| 521 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 522 | + // par exemple acces_restreint ; |
|
| 523 | + // si .htaccess existe, outrepasser spip_meta |
|
| 524 | + if ( |
|
| 525 | + (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 526 | + ) { |
|
| 527 | + spip_unlink($htpasswd); |
|
| 528 | + spip_unlink($htpasswd . '-admin'); |
|
| 529 | + |
|
| 530 | + return; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 534 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 535 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 536 | + |
|
| 537 | + $p1 = ''; // login:htpass pour tous |
|
| 538 | + $p2 = ''; // login:htpass pour les admins |
|
| 539 | + $s = sql_select( |
|
| 540 | + 'login, htpass, statut', |
|
| 541 | + 'spip_auteurs', |
|
| 542 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 543 | + ); |
|
| 544 | + while ($t = sql_fetch($s)) { |
|
| 545 | + if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
|
| 546 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 547 | + if ($t['statut'] == '0minirezo') { |
|
| 548 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + sql_free($s); |
|
| 553 | + if ($p1) { |
|
| 554 | + ecrire_fichier($htpasswd, $p1); |
|
| 555 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 556 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | 559 | } |
@@ -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,20 +76,20 @@ 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 | 84 | include_spip('auth/sha256.inc'); |
| 85 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 85 | + $hash = spip_sha256($row['alea_actuel'].$pass); |
|
| 86 | 86 | $methode = 'sha256'; |
| 87 | 87 | } |
| 88 | 88 | if ($row['pass'] === $hash) { |
| 89 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 89 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode", 'auth'._LOG_DEBUG); |
|
| 90 | 90 | // 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 |
| 91 | 91 | if (!empty($row['backup_cles'])) { |
| 92 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 92 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.(int) $row['id_auteur']); |
|
| 93 | 93 | } |
| 94 | 94 | break; |
| 95 | 95 | } |
@@ -107,19 +107,19 @@ discard block |
||
| 107 | 107 | && !empty($row['backup_cles']) |
| 108 | 108 | ) { |
| 109 | 109 | if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
| 110 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 110 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur'], 'auth'._LOG_INFO_IMPORTANTE); |
|
| 111 | 111 | if ($cles->save()) { |
| 112 | 112 | $secret = $cles->getSecretAuth(); |
| 113 | 113 | } |
| 114 | 114 | else { |
| 115 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 115 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 116 | 116 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 117 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | else { |
| 121 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 121 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide", 'auth'._LOG_ERREUR); |
|
| 122 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.(int) $row['id_auteur']); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | unset($row); |
| 128 | 128 | } |
| 129 | 129 | else { |
| 130 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 130 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier", 'auth'._LOG_DEBUG); |
|
| 131 | 131 | } |
| 132 | 132 | break; |
| 133 | 133 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | @sql_update( |
| 173 | 173 | 'spip_auteurs', |
| 174 | 174 | $set, |
| 175 | - 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 175 | + 'id_auteur='.(int) $row['id_auteur'].' AND pass='.sql_quote( |
|
| 176 | 176 | $row['pass'], |
| 177 | 177 | $serveur, |
| 178 | 178 | 'text' |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | // si force, on ne verifie pas la presence d'un backup chez un webmestre |
| 221 | 221 | if ($force) { |
| 222 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 222 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth'._LOG_INFO_IMPORTANTE); |
|
| 223 | 223 | $secret = $cles->getSecretAuth(true); |
| 224 | 224 | return true; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 227 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''"); |
|
| 228 | 228 | $has_backup = array_column($has_backup, 'id_auteur'); |
| 229 | 229 | if ($has_backup === []) { |
| 230 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 230 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth'._LOG_INFO_IMPORTANTE); |
|
| 231 | 231 | if ($secret = $cles->getSecretAuth(true)) { |
| 232 | 232 | return true; |
| 233 | 233 | } |
| 234 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 234 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 235 | 235 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 236 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 236 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 237 | 237 | } |
| 238 | 238 | else { |
| 239 | - spip_log('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', 'auth' . _LOG_ERREUR); |
|
| 239 | + spip_log('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', 'auth'._LOG_ERREUR); |
|
| 240 | 240 | } |
| 241 | 241 | return false; |
| 242 | 242 | } |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | $flux['data'] .= |
| 254 | 254 | '<script type="text/javascript">/*<![CDATA[*/' |
| 255 | 255 | . "$js\n" |
| 256 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 257 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 256 | + . "var login_info={'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 257 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 258 | 258 | . "'informe_auteur_en_cours':false," |
| 259 | 259 | . "'attente_informe':0};" |
| 260 | 260 | . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | } else { |
| 295 | 295 | $n = sql_countsel( |
| 296 | 296 | 'spip_auteurs', |
| 297 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 297 | + 'login='.sql_quote($new_login).' AND id_auteur!='.(int) $id_auteur." AND statut!='5poubelle'", |
|
| 298 | 298 | '', |
| 299 | 299 | '', |
| 300 | 300 | $serveur |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | if ( |
| 324 | 324 | !($id_auteur = (int) $id_auteur) |
| 325 | - || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | + || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.(int) $id_auteur, '', '', '', '', $serveur) |
|
| 326 | 326 | ) { |
| 327 | 327 | return false; |
| 328 | 328 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $anciens = sql_allfetsel( |
| 338 | 338 | 'id_auteur', |
| 339 | 339 | 'spip_auteurs', |
| 340 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 340 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", |
|
| 341 | 341 | '', |
| 342 | 342 | '', |
| 343 | 343 | '', |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | $r = sql_getfetsel( |
| 372 | 372 | 'login', |
| 373 | 373 | 'spip_auteurs', |
| 374 | - "statut<>'5poubelle'" . |
|
| 375 | - ' AND (length(pass)>0)' . |
|
| 374 | + "statut<>'5poubelle'". |
|
| 375 | + ' AND (length(pass)>0)'. |
|
| 376 | 376 | " AND (login=$l)", |
| 377 | 377 | '', |
| 378 | 378 | '', |
@@ -391,8 +391,8 @@ discard block |
||
| 391 | 391 | return sql_getfetsel( |
| 392 | 392 | 'login', |
| 393 | 393 | 'spip_auteurs', |
| 394 | - "statut<>'5poubelle'" . |
|
| 395 | - ' AND (length(pass)>0)' . |
|
| 394 | + "statut<>'5poubelle'". |
|
| 395 | + ' AND (length(pass)>0)'. |
|
| 396 | 396 | " AND (login<>'' AND (nom=$l OR email=$l))", |
| 397 | 397 | '', |
| 398 | 398 | '', |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | if ( |
| 460 | 460 | !($id_auteur = (int) $id_auteur) |
| 461 | - || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | + || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.(int) $id_auteur, '', '', '', '', $serveur)) |
|
| 462 | 462 | ) { |
| 463 | 463 | return false; |
| 464 | 464 | } |
@@ -515,8 +515,8 @@ discard block |
||
| 515 | 515 | if ( |
| 516 | 516 | isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
| 517 | 517 | ) { |
| 518 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 519 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 518 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 519 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 520 | 520 | |
| 521 | 521 | // Cette variable de configuration peut etre posee par un plugin |
| 522 | 522 | // par exemple acces_restreint ; |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
| 526 | 526 | ) { |
| 527 | 527 | spip_unlink($htpasswd); |
| 528 | - spip_unlink($htpasswd . '-admin'); |
|
| 528 | + spip_unlink($htpasswd.'-admin'); |
|
| 529 | 529 | |
| 530 | 530 | return; |
| 531 | 531 | } |
@@ -543,16 +543,16 @@ discard block |
||
| 543 | 543 | ); |
| 544 | 544 | while ($t = sql_fetch($s)) { |
| 545 | 545 | if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
| 546 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 546 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 547 | 547 | if ($t['statut'] == '0minirezo') { |
| 548 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 548 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | sql_free($s); |
| 553 | 553 | if ($p1) { |
| 554 | 554 | ecrire_fichier($htpasswd, $p1); |
| 555 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 555 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 556 | 556 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 557 | 557 | } |
| 558 | 558 | } |
@@ -110,14 +110,12 @@ discard block |
||
| 110 | 110 | spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
| 111 | 111 | if ($cles->save()) { |
| 112 | 112 | $secret = $cles->getSecretAuth(); |
| 113 | - } |
|
| 114 | - else { |
|
| 113 | + } else { |
|
| 115 | 114 | spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 116 | 115 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 117 | 116 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 118 | 117 | } |
| 119 | - } |
|
| 120 | - else { |
|
| 118 | + } else { |
|
| 121 | 119 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
| 122 | 120 | sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
| 123 | 121 | } |
@@ -125,8 +123,7 @@ discard block |
||
| 125 | 123 | |
| 126 | 124 | if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
| 127 | 125 | unset($row); |
| 128 | - } |
|
| 129 | - else { |
|
| 126 | + } else { |
|
| 130 | 127 | spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
| 131 | 128 | } |
| 132 | 129 | break; |
@@ -234,8 +231,7 @@ discard block |
||
| 234 | 231 | spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 235 | 232 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 236 | 233 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 237 | - } |
|
| 238 | - else { |
|
| 234 | + } else { |
|
| 239 | 235 | spip_log('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', 'auth' . _LOG_ERREUR); |
| 240 | 236 | } |
| 241 | 237 | return false; |
@@ -468,8 +464,7 @@ discard block |
||
| 468 | 464 | if (!$secret) { |
| 469 | 465 | if (auth_spip_initialiser_secret()) { |
| 470 | 466 | $secret = $cles->getSecretAuth(); |
| 471 | - } |
|
| 472 | - else { |
|
| 467 | + } else { |
|
| 473 | 468 | return false; |
| 474 | 469 | } |
| 475 | 470 | } |
@@ -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_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 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_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 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_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 148 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 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 | - } |
|
| 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 | 65 | |
| 66 | - return $x . $texte; |
|
| 66 | + return $x . $texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -82,26 +82,26 @@ discard block |
||
| 82 | 82 | * @return string Contenu de la page envoyée au navigateur |
| 83 | 83 | **/ |
| 84 | 84 | function f_surligne($texte) { |
| 85 | - if (!$GLOBALS['html']) { |
|
| 86 | - return $texte; |
|
| 87 | - } |
|
| 88 | - $rech = _request('var_recherche'); |
|
| 89 | - if ( |
|
| 90 | - !$rech |
|
| 91 | - && (!defined('_SURLIGNE_RECHERCHE_REFERERS') || !_SURLIGNE_RECHERCHE_REFERERS || !isset($_SERVER['HTTP_REFERER'])) |
|
| 92 | - ) { |
|
| 93 | - return $texte; |
|
| 94 | - } |
|
| 95 | - include_spip('inc/surligne'); |
|
| 85 | + if (!$GLOBALS['html']) { |
|
| 86 | + return $texte; |
|
| 87 | + } |
|
| 88 | + $rech = _request('var_recherche'); |
|
| 89 | + if ( |
|
| 90 | + !$rech |
|
| 91 | + && (!defined('_SURLIGNE_RECHERCHE_REFERERS') || !_SURLIGNE_RECHERCHE_REFERERS || !isset($_SERVER['HTTP_REFERER'])) |
|
| 92 | + ) { |
|
| 93 | + return $texte; |
|
| 94 | + } |
|
| 95 | + include_spip('inc/surligne'); |
|
| 96 | 96 | |
| 97 | - if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 98 | - $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $_SERVER['HTTP_REFERER']); |
|
| 99 | - } |
|
| 100 | - if ($rech) { |
|
| 101 | - $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $rech); |
|
| 102 | - } |
|
| 97 | + if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 98 | + $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $_SERVER['HTTP_REFERER']); |
|
| 99 | + } |
|
| 100 | + if ($rech) { |
|
| 101 | + $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $rech); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - return surligner_mots($texte, $rech); |
|
| 104 | + return surligner_mots($texte, $rech); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -118,33 +118,33 @@ discard block |
||
| 118 | 118 | * @return string Contenu de la page envoyée au navigateur |
| 119 | 119 | **/ |
| 120 | 120 | function f_tidy($texte) { |
| 121 | - /** |
|
| 122 | - * Indentation à faire ? |
|
| 123 | - * |
|
| 124 | - * - true : actif. |
|
| 125 | - * - false par défaut. |
|
| 126 | - */ |
|
| 121 | + /** |
|
| 122 | + * Indentation à faire ? |
|
| 123 | + * |
|
| 124 | + * - true : actif. |
|
| 125 | + * - false par défaut. |
|
| 126 | + */ |
|
| 127 | 127 | |
| 128 | - if ( |
|
| 129 | - $GLOBALS['xhtml'] |
|
| 130 | - && $GLOBALS['html'] |
|
| 131 | - && strlen($texte) |
|
| 132 | - && !headers_sent() |
|
| 133 | - ) { |
|
| 134 | - # Compatibilite ascendante |
|
| 135 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 136 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 137 | - } |
|
| 128 | + if ( |
|
| 129 | + $GLOBALS['xhtml'] |
|
| 130 | + && $GLOBALS['html'] |
|
| 131 | + && strlen($texte) |
|
| 132 | + && !headers_sent() |
|
| 133 | + ) { |
|
| 134 | + # Compatibilite ascendante |
|
| 135 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 136 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 140 | - spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 141 | - $f = charger_fonction('sax', 'xml'); |
|
| 142 | - } |
|
| 139 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 140 | + spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 141 | + $f = charger_fonction('sax', 'xml'); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - return $f($texte); |
|
| 145 | - } |
|
| 144 | + return $f($texte); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return $texte; |
|
| 147 | + return $texte; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -163,24 +163,24 @@ discard block |
||
| 163 | 163 | * @return string Contenu de la page envoyée au navigateur |
| 164 | 164 | **/ |
| 165 | 165 | function f_insert_head($texte) { |
| 166 | - if (!$GLOBALS['html']) { |
|
| 167 | - return $texte; |
|
| 168 | - } |
|
| 169 | - include_spip('public/admin'); // pour strripos |
|
| 166 | + if (!$GLOBALS['html']) { |
|
| 167 | + return $texte; |
|
| 168 | + } |
|
| 169 | + include_spip('public/admin'); // pour strripos |
|
| 170 | 170 | |
| 171 | - if ( |
|
| 172 | - !($pos = stripos($texte, '</head>')) |
|
| 173 | - && !($pos = stripos($texte, '<body>')) |
|
| 174 | - ) { |
|
| 175 | - $pos = 0; |
|
| 176 | - } |
|
| 171 | + if ( |
|
| 172 | + !($pos = stripos($texte, '</head>')) |
|
| 173 | + && !($pos = stripos($texte, '<body>')) |
|
| 174 | + ) { |
|
| 175 | + $pos = 0; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 179 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 180 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 181 | - } |
|
| 178 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 179 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 180 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $texte; |
|
| 183 | + return $texte; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -196,34 +196,34 @@ discard block |
||
| 196 | 196 | * @return string Contenu de la page envoyée au navigateur |
| 197 | 197 | **/ |
| 198 | 198 | function f_admin($texte) { |
| 199 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 200 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 201 | - $x = "<div class='spip-previsu' " |
|
| 202 | - . http_style_background('preview-32.png', '', 32) |
|
| 203 | - . '>' |
|
| 204 | - . _T('previsualisation') |
|
| 205 | - . '</div>'; |
|
| 206 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 207 | - $pos = strlen($texte); |
|
| 208 | - } |
|
| 209 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 210 | - // pas de preview en fenetre enfant |
|
| 211 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 212 | - if (!$pos = stripos($texte, '<head') || !$pos = strpos($texte, '>', $pos)) { |
|
| 213 | - $pos = -1; |
|
| 214 | - } |
|
| 215 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 216 | - } |
|
| 199 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 200 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 201 | + $x = "<div class='spip-previsu' " |
|
| 202 | + . http_style_background('preview-32.png', '', 32) |
|
| 203 | + . '>' |
|
| 204 | + . _T('previsualisation') |
|
| 205 | + . '</div>'; |
|
| 206 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 207 | + $pos = strlen($texte); |
|
| 208 | + } |
|
| 209 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 210 | + // pas de preview en fenetre enfant |
|
| 211 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 212 | + if (!$pos = stripos($texte, '<head') || !$pos = strpos($texte, '>', $pos)) { |
|
| 213 | + $pos = -1; |
|
| 214 | + } |
|
| 215 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 219 | - include_spip('public/admin'); |
|
| 220 | - $texte = affiche_boutons_admin($texte); |
|
| 221 | - } |
|
| 222 | - if (_request('var_mode') == 'noajax') { |
|
| 223 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 224 | - } |
|
| 218 | + if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 219 | + include_spip('public/admin'); |
|
| 220 | + $texte = affiche_boutons_admin($texte); |
|
| 221 | + } |
|
| 222 | + if (_request('var_mode') == 'noajax') { |
|
| 223 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - return $texte; |
|
| 226 | + return $texte; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | * @return array $flux Description et contenu de l'inclusion |
| 242 | 242 | **/ |
| 243 | 243 | function f_recuperer_fond($flux) { |
| 244 | - if (!test_espace_prive()) { |
|
| 245 | - return $flux; |
|
| 246 | - } |
|
| 244 | + if (!test_espace_prive()) { |
|
| 245 | + return $flux; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - return f_afficher_blocs_ecrire($flux); |
|
| 248 | + return f_afficher_blocs_ecrire($flux); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -259,30 +259,30 @@ discard block |
||
| 259 | 259 | * @return string Contenu de la page envoyée au navigateur |
| 260 | 260 | */ |
| 261 | 261 | function f_queue($texte) { |
| 262 | - // eviter une inclusion si rien a faire |
|
| 263 | - if ( |
|
| 264 | - _request('action') == 'cron' |
|
| 265 | - || queue_sleep_time_to_next_job() > 0 |
|
| 266 | - || defined('_DEBUG_BLOCK_QUEUE') |
|
| 267 | - ) { |
|
| 268 | - return $texte; |
|
| 269 | - } |
|
| 262 | + // eviter une inclusion si rien a faire |
|
| 263 | + if ( |
|
| 264 | + _request('action') == 'cron' |
|
| 265 | + || queue_sleep_time_to_next_job() > 0 |
|
| 266 | + || defined('_DEBUG_BLOCK_QUEUE') |
|
| 267 | + ) { |
|
| 268 | + return $texte; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - include_spip('inc/queue'); |
|
| 272 | - $code = queue_affichage_cron(); |
|
| 271 | + include_spip('inc/queue'); |
|
| 272 | + $code = queue_affichage_cron(); |
|
| 273 | 273 | |
| 274 | - // si rien a afficher |
|
| 275 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 276 | - if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 277 | - return $texte; |
|
| 278 | - } |
|
| 274 | + // si rien a afficher |
|
| 275 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 276 | + if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 277 | + return $texte; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 281 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 282 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 283 | - } else { |
|
| 284 | - $texte .= $code; |
|
| 285 | - } |
|
| 280 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 281 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 282 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 283 | + } else { |
|
| 284 | + $texte .= $code; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - return $texte; |
|
| 287 | + return $texte; |
|
| 288 | 288 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return $x . $texte; |
|
| 66 | + return $x.$texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
| 179 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 179 | + $insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n"; |
|
| 180 | 180 | $texte = substr_replace($texte, $insert, $pos, 0); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | $texte = substr_replace($texte, $x, $pos, 0); |
| 210 | 210 | // pas de preview en fenetre enfant |
| 211 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 211 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes((string) $GLOBALS['meta']['adresse_site'])."';}</script>"; |
|
| 212 | 212 | if (!$pos = stripos($texte, '<head') || !$pos = strpos($texte, '>', $pos)) { |
| 213 | 213 | $pos = -1; |
| 214 | 214 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
| 281 | 281 | if (($p = strpos($texte, '</body>')) !== false) { |
| 282 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 282 | + $texte = substr($texte, 0, $p).$code.substr($texte, $p); |
|
| 283 | 283 | } else { |
| 284 | 284 | $texte .= $code; |
| 285 | 285 | } |
@@ -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 | include_spip('inc/charsets'); |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | function exporter_csv_champ($champ) { |
| 34 | - #$champ = str_replace("\r", "\n", $champ); |
|
| 35 | - #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 36 | - #$champ = str_replace("\n", ", ", $champ); |
|
| 37 | - $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 38 | - $champ = str_replace('"', '""', $champ); |
|
| 34 | + #$champ = str_replace("\r", "\n", $champ); |
|
| 35 | + #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 36 | + #$champ = str_replace("\n", ", ", $champ); |
|
| 37 | + $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 38 | + $champ = str_replace('"', '""', $champ); |
|
| 39 | 39 | |
| 40 | - return '"' . $champ . '"'; |
|
| 40 | + return '"' . $champ . '"'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -54,15 +54,15 @@ discard block |
||
| 54 | 54 | * @return string |
| 55 | 55 | */ |
| 56 | 56 | function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) { |
| 57 | - if ($callback) { |
|
| 58 | - $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 59 | - } |
|
| 60 | - $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 61 | - if ($importer_charset) { |
|
| 62 | - $output = str_replace('’', '\'', $output); |
|
| 63 | - $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 64 | - } |
|
| 65 | - return $output; |
|
| 57 | + if ($callback) { |
|
| 58 | + $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 59 | + } |
|
| 60 | + $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 61 | + if ($importer_charset) { |
|
| 62 | + $output = str_replace('’', '\'', $output); |
|
| 63 | + $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 64 | + } |
|
| 65 | + return $output; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | 76 | function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) { |
| 77 | - return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 77 | + return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -104,107 +104,107 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function inc_exporter_csv_dist($titre, $resource, $options = []) { |
| 106 | 106 | |
| 107 | - // support ancienne syntaxe |
|
| 108 | - // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 109 | - if (is_string($options)) { |
|
| 110 | - $args = func_get_args(); |
|
| 111 | - $options = []; |
|
| 112 | - foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 113 | - if (!empty($args[$k])) { |
|
| 114 | - $options[$option] = $args[$k]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $default_options = [ |
|
| 120 | - 'fichier' => null, // par défaut = $titre |
|
| 121 | - 'extension' => null, // par défaut = choix auto |
|
| 122 | - 'delim' => ',', |
|
| 123 | - 'entetes' => null, |
|
| 124 | - 'envoyer' => true, |
|
| 125 | - 'charset' => null, |
|
| 126 | - 'callback' => null, |
|
| 127 | - ]; |
|
| 128 | - $options = array_merge($default_options, $options); |
|
| 129 | - |
|
| 130 | - // Délimiteur |
|
| 131 | - if ($options['delim'] == 'TAB') { |
|
| 132 | - $options['delim'] = "\t"; |
|
| 133 | - } |
|
| 134 | - if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 135 | - $options['delim'] = ','; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Nom du fichier : celui indiqué dans les options, sinon le titre |
|
| 139 | - // Normalisation : uniquement les caractères non spéciaux, tirets, underscore et point + remplacer espaces par underscores |
|
| 140 | - $filename = $options['fichier'] ?? translitteration(textebrut(typo($titre))); |
|
| 141 | - $filename = preg_replace([',[^\w\-_\.\s]+,', ',\s+,'], ['', '_'], trim((string) $filename)); |
|
| 142 | - $filename = rtrim($filename, '.'); |
|
| 143 | - |
|
| 144 | - // Extension : celle indiquée en option, sinon choisie selon le délimiteur |
|
| 145 | - // Normalisation : uniquement les charactères non spéciaux |
|
| 146 | - if (!empty($options['extension'])) { |
|
| 147 | - $options['extension'] = preg_replace(',[^\w]+,', '', trim((string) $options['extension'])); |
|
| 148 | - } |
|
| 149 | - $extension = $options['extension'] ?? ($options['delim'] === ',' ? 'csv' : 'xls'); |
|
| 150 | - |
|
| 151 | - // Fichier |
|
| 152 | - $basename = "$filename.$extension"; |
|
| 153 | - |
|
| 154 | - // Charset : celui indiqué en option, sinon celui compatible excel si nécessaire, sinon celui du site |
|
| 155 | - // Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 156 | - $charset_site = $GLOBALS['meta']['charset']; |
|
| 157 | - $charset_excel = ($extension === 'xls' ? 'iso-8859-1' : null); |
|
| 158 | - $charset = $options['charset'] ?? $charset_excel ?? $charset_site; |
|
| 159 | - $importer_charset = (($charset === $charset_site) ? null : $charset); |
|
| 160 | - |
|
| 161 | - $output = ''; |
|
| 162 | - $nb = 0; |
|
| 163 | - if (!empty($options['entetes']) && is_array($options['entetes'])) { |
|
| 164 | - $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 165 | - } |
|
| 166 | - // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 167 | - $nb++; |
|
| 168 | - |
|
| 169 | - if ($options['envoyer']) { |
|
| 170 | - $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 171 | - header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 172 | - header("Content-Disposition: $disposition; filename=$basename"); |
|
| 173 | - |
|
| 174 | - // Vider tous les tampons |
|
| 175 | - $level = @ob_get_level(); |
|
| 176 | - while ($level--) { |
|
| 177 | - @ob_end_flush(); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 182 | - // sinon on ecrit directement sur stdout |
|
| 183 | - if ($options['envoyer'] && $options['envoyer'] !== 'attachment') { |
|
| 184 | - $fichier = 'php://output'; |
|
| 185 | - } |
|
| 186 | - else { |
|
| 187 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $fp = fopen($fichier, 'w'); |
|
| 191 | - $length = fwrite($fp, $output); |
|
| 192 | - |
|
| 193 | - while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 194 | - $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 195 | - $length += fwrite($fp, $output); |
|
| 196 | - $nb++; |
|
| 197 | - } |
|
| 198 | - fclose($fp); |
|
| 199 | - |
|
| 200 | - if ($options['envoyer']) { |
|
| 201 | - if ($options['envoyer'] === 'attachment') { |
|
| 202 | - header("Content-Length: $length"); |
|
| 203 | - readfile($fichier); |
|
| 204 | - } |
|
| 205 | - // si on a envoye inline, c'est deja tout bon |
|
| 206 | - exit; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return $fichier; |
|
| 107 | + // support ancienne syntaxe |
|
| 108 | + // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 109 | + if (is_string($options)) { |
|
| 110 | + $args = func_get_args(); |
|
| 111 | + $options = []; |
|
| 112 | + foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 113 | + if (!empty($args[$k])) { |
|
| 114 | + $options[$option] = $args[$k]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $default_options = [ |
|
| 120 | + 'fichier' => null, // par défaut = $titre |
|
| 121 | + 'extension' => null, // par défaut = choix auto |
|
| 122 | + 'delim' => ',', |
|
| 123 | + 'entetes' => null, |
|
| 124 | + 'envoyer' => true, |
|
| 125 | + 'charset' => null, |
|
| 126 | + 'callback' => null, |
|
| 127 | + ]; |
|
| 128 | + $options = array_merge($default_options, $options); |
|
| 129 | + |
|
| 130 | + // Délimiteur |
|
| 131 | + if ($options['delim'] == 'TAB') { |
|
| 132 | + $options['delim'] = "\t"; |
|
| 133 | + } |
|
| 134 | + if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 135 | + $options['delim'] = ','; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Nom du fichier : celui indiqué dans les options, sinon le titre |
|
| 139 | + // Normalisation : uniquement les caractères non spéciaux, tirets, underscore et point + remplacer espaces par underscores |
|
| 140 | + $filename = $options['fichier'] ?? translitteration(textebrut(typo($titre))); |
|
| 141 | + $filename = preg_replace([',[^\w\-_\.\s]+,', ',\s+,'], ['', '_'], trim((string) $filename)); |
|
| 142 | + $filename = rtrim($filename, '.'); |
|
| 143 | + |
|
| 144 | + // Extension : celle indiquée en option, sinon choisie selon le délimiteur |
|
| 145 | + // Normalisation : uniquement les charactères non spéciaux |
|
| 146 | + if (!empty($options['extension'])) { |
|
| 147 | + $options['extension'] = preg_replace(',[^\w]+,', '', trim((string) $options['extension'])); |
|
| 148 | + } |
|
| 149 | + $extension = $options['extension'] ?? ($options['delim'] === ',' ? 'csv' : 'xls'); |
|
| 150 | + |
|
| 151 | + // Fichier |
|
| 152 | + $basename = "$filename.$extension"; |
|
| 153 | + |
|
| 154 | + // Charset : celui indiqué en option, sinon celui compatible excel si nécessaire, sinon celui du site |
|
| 155 | + // Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 156 | + $charset_site = $GLOBALS['meta']['charset']; |
|
| 157 | + $charset_excel = ($extension === 'xls' ? 'iso-8859-1' : null); |
|
| 158 | + $charset = $options['charset'] ?? $charset_excel ?? $charset_site; |
|
| 159 | + $importer_charset = (($charset === $charset_site) ? null : $charset); |
|
| 160 | + |
|
| 161 | + $output = ''; |
|
| 162 | + $nb = 0; |
|
| 163 | + if (!empty($options['entetes']) && is_array($options['entetes'])) { |
|
| 164 | + $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 165 | + } |
|
| 166 | + // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 167 | + $nb++; |
|
| 168 | + |
|
| 169 | + if ($options['envoyer']) { |
|
| 170 | + $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 171 | + header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 172 | + header("Content-Disposition: $disposition; filename=$basename"); |
|
| 173 | + |
|
| 174 | + // Vider tous les tampons |
|
| 175 | + $level = @ob_get_level(); |
|
| 176 | + while ($level--) { |
|
| 177 | + @ob_end_flush(); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 182 | + // sinon on ecrit directement sur stdout |
|
| 183 | + if ($options['envoyer'] && $options['envoyer'] !== 'attachment') { |
|
| 184 | + $fichier = 'php://output'; |
|
| 185 | + } |
|
| 186 | + else { |
|
| 187 | + $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $fp = fopen($fichier, 'w'); |
|
| 191 | + $length = fwrite($fp, $output); |
|
| 192 | + |
|
| 193 | + while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 194 | + $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 195 | + $length += fwrite($fp, $output); |
|
| 196 | + $nb++; |
|
| 197 | + } |
|
| 198 | + fclose($fp); |
|
| 199 | + |
|
| 200 | + if ($options['envoyer']) { |
|
| 201 | + if ($options['envoyer'] === 'attachment') { |
|
| 202 | + header("Content-Length: $length"); |
|
| 203 | + readfile($fichier); |
|
| 204 | + } |
|
| 205 | + // si on a envoye inline, c'est deja tout bon |
|
| 206 | + exit; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return $fichier; |
|
| 210 | 210 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
| 38 | 38 | $champ = str_replace('"', '""', $champ); |
| 39 | 39 | |
| 40 | - return '"' . $champ . '"'; |
|
| 40 | + return '"'.$champ.'"'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | if ($callback) { |
| 58 | 58 | $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
| 59 | 59 | } |
| 60 | - $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 60 | + $output = implode($delim, array_map('exporter_csv_champ', $ligne))."\r\n"; |
|
| 61 | 61 | if ($importer_charset) { |
| 62 | 62 | $output = str_replace('’', '\'', $output); |
| 63 | 63 | $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $fichier = 'php://output'; |
| 185 | 185 | } |
| 186 | 186 | else { |
| 187 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
|
| 187 | + $fichier = sous_repertoire(_DIR_CACHE, 'export').$basename; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $fp = fopen($fichier, 'w'); |
@@ -182,8 +182,7 @@ |
||
| 182 | 182 | // sinon on ecrit directement sur stdout |
| 183 | 183 | if ($options['envoyer'] && $options['envoyer'] !== 'attachment') { |
| 184 | 184 | $fichier = 'php://output'; |
| 185 | - } |
|
| 186 | - else { |
|
| 185 | + } else { |
|
| 187 | 186 | $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
| 188 | 187 | } |
| 189 | 188 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 23 | 23 | |
@@ -30,161 +30,161 @@ discard block |
||
| 30 | 30 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 31 | 31 | */ |
| 32 | 32 | function couleur_html_to_hex($couleur) { |
| 33 | - $couleurs_html = [ |
|
| 34 | - 'aliceblue' => 'F0F8FF', |
|
| 35 | - 'antiquewhite' => 'FAEBD7', |
|
| 36 | - 'aqua' => '00FFFF', |
|
| 37 | - 'aquamarine' => '7FFFD4', |
|
| 38 | - 'azure' => 'F0FFFF', |
|
| 39 | - 'beige' => 'F5F5DC', |
|
| 40 | - 'bisque' => 'FFE4C4', |
|
| 41 | - 'black' => '000000', |
|
| 42 | - 'blanchedalmond' => 'FFEBCD', |
|
| 43 | - 'blue' => '0000FF', |
|
| 44 | - 'blueviolet' => '8A2BE2', |
|
| 45 | - 'brown' => 'A52A2A', |
|
| 46 | - 'burlywood' => 'DEB887', |
|
| 47 | - 'cadetblue' => '5F9EA0', |
|
| 48 | - 'chartreuse' => '7FFF00', |
|
| 49 | - 'chocolate' => 'D2691E', |
|
| 50 | - 'coral' => 'FF7F50', |
|
| 51 | - 'cornflowerblue' => '6495ED', |
|
| 52 | - 'cornsilk' => 'FFF8DC', |
|
| 53 | - 'crimson' => 'DC143C', |
|
| 54 | - 'cyan' => '00FFFF', |
|
| 55 | - 'darkblue' => '00008B', |
|
| 56 | - 'darkcyan' => '008B8B', |
|
| 57 | - 'darkgoldenrod' => 'B8860B', |
|
| 58 | - 'darkgray' => 'A9A9A9', |
|
| 59 | - 'darkgreen' => '006400', |
|
| 60 | - 'darkgrey' => 'A9A9A9', |
|
| 61 | - 'darkkhaki' => 'BDB76B', |
|
| 62 | - 'darkmagenta' => '8B008B', |
|
| 63 | - 'darkolivegreen' => '556B2F', |
|
| 64 | - 'darkorange' => 'FF8C00', |
|
| 65 | - 'darkorchid' => '9932CC', |
|
| 66 | - 'darkred' => '8B0000', |
|
| 67 | - 'darksalmon' => 'E9967A', |
|
| 68 | - 'darkseagreen' => '8FBC8F', |
|
| 69 | - 'darkslateblue' => '483D8B', |
|
| 70 | - 'darkslategray' => '2F4F4F', |
|
| 71 | - 'darkslategrey' => '2F4F4F', |
|
| 72 | - 'darkturquoise' => '00CED1', |
|
| 73 | - 'darkviolet' => '9400D3', |
|
| 74 | - 'deeppink' => 'FF1493', |
|
| 75 | - 'deepskyblue' => '00BFFF', |
|
| 76 | - 'dimgray' => '696969', |
|
| 77 | - 'dimgrey' => '696969', |
|
| 78 | - 'dodgerblue' => '1E90FF', |
|
| 79 | - 'firebrick' => 'B22222', |
|
| 80 | - 'floralwhite' => 'FFFAF0', |
|
| 81 | - 'forestgreen' => '228B22', |
|
| 82 | - 'fuchsia' => 'FF00FF', |
|
| 83 | - 'gainsboro' => 'DCDCDC', |
|
| 84 | - 'ghostwhite' => 'F8F8FF', |
|
| 85 | - 'gold' => 'FFD700', |
|
| 86 | - 'goldenrod' => 'DAA520', |
|
| 87 | - 'gray' => '808080', |
|
| 88 | - 'green' => '008000', |
|
| 89 | - 'greenyellow' => 'ADFF2F', |
|
| 90 | - 'grey' => '808080', |
|
| 91 | - 'honeydew' => 'F0FFF0', |
|
| 92 | - 'hotpink' => 'FF69B4', |
|
| 93 | - 'indianred' => 'CD5C5C', |
|
| 94 | - 'indigo' => '4B0082', |
|
| 95 | - 'ivory' => 'FFFFF0', |
|
| 96 | - 'khaki' => 'F0E68C', |
|
| 97 | - 'lavender' => 'E6E6FA', |
|
| 98 | - 'lavenderblush' => 'FFF0F5', |
|
| 99 | - 'lawngreen' => '7CFC00', |
|
| 100 | - 'lemonchiffon' => 'FFFACD', |
|
| 101 | - 'lightblue' => 'ADD8E6', |
|
| 102 | - 'lightcoral' => 'F08080', |
|
| 103 | - 'lightcyan' => 'E0FFFF', |
|
| 104 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 105 | - 'lightgray' => 'D3D3D3', |
|
| 106 | - 'lightgreen' => '90EE90', |
|
| 107 | - 'lightgrey' => 'D3D3D3', |
|
| 108 | - 'lightpink' => 'FFB6C1', |
|
| 109 | - 'lightsalmon' => 'FFA07A', |
|
| 110 | - 'lightseagreen' => '20B2AA', |
|
| 111 | - 'lightskyblue' => '87CEFA', |
|
| 112 | - 'lightslategray' => '778899', |
|
| 113 | - 'lightslategrey' => '778899', |
|
| 114 | - 'lightsteelblue' => 'B0C4DE', |
|
| 115 | - 'lightyellow' => 'FFFFE0', |
|
| 116 | - 'lime' => '00FF00', |
|
| 117 | - 'limegreen' => '32CD32', |
|
| 118 | - 'linen' => 'FAF0E6', |
|
| 119 | - 'magenta' => 'FF00FF', |
|
| 120 | - 'maroon' => '800000', |
|
| 121 | - 'mediumaquamarine' => '66CDAA', |
|
| 122 | - 'mediumblue' => '0000CD', |
|
| 123 | - 'mediumorchid' => 'BA55D3', |
|
| 124 | - 'mediumpurple' => '9370DB', |
|
| 125 | - 'mediumseagreen' => '3CB371', |
|
| 126 | - 'mediumslateblue' => '7B68EE', |
|
| 127 | - 'mediumspringgreen' => '00FA9A', |
|
| 128 | - 'mediumturquoise' => '48D1CC', |
|
| 129 | - 'mediumvioletred' => 'C71585', |
|
| 130 | - 'midnightblue' => '191970', |
|
| 131 | - 'mintcream' => 'F5FFFA', |
|
| 132 | - 'mistyrose' => 'FFE4E1', |
|
| 133 | - 'moccasin' => 'FFE4B5', |
|
| 134 | - 'navajowhite' => 'FFDEAD', |
|
| 135 | - 'navy' => '000080', |
|
| 136 | - 'oldlace' => 'FDF5E6', |
|
| 137 | - 'olive' => '808000', |
|
| 138 | - 'olivedrab' => '6B8E23', |
|
| 139 | - 'orange' => 'FFA500', |
|
| 140 | - 'orangered' => 'FF4500', |
|
| 141 | - 'orchid' => 'DA70D6', |
|
| 142 | - 'palegoldenrod' => 'EEE8AA', |
|
| 143 | - 'palegreen' => '98FB98', |
|
| 144 | - 'paleturquoise' => 'AFEEEE', |
|
| 145 | - 'palevioletred' => 'DB7093', |
|
| 146 | - 'papayawhip' => 'FFEFD5', |
|
| 147 | - 'peachpuff' => 'FFDAB9', |
|
| 148 | - 'peru' => 'CD853F', |
|
| 149 | - 'pink' => 'FFC0CB', |
|
| 150 | - 'plum' => 'DDA0DD', |
|
| 151 | - 'powderblue' => 'B0E0E6', |
|
| 152 | - 'purple' => '800080', |
|
| 153 | - 'rebeccapurple' => '663399', |
|
| 154 | - 'red' => 'FF0000', |
|
| 155 | - 'rosybrown' => 'BC8F8F', |
|
| 156 | - 'royalblue' => '4169E1', |
|
| 157 | - 'saddlebrown' => '8B4513', |
|
| 158 | - 'salmon' => 'FA8072', |
|
| 159 | - 'sandybrown' => 'F4A460', |
|
| 160 | - 'seagreen' => '2E8B57', |
|
| 161 | - 'seashell' => 'FFF5EE', |
|
| 162 | - 'sienna' => 'A0522D', |
|
| 163 | - 'silver' => 'C0C0C0', |
|
| 164 | - 'skyblue' => '87CEEB', |
|
| 165 | - 'slateblue' => '6A5ACD', |
|
| 166 | - 'slategray' => '708090', |
|
| 167 | - 'slategrey' => '708090', |
|
| 168 | - 'snow' => 'FFFAFA', |
|
| 169 | - 'springgreen' => '00FF7F', |
|
| 170 | - 'steelblue' => '4682B4', |
|
| 171 | - 'tan' => 'D2B48C', |
|
| 172 | - 'teal' => '008080', |
|
| 173 | - 'thistle' => 'D8BFD8', |
|
| 174 | - 'tomato' => 'FF6347', |
|
| 175 | - 'turquoise' => '40E0D0', |
|
| 176 | - 'violet' => 'EE82EE', |
|
| 177 | - 'wheat' => 'F5DEB3', |
|
| 178 | - 'white' => 'FFFFFF', |
|
| 179 | - 'whitesmoke' => 'F5F5F5', |
|
| 180 | - 'yellow' => 'FFFF00', |
|
| 181 | - 'yellowgreen' => '9ACD32', |
|
| 182 | - ]; |
|
| 183 | - if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 184 | - return $couleurs_html[$lc]; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $couleur; |
|
| 33 | + $couleurs_html = [ |
|
| 34 | + 'aliceblue' => 'F0F8FF', |
|
| 35 | + 'antiquewhite' => 'FAEBD7', |
|
| 36 | + 'aqua' => '00FFFF', |
|
| 37 | + 'aquamarine' => '7FFFD4', |
|
| 38 | + 'azure' => 'F0FFFF', |
|
| 39 | + 'beige' => 'F5F5DC', |
|
| 40 | + 'bisque' => 'FFE4C4', |
|
| 41 | + 'black' => '000000', |
|
| 42 | + 'blanchedalmond' => 'FFEBCD', |
|
| 43 | + 'blue' => '0000FF', |
|
| 44 | + 'blueviolet' => '8A2BE2', |
|
| 45 | + 'brown' => 'A52A2A', |
|
| 46 | + 'burlywood' => 'DEB887', |
|
| 47 | + 'cadetblue' => '5F9EA0', |
|
| 48 | + 'chartreuse' => '7FFF00', |
|
| 49 | + 'chocolate' => 'D2691E', |
|
| 50 | + 'coral' => 'FF7F50', |
|
| 51 | + 'cornflowerblue' => '6495ED', |
|
| 52 | + 'cornsilk' => 'FFF8DC', |
|
| 53 | + 'crimson' => 'DC143C', |
|
| 54 | + 'cyan' => '00FFFF', |
|
| 55 | + 'darkblue' => '00008B', |
|
| 56 | + 'darkcyan' => '008B8B', |
|
| 57 | + 'darkgoldenrod' => 'B8860B', |
|
| 58 | + 'darkgray' => 'A9A9A9', |
|
| 59 | + 'darkgreen' => '006400', |
|
| 60 | + 'darkgrey' => 'A9A9A9', |
|
| 61 | + 'darkkhaki' => 'BDB76B', |
|
| 62 | + 'darkmagenta' => '8B008B', |
|
| 63 | + 'darkolivegreen' => '556B2F', |
|
| 64 | + 'darkorange' => 'FF8C00', |
|
| 65 | + 'darkorchid' => '9932CC', |
|
| 66 | + 'darkred' => '8B0000', |
|
| 67 | + 'darksalmon' => 'E9967A', |
|
| 68 | + 'darkseagreen' => '8FBC8F', |
|
| 69 | + 'darkslateblue' => '483D8B', |
|
| 70 | + 'darkslategray' => '2F4F4F', |
|
| 71 | + 'darkslategrey' => '2F4F4F', |
|
| 72 | + 'darkturquoise' => '00CED1', |
|
| 73 | + 'darkviolet' => '9400D3', |
|
| 74 | + 'deeppink' => 'FF1493', |
|
| 75 | + 'deepskyblue' => '00BFFF', |
|
| 76 | + 'dimgray' => '696969', |
|
| 77 | + 'dimgrey' => '696969', |
|
| 78 | + 'dodgerblue' => '1E90FF', |
|
| 79 | + 'firebrick' => 'B22222', |
|
| 80 | + 'floralwhite' => 'FFFAF0', |
|
| 81 | + 'forestgreen' => '228B22', |
|
| 82 | + 'fuchsia' => 'FF00FF', |
|
| 83 | + 'gainsboro' => 'DCDCDC', |
|
| 84 | + 'ghostwhite' => 'F8F8FF', |
|
| 85 | + 'gold' => 'FFD700', |
|
| 86 | + 'goldenrod' => 'DAA520', |
|
| 87 | + 'gray' => '808080', |
|
| 88 | + 'green' => '008000', |
|
| 89 | + 'greenyellow' => 'ADFF2F', |
|
| 90 | + 'grey' => '808080', |
|
| 91 | + 'honeydew' => 'F0FFF0', |
|
| 92 | + 'hotpink' => 'FF69B4', |
|
| 93 | + 'indianred' => 'CD5C5C', |
|
| 94 | + 'indigo' => '4B0082', |
|
| 95 | + 'ivory' => 'FFFFF0', |
|
| 96 | + 'khaki' => 'F0E68C', |
|
| 97 | + 'lavender' => 'E6E6FA', |
|
| 98 | + 'lavenderblush' => 'FFF0F5', |
|
| 99 | + 'lawngreen' => '7CFC00', |
|
| 100 | + 'lemonchiffon' => 'FFFACD', |
|
| 101 | + 'lightblue' => 'ADD8E6', |
|
| 102 | + 'lightcoral' => 'F08080', |
|
| 103 | + 'lightcyan' => 'E0FFFF', |
|
| 104 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 105 | + 'lightgray' => 'D3D3D3', |
|
| 106 | + 'lightgreen' => '90EE90', |
|
| 107 | + 'lightgrey' => 'D3D3D3', |
|
| 108 | + 'lightpink' => 'FFB6C1', |
|
| 109 | + 'lightsalmon' => 'FFA07A', |
|
| 110 | + 'lightseagreen' => '20B2AA', |
|
| 111 | + 'lightskyblue' => '87CEFA', |
|
| 112 | + 'lightslategray' => '778899', |
|
| 113 | + 'lightslategrey' => '778899', |
|
| 114 | + 'lightsteelblue' => 'B0C4DE', |
|
| 115 | + 'lightyellow' => 'FFFFE0', |
|
| 116 | + 'lime' => '00FF00', |
|
| 117 | + 'limegreen' => '32CD32', |
|
| 118 | + 'linen' => 'FAF0E6', |
|
| 119 | + 'magenta' => 'FF00FF', |
|
| 120 | + 'maroon' => '800000', |
|
| 121 | + 'mediumaquamarine' => '66CDAA', |
|
| 122 | + 'mediumblue' => '0000CD', |
|
| 123 | + 'mediumorchid' => 'BA55D3', |
|
| 124 | + 'mediumpurple' => '9370DB', |
|
| 125 | + 'mediumseagreen' => '3CB371', |
|
| 126 | + 'mediumslateblue' => '7B68EE', |
|
| 127 | + 'mediumspringgreen' => '00FA9A', |
|
| 128 | + 'mediumturquoise' => '48D1CC', |
|
| 129 | + 'mediumvioletred' => 'C71585', |
|
| 130 | + 'midnightblue' => '191970', |
|
| 131 | + 'mintcream' => 'F5FFFA', |
|
| 132 | + 'mistyrose' => 'FFE4E1', |
|
| 133 | + 'moccasin' => 'FFE4B5', |
|
| 134 | + 'navajowhite' => 'FFDEAD', |
|
| 135 | + 'navy' => '000080', |
|
| 136 | + 'oldlace' => 'FDF5E6', |
|
| 137 | + 'olive' => '808000', |
|
| 138 | + 'olivedrab' => '6B8E23', |
|
| 139 | + 'orange' => 'FFA500', |
|
| 140 | + 'orangered' => 'FF4500', |
|
| 141 | + 'orchid' => 'DA70D6', |
|
| 142 | + 'palegoldenrod' => 'EEE8AA', |
|
| 143 | + 'palegreen' => '98FB98', |
|
| 144 | + 'paleturquoise' => 'AFEEEE', |
|
| 145 | + 'palevioletred' => 'DB7093', |
|
| 146 | + 'papayawhip' => 'FFEFD5', |
|
| 147 | + 'peachpuff' => 'FFDAB9', |
|
| 148 | + 'peru' => 'CD853F', |
|
| 149 | + 'pink' => 'FFC0CB', |
|
| 150 | + 'plum' => 'DDA0DD', |
|
| 151 | + 'powderblue' => 'B0E0E6', |
|
| 152 | + 'purple' => '800080', |
|
| 153 | + 'rebeccapurple' => '663399', |
|
| 154 | + 'red' => 'FF0000', |
|
| 155 | + 'rosybrown' => 'BC8F8F', |
|
| 156 | + 'royalblue' => '4169E1', |
|
| 157 | + 'saddlebrown' => '8B4513', |
|
| 158 | + 'salmon' => 'FA8072', |
|
| 159 | + 'sandybrown' => 'F4A460', |
|
| 160 | + 'seagreen' => '2E8B57', |
|
| 161 | + 'seashell' => 'FFF5EE', |
|
| 162 | + 'sienna' => 'A0522D', |
|
| 163 | + 'silver' => 'C0C0C0', |
|
| 164 | + 'skyblue' => '87CEEB', |
|
| 165 | + 'slateblue' => '6A5ACD', |
|
| 166 | + 'slategray' => '708090', |
|
| 167 | + 'slategrey' => '708090', |
|
| 168 | + 'snow' => 'FFFAFA', |
|
| 169 | + 'springgreen' => '00FF7F', |
|
| 170 | + 'steelblue' => '4682B4', |
|
| 171 | + 'tan' => 'D2B48C', |
|
| 172 | + 'teal' => '008080', |
|
| 173 | + 'thistle' => 'D8BFD8', |
|
| 174 | + 'tomato' => 'FF6347', |
|
| 175 | + 'turquoise' => '40E0D0', |
|
| 176 | + 'violet' => 'EE82EE', |
|
| 177 | + 'wheat' => 'F5DEB3', |
|
| 178 | + 'white' => 'FFFFFF', |
|
| 179 | + 'whitesmoke' => 'F5F5F5', |
|
| 180 | + 'yellow' => 'FFFF00', |
|
| 181 | + 'yellowgreen' => '9ACD32', |
|
| 182 | + ]; |
|
| 183 | + if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 184 | + return $couleurs_html[$lc]; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $couleur; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -200,16 +200,16 @@ discard block |
||
| 200 | 200 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 201 | 201 | */ |
| 202 | 202 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 203 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 204 | - $hsl = [ |
|
| 205 | - 'h' => round($hsl['h'] * 360), |
|
| 206 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 207 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 208 | - ]; |
|
| 209 | - if ($format === null) { |
|
| 210 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 211 | - } |
|
| 212 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 203 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 204 | + $hsl = [ |
|
| 205 | + 'h' => round($hsl['h'] * 360), |
|
| 206 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 207 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 208 | + ]; |
|
| 209 | + if ($format === null) { |
|
| 210 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 211 | + } |
|
| 212 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -226,16 +226,16 @@ discard block |
||
| 226 | 226 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 227 | 227 | */ |
| 228 | 228 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 229 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 230 | - $rgb = [ |
|
| 231 | - 'r' => $rgb['red'], |
|
| 232 | - 'g' => $rgb['green'], |
|
| 233 | - 'b' => $rgb['blue'], |
|
| 234 | - ]; |
|
| 235 | - if ($format === null) { |
|
| 236 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 237 | - } |
|
| 238 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 229 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 230 | + $rgb = [ |
|
| 231 | + 'r' => $rgb['red'], |
|
| 232 | + 'g' => $rgb['green'], |
|
| 233 | + 'b' => $rgb['blue'], |
|
| 234 | + ]; |
|
| 235 | + if ($format === null) { |
|
| 236 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 237 | + } |
|
| 238 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -251,13 +251,13 @@ discard block |
||
| 251 | 251 | * Code hexadécimal de la couleur plus foncée |
| 252 | 252 | */ |
| 253 | 253 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 254 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 254 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | 255 | |
| 256 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 257 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 258 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 256 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 257 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 258 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 259 | 259 | |
| 260 | - return _couleur_dec_to_hex($red, $green, $blue); |
|
| 260 | + return _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | * Code hexadécimal de la couleur éclaircie |
| 274 | 274 | */ |
| 275 | 275 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 276 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 276 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 277 | 277 | |
| 278 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 279 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 280 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 278 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 279 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 280 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | 281 | |
| 282 | - return _couleur_dec_to_hex($red, $green, $blue); |
|
| 282 | + return _couleur_dec_to_hex($red, $green, $blue); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -302,28 +302,28 @@ discard block |
||
| 302 | 302 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 303 | 303 | */ |
| 304 | 304 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 305 | - if (!$img) { |
|
| 306 | - return $img; |
|
| 307 | - } |
|
| 308 | - [$h, $l] = taille_image($img); |
|
| 309 | - $select = true; |
|
| 310 | - if ($l < $width_min || $l > $width_max || $h < $height_min || $h > $height_max) { |
|
| 311 | - $select = false; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $class = extraire_attribut($img, 'class'); |
|
| 315 | - $p = strpos((string) $class, 'filtre_inactif'); |
|
| 316 | - if ($select == false && $p === false) { |
|
| 317 | - $class .= ' filtre_inactif'; |
|
| 318 | - $img = inserer_attribut($img, 'class', $class); |
|
| 319 | - } |
|
| 320 | - if ($select == true && $p !== false) { |
|
| 321 | - // no_image_filtrer : historique, a virer |
|
| 322 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', (string) $class); |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return $img; |
|
| 305 | + if (!$img) { |
|
| 306 | + return $img; |
|
| 307 | + } |
|
| 308 | + [$h, $l] = taille_image($img); |
|
| 309 | + $select = true; |
|
| 310 | + if ($l < $width_min || $l > $width_max || $h < $height_min || $h > $height_max) { |
|
| 311 | + $select = false; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $class = extraire_attribut($img, 'class'); |
|
| 315 | + $p = strpos((string) $class, 'filtre_inactif'); |
|
| 316 | + if ($select == false && $p === false) { |
|
| 317 | + $class .= ' filtre_inactif'; |
|
| 318 | + $img = inserer_attribut($img, 'class', $class); |
|
| 319 | + } |
|
| 320 | + if ($select == true && $p !== false) { |
|
| 321 | + // no_image_filtrer : historique, a virer |
|
| 322 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', (string) $class); |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return $img; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -371,45 +371,45 @@ discard block |
||
| 371 | 371 | * Code HTML de l'image ou du texte. |
| 372 | 372 | **/ |
| 373 | 373 | function image_passe_partout( |
| 374 | - $img, |
|
| 375 | - $taille_x = -1, |
|
| 376 | - $taille_y = -1, |
|
| 377 | - $force = false, |
|
| 378 | - $cherche_image = false, |
|
| 379 | - $process = 'AUTO' |
|
| 374 | + $img, |
|
| 375 | + $taille_x = -1, |
|
| 376 | + $taille_y = -1, |
|
| 377 | + $force = false, |
|
| 378 | + $cherche_image = false, |
|
| 379 | + $process = 'AUTO' |
|
| 380 | 380 | ) { |
| 381 | - // PHP 7+ type hint |
|
| 382 | - $img = (string)$img; |
|
| 383 | - $taille_x = (int)$taille_x; |
|
| 384 | - $taille_y = (int)$taille_y; |
|
| 385 | - $force = (bool)$force; |
|
| 386 | - $process = (string)$process; |
|
| 387 | - |
|
| 388 | - if (!$img) { |
|
| 389 | - return ''; |
|
| 390 | - } |
|
| 391 | - [$hauteur, $largeur] = taille_image($img); |
|
| 392 | - if ($taille_x === -1) { |
|
| 393 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 394 | - } |
|
| 395 | - if ($taille_y === -1) { |
|
| 396 | - $taille_y = $taille_x; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if ($taille_x === 0 && $taille_y > 0) { |
|
| 400 | - $taille_x = 1; |
|
| 401 | - } # {0,300} -> c'est 300 qui compte |
|
| 402 | - elseif ($taille_x > 0 && $taille_y === 0) { |
|
| 403 | - $taille_y = 1; |
|
| 404 | - } # {300,0} -> c'est 300 qui compte |
|
| 405 | - elseif ($taille_x == 0 && $taille_y === 0) { |
|
| 406 | - return ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 410 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 411 | - |
|
| 412 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 381 | + // PHP 7+ type hint |
|
| 382 | + $img = (string)$img; |
|
| 383 | + $taille_x = (int)$taille_x; |
|
| 384 | + $taille_y = (int)$taille_y; |
|
| 385 | + $force = (bool)$force; |
|
| 386 | + $process = (string)$process; |
|
| 387 | + |
|
| 388 | + if (!$img) { |
|
| 389 | + return ''; |
|
| 390 | + } |
|
| 391 | + [$hauteur, $largeur] = taille_image($img); |
|
| 392 | + if ($taille_x === -1) { |
|
| 393 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 394 | + } |
|
| 395 | + if ($taille_y === -1) { |
|
| 396 | + $taille_y = $taille_x; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if ($taille_x === 0 && $taille_y > 0) { |
|
| 400 | + $taille_x = 1; |
|
| 401 | + } # {0,300} -> c'est 300 qui compte |
|
| 402 | + elseif ($taille_x > 0 && $taille_y === 0) { |
|
| 403 | + $taille_y = 1; |
|
| 404 | + } # {300,0} -> c'est 300 qui compte |
|
| 405 | + elseif ($taille_x == 0 && $taille_y === 0) { |
|
| 406 | + return ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 410 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 411 | + |
|
| 412 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -452,44 +452,44 @@ discard block |
||
| 452 | 452 | * Code HTML de l'image ou du texte. |
| 453 | 453 | **/ |
| 454 | 454 | function image_reduire( |
| 455 | - $img, |
|
| 456 | - $taille = -1, |
|
| 457 | - $taille_y = -1, |
|
| 458 | - $force = false, |
|
| 459 | - $cherche_image = false, |
|
| 460 | - $process = 'AUTO' |
|
| 455 | + $img, |
|
| 456 | + $taille = -1, |
|
| 457 | + $taille_y = -1, |
|
| 458 | + $force = false, |
|
| 459 | + $cherche_image = false, |
|
| 460 | + $process = 'AUTO' |
|
| 461 | 461 | ) { |
| 462 | - // PHP 7+ type hint |
|
| 463 | - $img = (string)$img; |
|
| 464 | - $taille = (int)$taille; |
|
| 465 | - $taille_y = (int)$taille_y; |
|
| 466 | - $force = (bool)$force; |
|
| 467 | - $process = (string)$process; |
|
| 468 | - |
|
| 469 | - // Determiner la taille x,y maxi |
|
| 470 | - // prendre le reglage de previsu par defaut |
|
| 471 | - if ($taille === -1) { |
|
| 472 | - $taille = (isset($GLOBALS['meta']['taille_preview']) && (int) $GLOBALS['meta']['taille_preview']) |
|
| 473 | - ? (int) $GLOBALS['meta']['taille_preview'] |
|
| 474 | - : 150; |
|
| 475 | - } |
|
| 476 | - if ($taille_y === -1) { |
|
| 477 | - $taille_y = $taille; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - if ($taille === 0 && $taille_y > 0) { |
|
| 481 | - $taille = 10000; |
|
| 482 | - } # {0,300} -> c'est 300 qui compte |
|
| 483 | - elseif ($taille > 0 && $taille_y === 0) { |
|
| 484 | - $taille_y = 10000; |
|
| 485 | - } # {300,0} -> c'est 300 qui compte |
|
| 486 | - elseif ($taille == 0 && $taille_y === 0) { |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 491 | - |
|
| 492 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 462 | + // PHP 7+ type hint |
|
| 463 | + $img = (string)$img; |
|
| 464 | + $taille = (int)$taille; |
|
| 465 | + $taille_y = (int)$taille_y; |
|
| 466 | + $force = (bool)$force; |
|
| 467 | + $process = (string)$process; |
|
| 468 | + |
|
| 469 | + // Determiner la taille x,y maxi |
|
| 470 | + // prendre le reglage de previsu par defaut |
|
| 471 | + if ($taille === -1) { |
|
| 472 | + $taille = (isset($GLOBALS['meta']['taille_preview']) && (int) $GLOBALS['meta']['taille_preview']) |
|
| 473 | + ? (int) $GLOBALS['meta']['taille_preview'] |
|
| 474 | + : 150; |
|
| 475 | + } |
|
| 476 | + if ($taille_y === -1) { |
|
| 477 | + $taille_y = $taille; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + if ($taille === 0 && $taille_y > 0) { |
|
| 481 | + $taille = 10000; |
|
| 482 | + } # {0,300} -> c'est 300 qui compte |
|
| 483 | + elseif ($taille > 0 && $taille_y === 0) { |
|
| 484 | + $taille_y = 10000; |
|
| 485 | + } # {300,0} -> c'est 300 qui compte |
|
| 486 | + elseif ($taille == 0 && $taille_y === 0) { |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 491 | + |
|
| 492 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -500,16 +500,16 @@ discard block |
||
| 500 | 500 | * |
| 501 | 501 | **/ |
| 502 | 502 | function image_recadre_avec_fallback( |
| 503 | - $im, |
|
| 504 | - $width, |
|
| 505 | - $height = '-', |
|
| 506 | - $position = 'focus', |
|
| 507 | - $background_color = 'white' |
|
| 503 | + $im, |
|
| 504 | + $width, |
|
| 505 | + $height = '-', |
|
| 506 | + $position = 'focus', |
|
| 507 | + $background_color = 'white' |
|
| 508 | 508 | ) { |
| 509 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 510 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 511 | - } else { return image_passe_partout($im, $width, $height); |
|
| 512 | - } |
|
| 509 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 510 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 511 | + } else { return image_passe_partout($im, $width, $height); |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -527,23 +527,23 @@ discard block |
||
| 527 | 527 | * Code HTML de l'image ou du texte. |
| 528 | 528 | **/ |
| 529 | 529 | function image_reduire_par($img, $val = 1, $force = false) { |
| 530 | - // PHP 7+ type hint |
|
| 531 | - $img = (string)$img; |
|
| 532 | - $val = (int)$val; |
|
| 533 | - $force = (bool)$force; |
|
| 530 | + // PHP 7+ type hint |
|
| 531 | + $img = (string)$img; |
|
| 532 | + $val = (int)$val; |
|
| 533 | + $force = (bool)$force; |
|
| 534 | 534 | |
| 535 | - [$hauteur, $largeur] = taille_image($img); |
|
| 535 | + [$hauteur, $largeur] = taille_image($img); |
|
| 536 | 536 | |
| 537 | - $l = round($largeur / $val); |
|
| 538 | - $h = round($hauteur / $val); |
|
| 537 | + $l = round($largeur / $val); |
|
| 538 | + $h = round($hauteur / $val); |
|
| 539 | 539 | |
| 540 | - if ($l > $h) { |
|
| 541 | - $h = 0; |
|
| 542 | - } else { |
|
| 543 | - $l = 0; |
|
| 544 | - } |
|
| 540 | + if ($l > $h) { |
|
| 541 | + $h = 0; |
|
| 542 | + } else { |
|
| 543 | + $l = 0; |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - return image_reduire($img, $l, $h, $force); |
|
| 546 | + return image_reduire($img, $l, $h, $force); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | * Couleur en écriture hexadécimale. |
| 567 | 567 | **/ |
| 568 | 568 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 569 | - if (function_exists('couleur_saturation')) { |
|
| 570 | - return couleur_saturation($couleur, $val, $strict); |
|
| 571 | - } |
|
| 572 | - return $couleur; |
|
| 569 | + if (function_exists('couleur_saturation')) { |
|
| 570 | + return couleur_saturation($couleur, $val, $strict); |
|
| 571 | + } |
|
| 572 | + return $couleur; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * Couleur en écriture hexadécimale. |
| 591 | 591 | **/ |
| 592 | 592 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 593 | - if (function_exists('couleur_luminance')) { |
|
| 594 | - return couleur_luminance($couleur, $val); |
|
| 595 | - } |
|
| 596 | - return $couleur; |
|
| 593 | + if (function_exists('couleur_luminance')) { |
|
| 594 | + return couleur_luminance($couleur, $val); |
|
| 595 | + } |
|
| 596 | + return $couleur; |
|
| 597 | 597 | } |
@@ -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_log("redirige $status: $url"); |
|
| 117 | + spip_log("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_log("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_log("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,7 +184,7 @@ 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 | * Renvoie au client le header HTTP avec le message correspondant au code indiqué. |
@@ -199,27 +199,27 @@ discard block |
||
| 199 | 199 | * Code d'erreur |
| 200 | 200 | **/ |
| 201 | 201 | function http_status($status) { |
| 202 | - http_response_code($status); |
|
| 202 | + http_response_code($status); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache |
| 206 | 206 | function http_no_cache() { |
| 207 | - if (headers_sent()) { |
|
| 208 | - spip_log('http_no_cache arrive trop tard'); |
|
| 209 | - |
|
| 210 | - return; |
|
| 211 | - } |
|
| 212 | - $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; |
|
| 213 | - |
|
| 214 | - // selon http://developer.apple.com/internet/safari/faq.html#anchor5 |
|
| 215 | - // il faudrait aussi pour Safari |
|
| 216 | - // header("Cache-Control: post-check=0, pre-check=0", false) |
|
| 217 | - // mais ca ne respecte pas |
|
| 218 | - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 |
|
| 219 | - |
|
| 220 | - header("Content-Type: text/html; charset=$charset"); |
|
| 221 | - header('Expires: 0'); |
|
| 222 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 223 | - header('Cache-Control: no-cache, must-revalidate'); |
|
| 224 | - header('Pragma: no-cache'); |
|
| 207 | + if (headers_sent()) { |
|
| 208 | + spip_log('http_no_cache arrive trop tard'); |
|
| 209 | + |
|
| 210 | + return; |
|
| 211 | + } |
|
| 212 | + $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; |
|
| 213 | + |
|
| 214 | + // selon http://developer.apple.com/internet/safari/faq.html#anchor5 |
|
| 215 | + // il faudrait aussi pour Safari |
|
| 216 | + // header("Cache-Control: post-check=0, pre-check=0", false) |
|
| 217 | + // mais ca ne respecte pas |
|
| 218 | + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 |
|
| 219 | + |
|
| 220 | + header("Content-Type: text/html; charset=$charset"); |
|
| 221 | + header('Expires: 0'); |
|
| 222 | + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 223 | + header('Cache-Control: no-cache, must-revalidate'); |
|
| 224 | + header('Pragma: no-cache'); |
|
| 225 | 225 | } |
@@ -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_log("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 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | header("Content-Type: text/html; charset=$charset"); |
| 221 | 221 | header('Expires: 0'); |
| 222 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 222 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
| 223 | 223 | header('Cache-Control: no-cache, must-revalidate'); |
| 224 | 224 | header('Pragma: no-cache'); |
| 225 | 225 | } |
@@ -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 | /** |
@@ -32,117 +32,117 @@ discard block |
||
| 32 | 32 | **/ |
| 33 | 33 | function analyse_csv($t) { |
| 34 | 34 | |
| 35 | - // Quel est le séparateur ? |
|
| 36 | - $virg = substr_count($t, ','); |
|
| 37 | - $pvirg = substr_count($t, ';'); |
|
| 38 | - $tab = substr_count($t, "\t"); |
|
| 39 | - if ($virg > $pvirg) { |
|
| 40 | - $sep = ','; |
|
| 41 | - $hs = ','; |
|
| 42 | - } else { |
|
| 43 | - $sep = ';'; |
|
| 44 | - $hs = ';'; |
|
| 45 | - $virg = $pvirg; |
|
| 46 | - } |
|
| 47 | - // un certain nombre de tab => le séparateur est tab |
|
| 48 | - if ($tab > $virg / 10) { |
|
| 49 | - $sep = "\t"; |
|
| 50 | - $hs = "\t"; |
|
| 51 | - } |
|
| 35 | + // Quel est le séparateur ? |
|
| 36 | + $virg = substr_count($t, ','); |
|
| 37 | + $pvirg = substr_count($t, ';'); |
|
| 38 | + $tab = substr_count($t, "\t"); |
|
| 39 | + if ($virg > $pvirg) { |
|
| 40 | + $sep = ','; |
|
| 41 | + $hs = ','; |
|
| 42 | + } else { |
|
| 43 | + $sep = ';'; |
|
| 44 | + $hs = ';'; |
|
| 45 | + $virg = $pvirg; |
|
| 46 | + } |
|
| 47 | + // un certain nombre de tab => le séparateur est tab |
|
| 48 | + if ($tab > $virg / 10) { |
|
| 49 | + $sep = "\t"; |
|
| 50 | + $hs = "\t"; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // un separateur suivi de 3 guillemets attention ! |
|
| 54 | - // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 55 | - // on substitue un # et on remplacera a la fin |
|
| 56 | - $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 57 | - $t = str_replace('""', '"#', $t); |
|
| 58 | - preg_match_all('/"[^"]*"/', $t, $r); |
|
| 59 | - foreach ($r[0] as $cell) { |
|
| 60 | - $t = str_replace( |
|
| 61 | - $cell, |
|
| 62 | - str_replace( |
|
| 63 | - $sep, |
|
| 64 | - $hs, |
|
| 65 | - str_replace( |
|
| 66 | - "\n", |
|
| 67 | - '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 68 | - substr((string) $cell, 1, -1) |
|
| 69 | - ) |
|
| 70 | - ), |
|
| 71 | - $t |
|
| 72 | - ); |
|
| 73 | - } |
|
| 53 | + // un separateur suivi de 3 guillemets attention ! |
|
| 54 | + // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 55 | + // on substitue un # et on remplacera a la fin |
|
| 56 | + $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 57 | + $t = str_replace('""', '"#', $t); |
|
| 58 | + preg_match_all('/"[^"]*"/', $t, $r); |
|
| 59 | + foreach ($r[0] as $cell) { |
|
| 60 | + $t = str_replace( |
|
| 61 | + $cell, |
|
| 62 | + str_replace( |
|
| 63 | + $sep, |
|
| 64 | + $hs, |
|
| 65 | + str_replace( |
|
| 66 | + "\n", |
|
| 67 | + '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 68 | + substr((string) $cell, 1, -1) |
|
| 69 | + ) |
|
| 70 | + ), |
|
| 71 | + $t |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $t = preg_replace( |
|
| 76 | - '/\r?\n/', |
|
| 77 | - "\n", |
|
| 78 | - preg_replace('/[\r\n]+/', "\n", $t) |
|
| 79 | - ); |
|
| 75 | + $t = preg_replace( |
|
| 76 | + '/\r?\n/', |
|
| 77 | + "\n", |
|
| 78 | + preg_replace('/[\r\n]+/', "\n", $t) |
|
| 79 | + ); |
|
| 80 | 80 | |
| 81 | - [$entete, $corps] = explode("\n", $t, 2); |
|
| 82 | - $caption = ''; |
|
| 83 | - // sauter la ligne de tete formee seulement de separateurs |
|
| 84 | - if (substr_count($entete, $sep) === strlen($entete)) { |
|
| 85 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 86 | - } |
|
| 87 | - // si une seule colonne, en faire le titre |
|
| 88 | - if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 89 | - $caption = "\n||" . $l[1] . '|'; |
|
| 90 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 91 | - } |
|
| 92 | - // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 93 | - if ($entete[0] == $sep) { |
|
| 94 | - $entete = ' ' . $entete; |
|
| 95 | - } |
|
| 81 | + [$entete, $corps] = explode("\n", $t, 2); |
|
| 82 | + $caption = ''; |
|
| 83 | + // sauter la ligne de tete formee seulement de separateurs |
|
| 84 | + if (substr_count($entete, $sep) === strlen($entete)) { |
|
| 85 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 86 | + } |
|
| 87 | + // si une seule colonne, en faire le titre |
|
| 88 | + if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 89 | + $caption = "\n||" . $l[1] . '|'; |
|
| 90 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 91 | + } |
|
| 92 | + // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 93 | + if ($entete[0] == $sep) { |
|
| 94 | + $entete = ' ' . $entete; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $lignes = explode("\n", $corps); |
|
| 97 | + $lignes = explode("\n", $corps); |
|
| 98 | 98 | |
| 99 | - // retrait des lignes vides finales |
|
| 100 | - while ( |
|
| 101 | - $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 102 | - ) { |
|
| 103 | - unset($lignes[count($lignes) - 1]); |
|
| 104 | - } |
|
| 105 | - // calcul du nombre de colonne a chaque ligne |
|
| 106 | - $nbcols = []; |
|
| 107 | - $max = $mil = substr_count($entete, $sep); |
|
| 108 | - foreach ($lignes as $k => $v) { |
|
| 109 | - if ($max !== ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 110 | - if ($max > $nbcols[$k]) { |
|
| 111 | - $mil = $nbcols[$k]; |
|
| 112 | - } else { |
|
| 113 | - $mil = $max; |
|
| 114 | - $max = $nbcols[$k]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - // Si pas le meme nombre, cadrer au nombre max |
|
| 119 | - if ($mil !== $max) { |
|
| 120 | - foreach ($nbcols as $k => $v) { |
|
| 121 | - if ($v < $max) { |
|
| 122 | - $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - // et retirer les colonnes integralement vides |
|
| 127 | - while (true) { |
|
| 128 | - $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 129 | - foreach ($lignes as $v) { |
|
| 130 | - $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 131 | - } |
|
| 132 | - if (!$nbcols) { |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - $entete = substr($entete, 0, -1); |
|
| 136 | - foreach ($lignes as $k => $v) { |
|
| 137 | - $lignes[$k] = substr($v, 0, -1); |
|
| 138 | - } |
|
| 139 | - } |
|
| 99 | + // retrait des lignes vides finales |
|
| 100 | + while ( |
|
| 101 | + $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 102 | + ) { |
|
| 103 | + unset($lignes[count($lignes) - 1]); |
|
| 104 | + } |
|
| 105 | + // calcul du nombre de colonne a chaque ligne |
|
| 106 | + $nbcols = []; |
|
| 107 | + $max = $mil = substr_count($entete, $sep); |
|
| 108 | + foreach ($lignes as $k => $v) { |
|
| 109 | + if ($max !== ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 110 | + if ($max > $nbcols[$k]) { |
|
| 111 | + $mil = $nbcols[$k]; |
|
| 112 | + } else { |
|
| 113 | + $mil = $max; |
|
| 114 | + $max = $nbcols[$k]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + // Si pas le meme nombre, cadrer au nombre max |
|
| 119 | + if ($mil !== $max) { |
|
| 120 | + foreach ($nbcols as $k => $v) { |
|
| 121 | + if ($v < $max) { |
|
| 122 | + $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + // et retirer les colonnes integralement vides |
|
| 127 | + while (true) { |
|
| 128 | + $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 129 | + foreach ($lignes as $v) { |
|
| 130 | + $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 131 | + } |
|
| 132 | + if (!$nbcols) { |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + $entete = substr($entete, 0, -1); |
|
| 136 | + foreach ($lignes as $k => $v) { |
|
| 137 | + $lignes[$k] = substr($v, 0, -1); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - foreach ($lignes as &$l) { |
|
| 142 | - $l = str_replace('"#', '"', $l); |
|
| 143 | - $l = str_replace('``**``', "\n", $l); |
|
| 144 | - $l = explode($sep, $l); |
|
| 145 | - } |
|
| 141 | + foreach ($lignes as &$l) { |
|
| 142 | + $l = str_replace('"#', '"', $l); |
|
| 143 | + $l = str_replace('``**``', "\n", $l); |
|
| 144 | + $l = explode($sep, $l); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return [explode($sep, $entete), $lignes, $caption]; |
|
| 147 | + return [explode($sep, $entete), $lignes, $caption]; |
|
| 148 | 148 | } |
@@ -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,34 +38,34 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | - if (is_null($liste_langues)) { |
|
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | - } else { |
|
| 44 | - if (is_array($liste_langues)) { |
|
| 45 | - $liste_langues = implode(',', $liste_langues); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | - |
|
| 50 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | - if (!$lang) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( |
|
| 58 | - str_contains($liste_langues, (string) ",$lang,") |
|
| 59 | - || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | - ) { |
|
| 61 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 62 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 63 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 64 | - |
|
| 65 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 66 | - } else { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 41 | + if (is_null($liste_langues)) { |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | + } else { |
|
| 44 | + if (is_array($liste_langues)) { |
|
| 45 | + $liste_langues = implode(',', $liste_langues); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | + |
|
| 50 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | + if (!$lang) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( |
|
| 58 | + str_contains($liste_langues, (string) ",$lang,") |
|
| 59 | + || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | + ) { |
|
| 61 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 62 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 63 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 64 | + |
|
| 65 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 66 | + } else { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 79 | 79 | |
| 80 | 80 | function choisir_traduction($trads, $lang = '') { |
| 81 | - $k = approcher_langue($trads, $lang); |
|
| 81 | + $k = approcher_langue($trads, $lang); |
|
| 82 | 82 | |
| 83 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 83 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // retourne son 2e argument si c'est un index du premier |
@@ -88,21 +88,21 @@ discard block |
||
| 88 | 88 | // la langue X etant consideree comme une approche de X_Y |
| 89 | 89 | function approcher_langue($trads, $lang = '') { |
| 90 | 90 | |
| 91 | - if (!$lang) { |
|
| 92 | - $lang = $GLOBALS['spip_lang']; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if (isset($trads[$lang])) { |
|
| 96 | - return $lang; |
|
| 97 | - } // cas des langues xx_yy |
|
| 98 | - else { |
|
| 99 | - $r = explode('_', (string) $lang); |
|
| 100 | - if (isset($trads[$r[0]])) { |
|
| 101 | - return $r[0]; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return ''; |
|
| 91 | + if (!$lang) { |
|
| 92 | + $lang = $GLOBALS['spip_lang']; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if (isset($trads[$lang])) { |
|
| 96 | + return $lang; |
|
| 97 | + } // cas des langues xx_yy |
|
| 98 | + else { |
|
| 99 | + $r = explode('_', (string) $lang); |
|
| 100 | + if (isset($trads[$r[0]])) { |
|
| 101 | + return $r[0]; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return ''; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * Nom de la langue, sinon son code. |
| 118 | 118 | **/ |
| 119 | 119 | function traduire_nom_langue($lang) { |
| 120 | - include_spip('inc/lang_liste'); |
|
| 121 | - include_spip('inc/charsets'); |
|
| 120 | + include_spip('inc/lang_liste'); |
|
| 121 | + include_spip('inc/charsets'); |
|
| 122 | 122 | |
| 123 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 123 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | // hebreu a priori), 'droitier' sinon. |
| 134 | 134 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 135 | 135 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 136 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 136 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 137 | 137 | |
| 138 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 139 | - $gaucher : $droitier; |
|
| 138 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 139 | + $gaucher : $droitier; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // typo francaise ou anglaise ? |
@@ -145,29 +145,29 @@ discard block |
||
| 145 | 145 | // sinon determiner la typo en fonction de la langue courante |
| 146 | 146 | |
| 147 | 147 | function lang_typo($lang = '') { |
| 148 | - if (!$lang) { |
|
| 149 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 150 | - } |
|
| 151 | - if ( |
|
| 152 | - $lang == 'eo' |
|
| 153 | - || $lang == 'fr' |
|
| 154 | - || str_starts_with((string) $lang, 'fr_') |
|
| 155 | - || $lang == 'cpf' |
|
| 156 | - ) { |
|
| 157 | - return 'fr'; |
|
| 158 | - } else { |
|
| 159 | - return 'en'; |
|
| 160 | - } |
|
| 148 | + if (!$lang) { |
|
| 149 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 150 | + } |
|
| 151 | + if ( |
|
| 152 | + $lang == 'eo' |
|
| 153 | + || $lang == 'fr' |
|
| 154 | + || str_starts_with((string) $lang, 'fr_') |
|
| 155 | + || $lang == 'cpf' |
|
| 156 | + ) { |
|
| 157 | + return 'fr'; |
|
| 158 | + } else { |
|
| 159 | + return 'en'; |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 164 | 164 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 165 | 165 | function changer_typo($lang = '') { |
| 166 | - if ($lang) { |
|
| 167 | - $GLOBALS['lang_objet'] = $lang; |
|
| 168 | - } else { |
|
| 169 | - unset($GLOBALS['lang_objet']); |
|
| 170 | - } |
|
| 166 | + if ($lang) { |
|
| 167 | + $GLOBALS['lang_objet'] = $lang; |
|
| 168 | + } else { |
|
| 169 | + unset($GLOBALS['lang_objet']); |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // |
@@ -177,56 +177,56 @@ discard block |
||
| 177 | 177 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 178 | 178 | // |
| 179 | 179 | function menu_langues($nom_select, $default = '') { |
| 180 | - include_spip('inc/actions'); |
|
| 181 | - |
|
| 182 | - $langues = liste_options_langues($nom_select); |
|
| 183 | - $ret = ''; |
|
| 184 | - if ($langues === []) { |
|
| 185 | - return ''; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if (!$default) { |
|
| 189 | - $default = $GLOBALS['spip_lang']; |
|
| 190 | - } |
|
| 191 | - foreach ($langues as $l) { |
|
| 192 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 193 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!test_espace_prive()) { |
|
| 197 | - $cible = self(); |
|
| 198 | - $base = ''; |
|
| 199 | - } else { |
|
| 200 | - $cible = self(); |
|
| 201 | - $base = spip_connect() ? 'base' : ''; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 205 | - |
|
| 206 | - return generer_action_auteur( |
|
| 207 | - 'converser', |
|
| 208 | - $base, |
|
| 209 | - $cible, |
|
| 210 | - (select_langues($nom_select, $change, $ret) |
|
| 211 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | - " method='post'" |
|
| 213 | - ); |
|
| 180 | + include_spip('inc/actions'); |
|
| 181 | + |
|
| 182 | + $langues = liste_options_langues($nom_select); |
|
| 183 | + $ret = ''; |
|
| 184 | + if ($langues === []) { |
|
| 185 | + return ''; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if (!$default) { |
|
| 189 | + $default = $GLOBALS['spip_lang']; |
|
| 190 | + } |
|
| 191 | + foreach ($langues as $l) { |
|
| 192 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 193 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!test_espace_prive()) { |
|
| 197 | + $cible = self(); |
|
| 198 | + $base = ''; |
|
| 199 | + } else { |
|
| 200 | + $cible = self(); |
|
| 201 | + $base = spip_connect() ? 'base' : ''; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 205 | + |
|
| 206 | + return generer_action_auteur( |
|
| 207 | + 'converser', |
|
| 208 | + $base, |
|
| 209 | + $cible, |
|
| 210 | + (select_langues($nom_select, $change, $ret) |
|
| 211 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | + " method='post'" |
|
| 213 | + ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function select_langues($nom_select, $change, $options, $label = '') { |
| 217 | - static $cpt = 0; |
|
| 218 | - $id = 'menu_langues' . $cpt++; |
|
| 219 | - |
|
| 220 | - return |
|
| 221 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | - "<select name='$nom_select' id='$id' " |
|
| 223 | - . ((test_espace_prive()) ? |
|
| 224 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | - ("class='forml menu_langues'")) |
|
| 226 | - . $change |
|
| 227 | - . ">\n" |
|
| 228 | - . $options |
|
| 229 | - . '</select>'; |
|
| 217 | + static $cpt = 0; |
|
| 218 | + $id = 'menu_langues' . $cpt++; |
|
| 219 | + |
|
| 220 | + return |
|
| 221 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | + "<select name='$nom_select' id='$id' " |
|
| 223 | + . ((test_espace_prive()) ? |
|
| 224 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | + ("class='forml menu_langues'")) |
|
| 226 | + . $change |
|
| 227 | + . ">\n" |
|
| 228 | + . $options |
|
| 229 | + . '</select>'; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -248,34 +248,34 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | function liste_options_langues($nom_select) { |
| 250 | 250 | |
| 251 | - switch ($nom_select) { |
|
| 252 | - # #MENU_LANG |
|
| 253 | - case 'var_lang': |
|
| 254 | - # menu de changement de la langue d'un article |
|
| 255 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 256 | - case 'changer_lang': |
|
| 257 | - $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 258 | - break; |
|
| 259 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 260 | - # les langues presentes sous forme de fichiers de langue |
|
| 261 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 262 | - case 'var_lang_ecrire': |
|
| 263 | - default: |
|
| 264 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 265 | - init_langues(); |
|
| 266 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 267 | - break; |
|
| 251 | + switch ($nom_select) { |
|
| 252 | + # #MENU_LANG |
|
| 253 | + case 'var_lang': |
|
| 254 | + # menu de changement de la langue d'un article |
|
| 255 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 256 | + case 'changer_lang': |
|
| 257 | + $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 258 | + break; |
|
| 259 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 260 | + # les langues presentes sous forme de fichiers de langue |
|
| 261 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 262 | + case 'var_lang_ecrire': |
|
| 263 | + default: |
|
| 264 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 265 | + init_langues(); |
|
| 266 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 267 | + break; |
|
| 268 | 268 | |
| 269 | 269 | # dernier choix possible : toutes les langues = langues_proposees |
| 270 | 270 | # + langues_multilingues ; mais, ne sert pas |
| 271 | 271 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 272 | - } |
|
| 273 | - if (count($langues) <= 1) { |
|
| 274 | - return []; |
|
| 275 | - } |
|
| 276 | - sort($langues); |
|
| 272 | + } |
|
| 273 | + if (count($langues) <= 1) { |
|
| 274 | + return []; |
|
| 275 | + } |
|
| 276 | + sort($langues); |
|
| 277 | 277 | |
| 278 | - return $langues; |
|
| 278 | + return $langues; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -290,39 +290,39 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function verifier_lang_url() { |
| 292 | 292 | |
| 293 | - // quelle langue est demandee ? |
|
| 294 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 295 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 296 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 297 | - } |
|
| 298 | - if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 299 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 300 | - } |
|
| 301 | - if (isset($_GET['lang'])) { |
|
| 302 | - $lang_demandee = $_GET['lang']; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 306 | - if ( |
|
| 307 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 308 | - && changer_langue($lang_demandee) |
|
| 309 | - && $lang_demandee != @$_GET['lang'] |
|
| 310 | - ) { |
|
| 311 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 312 | - // ici on a besoin des var_truc |
|
| 313 | - foreach ($_GET as $var => $val) { |
|
| 314 | - if (!strncmp('var_', $var, 4)) { |
|
| 315 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - include_spip('inc/headers'); |
|
| 319 | - redirige_par_entete($destination); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 323 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 324 | - // (pour criteres {lang}). |
|
| 325 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 293 | + // quelle langue est demandee ? |
|
| 294 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 295 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 296 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 297 | + } |
|
| 298 | + if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 299 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 300 | + } |
|
| 301 | + if (isset($_GET['lang'])) { |
|
| 302 | + $lang_demandee = $_GET['lang']; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 306 | + if ( |
|
| 307 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 308 | + && changer_langue($lang_demandee) |
|
| 309 | + && $lang_demandee != @$_GET['lang'] |
|
| 310 | + ) { |
|
| 311 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 312 | + // ici on a besoin des var_truc |
|
| 313 | + foreach ($_GET as $var => $val) { |
|
| 314 | + if (!strncmp('var_', $var, 4)) { |
|
| 315 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + include_spip('inc/headers'); |
|
| 319 | + redirige_par_entete($destination); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 323 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 324 | + // (pour criteres {lang}). |
|
| 325 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
@@ -340,19 +340,19 @@ discard block |
||
| 340 | 340 | * La langue sélectionnée |
| 341 | 341 | **/ |
| 342 | 342 | function utiliser_langue_site($liste_langues = null) { |
| 343 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 344 | - if ( |
|
| 345 | - isset($GLOBALS['meta']['langue_site']) |
|
| 346 | - && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 347 | - ) { |
|
| 348 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 349 | - } |
|
| 350 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 351 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 352 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return $GLOBALS['spip_lang']; |
|
| 343 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 344 | + if ( |
|
| 345 | + isset($GLOBALS['meta']['langue_site']) |
|
| 346 | + && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 347 | + ) { |
|
| 348 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 349 | + } |
|
| 350 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 351 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 352 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return $GLOBALS['spip_lang']; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -371,38 +371,38 @@ discard block |
||
| 371 | 371 | **/ |
| 372 | 372 | function utiliser_langue_visiteur($liste_langues = null) { |
| 373 | 373 | |
| 374 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 375 | - if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 376 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 380 | - if ( |
|
| 381 | - isset($_COOKIE[$l]) |
|
| 382 | - && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 383 | - ) { |
|
| 384 | - return $l; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ( |
|
| 388 | - isset($GLOBALS['visiteur_session']['lang']) |
|
| 389 | - && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 390 | - ) { |
|
| 391 | - return $l; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | - foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | - if ( |
|
| 397 | - preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 398 | - && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 399 | - ) { |
|
| 400 | - return $l; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return utiliser_langue_site($liste_langues); |
|
| 374 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 375 | + if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 376 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 380 | + if ( |
|
| 381 | + isset($_COOKIE[$l]) |
|
| 382 | + && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 383 | + ) { |
|
| 384 | + return $l; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ( |
|
| 388 | + isset($GLOBALS['visiteur_session']['lang']) |
|
| 389 | + && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 390 | + ) { |
|
| 391 | + return $l; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | + foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | + if ( |
|
| 397 | + preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 398 | + && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 399 | + ) { |
|
| 400 | + return $l; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return utiliser_langue_site($liste_langues); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return int |
| 413 | 413 | */ |
| 414 | 414 | function match_langue($chaine) { |
| 415 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 415 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -430,38 +430,38 @@ discard block |
||
| 430 | 430 | **/ |
| 431 | 431 | function init_langues() { |
| 432 | 432 | |
| 433 | - // liste des langues dans les meta, sauf a l'install |
|
| 434 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 435 | - |
|
| 436 | - $tout = []; |
|
| 437 | - if (!$all_langs) { |
|
| 438 | - // trouver tous les modules lang/spip_xx.php |
|
| 439 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | - foreach (array_keys($modules) as $name) { |
|
| 441 | - if ( |
|
| 442 | - preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 443 | - && match_langue($regs[1]) |
|
| 444 | - ) { |
|
| 445 | - $tout[] = $regs[1]; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - sort($tout); |
|
| 449 | - $tout = implode(',', $tout); |
|
| 450 | - // Si les langues n'ont pas change, ne rien faire |
|
| 451 | - if ($tout != $all_langs) { |
|
| 452 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 453 | - include_spip('inc/meta'); |
|
| 454 | - ecrire_meta('langues_proposees', $tout); |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 458 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 459 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 460 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 461 | - ? _LANGUE_PAR_DEFAUT |
|
| 462 | - : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 463 | - ecrire_meta('langue_site', $tout); |
|
| 464 | - } |
|
| 433 | + // liste des langues dans les meta, sauf a l'install |
|
| 434 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 435 | + |
|
| 436 | + $tout = []; |
|
| 437 | + if (!$all_langs) { |
|
| 438 | + // trouver tous les modules lang/spip_xx.php |
|
| 439 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | + foreach (array_keys($modules) as $name) { |
|
| 441 | + if ( |
|
| 442 | + preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 443 | + && match_langue($regs[1]) |
|
| 444 | + ) { |
|
| 445 | + $tout[] = $regs[1]; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + sort($tout); |
|
| 449 | + $tout = implode(',', $tout); |
|
| 450 | + // Si les langues n'ont pas change, ne rien faire |
|
| 451 | + if ($tout != $all_langs) { |
|
| 452 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 453 | + include_spip('inc/meta'); |
|
| 454 | + ecrire_meta('langues_proposees', $tout); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 458 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 459 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 460 | + (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 461 | + ? _LANGUE_PAR_DEFAUT |
|
| 462 | + : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 463 | + ecrire_meta('langue_site', $tout); |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -475,10 +475,10 @@ discard block |
||
| 475 | 475 | * Code html de la balise <html> |
| 476 | 476 | **/ |
| 477 | 477 | function html_lang_attributes() { |
| 478 | - $lang = $GLOBALS['spip_lang']; |
|
| 479 | - $dir = lang_dir($lang); |
|
| 478 | + $lang = $GLOBALS['spip_lang']; |
|
| 479 | + $dir = lang_dir($lang); |
|
| 480 | 480 | |
| 481 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 481 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | 494 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 495 | - return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 495 | + return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | 41 | if (is_null($liste_langues)) { |
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '').','.($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | 43 | } else { |
| 44 | 44 | if (is_array($liste_langues)) { |
| 45 | 45 | $liste_langues = implode(',', $liste_langues); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 48 | + $liste_langues = ','.$liste_langues.','; |
|
| 49 | 49 | |
| 50 | 50 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 51 | 51 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | foreach ($langues as $l) { |
| 192 | 192 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 193 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 193 | + $ret .= "<option value='$l'$selected>[".$l.'] '.traduire_nom_langue($l)."</option>\n"; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (!test_espace_prive()) { |
@@ -208,21 +208,20 @@ discard block |
||
| 208 | 208 | $base, |
| 209 | 209 | $cible, |
| 210 | 210 | (select_langues($nom_select, $change, $ret) |
| 211 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 211 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 212 | 212 | " method='post'" |
| 213 | 213 | ); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function select_langues($nom_select, $change, $options, $label = '') { |
| 217 | 217 | static $cpt = 0; |
| 218 | - $id = 'menu_langues' . $cpt++; |
|
| 218 | + $id = 'menu_langues'.$cpt++; |
|
| 219 | 219 | |
| 220 | 220 | return |
| 221 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 221 | + "<label for='$id'>".($label ?: _T('info_langues')).'</label> '. |
|
| 222 | 222 | "<select name='$nom_select' id='$id' " |
| 223 | 223 | . ((test_espace_prive()) ? |
| 224 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | - ("class='forml menu_langues'")) |
|
| 224 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : ("class='forml menu_langues'")) |
|
| 226 | 225 | . $change |
| 227 | 226 | . ">\n" |
| 228 | 227 | . $options |
@@ -345,7 +344,7 @@ discard block |
||
| 345 | 344 | isset($GLOBALS['meta']['langue_site']) |
| 346 | 345 | && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 347 | 346 | ) { |
| 348 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 347 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 349 | 348 | } |
| 350 | 349 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 351 | 350 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -457,7 +456,7 @@ discard block |
||
| 457 | 456 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 458 | 457 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 459 | 458 | $GLOBALS['meta']['langue_site'] = $tout = |
| 460 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 459 | + (!$all_langs || str_contains(','._LANGUE_PAR_DEFAUT.',', (string) ",$all_langs,")) |
|
| 461 | 460 | ? _LANGUE_PAR_DEFAUT |
| 462 | 461 | : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
| 463 | 462 | ecrire_meta('langue_site', $tout); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | // |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // |
@@ -20,52 +20,52 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function produire_image_math($tex) { |
| 22 | 22 | |
| 23 | - switch ($GLOBALS['traiter_math']) { |
|
| 24 | - // Attention: mathml desactiv'e pour l'instant |
|
| 25 | - case 'mathml': |
|
| 26 | - $ext = '.xhtml'; |
|
| 27 | - $server = $GLOBALS['mathml_server']; |
|
| 28 | - break; |
|
| 29 | - case 'tex': |
|
| 30 | - $ext = '.png'; |
|
| 31 | - $server = $GLOBALS['tex_server']; |
|
| 32 | - break; |
|
| 33 | - default: |
|
| 34 | - return $tex; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | - } |
|
| 41 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - // Aller chercher l'image sur le serveur |
|
| 45 | - if (!@file_exists($fichier) && $server) { |
|
| 46 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 47 | - include_spip('inc/distant'); |
|
| 48 | - recuperer_url($url, ['file' => $fichier]); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - // Composer la reponse selon presence ou non de l'image |
|
| 53 | - $tex = entites_html($tex); |
|
| 54 | - if (@file_exists($fichier)) { |
|
| 55 | - // MathML |
|
| 56 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | - return implode('', file($fichier)); |
|
| 58 | - } // TeX |
|
| 59 | - else { |
|
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | - |
|
| 63 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | - } |
|
| 65 | - } else // pas de fichier |
|
| 66 | - { |
|
| 67 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | - } |
|
| 23 | + switch ($GLOBALS['traiter_math']) { |
|
| 24 | + // Attention: mathml desactiv'e pour l'instant |
|
| 25 | + case 'mathml': |
|
| 26 | + $ext = '.xhtml'; |
|
| 27 | + $server = $GLOBALS['mathml_server']; |
|
| 28 | + break; |
|
| 29 | + case 'tex': |
|
| 30 | + $ext = '.png'; |
|
| 31 | + $server = $GLOBALS['tex_server']; |
|
| 32 | + break; |
|
| 33 | + default: |
|
| 34 | + return $tex; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | + } |
|
| 41 | + $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + // Aller chercher l'image sur le serveur |
|
| 45 | + if (!@file_exists($fichier) && $server) { |
|
| 46 | + spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 47 | + include_spip('inc/distant'); |
|
| 48 | + recuperer_url($url, ['file' => $fichier]); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + // Composer la reponse selon presence ou non de l'image |
|
| 53 | + $tex = entites_html($tex); |
|
| 54 | + if (@file_exists($fichier)) { |
|
| 55 | + // MathML |
|
| 56 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | + return implode('', file($fichier)); |
|
| 58 | + } // TeX |
|
| 59 | + else { |
|
| 60 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | + |
|
| 63 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | + } |
|
| 65 | + } else // pas de fichier |
|
| 66 | + { |
|
| 67 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -100,52 +100,52 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 102 | 102 | |
| 103 | - $texte_a_voir = $letexte; |
|
| 104 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | - $fin = strlen($texte_a_voir); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | - $texte_milieu = substr( |
|
| 111 | - $texte_a_voir, |
|
| 112 | - $debut + strlen('<math>'), |
|
| 113 | - $fin - $debut - strlen('<math>') |
|
| 114 | - ); |
|
| 115 | - $texte_fin = substr( |
|
| 116 | - $texte_a_voir, |
|
| 117 | - $fin + strlen('</math>'), |
|
| 118 | - strlen($texte_a_voir) |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | - $expression = $regs[1]; |
|
| 124 | - if ($defaire_amp) { |
|
| 125 | - $expression = str_replace('&', '&', $expression); |
|
| 126 | - } |
|
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | - . code_echappement($echap, $source) |
|
| 131 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Les simples $x^2$ en mode 'span' |
|
| 135 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | - $expression = $regs[1]; |
|
| 137 | - if ($defaire_amp) { |
|
| 138 | - $expression = str_replace('&', '&', $expression); |
|
| 139 | - } |
|
| 140 | - $echap = produire_image_math($expression); |
|
| 141 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | - . code_echappement($echap, $source) |
|
| 144 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $texte_a_voir; |
|
| 103 | + $texte_a_voir = $letexte; |
|
| 104 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | + $fin = strlen($texte_a_voir); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | + $texte_milieu = substr( |
|
| 111 | + $texte_a_voir, |
|
| 112 | + $debut + strlen('<math>'), |
|
| 113 | + $fin - $debut - strlen('<math>') |
|
| 114 | + ); |
|
| 115 | + $texte_fin = substr( |
|
| 116 | + $texte_a_voir, |
|
| 117 | + $fin + strlen('</math>'), |
|
| 118 | + strlen($texte_a_voir) |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | + $expression = $regs[1]; |
|
| 124 | + if ($defaire_amp) { |
|
| 125 | + $expression = str_replace('&', '&', $expression); |
|
| 126 | + } |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | + . code_echappement($echap, $source) |
|
| 131 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Les simples $x^2$ en mode 'span' |
|
| 135 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | + $expression = $regs[1]; |
|
| 137 | + if ($defaire_amp) { |
|
| 138 | + $expression = str_replace('&', '&', $expression); |
|
| 139 | + } |
|
| 140 | + $echap = produire_image_math($expression); |
|
| 141 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | + . code_echappement($echap, $source) |
|
| 144 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $texte_a_voir; |
|
| 151 | 151 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 39 | 39 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 40 | 40 | } |
| 41 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 41 | + $fichier = $dir_tex.md5(trim((string) $tex)).$ext; |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | // Aller chercher l'image sur le serveur |
| 45 | 45 | if (!@file_exists($fichier) && $server) { |
| 46 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 46 | + spip_log($url = $server.'?'.rawurlencode((string) $tex)); |
|
| 47 | 47 | include_spip('inc/distant'); |
| 48 | 48 | recuperer_url($url, ['file' => $fichier]); |
| 49 | 49 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | return implode('', file($fichier)); |
| 58 | 58 | } // TeX |
| 59 | 59 | else { |
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 60 | + [,,, $size] = @spip_getimagesize($fichier); |
|
| 61 | 61 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 62 | 62 | |
| 63 | 63 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if ($defaire_amp) { |
| 125 | 125 | $expression = str_replace('&', '&', $expression); |
| 126 | 126 | } |
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 128 | 128 | $pos = strpos($texte_milieu, (string) $regs[0]); |
| 129 | 129 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 130 | 130 | . code_echappement($echap, $source) |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 147 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $texte_a_voir; |