Completed
Push — master ( fdca64...241762 )
by cam
02:05
created
ecrire/inc/install.php 2 patches
Indentation   +343 added lines, -343 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
 
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
  * @return void
43 43
  **/
44 44
 function install_fichier_connexion($nom, $texte) {
45
-	$texte = '<' . "?php\n"
46
-		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
47
-		. $texte;
45
+    $texte = '<' . "?php\n"
46
+        . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
47
+        . $texte;
48 48
 
49
-	ecrire_fichier($nom, $texte);
49
+    ecrire_fichier($nom, $texte);
50 50
 }
51 51
 
52 52
 
@@ -75,20 +75,20 @@  discard block
 block discarded – undo
75 75
  *
76 76
  **/
77 77
 function install_connexion($adr, $port, $login, #[\SensitiveParameter] $pass, $base, $type, $pref, $ldap = '', $charset = '') {
78
-	$adr = addcslashes($adr, "'\\");
79
-	$port = addcslashes($port, "'\\");
80
-	$login = addcslashes($login, "'\\");
81
-	$pass = addcslashes($pass, "'\\");
82
-	$base = addcslashes($base, "'\\");
83
-	$type = addcslashes($type, "'\\");
84
-	$pref = addcslashes($pref, "'\\");
85
-	$ldap = addcslashes($ldap, "'\\");
86
-	$charset = addcslashes($charset, "'\\");
87
-
88
-	return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
89
-	. 'spip_connect_db('
90
-	. "'$adr','$port','$login','$pass','$base'"
91
-	. ",'$type', '$pref','$ldap','$charset');\n";
78
+    $adr = addcslashes($adr, "'\\");
79
+    $port = addcslashes($port, "'\\");
80
+    $login = addcslashes($login, "'\\");
81
+    $pass = addcslashes($pass, "'\\");
82
+    $base = addcslashes($base, "'\\");
83
+    $type = addcslashes($type, "'\\");
84
+    $pref = addcslashes($pref, "'\\");
85
+    $ldap = addcslashes($ldap, "'\\");
86
+    $charset = addcslashes($charset, "'\\");
87
+
88
+    return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
89
+    . 'spip_connect_db('
90
+    . "'$adr','$port','$login','$pass','$base'"
91
+    . ",'$type', '$pref','$ldap','$charset');\n";
92 92
 }
93 93
 
94 94
 
@@ -104,29 +104,29 @@  discard block
 block discarded – undo
104 104
  *     Tableau des informations sur la connexion
105 105
  **/
106 106
 function analyse_fichier_connection(string $file): array {
107
-	if (!file_exists($file)) {
108
-		return [];
109
-	}
110
-	$s = file_get_contents($file);
111
-	if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
112
-		array_shift($regs);
113
-
114
-		return $regs;
115
-	} else {
116
-		$ar = '\s*\'([^\']*)\'';
117
-		$r = '\s*,' . $ar;
118
-		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
119
-		if (preg_match($r, $s, $regs)) {
120
-			$regs[2] = $regs[1] . ($regs[2] ? ':' . $regs[2] . ';' : '');
121
-			array_shift($regs);
122
-			array_shift($regs);
123
-
124
-			return $regs;
125
-		}
126
-	}
127
-	spip_logger()->info("$file n'est pas un fichier de connexion");
128
-
129
-	return [];
107
+    if (!file_exists($file)) {
108
+        return [];
109
+    }
110
+    $s = file_get_contents($file);
111
+    if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
112
+        array_shift($regs);
113
+
114
+        return $regs;
115
+    } else {
116
+        $ar = '\s*\'([^\']*)\'';
117
+        $r = '\s*,' . $ar;
118
+        $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
119
+        if (preg_match($r, $s, $regs)) {
120
+            $regs[2] = $regs[1] . ($regs[2] ? ':' . $regs[2] . ';' : '');
121
+            array_shift($regs);
122
+            array_shift($regs);
123
+
124
+            return $regs;
125
+        }
126
+    }
127
+    spip_logger()->info("$file n'est pas un fichier de connexion");
128
+
129
+    return [];
130 130
 }
131 131
 
132 132
 /**
@@ -143,74 +143,74 @@  discard block
 block discarded – undo
143 143
  *     Liste des noms de connecteurs
144 144
  **/
145 145
 function bases_referencees($exclu = '') {
146
-	$tables = [];
147
-	foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
148
-		if ($f != $exclu && analyse_fichier_connection($f)) {
149
-			$tables[] = basename((string) $f, '.php');
150
-		}
151
-	}
152
-
153
-	return $tables;
146
+    $tables = [];
147
+    foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
148
+        if ($f != $exclu && analyse_fichier_connection($f)) {
149
+            $tables[] = basename((string) $f, '.php');
150
+        }
151
+    }
152
+
153
+    return $tables;
154 154
 }
155 155
 
156 156
 
157 157
 function install_mode_appel($server_db, $tout = true) {
158
-	return ($server_db != 'mysql') ? ''
159
-		: (($tout ? test_rappel_nom_base_mysql($server_db) : '')
160
-			. test_sql_mode_mysql($server_db));
158
+    return ($server_db != 'mysql') ? ''
159
+        : (($tout ? test_rappel_nom_base_mysql($server_db) : '')
160
+            . test_sql_mode_mysql($server_db));
161 161
 }
162 162
 
163 163
 //
164 164
 // Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-)
165 165
 // (sert a l'etape 1 de l'installation)
166 166
 function tester_compatibilite_hebergement() {
167
-	$err = [];
168
-
169
-	$p = phpversion();
170
-	if (version_compare($p, _PHP_MIN, '<')) {
171
-		$err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
-	}
173
-	if (version_compare($p, _PHP_MAX, '>')) {
174
-		$err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]);
175
-	}
176
-
177
-	$diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions());
178
-	if ($diff !== []) {
179
-		$err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]);
180
-	}
181
-
182
-	// Si on n'a pas la bonne version de PHP, c'est la fin
183
-	if ($err) {
184
-		die("<div class='error'>"
185
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
186
-			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
187
-	}
188
-
189
-	// Il faut une base de donnees tout de meme ...
190
-	$serveurs = install_select_serveur();
191
-	if (!$serveurs) {
192
-		$err[] = _T('install_extension_php_obligatoire')
193
-			. " <a href='http://www.php.net/mysql'>MYSQL</a>"
194
-			. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
195
-	}
196
-
197
-	if ($err) {
198
-		echo "<div class='error'>"
199
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
200
-		foreach ($err as $e) {
201
-			echo "<li><strong>$e</strong></li>\n";
202
-		}
203
-
204
-		# a priori ici on pourrait die(), mais il faut laisser la possibilite
205
-		# de forcer malgre tout (pour tester, ou si bug de detection)
206
-		echo "</ul></div>\n";
207
-	}
167
+    $err = [];
168
+
169
+    $p = phpversion();
170
+    if (version_compare($p, _PHP_MIN, '<')) {
171
+        $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
+    }
173
+    if (version_compare($p, _PHP_MAX, '>')) {
174
+        $err[] = _T('install_php_version_max', ['version' => $p, 'maximum' => _PHP_MAX]);
175
+    }
176
+
177
+    $diff = array_diff(['sodium', 'xml', 'zip'], get_loaded_extensions());
178
+    if ($diff !== []) {
179
+        $err[] = _T('install_php_extension', ['extensions' => implode(',', $diff)]);
180
+    }
181
+
182
+    // Si on n'a pas la bonne version de PHP, c'est la fin
183
+    if ($err) {
184
+        die("<div class='error'>"
185
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
186
+            . "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
187
+    }
188
+
189
+    // Il faut une base de donnees tout de meme ...
190
+    $serveurs = install_select_serveur();
191
+    if (!$serveurs) {
192
+        $err[] = _T('install_extension_php_obligatoire')
193
+            . " <a href='http://www.php.net/mysql'>MYSQL</a>"
194
+            . "| <a href='http://www.php.net/sqlite'>SQLite</a>";
195
+    }
196
+
197
+    if ($err) {
198
+        echo "<div class='error'>"
199
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
200
+        foreach ($err as $e) {
201
+            echo "<li><strong>$e</strong></li>\n";
202
+        }
203
+
204
+        # a priori ici on pourrait die(), mais il faut laisser la possibilite
205
+        # de forcer malgre tout (pour tester, ou si bug de detection)
206
+        echo "</ul></div>\n";
207
+    }
208 208
 }
209 209
 
210 210
 
211 211
 function info_etape($titre, $complement = '') {
212
-	return '<h2>' . $titre . "</h2>\n" .
213
-	($complement ? '' . $complement . "\n" : '');
212
+    return '<h2>' . $titre . "</h2>\n" .
213
+    ($complement ? '' . $complement . "\n" : '');
214 214
 }
215 215
 
216 216
 /**
@@ -220,143 +220,143 @@  discard block
 block discarded – undo
220 220
  * @return string Code HTML du bouton
221 221
  **/
222 222
 function bouton_suivant($code = '') {
223
-	if ($code == '') {
224
-		$code = _T('bouton_suivant');
225
-	}
226
-	static $suivant = 0;
227
-	$id = 'suivant' . (($suivant > 0) ? (string) $suivant : '');
228
-	$suivant += 1;
229
-
230
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
231
-	$code .
232
-	" >>\" /></p>\n";
223
+    if ($code == '') {
224
+        $code = _T('bouton_suivant');
225
+    }
226
+    static $suivant = 0;
227
+    $id = 'suivant' . (($suivant > 0) ? (string) $suivant : '');
228
+    $suivant += 1;
229
+
230
+    return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
231
+    $code .
232
+    " >>\" /></p>\n";
233 233
 }
234 234
 
235 235
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
236
-	$intitule_etat = [];
237
-
238
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
239
-	$debut = 1;
240
-	$last = is_countable($liste) ? count($liste) : 0;
241
-
242
-	include_spip('inc/texte');
243
-	$intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
244
-	$intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
245
-	$intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
246
-	$intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
247
-
248
-	$intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
249
-	$intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
250
-	$intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
251
-	$intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
252
-	$intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
253
-
254
-	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
255
-
256
-	foreach (array_keys($liste) as $etape) {
257
-		if ($debut < $last) {
258
-			if ($debut == $en_cours && $erreur) {
259
-				$class = 'on erreur';
260
-			} else {
261
-				if ($debut == $en_cours) {
262
-					$class = 'on';
263
-				} else {
264
-					$class = $debut > $en_cours ? 'prochains' : 'valides';
265
-				}
266
-			}
267
-
268
-			$aff_etapes .= "<li class='$class'><div class='fond'>";
269
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
270
-			$aff_etapes .= '<' . (($debut == $en_cours) ? 'strong' : 'span') . ' class="label_etape">' . $intitule_etat["$phase"][$debut] . '</' . (($debut == $en_cours) ? 'strong' : 'span') . '>';
271
-			$aff_etapes .= '</div></li>';
272
-		}
273
-		$debut++;
274
-	}
275
-
276
-	return $aff_etapes . '</ul>';
236
+    $intitule_etat = [];
237
+
238
+    $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
239
+    $debut = 1;
240
+    $last = is_countable($liste) ? count($liste) : 0;
241
+
242
+    include_spip('inc/texte');
243
+    $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
244
+    $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
245
+    $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
246
+    $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
247
+
248
+    $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
249
+    $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
250
+    $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
251
+    $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
252
+    $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
253
+
254
+    $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
255
+
256
+    foreach (array_keys($liste) as $etape) {
257
+        if ($debut < $last) {
258
+            if ($debut == $en_cours && $erreur) {
259
+                $class = 'on erreur';
260
+            } else {
261
+                if ($debut == $en_cours) {
262
+                    $class = 'on';
263
+                } else {
264
+                    $class = $debut > $en_cours ? 'prochains' : 'valides';
265
+                }
266
+            }
267
+
268
+            $aff_etapes .= "<li class='$class'><div class='fond'>";
269
+            $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
270
+            $aff_etapes .= '<' . (($debut == $en_cours) ? 'strong' : 'span') . ' class="label_etape">' . $intitule_etat["$phase"][$debut] . '</' . (($debut == $en_cours) ? 'strong' : 'span') . '>';
271
+            $aff_etapes .= '</div></li>';
272
+        }
273
+        $debut++;
274
+    }
275
+
276
+    return $aff_etapes . '</ul>';
277 277
 }
278 278
 
279 279
 
280 280
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
281
-	return "<fieldset>\n" .
282
-	$avant .
283
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
284
-	fieldset_champs($champs) .
285
-	$apres .
286
-	"</fieldset>\n";
281
+    return "<fieldset>\n" .
282
+    $avant .
283
+    ($legend ? '<legend>' . $legend . "</legend>\n" : '') .
284
+    fieldset_champs($champs) .
285
+    $apres .
286
+    "</fieldset>\n";
287 287
 }
288 288
 
289 289
 function fieldset_champs($champs = []) {
290
-	$fieldset = '';
291
-	foreach ($champs as $nom => $contenu) {
292
-		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', (string) $nom) ? 'password' : 'text');
293
-		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
294
-		if (isset($contenu['alternatives'])) {
295
-			$fieldset .= $contenu['label'] . "\n";
296
-			foreach ($contenu['alternatives'] as $valeur => $label) {
297
-				$fieldset .= "<input type='radio' name='" . $nom .
298
-					"' id='$nom-$valeur' value='$valeur'"
299
-					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
300
-					. "/>\n";
301
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
302
-			}
303
-			$fieldset .= "<br />\n";
304
-		} else {
305
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
306
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
307
-				. (preg_match(',^(pass|login),', (string) $nom) ? " autocomplete='off'" : '')
308
-				. ((isset($contenu['required']) && $contenu['required']) ? " required='required'" : '')
309
-				. " />\n";
310
-		}
311
-	}
312
-
313
-	return $fieldset;
290
+    $fieldset = '';
291
+    foreach ($champs as $nom => $contenu) {
292
+        $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', (string) $nom) ? 'password' : 'text');
293
+        $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
294
+        if (isset($contenu['alternatives'])) {
295
+            $fieldset .= $contenu['label'] . "\n";
296
+            foreach ($contenu['alternatives'] as $valeur => $label) {
297
+                $fieldset .= "<input type='radio' name='" . $nom .
298
+                    "' id='$nom-$valeur' value='$valeur'"
299
+                    . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
300
+                    . "/>\n";
301
+                $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
302
+            }
303
+            $fieldset .= "<br />\n";
304
+        } else {
305
+            $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
306
+            $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
307
+                . (preg_match(',^(pass|login),', (string) $nom) ? " autocomplete='off'" : '')
308
+                . ((isset($contenu['required']) && $contenu['required']) ? " required='required'" : '')
309
+                . " />\n";
310
+        }
311
+    }
312
+
313
+    return $fieldset;
314 314
 }
315 315
 
316 316
 function install_select_serveur() {
317
-	$options = [];
318
-	$dir = _DIR_RESTREINT . 'req/';
319
-	$d = opendir($dir);
320
-	if (!$d) {
321
-		return [];
322
-	}
323
-	while (($f = readdir($d)) !== false) {
324
-		if (
325
-			preg_match('/^(.*)[.]php$/', $f, $s)
326
-			&& is_readable($f = $dir . $f)
327
-		) {
328
-			require_once($f);
329
-			$s = $s[1];
330
-			$v = 'spip_versions_' . $s;
331
-			if (function_exists($v) && $v()) {
332
-				$titre = _T("install_select_type_$s");
333
-				// proposer mysql par defaut si dispo
334
-				$checked = ($s == 'mysql' ? " checked='checked'" : '');
335
-				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
336
-					. "<label for='$s'>" . ($titre ?: $s) . '</label></li>';
337
-			} else {
338
-				spip_logger()->info("$s: portage indisponible");
339
-			}
340
-		}
341
-	}
342
-	sort($options);
343
-
344
-	return $options;
317
+    $options = [];
318
+    $dir = _DIR_RESTREINT . 'req/';
319
+    $d = opendir($dir);
320
+    if (!$d) {
321
+        return [];
322
+    }
323
+    while (($f = readdir($d)) !== false) {
324
+        if (
325
+            preg_match('/^(.*)[.]php$/', $f, $s)
326
+            && is_readable($f = $dir . $f)
327
+        ) {
328
+            require_once($f);
329
+            $s = $s[1];
330
+            $v = 'spip_versions_' . $s;
331
+            if (function_exists($v) && $v()) {
332
+                $titre = _T("install_select_type_$s");
333
+                // proposer mysql par defaut si dispo
334
+                $checked = ($s == 'mysql' ? " checked='checked'" : '');
335
+                $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
336
+                    . "<label for='$s'>" . ($titre ?: $s) . '</label></li>';
337
+            } else {
338
+                spip_logger()->info("$s: portage indisponible");
339
+            }
340
+        }
341
+    }
342
+    sort($options);
343
+
344
+    return $options;
345 345
 }
346 346
 
347 347
 function install_connexion_form($db, $login, #[\SensitiveParameter] $pass, $predef, $hidden, $etape, $jquery = true) {
348
-	$server_db = (is_string($predef[0])) ? $predef[0] : '';
349
-
350
-	return generer_form_ecrire('install', (
351
-		"\n<input type='hidden' name='etape' value='$etape' />"
352
-		. $hidden
353
-		. (_request('echec') ?
354
-			('<p><b>' . _T('avis_connexion_echec_1') .
355
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
356
-			: '')
357
-
358
-		. ($jquery ? http_script('', 'jquery.js') : '')
359
-		. http_script('
348
+    $server_db = (is_string($predef[0])) ? $predef[0] : '';
349
+
350
+    return generer_form_ecrire('install', (
351
+        "\n<input type='hidden' name='etape' value='$etape' />"
352
+        . $hidden
353
+        . (_request('echec') ?
354
+            ('<p><b>' . _T('avis_connexion_echec_1') .
355
+                '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
356
+            : '')
357
+
358
+        . ($jquery ? http_script('', 'jquery.js') : '')
359
+        . http_script('
360 360
 		jQuery(function($) {
361 361
 			$details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur");
362 362
 			$("input[type=hidden][name=server_db]").each(function(){
@@ -389,145 +389,145 @@  discard block
 block discarded – undo
389 389
 			});
390 390
 		});')
391 391
 
392
-		. ($server_db
393
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
394
-			. (($predef[0])
395
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
396
-				: '')
397
-			: ('<fieldset><legend>'
398
-				. _T('install_select_type_db')
399
-				. '</legend>'
400
-				. '<p class="explication">'
401
-				. _T('install_types_db_connus')
402
-				// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
403
-				// . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
404
-				. '</p>'
405
-				. "\n<div class='p'>\n<ul>\n"
406
-				. implode("\n", install_select_serveur())
407
-				. "\n</ul>\n</div></fieldset>")
408
-		)
409
-		. '<div id="install_adresse_base_hebergeur">'
410
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
411
-		. ($predef[1]
412
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
413
-			: fieldset(
414
-				_T('entree_base_donnee_1'),
415
-				[
416
-					'adresse_db' => [
417
-						'label' => $db[1],
418
-						'valeur' => $db[0]
419
-					],
420
-				]
421
-			)
422
-		)
423
-		. '</div>'
424
-
425
-		. '<div id="install_login_base_hebergeur">'
426
-		. ($predef[2]
427
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
428
-			: fieldset(
429
-				_T('entree_login_connexion_1'),
430
-				[
431
-					'login_db' => [
432
-						'label' => $login[1],
433
-						'valeur' => $login[0]
434
-					],
435
-				]
436
-			)
437
-		)
438
-		. '</div>'
439
-
440
-		. '<div id="install_pass_base_hebergeur">'
441
-		. ($predef[3]
442
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
443
-			: fieldset(
444
-				_T('entree_mot_passe_1'),
445
-				[
446
-					'pass_db' => [
447
-						'label' => $pass[1],
448
-						'valeur' => $pass[0]
449
-					],
450
-				]
451
-			)
452
-		)
453
-		. '</div>'
454
-
455
-		. bouton_suivant()));
392
+        . ($server_db
393
+            ? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
394
+            . (($predef[0])
395
+                ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
396
+                : '')
397
+            : ('<fieldset><legend>'
398
+                . _T('install_select_type_db')
399
+                . '</legend>'
400
+                . '<p class="explication">'
401
+                . _T('install_types_db_connus')
402
+                // Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
403
+                // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
404
+                . '</p>'
405
+                . "\n<div class='p'>\n<ul>\n"
406
+                . implode("\n", install_select_serveur())
407
+                . "\n</ul>\n</div></fieldset>")
408
+        )
409
+        . '<div id="install_adresse_base_hebergeur">'
410
+        . '<p>' . _T('texte_connexion_mysql') . '</p>'
411
+        . ($predef[1]
412
+            ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
413
+            : fieldset(
414
+                _T('entree_base_donnee_1'),
415
+                [
416
+                    'adresse_db' => [
417
+                        'label' => $db[1],
418
+                        'valeur' => $db[0]
419
+                    ],
420
+                ]
421
+            )
422
+        )
423
+        . '</div>'
424
+
425
+        . '<div id="install_login_base_hebergeur">'
426
+        . ($predef[2]
427
+            ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
428
+            : fieldset(
429
+                _T('entree_login_connexion_1'),
430
+                [
431
+                    'login_db' => [
432
+                        'label' => $login[1],
433
+                        'valeur' => $login[0]
434
+                    ],
435
+                ]
436
+            )
437
+        )
438
+        . '</div>'
439
+
440
+        . '<div id="install_pass_base_hebergeur">'
441
+        . ($predef[3]
442
+            ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
443
+            : fieldset(
444
+                _T('entree_mot_passe_1'),
445
+                [
446
+                    'pass_db' => [
447
+                        'label' => $pass[1],
448
+                        'valeur' => $pass[0]
449
+                    ],
450
+                ]
451
+            )
452
+        )
453
+        . '</div>'
454
+
455
+        . bouton_suivant()));
456 456
 }
457 457
 
458 458
 // 4 valeurs qu'on reconduit d'un script a l'autre
459 459
 // sauf s'ils sont predefinis.
460 460
 
461 461
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
462
-	return ((defined('_INSTALL_HOST_DB'))
463
-		? ''
464
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
465
-	)
466
-	. ((defined('_INSTALL_USER_DB'))
467
-		? ''
468
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
469
-	)
470
-	. ((defined('_INSTALL_PASS_DB'))
471
-		? ''
472
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
473
-	)
474
-
475
-	. ((defined('_INSTALL_SERVER_DB'))
476
-		? ''
477
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
478
-	);
462
+    return ((defined('_INSTALL_HOST_DB'))
463
+        ? ''
464
+        : "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
465
+    )
466
+    . ((defined('_INSTALL_USER_DB'))
467
+        ? ''
468
+        : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
469
+    )
470
+    . ((defined('_INSTALL_PASS_DB'))
471
+        ? ''
472
+        : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
473
+    )
474
+
475
+    . ((defined('_INSTALL_SERVER_DB'))
476
+        ? ''
477
+        : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
478
+    );
479 479
 }
480 480
 
481 481
 // presentation des bases existantes
482 482
 
483 483
 function install_etape_liste_bases($server_db, $login_db, $disabled = []) {
484
-	$bases = $checked = [];
485
-	$noms = sql_listdbs($server_db);
486
-	if (!$noms) {
487
-		return '';
488
-	}
489
-
490
-	foreach ($noms as $nom) {
491
-		$id = spip_htmlspecialchars($nom);
492
-		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
493
-		$base = ' name="choix_db" value="'
494
-			. $nom
495
-			. '"'
496
-			. $dis
497
-			. " type='radio' id='$id'";
498
-		$label = "<label for='$id'>"
499
-			. ($dis ? "<i>$nom</i>" : $nom)
500
-			. '</label>';
501
-
502
-		if (
503
-			!$checked
504
-			&& !$dis
505
-			&& ($nom == $login_db || $GLOBALS['table_prefix'] == $nom)
506
-		) {
507
-			$checked = "<input$base checked='checked' />\n$label";
508
-		} else {
509
-			$bases[] = "<input$base />\n$label";
510
-		}
511
-	}
512
-
513
-	if (!$bases && !$checked) {
514
-		return false;
515
-	}
516
-
517
-	if ($checked) {
518
-		array_unshift($bases, $checked);
519
-		$checked = true;
520
-	}
521
-
522
-	return [$checked, $bases];
484
+    $bases = $checked = [];
485
+    $noms = sql_listdbs($server_db);
486
+    if (!$noms) {
487
+        return '';
488
+    }
489
+
490
+    foreach ($noms as $nom) {
491
+        $id = spip_htmlspecialchars($nom);
492
+        $dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
493
+        $base = ' name="choix_db" value="'
494
+            . $nom
495
+            . '"'
496
+            . $dis
497
+            . " type='radio' id='$id'";
498
+        $label = "<label for='$id'>"
499
+            . ($dis ? "<i>$nom</i>" : $nom)
500
+            . '</label>';
501
+
502
+        if (
503
+            !$checked
504
+            && !$dis
505
+            && ($nom == $login_db || $GLOBALS['table_prefix'] == $nom)
506
+        ) {
507
+            $checked = "<input$base checked='checked' />\n$label";
508
+        } else {
509
+            $bases[] = "<input$base />\n$label";
510
+        }
511
+    }
512
+
513
+    if (!$bases && !$checked) {
514
+        return false;
515
+    }
516
+
517
+    if ($checked) {
518
+        array_unshift($bases, $checked);
519
+        $checked = true;
520
+    }
521
+
522
+    return [$checked, $bases];
523 523
 }
524 524
 
525 525
 function install_propager($hidden) {
526
-	$res = '';
527
-	foreach ($hidden as $k) {
528
-		$v = spip_htmlentities(_request($k));
529
-		$res .= "<input type='hidden' name='$k' value='$v' />";
530
-	}
526
+    $res = '';
527
+    foreach ($hidden as $k) {
528
+        $v = spip_htmlentities(_request($k));
529
+        $res .= "<input type='hidden' name='$k' value='$v' />";
530
+    }
531 531
 
532
-	return $res;
532
+    return $res;
533 533
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
  * @return void
43 43
  **/
44 44
 function install_fichier_connexion($nom, $texte) {
45
-	$texte = '<' . "?php\n"
45
+	$texte = '<'."?php\n"
46 46
 		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
47 47
 		. $texte;
48 48
 
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 		return $regs;
115 115
 	} else {
116 116
 		$ar = '\s*\'([^\']*)\'';
117
-		$r = '\s*,' . $ar;
117
+		$r = '\s*,'.$ar;
118 118
 		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
119 119
 		if (preg_match($r, $s, $regs)) {
120
-			$regs[2] = $regs[1] . ($regs[2] ? ':' . $regs[2] . ';' : '');
120
+			$regs[2] = $regs[1].($regs[2] ? ':'.$regs[2].';' : '');
121 121
 			array_shift($regs);
122 122
 			array_shift($regs);
123 123
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	// Si on n'a pas la bonne version de PHP, c'est la fin
183 183
 	if ($err) {
184 184
 		die("<div class='error'>"
185
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
185
+			. '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"
186 186
 			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
187 187
 	}
188 188
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
 	if ($err) {
198 198
 		echo "<div class='error'>"
199
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
199
+			. '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
200 200
 		foreach ($err as $e) {
201 201
 			echo "<li><strong>$e</strong></li>\n";
202 202
 		}
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 
210 210
 
211 211
 function info_etape($titre, $complement = '') {
212
-	return '<h2>' . $titre . "</h2>\n" .
213
-	($complement ? '' . $complement . "\n" : '');
212
+	return '<h2>'.$titre."</h2>\n".
213
+	($complement ? ''.$complement."\n" : '');
214 214
 }
215 215
 
216 216
 /**
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
 		$code = _T('bouton_suivant');
225 225
 	}
226 226
 	static $suivant = 0;
227
-	$id = 'suivant' . (($suivant > 0) ? (string) $suivant : '');
227
+	$id = 'suivant'.(($suivant > 0) ? (string) $suivant : '');
228 228
 	$suivant += 1;
229 229
 
230
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
231
-	$code .
230
+	return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"".
231
+	$code.
232 232
 	" >>\" /></p>\n";
233 233
 }
234 234
 
235 235
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
236 236
 	$intitule_etat = [];
237 237
 
238
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
238
+	$liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$');
239 239
 	$debut = 1;
240 240
 	$last = is_countable($liste) ? count($liste) : 0;
241 241
 
@@ -266,23 +266,23 @@  discard block
 block discarded – undo
266 266
 			}
267 267
 
268 268
 			$aff_etapes .= "<li class='$class'><div class='fond'>";
269
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
270
-			$aff_etapes .= '<' . (($debut == $en_cours) ? 'strong' : 'span') . ' class="label_etape">' . $intitule_etat["$phase"][$debut] . '</' . (($debut == $en_cours) ? 'strong' : 'span') . '>';
269
+			$aff_etapes .= '<em>'._T('etape')." </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
270
+			$aff_etapes .= '<'.(($debut == $en_cours) ? 'strong' : 'span').' class="label_etape">'.$intitule_etat["$phase"][$debut].'</'.(($debut == $en_cours) ? 'strong' : 'span').'>';
271 271
 			$aff_etapes .= '</div></li>';
272 272
 		}
273 273
 		$debut++;
274 274
 	}
275 275
 
276
-	return $aff_etapes . '</ul>';
276
+	return $aff_etapes.'</ul>';
277 277
 }
278 278
 
279 279
 
280 280
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
281
-	return "<fieldset>\n" .
282
-	$avant .
283
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
284
-	fieldset_champs($champs) .
285
-	$apres .
281
+	return "<fieldset>\n".
282
+	$avant.
283
+	($legend ? '<legend>'.$legend."</legend>\n" : '').
284
+	fieldset_champs($champs).
285
+	$apres.
286 286
 	"</fieldset>\n";
287 287
 }
288 288
 
@@ -292,18 +292,18 @@  discard block
 block discarded – undo
292 292
 		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', (string) $nom) ? 'password' : 'text');
293 293
 		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
294 294
 		if (isset($contenu['alternatives'])) {
295
-			$fieldset .= $contenu['label'] . "\n";
295
+			$fieldset .= $contenu['label']."\n";
296 296
 			foreach ($contenu['alternatives'] as $valeur => $label) {
297
-				$fieldset .= "<input type='radio' name='" . $nom .
297
+				$fieldset .= "<input type='radio' name='".$nom.
298 298
 					"' id='$nom-$valeur' value='$valeur'"
299 299
 					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
300 300
 					. "/>\n";
301
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
301
+				$fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
302 302
 			}
303 303
 			$fieldset .= "<br />\n";
304 304
 		} else {
305
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
306
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
305
+			$fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
306
+			$fieldset .= '<input '.$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'"
307 307
 				. (preg_match(',^(pass|login),', (string) $nom) ? " autocomplete='off'" : '')
308 308
 				. ((isset($contenu['required']) && $contenu['required']) ? " required='required'" : '')
309 309
 				. " />\n";
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 
316 316
 function install_select_serveur() {
317 317
 	$options = [];
318
-	$dir = _DIR_RESTREINT . 'req/';
318
+	$dir = _DIR_RESTREINT.'req/';
319 319
 	$d = opendir($dir);
320 320
 	if (!$d) {
321 321
 		return [];
@@ -323,17 +323,17 @@  discard block
 block discarded – undo
323 323
 	while (($f = readdir($d)) !== false) {
324 324
 		if (
325 325
 			preg_match('/^(.*)[.]php$/', $f, $s)
326
-			&& is_readable($f = $dir . $f)
326
+			&& is_readable($f = $dir.$f)
327 327
 		) {
328 328
 			require_once($f);
329 329
 			$s = $s[1];
330
-			$v = 'spip_versions_' . $s;
330
+			$v = 'spip_versions_'.$s;
331 331
 			if (function_exists($v) && $v()) {
332 332
 				$titre = _T("install_select_type_$s");
333 333
 				// proposer mysql par defaut si dispo
334 334
 				$checked = ($s == 'mysql' ? " checked='checked'" : '');
335 335
 				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
336
-					. "<label for='$s'>" . ($titre ?: $s) . '</label></li>';
336
+					. "<label for='$s'>".($titre ?: $s).'</label></li>';
337 337
 			} else {
338 338
 				spip_logger()->info("$s: portage indisponible");
339 339
 			}
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
 		"\n<input type='hidden' name='etape' value='$etape' />"
352 352
 		. $hidden
353 353
 		. (_request('echec') ?
354
-			('<p><b>' . _T('avis_connexion_echec_1') .
355
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
354
+			('<p><b>'._T('avis_connexion_echec_1').
355
+				'</b></p><p>'._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3').'</p>')
356 356
 			: '')
357 357
 
358 358
 		. ($jquery ? http_script('', 'jquery.js') : '')
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
 		});')
391 391
 
392 392
 		. ($server_db
393
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
393
+			? '<input type="hidden" name="server_db" value="'.$server_db.'" />'
394 394
 			. (($predef[0])
395
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
395
+				? ('<h3>'._T('install_serveur_hebergeur').'</h3>')
396 396
 				: '')
397 397
 			: ('<fieldset><legend>'
398 398
 				. _T('install_select_type_db')
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 				. "\n</ul>\n</div></fieldset>")
408 408
 		)
409 409
 		. '<div id="install_adresse_base_hebergeur">'
410
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
410
+		. '<p>'._T('texte_connexion_mysql').'</p>'
411 411
 		. ($predef[1]
412
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
412
+			? '<h3>'._T('install_adresse_base_hebergeur').'</h3>'
413 413
 			: fieldset(
414 414
 				_T('entree_base_donnee_1'),
415 415
 				[
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 
425 425
 		. '<div id="install_login_base_hebergeur">'
426 426
 		. ($predef[2]
427
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
427
+			? '<h3>'._T('install_login_base_hebergeur').'</h3>'
428 428
 			: fieldset(
429 429
 				_T('entree_login_connexion_1'),
430 430
 				[
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 
440 440
 		. '<div id="install_pass_base_hebergeur">'
441 441
 		. ($predef[3]
442
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
442
+			? '<h3>'._T('install_pass_base_hebergeur').'</h3>'
443 443
 			: fieldset(
444 444
 				_T('entree_mot_passe_1'),
445 445
 				[
@@ -461,20 +461,20 @@  discard block
 block discarded – undo
461 461
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
462 462
 	return ((defined('_INSTALL_HOST_DB'))
463 463
 		? ''
464
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
464
+		: "\n<input type='hidden' name='adresse_db'  value=\"".spip_htmlspecialchars($adresse_db).'" />'
465 465
 	)
466 466
 	. ((defined('_INSTALL_USER_DB'))
467 467
 		? ''
468
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
468
+		: "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db).'" />'
469 469
 	)
470 470
 	. ((defined('_INSTALL_PASS_DB'))
471 471
 		? ''
472
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
472
+		: "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db).'" />'
473 473
 	)
474 474
 
475 475
 	. ((defined('_INSTALL_SERVER_DB'))
476 476
 		? ''
477
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
477
+		: "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db).'" />'
478 478
 	);
479 479
 }
480 480
 
Please login to merge, or discard this patch.
ecrire/inc/traduire.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 /**
@@ -39,18 +39,18 @@  discard block
 block discarded – undo
39 39
  *     Liste des fichiers de langue trouvés, dans l'ordre des chemins
40 40
  */
41 41
 function find_langs_in_path($file, $dirname = 'lang') {
42
-	static $dirs = [];
43
-	$liste = [];
44
-	foreach (creer_chemin() as $dir) {
45
-		if (!isset($dirs[$a = $dir . $dirname])) {
46
-			$dirs[$a] = (is_dir($a) || !$a);
47
-		}
48
-		if ($dirs[$a] && is_readable($a .= $file)) {
49
-			$liste[] = $a;
50
-		}
51
-	}
42
+    static $dirs = [];
43
+    $liste = [];
44
+    foreach (creer_chemin() as $dir) {
45
+        if (!isset($dirs[$a = $dir . $dirname])) {
46
+            $dirs[$a] = (is_dir($a) || !$a);
47
+        }
48
+        if ($dirs[$a] && is_readable($a .= $file)) {
49
+            $liste[] = $a;
50
+        }
51
+    }
52 52
 
53
-	return array_reverse($liste);
53
+    return array_reverse($liste);
54 54
 }
55 55
 
56 56
 /**
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
  *     Liste des fichiers touvés pour ce module et cette langue.
66 66
  **/
67 67
 function chercher_module_lang($module, $lang = '') {
68
-	if ($lang) {
69
-		$lang = '_' . $lang;
70
-	}
68
+    if ($lang) {
69
+        $lang = '_' . $lang;
70
+    }
71 71
 
72
-	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
73
-	if (
74
-		$f = ($module == 'local'
75
-		? find_in_path($module . $lang . '.php', 'lang/')
76
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
77
-	) {
78
-		return is_array($f) ? $f : [$f];
79
-	}
72
+    // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
73
+    if (
74
+        $f = ($module == 'local'
75
+        ? find_in_path($module . $lang . '.php', 'lang/')
76
+        : find_langs_in_path($module . $lang . '.php', 'lang/'))
77
+    ) {
78
+        return is_array($f) ? $f : [$f];
79
+    }
80 80
 
81
-	// 2) directement dans le chemin (old style, uniquement pour local)
82
-	return ($module == 'local' || strpos($module, '/'))
83
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
84
-		: false;
81
+    // 2) directement dans le chemin (old style, uniquement pour local)
82
+    return ($module == 'local' || strpos($module, '/'))
83
+        ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
84
+        : false;
85 85
 }
86 86
 
87 87
 /**
@@ -103,33 +103,33 @@  discard block
 block discarded – undo
103 103
  * @return void
104 104
  **/
105 105
 function charger_langue($lang, $module = 'spip') {
106
-	static $langs = [];
107
-	$var = 'i18n_' . $module . '_' . $lang;
108
-	if (!isset($langs[$lang])) {
109
-		$langs[$lang] = [];
110
-		if ($lang) {
111
-			$langs[$lang][] = $lang;
112
-			if (str_contains($lang, '_')) {
113
-				$l = explode('_', $lang);
114
-				$langs[$lang][] = reset($l);
115
-			}
116
-		}
117
-		$langs[$lang][] = $GLOBALS['meta']['langue_site'];
118
-		$langs[$lang][] = _LANGUE_PAR_DEFAUT;
119
-	}
120
-	foreach ($langs[$lang] as $l) {
121
-		if ($fichiers_lang = chercher_module_lang($module, $l)) {
122
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
123
-			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
124
-			surcharger_langue($fichiers_lang);
125
-			if ($l !== $lang) {
126
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
127
-			}
128
-			$GLOBALS['lang_' . $var] = $l;
129
-			#spip_logger('traduire')->info("module de langue : {$module}_$l.php");
130
-			break;
131
-		}
132
-	}
106
+    static $langs = [];
107
+    $var = 'i18n_' . $module . '_' . $lang;
108
+    if (!isset($langs[$lang])) {
109
+        $langs[$lang] = [];
110
+        if ($lang) {
111
+            $langs[$lang][] = $lang;
112
+            if (str_contains($lang, '_')) {
113
+                $l = explode('_', $lang);
114
+                $langs[$lang][] = reset($l);
115
+            }
116
+        }
117
+        $langs[$lang][] = $GLOBALS['meta']['langue_site'];
118
+        $langs[$lang][] = _LANGUE_PAR_DEFAUT;
119
+    }
120
+    foreach ($langs[$lang] as $l) {
121
+        if ($fichiers_lang = chercher_module_lang($module, $l)) {
122
+            $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
123
+            $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
124
+            surcharger_langue($fichiers_lang);
125
+            if ($l !== $lang) {
126
+                $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
127
+            }
128
+            $GLOBALS['lang_' . $var] = $l;
129
+            #spip_logger('traduire')->info("module de langue : {$module}_$l.php");
130
+            break;
131
+        }
132
+    }
133 133
 }
134 134
 
135 135
 /**
@@ -142,22 +142,22 @@  discard block
 block discarded – undo
142 142
  * @return array<string, string>
143 143
  */
144 144
 function lire_fichier_langue(string $fichier): array {
145
-	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
146
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
147
-	$GLOBALS['idx_lang'] = $idx_lang_tmp;
148
-	$idx_lang = include $fichier;
149
-	$GLOBALS['idx_lang'] = $idx_lang_before;
150
-	if (!is_array($idx_lang)) {
151
-		if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) {
152
-			trigger_deprecation('spip', '5.0', sprintf('Lang file "%s" populating a GLOBALS is deprecated. Return an array instead.', $fichier));
153
-			$idx_lang = $GLOBALS[$idx_lang_tmp];
154
-		} else {
155
-			$idx_lang = [];
156
-			spip_logger()->error(sprintf('Fichier de langue incorrect : %s', $fichier));
157
-		}
158
-		unset($GLOBALS[$idx_lang_tmp]);
159
-	}
160
-	return $idx_lang;
145
+    $idx_lang_before = $GLOBALS['idx_lang'] ?? null;
146
+    $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
147
+    $GLOBALS['idx_lang'] = $idx_lang_tmp;
148
+    $idx_lang = include $fichier;
149
+    $GLOBALS['idx_lang'] = $idx_lang_before;
150
+    if (!is_array($idx_lang)) {
151
+        if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) {
152
+            trigger_deprecation('spip', '5.0', sprintf('Lang file "%s" populating a GLOBALS is deprecated. Return an array instead.', $fichier));
153
+            $idx_lang = $GLOBALS[$idx_lang_tmp];
154
+        } else {
155
+            $idx_lang = [];
156
+            spip_logger()->error(sprintf('Fichier de langue incorrect : %s', $fichier));
157
+        }
158
+        unset($GLOBALS[$idx_lang_tmp]);
159
+    }
160
+    return $idx_lang;
161 161
 }
162 162
 
163 163
 /**
@@ -177,29 +177,29 @@  discard block
 block discarded – undo
177 177
  *    Liste des chemins de fichiers de langue à surcharger.
178 178
  **/
179 179
 function surcharger_langue($fichiers) {
180
-	static $surcharges = [];
181
-	if (!isset($GLOBALS['idx_lang'])) {
182
-		return;
183
-	}
180
+    static $surcharges = [];
181
+    if (!isset($GLOBALS['idx_lang'])) {
182
+        return;
183
+    }
184 184
 
185
-	if (!is_array($fichiers)) {
186
-		$fichiers = [$fichiers];
187
-	}
188
-	if ($fichiers === []) {
189
-		return;
190
-	}
191
-	foreach ($fichiers as $fichier) {
192
-		if (!isset($surcharges[$fichier])) {
193
-			$surcharges[$fichier] = lire_fichier_langue($fichier);
194
-		}
195
-		if (is_array($surcharges[$fichier])) {
196
-			$GLOBALS[$GLOBALS['idx_lang']] ??= [];
197
-			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
198
-				$GLOBALS[$GLOBALS['idx_lang']],
199
-				$surcharges[$fichier]
200
-			);
201
-		}
202
-	}
185
+    if (!is_array($fichiers)) {
186
+        $fichiers = [$fichiers];
187
+    }
188
+    if ($fichiers === []) {
189
+        return;
190
+    }
191
+    foreach ($fichiers as $fichier) {
192
+        if (!isset($surcharges[$fichier])) {
193
+            $surcharges[$fichier] = lire_fichier_langue($fichier);
194
+        }
195
+        if (is_array($surcharges[$fichier])) {
196
+            $GLOBALS[$GLOBALS['idx_lang']] ??= [];
197
+            $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
198
+                $GLOBALS[$GLOBALS['idx_lang']],
199
+                $surcharges[$fichier]
200
+            );
201
+        }
202
+    }
203 203
 }
204 204
 
205 205
 /**
@@ -240,99 +240,99 @@  discard block
 block discarded – undo
240 240
  *     - Description : traduction et description (texte, module, langue)
241 241
  **/
242 242
 function inc_traduire_dist($ori, $lang, $raw = false) {
243
-	static $deja_vu = [];
244
-	static $local = [];
243
+    static $deja_vu = [];
244
+    static $local = [];
245 245
 
246
-	if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') {
247
-		return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
248
-	}
246
+    if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') {
247
+        return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
248
+    }
249 249
 
250
-	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
251
-	if (strpos($ori, ':')) {
252
-		[$modules, $code] = explode(':', $ori, 2);
253
-		$modules = explode('|', $modules);
254
-		$ori_complet = $ori;
255
-	} else {
256
-		$modules = ['spip', 'ecrire'];
257
-		$code = $ori;
258
-		$ori_complet = implode('|', $modules) . ':' . $ori;
259
-	}
250
+    // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
251
+    if (strpos($ori, ':')) {
252
+        [$modules, $code] = explode(':', $ori, 2);
253
+        $modules = explode('|', $modules);
254
+        $ori_complet = $ori;
255
+    } else {
256
+        $modules = ['spip', 'ecrire'];
257
+        $code = $ori;
258
+        $ori_complet = implode('|', $modules) . ':' . $ori;
259
+    }
260 260
 
261
-	$desc = new Description();
261
+    $desc = new Description();
262 262
 
263
-	// parcourir tous les modules jusqu'a ce qu'on trouve
264
-	foreach ($modules as $module) {
265
-		$var = 'i18n_' . $module . '_' . $lang;
263
+    // parcourir tous les modules jusqu'a ce qu'on trouve
264
+    foreach ($modules as $module) {
265
+        $var = 'i18n_' . $module . '_' . $lang;
266 266
 
267
-		if (empty($GLOBALS[$var])) {
268
-			charger_langue($lang, $module);
269
-			// surcharges persos -- on cherche
270
-			// (lang/)local_xx.php et/ou (lang/)local.php ...
271
-			if (!isset($local['local_' . $lang])) {
272
-				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
273
-				$GLOBALS['idx_lang'] = $var;
274
-				// ... (lang/)local_xx.php
275
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
276
-			}
277
-			if ($local['local_' . $lang]) {
278
-				surcharger_langue($local['local_' . $lang]);
279
-			}
280
-			// ... puis (lang/)local.php
281
-			if (!isset($local['local'])) {
282
-				$local['local'] = chercher_module_lang('local');
283
-			}
284
-			if ($local['local']) {
285
-				surcharger_langue($local['local']);
286
-			}
287
-		}
267
+        if (empty($GLOBALS[$var])) {
268
+            charger_langue($lang, $module);
269
+            // surcharges persos -- on cherche
270
+            // (lang/)local_xx.php et/ou (lang/)local.php ...
271
+            if (!isset($local['local_' . $lang])) {
272
+                // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
273
+                $GLOBALS['idx_lang'] = $var;
274
+                // ... (lang/)local_xx.php
275
+                $local['local_' . $lang] = chercher_module_lang('local', $lang);
276
+            }
277
+            if ($local['local_' . $lang]) {
278
+                surcharger_langue($local['local_' . $lang]);
279
+            }
280
+            // ... puis (lang/)local.php
281
+            if (!isset($local['local'])) {
282
+                $local['local'] = chercher_module_lang('local');
283
+            }
284
+            if ($local['local']) {
285
+                surcharger_langue($local['local']);
286
+            }
287
+        }
288 288
 
289
-		if (isset($GLOBALS[$var][$code])) {
290
-			$desc->code = $code;
291
-			$desc->module = $module;
292
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
293
-			$desc->texte = $GLOBALS[$var][$code];
294
-			break;
295
-		}
296
-	}
289
+        if (isset($GLOBALS[$var][$code])) {
290
+            $desc->code = $code;
291
+            $desc->module = $module;
292
+            $desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
293
+            $desc->texte = $GLOBALS[$var][$code];
294
+            break;
295
+        }
296
+    }
297 297
 
298
-	if (!$desc->corrections) {
299
-		$desc->corrections = true;
300
-		// Retour aux sources si la chaine est absente dans la langue cible ;
301
-		// on essaie d'abord la langue du site, puis a defaut la langue fr
302
-		if (
303
-			($desc->texte === null || !strlen($desc->texte))
304
-			&& $lang !== _LANGUE_PAR_DEFAUT
305
-		) {
306
-			if ($lang !== $GLOBALS['meta']['langue_site']) {
307
-				$desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
308
-			} else {
309
-				$desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
310
-			}
311
-		}
298
+    if (!$desc->corrections) {
299
+        $desc->corrections = true;
300
+        // Retour aux sources si la chaine est absente dans la langue cible ;
301
+        // on essaie d'abord la langue du site, puis a defaut la langue fr
302
+        if (
303
+            ($desc->texte === null || !strlen($desc->texte))
304
+            && $lang !== _LANGUE_PAR_DEFAUT
305
+        ) {
306
+            if ($lang !== $GLOBALS['meta']['langue_site']) {
307
+                $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
308
+            } else {
309
+                $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
310
+            }
311
+        }
312 312
 
313
-		// Supprimer la mention <NEW> ou <MODIF>
314
-		if ($desc->texte && str_starts_with($desc->texte, '<')) {
315
-			$desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
316
-		}
313
+        // Supprimer la mention <NEW> ou <MODIF>
314
+        if ($desc->texte && str_starts_with($desc->texte, '<')) {
315
+            $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
316
+        }
317 317
 
318
-		// Si on n'est pas en utf-8, la chaine peut l'etre...
319
-		// le cas echeant on la convertit en entites html &#xxx;
320
-		if (
321
-			(!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8')
322
-			&& preg_match(',[\x7f-\xff],S', $desc->texte)
323
-		) {
324
-			include_spip('inc/charsets');
325
-			$desc->texte = charset2unicode($desc->texte, 'utf-8');
326
-		}
327
-	}
318
+        // Si on n'est pas en utf-8, la chaine peut l'etre...
319
+        // le cas echeant on la convertit en entites html &#xxx;
320
+        if (
321
+            (!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8')
322
+            && preg_match(',[\x7f-\xff],S', $desc->texte)
323
+        ) {
324
+            include_spip('inc/charsets');
325
+            $desc->texte = charset2unicode($desc->texte, 'utf-8');
326
+        }
327
+    }
328 328
 
329
-	if (_request('var_mode') == 'traduction') {
330
-		$desc = definir_details_traduction($desc, $ori_complet);
331
-	} else {
332
-		$deja_vu[$lang][$ori] = $desc;
333
-	}
329
+    if (_request('var_mode') == 'traduction') {
330
+        $desc = definir_details_traduction($desc, $ori_complet);
331
+    } else {
332
+        $deja_vu[$lang][$ori] = $desc;
333
+    }
334 334
 
335
-	return $raw ? $desc : $desc->texte;
335
+    return $raw ? $desc : $desc->texte;
336 336
 }
337 337
 
338 338
 /**
@@ -344,23 +344,23 @@  discard block
 block discarded – undo
344 344
  * @return Description
345 345
  */
346 346
 function definir_details_traduction($desc, $modules) {
347
-	if (!$desc->mode && $desc->texte) {
348
-		// ne pas modifier 2 fois l'affichage
349
-		$desc->mode = 'traduction';
350
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
351
-		$desc->texte = '<span '
352
-			. 'lang=' . $desc->langue
353
-			. ' class=' . $classe
354
-			. ' data-module=' . $desc->module
355
-			. ' data-code=' . $desc->code
356
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
357
-			. $desc->texte
358
-			. '</span>';
359
-		$desc->texte = str_replace(
360
-			["$desc->module:", "$desc->module|"],
361
-			["*$desc->module*:", "*$desc->module*|"],
362
-			$desc->texte
363
-		);
364
-	}
365
-	return $desc;
347
+    if (!$desc->mode && $desc->texte) {
348
+        // ne pas modifier 2 fois l'affichage
349
+        $desc->mode = 'traduction';
350
+        $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
351
+        $desc->texte = '<span '
352
+            . 'lang=' . $desc->langue
353
+            . ' class=' . $classe
354
+            . ' data-module=' . $desc->module
355
+            . ' data-code=' . $desc->code
356
+            . ' title=' . $modules . '(' . $desc->langue . ')>'
357
+            . $desc->texte
358
+            . '</span>';
359
+        $desc->texte = str_replace(
360
+            ["$desc->module:", "$desc->module|"],
361
+            ["*$desc->module*:", "*$desc->module*|"],
362
+            $desc->texte
363
+        );
364
+    }
365
+    return $desc;
366 366
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	static $dirs = [];
43 43
 	$liste = [];
44 44
 	foreach (creer_chemin() as $dir) {
45
-		if (!isset($dirs[$a = $dir . $dirname])) {
45
+		if (!isset($dirs[$a = $dir.$dirname])) {
46 46
 			$dirs[$a] = (is_dir($a) || !$a);
47 47
 		}
48 48
 		if ($dirs[$a] && is_readable($a .= $file)) {
@@ -66,21 +66,21 @@  discard block
 block discarded – undo
66 66
  **/
67 67
 function chercher_module_lang($module, $lang = '') {
68 68
 	if ($lang) {
69
-		$lang = '_' . $lang;
69
+		$lang = '_'.$lang;
70 70
 	}
71 71
 
72 72
 	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
73 73
 	if (
74 74
 		$f = ($module == 'local'
75
-		? find_in_path($module . $lang . '.php', 'lang/')
76
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
75
+		? find_in_path($module.$lang.'.php', 'lang/')
76
+		: find_langs_in_path($module.$lang.'.php', 'lang/'))
77 77
 	) {
78 78
 		return is_array($f) ? $f : [$f];
79 79
 	}
80 80
 
81 81
 	// 2) directement dans le chemin (old style, uniquement pour local)
82 82
 	return ($module == 'local' || strpos($module, '/'))
83
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
83
+		? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false)
84 84
 		: false;
85 85
 }
86 86
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  **/
105 105
 function charger_langue($lang, $module = 'spip') {
106 106
 	static $langs = [];
107
-	$var = 'i18n_' . $module . '_' . $lang;
107
+	$var = 'i18n_'.$module.'_'.$lang;
108 108
 	if (!isset($langs[$lang])) {
109 109
 		$langs[$lang] = [];
110 110
 		if ($lang) {
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	}
120 120
 	foreach ($langs[$lang] as $l) {
121 121
 		if ($fichiers_lang = chercher_module_lang($module, $l)) {
122
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
122
+			$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l;
123 123
 			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
124 124
 			surcharger_langue($fichiers_lang);
125 125
 			if ($l !== $lang) {
126
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
126
+				$GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l];
127 127
 			}
128
-			$GLOBALS['lang_' . $var] = $l;
128
+			$GLOBALS['lang_'.$var] = $l;
129 129
 			#spip_logger('traduire')->info("module de langue : {$module}_$l.php");
130 130
 			break;
131 131
 		}
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
  */
144 144
 function lire_fichier_langue(string $fichier): array {
145 145
 	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
146
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
146
+	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire';
147 147
 	$GLOBALS['idx_lang'] = $idx_lang_tmp;
148 148
 	$idx_lang = include $fichier;
149 149
 	$GLOBALS['idx_lang'] = $idx_lang_before;
@@ -255,27 +255,27 @@  discard block
 block discarded – undo
255 255
 	} else {
256 256
 		$modules = ['spip', 'ecrire'];
257 257
 		$code = $ori;
258
-		$ori_complet = implode('|', $modules) . ':' . $ori;
258
+		$ori_complet = implode('|', $modules).':'.$ori;
259 259
 	}
260 260
 
261 261
 	$desc = new Description();
262 262
 
263 263
 	// parcourir tous les modules jusqu'a ce qu'on trouve
264 264
 	foreach ($modules as $module) {
265
-		$var = 'i18n_' . $module . '_' . $lang;
265
+		$var = 'i18n_'.$module.'_'.$lang;
266 266
 
267 267
 		if (empty($GLOBALS[$var])) {
268 268
 			charger_langue($lang, $module);
269 269
 			// surcharges persos -- on cherche
270 270
 			// (lang/)local_xx.php et/ou (lang/)local.php ...
271
-			if (!isset($local['local_' . $lang])) {
271
+			if (!isset($local['local_'.$lang])) {
272 272
 				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
273 273
 				$GLOBALS['idx_lang'] = $var;
274 274
 				// ... (lang/)local_xx.php
275
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
275
+				$local['local_'.$lang] = chercher_module_lang('local', $lang);
276 276
 			}
277
-			if ($local['local_' . $lang]) {
278
-				surcharger_langue($local['local_' . $lang]);
277
+			if ($local['local_'.$lang]) {
278
+				surcharger_langue($local['local_'.$lang]);
279 279
 			}
280 280
 			// ... puis (lang/)local.php
281 281
 			if (!isset($local['local'])) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		if (isset($GLOBALS[$var][$code])) {
290 290
 			$desc->code = $code;
291 291
 			$desc->module = $module;
292
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
292
+			$desc->langue = $GLOBALS['lang_'.$var] ?? $lang;
293 293
 			$desc->texte = $GLOBALS[$var][$code];
294 294
 			break;
295 295
 		}
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
 	if (!$desc->mode && $desc->texte) {
348 348
 		// ne pas modifier 2 fois l'affichage
349 349
 		$desc->mode = 'traduction';
350
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
350
+		$classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : '');
351 351
 		$desc->texte = '<span '
352
-			. 'lang=' . $desc->langue
353
-			. ' class=' . $classe
354
-			. ' data-module=' . $desc->module
355
-			. ' data-code=' . $desc->code
356
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
352
+			. 'lang='.$desc->langue
353
+			. ' class='.$classe
354
+			. ' data-module='.$desc->module
355
+			. ' data-code='.$desc->code
356
+			. ' title='.$modules.'('.$desc->langue.')>'
357 357
 			. $desc->texte
358 358
 			. '</span>';
359 359
 		$desc->texte = str_replace(
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2341 added lines, -2341 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @package SPIP\Core\Filtres
21 21
  **/
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 include_spip('inc/charsets');
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
  * @return string Fonction PHP correspondante du filtre
47 47
  */
48 48
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
49
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
50
-	return chercher_filtre($fonc, $default);
49
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
50
+    return chercher_filtre($fonc, $default);
51 51
 }
52 52
 
53 53
 /**
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
  * @return string texte
58 58
  **/
59 59
 function filtre_identite_dist($texte) {
60
- return $texte;
60
+    return $texte;
61 61
 }
62 62
 
63 63
 /**
@@ -81,33 +81,33 @@  discard block
 block discarded – undo
81 81
  *     Fonction PHP correspondante du filtre demandé
82 82
  */
83 83
 function chercher_filtre($fonc, $default = null) {
84
-	if (!$fonc) {
85
-		return $default;
86
-	}
87
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
88
-	// Foo::Bar
89
-	// qui peuvent etre avec un namespace : space\Foo::Bar
90
-	if (preg_match(',^[\w]+/,', $fonc)) {
91
-		$nom = preg_replace(',\W,', '_', $fonc);
92
-		$f = chercher_filtre($nom);
93
-		// cas du sous-type MIME sans filtre associe, passer au type:
94
-		// si filtre_text_plain pas defini, passe a filtre_text
95
-		if (!$f && $nom !== $fonc) {
96
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
97
-		}
98
-
99
-		return $f;
100
-	}
101
-
102
-	include_fichiers_fonctions();
103
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
104
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
105
-		if (is_callable($f)) {
106
-			return $f;
107
-		}
108
-	}
109
-
110
-	return $default;
84
+    if (!$fonc) {
85
+        return $default;
86
+    }
87
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
88
+    // Foo::Bar
89
+    // qui peuvent etre avec un namespace : space\Foo::Bar
90
+    if (preg_match(',^[\w]+/,', $fonc)) {
91
+        $nom = preg_replace(',\W,', '_', $fonc);
92
+        $f = chercher_filtre($nom);
93
+        // cas du sous-type MIME sans filtre associe, passer au type:
94
+        // si filtre_text_plain pas defini, passe a filtre_text
95
+        if (!$f && $nom !== $fonc) {
96
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
97
+        }
98
+
99
+        return $f;
100
+    }
101
+
102
+    include_fichiers_fonctions();
103
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
104
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
105
+        if (is_callable($f)) {
106
+            return $f;
107
+        }
108
+    }
109
+
110
+    return $default;
111 111
 }
112 112
 
113 113
 /**
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
  *     Chaîne vide sinon.
152 152
  **/
153 153
 function appliquer_filtre(mixed $arg, $filtre) {
154
-	$args = func_get_args();
155
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
154
+    $args = func_get_args();
155
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
156 156
 }
157 157
 
158 158
 /**
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
  *     texte d'origine sinon
178 178
  **/
179 179
 function appliquer_si_filtre(mixed $arg, $filtre) {
180
-	$args = func_get_args();
181
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
180
+    $args = func_get_args();
181
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
182 182
 }
183 183
 
184 184
 /**
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
  *     Version de SPIP
195 195
  **/
196 196
 function spip_version() {
197
-	$version = $GLOBALS['spip_version_affichee'];
198
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
199
-		$version .= " $vcs_version";
200
-	}
197
+    $version = $GLOBALS['spip_version_affichee'];
198
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
199
+        $version .= " $vcs_version";
200
+    }
201 201
 
202
-	return $version;
202
+    return $version;
203 203
 }
204 204
 
205 205
 /**
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
  * @return string
212 212
  */
213 213
 function header_silencieux($version): string {
214
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
215
-		$version = '';
216
-	}
214
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
215
+        $version = '';
216
+    }
217 217
 
218
-	return (string) $version;
218
+    return (string) $version;
219 219
 }
220 220
 
221 221
 /**
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
  *    - string|null si $raw = false
229 229
  */
230 230
 function version_vcs_courante($dir, $raw = false) {
231
-	$desc = decrire_version_git($dir);
232
-	if ($desc === null || $raw) {
233
-		return $desc;
234
-	}
235
-	// affichage "GIT [master: abcdef]"
236
-	$commit = $desc['commit_short'] ?? $desc['commit'];
237
-	if ($desc['branch']) {
238
-		$commit = $desc['branch'] . ': ' . $commit;
239
-	}
240
-	return "{$desc['vcs']} [$commit]";
231
+    $desc = decrire_version_git($dir);
232
+    if ($desc === null || $raw) {
233
+        return $desc;
234
+    }
235
+    // affichage "GIT [master: abcdef]"
236
+    $commit = $desc['commit_short'] ?? $desc['commit'];
237
+    if ($desc['branch']) {
238
+        $commit = $desc['branch'] . ': ' . $commit;
239
+    }
240
+    return "{$desc['vcs']} [$commit]";
241 241
 }
242 242
 
243 243
 /**
@@ -249,26 +249,26 @@  discard block
 block discarded – undo
249 249
  *      array ['branch' => xx, 'commit' => yy] sinon.
250 250
  **/
251 251
 function decrire_version_git($dir) {
252
-	$c = null;
253
-	$hash = null;
254
-	if (!$dir) {
255
-		$dir = '.';
256
-	}
257
-
258
-	// version installee par GIT
259
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
260
-		$currentHead = trim(substr((string) $c, 4));
261
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
262
-			return [
263
-				'vcs' => 'GIT',
264
-				'branch' => basename($currentHead),
265
-				'commit' => trim((string) $hash),
266
-				'commit_short' => substr(trim((string) $hash), 0, 8),
267
-			];
268
-		}
269
-	}
270
-
271
-	return null;
252
+    $c = null;
253
+    $hash = null;
254
+    if (!$dir) {
255
+        $dir = '.';
256
+    }
257
+
258
+    // version installee par GIT
259
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
260
+        $currentHead = trim(substr((string) $c, 4));
261
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
262
+            return [
263
+                'vcs' => 'GIT',
264
+                'branch' => basename($currentHead),
265
+                'commit' => trim((string) $hash),
266
+                'commit_short' => substr(trim((string) $hash), 0, 8),
267
+            ];
268
+        }
269
+    }
270
+
271
+    return null;
272 272
 }
273 273
 
274 274
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -315,18 +315,18 @@  discard block
 block discarded – undo
315 315
  *     Code HTML retourné par le filtre
316 316
  **/
317 317
 function filtrer($filtre) {
318
-	$tous = func_get_args();
319
-	if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) {
320
-		return image_filtrer($tous);
321
-	} elseif ($f = chercher_filtre($filtre)) {
322
-		array_shift($tous);
323
-		return $f(...$tous);
324
-	} else {
325
-		// le filtre n'existe pas, on provoque une erreur
326
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
327
-		erreur_squelette($msg);
328
-		return '';
329
-	}
318
+    $tous = func_get_args();
319
+    if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) {
320
+        return image_filtrer($tous);
321
+    } elseif ($f = chercher_filtre($filtre)) {
322
+        array_shift($tous);
323
+        return $f(...$tous);
324
+    } else {
325
+        // le filtre n'existe pas, on provoque une erreur
326
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
327
+        erreur_squelette($msg);
328
+        return '';
329
+    }
330 330
 }
331 331
 
332 332
 /**
@@ -343,11 +343,11 @@  discard block
 block discarded – undo
343 343
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
344 344
  */
345 345
 function trouver_filtre_matrice($filtre) {
346
-	if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
347
-		find_in_path($f, '', true);
348
-		$GLOBALS['spip_matrice'][$filtre] = true;
349
-	}
350
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
346
+    if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
347
+        find_in_path($f, '', true);
348
+        $GLOBALS['spip_matrice'][$filtre] = true;
349
+    }
350
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
351 351
 }
352 352
 
353 353
 
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
  * @return mixed
376 376
  */
377 377
 function filtre_set(&$Pile, mixed $val, $key, $continue = null) {
378
-	$Pile['vars'][$key] = $val;
379
-	return $continue ? $val : '';
378
+    $Pile['vars'][$key] = $val;
379
+    return $continue ? $val : '';
380 380
 }
381 381
 
382 382
 /**
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
403 403
  */
404 404
 function filtre_setenv(&$Pile, mixed $val, mixed $key, $continue = null) {
405
-	$Pile[0][$key] = $val;
406
-	return $continue ? $val : '';
405
+    $Pile[0][$key] = $val;
406
+    return $continue ? $val : '';
407 407
 }
408 408
 
409 409
 /**
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
  * @return string
413 413
  */
414 414
 function filtre_sanitize_env(&$Pile, $keys) {
415
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
416
-	return '';
415
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
416
+    return '';
417 417
 }
418 418
 
419 419
 
@@ -436,18 +436,18 @@  discard block
 block discarded – undo
436 436
  * @return mixed Retourne la valeur (sans la modifier).
437 437
  */
438 438
 function filtre_debug(mixed $val, $key = null) {
439
-	$debug = (
440
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
441
-		) . var_export($val, true);
439
+    $debug = (
440
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
441
+        ) . var_export($val, true);
442 442
 
443
-	include_spip('inc/autoriser');
444
-	if (autoriser('webmestre')) {
445
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
446
-	}
443
+    include_spip('inc/autoriser');
444
+    if (autoriser('webmestre')) {
445
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
446
+    }
447 447
 
448
-	spip_logger('debug')->info($debug);
448
+    spip_logger('debug')->info($debug);
449 449
 
450
-	return $val;
450
+    return $val;
451 451
 }
452 452
 
453 453
 
@@ -477,81 +477,81 @@  discard block
 block discarded – undo
477 477
  *     texte qui a reçu les filtres
478 478
  **/
479 479
 function image_filtrer($args) {
480
-	$filtre = array_shift($args); # enlever $filtre
481
-	$texte = array_shift($args);
482
-	if ($texte === null || !strlen((string) $texte)) {
483
-		return '';
484
-	}
485
-	find_in_path('filtres_images_mini.php', 'inc/', true);
486
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
487
-	// Cas du nom de fichier local
488
-	$is_file = trim((string) $texte);
489
-	if (
490
-		str_contains(substr($is_file, strlen(_DIR_RACINE)), '..')
491
-		|| strpbrk($is_file, "<>\n\r\t") !== false
492
-		|| str_starts_with($is_file, '/')
493
-	) {
494
-		$is_file = false;
495
-	}
496
-	if ($is_file) {
497
-		$is_local_file = function ($path) {
498
-			if (str_contains($path, '?')) {
499
-				$path = supprimer_timestamp($path);
500
-				// remove ?24px added by find_in_theme on .svg files
501
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
502
-			}
503
-			return file_exists($path);
504
-		};
505
-		if ($is_local_file($is_file) || tester_url_absolue($is_file)) {
506
-			$res = $filtre("<img src='$is_file' />", ...$args);
507
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
508
-			return $res;
509
-		}
510
-	}
511
-
512
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
513
-	if (
514
-		preg_match_all(
515
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
516
-			(string) $texte,
517
-			$tags,
518
-			PREG_SET_ORDER
519
-		)
520
-	) {
521
-		foreach ($tags as $tag) {
522
-			$class = extraire_attribut($tag[3], 'class');
523
-			if (
524
-				(!$class || !str_contains($class, 'filtre_inactif'))
525
-				&& ($reduit = $filtre($tag[3], ...$args))
526
-			) {
527
-				// En cas de span spip_documents, modifier le style=...width:
528
-				if ($tag[1]) {
529
-					$w = extraire_attribut($reduit, 'width');
530
-					if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
531
-						$w = $regs[1];
532
-					}
533
-					if ($w && ($style = extraire_attribut($tag[1], 'style'))) {
534
-						$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
535
-						$replace = inserer_attribut($tag[1], 'style', $style);
536
-						$texte = str_replace($tag[1], $replace, (string) $texte);
537
-					}
538
-				}
539
-				// traiter aussi un eventuel mouseover
540
-				if (
541
-					($mouseover = extraire_attribut($reduit, 'onmouseover'))
542
-					&& preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)
543
-				) {
544
-					$srcover = $match[1];
545
-					$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
546
-					$srcover_filter = extraire_attribut($srcover_filter, 'src');
547
-					$reduit = str_replace($srcover, $srcover_filter, (string) $reduit);
548
-				}
549
-				$texte = str_replace($tag[3], $reduit, (string) $texte);
550
-			}
551
-		}
552
-	}
553
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
554
-	return $texte;
480
+    $filtre = array_shift($args); # enlever $filtre
481
+    $texte = array_shift($args);
482
+    if ($texte === null || !strlen((string) $texte)) {
483
+        return '';
484
+    }
485
+    find_in_path('filtres_images_mini.php', 'inc/', true);
486
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
487
+    // Cas du nom de fichier local
488
+    $is_file = trim((string) $texte);
489
+    if (
490
+        str_contains(substr($is_file, strlen(_DIR_RACINE)), '..')
491
+        || strpbrk($is_file, "<>\n\r\t") !== false
492
+        || str_starts_with($is_file, '/')
493
+    ) {
494
+        $is_file = false;
495
+    }
496
+    if ($is_file) {
497
+        $is_local_file = function ($path) {
498
+            if (str_contains($path, '?')) {
499
+                $path = supprimer_timestamp($path);
500
+                // remove ?24px added by find_in_theme on .svg files
501
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
502
+            }
503
+            return file_exists($path);
504
+        };
505
+        if ($is_local_file($is_file) || tester_url_absolue($is_file)) {
506
+            $res = $filtre("<img src='$is_file' />", ...$args);
507
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
508
+            return $res;
509
+        }
510
+    }
511
+
512
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
513
+    if (
514
+        preg_match_all(
515
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
516
+            (string) $texte,
517
+            $tags,
518
+            PREG_SET_ORDER
519
+        )
520
+    ) {
521
+        foreach ($tags as $tag) {
522
+            $class = extraire_attribut($tag[3], 'class');
523
+            if (
524
+                (!$class || !str_contains($class, 'filtre_inactif'))
525
+                && ($reduit = $filtre($tag[3], ...$args))
526
+            ) {
527
+                // En cas de span spip_documents, modifier le style=...width:
528
+                if ($tag[1]) {
529
+                    $w = extraire_attribut($reduit, 'width');
530
+                    if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
531
+                        $w = $regs[1];
532
+                    }
533
+                    if ($w && ($style = extraire_attribut($tag[1], 'style'))) {
534
+                        $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
535
+                        $replace = inserer_attribut($tag[1], 'style', $style);
536
+                        $texte = str_replace($tag[1], $replace, (string) $texte);
537
+                    }
538
+                }
539
+                // traiter aussi un eventuel mouseover
540
+                if (
541
+                    ($mouseover = extraire_attribut($reduit, 'onmouseover'))
542
+                    && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)
543
+                ) {
544
+                    $srcover = $match[1];
545
+                    $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
546
+                    $srcover_filter = extraire_attribut($srcover_filter, 'src');
547
+                    $reduit = str_replace($srcover, $srcover_filter, (string) $reduit);
548
+                }
549
+                $texte = str_replace($tag[3], $reduit, (string) $texte);
550
+            }
551
+        }
552
+    }
553
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
554
+    return $texte;
555 555
 }
556 556
 
557 557
 /**
@@ -568,94 +568,94 @@  discard block
 block discarded – undo
568 568
  **/
569 569
 function infos_image($img, $force_refresh = false) {
570 570
 
571
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
572
-	$srcWidth = 0;
573
-	$srcHeight = 0;
574
-	$srcSize = null;
575
-	$valeurs = null;
576
-
577
-	$src = extraire_attribut($img, 'src');
578
-
579
-	if (!$src) {
580
-		$src = $img;
581
-	} else {
582
-		$srcWidth = extraire_attribut($img, 'width');
583
-		$srcHeight = extraire_attribut($img, 'height');
584
-		if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) {
585
-			$srcWidth = $srcHeight = 0;
586
-		}
587
-	}
588
-
589
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
590
-	// la copie locale a toutes les chances d'etre la ou de resservir
591
-	if (tester_url_absolue($src)) {
592
-		include_spip('inc/distant');
593
-		$fichier = copie_locale($src);
594
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
595
-	}
596
-	if (($p = strpos($src, '?')) !== false) {
597
-		$src = substr($src, 0, $p);
598
-	}
599
-
600
-	$imagesize = false;
601
-	if (isset($largeur_img[$src]) && !$force_refresh) {
602
-		$srcWidth = $largeur_img[$src];
603
-	}
604
-	if (isset($hauteur_img[$src]) && !$force_refresh) {
605
-		$srcHeight = $hauteur_img[$src];
606
-	}
607
-	if (isset($poids_img[$src]) && !$force_refresh) {
608
-		$srcSize = $poids_img[$src];
609
-	}
610
-	if (!$srcWidth || !$srcHeight || is_null($srcSize)) {
611
-		if (
612
-			file_exists($src) && ($imagesize = spip_getimagesize($src))
613
-		) {
614
-			if (!$srcWidth) {
615
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
616
-			}
617
-			if (!$srcHeight) {
618
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
619
-			}
620
-			if (!$srcSize) {
621
-				$poids_img[$src] = filesize($src);
622
-			}
623
-		}
624
-		elseif (str_contains($src, '<svg')) {
625
-			include_spip('inc/svg');
626
-			if ($attrs = svg_lire_attributs($src)) {
627
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
628
-				if (!$srcWidth) {
629
-					$largeur_img[$src] = $srcWidth = $width;
630
-				}
631
-				if (!$srcHeight) {
632
-					$hauteur_img[$src] = $srcHeight = $height;
633
-				}
634
-				if (!$srcSize) {
635
-					$poids_img[$src] = $srcSize = strlen($src);
636
-				}
637
-			}
638
-		}
639
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
640
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
641
-		elseif (
642
-			@file_exists($f = "$src.src")
643
-			&& lire_fichier($f, $valeurs)
644
-			&& ($valeurs = unserialize($valeurs))
645
-		) {
646
-			if (!$srcWidth) {
647
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
648
-			}
649
-			if (!$srcHeight) {
650
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
651
-			}
652
-			if (!$srcSize) {
653
-				$poids_img[$src] = $srcSize = 0;
654
-			}
655
-		}
656
-	}
657
-
658
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
571
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
572
+    $srcWidth = 0;
573
+    $srcHeight = 0;
574
+    $srcSize = null;
575
+    $valeurs = null;
576
+
577
+    $src = extraire_attribut($img, 'src');
578
+
579
+    if (!$src) {
580
+        $src = $img;
581
+    } else {
582
+        $srcWidth = extraire_attribut($img, 'width');
583
+        $srcHeight = extraire_attribut($img, 'height');
584
+        if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) {
585
+            $srcWidth = $srcHeight = 0;
586
+        }
587
+    }
588
+
589
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
590
+    // la copie locale a toutes les chances d'etre la ou de resservir
591
+    if (tester_url_absolue($src)) {
592
+        include_spip('inc/distant');
593
+        $fichier = copie_locale($src);
594
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
595
+    }
596
+    if (($p = strpos($src, '?')) !== false) {
597
+        $src = substr($src, 0, $p);
598
+    }
599
+
600
+    $imagesize = false;
601
+    if (isset($largeur_img[$src]) && !$force_refresh) {
602
+        $srcWidth = $largeur_img[$src];
603
+    }
604
+    if (isset($hauteur_img[$src]) && !$force_refresh) {
605
+        $srcHeight = $hauteur_img[$src];
606
+    }
607
+    if (isset($poids_img[$src]) && !$force_refresh) {
608
+        $srcSize = $poids_img[$src];
609
+    }
610
+    if (!$srcWidth || !$srcHeight || is_null($srcSize)) {
611
+        if (
612
+            file_exists($src) && ($imagesize = spip_getimagesize($src))
613
+        ) {
614
+            if (!$srcWidth) {
615
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
616
+            }
617
+            if (!$srcHeight) {
618
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
619
+            }
620
+            if (!$srcSize) {
621
+                $poids_img[$src] = filesize($src);
622
+            }
623
+        }
624
+        elseif (str_contains($src, '<svg')) {
625
+            include_spip('inc/svg');
626
+            if ($attrs = svg_lire_attributs($src)) {
627
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
628
+                if (!$srcWidth) {
629
+                    $largeur_img[$src] = $srcWidth = $width;
630
+                }
631
+                if (!$srcHeight) {
632
+                    $hauteur_img[$src] = $srcHeight = $height;
633
+                }
634
+                if (!$srcSize) {
635
+                    $poids_img[$src] = $srcSize = strlen($src);
636
+                }
637
+            }
638
+        }
639
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
640
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
641
+        elseif (
642
+            @file_exists($f = "$src.src")
643
+            && lire_fichier($f, $valeurs)
644
+            && ($valeurs = unserialize($valeurs))
645
+        ) {
646
+            if (!$srcWidth) {
647
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
648
+            }
649
+            if (!$srcHeight) {
650
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
651
+            }
652
+            if (!$srcSize) {
653
+                $poids_img[$src] = $srcSize = 0;
654
+            }
655
+        }
656
+    }
657
+
658
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
659 659
 }
660 660
 
661 661
 /**
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
  *     poids
672 672
  **/
673 673
 function poids_image($img, $force_refresh = false) {
674
-	$infos = infos_image($img, $force_refresh);
675
-	return $infos['poids'];
674
+    $infos = infos_image($img, $force_refresh);
675
+    return $infos['poids'];
676 676
 }
677 677
 
678 678
 function taille_image($img, $force_refresh = false) {
679
-	$infos = infos_image($img, $force_refresh);
680
-	return [$infos['hauteur'], $infos['largeur']];
679
+    $infos = infos_image($img, $force_refresh);
680
+    return [$infos['hauteur'], $infos['largeur']];
681 681
 }
682 682
 
683 683
 /**
@@ -694,12 +694,12 @@  discard block
 block discarded – undo
694 694
  *     Largeur en pixels, NULL ou 0 si aucune image.
695 695
  **/
696 696
 function largeur($img) {
697
-	if (!$img) {
698
-		return;
699
-	}
700
-	[$h, $l] = taille_image($img);
697
+    if (!$img) {
698
+        return;
699
+    }
700
+    [$h, $l] = taille_image($img);
701 701
 
702
-	return $l;
702
+    return $l;
703 703
 }
704 704
 
705 705
 /**
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
  *     Hauteur en pixels, NULL ou 0 si aucune image.
717 717
  **/
718 718
 function hauteur($img) {
719
-	if (!$img) {
720
-		return;
721
-	}
722
-	[$h, $l] = taille_image($img);
719
+    if (!$img) {
720
+        return;
721
+    }
722
+    [$h, $l] = taille_image($img);
723 723
 
724
-	return $h;
724
+    return $h;
725 725
 }
726 726
 
727 727
 
@@ -741,11 +741,11 @@  discard block
 block discarded – undo
741 741
  * @return string
742 742
  **/
743 743
 function corriger_entites_html($texte) {
744
-	if (!str_contains($texte, '&amp;')) {
745
-		return $texte;
746
-	}
744
+    if (!str_contains($texte, '&amp;')) {
745
+        return $texte;
746
+    }
747 747
 
748
-	return preg_replace(',&amp;(#\d\d\d+;|amp;),iS', '&\1', $texte);
748
+    return preg_replace(',&amp;(#\d\d\d+;|amp;),iS', '&\1', $texte);
749 749
 }
750 750
 
751 751
 /**
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
  * @return string
761 761
  **/
762 762
 function corriger_toutes_entites_html($texte) {
763
-	if (!str_contains($texte, '&amp;')) {
764
-		return $texte;
765
-	}
763
+    if (!str_contains($texte, '&amp;')) {
764
+        return $texte;
765
+    }
766 766
 
767
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
767
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
768 768
 }
769 769
 
770 770
 /**
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
  * @return string
775 775
  **/
776 776
 function proteger_amp($texte) {
777
-	return str_replace('&', '&amp;', $texte);
777
+    return str_replace('&', '&amp;', $texte);
778 778
 }
779 779
 
780 780
 
@@ -805,20 +805,20 @@  discard block
 block discarded – undo
805 805
  * @return mixed|string
806 806
  */
807 807
 function entites_html($texte, $tout = false, $quote = true) {
808
-	if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) {
809
-		return $texte;
810
-	}
811
-	include_spip('inc/texte');
812
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
-	$flags |= ENT_HTML401;
814
-	$texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
815
-	$texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte, '', 'proteger_amp');
816
-	$texte = spip_htmlspecialchars($texte, $flags);
817
-	if ($tout) {
818
-		return corriger_toutes_entites_html($texte);
819
-	} else {
820
-		return corriger_entites_html($texte);
821
-	}
808
+    if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) {
809
+        return $texte;
810
+    }
811
+    include_spip('inc/texte');
812
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
+    $flags |= ENT_HTML401;
814
+    $texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
815
+    $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte, '', 'proteger_amp');
816
+    $texte = spip_htmlspecialchars($texte, $flags);
817
+    if ($tout) {
818
+        return corriger_toutes_entites_html($texte);
819
+    } else {
820
+        return corriger_entites_html($texte);
821
+    }
822 822
 }
823 823
 
824 824
 /**
@@ -837,38 +837,38 @@  discard block
 block discarded – undo
837 837
  *     texte converti
838 838
  **/
839 839
 function filtrer_entites(?string $texte): string {
840
-	$texte ??= '';
841
-	if (!str_contains($texte, '&')) {
842
-		return $texte;
843
-	}
844
-	// filtrer
845
-	$texte = html2unicode($texte);
846
-	// remettre le tout dans le charset cible
847
-	$texte = unicode2charset($texte);
848
-	// cas particulier des " et ' qu'il faut filtrer aussi
849
-	// (on le faisait deja avec un &quot;)
850
-	if (str_contains($texte, '&#')) {
851
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
852
-	}
840
+    $texte ??= '';
841
+    if (!str_contains($texte, '&')) {
842
+        return $texte;
843
+    }
844
+    // filtrer
845
+    $texte = html2unicode($texte);
846
+    // remettre le tout dans le charset cible
847
+    $texte = unicode2charset($texte);
848
+    // cas particulier des " et ' qu'il faut filtrer aussi
849
+    // (on le faisait deja avec un &quot;)
850
+    if (str_contains($texte, '&#')) {
851
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
852
+    }
853 853
 
854
-	return $texte;
854
+    return $texte;
855 855
 }
856 856
 
857 857
 
858 858
 if (!function_exists('filtre_filtrer_entites_dist')) {
859
-	/**
860
-	 * Version sécurisée de filtrer_entites
861
-	 *
862
-	 * @uses interdire_scripts()
863
-	 * @uses filtrer_entites()
864
-	 *
865
-	 * @param string $t
866
-	 * @return string
867
-	 */
868
-	function filtre_filtrer_entites_dist($t) {
869
-		include_spip('inc/texte');
870
-		return interdire_scripts(filtrer_entites($t));
871
-	}
859
+    /**
860
+     * Version sécurisée de filtrer_entites
861
+     *
862
+     * @uses interdire_scripts()
863
+     * @uses filtrer_entites()
864
+     *
865
+     * @param string $t
866
+     * @return string
867
+     */
868
+    function filtre_filtrer_entites_dist($t) {
869
+        include_spip('inc/texte');
870
+        return interdire_scripts(filtrer_entites($t));
871
+    }
872 872
 }
873 873
 
874 874
 
@@ -883,18 +883,18 @@  discard block
 block discarded – undo
883 883
  * @return string|array
884 884
  **/
885 885
 function supprimer_caracteres_illegaux($texte) {
886
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
887
-	static $to = null;
886
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
887
+    static $to = null;
888 888
 
889
-	if (is_array($texte)) {
890
-		return array_map('supprimer_caracteres_illegaux', $texte);
891
-	}
889
+    if (is_array($texte)) {
890
+        return array_map('supprimer_caracteres_illegaux', $texte);
891
+    }
892 892
 
893
-	if (!$to) {
894
-		$to = str_repeat('-', strlen((string) $from));
895
-	}
893
+    if (!$to) {
894
+        $to = str_repeat('-', strlen((string) $from));
895
+    }
896 896
 
897
-	return strtr($texte, $from, $to);
897
+    return strtr($texte, $from, $to);
898 898
 }
899 899
 
900 900
 /**
@@ -906,9 +906,9 @@  discard block
 block discarded – undo
906 906
  * @return string|array
907 907
  **/
908 908
 function corriger_caracteres($texte) {
909
-	$texte = corriger_caracteres_windows($texte);
909
+    $texte = corriger_caracteres_windows($texte);
910 910
 
911
-	return supprimer_caracteres_illegaux($texte);
911
+    return supprimer_caracteres_illegaux($texte);
912 912
 }
913 913
 
914 914
 /**
@@ -925,44 +925,44 @@  discard block
 block discarded – undo
925 925
  *     texte encodé pour XML
926 926
  */
927 927
 function texte_backend(?string $texte): string {
928
-	if ($texte === null || $texte === '') {
929
-		return '';
930
-	}
928
+    if ($texte === null || $texte === '') {
929
+        return '';
930
+    }
931 931
 
932
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
932
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
933 933
 
934
-	// si on a des liens ou des images, les passer en absolu
935
-	$texte = liens_absolus($texte);
934
+    // si on a des liens ou des images, les passer en absolu
935
+    $texte = liens_absolus($texte);
936 936
 
937
-	// echapper les tags &gt; &lt;
938
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
937
+    // echapper les tags &gt; &lt;
938
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
939 939
 
940
-	// importer les &eacute;
941
-	$texte = filtrer_entites($texte);
940
+    // importer les &eacute;
941
+    $texte = filtrer_entites($texte);
942 942
 
943
-	// " -> &quot; et tout ce genre de choses
944
-	$u = $GLOBALS['meta']['pcre_u'];
945
-	$texte = str_replace('&nbsp;', ' ', $texte);
946
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
947
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
948
-	$texte = entites_html($texte, false, false);
949
-	// mais bien echapper les double quotes !
950
-	$texte = str_replace('"', '&#034;', (string) $texte);
943
+    // " -> &quot; et tout ce genre de choses
944
+    $u = $GLOBALS['meta']['pcre_u'];
945
+    $texte = str_replace('&nbsp;', ' ', $texte);
946
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
947
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
948
+    $texte = entites_html($texte, false, false);
949
+    // mais bien echapper les double quotes !
950
+    $texte = str_replace('"', '&#034;', (string) $texte);
951 951
 
952
-	// verifier le charset
953
-	$texte = charset2unicode($texte);
952
+    // verifier le charset
953
+    $texte = charset2unicode($texte);
954 954
 
955
-	// Caracteres problematiques en iso-latin 1
956
-	if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') {
957
-		$texte = str_replace(chr(156), '&#156;', $texte);
958
-		$texte = str_replace(chr(140), '&#140;', $texte);
959
-		$texte = str_replace(chr(159), '&#159;', $texte);
960
-	}
955
+    // Caracteres problematiques en iso-latin 1
956
+    if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') {
957
+        $texte = str_replace(chr(156), '&#156;', $texte);
958
+        $texte = str_replace(chr(140), '&#140;', $texte);
959
+        $texte = str_replace(chr(159), '&#159;', $texte);
960
+    }
961 961
 
962
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
963
-	// et le caractere apostrophe alourdit les squelettes avec PHP
964
-	// ==> on les remplace par l'entite HTML
965
-	return str_replace($apostrophe, "'", $texte);
962
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
963
+    // et le caractere apostrophe alourdit les squelettes avec PHP
964
+    // ==> on les remplace par l'entite HTML
965
+    return str_replace($apostrophe, "'", $texte);
966 966
 }
967 967
 
968 968
 /**
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
  *     texte encodé et quote pour XML
980 980
  */
981 981
 function texte_backendq(?string $texte): string {
982
-	return addslashes(texte_backend($texte));
982
+    return addslashes(texte_backend($texte));
983 983
 }
984 984
 
985 985
 
@@ -1001,14 +1001,14 @@  discard block
 block discarded – undo
1001 1001
  *     Texte sans son numéro éventuel
1002 1002
  **/
1003 1003
 function supprimer_numero(?string $texte): string {
1004
-	if ($texte === null || $texte === '') {
1005
-		return '';
1006
-	}
1007
-	return preg_replace(
1008
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1009
-		'',
1010
-		$texte
1011
-	);
1004
+    if ($texte === null || $texte === '') {
1005
+        return '';
1006
+    }
1007
+    return preg_replace(
1008
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1009
+        '',
1010
+        $texte
1011
+    );
1012 1012
 }
1013 1013
 
1014 1014
 /**
@@ -1031,19 +1031,19 @@  discard block
 block discarded – undo
1031 1031
  *     Numéro de titre, sinon chaîne vide
1032 1032
  **/
1033 1033
 function recuperer_numero(?string $texte): string {
1034
-	if ($texte === null || $texte === '') {
1035
-		return '';
1036
-	}
1037
-	if (preg_match(
1038
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1039
-			$texte,
1040
-			$regs
1041
-		)
1042
-	) {
1043
-		return (string) $regs[1];
1044
-	}
1034
+    if ($texte === null || $texte === '') {
1035
+        return '';
1036
+    }
1037
+    if (preg_match(
1038
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1039
+            $texte,
1040
+            $regs
1041
+        )
1042
+    ) {
1043
+        return (string) $regs[1];
1044
+    }
1045 1045
 
1046
-	return '';
1046
+    return '';
1047 1047
 }
1048 1048
 
1049 1049
 /**
@@ -1070,16 +1070,16 @@  discard block
 block discarded – undo
1070 1070
  *     texte ou tableau de textes converti
1071 1071
  **/
1072 1072
 function supprimer_tags($texte, $rempl = '') {
1073
-	if ($texte === null || $texte === '') {
1074
-		return '';
1075
-	}
1076
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1077
-	// ne pas oublier un < final non ferme car coupe
1078
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1079
-	// mais qui peut aussi etre un simple signe plus petit que
1080
-	$texte = str_replace('<', '&lt;', $texte);
1073
+    if ($texte === null || $texte === '') {
1074
+        return '';
1075
+    }
1076
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1077
+    // ne pas oublier un < final non ferme car coupe
1078
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1079
+    // mais qui peut aussi etre un simple signe plus petit que
1080
+    $texte = str_replace('<', '&lt;', $texte);
1081 1081
 
1082
-	return $texte;
1082
+    return $texte;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
  *     texte converti
1103 1103
  **/
1104 1104
 function echapper_tags($texte, $rempl = '') {
1105
-	return preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1105
+    return preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1106 1106
 }
1107 1107
 
1108 1108
 /**
@@ -1123,21 +1123,21 @@  discard block
 block discarded – undo
1123 1123
  *     texte converti
1124 1124
  **/
1125 1125
 function textebrut($texte) {
1126
-	if ($texte === null || $texte === '') {
1127
-		return '';
1128
-	}
1129
-	$u = $GLOBALS['meta']['pcre_u'];
1130
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1131
-	$texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte);
1132
-	$texte = preg_replace("/^\n+/", '', $texte);
1133
-	$texte = preg_replace("/\n+$/", '', $texte);
1134
-	$texte = preg_replace("/\n +/", "\n", $texte);
1135
-	$texte = supprimer_tags($texte);
1136
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1137
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1138
-	$texte = str_replace('&#8217;', "'", $texte);
1126
+    if ($texte === null || $texte === '') {
1127
+        return '';
1128
+    }
1129
+    $u = $GLOBALS['meta']['pcre_u'];
1130
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1131
+    $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte);
1132
+    $texte = preg_replace("/^\n+/", '', $texte);
1133
+    $texte = preg_replace("/\n+$/", '', $texte);
1134
+    $texte = preg_replace("/\n +/", "\n", $texte);
1135
+    $texte = supprimer_tags($texte);
1136
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1137
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1138
+    $texte = str_replace('&#8217;', "'", $texte);
1139 1139
 
1140
-	return $texte;
1140
+    return $texte;
1141 1141
 }
1142 1142
 
1143 1143
 
@@ -1153,26 +1153,26 @@  discard block
 block discarded – undo
1153 1153
  *     texte avec liens ouvrants
1154 1154
  **/
1155 1155
 function liens_ouvrants($texte) {
1156
-	if ($texte === null || $texte === '') {
1157
-		return '';
1158
-	}
1159
-	if (
1160
-		preg_match_all(
1161
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1162
-			$texte,
1163
-			$liens,
1164
-			PREG_PATTERN_ORDER
1165
-		)
1166
-	) {
1167
-		foreach ($liens[0] as $a) {
1168
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1169
-			$ablank = inserer_attribut($a, 'rel', $rel);
1170
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1171
-			$texte = str_replace($a, $ablank, $texte);
1172
-		}
1173
-	}
1174
-
1175
-	return $texte;
1156
+    if ($texte === null || $texte === '') {
1157
+        return '';
1158
+    }
1159
+    if (
1160
+        preg_match_all(
1161
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1162
+            $texte,
1163
+            $liens,
1164
+            PREG_PATTERN_ORDER
1165
+        )
1166
+    ) {
1167
+        foreach ($liens[0] as $a) {
1168
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1169
+            $ablank = inserer_attribut($a, 'rel', $rel);
1170
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1171
+            $texte = str_replace($a, $ablank, $texte);
1172
+        }
1173
+    }
1174
+
1175
+    return $texte;
1176 1176
 }
1177 1177
 
1178 1178
 /**
@@ -1182,25 +1182,25 @@  discard block
 block discarded – undo
1182 1182
  * @return string
1183 1183
  */
1184 1184
 function liens_nofollow($texte) {
1185
-	if ($texte === null || $texte === '') {
1186
-		return '';
1187
-	}
1188
-	if (stripos($texte, '<a') === false) {
1189
-		return $texte;
1190
-	}
1185
+    if ($texte === null || $texte === '') {
1186
+        return '';
1187
+    }
1188
+    if (stripos($texte, '<a') === false) {
1189
+        return $texte;
1190
+    }
1191 1191
 
1192
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1193
-		foreach ($regs[0] as $a) {
1194
-			$rel = extraire_attribut($a, 'rel') ?? '';
1195
-			if (!str_contains($rel, 'nofollow')) {
1196
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1197
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1198
-				$texte = str_replace($a, $anofollow, $texte);
1199
-			}
1200
-		}
1201
-	}
1192
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1193
+        foreach ($regs[0] as $a) {
1194
+            $rel = extraire_attribut($a, 'rel') ?? '';
1195
+            if (!str_contains($rel, 'nofollow')) {
1196
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1197
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1198
+                $texte = str_replace($a, $anofollow, $texte);
1199
+            }
1200
+        }
1201
+    }
1202 1202
 
1203
-	return $texte;
1203
+    return $texte;
1204 1204
 }
1205 1205
 
1206 1206
 /**
@@ -1219,14 +1219,14 @@  discard block
 block discarded – undo
1219 1219
  *     texte sans paraghaphes
1220 1220
  **/
1221 1221
 function PtoBR($texte) {
1222
-	if ($texte === null || $texte === '') {
1223
-		return '';
1224
-	}
1225
-	$u = $GLOBALS['meta']['pcre_u'];
1226
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1227
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1222
+    if ($texte === null || $texte === '') {
1223
+        return '';
1224
+    }
1225
+    $u = $GLOBALS['meta']['pcre_u'];
1226
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1227
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1228 1228
 
1229
-	return preg_replace('@^\s*<br />@S' . $u, '', $texte);
1229
+    return preg_replace('@^\s*<br />@S' . $u, '', $texte);
1230 1230
 }
1231 1231
 
1232 1232
 /**
@@ -1245,30 +1245,30 @@  discard block
 block discarded – undo
1245 1245
  * @return string texte en majuscule
1246 1246
  */
1247 1247
 function majuscules($texte) {
1248
-	if ($texte === null || $texte === '') {
1249
-		return '';
1250
-	}
1248
+    if ($texte === null || $texte === '') {
1249
+        return '';
1250
+    }
1251 1251
 
1252
-	// Cas du turc
1253
-	if ($GLOBALS['spip_lang'] == 'tr') {
1254
-		# remplacer hors des tags et des entites
1255
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1256
-			foreach ($regs as $n => $match) {
1257
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1258
-			}
1259
-		}
1252
+    // Cas du turc
1253
+    if ($GLOBALS['spip_lang'] == 'tr') {
1254
+        # remplacer hors des tags et des entites
1255
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1256
+            foreach ($regs as $n => $match) {
1257
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1258
+            }
1259
+        }
1260 1260
 
1261
-		$texte = str_replace('i', '&#304;', $texte);
1261
+        $texte = str_replace('i', '&#304;', $texte);
1262 1262
 
1263
-		if ($regs) {
1264
-			foreach ($regs as $n => $match) {
1265
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1266
-			}
1267
-		}
1268
-	}
1263
+        if ($regs) {
1264
+            foreach ($regs as $n => $match) {
1265
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1266
+            }
1267
+        }
1268
+    }
1269 1269
 
1270
-	// Cas general
1271
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1270
+    // Cas general
1271
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1272 1272
 }
1273 1273
 
1274 1274
 /**
@@ -1290,38 +1290,38 @@  discard block
 block discarded – undo
1290 1290
  */
1291 1291
 function taille_en_octets($octets, $systeme = 'BI') {
1292 1292
 
1293
-	// Texte à afficher pour la taille
1294
-	$affichage = '';
1293
+    // Texte à afficher pour la taille
1294
+    $affichage = '';
1295 1295
 
1296
-	static $unites = ['octets', 'ko', 'mo', 'go'];
1297
-	static $precisions = [0, 1, 1, 2];
1296
+    static $unites = ['octets', 'ko', 'mo', 'go'];
1297
+    static $precisions = [0, 1, 1, 2];
1298 1298
 
1299
-	if ($octets >= 1) {
1300
-		// Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1301
-		$systeme = strtolower($systeme);
1302
-		if ($systeme === 'bi') {
1303
-			$kilo = 1024;
1304
-			$suffixe_item = "_$systeme";
1305
-		} elseif ($systeme === 'si') {
1306
-			$kilo = 1000;
1307
-			$suffixe_item = '';
1308
-		} else {
1309
-			return $affichage;
1310
-		}
1299
+    if ($octets >= 1) {
1300
+        // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1301
+        $systeme = strtolower($systeme);
1302
+        if ($systeme === 'bi') {
1303
+            $kilo = 1024;
1304
+            $suffixe_item = "_$systeme";
1305
+        } elseif ($systeme === 'si') {
1306
+            $kilo = 1000;
1307
+            $suffixe_item = '';
1308
+        } else {
1309
+            return $affichage;
1310
+        }
1311 1311
 
1312
-		// Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1313
-		$puissance = floor(log($octets, $kilo));
1312
+        // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1313
+        $puissance = floor(log($octets, $kilo));
1314 1314
 
1315
-		// Calcul de la taille et choix de l'unité
1316
-		$affichage = _T(
1317
-			'spip:taille_' . $unites[$puissance] . $suffixe_item,
1318
-			[
1319
-				'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance])
1320
-			]
1321
-		);
1322
-	}
1315
+        // Calcul de la taille et choix de l'unité
1316
+        $affichage = _T(
1317
+            'spip:taille_' . $unites[$puissance] . $suffixe_item,
1318
+            [
1319
+                'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance])
1320
+            ]
1321
+        );
1322
+    }
1323 1323
 
1324
-	return $affichage;
1324
+    return $affichage;
1325 1325
 }
1326 1326
 
1327 1327
 
@@ -1343,21 +1343,21 @@  discard block
 block discarded – undo
1343 1343
  *     texte prêt pour être utilisé en attribut HTML
1344 1344
  **/
1345 1345
 function attribut_html(?string $texte, $textebrut = true): string {
1346
-	if ($texte === null || $texte === '') {
1347
-		return '';
1348
-	}
1349
-	$u = $GLOBALS['meta']['pcre_u'];
1350
-	if ($textebrut) {
1351
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1352
-	}
1353
-	$texte = texte_backend($texte);
1354
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1346
+    if ($texte === null || $texte === '') {
1347
+        return '';
1348
+    }
1349
+    $u = $GLOBALS['meta']['pcre_u'];
1350
+    if ($textebrut) {
1351
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1352
+    }
1353
+    $texte = texte_backend($texte);
1354
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1355 1355
 
1356
-	return preg_replace(
1357
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1358
-		['&', '&#38;'],
1359
-		$texte
1360
-	);
1356
+    return preg_replace(
1357
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1358
+        ['&', '&#38;'],
1359
+        $texte
1360
+    );
1361 1361
 }
1362 1362
 
1363 1363
 
@@ -1377,15 +1377,15 @@  discard block
 block discarded – undo
1377 1377
  *     URL ou chaîne vide
1378 1378
  **/
1379 1379
 function vider_url(?string $url, $entites = true): string {
1380
-	if ($url === null || $url === '') {
1381
-		return '';
1382
-	}
1383
-	# un message pour abs_url
1384
-	$GLOBALS['mode_abs_url'] = 'url';
1385
-	$url = trim($url);
1386
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1380
+    if ($url === null || $url === '') {
1381
+        return '';
1382
+    }
1383
+    # un message pour abs_url
1384
+    $GLOBALS['mode_abs_url'] = 'url';
1385
+    $url = trim($url);
1386
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1387 1387
 
1388
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1388
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1389 1389
 }
1390 1390
 
1391 1391
 
@@ -1400,10 +1400,10 @@  discard block
 block discarded – undo
1400 1400
  * @return string Adresse email maquillée
1401 1401
  **/
1402 1402
 function antispam($texte) {
1403
-	include_spip('inc/acces');
1404
-	$masque = creer_pass_aleatoire(3);
1403
+    include_spip('inc/acces');
1404
+    $masque = creer_pass_aleatoire(3);
1405 1405
 
1406
-	return preg_replace('/@/', " $masque ", $texte);
1406
+    return preg_replace('/@/', " $masque ", $texte);
1407 1407
 }
1408 1408
 
1409 1409
 /**
@@ -1435,8 +1435,8 @@  discard block
 block discarded – undo
1435 1435
  *     True si on a le droit d'accès, false sinon.
1436 1436
  **/
1437 1437
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1438
-	include_spip('inc/acces');
1439
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1438
+    include_spip('inc/acces');
1439
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1440 1440
 }
1441 1441
 
1442 1442
 /**
@@ -1460,13 +1460,13 @@  discard block
 block discarded – undo
1460 1460
  *     Retourne $texte, sinon $sinon.
1461 1461
  **/
1462 1462
 function sinon(mixed $texte, mixed $sinon = '') {
1463
-	if ($texte) {
1464
-		return $texte;
1465
-	} elseif (is_scalar($texte) && strlen($texte)) {
1466
-		return $texte;
1467
-	}
1463
+    if ($texte) {
1464
+        return $texte;
1465
+    } elseif (is_scalar($texte) && strlen($texte)) {
1466
+        return $texte;
1467
+    }
1468 1468
 
1469
-	return $sinon;
1469
+    return $sinon;
1470 1470
 }
1471 1471
 
1472 1472
 /**
@@ -1490,7 +1490,7 @@  discard block
 block discarded – undo
1490 1490
  * @return mixed
1491 1491
  **/
1492 1492
 function choixsivide(mixed $a, mixed $vide, mixed $pasvide) {
1493
-	return $a ? $pasvide : $vide;
1493
+    return $a ? $pasvide : $vide;
1494 1494
 }
1495 1495
 
1496 1496
 /**
@@ -1514,7 +1514,7 @@  discard block
 block discarded – undo
1514 1514
  * @return mixed
1515 1515
  **/
1516 1516
 function choixsiegal(mixed $a1, mixed $a2, mixed $v, mixed $f) {
1517
-	return ($a1 == $a2) ? $v : $f;
1517
+    return ($a1 == $a2) ? $v : $f;
1518 1518
 }
1519 1519
 
1520 1520
 //
@@ -1533,15 +1533,15 @@  discard block
 block discarded – undo
1533 1533
  * @return string
1534 1534
  **/
1535 1535
 function filtrer_ical($texte) {
1536
-	if ($texte === null || $texte === '') {
1537
-		return '';
1538
-	}
1539
-	#include_spip('inc/charsets');
1540
-	$texte = html2unicode($texte);
1541
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1542
-	$texte = preg_replace("/\n/", ' ', $texte);
1536
+    if ($texte === null || $texte === '') {
1537
+        return '';
1538
+    }
1539
+    #include_spip('inc/charsets');
1540
+    $texte = html2unicode($texte);
1541
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1542
+    $texte = preg_replace("/\n/", ' ', $texte);
1543 1543
 
1544
-	return preg_replace('/,/', '\,', $texte);
1544
+    return preg_replace('/,/', '\,', $texte);
1545 1545
 }
1546 1546
 
1547 1547
 
@@ -1566,56 +1566,56 @@  discard block
 block discarded – undo
1566 1566
  * @return string
1567 1567
  **/
1568 1568
 function post_autobr($texte, $delim = "\n_ ") {
1569
-	if (!function_exists('echappe_html')) {
1570
-		include_spip('inc/texte_mini');
1571
-	}
1572
-	$texte = str_replace("\r\n", "\r", $texte);
1573
-	$texte = str_replace("\r", "\n", $texte);
1574
-
1575
-	if (preg_match(",\n+$,", $texte, $fin)) {
1576
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1577
-	} else {
1578
-		$fin = '';
1579
-	}
1580
-
1581
-	$texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
1582
-
1583
-	// echapper les modeles
1584
-	$collecteurModeles = null;
1585
-	if (str_contains($texte, '<')) {
1586
-		$collecteurModeles = new CollecteurModeles();
1587
-		$texte = $collecteurModeles->echapper($texte);
1588
-	}
1589
-
1590
-	$debut = '';
1591
-	$suite = $texte;
1592
-	while ($t = strpos((string) ('-' . $suite), "\n", 1)) {
1593
-		$debut .= substr($suite, 0, $t - 1);
1594
-		$suite = substr($suite, $t);
1595
-		$car = substr($suite, 0, 1);
1596
-		if (
1597
-			$car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}'
1598
-			&& !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1599
-			&& !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1600
-		) {
1601
-			$debut .= $delim;
1602
-		} else {
1603
-			$debut .= "\n";
1604
-		}
1605
-		if (preg_match(",^\n+,", $suite, $regs)) {
1606
-			$debut .= $regs[0];
1607
-			$suite = substr($suite, strlen($regs[0]));
1608
-		}
1609
-	}
1610
-	$texte = $debut . $suite;
1611
-
1612
-	if ($collecteurModeles) {
1613
-		$texte = $collecteurModeles->retablir($texte);
1614
-	}
1615
-
1616
-	$texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte);
1617
-
1618
-	return $texte . $fin;
1569
+    if (!function_exists('echappe_html')) {
1570
+        include_spip('inc/texte_mini');
1571
+    }
1572
+    $texte = str_replace("\r\n", "\r", $texte);
1573
+    $texte = str_replace("\r", "\n", $texte);
1574
+
1575
+    if (preg_match(",\n+$,", $texte, $fin)) {
1576
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1577
+    } else {
1578
+        $fin = '';
1579
+    }
1580
+
1581
+    $texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
1582
+
1583
+    // echapper les modeles
1584
+    $collecteurModeles = null;
1585
+    if (str_contains($texte, '<')) {
1586
+        $collecteurModeles = new CollecteurModeles();
1587
+        $texte = $collecteurModeles->echapper($texte);
1588
+    }
1589
+
1590
+    $debut = '';
1591
+    $suite = $texte;
1592
+    while ($t = strpos((string) ('-' . $suite), "\n", 1)) {
1593
+        $debut .= substr($suite, 0, $t - 1);
1594
+        $suite = substr($suite, $t);
1595
+        $car = substr($suite, 0, 1);
1596
+        if (
1597
+            $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}'
1598
+            && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1599
+            && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1600
+        ) {
1601
+            $debut .= $delim;
1602
+        } else {
1603
+            $debut .= "\n";
1604
+        }
1605
+        if (preg_match(",^\n+,", $suite, $regs)) {
1606
+            $debut .= $regs[0];
1607
+            $suite = substr($suite, strlen($regs[0]));
1608
+        }
1609
+    }
1610
+    $texte = $debut . $suite;
1611
+
1612
+    if ($collecteurModeles) {
1613
+        $texte = $collecteurModeles->retablir($texte);
1614
+    }
1615
+
1616
+    $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte);
1617
+
1618
+    return $texte . $fin;
1619 1619
 }
1620 1620
 
1621 1621
 
@@ -1648,25 +1648,25 @@  discard block
 block discarded – undo
1648 1648
  **/
1649 1649
 function extraire_idiome($letexte, $lang = null, $options = []) {
1650 1650
 
1651
-	if ($letexte && str_contains($letexte, '<:')) {
1652
-		if (!$lang) {
1653
-			$lang = $GLOBALS['spip_lang'];
1654
-		}
1655
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1656
-		if (is_bool($options)) {
1657
-			trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1658
-			$options = ['echappe_span' => $options];
1659
-		}
1660
-		if (!isset($options['echappe_span'])) {
1661
-			$options = array_merge($options, ['echappe_span' => false]);
1662
-		}
1663
-		$options['lang'] = $lang;
1651
+    if ($letexte && str_contains($letexte, '<:')) {
1652
+        if (!$lang) {
1653
+            $lang = $GLOBALS['spip_lang'];
1654
+        }
1655
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1656
+        if (is_bool($options)) {
1657
+            trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1658
+            $options = ['echappe_span' => $options];
1659
+        }
1660
+        if (!isset($options['echappe_span'])) {
1661
+            $options = array_merge($options, ['echappe_span' => false]);
1662
+        }
1663
+        $options['lang'] = $lang;
1664 1664
 
1665
-		$collecteurIdiomes = new CollecteurIdiomes();
1665
+        $collecteurIdiomes = new CollecteurIdiomes();
1666 1666
 
1667
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1668
-	}
1669
-	return $letexte;
1667
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1668
+    }
1669
+    return $letexte;
1670 1670
 }
1671 1671
 
1672 1672
 /**
@@ -1704,30 +1704,30 @@  discard block
 block discarded – undo
1704 1704
  **/
1705 1705
 function extraire_multi($letexte, $lang = null, $options = []) {
1706 1706
 
1707
-	if ($letexte && stripos($letexte, '<multi') !== false) {
1708
-		if (!$lang) {
1709
-			$lang = $GLOBALS['spip_lang'];
1710
-		}
1707
+    if ($letexte && stripos($letexte, '<multi') !== false) {
1708
+        if (!$lang) {
1709
+            $lang = $GLOBALS['spip_lang'];
1710
+        }
1711 1711
 
1712
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1713
-		if (is_bool($options)) {
1714
-			trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1715
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1716
-		}
1717
-		if (!isset($options['echappe_span'])) {
1718
-			$options = array_merge($options, ['echappe_span' => false]);
1719
-		}
1720
-		if (!isset($options['lang_defaut'])) {
1721
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1722
-		}
1723
-		$options['lang'] = $lang;
1712
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1713
+        if (is_bool($options)) {
1714
+            trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1715
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1716
+        }
1717
+        if (!isset($options['echappe_span'])) {
1718
+            $options = array_merge($options, ['echappe_span' => false]);
1719
+        }
1720
+        if (!isset($options['lang_defaut'])) {
1721
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1722
+        }
1723
+        $options['lang'] = $lang;
1724 1724
 
1725
-		$collecteurMultis = new CollecteurMultis();
1725
+        $collecteurMultis = new CollecteurMultis();
1726 1726
 
1727
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1728
-	}
1727
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1728
+    }
1729 1729
 
1730
-	return $letexte;
1730
+    return $letexte;
1731 1731
 }
1732 1732
 
1733 1733
 /**
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
  * @return string L'initiale en majuscule
1738 1738
  */
1739 1739
 function filtre_initiale($nom) {
1740
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1740
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1741 1741
 }
1742 1742
 
1743 1743
 
@@ -1782,33 +1782,33 @@  discard block
 block discarded – undo
1782 1782
  *      - null (interne) : si on empile
1783 1783
  **/
1784 1784
 function unique($donnee, $famille = '', $cpt = false) {
1785
-	static $mem = [];
1786
-	// permettre de vider la pile et de la restaurer
1787
-	// pour le calcul de introduction...
1788
-	if ($famille == '_spip_raz_') {
1789
-		$tmp = $mem;
1790
-		$mem = [];
1791
-
1792
-		return $tmp;
1793
-	} elseif ($famille == '_spip_set_') {
1794
-		$mem = $donnee;
1795
-
1796
-		return;
1797
-	}
1798
-	// eviter une notice
1799
-	if (!isset($mem[$famille])) {
1800
-		$mem[$famille] = [];
1801
-	}
1802
-	if ($cpt) {
1803
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1804
-	}
1805
-	// eviter une notice
1806
-	if (!isset($mem[$famille][$donnee])) {
1807
-		$mem[$famille][$donnee] = 0;
1808
-	}
1809
-	if (!($mem[$famille][$donnee]++)) {
1810
-		return $donnee;
1811
-	}
1785
+    static $mem = [];
1786
+    // permettre de vider la pile et de la restaurer
1787
+    // pour le calcul de introduction...
1788
+    if ($famille == '_spip_raz_') {
1789
+        $tmp = $mem;
1790
+        $mem = [];
1791
+
1792
+        return $tmp;
1793
+    } elseif ($famille == '_spip_set_') {
1794
+        $mem = $donnee;
1795
+
1796
+        return;
1797
+    }
1798
+    // eviter une notice
1799
+    if (!isset($mem[$famille])) {
1800
+        $mem[$famille] = [];
1801
+    }
1802
+    if ($cpt) {
1803
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1804
+    }
1805
+    // eviter une notice
1806
+    if (!isset($mem[$famille][$donnee])) {
1807
+        $mem[$famille][$donnee] = 0;
1808
+    }
1809
+    if (!($mem[$famille][$donnee]++)) {
1810
+        return $donnee;
1811
+    }
1812 1812
 }
1813 1813
 
1814 1814
 
@@ -1838,20 +1838,20 @@  discard block
 block discarded – undo
1838 1838
  *     Une des valeurs en fonction du compteur.
1839 1839
  **/
1840 1840
 function alterner($i, ...$args) {
1841
-	// recuperer les arguments (attention fonctions un peu space)
1842
-	$num = count($args);
1841
+    // recuperer les arguments (attention fonctions un peu space)
1842
+    $num = count($args);
1843 1843
 
1844
-	if ($num === 1 && is_array($args[0])) {
1845
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1846
-		$args = array_values($args[0]);
1847
-		$num = count($args);
1848
-	}
1844
+    if ($num === 1 && is_array($args[0])) {
1845
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1846
+        $args = array_values($args[0]);
1847
+        $num = count($args);
1848
+    }
1849 1849
 
1850
-	// un index compris entre 0 et num exclus
1851
-	$i = (((int) $i - 1) % $num); // dans ]-$num;$num[
1852
-	$i = ($i + $num) % $num; // dans [0;$num[
1853
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1854
-	return $args[$i];
1850
+    // un index compris entre 0 et num exclus
1851
+    $i = (((int) $i - 1) % $num); // dans ]-$num;$num[
1852
+    $i = ($i + $num) % $num; // dans [0;$num[
1853
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1854
+    return $args[$i];
1855 1855
 }
1856 1856
 
1857 1857
 
@@ -1877,52 +1877,52 @@  discard block
 block discarded – undo
1877 1877
  *     - null lorsque l’attribut n’existe pas.
1878 1878
  **/
1879 1879
 function extraire_attribut($balise, $attribut, $complet = false) {
1880
-	if (is_array($balise)) {
1881
-		array_walk(
1882
-			$balise,
1883
-			function (&$a, $key, $t) {
1884
-				$a = extraire_attribut($a, $t);
1885
-			},
1886
-			$attribut
1887
-		);
1888
-
1889
-		return $balise;
1890
-	}
1891
-	if (
1892
-		$balise
1893
-		&& stripos($balise, $attribut) !== false
1894
-		&& preg_match(
1895
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1896
-			. $attribut
1897
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1898
-			$balise,
1899
-			$r
1900
-		)
1901
-	) {
1902
-		if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) {
1903
-			$r[4] = substr($r[3], 1, -1);
1904
-			$r[3] = $r[3][0];
1905
-		} elseif ($r[3] !== '') {
1906
-			$r[4] = $r[3];
1907
-			$r[3] = '';
1908
-		} else {
1909
-			$r[4] = trim($r[2]);
1910
-		}
1911
-		$att = $r[4];
1912
-		if (str_contains($att, '&#')) {
1913
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1914
-		}
1915
-		$att = filtrer_entites($att);
1916
-	} else {
1917
-		$att = null;
1918
-		$r = [];
1919
-	}
1920
-
1921
-	if ($complet) {
1922
-		return [$att, $r];
1923
-	} else {
1924
-		return $att;
1925
-	}
1880
+    if (is_array($balise)) {
1881
+        array_walk(
1882
+            $balise,
1883
+            function (&$a, $key, $t) {
1884
+                $a = extraire_attribut($a, $t);
1885
+            },
1886
+            $attribut
1887
+        );
1888
+
1889
+        return $balise;
1890
+    }
1891
+    if (
1892
+        $balise
1893
+        && stripos($balise, $attribut) !== false
1894
+        && preg_match(
1895
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1896
+            . $attribut
1897
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1898
+            $balise,
1899
+            $r
1900
+        )
1901
+    ) {
1902
+        if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) {
1903
+            $r[4] = substr($r[3], 1, -1);
1904
+            $r[3] = $r[3][0];
1905
+        } elseif ($r[3] !== '') {
1906
+            $r[4] = $r[3];
1907
+            $r[3] = '';
1908
+        } else {
1909
+            $r[4] = trim($r[2]);
1910
+        }
1911
+        $att = $r[4];
1912
+        if (str_contains($att, '&#')) {
1913
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1914
+        }
1915
+        $att = filtrer_entites($att);
1916
+    } else {
1917
+        $att = null;
1918
+        $r = [];
1919
+    }
1920
+
1921
+    if ($complet) {
1922
+        return [$att, $r];
1923
+    } else {
1924
+        return $att;
1925
+    }
1926 1926
 }
1927 1927
 
1928 1928
 /**
@@ -1955,37 +1955,37 @@  discard block
 block discarded – undo
1955 1955
  **/
1956 1956
 function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string {
1957 1957
 
1958
-	if ($balise === null || $balise === '') {
1959
-		return '';
1960
-	}
1958
+    if ($balise === null || $balise === '') {
1959
+        return '';
1960
+    }
1961 1961
 
1962
-	// preparer l'attribut
1963
-	// supprimer les &nbsp; etc mais pas les balises html
1964
-	// qui ont un sens dans un attribut value d'un input
1965
-	if ($proteger) {
1966
-		$val = attribut_html($val, false);
1967
-	}
1962
+    // preparer l'attribut
1963
+    // supprimer les &nbsp; etc mais pas les balises html
1964
+    // qui ont un sens dans un attribut value d'un input
1965
+    if ($proteger) {
1966
+        $val = attribut_html($val, false);
1967
+    }
1968 1968
 
1969
-	// echapper les ' pour eviter tout bug
1970
-	$val = str_replace("'", '&#039;', $val ?? '');
1971
-	$insert = $vider && (string) $val === '' ? '' : " $attribut='$val'";
1969
+    // echapper les ' pour eviter tout bug
1970
+    $val = str_replace("'", '&#039;', $val ?? '');
1971
+    $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'";
1972 1972
 
1973
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
1973
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
1974 1974
 
1975
-	if ($old !== null) {
1976
-		// Remplacer l'ancien attribut du meme nom
1977
-		$balise = $r[1] . $insert . $r[5];
1978
-	} else {
1979
-		// preferer une balise " />" (comme <img />)
1980
-		if (preg_match(',/>,', $balise)) {
1981
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
1982
-		} // sinon une balise <a ...> ... </a>
1983
-		else {
1984
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
1985
-		}
1986
-	}
1975
+    if ($old !== null) {
1976
+        // Remplacer l'ancien attribut du meme nom
1977
+        $balise = $r[1] . $insert . $r[5];
1978
+    } else {
1979
+        // preferer une balise " />" (comme <img />)
1980
+        if (preg_match(',/>,', $balise)) {
1981
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
1982
+        } // sinon une balise <a ...> ... </a>
1983
+        else {
1984
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
1985
+        }
1986
+    }
1987 1987
 
1988
-	return $balise;
1988
+    return $balise;
1989 1989
 }
1990 1990
 
1991 1991
 /**
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
  * @return string Code HTML sans l'attribut
2004 2004
  **/
2005 2005
 function vider_attribut(?string $balise, string $attribut): string {
2006
-	return inserer_attribut($balise, $attribut, '', false, true);
2006
+    return inserer_attribut($balise, $attribut, '', false, true);
2007 2007
 }
2008 2008
 
2009 2009
 /**
@@ -2015,50 +2015,50 @@  discard block
 block discarded – undo
2015 2015
  * @return string
2016 2016
  */
2017 2017
 function modifier_class($balise, $class, $operation = 'ajouter') {
2018
-	if (is_string($class)) {
2019
-		$class = explode(' ', trim($class));
2020
-	}
2021
-	$class = array_filter($class);
2022
-	$class = array_unique($class);
2023
-	if (!$class) {
2024
-		return $balise;
2025
-	}
2026
-
2027
-	$class_courante = extraire_attribut($balise, 'class');
2028
-	$class_new = $class_courante;
2029
-	foreach ($class as $c) {
2030
-		$is_class_presente = false;
2031
-		if (
2032
-			$class_courante
2033
-			&& str_contains($class_courante, (string) $c)
2034
-			&& in_array($c, preg_split(',\s+,', $class_courante))
2035
-		) {
2036
-			$is_class_presente = true;
2037
-		}
2038
-		if (
2039
-			in_array($operation, ['ajouter', 'commuter'])
2040
-			&& !$is_class_presente
2041
-		) {
2042
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2043
-		} elseif (
2044
-			in_array($operation, ['supprimer', 'commuter'])
2045
-			&& $is_class_presente
2046
-		) {
2047
-			$class_new = preg_split(',\s+,', $class_new);
2048
-			$class_new = array_diff($class_new, [$c]);
2049
-			$class_new = implode(' ', $class_new);
2050
-		}
2051
-	}
2052
-
2053
-	if ($class_new !== $class_courante) {
2054
-		if (strlen($class_new)) {
2055
-			$balise = inserer_attribut($balise, 'class', $class_new);
2056
-		} elseif ($class_courante) {
2057
-			$balise = vider_attribut($balise, 'class');
2058
-		}
2059
-	}
2060
-
2061
-	return $balise;
2018
+    if (is_string($class)) {
2019
+        $class = explode(' ', trim($class));
2020
+    }
2021
+    $class = array_filter($class);
2022
+    $class = array_unique($class);
2023
+    if (!$class) {
2024
+        return $balise;
2025
+    }
2026
+
2027
+    $class_courante = extraire_attribut($balise, 'class');
2028
+    $class_new = $class_courante;
2029
+    foreach ($class as $c) {
2030
+        $is_class_presente = false;
2031
+        if (
2032
+            $class_courante
2033
+            && str_contains($class_courante, (string) $c)
2034
+            && in_array($c, preg_split(',\s+,', $class_courante))
2035
+        ) {
2036
+            $is_class_presente = true;
2037
+        }
2038
+        if (
2039
+            in_array($operation, ['ajouter', 'commuter'])
2040
+            && !$is_class_presente
2041
+        ) {
2042
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2043
+        } elseif (
2044
+            in_array($operation, ['supprimer', 'commuter'])
2045
+            && $is_class_presente
2046
+        ) {
2047
+            $class_new = preg_split(',\s+,', $class_new);
2048
+            $class_new = array_diff($class_new, [$c]);
2049
+            $class_new = implode(' ', $class_new);
2050
+        }
2051
+    }
2052
+
2053
+    if ($class_new !== $class_courante) {
2054
+        if (strlen($class_new)) {
2055
+            $balise = inserer_attribut($balise, 'class', $class_new);
2056
+        } elseif ($class_courante) {
2057
+            $balise = vider_attribut($balise, 'class');
2058
+        }
2059
+    }
2060
+
2061
+    return $balise;
2062 2062
 }
2063 2063
 
2064 2064
 /**
@@ -2068,7 +2068,7 @@  discard block
 block discarded – undo
2068 2068
  * @return string
2069 2069
  */
2070 2070
 function ajouter_class($balise, $class) {
2071
-	return modifier_class($balise, $class, 'ajouter');
2071
+    return modifier_class($balise, $class, 'ajouter');
2072 2072
 }
2073 2073
 
2074 2074
 /**
@@ -2078,7 +2078,7 @@  discard block
 block discarded – undo
2078 2078
  * @return string
2079 2079
  */
2080 2080
 function supprimer_class($balise, $class) {
2081
-	return modifier_class($balise, $class, 'supprimer');
2081
+    return modifier_class($balise, $class, 'supprimer');
2082 2082
 }
2083 2083
 
2084 2084
 /**
@@ -2089,7 +2089,7 @@  discard block
 block discarded – undo
2089 2089
  * @return string
2090 2090
  */
2091 2091
 function commuter_class($balise, $class) {
2092
-	return modifier_class($balise, $class, 'commuter');
2092
+    return modifier_class($balise, $class, 'commuter');
2093 2093
 }
2094 2094
 
2095 2095
 /**
@@ -2100,19 +2100,19 @@  discard block
 block discarded – undo
2100 2100
  * @return string
2101 2101
  */
2102 2102
 function tester_config($id, $mode = '') {
2103
-	include_spip('action/inscrire_auteur');
2103
+    include_spip('action/inscrire_auteur');
2104 2104
 
2105
-	return tester_statut_inscription($mode, $id);
2105
+    return tester_statut_inscription($mode, $id);
2106 2106
 }
2107 2107
 
2108 2108
 //
2109 2109
 // Quelques fonctions de calcul arithmetique
2110 2110
 //
2111 2111
 function floatstr($a) {
2112
-	return str_replace(',', '.', (string)(float) $a);
2112
+    return str_replace(',', '.', (string)(float) $a);
2113 2113
 }
2114 2114
 function strize($f, $a, $b) {
2115
-	return floatstr($f(floatstr($a), floatstr($b)));
2115
+    return floatstr($f(floatstr($a), floatstr($b)));
2116 2116
 }
2117 2117
 
2118 2118
 /**
@@ -2131,11 +2131,11 @@  discard block
 block discarded – undo
2131 2131
  * @return int $a+$b
2132 2132
  **/
2133 2133
 function plus($a, $b) {
2134
-	return $a + $b;
2134
+    return $a + $b;
2135 2135
 }
2136 2136
 
2137 2137
 function strplus($a, $b) {
2138
-	return strize('plus', $a, $b);
2138
+    return strize('plus', $a, $b);
2139 2139
 }
2140 2140
 
2141 2141
 /**
@@ -2154,11 +2154,11 @@  discard block
 block discarded – undo
2154 2154
  * @return int $a-$b
2155 2155
  **/
2156 2156
 function moins($a, $b) {
2157
-	return $a - $b;
2157
+    return $a - $b;
2158 2158
 }
2159 2159
 
2160 2160
 function strmoins($a, $b) {
2161
-	return strize('moins', $a, $b);
2161
+    return strize('moins', $a, $b);
2162 2162
 }
2163 2163
 
2164 2164
 /**
@@ -2178,11 +2178,11 @@  discard block
 block discarded – undo
2178 2178
  * @return int $a*$b
2179 2179
  **/
2180 2180
 function mult($a, $b) {
2181
-	return $a * $b;
2181
+    return $a * $b;
2182 2182
 }
2183 2183
 
2184 2184
 function strmult($a, $b) {
2185
-	return strize('mult', $a, $b);
2185
+    return strize('mult', $a, $b);
2186 2186
 }
2187 2187
 
2188 2188
 /**
@@ -2202,11 +2202,11 @@  discard block
 block discarded – undo
2202 2202
  * @return int $a/$b (ou 0 si $b est nul)
2203 2203
  **/
2204 2204
 function div($a, $b) {
2205
-	return $b ? $a / $b : 0;
2205
+    return $b ? $a / $b : 0;
2206 2206
 }
2207 2207
 
2208 2208
 function strdiv($a, $b) {
2209
-	return strize('div', $a, $b);
2209
+    return strize('div', $a, $b);
2210 2210
 }
2211 2211
 
2212 2212
 /**
@@ -2227,7 +2227,7 @@  discard block
 block discarded – undo
2227 2227
  * @return int ($nb % $mod) + $add
2228 2228
  **/
2229 2229
 function modulo($nb, $mod, $add = 0) {
2230
-	return ($mod ? $nb % $mod : 0) + $add;
2230
+    return ($mod ? $nb % $mod : 0) + $add;
2231 2231
 }
2232 2232
 
2233 2233
 
@@ -2242,26 +2242,26 @@  discard block
 block discarded – undo
2242 2242
  *      - true sinon
2243 2243
  **/
2244 2244
 function nom_acceptable($nom) {
2245
-	$remp2 = [];
2246
-	$remp1 = [];
2247
-	if (!is_string($nom)) {
2248
-		return false;
2249
-	}
2250
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2251
-		define('_TAGS_NOM_AUTEUR', '');
2252
-	}
2253
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2254
-	foreach ($tags_acceptes as $tag) {
2255
-		if (strlen($tag)) {
2256
-			$remp1[] = '<' . trim($tag) . '>';
2257
-			$remp1[] = '</' . trim($tag) . '>';
2258
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2259
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2260
-		}
2261
-	}
2262
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2263
-
2264
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2245
+    $remp2 = [];
2246
+    $remp1 = [];
2247
+    if (!is_string($nom)) {
2248
+        return false;
2249
+    }
2250
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2251
+        define('_TAGS_NOM_AUTEUR', '');
2252
+    }
2253
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2254
+    foreach ($tags_acceptes as $tag) {
2255
+        if (strlen($tag)) {
2256
+            $remp1[] = '<' . trim($tag) . '>';
2257
+            $remp1[] = '</' . trim($tag) . '>';
2258
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2259
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2260
+        }
2261
+    }
2262
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2263
+
2264
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2265 2265
 }
2266 2266
 
2267 2267
 
@@ -2277,13 +2277,13 @@  discard block
 block discarded – undo
2277 2277
  *      - renvoie un tableau si l'entree est un tableau
2278 2278
  **/
2279 2279
 function email_valide($adresses) {
2280
-	if (is_array($adresses)) {
2281
-		$adresses = array_map('email_valide', $adresses);
2282
-		return array_filter($adresses);
2283
-	}
2280
+    if (is_array($adresses)) {
2281
+        $adresses = array_map('email_valide', $adresses);
2282
+        return array_filter($adresses);
2283
+    }
2284 2284
 
2285
-	$email_valide = charger_fonction('email_valide', 'inc');
2286
-	return $email_valide($adresses);
2285
+    $email_valide = charger_fonction('email_valide', 'inc');
2286
+    return $email_valide($adresses);
2287 2287
 }
2288 2288
 
2289 2289
 /**
@@ -2297,29 +2297,29 @@  discard block
 block discarded – undo
2297 2297
  * @return string texte
2298 2298
  **/
2299 2299
 function afficher_enclosures($tags) {
2300
-	$s = [];
2301
-	foreach (extraire_balises($tags, 'a') as $tag) {
2302
-		if (
2303
-			extraire_attribut($tag, 'rel') == 'enclosure'
2304
-			&& ($t = extraire_attribut($tag, 'href'))
2305
-		) {
2306
-			$s[] = preg_replace(
2307
-				',>[^<]+</a>,S',
2308
-				'>'
2309
-				. http_img_pack(
2310
-					'attachment-16.png',
2311
-					$t,
2312
-					'',
2313
-					$t,
2314
-					['utiliser_suffixe_size' => true]
2315
-				)
2316
-				. '</a>',
2317
-				(string) $tag
2318
-			);
2319
-		}
2320
-	}
2321
-
2322
-	return implode('&nbsp;', $s);
2300
+    $s = [];
2301
+    foreach (extraire_balises($tags, 'a') as $tag) {
2302
+        if (
2303
+            extraire_attribut($tag, 'rel') == 'enclosure'
2304
+            && ($t = extraire_attribut($tag, 'href'))
2305
+        ) {
2306
+            $s[] = preg_replace(
2307
+                ',>[^<]+</a>,S',
2308
+                '>'
2309
+                . http_img_pack(
2310
+                    'attachment-16.png',
2311
+                    $t,
2312
+                    '',
2313
+                    $t,
2314
+                    ['utiliser_suffixe_size' => true]
2315
+                )
2316
+                . '</a>',
2317
+                (string) $tag
2318
+            );
2319
+        }
2320
+    }
2321
+
2322
+    return implode('&nbsp;', $s);
2323 2323
 }
2324 2324
 
2325 2325
 /**
@@ -2334,15 +2334,15 @@  discard block
 block discarded – undo
2334 2334
  * @return string Liens trouvés
2335 2335
  **/
2336 2336
 function afficher_tags($tags, $rels = 'tag,directory') {
2337
-	$s = [];
2338
-	foreach (extraire_balises($tags, 'a') as $tag) {
2339
-		$rel = extraire_attribut($tag, 'rel');
2340
-		if (strstr(",$rels,", (string) ",$rel,")) {
2341
-			$s[] = $tag;
2342
-		}
2343
-	}
2337
+    $s = [];
2338
+    foreach (extraire_balises($tags, 'a') as $tag) {
2339
+        $rel = extraire_attribut($tag, 'rel');
2340
+        if (strstr(",$rels,", (string) ",$rel,")) {
2341
+            $s[] = $tag;
2342
+        }
2343
+    }
2344 2344
 
2345
-	return implode(', ', $s);
2345
+    return implode(', ', $s);
2346 2346
 }
2347 2347
 
2348 2348
 
@@ -2364,21 +2364,21 @@  discard block
 block discarded – undo
2364 2364
  * @return string Tag HTML `<a>` avec microformat.
2365 2365
  **/
2366 2366
 function enclosure2microformat($e) {
2367
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2368
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2369
-	}
2370
-	$type = extraire_attribut($e, 'type');
2371
-	if (!$length = extraire_attribut($e, 'length')) {
2372
-		# <media:content : longeur dans fileSize. On tente.
2373
-		$length = extraire_attribut($e, 'fileSize');
2374
-	}
2375
-	$fichier = basename($url);
2367
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2368
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2369
+    }
2370
+    $type = extraire_attribut($e, 'type');
2371
+    if (!$length = extraire_attribut($e, 'length')) {
2372
+        # <media:content : longeur dans fileSize. On tente.
2373
+        $length = extraire_attribut($e, 'fileSize');
2374
+    }
2375
+    $fichier = basename($url);
2376 2376
 
2377
-	return '<a rel="enclosure"'
2378
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2379
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2380
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2381
-	. '>' . $fichier . '</a>';
2377
+    return '<a rel="enclosure"'
2378
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2379
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2380
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2381
+    . '>' . $fichier . '</a>';
2382 2382
 }
2383 2383
 
2384 2384
 /**
@@ -2396,24 +2396,24 @@  discard block
 block discarded – undo
2396 2396
  * @return string Tags RSS `<enclosure>`.
2397 2397
  **/
2398 2398
 function microformat2enclosure($tags) {
2399
-	$enclosures = [];
2400
-	foreach (extraire_balises($tags, 'a') as $e) {
2401
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2402
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2403
-			$type = extraire_attribut($e, 'type');
2404
-			if (!$length = (int) extraire_attribut($e, 'title')) {
2405
-				$length = (int) extraire_attribut($e, 'length');
2406
-			} # vieux data
2407
-			$fichier = basename($url);
2408
-			$enclosures[] = '<enclosure'
2409
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2410
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2411
-				. ($length ? ' length="' . $length . '"' : '')
2412
-				. ' />';
2413
-		}
2414
-	}
2399
+    $enclosures = [];
2400
+    foreach (extraire_balises($tags, 'a') as $e) {
2401
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2402
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2403
+            $type = extraire_attribut($e, 'type');
2404
+            if (!$length = (int) extraire_attribut($e, 'title')) {
2405
+                $length = (int) extraire_attribut($e, 'length');
2406
+            } # vieux data
2407
+            $fichier = basename($url);
2408
+            $enclosures[] = '<enclosure'
2409
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2410
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2411
+                . ($length ? ' length="' . $length . '"' : '')
2412
+                . ' />';
2413
+        }
2414
+    }
2415 2415
 
2416
-	return implode("\n", $enclosures);
2416
+    return implode("\n", $enclosures);
2417 2417
 }
2418 2418
 
2419 2419
 
@@ -2429,16 +2429,16 @@  discard block
 block discarded – undo
2429 2429
  * @return string Tags RSS Atom `<dc:subject>`.
2430 2430
  **/
2431 2431
 function tags2dcsubject($tags) {
2432
-	$subjects = '';
2433
-	foreach (extraire_balises($tags, 'a') as $e) {
2434
-		if (extraire_attribut($e, 'rel') == 'tag') {
2435
-			$subjects .= '<dc:subject>'
2436
-				. texte_backend(textebrut($e))
2437
-				. '</dc:subject>' . "\n";
2438
-		}
2439
-	}
2432
+    $subjects = '';
2433
+    foreach (extraire_balises($tags, 'a') as $e) {
2434
+        if (extraire_attribut($e, 'rel') == 'tag') {
2435
+            $subjects .= '<dc:subject>'
2436
+                . texte_backend(textebrut($e))
2437
+                . '</dc:subject>' . "\n";
2438
+        }
2439
+    }
2440 2440
 
2441
-	return $subjects;
2441
+    return $subjects;
2442 2442
 }
2443 2443
 
2444 2444
 /**
@@ -2467,12 +2467,12 @@  discard block
 block discarded – undo
2467 2467
  *     - Tableau de résultats, si tableau en entrée.
2468 2468
  **/
2469 2469
 function extraire_balise($texte, $tag = 'a', $profondeur = 1) {
2470
-	$balises = extraire_balises($texte, $tag, ['nb_max' => 1, 'profondeur' => $profondeur]);
2471
-	if (is_array($texte)) {
2472
-		return array_map(fn (array $a) => empty($a) ? '' : reset($a), $balises);
2473
-	}
2470
+    $balises = extraire_balises($texte, $tag, ['nb_max' => 1, 'profondeur' => $profondeur]);
2471
+    if (is_array($texte)) {
2472
+        return array_map(fn (array $a) => empty($a) ? '' : reset($a), $balises);
2473
+    }
2474 2474
 
2475
-	return (empty($balises) ? '' : reset($balises));
2475
+    return (empty($balises) ? '' : reset($balises));
2476 2476
 }
2477 2477
 
2478 2478
 /**
@@ -2500,25 +2500,25 @@  discard block
 block discarded – undo
2500 2500
  *     - Tableau de résultats, si tableau en entrée.
2501 2501
  **/
2502 2502
 function extraire_balises($texte, $tag = 'a', $options = []) {
2503
-	if (is_array($texte)) {
2504
-		array_walk(
2505
-			$texte,
2506
-			function (&$a, $key, $t) {
2507
-				$a = extraire_balises($a, $t);
2508
-			},
2509
-			$tag
2510
-		);
2503
+    if (is_array($texte)) {
2504
+        array_walk(
2505
+            $texte,
2506
+            function (&$a, $key, $t) {
2507
+                $a = extraire_balises($a, $t);
2508
+            },
2509
+            $tag
2510
+        );
2511 2511
 
2512
-		return $texte;
2513
-	}
2512
+        return $texte;
2513
+    }
2514 2514
 
2515
-	$htmlTagCollecteur = new CollecteurHtmlTag($tag);
2516
-	$collection = $htmlTagCollecteur->collecter($texte, $options);
2517
-	if (!empty($collection)) {
2518
-		return array_column($collection, 'raw');
2519
-	}
2515
+    $htmlTagCollecteur = new CollecteurHtmlTag($tag);
2516
+    $collection = $htmlTagCollecteur->collecter($texte, $options);
2517
+    if (!empty($collection)) {
2518
+        return array_column($collection, 'raw');
2519
+    }
2520 2520
 
2521
-	return [];
2521
+    return [];
2522 2522
 }
2523 2523
 
2524 2524
 /**
@@ -2547,11 +2547,11 @@  discard block
 block discarded – undo
2547 2547
  *     - `$def` si on n'a pas transmis de tableau
2548 2548
  **/
2549 2549
 function in_any($val, $vals, $def = '') {
2550
-	if (!is_array($vals) && $vals && ($v = unserialize($vals))) {
2551
-		$vals = $v;
2552
-	}
2550
+    if (!is_array($vals) && $vals && ($v = unserialize($vals))) {
2551
+        $vals = $v;
2552
+    }
2553 2553
 
2554
-	return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def));
2554
+    return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def));
2555 2555
 }
2556 2556
 
2557 2557
 
@@ -2572,12 +2572,12 @@  discard block
 block discarded – undo
2572 2572
  *     Résultat du calcul
2573 2573
  **/
2574 2574
 function valeur_numerique($expr) {
2575
-	$a = 0;
2576
-	if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) {
2577
-		eval("\$a = $expr;");
2578
-	}
2575
+    $a = 0;
2576
+    if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) {
2577
+        eval("\$a = $expr;");
2578
+    }
2579 2579
 
2580
-	return (int) $a;
2580
+    return (int) $a;
2581 2581
 }
2582 2582
 
2583 2583
 /**
@@ -2596,7 +2596,7 @@  discard block
 block discarded – undo
2596 2596
  *      Retourne `$a*$b/$c`
2597 2597
  **/
2598 2598
 function regledetrois($a, $b, $c) {
2599
-	return round($a * $b / $c);
2599
+    return round($a * $b / $c);
2600 2600
 }
2601 2601
 
2602 2602
 
@@ -2619,79 +2619,79 @@  discard block
 block discarded – undo
2619 2619
  * @return string Suite de champs input hidden
2620 2620
  **/
2621 2621
 function form_hidden(?string $action = ''): string {
2622
-	$action ??= '';
2623
-
2624
-	$contexte = [];
2625
-	include_spip('inc/urls');
2626
-	if (
2627
-		($p = urls_decoder_url($action, ''))
2628
-		&& reset($p)
2629
-	) {
2630
-		$fond = array_shift($p);
2631
-		if ($fond != '404') {
2632
-			$contexte = array_shift($p);
2633
-			$contexte['page'] = $fond;
2634
-			$action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2635
-		}
2636
-	}
2637
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2638
-	if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) {
2639
-		unset($contexte['type']);
2640
-	}
2641
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) {
2642
-		unset($contexte['type-page']);
2643
-	}
2644
-
2645
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2646
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2647
-	$values = [];
2648
-
2649
-	// d'abord avec celles de l'url
2650
-	if (false !== ($p = strpos($action, '?'))) {
2651
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2652
-			$c = explode('=', (string) $c, 2);
2653
-			$var = array_shift($c);
2654
-			$val = array_shift($c) ?? '';
2655
-			if ($var) {
2656
-				$val = rawurldecode($val);
2657
-				$var = rawurldecode($var); // decoder les [] eventuels
2658
-				if (preg_match(',\[\]$,S', $var)) {
2659
-					$values[] = [$var, $val];
2660
-				} else {
2661
-					if (!isset($values[$var])) {
2662
-						$values[$var] = [$var, $val];
2663
-					}
2664
-				}
2665
-			}
2666
-		}
2667
-	}
2668
-
2669
-	// ensuite avec celles du contexte, sans doublonner !
2670
-	foreach ($contexte as $var => $val) {
2671
-		if (preg_match(',\[\]$,S', (string) $var)) {
2672
-			$values[] = [$var, $val];
2673
-		} else {
2674
-			if (!isset($values[$var])) {
2675
-				$values[$var] = [$var, $val];
2676
-			}
2677
-		}
2678
-	}
2679
-
2680
-	// puis on rassemble le tout
2681
-	$hidden = [];
2682
-	foreach ($values as $value) {
2683
-		[$var, $val] = $value;
2684
-		$hidden[] = '<input name="'
2685
-			. entites_html($var)
2686
-			. '"'
2687
-			. (is_null($val)
2688
-				? ''
2689
-				: ' value="' . entites_html($val) . '"'
2690
-			)
2691
-			. ' type="hidden"' . "\n/>";
2692
-	}
2693
-
2694
-	return implode('', $hidden);
2622
+    $action ??= '';
2623
+
2624
+    $contexte = [];
2625
+    include_spip('inc/urls');
2626
+    if (
2627
+        ($p = urls_decoder_url($action, ''))
2628
+        && reset($p)
2629
+    ) {
2630
+        $fond = array_shift($p);
2631
+        if ($fond != '404') {
2632
+            $contexte = array_shift($p);
2633
+            $contexte['page'] = $fond;
2634
+            $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2635
+        }
2636
+    }
2637
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2638
+    if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) {
2639
+        unset($contexte['type']);
2640
+    }
2641
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) {
2642
+        unset($contexte['type-page']);
2643
+    }
2644
+
2645
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2646
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2647
+    $values = [];
2648
+
2649
+    // d'abord avec celles de l'url
2650
+    if (false !== ($p = strpos($action, '?'))) {
2651
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2652
+            $c = explode('=', (string) $c, 2);
2653
+            $var = array_shift($c);
2654
+            $val = array_shift($c) ?? '';
2655
+            if ($var) {
2656
+                $val = rawurldecode($val);
2657
+                $var = rawurldecode($var); // decoder les [] eventuels
2658
+                if (preg_match(',\[\]$,S', $var)) {
2659
+                    $values[] = [$var, $val];
2660
+                } else {
2661
+                    if (!isset($values[$var])) {
2662
+                        $values[$var] = [$var, $val];
2663
+                    }
2664
+                }
2665
+            }
2666
+        }
2667
+    }
2668
+
2669
+    // ensuite avec celles du contexte, sans doublonner !
2670
+    foreach ($contexte as $var => $val) {
2671
+        if (preg_match(',\[\]$,S', (string) $var)) {
2672
+            $values[] = [$var, $val];
2673
+        } else {
2674
+            if (!isset($values[$var])) {
2675
+                $values[$var] = [$var, $val];
2676
+            }
2677
+        }
2678
+    }
2679
+
2680
+    // puis on rassemble le tout
2681
+    $hidden = [];
2682
+    foreach ($values as $value) {
2683
+        [$var, $val] = $value;
2684
+        $hidden[] = '<input name="'
2685
+            . entites_html($var)
2686
+            . '"'
2687
+            . (is_null($val)
2688
+                ? ''
2689
+                : ' value="' . entites_html($val) . '"'
2690
+            )
2691
+            . ' type="hidden"' . "\n/>";
2692
+    }
2693
+
2694
+    return implode('', $hidden);
2695 2695
 }
2696 2696
 
2697 2697
 
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
  *    - la première valeur du tableau sinon.
2714 2714
  **/
2715 2715
 function filtre_reset($array) {
2716
-	return is_array($array) ? reset($array) : null;
2716
+    return is_array($array) ? reset($array) : null;
2717 2717
 }
2718 2718
 
2719 2719
 /**
@@ -2734,7 +2734,7 @@  discard block
 block discarded – undo
2734 2734
  *    - la dernière valeur du tableau sinon.
2735 2735
  **/
2736 2736
 function filtre_end($array) {
2737
-	return is_array($array) ? end($array) : null;
2737
+    return is_array($array) ? end($array) : null;
2738 2738
 }
2739 2739
 
2740 2740
 /**
@@ -2754,11 +2754,11 @@  discard block
 block discarded – undo
2754 2754
  *
2755 2755
  **/
2756 2756
 function filtre_push($array, mixed $val) {
2757
-	if (!is_array($array) || !array_push($array, $val)) {
2758
-		return '';
2759
-	}
2757
+    if (!is_array($array) || !array_push($array, $val)) {
2758
+        return '';
2759
+    }
2760 2760
 
2761
-	return $array;
2761
+    return $array;
2762 2762
 }
2763 2763
 
2764 2764
 /**
@@ -2777,7 +2777,7 @@  discard block
 block discarded – undo
2777 2777
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2778 2778
  **/
2779 2779
 function filtre_find($array, mixed $val) {
2780
-	return (is_array($array) && in_array($val, $array));
2780
+    return (is_array($array) && in_array($val, $array));
2781 2781
 }
2782 2782
 
2783 2783
 
@@ -2794,13 +2794,13 @@  discard block
 block discarded – undo
2794 2794
  *     Contenu avec urls en absolus
2795 2795
  **/
2796 2796
 function urls_absolues_css($contenu, $source) {
2797
-	$path = suivre_lien(url_absolue($source), './');
2797
+    $path = suivre_lien(url_absolue($source), './');
2798 2798
 
2799
-	return preg_replace_callback(
2800
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2801
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2802
-		$contenu
2803
-	);
2799
+    return preg_replace_callback(
2800
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2801
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2802
+        $contenu
2803
+    );
2804 2804
 }
2805 2805
 
2806 2806
 
@@ -2829,123 +2829,123 @@  discard block
 block discarded – undo
2829 2829
  *     Chemin du fichier CSS inversé
2830 2830
  **/
2831 2831
 function direction_css($css, $voulue = '') {
2832
-	if (!$css) {
2833
-		return '';
2834
-	}
2835
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2836
-		return $css;
2837
-	}
2838
-	include_spip('inc/lang');
2839
-	// si on a precise le sens voulu en argument, le prendre en compte
2840
-	if ($voulue = strtolower($voulue)) {
2841
-		if ($voulue != 'rtl' && $voulue != 'ltr') {
2842
-			$voulue = lang_dir($voulue);
2843
-		}
2844
-	} else {
2845
-		$voulue = lang_dir();
2846
-	}
2847
-
2848
-	$r = count($r) > 1;
2849
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2850
-	$dir = $r ? 'rtl' : 'ltr';
2851
-	$ndir = $r ? 'ltr' : 'rtl';
2852
-
2853
-	if ($voulue == $dir) {
2854
-		return $css;
2855
-	}
2856
-
2857
-	if (
2858
-		// url absolue
2859
-		preg_match(',^https?:,i', $css)
2860
-		// ou qui contient un ?
2861
-		|| ($p = strpos($css, '?')) !== false
2862
-	) {
2863
-		$distant = true;
2864
-		$cssf = parse_url($css);
2865
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2866
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2867
-	} else {
2868
-		$distant = false;
2869
-		$cssf = $css;
2870
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2871
-		//propose (rien a faire dans ce cas)
2872
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2873
-		if (@file_exists($f)) {
2874
-			return $f;
2875
-		}
2876
-	}
2877
-
2878
-	// 2.
2879
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2880
-	$f = $dir_var
2881
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2882
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2883
-
2884
-	// la css peut etre distante (url absolue !)
2885
-	$contenu = null;
2886
-	if ($distant) {
2887
-		include_spip('inc/distant');
2888
-		$res = recuperer_url($css);
2889
-		if (!$res || !($contenu = $res['page'])) {
2890
-			return $css;
2891
-		}
2892
-	} else {
2893
-		if (
2894
-			@filemtime($f) > @filemtime($css)
2895
-			&& _VAR_MODE != 'recalcul'
2896
-		) {
2897
-			return $f;
2898
-		}
2899
-		if (!lire_fichier($css, $contenu)) {
2900
-			return $css;
2901
-		}
2902
-	}
2903
-
2904
-
2905
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2906
-	include_spip('lib/csstidy/class.csstidy');
2907
-	$parser = new csstidy();
2908
-	$parser->set_cfg('optimise_shorthands', 0);
2909
-	$parser->set_cfg('reverse_left_and_right', true);
2910
-	$parser->parse($contenu);
2911
-
2912
-	$contenu = $parser->print->plain();
2913
-
2914
-
2915
-	// reperer les @import auxquels il faut propager le direction_css
2916
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs);
2917
-	$src = [];
2918
-	$src_direction_css = [];
2919
-	$src_faux_abs = [];
2920
-	$d = dirname($css);
2921
-	foreach ($regs[1] as $k => $import_css) {
2922
-		$css_direction = direction_css("$d/$import_css", $voulue);
2923
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2924
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2925
-			$css_direction = substr($css_direction, strlen($d) + 1);
2926
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2927
-		elseif (str_starts_with($css_direction, $dir_var)) {
2928
-			$css_direction = substr($css_direction, strlen($dir_var));
2929
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2930
-			$css_direction = '/@@@@@@/' . $css_direction;
2931
-		}
2932
-		$src[] = $regs[0][$k];
2933
-		$src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]);
2934
-	}
2935
-	$contenu = str_replace($src, $src_direction_css, (string) $contenu);
2936
-
2937
-	$contenu = urls_absolues_css($contenu, $css);
2938
-
2939
-	// virer les fausses url absolues que l'on a mis dans les import
2940
-	if ($src_faux_abs !== []) {
2941
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2942
-	}
2943
-
2944
-	if (!ecrire_fichier($f, $contenu)) {
2945
-		return $css;
2946
-	}
2947
-
2948
-	return $f;
2832
+    if (!$css) {
2833
+        return '';
2834
+    }
2835
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2836
+        return $css;
2837
+    }
2838
+    include_spip('inc/lang');
2839
+    // si on a precise le sens voulu en argument, le prendre en compte
2840
+    if ($voulue = strtolower($voulue)) {
2841
+        if ($voulue != 'rtl' && $voulue != 'ltr') {
2842
+            $voulue = lang_dir($voulue);
2843
+        }
2844
+    } else {
2845
+        $voulue = lang_dir();
2846
+    }
2847
+
2848
+    $r = count($r) > 1;
2849
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2850
+    $dir = $r ? 'rtl' : 'ltr';
2851
+    $ndir = $r ? 'ltr' : 'rtl';
2852
+
2853
+    if ($voulue == $dir) {
2854
+        return $css;
2855
+    }
2856
+
2857
+    if (
2858
+        // url absolue
2859
+        preg_match(',^https?:,i', $css)
2860
+        // ou qui contient un ?
2861
+        || ($p = strpos($css, '?')) !== false
2862
+    ) {
2863
+        $distant = true;
2864
+        $cssf = parse_url($css);
2865
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2866
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2867
+    } else {
2868
+        $distant = false;
2869
+        $cssf = $css;
2870
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2871
+        //propose (rien a faire dans ce cas)
2872
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2873
+        if (@file_exists($f)) {
2874
+            return $f;
2875
+        }
2876
+    }
2877
+
2878
+    // 2.
2879
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2880
+    $f = $dir_var
2881
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2882
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2883
+
2884
+    // la css peut etre distante (url absolue !)
2885
+    $contenu = null;
2886
+    if ($distant) {
2887
+        include_spip('inc/distant');
2888
+        $res = recuperer_url($css);
2889
+        if (!$res || !($contenu = $res['page'])) {
2890
+            return $css;
2891
+        }
2892
+    } else {
2893
+        if (
2894
+            @filemtime($f) > @filemtime($css)
2895
+            && _VAR_MODE != 'recalcul'
2896
+        ) {
2897
+            return $f;
2898
+        }
2899
+        if (!lire_fichier($css, $contenu)) {
2900
+            return $css;
2901
+        }
2902
+    }
2903
+
2904
+
2905
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2906
+    include_spip('lib/csstidy/class.csstidy');
2907
+    $parser = new csstidy();
2908
+    $parser->set_cfg('optimise_shorthands', 0);
2909
+    $parser->set_cfg('reverse_left_and_right', true);
2910
+    $parser->parse($contenu);
2911
+
2912
+    $contenu = $parser->print->plain();
2913
+
2914
+
2915
+    // reperer les @import auxquels il faut propager le direction_css
2916
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs);
2917
+    $src = [];
2918
+    $src_direction_css = [];
2919
+    $src_faux_abs = [];
2920
+    $d = dirname($css);
2921
+    foreach ($regs[1] as $k => $import_css) {
2922
+        $css_direction = direction_css("$d/$import_css", $voulue);
2923
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2924
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2925
+            $css_direction = substr($css_direction, strlen($d) + 1);
2926
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2927
+        elseif (str_starts_with($css_direction, $dir_var)) {
2928
+            $css_direction = substr($css_direction, strlen($dir_var));
2929
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2930
+            $css_direction = '/@@@@@@/' . $css_direction;
2931
+        }
2932
+        $src[] = $regs[0][$k];
2933
+        $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]);
2934
+    }
2935
+    $contenu = str_replace($src, $src_direction_css, (string) $contenu);
2936
+
2937
+    $contenu = urls_absolues_css($contenu, $css);
2938
+
2939
+    // virer les fausses url absolues que l'on a mis dans les import
2940
+    if ($src_faux_abs !== []) {
2941
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2942
+    }
2943
+
2944
+    if (!ecrire_fichier($f, $contenu)) {
2945
+        return $css;
2946
+    }
2947
+
2948
+    return $f;
2949 2949
 }
2950 2950
 
2951 2951
 
@@ -2968,47 +2968,47 @@  discard block
 block discarded – undo
2968 2968
  *     - Chemin ou URL du fichier CSS source sinon.
2969 2969
  **/
2970 2970
 function url_absolue_css($css) {
2971
-	if (!preg_match(',\.css$,i', $css, $r)) {
2972
-		return $css;
2973
-	}
2971
+    if (!preg_match(',\.css$,i', $css, $r)) {
2972
+        return $css;
2973
+    }
2974 2974
 
2975
-	$url_absolue_css = url_absolue($css);
2975
+    $url_absolue_css = url_absolue($css);
2976 2976
 
2977
-	$f = basename($css, '.css');
2978
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2979
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2980
-		. '.css';
2977
+    $f = basename($css, '.css');
2978
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
2979
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2980
+        . '.css';
2981 2981
 
2982
-	if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') {
2983
-		return $f;
2984
-	}
2982
+    if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') {
2983
+        return $f;
2984
+    }
2985 2985
 
2986
-	$contenu = null;
2987
-	if ($url_absolue_css == $css) {
2988
-		if (
2989
-			strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0
2990
-			|| !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2991
-		) {
2992
-			include_spip('inc/distant');
2993
-			$contenu = recuperer_url($css);
2994
-			$contenu = $contenu['page'] ?? '';
2995
-			if (!$contenu) {
2996
-				return $css;
2997
-			}
2998
-		}
2999
-	} elseif (!lire_fichier($css, $contenu)) {
3000
-		return $css;
3001
-	}
2986
+    $contenu = null;
2987
+    if ($url_absolue_css == $css) {
2988
+        if (
2989
+            strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0
2990
+            || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2991
+        ) {
2992
+            include_spip('inc/distant');
2993
+            $contenu = recuperer_url($css);
2994
+            $contenu = $contenu['page'] ?? '';
2995
+            if (!$contenu) {
2996
+                return $css;
2997
+            }
2998
+        }
2999
+    } elseif (!lire_fichier($css, $contenu)) {
3000
+        return $css;
3001
+    }
3002 3002
 
3003
-	// passer les url relatives a la css d'origine en url absolues
3004
-	$contenu = urls_absolues_css($contenu, $css);
3003
+    // passer les url relatives a la css d'origine en url absolues
3004
+    $contenu = urls_absolues_css($contenu, $css);
3005 3005
 
3006
-	// ecrire la css
3007
-	if (!ecrire_fichier($f, $contenu)) {
3008
-		return $css;
3009
-	}
3006
+    // ecrire la css
3007
+    if (!ecrire_fichier($f, $contenu)) {
3008
+        return $css;
3009
+    }
3010 3010
 
3011
-	return $f;
3011
+    return $f;
3012 3012
 }
3013 3013
 
3014 3014
 
@@ -3042,24 +3042,24 @@  discard block
 block discarded – undo
3042 3042
  *     Valeur trouvée ou valeur par défaut.
3043 3043
  **/
3044 3044
 function table_valeur(mixed $table, $cle, mixed $defaut = '', $conserver_null = false) {
3045
-	foreach (explode('/', $cle) as $k) {
3046
-		$table = (is_string($table) ? @unserialize($table) : $table);
3045
+    foreach (explode('/', $cle) as $k) {
3046
+        $table = (is_string($table) ? @unserialize($table) : $table);
3047 3047
 
3048
-		if (is_object($table)) {
3049
-			$table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut;
3050
-		} elseif (is_array($table)) {
3051
-			if ($conserver_null) {
3052
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3053
-			} else {
3054
-				$table = ($table[$k] ?? $defaut);
3055
-			}
3056
-		} else {
3057
-			$table = $defaut;
3058
-			break;
3059
-		}
3060
-	}
3048
+        if (is_object($table)) {
3049
+            $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut;
3050
+        } elseif (is_array($table)) {
3051
+            if ($conserver_null) {
3052
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3053
+            } else {
3054
+                $table = ($table[$k] ?? $defaut);
3055
+            }
3056
+        } else {
3057
+            $table = $defaut;
3058
+            break;
3059
+        }
3060
+    }
3061 3061
 
3062
-	return $table;
3062
+    return $table;
3063 3063
 }
3064 3064
 
3065 3065
 /**
@@ -3092,22 +3092,22 @@  discard block
 block discarded – undo
3092 3092
  *     - string : expression trouvée.
3093 3093
  **/
3094 3094
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3095
-	if ((int) $modif && $capte == 0) {
3096
-		$capte = $modif;
3097
-		$modif = 'UuimsS';
3098
-	}
3099
-	$expression = str_replace('\/', '/', $expression);
3100
-	$expression = str_replace('/', '\/', $expression);
3095
+    if ((int) $modif && $capte == 0) {
3096
+        $capte = $modif;
3097
+        $modif = 'UuimsS';
3098
+    }
3099
+    $expression = str_replace('\/', '/', $expression);
3100
+    $expression = str_replace('/', '\/', $expression);
3101 3101
 
3102
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3103
-		if (isset($r[$capte])) {
3104
-			return $r[$capte];
3105
-		} else {
3106
-			return true;
3107
-		}
3108
-	}
3102
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3103
+        if (isset($r[$capte])) {
3104
+            return $r[$capte];
3105
+        } else {
3106
+            return true;
3107
+        }
3108
+    }
3109 3109
 
3110
-	return false;
3110
+    return false;
3111 3111
 }
3112 3112
 
3113 3113
 
@@ -3134,14 +3134,14 @@  discard block
 block discarded – undo
3134 3134
  *     Texte
3135 3135
  **/
3136 3136
 function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string {
3137
-	if (null === $texte) {
3138
-		return '';
3139
-	}
3137
+    if (null === $texte) {
3138
+        return '';
3139
+    }
3140 3140
 
3141
-	$expression = str_replace('\/', '/', $expression);
3142
-	$expression = str_replace('/', '\/', $expression);
3141
+    $expression = str_replace('\/', '/', $expression);
3142
+    $expression = str_replace('/', '\/', $expression);
3143 3143
 
3144
-	return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3144
+    return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3145 3145
 }
3146 3146
 
3147 3147
 
@@ -3159,25 +3159,25 @@  discard block
 block discarded – undo
3159 3159
  **/
3160 3160
 function traiter_doublons_documents(&$doublons, $letexte) {
3161 3161
 
3162
-	// Verifier dans le texte & les notes (pas beau, helas)
3163
-	$t = $letexte . $GLOBALS['les_notes'];
3162
+    // Verifier dans le texte & les notes (pas beau, helas)
3163
+    $t = $letexte . $GLOBALS['les_notes'];
3164 3164
 
3165
-	if (
3166
-		strstr($t, 'spip_document_')
3167
-		&& preg_match_all(
3168
-			',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS',
3169
-			$t,
3170
-			$matches,
3171
-			PREG_PATTERN_ORDER
3172
-		)
3173
-	) {
3174
-		if (!isset($doublons['documents'])) {
3175
-			$doublons['documents'] = '';
3176
-		}
3177
-		$doublons['documents'] .= ',' . implode(',', $matches[1]);
3178
-	}
3165
+    if (
3166
+        strstr($t, 'spip_document_')
3167
+        && preg_match_all(
3168
+            ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS',
3169
+            $t,
3170
+            $matches,
3171
+            PREG_PATTERN_ORDER
3172
+        )
3173
+    ) {
3174
+        if (!isset($doublons['documents'])) {
3175
+            $doublons['documents'] = '';
3176
+        }
3177
+        $doublons['documents'] .= ',' . implode(',', $matches[1]);
3178
+    }
3179 3179
 
3180
-	return $letexte;
3180
+    return $letexte;
3181 3181
 }
3182 3182
 
3183 3183
 /**
@@ -3191,7 +3191,7 @@  discard block
 block discarded – undo
3191 3191
  * @return string Chaîne vide
3192 3192
  **/
3193 3193
 function vide(mixed $texte) {
3194
-	return '';
3194
+    return '';
3195 3195
 }
3196 3196
 
3197 3197
 //
@@ -3220,23 +3220,23 @@  discard block
 block discarded – undo
3220 3220
  *      Code HTML résultant
3221 3221
  **/
3222 3222
 function env_to_params($env, $ignore_params = []) {
3223
-	$ignore_params = array_merge(
3224
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3225
-		$ignore_params
3226
-	);
3227
-	if (!is_array($env)) {
3228
-		$env = unserialize($env);
3229
-	}
3230
-	$texte = '';
3231
-	if ($env) {
3232
-		foreach ($env as $i => $j) {
3233
-			if (is_string($j) && !in_array($i, $ignore_params)) {
3234
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3235
-			}
3236
-		}
3237
-	}
3238
-
3239
-	return $texte;
3223
+    $ignore_params = array_merge(
3224
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3225
+        $ignore_params
3226
+    );
3227
+    if (!is_array($env)) {
3228
+        $env = unserialize($env);
3229
+    }
3230
+    $texte = '';
3231
+    if ($env) {
3232
+        foreach ($env as $i => $j) {
3233
+            if (is_string($j) && !in_array($i, $ignore_params)) {
3234
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3235
+            }
3236
+        }
3237
+    }
3238
+
3239
+    return $texte;
3240 3240
 }
3241 3241
 
3242 3242
 /**
@@ -3259,23 +3259,23 @@  discard block
 block discarded – undo
3259 3259
  *      Code HTML résultant
3260 3260
  **/
3261 3261
 function env_to_attributs($env, $ignore_params = []) {
3262
-	$ignore_params = array_merge(
3263
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3264
-		$ignore_params
3265
-	);
3266
-	if (!is_array($env)) {
3267
-		$env = unserialize($env);
3268
-	}
3269
-	$texte = '';
3270
-	if ($env) {
3271
-		foreach ($env as $i => $j) {
3272
-			if (is_string($j) && !in_array($i, $ignore_params)) {
3273
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3274
-			}
3275
-		}
3276
-	}
3262
+    $ignore_params = array_merge(
3263
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3264
+        $ignore_params
3265
+    );
3266
+    if (!is_array($env)) {
3267
+        $env = unserialize($env);
3268
+    }
3269
+    $texte = '';
3270
+    if ($env) {
3271
+        foreach ($env as $i => $j) {
3272
+            if (is_string($j) && !in_array($i, $ignore_params)) {
3273
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3274
+            }
3275
+        }
3276
+    }
3277 3277
 
3278
-	return $texte;
3278
+    return $texte;
3279 3279
 }
3280 3280
 
3281 3281
 
@@ -3293,7 +3293,7 @@  discard block
 block discarded – undo
3293 3293
  * @return string Chaînes concaténés
3294 3294
  **/
3295 3295
 function concat(...$args): string {
3296
-	return implode('', $args);
3296
+    return implode('', $args);
3297 3297
 }
3298 3298
 
3299 3299
 
@@ -3313,23 +3313,23 @@  discard block
 block discarded – undo
3313 3313
  *     Contenu du ou des fichiers, concaténé
3314 3314
  **/
3315 3315
 function charge_scripts($files, $script = true) {
3316
-	$flux = '';
3317
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3318
-		if (!is_string($file)) {
3319
-			continue;
3320
-		}
3321
-		if ($script) {
3322
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3323
-		}
3324
-		if ($file) {
3325
-			$path = find_in_path($file);
3326
-			if ($path) {
3327
-				$flux .= spip_file_get_contents($path);
3328
-			}
3329
-		}
3330
-	}
3331
-
3332
-	return $flux;
3316
+    $flux = '';
3317
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3318
+        if (!is_string($file)) {
3319
+            continue;
3320
+        }
3321
+        if ($script) {
3322
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3323
+        }
3324
+        if ($file) {
3325
+            $path = find_in_path($file);
3326
+            if ($path) {
3327
+                $flux .= spip_file_get_contents($path);
3328
+            }
3329
+        }
3330
+    }
3331
+
3332
+    return $flux;
3333 3333
 }
3334 3334
 
3335 3335
 /**
@@ -3340,24 +3340,24 @@  discard block
 block discarded – undo
3340 3340
  * @return string
3341 3341
  */
3342 3342
 function http_img_variante_svg_si_possible($img_file) {
3343
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3344
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3345
-	if (
3346
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3347
-		&& ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg')
3348
-		&& file_exists($variante_svg_generique)
3349
-	) {
3350
-		if (
3351
-			($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg')
3352
-			&& file_exists($variante_svg_size)
3353
-		) {
3354
-			$img_file = $variante_svg_size;
3355
-		} else {
3356
-			$img_file = $variante_svg_generique;
3357
-		}
3358
-	}
3359
-
3360
-	return $img_file;
3343
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3344
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3345
+    if (
3346
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3347
+        && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg')
3348
+        && file_exists($variante_svg_generique)
3349
+    ) {
3350
+        if (
3351
+            ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg')
3352
+            && file_exists($variante_svg_size)
3353
+        ) {
3354
+            $img_file = $variante_svg_size;
3355
+        } else {
3356
+            $img_file = $variante_svg_generique;
3357
+        }
3358
+    }
3359
+
3360
+    return $img_file;
3361 3361
 }
3362 3362
 
3363 3363
 /**
@@ -3378,51 +3378,51 @@  discard block
 block discarded – undo
3378 3378
  */
3379 3379
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3380 3380
 
3381
-	$img_file = $img;
3382
-	if ($p = strpos($img_file, '?')) {
3383
-		$img_file = substr($img_file, 0, $p);
3384
-	}
3385
-	if (!isset($options['chemin_image']) || $options['chemin_image'] == true) {
3386
-		$img_file = chemin_image($img);
3387
-	}
3388
-	else {
3389
-		if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) {
3390
-			$img_file = http_img_variante_svg_si_possible($img_file);
3391
-		}
3392
-	}
3393
-	if (stripos($atts, 'width') === false) {
3394
-		// utiliser directement l'info de taille presente dans le nom
3395
-		if (
3396
-			(!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg'))
3397
-			&& (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs))
3398
-		) {
3399
-			$largeur = $hauteur = (int) $regs[1];
3400
-		} else {
3401
-			$taille = taille_image($img_file);
3402
-			[$hauteur, $largeur] = $taille;
3403
-			if (!$hauteur || !$largeur) {
3404
-				return '';
3405
-			}
3406
-		}
3407
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3408
-	}
3409
-
3410
-	if (file_exists($img_file)) {
3411
-		$img_file = timestamp($img_file);
3412
-	}
3413
-	if ($alt === false) {
3414
-		$alt = '';
3415
-	}
3416
-	elseif ($alt || $alt === '') {
3417
-		$alt = " alt='" . attribut_html($alt) . "'";
3418
-	}
3419
-	else {
3420
-		$alt = " alt='" . attribut_html($title) . "'";
3421
-	}
3422
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3423
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3424
-	. ' ' . ltrim($atts)
3425
-	. ' />';
3381
+    $img_file = $img;
3382
+    if ($p = strpos($img_file, '?')) {
3383
+        $img_file = substr($img_file, 0, $p);
3384
+    }
3385
+    if (!isset($options['chemin_image']) || $options['chemin_image'] == true) {
3386
+        $img_file = chemin_image($img);
3387
+    }
3388
+    else {
3389
+        if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) {
3390
+            $img_file = http_img_variante_svg_si_possible($img_file);
3391
+        }
3392
+    }
3393
+    if (stripos($atts, 'width') === false) {
3394
+        // utiliser directement l'info de taille presente dans le nom
3395
+        if (
3396
+            (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg'))
3397
+            && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs))
3398
+        ) {
3399
+            $largeur = $hauteur = (int) $regs[1];
3400
+        } else {
3401
+            $taille = taille_image($img_file);
3402
+            [$hauteur, $largeur] = $taille;
3403
+            if (!$hauteur || !$largeur) {
3404
+                return '';
3405
+            }
3406
+        }
3407
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3408
+    }
3409
+
3410
+    if (file_exists($img_file)) {
3411
+        $img_file = timestamp($img_file);
3412
+    }
3413
+    if ($alt === false) {
3414
+        $alt = '';
3415
+    }
3416
+    elseif ($alt || $alt === '') {
3417
+        $alt = " alt='" . attribut_html($alt) . "'";
3418
+    }
3419
+    else {
3420
+        $alt = " alt='" . attribut_html($title) . "'";
3421
+    }
3422
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3423
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3424
+    . ' ' . ltrim($atts)
3425
+    . ' />';
3426 3426
 }
3427 3427
 
3428 3428
 /**
@@ -3434,70 +3434,70 @@  discard block
 block discarded – undo
3434 3434
  * @return string
3435 3435
  */
3436 3436
 function http_style_background($img, $att = '', $size = null) {
3437
-	if ($size && is_numeric($size)) {
3438
-		$size = trim($size) . 'px';
3439
-	}
3440
-	return " style='background" .
3441
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3442
-		. ($size ? "background-size:{$size};" : '')
3443
-		. "'";
3437
+    if ($size && is_numeric($size)) {
3438
+        $size = trim($size) . 'px';
3439
+    }
3440
+    return " style='background" .
3441
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3442
+        . ($size ? "background-size:{$size};" : '')
3443
+        . "'";
3444 3444
 }
3445 3445
 
3446 3446
 
3447 3447
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3448
-	$args = [$alt_or_size, $class_or_size, $size];
3449
-	while (is_null(end($args)) && count($args)) {
3450
-		array_pop($args);
3451
-	}
3452
-	if ($args === []) {
3453
-		return [null, null, null];
3454
-	}
3455
-	if (count($args) < 3) {
3456
-		$maybe_size = array_pop($args);
3457
-		// @2x
3458
-		// @1.5x
3459
-		// 512
3460
-		// 512x*
3461
-		// 512x300
3462
-		if (
3463
-			!strlen((string) $maybe_size)
3464
-			|| !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size))
3465
-		) {
3466
-			$args[] = $maybe_size;
3467
-			$maybe_size = null;
3468
-		}
3469
-		while (count($args) < 2) {
3470
-			$args[] = null; // default alt or class
3471
-		}
3472
-		$args[] = $maybe_size;
3473
-	}
3474
-	return $args;
3448
+    $args = [$alt_or_size, $class_or_size, $size];
3449
+    while (is_null(end($args)) && count($args)) {
3450
+        array_pop($args);
3451
+    }
3452
+    if ($args === []) {
3453
+        return [null, null, null];
3454
+    }
3455
+    if (count($args) < 3) {
3456
+        $maybe_size = array_pop($args);
3457
+        // @2x
3458
+        // @1.5x
3459
+        // 512
3460
+        // 512x*
3461
+        // 512x300
3462
+        if (
3463
+            !strlen((string) $maybe_size)
3464
+            || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size))
3465
+        ) {
3466
+            $args[] = $maybe_size;
3467
+            $maybe_size = null;
3468
+        }
3469
+        while (count($args) < 2) {
3470
+            $args[] = null; // default alt or class
3471
+        }
3472
+        $args[] = $maybe_size;
3473
+    }
3474
+    return $args;
3475 3475
 }
3476 3476
 
3477 3477
 function helper_filtre_balise_img_svg_size($img, $size) {
3478
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3479
-	if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) {
3480
-		$coef = (float) substr((string) $size, 1, -1);
3481
-		[$h, $w] = taille_image($img);
3482
-		$height = (int) round($h / $coef);
3483
-		$width = (int) round($w / $coef);
3484
-	}
3485
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3486
-	else {
3487
-		$size = explode('x', (string) $size, 2);
3488
-		$size = array_map('trim', $size);
3489
-		$height = $width = (int) array_shift($size);
3490
-
3491
-		if (count($size) && reset($size)) {
3492
-			$height = array_shift($size);
3493
-			if ($height === '*') {
3494
-				[$h, $w] = taille_image($img);
3495
-				$height = (int) round($h * $width / $w);
3496
-			}
3497
-		}
3498
-	}
3499
-
3500
-	return [$width, $height];
3478
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3479
+    if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) {
3480
+        $coef = (float) substr((string) $size, 1, -1);
3481
+        [$h, $w] = taille_image($img);
3482
+        $height = (int) round($h / $coef);
3483
+        $width = (int) round($w / $coef);
3484
+    }
3485
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3486
+    else {
3487
+        $size = explode('x', (string) $size, 2);
3488
+        $size = array_map('trim', $size);
3489
+        $height = $width = (int) array_shift($size);
3490
+
3491
+        if (count($size) && reset($size)) {
3492
+            $height = array_shift($size);
3493
+            if ($height === '*') {
3494
+                [$h, $w] = taille_image($img);
3495
+                $height = (int) round($h * $width / $w);
3496
+            }
3497
+        }
3498
+    }
3499
+
3500
+    return [$width, $height];
3501 3501
 }
3502 3502
 
3503 3503
 /**
@@ -3533,38 +3533,38 @@  discard block
 block discarded – undo
3533 3533
  */
3534 3534
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3535 3535
 
3536
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3536
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3537 3537
 
3538
-	$img = trim((string) $img);
3539
-	if (str_starts_with($img, '<img')) {
3540
-		if (!is_null($alt)) {
3541
-			$img = inserer_attribut($img, 'alt', $alt);
3542
-		}
3543
-		if (!is_null($class)) {
3544
-			$img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class');
3545
-		}
3546
-	}
3547
-	else {
3548
-		$img = http_img_pack(
3549
-			$img,
3550
-			$alt,
3551
-			$class ? " class='" . attribut_html($class) . "'" : '',
3552
-			'',
3553
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3554
-		);
3555
-		if (is_null($alt)) {
3556
-			$img = vider_attribut($img, 'alt');
3557
-		}
3558
-	}
3538
+    $img = trim((string) $img);
3539
+    if (str_starts_with($img, '<img')) {
3540
+        if (!is_null($alt)) {
3541
+            $img = inserer_attribut($img, 'alt', $alt);
3542
+        }
3543
+        if (!is_null($class)) {
3544
+            $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class');
3545
+        }
3546
+    }
3547
+    else {
3548
+        $img = http_img_pack(
3549
+            $img,
3550
+            $alt,
3551
+            $class ? " class='" . attribut_html($class) . "'" : '',
3552
+            '',
3553
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3554
+        );
3555
+        if (is_null($alt)) {
3556
+            $img = vider_attribut($img, 'alt');
3557
+        }
3558
+    }
3559 3559
 
3560
-	if ($img && !is_null($size) && strlen($size = trim((string) $size))) {
3561
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3560
+    if ($img && !is_null($size) && strlen($size = trim((string) $size))) {
3561
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3562 3562
 
3563
-		$img = inserer_attribut($img, 'width', $width);
3564
-		$img = inserer_attribut($img, 'height', $height);
3565
-	}
3563
+        $img = inserer_attribut($img, 'width', $width);
3564
+        $img = inserer_attribut($img, 'height', $height);
3565
+    }
3566 3566
 
3567
-	return $img;
3567
+    return $img;
3568 3568
 }
3569 3569
 
3570 3570
 
@@ -3598,77 +3598,77 @@  discard block
 block discarded – undo
3598 3598
  */
3599 3599
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3600 3600
 
3601
-	$svg = null;
3602
-	$img = trim($img);
3603
-	$img_file = $img;
3604
-	if (!str_contains($img, '<svg')) {
3605
-		if ($p = strpos($img_file, '?')) {
3606
-			$img_file = substr($img_file, 0, $p);
3607
-		}
3608
-
3609
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3610
-		// la copie locale a toutes les chances d'etre la ou de resservir
3611
-		if (tester_url_absolue($img_file)) {
3612
-			include_spip('inc/distant');
3613
-			$fichier = copie_locale($img_file);
3614
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3615
-		}
3616
-
3617
-		if (
3618
-			!$img_file
3619
-			|| !file_exists($img_file)
3620
-			|| !$svg = file_get_contents($img_file)
3621
-		) {
3622
-			return '';
3623
-		}
3624
-	}
3625
-
3626
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3627
-		return '';
3628
-	}
3629
-
3630
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3631
-
3632
-	$balise_svg = $match[0];
3633
-	$balise_svg_source = $balise_svg;
3634
-
3635
-	// entete XML à supprimer
3636
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg);
3637
-
3638
-	// IE est toujours mon ami
3639
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3640
-
3641
-	// regler la classe
3642
-	if (!is_null($class)) {
3643
-		$balise_svg = strlen((string) $class)
3644
-			? inserer_attribut($balise_svg, 'class', $class)
3645
-			: vider_attribut($balise_svg, 'class');
3646
-	}
3647
-
3648
-	// regler le alt
3649
-	if ($alt) {
3650
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3651
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3652
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3653
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3654
-		$balise_svg .= $title;
3655
-	}
3656
-	else {
3657
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3658
-	}
3659
-
3660
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3661
-
3662
-	if (!is_null($size) && strlen($size = trim((string) $size))) {
3663
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3664
-
3665
-		if (!function_exists('svg_redimensionner')) {
3666
-			include_spip('inc/svg');
3667
-		}
3668
-		$svg = svg_redimensionner($svg, $width, $height);
3669
-	}
3670
-
3671
-	return $svg;
3601
+    $svg = null;
3602
+    $img = trim($img);
3603
+    $img_file = $img;
3604
+    if (!str_contains($img, '<svg')) {
3605
+        if ($p = strpos($img_file, '?')) {
3606
+            $img_file = substr($img_file, 0, $p);
3607
+        }
3608
+
3609
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3610
+        // la copie locale a toutes les chances d'etre la ou de resservir
3611
+        if (tester_url_absolue($img_file)) {
3612
+            include_spip('inc/distant');
3613
+            $fichier = copie_locale($img_file);
3614
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3615
+        }
3616
+
3617
+        if (
3618
+            !$img_file
3619
+            || !file_exists($img_file)
3620
+            || !$svg = file_get_contents($img_file)
3621
+        ) {
3622
+            return '';
3623
+        }
3624
+    }
3625
+
3626
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3627
+        return '';
3628
+    }
3629
+
3630
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3631
+
3632
+    $balise_svg = $match[0];
3633
+    $balise_svg_source = $balise_svg;
3634
+
3635
+    // entete XML à supprimer
3636
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg);
3637
+
3638
+    // IE est toujours mon ami
3639
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3640
+
3641
+    // regler la classe
3642
+    if (!is_null($class)) {
3643
+        $balise_svg = strlen((string) $class)
3644
+            ? inserer_attribut($balise_svg, 'class', $class)
3645
+            : vider_attribut($balise_svg, 'class');
3646
+    }
3647
+
3648
+    // regler le alt
3649
+    if ($alt) {
3650
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3651
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3652
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3653
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3654
+        $balise_svg .= $title;
3655
+    }
3656
+    else {
3657
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3658
+    }
3659
+
3660
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3661
+
3662
+    if (!is_null($size) && strlen($size = trim((string) $size))) {
3663
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3664
+
3665
+        if (!function_exists('svg_redimensionner')) {
3666
+            include_spip('inc/svg');
3667
+        }
3668
+        $svg = svg_redimensionner($svg, $width, $height);
3669
+    }
3670
+
3671
+    return $svg;
3672 3672
 }
3673 3673
 
3674 3674
 /**
@@ -3692,37 +3692,37 @@  discard block
 block discarded – undo
3692 3692
  *         - tout : retourne toutes les informations du plugin actif
3693 3693
  **/
3694 3694
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3695
-	include_spip('inc/plugin');
3696
-	$plugin = strtoupper($plugin);
3697
-	$plugins_actifs = liste_plugin_actifs();
3698
-
3699
-	if (!$plugin) {
3700
-		return serialize(array_keys($plugins_actifs));
3701
-	} elseif (empty($plugins_actifs[$plugin]) && !$reload) {
3702
-		return '';
3703
-	} elseif ($type_info == 'est_actif' && !$reload) {
3704
-		return $plugins_actifs[$plugin] ? 1 : 0;
3705
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) {
3706
-		return $plugins_actifs[$plugin][$type_info];
3707
-	} else {
3708
-		$get_infos = charger_fonction('get_infos', 'plugins');
3709
-		// On prend en compte les extensions
3710
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3711
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3712
-		} else {
3713
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3714
-		}
3715
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3716
-			return '';
3717
-		}
3718
-		if ($type_info == 'tout') {
3719
-			return $infos;
3720
-		} elseif ($type_info == 'est_actif') {
3721
-			return $infos ? 1 : 0;
3722
-		} else {
3723
-			return (string) $infos[$type_info];
3724
-		}
3725
-	}
3695
+    include_spip('inc/plugin');
3696
+    $plugin = strtoupper($plugin);
3697
+    $plugins_actifs = liste_plugin_actifs();
3698
+
3699
+    if (!$plugin) {
3700
+        return serialize(array_keys($plugins_actifs));
3701
+    } elseif (empty($plugins_actifs[$plugin]) && !$reload) {
3702
+        return '';
3703
+    } elseif ($type_info == 'est_actif' && !$reload) {
3704
+        return $plugins_actifs[$plugin] ? 1 : 0;
3705
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) {
3706
+        return $plugins_actifs[$plugin][$type_info];
3707
+    } else {
3708
+        $get_infos = charger_fonction('get_infos', 'plugins');
3709
+        // On prend en compte les extensions
3710
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3711
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3712
+        } else {
3713
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3714
+        }
3715
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3716
+            return '';
3717
+        }
3718
+        if ($type_info == 'tout') {
3719
+            return $infos;
3720
+        } elseif ($type_info == 'est_actif') {
3721
+            return $infos ? 1 : 0;
3722
+        } else {
3723
+            return (string) $infos[$type_info];
3724
+        }
3725
+    }
3726 3726
 }
3727 3727
 
3728 3728
 
@@ -3749,9 +3749,9 @@  discard block
 block discarded – undo
3749 3749
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3750 3750
  */
3751 3751
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3752
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3752
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3753 3753
 
3754
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3754
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3755 3755
 }
3756 3756
 
3757 3757
 
@@ -3781,19 +3781,19 @@  discard block
 block discarded – undo
3781 3781
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3782 3782
  */
3783 3783
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3784
-	static $puce_statut = null;
3785
-	if (!$puce_statut) {
3786
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3787
-	}
3784
+    static $puce_statut = null;
3785
+    if (!$puce_statut) {
3786
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3787
+    }
3788 3788
 
3789
-	return $puce_statut(
3790
-		$id_objet,
3791
-		$statut,
3792
-		$id_parent,
3793
-		$objet,
3794
-		false,
3795
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3796
-	);
3789
+    return $puce_statut(
3790
+        $id_objet,
3791
+        $statut,
3792
+        $id_parent,
3793
+        $objet,
3794
+        false,
3795
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3796
+    );
3797 3797
 }
3798 3798
 
3799 3799
 
@@ -3820,94 +3820,94 @@  discard block
 block discarded – undo
3820 3820
  *   hash du contexte
3821 3821
  */
3822 3822
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3823
-	$env = null;
3824
-	if (is_string($c) && @unserialize($c) !== false) {
3825
-		$c = unserialize($c);
3826
-	}
3827
-
3828
-	// supprimer les parametres debut_x
3829
-	// pour que la pagination ajax ne soit pas plantee
3830
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3831
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3832
-	if (is_array($c)) {
3833
-		foreach (array_keys($c) as $k) {
3834
-			if (str_starts_with($k, 'debut_')) {
3835
-				unset($c[$k]);
3836
-			}
3837
-		}
3838
-	}
3839
-
3840
-	if (!function_exists('calculer_cle_action')) {
3841
-		include_spip('inc/securiser_action');
3842
-	}
3843
-
3844
-	$c = serialize($c);
3845
-	$cle = calculer_cle_action($form . $c);
3846
-	$c = "$cle:$c";
3847
-
3848
-	// on ne stocke pas les contextes dans des fichiers en cache
3849
-	// par defaut, sauf si cette configuration a été forcée
3850
-	// OU que la longueur de l’argument géneré est plus long
3851
-	// que ce qui est toléré.
3852
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX);
3853
-	if (!$cache_contextes_ajax) {
3854
-		$env = $c;
3855
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3856
-			$env = gzdeflate($env);
3857
-		}
3858
-		$env = _xor($env);
3859
-		$env = base64_encode($env);
3860
-		$len = strlen($env);
3861
-		// Si l’url est trop longue pour le navigateur
3862
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3863
-		if ($len > $max_len) {
3864
-			$cache_contextes_ajax = true;
3865
-			spip_logger()->warning(
3866
-				'Contextes AJAX forces en fichiers !'
3867
-				. ' Cela arrive lorsque la valeur du contexte'
3868
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3869
-			);
3870
-		}
3871
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3872
-		elseif (
3873
-			($max_len = @ini_get('suhosin.get.max_value_length'))
3874
-			&& $max_len < $len
3875
-		) {
3876
-			$cache_contextes_ajax = true;
3877
-			spip_logger()->warning('Contextes AJAX forces en fichiers !'
3878
-				. ' Cela arrive lorsque la valeur du contexte'
3879
-				. ' depasse la longueur maximale autorisee par Suhosin'
3880
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3881
-				. ' Vous devriez modifier les parametres de Suhosin'
3882
-				. ' pour accepter au moins 1024 caracteres.');
3883
-		}
3884
-	}
3885
-
3886
-	if ($cache_contextes_ajax) {
3887
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3888
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3889
-		$md5 = md5($c);
3890
-		ecrire_fichier("$dir/c$md5", $c);
3891
-		$env = $md5;
3892
-	}
3893
-
3894
-	if ($emboite === null) {
3895
-		return $env;
3896
-	}
3897
-	if (!trim($emboite)) {
3898
-		return '';
3899
-	}
3900
-	// toujours encoder l'url source dans le bloc ajax
3901
-	$r = self();
3902
-	$r = ' data-origin="' . $r . '"';
3903
-	$class = 'ajaxbloc';
3904
-	if ($ajaxid && is_string($ajaxid)) {
3905
-		// ajaxid est normalement conforme a un nom de classe css
3906
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3907
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3908
-	}
3909
-
3910
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3823
+    $env = null;
3824
+    if (is_string($c) && @unserialize($c) !== false) {
3825
+        $c = unserialize($c);
3826
+    }
3827
+
3828
+    // supprimer les parametres debut_x
3829
+    // pour que la pagination ajax ne soit pas plantee
3830
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3831
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3832
+    if (is_array($c)) {
3833
+        foreach (array_keys($c) as $k) {
3834
+            if (str_starts_with($k, 'debut_')) {
3835
+                unset($c[$k]);
3836
+            }
3837
+        }
3838
+    }
3839
+
3840
+    if (!function_exists('calculer_cle_action')) {
3841
+        include_spip('inc/securiser_action');
3842
+    }
3843
+
3844
+    $c = serialize($c);
3845
+    $cle = calculer_cle_action($form . $c);
3846
+    $c = "$cle:$c";
3847
+
3848
+    // on ne stocke pas les contextes dans des fichiers en cache
3849
+    // par defaut, sauf si cette configuration a été forcée
3850
+    // OU que la longueur de l’argument géneré est plus long
3851
+    // que ce qui est toléré.
3852
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX);
3853
+    if (!$cache_contextes_ajax) {
3854
+        $env = $c;
3855
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3856
+            $env = gzdeflate($env);
3857
+        }
3858
+        $env = _xor($env);
3859
+        $env = base64_encode($env);
3860
+        $len = strlen($env);
3861
+        // Si l’url est trop longue pour le navigateur
3862
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3863
+        if ($len > $max_len) {
3864
+            $cache_contextes_ajax = true;
3865
+            spip_logger()->warning(
3866
+                'Contextes AJAX forces en fichiers !'
3867
+                . ' Cela arrive lorsque la valeur du contexte'
3868
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3869
+            );
3870
+        }
3871
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3872
+        elseif (
3873
+            ($max_len = @ini_get('suhosin.get.max_value_length'))
3874
+            && $max_len < $len
3875
+        ) {
3876
+            $cache_contextes_ajax = true;
3877
+            spip_logger()->warning('Contextes AJAX forces en fichiers !'
3878
+                . ' Cela arrive lorsque la valeur du contexte'
3879
+                . ' depasse la longueur maximale autorisee par Suhosin'
3880
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3881
+                . ' Vous devriez modifier les parametres de Suhosin'
3882
+                . ' pour accepter au moins 1024 caracteres.');
3883
+        }
3884
+    }
3885
+
3886
+    if ($cache_contextes_ajax) {
3887
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3888
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3889
+        $md5 = md5($c);
3890
+        ecrire_fichier("$dir/c$md5", $c);
3891
+        $env = $md5;
3892
+    }
3893
+
3894
+    if ($emboite === null) {
3895
+        return $env;
3896
+    }
3897
+    if (!trim($emboite)) {
3898
+        return '';
3899
+    }
3900
+    // toujours encoder l'url source dans le bloc ajax
3901
+    $r = self();
3902
+    $r = ' data-origin="' . $r . '"';
3903
+    $class = 'ajaxbloc';
3904
+    if ($ajaxid && is_string($ajaxid)) {
3905
+        // ajaxid est normalement conforme a un nom de classe css
3906
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3907
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3908
+    }
3909
+
3910
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3911 3911
 }
3912 3912
 
3913 3913
 /**
@@ -3927,37 +3927,37 @@  discard block
 block discarded – undo
3927 3927
  *   - false : erreur de décodage
3928 3928
  */
3929 3929
 function decoder_contexte_ajax($c, $form = '') {
3930
-	$contexte = null;
3931
-	if (!function_exists('calculer_cle_action')) {
3932
-		include_spip('inc/securiser_action');
3933
-	}
3934
-	if (
3935
-		(defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32)
3936
-		&& ($dir = sous_repertoire(_DIR_CACHE, 'contextes'))
3937
-		&& lire_fichier("$dir/c$c", $contexte)
3938
-	) {
3939
-		$c = $contexte;
3940
-	} else {
3941
-		$c = @base64_decode($c);
3942
-		$c = _xor($c);
3943
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3944
-			$c = @gzinflate($c);
3945
-		}
3946
-	}
3947
-
3948
-	// extraire la signature en debut de contexte
3949
-	// et la verifier avant de deserializer
3950
-	// format : signature:donneesserializees
3951
-	if ($p = strpos((string) $c, ':')) {
3952
-		$cle = substr((string) $c, 0, $p);
3953
-		$c = substr((string) $c, $p + 1);
3954
-
3955
-		if ($cle === calculer_cle_action($form . $c)) {
3956
-			return @unserialize($c);
3957
-		}
3958
-	}
3959
-
3960
-	return false;
3930
+    $contexte = null;
3931
+    if (!function_exists('calculer_cle_action')) {
3932
+        include_spip('inc/securiser_action');
3933
+    }
3934
+    if (
3935
+        (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32)
3936
+        && ($dir = sous_repertoire(_DIR_CACHE, 'contextes'))
3937
+        && lire_fichier("$dir/c$c", $contexte)
3938
+    ) {
3939
+        $c = $contexte;
3940
+    } else {
3941
+        $c = @base64_decode($c);
3942
+        $c = _xor($c);
3943
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3944
+            $c = @gzinflate($c);
3945
+        }
3946
+    }
3947
+
3948
+    // extraire la signature en debut de contexte
3949
+    // et la verifier avant de deserializer
3950
+    // format : signature:donneesserializees
3951
+    if ($p = strpos((string) $c, ':')) {
3952
+        $cle = substr((string) $c, 0, $p);
3953
+        $c = substr((string) $c, $p + 1);
3954
+
3955
+        if ($cle === calculer_cle_action($form . $c)) {
3956
+            return @unserialize($c);
3957
+        }
3958
+    }
3959
+
3960
+    return false;
3961 3961
 }
3962 3962
 
3963 3963
 
@@ -3975,20 +3975,20 @@  discard block
 block discarded – undo
3975 3975
  *    Message décrypté ou encrypté
3976 3976
  **/
3977 3977
 function _xor($message, $key = null) {
3978
-	if (is_null($key)) {
3979
-		if (!function_exists('calculer_cle_action')) {
3980
-			include_spip('inc/securiser_action');
3981
-		}
3982
-		$key = pack('H*', calculer_cle_action('_xor'));
3983
-	}
3978
+    if (is_null($key)) {
3979
+        if (!function_exists('calculer_cle_action')) {
3980
+            include_spip('inc/securiser_action');
3981
+        }
3982
+        $key = pack('H*', calculer_cle_action('_xor'));
3983
+    }
3984 3984
 
3985
-	$keylen = strlen($key);
3986
-	$messagelen = strlen($message);
3987
-	for ($i = 0; $i < $messagelen; $i++) {
3988
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3989
-	}
3985
+    $keylen = strlen($key);
3986
+    $messagelen = strlen($message);
3987
+    for ($i = 0; $i < $messagelen; $i++) {
3988
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3989
+    }
3990 3990
 
3991
-	return $message;
3991
+    return $message;
3992 3992
 }
3993 3993
 
3994 3994
 /**
@@ -4002,7 +4002,7 @@  discard block
 block discarded – undo
4002 4002
  * @return string
4003 4003
  */
4004 4004
 function url_reponse_forum($texte) {
4005
- return $texte;
4005
+    return $texte;
4006 4006
 }
4007 4007
 
4008 4008
 /**
@@ -4016,7 +4016,7 @@  discard block
 block discarded – undo
4016 4016
  * @return string
4017 4017
  */
4018 4018
 function url_rss_forum($texte) {
4019
- return $texte;
4019
+    return $texte;
4020 4020
 }
4021 4021
 
4022 4022
 
@@ -4055,37 +4055,37 @@  discard block
 block discarded – undo
4055 4055
  *   Code HTML
4056 4056
  */
4057 4057
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4058
-	if ($on) {
4059
-		$bal = 'strong';
4060
-		$class = '';
4061
-		$att = '';
4062
-		// si $on passe la balise et optionnelement une ou ++classe
4063
-		// a.active span.selected.active etc....
4064
-		if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) {
4065
-			$on = explode('.', $on);
4066
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4067
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4068
-				$bal = array_shift($on);
4069
-				$class = implode(' ', $on);
4070
-				if ($bal == 'a') {
4071
-					$att = 'href="#" ';
4072
-				}
4073
-			}
4074
-		}
4075
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4076
-	} else {
4077
-		$bal = 'a';
4078
-		$att = "href='$url'"
4079
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4080
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4081
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4082
-			. $evt;
4083
-	}
4084
-	if ($libelle === null) {
4085
-		$libelle = $url;
4086
-	}
4087
-
4088
-	return "<$bal $att>$libelle</$bal>";
4058
+    if ($on) {
4059
+        $bal = 'strong';
4060
+        $class = '';
4061
+        $att = '';
4062
+        // si $on passe la balise et optionnelement une ou ++classe
4063
+        // a.active span.selected.active etc....
4064
+        if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) {
4065
+            $on = explode('.', $on);
4066
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4067
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4068
+                $bal = array_shift($on);
4069
+                $class = implode(' ', $on);
4070
+                if ($bal == 'a') {
4071
+                    $att = 'href="#" ';
4072
+                }
4073
+            }
4074
+        }
4075
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4076
+    } else {
4077
+        $bal = 'a';
4078
+        $att = "href='$url'"
4079
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4080
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4081
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4082
+            . $evt;
4083
+    }
4084
+    if ($libelle === null) {
4085
+        $libelle = $url;
4086
+    }
4087
+
4088
+    return "<$bal $att>$libelle</$bal>";
4089 4089
 }
4090 4090
 
4091 4091
 
@@ -4102,39 +4102,39 @@  discard block
 block discarded – undo
4102 4102
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4103 4103
  */
4104 4104
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4105
-	static $local_singulier_ou_pluriel = [];
4106
-
4107
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4108
-	if (!is_numeric($nb) || $nb == 0) {
4109
-		return '';
4110
-	}
4111
-	if (!is_array($vars)) {
4112
-		return '';
4113
-	}
4114
-
4115
-	$langue = $GLOBALS['spip_lang'];
4116
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4117
-		$local_singulier_ou_pluriel[$langue] = false;
4118
-		if (
4119
-			($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true))
4120
-			|| ($f = charger_fonction('singulier_ou_pluriel', 'inc', true))
4121
-		) {
4122
-			$local_singulier_ou_pluriel[$langue] = $f;
4123
-		}
4124
-	}
4125
-
4126
-	// si on a une surcharge on l'utilise
4127
-	if ($local_singulier_ou_pluriel[$langue]) {
4128
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4129
-	}
4130
-
4131
-	// sinon traitement par defaut
4132
-	$vars[$var] = $nb;
4133
-	if ($nb >= 2) {
4134
-		return _T($chaine_plusieurs, $vars);
4135
-	} else {
4136
-		return _T($chaine_un, $vars);
4137
-	}
4105
+    static $local_singulier_ou_pluriel = [];
4106
+
4107
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4108
+    if (!is_numeric($nb) || $nb == 0) {
4109
+        return '';
4110
+    }
4111
+    if (!is_array($vars)) {
4112
+        return '';
4113
+    }
4114
+
4115
+    $langue = $GLOBALS['spip_lang'];
4116
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4117
+        $local_singulier_ou_pluriel[$langue] = false;
4118
+        if (
4119
+            ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true))
4120
+            || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true))
4121
+        ) {
4122
+            $local_singulier_ou_pluriel[$langue] = $f;
4123
+        }
4124
+    }
4125
+
4126
+    // si on a une surcharge on l'utilise
4127
+    if ($local_singulier_ou_pluriel[$langue]) {
4128
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4129
+    }
4130
+
4131
+    // sinon traitement par defaut
4132
+    $vars[$var] = $nb;
4133
+    if ($nb >= 2) {
4134
+        return _T($chaine_plusieurs, $vars);
4135
+    } else {
4136
+        return _T($chaine_un, $vars);
4137
+    }
4138 4138
 }
4139 4139
 
4140 4140
 
@@ -4162,71 +4162,71 @@  discard block
 block discarded – undo
4162 4162
  */
4163 4163
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4164 4164
 
4165
-	$class_lien = $class_bouton = $class;
4166
-
4167
-	// Normaliser la fonction et compléter la classe en fonction
4168
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4169
-		$class_lien .= ' danger';
4170
-		$class_bouton .= ' btn_danger';
4171
-	} elseif ($fonction == 'rien.gif') {
4172
-		$fonction = '';
4173
-	} elseif ($fonction == 'delsafe') {
4174
-		$fonction = 'del';
4175
-	}
4176
-
4177
-	$fond_origine = $fond;
4178
-	// Remappage des icone : article-24.png+new => article-new-24.png
4179
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4180
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4181
-	}
4182
-
4183
-	// Ajouter le type d'objet dans la classe
4184
-	$objet_type = substr(basename((string) $fond), 0, -4);
4185
-	$class_lien .= " $objet_type";
4186
-	$class_bouton .= " $objet_type";
4187
-
4188
-	// texte
4189
-	$alt = attribut_html($texte);
4190
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4191
-
4192
-	// Liens : préparer les classes ajax
4193
-	$ajax = '';
4194
-	if ($type === 'lien' && str_contains($class_lien, 'ajax')) {
4195
-		$ajax = 'ajax';
4196
-		if (str_contains($class_lien, 'preload')) {
4197
-			$ajax .= ' preload';
4198
-		}
4199
-		if (str_contains($class_lien, 'nocache')) {
4200
-			$ajax .= ' nocache';
4201
-		}
4202
-		$ajax = " class='$ajax'";
4203
-	}
4204
-
4205
-	// Repérer la taille et l'ajouter dans la classe
4206
-	$size = 24;
4207
-	if (
4208
-		preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match)
4209
-		|| preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4210
-	) {
4211
-		$size = $match[1];
4212
-	}
4213
-	$class_lien .= " s$size";
4214
-	$class_bouton .= " s$size";
4215
-
4216
-	// Icône
4217
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4218
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4219
-
4220
-	// Markup final
4221
-	if ($type == 'lien') {
4222
-		return "<span class='icone $class_lien'>"
4223
-		. "<a href='$lien'$title$ajax$javascript>"
4224
-		. $icone
4225
-		. "<b>$texte</b>"
4226
-		. "</a></span>\n";
4227
-	} else {
4228
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4229
-	}
4165
+    $class_lien = $class_bouton = $class;
4166
+
4167
+    // Normaliser la fonction et compléter la classe en fonction
4168
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4169
+        $class_lien .= ' danger';
4170
+        $class_bouton .= ' btn_danger';
4171
+    } elseif ($fonction == 'rien.gif') {
4172
+        $fonction = '';
4173
+    } elseif ($fonction == 'delsafe') {
4174
+        $fonction = 'del';
4175
+    }
4176
+
4177
+    $fond_origine = $fond;
4178
+    // Remappage des icone : article-24.png+new => article-new-24.png
4179
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4180
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4181
+    }
4182
+
4183
+    // Ajouter le type d'objet dans la classe
4184
+    $objet_type = substr(basename((string) $fond), 0, -4);
4185
+    $class_lien .= " $objet_type";
4186
+    $class_bouton .= " $objet_type";
4187
+
4188
+    // texte
4189
+    $alt = attribut_html($texte);
4190
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4191
+
4192
+    // Liens : préparer les classes ajax
4193
+    $ajax = '';
4194
+    if ($type === 'lien' && str_contains($class_lien, 'ajax')) {
4195
+        $ajax = 'ajax';
4196
+        if (str_contains($class_lien, 'preload')) {
4197
+            $ajax .= ' preload';
4198
+        }
4199
+        if (str_contains($class_lien, 'nocache')) {
4200
+            $ajax .= ' nocache';
4201
+        }
4202
+        $ajax = " class='$ajax'";
4203
+    }
4204
+
4205
+    // Repérer la taille et l'ajouter dans la classe
4206
+    $size = 24;
4207
+    if (
4208
+        preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match)
4209
+        || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4210
+    ) {
4211
+        $size = $match[1];
4212
+    }
4213
+    $class_lien .= " s$size";
4214
+    $class_bouton .= " s$size";
4215
+
4216
+    // Icône
4217
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4218
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4219
+
4220
+    // Markup final
4221
+    if ($type == 'lien') {
4222
+        return "<span class='icone $class_lien'>"
4223
+        . "<a href='$lien'$title$ajax$javascript>"
4224
+        . $icone
4225
+        . "<b>$texte</b>"
4226
+        . "</a></span>\n";
4227
+    } else {
4228
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4229
+    }
4230 4230
 }
4231 4231
 
4232 4232
 /**
@@ -4250,7 +4250,7 @@  discard block
 block discarded – undo
4250 4250
  *     Code HTML du lien
4251 4251
  **/
4252 4252
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4253
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4253
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4254 4254
 }
4255 4255
 
4256 4256
 /**
@@ -4285,7 +4285,7 @@  discard block
 block discarded – undo
4285 4285
  *     Code HTML du lien
4286 4286
  **/
4287 4287
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4288
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4288
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4289 4289
 }
4290 4290
 
4291 4291
 /**
@@ -4330,7 +4330,7 @@  discard block
 block discarded – undo
4330 4330
  *     Code HTML du lien
4331 4331
  **/
4332 4332
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4333
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4333
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4334 4334
 }
4335 4335
 
4336 4336
 /**
@@ -4361,7 +4361,7 @@  discard block
 block discarded – undo
4361 4361
  *     Code HTML du lien
4362 4362
  **/
4363 4363
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4364
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4364
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4365 4365
 }
4366 4366
 
4367 4367
 /**
@@ -4392,7 +4392,7 @@  discard block
 block discarded – undo
4392 4392
  *     Code HTML du lien
4393 4393
  */
4394 4394
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4395
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4395
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4396 4396
 }
4397 4397
 
4398 4398
 
@@ -4414,7 +4414,7 @@  discard block
 block discarded – undo
4414 4414
  * @return array Liste des éléments
4415 4415
  */
4416 4416
 function filtre_explode_dist($a, $b) {
4417
-	return explode($b, (string) $a);
4417
+    return explode($b, (string) $a);
4418 4418
 }
4419 4419
 
4420 4420
 /**
@@ -4435,7 +4435,7 @@  discard block
 block discarded – undo
4435 4435
  * @return string texte
4436 4436
  */
4437 4437
 function filtre_implode_dist($a, $b) {
4438
-	return is_array($a) ? implode($b, $a) : $a;
4438
+    return is_array($a) ? implode($b, $a) : $a;
4439 4439
 }
4440 4440
 
4441 4441
 /**
@@ -4444,22 +4444,22 @@  discard block
 block discarded – undo
4444 4444
  * @return string Code CSS
4445 4445
  */
4446 4446
 function bando_images_background() {
4447
-	include_spip('inc/bandeau');
4448
-	// recuperer tous les boutons et leurs images
4449
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4447
+    include_spip('inc/bandeau');
4448
+    // recuperer tous les boutons et leurs images
4449
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4450 4450
 
4451
-	$res = '';
4452
-	foreach ($boutons as $page => $detail) {
4453
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4454
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4455
-			if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) {
4456
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4457
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4458
-			}
4459
-		}
4460
-	}
4451
+    $res = '';
4452
+    foreach ($boutons as $page => $detail) {
4453
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4454
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4455
+            if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) {
4456
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4457
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4458
+            }
4459
+        }
4460
+    }
4461 4461
 
4462
-	return $res;
4462
+    return $res;
4463 4463
 }
4464 4464
 
4465 4465
 /**
@@ -4484,23 +4484,23 @@  discard block
 block discarded – undo
4484 4484
  */
4485 4485
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4486 4486
 
4487
-	// Classes : dispatcher `ajax` sur le formulaire
4488
-	$class_form = '';
4489
-	if (str_contains($class, 'ajax')) {
4490
-		$class_form = 'ajax';
4491
-		$class = str_replace('ajax', '', $class);
4492
-	}
4493
-	$class_btn = 'submit ' . trim($class);
4487
+    // Classes : dispatcher `ajax` sur le formulaire
4488
+    $class_form = '';
4489
+    if (str_contains($class, 'ajax')) {
4490
+        $class_form = 'ajax';
4491
+        $class = str_replace('ajax', '', $class);
4492
+    }
4493
+    $class_btn = 'submit ' . trim($class);
4494 4494
 
4495
-	if ($confirm) {
4496
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4497
-		$callback = $callback ? "$confirm?($callback):false" : $confirm;
4498
-	}
4499
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4500
-	$title = $title ? " title='$title'" : '';
4495
+    if ($confirm) {
4496
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4497
+        $callback = $callback ? "$confirm?($callback):false" : $confirm;
4498
+    }
4499
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4500
+    $title = $title ? " title='$title'" : '';
4501 4501
 
4502
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4503
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4502
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4503
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4504 4504
 }
4505 4505
 
4506 4506
 /**
@@ -4523,104 +4523,104 @@  discard block
 block discarded – undo
4523 4523
  * @return string
4524 4524
  */
4525 4525
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4526
-	static $trouver_table = null;
4527
-	static $objets;
4528
-
4529
-	// On verifie qu'on a tout ce qu'il faut
4530
-	$id_objet = (int) $id_objet;
4531
-	if (!($id_objet && $type_objet && $info)) {
4532
-		return '';
4533
-	}
4534
-
4535
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4536
-	if (isset($objets[$type_objet]) && $objets[$type_objet] === false) {
4537
-		return '';
4538
-	}
4539
-
4540
-	// Si on demande l'url, on retourne direct la fonction
4541
-	if ($info == 'url') {
4542
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4543
-	}
4544
-
4545
-	// Sinon on va tout chercher dans la table et on garde en memoire
4546
-	$demande_titre = ($info === 'titre');
4547
-	$demande_introduction = ($info === 'introduction');
4548
-
4549
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4550
-	if (
4551
-		!isset($objets[$type_objet][$id_objet])
4552
-		|| $demande_titre && !isset($objets[$type_objet][$id_objet]['titre'])
4553
-	) {
4554
-		if (!$trouver_table) {
4555
-			$trouver_table = charger_fonction('trouver_table', 'base');
4556
-		}
4557
-		$desc = $trouver_table(table_objet_sql($type_objet));
4558
-		if (!$desc) {
4559
-			return $objets[$type_objet] = false;
4560
-		}
4561
-
4562
-		// Si on demande le titre, on le gere en interne
4563
-		$champ_titre = '';
4564
-		if ($demande_titre) {
4565
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4566
-			$champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre'];
4567
-		}
4568
-		include_spip('base/abstract_sql');
4569
-		include_spip('base/connect_sql');
4570
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4571
-			'*' . $champ_titre,
4572
-			$desc['table_sql'],
4573
-			id_table_objet($type_objet) . ' = ' . (int) $id_objet
4574
-		);
4575
-
4576
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4577
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4578
-	}
4579
-
4580
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4581
-	// ajouter la longueur au début des params supplémentaires
4582
-	if ($demande_introduction) {
4583
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4584
-		array_unshift($params, $introduction_longueur);
4585
-	}
4586
-
4587
-	$row = ($objets[$type_objet][$id_objet] ?? []) ?: [];
4588
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4589
-	if ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) {
4590
-		$info_generee = $generer($id_objet, $row, ...$params);
4591
-	}
4592
-	// @deprecated 4.1 generer_TRUC_TYPE
4593
-	elseif ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) {
4594
-		trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_{$type_objet}", "generer_{$type_objet}_{$info}");
4595
-		$info_generee = $generer($id_objet, $row, ...$params);
4596
-	}
4597
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4598
-	elseif ($generer = charger_fonction("generer_objet_{$info}", '', true)) {
4599
-		$info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4600
-	}
4601
-	// @deprecated 4.1 generer_TRUC_entite
4602
-	elseif ($generer = charger_fonction("generer_{$info}_entite", '', true)) {
4603
-		trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_entite", "generer_objet_{$info}");
4604
-		$info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4605
-	}
4606
-	// Sinon on prend directement le champ SQL tel quel
4607
-	else {
4608
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4609
-	}
4610
-
4611
-	// On va ensuite appliquer les traitements automatiques si besoin
4612
-	if (!$etoile) {
4613
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4614
-		// mais ce fonctionnement est a ameliorer !
4615
-		$info_generee = appliquer_traitement_champ(
4616
-			$info_generee,
4617
-			$info,
4618
-			table_objet($type_objet),
4619
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4620
-		);
4621
-	}
4622
-
4623
-	return $info_generee;
4526
+    static $trouver_table = null;
4527
+    static $objets;
4528
+
4529
+    // On verifie qu'on a tout ce qu'il faut
4530
+    $id_objet = (int) $id_objet;
4531
+    if (!($id_objet && $type_objet && $info)) {
4532
+        return '';
4533
+    }
4534
+
4535
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4536
+    if (isset($objets[$type_objet]) && $objets[$type_objet] === false) {
4537
+        return '';
4538
+    }
4539
+
4540
+    // Si on demande l'url, on retourne direct la fonction
4541
+    if ($info == 'url') {
4542
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4543
+    }
4544
+
4545
+    // Sinon on va tout chercher dans la table et on garde en memoire
4546
+    $demande_titre = ($info === 'titre');
4547
+    $demande_introduction = ($info === 'introduction');
4548
+
4549
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4550
+    if (
4551
+        !isset($objets[$type_objet][$id_objet])
4552
+        || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre'])
4553
+    ) {
4554
+        if (!$trouver_table) {
4555
+            $trouver_table = charger_fonction('trouver_table', 'base');
4556
+        }
4557
+        $desc = $trouver_table(table_objet_sql($type_objet));
4558
+        if (!$desc) {
4559
+            return $objets[$type_objet] = false;
4560
+        }
4561
+
4562
+        // Si on demande le titre, on le gere en interne
4563
+        $champ_titre = '';
4564
+        if ($demande_titre) {
4565
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4566
+            $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre'];
4567
+        }
4568
+        include_spip('base/abstract_sql');
4569
+        include_spip('base/connect_sql');
4570
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4571
+            '*' . $champ_titre,
4572
+            $desc['table_sql'],
4573
+            id_table_objet($type_objet) . ' = ' . (int) $id_objet
4574
+        );
4575
+
4576
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4577
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4578
+    }
4579
+
4580
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4581
+    // ajouter la longueur au début des params supplémentaires
4582
+    if ($demande_introduction) {
4583
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4584
+        array_unshift($params, $introduction_longueur);
4585
+    }
4586
+
4587
+    $row = ($objets[$type_objet][$id_objet] ?? []) ?: [];
4588
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4589
+    if ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) {
4590
+        $info_generee = $generer($id_objet, $row, ...$params);
4591
+    }
4592
+    // @deprecated 4.1 generer_TRUC_TYPE
4593
+    elseif ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) {
4594
+        trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_{$type_objet}", "generer_{$type_objet}_{$info}");
4595
+        $info_generee = $generer($id_objet, $row, ...$params);
4596
+    }
4597
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4598
+    elseif ($generer = charger_fonction("generer_objet_{$info}", '', true)) {
4599
+        $info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4600
+    }
4601
+    // @deprecated 4.1 generer_TRUC_entite
4602
+    elseif ($generer = charger_fonction("generer_{$info}_entite", '', true)) {
4603
+        trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_entite", "generer_objet_{$info}");
4604
+        $info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4605
+    }
4606
+    // Sinon on prend directement le champ SQL tel quel
4607
+    else {
4608
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4609
+    }
4610
+
4611
+    // On va ensuite appliquer les traitements automatiques si besoin
4612
+    if (!$etoile) {
4613
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4614
+        // mais ce fonctionnement est a ameliorer !
4615
+        $info_generee = appliquer_traitement_champ(
4616
+            $info_generee,
4617
+            $info,
4618
+            table_objet($type_objet),
4619
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4620
+        );
4621
+    }
4622
+
4623
+    return $info_generee;
4624 4624
 }
4625 4625
 
4626 4626
 /**
@@ -4653,34 +4653,34 @@  discard block
 block discarded – undo
4653 4653
  */
4654 4654
 function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string {
4655 4655
 
4656
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4657
-	$texte = $ligne_sql['texte'] ?? '';
4658
-	// En absence de descriptif, on se rabat sur chapo + texte
4659
-	if (isset($ligne_sql['chapo'])) {
4660
-		$chapo = $ligne_sql['chapo'];
4661
-		$texte = strlen((string) $descriptif) ?
4662
-			'' :
4663
-			"$chapo \n\n $texte";
4664
-	}
4656
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4657
+    $texte = $ligne_sql['texte'] ?? '';
4658
+    // En absence de descriptif, on se rabat sur chapo + texte
4659
+    if (isset($ligne_sql['chapo'])) {
4660
+        $chapo = $ligne_sql['chapo'];
4661
+        $texte = strlen((string) $descriptif) ?
4662
+            '' :
4663
+            "$chapo \n\n $texte";
4664
+    }
4665 4665
 
4666
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4667
-	if (!(int) $longueur_ou_suite) {
4668
-		$longueur = (int) ($introduction_longueur ?: 600);
4669
-	} else {
4670
-		$longueur = (int) $longueur_ou_suite;
4671
-	}
4666
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4667
+    if (!(int) $longueur_ou_suite) {
4668
+        $longueur = (int) ($introduction_longueur ?: 600);
4669
+    } else {
4670
+        $longueur = (int) $longueur_ou_suite;
4671
+    }
4672 4672
 
4673
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4674
-	// Ex : #INTRODUCTION{...}
4675
-	if (
4676
-		is_null($suite) && !(int) $longueur_ou_suite
4677
-	) {
4678
-		$suite = $longueur_ou_suite;
4679
-	}
4673
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4674
+    // Ex : #INTRODUCTION{...}
4675
+    if (
4676
+        is_null($suite) && !(int) $longueur_ou_suite
4677
+    ) {
4678
+        $suite = $longueur_ou_suite;
4679
+    }
4680 4680
 
4681
-	$f = chercher_filtre('introduction');
4681
+    $f = chercher_filtre('introduction');
4682 4682
 
4683
-	return $f($descriptif, $texte, $longueur, $connect, $suite);
4683
+    return $f($descriptif, $texte, $longueur, $connect, $suite);
4684 4684
 }
4685 4685
 
4686 4686
 /**
@@ -4693,49 +4693,49 @@  discard block
 block discarded – undo
4693 4693
  * @return string
4694 4694
  */
4695 4695
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4696
-	if (!$champ) {
4697
-		return $texte;
4698
-	}
4696
+    if (!$champ) {
4697
+        return $texte;
4698
+    }
4699 4699
 
4700
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4701
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4702
-	include_fichiers_fonctions();
4700
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4701
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4702
+    include_fichiers_fonctions();
4703 4703
 
4704
-	$champ = strtoupper($champ);
4705
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4706
-	if (!$traitements || !is_array($traitements)) {
4707
-		return $texte;
4708
-	}
4704
+    $champ = strtoupper($champ);
4705
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4706
+    if (!$traitements || !is_array($traitements)) {
4707
+        return $texte;
4708
+    }
4709 4709
 
4710
-	$traitement = '';
4711
-	if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) {
4712
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4713
-		$table_objet = table_objet($table_objet);
4714
-		if (isset($traitements[$table_objet])) {
4715
-			$traitement = $traitements[$table_objet];
4716
-		}
4717
-	}
4718
-	if (!$traitement && isset($traitements[0])) {
4719
-		$traitement = $traitements[0];
4720
-	}
4721
-	// (sinon prendre le premier de la liste par defaut ?)
4710
+    $traitement = '';
4711
+    if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) {
4712
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4713
+        $table_objet = table_objet($table_objet);
4714
+        if (isset($traitements[$table_objet])) {
4715
+            $traitement = $traitements[$table_objet];
4716
+        }
4717
+    }
4718
+    if (!$traitement && isset($traitements[0])) {
4719
+        $traitement = $traitements[0];
4720
+    }
4721
+    // (sinon prendre le premier de la liste par defaut ?)
4722 4722
 
4723
-	if (!$traitement) {
4724
-		return $texte;
4725
-	}
4723
+    if (!$traitement) {
4724
+        return $texte;
4725
+    }
4726 4726
 
4727
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement);
4727
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement);
4728 4728
 
4729
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4730
-	if (test_espace_prive()) {
4731
-		$env['espace_prive'] = 1;
4732
-	}
4729
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4730
+    if (test_espace_prive()) {
4731
+        $env['espace_prive'] = 1;
4732
+    }
4733 4733
 
4734
-	// Fournir $connect et $Pile[0] au traitement si besoin
4735
-	$Pile = [0 => $env];
4736
-	eval("\$texte = $traitement;");
4734
+    // Fournir $connect et $Pile[0] au traitement si besoin
4735
+    $Pile = [0 => $env];
4736
+    eval("\$texte = $traitement;");
4737 4737
 
4738
-	return $texte;
4738
+    return $texte;
4739 4739
 }
4740 4740
 
4741 4741
 
@@ -4746,21 +4746,21 @@  discard block
 block discarded – undo
4746 4746
  * @return string
4747 4747
  */
4748 4748
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4749
-	include_spip('inc/liens');
4750
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4751
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4752
-	// le raccourcis n'est plus valide
4753
-	$titre = typo($titre['titre'] ?? '');
4754
-	// on essaye avec generer_objet_info ?
4755
-	if (!strlen($titre) && !$connect) {
4756
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4757
-	}
4758
-	if (!strlen($titre)) {
4759
-		$titre = _T('info_sans_titre');
4760
-	}
4761
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4749
+    include_spip('inc/liens');
4750
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4751
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4752
+    // le raccourcis n'est plus valide
4753
+    $titre = typo($titre['titre'] ?? '');
4754
+    // on essaye avec generer_objet_info ?
4755
+    if (!strlen($titre) && !$connect) {
4756
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4757
+    }
4758
+    if (!strlen($titre)) {
4759
+        $titre = _T('info_sans_titre');
4760
+    }
4761
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4762 4762
 
4763
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4763
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4764 4764
 }
4765 4765
 
4766 4766
 /**
@@ -4776,15 +4776,15 @@  discard block
 block discarded – undo
4776 4776
  * @return string
4777 4777
  */
4778 4778
 function wrap($texte, $wrap) {
4779
-	$balises = extraire_balises($wrap);
4780
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4781
-		$texte = $wrap . $texte;
4782
-		$regs = array_reverse($regs[1]);
4783
-		$wrap = '</' . implode('></', $regs) . '>';
4784
-		$texte .= $wrap;
4785
-	}
4779
+    $balises = extraire_balises($wrap);
4780
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4781
+        $texte = $wrap . $texte;
4782
+        $regs = array_reverse($regs[1]);
4783
+        $wrap = '</' . implode('></', $regs) . '>';
4784
+        $texte .= $wrap;
4785
+    }
4786 4786
 
4787
-	return $texte;
4787
+    return $texte;
4788 4788
 }
4789 4789
 
4790 4790
 
@@ -4804,42 +4804,42 @@  discard block
 block discarded – undo
4804 4804
  * @return array|mixed|string
4805 4805
  */
4806 4806
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4807
-	if (is_string($u)) {
4808
-		return typo($u);
4809
-	}
4810
-
4811
-	// caster $u en array si besoin
4812
-	if (is_object($u)) {
4813
-		$u = (array)$u;
4814
-	}
4815
-
4816
-	if (is_array($u)) {
4817
-		$out = '';
4818
-		// toutes les cles sont numeriques ?
4819
-		// et aucun enfant n'est un tableau
4820
-		// liste simple separee par des virgules
4821
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4822
-		$array_values = array_map('is_array', $u);
4823
-		$object_values = array_map('is_object', $u);
4824
-		if (
4825
-			array_sum($numeric_keys) == count($numeric_keys)
4826
-			&& !array_sum($array_values)
4827
-			&& !array_sum($object_values)
4828
-		) {
4829
-			return implode(', ', array_map('filtre_print_dist', $u));
4830
-		}
4831
-
4832
-		// sinon on passe a la ligne et on indente
4833
-		$i_str = str_pad('', $indent, ' ');
4834
-		foreach ($u as $k => $v) {
4835
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4836
-		}
4837
-
4838
-		return $out;
4839
-	}
4840
-
4841
-	// on sait pas quoi faire...
4842
-	return $u;
4807
+    if (is_string($u)) {
4808
+        return typo($u);
4809
+    }
4810
+
4811
+    // caster $u en array si besoin
4812
+    if (is_object($u)) {
4813
+        $u = (array)$u;
4814
+    }
4815
+
4816
+    if (is_array($u)) {
4817
+        $out = '';
4818
+        // toutes les cles sont numeriques ?
4819
+        // et aucun enfant n'est un tableau
4820
+        // liste simple separee par des virgules
4821
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4822
+        $array_values = array_map('is_array', $u);
4823
+        $object_values = array_map('is_object', $u);
4824
+        if (
4825
+            array_sum($numeric_keys) == count($numeric_keys)
4826
+            && !array_sum($array_values)
4827
+            && !array_sum($object_values)
4828
+        ) {
4829
+            return implode(', ', array_map('filtre_print_dist', $u));
4830
+        }
4831
+
4832
+        // sinon on passe a la ligne et on indente
4833
+        $i_str = str_pad('', $indent, ' ');
4834
+        foreach ($u as $k => $v) {
4835
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4836
+        }
4837
+
4838
+        return $out;
4839
+    }
4840
+
4841
+    // on sait pas quoi faire...
4842
+    return $u;
4843 4843
 }
4844 4844
 
4845 4845
 
@@ -4852,10 +4852,10 @@  discard block
 block discarded – undo
4852 4852
  * @return string|array
4853 4853
  */
4854 4854
 function objet_info($objet, $info) {
4855
-	$table = table_objet_sql($objet);
4856
-	$infos = lister_tables_objets_sql($table);
4855
+    $table = table_objet_sql($objet);
4856
+    $infos = lister_tables_objets_sql($table);
4857 4857
 
4858
-	return ($infos[$info] ?? '');
4858
+    return ($infos[$info] ?? '');
4859 4859
 }
4860 4860
 
4861 4861
 /**
@@ -4870,11 +4870,11 @@  discard block
 block discarded – undo
4870 4870
  *     texte traduit du comptage, tel que '3 articles'
4871 4871
  */
4872 4872
 function objet_afficher_nb($nb, $objet) {
4873
-	if (!$nb) {
4874
-		return _T(objet_info($objet, 'info_aucun_objet'));
4875
-	} else {
4876
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4877
-	}
4873
+    if (!$nb) {
4874
+        return _T(objet_info($objet, 'info_aucun_objet'));
4875
+    } else {
4876
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4877
+    }
4878 4878
 }
4879 4879
 
4880 4880
 /**
@@ -4886,11 +4886,11 @@  discard block
 block discarded – undo
4886 4886
  * @return string
4887 4887
  */
4888 4888
 function objet_icone($objet, $taille = 24, $class = '') {
4889
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
4890
-	$icone = chemin_image($icone);
4891
-	$balise_img = charger_filtre('balise_img');
4889
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
4890
+    $icone = chemin_image($icone);
4891
+    $balise_img = charger_filtre('balise_img');
4892 4892
 
4893
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4893
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4894 4894
 }
4895 4895
 
4896 4896
 /**
@@ -4911,12 +4911,12 @@  discard block
 block discarded – undo
4911 4911
  * @return string
4912 4912
  */
4913 4913
 function objet_T($objet, $chaine, $args = [], $options = []) {
4914
-	$chaine = explode(':', $chaine);
4915
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
4916
-		return $t;
4917
-	}
4918
-	$chaine = implode(':', $chaine);
4919
-	return _T($chaine, $args, $options);
4914
+    $chaine = explode(':', $chaine);
4915
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
4916
+        return $t;
4917
+    }
4918
+    $chaine = implode(':', $chaine);
4919
+    return _T($chaine, $args, $options);
4920 4920
 }
4921 4921
 
4922 4922
 /**
@@ -4930,18 +4930,18 @@  discard block
 block discarded – undo
4930 4930
  * @return string      Code HTML
4931 4931
  */
4932 4932
 function insert_head_css_conditionnel($flux) {
4933
-	if (
4934
-		!str_contains($flux, '<!-- insert_head_css -->')
4935
-		&& ($p = strpos($flux, '<!-- insert_head -->'))
4936
-	) {
4937
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4938
-		if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) {
4939
-			$p = $p1;
4940
-		}
4941
-		$flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4942
-	}
4933
+    if (
4934
+        !str_contains($flux, '<!-- insert_head_css -->')
4935
+        && ($p = strpos($flux, '<!-- insert_head -->'))
4936
+    ) {
4937
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4938
+        if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) {
4939
+            $p = $p1;
4940
+        }
4941
+        $flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4942
+    }
4943 4943
 
4944
-	return $flux;
4944
+    return $flux;
4945 4945
 }
4946 4946
 
4947 4947
 /**
@@ -4964,75 +4964,75 @@  discard block
 block discarded – undo
4964 4964
  * @return string
4965 4965
  */
4966 4966
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
4967
-	if (isset($contexte['format'])) {
4968
-		$extension = $contexte['format'];
4969
-		unset($contexte['format']);
4970
-	} else {
4971
-		$extension = 'html';
4972
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
4973
-			$extension = $m[1];
4974
-		}
4975
-	}
4976
-	// recuperer le contenu produit par le squelette
4977
-	$options['raw'] = true;
4978
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4979
-
4980
-	// calculer le nom de la css
4981
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4982
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
4983
-	$contexte_implicite = calculer_contexte_implicite();
4984
-
4985
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4986
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4987
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4988
-	if (isset($options['hash_on_content']) && $options['hash_on_content']) {
4989
-		$hash = md5((string) ($contexte_implicite['host'] . '::' . $cache));
4990
-	}
4991
-	else {
4992
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4993
-		ksort($contexte);
4994
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
4995
-	}
4996
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4997
-
4998
-	// mettre a jour le fichier si il n'existe pas
4999
-	// ou trop ancien
5000
-	// le dernier fichier produit est toujours suffixe par .last
5001
-	// et recopie sur le fichier cible uniquement si il change
5002
-	if (
5003
-		!file_exists($filename)
5004
-		|| !file_exists($filename . '.last')
5005
-		|| isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified']
5006
-		|| defined('_VAR_MODE') && _VAR_MODE == 'recalcul'
5007
-	) {
5008
-		$contenu = $cache['texte'];
5009
-		// passer les urls en absolu si c'est une css
5010
-		if ($extension == 'css') {
5011
-			$contenu = urls_absolues_css(
5012
-				$contenu,
5013
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5014
-			);
5015
-		}
5016
-
5017
-		$comment = '';
5018
-		// ne pas insérer de commentaire sur certains formats
5019
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5020
-			$comment = "/* #PRODUIRE{fond=$fond";
5021
-			foreach ($contexte as $k => $v) {
5022
-				if (is_array($v)) {
5023
-					$v = var_export($v, true);
5024
-				}
5025
-				$comment .= ",$k=$v";
5026
-			}
5027
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5028
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5029
-			$comment .= "}\n   md5:" . md5((string) $contenu) . " */\n";
5030
-		}
5031
-		// et ecrire le fichier si il change
5032
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5033
-	}
5034
-
5035
-	return timestamp($filename);
4967
+    if (isset($contexte['format'])) {
4968
+        $extension = $contexte['format'];
4969
+        unset($contexte['format']);
4970
+    } else {
4971
+        $extension = 'html';
4972
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
4973
+            $extension = $m[1];
4974
+        }
4975
+    }
4976
+    // recuperer le contenu produit par le squelette
4977
+    $options['raw'] = true;
4978
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4979
+
4980
+    // calculer le nom de la css
4981
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4982
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
4983
+    $contexte_implicite = calculer_contexte_implicite();
4984
+
4985
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4986
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4987
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4988
+    if (isset($options['hash_on_content']) && $options['hash_on_content']) {
4989
+        $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache));
4990
+    }
4991
+    else {
4992
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4993
+        ksort($contexte);
4994
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
4995
+    }
4996
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4997
+
4998
+    // mettre a jour le fichier si il n'existe pas
4999
+    // ou trop ancien
5000
+    // le dernier fichier produit est toujours suffixe par .last
5001
+    // et recopie sur le fichier cible uniquement si il change
5002
+    if (
5003
+        !file_exists($filename)
5004
+        || !file_exists($filename . '.last')
5005
+        || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified']
5006
+        || defined('_VAR_MODE') && _VAR_MODE == 'recalcul'
5007
+    ) {
5008
+        $contenu = $cache['texte'];
5009
+        // passer les urls en absolu si c'est une css
5010
+        if ($extension == 'css') {
5011
+            $contenu = urls_absolues_css(
5012
+                $contenu,
5013
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5014
+            );
5015
+        }
5016
+
5017
+        $comment = '';
5018
+        // ne pas insérer de commentaire sur certains formats
5019
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5020
+            $comment = "/* #PRODUIRE{fond=$fond";
5021
+            foreach ($contexte as $k => $v) {
5022
+                if (is_array($v)) {
5023
+                    $v = var_export($v, true);
5024
+                }
5025
+                $comment .= ",$k=$v";
5026
+            }
5027
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5028
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5029
+            $comment .= "}\n   md5:" . md5((string) $contenu) . " */\n";
5030
+        }
5031
+        // et ecrire le fichier si il change
5032
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5033
+    }
5034
+
5035
+    return timestamp($filename);
5036 5036
 }
5037 5037
 
5038 5038
 /**
@@ -5045,11 +5045,11 @@  discard block
 block discarded – undo
5045 5045
  *    $fichier auquel on a ajouté le timestamp
5046 5046
  */
5047 5047
 function timestamp($fichier) {
5048
-	if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) {
5049
-		return $fichier;
5050
-	}
5048
+    if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) {
5049
+        return $fichier;
5050
+    }
5051 5051
 
5052
-	return "$fichier?$m";
5052
+    return "$fichier?$m";
5053 5053
 }
5054 5054
 
5055 5055
 /**
@@ -5059,11 +5059,11 @@  discard block
 block discarded – undo
5059 5059
  * @return string
5060 5060
  */
5061 5061
 function supprimer_timestamp($url) {
5062
-	if (!str_contains($url, '?')) {
5063
-		return $url;
5064
-	}
5062
+    if (!str_contains($url, '?')) {
5063
+        return $url;
5064
+    }
5065 5065
 
5066
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5066
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5067 5067
 }
5068 5068
 
5069 5069
 /**
@@ -5078,15 +5078,15 @@  discard block
 block discarded – undo
5078 5078
  * @return string
5079 5079
  */
5080 5080
 function filtre_nettoyer_titre_email_dist($titre) {
5081
-	include_spip('inc/envoyer_mail');
5081
+    include_spip('inc/envoyer_mail');
5082 5082
 
5083
-	$titre = nettoyer_titre_email($titre);
5084
-	// on est dans un squelette : securiser le retour
5085
-	if (str_contains($titre, '<')) {
5086
-		$titre = interdire_scripts($titre);
5087
-	}
5083
+    $titre = nettoyer_titre_email($titre);
5084
+    // on est dans un squelette : securiser le retour
5085
+    if (str_contains($titre, '<')) {
5086
+        $titre = interdire_scripts($titre);
5087
+    }
5088 5088
 
5089
-	return $titre;
5089
+    return $titre;
5090 5090
 }
5091 5091
 
5092 5092
 /**
@@ -5108,27 +5108,27 @@  discard block
 block discarded – undo
5108 5108
  * @return string
5109 5109
  */
5110 5110
 function filtre_chercher_rubrique_dist(
5111
-	$titre,
5112
-	$id_objet,
5113
-	$id_parent,
5114
-	$objet,
5115
-	$id_secteur,
5116
-	$restreint,
5117
-	$actionable = false,
5118
-	$retour_sans_cadre = false
5111
+    $titre,
5112
+    $id_objet,
5113
+    $id_parent,
5114
+    $objet,
5115
+    $id_secteur,
5116
+    $restreint,
5117
+    $actionable = false,
5118
+    $retour_sans_cadre = false
5119 5119
 ) {
5120
-	include_spip('inc/filtres_ecrire');
5120
+    include_spip('inc/filtres_ecrire');
5121 5121
 
5122
-	return chercher_rubrique(
5123
-		$titre,
5124
-		$id_objet,
5125
-		$id_parent,
5126
-		$objet,
5127
-		$id_secteur,
5128
-		$restreint,
5129
-		$actionable,
5130
-		$retour_sans_cadre
5131
-	);
5122
+    return chercher_rubrique(
5123
+        $titre,
5124
+        $id_objet,
5125
+        $id_parent,
5126
+        $objet,
5127
+        $id_secteur,
5128
+        $restreint,
5129
+        $actionable,
5130
+        $retour_sans_cadre
5131
+    );
5132 5132
 }
5133 5133
 
5134 5134
 /**
@@ -5157,56 +5157,56 @@  discard block
 block discarded – undo
5157 5157
  *     Chaîne vide si l'accès est autorisé
5158 5158
  */
5159 5159
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5160
-	if ($ok) {
5161
-		return '';
5162
-	}
5163
-
5164
-	// Vider tous les tampons
5165
-	$level = @ob_get_level();
5166
-	while ($level--) {
5167
-		@ob_end_clean();
5168
-	}
5169
-
5170
-	include_spip('inc/headers');
5171
-
5172
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5173
-	if ($url) {
5174
-		redirige_par_entete($url, '', $statut);
5175
-	}
5176
-
5177
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5178
-	if (!is_numeric($statut) && is_null($message)) {
5179
-		$message = $statut;
5180
-		$statut = 0;
5181
-	}
5182
-	if (!$message) {
5183
-		$message = '';
5184
-	}
5185
-	$statut = (int) $statut;
5186
-
5187
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5188
-	if (test_espace_prive()) {
5189
-		if (!$statut || !in_array($statut, [404, 403])) {
5190
-			$statut = 403;
5191
-		}
5192
-		http_response_code(403);
5193
-		$echec = charger_fonction('403', 'exec');
5194
-		$echec($message);
5195
-	} else {
5196
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5197
-		if (!$statut) {
5198
-			$statut = 404;
5199
-		}
5200
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5201
-		http_response_code($statut);
5202
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5203
-		if ($statut >= 400) {
5204
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5205
-		}
5206
-	}
5207
-
5208
-
5209
-	exit;
5160
+    if ($ok) {
5161
+        return '';
5162
+    }
5163
+
5164
+    // Vider tous les tampons
5165
+    $level = @ob_get_level();
5166
+    while ($level--) {
5167
+        @ob_end_clean();
5168
+    }
5169
+
5170
+    include_spip('inc/headers');
5171
+
5172
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5173
+    if ($url) {
5174
+        redirige_par_entete($url, '', $statut);
5175
+    }
5176
+
5177
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5178
+    if (!is_numeric($statut) && is_null($message)) {
5179
+        $message = $statut;
5180
+        $statut = 0;
5181
+    }
5182
+    if (!$message) {
5183
+        $message = '';
5184
+    }
5185
+    $statut = (int) $statut;
5186
+
5187
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5188
+    if (test_espace_prive()) {
5189
+        if (!$statut || !in_array($statut, [404, 403])) {
5190
+            $statut = 403;
5191
+        }
5192
+        http_response_code(403);
5193
+        $echec = charger_fonction('403', 'exec');
5194
+        $echec($message);
5195
+    } else {
5196
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5197
+        if (!$statut) {
5198
+            $statut = 404;
5199
+        }
5200
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5201
+        http_response_code($statut);
5202
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5203
+        if ($statut >= 400) {
5204
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5205
+        }
5206
+    }
5207
+
5208
+
5209
+    exit;
5210 5210
 }
5211 5211
 
5212 5212
 /**
@@ -5217,11 +5217,11 @@  discard block
 block discarded – undo
5217 5217
  * @return string
5218 5218
  */
5219 5219
 function filtre_compacte_dist($source, $format = null) {
5220
-	if (function_exists('minifier')) {
5221
-		return minifier($source, $format);
5222
-	}
5220
+    if (function_exists('minifier')) {
5221
+        return minifier($source, $format);
5222
+    }
5223 5223
 
5224
-	return $source;
5224
+    return $source;
5225 5225
 }
5226 5226
 
5227 5227
 
@@ -5231,32 +5231,32 @@  discard block
 block discarded – undo
5231 5231
  * @return string
5232 5232
  */
5233 5233
 function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5234
-	$passe ??= '';
5235
-	$l = strlen($passe);
5236
-
5237
-	if ($l <= 8 || !$afficher_partiellement) {
5238
-		if (!$l) {
5239
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5240
-		}
5241
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5242
-	}
5243
-
5244
-	if (is_null($portion_pourcent)) {
5245
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5246
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5247
-		}
5248
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5249
-	}
5250
-	if ($portion_pourcent >= 100) {
5251
-		return $passe;
5252
-	}
5253
-	$e = (int) ceil($l * $portion_pourcent / 100 / 2);
5254
-	$e = max($e, 0);
5255
-	$mid = str_pad('', $l - 2 * $e, '*');
5256
-	if ($e > 0 && strlen($mid) > 8) {
5257
-		$mid = '***...***';
5258
-	}
5259
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5234
+    $passe ??= '';
5235
+    $l = strlen($passe);
5236
+
5237
+    if ($l <= 8 || !$afficher_partiellement) {
5238
+        if (!$l) {
5239
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5240
+        }
5241
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5242
+    }
5243
+
5244
+    if (is_null($portion_pourcent)) {
5245
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5246
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5247
+        }
5248
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5249
+    }
5250
+    if ($portion_pourcent >= 100) {
5251
+        return $passe;
5252
+    }
5253
+    $e = (int) ceil($l * $portion_pourcent / 100 / 2);
5254
+    $e = max($e, 0);
5255
+    $mid = str_pad('', $l - 2 * $e, '*');
5256
+    if ($e > 0 && strlen($mid) > 8) {
5257
+        $mid = '***...***';
5258
+    }
5259
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5260 5260
 }
5261 5261
 
5262 5262
 
@@ -5277,64 +5277,64 @@  discard block
 block discarded – undo
5277 5277
  */
5278 5278
 function identifiant_slug($texte, $type = '', $options = []) {
5279 5279
 
5280
-	$original = $texte;
5281
-	$separateur = ($options['separateur'] ?? '_');
5282
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5283
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5280
+    $original = $texte;
5281
+    $separateur = ($options['separateur'] ?? '_');
5282
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5283
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5284 5284
 
5285
-	if (!function_exists('translitteration')) {
5286
-		include_spip('inc/charsets');
5287
-	}
5285
+    if (!function_exists('translitteration')) {
5286
+        include_spip('inc/charsets');
5287
+    }
5288 5288
 
5289
-	// pas de balise html
5290
-	if (str_contains($texte, '<')) {
5291
-		$texte = strip_tags($texte);
5292
-	}
5293
-	if (str_contains($texte, '&')) {
5294
-		$texte = unicode2charset($texte);
5295
-	}
5296
-	// On enlève les espaces indésirables
5297
-	$texte = trim($texte);
5289
+    // pas de balise html
5290
+    if (str_contains($texte, '<')) {
5291
+        $texte = strip_tags($texte);
5292
+    }
5293
+    if (str_contains($texte, '&')) {
5294
+        $texte = unicode2charset($texte);
5295
+    }
5296
+    // On enlève les espaces indésirables
5297
+    $texte = trim($texte);
5298 5298
 
5299
-	// On enlève les accents et cie
5300
-	$texte = translitteration($texte);
5299
+    // On enlève les accents et cie
5300
+    $texte = translitteration($texte);
5301 5301
 
5302
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5303
-	$texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte);
5302
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5303
+    $texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte);
5304 5304
 
5305
-	// nettoyer les doubles occurences du separateur si besoin
5306
-	while (str_contains($texte, (string) "$separateur$separateur")) {
5307
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5308
-	}
5305
+    // nettoyer les doubles occurences du separateur si besoin
5306
+    while (str_contains($texte, (string) "$separateur$separateur")) {
5307
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5308
+    }
5309 5309
 
5310
-	// pas de separateur au debut ni a la fin
5311
-	$texte = trim($texte, $separateur);
5310
+    // pas de separateur au debut ni a la fin
5311
+    $texte = trim($texte, $separateur);
5312 5312
 
5313
-	// en minuscules
5314
-	$texte = strtolower($texte);
5313
+    // en minuscules
5314
+    $texte = strtolower($texte);
5315 5315
 
5316
-	switch ($type) {
5317
-		case 'class':
5318
-		case 'id':
5319
-		case 'anchor':
5320
-			if (preg_match(',^\d,', $texte)) {
5321
-				$texte = substr($type, 0, 1) . $texte;
5322
-			}
5323
-	}
5316
+    switch ($type) {
5317
+        case 'class':
5318
+        case 'id':
5319
+        case 'anchor':
5320
+            if (preg_match(',^\d,', $texte)) {
5321
+                $texte = substr($type, 0, 1) . $texte;
5322
+            }
5323
+    }
5324 5324
 
5325
-	if (strlen($texte) > $longueur_maxi) {
5326
-		$texte = substr($texte, 0, $longueur_maxi);
5327
-	}
5325
+    if (strlen($texte) > $longueur_maxi) {
5326
+        $texte = substr($texte, 0, $longueur_maxi);
5327
+    }
5328 5328
 
5329
-	if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) {
5330
-		if (preg_match(',^\d,', $texte)) {
5331
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5332
-		}
5333
-		$texte .= $separateur . md5($original);
5334
-		$texte = substr($texte, 0, $longueur_mini);
5335
-	}
5329
+    if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) {
5330
+        if (preg_match(',^\d,', $texte)) {
5331
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5332
+        }
5333
+        $texte .= $separateur . md5($original);
5334
+        $texte = substr($texte, 0, $longueur_mini);
5335
+    }
5336 5336
 
5337
-	return $texte;
5337
+    return $texte;
5338 5338
 }
5339 5339
 
5340 5340
 
@@ -5355,11 +5355,11 @@  discard block
 block discarded – undo
5355 5355
  * @exemple `<:info_maximum|label_nettoyer:>`
5356 5356
  */
5357 5357
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5358
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5359
-	if ($ucfirst) {
5360
-		$label = spip_ucfirst($label);
5361
-	}
5362
-	return $label;
5358
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5359
+    if ($ucfirst) {
5360
+        $label = spip_ucfirst($label);
5361
+    }
5362
+    return $label;
5363 5363
 }
5364 5364
 
5365 5365
 /**
@@ -5372,8 +5372,8 @@  discard block
 block discarded – undo
5372 5372
  * @exemple `<:info_maximum|label_ponctuer:>`
5373 5373
  */
5374 5374
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5375
-	$label = label_nettoyer($text, $ucfirst);
5376
-	return _T('label_ponctuer', ['label' => $label]);
5375
+    $label = label_nettoyer($text, $ucfirst);
5376
+    return _T('label_ponctuer', ['label' => $label]);
5377 5377
 }
5378 5378
 
5379 5379
 
@@ -5386,19 +5386,19 @@  discard block
 block discarded – undo
5386 5386
  * @return array
5387 5387
  */
5388 5388
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5389
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5390
-		return [];
5391
-	}
5389
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5390
+        return [];
5391
+    }
5392 5392
 
5393
-	// compatibilite signature inversee
5394
-	if (is_numeric($objet) && !is_numeric($id_objet)) {
5395
-		[$objet, $id_objet] = [$id_objet, $objet];
5396
-	}
5393
+    // compatibilite signature inversee
5394
+    if (is_numeric($objet) && !is_numeric($id_objet)) {
5395
+        [$objet, $id_objet] = [$id_objet, $objet];
5396
+    }
5397 5397
 
5398
-	if (!function_exists($fonction)) {
5399
-		include_spip('base/objets');
5400
-	}
5401
-	return $fonction($objet, $id_objet);
5398
+    if (!function_exists($fonction)) {
5399
+        include_spip('base/objets');
5400
+    }
5401
+    return $fonction($objet, $id_objet);
5402 5402
 }
5403 5403
 
5404 5404
 
@@ -5413,7 +5413,7 @@  discard block
 block discarded – undo
5413 5413
  * @return array
5414 5414
  */
5415 5415
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5416
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5416
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5417 5417
 }
5418 5418
 
5419 5419
 /**
@@ -5427,7 +5427,7 @@  discard block
 block discarded – undo
5427 5427
  * @return array
5428 5428
  */
5429 5429
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5430
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5430
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5431 5431
 }
5432 5432
 
5433 5433
 /**
@@ -5441,7 +5441,7 @@  discard block
 block discarded – undo
5441 5441
  * @return array
5442 5442
  */
5443 5443
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5444
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5444
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5445 5445
 }
5446 5446
 
5447 5447
 /**
@@ -5455,5 +5455,5 @@  discard block
 block discarded – undo
5455 5455
  * @return array
5456 5456
  */
5457 5457
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5458
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5458
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5459 5459
 }
Please login to merge, or discard this patch.
ecrire/inc/recherche_to_array.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -10,291 +10,291 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 
17 17
 // methodes sql
18 18
 function inc_recherche_to_array_dist($recherche, $options = []) {
19 19
 
20
-	// options par defaut
21
-	$options = array_merge(
22
-		[
23
-			'score' => true,
24
-			'champs' => false,
25
-			'toutvoir' => false,
26
-			'matches' => false,
27
-			'jointures' => false
28
-		],
29
-		$options
30
-	);
20
+    // options par defaut
21
+    $options = array_merge(
22
+        [
23
+            'score' => true,
24
+            'champs' => false,
25
+            'toutvoir' => false,
26
+            'matches' => false,
27
+            'jointures' => false
28
+        ],
29
+        $options
30
+    );
31 31
 
32
-	include_spip('inc/rechercher');
33
-	include_spip('inc/autoriser');
32
+    include_spip('inc/rechercher');
33
+    include_spip('inc/autoriser');
34 34
 
35
-	$requete = [
36
-		'SELECT' => [],
37
-		'FROM' => [],
38
-		'WHERE' => [],
39
-		'GROUPBY' => [],
40
-		'ORDERBY' => [],
41
-		'LIMIT' => '',
42
-		'HAVING' => []
43
-	];
35
+    $requete = [
36
+        'SELECT' => [],
37
+        'FROM' => [],
38
+        'WHERE' => [],
39
+        'GROUPBY' => [],
40
+        'ORDERBY' => [],
41
+        'LIMIT' => '',
42
+        'HAVING' => []
43
+    ];
44 44
 
45
-	$table = sinon($options['table'], 'article');
46
-	if ($options['champs']) {
47
-		$champs = $options['champs'];
48
-	} else {
49
-		$l = liste_des_champs();
50
-		$champs = $l['article'];
51
-	}
52
-	$serveur = $options['serveur'];
45
+    $table = sinon($options['table'], 'article');
46
+    if ($options['champs']) {
47
+        $champs = $options['champs'];
48
+    } else {
49
+        $l = liste_des_champs();
50
+        $champs = $l['article'];
51
+    }
52
+    $serveur = $options['serveur'];
53 53
 
54
-	[$methode, $q, $preg] = expression_recherche($recherche, $options);
54
+    [$methode, $q, $preg] = expression_recherche($recherche, $options);
55 55
 
56
-	$jointures = $options['jointures']
57
-		? liste_des_jointures()
58
-		: [];
56
+    $jointures = $options['jointures']
57
+        ? liste_des_jointures()
58
+        : [];
59 59
 
60
-	$_id_table = id_table_objet($table);
60
+    $_id_table = id_table_objet($table);
61 61
 
62
-	// c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
63
-	// (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
64
-	if (str_contains((string) $_id_table, ',')) {
65
-		$_id_table = explode(',', (string) $_id_table);
66
-		$_id_table = reset($_id_table);
67
-	}
62
+    // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
63
+    // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
64
+    if (str_contains((string) $_id_table, ',')) {
65
+        $_id_table = explode(',', (string) $_id_table);
66
+        $_id_table = reset($_id_table);
67
+    }
68 68
 
69
-	$requete['SELECT'][] = 't.' . $_id_table;
70
-	$a = [];
71
-	// Recherche fulltext
72
-	foreach ($champs as $champ => $poids) {
73
-		if (is_array($champ)) {
74
-			spip_logger()->info('requetes imbriquees interdites');
75
-		} else {
76
-			if (!str_contains((string) $champ, '.')) {
77
-				$champ = "t.$champ";
78
-			}
79
-			$requete['SELECT'][] = $champ;
80
-			$a[] = $champ . ' ' . $methode . ' ' . $q;
81
-		}
82
-	}
83
-	if ($a) {
84
-		$requete['WHERE'][] = implode(' OR ', $a);
85
-	}
86
-	$requete['FROM'][] = table_objet_sql($table) . ' AS t';
69
+    $requete['SELECT'][] = 't.' . $_id_table;
70
+    $a = [];
71
+    // Recherche fulltext
72
+    foreach ($champs as $champ => $poids) {
73
+        if (is_array($champ)) {
74
+            spip_logger()->info('requetes imbriquees interdites');
75
+        } else {
76
+            if (!str_contains((string) $champ, '.')) {
77
+                $champ = "t.$champ";
78
+            }
79
+            $requete['SELECT'][] = $champ;
80
+            $a[] = $champ . ' ' . $methode . ' ' . $q;
81
+        }
82
+    }
83
+    if ($a) {
84
+        $requete['WHERE'][] = implode(' OR ', $a);
85
+    }
86
+    $requete['FROM'][] = table_objet_sql($table) . ' AS t';
87 87
 
88
-	$results = [];
88
+    $results = [];
89 89
 
90
-	$s = sql_select(
91
-		$requete['SELECT'],
92
-		$requete['FROM'],
93
-		$requete['WHERE'],
94
-		implode(' ', $requete['GROUPBY']),
95
-		$requete['ORDERBY'],
96
-		$requete['LIMIT'],
97
-		$requete['HAVING'],
98
-		$serveur
99
-	);
90
+    $s = sql_select(
91
+        $requete['SELECT'],
92
+        $requete['FROM'],
93
+        $requete['WHERE'],
94
+        implode(' ', $requete['GROUPBY']),
95
+        $requete['ORDERBY'],
96
+        $requete['LIMIT'],
97
+        $requete['HAVING'],
98
+        $serveur
99
+    );
100 100
 
101
-	while (
102
-		($t = sql_fetch($s, $serveur))
103
-		&& (!isset($t['score']) || $t['score'] > 0)
104
-	) {
105
-		$id = (int) $t[$_id_table];
101
+    while (
102
+        ($t = sql_fetch($s, $serveur))
103
+        && (!isset($t['score']) || $t['score'] > 0)
104
+    ) {
105
+        $id = (int) $t[$_id_table];
106 106
 
107
-		if ($options['toutvoir'] || autoriser('voir', $table, $id)) {
108
-			// indiquer les champs concernes
109
-			$champs_vus = [];
110
-			$score = 0;
111
-			$matches = [];
107
+        if ($options['toutvoir'] || autoriser('voir', $table, $id)) {
108
+            // indiquer les champs concernes
109
+            $champs_vus = [];
110
+            $score = 0;
111
+            $matches = [];
112 112
 
113
-			$vu = false;
114
-			foreach ($champs as $champ => $poids) {
115
-				$champ = explode('.', (string) $champ);
116
-				$champ = end($champ);
117
-				// translitteration_rapide uniquement si on est deja en utf-8
118
-				$value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
119
-				if (
120
-					$n =
121
-					($options['score'] || $options['matches'])
122
-						? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER)
123
-						: preg_match($preg, (string) $value)
124
-				) {
125
-					$vu = true;
113
+            $vu = false;
114
+            foreach ($champs as $champ => $poids) {
115
+                $champ = explode('.', (string) $champ);
116
+                $champ = end($champ);
117
+                // translitteration_rapide uniquement si on est deja en utf-8
118
+                $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
119
+                if (
120
+                    $n =
121
+                    ($options['score'] || $options['matches'])
122
+                        ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER)
123
+                        : preg_match($preg, (string) $value)
124
+                ) {
125
+                    $vu = true;
126 126
 
127
-					if ($options['champs']) {
128
-						$champs_vus[$champ] = $t[$champ];
129
-					}
130
-					if ($options['score']) {
131
-						// compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
132
-						$score += $poids * strlen(implode('', array_column($regs, 0)));
133
-					}
127
+                    if ($options['champs']) {
128
+                        $champs_vus[$champ] = $t[$champ];
129
+                    }
130
+                    if ($options['score']) {
131
+                        // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
132
+                        $score += $poids * strlen(implode('', array_column($regs, 0)));
133
+                    }
134 134
 
135
-					if ($options['matches']) {
136
-						$matches[$champ] = $regs;
137
-					}
135
+                    if ($options['matches']) {
136
+                        $matches[$champ] = $regs;
137
+                    }
138 138
 
139
-					if (!$options['champs'] && !$options['score'] && !$options['matches']) {
140
-						break;
141
-					}
142
-				}
143
-			}
139
+                    if (!$options['champs'] && !$options['score'] && !$options['matches']) {
140
+                        break;
141
+                    }
142
+                }
143
+            }
144 144
 
145
-			if ($vu) {
146
-				if (!isset($results)) {
147
-					$results = [];
148
-				}
149
-				$results[$id] = [];
150
-				if ($champs_vus) {
151
-					$results[$id]['champs'] = $champs_vus;
152
-				}
153
-				if ($score) {
154
-					$results[$id]['score'] = $score;
155
-				}
156
-				if ($matches) {
157
-					$results[$id]['matches'] = $matches;
158
-				}
159
-			}
160
-		}
161
-	}
145
+            if ($vu) {
146
+                if (!isset($results)) {
147
+                    $results = [];
148
+                }
149
+                $results[$id] = [];
150
+                if ($champs_vus) {
151
+                    $results[$id]['champs'] = $champs_vus;
152
+                }
153
+                if ($score) {
154
+                    $results[$id]['score'] = $score;
155
+                }
156
+                if ($matches) {
157
+                    $results[$id]['matches'] = $matches;
158
+                }
159
+            }
160
+        }
161
+    }
162 162
 
163 163
 
164
-	// Gerer les donnees associees
165
-	// ici on est un peu naze : pas capables de reconstruire une jointure complexe
166
-	// on ne sait passer que par table de laison en 1 coup
167
-	if (
168
-		isset($jointures[$table])
169
-		&& ($joints = recherche_en_base(
170
-			$recherche,
171
-			$jointures[$table],
172
-			array_merge($options, ['jointures' => false])
173
-		))
174
-	) {
175
-		include_spip('action/editer_liens');
176
-		$trouver_table = charger_fonction('trouver_table', 'base');
177
-		$cle_depart = id_table_objet($table);
178
-		$table_depart = table_objet($table, $serveur);
179
-		$desc_depart = $trouver_table($table_depart, $serveur);
180
-		$depart_associable = objet_associable($table);
181
-		foreach ($joints as $table_liee => $ids_trouves) {
182
-			// on peut definir une fonction de recherche jointe pour regler les cas particuliers
183
-			if (
184
-				!(
185
-				($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true))
186
-				|| ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true))
187
-				|| ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true))
188
-				)
189
-			) {
190
-				$cle_arrivee = id_table_objet($table_liee);
191
-				$table_arrivee = table_objet($table_liee, $serveur);
192
-				$desc_arrivee = $trouver_table($table_arrivee, $serveur);
193
-				// cas simple : $cle_depart dans la table_liee
194
-				if (isset($desc_arrivee['field'][$cle_depart])) {
195
-					$s = sql_select(
196
-						"$cle_depart, $cle_arrivee",
197
-						$desc_arrivee['table_sql'],
198
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
199
-						'',
200
-						'',
201
-						'',
202
-						'',
203
-						$serveur
204
-					);
205
-				} // cas simple : $cle_arrivee dans la table
206
-				elseif (isset($desc_depart['field'][$cle_arrivee])) {
207
-					$s = sql_select(
208
-						"$cle_depart, $cle_arrivee",
209
-						$desc_depart['table_sql'],
210
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
211
-						'',
212
-						'',
213
-						'',
214
-						'',
215
-						$serveur
216
-					);
217
-				}
218
-				// sinon cherchons une table de liaison
219
-				// cas recherche principale article, objet lie document : passer par spip_documents_liens
220
-				elseif ($l = objet_associable($table_liee)) {
221
-					[$primary, $table_liens] = $l;
222
-					$s = sql_select(
223
-						"id_objet as $cle_depart, $primary as $cle_arrivee",
224
-						$table_liens,
225
-						["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
226
-						'',
227
-						'',
228
-						'',
229
-						'',
230
-						$serveur
231
-					);
232
-				} // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
233
-				elseif ($l = $depart_associable) {
234
-					[$primary, $table_liens] = $l;
235
-					$s = sql_select(
236
-						"$primary as $cle_depart, id_objet as $cle_arrivee",
237
-						$table_liens,
238
-						["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
239
-						'',
240
-						'',
241
-						'',
242
-						'',
243
-						$serveur
244
-					);
245
-				} // cas table de liaison generique spip_xxx_yyy
246
-				elseif (
247
-					($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur))
248
-					|| ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur))
249
-				) {
250
-					$s = sql_select(
251
-						"$cle_depart,$cle_arrivee",
252
-						$t['table_sql'],
253
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
254
-						'',
255
-						'',
256
-						'',
257
-						'',
258
-						$serveur
259
-					);
260
-				}
261
-			} else {
262
-				[$cle_depart, $cle_arrivee, $s] = $rechercher_joints(
263
-					$table,
264
-					$table_liee,
265
-					array_keys($ids_trouves),
266
-					$serveur
267
-				);
268
-			}
164
+    // Gerer les donnees associees
165
+    // ici on est un peu naze : pas capables de reconstruire une jointure complexe
166
+    // on ne sait passer que par table de laison en 1 coup
167
+    if (
168
+        isset($jointures[$table])
169
+        && ($joints = recherche_en_base(
170
+            $recherche,
171
+            $jointures[$table],
172
+            array_merge($options, ['jointures' => false])
173
+        ))
174
+    ) {
175
+        include_spip('action/editer_liens');
176
+        $trouver_table = charger_fonction('trouver_table', 'base');
177
+        $cle_depart = id_table_objet($table);
178
+        $table_depart = table_objet($table, $serveur);
179
+        $desc_depart = $trouver_table($table_depart, $serveur);
180
+        $depart_associable = objet_associable($table);
181
+        foreach ($joints as $table_liee => $ids_trouves) {
182
+            // on peut definir une fonction de recherche jointe pour regler les cas particuliers
183
+            if (
184
+                !(
185
+                ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true))
186
+                || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true))
187
+                || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true))
188
+                )
189
+            ) {
190
+                $cle_arrivee = id_table_objet($table_liee);
191
+                $table_arrivee = table_objet($table_liee, $serveur);
192
+                $desc_arrivee = $trouver_table($table_arrivee, $serveur);
193
+                // cas simple : $cle_depart dans la table_liee
194
+                if (isset($desc_arrivee['field'][$cle_depart])) {
195
+                    $s = sql_select(
196
+                        "$cle_depart, $cle_arrivee",
197
+                        $desc_arrivee['table_sql'],
198
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
199
+                        '',
200
+                        '',
201
+                        '',
202
+                        '',
203
+                        $serveur
204
+                    );
205
+                } // cas simple : $cle_arrivee dans la table
206
+                elseif (isset($desc_depart['field'][$cle_arrivee])) {
207
+                    $s = sql_select(
208
+                        "$cle_depart, $cle_arrivee",
209
+                        $desc_depart['table_sql'],
210
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
211
+                        '',
212
+                        '',
213
+                        '',
214
+                        '',
215
+                        $serveur
216
+                    );
217
+                }
218
+                // sinon cherchons une table de liaison
219
+                // cas recherche principale article, objet lie document : passer par spip_documents_liens
220
+                elseif ($l = objet_associable($table_liee)) {
221
+                    [$primary, $table_liens] = $l;
222
+                    $s = sql_select(
223
+                        "id_objet as $cle_depart, $primary as $cle_arrivee",
224
+                        $table_liens,
225
+                        ["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
226
+                        '',
227
+                        '',
228
+                        '',
229
+                        '',
230
+                        $serveur
231
+                    );
232
+                } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
233
+                elseif ($l = $depart_associable) {
234
+                    [$primary, $table_liens] = $l;
235
+                    $s = sql_select(
236
+                        "$primary as $cle_depart, id_objet as $cle_arrivee",
237
+                        $table_liens,
238
+                        ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
239
+                        '',
240
+                        '',
241
+                        '',
242
+                        '',
243
+                        $serveur
244
+                    );
245
+                } // cas table de liaison generique spip_xxx_yyy
246
+                elseif (
247
+                    ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur))
248
+                    || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur))
249
+                ) {
250
+                    $s = sql_select(
251
+                        "$cle_depart,$cle_arrivee",
252
+                        $t['table_sql'],
253
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
254
+                        '',
255
+                        '',
256
+                        '',
257
+                        '',
258
+                        $serveur
259
+                    );
260
+                }
261
+            } else {
262
+                [$cle_depart, $cle_arrivee, $s] = $rechercher_joints(
263
+                    $table,
264
+                    $table_liee,
265
+                    array_keys($ids_trouves),
266
+                    $serveur
267
+                );
268
+            }
269 269
 
270
-			while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
271
-				$id = $t[$cle_depart];
272
-				$joint = $ids_trouves[$t[$cle_arrivee]];
273
-				if (!isset($results)) {
274
-					$results = [];
275
-				}
276
-				if (!isset($results[$id])) {
277
-					$results[$id] = [];
278
-				}
279
-				if (isset($joint['score']) && $joint['score']) {
280
-					if (!isset($results[$id]['score'])) {
281
-						$results[$id]['score'] = 0;
282
-					}
283
-					$results[$id]['score'] += $joint['score'];
284
-				}
285
-				if (isset($joint['champs']) && $joint['champs']) {
286
-					foreach ($joint['champs'] as $c => $val) {
287
-						$results[$id]['champs'][$table_liee . '.' . $c] = $val;
288
-					}
289
-				}
290
-				if (isset($joint['matches']) && $joint['matches']) {
291
-					foreach ($joint['matches'] as $c => $val) {
292
-						$results[$id]['matches'][$table_liee . '.' . $c] = $val;
293
-					}
294
-				}
295
-			}
296
-		}
297
-	}
270
+            while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
271
+                $id = $t[$cle_depart];
272
+                $joint = $ids_trouves[$t[$cle_arrivee]];
273
+                if (!isset($results)) {
274
+                    $results = [];
275
+                }
276
+                if (!isset($results[$id])) {
277
+                    $results[$id] = [];
278
+                }
279
+                if (isset($joint['score']) && $joint['score']) {
280
+                    if (!isset($results[$id]['score'])) {
281
+                        $results[$id]['score'] = 0;
282
+                    }
283
+                    $results[$id]['score'] += $joint['score'];
284
+                }
285
+                if (isset($joint['champs']) && $joint['champs']) {
286
+                    foreach ($joint['champs'] as $c => $val) {
287
+                        $results[$id]['champs'][$table_liee . '.' . $c] = $val;
288
+                    }
289
+                }
290
+                if (isset($joint['matches']) && $joint['matches']) {
291
+                    foreach ($joint['matches'] as $c => $val) {
292
+                        $results[$id]['matches'][$table_liee . '.' . $c] = $val;
293
+                    }
294
+                }
295
+            }
296
+        }
297
+    }
298 298
 
299
-	return $results;
299
+    return $results;
300 300
 }
Please login to merge, or discard this patch.
ecrire/inc/acces.php 2 patches
Indentation   +204 added lines, -204 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
 /**
@@ -30,41 +30,41 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
34
-
35
-	mt_srand($seed);
36
-	$s = '';
37
-	$pass = '';
38
-	for ($i = 0; $i < $longueur; $i++) {
39
-		if (!$s) {
40
-			$s = random_int(0, mt_getrandmax());
41
-			if (!$s) {
42
-				$s = random_int(0, mt_getrandmax());
43
-			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
45
-		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
47
-		$x = $r['r'] & 63;
48
-		if ($x < 10) {
49
-			$x = chr($x + 48);
50
-		} else {
51
-			if ($x < 36) {
52
-				$x = chr($x + 55);
53
-			} else {
54
-				if ($x < 62) {
55
-					$x = chr($x + 61);
56
-				} else {
57
-					$x = $x == 63 ? '/' : '.';
58
-				}
59
-			}
60
-		}
61
-		$pass .= $x;
62
-		$s = substr($s, 2);
63
-	}
64
-	$pass = preg_replace('@[./]@', 'a', $pass);
65
-	$pass = preg_replace('@[I1l]@', 'L', $pass);
66
-
67
-	return preg_replace('@[0O]@', 'o', $pass);
33
+    $seed = (int)round(((float)microtime() + 1) * time());
34
+
35
+    mt_srand($seed);
36
+    $s = '';
37
+    $pass = '';
38
+    for ($i = 0; $i < $longueur; $i++) {
39
+        if (!$s) {
40
+            $s = random_int(0, mt_getrandmax());
41
+            if (!$s) {
42
+                $s = random_int(0, mt_getrandmax());
43
+            }
44
+            $s = substr(md5(uniqid($s) . $sel), 0, 16);
45
+        }
46
+        $r = unpack('Cr', pack('H2', $s . $s));
47
+        $x = $r['r'] & 63;
48
+        if ($x < 10) {
49
+            $x = chr($x + 48);
50
+        } else {
51
+            if ($x < 36) {
52
+                $x = chr($x + 55);
53
+            } else {
54
+                if ($x < 62) {
55
+                    $x = chr($x + 61);
56
+                } else {
57
+                    $x = $x == 63 ? '/' : '.';
58
+                }
59
+            }
60
+        }
61
+        $pass .= $x;
62
+        $s = substr($s, 2);
63
+    }
64
+    $pass = preg_replace('@[./]@', 'a', $pass);
65
+    $pass = preg_replace('@[I1l]@', 'L', $pass);
66
+
67
+    return preg_replace('@[0O]@', 'o', $pass);
68 68
 }
69 69
 
70 70
 /**
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
  * @return string Identifiant
74 74
  */
75 75
 function creer_uniqid() {
76
-	static $seeded;
76
+    static $seeded;
77 77
 
78
-	if (!$seeded) {
79
-		$seed = (int)round(((float)microtime() + 1) * time());
80
-		mt_srand($seed);
81
-		$seeded = true;
82
-	}
78
+    if (!$seeded) {
79
+        $seed = (int)round(((float)microtime() + 1) * time());
80
+        mt_srand($seed);
81
+        $seeded = true;
82
+    }
83 83
 
84
-	$s = random_int(0, mt_getrandmax());
85
-	if (!$s) {
86
-		$s = random_int(0, mt_getrandmax());
87
-	}
84
+    $s = random_int(0, mt_getrandmax());
85
+    if (!$s) {
86
+        $s = random_int(0, mt_getrandmax());
87
+    }
88 88
 
89
-	return uniqid((string) $s, true);
89
+    return uniqid((string) $s, true);
90 90
 }
91 91
 
92 92
 /**
@@ -100,42 +100,42 @@  discard block
 block discarded – undo
100 100
  * @return string Retourne l'alea éphemère actuel au passage
101 101
  */
102 102
 function charger_aleas() {
103
-	if (!isset($GLOBALS['meta']['alea_ephemere'])) {
104
-		include_spip('base/abstract_sql');
105
-		$aleas = sql_allfetsel(
106
-			['nom', 'valeur'],
107
-			'spip_meta',
108
-			sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
109
-			'',
110
-			'',
111
-			'',
112
-			'',
113
-			'',
114
-			'continue'
115
-		);
116
-		if ($aleas) {
117
-			foreach ($aleas as $a) {
118
-				$GLOBALS['meta'][$a['nom']] = $a['valeur'];
119
-			}
120
-			return $GLOBALS['meta']['alea_ephemere'];
121
-		} else {
122
-			spip_logger('session')->info('aleas indisponibles');
123
-			return '';
124
-		}
125
-	}
126
-	return $GLOBALS['meta']['alea_ephemere'];
103
+    if (!isset($GLOBALS['meta']['alea_ephemere'])) {
104
+        include_spip('base/abstract_sql');
105
+        $aleas = sql_allfetsel(
106
+            ['nom', 'valeur'],
107
+            'spip_meta',
108
+            sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
109
+            '',
110
+            '',
111
+            '',
112
+            '',
113
+            '',
114
+            'continue'
115
+        );
116
+        if ($aleas) {
117
+            foreach ($aleas as $a) {
118
+                $GLOBALS['meta'][$a['nom']] = $a['valeur'];
119
+            }
120
+            return $GLOBALS['meta']['alea_ephemere'];
121
+        } else {
122
+            spip_logger('session')->info('aleas indisponibles');
123
+            return '';
124
+        }
125
+    }
126
+    return $GLOBALS['meta']['alea_ephemere'];
127 127
 }
128 128
 
129 129
 /**
130 130
  * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`)
131 131
  **/
132 132
 function renouvelle_alea() {
133
-	charger_aleas();
134
-	ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
135
-	$GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
136
-	ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
137
-	ecrire_meta('alea_ephemere_date', time(), 'non');
138
-	spip_logger()->info("renouvellement de l'alea_ephemere");
133
+    charger_aleas();
134
+    ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
135
+    $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
136
+    ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
137
+    ecrire_meta('alea_ephemere_date', time(), 'non');
138
+    spip_logger()->info("renouvellement de l'alea_ephemere");
139 139
 }
140 140
 
141 141
 
@@ -155,21 +155,21 @@  discard block
 block discarded – undo
155 155
  *     Clé de sécurité.
156 156
  **/
157 157
 function low_sec($id_auteur) {
158
-	// Pas d'id_auteur : low_sec
159
-	if (!$id_auteur = (int) $id_auteur) {
160
-		include_spip('inc/config');
161
-		if (!$low_sec = lire_config('low_sec')) {
162
-			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163
-		}
164
-	} else {
165
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
166
-		if (!$low_sec) {
167
-			$low_sec = creer_pass_aleatoire();
168
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
169
-		}
170
-	}
171
-
172
-	return $low_sec;
158
+    // Pas d'id_auteur : low_sec
159
+    if (!$id_auteur = (int) $id_auteur) {
160
+        include_spip('inc/config');
161
+        if (!$low_sec = lire_config('low_sec')) {
162
+            ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163
+        }
164
+    } else {
165
+        $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
166
+        if (!$low_sec) {
167
+            $low_sec = creer_pass_aleatoire();
168
+            sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
169
+        }
170
+    }
171
+
172
+    return $low_sec;
173 173
 }
174 174
 
175 175
 
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
  * @filtre
203 203
  */
204 204
 function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') {
205
-	if ($op) {
206
-		$dir .= " $op $args";
207
-	}
205
+    if ($op) {
206
+        $dir .= " $op $args";
207
+    }
208 208
 
209
-	return verifier_low_sec($id_auteur, $cle, $dir);
209
+    return verifier_low_sec($id_auteur, $cle, $dir);
210 210
 }
211 211
 
212 212
 /**
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
  * @return string
215 215
  */
216 216
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
217
-	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218
-	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
217
+    $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218
+    $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
+    $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
220 220
 
221
-	return generer_url_api($script, $path, $args, $no_entities, $public);
221
+    return generer_url_api($script, $path, $args, $no_entities, $public);
222 222
 }
223 223
 
224 224
 /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
  *     Clé
235 235
  **/
236 236
 function afficher_low_sec($id_auteur, $action = '') {
237
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
237
+    return substr(md5($action . low_sec($id_auteur)), 0, 8);
238 238
 }
239 239
 
240 240
 /**
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
  *     true si les clés corresponde, false sinon
253 253
  **/
254 254
 function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') {
255
-	return ($cle == afficher_low_sec($id_auteur, $action));
255
+    return ($cle == afficher_low_sec($id_auteur, $action));
256 256
 }
257 257
 
258 258
 /**
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
  *     Identifiant de l'auteur
263 263
  **/
264 264
 function effacer_low_sec($id_auteur) {
265
-	if (!$id_auteur = (int) $id_auteur) {
266
-		return;
267
-	} // jamais trop prudent ;)
268
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
265
+    if (!$id_auteur = (int) $id_auteur) {
266
+        return;
267
+    } // jamais trop prudent ;)
268
+    sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
269 269
 }
270 270
 
271 271
 
@@ -283,29 +283,29 @@  discard block
 block discarded – undo
283 283
  *     - void sinon.
284 284
  **/
285 285
 function ecrire_acces() {
286
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
287
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
288
-
289
-	// Cette variable de configuration peut etre posee par un plugin
290
-	// par exemple acces_restreint ;
291
-	// si .htaccess existe, outrepasser spip_meta
292
-	if (
293
-		(!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
294
-	) {
295
-		spip_unlink($htpasswd);
296
-		spip_unlink($htpasswd . '-admin');
297
-		return;
298
-	}
299
-
300
-	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
301
-	# de devenir redacteur le cas echeant (auth http)... a nettoyer
302
-	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
303
-	// TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
304
-	if (include_spip('auth/ldap') && auth_ldap_connect()) {
305
-		return;
306
-	}
307
-
308
-	generer_htpasswd_files($htpasswd, "$htpasswd-admin");
286
+    $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
287
+    $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
288
+
289
+    // Cette variable de configuration peut etre posee par un plugin
290
+    // par exemple acces_restreint ;
291
+    // si .htaccess existe, outrepasser spip_meta
292
+    if (
293
+        (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
294
+    ) {
295
+        spip_unlink($htpasswd);
296
+        spip_unlink($htpasswd . '-admin');
297
+        return;
298
+    }
299
+
300
+    # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
301
+    # de devenir redacteur le cas echeant (auth http)... a nettoyer
302
+    // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
303
+    // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
304
+    if (include_spip('auth/ldap') && auth_ldap_connect()) {
305
+        return;
306
+    }
307
+
308
+    generer_htpasswd_files($htpasswd, "$htpasswd-admin");
309 309
 }
310 310
 
311 311
 /**
@@ -314,29 +314,29 @@  discard block
 block discarded – undo
314 314
  * @param string $htpasswd_admin
315 315
  */
316 316
 function generer_htpasswd_files($htpasswd, $htpasswd_admin) {
317
-	if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
318
-		$generer_htpasswd($htpasswd, $htpasswd_admin);
319
-	}
320
-
321
-	$pwd_all = ''; // login:htpass pour tous
322
-	$pwd_admin = ''; // login:htpass pour les admins
323
-
324
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
325
-	while ($row = sql_fetch($res)) {
326
-		if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
327
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
328
-			$pwd_all .= $ligne;
329
-			if ($row['statut'] == '0minirezo') {
330
-				$pwd_admin .= $ligne;
331
-			}
332
-		}
333
-	}
334
-
335
-	if ($pwd_all) {
336
-		ecrire_fichier($htpasswd, $pwd_all);
337
-		ecrire_fichier($htpasswd_admin, $pwd_admin);
338
-		spip_logger('htpass')->info("Ecriture de $htpasswd et $htpasswd_admin");
339
-	}
317
+    if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
318
+        $generer_htpasswd($htpasswd, $htpasswd_admin);
319
+    }
320
+
321
+    $pwd_all = ''; // login:htpass pour tous
322
+    $pwd_admin = ''; // login:htpass pour les admins
323
+
324
+    $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
325
+    while ($row = sql_fetch($res)) {
326
+        if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
327
+            $ligne = $row['login'] . ':' . $row['htpass'] . "\n";
328
+            $pwd_all .= $ligne;
329
+            if ($row['statut'] == '0minirezo') {
330
+                $pwd_admin .= $ligne;
331
+            }
332
+        }
333
+    }
334
+
335
+    if ($pwd_all) {
336
+        ecrire_fichier($htpasswd, $pwd_all);
337
+        ecrire_fichier($htpasswd_admin, $pwd_admin);
338
+        spip_logger('htpass')->info("Ecriture de $htpasswd et $htpasswd_admin");
339
+    }
340 340
 }
341 341
 
342 342
 /**
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
  *  La chaîne hachée si fonction crypt présente, rien sinon.
351 351
  */
352 352
 function generer_htpass(#[\SensitiveParameter] $pass) {
353
-	if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
354
-		return $generer_htpass($pass);
355
-	}
353
+    if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
354
+        return $generer_htpass($pass);
355
+    }
356 356
 
357
-	return '';
357
+    return '';
358 358
 }
359 359
 
360 360
 /**
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
  * @return boolean
368 368
  */
369 369
 function verifier_htaccess($rep, $force = false) {
370
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
371
-	if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
372
-		return true;
373
-	}
374
-
375
-	// directive deny compatible Apache 2.0+
376
-	$deny =
377
-		'# Deny all requests from Apache 2.4+.
370
+    $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
371
+    if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
372
+        return true;
373
+    }
374
+
375
+    // directive deny compatible Apache 2.0+
376
+    $deny =
377
+        '# Deny all requests from Apache 2.4+.
378 378
 <IfModule mod_authz_core.c>
379 379
   Require all denied
380 380
 </IfModule>
@@ -383,30 +383,30 @@  discard block
 block discarded – undo
383 383
   Deny from all
384 384
 </IfModule>
385 385
 ';
386
-	// support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
387
-	if (
388
-		function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.')
389
-	) {
390
-		$deny = "deny from all\n";
391
-	}
392
-
393
-	if ($ht = @fopen($htaccess, 'w')) {
394
-		fwrite($ht, $deny);
395
-		fclose($ht);
396
-		@chmod($htaccess, _SPIP_CHMOD & 0666);
397
-		$t = rtrim($rep, '/') . '/.ok';
398
-		if ($ht = @fopen($t, 'w')) {
399
-			@fclose($ht);
400
-			include_spip('inc/distant');
401
-			$t = substr($t, strlen(_DIR_RACINE));
402
-			$t = url_de_base() . $t;
403
-			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
404
-			$ht = ($ht['status'] ?? null) === 403;
405
-		}
406
-	}
407
-	spip_logger()->info("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
408
-
409
-	return $ht;
386
+    // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
387
+    if (
388
+        function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.')
389
+    ) {
390
+        $deny = "deny from all\n";
391
+    }
392
+
393
+    if ($ht = @fopen($htaccess, 'w')) {
394
+        fwrite($ht, $deny);
395
+        fclose($ht);
396
+        @chmod($htaccess, _SPIP_CHMOD & 0666);
397
+        $t = rtrim($rep, '/') . '/.ok';
398
+        if ($ht = @fopen($t, 'w')) {
399
+            @fclose($ht);
400
+            include_spip('inc/distant');
401
+            $t = substr($t, strlen(_DIR_RACINE));
402
+            $t = url_de_base() . $t;
403
+            $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
404
+            $ht = ($ht['status'] ?? null) === 403;
405
+        }
406
+    }
407
+    spip_logger()->info("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
408
+
409
+    return $ht;
410 410
 }
411 411
 
412 412
 /**
@@ -424,20 +424,20 @@  discard block
 block discarded – undo
424 424
  *         Valeur de la configuration `creer_htaccess`
425 425
  */
426 426
 function gerer_htaccess() {
427
-	// Cette variable de configuration peut etre posee par un plugin
428
-	// par exemple acces_restreint
429
-	$f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui');
430
-	$dirs = sql_allfetsel('extension', 'spip_types_documents');
431
-	$dirs[] = ['extension' => 'distant'];
432
-	foreach ($dirs as $e) {
433
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
434
-			if ($f) {
435
-				verifier_htaccess($dir);
436
-			} else {
437
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
438
-			}
439
-		}
440
-	}
441
-
442
-	return $GLOBALS['meta']['creer_htaccess'] ?? '';
427
+    // Cette variable de configuration peut etre posee par un plugin
428
+    // par exemple acces_restreint
429
+    $f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui');
430
+    $dirs = sql_allfetsel('extension', 'spip_types_documents');
431
+    $dirs[] = ['extension' => 'distant'];
432
+    foreach ($dirs as $e) {
433
+        if (is_dir($dir = _DIR_IMG . $e['extension'])) {
434
+            if ($f) {
435
+                verifier_htaccess($dir);
436
+            } else {
437
+                spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
438
+            }
439
+        }
440
+    }
441
+
442
+    return $GLOBALS['meta']['creer_htaccess'] ?? '';
443 443
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
33
+	$seed = (int) round(((float) microtime() + 1) * time());
34 34
 
35 35
 	mt_srand($seed);
36 36
 	$s = '';
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 			if (!$s) {
42 42
 				$s = random_int(0, mt_getrandmax());
43 43
 			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
44
+			$s = substr(md5(uniqid($s).$sel), 0, 16);
45 45
 		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
46
+		$r = unpack('Cr', pack('H2', $s.$s));
47 47
 		$x = $r['r'] & 63;
48 48
 		if ($x < 10) {
49 49
 			$x = chr($x + 48);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	static $seeded;
77 77
 
78 78
 	if (!$seeded) {
79
-		$seed = (int)round(((float)microtime() + 1) * time());
79
+		$seed = (int) round(((float) microtime() + 1) * time());
80 80
 		mt_srand($seed);
81 81
 		$seeded = true;
82 82
 	}
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163 163
 		}
164 164
 	} else {
165
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
165
+		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.(int) $id_auteur);
166 166
 		if (!$low_sec) {
167 167
 			$low_sec = creer_pass_aleatoire();
168
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
168
+			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.(int) $id_auteur);
169 169
 		}
170 170
 	}
171 171
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
217 217
 	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218 218
 	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
219
+	$path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : '');
220 220
 
221 221
 	return generer_url_api($script, $path, $args, $no_entities, $public);
222 222
 }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
  *     Clé
235 235
  **/
236 236
 function afficher_low_sec($id_auteur, $action = '') {
237
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
237
+	return substr(md5($action.low_sec($id_auteur)), 0, 8);
238 238
 }
239 239
 
240 240
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	if (!$id_auteur = (int) $id_auteur) {
266 266
 		return;
267 267
 	} // jamais trop prudent ;)
268
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
268
+	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.(int) $id_auteur);
269 269
 }
270 270
 
271 271
 
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
  *     - void sinon.
284 284
  **/
285 285
 function ecrire_acces() {
286
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
287
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
286
+	$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
287
+	$htpasswd = _DIR_TMP._AUTH_USER_FILE;
288 288
 
289 289
 	// Cette variable de configuration peut etre posee par un plugin
290 290
 	// par exemple acces_restreint ;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		(!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
294 294
 	) {
295 295
 		spip_unlink($htpasswd);
296
-		spip_unlink($htpasswd . '-admin');
296
+		spip_unlink($htpasswd.'-admin');
297 297
 		return;
298 298
 	}
299 299
 
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
 	$pwd_all = ''; // login:htpass pour tous
322 322
 	$pwd_admin = ''; // login:htpass pour les admins
323 323
 
324
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
324
+	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
325 325
 	while ($row = sql_fetch($res)) {
326 326
 		if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
327
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
327
+			$ligne = $row['login'].':'.$row['htpass']."\n";
328 328
 			$pwd_all .= $ligne;
329 329
 			if ($row['statut'] == '0minirezo') {
330 330
 				$pwd_admin .= $ligne;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
  * @return boolean
368 368
  */
369 369
 function verifier_htaccess($rep, $force = false) {
370
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
370
+	$htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME;
371 371
 	if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
372 372
 		return true;
373 373
 	}
@@ -394,17 +394,17 @@  discard block
 block discarded – undo
394 394
 		fwrite($ht, $deny);
395 395
 		fclose($ht);
396 396
 		@chmod($htaccess, _SPIP_CHMOD & 0666);
397
-		$t = rtrim($rep, '/') . '/.ok';
397
+		$t = rtrim($rep, '/').'/.ok';
398 398
 		if ($ht = @fopen($t, 'w')) {
399 399
 			@fclose($ht);
400 400
 			include_spip('inc/distant');
401 401
 			$t = substr($t, strlen(_DIR_RACINE));
402
-			$t = url_de_base() . $t;
402
+			$t = url_de_base().$t;
403 403
 			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
404 404
 			$ht = ($ht['status'] ?? null) === 403;
405 405
 		}
406 406
 	}
407
-	spip_logger()->info("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
407
+	spip_logger()->info("Creation de $htaccess ".($ht ? ' reussie' : ' manquee'));
408 408
 
409 409
 	return $ht;
410 410
 }
@@ -430,11 +430,11 @@  discard block
 block discarded – undo
430 430
 	$dirs = sql_allfetsel('extension', 'spip_types_documents');
431 431
 	$dirs[] = ['extension' => 'distant'];
432 432
 	foreach ($dirs as $e) {
433
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
433
+		if (is_dir($dir = _DIR_IMG.$e['extension'])) {
434 434
 			if ($f) {
435 435
 				verifier_htaccess($dir);
436 436
 			} else {
437
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
437
+				spip_unlink($dir.'/'._ACCESS_FILE_NAME);
438 438
 			}
439 439
 		}
440 440
 	}
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 2 patches
Indentation   +307 added lines, -307 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
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -34,195 +34,195 @@  discard block
 block discarded – undo
34 34
  * @return array Couples (type d'objet => Couples (champ => score))
35 35
  */
36 36
 function liste_des_champs() {
37
-	static $liste = null;
38
-	if (is_null($liste)) {
39
-		$liste = [];
40
-		// recuperer les tables_objets_sql declarees
41
-		include_spip('base/objets');
42
-		$tables_objets = lister_tables_objets_sql();
43
-		foreach ($tables_objets as $t => $infos) {
44
-			if ($infos['rechercher_champs']) {
45
-				$liste[$infos['type']] = $infos['rechercher_champs'];
46
-			}
47
-		}
48
-		// puis passer dans le pipeline
49
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
50
-	}
51
-
52
-	return $liste;
37
+    static $liste = null;
38
+    if (is_null($liste)) {
39
+        $liste = [];
40
+        // recuperer les tables_objets_sql declarees
41
+        include_spip('base/objets');
42
+        $tables_objets = lister_tables_objets_sql();
43
+        foreach ($tables_objets as $t => $infos) {
44
+            if ($infos['rechercher_champs']) {
45
+                $liste[$infos['type']] = $infos['rechercher_champs'];
46
+            }
47
+        }
48
+        // puis passer dans le pipeline
49
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
50
+    }
51
+
52
+    return $liste;
53 53
 }
54 54
 
55 55
 
56 56
 // Recherche des auteurs et mots-cles associes
57 57
 // en ne regardant que le titre ou le nom
58 58
 function liste_des_jointures() {
59
-	static $liste = null;
60
-	if (is_null($liste)) {
61
-		$liste = [];
62
-		// recuperer les tables_objets_sql declarees
63
-		include_spip('base/objets');
64
-		$tables_objets = lister_tables_objets_sql();
65
-		foreach ($tables_objets as $t => $infos) {
66
-			if ($infos['rechercher_jointures']) {
67
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
68
-			}
69
-		}
70
-		// puis passer dans le pipeline
71
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
72
-	}
73
-
74
-	return $liste;
59
+    static $liste = null;
60
+    if (is_null($liste)) {
61
+        $liste = [];
62
+        // recuperer les tables_objets_sql declarees
63
+        include_spip('base/objets');
64
+        $tables_objets = lister_tables_objets_sql();
65
+        foreach ($tables_objets as $t => $infos) {
66
+            if ($infos['rechercher_jointures']) {
67
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
68
+            }
69
+        }
70
+        // puis passer dans le pipeline
71
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
72
+    }
73
+
74
+    return $liste;
75 75
 }
76 76
 
77 77
 function expression_recherche($recherche, $options) {
78
-	// ne calculer qu'une seule fois l'expression par hit
79
-	// (meme si utilisee dans plusieurs boucles)
80
-	static $expression = [];
81
-	$key = serialize([$recherche, $options['preg_flags']]);
82
-	if (isset($expression[$key])) {
83
-		return $expression[$key];
84
-	}
85
-
86
-	$u = $GLOBALS['meta']['pcre_u'];
87
-	if ($u && !str_contains((string) $options['preg_flags'], (string) $u)) {
88
-		$options['preg_flags'] .= $u;
89
-	}
90
-	include_spip('inc/charsets');
91
-	$recherche = trim((string) $recherche);
92
-
93
-	// retirer les + de +truc et les * de truc*
94
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
95
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
96
-
97
-	$is_preg = false;
98
-	if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99
-		// c'est une preg
100
-		$recherche_trans = translitteration($recherche);
101
-		$preg = $recherche_trans . $options['preg_flags'];
102
-		$is_preg = true;
103
-	} else {
104
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
105
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
106
-		// 'une', 'des' ...)
107
-
108
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
109
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
110
-
111
-		// les expressions entre " " sont un mot a chercher tel quel
112
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
113
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
114
-			foreach ($matches as $match) {
115
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
116
-				$word = trim($word, '"');
117
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
118
-			}
119
-		}
120
-
121
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
122
-			$is_preg = true;
123
-
124
-			$recherche_inter = '|';
125
-			$recherche_mots = explode(' ', $recherche_mod);
126
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
127
-			$petits_mots = true;
128
-			foreach ($recherche_mots as $mot) {
129
-				if (strlen($mot) >= $min_long) {
130
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
-					$recherche_inter .= preg_quote($mot) . ' ';
132
-					$petits_mots = false;
133
-				}
134
-			}
135
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
136
-
137
-			// mais on cherche quand même l'expression complète, même si elle
138
-			// comporte des mots de moins de quatre lettres
139
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
140
-			if (!$recherche || $petits_mots) {
141
-				$recherche = preg_quote($recherche_org);
142
-			}
143
-			$recherche_trans = translitteration($recherche);
144
-		}
145
-
146
-		$preg = '/' . str_replace('/', '\\/', (string) $recherche_trans) . '/' . $options['preg_flags'];
147
-	}
148
-
149
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
150
-	// ou si l'expression reguliere est invalide
151
-	if (!$is_preg || @preg_match($preg, '') === false) {
152
-		$methode = 'LIKE';
153
-		$u = $GLOBALS['meta']['pcre_u'];
154
-
155
-		// echapper les % et _
156
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
157
-
158
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
159
-		$recherche = preg_quote($recherche, '/');
160
-		$recherche_trans = translitteration($recherche);
161
-		$recherche_mod = $recherche_trans;
162
-
163
-		// les expressions entre " " sont un mot a chercher tel quel
164
-		// -> on remplace les espaces par un _ et on enleve les guillemets
165
-		// corriger le like dans le $q
166
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
167
-			foreach ($matches as $match) {
168
-				$word = preg_replace(',\s+,Uims', '_', $match);
169
-				$word = trim($word, '"');
170
-				$q = str_replace($match, $word, $q);
171
-			}
172
-		}
173
-		// corriger la regexp
174
-		if (preg_match(',["][^"]+["],Uims', (string) $recherche_mod, $matches)) {
175
-			foreach ($matches as $match) {
176
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
177
-				$word = trim($word, '"');
178
-				$recherche_mod = str_replace($match, $word, (string) $recherche_mod);
179
-			}
180
-		}
181
-		$q = sql_quote(
182
-			'%'
183
-			. preg_replace(',\s+,' . $u, '%', $q)
184
-			. '%'
185
-		);
186
-
187
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim((string) $recherche_mod)) . '/' . $options['preg_flags'];
188
-	} else {
189
-		$methode = 'REGEXP';
190
-		$q = sql_quote(trim($recherche, '/'));
191
-	}
192
-
193
-	// tous les caracteres transliterables de $q sont remplaces par un joker
194
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
195
-	$q_t = $q;
196
-	for ($i = 0; $i < spip_strlen($q); $i++) {
197
-		$char = spip_substr($q, $i, 1);
198
-		if (
199
-			!is_ascii($char)
200
-			&& ($char_t = translitteration($char))
201
-			&& $char_t !== $char
202
-		) {
203
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
204
-			// mais c'est un pis aller cf #4354
205
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', (string) $q_t);
206
-		}
207
-	}
208
-
209
-	$q = $q_t;
210
-
211
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
212
-	// les plus frequents qui peuvent etre accentues
213
-	// (oui c'est tres dicustable...)
214
-	if (
215
-		isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
216
-		&& str_starts_with((string) $GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite')
217
-	) {
218
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
219
-		// si il reste au moins un char significatif...
220
-		if (preg_match(",[^'%_.],", $q_t)) {
221
-			$q = $q_t;
222
-		}
223
-	}
224
-
225
-	return $expression[$key] = [$methode, $q, $preg];
78
+    // ne calculer qu'une seule fois l'expression par hit
79
+    // (meme si utilisee dans plusieurs boucles)
80
+    static $expression = [];
81
+    $key = serialize([$recherche, $options['preg_flags']]);
82
+    if (isset($expression[$key])) {
83
+        return $expression[$key];
84
+    }
85
+
86
+    $u = $GLOBALS['meta']['pcre_u'];
87
+    if ($u && !str_contains((string) $options['preg_flags'], (string) $u)) {
88
+        $options['preg_flags'] .= $u;
89
+    }
90
+    include_spip('inc/charsets');
91
+    $recherche = trim((string) $recherche);
92
+
93
+    // retirer les + de +truc et les * de truc*
94
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
95
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
96
+
97
+    $is_preg = false;
98
+    if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99
+        // c'est une preg
100
+        $recherche_trans = translitteration($recherche);
101
+        $preg = $recherche_trans . $options['preg_flags'];
102
+        $is_preg = true;
103
+    } else {
104
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
105
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
106
+        // 'une', 'des' ...)
107
+
108
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
109
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
110
+
111
+        // les expressions entre " " sont un mot a chercher tel quel
112
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
113
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
114
+            foreach ($matches as $match) {
115
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
116
+                $word = trim($word, '"');
117
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
118
+            }
119
+        }
120
+
121
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
122
+            $is_preg = true;
123
+
124
+            $recherche_inter = '|';
125
+            $recherche_mots = explode(' ', $recherche_mod);
126
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
127
+            $petits_mots = true;
128
+            foreach ($recherche_mots as $mot) {
129
+                if (strlen($mot) >= $min_long) {
130
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
+                    $recherche_inter .= preg_quote($mot) . ' ';
132
+                    $petits_mots = false;
133
+                }
134
+            }
135
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
136
+
137
+            // mais on cherche quand même l'expression complète, même si elle
138
+            // comporte des mots de moins de quatre lettres
139
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
140
+            if (!$recherche || $petits_mots) {
141
+                $recherche = preg_quote($recherche_org);
142
+            }
143
+            $recherche_trans = translitteration($recherche);
144
+        }
145
+
146
+        $preg = '/' . str_replace('/', '\\/', (string) $recherche_trans) . '/' . $options['preg_flags'];
147
+    }
148
+
149
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
150
+    // ou si l'expression reguliere est invalide
151
+    if (!$is_preg || @preg_match($preg, '') === false) {
152
+        $methode = 'LIKE';
153
+        $u = $GLOBALS['meta']['pcre_u'];
154
+
155
+        // echapper les % et _
156
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
157
+
158
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
159
+        $recherche = preg_quote($recherche, '/');
160
+        $recherche_trans = translitteration($recherche);
161
+        $recherche_mod = $recherche_trans;
162
+
163
+        // les expressions entre " " sont un mot a chercher tel quel
164
+        // -> on remplace les espaces par un _ et on enleve les guillemets
165
+        // corriger le like dans le $q
166
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
167
+            foreach ($matches as $match) {
168
+                $word = preg_replace(',\s+,Uims', '_', $match);
169
+                $word = trim($word, '"');
170
+                $q = str_replace($match, $word, $q);
171
+            }
172
+        }
173
+        // corriger la regexp
174
+        if (preg_match(',["][^"]+["],Uims', (string) $recherche_mod, $matches)) {
175
+            foreach ($matches as $match) {
176
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
177
+                $word = trim($word, '"');
178
+                $recherche_mod = str_replace($match, $word, (string) $recherche_mod);
179
+            }
180
+        }
181
+        $q = sql_quote(
182
+            '%'
183
+            . preg_replace(',\s+,' . $u, '%', $q)
184
+            . '%'
185
+        );
186
+
187
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim((string) $recherche_mod)) . '/' . $options['preg_flags'];
188
+    } else {
189
+        $methode = 'REGEXP';
190
+        $q = sql_quote(trim($recherche, '/'));
191
+    }
192
+
193
+    // tous les caracteres transliterables de $q sont remplaces par un joker
194
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
195
+    $q_t = $q;
196
+    for ($i = 0; $i < spip_strlen($q); $i++) {
197
+        $char = spip_substr($q, $i, 1);
198
+        if (
199
+            !is_ascii($char)
200
+            && ($char_t = translitteration($char))
201
+            && $char_t !== $char
202
+        ) {
203
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
204
+            // mais c'est un pis aller cf #4354
205
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', (string) $q_t);
206
+        }
207
+    }
208
+
209
+    $q = $q_t;
210
+
211
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
212
+    // les plus frequents qui peuvent etre accentues
213
+    // (oui c'est tres dicustable...)
214
+    if (
215
+        isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
216
+        && str_starts_with((string) $GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite')
217
+    ) {
218
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
219
+        // si il reste au moins un char significatif...
220
+        if (preg_match(",[^'%_.],", $q_t)) {
221
+            $q = $q_t;
222
+        }
223
+    }
224
+
225
+    return $expression[$key] = [$methode, $q, $preg];
226 226
 }
227 227
 
228 228
 
@@ -249,135 +249,135 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
252
-	include_spip('base/abstract_sql');
253
-
254
-	if (!is_array($tables)) {
255
-		$liste = liste_des_champs();
256
-
257
-		if (is_string($tables) && $tables != '') {
258
-			$toutes = [];
259
-			foreach (explode(',', $tables) as $t) {
260
-				$t = trim($t);
261
-				if (isset($liste[$t])) {
262
-					$toutes[$t] = $liste[$t];
263
-				}
264
-			}
265
-			$tables = $toutes;
266
-			unset($toutes);
267
-		} else {
268
-			$tables = $liste;
269
-		}
270
-	}
271
-
272
-	if (!strlen($recherche) || $tables === []) {
273
-		return [];
274
-	}
275
-
276
-	include_spip('inc/autoriser');
277
-
278
-	// options par defaut
279
-	$options = array_merge(
280
-		[
281
-		'preg_flags' => 'UimsS',
282
-		'toutvoir' => false,
283
-		'champs' => false,
284
-		'score' => false,
285
-		'matches' => false,
286
-		'jointures' => false,
287
-		'serveur' => $serveur
288
-		],
289
-		$options
290
-	);
291
-
292
-	$results = [];
293
-
294
-	// Utiliser l'iterateur (DATA:recherche)
295
-	// pour recuperer les couples (id_objet, score)
296
-	// Le resultat est au format {
297
-	//      id1 = { 'score' => x, attrs => { } },
298
-	//      id2 = { 'score' => x, attrs => { } },
299
-	// }
300
-
301
-	include_spip('inc/recherche_to_array');
302
-
303
-	foreach ($tables as $table => $champs) {
304
-		# lock via memoization, si dispo
305
-		if (function_exists('cache_lock')) {
306
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
307
-		}
308
-
309
-		spip_timer('rech');
310
-
311
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
312
-		$to_array = charger_fonction('recherche_to_array', 'inc');
313
-		$results[$table] = $to_array(
314
-			$recherche,
315
-			array_merge($options, ['table' => $table, 'champs' => $champs])
316
-		);
317
-		##var_dump($results[$table]);
318
-
319
-
320
-		spip_logger('recherche')->info(
321
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
322
-		);
323
-
324
-		if (isset($lock)) {
325
-			cache_unlock($lock);
326
-		}
327
-	}
328
-
329
-	return $results;
252
+    include_spip('base/abstract_sql');
253
+
254
+    if (!is_array($tables)) {
255
+        $liste = liste_des_champs();
256
+
257
+        if (is_string($tables) && $tables != '') {
258
+            $toutes = [];
259
+            foreach (explode(',', $tables) as $t) {
260
+                $t = trim($t);
261
+                if (isset($liste[$t])) {
262
+                    $toutes[$t] = $liste[$t];
263
+                }
264
+            }
265
+            $tables = $toutes;
266
+            unset($toutes);
267
+        } else {
268
+            $tables = $liste;
269
+        }
270
+    }
271
+
272
+    if (!strlen($recherche) || $tables === []) {
273
+        return [];
274
+    }
275
+
276
+    include_spip('inc/autoriser');
277
+
278
+    // options par defaut
279
+    $options = array_merge(
280
+        [
281
+        'preg_flags' => 'UimsS',
282
+        'toutvoir' => false,
283
+        'champs' => false,
284
+        'score' => false,
285
+        'matches' => false,
286
+        'jointures' => false,
287
+        'serveur' => $serveur
288
+        ],
289
+        $options
290
+    );
291
+
292
+    $results = [];
293
+
294
+    // Utiliser l'iterateur (DATA:recherche)
295
+    // pour recuperer les couples (id_objet, score)
296
+    // Le resultat est au format {
297
+    //      id1 = { 'score' => x, attrs => { } },
298
+    //      id2 = { 'score' => x, attrs => { } },
299
+    // }
300
+
301
+    include_spip('inc/recherche_to_array');
302
+
303
+    foreach ($tables as $table => $champs) {
304
+        # lock via memoization, si dispo
305
+        if (function_exists('cache_lock')) {
306
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
307
+        }
308
+
309
+        spip_timer('rech');
310
+
311
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
312
+        $to_array = charger_fonction('recherche_to_array', 'inc');
313
+        $results[$table] = $to_array(
314
+            $recherche,
315
+            array_merge($options, ['table' => $table, 'champs' => $champs])
316
+        );
317
+        ##var_dump($results[$table]);
318
+
319
+
320
+        spip_logger('recherche')->info(
321
+            "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
322
+        );
323
+
324
+        if (isset($lock)) {
325
+            cache_unlock($lock);
326
+        }
327
+    }
328
+
329
+    return $results;
330 330
 }
331 331
 
332 332
 
333 333
 // Effectue une recherche sur toutes les tables de la base de donnees
334 334
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
335
-	include_spip('inc/modifier');
336
-
337
-	// options par defaut
338
-	$options = array_merge(
339
-		[
340
-		'preg_flags' => 'UimsS',
341
-		'toutmodifier' => false
342
-		],
343
-		$options
344
-	);
345
-	$options['champs'] = true;
346
-
347
-
348
-	if (!is_array($tables)) {
349
-		$tables = liste_des_champs();
350
-	}
351
-
352
-	$results = recherche_en_base($recherche, $tables, $options);
353
-
354
-	$preg = '/' . str_replace('/', '\\/', (string) $recherche) . '/' . $options['preg_flags'];
355
-
356
-	foreach ($results as $table => $r) {
357
-		$_id_table = id_table_objet($table);
358
-		foreach ($r as $id => $x) {
359
-			if ($options['toutmodifier'] || autoriser('modifier', $table, $id)) {
360
-				$modifs = [];
361
-				foreach ($x['champs'] as $key => $val) {
362
-					if ($key == $_id_table) {
363
-						continue;
364
-					}
365
-					$repl = preg_replace($preg, (string) $remplace, (string) $val);
366
-					if ($repl != $val) {
367
-						$modifs[$key] = $repl;
368
-					}
369
-				}
370
-				if ($modifs) {
371
-					objet_modifier_champs(
372
-						$table,
373
-						$id,
374
-						[
375
-							'champs' => array_keys($modifs),
376
-						],
377
-						$modifs
378
-					);
379
-				}
380
-			}
381
-		}
382
-	}
335
+    include_spip('inc/modifier');
336
+
337
+    // options par defaut
338
+    $options = array_merge(
339
+        [
340
+        'preg_flags' => 'UimsS',
341
+        'toutmodifier' => false
342
+        ],
343
+        $options
344
+    );
345
+    $options['champs'] = true;
346
+
347
+
348
+    if (!is_array($tables)) {
349
+        $tables = liste_des_champs();
350
+    }
351
+
352
+    $results = recherche_en_base($recherche, $tables, $options);
353
+
354
+    $preg = '/' . str_replace('/', '\\/', (string) $recherche) . '/' . $options['preg_flags'];
355
+
356
+    foreach ($results as $table => $r) {
357
+        $_id_table = id_table_objet($table);
358
+        foreach ($r as $id => $x) {
359
+            if ($options['toutmodifier'] || autoriser('modifier', $table, $id)) {
360
+                $modifs = [];
361
+                foreach ($x['champs'] as $key => $val) {
362
+                    if ($key == $_id_table) {
363
+                        continue;
364
+                    }
365
+                    $repl = preg_replace($preg, (string) $remplace, (string) $val);
366
+                    if ($repl != $val) {
367
+                        $modifs[$key] = $repl;
368
+                    }
369
+                }
370
+                if ($modifs) {
371
+                    objet_modifier_champs(
372
+                        $table,
373
+                        $id,
374
+                        [
375
+                            'champs' => array_keys($modifs),
376
+                        ],
377
+                        $modifs
378
+                    );
379
+                }
380
+            }
381
+        }
382
+    }
383 383
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99 99
 		// c'est une preg
100 100
 		$recherche_trans = translitteration($recherche);
101
-		$preg = $recherche_trans . $options['preg_flags'];
101
+		$preg = $recherche_trans.$options['preg_flags'];
102 102
 		$is_preg = true;
103 103
 	} else {
104 104
 		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 			}
119 119
 		}
120 120
 
121
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
121
+		if (preg_match(',\s+,'.$u, $recherche_mod)) {
122 122
 			$is_preg = true;
123 123
 
124 124
 			$recherche_inter = '|';
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			foreach ($recherche_mots as $mot) {
129 129
 				if (strlen($mot) >= $min_long) {
130 130
 					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
-					$recherche_inter .= preg_quote($mot) . ' ';
131
+					$recherche_inter .= preg_quote($mot).' ';
132 132
 					$petits_mots = false;
133 133
 				}
134 134
 			}
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 
137 137
 			// mais on cherche quand même l'expression complète, même si elle
138 138
 			// comporte des mots de moins de quatre lettres
139
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
139
+			$recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|');
140 140
 			if (!$recherche || $petits_mots) {
141 141
 				$recherche = preg_quote($recherche_org);
142 142
 			}
143 143
 			$recherche_trans = translitteration($recherche);
144 144
 		}
145 145
 
146
-		$preg = '/' . str_replace('/', '\\/', (string) $recherche_trans) . '/' . $options['preg_flags'];
146
+		$preg = '/'.str_replace('/', '\\/', (string) $recherche_trans).'/'.$options['preg_flags'];
147 147
 	}
148 148
 
149 149
 	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 		}
181 181
 		$q = sql_quote(
182 182
 			'%'
183
-			. preg_replace(',\s+,' . $u, '%', $q)
183
+			. preg_replace(',\s+,'.$u, '%', $q)
184 184
 			. '%'
185 185
 		);
186 186
 
187
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim((string) $recherche_mod)) . '/' . $options['preg_flags'];
187
+		$preg = '/'.preg_replace(',\s+,'.$u, '.+', trim((string) $recherche_mod)).'/'.$options['preg_flags'];
188 188
 	} else {
189 189
 		$methode = 'REGEXP';
190 190
 		$q = sql_quote(trim($recherche, '/'));
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	foreach ($tables as $table => $champs) {
304 304
 		# lock via memoization, si dispo
305 305
 		if (function_exists('cache_lock')) {
306
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
306
+			cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche);
307 307
 		}
308 308
 
309 309
 		spip_timer('rech');
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 
319 319
 
320 320
 		spip_logger('recherche')->info(
321
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
321
+			"recherche $table ($recherche) : ".(is_countable($results[$table]) ? count($results[$table]) : 0).' resultats '.spip_timer('rech'),
322 322
 		);
323 323
 
324 324
 		if (isset($lock)) {
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 
352 352
 	$results = recherche_en_base($recherche, $tables, $options);
353 353
 
354
-	$preg = '/' . str_replace('/', '\\/', (string) $recherche) . '/' . $options['preg_flags'];
354
+	$preg = '/'.str_replace('/', '\\/', (string) $recherche).'/'.$options['preg_flags'];
355 355
 
356 356
 	foreach ($results as $table => $r) {
357 357
 		$_id_table = id_table_objet($table);
Please login to merge, or discard this patch.
ecrire/inc/auth.php 2 patches
Indentation   +448 added lines, -448 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
 include_spip('base/abstract_sql');
@@ -34,33 +34,33 @@  discard block
 block discarded – undo
34 34
  *  - une chaîne vide si autorisation à pénétrer dans l'espace privé.
35 35
  */
36 36
 function inc_auth_dist() {
37
-	$row = auth_mode();
37
+    $row = auth_mode();
38 38
 
39
-	if ($row) {
40
-		return auth_init_droits($row);
41
-	}
39
+    if ($row) {
40
+        return auth_init_droits($row);
41
+    }
42 42
 
43
-	if (!$GLOBALS['connect_login']) {
44
-		return auth_a_loger();
45
-	}
43
+    if (!$GLOBALS['connect_login']) {
44
+        return auth_a_loger();
45
+    }
46 46
 
47
-	// Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui
48
-	// C'est soit parce que la base est inutilisable,
49
-	// soit parce que la table des auteurs a changee (restauration etc)
50
-	// Pas la peine d'insister.
51
-	// Renvoyer le nom fautif et une URL de remise a zero
47
+    // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui
48
+    // C'est soit parce que la base est inutilisable,
49
+    // soit parce que la table des auteurs a changee (restauration etc)
50
+    // Pas la peine d'insister.
51
+    // Renvoyer le nom fautif et une URL de remise a zero
52 52
 
53
-	if (spip_connect()) {
54
-		return [
55
-			'login' => $GLOBALS['connect_login'],
56
-			'site' => generer_url_public('', 'action=logout&amp;logout=prive')
57
-		];
58
-	}
53
+    if (spip_connect()) {
54
+        return [
55
+            'login' => $GLOBALS['connect_login'],
56
+            'site' => generer_url_public('', 'action=logout&amp;logout=prive')
57
+        ];
58
+    }
59 59
 
60
-	$n = (int) sql_errno();
61
-	spip_logger()->info("Erreur base de donnees $n " . sql_error());
60
+    $n = (int) sql_errno();
61
+    spip_logger()->info("Erreur base de donnees $n " . sql_error());
62 62
 
63
-	return $n ?: 1;
63
+    return $n ?: 1;
64 64
 }
65 65
 
66 66
 /**
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
  */
70 70
 function auth_controler_password_auteur_connecte(#[\SensitiveParameter] string $password): bool {
71 71
 
72
-	if (
73
-		empty($GLOBALS['visiteur_session']['id_auteur'])
74
-		|| empty($GLOBALS['visiteur_session']['login'])
75
-	) {
76
-		return false;
77
-	}
72
+    if (
73
+        empty($GLOBALS['visiteur_session']['id_auteur'])
74
+        || empty($GLOBALS['visiteur_session']['login'])
75
+    ) {
76
+        return false;
77
+    }
78 78
 
79
-	$auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true);
80
-	return is_array($auth) && $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur'];
79
+    $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true);
80
+    return is_array($auth) && $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur'];
81 81
 }
82 82
 
83 83
 /**
@@ -89,47 +89,47 @@  discard block
 block discarded – undo
89 89
  * @return array|string
90 90
  */
91 91
 function auth_echec($raison) {
92
-	include_spip('inc/minipres');
93
-	include_spip('inc/headers');
94
-	// pas authentifie. Pourquoi ?
95
-	if (is_string($raison)) {
96
-		// redirection vers une page d'authentification
97
-		// on ne revient pas de cette fonction
98
-		// sauf si pb de header
99
-		$raison = redirige_formulaire($raison);
100
-	} elseif (is_int($raison)) {
101
-		// erreur SQL a afficher
102
-		$raison = minipres(
103
-			_T('info_travaux_titre'),
104
-			_T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
105
-		);
106
-	} elseif (@$raison['statut']) {
107
-		// un simple visiteur n'a pas acces a l'espace prive
108
-		spip_logger()->info('connexion refusee a ' . @$raison['id_auteur']);
109
-		$est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT
110
-		$raison = minipres(
111
-			_T('avis_erreur_connexion'),
112
-			_T('avis_erreur_visiteur')
113
-				// Lien vers le site public
114
-				. '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>'
115
-				// Si la personne est connectée, lien de déconnexion ramenant vers la page de login
116
-				. ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&amp;logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '')
117
-		);
118
-	} else {
119
-		// auteur en fin de droits ...
120
-		$h = $raison['site'];
121
-		$raison = minipres(
122
-			_T('avis_erreur_connexion'),
123
-			'<br /><br /><p>'
124
-			. _T('texte_inc_auth_1', ['auth_login' => $raison['login']])
125
-			. " <a href='$h'>"
126
-			. _T('texte_inc_auth_2')
127
-			. '</a>'
128
-			. _T('texte_inc_auth_3')
129
-		);
130
-	}
131
-
132
-	return $raison;
92
+    include_spip('inc/minipres');
93
+    include_spip('inc/headers');
94
+    // pas authentifie. Pourquoi ?
95
+    if (is_string($raison)) {
96
+        // redirection vers une page d'authentification
97
+        // on ne revient pas de cette fonction
98
+        // sauf si pb de header
99
+        $raison = redirige_formulaire($raison);
100
+    } elseif (is_int($raison)) {
101
+        // erreur SQL a afficher
102
+        $raison = minipres(
103
+            _T('info_travaux_titre'),
104
+            _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
105
+        );
106
+    } elseif (@$raison['statut']) {
107
+        // un simple visiteur n'a pas acces a l'espace prive
108
+        spip_logger()->info('connexion refusee a ' . @$raison['id_auteur']);
109
+        $est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT
110
+        $raison = minipres(
111
+            _T('avis_erreur_connexion'),
112
+            _T('avis_erreur_visiteur')
113
+                // Lien vers le site public
114
+                . '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>'
115
+                // Si la personne est connectée, lien de déconnexion ramenant vers la page de login
116
+                . ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&amp;logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '')
117
+        );
118
+    } else {
119
+        // auteur en fin de droits ...
120
+        $h = $raison['site'];
121
+        $raison = minipres(
122
+            _T('avis_erreur_connexion'),
123
+            '<br /><br /><p>'
124
+            . _T('texte_inc_auth_1', ['auth_login' => $raison['login']])
125
+            . " <a href='$h'>"
126
+            . _T('texte_inc_auth_2')
127
+            . '</a>'
128
+            . _T('texte_inc_auth_3')
129
+        );
130
+    }
131
+
132
+    return $raison;
133 133
 }
134 134
 
135 135
 /**
@@ -139,79 +139,79 @@  discard block
 block discarded – undo
139 139
  * @return array|bool|string
140 140
  */
141 141
 function auth_mode() {
142
-	//
143
-	// Initialiser variables (eviter hacks par URL)
144
-	//
145
-	$GLOBALS['connect_login'] = '';
146
-	$id_auteur = null;
147
-	$GLOBALS['auth_can_disconnect'] = false;
148
-
149
-	//
150
-	// Recuperer les donnees d'identification
151
-	//
152
-	include_spip('inc/session');
153
-	// Session valide en cours ?
154
-	if ($cookie = lire_cookie_session()) {
155
-		$session = charger_fonction('session', 'inc');
156
-		if (
157
-			($id_auteur = $session()) || $id_auteur === 0 // reprise sur restauration
158
-		) {
159
-			$GLOBALS['auth_can_disconnect'] = true;
160
-			$GLOBALS['connect_login'] = session_get('login');
161
-		} else {
162
-			unset($_COOKIE['spip_session']);
163
-		}
164
-	}
165
-
166
-	// Essayer auth http si significatif
167
-	// (ignorer les login d'intranet independants de spip)
168
-	if (!$GLOBALS['ignore_auth_http']) {
169
-		if (
170
-			isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])
171
-				&& ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
172
-			// Si auth http differtente de basic, PHP_AUTH_PW
173
-			// est indisponible mais tentons quand meme pour
174
-			// autocreation via LDAP
175
-			|| isset($_SERVER['REMOTE_USER'])
176
-				&& ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], ''))
177
-		) {
178
-			if (!$id_auteur) {
179
-				$_SERVER['PHP_AUTH_PW'] = '';
180
-				$GLOBALS['auth_can_disconnect'] = true;
181
-				$GLOBALS['visiteur_session'] = $r;
182
-				$GLOBALS['connect_login'] = session_get('login');
183
-				$id_auteur = $r['id_auteur'];
184
-			} else {
185
-				// cas de la session en plus de PHP_AUTH
186
-				/*				  if ($id_auteur != $r['id_auteur']){
142
+    //
143
+    // Initialiser variables (eviter hacks par URL)
144
+    //
145
+    $GLOBALS['connect_login'] = '';
146
+    $id_auteur = null;
147
+    $GLOBALS['auth_can_disconnect'] = false;
148
+
149
+    //
150
+    // Recuperer les donnees d'identification
151
+    //
152
+    include_spip('inc/session');
153
+    // Session valide en cours ?
154
+    if ($cookie = lire_cookie_session()) {
155
+        $session = charger_fonction('session', 'inc');
156
+        if (
157
+            ($id_auteur = $session()) || $id_auteur === 0 // reprise sur restauration
158
+        ) {
159
+            $GLOBALS['auth_can_disconnect'] = true;
160
+            $GLOBALS['connect_login'] = session_get('login');
161
+        } else {
162
+            unset($_COOKIE['spip_session']);
163
+        }
164
+    }
165
+
166
+    // Essayer auth http si significatif
167
+    // (ignorer les login d'intranet independants de spip)
168
+    if (!$GLOBALS['ignore_auth_http']) {
169
+        if (
170
+            isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])
171
+                && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
172
+            // Si auth http differtente de basic, PHP_AUTH_PW
173
+            // est indisponible mais tentons quand meme pour
174
+            // autocreation via LDAP
175
+            || isset($_SERVER['REMOTE_USER'])
176
+                && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], ''))
177
+        ) {
178
+            if (!$id_auteur) {
179
+                $_SERVER['PHP_AUTH_PW'] = '';
180
+                $GLOBALS['auth_can_disconnect'] = true;
181
+                $GLOBALS['visiteur_session'] = $r;
182
+                $GLOBALS['connect_login'] = session_get('login');
183
+                $id_auteur = $r['id_auteur'];
184
+            } else {
185
+                // cas de la session en plus de PHP_AUTH
186
+                /*				  if ($id_auteur != $r['id_auteur']){
187 187
 					spip_logger()->info("vol de session $id_auteur" . join(', ', $r));
188 188
 				unset($_COOKIE['spip_session']);
189 189
 				$id_auteur = '';
190 190
 				} */
191
-			}
192
-		} else {
193
-			// Authentification .htaccess old style, car .htaccess semble
194
-			// souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW
195
-			if (isset($_SERVER['REMOTE_USER'])) {
196
-				$GLOBALS['connect_login'] = $_SERVER['REMOTE_USER'];
197
-			}
198
-		}
199
-	}
200
-
201
-	$where = (is_numeric($id_auteur)
202
-		/*AND $id_auteur>0*/ // reprise lors des restaurations
203
-	) ?
204
-		"id_auteur=$id_auteur" :
205
-		(strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : '');
206
-
207
-	if (!$where) {
208
-		return '';
209
-	}
210
-
211
-	// Trouver les autres infos dans la table auteurs.
212
-	// le champ 'quand' est utilise par l'agenda
213
-
214
-	return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'");
191
+            }
192
+        } else {
193
+            // Authentification .htaccess old style, car .htaccess semble
194
+            // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW
195
+            if (isset($_SERVER['REMOTE_USER'])) {
196
+                $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER'];
197
+            }
198
+        }
199
+    }
200
+
201
+    $where = (is_numeric($id_auteur)
202
+        /*AND $id_auteur>0*/ // reprise lors des restaurations
203
+    ) ?
204
+        "id_auteur=$id_auteur" :
205
+        (strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : '');
206
+
207
+    if (!$where) {
208
+        return '';
209
+    }
210
+
211
+    // Trouver les autres infos dans la table auteurs.
212
+    // le champ 'quand' est utilise par l'agenda
213
+
214
+    return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'");
215 215
 }
216 216
 
217 217
 /**
@@ -229,96 +229,96 @@  discard block
 block discarded – undo
229 229
  */
230 230
 function auth_init_droits($row) {
231 231
 
232
-	include_spip('inc/autoriser');
233
-	if (!autoriser('loger', '', 0, $row)) {
234
-		return false;
235
-	}
236
-
237
-
238
-	if ($row['statut'] == 'nouveau') {
239
-		include_spip('action/inscrire_auteur');
240
-		$row = confirmer_statut_inscription($row);
241
-	}
242
-
243
-	$GLOBALS['connect_id_auteur'] = $row['id_auteur'];
244
-	$GLOBALS['connect_login'] = $row['login'];
245
-	$GLOBALS['connect_statut'] = $row['statut'];
246
-
247
-	$GLOBALS['visiteur_session'] = array_merge((array) $GLOBALS['visiteur_session'], $row);
248
-
249
-	// au cas ou : ne pas memoriser les champs sensibles
250
-	$GLOBALS['visiteur_session'] = auth_desensibiliser_session($GLOBALS['visiteur_session']);
251
-
252
-	// creer la session au besoin
253
-	include_spip('inc/session');
254
-	if (!lire_cookie_session()) {
255
-		$session = charger_fonction('session', 'inc');
256
-		$spip_session = $session($row);
257
-	}
258
-
259
-	// reinjecter les preferences_auteur apres le reset de spip_session
260
-	// car utilisees au retour par auth_loger()
261
-	$r = @unserialize($row['prefs']);
262
-	$GLOBALS['visiteur_session']['prefs'] = ($r ?: []);
263
-	// si prefs pas definies, les definir par defaut
264
-	if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) {
265
-		$GLOBALS['visiteur_session']['prefs']['couleur'] = 2;
266
-		$GLOBALS['visiteur_session']['prefs']['display'] = 2;
267
-		$GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones';
268
-	}
269
-
270
-	$GLOBALS['visiteur_session'] = pipeline(
271
-		'preparer_visiteur_session',
272
-		['args' => ['row' => $row],
273
-		'data' => $GLOBALS['visiteur_session']]
274
-	);
275
-
276
-	// Etablir les droits selon le codage attendu
277
-	// dans ecrire/index.php ecrire/prive.php
278
-
279
-	// Pas autorise a acceder a ecrire ? renvoyer le tableau
280
-	// A noter : le premier appel a autoriser() a le bon gout
281
-	// d'initialiser $GLOBALS['visiteur_session']['restreint'],
282
-	// qui ne figure pas dans le fichier de session
283
-
284
-	if (!autoriser('ecrire')) {
285
-		return $row;
286
-	}
287
-
288
-	// autoriser('ecrire') ne laisse passer que les Admin et les Redac
289
-
290
-	auth_trace($row);
291
-
292
-	// Administrateurs
293
-	if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) {
294
-		if (
295
-			isset($GLOBALS['visiteur_session']['restreint'])
296
-			&& is_array($GLOBALS['visiteur_session']['restreint'])
297
-		) {
298
-			$GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint'];
299
-		}
300
-		if ($GLOBALS['connect_statut'] == '0minirezo') {
301
-			$GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique'];
302
-		}
303
-	}
304
-
305
-	// Pour les redacteurs, inc_version a fait l'initialisation minimale
306
-
307
-	return ''; // i.e. pas de pb.
232
+    include_spip('inc/autoriser');
233
+    if (!autoriser('loger', '', 0, $row)) {
234
+        return false;
235
+    }
236
+
237
+
238
+    if ($row['statut'] == 'nouveau') {
239
+        include_spip('action/inscrire_auteur');
240
+        $row = confirmer_statut_inscription($row);
241
+    }
242
+
243
+    $GLOBALS['connect_id_auteur'] = $row['id_auteur'];
244
+    $GLOBALS['connect_login'] = $row['login'];
245
+    $GLOBALS['connect_statut'] = $row['statut'];
246
+
247
+    $GLOBALS['visiteur_session'] = array_merge((array) $GLOBALS['visiteur_session'], $row);
248
+
249
+    // au cas ou : ne pas memoriser les champs sensibles
250
+    $GLOBALS['visiteur_session'] = auth_desensibiliser_session($GLOBALS['visiteur_session']);
251
+
252
+    // creer la session au besoin
253
+    include_spip('inc/session');
254
+    if (!lire_cookie_session()) {
255
+        $session = charger_fonction('session', 'inc');
256
+        $spip_session = $session($row);
257
+    }
258
+
259
+    // reinjecter les preferences_auteur apres le reset de spip_session
260
+    // car utilisees au retour par auth_loger()
261
+    $r = @unserialize($row['prefs']);
262
+    $GLOBALS['visiteur_session']['prefs'] = ($r ?: []);
263
+    // si prefs pas definies, les definir par defaut
264
+    if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) {
265
+        $GLOBALS['visiteur_session']['prefs']['couleur'] = 2;
266
+        $GLOBALS['visiteur_session']['prefs']['display'] = 2;
267
+        $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones';
268
+    }
269
+
270
+    $GLOBALS['visiteur_session'] = pipeline(
271
+        'preparer_visiteur_session',
272
+        ['args' => ['row' => $row],
273
+        'data' => $GLOBALS['visiteur_session']]
274
+    );
275
+
276
+    // Etablir les droits selon le codage attendu
277
+    // dans ecrire/index.php ecrire/prive.php
278
+
279
+    // Pas autorise a acceder a ecrire ? renvoyer le tableau
280
+    // A noter : le premier appel a autoriser() a le bon gout
281
+    // d'initialiser $GLOBALS['visiteur_session']['restreint'],
282
+    // qui ne figure pas dans le fichier de session
283
+
284
+    if (!autoriser('ecrire')) {
285
+        return $row;
286
+    }
287
+
288
+    // autoriser('ecrire') ne laisse passer que les Admin et les Redac
289
+
290
+    auth_trace($row);
291
+
292
+    // Administrateurs
293
+    if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) {
294
+        if (
295
+            isset($GLOBALS['visiteur_session']['restreint'])
296
+            && is_array($GLOBALS['visiteur_session']['restreint'])
297
+        ) {
298
+            $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint'];
299
+        }
300
+        if ($GLOBALS['connect_statut'] == '0minirezo') {
301
+            $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique'];
302
+        }
303
+    }
304
+
305
+    // Pour les redacteurs, inc_version a fait l'initialisation minimale
306
+
307
+    return ''; // i.e. pas de pb.
308 308
 }
309 309
 
310 310
 /**
311 311
  * Enlever les clés sensibles d'une ligne auteur
312 312
  */
313 313
 function auth_desensibiliser_session(array $auteur): array {
314
-	$cles_sensibles = ['pass', 'htpass', 'low_sec', 'alea_actuel', 'alea_futur', 'ldap_password', 'backup_cles'];
315
-	foreach ($cles_sensibles as $cle) {
316
-		if (array_key_exists($cle, $auteur)) {
317
-			unset($auteur[$cle]);
318
-		}
319
-	}
320
-
321
-	return $auteur;
314
+    $cles_sensibles = ['pass', 'htpass', 'low_sec', 'alea_actuel', 'alea_futur', 'ldap_password', 'backup_cles'];
315
+    foreach ($cles_sensibles as $cle) {
316
+        if (array_key_exists($cle, $auteur)) {
317
+            unset($auteur[$cle]);
318
+        }
319
+    }
320
+
321
+    return $auteur;
322 322
 }
323 323
 
324 324
 /**
@@ -327,23 +327,23 @@  discard block
 block discarded – undo
327 327
  * @return string
328 328
  */
329 329
 function auth_a_loger() {
330
-	$redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true);
331
-
332
-	// un echec au "bonjour" (login initial) quand le statut est
333
-	// inconnu signale sans doute un probleme de cookies
334
-	if (isset($_GET['bonjour'])) {
335
-		$redirect = parametre_url(
336
-			$redirect,
337
-			'var_erreur',
338
-			(isset($GLOBALS['visiteur_session']['statut'])
339
-				? 'statut'
340
-				: 'cookie'
341
-			),
342
-			'&'
343
-		);
344
-	}
345
-
346
-	return $redirect;
330
+    $redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true);
331
+
332
+    // un echec au "bonjour" (login initial) quand le statut est
333
+    // inconnu signale sans doute un probleme de cookies
334
+    if (isset($_GET['bonjour'])) {
335
+        $redirect = parametre_url(
336
+            $redirect,
337
+            'var_erreur',
338
+            (isset($GLOBALS['visiteur_session']['statut'])
339
+                ? 'statut'
340
+                : 'cookie'
341
+            ),
342
+            '&'
343
+        );
344
+    }
345
+
346
+    return $redirect;
347 347
 }
348 348
 
349 349
 /**
@@ -355,19 +355,19 @@  discard block
 block discarded – undo
355 355
  * @param null|string $date
356 356
  */
357 357
 function auth_trace($row, $date = null) {
358
-	// Indiquer la connexion. A la minute pres ca suffit.
359
-	if (!is_numeric($connect_quand = $row['quand'] ?? '')) {
360
-		$connect_quand = strtotime((string) $connect_quand);
361
-	}
358
+    // Indiquer la connexion. A la minute pres ca suffit.
359
+    if (!is_numeric($connect_quand = $row['quand'] ?? '')) {
360
+        $connect_quand = strtotime((string) $connect_quand);
361
+    }
362 362
 
363
-	$date ??= date('Y-m-d H:i:s');
363
+    $date ??= date('Y-m-d H:i:s');
364 364
 
365
-	if (abs(strtotime($date) - $connect_quand) >= 60) {
366
-		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']);
367
-		$row['en_ligne'] = $date;
368
-	}
365
+    if (abs(strtotime($date) - $connect_quand) >= 60) {
366
+        sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']);
367
+        $row['en_ligne'] = $date;
368
+    }
369 369
 
370
-	pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]);
370
+    pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]);
371 371
 }
372 372
 
373 373
 
@@ -393,27 +393,27 @@  discard block
 block discarded – undo
393 393
  * @return mixed
394 394
  */
395 395
 function auth_administrer($fonction, $args, mixed $defaut = false) {
396
-	$auth_methode = array_shift($args);
397
-	$auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou
398
-	if (
399
-		($auth = charger_fonction($auth_methode, 'auth', true))
400
-		&& function_exists($f = "auth_{$auth_methode}_$fonction")
401
-	) {
402
-		$res = $f(...$args);
403
-	} else {
404
-		$res = $defaut;
405
-	}
406
-	return pipeline(
407
-		'auth_administrer',
408
-		[
409
-			'args' => [
410
-				'fonction' => $fonction,
411
-				'methode' => $auth_methode,
412
-				'args' => $args
413
-			],
414
-			'data' => $res
415
-		]
416
-	);
396
+    $auth_methode = array_shift($args);
397
+    $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou
398
+    if (
399
+        ($auth = charger_fonction($auth_methode, 'auth', true))
400
+        && function_exists($f = "auth_{$auth_methode}_$fonction")
401
+    ) {
402
+        $res = $f(...$args);
403
+    } else {
404
+        $res = $defaut;
405
+    }
406
+    return pipeline(
407
+        'auth_administrer',
408
+        [
409
+            'args' => [
410
+                'fonction' => $fonction,
411
+                'methode' => $auth_methode,
412
+                'args' => $args
413
+            ],
414
+            'data' => $res
415
+        ]
416
+    );
417 417
 }
418 418
 
419 419
 /**
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
  * @return array
424 424
  */
425 425
 function auth_formulaire_login($flux) {
426
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
427
-		$flux = auth_administrer('formulaire_login', [$methode, $flux], $flux);
428
-	}
426
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
427
+        $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux);
428
+    }
429 429
 
430
-	return $flux;
430
+    return $flux;
431 431
 }
432 432
 
433 433
 
@@ -441,19 +441,19 @@  discard block
 block discarded – undo
441 441
  * @return string/bool
442 442
  */
443 443
 function auth_retrouver_login($login, $serveur = '') {
444
-	if (!spip_connect($serveur)) {
445
-		include_spip('inc/minipres');
446
-		echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
447
-		exit;
448
-	}
449
-
450
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
451
-		if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) {
452
-			return $auteur;
453
-		}
454
-	}
455
-
456
-	return false;
444
+    if (!spip_connect($serveur)) {
445
+        include_spip('inc/minipres');
446
+        echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
447
+        exit;
448
+    }
449
+
450
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
451
+        if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) {
452
+            return $auteur;
453
+        }
454
+    }
455
+
456
+    return false;
457 457
 }
458 458
 
459 459
 /**
@@ -468,35 +468,35 @@  discard block
 block discarded – undo
468 468
  * @return array
469 469
  */
470 470
 function auth_informer_login($login, $serveur = '') {
471
-	if (
472
-		!$login
473
-		|| !($login_base = auth_retrouver_login($login, $serveur))
474
-		|| !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
475
-	) {
476
-		// generer de fausses infos, mais credibles, pour eviter une attaque
477
-		// https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
478
-
479
-		$row = [
480
-			'login' => $login,
481
-			'cnx' => '0',
482
-			'logo' => '',
483
-		];
484
-
485
-		return $row;
486
-	}
487
-
488
-	$prefs = @unserialize($row['prefs']);
489
-	$row = auth_desensibiliser_session($row);
490
-	$infos = [
491
-		'id_auteur' => $row['id_auteur'],
492
-		'login' => $row['login'],
493
-		'cnx' => (isset($prefs['cnx']) && $prefs['cnx'] === 'perma') ? '1' : '0',
494
-		'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row),
495
-	];
496
-
497
-	verifier_visiteur();
498
-
499
-	return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos);
471
+    if (
472
+        !$login
473
+        || !($login_base = auth_retrouver_login($login, $serveur))
474
+        || !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
475
+    ) {
476
+        // generer de fausses infos, mais credibles, pour eviter une attaque
477
+        // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
478
+
479
+        $row = [
480
+            'login' => $login,
481
+            'cnx' => '0',
482
+            'logo' => '',
483
+        ];
484
+
485
+        return $row;
486
+    }
487
+
488
+    $prefs = @unserialize($row['prefs']);
489
+    $row = auth_desensibiliser_session($row);
490
+    $infos = [
491
+        'id_auteur' => $row['id_auteur'],
492
+        'login' => $row['login'],
493
+        'cnx' => (isset($prefs['cnx']) && $prefs['cnx'] === 'perma') ? '1' : '0',
494
+        'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row),
495
+    ];
496
+
497
+    verifier_visiteur();
498
+
499
+    return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos);
500 500
 }
501 501
 
502 502
 
@@ -510,21 +510,21 @@  discard block
 block discarded – undo
510 510
  * @return mixed
511 511
  */
512 512
 function auth_identifier_login($login, #[\SensitiveParameter] $password, $serveur = '', bool $phpauth = false) {
513
-	$erreur = '';
514
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
515
-		if ($auth = charger_fonction($methode, 'auth', true)) {
516
-			$auteur = $auth($login, $password, $serveur, $phpauth);
517
-			if (is_array($auteur) && count($auteur)) {
518
-				spip_logger()->info("connexion de $login par methode $methode");
519
-				$auteur['auth'] = $methode;
520
-				return $auteur;
521
-			} elseif (is_string($auteur)) {
522
-				$erreur .= "$auteur ";
523
-			}
524
-		}
525
-	}
526
-
527
-	return $erreur;
513
+    $erreur = '';
514
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
515
+        if ($auth = charger_fonction($methode, 'auth', true)) {
516
+            $auteur = $auth($login, $password, $serveur, $phpauth);
517
+            if (is_array($auteur) && count($auteur)) {
518
+                spip_logger()->info("connexion de $login par methode $methode");
519
+                $auteur['auth'] = $methode;
520
+                return $auteur;
521
+            } elseif (is_string($auteur)) {
522
+                $erreur .= "$auteur ";
523
+            }
524
+        }
525
+    }
526
+
527
+    return $erreur;
528 528
 }
529 529
 
530 530
 /**
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
  * @return string
539 539
  */
540 540
 function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') {
541
-	$securiser_action = charger_fonction('securiser_action', 'inc');
542
-	return $securiser_action('auth', "$auth_methode/$login", $redirect, true);
541
+    $securiser_action = charger_fonction('securiser_action', 'inc');
542
+    return $securiser_action('auth', "$auth_methode/$login", $redirect, true);
543 543
 }
544 544
 
545 545
 /**
@@ -553,8 +553,8 @@  discard block
 block discarded – undo
553 553
  * @return mixed
554 554
  */
555 555
 function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') {
556
-	$args = func_get_args();
557
-	return auth_administrer('terminer_identifier_login', $args);
556
+    $args = func_get_args();
557
+    return auth_administrer('terminer_identifier_login', $args);
558 558
 }
559 559
 
560 560
 /**
@@ -564,29 +564,29 @@  discard block
 block discarded – undo
564 564
  * @return bool
565 565
  */
566 566
 function auth_loger($auteur) {
567
-	if (!is_array($auteur) || $auteur === []) {
568
-		return false;
569
-	}
570
-
571
-	// initialiser et poser le cookie de session
572
-	unset($_COOKIE['spip_session']);
573
-	if (auth_init_droits($auteur) === false) {
574
-		return false;
575
-	}
576
-
577
-	// initialiser les prefs
578
-	$p = $GLOBALS['visiteur_session']['prefs'];
579
-	$p['cnx'] = (isset($auteur['cookie']) && $auteur['cookie'] == 'oui') ? 'perma' : '';
580
-
581
-	sql_updateq(
582
-		'spip_auteurs',
583
-		['prefs' => serialize($p)],
584
-		'id_auteur=' . (int) $auteur['id_auteur']
585
-	);
586
-
587
-	//  bloquer ici le visiteur qui tente d'abuser de ses droits
588
-	verifier_visiteur();
589
-	return true;
567
+    if (!is_array($auteur) || $auteur === []) {
568
+        return false;
569
+    }
570
+
571
+    // initialiser et poser le cookie de session
572
+    unset($_COOKIE['spip_session']);
573
+    if (auth_init_droits($auteur) === false) {
574
+        return false;
575
+    }
576
+
577
+    // initialiser les prefs
578
+    $p = $GLOBALS['visiteur_session']['prefs'];
579
+    $p['cnx'] = (isset($auteur['cookie']) && $auteur['cookie'] == 'oui') ? 'perma' : '';
580
+
581
+    sql_updateq(
582
+        'spip_auteurs',
583
+        ['prefs' => serialize($p)],
584
+        'id_auteur=' . (int) $auteur['id_auteur']
585
+    );
586
+
587
+    //  bloquer ici le visiteur qui tente d'abuser de ses droits
588
+    verifier_visiteur();
589
+    return true;
590 590
 }
591 591
 
592 592
 /**
@@ -596,8 +596,8 @@  discard block
 block discarded – undo
596 596
  * return void
597 597
  **/
598 598
 function auth_deloger() {
599
-	$logout = charger_fonction('logout', 'action');
600
-	$logout();
599
+    $logout = charger_fonction('logout', 'action');
600
+    $logout();
601 601
 }
602 602
 
603 603
 /**
@@ -611,8 +611,8 @@  discard block
 block discarded – undo
611 611
  * @return bool
612 612
  */
613 613
 function auth_autoriser_modifier_login($auth_methode, $serveur = '') {
614
-	$args = func_get_args();
615
-	return auth_administrer('autoriser_modifier_login', $args);
614
+    $args = func_get_args();
615
+    return auth_administrer('autoriser_modifier_login', $args);
616 616
 }
617 617
 
618 618
 /**
@@ -627,8 +627,8 @@  discard block
 block discarded – undo
627 627
  *  message d'erreur ou chaine vide si pas d'erreur
628 628
  */
629 629
 function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') {
630
-	$args = func_get_args();
631
-	return auth_administrer('verifier_login', $args, '');
630
+    $args = func_get_args();
631
+    return auth_administrer('verifier_login', $args, '');
632 632
 }
633 633
 
634 634
 /**
@@ -641,8 +641,8 @@  discard block
 block discarded – undo
641 641
  * @return bool
642 642
  */
643 643
 function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') {
644
-	$args = func_get_args();
645
-	return auth_administrer('modifier_login', $args);
644
+    $args = func_get_args();
645
+    return auth_administrer('modifier_login', $args);
646 646
 }
647 647
 
648 648
 /**
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
  *  succès ou échec
658 658
  */
659 659
 function auth_autoriser_modifier_pass($auth_methode, $serveur = '') {
660
-	$args = func_get_args();
661
-	return auth_administrer('autoriser_modifier_pass', $args);
660
+    $args = func_get_args();
661
+    return auth_administrer('autoriser_modifier_pass', $args);
662 662
 }
663 663
 
664 664
 /**
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
  *  message d'erreur ou chaine vide si pas d'erreur
675 675
  */
676 676
 function auth_verifier_pass($auth_methode, $login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') {
677
-	$args = func_get_args();
678
-	return auth_administrer('verifier_pass', $args, '');
677
+    $args = func_get_args();
678
+    return auth_administrer('verifier_pass', $args, '');
679 679
 }
680 680
 
681 681
 /**
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
  *  succes ou echec
692 692
  */
693 693
 function auth_modifier_pass($auth_methode, $login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') {
694
-	$args = func_get_args();
695
-	return auth_administrer('modifier_pass', $args);
694
+    $args = func_get_args();
695
+    return auth_administrer('modifier_pass', $args);
696 696
 }
697 697
 
698 698
 /**
@@ -708,24 +708,24 @@  discard block
 block discarded – undo
708 708
  * @return void
709 709
  */
710 710
 function auth_synchroniser_distant(
711
-	$auth_methode = true,
712
-	$id_auteur = 0,
713
-	$champs = [],
714
-	$options = [],
715
-	$serveur = ''
711
+    $auth_methode = true,
712
+    $id_auteur = 0,
713
+    $champs = [],
714
+    $options = [],
715
+    $serveur = ''
716 716
 ) {
717
-	$args = func_get_args();
718
-	if ($auth_methode === true || isset($options['all']) && $options['all'] == true) {
719
-		$options['all'] = true; // ajouter une option all=>true pour chaque auth
720
-		$args = [true, $id_auteur, $champs, $options, $serveur];
721
-		foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
722
-			array_shift($args);
723
-			array_unshift($args, $methode);
724
-			auth_administrer('synchroniser_distant', $args);
725
-		}
726
-	} else {
727
-		auth_administrer('synchroniser_distant', $args);
728
-	}
717
+    $args = func_get_args();
718
+    if ($auth_methode === true || isset($options['all']) && $options['all'] == true) {
719
+        $options['all'] = true; // ajouter une option all=>true pour chaque auth
720
+        $args = [true, $id_auteur, $champs, $options, $serveur];
721
+        foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
722
+            array_shift($args);
723
+            array_unshift($args, $methode);
724
+            auth_administrer('synchroniser_distant', $args);
725
+        }
726
+    } else {
727
+        auth_administrer('synchroniser_distant', $args);
728
+    }
729 729
 }
730 730
 
731 731
 
@@ -738,46 +738,46 @@  discard block
 block discarded – undo
738 738
  * @return array|bool
739 739
  */
740 740
 function lire_php_auth($login, #[\SensitiveParameter] $pw, $serveur = '') {
741
-	if (
742
-		!$login
743
-		|| !$login_base = auth_retrouver_login($login, $serveur)
744
-	) {
745
-		return false;
746
-	}
747
-
748
-	$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
749
-
750
-	if (!$row) {
751
-		if (
752
-			include_spip('inc/auth')
753
-			&& auth_ldap_connect($serveur)
754
-			&& ($auth_ldap = charger_fonction('ldap', 'auth', true))
755
-		) {
756
-			return $auth_ldap($login_base, $pw, $serveur, true);
757
-		}
758
-
759
-		return false;
760
-	}
761
-
762
-	// si pas de source definie
763
-	// ou auth/xxx introuvable, utiliser 'spip' ou autre et avec le login passé par PHP_AUTH_USER
764
-	if (
765
-		!($auth_methode = $row['source'])
766
-		|| !($auth = charger_fonction($auth_methode, 'auth', true))
767
-	) {
768
-		$auth = charger_fonction('spip', 'auth', true);
769
-	}
770
-
771
-	$auteur = '';
772
-	if ($auth) {
773
-		$auteur = $auth($login, $pw, $serveur, true);
774
-	}
775
-	// verifier que ce n'est pas un message d'erreur
776
-	if (is_array($auteur) && count($auteur)) {
777
-		return $auteur;
778
-	}
779
-
780
-	return false;
741
+    if (
742
+        !$login
743
+        || !$login_base = auth_retrouver_login($login, $serveur)
744
+    ) {
745
+        return false;
746
+    }
747
+
748
+    $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
749
+
750
+    if (!$row) {
751
+        if (
752
+            include_spip('inc/auth')
753
+            && auth_ldap_connect($serveur)
754
+            && ($auth_ldap = charger_fonction('ldap', 'auth', true))
755
+        ) {
756
+            return $auth_ldap($login_base, $pw, $serveur, true);
757
+        }
758
+
759
+        return false;
760
+    }
761
+
762
+    // si pas de source definie
763
+    // ou auth/xxx introuvable, utiliser 'spip' ou autre et avec le login passé par PHP_AUTH_USER
764
+    if (
765
+        !($auth_methode = $row['source'])
766
+        || !($auth = charger_fonction($auth_methode, 'auth', true))
767
+    ) {
768
+        $auth = charger_fonction('spip', 'auth', true);
769
+    }
770
+
771
+    $auteur = '';
772
+    if ($auth) {
773
+        $auteur = $auth($login, $pw, $serveur, true);
774
+    }
775
+    // verifier que ce n'est pas un message d'erreur
776
+    if (is_array($auteur) && count($auteur)) {
777
+        return $auteur;
778
+    }
779
+
780
+    return false;
781 781
 }
782 782
 
783 783
 /**
@@ -793,21 +793,21 @@  discard block
 block discarded – undo
793 793
  * @param string $lien
794 794
  */
795 795
 function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') {
796
-	@Header('WWW-Authenticate: Basic realm="espace prive"');
797
-	@Header('HTTP/1.0 401 Unauthorized');
798
-	$corps = '';
799
-	$public = generer_url_public();
800
-	$ecrire = generer_url_ecrire();
801
-	$retour = $retour ?: _T('icone_retour');
802
-	$corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
803
-	if ($url) {
804
-		$corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
805
-	}
806
-
807
-	if ($lien) {
808
-		$corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
809
-	}
810
-	include_spip('inc/minipres');
811
-	echo minipres($pb, $corps);
812
-	exit;
796
+    @Header('WWW-Authenticate: Basic realm="espace prive"');
797
+    @Header('HTTP/1.0 401 Unauthorized');
798
+    $corps = '';
799
+    $public = generer_url_public();
800
+    $ecrire = generer_url_ecrire();
801
+    $retour = $retour ?: _T('icone_retour');
802
+    $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
803
+    if ($url) {
804
+        $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
805
+    }
806
+
807
+    if ($lien) {
808
+        $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
809
+    }
810
+    include_spip('inc/minipres');
811
+    echo minipres($pb, $corps);
812
+    exit;
813 813
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	}
59 59
 
60 60
 	$n = (int) sql_errno();
61
-	spip_logger()->info("Erreur base de donnees $n " . sql_error());
61
+	spip_logger()->info("Erreur base de donnees $n ".sql_error());
62 62
 
63 63
 	return $n ?: 1;
64 64
 }
@@ -101,19 +101,19 @@  discard block
 block discarded – undo
101 101
 		// erreur SQL a afficher
102 102
 		$raison = minipres(
103 103
 			_T('info_travaux_titre'),
104
-			_T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
104
+			_T('titre_probleme_technique').'<p><tt>'.sql_errno().' '.sql_error().'</tt></p>'
105 105
 		);
106 106
 	} elseif (@$raison['statut']) {
107 107
 		// un simple visiteur n'a pas acces a l'espace prive
108
-		spip_logger()->info('connexion refusee a ' . @$raison['id_auteur']);
108
+		spip_logger()->info('connexion refusee a '.@$raison['id_auteur']);
109 109
 		$est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT
110 110
 		$raison = minipres(
111 111
 			_T('avis_erreur_connexion'),
112 112
 			_T('avis_erreur_visiteur')
113 113
 				// Lien vers le site public
114
-				. '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>'
114
+				. '<br /><a href="'.url_de_base().'">'._T('login_retour_public').'</a>'
115 115
 				// Si la personne est connectée, lien de déconnexion ramenant vers la page de login
116
-				. ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&amp;logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '')
116
+				. ($est_connecte ? ' | <a href="'.generer_url_public('', 'action=logout&amp;logout=prive').'">'._T('icone_deconnecter').'</a>' : '')
117 117
 		);
118 118
 	} else {
119 119
 		// auteur en fin de droits ...
@@ -201,8 +201,7 @@  discard block
 block discarded – undo
201 201
 	$where = (is_numeric($id_auteur)
202 202
 		/*AND $id_auteur>0*/ // reprise lors des restaurations
203 203
 	) ?
204
-		"id_auteur=$id_auteur" :
205
-		(strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : '');
204
+		"id_auteur=$id_auteur" : (strlen((string) $GLOBALS['connect_login']) ? 'login='.sql_quote($GLOBALS['connect_login'], '', 'text') : '');
206 205
 
207 206
 	if (!$where) {
208 207
 		return '';
@@ -327,7 +326,7 @@  discard block
 block discarded – undo
327 326
  * @return string
328 327
  */
329 328
 function auth_a_loger() {
330
-	$redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true);
329
+	$redirect = generer_url_public('login', 'url='.rawurlencode((string) self('&', true)), true);
331 330
 
332 331
 	// un echec au "bonjour" (login initial) quand le statut est
333 332
 	// inconnu signale sans doute un probleme de cookies
@@ -363,7 +362,7 @@  discard block
 block discarded – undo
363 362
 	$date ??= date('Y-m-d H:i:s');
364 363
 
365 364
 	if (abs(strtotime($date) - $connect_quand) >= 60) {
366
-		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']);
365
+		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur='.(int) $row['id_auteur']);
367 366
 		$row['en_ligne'] = $date;
368 367
 	}
369 368
 
@@ -471,7 +470,7 @@  discard block
 block discarded – undo
471 470
 	if (
472 471
 		!$login
473 472
 		|| !($login_base = auth_retrouver_login($login, $serveur))
474
-		|| !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
473
+		|| !($row = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
475 474
 	) {
476 475
 		// generer de fausses infos, mais credibles, pour eviter une attaque
477 476
 		// https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
@@ -581,7 +580,7 @@  discard block
 block discarded – undo
581 580
 	sql_updateq(
582 581
 		'spip_auteurs',
583 582
 		['prefs' => serialize($p)],
584
-		'id_auteur=' . (int) $auteur['id_auteur']
583
+		'id_auteur='.(int) $auteur['id_auteur']
585 584
 	);
586 585
 
587 586
 	//  bloquer ici le visiteur qui tente d'abuser de ses droits
@@ -745,7 +744,7 @@  discard block
 block discarded – undo
745 744
 		return false;
746 745
 	}
747 746
 
748
-	$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
747
+	$row = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
749 748
 
750 749
 	if (!$row) {
751 750
 		if (
@@ -801,11 +800,11 @@  discard block
 block discarded – undo
801 800
 	$retour = $retour ?: _T('icone_retour');
802 801
 	$corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
803 802
 	if ($url) {
804
-		$corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
803
+		$corps .= "[<a href='".generer_url_action('cookie', "essai_auth_http=oui&$url")."'>$re</a>]";
805 804
 	}
806 805
 
807 806
 	if ($lien) {
808
-		$corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
807
+		$corps .= " [<a href='$ecrire'>"._T('login_espace_prive').'</a>]';
809 808
 	}
810 809
 	include_spip('inc/minipres');
811 810
 	echo minipres($pb, $corps);
Please login to merge, or discard this patch.
ecrire/inc/journal.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
  * @param array $opt
24 24
  */
25 25
 function inc_journal_dist($phrase, $opt = []) {
26
-	if (!strlen((string) $phrase)) {
27
-		return;
28
-	}
29
-	if ($opt) {
30
-		$phrase .= ' :: ' . str_replace("\n", ' ', implode(', ', $opt));
31
-	}
32
-	spip_logger('journal')->info($phrase);
26
+    if (!strlen((string) $phrase)) {
27
+        return;
28
+    }
29
+    if ($opt) {
30
+        $phrase .= ' :: ' . str_replace("\n", ' ', implode(', ', $opt));
31
+    }
32
+    spip_logger('journal')->info($phrase);
33 33
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 		return;
28 28
 	}
29 29
 	if ($opt) {
30
-		$phrase .= ' :: ' . str_replace("\n", ' ', implode(', ', $opt));
30
+		$phrase .= ' :: '.str_replace("\n", ' ', implode(', ', $opt));
31 31
 	}
32 32
 	spip_logger('journal')->info($phrase);
33 33
 }
Please login to merge, or discard this patch.
ecrire/inc/envoyer_mail.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Mail
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/charsets');
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @return string
32 32
  */
33 33
 function nettoyer_titre_email($titre) {
34
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
34
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35 35
 }
36 36
 
37 37
 /**
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function nettoyer_caracteres_mail($t) {
49 49
 
50
-	$t = filtrer_entites($t);
51
-
52
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
53
-		$t = str_replace(
54
-			['&#8217;', '&#8220;', '&#8221;'],
55
-			["'", '"', '"'],
56
-			$t
57
-		);
58
-	}
59
-
60
-	return str_replace(
61
-		['&mdash;', '&endash;'],
62
-		['--', '-'],
63
-		$t
64
-	);
50
+    $t = filtrer_entites($t);
51
+
52
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
53
+        $t = str_replace(
54
+            ['&#8217;', '&#8220;', '&#8221;'],
55
+            ["'", '"', '"'],
56
+            $t
57
+        );
58
+    }
59
+
60
+    return str_replace(
61
+        ['&mdash;', '&endash;'],
62
+        ['--', '-'],
63
+        $t
64
+    );
65 65
 }
66 66
 
67 67
 /**
@@ -94,87 +94,87 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
96 96
 
97
-	if (!email_valide($destinataire)) {
98
-		return false;
99
-	}
100
-	if ($destinataire == _T('info_mail_fournisseur')) {
101
-		return false;
102
-	} // tres fort
103
-
104
-	// Fournir si possible un Message-Id: conforme au RFC1036,
105
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
106
-
107
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
108
-	if (!email_valide($email_envoi)) {
109
-		spip_logger()->info('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
110
-		$email_envoi = $destinataire;
111
-	}
112
-
113
-	$parts = '';
114
-	if (is_array($corps)) {
115
-		$texte = $corps['texte'];
116
-		$from = ($corps['from'] ?? $from);
117
-		$headers = ($corps['headers'] ?? $headers);
118
-		if (is_array($headers)) {
119
-			$headers = implode("\n", $headers);
120
-		}
121
-		if (isset($corps['pieces_jointes']) && function_exists('mail_embarquer_pieces_jointes')) {
122
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
123
-		}
124
-	} else {
125
-		$texte = $corps;
126
-	}
127
-
128
-	if (!$from) {
129
-		$from = $email_envoi;
130
-	}
131
-
132
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
135
-	}
136
-
137
-	// nettoyer les &eacute; &#8217, &emdash; etc...
138
-	// les 'cliquer ici' etc sont a eviter;  voir:
139
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
140
-	$texte = nettoyer_caracteres_mail($texte);
141
-	$sujet = nettoyer_caracteres_mail($sujet);
142
-
143
-	// encoder le sujet si possible selon la RFC
144
-	if (init_mb_string()) {
145
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
146
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
147
-		$charset = $GLOBALS['meta']['charset'];
148
-		mb_internal_encoding($charset);
149
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
150
-		mb_internal_encoding('utf-8');
151
-	}
152
-
153
-	$headers ??= '';
154
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', (string) $headers) == 0)) {
155
-		$texte = wordwrap($texte);
156
-	}
157
-
158
-	[$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
159
-
160
-	if (_OS_SERVEUR == 'windows') {
161
-		$texte = preg_replace("@\r*\n@", "\r\n", (string) $texte);
162
-		$headers = preg_replace("@\r*\n@", "\r\n", (string) $headers);
163
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
164
-	}
165
-
166
-	spip_logger('mails')->info("mail $destinataire\n$sujet\n$headers");
167
-	// mode TEST : forcer l'email
168
-	if (defined('_TEST_EMAIL_DEST')) {
169
-		if (!_TEST_EMAIL_DEST) {
170
-			return false;
171
-		} else {
172
-			$texte = "Dest : $destinataire\r\n" . $texte;
173
-			$destinataire = _TEST_EMAIL_DEST;
174
-		}
175
-	}
176
-
177
-	return @mail((string) $destinataire, $sujet, (string) $texte, $headers);
97
+    if (!email_valide($destinataire)) {
98
+        return false;
99
+    }
100
+    if ($destinataire == _T('info_mail_fournisseur')) {
101
+        return false;
102
+    } // tres fort
103
+
104
+    // Fournir si possible un Message-Id: conforme au RFC1036,
105
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
106
+
107
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
108
+    if (!email_valide($email_envoi)) {
109
+        spip_logger()->info('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
110
+        $email_envoi = $destinataire;
111
+    }
112
+
113
+    $parts = '';
114
+    if (is_array($corps)) {
115
+        $texte = $corps['texte'];
116
+        $from = ($corps['from'] ?? $from);
117
+        $headers = ($corps['headers'] ?? $headers);
118
+        if (is_array($headers)) {
119
+            $headers = implode("\n", $headers);
120
+        }
121
+        if (isset($corps['pieces_jointes']) && function_exists('mail_embarquer_pieces_jointes')) {
122
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
123
+        }
124
+    } else {
125
+        $texte = $corps;
126
+    }
127
+
128
+    if (!$from) {
129
+        $from = $email_envoi;
130
+    }
131
+
132
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
135
+    }
136
+
137
+    // nettoyer les &eacute; &#8217, &emdash; etc...
138
+    // les 'cliquer ici' etc sont a eviter;  voir:
139
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
140
+    $texte = nettoyer_caracteres_mail($texte);
141
+    $sujet = nettoyer_caracteres_mail($sujet);
142
+
143
+    // encoder le sujet si possible selon la RFC
144
+    if (init_mb_string()) {
145
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
146
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
147
+        $charset = $GLOBALS['meta']['charset'];
148
+        mb_internal_encoding($charset);
149
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
150
+        mb_internal_encoding('utf-8');
151
+    }
152
+
153
+    $headers ??= '';
154
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', (string) $headers) == 0)) {
155
+        $texte = wordwrap($texte);
156
+    }
157
+
158
+    [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
159
+
160
+    if (_OS_SERVEUR == 'windows') {
161
+        $texte = preg_replace("@\r*\n@", "\r\n", (string) $texte);
162
+        $headers = preg_replace("@\r*\n@", "\r\n", (string) $headers);
163
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
164
+    }
165
+
166
+    spip_logger('mails')->info("mail $destinataire\n$sujet\n$headers");
167
+    // mode TEST : forcer l'email
168
+    if (defined('_TEST_EMAIL_DEST')) {
169
+        if (!_TEST_EMAIL_DEST) {
170
+            return false;
171
+        } else {
172
+            $texte = "Dest : $destinataire\r\n" . $texte;
173
+            $destinataire = _TEST_EMAIL_DEST;
174
+        }
175
+    }
176
+
177
+    return @mail((string) $destinataire, $sujet, (string) $texte, $headers);
178 178
 }
179 179
 
180 180
 /**
@@ -188,53 +188,53 @@  discard block
 block discarded – undo
188 188
  * @return array
189 189
  */
190 190
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
191
-	$charset = $GLOBALS['meta']['charset'];
192
-
193
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
194
-	if (!str_contains($headers, 'Content-Type: ')) {
195
-		$type =
196
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
197
-			"Content-Transfer-Encoding: 8bit\n";
198
-	} else {
199
-		$type = '';
200
-	}
201
-
202
-	// calculer un identifiant unique
203
-	// Marie Toto <[email protected]> => @toto.com
204
-	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
206
-
207
-	// Si multi-part, s'en servir comme borne ...
208
-	if ($parts) {
209
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
210
-		foreach ($parts as $part) {
211
-			$n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
212
-			$e = implode("\n", $part[0]);
213
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
-		}
215
-		$texte .= "\n\n--$uniq--\n";
216
-		// Si boundary n'est pas entre guillemets,
217
-		// elle est comprise mais le charset est ignoree !
218
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
219
-	}
220
-
221
-	// .. et s'en servir pour plaire a SpamAssassin
222
-
223
-	$mid = 'Message-Id: <' . $uniq . '>';
224
-
225
-	// indispensable pour les sites qui collent d'office From: serveur-http
226
-	// sauf si deja mis par l'envoyeur
227
-	$rep = (str_contains($headers, 'Reply-To:')) ? '' : "Reply-To: $from\n";
228
-
229
-	// Nettoyer les en-tetes envoyees
230
-	// Ajouter le \n final
231
-	if (strlen($headers = trim($headers))) {
232
-		$headers .= "\n";
233
-	}
234
-
235
-	// Et mentionner l'indeboulonable nomenclature ratee
236
-
237
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
238
-
239
-	return [$headers, $texte];
191
+    $charset = $GLOBALS['meta']['charset'];
192
+
193
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
194
+    if (!str_contains($headers, 'Content-Type: ')) {
195
+        $type =
196
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
197
+            "Content-Transfer-Encoding: 8bit\n";
198
+    } else {
199
+        $type = '';
200
+    }
201
+
202
+    // calculer un identifiant unique
203
+    // Marie Toto <[email protected]> => @toto.com
204
+    $domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
+    $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
206
+
207
+    // Si multi-part, s'en servir comme borne ...
208
+    if ($parts) {
209
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
210
+        foreach ($parts as $part) {
211
+            $n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
212
+            $e = implode("\n", $part[0]);
213
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
+        }
215
+        $texte .= "\n\n--$uniq--\n";
216
+        // Si boundary n'est pas entre guillemets,
217
+        // elle est comprise mais le charset est ignoree !
218
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
219
+    }
220
+
221
+    // .. et s'en servir pour plaire a SpamAssassin
222
+
223
+    $mid = 'Message-Id: <' . $uniq . '>';
224
+
225
+    // indispensable pour les sites qui collent d'office From: serveur-http
226
+    // sauf si deja mis par l'envoyeur
227
+    $rep = (str_contains($headers, 'Reply-To:')) ? '' : "Reply-To: $from\n";
228
+
229
+    // Nettoyer les en-tetes envoyees
230
+    // Ajouter le \n final
231
+    if (strlen($headers = trim($headers))) {
232
+        $headers .= "\n";
233
+    }
234
+
235
+    // Et mentionner l'indeboulonable nomenclature ratee
236
+
237
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
238
+
239
+    return [$headers, $texte];
240 240
 }
Please login to merge, or discard this patch.