@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
| 38 | - // (re)mettre .htaccess avec deny from all |
|
| 39 | - // dans les deux repertoires dits inaccessibles par http |
|
| 40 | - include_spip('inc/acces'); |
|
| 41 | - verifier_htaccess(_DIR_ETC); |
|
| 42 | - verifier_htaccess(_DIR_TMP); |
|
| 43 | - verifier_htaccess(_DIR_VENDOR); |
|
| 38 | + // (re)mettre .htaccess avec deny from all |
|
| 39 | + // dans les deux repertoires dits inaccessibles par http |
|
| 40 | + include_spip('inc/acces'); |
|
| 41 | + verifier_htaccess(_DIR_ETC); |
|
| 42 | + verifier_htaccess(_DIR_TMP); |
|
| 43 | + verifier_htaccess(_DIR_VENDOR); |
|
| 44 | 44 | |
| 45 | - // Verifier qu'aucune table n'est crashee |
|
| 46 | - if (!_request('reinstall')) { |
|
| 47 | - verifier_crash_tables(); |
|
| 48 | - } |
|
| 45 | + // Verifier qu'aucune table n'est crashee |
|
| 46 | + if (!_request('reinstall')) { |
|
| 47 | + verifier_crash_tables(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return 1; |
|
| 50 | + return 1; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -64,33 +64,33 @@ discard block |
||
| 64 | 64 | * des tables qui ont crashé. |
| 65 | 65 | */ |
| 66 | 66 | function verifier_crash_tables() { |
| 67 | - if (spip_connect()) { |
|
| 68 | - include_spip('base/serial'); |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - $crash = []; |
|
| 71 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 72 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 73 | - if ( |
|
| 74 | - !sql_select('*', $table, '', '', '', 1) |
|
| 75 | - and !defined('spip_interdire_cache') |
|
| 76 | - ) { # cas "LOST CONNECTION" |
|
| 77 | - $crash[] = $table; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - #$crash[] = 'test'; |
|
| 82 | - if ($crash) { |
|
| 83 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 84 | - spip_log('crash des tables', 'err'); |
|
| 85 | - spip_log($crash, 'err'); |
|
| 86 | - } else { |
|
| 87 | - effacer_meta('message_crash_tables'); |
|
| 88 | - } |
|
| 67 | + if (spip_connect()) { |
|
| 68 | + include_spip('base/serial'); |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + $crash = []; |
|
| 71 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 72 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 73 | + if ( |
|
| 74 | + !sql_select('*', $table, '', '', '', 1) |
|
| 75 | + and !defined('spip_interdire_cache') |
|
| 76 | + ) { # cas "LOST CONNECTION" |
|
| 77 | + $crash[] = $table; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + #$crash[] = 'test'; |
|
| 82 | + if ($crash) { |
|
| 83 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 84 | + spip_log('crash des tables', 'err'); |
|
| 85 | + spip_log($crash, 'err'); |
|
| 86 | + } else { |
|
| 87 | + effacer_meta('message_crash_tables'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return $crash; |
|
| 91 | - } |
|
| 90 | + return $crash; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return false; |
|
| 93 | + return false; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function message_crash_tables() { |
| 109 | - if ($crash = verifier_crash_tables()) { |
|
| 110 | - return |
|
| 111 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 113 | - . generer_form_ecrire( |
|
| 114 | - 'base_repair', |
|
| 115 | - _T('texte_crash_base'), |
|
| 116 | - '', |
|
| 117 | - _T('bouton_tenter_recuperation') |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - return ''; |
|
| 109 | + if ($crash = verifier_crash_tables()) { |
|
| 110 | + return |
|
| 111 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | + . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 113 | + . generer_form_ecrire( |
|
| 114 | + 'base_repair', |
|
| 115 | + _T('texte_crash_base'), |
|
| 116 | + '', |
|
| 117 | + _T('bouton_tenter_recuperation') |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + return ''; |
|
| 121 | 121 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | use Spip\Chiffrer\SpipCles; |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -34,169 +34,169 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 36 | 36 | |
| 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' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | - $auteur_peut_sauver_cles = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // login inexistant ou mot de passe vide |
|
| 67 | - if (!$pass or !$row) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $cles = SpipCles::instance(); |
|
| 72 | - $secret = $cles->getSecretAuth(); |
|
| 73 | - |
|
| 74 | - $hash = null; |
|
| 75 | - switch (strlen($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=' . intval($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 | - and $auteur_peut_sauver_cles |
|
| 107 | - and !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=' . intval($row['id_auteur'])); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!$secret or !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 and $auteur_peut_sauver_cles) { |
|
| 140 | - if (auth_spip_initialiser_secret()) { |
|
| 141 | - $secret = $cles->getSecretAuth(); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // login/mot de passe incorrect |
|
| 146 | - if (empty($row)) { |
|
| 147 | - return []; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // fait tourner le codage du pass dans la base |
|
| 151 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 152 | - if (!$phpauth and $secret) { |
|
| 153 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 154 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 155 | - if ($pass_hash_next) { |
|
| 156 | - $set = [ |
|
| 157 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 158 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 159 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 160 | - ]; |
|
| 161 | - |
|
| 162 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 163 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 164 | - $htpass = generer_htpass($pass); |
|
| 165 | - if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 166 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 170 | - if ($auteur_peut_sauver_cles) { |
|
| 171 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - @sql_update( |
|
| 175 | - 'spip_auteurs', |
|
| 176 | - $set, |
|
| 177 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | - $row['pass'], |
|
| 179 | - $serveur, |
|
| 180 | - 'text' |
|
| 181 | - ), |
|
| 182 | - [], |
|
| 183 | - $serveur |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 187 | - if (isset($set['htpass'])) { |
|
| 188 | - ecrire_acces(); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // En profiter pour verifier la securite de tmp/ |
|
| 193 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 194 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $row; |
|
| 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' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | + $auteur_peut_sauver_cles = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // login inexistant ou mot de passe vide |
|
| 67 | + if (!$pass or !$row) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $cles = SpipCles::instance(); |
|
| 72 | + $secret = $cles->getSecretAuth(); |
|
| 73 | + |
|
| 74 | + $hash = null; |
|
| 75 | + switch (strlen($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=' . intval($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 | + and $auteur_peut_sauver_cles |
|
| 107 | + and !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=' . intval($row['id_auteur'])); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!$secret or !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 and $auteur_peut_sauver_cles) { |
|
| 140 | + if (auth_spip_initialiser_secret()) { |
|
| 141 | + $secret = $cles->getSecretAuth(); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // login/mot de passe incorrect |
|
| 146 | + if (empty($row)) { |
|
| 147 | + return []; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // fait tourner le codage du pass dans la base |
|
| 151 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 152 | + if (!$phpauth and $secret) { |
|
| 153 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 154 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 155 | + if ($pass_hash_next) { |
|
| 156 | + $set = [ |
|
| 157 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 158 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 159 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 160 | + ]; |
|
| 161 | + |
|
| 162 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 163 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 164 | + $htpass = generer_htpass($pass); |
|
| 165 | + if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 166 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 170 | + if ($auteur_peut_sauver_cles) { |
|
| 171 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + @sql_update( |
|
| 175 | + 'spip_auteurs', |
|
| 176 | + $set, |
|
| 177 | + 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | + $row['pass'], |
|
| 179 | + $serveur, |
|
| 180 | + 'text' |
|
| 181 | + ), |
|
| 182 | + [], |
|
| 183 | + $serveur |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 187 | + if (isset($set['htpass'])) { |
|
| 188 | + ecrire_acces(); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // En profiter pour verifier la securite de tmp/ |
|
| 193 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 194 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $row; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -211,36 +211,36 @@ discard block |
||
| 211 | 211 | * @return bool |
| 212 | 212 | */ |
| 213 | 213 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 214 | - $cles = SpipCles::instance(); |
|
| 215 | - $secret = $cles->getSecretAuth(); |
|
| 216 | - |
|
| 217 | - // on ne fait rien si on a un secret dispo |
|
| 218 | - if ($secret) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 223 | - if ($force) { |
|
| 224 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 225 | - $secret = $cles->getSecretAuth(true); |
|
| 226 | - return true; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 230 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 231 | - if (empty($has_backup)) { |
|
| 232 | - 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); |
|
| 233 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 234 | - return true; |
|
| 235 | - } |
|
| 236 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 237 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 238 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 239 | - } |
|
| 240 | - else { |
|
| 241 | - 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); |
|
| 242 | - } |
|
| 243 | - return false; |
|
| 214 | + $cles = SpipCles::instance(); |
|
| 215 | + $secret = $cles->getSecretAuth(); |
|
| 216 | + |
|
| 217 | + // on ne fait rien si on a un secret dispo |
|
| 218 | + if ($secret) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 223 | + if ($force) { |
|
| 224 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 225 | + $secret = $cles->getSecretAuth(true); |
|
| 226 | + return true; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 230 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 231 | + if (empty($has_backup)) { |
|
| 232 | + 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); |
|
| 233 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 234 | + return true; |
|
| 235 | + } |
|
| 236 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 237 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 238 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 239 | + } |
|
| 240 | + else { |
|
| 241 | + 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); |
|
| 242 | + } |
|
| 243 | + return false; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -250,19 +250,19 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function auth_spip_formulaire_login($flux) { |
| 253 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 254 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 255 | - $flux['data'] .= |
|
| 256 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 257 | - . "$js\n" |
|
| 258 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 259 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | - . "'informe_auteur_en_cours':false," |
|
| 261 | - . "'attente_informe':0};" |
|
| 262 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 263 | - . '/*]]>*/</script>'; |
|
| 264 | - |
|
| 265 | - return $flux; |
|
| 253 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 254 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 255 | + $flux['data'] .= |
|
| 256 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 257 | + . "$js\n" |
|
| 258 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 259 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | + . "'informe_auteur_en_cours':false," |
|
| 261 | + . "'attente_informe':0};" |
|
| 262 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 263 | + . '/*]]>*/</script>'; |
|
| 264 | + |
|
| 265 | + return $flux; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -274,11 +274,11 @@ discard block |
||
| 274 | 274 | * toujours true pour un auteur cree dans SPIP |
| 275 | 275 | */ |
| 276 | 276 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 277 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 278 | - if (strlen($serveur)) { |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - return true; |
|
| 277 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 278 | + if (strlen($serveur)) { |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + return true; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -292,25 +292,25 @@ discard block |
||
| 292 | 292 | * message d'erreur si login non valide, chaine vide sinon |
| 293 | 293 | */ |
| 294 | 294 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 295 | - // login et mot de passe |
|
| 296 | - if (strlen($new_login)) { |
|
| 297 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 298 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 299 | - } else { |
|
| 300 | - $n = sql_countsel( |
|
| 301 | - 'spip_auteurs', |
|
| 302 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 303 | - '', |
|
| 304 | - '', |
|
| 305 | - $serveur |
|
| 306 | - ); |
|
| 307 | - if ($n) { |
|
| 308 | - return _T('info_login_existant'); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return ''; |
|
| 295 | + // login et mot de passe |
|
| 296 | + if (strlen($new_login)) { |
|
| 297 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 298 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 299 | + } else { |
|
| 300 | + $n = sql_countsel( |
|
| 301 | + 'spip_auteurs', |
|
| 302 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 303 | + '', |
|
| 304 | + '', |
|
| 305 | + $serveur |
|
| 306 | + ); |
|
| 307 | + if ($n) { |
|
| 308 | + return _T('info_login_existant'); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return ''; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -322,41 +322,41 @@ discard block |
||
| 322 | 322 | * @return bool |
| 323 | 323 | */ |
| 324 | 324 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 325 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - if ( |
|
| 329 | - !$id_auteur = intval($id_auteur) |
|
| 330 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 331 | - ) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if ($new_login == $auteur['login']) { |
|
| 335 | - return true; |
|
| 336 | - } // on a rien fait mais c'est bon ! |
|
| 337 | - |
|
| 338 | - include_spip('action/editer_auteur'); |
|
| 339 | - |
|
| 340 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 341 | - if (strlen($new_login)) { |
|
| 342 | - $anciens = sql_allfetsel( |
|
| 343 | - 'id_auteur', |
|
| 344 | - 'spip_auteurs', |
|
| 345 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 346 | - '', |
|
| 347 | - '', |
|
| 348 | - '', |
|
| 349 | - '', |
|
| 350 | - $serveur |
|
| 351 | - ); |
|
| 352 | - while ($row = array_pop($anciens)) { |
|
| 353 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 358 | - |
|
| 359 | - return true; |
|
| 325 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + if ( |
|
| 329 | + !$id_auteur = intval($id_auteur) |
|
| 330 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 331 | + ) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if ($new_login == $auteur['login']) { |
|
| 335 | + return true; |
|
| 336 | + } // on a rien fait mais c'est bon ! |
|
| 337 | + |
|
| 338 | + include_spip('action/editer_auteur'); |
|
| 339 | + |
|
| 340 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 341 | + if (strlen($new_login)) { |
|
| 342 | + $anciens = sql_allfetsel( |
|
| 343 | + 'id_auteur', |
|
| 344 | + 'spip_auteurs', |
|
| 345 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 346 | + '', |
|
| 347 | + '', |
|
| 348 | + '', |
|
| 349 | + '', |
|
| 350 | + $serveur |
|
| 351 | + ); |
|
| 352 | + while ($row = array_pop($anciens)) { |
|
| 353 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 358 | + |
|
| 359 | + return true; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -368,44 +368,44 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 371 | - if (!strlen($login)) { |
|
| 372 | - return null; |
|
| 373 | - } // pas la peine de requeter |
|
| 374 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 375 | - if ( |
|
| 376 | - $r = sql_getfetsel( |
|
| 377 | - 'login', |
|
| 378 | - 'spip_auteurs', |
|
| 379 | - "statut<>'5poubelle'" . |
|
| 380 | - ' AND (length(pass)>0)' . |
|
| 381 | - " AND (login=$l)", |
|
| 382 | - '', |
|
| 383 | - '', |
|
| 384 | - '', |
|
| 385 | - '', |
|
| 386 | - $serveur |
|
| 387 | - ) |
|
| 388 | - ) { |
|
| 389 | - return $r; |
|
| 390 | - } |
|
| 391 | - // Si pas d'auteur avec ce login |
|
| 392 | - // regarder s'il a saisi son nom ou son mail. |
|
| 393 | - // Ne pas fusionner avec la requete precedente |
|
| 394 | - // car un nom peut etre homonyme d'un autre login |
|
| 395 | - else { |
|
| 396 | - return sql_getfetsel( |
|
| 397 | - 'login', |
|
| 398 | - 'spip_auteurs', |
|
| 399 | - "statut<>'5poubelle'" . |
|
| 400 | - ' AND (length(pass)>0)' . |
|
| 401 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 402 | - '', |
|
| 403 | - '', |
|
| 404 | - '', |
|
| 405 | - '', |
|
| 406 | - $serveur |
|
| 407 | - ); |
|
| 408 | - } |
|
| 371 | + if (!strlen($login)) { |
|
| 372 | + return null; |
|
| 373 | + } // pas la peine de requeter |
|
| 374 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 375 | + if ( |
|
| 376 | + $r = sql_getfetsel( |
|
| 377 | + 'login', |
|
| 378 | + 'spip_auteurs', |
|
| 379 | + "statut<>'5poubelle'" . |
|
| 380 | + ' AND (length(pass)>0)' . |
|
| 381 | + " AND (login=$l)", |
|
| 382 | + '', |
|
| 383 | + '', |
|
| 384 | + '', |
|
| 385 | + '', |
|
| 386 | + $serveur |
|
| 387 | + ) |
|
| 388 | + ) { |
|
| 389 | + return $r; |
|
| 390 | + } |
|
| 391 | + // Si pas d'auteur avec ce login |
|
| 392 | + // regarder s'il a saisi son nom ou son mail. |
|
| 393 | + // Ne pas fusionner avec la requete precedente |
|
| 394 | + // car un nom peut etre homonyme d'un autre login |
|
| 395 | + else { |
|
| 396 | + return sql_getfetsel( |
|
| 397 | + 'login', |
|
| 398 | + 'spip_auteurs', |
|
| 399 | + "statut<>'5poubelle'" . |
|
| 400 | + ' AND (length(pass)>0)' . |
|
| 401 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 402 | + '', |
|
| 403 | + '', |
|
| 404 | + '', |
|
| 405 | + '', |
|
| 406 | + $serveur |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -416,11 +416,11 @@ discard block |
||
| 416 | 416 | * toujours true pour un auteur cree dans SPIP |
| 417 | 417 | */ |
| 418 | 418 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 419 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 420 | - if (strlen($serveur)) { |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - return true; |
|
| 419 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 420 | + if (strlen($serveur)) { |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + return true; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -441,12 +441,12 @@ discard block |
||
| 441 | 441 | * message d'erreur si login non valide, chaine vide sinon |
| 442 | 442 | */ |
| 443 | 443 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 444 | - // login et mot de passe |
|
| 445 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 446 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 447 | - } |
|
| 444 | + // login et mot de passe |
|
| 445 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 446 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - return ''; |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -460,47 +460,47 @@ discard block |
||
| 460 | 460 | * @return bool |
| 461 | 461 | */ |
| 462 | 462 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 463 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 464 | - return false; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - if ( |
|
| 468 | - !$id_auteur = intval($id_auteur) |
|
| 469 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 470 | - ) { |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $cles = SpipCles::instance(); |
|
| 475 | - $secret = $cles->getSecretAuth(); |
|
| 476 | - if (!$secret) { |
|
| 477 | - if (auth_spip_initialiser_secret()) { |
|
| 478 | - $secret = $cles->getSecretAuth(); |
|
| 479 | - } |
|
| 480 | - else { |
|
| 481 | - return false; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - include_spip('inc/acces'); |
|
| 487 | - $set = [ |
|
| 488 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 489 | - 'htpass' => generer_htpass($new_pass), |
|
| 490 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 492 | - 'low_sec' => '', |
|
| 493 | - ]; |
|
| 494 | - |
|
| 495 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 496 | - if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 497 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - include_spip('action/editer_auteur'); |
|
| 501 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 502 | - |
|
| 503 | - return true; // on a bien modifie le pass |
|
| 463 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 464 | + return false; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if ( |
|
| 468 | + !$id_auteur = intval($id_auteur) |
|
| 469 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 470 | + ) { |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $cles = SpipCles::instance(); |
|
| 475 | + $secret = $cles->getSecretAuth(); |
|
| 476 | + if (!$secret) { |
|
| 477 | + if (auth_spip_initialiser_secret()) { |
|
| 478 | + $secret = $cles->getSecretAuth(); |
|
| 479 | + } |
|
| 480 | + else { |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + include_spip('inc/acces'); |
|
| 487 | + $set = [ |
|
| 488 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 489 | + 'htpass' => generer_htpass($new_pass), |
|
| 490 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 492 | + 'low_sec' => '', |
|
| 493 | + ]; |
|
| 494 | + |
|
| 495 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 496 | + if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 497 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + include_spip('action/editer_auteur'); |
|
| 501 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 502 | + |
|
| 503 | + return true; // on a bien modifie le pass |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -514,58 +514,58 @@ discard block |
||
| 514 | 514 | * @return void |
| 515 | 515 | */ |
| 516 | 516 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 517 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 518 | - if (strlen($serveur)) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - // si un login, pass ou statut a ete modifie |
|
| 522 | - // regenerer les fichier htpass |
|
| 523 | - if ( |
|
| 524 | - isset($champs['login']) |
|
| 525 | - or isset($champs['pass']) |
|
| 526 | - or isset($champs['statut']) |
|
| 527 | - or (isset($options['all']) and $options['all']) |
|
| 528 | - ) { |
|
| 529 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 530 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 531 | - |
|
| 532 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 533 | - // par exemple acces_restreint ; |
|
| 534 | - // si .htaccess existe, outrepasser spip_meta |
|
| 535 | - if ( |
|
| 536 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 537 | - and !@file_exists($htaccess) |
|
| 538 | - ) { |
|
| 539 | - spip_unlink($htpasswd); |
|
| 540 | - spip_unlink($htpasswd . '-admin'); |
|
| 541 | - |
|
| 542 | - return; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 546 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 547 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 548 | - |
|
| 549 | - $p1 = ''; // login:htpass pour tous |
|
| 550 | - $p2 = ''; // login:htpass pour les admins |
|
| 551 | - $s = sql_select( |
|
| 552 | - 'login, htpass, statut', |
|
| 553 | - 'spip_auteurs', |
|
| 554 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 555 | - ); |
|
| 556 | - while ($t = sql_fetch($s)) { |
|
| 557 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 558 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 559 | - if ($t['statut'] == '0minirezo') { |
|
| 560 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - sql_free($s); |
|
| 565 | - if ($p1) { |
|
| 566 | - ecrire_fichier($htpasswd, $p1); |
|
| 567 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 568 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 569 | - } |
|
| 570 | - } |
|
| 517 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 518 | + if (strlen($serveur)) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + // si un login, pass ou statut a ete modifie |
|
| 522 | + // regenerer les fichier htpass |
|
| 523 | + if ( |
|
| 524 | + isset($champs['login']) |
|
| 525 | + or isset($champs['pass']) |
|
| 526 | + or isset($champs['statut']) |
|
| 527 | + or (isset($options['all']) and $options['all']) |
|
| 528 | + ) { |
|
| 529 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 530 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 531 | + |
|
| 532 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 533 | + // par exemple acces_restreint ; |
|
| 534 | + // si .htaccess existe, outrepasser spip_meta |
|
| 535 | + if ( |
|
| 536 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 537 | + and !@file_exists($htaccess) |
|
| 538 | + ) { |
|
| 539 | + spip_unlink($htpasswd); |
|
| 540 | + spip_unlink($htpasswd . '-admin'); |
|
| 541 | + |
|
| 542 | + return; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 546 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 547 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 548 | + |
|
| 549 | + $p1 = ''; // login:htpass pour tous |
|
| 550 | + $p2 = ''; // login:htpass pour les admins |
|
| 551 | + $s = sql_select( |
|
| 552 | + 'login, htpass, statut', |
|
| 553 | + 'spip_auteurs', |
|
| 554 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 555 | + ); |
|
| 556 | + while ($t = sql_fetch($s)) { |
|
| 557 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 558 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 559 | + if ($t['statut'] == '0minirezo') { |
|
| 560 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + sql_free($s); |
|
| 565 | + if ($p1) { |
|
| 566 | + ecrire_fichier($htpasswd, $p1); |
|
| 567 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 568 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 26 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | * Description de la boucle complétée des champs |
| 45 | 45 | */ |
| 46 | 46 | function iterateur_DATA_dist($b) { |
| 47 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | - $b->show = [ |
|
| 49 | - 'field' => [ |
|
| 50 | - 'cle' => 'STRING', |
|
| 51 | - 'valeur' => 'STRING', |
|
| 52 | - '*' => 'ALL' // Champ joker * |
|
| 53 | - ] |
|
| 54 | - ]; |
|
| 55 | - $b->select[] = '.valeur'; |
|
| 56 | - |
|
| 57 | - return $b; |
|
| 47 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | + $b->show = [ |
|
| 49 | + 'field' => [ |
|
| 50 | + 'cle' => 'STRING', |
|
| 51 | + 'valeur' => 'STRING', |
|
| 52 | + '*' => 'ALL' // Champ joker * |
|
| 53 | + ] |
|
| 54 | + ]; |
|
| 55 | + $b->select[] = '.valeur'; |
|
| 56 | + |
|
| 57 | + return $b; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | 71 | function inc_file_to_array_dist($data) { |
| 72 | - return preg_split('/\r?\n/', $data); |
|
| 72 | + return preg_split('/\r?\n/', $data); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | function inc_plugins_to_array_dist() { |
| 81 | - include_spip('inc/plugin'); |
|
| 81 | + include_spip('inc/plugin'); |
|
| 82 | 82 | |
| 83 | - return liste_chemin_plugin_actifs(); |
|
| 83 | + return liste_chemin_plugin_actifs(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | 92 | function inc_xml_to_array_dist($data) { |
| 93 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | */ |
| 104 | 104 | function inc_object_to_array($object) { |
| 105 | - if (!is_object($object) && !is_array($object)) { |
|
| 106 | - return $object; |
|
| 107 | - } |
|
| 108 | - if (is_object($object)) { |
|
| 109 | - $object = get_object_vars($object); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return array_map('inc_object_to_array', $object); |
|
| 105 | + if (!is_object($object) && !is_array($object)) { |
|
| 106 | + return $object; |
|
| 107 | + } |
|
| 108 | + if (is_object($object)) { |
|
| 109 | + $object = get_object_vars($object); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return array_map('inc_object_to_array', $object); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,20 +119,20 @@ discard block |
||
| 119 | 119 | * @return array|bool |
| 120 | 120 | */ |
| 121 | 121 | function inc_sql_to_array_dist($data) { |
| 122 | - # sortir le connecteur de $data |
|
| 123 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | - $serveur = (string)$v[1]; |
|
| 125 | - $req = trim($v[2]); |
|
| 126 | - if ($s = sql_query($req, $serveur)) { |
|
| 127 | - $r = []; |
|
| 128 | - while ($t = sql_fetch($s)) { |
|
| 129 | - $r[] = $t; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $r; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return false; |
|
| 122 | + # sortir le connecteur de $data |
|
| 123 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | + $serveur = (string)$v[1]; |
|
| 125 | + $req = trim($v[2]); |
|
| 126 | + if ($s = sql_query($req, $serveur)) { |
|
| 127 | + $r = []; |
|
| 128 | + while ($t = sql_fetch($s)) { |
|
| 129 | + $r[] = $t; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $r; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | * @return array|bool |
| 143 | 143 | */ |
| 144 | 144 | function inc_json_to_array_dist($data) { |
| 145 | - try { |
|
| 146 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | - } catch (JsonException $e) { |
|
| 148 | - $json = null; |
|
| 149 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | - } |
|
| 151 | - return is_array($json) ? (array) $json : []; |
|
| 145 | + try { |
|
| 146 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | + } catch (JsonException $e) { |
|
| 148 | + $json = null; |
|
| 149 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | + } |
|
| 151 | + return is_array($json) ? (array) $json : []; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return array|bool |
| 159 | 159 | */ |
| 160 | 160 | function inc_csv_to_array_dist($data) { |
| 161 | - include_spip('inc/csv'); |
|
| 162 | - [$entete, $csv] = analyse_csv($data); |
|
| 163 | - array_unshift($csv, $entete); |
|
| 164 | - |
|
| 165 | - include_spip('inc/charsets'); |
|
| 166 | - $i = 1; |
|
| 167 | - foreach ($entete as $k => $v) { |
|
| 168 | - if (trim($v) == '') { |
|
| 169 | - $v = 'col' . $i; |
|
| 170 | - } // reperer des eventuelles cases vides |
|
| 171 | - if (is_numeric($v) and $v < 0) { |
|
| 172 | - $v = '__' . $v; |
|
| 173 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | - if (is_numeric($v)) { |
|
| 175 | - $v = '_' . $v; |
|
| 176 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | - foreach ($csv as &$item) { |
|
| 179 | - $item[$v] = &$item[$k]; |
|
| 180 | - } |
|
| 181 | - $i++; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $csv; |
|
| 161 | + include_spip('inc/csv'); |
|
| 162 | + [$entete, $csv] = analyse_csv($data); |
|
| 163 | + array_unshift($csv, $entete); |
|
| 164 | + |
|
| 165 | + include_spip('inc/charsets'); |
|
| 166 | + $i = 1; |
|
| 167 | + foreach ($entete as $k => $v) { |
|
| 168 | + if (trim($v) == '') { |
|
| 169 | + $v = 'col' . $i; |
|
| 170 | + } // reperer des eventuelles cases vides |
|
| 171 | + if (is_numeric($v) and $v < 0) { |
|
| 172 | + $v = '__' . $v; |
|
| 173 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | + if (is_numeric($v)) { |
|
| 175 | + $v = '_' . $v; |
|
| 176 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | + foreach ($csv as &$item) { |
|
| 179 | + $item[$v] = &$item[$k]; |
|
| 180 | + } |
|
| 181 | + $i++; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $csv; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return array|bool |
| 192 | 192 | */ |
| 193 | 193 | function inc_rss_to_array_dist($data) { |
| 194 | - $tableau = null; |
|
| 195 | - include_spip('inc/syndic'); |
|
| 196 | - if (is_array($rss = analyser_backend($data))) { |
|
| 197 | - $tableau = $rss; |
|
| 198 | - } |
|
| 194 | + $tableau = null; |
|
| 195 | + include_spip('inc/syndic'); |
|
| 196 | + if (is_array($rss = analyser_backend($data))) { |
|
| 197 | + $tableau = $rss; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - return $tableau; |
|
| 200 | + return $tableau; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | * @return array|bool |
| 208 | 208 | */ |
| 209 | 209 | function inc_atom_to_array_dist($data) { |
| 210 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 211 | 211 | |
| 212 | - return $rss_to_array($data); |
|
| 212 | + return $rss_to_array($data); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | * @return array|bool |
| 221 | 221 | */ |
| 222 | 222 | function inc_glob_to_array_dist($data) { |
| 223 | - $a = glob( |
|
| 224 | - $data, |
|
| 225 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | - ); |
|
| 223 | + $a = glob( |
|
| 224 | + $data, |
|
| 225 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - return $a ?: []; |
|
| 228 | + return $a ?: []; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | * @throws Exception |
| 237 | 237 | */ |
| 238 | 238 | function inc_yaml_to_array_dist($data) { |
| 239 | - include_spip('inc/yaml-mini'); |
|
| 240 | - if (!function_exists('yaml_decode')) { |
|
| 241 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 239 | + include_spip('inc/yaml-mini'); |
|
| 240 | + if (!function_exists('yaml_decode')) { |
|
| 241 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 242 | 242 | |
| 243 | - return false; |
|
| 244 | - } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return yaml_decode($data); |
|
| 246 | + return yaml_decode($data); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return array|bool |
| 259 | 259 | */ |
| 260 | 260 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 261 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | * @return array|bool |
| 271 | 271 | */ |
| 272 | 272 | function inc_ls_to_array_dist($data) { |
| 273 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | - $a = $glob_to_array($data); |
|
| 275 | - foreach ($a as &$v) { |
|
| 276 | - $b = (array)@stat($v); |
|
| 277 | - foreach ($b as $k => $ignore) { |
|
| 278 | - if (is_numeric($k)) { |
|
| 279 | - unset($b[$k]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | - $v = array_merge( |
|
| 284 | - pathinfo($v), |
|
| 285 | - $b |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $a; |
|
| 273 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | + $a = $glob_to_array($data); |
|
| 275 | + foreach ($a as &$v) { |
|
| 276 | + $b = (array)@stat($v); |
|
| 277 | + foreach ($b as $k => $ignore) { |
|
| 278 | + if (is_numeric($k)) { |
|
| 279 | + unset($b[$k]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | + $v = array_merge( |
|
| 284 | + pathinfo($v), |
|
| 285 | + $b |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return $a; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -296,25 +296,25 @@ discard block |
||
| 296 | 296 | * @return array|bool |
| 297 | 297 | */ |
| 298 | 298 | function XMLObjectToArray($object) { |
| 299 | - $xml_array = []; |
|
| 300 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | - $key .= '-' . uniqid(); |
|
| 303 | - } |
|
| 304 | - $vars = get_object_vars($object->current()); |
|
| 305 | - if (isset($vars['@attributes'])) { |
|
| 306 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | - $xml_array[$key][$k] = $v; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - if ($object->hasChildren()) { |
|
| 311 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | - $object->current() |
|
| 313 | - ); |
|
| 314 | - } else { |
|
| 315 | - $xml_array[$key][] = strval($object->current()); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $xml_array; |
|
| 299 | + $xml_array = []; |
|
| 300 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | + $key .= '-' . uniqid(); |
|
| 303 | + } |
|
| 304 | + $vars = get_object_vars($object->current()); |
|
| 305 | + if (isset($vars['@attributes'])) { |
|
| 306 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | + $xml_array[$key][$k] = $v; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + if ($object->hasChildren()) { |
|
| 311 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | + $object->current() |
|
| 313 | + ); |
|
| 314 | + } else { |
|
| 315 | + $xml_array[$key][] = strval($object->current()); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $xml_array; |
|
| 320 | 320 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('iterateur/data'); |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | * Description de la boucle complétée des champs |
| 38 | 38 | */ |
| 39 | 39 | function iterateur_CONDITION_dist($b) { |
| 40 | - $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | - $b->show = [ |
|
| 42 | - 'field' => [] |
|
| 43 | - ]; |
|
| 40 | + $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | + $b->show = [ |
|
| 42 | + 'field' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - return $b; |
|
| 45 | + return $b; |
|
| 46 | 46 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_POUR_dist($b) { |
| 41 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 41 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - return $b; |
|
| 49 | + return $b; |
|
| 50 | 50 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_php_dist($b, $iteratorName) { |
| 41 | - $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 48 | - |
|
| 49 | - foreach (get_class_methods($iteratorName) as $method) { |
|
| 50 | - $b->show['field'][strtolower($method)] = 'METHOD'; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $b; |
|
| 41 | + $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | + |
|
| 49 | + foreach (get_class_methods($iteratorName) as $method) { |
|
| 50 | + $b->show['field'][strtolower($method)] = 'METHOD'; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $b; |
|
| 54 | 54 | } |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Pipelines |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | if (test_espace_prive()) { |
| 22 | - include_spip('inc/pipelines_ecrire'); |
|
| 22 | + include_spip('inc/pipelines_ecrire'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -45,28 +45,28 @@ discard block |
||
| 45 | 45 | * @return string Contenu qui sera inséré dans le head HTML |
| 46 | 46 | **/ |
| 47 | 47 | function f_jQuery($texte) { |
| 48 | - $x = ''; |
|
| 49 | - $jquery_plugins = pipeline( |
|
| 50 | - 'jquery_plugins', |
|
| 51 | - [ |
|
| 52 | - 'javascript/jquery.js', |
|
| 53 | - 'javascript/jquery.form.js', |
|
| 54 | - 'javascript/jquery.autosave.js', |
|
| 55 | - 'javascript/jquery.placeholder-label.js', |
|
| 56 | - 'javascript/ajaxCallback.js', |
|
| 57 | - 'javascript/js.cookie.js', |
|
| 58 | - ] |
|
| 59 | - ); |
|
| 60 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 61 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 62 | - $script = timestamp($script); |
|
| 63 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 64 | - } |
|
| 65 | - } |
|
| 48 | + $x = ''; |
|
| 49 | + $jquery_plugins = pipeline( |
|
| 50 | + 'jquery_plugins', |
|
| 51 | + [ |
|
| 52 | + 'javascript/jquery.js', |
|
| 53 | + 'javascript/jquery.form.js', |
|
| 54 | + 'javascript/jquery.autosave.js', |
|
| 55 | + 'javascript/jquery.placeholder-label.js', |
|
| 56 | + 'javascript/ajaxCallback.js', |
|
| 57 | + 'javascript/js.cookie.js', |
|
| 58 | + ] |
|
| 59 | + ); |
|
| 60 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 61 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 62 | + $script = timestamp($script); |
|
| 63 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $texte = $x . $texte; |
|
| 67 | + $texte = $x . $texte; |
|
| 68 | 68 | |
| 69 | - return $texte; |
|
| 69 | + return $texte; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -85,28 +85,28 @@ discard block |
||
| 85 | 85 | * @return string Contenu de la page envoyée au navigateur |
| 86 | 86 | **/ |
| 87 | 87 | function f_surligne($texte) { |
| 88 | - if (!$GLOBALS['html']) { |
|
| 89 | - return $texte; |
|
| 90 | - } |
|
| 91 | - $rech = _request('var_recherche'); |
|
| 92 | - if ( |
|
| 93 | - !$rech |
|
| 94 | - and (!defined('_SURLIGNE_RECHERCHE_REFERERS') |
|
| 95 | - or !_SURLIGNE_RECHERCHE_REFERERS |
|
| 96 | - or !isset($_SERVER['HTTP_REFERER'])) |
|
| 97 | - ) { |
|
| 98 | - return $texte; |
|
| 99 | - } |
|
| 100 | - include_spip('inc/surligne'); |
|
| 88 | + if (!$GLOBALS['html']) { |
|
| 89 | + return $texte; |
|
| 90 | + } |
|
| 91 | + $rech = _request('var_recherche'); |
|
| 92 | + if ( |
|
| 93 | + !$rech |
|
| 94 | + and (!defined('_SURLIGNE_RECHERCHE_REFERERS') |
|
| 95 | + or !_SURLIGNE_RECHERCHE_REFERERS |
|
| 96 | + or !isset($_SERVER['HTTP_REFERER'])) |
|
| 97 | + ) { |
|
| 98 | + return $texte; |
|
| 99 | + } |
|
| 100 | + include_spip('inc/surligne'); |
|
| 101 | 101 | |
| 102 | - if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 103 | - $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']); |
|
| 104 | - } |
|
| 105 | - if ($rech) { |
|
| 106 | - $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech); |
|
| 107 | - } |
|
| 102 | + if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 103 | + $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']); |
|
| 104 | + } |
|
| 105 | + if ($rech) { |
|
| 106 | + $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return surligner_mots($texte, $rech); |
|
| 109 | + return surligner_mots($texte, $rech); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -123,33 +123,33 @@ discard block |
||
| 123 | 123 | * @return string Contenu de la page envoyée au navigateur |
| 124 | 124 | **/ |
| 125 | 125 | function f_tidy($texte) { |
| 126 | - /** |
|
| 127 | - * Indentation à faire ? |
|
| 128 | - * |
|
| 129 | - * - true : actif. |
|
| 130 | - * - false par défaut. |
|
| 131 | - */ |
|
| 126 | + /** |
|
| 127 | + * Indentation à faire ? |
|
| 128 | + * |
|
| 129 | + * - true : actif. |
|
| 130 | + * - false par défaut. |
|
| 131 | + */ |
|
| 132 | 132 | |
| 133 | - if ( |
|
| 134 | - $GLOBALS['xhtml'] # tidy demande |
|
| 135 | - and $GLOBALS['html'] # verifie que la page avait l'entete text/html |
|
| 136 | - and strlen($texte) |
|
| 137 | - and !headers_sent() |
|
| 138 | - ) { |
|
| 139 | - # Compatibilite ascendante |
|
| 140 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 141 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 142 | - } |
|
| 133 | + if ( |
|
| 134 | + $GLOBALS['xhtml'] # tidy demande |
|
| 135 | + and $GLOBALS['html'] # verifie que la page avait l'entete text/html |
|
| 136 | + and strlen($texte) |
|
| 137 | + and !headers_sent() |
|
| 138 | + ) { |
|
| 139 | + # Compatibilite ascendante |
|
| 140 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 141 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 145 | - spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 146 | - $f = charger_fonction('sax', 'xml'); |
|
| 147 | - } |
|
| 144 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 145 | + spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 146 | + $f = charger_fonction('sax', 'xml'); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return $f($texte); |
|
| 150 | - } |
|
| 149 | + return $f($texte); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return $texte; |
|
| 152 | + return $texte; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -168,21 +168,21 @@ discard block |
||
| 168 | 168 | * @return string Contenu de la page envoyée au navigateur |
| 169 | 169 | **/ |
| 170 | 170 | function f_insert_head($texte) { |
| 171 | - if (!$GLOBALS['html']) { |
|
| 172 | - return $texte; |
|
| 173 | - } |
|
| 174 | - include_spip('public/admin'); // pour strripos |
|
| 171 | + if (!$GLOBALS['html']) { |
|
| 172 | + return $texte; |
|
| 173 | + } |
|
| 174 | + include_spip('public/admin'); // pour strripos |
|
| 175 | 175 | |
| 176 | - ($pos = stripos($texte, '</head>')) |
|
| 177 | - || ($pos = stripos($texte, '<body>')) |
|
| 178 | - || ($pos = 0); |
|
| 176 | + ($pos = stripos($texte, '</head>')) |
|
| 177 | + || ($pos = stripos($texte, '<body>')) |
|
| 178 | + || ($pos = 0); |
|
| 179 | 179 | |
| 180 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 181 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 182 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 183 | - } |
|
| 180 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 181 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 182 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - return $texte; |
|
| 185 | + return $texte; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -198,34 +198,34 @@ discard block |
||
| 198 | 198 | * @return string Contenu de la page envoyée au navigateur |
| 199 | 199 | **/ |
| 200 | 200 | function f_admin($texte) { |
| 201 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) { |
|
| 202 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 203 | - $x = "<div class='spip-previsu' " |
|
| 204 | - . http_style_background('preview-32.png', '', 32) |
|
| 205 | - . '>' |
|
| 206 | - . _T('previsualisation') |
|
| 207 | - . '</div>'; |
|
| 208 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 209 | - $pos = strlen($texte); |
|
| 210 | - } |
|
| 211 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 212 | - // pas de preview en fenetre enfant |
|
| 213 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 214 | - if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
|
| 215 | - $pos = -1; |
|
| 216 | - } |
|
| 217 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 218 | - } |
|
| 201 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) { |
|
| 202 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 203 | + $x = "<div class='spip-previsu' " |
|
| 204 | + . http_style_background('preview-32.png', '', 32) |
|
| 205 | + . '>' |
|
| 206 | + . _T('previsualisation') |
|
| 207 | + . '</div>'; |
|
| 208 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 209 | + $pos = strlen($texte); |
|
| 210 | + } |
|
| 211 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 212 | + // pas de preview en fenetre enfant |
|
| 213 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 214 | + if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
|
| 215 | + $pos = -1; |
|
| 216 | + } |
|
| 217 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) { |
|
| 221 | - include_spip('public/admin'); |
|
| 222 | - $texte = affiche_boutons_admin($texte); |
|
| 223 | - } |
|
| 224 | - if (_request('var_mode') == 'noajax') { |
|
| 225 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 226 | - } |
|
| 220 | + if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) { |
|
| 221 | + include_spip('public/admin'); |
|
| 222 | + $texte = affiche_boutons_admin($texte); |
|
| 223 | + } |
|
| 224 | + if (_request('var_mode') == 'noajax') { |
|
| 225 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return $texte; |
|
| 228 | + return $texte; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * @return array $flux Description et contenu de l'inclusion |
| 244 | 244 | **/ |
| 245 | 245 | function f_recuperer_fond($flux) { |
| 246 | - if (!test_espace_prive()) { |
|
| 247 | - return $flux; |
|
| 248 | - } |
|
| 246 | + if (!test_espace_prive()) { |
|
| 247 | + return $flux; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return f_afficher_blocs_ecrire($flux); |
|
| 250 | + return f_afficher_blocs_ecrire($flux); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -261,30 +261,30 @@ discard block |
||
| 261 | 261 | * @return string Contenu de la page envoyée au navigateur |
| 262 | 262 | */ |
| 263 | 263 | function f_queue($texte) { |
| 264 | - // eviter une inclusion si rien a faire |
|
| 265 | - if ( |
|
| 266 | - _request('action') == 'cron' |
|
| 267 | - or queue_sleep_time_to_next_job() > 0 |
|
| 268 | - or defined('_DEBUG_BLOCK_QUEUE') |
|
| 269 | - ) { |
|
| 270 | - return $texte; |
|
| 271 | - } |
|
| 264 | + // eviter une inclusion si rien a faire |
|
| 265 | + if ( |
|
| 266 | + _request('action') == 'cron' |
|
| 267 | + or queue_sleep_time_to_next_job() > 0 |
|
| 268 | + or defined('_DEBUG_BLOCK_QUEUE') |
|
| 269 | + ) { |
|
| 270 | + return $texte; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - include_spip('inc/queue'); |
|
| 274 | - $code = queue_affichage_cron(); |
|
| 273 | + include_spip('inc/queue'); |
|
| 274 | + $code = queue_affichage_cron(); |
|
| 275 | 275 | |
| 276 | - // si rien a afficher |
|
| 277 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 278 | - if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) { |
|
| 279 | - return $texte; |
|
| 280 | - } |
|
| 276 | + // si rien a afficher |
|
| 277 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 278 | + if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) { |
|
| 279 | + return $texte; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 283 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 284 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 285 | - } else { |
|
| 286 | - $texte .= $code; |
|
| 287 | - } |
|
| 282 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 283 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 284 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 285 | + } else { |
|
| 286 | + $texte .= $code; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - return $texte; |
|
| 289 | + return $texte; |
|
| 290 | 290 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,35 +39,35 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | - } else { |
|
| 45 | - if (is_array($liste_langues)) { |
|
| 46 | - $liste_langues = implode(',', $liste_langues); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | - |
|
| 51 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | - if (!$lang) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | - and str_contains($liste_langues, (string) ",$lang,")) |
|
| 62 | - ) { |
|
| 63 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | - |
|
| 67 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | + } else { |
|
| 45 | + if (is_array($liste_langues)) { |
|
| 46 | + $liste_langues = implode(',', $liste_langues); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | + |
|
| 51 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | + if (!$lang) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | + and str_contains($liste_langues, (string) ",$lang,")) |
|
| 62 | + ) { |
|
| 63 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | + |
|
| 67 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 81 | 81 | |
| 82 | 82 | function choisir_traduction($trads, $lang = '') { |
| 83 | - $k = approcher_langue($trads, $lang); |
|
| 83 | + $k = approcher_langue($trads, $lang); |
|
| 84 | 84 | |
| 85 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // retourne son 2e argument si c'est un index du premier |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | // la langue X etant consideree comme une approche de X_Y |
| 91 | 91 | function approcher_langue($trads, $lang = '') { |
| 92 | 92 | |
| 93 | - if (!$lang) { |
|
| 94 | - $lang = $GLOBALS['spip_lang']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (isset($trads[$lang])) { |
|
| 98 | - return $lang; |
|
| 99 | - } // cas des langues xx_yy |
|
| 100 | - else { |
|
| 101 | - $r = explode('_', $lang); |
|
| 102 | - if (isset($trads[$r[0]])) { |
|
| 103 | - return $r[0]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return ''; |
|
| 93 | + if (!$lang) { |
|
| 94 | + $lang = $GLOBALS['spip_lang']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (isset($trads[$lang])) { |
|
| 98 | + return $lang; |
|
| 99 | + } // cas des langues xx_yy |
|
| 100 | + else { |
|
| 101 | + $r = explode('_', $lang); |
|
| 102 | + if (isset($trads[$r[0]])) { |
|
| 103 | + return $r[0]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * Nom de la langue, sinon son code. |
| 120 | 120 | **/ |
| 121 | 121 | function traduire_nom_langue($lang) { |
| 122 | - include_spip('inc/lang_liste'); |
|
| 123 | - include_spip('inc/charsets'); |
|
| 122 | + include_spip('inc/lang_liste'); |
|
| 123 | + include_spip('inc/charsets'); |
|
| 124 | 124 | |
| 125 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | // hebreu a priori), 'droitier' sinon. |
| 136 | 136 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 137 | 137 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 138 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 139 | 139 | |
| 140 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | - $gaucher : $droitier; |
|
| 140 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | + $gaucher : $droitier; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // typo francaise ou anglaise ? |
@@ -147,29 +147,29 @@ discard block |
||
| 147 | 147 | // sinon determiner la typo en fonction de la langue courante |
| 148 | 148 | |
| 149 | 149 | function lang_typo($lang = '') { |
| 150 | - if (!$lang) { |
|
| 151 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | - } |
|
| 153 | - if ( |
|
| 154 | - $lang == 'eo' |
|
| 155 | - or $lang == 'fr' |
|
| 156 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | - or $lang == 'cpf' |
|
| 158 | - ) { |
|
| 159 | - return 'fr'; |
|
| 160 | - } else { |
|
| 161 | - return 'en'; |
|
| 162 | - } |
|
| 150 | + if (!$lang) { |
|
| 151 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | + } |
|
| 153 | + if ( |
|
| 154 | + $lang == 'eo' |
|
| 155 | + or $lang == 'fr' |
|
| 156 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | + or $lang == 'cpf' |
|
| 158 | + ) { |
|
| 159 | + return 'fr'; |
|
| 160 | + } else { |
|
| 161 | + return 'en'; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 166 | 166 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 167 | 167 | function changer_typo($lang = '') { |
| 168 | - if ($lang) { |
|
| 169 | - $GLOBALS['lang_objet'] = $lang; |
|
| 170 | - } else { |
|
| 171 | - unset($GLOBALS['lang_objet']); |
|
| 172 | - } |
|
| 168 | + if ($lang) { |
|
| 169 | + $GLOBALS['lang_objet'] = $lang; |
|
| 170 | + } else { |
|
| 171 | + unset($GLOBALS['lang_objet']); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // |
@@ -179,58 +179,58 @@ discard block |
||
| 179 | 179 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 180 | 180 | // |
| 181 | 181 | function menu_langues($nom_select, $default = '') { |
| 182 | - include_spip('inc/actions'); |
|
| 183 | - |
|
| 184 | - $langues = liste_options_langues($nom_select); |
|
| 185 | - $ret = ''; |
|
| 186 | - if (!count($langues)) { |
|
| 187 | - return ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (!$default) { |
|
| 191 | - $default = $GLOBALS['spip_lang']; |
|
| 192 | - } |
|
| 193 | - foreach ($langues as $l) { |
|
| 194 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (!test_espace_prive()) { |
|
| 199 | - $cible = self(); |
|
| 200 | - $base = ''; |
|
| 201 | - } else { |
|
| 202 | - $cible = self(); |
|
| 203 | - $base = spip_connect() ? 'base' : ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | - |
|
| 208 | - return generer_action_auteur( |
|
| 209 | - 'converser', |
|
| 210 | - $base, |
|
| 211 | - $cible, |
|
| 212 | - (select_langues($nom_select, $change, $ret) |
|
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | - " method='post'" |
|
| 215 | - ); |
|
| 182 | + include_spip('inc/actions'); |
|
| 183 | + |
|
| 184 | + $langues = liste_options_langues($nom_select); |
|
| 185 | + $ret = ''; |
|
| 186 | + if (!count($langues)) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (!$default) { |
|
| 191 | + $default = $GLOBALS['spip_lang']; |
|
| 192 | + } |
|
| 193 | + foreach ($langues as $l) { |
|
| 194 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (!test_espace_prive()) { |
|
| 199 | + $cible = self(); |
|
| 200 | + $base = ''; |
|
| 201 | + } else { |
|
| 202 | + $cible = self(); |
|
| 203 | + $base = spip_connect() ? 'base' : ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | + |
|
| 208 | + return generer_action_auteur( |
|
| 209 | + 'converser', |
|
| 210 | + $base, |
|
| 211 | + $cible, |
|
| 212 | + (select_langues($nom_select, $change, $ret) |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | + " method='post'" |
|
| 215 | + ); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | - static $cpt = 0; |
|
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 221 | - |
|
| 222 | - return |
|
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | - "<select name='$nom_select' id='$id' " |
|
| 225 | - . ((!test_espace_prive()) ? |
|
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 230 | - . $change |
|
| 231 | - . ">\n" |
|
| 232 | - . $options |
|
| 233 | - . '</select>'; |
|
| 219 | + static $cpt = 0; |
|
| 220 | + $id = 'menu_langues' . $cpt++; |
|
| 221 | + |
|
| 222 | + return |
|
| 223 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | + "<select name='$nom_select' id='$id' " |
|
| 225 | + . ((!test_espace_prive()) ? |
|
| 226 | + ("class='forml menu_langues'") : |
|
| 227 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | + ("class='lang_ecrire'") : |
|
| 229 | + "class='fondl'")) |
|
| 230 | + . $change |
|
| 231 | + . ">\n" |
|
| 232 | + . $options |
|
| 233 | + . '</select>'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -252,34 +252,34 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function liste_options_langues($nom_select) { |
| 254 | 254 | |
| 255 | - switch ($nom_select) { |
|
| 256 | - # #MENU_LANG |
|
| 257 | - case 'var_lang': |
|
| 258 | - # menu de changement de la langue d'un article |
|
| 259 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | - case 'changer_lang': |
|
| 261 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | - break; |
|
| 263 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | - # les langues presentes sous forme de fichiers de langue |
|
| 265 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | - case 'var_lang_ecrire': |
|
| 267 | - default: |
|
| 268 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | - init_langues(); |
|
| 270 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | - break; |
|
| 255 | + switch ($nom_select) { |
|
| 256 | + # #MENU_LANG |
|
| 257 | + case 'var_lang': |
|
| 258 | + # menu de changement de la langue d'un article |
|
| 259 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | + case 'changer_lang': |
|
| 261 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | + break; |
|
| 263 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | + # les langues presentes sous forme de fichiers de langue |
|
| 265 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | + case 'var_lang_ecrire': |
|
| 267 | + default: |
|
| 268 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | + init_langues(); |
|
| 270 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | + break; |
|
| 272 | 272 | |
| 273 | 273 | # dernier choix possible : toutes les langues = langues_proposees |
| 274 | 274 | # + langues_multilingues ; mais, ne sert pas |
| 275 | 275 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 276 | - } |
|
| 277 | - if (count($langues) <= 1) { |
|
| 278 | - return []; |
|
| 279 | - } |
|
| 280 | - sort($langues); |
|
| 276 | + } |
|
| 277 | + if (count($langues) <= 1) { |
|
| 278 | + return []; |
|
| 279 | + } |
|
| 280 | + sort($langues); |
|
| 281 | 281 | |
| 282 | - return $langues; |
|
| 282 | + return $langues; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -294,39 +294,39 @@ discard block |
||
| 294 | 294 | **/ |
| 295 | 295 | function verifier_lang_url() { |
| 296 | 296 | |
| 297 | - // quelle langue est demandee ? |
|
| 298 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | - } |
|
| 302 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | - } |
|
| 305 | - if (isset($_GET['lang'])) { |
|
| 306 | - $lang_demandee = $_GET['lang']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | - if ( |
|
| 311 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | - and changer_langue($lang_demandee) |
|
| 313 | - and $lang_demandee != @$_GET['lang'] |
|
| 314 | - ) { |
|
| 315 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | - // ici on a besoin des var_truc |
|
| 317 | - foreach ($_GET as $var => $val) { |
|
| 318 | - if (!strncmp('var_', $var, 4)) { |
|
| 319 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - include_spip('inc/headers'); |
|
| 323 | - redirige_par_entete($destination); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | - // (pour criteres {lang}). |
|
| 329 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 297 | + // quelle langue est demandee ? |
|
| 298 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | + } |
|
| 302 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | + } |
|
| 305 | + if (isset($_GET['lang'])) { |
|
| 306 | + $lang_demandee = $_GET['lang']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | + if ( |
|
| 311 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | + and changer_langue($lang_demandee) |
|
| 313 | + and $lang_demandee != @$_GET['lang'] |
|
| 314 | + ) { |
|
| 315 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | + // ici on a besoin des var_truc |
|
| 317 | + foreach ($_GET as $var => $val) { |
|
| 318 | + if (!strncmp('var_', $var, 4)) { |
|
| 319 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + include_spip('inc/headers'); |
|
| 323 | + redirige_par_entete($destination); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | + // (pour criteres {lang}). |
|
| 329 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -344,22 +344,22 @@ discard block |
||
| 344 | 344 | * La langue sélectionnée |
| 345 | 345 | **/ |
| 346 | 346 | function utiliser_langue_site($liste_langues = null) { |
| 347 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | - if ( |
|
| 349 | - isset($GLOBALS['meta']['langue_site']) |
|
| 350 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | - and (!isset($GLOBALS['spip_lang']) |
|
| 353 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | - ) { |
|
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | - } |
|
| 357 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $GLOBALS['spip_lang']; |
|
| 347 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | + if ( |
|
| 349 | + isset($GLOBALS['meta']['langue_site']) |
|
| 350 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | + and (!isset($GLOBALS['spip_lang']) |
|
| 353 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | + ) { |
|
| 355 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | + } |
|
| 357 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $GLOBALS['spip_lang']; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,35 +378,35 @@ discard block |
||
| 378 | 378 | **/ |
| 379 | 379 | function utiliser_langue_visiteur($liste_langues = null) { |
| 380 | 380 | |
| 381 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | - if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | - if (isset($_COOKIE[$l])) { |
|
| 388 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | - return $l; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | - return $l; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | - return $l; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return utiliser_langue_site($liste_langues); |
|
| 381 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | + if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | + if (isset($_COOKIE[$l])) { |
|
| 388 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | + return $l; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | + return $l; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | + return $l; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return utiliser_langue_site($liste_langues); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return int |
| 417 | 417 | */ |
| 418 | 418 | function match_langue($chaine) { |
| 419 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 419 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -434,36 +434,36 @@ discard block |
||
| 434 | 434 | **/ |
| 435 | 435 | function init_langues() { |
| 436 | 436 | |
| 437 | - // liste des langues dans les meta, sauf a l'install |
|
| 438 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | - |
|
| 440 | - $tout = []; |
|
| 441 | - if (!$all_langs) { |
|
| 442 | - // trouver tous les modules lang/spip_xx.php |
|
| 443 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | - foreach ($modules as $name => $path) { |
|
| 445 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | - if (match_langue($regs[1])) { |
|
| 447 | - $tout[] = $regs[1]; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - sort($tout); |
|
| 452 | - $tout = join(',', $tout); |
|
| 453 | - // Si les langues n'ont pas change, ne rien faire |
|
| 454 | - if ($tout != $all_langs) { |
|
| 455 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | - include_spip('inc/meta'); |
|
| 457 | - ecrire_meta('langues_proposees', $tout); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | - ecrire_meta('langue_site', $tout); |
|
| 466 | - } |
|
| 437 | + // liste des langues dans les meta, sauf a l'install |
|
| 438 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | + |
|
| 440 | + $tout = []; |
|
| 441 | + if (!$all_langs) { |
|
| 442 | + // trouver tous les modules lang/spip_xx.php |
|
| 443 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | + foreach ($modules as $name => $path) { |
|
| 445 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | + if (match_langue($regs[1])) { |
|
| 447 | + $tout[] = $regs[1]; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + sort($tout); |
|
| 452 | + $tout = join(',', $tout); |
|
| 453 | + // Si les langues n'ont pas change, ne rien faire |
|
| 454 | + if ($tout != $all_langs) { |
|
| 455 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | + include_spip('inc/meta'); |
|
| 457 | + ecrire_meta('langues_proposees', $tout); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | + ecrire_meta('langue_site', $tout); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | * Code html de la balise <html> |
| 478 | 478 | **/ |
| 479 | 479 | function html_lang_attributes() { |
| 480 | - $lang = $GLOBALS['spip_lang']; |
|
| 481 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 480 | + $lang = $GLOBALS['spip_lang']; |
|
| 481 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 482 | 482 | |
| 483 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | 496 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 497 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 497 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,44 +69,44 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - $mot = null; |
|
| 73 | - $get = null; |
|
| 74 | - $hash = null; |
|
| 75 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | - return $lien; |
|
| 77 | - } |
|
| 78 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | - $r = array_pad($r, 3, ''); |
|
| 72 | + $mot = null; |
|
| 73 | + $get = null; |
|
| 74 | + $hash = null; |
|
| 75 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | + return $lien; |
|
| 77 | + } |
|
| 78 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | + $r = array_pad($r, 3, ''); |
|
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 82 | - } |
|
| 81 | + return $r[1] . resolve_path($r[2]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - # L'url site spip est un lien absolu aussi |
|
| 85 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | - return $lien; |
|
| 87 | - } |
|
| 84 | + # L'url site spip est un lien absolu aussi |
|
| 85 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | + return $lien; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - # lien relatif, il faut verifier l'url de base |
|
| 90 | - # commencer par virer la chaine de get de l'url de base |
|
| 91 | - $dir = '/'; |
|
| 92 | - $debut = ''; |
|
| 93 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | - $debut = $regs[1]; |
|
| 95 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | - $mot = $regs[3]; |
|
| 97 | - $get = $regs[4] ?? ''; |
|
| 98 | - $hash = $regs[5] ?? ''; |
|
| 99 | - } |
|
| 100 | - switch (substr($lien, 0, 1)) { |
|
| 101 | - case '/': |
|
| 102 | - return $debut . resolve_path($lien); |
|
| 103 | - case '#': |
|
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | - case '': |
|
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | - default: |
|
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 109 | - } |
|
| 89 | + # lien relatif, il faut verifier l'url de base |
|
| 90 | + # commencer par virer la chaine de get de l'url de base |
|
| 91 | + $dir = '/'; |
|
| 92 | + $debut = ''; |
|
| 93 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | + $debut = $regs[1]; |
|
| 95 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | + $mot = $regs[3]; |
|
| 97 | + $get = $regs[4] ?? ''; |
|
| 98 | + $hash = $regs[5] ?? ''; |
|
| 99 | + } |
|
| 100 | + switch (substr($lien, 0, 1)) { |
|
| 101 | + case '/': |
|
| 102 | + return $debut . resolve_path($lien); |
|
| 103 | + case '#': |
|
| 104 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | + case '': |
|
| 106 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | + default: |
|
| 108 | + return $debut . resolve_path($dir . $lien); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | * @return string texte ou URL (en absolus) |
| 130 | 130 | **/ |
| 131 | 131 | function url_absolue($url, $base = '') { |
| 132 | - $url = trim((string) $url); |
|
| 133 | - if (strlen($url = trim($url)) == 0) { |
|
| 134 | - return ''; |
|
| 135 | - } |
|
| 136 | - if (!$base) { |
|
| 137 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | - } |
|
| 132 | + $url = trim((string) $url); |
|
| 133 | + if (strlen($url = trim($url)) == 0) { |
|
| 134 | + return ''; |
|
| 135 | + } |
|
| 136 | + if (!$base) { |
|
| 137 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return suivre_lien($base, $url); |
|
| 140 | + return suivre_lien($base, $url); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | 150 | function protocole_implicite($url_absolue) { |
| 151 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 151 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 161 | 161 | |
| 162 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | - $protocole = $m[1]; |
|
| 164 | - if ( |
|
| 165 | - in_array($protocole, $protocoles_autorises) |
|
| 166 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | - ) { |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - return false; |
|
| 162 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | + $protocole = $m[1]; |
|
| 164 | + if ( |
|
| 165 | + in_array($protocole, $protocoles_autorises) |
|
| 166 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | + ) { |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + return false; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -185,27 +185,27 @@ discard block |
||
| 185 | 185 | * @return string texte avec des URLs absolues |
| 186 | 186 | **/ |
| 187 | 187 | function liens_absolus($texte, $base = '') { |
| 188 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | - if (!function_exists('extraire_attribut')) { |
|
| 190 | - include_spip('inc/filtres'); |
|
| 191 | - } |
|
| 192 | - foreach ($liens as $lien) { |
|
| 193 | - foreach (['href', 'src'] as $attr) { |
|
| 194 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | - if (strlen($href) > 0) { |
|
| 196 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 188 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | + if (!function_exists('extraire_attribut')) { |
|
| 190 | + include_spip('inc/filtres'); |
|
| 191 | + } |
|
| 192 | + foreach ($liens as $lien) { |
|
| 193 | + foreach (['href', 'src'] as $attr) { |
|
| 194 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | + if (strlen($href) > 0) { |
|
| 196 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $texte; |
|
| 208 | + return $texte; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @return string texte ou URL (en absolus) |
| 222 | 222 | **/ |
| 223 | 223 | function abs_url($texte, $base = '') { |
| 224 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | - return url_absolue($texte, $base); |
|
| 226 | - } else { |
|
| 227 | - return liens_absolus($texte, $base); |
|
| 228 | - } |
|
| 224 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | + return url_absolue($texte, $base); |
|
| 226 | + } else { |
|
| 227 | + return liens_absolus($texte, $base); |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 241 | - if (is_null($flags)) { |
|
| 242 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | - } |
|
| 241 | + if (is_null($flags)) { |
|
| 242 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 245 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 258 | - if (is_null($flags)) { |
|
| 259 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | - } |
|
| 258 | + if (is_null($flags)) { |
|
| 259 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 262 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 263 | 263 | } |