Completed
Push — master ( f9873c...efe545 )
by cam
01:01
created
ecrire/inc/envoyer_mail.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Mail
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function nettoyer_titre_email($titre) {
35
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
36 36
 }
37 37
 
38 38
 /**
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function nettoyer_caracteres_mail($t) {
50 50
 
51
-	$t = filtrer_entites($t);
51
+    $t = filtrer_entites($t);
52 52
 
53
-	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
-		$t = str_replace(
55
-			['&#8217;', '&#8220;', '&#8221;'],
56
-			["'", '"', '"'],
57
-			$t
58
-		);
59
-	}
53
+    if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
+        $t = str_replace(
55
+            ['&#8217;', '&#8220;', '&#8221;'],
56
+            ["'", '"', '"'],
57
+            $t
58
+        );
59
+    }
60 60
 
61
-	$t = str_replace(
62
-		['&mdash;', '&endash;'],
63
-		['--', '-'],
64
-		$t
65
-	);
61
+    $t = str_replace(
62
+        ['&mdash;', '&endash;'],
63
+        ['--', '-'],
64
+        $t
65
+    );
66 66
 
67
-	return $t;
67
+    return $t;
68 68
 }
69 69
 
70 70
 /**
@@ -97,87 +97,87 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
99 99
 
100
-	if (!email_valide($destinataire)) {
101
-		return false;
102
-	}
103
-	if ($destinataire == _T('info_mail_fournisseur')) {
104
-		return false;
105
-	} // tres fort
106
-
107
-	// Fournir si possible un Message-Id: conforme au RFC1036,
108
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
-
110
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
111
-	if (!email_valide($email_envoi)) {
112
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
-		$email_envoi = $destinataire;
114
-	}
115
-
116
-	$parts = '';
117
-	if (is_array($corps)) {
118
-		$texte = $corps['texte'];
119
-		$from = ($corps['from'] ?? $from);
120
-		$headers = ($corps['headers'] ?? $headers);
121
-		if (is_array($headers)) {
122
-			$headers = implode("\n", $headers);
123
-		}
124
-		if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) {
125
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
-		}
127
-	} else {
128
-		$texte = $corps;
129
-	}
130
-
131
-	if (!$from) {
132
-		$from = $email_envoi;
133
-	}
134
-
135
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
-	}
139
-
140
-	// nettoyer les &eacute; &#8217, &emdash; etc...
141
-	// les 'cliquer ici' etc sont a eviter;  voir:
142
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
-	$texte = nettoyer_caracteres_mail($texte);
144
-	$sujet = nettoyer_caracteres_mail($sujet);
145
-
146
-	// encoder le sujet si possible selon la RFC
147
-	if (init_mb_string()) {
148
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
-		$charset = $GLOBALS['meta']['charset'];
151
-		mb_internal_encoding($charset);
152
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
-		mb_internal_encoding('utf-8');
154
-	}
155
-
156
-	$headers = $headers ?? '';
157
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
158
-		$texte = wordwrap($texte);
159
-	}
160
-
161
-	[$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
162
-
163
-	if (_OS_SERVEUR == 'windows') {
164
-		$texte = preg_replace("@\r*\n@", "\r\n", $texte);
165
-		$headers = preg_replace("@\r*\n@", "\r\n", $headers);
166
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
167
-	}
168
-
169
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
170
-	// mode TEST : forcer l'email
171
-	if (defined('_TEST_EMAIL_DEST')) {
172
-		if (!_TEST_EMAIL_DEST) {
173
-			return false;
174
-		} else {
175
-			$texte = "Dest : $destinataire\r\n" . $texte;
176
-			$destinataire = _TEST_EMAIL_DEST;
177
-		}
178
-	}
179
-
180
-	return @mail($destinataire, $sujet, $texte, $headers);
100
+    if (!email_valide($destinataire)) {
101
+        return false;
102
+    }
103
+    if ($destinataire == _T('info_mail_fournisseur')) {
104
+        return false;
105
+    } // tres fort
106
+
107
+    // Fournir si possible un Message-Id: conforme au RFC1036,
108
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
+
110
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
111
+    if (!email_valide($email_envoi)) {
112
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
+        $email_envoi = $destinataire;
114
+    }
115
+
116
+    $parts = '';
117
+    if (is_array($corps)) {
118
+        $texte = $corps['texte'];
119
+        $from = ($corps['from'] ?? $from);
120
+        $headers = ($corps['headers'] ?? $headers);
121
+        if (is_array($headers)) {
122
+            $headers = implode("\n", $headers);
123
+        }
124
+        if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) {
125
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
+        }
127
+    } else {
128
+        $texte = $corps;
129
+    }
130
+
131
+    if (!$from) {
132
+        $from = $email_envoi;
133
+    }
134
+
135
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
+    }
139
+
140
+    // nettoyer les &eacute; &#8217, &emdash; etc...
141
+    // les 'cliquer ici' etc sont a eviter;  voir:
142
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
+    $texte = nettoyer_caracteres_mail($texte);
144
+    $sujet = nettoyer_caracteres_mail($sujet);
145
+
146
+    // encoder le sujet si possible selon la RFC
147
+    if (init_mb_string()) {
148
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
+        $charset = $GLOBALS['meta']['charset'];
151
+        mb_internal_encoding($charset);
152
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
+        mb_internal_encoding('utf-8');
154
+    }
155
+
156
+    $headers = $headers ?? '';
157
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
158
+        $texte = wordwrap($texte);
159
+    }
160
+
161
+    [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
162
+
163
+    if (_OS_SERVEUR == 'windows') {
164
+        $texte = preg_replace("@\r*\n@", "\r\n", $texte);
165
+        $headers = preg_replace("@\r*\n@", "\r\n", $headers);
166
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
167
+    }
168
+
169
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
170
+    // mode TEST : forcer l'email
171
+    if (defined('_TEST_EMAIL_DEST')) {
172
+        if (!_TEST_EMAIL_DEST) {
173
+            return false;
174
+        } else {
175
+            $texte = "Dest : $destinataire\r\n" . $texte;
176
+            $destinataire = _TEST_EMAIL_DEST;
177
+        }
178
+    }
179
+
180
+    return @mail($destinataire, $sujet, $texte, $headers);
181 181
 }
182 182
 
183 183
 /**
@@ -191,58 +191,58 @@  discard block
 block discarded – undo
191 191
  * @return array
192 192
  */
193 193
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
194
-	$charset = $GLOBALS['meta']['charset'];
195
-
196
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
197
-	if (strpos($headers, 'Content-Type: ') === false) {
198
-		$type =
199
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
200
-			"Content-Transfer-Encoding: 8bit\n";
201
-	} else {
202
-		$type = '';
203
-	}
204
-
205
-	// calculer un identifiant unique
206
-	// Marie Toto <[email protected]> => @toto.com
207
-	if (preg_match('/@[^\s>]+/', $from, $domain)) {
208
-		$domain = $domain[0];
209
-	}
210
-	else {
211
-		$domain = '@unknown-' . md5($from) . '.org';
212
-	}
213
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
214
-
215
-	// Si multi-part, s'en servir comme borne ...
216
-	if ($parts) {
217
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
218
-		foreach ($parts as $part) {
219
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
220
-			$e = join("\n", $part[0]);
221
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
222
-		}
223
-		$texte .= "\n\n--$uniq--\n";
224
-		// Si boundary n'est pas entre guillemets,
225
-		// elle est comprise mais le charset est ignoree !
226
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
227
-	}
228
-
229
-	// .. et s'en servir pour plaire a SpamAssassin
230
-
231
-	$mid = 'Message-Id: <' . $uniq . '>';
232
-
233
-	// indispensable pour les sites qui collent d'office From: serveur-http
234
-	// sauf si deja mis par l'envoyeur
235
-	$rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
236
-
237
-	// Nettoyer les en-tetes envoyees
238
-	// Ajouter le \n final
239
-	if (strlen($headers = trim($headers))) {
240
-		$headers .= "\n";
241
-	}
242
-
243
-	// Et mentionner l'indeboulonable nomenclature ratee
244
-
245
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
246
-
247
-	return [$headers, $texte];
194
+    $charset = $GLOBALS['meta']['charset'];
195
+
196
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
197
+    if (strpos($headers, 'Content-Type: ') === false) {
198
+        $type =
199
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
200
+            "Content-Transfer-Encoding: 8bit\n";
201
+    } else {
202
+        $type = '';
203
+    }
204
+
205
+    // calculer un identifiant unique
206
+    // Marie Toto <[email protected]> => @toto.com
207
+    if (preg_match('/@[^\s>]+/', $from, $domain)) {
208
+        $domain = $domain[0];
209
+    }
210
+    else {
211
+        $domain = '@unknown-' . md5($from) . '.org';
212
+    }
213
+    $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
214
+
215
+    // Si multi-part, s'en servir comme borne ...
216
+    if ($parts) {
217
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
218
+        foreach ($parts as $part) {
219
+            $n = strlen($part[1]) . ($part[0] ? "\n" : '');
220
+            $e = join("\n", $part[0]);
221
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
222
+        }
223
+        $texte .= "\n\n--$uniq--\n";
224
+        // Si boundary n'est pas entre guillemets,
225
+        // elle est comprise mais le charset est ignoree !
226
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
227
+    }
228
+
229
+    // .. et s'en servir pour plaire a SpamAssassin
230
+
231
+    $mid = 'Message-Id: <' . $uniq . '>';
232
+
233
+    // indispensable pour les sites qui collent d'office From: serveur-http
234
+    // sauf si deja mis par l'envoyeur
235
+    $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
236
+
237
+    // Nettoyer les en-tetes envoyees
238
+    // Ajouter le \n final
239
+    if (strlen($headers = trim($headers))) {
240
+        $headers .= "\n";
241
+    }
242
+
243
+    // Et mentionner l'indeboulonable nomenclature ratee
244
+
245
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
246
+
247
+    return [$headers, $texte];
248 248
 }
Please login to merge, or discard this patch.
ecrire/action/inscrire_auteur.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 
23 23
 if (!defined('_ECRIRE_INC_VERSION')) {
24
-	return;
24
+    return;
25 25
 }
26 26
 
27 27
 
@@ -44,70 +44,70 @@  discard block
 block discarded – undo
44 44
  * @return array|string
45 45
  */
46 46
 function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = []) {
47
-	if (!is_array($options)) {
48
-		$options = ['id' => $options];
49
-	}
50
-
51
-	if (function_exists('test_inscription')) {
52
-		$f = 'test_inscription';
53
-	} else {
54
-		$f = 'test_inscription_dist';
55
-	}
56
-	$desc = $f($statut, $mail_complet, $nom, $options);
57
-
58
-	// erreur ?
59
-	if (!is_array($desc)) {
60
-		return _T($desc);
61
-	}
62
-
63
-	include_spip('base/abstract_sql');
64
-	$res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email']));
65
-	// erreur ?
66
-	if (!$res) {
67
-		return _T('titre_probleme_technique');
68
-	}
69
-
70
-	$row = sql_fetch($res);
71
-	sql_free($res);
72
-	if ($row) {
73
-		if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) {
74
-			$desc['id_auteur'] = $row['id_auteur'];
75
-			$desc = inscription_nouveau($desc);
76
-		} else {
77
-			$desc = $row;
78
-		}
79
-	} else // s'il n'existe pas deja, creer les identifiants
80
-	{
81
-		$desc = inscription_nouveau($desc);
82
-	}
83
-
84
-	// erreur ?
85
-	if (!is_array($desc)) {
86
-		return $desc;
87
-	}
88
-
89
-
90
-	// generer le mot de passe (ou le refaire si compte inutilise)
91
-	$desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']);
92
-
93
-	// attribuer un jeton pour confirmation par clic sur un lien
94
-	$desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']);
95
-
96
-	// charger de suite cette fonction, pour ses utilitaires
97
-	$envoyer_inscription = charger_fonction('envoyer_inscription', '');
98
-	[$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options);
99
-
100
-	$notifications = charger_fonction('notifications', 'inc');
101
-	notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head);
102
-
103
-	// Notifications
104
-	$notifications(
105
-		'inscription',
106
-		$desc['id_auteur'],
107
-		['nom' => $desc['nom'], 'email' => $desc['email']]
108
-	);
109
-
110
-	return $desc;
47
+    if (!is_array($options)) {
48
+        $options = ['id' => $options];
49
+    }
50
+
51
+    if (function_exists('test_inscription')) {
52
+        $f = 'test_inscription';
53
+    } else {
54
+        $f = 'test_inscription_dist';
55
+    }
56
+    $desc = $f($statut, $mail_complet, $nom, $options);
57
+
58
+    // erreur ?
59
+    if (!is_array($desc)) {
60
+        return _T($desc);
61
+    }
62
+
63
+    include_spip('base/abstract_sql');
64
+    $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email']));
65
+    // erreur ?
66
+    if (!$res) {
67
+        return _T('titre_probleme_technique');
68
+    }
69
+
70
+    $row = sql_fetch($res);
71
+    sql_free($res);
72
+    if ($row) {
73
+        if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) {
74
+            $desc['id_auteur'] = $row['id_auteur'];
75
+            $desc = inscription_nouveau($desc);
76
+        } else {
77
+            $desc = $row;
78
+        }
79
+    } else // s'il n'existe pas deja, creer les identifiants
80
+    {
81
+        $desc = inscription_nouveau($desc);
82
+    }
83
+
84
+    // erreur ?
85
+    if (!is_array($desc)) {
86
+        return $desc;
87
+    }
88
+
89
+
90
+    // generer le mot de passe (ou le refaire si compte inutilise)
91
+    $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']);
92
+
93
+    // attribuer un jeton pour confirmation par clic sur un lien
94
+    $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']);
95
+
96
+    // charger de suite cette fonction, pour ses utilitaires
97
+    $envoyer_inscription = charger_fonction('envoyer_inscription', '');
98
+    [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options);
99
+
100
+    $notifications = charger_fonction('notifications', 'inc');
101
+    notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head);
102
+
103
+    // Notifications
104
+    $notifications(
105
+        'inscription',
106
+        $desc['id_auteur'],
107
+        ['nom' => $desc['nom'], 'email' => $desc['email']]
108
+    );
109
+
110
+    return $desc;
111 111
 }
112 112
 
113 113
 
@@ -130,23 +130,23 @@  discard block
 block discarded – undo
130 130
  *
131 131
  */
132 132
 function test_inscription_dist($statut, $mail, $nom, $options) {
133
-	include_spip('inc/filtres');
134
-	if (!$r = email_valide($mail)) {
135
-		return 'info_email_invalide';
136
-	}
137
-	$nom = trim(corriger_caracteres($nom));
138
-	$res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut];
139
-	if (isset($options['login'])) {
140
-		$login = trim(corriger_caracteres($options['login']));
141
-		if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) {
142
-			$res['login'] = $login;
143
-		}
144
-	}
145
-	if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) {
146
-		return 'ecrire:info_login_trop_court';
147
-	}
148
-
149
-	return $res;
133
+    include_spip('inc/filtres');
134
+    if (!$r = email_valide($mail)) {
135
+        return 'info_email_invalide';
136
+    }
137
+    $nom = trim(corriger_caracteres($nom));
138
+    $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut];
139
+    if (isset($options['login'])) {
140
+        $login = trim(corriger_caracteres($options['login']));
141
+        if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) {
142
+            $res['login'] = $login;
143
+        }
144
+    }
145
+    if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) {
146
+        return 'ecrire:info_login_trop_court';
147
+    }
148
+
149
+    return $res;
150 150
 }
151 151
 
152 152
 
@@ -159,33 +159,33 @@  discard block
 block discarded – undo
159 159
  * @return mixed|string
160 160
  */
161 161
 function inscription_nouveau($desc) {
162
-	if (!isset($desc['login']) or !strlen($desc['login'])) {
163
-		$desc['login'] = test_login($desc['nom'], $desc['email']);
164
-	}
162
+    if (!isset($desc['login']) or !strlen($desc['login'])) {
163
+        $desc['login'] = test_login($desc['nom'], $desc['email']);
164
+    }
165 165
 
166
-	$desc['statut'] = 'nouveau';
167
-	include_spip('action/editer_auteur');
168
-	if (isset($desc['id_auteur'])) {
169
-		$id_auteur = $desc['id_auteur'];
170
-	} else {
171
-		$id_auteur = auteur_inserer();
172
-	}
166
+    $desc['statut'] = 'nouveau';
167
+    include_spip('action/editer_auteur');
168
+    if (isset($desc['id_auteur'])) {
169
+        $id_auteur = $desc['id_auteur'];
170
+    } else {
171
+        $id_auteur = auteur_inserer();
172
+    }
173 173
 
174
-	if (!$id_auteur) {
175
-		return _T('titre_probleme_technique');
176
-	}
174
+    if (!$id_auteur) {
175
+        return _T('titre_probleme_technique');
176
+    }
177 177
 
178
-	$desc['lang'] = $GLOBALS['spip_lang'];
178
+    $desc['lang'] = $GLOBALS['spip_lang'];
179 179
 
180
-	include_spip('inc/autoriser');
181
-	// lever l'autorisation pour pouvoir modifier le statut
182
-	autoriser_exception('modifier', 'auteur', $id_auteur);
183
-	auteur_modifier($id_auteur, $desc);
184
-	autoriser_exception('modifier', 'auteur', $id_auteur, false);
180
+    include_spip('inc/autoriser');
181
+    // lever l'autorisation pour pouvoir modifier le statut
182
+    autoriser_exception('modifier', 'auteur', $id_auteur);
183
+    auteur_modifier($id_auteur, $desc);
184
+    autoriser_exception('modifier', 'auteur', $id_auteur, false);
185 185
 
186
-	$desc['id_auteur'] = $id_auteur;
186
+    $desc['id_auteur'] = $id_auteur;
187 187
 
188
-	return $desc;
188
+    return $desc;
189 189
 }
190 190
 
191 191
 
@@ -202,27 +202,27 @@  discard block
 block discarded – undo
202 202
  * @return string
203 203
  */
204 204
 function test_login($nom, $mail) {
205
-	include_spip('inc/charsets');
206
-	$nom = strtolower(translitteration($nom));
207
-	$login_base = preg_replace('/[^\w\d_]/', '_', $nom);
208
-
209
-	// il faut eviter que le login soit vraiment trop court
210
-	if (strlen($login_base) < 3) {
211
-		$mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail)));
212
-		$login_base = preg_replace('/[^\w\d]/', '_', $mail);
213
-	}
214
-	if (strlen($login_base) < 3) {
215
-		$login_base = 'user';
216
-	}
217
-
218
-	$login = $login_base;
219
-
220
-	for ($i = 1;; $i++) {
221
-		if (!sql_countsel('spip_auteurs', "login='$login'")) {
222
-			return $login;
223
-		}
224
-		$login = $login_base . $i;
225
-	}
205
+    include_spip('inc/charsets');
206
+    $nom = strtolower(translitteration($nom));
207
+    $login_base = preg_replace('/[^\w\d_]/', '_', $nom);
208
+
209
+    // il faut eviter que le login soit vraiment trop court
210
+    if (strlen($login_base) < 3) {
211
+        $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail)));
212
+        $login_base = preg_replace('/[^\w\d]/', '_', $mail);
213
+    }
214
+    if (strlen($login_base) < 3) {
215
+        $login_base = 'user';
216
+    }
217
+
218
+    $login = $login_base;
219
+
220
+    for ($i = 1;; $i++) {
221
+        if (!sql_countsel('spip_auteurs', "login='$login'")) {
222
+            return $login;
223
+        }
224
+        $login = $login_base . $i;
225
+    }
226 226
 }
227 227
 
228 228
 
@@ -240,26 +240,26 @@  discard block
 block discarded – undo
240 240
  */
241 241
 function envoyer_inscription_dist($desc, $nom, $mode, $options = []) {
242 242
 
243
-	$contexte = array_merge($desc, $options);
244
-	$contexte['nom'] = $nom;
245
-	$contexte['mode'] = $mode;
246
-	$contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true);
247
-	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']);
248
-	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
249
-	// S'il y a l'option redirect, on l'ajoute directement ici
250
-	if (isset($options['redirect'])) {
251
-		$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']);
252
-	}
253
-
254
-	$modele_mail = 'modeles/mail_inscription';
255
-	if (isset($options['modele_mail']) and $options['modele_mail']) {
256
-		$modele_mail = $options['modele_mail'];
257
-	}
258
-	$message = recuperer_fond($modele_mail, $contexte);
259
-	$from = ($options['from'] ?? '');
260
-	$head = '';
261
-
262
-	return ['', $message, $from, $head];
243
+    $contexte = array_merge($desc, $options);
244
+    $contexte['nom'] = $nom;
245
+    $contexte['mode'] = $mode;
246
+    $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true);
247
+    $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']);
248
+    $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
249
+    // S'il y a l'option redirect, on l'ajoute directement ici
250
+    if (isset($options['redirect'])) {
251
+        $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']);
252
+    }
253
+
254
+    $modele_mail = 'modeles/mail_inscription';
255
+    if (isset($options['modele_mail']) and $options['modele_mail']) {
256
+        $modele_mail = $options['modele_mail'];
257
+    }
258
+    $message = recuperer_fond($modele_mail, $contexte);
259
+    $from = ($options['from'] ?? '');
260
+    $head = '';
261
+
262
+    return ['', $message, $from, $head];
263 263
 }
264 264
 
265 265
 
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
  * @return string
271 271
  */
272 272
 function creer_pass_pour_auteur($id_auteur) {
273
-	include_spip('inc/acces');
274
-	$pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur);
275
-	include_spip('action/editer_auteur');
276
-	auteur_instituer($id_auteur, ['pass' => $pass]);
273
+    include_spip('inc/acces');
274
+    $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur);
275
+    include_spip('action/editer_auteur');
276
+    auteur_instituer($id_auteur, ['pass' => $pass]);
277 277
 
278
-	return $pass;
278
+    return $pass;
279 279
 }
280 280
 
281 281
 /**
@@ -288,17 +288,17 @@  discard block
 block discarded – undo
288 288
  * @return string
289 289
  */
290 290
 function tester_statut_inscription($statut_tmp, $id) {
291
-	include_spip('inc/autoriser');
292
-	if ($statut_tmp) {
293
-		return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
294
-	} elseif (
295
-		autoriser('inscrireauteur', $statut_tmp = '1comite', $id)
296
-		or autoriser('inscrireauteur', $statut_tmp = '6forum', $id)
297
-	) {
298
-		return $statut_tmp;
299
-	}
300
-
301
-	return '';
291
+    include_spip('inc/autoriser');
292
+    if ($statut_tmp) {
293
+        return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
294
+    } elseif (
295
+        autoriser('inscrireauteur', $statut_tmp = '1comite', $id)
296
+        or autoriser('inscrireauteur', $statut_tmp = '6forum', $id)
297
+    ) {
298
+        return $statut_tmp;
299
+    }
300
+
301
+    return '';
302 302
 }
303 303
 
304 304
 
@@ -312,35 +312,35 @@  discard block
 block discarded – undo
312 312
  * @return array
313 313
  */
314 314
 function confirmer_statut_inscription($auteur) {
315
-	// securite
316
-	if ($auteur['statut'] != 'nouveau') {
317
-		return $auteur;
318
-	}
319
-
320
-	$s = $auteur['prefs'];
321
-	// securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize)
322
-	if (!preg_match(',^\w+$,', $s)) {
323
-		$s = '6forum';
324
-	}
325
-	include_spip('inc/autoriser');
326
-	if (!autoriser('inscrireauteur', $s)) {
327
-		return $auteur;
328
-	}
329
-
330
-	include_spip('inc/autoriser');
331
-	// accorder l'autorisation de modif du statut auteur
332
-	autoriser_exception('modifier', 'auteur', $auteur['id_auteur']);
333
-	include_spip('action/editer_auteur');
334
-	// changer le statut
335
-	auteur_modifier($auteur['id_auteur'], ['statut' => $s]);
336
-	unset($_COOKIE['spip_session']); // forcer la maj de la session
337
-	// lever l'autorisation de modif du statut auteur
338
-	autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false);
339
-
340
-	// mettre a jour le statut
341
-	$auteur['statut'] = $s;
342
-
343
-	return $auteur;
315
+    // securite
316
+    if ($auteur['statut'] != 'nouveau') {
317
+        return $auteur;
318
+    }
319
+
320
+    $s = $auteur['prefs'];
321
+    // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize)
322
+    if (!preg_match(',^\w+$,', $s)) {
323
+        $s = '6forum';
324
+    }
325
+    include_spip('inc/autoriser');
326
+    if (!autoriser('inscrireauteur', $s)) {
327
+        return $auteur;
328
+    }
329
+
330
+    include_spip('inc/autoriser');
331
+    // accorder l'autorisation de modif du statut auteur
332
+    autoriser_exception('modifier', 'auteur', $auteur['id_auteur']);
333
+    include_spip('action/editer_auteur');
334
+    // changer le statut
335
+    auteur_modifier($auteur['id_auteur'], ['statut' => $s]);
336
+    unset($_COOKIE['spip_session']); // forcer la maj de la session
337
+    // lever l'autorisation de modif du statut auteur
338
+    autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false);
339
+
340
+    // mettre a jour le statut
341
+    $auteur['statut'] = $s;
342
+
343
+    return $auteur;
344 344
 }
345 345
 
346 346
 
@@ -354,20 +354,20 @@  discard block
 block discarded – undo
354 354
  * @return string
355 355
  */
356 356
 function auteur_attribuer_jeton($id_auteur): string {
357
-	include_spip('base/abstract_sql');
358
-	include_spip('inc/acces');
359
-	include_spip('inc/chiffrer');
360
-	// s'assurer de l'unicite du jeton pour le couple (email,cookie)
361
-	do {
362
-		// Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer
363
-		// tous les jetons connus pour vérifier le jeton d’un auteur.
364
-		$public = substr(creer_uniqid(), 0, 7) . '.';
365
-		$jeton = $public . creer_uniqid();
366
-		$jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site());
367
-		sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur));
368
-	} while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1);
369
-
370
-	return $jeton;
357
+    include_spip('base/abstract_sql');
358
+    include_spip('inc/acces');
359
+    include_spip('inc/chiffrer');
360
+    // s'assurer de l'unicite du jeton pour le couple (email,cookie)
361
+    do {
362
+        // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer
363
+        // tous les jetons connus pour vérifier le jeton d’un auteur.
364
+        $public = substr(creer_uniqid(), 0, 7) . '.';
365
+        $jeton = $public . creer_uniqid();
366
+        $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site());
367
+        sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . intval($id_auteur));
368
+    } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1);
369
+
370
+    return $jeton;
371 371
 }
372 372
 
373 373
 /**
@@ -381,20 +381,20 @@  discard block
 block discarded – undo
381 381
  * @return string|null
382 382
  */
383 383
 function auteur_lire_jeton(int $id_auteur, bool $autoInit = false): ?string {
384
-	include_spip('base/abstract_sql');
385
-	$jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur);
386
-	if ($jeton_chiffre_prefixe) {
387
-		include_spip('inc/chiffrer');
388
-		$jeton_chiffre = substr($jeton_chiffre_prefixe, 8);
389
-		$jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
390
-		if ($jeton) {
391
-			return $jeton;
392
-		}
393
-	}
394
-	if ($autoInit) {
395
-		return auteur_attribuer_jeton($id_auteur);
396
-	}
397
-	return null;
384
+    include_spip('base/abstract_sql');
385
+    $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur);
386
+    if ($jeton_chiffre_prefixe) {
387
+        include_spip('inc/chiffrer');
388
+        $jeton_chiffre = substr($jeton_chiffre_prefixe, 8);
389
+        $jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
390
+        if ($jeton) {
391
+            return $jeton;
392
+        }
393
+    }
394
+    if ($autoInit) {
395
+        return auteur_attribuer_jeton($id_auteur);
396
+    }
397
+    return null;
398 398
 }
399 399
 
400 400
 /**
@@ -404,25 +404,25 @@  discard block
 block discarded – undo
404 404
  * @return array|bool
405 405
  */
406 406
 function auteur_verifier_jeton($jeton) {
407
-	// refuser un jeton corrompu
408
-	if (preg_match(',[^0-9a-f.],i', $jeton)) {
409
-		return false;
410
-	}
411
-
412
-	include_spip('base/abstract_sql');
413
-	include_spip('inc/chiffrer');
414
-	$public = substr($jeton, 0, 8);
415
-
416
-	// Les auteurs qui ont un jetons ressemblant
417
-	$auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%'));
418
-	foreach ($auteurs as $auteur) {
419
-		$jeton_chiffre = substr($auteur['cookie_oubli'], 8);
420
-		$_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
421
-		if ($_jeton and hash_equals($jeton, $_jeton)) {
422
-			return $auteur;
423
-		}
424
-	}
425
-	return false;
407
+    // refuser un jeton corrompu
408
+    if (preg_match(',[^0-9a-f.],i', $jeton)) {
409
+        return false;
410
+    }
411
+
412
+    include_spip('base/abstract_sql');
413
+    include_spip('inc/chiffrer');
414
+    $public = substr($jeton, 0, 8);
415
+
416
+    // Les auteurs qui ont un jetons ressemblant
417
+    $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%'));
418
+    foreach ($auteurs as $auteur) {
419
+        $jeton_chiffre = substr($auteur['cookie_oubli'], 8);
420
+        $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
421
+        if ($_jeton and hash_equals($jeton, $_jeton)) {
422
+            return $auteur;
423
+        }
424
+    }
425
+    return false;
426 426
 }
427 427
 
428 428
 /**
@@ -432,6 +432,6 @@  discard block
 block discarded – undo
432 432
  * @return bool
433 433
  */
434 434
 function auteur_effacer_jeton($id_auteur) {
435
-	include_spip('base/abstract_sql');
436
-	return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur));
435
+    include_spip('base/abstract_sql');
436
+    return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur));
437 437
 }
Please login to merge, or discard this patch.