Completed
Push — master ( 62aed1...8add54 )
by cam
01:34
created
ecrire/action/inscrire_auteur.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 
@@ -43,68 +43,68 @@  discard block
 block discarded – undo
43 43
  * @return array|string
44 44
  */
45 45
 function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = []) {
46
-	if (!is_array($options)) {
47
-		$options = ['id' => $options];
48
-	}
49
-
50
-	$f = function_exists('test_inscription')
51
-		? 'test_inscription'
52
-		: 'test_inscription_dist';
53
-	$desc = $f($statut, $mail_complet, $nom, $options);
54
-
55
-	// erreur ?
56
-	if (!is_array($desc)) {
57
-		return _T($desc);
58
-	}
59
-
60
-	include_spip('base/abstract_sql');
61
-	$res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email']));
62
-	// erreur ?
63
-	if (!$res) {
64
-		return _T('titre_probleme_technique');
65
-	}
66
-
67
-	$row = sql_fetch($res);
68
-	sql_free($res);
69
-	if ($row) {
70
-		if (isset($options['force_nouveau']) && $options['force_nouveau'] == true) {
71
-			$desc['id_auteur'] = $row['id_auteur'];
72
-			$desc = inscription_nouveau($desc);
73
-		} else {
74
-			$desc = $row;
75
-		}
76
-	} else // s'il n'existe pas deja, creer les identifiants
77
-	{
78
-		$desc = inscription_nouveau($desc);
79
-	}
80
-
81
-	// erreur ?
82
-	if (!is_array($desc)) {
83
-		return $desc;
84
-	}
85
-
86
-
87
-	// generer le mot de passe (ou le refaire si compte inutilise)
88
-	$desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']);
89
-
90
-	// attribuer un jeton pour confirmation par clic sur un lien
91
-	$desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']);
92
-
93
-	// charger de suite cette fonction, pour ses utilitaires
94
-	$envoyer_inscription = charger_fonction('envoyer_inscription', '');
95
-	[$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options);
96
-
97
-	$notifications = charger_fonction('notifications', 'inc');
98
-	notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head);
99
-
100
-	// Notifications
101
-	$notifications(
102
-		'inscription',
103
-		$desc['id_auteur'],
104
-		['nom' => $desc['nom'], 'email' => $desc['email']]
105
-	);
106
-
107
-	return $desc;
46
+    if (!is_array($options)) {
47
+        $options = ['id' => $options];
48
+    }
49
+
50
+    $f = function_exists('test_inscription')
51
+        ? 'test_inscription'
52
+        : 'test_inscription_dist';
53
+    $desc = $f($statut, $mail_complet, $nom, $options);
54
+
55
+    // erreur ?
56
+    if (!is_array($desc)) {
57
+        return _T($desc);
58
+    }
59
+
60
+    include_spip('base/abstract_sql');
61
+    $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email']));
62
+    // erreur ?
63
+    if (!$res) {
64
+        return _T('titre_probleme_technique');
65
+    }
66
+
67
+    $row = sql_fetch($res);
68
+    sql_free($res);
69
+    if ($row) {
70
+        if (isset($options['force_nouveau']) && $options['force_nouveau'] == true) {
71
+            $desc['id_auteur'] = $row['id_auteur'];
72
+            $desc = inscription_nouveau($desc);
73
+        } else {
74
+            $desc = $row;
75
+        }
76
+    } else // s'il n'existe pas deja, creer les identifiants
77
+    {
78
+        $desc = inscription_nouveau($desc);
79
+    }
80
+
81
+    // erreur ?
82
+    if (!is_array($desc)) {
83
+        return $desc;
84
+    }
85
+
86
+
87
+    // generer le mot de passe (ou le refaire si compte inutilise)
88
+    $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']);
89
+
90
+    // attribuer un jeton pour confirmation par clic sur un lien
91
+    $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']);
92
+
93
+    // charger de suite cette fonction, pour ses utilitaires
94
+    $envoyer_inscription = charger_fonction('envoyer_inscription', '');
95
+    [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options);
96
+
97
+    $notifications = charger_fonction('notifications', 'inc');
98
+    notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head);
99
+
100
+    // Notifications
101
+    $notifications(
102
+        'inscription',
103
+        $desc['id_auteur'],
104
+        ['nom' => $desc['nom'], 'email' => $desc['email']]
105
+    );
106
+
107
+    return $desc;
108 108
 }
109 109
 
110 110
 
@@ -127,23 +127,23 @@  discard block
 block discarded – undo
127 127
  *
128 128
  */
129 129
 function test_inscription_dist($statut, $mail, $nom, $options) {
130
-	include_spip('inc/filtres');
131
-	if (!$r = email_valide($mail)) {
132
-		return 'info_email_invalide';
133
-	}
134
-	$nom = trim((string) corriger_caracteres($nom));
135
-	$res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut];
136
-	if (isset($options['login'])) {
137
-		$login = trim((string) corriger_caracteres($options['login']));
138
-		if (strlen($login) >= _LOGIN_TROP_COURT && strlen($nom) <= 64) {
139
-			$res['login'] = $login;
140
-		}
141
-	}
142
-	if (!isset($res['login']) && (strlen($nom) < _LOGIN_TROP_COURT || strlen($nom) > 64)) {
143
-		return 'ecrire:info_login_trop_court';
144
-	}
145
-
146
-	return $res;
130
+    include_spip('inc/filtres');
131
+    if (!$r = email_valide($mail)) {
132
+        return 'info_email_invalide';
133
+    }
134
+    $nom = trim((string) corriger_caracteres($nom));
135
+    $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut];
136
+    if (isset($options['login'])) {
137
+        $login = trim((string) corriger_caracteres($options['login']));
138
+        if (strlen($login) >= _LOGIN_TROP_COURT && strlen($nom) <= 64) {
139
+            $res['login'] = $login;
140
+        }
141
+    }
142
+    if (!isset($res['login']) && (strlen($nom) < _LOGIN_TROP_COURT || strlen($nom) > 64)) {
143
+        return 'ecrire:info_login_trop_court';
144
+    }
145
+
146
+    return $res;
147 147
 }
148 148
 
149 149
 
@@ -156,29 +156,29 @@  discard block
 block discarded – undo
156 156
  * @return mixed|string
157 157
  */
158 158
 function inscription_nouveau($desc) {
159
-	if (!isset($desc['login']) || !strlen((string) $desc['login'])) {
160
-		$desc['login'] = test_login($desc['nom'], $desc['email']);
161
-	}
159
+    if (!isset($desc['login']) || !strlen((string) $desc['login'])) {
160
+        $desc['login'] = test_login($desc['nom'], $desc['email']);
161
+    }
162 162
 
163
-	$desc['statut'] = 'nouveau';
164
-	include_spip('action/editer_auteur');
165
-	$id_auteur = $desc['id_auteur'] ?? auteur_inserer();
163
+    $desc['statut'] = 'nouveau';
164
+    include_spip('action/editer_auteur');
165
+    $id_auteur = $desc['id_auteur'] ?? auteur_inserer();
166 166
 
167
-	if (!$id_auteur) {
168
-		return _T('titre_probleme_technique');
169
-	}
167
+    if (!$id_auteur) {
168
+        return _T('titre_probleme_technique');
169
+    }
170 170
 
171
-	$desc['lang'] = $GLOBALS['spip_lang'];
171
+    $desc['lang'] = $GLOBALS['spip_lang'];
172 172
 
173
-	include_spip('inc/autoriser');
174
-	// lever l'autorisation pour pouvoir modifier le statut
175
-	autoriser_exception('modifier', 'auteur', $id_auteur);
176
-	auteur_modifier($id_auteur, $desc);
177
-	autoriser_exception('modifier', 'auteur', $id_auteur, false);
173
+    include_spip('inc/autoriser');
174
+    // lever l'autorisation pour pouvoir modifier le statut
175
+    autoriser_exception('modifier', 'auteur', $id_auteur);
176
+    auteur_modifier($id_auteur, $desc);
177
+    autoriser_exception('modifier', 'auteur', $id_auteur, false);
178 178
 
179
-	$desc['id_auteur'] = $id_auteur;
179
+    $desc['id_auteur'] = $id_auteur;
180 180
 
181
-	return $desc;
181
+    return $desc;
182 182
 }
183 183
 
184 184
 
@@ -194,27 +194,27 @@  discard block
 block discarded – undo
194 194
  * @param string $mail
195 195
  */
196 196
 function test_login($nom, $mail): string {
197
-	include_spip('inc/charsets');
198
-	$nom = strtolower((string) translitteration($nom));
199
-	$login_base = preg_replace('/[^\w]/', '_', $nom);
200
-
201
-	// il faut eviter que le login soit vraiment trop court
202
-	if (strlen($login_base) < 3) {
203
-		$mail = strtolower((string) translitteration(preg_replace('/@.*/', '', $mail)));
204
-		$login_base = preg_replace('/[^\w]/', '_', $mail);
205
-	}
206
-	if (strlen($login_base) < 3) {
207
-		$login_base = 'user';
208
-	}
209
-
210
-	$login = $login_base;
211
-
212
-	for ($i = 1;; $i++) {
213
-		if (!sql_countsel('spip_auteurs', "login='$login'")) {
214
-			return $login;
215
-		}
216
-		$login = $login_base . $i;
217
-	}
197
+    include_spip('inc/charsets');
198
+    $nom = strtolower((string) translitteration($nom));
199
+    $login_base = preg_replace('/[^\w]/', '_', $nom);
200
+
201
+    // il faut eviter que le login soit vraiment trop court
202
+    if (strlen($login_base) < 3) {
203
+        $mail = strtolower((string) translitteration(preg_replace('/@.*/', '', $mail)));
204
+        $login_base = preg_replace('/[^\w]/', '_', $mail);
205
+    }
206
+    if (strlen($login_base) < 3) {
207
+        $login_base = 'user';
208
+    }
209
+
210
+    $login = $login_base;
211
+
212
+    for ($i = 1;; $i++) {
213
+        if (!sql_countsel('spip_auteurs', "login='$login'")) {
214
+            return $login;
215
+        }
216
+        $login = $login_base . $i;
217
+    }
218 218
 }
219 219
 
220 220
 
@@ -232,26 +232,26 @@  discard block
 block discarded – undo
232 232
  */
233 233
 function envoyer_inscription_dist($desc, $nom, $mode, $options = []) {
234 234
 
235
-	$contexte = array_merge($desc, $options);
236
-	$contexte['nom'] = $nom;
237
-	$contexte['mode'] = $mode;
238
-	$contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true);
239
-	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']);
240
-	$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
241
-	// S'il y a l'option redirect, on l'ajoute directement ici
242
-	if (isset($options['redirect'])) {
243
-		$contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']);
244
-	}
245
-
246
-	$modele_mail = 'modeles/mail_inscription';
247
-	if (isset($options['modele_mail']) && $options['modele_mail']) {
248
-		$modele_mail = $options['modele_mail'];
249
-	}
250
-	$message = recuperer_fond($modele_mail, $contexte);
251
-	$from = ($options['from'] ?? '');
252
-	$head = '';
253
-
254
-	return ['', $message, $from, $head];
235
+    $contexte = array_merge($desc, $options);
236
+    $contexte['nom'] = $nom;
237
+    $contexte['mode'] = $mode;
238
+    $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true);
239
+    $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']);
240
+    $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']);
241
+    // S'il y a l'option redirect, on l'ajoute directement ici
242
+    if (isset($options['redirect'])) {
243
+        $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']);
244
+    }
245
+
246
+    $modele_mail = 'modeles/mail_inscription';
247
+    if (isset($options['modele_mail']) && $options['modele_mail']) {
248
+        $modele_mail = $options['modele_mail'];
249
+    }
250
+    $message = recuperer_fond($modele_mail, $contexte);
251
+    $from = ($options['from'] ?? '');
252
+    $head = '';
253
+
254
+    return ['', $message, $from, $head];
255 255
 }
256 256
 
257 257
 
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
  * @return string
263 263
  */
264 264
 function creer_pass_pour_auteur($id_auteur) {
265
-	include_spip('inc/acces');
266
-	$pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur);
267
-	include_spip('action/editer_auteur');
268
-	auteur_instituer($id_auteur, ['pass' => $pass]);
265
+    include_spip('inc/acces');
266
+    $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur);
267
+    include_spip('action/editer_auteur');
268
+    auteur_instituer($id_auteur, ['pass' => $pass]);
269 269
 
270
-	return $pass;
270
+    return $pass;
271 271
 }
272 272
 
273 273
 /**
@@ -280,17 +280,17 @@  discard block
 block discarded – undo
280 280
  * @return string
281 281
  */
282 282
 function tester_statut_inscription($statut_tmp, $id) {
283
-	include_spip('inc/autoriser');
284
-	if ($statut_tmp) {
285
-		return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
286
-	} elseif (
287
-		autoriser('inscrireauteur', $statut_tmp = '1comite', $id)
288
-		|| autoriser('inscrireauteur', $statut_tmp = '6forum', $id)
289
-	) {
290
-		return $statut_tmp;
291
-	}
292
-
293
-	return '';
283
+    include_spip('inc/autoriser');
284
+    if ($statut_tmp) {
285
+        return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : '';
286
+    } elseif (
287
+        autoriser('inscrireauteur', $statut_tmp = '1comite', $id)
288
+        || autoriser('inscrireauteur', $statut_tmp = '6forum', $id)
289
+    ) {
290
+        return $statut_tmp;
291
+    }
292
+
293
+    return '';
294 294
 }
295 295
 
296 296
 
@@ -304,35 +304,35 @@  discard block
 block discarded – undo
304 304
  * @return array
305 305
  */
306 306
 function confirmer_statut_inscription($auteur) {
307
-	// securite
308
-	if ($auteur['statut'] != 'nouveau') {
309
-		return $auteur;
310
-	}
311
-
312
-	$s = $auteur['prefs'];
313
-	// securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize)
314
-	if (!preg_match(',^\w+$,', (string) $s)) {
315
-		$s = '6forum';
316
-	}
317
-	include_spip('inc/autoriser');
318
-	if (!autoriser('inscrireauteur', $s)) {
319
-		return $auteur;
320
-	}
321
-
322
-	include_spip('inc/autoriser');
323
-	// accorder l'autorisation de modif du statut auteur
324
-	autoriser_exception('modifier', 'auteur', $auteur['id_auteur']);
325
-	include_spip('action/editer_auteur');
326
-	// changer le statut
327
-	auteur_modifier($auteur['id_auteur'], ['statut' => $s]);
328
-	unset($_COOKIE['spip_session']); // forcer la maj de la session
329
-	// lever l'autorisation de modif du statut auteur
330
-	autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false);
331
-
332
-	// mettre a jour le statut
333
-	$auteur['statut'] = $s;
334
-
335
-	return $auteur;
307
+    // securite
308
+    if ($auteur['statut'] != 'nouveau') {
309
+        return $auteur;
310
+    }
311
+
312
+    $s = $auteur['prefs'];
313
+    // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize)
314
+    if (!preg_match(',^\w+$,', (string) $s)) {
315
+        $s = '6forum';
316
+    }
317
+    include_spip('inc/autoriser');
318
+    if (!autoriser('inscrireauteur', $s)) {
319
+        return $auteur;
320
+    }
321
+
322
+    include_spip('inc/autoriser');
323
+    // accorder l'autorisation de modif du statut auteur
324
+    autoriser_exception('modifier', 'auteur', $auteur['id_auteur']);
325
+    include_spip('action/editer_auteur');
326
+    // changer le statut
327
+    auteur_modifier($auteur['id_auteur'], ['statut' => $s]);
328
+    unset($_COOKIE['spip_session']); // forcer la maj de la session
329
+    // lever l'autorisation de modif du statut auteur
330
+    autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false);
331
+
332
+    // mettre a jour le statut
333
+    $auteur['statut'] = $s;
334
+
335
+    return $auteur;
336 336
 }
337 337
 
338 338
 
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
  * @return string
347 347
  */
348 348
 function auteur_attribuer_jeton($id_auteur): string {
349
-	include_spip('base/abstract_sql');
350
-	include_spip('inc/acces');
351
-
352
-	// s'assurer de l'unicite du jeton pour le couple (email,cookie)
353
-	do {
354
-		// Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer
355
-		// tous les jetons connus pour vérifier le jeton d’un auteur.
356
-		$public = substr((string) creer_uniqid(), 0, 7) . '.';
357
-		$jeton = $public . creer_uniqid();
358
-		$jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site());
359
-		sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . (int) $id_auteur);
360
-	} while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1);
361
-
362
-	return $jeton;
349
+    include_spip('base/abstract_sql');
350
+    include_spip('inc/acces');
351
+
352
+    // s'assurer de l'unicite du jeton pour le couple (email,cookie)
353
+    do {
354
+        // Un morceau du jeton est lisible en bdd pour éviter de devoir déchiffrer
355
+        // tous les jetons connus pour vérifier le jeton d’un auteur.
356
+        $public = substr((string) creer_uniqid(), 0, 7) . '.';
357
+        $jeton = $public . creer_uniqid();
358
+        $jeton_chiffre_prefixe = $public . Chiffrement::chiffrer($jeton, SpipCles::secret_du_site());
359
+        sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton_chiffre_prefixe], 'id_auteur=' . (int) $id_auteur);
360
+    } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton_chiffre_prefixe, '', 'string')) > 1);
361
+
362
+    return $jeton;
363 363
 }
364 364
 
365 365
 /**
@@ -373,19 +373,19 @@  discard block
 block discarded – undo
373 373
  * @return string|null
374 374
  */
375 375
 function auteur_lire_jeton(int $id_auteur, bool $autoInit = false): ?string {
376
-	include_spip('base/abstract_sql');
377
-	$jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur);
378
-	if ($jeton_chiffre_prefixe) {
379
-		$jeton_chiffre = substr((string) $jeton_chiffre_prefixe, 8);
380
-		$jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
381
-		if ($jeton) {
382
-			return $jeton;
383
-		}
384
-	}
385
-	if ($autoInit) {
386
-		return auteur_attribuer_jeton($id_auteur);
387
-	}
388
-	return null;
376
+    include_spip('base/abstract_sql');
377
+    $jeton_chiffre_prefixe = sql_getfetsel('cookie_oubli', 'spip_auteurs', 'id_auteur=' . $id_auteur);
378
+    if ($jeton_chiffre_prefixe) {
379
+        $jeton_chiffre = substr((string) $jeton_chiffre_prefixe, 8);
380
+        $jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
381
+        if ($jeton) {
382
+            return $jeton;
383
+        }
384
+    }
385
+    if ($autoInit) {
386
+        return auteur_attribuer_jeton($id_auteur);
387
+    }
388
+    return null;
389 389
 }
390 390
 
391 391
 /**
@@ -395,29 +395,29 @@  discard block
 block discarded – undo
395 395
  * @return array|bool
396 396
  */
397 397
 function auteur_verifier_jeton($jeton) {
398
-	// refuser un jeton corrompu
399
-	if (preg_match(',[^0-9a-f.],i', $jeton)) {
400
-		return false;
401
-	}
402
-
403
-	include_spip('base/abstract_sql');
404
-	$public = substr($jeton, 0, 8);
405
-
406
-	// Les auteurs qui ont un jetons ressemblant
407
-	$auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%'));
408
-	foreach ($auteurs as $auteur) {
409
-		$jeton_chiffre = substr((string) $auteur['cookie_oubli'], 8);
410
-		try {
411
-			$_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
412
-		} catch (\Exception $e) {
413
-			spip_logger('chiffrer')->error('Échec du déchiffrage du jeton d’auteur: ' . $e->getMessage());
414
-			return false;
415
-		}
416
-		if ($_jeton && hash_equals($jeton, $_jeton)) {
417
-			return $auteur;
418
-		}
419
-	}
420
-	return false;
398
+    // refuser un jeton corrompu
399
+    if (preg_match(',[^0-9a-f.],i', $jeton)) {
400
+        return false;
401
+    }
402
+
403
+    include_spip('base/abstract_sql');
404
+    $public = substr($jeton, 0, 8);
405
+
406
+    // Les auteurs qui ont un jetons ressemblant
407
+    $auteurs = sql_allfetsel('*', 'spip_auteurs', 'cookie_oubli LIKE ' . sql_quote($public . '%'));
408
+    foreach ($auteurs as $auteur) {
409
+        $jeton_chiffre = substr((string) $auteur['cookie_oubli'], 8);
410
+        try {
411
+            $_jeton = Chiffrement::dechiffrer($jeton_chiffre, SpipCles::secret_du_site());
412
+        } catch (\Exception $e) {
413
+            spip_logger('chiffrer')->error('Échec du déchiffrage du jeton d’auteur: ' . $e->getMessage());
414
+            return false;
415
+        }
416
+        if ($_jeton && hash_equals($jeton, $_jeton)) {
417
+            return $auteur;
418
+        }
419
+    }
420
+    return false;
421 421
 }
422 422
 
423 423
 /**
@@ -427,6 +427,6 @@  discard block
 block discarded – undo
427 427
  * @return bool
428 428
  */
429 429
 function auteur_effacer_jeton($id_auteur) {
430
-	include_spip('base/abstract_sql');
431
-	return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . (int) $id_auteur);
430
+    include_spip('base/abstract_sql');
431
+    return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . (int) $id_auteur);
432 432
 }
Please login to merge, or discard this patch.
ecrire/bootstrap/inc/urls.php 2 patches
Indentation   +500 added lines, -501 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
  * @return string
9 9
  */
10 10
 function quote_amp($u) {
11
-	return preg_replace(
12
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
13
-		'&amp;',
14
-		$u
15
-	);
11
+    return preg_replace(
12
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
13
+        '&amp;',
14
+        $u
15
+    );
16 16
 }
17 17
 
18 18
 /**
@@ -20,23 +20,22 @@  discard block
 block discarded – undo
20 20
  *
21 21
  * On est sur le web, on exclut certains protocoles,
22 22
  * notamment 'file://', 'php://' et d'autres…
23
-
24 23
  * @param string $url
25 24
  * @return bool
26 25
  */
27 26
 function tester_url_absolue($url) {
28
-	$url = trim($url ?? '');
29
-	if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
30
-		if (
31
-			isset($m[1])
32
-			&& ($p = strtolower(rtrim($m[1], ':')))
33
-			&& in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
34
-		) {
35
-			return false;
36
-		}
37
-		return true;
38
-	}
39
-	return false;
27
+    $url = trim($url ?? '');
28
+    if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
29
+        if (
30
+            isset($m[1])
31
+            && ($p = strtolower(rtrim($m[1], ':')))
32
+            && in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
33
+        ) {
34
+            return false;
35
+        }
36
+        return true;
37
+    }
38
+    return false;
40 39
 }
41 40
 
42 41
 /**
@@ -58,100 +57,100 @@  discard block
 block discarded – undo
58 57
  * @return string URL
59 58
  */
60 59
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
61
-	// requete erronnee : plusieurs variable dans $c et aucun $v
62
-	if (str_contains($c, '|') && is_null($v)) {
63
-		return null;
64
-	}
65
-
66
-	// lever l'#ancre
67
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
68
-		$url = $r[1];
69
-		$ancre = $r[2];
70
-	} else {
71
-		$ancre = '';
72
-	}
73
-
74
-	// eclater
75
-	$url = preg_split(',[?]|&amp;|&,', $url);
76
-
77
-	// recuperer la base
78
-	$a = array_shift($url);
79
-	if (!$a) {
80
-		$a = './';
81
-	}
82
-
83
-	// preparer la regexp de maniere securisee
84
-	$regexp = explode('|', $c);
85
-	foreach ($regexp as $r => $e) {
86
-		$regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\[\]-],', '', $e));
87
-	}
88
-	$regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
89
-	$ajouts = array_flip(explode('|', $c));
90
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
91
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
92
-	$v_read = null;
93
-	// lire les variables et agir
94
-	foreach ($url as $n => $val) {
95
-		if (preg_match($regexp, urldecode($val), $r)) {
96
-			$r = array_pad($r, 3, null);
97
-			if ($v === null) {
98
-				// c'est un tableau, on memorise les valeurs
99
-				if (str_ends_with($r[1], '[]')) {
100
-					if (!$v_read) {
101
-						$v_read = [];
102
-					}
103
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
104
-				} // c'est un scalaire, on retourne direct
105
-				else {
106
-					return $r[2] ? substr($r[2], 1) : '';
107
-				}
108
-			} // suppression
109
-			elseif (!$testv) {
110
-				unset($url[$n]);
111
-			}
112
-			// Ajout. Pour une variable, remplacer au meme endroit,
113
-			// pour un tableau ce sera fait dans la prochaine boucle
114
-			elseif (!str_ends_with($r[1], '[]')) {
115
-				$url[$n] = $r[1] . '=' . $u;
116
-				unset($ajouts[$r[1]]);
117
-			}
118
-			// Pour les tableaux on laisse tomber les valeurs de
119
-			// départ, on remplira à l'étape suivante
120
-			else {
121
-				unset($url[$n]);
122
-			}
123
-		}
124
-	}
125
-
126
-	// traiter les parametres pas encore trouves
127
-	if (
128
-		$v === null
129
-		&& ($args = func_get_args())
130
-		&& count($args) == 2
131
-	) {
132
-		return $v_read; // rien trouve ou un tableau
133
-	} elseif ($testv) {
134
-		foreach ($ajouts as $k => $n) {
135
-			if (!is_array($v)) {
136
-				$url[] = $k . '=' . $u;
137
-			} else {
138
-				$id = (str_ends_with($k, '[]')) ? $k : ($k . '[]');
139
-				foreach ($v as $w) {
140
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
141
-				}
142
-			}
143
-		}
144
-	}
145
-
146
-	// eliminer les vides
147
-	$url = array_filter($url);
148
-
149
-	// recomposer l'adresse
150
-	if ($url) {
151
-		$a .= '?' . join($sep, $url);
152
-	}
153
-
154
-	return $a . $ancre;
60
+    // requete erronnee : plusieurs variable dans $c et aucun $v
61
+    if (str_contains($c, '|') && is_null($v)) {
62
+        return null;
63
+    }
64
+
65
+    // lever l'#ancre
66
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
67
+        $url = $r[1];
68
+        $ancre = $r[2];
69
+    } else {
70
+        $ancre = '';
71
+    }
72
+
73
+    // eclater
74
+    $url = preg_split(',[?]|&amp;|&,', $url);
75
+
76
+    // recuperer la base
77
+    $a = array_shift($url);
78
+    if (!$a) {
79
+        $a = './';
80
+    }
81
+
82
+    // preparer la regexp de maniere securisee
83
+    $regexp = explode('|', $c);
84
+    foreach ($regexp as $r => $e) {
85
+        $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\[\]-],', '', $e));
86
+    }
87
+    $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
88
+    $ajouts = array_flip(explode('|', $c));
89
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
90
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
91
+    $v_read = null;
92
+    // lire les variables et agir
93
+    foreach ($url as $n => $val) {
94
+        if (preg_match($regexp, urldecode($val), $r)) {
95
+            $r = array_pad($r, 3, null);
96
+            if ($v === null) {
97
+                // c'est un tableau, on memorise les valeurs
98
+                if (str_ends_with($r[1], '[]')) {
99
+                    if (!$v_read) {
100
+                        $v_read = [];
101
+                    }
102
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
103
+                } // c'est un scalaire, on retourne direct
104
+                else {
105
+                    return $r[2] ? substr($r[2], 1) : '';
106
+                }
107
+            } // suppression
108
+            elseif (!$testv) {
109
+                unset($url[$n]);
110
+            }
111
+            // Ajout. Pour une variable, remplacer au meme endroit,
112
+            // pour un tableau ce sera fait dans la prochaine boucle
113
+            elseif (!str_ends_with($r[1], '[]')) {
114
+                $url[$n] = $r[1] . '=' . $u;
115
+                unset($ajouts[$r[1]]);
116
+            }
117
+            // Pour les tableaux on laisse tomber les valeurs de
118
+            // départ, on remplira à l'étape suivante
119
+            else {
120
+                unset($url[$n]);
121
+            }
122
+        }
123
+    }
124
+
125
+    // traiter les parametres pas encore trouves
126
+    if (
127
+        $v === null
128
+        && ($args = func_get_args())
129
+        && count($args) == 2
130
+    ) {
131
+        return $v_read; // rien trouve ou un tableau
132
+    } elseif ($testv) {
133
+        foreach ($ajouts as $k => $n) {
134
+            if (!is_array($v)) {
135
+                $url[] = $k . '=' . $u;
136
+            } else {
137
+                $id = (str_ends_with($k, '[]')) ? $k : ($k . '[]');
138
+                foreach ($v as $w) {
139
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
140
+                }
141
+            }
142
+        }
143
+    }
144
+
145
+    // eliminer les vides
146
+    $url = array_filter($url);
147
+
148
+    // recomposer l'adresse
149
+    if ($url) {
150
+        $a .= '?' . join($sep, $url);
151
+    }
152
+
153
+    return $a . $ancre;
155 154
 }
156 155
 
157 156
 /**
@@ -166,22 +165,22 @@  discard block
 block discarded – undo
166 165
  * @uses translitteration()
167 166
  */
168 167
 function ancre_url(string $url, ?string $ancre = ''): string {
169
-	$ancre ??= '';
170
-	// lever l'#ancre
171
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
172
-		$url = $r[1];
173
-	}
174
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
175
-		if (!function_exists('translitteration')) {
176
-			include_spip('inc/charsets');
177
-		}
178
-		$ancre = preg_replace(
179
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
180
-			['', '-'],
181
-			translitteration($ancre)
182
-		);
183
-	}
184
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
168
+    $ancre ??= '';
169
+    // lever l'#ancre
170
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
171
+        $url = $r[1];
172
+    }
173
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
174
+        if (!function_exists('translitteration')) {
175
+            include_spip('inc/charsets');
176
+        }
177
+        $ancre = preg_replace(
178
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
179
+            ['', '-'],
180
+            translitteration($ancre)
181
+        );
182
+    }
183
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
185 184
 }
186 185
 
187 186
 /**
@@ -191,16 +190,16 @@  discard block
 block discarded – undo
191 190
  * @return string
192 191
  */
193 192
 function nettoyer_uri($reset = null) {
194
-	static $done = false;
195
-	static $propre = '';
196
-	if (!is_null($reset)) {
197
-		return $propre = $reset;
198
-	}
199
-	if ($done) {
200
-		return $propre;
201
-	}
202
-	$done = true;
203
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
193
+    static $done = false;
194
+    static $propre = '';
195
+    if (!is_null($reset)) {
196
+        return $propre = $reset;
197
+    }
198
+    if ($done) {
199
+        return $propre;
200
+    }
201
+    $done = true;
202
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
204 203
 }
205 204
 
206 205
 /**
@@ -215,36 +214,36 @@  discard block
 block discarded – undo
215 214
  * @return string
216 215
  */
217 216
 function nettoyer_uri_var($request_uri) {
218
-	static $preg_nettoyer;
219
-	if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) {
220
-		/** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */
221
-		define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']);
222
-	}
223
-	if (empty($preg_nettoyer)) {
224
-		$preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES;
225
-		foreach ($preg_nettoyer_vars as &$var) {
226
-			if (str_starts_with($var, '^')) {
227
-				$var = substr($var, 1);
228
-			} else {
229
-				$var = '[^=&]*' . $var;
230
-			}
231
-			if (str_ends_with($var, '$')) {
232
-				$var = substr($var, 0, -1);
233
-			} else {
234
-				$var .= '[^=&]*';
235
-			}
236
-		}
237
-		$preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i';
238
-	}
239
-	if (empty($request_uri)) {
240
-		return $request_uri;
241
-	}
242
-	$uri1 = $request_uri;
243
-	do {
244
-		$uri = $uri1;
245
-		$uri1 = preg_replace($preg_nettoyer, '\1', $uri);
246
-	} while ($uri <> $uri1);
247
-	return rtrim($uri1, '?&');
217
+    static $preg_nettoyer;
218
+    if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) {
219
+        /** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */
220
+        define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']);
221
+    }
222
+    if (empty($preg_nettoyer)) {
223
+        $preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES;
224
+        foreach ($preg_nettoyer_vars as &$var) {
225
+            if (str_starts_with($var, '^')) {
226
+                $var = substr($var, 1);
227
+            } else {
228
+                $var = '[^=&]*' . $var;
229
+            }
230
+            if (str_ends_with($var, '$')) {
231
+                $var = substr($var, 0, -1);
232
+            } else {
233
+                $var .= '[^=&]*';
234
+            }
235
+        }
236
+        $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i';
237
+    }
238
+    if (empty($request_uri)) {
239
+        return $request_uri;
240
+    }
241
+    $uri1 = $request_uri;
242
+    do {
243
+        $uri = $uri1;
244
+        $uri1 = preg_replace($preg_nettoyer, '\1', $uri);
245
+    } while ($uri <> $uri1);
246
+    return rtrim($uri1, '?&');
248 247
 }
249 248
 
250 249
 
@@ -258,49 +257,49 @@  discard block
 block discarded – undo
258 257
  *    URL vers soi-même
259 258
  **/
260 259
 function self($amp = '&amp;', $root = false) {
261
-	$url = nettoyer_uri();
262
-	if (
263
-		!$root
264
-		&& (
265
-			// si pas de profondeur on peut tronquer
266
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
267
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
268
-			|| defined('_SET_HTML_BASE') && !_SET_HTML_BASE
269
-		)
270
-	) {
271
-		$url = preg_replace(',^[^?]*/,', '', $url);
272
-	}
273
-	// ajouter le cas echeant les variables _POST['id_...']
274
-	foreach ($_POST as $v => $c) {
275
-		if (str_starts_with($v, 'id_')) {
276
-			$url = parametre_url($url, $v, $c, '&');
277
-		}
278
-	}
279
-
280
-	// supprimer les variables sans interet
281
-	if (test_espace_prive()) {
282
-		$url = preg_replace(',([?&])('
283
-			. 'lang|show_docs|'
284
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
285
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
286
-		$url = preg_replace(',[&]$,', '\1', $url);
287
-	}
288
-
289
-	// eviter les hacks
290
-	include_spip('inc/filtres_mini');
291
-	$url = spip_htmlspecialchars($url);
292
-
293
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
294
-
295
-	// &amp; ?
296
-	if ($amp != '&amp;') {
297
-		$url = str_replace('&amp;', $amp, $url);
298
-	}
299
-
300
-	// Si ca demarre par ? ou vide, donner './'
301
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
302
-
303
-	return $url;
260
+    $url = nettoyer_uri();
261
+    if (
262
+        !$root
263
+        && (
264
+            // si pas de profondeur on peut tronquer
265
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
266
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
267
+            || defined('_SET_HTML_BASE') && !_SET_HTML_BASE
268
+        )
269
+    ) {
270
+        $url = preg_replace(',^[^?]*/,', '', $url);
271
+    }
272
+    // ajouter le cas echeant les variables _POST['id_...']
273
+    foreach ($_POST as $v => $c) {
274
+        if (str_starts_with($v, 'id_')) {
275
+            $url = parametre_url($url, $v, $c, '&');
276
+        }
277
+    }
278
+
279
+    // supprimer les variables sans interet
280
+    if (test_espace_prive()) {
281
+        $url = preg_replace(',([?&])('
282
+            . 'lang|show_docs|'
283
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
284
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
285
+        $url = preg_replace(',[&]$,', '\1', $url);
286
+    }
287
+
288
+    // eviter les hacks
289
+    include_spip('inc/filtres_mini');
290
+    $url = spip_htmlspecialchars($url);
291
+
292
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
293
+
294
+    // &amp; ?
295
+    if ($amp != '&amp;') {
296
+        $url = str_replace('&amp;', $amp, $url);
297
+    }
298
+
299
+    // Si ca demarre par ? ou vide, donner './'
300
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
301
+
302
+    return $url;
304 303
 }
305 304
 
306 305
 /**
@@ -325,48 +324,48 @@  discard block
 block discarded – undo
325 324
  *   url codee ou fonction de decodage
326 325
  */
327 326
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
328
-	if ($public === null) {
329
-		$public = !test_espace_prive();
330
-	}
331
-	$id = intval($id);
332
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
333
-
334
-	if (!$public) {
335
-		if (!$entite) {
336
-			return '';
337
-		}
338
-		if (!function_exists('generer_objet_url_ecrire')) {
339
-			include_spip('inc/urls');
340
-		}
341
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
342
-	} else {
343
-		$f = charger_fonction_url('objet', $type ?? '');
344
-
345
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
346
-		// @see charger_fonction_url
347
-		if (!$entite) {
348
-			return $f;
349
-		}
350
-
351
-		// mais d'abord il faut tester le cas des urls sur une
352
-		// base distante
353
-		if (
354
-			$connect
355
-			&& ($g = charger_fonction('connect', 'urls', true))
356
-		) {
357
-			$f = $g;
358
-		}
359
-
360
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
361
-	}
362
-	if ($res) {
363
-		return $res;
364
-	}
365
-
366
-	// On a ete gentil mais la ....
367
-	spip_logger()->error("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect");
368
-
369
-	return '';
327
+    if ($public === null) {
328
+        $public = !test_espace_prive();
329
+    }
330
+    $id = intval($id);
331
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
332
+
333
+    if (!$public) {
334
+        if (!$entite) {
335
+            return '';
336
+        }
337
+        if (!function_exists('generer_objet_url_ecrire')) {
338
+            include_spip('inc/urls');
339
+        }
340
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
341
+    } else {
342
+        $f = charger_fonction_url('objet', $type ?? '');
343
+
344
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
345
+        // @see charger_fonction_url
346
+        if (!$entite) {
347
+            return $f;
348
+        }
349
+
350
+        // mais d'abord il faut tester le cas des urls sur une
351
+        // base distante
352
+        if (
353
+            $connect
354
+            && ($g = charger_fonction('connect', 'urls', true))
355
+        ) {
356
+            $f = $g;
357
+        }
358
+
359
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
360
+    }
361
+    if ($res) {
362
+        return $res;
363
+    }
364
+
365
+    // On a ete gentil mais la ....
366
+    spip_logger()->error("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect");
367
+
368
+    return '';
370 369
 }
371 370
 
372 371
 /**
@@ -374,11 +373,11 @@  discard block
 block discarded – undo
374 373
  * @see generer_objet_url
375 374
  */
376 375
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
377
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url');
378
-	if ($public && is_string($public)) {
379
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
380
-	}
381
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
376
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url');
377
+    if ($public && is_string($public)) {
378
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
379
+    }
380
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
382 381
 }
383 382
 
384 383
 /**
@@ -386,19 +385,19 @@  discard block
 block discarded – undo
386 385
  * @param int|string|null $id
387 386
  */
388 387
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
389
-	$id = intval($id);
390
-	$exec = objet_info($entite, 'url_edit');
391
-	$url = generer_url_ecrire($exec, $args);
392
-	if (intval($id)) {
393
-		$url = parametre_url($url, id_table_objet($entite), $id);
394
-	} else {
395
-		$url = parametre_url($url, 'new', 'oui');
396
-	}
397
-	if ($ancre) {
398
-		$url = ancre_url($url, $ancre);
399
-	}
400
-
401
-	return $url;
388
+    $id = intval($id);
389
+    $exec = objet_info($entite, 'url_edit');
390
+    $url = generer_url_ecrire($exec, $args);
391
+    if (intval($id)) {
392
+        $url = parametre_url($url, id_table_objet($entite), $id);
393
+    } else {
394
+        $url = parametre_url($url, 'new', 'oui');
395
+    }
396
+    if ($ancre) {
397
+        $url = ancre_url($url, $ancre);
398
+    }
399
+
400
+    return $url;
402 401
 }
403 402
 
404 403
 /**
@@ -406,19 +405,19 @@  discard block
 block discarded – undo
406 405
  * @see generer_objet_url_ecrire_edit
407 406
  */
408 407
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
409
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit');
410
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
408
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit');
409
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
411 410
 }
412 411
 
413 412
 
414 413
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
415
-	include_spip('base/connect_sql');
416
-	$id_type = id_table_objet($entite, $public);
414
+    include_spip('base/connect_sql');
415
+    $id_type = id_table_objet($entite, $public);
417 416
 
418
-	return _DIR_RACINE . get_spip_script('./')
419
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
420
-	. (!$args ? '' : "&$args")
421
-	. (!$ancre ? '' : "#$ancre");
417
+    return _DIR_RACINE . get_spip_script('./')
418
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
419
+    . (!$args ? '' : "&$args")
420
+    . (!$ancre ? '' : "#$ancre");
422 421
 }
423 422
 
424 423
 
@@ -429,18 +428,18 @@  discard block
 block discarded – undo
429 428
  * @return string
430 429
  */
431 430
 function urlencode_1738($url) {
432
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
433
-		$uri = '';
434
-		for ($i = 0; $i < strlen($url); $i++) {
435
-			if (ord($a = $url[$i]) > 127) {
436
-				$a = rawurlencode($a);
437
-			}
438
-			$uri .= $a;
439
-		}
440
-		$url = $uri;
441
-	}
442
-
443
-	return quote_amp($url);
431
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
432
+        $uri = '';
433
+        for ($i = 0; $i < strlen($url); $i++) {
434
+            if (ord($a = $url[$i]) > 127) {
435
+                $a = rawurlencode($a);
436
+            }
437
+            $uri .= $a;
438
+        }
439
+        $url = $uri;
440
+    }
441
+
442
+    return quote_amp($url);
444 443
 }
445 444
 
446 445
 /**
@@ -449,14 +448,14 @@  discard block
 block discarded – undo
449 448
  * @param int|string|null $id
450 449
  */
451 450
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
452
-	$id = intval($id);
453
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
454
-	if (!preg_match(',^\w+:,', $h)) {
455
-		include_spip('inc/filtres_mini');
456
-		$h = url_absolue($h);
457
-	}
458
-
459
-	return $h;
451
+    $id = intval($id);
452
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
453
+    if (!preg_match(',^\w+:,', $h)) {
454
+        include_spip('inc/filtres_mini');
455
+        $h = url_absolue($h);
456
+    }
457
+
458
+    return $h;
460 459
 }
461 460
 
462 461
 /**
@@ -464,8 +463,8 @@  discard block
 block discarded – undo
464 463
  * @see  generer_objet_url_absolue
465 464
  */
466 465
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) {
467
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue');
468
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
466
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue');
467
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
469 468
 }
470 469
 
471 470
 
@@ -494,89 +493,89 @@  discard block
 block discarded – undo
494 493
  */
495 494
 function url_de_base($profondeur = null) {
496 495
 
497
-	static $url = [];
498
-	if (is_array($profondeur)) {
499
-		return $url = $profondeur;
500
-	}
501
-	if ($profondeur === false) {
502
-		return $url;
503
-	}
504
-
505
-	if (is_null($profondeur)) {
506
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
507
-	}
508
-
509
-	if (isset($url[$profondeur])) {
510
-		return $url[$profondeur];
511
-	}
512
-
513
-	$http = 'http';
514
-
515
-	if (
516
-		isset($_SERVER['SCRIPT_URI'])
517
-		&& str_starts_with($_SERVER['SCRIPT_URI'], 'https')
518
-	) {
519
-		$http = 'https';
520
-	} elseif (
521
-		isset($_SERVER['HTTPS'])
522
-		&& test_valeur_serveur($_SERVER['HTTPS'])
523
-	) {
524
-		$http = 'https';
525
-	}
526
-
527
-	// note : HTTP_HOST contient le :port si necessaire
528
-	if ($host = $_SERVER['HTTP_HOST'] ?? null) {
529
-		// Filtrer $host pour proteger d'attaques d'entete HTTP
530
-		$host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
531
-	}
532
-
533
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
534
-	if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) {
535
-		$host = $GLOBALS['meta']['adresse_site'];
536
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
537
-			$http = $scheme;
538
-			$host = str_replace("{$scheme}://", '', $host);
539
-		}
540
-	}
541
-	if (
542
-		isset($_SERVER['SERVER_PORT'])
543
-		&& ($port = $_SERVER['SERVER_PORT'])
544
-		&& !str_contains($host, ':')
545
-	) {
546
-		if (!defined('_PORT_HTTP_STANDARD')) {
547
-			define('_PORT_HTTP_STANDARD', '80');
548
-		}
549
-		if (!defined('_PORT_HTTPS_STANDARD')) {
550
-			define('_PORT_HTTPS_STANDARD', '443');
551
-		}
552
-		if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
553
-			$host .= ":$port";
554
-		}
555
-		if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
556
-			$host .= ":$port";
557
-		}
558
-	}
559
-
560
-	if (!$GLOBALS['REQUEST_URI']) {
561
-		if (isset($_SERVER['REQUEST_URI'])) {
562
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
563
-		} else {
564
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
565
-			if (
566
-				!empty($_SERVER['QUERY_STRING'])
567
-				&& !str_contains($_SERVER['REQUEST_URI'], '?')
568
-			) {
569
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
570
-			}
571
-		}
572
-	}
573
-
574
-	// Et nettoyer l'url
575
-	$GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
576
-
577
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
578
-
579
-	return $url[$profondeur];
496
+    static $url = [];
497
+    if (is_array($profondeur)) {
498
+        return $url = $profondeur;
499
+    }
500
+    if ($profondeur === false) {
501
+        return $url;
502
+    }
503
+
504
+    if (is_null($profondeur)) {
505
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
506
+    }
507
+
508
+    if (isset($url[$profondeur])) {
509
+        return $url[$profondeur];
510
+    }
511
+
512
+    $http = 'http';
513
+
514
+    if (
515
+        isset($_SERVER['SCRIPT_URI'])
516
+        && str_starts_with($_SERVER['SCRIPT_URI'], 'https')
517
+    ) {
518
+        $http = 'https';
519
+    } elseif (
520
+        isset($_SERVER['HTTPS'])
521
+        && test_valeur_serveur($_SERVER['HTTPS'])
522
+    ) {
523
+        $http = 'https';
524
+    }
525
+
526
+    // note : HTTP_HOST contient le :port si necessaire
527
+    if ($host = $_SERVER['HTTP_HOST'] ?? null) {
528
+        // Filtrer $host pour proteger d'attaques d'entete HTTP
529
+        $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
530
+    }
531
+
532
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
533
+    if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) {
534
+        $host = $GLOBALS['meta']['adresse_site'];
535
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
536
+            $http = $scheme;
537
+            $host = str_replace("{$scheme}://", '', $host);
538
+        }
539
+    }
540
+    if (
541
+        isset($_SERVER['SERVER_PORT'])
542
+        && ($port = $_SERVER['SERVER_PORT'])
543
+        && !str_contains($host, ':')
544
+    ) {
545
+        if (!defined('_PORT_HTTP_STANDARD')) {
546
+            define('_PORT_HTTP_STANDARD', '80');
547
+        }
548
+        if (!defined('_PORT_HTTPS_STANDARD')) {
549
+            define('_PORT_HTTPS_STANDARD', '443');
550
+        }
551
+        if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
552
+            $host .= ":$port";
553
+        }
554
+        if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
555
+            $host .= ":$port";
556
+        }
557
+    }
558
+
559
+    if (!$GLOBALS['REQUEST_URI']) {
560
+        if (isset($_SERVER['REQUEST_URI'])) {
561
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
562
+        } else {
563
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
564
+            if (
565
+                !empty($_SERVER['QUERY_STRING'])
566
+                && !str_contains($_SERVER['REQUEST_URI'], '?')
567
+            ) {
568
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
569
+            }
570
+        }
571
+    }
572
+
573
+    // Et nettoyer l'url
574
+    $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
575
+
576
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
577
+
578
+    return $url[$profondeur];
580 579
 }
581 580
 
582 581
 /**
@@ -589,26 +588,26 @@  discard block
 block discarded – undo
589 588
  * @return string
590 589
  */
591 590
 function url_de_($http, $host, $request, $prof = 0) {
592
-	$prof = max($prof, 0);
593
-
594
-	$myself = ltrim($request, '/');
595
-	# supprimer la chaine de GET
596
-	[$myself] = explode('?', $myself);
597
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
598
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
599
-	if (str_contains($myself, '://')) {
600
-		$myself = explode('://', $myself);
601
-		array_shift($myself);
602
-		$myself = implode('://', $myself);
603
-		$myself = explode('/', $myself);
604
-		array_shift($myself);
605
-		$myself = implode('/', $myself);
606
-	}
607
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
608
-
609
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
610
-
611
-	return $url;
591
+    $prof = max($prof, 0);
592
+
593
+    $myself = ltrim($request, '/');
594
+    # supprimer la chaine de GET
595
+    [$myself] = explode('?', $myself);
596
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
597
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
598
+    if (str_contains($myself, '://')) {
599
+        $myself = explode('://', $myself);
600
+        array_shift($myself);
601
+        $myself = implode('://', $myself);
602
+        $myself = explode('/', $myself);
603
+        array_shift($myself);
604
+        $myself = implode('/', $myself);
605
+    }
606
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
607
+
608
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
609
+
610
+    return $url;
612 611
 }
613 612
 
614 613
 
@@ -643,26 +642,26 @@  discard block
 block discarded – undo
643 642
  * @return string URL
644 643
  **/
645 644
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
646
-	$script ??= '';
647
-	if (!$rel) {
648
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
649
-	} else {
650
-		if (!is_string($rel)) {
651
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
652
-		}
653
-	}
654
-
655
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
656
-	if ($script && ($script <> 'accueil' || $rel)) {
657
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
658
-	} elseif ($args) {
659
-		$args = "?$args";
660
-	}
661
-	if ($ancre) {
662
-		$args .= "#$ancre";
663
-	}
664
-
665
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
645
+    $script ??= '';
646
+    if (!$rel) {
647
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
648
+    } else {
649
+        if (!is_string($rel)) {
650
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
651
+        }
652
+    }
653
+
654
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
655
+    if ($script && ($script <> 'accueil' || $rel)) {
656
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
657
+    } elseif ($args) {
658
+        $args = "?$args";
659
+    }
660
+    if ($ancre) {
661
+        $args .= "#$ancre";
662
+    }
663
+
664
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
666 665
 }
667 666
 
668 667
 //
@@ -684,15 +683,15 @@  discard block
 block discarded – undo
684 683
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
685 684
  **/
686 685
 function get_spip_script($default = '') {
687
-	if (!defined('_SPIP_SCRIPT')) {
688
-		return 'spip.php';
689
-	}
690
-	# cas define('_SPIP_SCRIPT', '');
691
-	if (_SPIP_SCRIPT) {
692
-		return _SPIP_SCRIPT;
693
-	} else {
694
-		return $default;
695
-	}
686
+    if (!defined('_SPIP_SCRIPT')) {
687
+        return 'spip.php';
688
+    }
689
+    # cas define('_SPIP_SCRIPT', '');
690
+    if (_SPIP_SCRIPT) {
691
+        return _SPIP_SCRIPT;
692
+    } else {
693
+        return $default;
694
+    }
696 695
 }
697 696
 
698 697
 /**
@@ -721,45 +720,45 @@  discard block
 block discarded – undo
721 720
  * @return string URL
722 721
  **/
723 722
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
724
-	// si le script est une action (spip_pass, spip_inscription),
725
-	// standardiser vers la nouvelle API
726
-
727
-	if (is_array($args)) {
728
-		$args = http_build_query($args);
729
-	}
730
-
731
-	$url = '';
732
-	if ($f = charger_fonction_url('page')) {
733
-		$url = $f($script, $args);
734
-		if ($url && !$rel) {
735
-			include_spip('inc/filtres_mini');
736
-			$url = url_absolue($url);
737
-		}
738
-	}
739
-	if (!$url) {
740
-		if (!$action) {
741
-			$action = get_spip_script();
742
-		}
743
-		if ($script) {
744
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
745
-		}
746
-		if ($args) {
747
-			$action .= (str_contains($action, '?') ? '&' : '?') . $args;
748
-		}
749
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
750
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
751
-	}
752
-
753
-	if (!$no_entities) {
754
-		$url = quote_amp($url);
755
-	}
756
-
757
-	return $url;
723
+    // si le script est une action (spip_pass, spip_inscription),
724
+    // standardiser vers la nouvelle API
725
+
726
+    if (is_array($args)) {
727
+        $args = http_build_query($args);
728
+    }
729
+
730
+    $url = '';
731
+    if ($f = charger_fonction_url('page')) {
732
+        $url = $f($script, $args);
733
+        if ($url && !$rel) {
734
+            include_spip('inc/filtres_mini');
735
+            $url = url_absolue($url);
736
+        }
737
+    }
738
+    if (!$url) {
739
+        if (!$action) {
740
+            $action = get_spip_script();
741
+        }
742
+        if ($script) {
743
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
744
+        }
745
+        if ($args) {
746
+            $action .= (str_contains($action, '?') ? '&' : '?') . $args;
747
+        }
748
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
749
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
750
+    }
751
+
752
+    if (!$no_entities) {
753
+        $url = quote_amp($url);
754
+    }
755
+
756
+    return $url;
758 757
 }
759 758
 
760 759
 function generer_url_prive($script, $args = '', $no_entities = false) {
761 760
 
762
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
761
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
763 762
 }
764 763
 
765 764
 
@@ -779,22 +778,22 @@  discard block
 block discarded – undo
779 778
  *     URL
780 779
  */
781 780
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
782
-	// si l'on est dans l'espace prive, on garde dans l'url
783
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
784
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
785
-	$url = (_DIR_RACINE && !$public)
786
-		? generer_url_ecrire(_request('exec'))
787
-		: generer_url_public('', '', false, false);
788
-	$url = parametre_url($url, 'action', $script);
789
-	if ($args) {
790
-		$url .= quote_amp('&' . $args);
791
-	}
792
-
793
-	if ($no_entities) {
794
-		$url = str_replace('&amp;', '&', $url);
795
-	}
796
-
797
-	return $url;
781
+    // si l'on est dans l'espace prive, on garde dans l'url
782
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
783
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
784
+    $url = (_DIR_RACINE && !$public)
785
+        ? generer_url_ecrire(_request('exec'))
786
+        : generer_url_public('', '', false, false);
787
+    $url = parametre_url($url, 'action', $script);
788
+    if ($args) {
789
+        $url .= quote_amp('&' . $args);
790
+    }
791
+
792
+    if ($no_entities) {
793
+        $url = str_replace('&amp;', '&', $url);
794
+    }
795
+
796
+    return $url;
798 797
 }
799 798
 
800 799
 
@@ -813,21 +812,21 @@  discard block
 block discarded – undo
813 812
  *     URL
814 813
  */
815 814
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
816
-	if (is_null($public)) {
817
-		$public = (_DIR_RACINE ? false : true);
818
-	}
819
-	if (!str_ends_with($script, '.api')) {
820
-		$script .= '.api';
821
-	}
822
-	$url =
823
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
824
-	. $script . '/'
825
-	. ($path ? trim($path, '/') : '')
826
-	. ($args ? '?' . quote_amp($args) : '');
827
-
828
-	if ($no_entities) {
829
-		$url = str_replace('&amp;', '&', $url);
830
-	}
831
-
832
-	return $url;
815
+    if (is_null($public)) {
816
+        $public = (_DIR_RACINE ? false : true);
817
+    }
818
+    if (!str_ends_with($script, '.api')) {
819
+        $script .= '.api';
820
+    }
821
+    $url =
822
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
823
+    . $script . '/'
824
+    . ($path ? trim($path, '/') : '')
825
+    . ($args ? '?' . quote_amp($args) : '');
826
+
827
+    if ($no_entities) {
828
+        $url = str_replace('&amp;', '&', $url);
829
+    }
830
+
831
+    return $url;
833 832
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	foreach ($regexp as $r => $e) {
86 86
 		$regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\[\]-],', '', $e));
87 87
 	}
88
-	$regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
88
+	$regexp = ',^('.implode('|', $regexp).'[[]?[]]?)(=.*)?$,';
89 89
 	$ajouts = array_flip(explode('|', $c));
90 90
 	$u = is_array($v) ? $v : rawurlencode((string) $v);
91 91
 	$testv = (is_array($v) ? count($v) : strlen((string) $v));
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 			// Ajout. Pour une variable, remplacer au meme endroit,
113 113
 			// pour un tableau ce sera fait dans la prochaine boucle
114 114
 			elseif (!str_ends_with($r[1], '[]')) {
115
-				$url[$n] = $r[1] . '=' . $u;
115
+				$url[$n] = $r[1].'='.$u;
116 116
 				unset($ajouts[$r[1]]);
117 117
 			}
118 118
 			// Pour les tableaux on laisse tomber les valeurs de
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
 	} elseif ($testv) {
134 134
 		foreach ($ajouts as $k => $n) {
135 135
 			if (!is_array($v)) {
136
-				$url[] = $k . '=' . $u;
136
+				$url[] = $k.'='.$u;
137 137
 			} else {
138
-				$id = (str_ends_with($k, '[]')) ? $k : ($k . '[]');
138
+				$id = (str_ends_with($k, '[]')) ? $k : ($k.'[]');
139 139
 				foreach ($v as $w) {
140
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
140
+					$url[] = $id.'='.(is_array($w) ? 'Array' : rawurlencode($w));
141 141
 				}
142 142
 			}
143 143
 		}
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 
149 149
 	// recomposer l'adresse
150 150
 	if ($url) {
151
-		$a .= '?' . join($sep, $url);
151
+		$a .= '?'.join($sep, $url);
152 152
 	}
153 153
 
154
-	return $a . $ancre;
154
+	return $a.$ancre;
155 155
 }
156 156
 
157 157
 /**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			translitteration($ancre)
182 182
 		);
183 183
 	}
184
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
184
+	return $url.(strlen($ancre) ? '#'.$ancre : '');
185 185
 }
186 186
 
187 187
 /**
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 			if (str_starts_with($var, '^')) {
227 227
 				$var = substr($var, 1);
228 228
 			} else {
229
-				$var = '[^=&]*' . $var;
229
+				$var = '[^=&]*'.$var;
230 230
 			}
231 231
 			if (str_ends_with($var, '$')) {
232 232
 				$var = substr($var, 0, -1);
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 				$var .= '[^=&]*';
235 235
 			}
236 236
 		}
237
-		$preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i';
237
+		$preg_nettoyer = ',([?&])('.implode('|', $preg_nettoyer_vars).')=[^&]*(&|$),i';
238 238
 	}
239 239
 	if (empty($request_uri)) {
240 240
 		return $request_uri;
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	}
365 365
 
366 366
 	// On a ete gentil mais la ....
367
-	spip_logger()->error("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect");
367
+	spip_logger()->error("generer_objet_url: entite $entite ".($public ? "($f)" : '')." inconnue $type $public $connect");
368 368
 
369 369
 	return '';
370 370
 }
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
 	include_spip('base/connect_sql');
416 416
 	$id_type = id_table_objet($entite, $public);
417 417
 
418
-	return _DIR_RACINE . get_spip_script('./')
419
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
418
+	return _DIR_RACINE.get_spip_script('./')
419
+	. '?'._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
420 420
 	. (!$args ? '' : "&$args")
421 421
 	. (!$ancre ? '' : "#$ancre");
422 422
 }
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 				!empty($_SERVER['QUERY_STRING'])
567 567
 				&& !str_contains($_SERVER['REQUEST_URI'], '?')
568 568
 			) {
569
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
569
+				$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
570 570
 			}
571 571
 		}
572 572
 	}
@@ -604,9 +604,9 @@  discard block
 block discarded – undo
604 604
 		array_shift($myself);
605 605
 		$myself = implode('/', $myself);
606 606
 	}
607
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
607
+	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/';
608 608
 
609
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
609
+	$url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/');
610 610
 
611 611
 	return $url;
612 612
 }
@@ -645,16 +645,16 @@  discard block
 block discarded – undo
645 645
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
646 646
 	$script ??= '';
647 647
 	if (!$rel) {
648
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
648
+		$rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT;
649 649
 	} else {
650 650
 		if (!is_string($rel)) {
651
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
651
+			$rel = _DIR_RESTREINT ?: './'._SPIP_ECRIRE_SCRIPT;
652 652
 		}
653 653
 	}
654 654
 
655 655
 	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
656 656
 	if ($script && ($script <> 'accueil' || $rel)) {
657
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
657
+		$args = "?exec=$script".(!$args ? '' : "&$args");
658 658
 	} elseif ($args) {
659 659
 		$args = "?$args";
660 660
 	}
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 		$args .= "#$ancre";
663 663
 	}
664 664
 
665
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
665
+	return $rel.($no_entities ? $args : str_replace('&', '&amp;', $args));
666 666
 }
667 667
 
668 668
 //
@@ -744,10 +744,10 @@  discard block
 block discarded – undo
744 744
 			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
745 745
 		}
746 746
 		if ($args) {
747
-			$action .= (str_contains($action, '?') ? '&' : '?') . $args;
747
+			$action .= (str_contains($action, '?') ? '&' : '?').$args;
748 748
 		}
749 749
 		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
750
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
750
+		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/').preg_replace(',^/[.]/,', '/', "/$action"));
751 751
 	}
752 752
 
753 753
 	if (!$no_entities) {
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 
760 760
 function generer_url_prive($script, $args = '', $no_entities = false) {
761 761
 
762
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
762
+	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php');
763 763
 }
764 764
 
765 765
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 		: generer_url_public('', '', false, false);
788 788
 	$url = parametre_url($url, 'action', $script);
789 789
 	if ($args) {
790
-		$url .= quote_amp('&' . $args);
790
+		$url .= quote_amp('&'.$args);
791 791
 	}
792 792
 
793 793
 	if ($no_entities) {
@@ -821,9 +821,9 @@  discard block
 block discarded – undo
821 821
 	}
822 822
 	$url =
823 823
 		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
824
-	. $script . '/'
824
+	. $script.'/'
825 825
 	. ($path ? trim($path, '/') : '')
826
-	. ($args ? '?' . quote_amp($args) : '');
826
+	. ($args ? '?'.quote_amp($args) : '');
827 827
 
828 828
 	if ($no_entities) {
829 829
 		$url = str_replace('&amp;', '&', $url);
Please login to merge, or discard this patch.
ecrire/public/format_html.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -10,123 +10,123 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) {
17
-	$preaff = $preaff ? "<BB$nom>$preaff" : '';
18
-	$avant = $avant ? "<B$nom>$avant" : '';
19
-	$apres = $apres ? "$apres</B$nom>" : '';
20
-	$altern = $altern ? "$altern<//B$nom>" : '';
21
-	$postaff = $postaff ? "$postaff</BB$nom>" : '';
22
-	$corps = $corps ? ">$corps</BOUCLE$nom>" : ' />';
23
-
24
-	return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
17
+    $preaff = $preaff ? "<BB$nom>$preaff" : '';
18
+    $avant = $avant ? "<B$nom>$avant" : '';
19
+    $apres = $apres ? "$apres</B$nom>" : '';
20
+    $altern = $altern ? "$altern<//B$nom>" : '';
21
+    $postaff = $postaff ? "$postaff</BB$nom>" : '';
22
+    $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />';
23
+
24
+    return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
25 25
 }
26 26
 
27 27
 function format_inclure_html($file, $args, $prof) {
28
-	if (!str_contains((string) $file, '#')) {
29
-		$t = $file ? ('(' . $file . ')') : '';
30
-	} else {
31
-		$t = '{fond=' . $file . '}';
32
-	}
33
-	$args = $args ? '{' . implode(', ', $args) . '}' : ('');
34
-
35
-	return ('<INCLURE' . $t . $args . '>');
28
+    if (!str_contains((string) $file, '#')) {
29
+        $t = $file ? ('(' . $file . ')') : '';
30
+    } else {
31
+        $t = '{fond=' . $file . '}';
32
+    }
33
+    $args = $args ? '{' . implode(', ', $args) . '}' : ('');
34
+
35
+    return ('<INCLURE' . $t . $args . '>');
36 36
 }
37 37
 
38 38
 function format_polyglotte_html($args, $prof) {
39
-	$contenu = [];
40
-	foreach ($args as $l => $t) {
41
-		$contenu[] = ($l ? "[$l]" : '') . $t;
42
-	}
39
+    $contenu = [];
40
+    foreach ($args as $l => $t) {
41
+        $contenu[] = ($l ? "[$l]" : '') . $t;
42
+    }
43 43
 
44
-	return ('<multi>' . implode(' ', $contenu) . '</multi>');
44
+    return ('<multi>' . implode(' ', $contenu) . '</multi>');
45 45
 }
46 46
 
47 47
 function format_idiome_html($nom, $module, $args, $filtres, $prof) {
48
-	foreach ($args as $k => $v) {
49
-		$args[$k] = "$k=$v";
50
-	}
51
-	$args = ($args ? '{' . implode(',', $args) . '}' : (''));
48
+    foreach ($args as $k => $v) {
49
+        $args[$k] = "$k=$v";
50
+    }
51
+    $args = ($args ? '{' . implode(',', $args) . '}' : (''));
52 52
 
53
-	return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
53
+    return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
54 54
 }
55 55
 
56 56
 function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
57
-	$nom = '#'
58
-		. ($boucle ? ($boucle . ':') : '')
59
-		. $nom
60
-		. $etoile
61
-		. $args
62
-		. $filtres;
57
+    $nom = '#'
58
+        . ($boucle ? ($boucle . ':') : '')
59
+        . $nom
60
+        . $etoile
61
+        . $args
62
+        . $filtres;
63 63
 
64
-	// Determiner si c'est un champ etendu,
64
+    // Determiner si c'est un champ etendu,
65 65
 
66
-	$s = ($avant || $apres || $filtres || str_contains((string) $args, '(#'));
66
+    $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#'));
67 67
 
68
-	return ($s ? "[$avant($nom)$apres]" : $nom);
68
+    return ($s ? "[$avant($nom)$apres]" : $nom);
69 69
 }
70 70
 
71 71
 function format_critere_html($critere) {
72
-	foreach ($critere as $k => $crit) {
73
-		$crit_s = '';
74
-		foreach ($crit as $operande) {
75
-			[$type, $valeur] = $operande;
76
-			if ($type == 'champ' && $valeur[0] == '[') {
77
-				$valeur = substr((string) $valeur, 1, -1);
78
-				if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
79
-					$valeur = substr($valeur, 1, -1);
80
-				}
81
-			}
82
-			$crit_s .= $valeur;
83
-		}
84
-		$critere[$k] = $crit_s;
85
-	}
86
-
87
-	return ($critere ? '{' . implode(',', $critere) . '}' : (''));
72
+    foreach ($critere as $k => $crit) {
73
+        $crit_s = '';
74
+        foreach ($crit as $operande) {
75
+            [$type, $valeur] = $operande;
76
+            if ($type == 'champ' && $valeur[0] == '[') {
77
+                $valeur = substr((string) $valeur, 1, -1);
78
+                if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
79
+                    $valeur = substr($valeur, 1, -1);
80
+                }
81
+            }
82
+            $crit_s .= $valeur;
83
+        }
84
+        $critere[$k] = $crit_s;
85
+    }
86
+
87
+    return ($critere ? '{' . implode(',', $critere) . '}' : (''));
88 88
 }
89 89
 
90 90
 function format_liste_html($fonc, $args, $prof) {
91
-	return ((($fonc !== '') ? "|$fonc" : $fonc)
92
-		. ($args ? '{' . implode(',', $args) . '}' : ('')));
91
+    return ((($fonc !== '') ? "|$fonc" : $fonc)
92
+        . ($args ? '{' . implode(',', $args) . '}' : ('')));
93 93
 }
94 94
 
95 95
 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
96 96
 function format_suite_html($args) {
97
-	$argsCount = is_countable($args) ? count($args) : 0;
98
-	for ($i = 0; $i < $argsCount - 1; $i++) {
99
-		[$texte, $type] = $args[$i];
100
-		[$texte2, $type2] = $args[$i + 1];
101
-		if (!$texte || !$texte2) {
102
-			continue;
103
-		}
104
-		$c1 = substr((string) $texte, -1);
105
-		if ($type2 !== 'texte') {
106
-			// si un texte se termine par ( et est suivi d'un champ
107
-			// ou assimiles, forcer la notation pleine
108
-			if ($c1 == '(' && str_starts_with((string) $texte2, '#')) {
109
-				$args[$i + 1][0] = '[(' . $texte2 . ')]';
110
-			}
111
-		} else {
112
-			if ($type == 'texte') {
113
-				continue;
114
-			}
115
-			// si un champ ou assimiles est suivi d'un texte
116
-			// et si celui-ci commence par un caractere de champ
117
-			// forcer la notation pleine
118
-			if (
119
-				$c1 == '}' && str_starts_with(ltrim((string) $texte2), '|')
120
-				|| preg_match('/[\w*]/', $c1) && preg_match('/^[\w*{|]/', (string) $texte2)
121
-			) {
122
-				$args[$i][0] = '[(' . $texte . ')]';
123
-			}
124
-		}
125
-	}
126
-
127
-	return implode('', array_map(fn($arg) => reset($arg), $args));
97
+    $argsCount = is_countable($args) ? count($args) : 0;
98
+    for ($i = 0; $i < $argsCount - 1; $i++) {
99
+        [$texte, $type] = $args[$i];
100
+        [$texte2, $type2] = $args[$i + 1];
101
+        if (!$texte || !$texte2) {
102
+            continue;
103
+        }
104
+        $c1 = substr((string) $texte, -1);
105
+        if ($type2 !== 'texte') {
106
+            // si un texte se termine par ( et est suivi d'un champ
107
+            // ou assimiles, forcer la notation pleine
108
+            if ($c1 == '(' && str_starts_with((string) $texte2, '#')) {
109
+                $args[$i + 1][0] = '[(' . $texte2 . ')]';
110
+            }
111
+        } else {
112
+            if ($type == 'texte') {
113
+                continue;
114
+            }
115
+            // si un champ ou assimiles est suivi d'un texte
116
+            // et si celui-ci commence par un caractere de champ
117
+            // forcer la notation pleine
118
+            if (
119
+                $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|')
120
+                || preg_match('/[\w*]/', $c1) && preg_match('/^[\w*{|]/', (string) $texte2)
121
+            ) {
122
+                $args[$i][0] = '[(' . $texte . ')]';
123
+            }
124
+        }
125
+    }
126
+
127
+    return implode('', array_map(fn($arg) => reset($arg), $args));
128 128
 }
129 129
 
130 130
 function format_texte_html($texte) {
131
-	return $texte;
131
+    return $texte;
132 132
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -26,36 +26,36 @@  discard block
 block discarded – undo
26 26
 
27 27
 function format_inclure_html($file, $args, $prof) {
28 28
 	if (!str_contains((string) $file, '#')) {
29
-		$t = $file ? ('(' . $file . ')') : '';
29
+		$t = $file ? ('('.$file.')') : '';
30 30
 	} else {
31
-		$t = '{fond=' . $file . '}';
31
+		$t = '{fond='.$file.'}';
32 32
 	}
33
-	$args = $args ? '{' . implode(', ', $args) . '}' : ('');
33
+	$args = $args ? '{'.implode(', ', $args).'}' : ('');
34 34
 
35
-	return ('<INCLURE' . $t . $args . '>');
35
+	return ('<INCLURE'.$t.$args.'>');
36 36
 }
37 37
 
38 38
 function format_polyglotte_html($args, $prof) {
39 39
 	$contenu = [];
40 40
 	foreach ($args as $l => $t) {
41
-		$contenu[] = ($l ? "[$l]" : '') . $t;
41
+		$contenu[] = ($l ? "[$l]" : '').$t;
42 42
 	}
43 43
 
44
-	return ('<multi>' . implode(' ', $contenu) . '</multi>');
44
+	return ('<multi>'.implode(' ', $contenu).'</multi>');
45 45
 }
46 46
 
47 47
 function format_idiome_html($nom, $module, $args, $filtres, $prof) {
48 48
 	foreach ($args as $k => $v) {
49 49
 		$args[$k] = "$k=$v";
50 50
 	}
51
-	$args = ($args ? '{' . implode(',', $args) . '}' : (''));
51
+	$args = ($args ? '{'.implode(',', $args).'}' : (''));
52 52
 
53
-	return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
53
+	return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>');
54 54
 }
55 55
 
56 56
 function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
57 57
 	$nom = '#'
58
-		. ($boucle ? ($boucle . ':') : '')
58
+		. ($boucle ? ($boucle.':') : '')
59 59
 		. $nom
60 60
 		. $etoile
61 61
 		. $args
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 		$critere[$k] = $crit_s;
85 85
 	}
86 86
 
87
-	return ($critere ? '{' . implode(',', $critere) . '}' : (''));
87
+	return ($critere ? '{'.implode(',', $critere).'}' : (''));
88 88
 }
89 89
 
90 90
 function format_liste_html($fonc, $args, $prof) {
91 91
 	return ((($fonc !== '') ? "|$fonc" : $fonc)
92
-		. ($args ? '{' . implode(',', $args) . '}' : ('')));
92
+		. ($args ? '{'.implode(',', $args).'}' : ('')));
93 93
 }
94 94
 
95 95
 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			// si un texte se termine par ( et est suivi d'un champ
107 107
 			// ou assimiles, forcer la notation pleine
108 108
 			if ($c1 == '(' && str_starts_with((string) $texte2, '#')) {
109
-				$args[$i + 1][0] = '[(' . $texte2 . ')]';
109
+				$args[$i + 1][0] = '[('.$texte2.')]';
110 110
 			}
111 111
 		} else {
112 112
 			if ($type == 'texte') {
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 				$c1 == '}' && str_starts_with(ltrim((string) $texte2), '|')
120 120
 				|| preg_match('/[\w*]/', $c1) && preg_match('/^[\w*{|]/', (string) $texte2)
121 121
 			) {
122
-				$args[$i][0] = '[(' . $texte . ')]';
122
+				$args[$i][0] = '[('.$texte.')]';
123 123
 			}
124 124
 		}
125 125
 	}
Please login to merge, or discard this patch.
ecrire/auth/ldap.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok
@@ -24,12 +24,12 @@  discard block
 block discarded – undo
24 24
 // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login
25 25
 // ne pas ecraser une definition perso dans mes_options
26 26
 if (!isset($GLOBALS['ldap_attributes']) || !is_array($GLOBALS['ldap_attributes'])) {
27
-	$GLOBALS['ldap_attributes'] = [
28
-		'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'],
29
-		'nom' => 'cn',
30
-		'email' => 'mail',
31
-		'bio' => 'description'
32
-	];
27
+    $GLOBALS['ldap_attributes'] = [
28
+        'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'],
29
+        'nom' => 'cn',
30
+        'email' => 'mail',
31
+        'bio' => 'description'
32
+    ];
33 33
 }
34 34
 
35 35
 /**
@@ -55,49 +55,49 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function auth_ldap_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) {
57 57
 
58
-	#spip_logger()->info("ldap $login " . ($pass ? "mdp fourni" : "mdp absent"));
59
-
60
-	// Utilisateur connu ?
61
-	// si http auth, inutile de reauthentifier: cela
62
-	// ne marchera pas avec auth http autre que basic.
63
-	$checkpass = !isset($_SERVER['REMOTE_USER']);
64
-	if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) {
65
-		return [];
66
-	}
67
-	$credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass];
68
-
69
-	// Si l'utilisateur figure deja dans la base, y recuperer les infos
70
-	$r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
71
-
72
-	if ($r) {
73
-		return array_merge($r, $credentials_ldap);
74
-	}
75
-
76
-	// sinon importer les infos depuis LDAP,
77
-
78
-	if (
79
-		$GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur))
80
-	) {
81
-		// rajouter le statut indique  a l'install
82
-		$desc['statut'] = $GLOBALS['meta']['ldap_statut_import'];
83
-		$desc['login'] = $login;
84
-		$desc['source'] = 'ldap';
85
-		$desc['pass'] = '';
86
-
87
-		$r = sql_insertq('spip_auteurs', $desc, [], $serveur);
88
-	}
89
-
90
-	if ($r) {
91
-		return array_merge(
92
-			$credentials_ldap,
93
-			sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur)
94
-		);
95
-	}
96
-
97
-	// sinon echec
98
-	spip_logger()->info("Creation de l'auteur '$login' impossible");
99
-
100
-	return [];
58
+    #spip_logger()->info("ldap $login " . ($pass ? "mdp fourni" : "mdp absent"));
59
+
60
+    // Utilisateur connu ?
61
+    // si http auth, inutile de reauthentifier: cela
62
+    // ne marchera pas avec auth http autre que basic.
63
+    $checkpass = !isset($_SERVER['REMOTE_USER']);
64
+    if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) {
65
+        return [];
66
+    }
67
+    $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass];
68
+
69
+    // Si l'utilisateur figure deja dans la base, y recuperer les infos
70
+    $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur);
71
+
72
+    if ($r) {
73
+        return array_merge($r, $credentials_ldap);
74
+    }
75
+
76
+    // sinon importer les infos depuis LDAP,
77
+
78
+    if (
79
+        $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur))
80
+    ) {
81
+        // rajouter le statut indique  a l'install
82
+        $desc['statut'] = $GLOBALS['meta']['ldap_statut_import'];
83
+        $desc['login'] = $login;
84
+        $desc['source'] = 'ldap';
85
+        $desc['pass'] = '';
86
+
87
+        $r = sql_insertq('spip_auteurs', $desc, [], $serveur);
88
+    }
89
+
90
+    if ($r) {
91
+        return array_merge(
92
+            $credentials_ldap,
93
+            sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur)
94
+        );
95
+    }
96
+
97
+    // sinon echec
98
+    spip_logger()->info("Creation de l'auteur '$login' impossible");
99
+
100
+    return [];
101 101
 }
102 102
 
103 103
 /**
@@ -111,36 +111,36 @@  discard block
 block discarded – undo
111 111
  * @return array
112 112
  */
113 113
 function auth_ldap_connect($serveur = '') {
114
-	include_spip('base/connect_sql');
115
-	static $connexions_ldap = [];
116
-	if (isset($connexions_ldap[$serveur])) {
117
-		return $connexions_ldap[$serveur];
118
-	}
119
-	$connexion = spip_connect($serveur);
120
-	if (!is_array($connexion['ldap'])) {
121
-		if ($connexion['authentification']['ldap']) {
122
-			$f = _DIR_CONNECT . $connexion['authentification']['ldap'];
123
-			unset($GLOBALS['ldap_link']);
124
-			if (is_readable($f)) {
125
-				include_once($f);
126
-			};
127
-			if (isset($GLOBALS['ldap_link'])) {
128
-				$connexion['ldap'] = [
129
-					'link' => $GLOBALS['ldap_link'],
130
-					'base' => $GLOBALS['ldap_base']
131
-				];
132
-			} else {
133
-				spip_logger()->info("connection LDAP $serveur mal definie dans $f");
134
-			}
135
-			if (isset($GLOBALS['ldap_champs'])) {
136
-				$connexion['ldap']['attributes'] = $GLOBALS['ldap_champs'];
137
-			}
138
-		} else {
139
-			spip_logger()->info("connection LDAP $serveur inconnue");
140
-		}
141
-	}
142
-
143
-	return $connexions_ldap[$serveur] = $connexion['ldap'];
114
+    include_spip('base/connect_sql');
115
+    static $connexions_ldap = [];
116
+    if (isset($connexions_ldap[$serveur])) {
117
+        return $connexions_ldap[$serveur];
118
+    }
119
+    $connexion = spip_connect($serveur);
120
+    if (!is_array($connexion['ldap'])) {
121
+        if ($connexion['authentification']['ldap']) {
122
+            $f = _DIR_CONNECT . $connexion['authentification']['ldap'];
123
+            unset($GLOBALS['ldap_link']);
124
+            if (is_readable($f)) {
125
+                include_once($f);
126
+            };
127
+            if (isset($GLOBALS['ldap_link'])) {
128
+                $connexion['ldap'] = [
129
+                    'link' => $GLOBALS['ldap_link'],
130
+                    'base' => $GLOBALS['ldap_base']
131
+                ];
132
+            } else {
133
+                spip_logger()->info("connection LDAP $serveur mal definie dans $f");
134
+            }
135
+            if (isset($GLOBALS['ldap_champs'])) {
136
+                $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs'];
137
+            }
138
+        } else {
139
+            spip_logger()->info("connection LDAP $serveur inconnue");
140
+        }
141
+    }
142
+
143
+    return $connexions_ldap[$serveur] = $connexion['ldap'];
144 144
 }
145 145
 
146 146
 /**
@@ -154,52 +154,52 @@  discard block
 block discarded – undo
154 154
  *    Le login trouvé ou chaine vide si non trouvé
155 155
  */
156 156
 function auth_ldap_search($login, #[\SensitiveParameter] $pass, $checkpass = true, $serveur = '') {
157
-	// Securite anti-injection et contre un serveur LDAP laxiste
158
-	$login_search = preg_replace('/[^-@.\s\w]/', '', $login);
159
-	if (!strlen($login_search) || $checkpass && !strlen($pass)) {
160
-		return '';
161
-	}
162
-
163
-	// verifier la connexion
164
-	if (!$ldap = auth_ldap_connect($serveur)) {
165
-		return '';
166
-	}
167
-
168
-	$ldap_link = $ldap['link'] ?? null;
169
-	$ldap_base = $ldap['base'] ?? null;
170
-	$desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes'];
171
-
172
-	$logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']];
173
-
174
-	// Tenter une recherche pour essayer de retrouver le DN
175
-	foreach ($logins as $att) {
176
-		$result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']);
177
-		$info = @ldap_get_entries($ldap_link, $result);
178
-		// Ne pas accepter les resultats si plus d'une entree
179
-		// (on veut un attribut unique)
180
-
181
-		if (is_array($info) && $info['count'] == 1) {
182
-			$dn = $info[0]['dn'];
183
-			if (!$checkpass) {
184
-				return $dn;
185
-			}
186
-			if (@ldap_bind($ldap_link, $dn, $pass)) {
187
-				return $dn;
188
-			}
189
-		}
190
-	}
191
-
192
-	if ($checkpass && !isset($dn)) {
193
-		// Si echec, essayer de deviner le DN
194
-		foreach ($logins as $att) {
195
-			$dn = "$att=$login_search, $ldap_base";
196
-			if (@ldap_bind($ldap_link, $dn, $pass)) {
197
-				return "$att=$login_search, $ldap_base";
198
-			}
199
-		}
200
-	}
201
-
202
-	return '';
157
+    // Securite anti-injection et contre un serveur LDAP laxiste
158
+    $login_search = preg_replace('/[^-@.\s\w]/', '', $login);
159
+    if (!strlen($login_search) || $checkpass && !strlen($pass)) {
160
+        return '';
161
+    }
162
+
163
+    // verifier la connexion
164
+    if (!$ldap = auth_ldap_connect($serveur)) {
165
+        return '';
166
+    }
167
+
168
+    $ldap_link = $ldap['link'] ?? null;
169
+    $ldap_base = $ldap['base'] ?? null;
170
+    $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes'];
171
+
172
+    $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']];
173
+
174
+    // Tenter une recherche pour essayer de retrouver le DN
175
+    foreach ($logins as $att) {
176
+        $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']);
177
+        $info = @ldap_get_entries($ldap_link, $result);
178
+        // Ne pas accepter les resultats si plus d'une entree
179
+        // (on veut un attribut unique)
180
+
181
+        if (is_array($info) && $info['count'] == 1) {
182
+            $dn = $info[0]['dn'];
183
+            if (!$checkpass) {
184
+                return $dn;
185
+            }
186
+            if (@ldap_bind($ldap_link, $dn, $pass)) {
187
+                return $dn;
188
+            }
189
+        }
190
+    }
191
+
192
+    if ($checkpass && !isset($dn)) {
193
+        // Si echec, essayer de deviner le DN
194
+        foreach ($logins as $att) {
195
+            $dn = "$att=$login_search, $ldap_base";
196
+            if (@ldap_bind($ldap_link, $dn, $pass)) {
197
+                return "$att=$login_search, $ldap_base";
198
+            }
199
+        }
200
+    }
201
+
202
+    return '';
203 203
 }
204 204
 
205 205
 /**
@@ -211,40 +211,40 @@  discard block
 block discarded – undo
211 211
  * @return array
212 212
  */
213 213
 function auth_ldap_retrouver($dn, $desc = [], $serveur = '') {
214
-	// Lire les infos sur l'utilisateur a partir de son DN depuis LDAP
214
+    // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP
215 215
 
216
-	if (!$ldap = auth_ldap_connect($serveur)) {
217
-		spip_logger()->info("ldap $serveur injoignable");
216
+    if (!$ldap = auth_ldap_connect($serveur)) {
217
+        spip_logger()->info("ldap $serveur injoignable");
218 218
 
219
-		return [];
220
-	}
219
+        return [];
220
+    }
221 221
 
222
-	$ldap_link = $ldap['link'];
223
-	if (!$desc) {
224
-		$desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes'];
225
-		unset($desc['login']);
226
-	}
227
-	$result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc));
222
+    $ldap_link = $ldap['link'];
223
+    if (!$desc) {
224
+        $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes'];
225
+        unset($desc['login']);
226
+    }
227
+    $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc));
228 228
 
229
-	if (!$result) {
230
-		return [];
231
-	}
229
+    if (!$result) {
230
+        return [];
231
+    }
232 232
 
233
-	// Recuperer les donnees du premier (unique?) compte de l'auteur
234
-	$val = @ldap_get_entries($ldap_link, $result);
235
-	if (!is_array($val) || !is_array($val[0])) {
236
-		return [];
237
-	}
238
-	$val = $val[0];
233
+    // Recuperer les donnees du premier (unique?) compte de l'auteur
234
+    $val = @ldap_get_entries($ldap_link, $result);
235
+    if (!is_array($val) || !is_array($val[0])) {
236
+        return [];
237
+    }
238
+    $val = $val[0];
239 239
 
240
-	// Convertir depuis UTF-8 (jeu de caracteres par defaut)
241
-	include_spip('inc/charsets');
240
+    // Convertir depuis UTF-8 (jeu de caracteres par defaut)
241
+    include_spip('inc/charsets');
242 242
 
243
-	foreach ($desc as $k => $v) {
244
-		$desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8');
245
-	}
243
+    foreach ($desc as $k => $v) {
244
+        $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8');
245
+    }
246 246
 
247
-	return $desc;
247
+    return $desc;
248 248
 }
249 249
 
250 250
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
  * @return string
257 257
  */
258 258
 function auth_ldap_retrouver_login($login, $serveur = '') {
259
-	return auth_ldap_search($login, '', false, $serveur) ? $login : '';
259
+    return auth_ldap_search($login, '', false, $serveur) ? $login : '';
260 260
 }
261 261
 
262 262
 /**
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
  *   Message d'erreur si login non valide, chaîne vide sinon
277 277
  */
278 278
 function auth_ldap_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') {
279
-	include_spip('auth/spip');
279
+    include_spip('auth/spip');
280 280
 
281
-	return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur);
281
+    return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur);
282 282
 }
283 283
 
284 284
 /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
  *   ```
300 300
  */
301 301
 function auth_ldap_autoriser_modifier_pass($serveur = '') {
302
-	return true;
302
+    return true;
303 303
 }
304 304
 
305 305
 /**
@@ -317,22 +317,22 @@  discard block
 block discarded – undo
317 317
  *    Informe du succès ou de l'echec du changement du mot de passe
318 318
  */
319 319
 function auth_ldap_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') {
320
-	if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
321
-		return false;
322
-	}
323
-	if (!$ldap = auth_ldap_connect($serveur)) {
324
-		return false;
325
-	}
326
-	$link = $ldap['link'];
327
-	include_spip('inc/session');
328
-	$dn = session_get('ldap_dn');
329
-	if ('' == $dn) {
330
-		return false;
331
-	}
332
-	if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
333
-		return false;
334
-	}
335
-	$encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass)));
336
-
337
-	return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]);
320
+    if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
321
+        return false;
322
+    }
323
+    if (!$ldap = auth_ldap_connect($serveur)) {
324
+        return false;
325
+    }
326
+    $link = $ldap['link'];
327
+    include_spip('inc/session');
328
+    $dn = session_get('ldap_dn');
329
+    if ('' == $dn) {
330
+        return false;
331
+    }
332
+    if (!ldap_bind($link, $dn, session_get('ldap_password'))) {
333
+        return false;
334
+    }
335
+    $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass)));
336
+
337
+    return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]);
338 338
 }
Please login to merge, or discard this patch.